2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
8 # This software is governed by the CeCILL-B license under French law and
9 # abiding by the rules of distribution of free software. You can use,
10 # modify and/ or redistribute the software under the terms of the CeCILL-B
11 # license as circulated by CEA, CNRS and INRIA at the following URL
12 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
13 # or in the file LICENSE.txt.
15 # As a counterpart to the access to the source code and rights to copy,
16 # modify and redistribute granted by the license, users are provided only
17 # with a limited warranty and the software's author, the holder of the
18 # economic rights, and the successive licensors have only limited
21 # The fact that you are presently reading this means that you have had
22 # knowledge of the CeCILL-B license and that you accept its terms.
23 # ------------------------------------------------------------------------
26 /*=========================================================================
32 =========================================================================*/
34 /* ---------------------------------------------------------------------
36 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
37 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
39 * This software is governed by the CeCILL-B license under French law and
40 * abiding by the rules of distribution of free software. You can use,
41 * modify and/ or redistribute the software under the terms of the CeCILL-B
42 * license as circulated by CEA, CNRS and INRIA at the following URL
43 * http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
44 * or in the file LICENSE.txt.
46 * As a counterpart to the access to the source code and rights to copy,
47 * modify and redistribute granted by the license, users are provided only
48 * with a limited warranty and the software's author, the holder of the
49 * economic rights, and the successive licensors have only limited
52 * The fact that you are presently reading this means that you have had
53 * knowledge of the CeCILL-B license and that you accept its terms.
54 * ------------------------------------------------------------------------ */
58 * \brief Class bbtk::wxVtkSceneManager .
61 #include "wxVtkSceneManager.h"
63 #include <vtkPolygon.h>
64 #include <vtkUnstructuredGrid.h>
68 #define POORT_MAX_LINE_SIZE_INTERPRETER 1500
70 //=========================================================================
72 // EED 15 oct 2012 wxVtkSceneManager::wxVtkSceneManager(wxGEditorTabPanel *parent, wxVtk3DBaseView *baseView, int idManager,Factory::Pointer bbtkfactory)
75 wxVtkSceneManager::wxVtkSceneManager(wxGEditorTabPanel *parent, wxVtk3DBaseView *baseView, int idManager,Factory::Pointer bbtkfactory)
77 _cbName = "ComplexBoxName";
78 _cbPackageName = "PackageName";
79 _Author = "Author ??";
81 _Description = "Description ??";
85 _bugTextActor_text = "void";
86 _bugTextActor_status = 0;
90 _idManager = idManager;
92 _bbtkfactory = bbtkfactory;
94 _startDragging = false;
95 _isComplexBox = false;
97 if (_baseView != NULL) {
100 "RaC-EED 21-06-2010 %p wxVtkSceneManager::wxVtkSceneManager If you comment this line, the drag and drop functionnality is not initialized.\n",
103 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget((wxDropTarget*)parent);
107 _worldState = NOTHING_HAPPENS;
108 registerController(this);
111 _idConnectionInCreation = -1;
115 //=========================================================================
117 void wxVtkSceneManager::disconnectDrop()
119 //EED02JUIN2010 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget(NULL);
120 // _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget( new tmpClasswxTextDropTarget() );
123 //=========================================================================
125 wxVtkSceneManager::~wxVtkSceneManager()
132 //=========================================================================
134 void wxVtkSceneManager::configureBaseView()
136 vtkInteractorStyleBaseView2D *interactorstylebaseview = vtkInteractorStyleBaseView2D::New();
137 _baseView->SetInteractorStyleBaseView(interactorstylebaseview);
138 // Important to activate the 2D interaction system
139 crea::wxVTKRenderWindowInteractor *iren = _baseView->GetWxVTKRenderWindowInteractor();
140 interactorstylebaseview->SetInteractor(iren);
141 iren->SetInteractorStyle(interactorstylebaseview);
142 interactorstylebaseview->SetwxVtkBaseView(_baseView);
143 _baseView->GetRenderer()->GetActiveCamera()->ParallelProjectionOn();
144 _baseView->GetRenderer()->ResetCamera(-100, 100, -100, 100, -1000, 1000);
145 _baseView->GetRenderer()->GetActiveCamera()->Zoom(20);
146 _baseView->GetRenderer()->SetBackground(0.9, 0.9, 0.9);
147 _baseView->GetRenderer()->GradientBackgroundOn();
149 _textActor = vtkTextActor3D::New();
150 // _textActor = vtkTextActor::New();
151 _textActor->SetPosition(-9999, -9999, GPOSITION_Z);
152 _textActor->SetInput("<void>");
154 // _textActor->GetTextProperty()->SetFontSize(60);
155 _textActor->GetTextProperty()->SetFontSize(40);
156 _textActor->GetTextProperty()->BoldOn();
157 _textActor->GetTextProperty()->SetFontFamilyToArial();
158 _textActor->GetTextProperty()->ShadowOff();
159 _textActor->GetTextProperty()->SetColor(PORTTEXT_NH_R, PORTTEXT_NH_G,PORTTEXT_NH_B);
160 _baseView->GetRenderer()->AddActor(_textActor);
161 // Actor Fill_Port_Text
165 double zInic = GPOSITION_Z;
166 vtkPolygon *aPolygon = vtkPolygon::New();
167 _fillObjectActor = vtkActor::New();
168 _pts = vtkPoints::New();
171 double w = 100, h = 10, b = h / 15, t = 3;
172 _pts->SetNumberOfPoints(21);
173 _pts->InsertPoint(0, xInic + w * 0.33 - t / 2, yInic, zInic);
174 _pts->InsertPoint(1, xInic + w * 0.33, yInic - t, zInic);
175 _pts->InsertPoint(2, xInic + w * 0.33 + t / 2, yInic, zInic);
176 _pts->InsertPoint(3, xInic + w * 0.33 + t / 2, yInic, zInic);
177 _pts->InsertPoint(4, xInic + w - b * 4, yInic + b * 0, zInic);
179 _pts->InsertPoint(5, xInic + w - b * 4, yInic + b * 0, zInic);
180 _pts->InsertPoint(6, xInic + w - b * 2, yInic + b * 1, zInic);
181 _pts->InsertPoint(7, xInic + w - b * 1, yInic + b * 2, zInic);
182 _pts->InsertPoint(8, xInic + w - b * 0, yInic + b * 4, zInic);
184 _pts->InsertPoint(9, xInic + w - b * 0, yInic + h - b * 4, zInic);
185 _pts->InsertPoint(10, xInic + w - b * 1, yInic + h - b * 2, zInic);
186 _pts->InsertPoint(11, xInic + w - b * 2, yInic + h - b * 1, zInic);
187 _pts->InsertPoint(12, xInic + w - b * 4, yInic + h - b * 0, zInic);
189 _pts->InsertPoint(13, xInic + b * 4, yInic + h - b * 0, zInic);
190 _pts->InsertPoint(14, xInic + b * 2, yInic + h - b * 1, zInic);
191 _pts->InsertPoint(15, xInic + b * 1, yInic + h - b * 2, zInic);
192 _pts->InsertPoint(16, xInic + b * 0, yInic + h - b * 4, zInic);
194 _pts->InsertPoint(17, xInic + b * 0, yInic + b * 4, zInic);
195 _pts->InsertPoint(18, xInic + b * 1, yInic + b * 2, zInic);
196 _pts->InsertPoint(19, xInic + b * 2, yInic + b * 1, zInic);
197 _pts->InsertPoint(20, xInic + b * 4, yInic + b * 0, zInic);
198 aPolygon->GetPointIds()->SetNumberOfIds(21);
199 for (int i = 0; i < 21; i++) {
201 aPolygon->GetPointIds()->SetId(i, i);
205 double w = BOX_WIDTH, h = BOX_HEIGHT, t = PORT_HEIGHT;
206 _pts->SetNumberOfPoints(7);
207 _pts->InsertPoint(0, xInic + t/2.0 , yInic + t , zInic );
208 _pts->InsertPoint(1, xInic + w , yInic + t , zInic );
209 _pts->InsertPoint(2, xInic + w , yInic + t + h , zInic );
210 _pts->InsertPoint(3, xInic - t*1.5 , yInic + t + h , zInic );
211 _pts->InsertPoint(4, xInic - t*1.5 , yInic + t , zInic );
212 _pts->InsertPoint(5, xInic - t/2 , yInic + t , zInic );
213 _pts->InsertPoint(6, xInic , yInic , zInic );
214 aPolygon->GetPointIds()->SetNumberOfIds(8);
215 for (int i = 0; i < 8; i++)
217 aPolygon->GetPointIds()->SetId(i, i);
218 if (i==7) aPolygon->GetPointIds()->SetId(i, 0);
220 vtkUnstructuredGrid *aPolygonGrid = vtkUnstructuredGrid::New();
221 aPolygonGrid->Allocate(1, 1);
222 aPolygonGrid->InsertNextCell(aPolygon->GetCellType(),aPolygon->GetPointIds());
223 aPolygonGrid->SetPoints(_pts);
224 _aPolygonMapper = vtkDataSetMapper::New();
225 //EED 2017-01-01 Migration VTK7
226 #if VTK_MAJOR_VERSION <= 5
227 _aPolygonMapper->SetInput(aPolygonGrid);
229 _aPolygonMapper->SetInputData(aPolygonGrid);
231 _fillObjectActor->SetMapper(_aPolygonMapper);
232 _fillObjectActor->GetProperty()->SetColor(PORTFILL_NH_R, PORTFILL_NH_G,PORTFILL_NH_B);
233 _fillObjectActor->GetProperty()->SetOpacity(0);
234 _aPolygonMapper->Modified();
235 _baseView->GetRenderer()->AddActor(_fillObjectActor);
239 //=========================================================================
241 std::string wxVtkSceneManager::generateANewNameForABox() {
242 std::stringstream boxname;
243 if (_numBoxes < 10) {
244 boxname << "Box0" << _numBoxes;
246 boxname << "Box" << _numBoxes;
249 return boxname.str();
252 //=========================================================================
254 std::string wxVtkSceneManager::findANewNameForABox() {
255 std::string boxname = generateANewNameForABox();
257 while (boxExist(boxname) == true) {
258 boxname = generateANewNameForABox();
264 //=========================================================================
265 void wxVtkSceneManager::configGBlackBox(int idBox, double xIn, double yIn,
266 double zIn, std::string name, bool boxExecutable, double xEn,
267 double yEn, double zEn) {
268 GObjectController *cont = _controllers[idBox];
269 GBlackBoxModel *bbmod = (GBlackBoxModel*) cont->getModel();
270 bbmod->setBBTKName(name);
271 bbmod->setInicPoint(xIn, yIn, zIn);
272 bbmod->setFinalPoint(xEn, yEn, zEn);
273 bbmod->setExecutable(boxExecutable);
275 bbmod->notifyObservers(_idManager);
279 //=========================================================================
281 int wxVtkSceneManager::createGBlackBox(int x, int y, std::string packageName,std::string boxType)
283 _worldState = NOTHING_HAPPENS;
284 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
285 int type = GBLACKBOX;
286 //Create the MVC Objects
287 GBlackBoxModel *model = (GBlackBoxModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(type);
288 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
289 GObjectController *controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
291 //EED 15 oct 2012 BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxType);
295 std::map< std::string, BlackBoxDescriptor::Pointer> mapDesc;
297 k = _bbtkfactory->GetPackage(packageName);
298 mapDesc = k->GetDescriptorMap();
300 printf("EED. ERROR!: Exception in wxVtkSceneManager::createGBlackBox for package %s, NOT EXIST\n", packageName.c_str());
303 BlackBoxDescriptor::Pointer descriptor;
305 descriptor = mapDesc[boxType];
307 printf("EED. ERROR!: Exception in wxVtkSceneManager::createGBlackBox for box %s of package %s, NOT EXIST\n", boxType.c_str(),packageName.c_str());
310 if (descriptor == NULL)
312 printf("SCP: ERROR in wxVtkSceneManager::createGBlackBox, box %s probably does not exist.\n", boxType.c_str());
315 //Prepares the initial model
316 //The coordinates obtained are the following. Top-Left:x=0,y=0 Bottom-Right:x=width,y=height
319 double yy = windowHeight - y;
321 //z value is not important yet, because it is only used a parallel projection
322 double zz = GPOSITION_Z;
323 _baseView->TransCoordScreenToWorld(xx, yy, zz);
324 model->setInicPoint(xx, yy, zz);
326 std::stringstream stream;
328 std::string newBoxName;
329 newBoxName = findANewNameForABox();
331 stream << newBoxName;
333 std::string arraystring = stream.str();
335 model->setBBTKName(arraystring);
336 model->setBBTKType(boxType);
337 model->setBBTKPackage(packageName);
339 model->addObserver(view);
340 model->addObserver(this);
343 //EED2017 change order
344 //Associates the view with the correspondent renderer and the model.
345 //(NOTE: Refresh is only made by the view)
346 view->setModel(model);
347 view->setBaseView(_baseView);
349 //Associates the controller with the correspondent model and view
350 controller->setModelAndView(model, view);
353 //Iterate and create the input ports
354 std::map<std::string, BlackBoxInputDescriptor*> descriptorInMap =
355 descriptor->GetInputDescriptorMap();
356 std::map<std::string, BlackBoxInputDescriptor*>::iterator itInput;
358 for (itInput = descriptorInMap.begin(); itInput != descriptorInMap.end(); ++itInput)
360 BlackBoxInputDescriptor *desc = itInput->second;
362 // createGInputPort(GINPUTPORT, i, model, desc);
363 createGInputPort(GINPUTPORT, i, controller, desc);
367 //Iterate and create the output ports
368 std::map<std::string, BlackBoxOutputDescriptor*> descriptorOutMap =
369 descriptor->GetOutputDescriptorMap();
370 std::map<std::string, BlackBoxOutputDescriptor*>::iterator itOutput;
372 for (itOutput = descriptorOutMap.begin(); itOutput!= descriptorOutMap.end(); ++itOutput)
374 BlackBoxOutputDescriptor *desc = itOutput->second;
376 // createGOutputPort(GOUTPUTPORT, i, model, desc);
377 createGOutputPort(GOUTPUTPORT, i, controller, desc);
381 //EED2017 change order
382 view->initVtkObjects();
384 //Resgiter change to the observers of the actual model
385 model->notifyObservers(_idManager);
386 int newId = addObjectController(controller);
392 //=========================================================================
394 int wxVtkSceneManager::createGComplexBoxInputPort(std::string inputName) {
395 //EED int windowWidth=_baseView->GetRenWin()->GetSize()[0];
396 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
398 int type = GCOMPLEXINPUTPORT;
400 //Create the MVC Objects
402 GComplexBoxPortModel *model = (GComplexBoxPortModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(type);
403 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
404 GObjectController *controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
406 //Prepares the initial model
409 double yy = windowHeight - 5;
411 //z value is not important yet, because it is only used a parallel projection
412 double zz = GPOSITION_Z;
414 _baseView->TransCoordScreenToWorld(xx, yy, zz);
415 model->setInicPoint(xx, yy, zz);
417 model->setBBTKName(inputName);
418 model->setBBTKType("ComplexInputPort");
419 model->setComplexPortType(type);
421 model->addObserver(view);
422 model->addObserver(this);
424 //create the output port
425 GPortController* portController = createGPort(GOUTPUTPORT, inputName,
426 "ComplexOutputPortType","ComplexOutputPortDescriopton", 0, model);
427 model->addOutputPort((GPortModel*) portController->getModel());
429 //Associates the view with the correspondent renderer and the model.
430 //(NOTE: Refresh is only made by the view)
431 view->setModel(model);
432 view->setBaseView(_baseView);
433 view->initVtkObjects();
435 //Associates the controller with the correspondent model and view
436 controller->setModelAndView(model, view);
438 //Resgiter change to the observers of the actual model
439 model->notifyObservers(_idManager);
441 int newId = addObjectController(controller);
445 //=========================================================================
447 int wxVtkSceneManager::createGComplexBoxOutputPort(std::string outputName) {
448 //EED int windowWidth=_baseView->GetRenWin()->GetSize()[0];
449 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
451 int type = GCOMPLEXOUTPUTPORT;
453 //Create the MVC Objects
455 GComplexBoxPortModel *model = (GComplexBoxPortModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(type);
456 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
457 GObjectController *controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
459 //Prepares the initial model
462 double yy = windowHeight - 5;
464 //z value is not important yet, because it is only used a parallel projection
465 double zz = GPOSITION_Z;
467 _baseView->TransCoordScreenToWorld(xx, yy, zz);
468 model->setInicPoint(xx, yy, zz);
470 model->setBBTKName(outputName);
471 model->setBBTKType("ComplexOutputPort");
472 model->setComplexPortType(type);
474 model->addObserver(view);
475 model->addObserver(this);
477 //create the output port
478 GPortController* portController = createGPort(GINPUTPORT, outputName,
479 "ComplexInputPort","ComplexInputPortDescription", 0, model);
480 model->addInputPort((GPortModel*) portController->getModel());
482 //Associates the view with the correspondent renderer and the model.
483 //(NOTE: Refresh is only made by the view)
484 view->setModel(model);
485 view->setBaseView(_baseView);
486 view->initVtkObjects();
488 //Associates the controller with the correspondent model and view
489 controller->setModelAndView(model, view);
491 //Resgiter change to the observers of the actual model
492 model->notifyObservers(_idManager);
494 int newId = addObjectController(controller);
498 //=========================================================================
501 //int wxVtkSceneManager::createGInputPort(int portType, int posinBox, GBoxModel *blackBox, BlackBoxInputDescriptor *desc)
502 int wxVtkSceneManager::createGInputPort(int portType, int posinBox, GObjectController *gBoxControler, BlackBoxInputDescriptor *desc)
504 GBoxModel *blackBox=(GBoxModel*)gBoxControler->getModel();
505 GPortController* portController = createGPort(portType, desc->GetName(),
506 desc->GetTypeName(), desc->GetDescription(), posinBox, blackBox);
507 blackBox->addInputPort( (GPortModel*)portController->getModel() );
509 vtkGBoxView *vtkgboxView=(vtkGBoxView*)gBoxControler->getView();
510 vtkgboxView->addInputPort( (vtkGPortView*)portController->getView() );
512 return portController->getId();
515 //=========================================================================
518 //int wxVtkSceneManager::createGOutputPort(int portType, int posinBox,GBoxModel *blackBox, BlackBoxOutputDescriptor *desc)
519 int wxVtkSceneManager::createGOutputPort(int portType, int posinBox,GObjectController *gBoxControler, BlackBoxOutputDescriptor *desc)
521 GBoxModel *blackBox=(GBoxModel*)gBoxControler->getModel();
522 GPortController* portController = createGPort(portType, desc->GetName(),
523 desc->GetTypeName(),desc->GetDescription(), posinBox, blackBox);
524 blackBox->addOutputPort((GPortModel*) portController->getModel());
526 vtkGBoxView *vtkgboxView=(vtkGBoxView*)gBoxControler->getView();
527 vtkgboxView->addOutputPort( (vtkGPortView*)portController->getView() );
529 return portController->getId();
532 //=========================================================================
534 GPortController* wxVtkSceneManager::createGPort(int portType,std::string bbtkName, std::string bbtkType, std::string bbtkDescription, int posInBox,GBoxModel *blackBox)
538 //Create the MVC Objects
539 GPortModel *model = (GPortModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(type);
540 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
541 GObjectController *controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
542 model->registerInBox(blackBox, portType, posInBox);
543 model->setBBTKType(bbtkType);
544 model->setBBTKName(bbtkName);
545 model->setBBTKDescription(bbtkDescription);
546 model->addObserver(view);
547 model->addObserver(this);
548 //Associates the view with the correspondent renderer and the model.
549 //(NOTE: Refresh is only made by the view)
550 view->setModel(model);
551 view->setBaseView(_baseView);
552 //EED017 view->initVtkObjects();
553 view->createVtkObjects();
554 // view->addVtkActors();
556 //Associates the controller with the correspondent model and view
557 controller->setModelAndView(model, view);
558 model->notifyObservers(_idManager);
559 addObjectController(controller);
560 return (GPortController*) controller;
563 //=========================================================================
565 int wxVtkSceneManager::createGConnector(GPortModel* startPort)
567 int type = GCONNECTOR;
569 manualConnectorContourController *manContourControl = new manualConnectorContourController();
570 manualConnectorContourView *manContourView = new manualConnectorContourView();
571 manualContourModel *manContourModel = new manualContourModel();
572 GConnectorController *connectorcontroller = new GConnectorController();
573 GConnectorModel *connectorModel = new GConnectorModel();
574 vtkGConnectorView *connectorView = new vtkGConnectorView();
575 connectorModel->setGObjectType(type);
577 manContourModel->SetCloseContour(false);
578 connectorModel->setStartPort(startPort);
580 manContourView->SetModel(manContourModel);
581 manContourView->SetWxVtkBaseView(_baseView);
582 manContourView->SetRange(0.5);
583 manContourView->SetZ(GPOSITION_Z);
585 manContourView->SetColorNormalContour(0, 0, 1);
586 manContourView->SetColorEditContour(0.5, 0.5, 0.5);
587 manContourView->SetColorSelectContour(1, 0.8, 0);
593 * Width increased from 2 to 3, it simplifies line handling and spline control :P
597 // manContourView->SetWidthLine( 3 ) ;
599 manContourView->SetWidthLine( 1 ) ;
601 manContourView->SetShowText(false);
603 manContourControl->SetModelView(manContourModel, manContourView);
605 manContourControl->CreateNewManualContour();
609 connectorModel->getInicPoint(x, y, z);
612 manContourControl->SetState(1);
613 manContourModel->SetCloseContour(false);
615 manContourModel->AddPoint(x, y, z);
616 manContourView->AddPoint();
618 manContourModel->AddPoint(x, y, z);
619 manContourView->AddPoint();
621 int bak = manContourControl->GetNumberOfPointsManualContour() - 1;
622 manContourControl->_bakIdPoint = bak;
624 manContourControl->SetMoving(false);
626 connectorcontroller->setModelAndView(connectorModel, connectorView);
628 int newId = addObjectController(connectorcontroller);
630 connectorcontroller->setManualContourController(manContourControl);
631 connectorModel->setManualContourModel(manContourModel);
632 connectorView->setManualContourView(manContourView);
633 connectorView->setModel(connectorModel);
634 connectorView->setBaseView(_baseView);
636 connectorModel->addObserver(connectorView);
637 connectorModel->addObserver(this);
639 // manContourView->Refresh();
644 //=========================================================================
646 void wxVtkSceneManager::registerController(InteractorStyleMaracas *param)
648 vtkInteractorStyleBaseView * baseViewControlManager = (vtkInteractorStyleBaseView*) _baseView->GetInteractorStyleBaseView();
649 baseViewControlManager->AddInteractorStyleMaracas(param);
652 //=========================================================================
654 void wxVtkSceneManager::unregisterController(InteractorStyleMaracas *param)
656 vtkInteractorStyleBaseView *baseViewControlManager = (vtkInteractorStyleBaseView*) _baseView->GetInteractorStyleBaseView();
657 baseViewControlManager->RemoveInteractorStyleMaracas(param);
660 //=========================================================================
662 vtkRenderer* wxVtkSceneManager::getRenderer()
664 return _baseView->GetRenderer();
667 //=========================================================================
669 vtkRenderWindow* wxVtkSceneManager::getRenderWindow()
671 return _baseView->GetRenWin();
673 //=========================================================================
676 //=========================================================================
677 int wxVtkSceneManager::GetIndexInSelected(int idControler)
680 for (int i = 0; i < (int) _selectedObjects.size(); i++)
682 if (_selectedObjects[i] == idControler)
690 //=========================================================================
692 void wxVtkSceneManager::update(int idController, int command) {
694 if (command != NO_COMMAND)
696 if (command == ADD_TO_SELECTED)
698 if (GetIndexInSelected(idController) == -1)
700 _selectedObjects.push_back(idController);
702 } else if (command == REMOVE_FROM_SELECTED) {
703 int index = GetIndexInSelected(idController);
706 _selectedObjects.erase(_selectedObjects.begin() + index);
708 } else if (command == INIT_CREATION_CONTOUR) {
710 typedef std::map<int , GObjectController*>::iterator TIterator ;
713 // Find current item in the controller
714 iter = _controllers.find( idController ) ;
715 iter_end = _controllers.end( ) ;
717 if ( iter != iter_end ) {
718 GObjectController* gobjc = iter->second ;
720 std::string bbtkType = gobjc->getModel( )->getBBTKType( ) ;
721 // And if the item is a port
722 if ( gobjc->getModel( )->getGObjectType( ) == GPORT ) {
723 TIterator c_it = _controllers.begin( ) ;
724 // Go through all componets
725 for ( c_it ; c_it != iter_end ; c_it++ ) {
726 GObjectController* obc = c_it->second ;
727 int obc_type = obc->getModel( )->getGObjectType( ) ;
728 std::string obc_bbtkType = obc->getModel( )->getBBTKType( ) ;
729 // if the component is a port and the type is the same of that selected
730 if ( ( obc_type == GPORT ) && ( obc_bbtkType == bbtkType ) ) {
732 obc->getView( )->setState( POSSIBLE_CONNECTION ) ;
733 //obc->getView( )->setState( HIGHLIGHTED ) ;
741 _worldState = INIT_CREATION_CONTOUR;
742 GObjectController* cont = _controllers[idController];
743 GPortModel* startOutputPort = (GPortModel*) cont->getModel();
745 // The last one is the controller of the connector
746 std::map<int, GObjectController*>::iterator it2;
748 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
750 GObjectController *cont = it2->second;
751 if (cont->getGObjectType() == GPORT)
753 GPortModel* port = (GPortModel*) cont->getModel();
754 if (port->getPortType() == GINPUTPORT)
756 cont->SetActive(true);
758 cont->getView()->setState(NOTHING_HAPPENS);
759 cont->getModel()->notifyObservers(_idManager);
760 cont->SetActive(false);
763 cont->getView()->setState(NOTHING_HAPPENS);
764 cont->getModel()->notifyObservers(_idManager);
765 cont->SetActive(false);
768 _selectedObjects.clear();
769 _idConnectionInCreation = createGConnector(startOutputPort);
770 } else if (command == FIN_CREATION_CONTOUR && _worldState == INIT_CREATION_CONTOUR) {
771 _worldState = NOTHING_HAPPENS;
772 //int id = _controllers.size()-1;
773 GObjectController *cont = _controllers[_idConnectionInCreation];
774 GConnectorModel *modelContour = (GConnectorModel*) cont->getModel();
775 GObjectController *finPort = _controllers[idController];
777 if (finPort->getGObjectType() == GPORT)
779 GPortModel* modelPort = (GPortModel*) finPort->getModel();
780 modelContour->setEndPort(modelPort);
783 typedef std::map<int, GObjectController*>::iterator TIterator;
784 TIterator c_it = _controllers.begin();
785 TIterator iter_end = _controllers.end();
786 // Go through all componets
787 for (c_it; c_it != iter_end; c_it++) {
788 GObjectController* obc = c_it->second;
789 int obc_type = obc->getModel()->getGObjectType();
790 int obc_state = obc->getView()->getState();
791 // if the component is a port and the type is the same of that selected
792 if ((obc_type == GPORT) && (obc_state == POSSIBLE_CONNECTION)) {
793 // Return element to neutral state if not selected
794 obc->getView()->setState(NOTHING_HAPPENS);
796 if ((obc_type == GPORT) && (obc_state == SELECTED_POSSIBLE_CONNECTION)) {
797 // Change element to connected state
798 obc->getView()->setState(HIGHLIGHTED);
804 _parent->saveTempandUpdate("create connection");
807 manualConnectorContourController *manCont = ((GConnectorController*) cont)->getManualContourController();
808 manualConnectorContourView *connView = (manualConnectorContourView*) manCont->GetManualViewBaseContour();
810 std::map<int, GObjectController*>::iterator it2;
812 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
814 GObjectController *cont = it2->second;
815 if (cont->getView() != NULL) {
816 cont->getView()->setState(NOTHING_HAPPENS);
817 cont->getModel()->notifyObservers(_idManager);
819 cont->SetActive(true);
828 //=========================================================================
830 bool wxVtkSceneManager::OnMouseMove()
833 bool okStatusMessage = false;
834 bool okPortMessage = false;
835 crea::wxVTKRenderWindowInteractor *wxVTKiren;
836 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
837 wxVTKiren->GetEventPosition(X, Y);
839 if (_worldState == DRAG_OBJECTS) {
840 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
841 int id = _selectedObjects[i];
842 GObjectController* cont = _controllers[id];
843 if (_startDragging) {
844 cont->getView()->setStartDragging(true);
846 cont->getView()->moveObject(X, Y);
847 cont->getView()->setState(DRAG);
848 cont->getModel()->notifyObservers(_idManager);
851 std::map<int, GObjectController*>::iterator it;
853 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
854 GObjectController *desc = it->second;
855 if (desc->getGObjectType() == GCONNECTOR) {
856 vtkGConnectorView* vconn = (vtkGConnectorView*) desc->getView();
857 vconn->updateStartEndPoints();
861 _startDragging = false;
863 } else if (_worldState == NOTHING_HAPPENS || _worldState == INIT_CREATION_CONTOUR) {
864 std::map<int, GObjectController*>::iterator it;
866 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
867 GObjectController *desc = it->second;
868 int type = desc->getGObjectType();
869 int state = desc->getView()->getState();
870 desc->getModel()->getCenter(px, py, pz);
873 if ((state == HIGHLIGHTED) || (state == SELECTED_POSSIBLE_CONNECTION ))
876 okStatusMessage = true;
877 updateStatusBar(desc->getStatusText());
878 if (type == GBLACKBOX)
880 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
881 _parent->displayBlackBoxInfo(mod->getBBTKPackage(),mod->getBBTKType());
886 if ( ( _bugTextActor_text==desc->getStatusText() ) || (_bugTextActor_status==0) )
888 _bugTextActor_status = 1;
889 okPortMessage = true;
892 // _textActor->SetScale(0.1);
894 _textActor->SetScale(0.05,0.05,1);
896 std::string tmp = desc->getStatusText()+"\n";
897 _textActor->SetInput( tmp.c_str() );
898 // _textActor->SetPosition(px - 25, py + 1, pz + 2);
899 // _textActor->SetPosition(px , py-PORT_HEIGHT/4 , pz + 2);
900 _textActor->SetPosition(px , py-PORT_HEIGHT , pz + 2);
901 _textActor->Modified();
905 _fillObjectActor->SetScale(1);
907 // _fillObjectActor->SetScale(0.7,0.5,1);
908 _fillObjectActor->GetProperty()->SetOpacity(0.75);
909 _fillObjectActor->SetPosition( px, py + PORT_HEIGHT/2.0 , 1);
910 _aPolygonMapper->Modified();
912 _bugTextActor_status= 2;
913 } // _bugTextActor_tex
914 _bugTextActor_text = desc->getStatusText();
918 } // for controllers it
920 if (okStatusMessage == false)
925 if ((okPortMessage == false) || (_bugTextActor_status== 2 ) )
927 _bugTextActor_status = 0;
928 _textActor->SetScale(0.0001);
929 _textActor->SetInput("a\n");
930 _textActor->Modified();
931 _fillObjectActor->SetScale(0.0001);
936 //=========================================================================
938 bool wxVtkSceneManager::OnLeftButtonDown()
940 if (_worldState == INIT_CREATION_CONTOUR)
942 bool isOverPort = false;
943 std::map<int, GObjectController*>::iterator it;
944 for (it = _controllers.begin(); it != _controllers.end() && isOverPort== false; ++it)
946 GObjectController *desc = it->second;
947 if (desc->getGObjectType() == GPORT)
949 GPortModel *portmod = (GPortModel*) desc->getModel();
950 vtkGObjectView *portView = desc->getView();
951 if (portmod->getPortType() == GINPUTPORT && portView->getState() == HIGHLIGHTED)
956 if ( portmod->getPortType( ) == GINPUTPORT && portView->getState( ) == SELECTED_POSSIBLE_CONNECTION ) {
958 portView->setState( HIGHLIGHTED);
965 if (isOverPort == false)
968 UnSelectBlackBoxes();
972 } else { //_worldState
974 _worldState = DRAG_OBJECTS;
975 _startDragging = true;
977 int shiftkey = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey();
978 int ctrlkey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
979 ctrlkey = ctrlkey + shiftkey;
981 GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
984 int state = cont->getView()->getState();
985 if ((ctrlkey == 0) && (state == HIGHLIGHTED)) {
986 UnSelectBlackBoxes();
989 UnSelectBlackBoxes(); // EED 12/07/2012
991 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
992 int id = _selectedObjects[i];
993 GObjectController *cont = _controllers[id];
994 cont->getView()->setState(DRAG);
995 cont->getModel()->notifyObservers(_idManager);
997 } // if _selectedObjects.size
1003 //=========================================================================
1005 bool wxVtkSceneManager::OnLeftButtonUp()
1007 if (_worldState == DRAG_OBJECTS) {
1008 _worldState = NOTHING_HAPPENS;
1010 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
1011 int id = _selectedObjects[i];
1012 GObjectController* cont = _controllers[id];
1013 cont->getView()->setState(SELECTED);
1014 cont->getModel()->notifyObservers(_idManager);
1020 //=========================================================================
1021 void wxVtkSceneManager::CancelConnection()
1023 if (_worldState == INIT_CREATION_CONTOUR)
1025 _worldState = NOTHING_HAPPENS;
1026 //int lastId = _controllers.size()-1;
1028 GConnectorController *connector =
1029 (GConnectorController*) _controllers[_idConnectionInCreation];
1030 connector->removeFromScene();
1031 unregisterController(connector);
1032 _controllers.erase(_idConnectionInCreation);
1034 std::map<int, GObjectController*>::iterator it;
1035 for (it = _controllers.begin(); it != _controllers.end(); ++it)
1037 GObjectController *desc = it->second;
1038 desc->SetActive(true);
1039 desc->getView()->setState(NOTHING_HAPPENS);
1040 desc->getModel()->notifyObservers(_idManager);
1045 //=========================================================================
1047 bool wxVtkSceneManager::OnRightButtonUp()
1049 if (_worldState == INIT_CREATION_CONTOUR)
1053 UnSelectBlackBoxes();
1059 bool wxVtkSceneManager::OnMiddleButtonDown() {
1062 this->_vtkInteractorStyleBaseView->StartPan();
1067 bool wxVtkSceneManager::OnMiddleButtonUp() {
1070 this->_vtkInteractorStyleBaseView->EndPan();
1077 //=========================================================================
1079 GObjectController *wxVtkSceneManager::GetGBlackBoxControlerPointedByMouse() {
1080 GObjectController *result = NULL;
1082 crea::wxVTKRenderWindowInteractor *wxVTKiren;
1084 = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
1085 wxVTKiren->GetEventPosition(X, Y);
1087 std::map<int, GObjectController*>::iterator it;
1089 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1090 GObjectController *cont = it->second;
1091 int type = cont->getGObjectType();
1093 if (cont->getView()->isPointInside(X, Y) == true) {
1094 if (type == GBLACKBOX) {
1097 } // if isPointInside
1102 //=========================================================================
1103 void wxVtkSceneManager::UnSelectBlackBoxes() {
1104 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
1105 int id = _selectedObjects[i];
1106 GObjectController* control = _controllers[id];
1107 control->getView()->setState(NOTHING_HAPPENS);
1108 control->getModel()->notifyObservers(_idManager);
1109 }// for _selectedObjects
1110 _selectedObjects.clear();
1113 //=========================================================================
1114 bool wxVtkSceneManager::OnLeftDClick() {
1115 GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
1117 UnSelectBlackBoxes();
1118 _parent->editBlackBox((GBlackBoxModel*) cont->getModel());
1123 //=========================================================================
1125 bool wxVtkSceneManager::OnChar()
1129 char keyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
1130 int ctrlkey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
1132 // KeyCode 127 : Delete Key
1133 // KeyCode 8 : Backspace Key
1136 if (keyCode == 8 || keyCode == 127 || keyCode == 27)
1138 if (_worldState == INIT_CREATION_CONTOUR)
1141 UnSelectBlackBoxes();
1146 if (keyCode == 8 || keyCode == 127)
1149 for (int i = 0; i < (int) _selectedObjects.size(); i++)
1151 int id = _selectedObjects[i];
1152 std::map<int, GObjectController*>::iterator it;
1153 it = _controllers.find(id);
1154 if (it != _controllers.end())
1156 oktmp = deleteObject(id);
1159 }// for selected objects
1160 if (ok) _selectedObjects.clear();
1161 _parent->saveTempandUpdate("delete object");
1167 if(_selectedObjects.size()){
1168 std::cout<<"objects to copy :";
1169 for(int i=0;i<_selectedObjects.size();i++)
1171 std::cout<<_selectedObjects.at(i)<<" ";
1173 DuplicateObjects(getSelectedObjects());
1175 std::cout<<"No objects to copy\n";
1176 } // _selectedObjects.size
1182 //=========================================================================
1184 void wxVtkSceneManager::AddControlerToBeRemove(
1185 std::vector<int> *controllersToRemove, int id) {
1189 for (i = 0; i < (int) controllersToRemove->size(); i++) {
1190 if (id == (*controllersToRemove)[i]) {
1196 controllersToRemove->push_back(id);
1201 //=========================================================================
1203 bool wxVtkSceneManager::deleteObject(int id)
1206 GObjectController *control = _controllers[id];
1207 std::vector<int> controllersToRemove;
1208 if (control->getGObjectType() == GBLACKBOX || control->getGObjectType()
1209 == GCOMPLEXINPUTPORT || control->getGObjectType()
1210 == GCOMPLEXOUTPUTPORT) {
1211 GBoxModel *bbmod = (GBoxModel*) control->getModel();
1212 std::vector<GPortModel*> inputs = bbmod->getInputPorts();
1214 bool boxConnected = false;
1216 // Add box input controllers to be removed
1217 for (int i = 0; i < (int) inputs.size(); i++) {
1218 AddControlerToBeRemove(&controllersToRemove, inputs[i]->getObjectId());
1219 if (inputs[i]->isConnected()) {
1220 boxConnected = true;
1224 std::vector<GPortModel*> outputs = bbmod->getOutputPorts();
1226 // Add box output controllers to be removed
1227 for (int i = 0; i < (int) outputs.size(); i++) {
1228 AddControlerToBeRemove(&controllersToRemove, outputs[i]->getObjectId());
1229 if (outputs[i]->isConnected()) {
1230 boxConnected = true;
1234 // Add connection controllers to be removed
1235 std::map<int, GObjectController*>::iterator it;
1236 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1237 GObjectController *cont = it->second;
1238 int type = cont->getGObjectType();
1239 if (type == GCONNECTOR) {
1240 GConnectorModel *conMod = (GConnectorModel*) cont->getModel();
1241 if (conMod->getStartPort() != NULL && conMod->getStartPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
1243 AddControlerToBeRemove(&controllersToRemove,conMod->getObjectId());
1245 if (conMod->getEndPort() != NULL && conMod->getEndPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
1247 AddControlerToBeRemove(&controllersToRemove,conMod->getObjectId());
1252 // Add box controller to be removed
1253 AddControlerToBeRemove(&controllersToRemove, bbmod->getObjectId());
1254 } else if (control->getGObjectType() == GCONNECTOR) {
1255 GConnectorController *gconnectorcontroler = (GConnectorController*)control;
1256 if (gconnectorcontroler->getManualContourController()->IsEditable()==false)
1258 GConnectorModel *conMod = (GConnectorModel*) control->getModel();
1259 AddControlerToBeRemove(&controllersToRemove, conMod->getObjectId());
1261 gconnectorcontroler->getManualContourController()->OnChar();
1266 std::map<int, GObjectController*>::iterator it;
1268 for (int i = 0; i < (int) controllersToRemove.size(); i++) {
1269 int key = controllersToRemove[i];
1270 it = _controllers.find(key);
1271 GObjectController *cont = _controllers[key];
1273 cont->removeFromScene();
1274 unregisterController((InteractorStyleMaracas*) cont);
1275 _controllers.erase(it);
1283 //=========================================================================
1285 void wxVtkSceneManager::displayBlackBoxInfo(std::string packageName,
1286 std::string boxName) {
1287 _parent->displayBlackBoxInfo(packageName, boxName);
1290 //=========================================================================
1292 void wxVtkSceneManager::updateStatusBar(std::string textStatus) {
1293 _parent->updateStatusBar(textStatus);
1296 //=========================================================================
1297 std::string wxVtkSceneManager::LineNumber(bool withLineNumber, int &value) {
1298 std::string result = "";
1299 if (withLineNumber == true) {
1301 stringstream StrStream;
1303 std::string strValue = StrStream.str();
1306 } else if (value < 100) {
1310 result += strValue + ": ";
1314 //=========================================================================
1316 bool wxVtkSceneManager::MakeBoxExecutable() {
1317 std::map<int, GObjectController*> selected = getSelectedObjects();
1318 if( selected.empty() )
1321 std::map<int, GObjectController*>::iterator it;
1322 for (it = selected.begin(); it != selected.end(); ++it) {
1323 GObjectController* lastSelected = it->second;
1325 vtkGObjectView* view = (vtkGObjectView*) lastSelected->getView();
1326 GBlackBoxModel *bbmodel =
1327 (GBlackBoxModel*) lastSelected->getModel();
1328 view->setState(HIGHLIGHTED);
1329 if (bbmodel->isExecutable()) {
1330 bbmodel->setExecutable(false);
1332 bbmodel->setExecutable(true);
1334 bbmodel->notifyObservers(lastSelected->getId());
1342 //=========================================================================
1344 std::string wxVtkSceneManager::getDiagramBBS(bool wln) {
1345 std::cout << "wxVtkSceneManager::getDiagramBBS" << std::endl;
1346 bool existsExec = false;
1348 std::vector<std::string> packages;
1349 std::vector<int> boxes;
1350 std::vector<int> connections;
1351 std::vector<int> execBoxes;
1353 std::map<int, GObjectController*>::iterator it;
1355 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1356 GObjectController *desc = it->second;
1357 int type = desc->getGObjectType();
1359 if (type == GBLACKBOX) {
1360 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
1362 std::string pkg = mod->getBBTKPackage();
1363 bool existsPkg = false;
1364 for (int t = 0; t < (int) packages.size() && existsPkg == false; t++) {
1365 if (packages[t] == pkg) {
1370 packages.push_back(pkg);
1373 boxes.push_back(it->first);
1374 if (mod->isExecutable()) {
1375 execBoxes.push_back(it->first);
1378 } else if (type == GCONNECTOR) {
1379 connections.push_back(it->first);
1384 std::string script = "";
1385 script += LineNumber(wln, lnNmbr) + "# BBTK GEditor Script\n";
1386 script += LineNumber(wln, lnNmbr) + "# ----------------------\n";
1387 script += LineNumber(wln, lnNmbr) + "\n";
1389 script += LineNumber(wln, lnNmbr) + "include std\n"; // EED
1390 script += LineNumber(wln, lnNmbr) + "include itkvtk\n"; // EED
1392 for (i = 0; i < (int) packages.size(); i++) {
1393 script += LineNumber(wln, lnNmbr);
1394 script += "include ";
1395 script += packages[i];
1399 script += LineNumber(wln, lnNmbr);
1404 script += LineNumber(wln, lnNmbr);
1405 script += "author \"";
1409 script += LineNumber(wln, lnNmbr);
1410 script += "description \"";
1411 script += _Description;
1414 script += LineNumber(wln, lnNmbr);
1415 script += "category \"";
1416 script += _Category;
1419 script += LineNumber(wln, lnNmbr);
1422 // script+="include std\n"; // JPR
1424 for (i = 0; i < (int) boxes.size(); i++) {
1425 script += LineNumber(wln, lnNmbr);
1428 GObjectController *control = _controllers[id];
1429 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1431 script += model->getBBTKPackage()+":";
1432 script += model->getBBTKType();
1434 script += model->getBBTKName();
1437 std::vector<GPortModel*> inputs = model->getInputPorts();
1438 for (int j = 0; j < (int) inputs.size(); j++) {
1439 GPortModel* inputPort = inputs[j];
1440 if (inputPort->isValueSet()) {
1441 script += LineNumber(wln, lnNmbr);
1443 script += model->getBBTKName();
1445 script += inputPort->getBBTKName();
1447 script += inputPort->getValue();
1452 script += LineNumber(wln, lnNmbr);
1457 script += LineNumber(wln, lnNmbr);
1461 std::string complexInputs="";
1463 for (i = 0; i < (int) connections.size(); i++) {
1464 //script += LineNumber(wln, lnNmbr);
1465 //script += "connect ";
1466 int id = connections[i];
1467 GObjectController *control = _controllers[id];
1468 GConnectorModel *model = (GConnectorModel*) control->getModel();
1472 GPortModel *start = model->getStartPort();
1473 GBoxModel *startBox = start->getParentBox();
1475 GPortModel *end = model->getEndPort();
1476 GBoxModel *endBox = end->getParentBox();
1478 if (startBox->getGObjectType() == GCOMPLEXINPUTPORT)
1480 complexInputs += "input ";
1481 complexInputs += startBox->getBBTKName();
1483 complexInputs += " ";
1484 complexInputs += endBox->getBBTKName();
1485 complexInputs += ".";
1486 complexInputs += end->getBBTKName();
1488 complexInputs += " ";
1489 complexInputs += "\" \"";
1491 complexInputs += "\n";
1495 script += LineNumber(wln, lnNmbr);
1496 script += "connect ";
1497 script += startBox->getBBTKName();
1499 script += start->getBBTKName();
1503 //End Connection info
1504 script += endBox->getBBTKName();
1506 script += end->getBBTKName();
1511 script += LineNumber(wln, lnNmbr);
1515 script += LineNumber(wln, lnNmbr);
1518 script += LineNumber(wln, lnNmbr);
1521 script += LineNumber(wln, lnNmbr);
1522 script += "# Complex input ports\n";
1523 script += complexInputs;
1525 if((_MessageKind!="-")&&(_MessageLevel!="-")){
1526 script += LineNumber(wln, lnNmbr);
1527 script += "message ";
1528 script += _MessageKind;
1530 script += _MessageLevel;
1534 for (i = 0; i < (int) execBoxes.size(); i++) {
1535 script += LineNumber(wln, lnNmbr);
1537 int id = execBoxes[i];
1538 GObjectController *control = _controllers[id];
1539 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1540 script += model->getBBTKName();
1549 //=========================================================================
1551 std::string wxVtkSceneManager::saveComplexBoxBBS() {
1552 std::cout<<"wxVtkSceneManager::saveComplexBoxBBS"<<std::endl;
1553 std::vector<std::string> packages;
1554 std::vector<int> boxes;
1555 std::vector<int> connections;
1556 std::vector<int> execBoxes;
1558 std::map<int, GObjectController*>::iterator it;
1560 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1561 GObjectController *desc = it->second;
1562 int type = desc->getGObjectType();
1564 if (type == GBLACKBOX) {
1565 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
1567 std::string pkg = mod->getBBTKPackage();
1568 bool existsPkg = false;
1569 for (int t = 0; t < (int) packages.size() && existsPkg == false; t++) {
1570 if (packages[t] == pkg) {
1575 packages.push_back(pkg);
1578 boxes.push_back(it->first);
1579 if (mod->isExecutable()) {
1580 execBoxes.push_back(it->first);
1582 } else if (type == GCONNECTOR) {
1583 connections.push_back(it->first);
1587 std::string script = "";
1589 script += "include std\n"; // EED
1590 script += "include itkvtk\n"; // EED
1592 for (i = 0; i < (int) packages.size(); i++) {
1593 script += "include ";
1594 script += packages[i];
1599 // Definition of a complex box
1600 script += "define ";
1601 script += _cbName + " " + _cbPackageName;
1605 script += "author \"";
1609 script += "description \"";
1610 script += _Description;
1614 script += "category \"";
1615 script += _Category;
1620 for (i = 0; i < (int) boxes.size(); i++) {
1623 GObjectController *control = _controllers[id];
1624 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1626 script += model->getBBTKPackage()+":";
1627 script += model->getBBTKType();
1629 script += model->getBBTKName();
1632 std::vector<GPortModel*> inputs = model->getInputPorts();
1633 for (int j = 0; j < (int) inputs.size(); j++) {
1634 GPortModel* inputPort = inputs[j];
1635 if (inputPort->isValueSet()) {
1637 script += model->getBBTKName();
1639 script += inputPort->getBBTKName();
1641 script += inputPort->getValue();
1649 // Create connections in the script. If the connection is made with a complex port, it is created the input or output
1651 std::string complexInputs = "";
1652 std::string complexOutputs = "";
1655 for (i = 0; i < (int) connections.size(); i++) {
1656 int id = connections[i];
1657 GObjectController *control = _controllers[id];
1658 GConnectorModel *model = (GConnectorModel*) control->getModel();
1661 GPortModel *start = model->getStartPort();
1662 GBoxModel *startBox = start->getParentBox();
1664 GPortModel *end = model->getEndPort();
1665 GBoxModel *endBox = end->getParentBox();
1667 if (startBox->getGObjectType() == GCOMPLEXINPUTPORT) {
1668 complexInputs += "input ";
1669 complexInputs += startBox->getBBTKName();
1671 complexInputs += " ";
1672 complexInputs += endBox->getBBTKName();
1673 complexInputs += ".";
1674 complexInputs += end->getBBTKName();
1676 complexInputs += " ";
1677 complexInputs += "\" \"";
1679 complexInputs += "\n";
1680 } else if (endBox->getGObjectType() == GCOMPLEXOUTPUTPORT) {
1681 complexOutputs += "output ";
1682 complexOutputs += endBox->getBBTKName();
1684 complexOutputs += " ";
1685 complexOutputs += startBox->getBBTKName();
1686 complexOutputs += ".";
1687 complexOutputs += start->getBBTKName();
1689 complexOutputs += " ";
1690 complexOutputs += "\" \"";
1692 complexOutputs += "\n";
1694 script += "connect ";
1695 script += startBox->getBBTKName();
1697 script += start->getBBTKName();
1701 //End Connection info
1702 script += endBox->getBBTKName();
1704 script += end->getBBTKName();
1711 script += "# Complex input ports\n";
1712 script += complexInputs;
1715 script += "# Complex output ports\n";
1716 script += complexOutputs;
1720 if((_MessageKind!="-")&&(_MessageLevel!="-"))
1722 script += "message ";
1723 script += _MessageKind;
1725 script += _MessageLevel;
1729 for (i = 0; i < (int) execBoxes.size(); i++)
1732 int id = execBoxes[i];
1733 GObjectController *control = _controllers[id];
1734 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1736 script += model->getBBTKName();
1741 script += "endefine";
1747 //=========================================================================
1749 void wxVtkSceneManager::deleteAllBoxes() {
1750 std::map<int, GObjectController*>::iterator it;
1751 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1752 GObjectController *cont = it->second;
1753 cont->removeFromScene();
1754 unregisterController((InteractorStyleMaracas*) cont);
1756 _selectedObjects.clear();
1757 _controllers.clear();
1760 //=========================================================================
1763 void wxVtkSceneManager::refresh() {
1764 _baseView->Refresh();
1766 //=========================================================================
1768 void wxVtkSceneManager::refreshScene()
1770 _baseView->RefreshView();
1773 //=========================================================================
1775 void wxVtkSceneManager::centerView()
1778 _baseView->GetRenderer()->ComputeVisiblePropBounds(bb);
1781 _baseView->GetRenderer()->GetActiveCamera()->GetFocalPoint(temp);
1782 _baseView->GetRenderer()->GetActiveCamera()->SetFocalPoint(0, 0, temp[2]);
1783 _baseView->GetRenderer()->GetActiveCamera()->GetPosition(temp);
1784 _baseView->GetRenderer()->GetActiveCamera()->SetPosition(0, 0, temp[2]);
1786 _baseView->GetRenderer()->ResetCamera();
1787 _baseView->GetRenderer()->ResetCameraClippingRange();
1790 double tt=_baseView->GetRenderer()->GetNearClippingPlaneTolerance();
1791 printf("EED wxVtkSceneManager::centerView() tolerance=%f\n",tt);
1793 _baseView->GetRenderer()->GetActiveCamera()->GetClippingRange(cr1,cr2);
1794 printf("EED wxVtkSceneManager::centerView() cr1=%f cr2=%f\n",cr1,cr2);
1795 _baseView->GetRenderer()->GetActiveCamera()->SetClippingRange(0.01,100000);
1796 _baseView->GetRenderer()->GetActiveCamera()->GetClippingRange(cr1,cr2);
1797 printf("EED wxVtkSceneManager::centerView() cr1=%f cr2=%f\n",cr1,cr2);
1800 _baseView->GetRenderer()->Render();
1803 //=========================================================================
1805 void wxVtkSceneManager::saveDiagram(std::string &content)
1809 content += "CATEGORY:";
1810 content += GetCategory();
1813 content += "DESCRIPTION:";
1814 content += GetDescription();
1817 content += "AUTHOR:";
1818 content += GetAuthor();
1821 //Print info IF COMPLEX BOX
1822 content += "COMPLEXBOX:";
1823 if (_isComplexBox) {
1824 content += "TRUE\n";
1826 content += "COMPLEXBOXNAME:";
1827 content += GetCbName();
1830 content += "PACKAGENAME:";
1831 content += GetCbPackageName();
1834 /* CHANGE TO THE VERSION 1.4 RaC2012 2nd HackFest
1835 * External inputs are possible for applications and complex boxes
1836 //Print info complex input ports
1837 std::vector<int> inputs = getComplexInputPorts();
1838 int insize = inputs.size();
1839 content += "COMPLEXINPUTS:";
1840 sprintf(buffer, "%d", insize);
1844 for (int i = 0; i < insize; i++) {
1846 GObjectController *cont = _controllers[id];
1847 cont->getModel()->save(content);
1851 //Print info complex output ports
1852 std::vector<int> outputs = getComplexOutputPorts();
1853 int outsize = outputs.size();
1854 content += "COMPLEXOUTPUTS:";
1855 sprintf(buffer, "%d", outsize);
1859 for (int i = 0; i < outsize; i++) {
1860 int id = outputs[i];
1861 GObjectController *cont = _controllers[id];
1862 cont->getModel()->save(content);
1866 content += "FALSE\n";
1869 // CHANGE TO THE VERSION 1.4 RaC2012 2nd HackFest
1870 // External inputs are possible for applications and complex boxes
1871 std::vector<int> inputs = getComplexInputPorts();
1872 int insize = inputs.size();
1873 content += "COMPLEXINPUTS:";
1874 sprintf(buffer, "%d", insize);
1878 for (int i = 0; i < insize; i++) {
1880 GObjectController *cont = _controllers[id];
1881 cont->getModel()->save(content);
1885 std::vector<int> boxes = getBlackBoxes();
1886 int bsize = boxes.size();
1887 content += "BOXES:";
1888 sprintf(buffer, "%d", bsize);
1892 for (int i = 0; i < bsize; i++) {
1894 // std::cout<<"id "<<id<<std::endl;//CFT
1895 GObjectController *cont = _controllers[id];
1896 // std::cout<<"nombre: "<<cont->getStatusText()<<std::endl;//CFT
1897 // std::cout<<"tipo: "<<cont->getModel()->getBBTKType()<<std::endl;//CFT
1898 // //boxesDiagram[i] = cont->getModel()->getBBTKType();//CFT
1899 // std::cout<<"nname: "<<cont->getModel()->getBBTKName()<<std::endl;//CFT
1900 // std::cout<<"categorie: "<<GetCategory()<<std::endl;//CFT
1901 // std::cout<<"type: "<<cont->getModel()->getGObjectType()<<std::endl;//CFT
1902 cont->getModel()->save(content);
1906 std::vector<int> connections = getConnections();
1907 int csize = connections.size();
1908 content += "CONNECTIONS:";
1909 sprintf(buffer, "%d", csize);
1913 for (int i = 0; i < csize; i++) {
1914 int id = connections[i];
1915 GObjectController *cont = _controllers[id];
1916 cont->getModel()->save(content);
1921 //=========================================================================
1922 void wxVtkSceneManager::getCleanLine(stringstream &inputStream, std::string &line)
1924 getline(inputStream, line,'\n');
1925 int size = line.length();
1928 if ( line[ size-1 ]==13 )
1930 line.erase(size-1,1);
1935 //=========================================================================
1936 void wxVtkSceneManager::loadDiagram(stringstream &inputStream)
1939 std::string version = "<void>";
1940 std::string line = "";
1941 char delims[] = ":";
1942 char *result = NULL;
1943 char poort[POORT_MAX_LINE_SIZE_INTERPRETER];
1945 getCleanLine(inputStream, line);
1948 while (!inputStream.eof()) {
1949 if (line == "" || line[0] == '#') {
1951 getCleanLine(inputStream, line);
1953 if (line == "# - BBTKGEditor v 1.0 BBG BlackBox Diagram file") {
1954 version = line.substr(18, 3);
1956 if (line == "# - BBTKGEditor v 1.1 BBG BlackBox Diagram file") {
1957 version = line.substr(18, 3);
1959 if (line == "# - BBTKGEditor v 1.2 BBG BlackBox Diagram file") {
1960 version = line.substr(18, 3);
1962 if (line == "# - BBTKGEditor v 1.3 BBG BlackBox Diagram file") {
1963 version = line.substr(18, 3);
1965 if (line == "# - BBTKGEditor v 1.4 BBG BlackBox Diagram file") {
1966 version = line.substr(18, 3);
1968 if (line == "# - BBTKGEditor v 1.5 BBG BlackBox Diagram file") {
1969 version = line.substr(18, 3);
1971 } else if (line == "APP_START") {
1981 if ((version != "1.0") && (version != "1.1")) {
1982 getCleanLine(inputStream, line);//CATEGORY:<category of the box>
1983 char categoryTmp[30];
1984 strcpy(categoryTmp, line.c_str());
1985 result = strtok(categoryTmp, delims);
1986 result = strtok(NULL, delims);
1987 SetCategory(result);
1989 getCleanLine(inputStream, line);//DESCRIPTION:<description of the box>
1990 char descriptionTmp[1024];
1991 strcpy(descriptionTmp, line.c_str());
1992 result = strtok(descriptionTmp, delims);
1993 result = strtok(NULL, delims);
1994 SetDescription(result);
1996 getCleanLine(inputStream, line);//AUTHOR:<author>
1997 char authorTmp[255];
1998 strcpy(authorTmp, line.c_str());
1999 result = strtok(authorTmp, delims);
2000 result = strtok(NULL, delims);
2005 getCleanLine(inputStream, line);//COMPLEX_BOX:TRUE|FALSE
2006 char complexTmp[30];
2007 strcpy(complexTmp, line.c_str());
2008 result = strtok(complexTmp, delims);
2009 result = strtok(NULL, delims);
2010 std::string isComplexBox(result);
2012 if (isComplexBox == "TRUE")
2014 _isComplexBox = true;
2016 if ((version != "1.0") && (version != "1.1"))
2018 getCleanLine(inputStream, line);//COMPLEXNAME:<name of the complex box>
2019 char complexboxnameTmp[255];
2020 strcpy(complexboxnameTmp, line.c_str());
2021 result = strtok(complexboxnameTmp, delims);
2022 result = strtok(NULL, delims);
2025 getCleanLine(inputStream, line);//PACKAGENAME:<name of the package of the box>
2026 char packagenameTmp[255];
2027 strcpy(packagenameTmp, line.c_str());
2028 result = strtok(packagenameTmp, delims);
2029 result = strtok(NULL, delims);
2030 SetCbPackageName(result);
2031 } // if version !1.0 !1.1
2035 //-----------------------
2036 //- COMPLEX INPUT PORTS
2037 //-----------------------
2038 getCleanLine(inputStream, line);//COMPLEXINPUTS:num
2040 strcpy(inputs, line.c_str());
2041 result = strtok(inputs, delims);
2042 result = strtok(NULL, delims);
2045 std::istringstream inps(result);
2048 for (int i = 0; i < numInputs; i++)
2051 getCleanLine(inputStream, line);//COMPLEX_PORT
2052 getCleanLine(inputStream, line);//name
2053 std::string inputPortName(line);
2056 getCleanLine(inputStream, line);//xInic:yInic:zInic
2058 strcpy(coord, line.c_str());
2059 result = strtok(coord, delims);//xInic
2060 std::string xInic(result);
2061 result = strtok(NULL, delims);//yInic
2062 std::string yInic(result);
2063 result = strtok(NULL, delims);//zInic
2064 std::string zInic(result);
2066 double xIn, yIn, zIn;
2067 std::istringstream xSt(xInic);
2069 std::istringstream ySt(yInic);
2071 std::istringstream zSt(zInic);
2076 if (zIn==900) zIn=GPOSITION_Z;
2077 } // if version <=1.2
2079 getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
2081 configGComBoxInputOutputPort(true, inputPortName, xIn, yIn, zIn);
2083 } // for input complex box
2084 } // if version < 1.4
2088 //-----------------------
2089 //- COMPLEX OUTPUT PORTS
2090 //-----------------------
2092 getCleanLine(inputStream, line);//COMPLEXOUTPUTS:num
2094 strcpy(outputs, line.c_str());
2095 result = strtok(outputs, delims);
2096 result = strtok(NULL, delims);
2099 std::istringstream outps(result);
2100 outps >> numOutputs;
2102 for (int i = 0; i < numOutputs; i++)
2105 getCleanLine(inputStream, line);//COMPLEX_PORT
2106 getCleanLine(inputStream, line);//name
2107 std::string outputPortName(line);
2110 getCleanLine(inputStream, line);//xInic:yInic:zInic
2112 strcpy(coord, line.c_str());
2113 result = strtok(coord, delims);//xInic
2114 std::string xInic(result);
2115 result = strtok(NULL, delims);//yInic
2116 std::string yInic(result);
2117 result = strtok(NULL, delims);//zInic
2118 std::string zInic(result);
2120 double xIn, yIn, zIn;
2121 std::istringstream xSt(xInic);
2123 std::istringstream ySt(yInic);
2125 std::istringstream zSt(zInic);
2130 if (zIn==900) zIn=GPOSITION_Z;
2139 getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
2141 configGComBoxInputOutputPort(false, outputPortName, xIn, yIn, zIn);
2143 } // for output complex box
2144 } // if isComplexBox
2147 // RaC2012 2nd Hackfest
2148 if(version >= "1.4")
2150 //-----------------------
2151 //- EXTERNAL INPUT PORTS
2152 //-----------------------
2153 getCleanLine(inputStream, line);//COMPLEXINPUTS:num
2155 strcpy(inputs, line.c_str());
2156 result = strtok(inputs, delims);
2157 result = strtok(NULL, delims);
2160 std::istringstream inps(result);
2163 for (int i = 0; i < numInputs; i++)
2165 getCleanLine(inputStream, line);//COMPLEX_PORT
2166 getCleanLine(inputStream, line);//name
2167 std::string inputPortName(line);
2168 getCleanLine(inputStream, line);//xInic:yInic:zInic
2170 strcpy(coord, line.c_str());
2171 result = strtok(coord, delims);//xInic
2172 std::string xInic(result);
2173 result = strtok(NULL, delims);//yInic
2174 std::string yInic(result);
2175 result = strtok(NULL, delims);//zInic
2176 std::string zInic(result);
2177 double xIn, yIn, zIn;
2178 std::istringstream xSt(xInic);
2180 std::istringstream ySt(yInic);
2182 std::istringstream zSt(zInic);
2186 if (zIn==900) zIn=GPOSITION_Z;
2194 getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
2195 configGComBoxInputOutputPort(true, inputPortName, xIn, yIn, zIn);
2196 } // for external input
2197 } // if(version >= "1.4")
2200 getCleanLine(inputStream, line);//BOXES:num
2202 strcpy(boxes, line.c_str());
2203 result = strtok(boxes, delims);
2204 result = strtok(NULL, delims);
2207 std::istringstream is(result);
2210 for (int i = 0; i < numBoxes; i++)
2213 getCleanLine(inputStream, line);//BOX
2214 getCleanLine(inputStream, line);//package:type:name
2216 strcpy(box, line.c_str());
2217 result = strtok(box, delims);//package
2218 std::string package(result);
2219 result = strtok(NULL, delims);//type
2220 std::string type(result);
2221 result = strtok(NULL, delims);//name
2222 std::string name(result);
2225 getCleanLine(inputStream, line);//ISEXEC:TRUE|FALSE
2227 strcpy(exec, line.c_str());
2228 result = strtok(exec, delims);//ISEXEC
2229 result = strtok(NULL, delims);//TRUE|FALSE
2230 std::string isExec(result);
2233 getCleanLine(inputStream, line);//xInic:yInic:zInic
2235 strcpy(coord, line.c_str());
2236 result = strtok(coord, delims);//xInic
2237 std::string xInic(result);
2238 result = strtok(NULL, delims);//yInic
2239 std::string yInic(result);
2240 result = strtok(NULL, delims);//zInic
2241 std::string zInic(result);
2242 double xIn, yIn, zIn;
2243 std::istringstream xSt(xInic);
2245 std::istringstream ySt(yInic);
2247 std::istringstream zSt(zInic);
2252 if (zIn==900) zIn=GPOSITION_Z;
2261 getCleanLine(inputStream, line);//xEnd:yEnd:zEnd
2262 strcpy(coord, line.c_str());
2263 result = strtok(coord, delims);//xEnd
2264 std::string xEnd(result);
2265 result = strtok(NULL, delims);//yEnd
2266 std::string yEnd(result);
2267 result = strtok(NULL, delims);//zEnd
2268 std::string zEnd(result);
2270 double xEn, yEn, zEn;
2271 std::istringstream xEt(xEnd);
2273 std::istringstream yEt(yEnd);
2275 std::istringstream zEt(zEnd);
2280 if (zEn==900) zEn=GPOSITION_Z;
2283 yEn = yIn-BOX_HEIGHT;
2285 bool boxExecutable = false;
2286 if (isExec == "TRUE")
2288 boxExecutable = true;
2291 int idBox = createGBlackBox(xIn, yIn, package, type);
2292 configGBlackBox(idBox, xIn, yIn, zIn, name, boxExecutable, xEn, yEn, zEn);
2294 GObjectController *cont = _controllers[idBox];
2295 GBlackBoxModel *bbmod = (GBlackBoxModel*) cont->getModel();
2298 getCleanLine(inputStream, line);//PORT o FIN_BOX
2299 std::string port = line.substr(0, 4);
2300 while (port == "PORT")
2302 getCleanLine(inputStream, line);//name:value
2303 if (line.length()>=POORT_MAX_LINE_SIZE_INTERPRETER-1)
2305 line=line.substr(0, POORT_MAX_LINE_SIZE_INTERPRETER-1);
2308 strcpy(poort, line.c_str());
2309 result = strtok(poort, delims);//name
2310 std::string name(result);
2312 //EED 16 oct 2012 Adding at the end character " if necesary in the value definition
2313 result = strtok(NULL, delims);//value
2314 if (( result[0]=='"' ) && ( result[ strlen(result)-1 ]!='"' ) )
2316 std::string tmpString=" ";
2317 tmpString[0]=34; // character "
2318 strcat(result,tmpString.c_str());
2320 std::string value(result);
2321 bbmod->setValueToInput(name, value);
2322 getCleanLine(inputStream, line);//PORT o FIN_BOX
2323 port = line.substr(0, 4);
2326 //EED bbmod->notifyObservers(_idManager);
2331 getCleanLine(inputStream, line);//CONNECTIONS:num
2333 strcpy(conns, line.c_str());
2334 result = strtok(conns, delims);
2335 result = strtok(NULL, delims);
2337 std::istringstream isCons(result);
2341 for (int i = 0; i < numConns; i++)
2344 getCleanLine(inputStream, line);//CONNECTION
2345 getCleanLine(inputStream, line);//Startbox.PortName:EndBox.PortName
2347 strcpy(connec, line.c_str());
2348 result = strtok(connec, delims);
2349 std::string nameStartBox(result);
2350 result = strtok(NULL, delims);
2351 std::string nameStartPort(result);
2352 result = strtok(NULL, delims);
2353 std::string nameEndBox(result);
2354 result = strtok(NULL, delims);
2355 std::string nameEndPort(result);
2356 int idCon = configGConnetion(nameStartBox, nameStartPort,nameEndBox, nameEndPort);
2357 if (version != "1.0") {
2358 //Readding control points of the manualContour
2359 GConnectorController *tempp = (GConnectorController*) _controllers[idCon];
2360 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2361 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2362 getCleanLine(inputStream, line); //NumberOfControlPoints:##
2363 strcpy(conns, line.c_str());
2364 result = strtok(conns, delims);
2365 result = strtok(NULL, delims);
2366 int numberOfControlPoints;
2367 std::istringstream isCons(result);
2368 isCons >> numberOfControlPoints;
2369 for (int ii = 0; ii < numberOfControlPoints; ii++) {
2370 getCleanLine(inputStream, line); //XX:YY:ZZ
2372 strcpy(connec, line.c_str());
2374 result = strtok(connec, delims);
2375 std::istringstream isPointX(result);
2377 result = strtok(NULL, delims);
2378 std::istringstream isPointY(result);
2380 result = strtok(NULL, delims);
2381 std::istringstream isPointZ(result);
2385 if (pz==900) pz=GPOSITION_Z;
2393 conMod->getManualContourModel()->InsertPoint_id(ii + 1, px, py, pz);
2394 conView->getManualContourView()->AddPoint();
2396 }// if version !=1.0
2400 //=========================================================================
2403 //=========================================================================
2404 void wxVtkSceneManager::configGComBoxInputOutputPort(bool inputoutput,
2405 std::string portName, double xIn, double yIn, double zIn)
2408 if (inputoutput == true) {
2409 idPort = createGComplexBoxInputPort(portName);
2411 idPort = createGComplexBoxOutputPort(portName);
2413 GObjectController *cont = _controllers[idPort];
2414 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2415 cbmod->setInicPoint(xIn, yIn, zIn);
2416 cbmod->notifyObservers(_idManager);
2418 //=========================================================================
2421 //=========================================================================
2422 GBoxModel* wxVtkSceneManager::findGBox(std::string boxname)
2427 GBoxModel *boxModel = NULL;
2428 std::vector<int> lstB = getBlackBoxes();
2429 for (j = 0; j < (int) lstB.size(); j++) {
2431 bMod = (GBoxModel*) _controllers[idB]->getModel();
2432 if (_controllers[idB]->getModel()->getBBTKName() == boxname)
2440 if (boxModel == NULL) {
2441 std::vector<int> lstInputs = getComplexInputPorts();
2442 for (j = 0; j < (int) lstInputs.size(); j++) {
2444 bMod = (GBoxModel*) _controllers[idB]->getModel();
2445 if (_controllers[idB]->getModel()->getBBTKName() == boxname)
2453 std::vector<int> lstOutputs = getComplexOutputPorts();
2454 for (j = 0; j < (int) lstOutputs.size(); j++) {
2455 int idB = lstOutputs[j];
2456 bMod = (GBoxModel*) _controllers[idB]->getModel();
2457 if (_controllers[idB]->getModel()->getBBTKName() == boxname)
2469 //=========================================================================
2472 int wxVtkSceneManager::configGConnetion(std::string nameStartBox,
2473 std::string nameStartPort, std::string nameEndBox,
2474 std::string nameEndPort) {
2476 GBoxModel *boxModel;
2477 GPortModel *startP = NULL;
2478 GPortModel *endP = NULL;
2480 boxModel = findGBox(nameStartBox);
2481 if(boxModel == NULL)
2483 printf("RaC: ERROR in wxVtkSceneManager::configGConnetion A box to connect start port %s is null. Box name is probably wrong.\n", nameStartPort.c_str());
2485 if (boxModel != NULL) {
2486 startP = boxModel->getOutputPort(nameStartPort);
2488 printf("SCP: ERROR in wxVtkSceneManager::configGConnetion start port is null. Port name is probably wrong. Start>%s::%s End>%s::%s\n", nameStartBox.c_str(), nameStartPort.c_str(), nameEndBox.c_str(), nameEndPort.c_str() );
2492 boxModel = findGBox(nameEndBox);
2493 if(boxModel == NULL)
2495 printf("RaC: ERROR in wxVtkSceneManager::configGConnetion A box to connect start port %s is null. Box name is probably wrong.\n", nameStartPort.c_str());
2497 if (boxModel != NULL) {
2498 endP = boxModel->getInputPort(nameEndPort);
2500 printf("SCP: ERROR in wxVtkSceneManager::configGConnetion end port is null. Port name is probably wrong. Start>%s::%s End>%s::%s \n", nameStartBox.c_str(), nameStartPort.c_str(), nameEndBox.c_str(), nameEndPort.c_str());
2505 int idCon = createGConnector(startP);
2507 _worldState = NOTHING_HAPPENS;
2508 GConnectorController *tempp = (GConnectorController*) _controllers[idCon];
2510 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2511 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2512 tempp->endContourCreation();
2513 conMod->setEndPort(endP);
2514 conView->updateStartEndPoints();
2518 //=========================================================================
2520 bool wxVtkSceneManager::boxExist(std::string boxname) {
2522 std::map<int, GObjectController*>::iterator it;
2523 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2524 GObjectController *cont = it->second;
2525 if (cont->getModel()->getBBTKName() == boxname) {
2532 //=========================================================================
2534 std::vector<int> wxVtkSceneManager::getBlackBoxes() {
2535 std::vector<int> vect;
2536 std::map<int, GObjectController*>::iterator it;
2537 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2538 GObjectController *cont = it->second;
2539 if (cont->getGObjectType() == GBLACKBOX) {
2540 vect.push_back(cont->getId());
2546 //=========================================================================
2548 std::vector<int> wxVtkSceneManager::getComplexInputPorts() {
2549 std::vector<int> vect;
2550 std::map<int, GObjectController*>::iterator it;
2551 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2552 GObjectController *cont = it->second;
2553 if (cont->getGObjectType() == GCOMPLEXINPUTPORT) {
2554 vect.push_back(cont->getId());
2560 //=========================================================================
2562 std::vector<int> wxVtkSceneManager::getComplexOutputPorts() {
2563 std::vector<int> vect;
2564 std::map<int, GObjectController*>::iterator it;
2565 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2566 GObjectController *cont = it->second;
2567 if (cont->getGObjectType() == GCOMPLEXOUTPUTPORT) {
2568 vect.push_back(cont->getId());
2574 //=========================================================================
2576 std::vector<int> wxVtkSceneManager::getConnections() {
2577 std::vector<int> vect;
2578 std::map<int, GObjectController*>::iterator it;
2579 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2580 GObjectController *cont = it->second;
2581 if (cont->getGObjectType() == GCONNECTOR) {
2582 vect.push_back(cont->getId());
2588 //=========================================================================
2590 bool wxVtkSceneManager::isComplexBox() {
2591 return _isComplexBox;
2594 //=========================================================================
2596 void wxVtkSceneManager::setComplexBox(bool val) {
2597 _isComplexBox = val;
2600 //=========================================================================
2602 int wxVtkSceneManager::addObjectController(GObjectController* objController) {
2603 //Register the controller of the new object
2604 registerController((InteractorStyleMaracas*) objController);
2605 //Add the object to the objects list
2606 int newId = _contLastId;//_controllers.size();
2607 objController->setId(newId);
2608 _controllers[newId] = objController;
2609 //std::cout << "DFCH: int wxVtkSceneManager::addObjectController(GObjectController* objController) ---- _contLastId = " << _contLastId << std::endl;
2614 //=========================================================================
2616 void wxVtkSceneManager::DuplicateObjects(std::map<int, GObjectController*> objectsMap)
2618 std::map<int, int> oldIdNewIdBoxes;
2619 std::vector<int> connections;
2620 std::vector<int> newBoxesID;
2621 std::map<int, GObjectController*>::iterator it;
2622 for (it = objectsMap.begin(); it != objectsMap.end(); ++it)
2624 GObjectController *cont = it->second;
2625 int type = cont->getGObjectType();
2626 if (type == GBLACKBOX)
2629 double xInic, yInic, zInic;
2630 GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
2631 copyBox->getInicPoint(xInic, yInic, zInic);
2632 int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(), copyBox->getBBTKType());
2634 int idcB = copyBox->getObjectId();
2635 oldIdNewIdBoxes[idcB] = idBox;
2636 cont = _controllers[idBox];
2637 GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
2638 newbox->setInicPoint(xInic, yInic, zInic);
2639 int num = newbox->getNumInputPorts();
2640 for (int j = 0; j < num; j++)
2642 newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
2646 // newbox->move(xInic + 20, yInic + 20, zInic);
2647 newbox->move(xInic + 14, yInic + 6, zInic);
2649 newbox->notifyObservers(_idManager);
2650 newBoxesID.push_back(newbox->getObjectId());
2652 } else if (type == GCONNECTOR) {
2653 int idCon = cont->getId();
2654 connections.push_back(idCon);
2659 for (int i = 0; i < (int) connections.size(); i++)
2661 int objId = connections[i];
2662 GObjectController *cont = objectsMap[objId];
2663 GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
2665 GPortModel* startPort = connectModel->getStartPort();
2666 int startPortIndex = startPort->getPosInBox();
2667 GPortModel* endPort = connectModel->getEndPort();
2668 int endPortIndex = endPort->getPosInBox();
2670 GBlackBoxModel* startPortParentBox =
2671 (GBlackBoxModel*) startPort->getParentBox();
2672 GBlackBoxModel* endPortParentBox =
2673 (GBlackBoxModel*) endPort->getParentBox();
2675 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2676 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2678 GBlackBoxModel* newStartBox =
2679 (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
2680 GBlackBoxModel* newEndBox =
2681 (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
2683 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2684 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2686 // Creates connection
2687 int idCon = createGConnector(newStartPort);
2688 GConnectorController *tempp =
2689 (GConnectorController*) _controllers[idCon];
2690 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2691 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2692 tempp->endContourCreation();
2693 conMod->setEndPort(newEndPort);
2694 conView->updateStartEndPoints();
2697 /// the new selected boxes are the duplicate ones
2699 UnSelectBlackBoxes();
2700 for (int i = 0; i < newBoxesID.size(); i++)
2702 _selectedObjects.push_back(newBoxesID.at(i));
2705 for (int i = 0; i < (int) _selectedObjects.size(); i++)
2707 int id = _selectedObjects[i];
2708 GObjectController* cont = _controllers[id];
2709 cont->getView()->setState(SELECTED);
2710 cont->getModel()->notifyObservers(_idManager);
2715 //=========================================================================
2717 int wxVtkSceneManager::getNumSelectedObjects() {
2718 return _selectedObjects.size();
2721 //=========================================================================
2723 std::map<int, GObjectController*> wxVtkSceneManager::getSelectedObjects() {
2724 std::map<int, GObjectController*> mapSelected;
2726 std::map<int, GObjectController*>::iterator it;
2727 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2728 GObjectController *cont = it->second;
2729 if (cont->getGObjectType() == GBLACKBOX && cont->getView()->getState()
2731 mapSelected[cont->getId()] = cont;
2735 std::map<int, GObjectController*>::iterator it2;
2736 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2) {
2737 GObjectController *cont = it2->second;
2738 if (cont->getGObjectType() == GCONNECTOR) {
2739 GConnectorModel* cmod = (GConnectorModel*) cont->getModel();
2740 GBoxModel* endPortParentBox = cmod->getEndPort()->getParentBox();
2741 GBoxModel* startPortParentBox =
2742 cmod->getStartPort()->getParentBox();
2744 std::map<int, GObjectController*>::iterator iterOBJ1 =
2745 mapSelected.find(startPortParentBox->getObjectId());
2746 std::map<int, GObjectController*>::iterator iterOBJ2 =
2747 mapSelected.find(endPortParentBox->getObjectId());
2749 if (iterOBJ1 != mapSelected.end() && iterOBJ2 != mapSelected.end()) {
2750 int ID = cont->getId();
2751 mapSelected[ID] = cont;
2758 //=========================================================================
2760 void wxVtkSceneManager::addObjects(std::map<int, GObjectController*> objectsMap) {
2762 std::map<int, int> oldIdNewIdBoxes;
2763 std::vector<int> connections;
2765 std::map<int, GObjectController*>::iterator it;
2766 for (it = objectsMap.begin(); it != objectsMap.end(); ++it) {
2767 GObjectController *cont = it->second;
2768 int type = cont->getGObjectType();
2770 if (type == GBLACKBOX) {
2772 double xInic, yInic, zInic;
2773 GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
2774 copyBox->getInicPoint(xInic, yInic, zInic);
2775 int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(),copyBox->getBBTKType());
2777 int idcB = copyBox->getObjectId();
2778 oldIdNewIdBoxes[idcB] = idBox;
2779 cont = _controllers[idBox];
2780 GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
2781 newbox->setInicPoint(xInic, yInic, zInic);
2782 int num = newbox->getNumInputPorts();
2783 for (int j = 0; j < num; j++)
2785 newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
2787 newbox->notifyObservers(_idManager);
2788 } else if (type == GCONNECTOR) {
2789 int idCon = cont->getId();
2790 connections.push_back(idCon);
2795 for (int i = 0; i < (int) connections.size(); i++) {
2796 int objId = connections[i];
2797 GObjectController *cont = objectsMap[objId];
2798 GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
2800 GPortModel* startPort = connectModel->getStartPort();
2801 int startPortIndex = startPort->getPosInBox();
2802 GPortModel* endPort = connectModel->getEndPort();
2803 int endPortIndex = endPort->getPosInBox();
2805 GBlackBoxModel* startPortParentBox =
2806 (GBlackBoxModel*) startPort->getParentBox();
2807 GBlackBoxModel* endPortParentBox =
2808 (GBlackBoxModel*) endPort->getParentBox();
2810 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2811 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2813 GBlackBoxModel* newStartBox =
2814 (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
2815 GBlackBoxModel* newEndBox =
2816 (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
2818 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2819 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2821 // Creates connection
2822 int idCon = createGConnector(newStartPort);
2823 GConnectorController *tempp =
2824 (GConnectorController*) _controllers[idCon];
2825 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2826 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2827 tempp->endContourCreation();
2828 conMod->setEndPort(newEndPort);
2829 conView->updateStartEndPoints();
2832 std::map<int, int>::iterator itIds;
2833 for (itIds = oldIdNewIdBoxes.begin(); itIds != oldIdNewIdBoxes.end(); ++itIds) {
2834 int idOld = itIds->first;
2835 int idNew = itIds->second;
2837 GBlackBoxModel* oldBox =
2838 (GBlackBoxModel*) objectsMap[idOld]->getModel();
2839 GBlackBoxModel* newBox =
2840 (GBlackBoxModel*) _controllers[idNew]->getModel();
2842 std::vector<int> oldInputConnections = oldBox->getConnectedInputs();
2843 std::vector<int> oldOutputConnections = oldBox->getConnectedOutputs();
2844 std::vector<int> newInputConnections = newBox->getConnectedInputs();
2845 std::vector<int> newOutputConnections = newBox->getConnectedOutputs();
2847 for (int k = 0; k < (int) oldInputConnections.size(); k++) {
2849 //EED int toCreate=-1;
2850 for (int l = 0; l < (int) newInputConnections.size() && !exist; l++) {
2851 if (oldInputConnections[k] == newInputConnections[l]) {
2856 if (exist == false) {
2857 //Create complex input
2858 int posInBox = oldInputConnections[k];
2859 GPortModel* inputPort = oldBox->getInputPort(posInBox);
2860 std::string inputPortName = inputPort->getBBTKName();
2861 int idInputPort = createGComplexBoxInputPort(inputPortName);
2862 GObjectController *cont = _controllers[idInputPort];
2863 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2864 double xIn, yIn, zIn;
2865 inputPort->getInicPoint(xIn, yIn, zIn);
2867 cbmod->setInicPoint(xIn, yIn, zIn);
2868 cbmod->notifyObservers(_idManager);
2870 GPortModel* inputPortEnd = newBox->getInputPort(posInBox);
2872 // Creates connection
2873 int idCon = createGConnector(cbmod->getOutputPort(0));
2874 GConnectorController *tempp =
2875 (GConnectorController*) _controllers[idCon];
2876 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2877 vtkGConnectorView *conView =
2878 (vtkGConnectorView*) tempp->getView();
2879 tempp->endContourCreation();
2880 conMod->setEndPort(inputPortEnd);
2881 conView->updateStartEndPoints();
2887 for (int k = 0; k < (int) oldOutputConnections.size(); k++) {
2889 //EED int toCreate=-1;
2890 for (int l = 0; l < (int) newOutputConnections.size() && !exist; l++) {
2891 if (oldOutputConnections[k] == newOutputConnections[l]) {
2896 if (exist == false) {
2897 //Create complex output
2898 int posInBox = oldOutputConnections[k];
2899 GPortModel* outputPort = oldBox->getOutputPort(posInBox);
2900 std::string outputPortName = outputPort->getBBTKName();
2901 int idOutputPort = createGComplexBoxOutputPort(outputPortName);
2902 GObjectController *cont = _controllers[idOutputPort];
2903 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2904 double xIn, yIn, zIn;
2905 outputPort->getInicPoint(xIn, yIn, zIn);
2907 cbmod->setInicPoint(xIn, yIn, zIn);
2908 cbmod->notifyObservers(_idManager);
2910 GPortModel* outputPortEnd = newBox->getOutputPort(posInBox);
2912 // Creates connection
2913 int idCon = createGConnector(outputPortEnd);
2914 GConnectorController *tempp =
2915 (GConnectorController*) _controllers[idCon];
2916 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2917 vtkGConnectorView *conView =
2918 (vtkGConnectorView*) tempp->getView();
2919 tempp->endContourCreation();
2920 conMod->setEndPort(cbmod->getInputPort(0));
2921 conView->updateStartEndPoints();
2931 //=========================================================================
2932 void wxVtkSceneManager::SetCbName(std::string cbName) {
2934 if (_cbName == "") {
2935 _cbName = "<complex box name>";
2939 //=========================================================================
2940 std::string wxVtkSceneManager::GetCbName() {
2944 //=========================================================================
2945 void wxVtkSceneManager::SetCbPackageName(std::string packagename) {
2946 _cbPackageName = packagename;
2947 if (_cbPackageName == "") {
2948 _cbPackageName = "<package name of the complex box>";
2952 //=========================================================================
2953 std::string wxVtkSceneManager::GetCbPackageName() {
2954 return _cbPackageName;
2957 //=========================================================================
2958 void wxVtkSceneManager::SetAuthor(std::string author) {
2960 if (_Author == "") {
2961 _Author = "<author of the box>";
2965 //=========================================================================
2966 std::string wxVtkSceneManager::GetAuthor() {
2970 //=========================================================================
2971 void wxVtkSceneManager::SetCategory(std::string category) {
2972 _Category = category;
2973 if (_Category == "") {
2974 _Category = "<category of the box>";
2978 //=========================================================================
2979 std::string wxVtkSceneManager::GetCategory() {
2983 //=========================================================================
2984 void wxVtkSceneManager::SetDescription(std::string description) {
2985 _Description = description;
2986 if (_Description == "") {
2987 _Description = "<description of the box>";
2991 //=========================================================================
2992 std::string wxVtkSceneManager::GetDescription() {
2993 return _Description;
2996 //=========================================================================
2998 void wxVtkSceneManager::SetMessageKind(std::string kind) {
2999 _MessageKind = kind;
3003 //=========================================================================
3005 std::string wxVtkSceneManager::GetMessageKind(){
3006 return _MessageKind;
3009 //=========================================================================
3011 void wxVtkSceneManager::SetMessageLevel(std::string Level){
3012 _MessageLevel = Level;
3015 //=========================================================================
3017 std::string wxVtkSceneManager::GetMessageLevel(){
3018 return _MessageLevel;
3021 //=========================================================================
3023 std::vector< std::string> wxVtkSceneManager::GetExternalInputsNames()
3026 std::vector< std::string> extInputs;
3027 std::map<int, GObjectController*>::iterator it;
3028 for (it = _controllers.begin(); it != _controllers.end(); ++it)
3030 GObjectController *cont = it->second;
3031 if (cont->getGObjectType() == GCOMPLEXINPUTPORT)
3033 extInputs.push_back(cont->getModel()->getBBTKName());
3039 //=========================================================================
3043 void wxVtkSceneManager::printAll(int com , int sta ){
3045 int tmpState = sta ;
3046 if ( tmpState == NOTHING_HAPPENS ) {
3047 std::cout << "CONTROLER STATE---->NOTHING_HAPPENS\n" ;
3049 if ( tmpState == HIGHLIGHTED ) {
3050 std::cout << "CONTROLER STATE---->HIGHLIGHTED\n" ;
3052 if ( tmpState == POSSIBLE_CONNECTION ) {
3053 std::cout << "CONTROLER STATE---->POSSIBLE_CONNECTION\n" ;
3055 if ( tmpState == SELECTED_POSSIBLE_CONNECTION ) {
3056 std::cout << "CONTROLER STATE---->SELECTED_POSSIBLE_CONNECTION\n" ;
3058 if ( tmpState == CLICKED ) {
3059 std::cout << "CONTROLER STATE---->CLICKED\n" ;
3061 if ( tmpState == DRAG ) {
3062 std::cout << "CONTROLER STATE---->DRAG\n" ;
3064 if ( tmpState == SELECTED ) {
3065 std::cout << "CONTROLER STATE---->SELECTED\n" ;
3067 if ( tmpState == CREATING_CONTOUR ) {
3068 std::cout << "CONTROLER STATE---->CREATING_CONTOUR\n" ;
3074 if ( command == INIT_CREATION_CONTOUR ) {
3075 std::cout << "COMMAND ----> INIT_CREATION_CONTOUR \n" ;
3077 if ( command == FIN_CREATION_CONTOUR ) {
3078 std::cout << "COMMAND ----> FIN_CREATION_CONTOUR \n" ;
3080 if ( command == ADD_TO_SELECTED ) {
3081 std::cout << "COMMAND ----> ADD_TO_SELECTED \n" ;
3083 if ( command == DRAG_OBJECTS ) {
3084 std::cout << "COMMAND ----> DRAG_OBJECTS \n" ;
3086 if ( command == EDIT_BLACKBOX ) {
3087 std::cout << "COMMAND ----> EDIT_BLACKBOX \n" ;
3089 if ( command == REMOVE_FROM_SELECTED ) {
3090 std::cout << "COMMAND ----> REMOVE_FROM_SELECTED \n" ;
3096 } // EO namespace bbtk