1 /*=========================================================================
7 =========================================================================*/
9 /* ---------------------------------------------------------------------
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
14 * This software is governed by the CeCILL-B license under French law and
15 * abiding by the rules of distribution of free software. You can use,
16 * modify and/ or redistribute the software under the terms of the CeCILL-B
17 * license as circulated by CEA, CNRS and INRIA at the following URL
18 * http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
19 * or in the file LICENSE.txt.
21 * As a counterpart to the access to the source code and rights to copy,
22 * modify and redistribute granted by the license, users are provided only
23 * with a limited warranty and the software's author, the holder of the
24 * economic rights, and the successive licensors have only limited
27 * The fact that you are presently reading this means that you have had
28 * knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */
33 * \brief Class bbtk::wxVtkSceneManager .
37 #include "wxVtkSceneManager.h"
43 //=========================================================================
44 wxVtkSceneManager::wxVtkSceneManager(wxGEditorTabPanel *parent, wxVtk3DBaseView *baseView,int idManager)
46 printf ("EED %p wxVtkSceneManager()\n" , this );
57 printf ("RaC-EED 21-06-2010 %p wxVtkSceneManager::wxVtkSceneManager If you comment this line, the drag and drop functionnality is not initialized.\n" , this );
58 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget((wxDropTarget*)parent);
61 _worldState=NOTHING_HAPPENS;
62 registerController(this);
65 _idConnectionInCreation=-1;
70 //=========================================================================
72 void wxVtkSceneManager::disconnectDrop()
74 printf ("EED %p ~wxVtkSceneManager::disconnectDrop()\n" , this );
75 //EED02JUIN2010 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget(NULL);
76 // _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget( new tmpClasswxTextDropTarget() );
79 //=========================================================================
81 wxVtkSceneManager::~wxVtkSceneManager()
83 printf ("EED %p ~wxVtkSceneManager()\n" , this );
87 //=========================================================================
89 void wxVtkSceneManager::configureBaseView()
91 vtkInteractorStyleBaseView2D *interactorstylebaseview = vtkInteractorStyleBaseView2D::New();
93 _baseView->SetInteractorStyleBaseView(interactorstylebaseview);
95 // Important to activate the 2D interaction system
96 wxVTKRenderWindowInteractor *iren = _baseView->GetWxVTKRenderWindowInteractor();
97 interactorstylebaseview->SetInteractor ( iren );
98 iren->SetInteractorStyle(interactorstylebaseview);
99 interactorstylebaseview->SetwxVtkBaseView(_baseView);
101 _baseView->GetRenderer()->GetActiveCamera()->ParallelProjectionOn();
102 _baseView->GetRenderer()->ResetCamera(-100,100,-100,100,900,1000);
104 _baseView->GetRenderer()->SetBackground(0.9,0.9,0.9);
105 _baseView->GetRenderer()->GradientBackgroundOff();
106 _baseView->Refresh();
109 //=========================================================================
111 int wxVtkSceneManager::createGBlackBox(int x, int y, std::string packageName, std::string boxType)
113 printf("EED %p wxVtkSceneManager::createGBlackBox 1\n",this);
115 _worldState = NOTHING_HAPPENS;
116 printf("EED %p wxVtkSceneManager::createGBlackBox 1.1\n",this);
117 int windowWidth=_baseView->GetRenWin()->GetSize()[0];
118 printf("EED %p wxVtkSceneManager::createGBlackBox 1.2\n",this);
119 int windowHeight=_baseView->GetRenWin()->GetSize()[1];
120 printf("EED %p wxVtkSceneManager::createGBlackBox 1.3\n",this);
122 int type = GBLACKBOX;
124 //Create the MVC Objects
126 GBlackBoxModel *model = (GBlackBoxModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
127 printf("EED %p wxVtkSceneManager::createGBlackBox 1.4\n",this);
128 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
129 printf("EED %p wxVtkSceneManager::createGBlackBox 1.5\n",this);
130 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
131 printf("EED %p wxVtkSceneManager::createGBlackBox 1.6 >%s< >%s<\n",this, packageName.c_str(), boxType.c_str() );
133 BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxType);
135 //Prepares the initial model
136 //The coordinates obtained are the following. Top-Left:x=0,y=0 Bottom-Right:x=width,y=height
138 printf("EED %p wxVtkSceneManager::createGBlackBox 2\n",this);
140 double yy = windowHeight-y;
142 //z value is not important yet, because it is only used a parallel projection
145 _baseView->TransCoordScreenToWorld(xx,yy,zz);
146 model->setInicPoint(xx,yy,zz);
149 std::stringstream stream;
151 printf("EED %p wxVtkSceneManager::createGBlackBox 3\n",this);
154 stream << "Box0" << _numBoxes;
158 stream << "Box" << _numBoxes;
160 std::string arraystring = stream.str();
162 model->setBBTKName(arraystring);
163 model->setBBTKType(boxType);
164 model->setBBTKPackage(packageName);
166 model->addObserver(view);
167 model->addObserver(this);
169 //Iterate and create the input ports
170 std::map<std::string, BlackBoxInputDescriptor*> descriptorInMap = descriptor->GetInputDescriptorMap();
171 std::map<std::string, BlackBoxInputDescriptor*>::iterator itInput;
174 for(itInput = descriptorInMap.begin(); itInput != descriptorInMap.end(); ++itInput)
176 BlackBoxInputDescriptor *desc = itInput->second;
177 createGInputPort(GINPUTPORT,i,model,desc);
181 printf("EED %p wxVtkSceneManager::createGBlackBox 4\n",this);
182 //Iterate and create the output ports
183 std::map<std::string, BlackBoxOutputDescriptor*> descriptorOutMap = descriptor->GetOutputDescriptorMap();
184 std::map<std::string, BlackBoxOutputDescriptor*>::iterator itOutput;
187 for(itOutput = descriptorOutMap.begin();itOutput != descriptorOutMap.end(); ++itOutput)
189 BlackBoxOutputDescriptor *desc = itOutput->second;
190 createGOutputPort(GOUTPUTPORT,i,model,desc);
195 //Associates the view with the correspondent renderer and the model.
196 //(NOTE: Refresh is only made by the view)
197 view->setModel(model);
198 view->setBaseView(_baseView);
199 view->initVtkObjects();
200 printf("EED %p wxVtkSceneManager::createGBlackBox 5\n",this);
202 //Associates the controller with the correspondent model and view
203 controller->setModelAndView(model,view);
205 //Resgiter change to the observers of the actual model
206 model->notifyObservers(_idManager);
208 int newId = addObjectController(controller);
209 printf("EED %p wxVtkSceneManager::createGBlackBox 6\n",this);
214 //=========================================================================
216 int wxVtkSceneManager::createGComplexBoxInputPort(std::string inputName)
218 int windowWidth=_baseView->GetRenWin()->GetSize()[0];
219 int windowHeight=_baseView->GetRenWin()->GetSize()[1];
221 int type = GCOMPLEXINPUTPORT;
223 //Create the MVC Objects
225 GComplexBoxPortModel *model = (GComplexBoxPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
226 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
227 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
229 //Prepares the initial model
232 double yy = windowHeight-5;
234 //z value is not important yet, because it is only used a parallel projection
237 _baseView->TransCoordScreenToWorld(xx,yy,zz);
238 model->setInicPoint(xx,yy,zz);
240 model->setBBTKName(inputName);
241 model->setBBTKType("ComplexInputPort");
242 model->setComplexPortType(type);
244 model->addObserver(view);
245 model->addObserver(this);
247 //create the output port
248 GPortController* portController = createGPort(GOUTPUTPORT,inputName,"ComplexInputPort",0,model);
249 model->addOutputPort((GPortModel*)portController->getModel());
251 //Associates the view with the correspondent renderer and the model.
252 //(NOTE: Refresh is only made by the view)
253 view->setModel(model);
254 view->setBaseView(_baseView);
255 view->initVtkObjects();
257 //Associates the controller with the correspondent model and view
258 controller->setModelAndView(model,view);
260 //Resgiter change to the observers of the actual model
261 model->notifyObservers(_idManager);
263 int newId = addObjectController(controller);
267 //=========================================================================
269 int wxVtkSceneManager::createGComplexBoxOutputPort(std::string outputName)
271 int windowWidth=_baseView->GetRenWin()->GetSize()[0];
272 int windowHeight=_baseView->GetRenWin()->GetSize()[1];
274 int type = GCOMPLEXOUTPUTPORT;
276 //Create the MVC Objects
278 GComplexBoxPortModel *model = (GComplexBoxPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
279 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
280 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
282 //Prepares the initial model
285 double yy = windowHeight-5;
287 //z value is not important yet, because it is only used a parallel projection
290 _baseView->TransCoordScreenToWorld(xx,yy,zz);
291 model->setInicPoint(xx,yy,zz);
293 model->setBBTKName(outputName);
294 model->setBBTKType("ComplexOutputPort");
295 model->setComplexPortType(type);
297 model->addObserver(view);
298 model->addObserver(this);
300 //create the output port
301 GPortController* portController = createGPort(GINPUTPORT,outputName,"ComplexInputPort",0,model);
302 model->addInputPort((GPortModel*)portController->getModel());
304 //Associates the view with the correspondent renderer and the model.
305 //(NOTE: Refresh is only made by the view)
306 view->setModel(model);
307 view->setBaseView(_baseView);
308 view->initVtkObjects();
310 //Associates the controller with the correspondent model and view
311 controller->setModelAndView(model,view);
313 //Resgiter change to the observers of the actual model
314 model->notifyObservers(_idManager);
316 int newId = addObjectController(controller);
320 //=========================================================================
322 int wxVtkSceneManager::createGInputPort(int portType, int posinBox,GBoxModel *blackBox, BlackBoxInputDescriptor *desc)
324 GPortController* portController = createGPort(portType,desc->GetName(),desc->GetTypeName(),posinBox,blackBox);
325 blackBox->addInputPort((GPortModel*)portController->getModel());
326 return portController->getId();
329 //=========================================================================
331 int wxVtkSceneManager::createGOutputPort(int portType, int posinBox,GBoxModel *blackBox, BlackBoxOutputDescriptor *desc)
333 GPortController* portController = createGPort(portType,desc->GetName(),desc->GetTypeName(),posinBox,blackBox);
334 blackBox->addOutputPort((GPortModel*)portController->getModel());
335 return portController->getId();
338 //=========================================================================
340 GPortController* wxVtkSceneManager::createGPort(int portType,std::string bbtkName, std::string bbtkType, int posInBox,GBoxModel *blackBox)
344 //Create the MVC Objects
345 GPortModel *model = (GPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
346 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
347 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
349 model->registerInBox(blackBox,portType, posInBox);
351 model->setBBTKType(bbtkType);
352 model->setBBTKName(bbtkName);
354 model->addObserver(view);
355 model->addObserver(this);
357 //Associates the view with the correspondent renderer and the model.
358 //(NOTE: Refresh is only made by the view)
359 view->setModel(model);
360 view->setBaseView(_baseView);
361 view->initVtkObjects();
363 //Associates the controller with the correspondent model and view
364 controller->setModelAndView(model,view);
366 model->notifyObservers(_idManager);
368 int newId = addObjectController(controller);
370 return (GPortController*)controller;
373 //=========================================================================
375 int wxVtkSceneManager::createGConnector(GPortModel* startPort)
377 int type = GCONNECTOR;
379 manualConnectorContourController* manContourControl = new manualConnectorContourController();
380 manualConnectorContourView* manContourView = new manualConnectorContourView();
381 manualContourModel* manContourModel = new manualContourModel();
383 GConnectorController* connectorcontroller = new GConnectorController();
384 GConnectorModel* connectorModel = new GConnectorModel();
385 vtkGConnectorView* connectorView = new vtkGConnectorView();
386 connectorModel->setGObjectType(type);
388 manContourModel->SetCloseContour(false);
389 connectorModel->setStartPort(startPort);
391 manContourView->SetModel( manContourModel );
392 manContourView->SetWxVtkBaseView( _baseView );
393 manContourView->SetRange( 0.5 );
394 manContourView->SetZ( 900 );
396 manContourView->SetColorNormalContour(0, 0, 1);
397 manContourView->SetColorEditContour(0.5, 0.5, 0.5);
398 manContourView->SetColorSelectContour(1, 0.8, 0);
399 manContourView->SetWidthLine(1);
400 manContourView->SetShowText(false);
402 manContourControl->SetModelView( manContourModel , manContourView );
404 manContourControl->CreateNewManualContour();
406 manContourView->RefreshContour();
410 connectorModel->getInicPoint(x,y,z);
412 manContourControl->SetState(1);
413 manContourModel->SetCloseContour(false);
415 manContourModel->AddPoint(x,y,z);
416 manContourView->AddPoint();
418 manContourModel->AddPoint(x,y,z);
419 manContourView->AddPoint();
421 int bak= manContourControl->GetNumberOfPointsManualContour() - 1;
422 manContourControl->_bakIdPoint=bak;
423 manContourView->Refresh();
425 manContourControl->SetMoving( false );
427 connectorcontroller->setModelAndView(connectorModel,connectorView);
429 int newId = addObjectController(connectorcontroller);
431 connectorcontroller->setManualContourController(manContourControl);
432 connectorModel->setManualContourModel(manContourModel);
433 connectorView->setManualContourView(manContourView);
434 connectorView->setModel(connectorModel);
435 connectorView->setBaseView(_baseView);
438 connectorModel->addObserver(connectorView);
439 connectorModel->addObserver(this);
444 //=========================================================================
446 void wxVtkSceneManager::registerController(InteractorStyleMaracas *param)
448 vtkInteractorStyleBaseView* baseViewControlManager = (vtkInteractorStyleBaseView*)_baseView->GetInteractorStyleBaseView();
449 baseViewControlManager->AddInteractorStyleMaracas( param );
452 //=========================================================================
454 void wxVtkSceneManager::unregisterController(InteractorStyleMaracas *param)
456 vtkInteractorStyleBaseView* baseViewControlManager = (vtkInteractorStyleBaseView*)_baseView->GetInteractorStyleBaseView();
457 baseViewControlManager->RemoveInteractorStyleMaracas( param );
460 //=========================================================================
462 vtkRenderer* wxVtkSceneManager::getRenderer()
464 return _baseView->GetRenderer();
467 //=========================================================================
469 vtkRenderWindow* wxVtkSceneManager::getRenderWindow()
471 return _baseView->GetRenWin();
473 //=========================================================================
476 void wxVtkSceneManager::update(int idController,int command)
478 if(command != NO_COMMAND)
480 if(command == ADD_TO_SELECTED)
482 GObjectController* cont = _controllers[idController];
485 for (int i=0; i<_selectedObjects.size() && foundID==false; i++)
487 int id = _selectedObjects[i];
495 int id = idController;
496 _selectedObjects.push_back(id);
500 else if(command == INIT_CREATION_CONTOUR)
502 _worldState = INIT_CREATION_CONTOUR;
503 GObjectController* cont = _controllers[idController];
504 GPortModel* startOutputPort = (GPortModel*)cont->getModel();
507 // The last one is the controller of the connector
508 std::map<int, GObjectController*>::iterator it2;
510 for(it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
512 GObjectController *cont = it2->second;
513 if(cont->getGObjectType() == GPORT )
515 GPortModel* port = (GPortModel*)cont->getModel();
516 if(port->getPortType()==GINPUTPORT)
518 cont->SetActive(true);
522 cont->getView()->setState(NOTHING_HAPPENS);
523 cont->getModel()->notifyObservers(_idManager);
524 cont->SetActive(false);
529 cont->getView()->setState(NOTHING_HAPPENS);
530 cont->getModel()->notifyObservers(_idManager);
531 cont->SetActive(false);
535 _selectedObjects.clear();
537 _idConnectionInCreation=createGConnector(startOutputPort);
540 else if(command == FIN_CREATION_CONTOUR && _worldState == INIT_CREATION_CONTOUR)
542 _worldState = NOTHING_HAPPENS;
543 //int id = _controllers.size()-1;
544 GObjectController* cont = _controllers[_idConnectionInCreation];
545 GConnectorModel* modelContour = (GConnectorModel*)cont->getModel();
547 GObjectController* finPort = _controllers[idController];
548 if(finPort->getGObjectType() == GPORT)
550 GPortModel* modelPort = (GPortModel*)finPort->getModel();
551 modelContour->setEndPort(modelPort);
554 manualConnectorContourController* manCont = ((GConnectorController*)cont)->getManualContourController();
555 manualConnectorContourView* connView = (manualConnectorContourView*)manCont->GetManualViewBaseContour();
558 std::map<int, GObjectController*>::iterator it2;
560 for(it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
562 GObjectController *cont = it2->second;
563 if(cont->getView()!=NULL)
565 cont->getView()->setState(NOTHING_HAPPENS);
566 cont->getModel()->notifyObservers(_idManager);
568 cont->SetActive(true);
575 //=========================================================================
577 bool wxVtkSceneManager::OnMouseMove()
580 wxVTKRenderWindowInteractor *wxVTKiren;
581 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
582 wxVTKiren->GetEventPosition(X,Y);
585 if(_worldState == DRAG_OBJECTS)
587 for (int i=0; i<_selectedObjects.size(); i++)
589 int id = _selectedObjects[i];
590 GObjectController* cont = _controllers[id];
593 cont->getView()->setStartDragging(true);
595 cont->getView()->moveObject(X,Y);
596 cont->getView()->setState(DRAG);
597 cont->getModel()->notifyObservers(_idManager);
600 std::map<int, GObjectController*>::iterator it;
602 for(it = _controllers.begin(); it != _controllers.end(); ++it)
604 GObjectController *desc = it->second;
605 if(desc->getGObjectType()==GCONNECTOR)
607 vtkGConnectorView* vconn = (vtkGConnectorView*)desc->getView();
608 vconn->updateStartEndPoints();
612 _startDragging=false;
615 else if(_worldState == NOTHING_HAPPENS || _worldState == INIT_CREATION_CONTOUR)
617 std::map<int, GObjectController*>::iterator it;
619 for(it = _controllers.begin(); it != _controllers.end(); ++it)
621 GObjectController *desc = it->second;
622 int type = desc->getGObjectType();
623 int state = desc->getView()->getState();
625 if(state == HIGHLIGHTED){
627 updateStatusBar(desc->getStatusText());
630 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
631 _parent->displayBlackBoxInfo(mod->getBBTKPackage(),mod->getBBTKType());
640 //=========================================================================
642 bool wxVtkSceneManager::OnLeftButtonDown()
644 if(_worldState==INIT_CREATION_CONTOUR)
646 bool isOverPort=false;
647 std::map<int, GObjectController*>::iterator it;
648 for(it = _controllers.begin(); it != _controllers.end() && isOverPort==false; ++it)
650 GObjectController *desc = it->second;
651 if(desc->getGObjectType()==GPORT)
653 GPortModel* portmod=(GPortModel*)desc->getModel();
654 vtkGObjectView* portView=desc->getView();
655 if(portmod->getPortType()==GINPUTPORT && portView->getState()==HIGHLIGHTED)
662 if(isOverPort==false)
664 _worldState=NOTHING_HAPPENS;
665 //int lastId = _controllers.size()-1;
666 GConnectorController *connector = (GConnectorController*)_controllers[_controllers.size()-1];
667 connector->removeFromScene();
668 unregisterController(connector);
669 _controllers.erase(_controllers.size()-1);
671 for(it = _controllers.begin(); it != _controllers.end(); ++it)
673 GObjectController *desc = it->second;
674 desc->SetActive(true);
675 desc->getView()->setState(NOTHING_HAPPENS);
676 desc->getModel()->notifyObservers(_idManager);
681 if(_selectedObjects.size()!=0)
683 _worldState = DRAG_OBJECTS;
684 _startDragging = true;
686 for (int i = 0; i < _selectedObjects.size(); i++)
688 int id = _selectedObjects[i];
689 GObjectController* cont = _controllers[id];
690 cont->getView()->setState(DRAG);
691 cont->getModel()->notifyObservers(_idManager);
700 //=========================================================================
702 bool wxVtkSceneManager::OnLeftButtonUp()
704 if(_worldState == DRAG_OBJECTS)
706 _worldState = NOTHING_HAPPENS;
708 for (int i = 0; i < _selectedObjects.size(); i++)
710 int id = _selectedObjects[i];
711 GObjectController* cont = _controllers[id];
712 cont->getView()->setState(SELECTED);
713 cont->getModel()->notifyObservers(_idManager);
719 //=========================================================================
721 bool wxVtkSceneManager::OnRightButtonUp()
723 if(_worldState==INIT_CREATION_CONTOUR)
725 _worldState=NOTHING_HAPPENS;
726 //int lastId = _controllers.size()-1;
727 GConnectorController *connector = (GConnectorController*)_controllers[_idConnectionInCreation];
728 connector->removeFromScene();
729 unregisterController(connector);
730 _controllers.erase(_idConnectionInCreation);
732 std::map<int, GObjectController*>::iterator it;
733 for(it = _controllers.begin(); it != _controllers.end(); ++it)
735 GObjectController *desc = it->second;
736 desc->SetActive(true);
737 desc->getView()->setState(NOTHING_HAPPENS);
738 desc->getModel()->notifyObservers(_idManager);
743 for (int i = 0; i < _selectedObjects.size(); i++)
745 int id = _selectedObjects[i];
746 GObjectController* cont = _controllers[id];
747 cont->SetActive(true);
748 cont->getView()->setState(NOTHING_HAPPENS);
749 cont->getModel()->notifyObservers(_idManager);
752 _selectedObjects.clear();
757 //=========================================================================
759 bool wxVtkSceneManager::OnLeftDClick()
762 wxVTKRenderWindowInteractor *wxVTKiren;
763 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
764 wxVTKiren->GetEventPosition(X,Y);
766 std::map<int, GObjectController*>::iterator it;
768 bool clickOnObject = false;
770 for(it = _controllers.begin(); it != _controllers.end() && clickOnObject==false; ++it)
772 GObjectController *cont = it->second;
773 int type = cont->getGObjectType();
775 if(cont->getView()->isPointInside(X,Y))
779 for (int i=0; i<_selectedObjects.size(); i++)
781 int id = _selectedObjects[i];
782 GObjectController* control = _controllers[id];
783 control->getView()->setState(NOTHING_HAPPENS);
785 _selectedObjects.clear();
787 GBlackBoxModel *bbmodel = (GBlackBoxModel*)cont->getModel();
788 _parent->editBlackBox(bbmodel);
790 clickOnObject = true;
794 if(clickOnObject==false)
796 //_parent->editDiagramParameters(this);
802 //=========================================================================
804 bool wxVtkSceneManager::OnChar()
806 char keyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
808 // KeyCode 127 : Delete Key
809 // KeyCode 8 : Backspace Key
810 if(keyCode == 8 || keyCode == 127)
812 if(_selectedObjects.size()>0)
814 for(int i=0;i<_selectedObjects.size();i++)
816 int id = _selectedObjects[i];
819 _selectedObjects.clear();
826 //=========================================================================
828 void wxVtkSceneManager::deleteObject(int id)
830 GObjectController *control = _controllers[id];
831 std::vector<int> controllersToRemove;
833 if(control->getGObjectType()==GBLACKBOX || control->getGObjectType()==GCOMPLEXINPUTPORT || control->getGObjectType()==GCOMPLEXOUTPUTPORT)
835 GBoxModel *bbmod = (GBoxModel*)control->getModel();
836 std::vector<GPortModel*> inputs = bbmod->getInputPorts();
838 bool boxConnected = false;
840 // Add box input controllers to be removed
841 for(int i = 0;i<inputs.size();i++)
843 controllersToRemove.push_back(inputs[i]->getObjectId());
844 if(inputs[i]->isConnected())
850 std::vector<GPortModel*> outputs = bbmod->getOutputPorts();
852 // Add box output controllers to be removed
853 for(int i = 0;i<outputs.size();i++)
855 controllersToRemove.push_back(outputs[i]->getObjectId());
856 if(outputs[i]->isConnected())
862 // Add connection controllers to be removed
863 std::map<int, GObjectController*>::iterator it;
864 for(it = _controllers.begin(); it != _controllers.end(); ++it)
866 GObjectController *cont = it->second;
867 int type = cont->getGObjectType();
870 GConnectorModel *conMod = (GConnectorModel*)cont->getModel();
871 if(conMod->getStartPort()!=NULL && conMod->getStartPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
873 controllersToRemove.push_back(conMod->getObjectId());
875 if(conMod->getEndPort()!=NULL && conMod->getEndPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
877 controllersToRemove.push_back(conMod->getObjectId());
882 // Add box controller to be removed
883 controllersToRemove.push_back(bbmod->getObjectId());
885 else if(control->getGObjectType()==GCONNECTOR)
887 GConnectorModel *conMod = (GConnectorModel*)control->getModel();
888 controllersToRemove.push_back(conMod->getObjectId());
891 for(int i = 0;i<controllersToRemove.size();i++)
893 int id = controllersToRemove[i];
894 GObjectController *cont = _controllers[id];
897 cont->removeFromScene();
898 unregisterController((InteractorStyleMaracas*)cont);
899 _controllers.erase(id);
906 //=========================================================================
908 void wxVtkSceneManager::displayBlackBoxInfo(std::string packageName, std::string boxName)
910 _parent->displayBlackBoxInfo(packageName,boxName);
913 //=========================================================================
915 void wxVtkSceneManager::updateStatusBar(std::string textStatus)
917 _parent->updateStatusBar(textStatus);
920 //=========================================================================
922 std::string wxVtkSceneManager::getDiagramBBS()
924 bool existsExec=false;
926 std::vector<std::string> packages;
927 std::vector<int> boxes;
928 std::vector<int> connections;
929 std::vector<int> execBoxes;
931 std::map<int, GObjectController*>::iterator it;
933 for(it = _controllers.begin(); it != _controllers.end(); ++it)
935 GObjectController *desc = it->second;
936 int type = desc->getGObjectType();
940 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
942 std::string pkg = mod->getBBTKPackage();
943 bool existsPkg = false;
944 for(int t = 0;t<packages.size() && existsPkg == false;t++)
953 packages.push_back(pkg);
957 boxes.push_back(it->first);
958 if(mod->isExecutable())
960 execBoxes.push_back(it->first);
964 else if(type==GCONNECTOR)
966 connections.push_back(it->first);
970 std::string script = "";
971 script+="# BBTK GEditor Script\n";
972 script+="# ----------------------\n";
975 script+="include std\n"; // EED
976 script+="include itkvtk\n"; // EED
978 for(i = 0; i<packages.size();i++)
985 // script+="include std\n"; // JPR
987 for(i = 0; i<boxes.size();i++)
991 GObjectController *control = _controllers[id];
992 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
994 script+=model->getBBTKType();
996 script+=model->getBBTKName();
999 std::vector<GPortModel*> inputs = model->getInputPorts();
1000 for(int j = 0; j<inputs.size();j++)
1002 GPortModel* inputPort = inputs[j];
1003 if(inputPort->isValueSet())
1006 script+=model->getBBTKName();
1008 script+=inputPort->getBBTKName();
1010 script+=inputPort->getValue();
1017 for(i = 0; i<connections.size();i++)
1020 int id = connections[i];
1021 GObjectController *control = _controllers[id];
1022 GConnectorModel *model = (GConnectorModel*)control->getModel();
1024 //Start Connection info
1025 GPortModel *start = model->getStartPort();
1026 script+=start->getParentBox()->getBBTKName();
1028 script+=start->getBBTKName();
1032 //End Connection info
1033 GPortModel *end = model->getEndPort();
1034 script+=end->getParentBox()->getBBTKName();
1036 script+=end->getBBTKName();
1041 for(i = 0; i<execBoxes.size();i++)
1044 int id = execBoxes[i];
1045 GObjectController *control = _controllers[id];
1046 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1048 script+=model->getBBTKName();
1057 //=========================================================================
1059 std::string wxVtkSceneManager::saveComplexBoxBBS(std::string cbName,std::string cbAuthor,std::string cbCategory,std::string cbDescription)
1062 std::vector<std::string> packages;
1063 std::vector<int> boxes;
1064 std::vector<int> connections;
1065 std::vector<int> execBoxes;
1067 std::map<int, GObjectController*>::iterator it;
1069 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1071 GObjectController *desc = it->second;
1072 int type = desc->getGObjectType();
1076 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
1078 std::string pkg = mod->getBBTKPackage();
1079 bool existsPkg = false;
1080 for(int t = 0;t<packages.size() && existsPkg == false;t++)
1082 if(packages[t]==pkg)
1089 packages.push_back(pkg);
1093 boxes.push_back(it->first);
1094 if(mod->isExecutable())
1096 execBoxes.push_back(it->first);
1099 else if(type==GCONNECTOR)
1101 connections.push_back(it->first);
1105 std::string script = "";
1107 script+="include std\n"; // EED
1108 script+="include itkvtk\n"; // EED
1110 for(i = 0; i<packages.size();i++)
1113 script+=packages[i];
1117 // Definition of a complex box
1122 script+="author \" ";
1126 script+="description \" ";
1127 script+=cbDescription;
1131 for(i = 0; i<boxes.size();i++)
1135 GObjectController *control = _controllers[id];
1136 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1138 script+=model->getBBTKType();
1140 script+=model->getBBTKName();
1143 std::vector<GPortModel*> inputs = model->getInputPorts();
1144 for(int j = 0; j<inputs.size();j++)
1146 GPortModel* inputPort = inputs[j];
1147 if(inputPort->isValueSet())
1150 script+=model->getBBTKName();
1152 script+=inputPort->getBBTKName();
1154 script+=inputPort->getValue();
1161 // Create connections in the script. If the connection is made with a complex port, it is created the input or output
1163 std::string complexInputs="";
1164 std::string complexOutputs="";
1166 for(i = 0; i<connections.size();i++)
1168 int id = connections[i];
1169 GObjectController *control = _controllers[id];
1170 GConnectorModel *model = (GConnectorModel*)control->getModel();
1173 GPortModel *start = model->getStartPort();
1174 GBoxModel *startBox =start->getParentBox();
1176 GPortModel *end = model->getEndPort();
1177 GBoxModel *endBox =end->getParentBox();
1179 if(startBox->getGObjectType()==GCOMPLEXINPUTPORT)
1181 complexInputs+="input ";
1182 complexInputs+=startBox->getBBTKName();
1185 complexInputs+=endBox->getBBTKName();
1187 complexInputs+=end->getBBTKName();
1190 complexInputs+="\" \"";
1192 complexInputs+="\n";
1194 else if(endBox->getGObjectType()==GCOMPLEXOUTPUTPORT)
1196 complexOutputs+="output ";
1197 complexOutputs+=endBox->getBBTKName();
1199 complexOutputs+=" ";
1200 complexOutputs+=startBox->getBBTKName();
1201 complexOutputs+=".";
1202 complexOutputs+=start->getBBTKName();
1204 complexOutputs+=" ";
1205 complexOutputs+="\" \"";
1207 complexOutputs+="\n";
1212 script+=startBox->getBBTKName();
1214 script+=start->getBBTKName();
1218 //End Connection info
1219 script+=endBox->getBBTKName();
1221 script+=end->getBBTKName();
1227 for(i = 0; i<execBoxes.size();i++)
1230 int id = execBoxes[i];
1231 GObjectController *control = _controllers[id];
1232 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1234 script+=model->getBBTKName();
1239 script+="# Complex input ports\n";
1240 script+=complexInputs;
1243 script+="# Complex output ports\n";
1244 script+=complexOutputs;
1253 //=========================================================================
1255 void wxVtkSceneManager::deleteAllBoxes()
1257 std::map<int, GObjectController*>::iterator it;
1258 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1260 GObjectController *cont = it->second;
1261 cont->removeFromScene();
1262 unregisterController((InteractorStyleMaracas*)cont);
1264 _selectedObjects.clear();
1265 _controllers.clear();
1269 //=========================================================================
1271 void wxVtkSceneManager::refreshScene()
1273 _baseView->RefreshView();
1276 //=========================================================================
1278 void wxVtkSceneManager::centerView()
1281 _baseView->GetRenderer()->GetActiveCamera()->GetFocalPoint(temp);
1282 _baseView->GetRenderer()->GetActiveCamera()->SetFocalPoint(0,0,temp[2]);
1283 _baseView->GetRenderer()->GetActiveCamera()->GetPosition(temp);
1284 _baseView->GetRenderer()->GetActiveCamera()->SetPosition(0,0,temp[2]);
1285 _baseView->RefreshView();
1289 //=========================================================================
1291 void wxVtkSceneManager::saveDiagram(std::string &content)
1293 printf("EED %p wxVtkSceneManager::saveDiagram 1\n",this);
1296 //Print info IF COMPLEX BOX
1297 content+="COMPLEXBOX:";
1300 printf("EED %p wxVtkSceneManager::saveDiagram 2\n",this);
1303 //Print info complex input ports
1304 std::vector<int> inputs = getComplexInputPorts();
1305 int insize = inputs.size();
1306 content+="COMPLEXINPUTS:";
1307 sprintf (buffer, "%d", insize);
1311 for(int i = 0;i<insize;i++)
1314 GObjectController *cont = _controllers[id];
1315 cont->getModel()->save(content);
1318 //Print info complex output ports
1319 std::vector<int> outputs = getComplexOutputPorts();
1320 int outsize = outputs.size();
1321 content+="COMPLEXOUTPUTS:";
1322 sprintf (buffer, "%d", outsize);
1326 for(int i = 0;i<outsize;i++)
1328 int id = outputs[i];
1329 GObjectController *cont = _controllers[id];
1330 cont->getModel()->save(content);
1339 std::vector<int> boxes = getBlackBoxes();
1340 int bsize = boxes.size();
1342 sprintf (buffer, "%d", bsize);
1346 printf("EED %p wxVtkSceneManager::saveDiagram 3\n",this);
1347 for(int i = 0;i<bsize;i++)
1350 GObjectController *cont = _controllers[id];
1351 cont->getModel()->save(content);
1355 std::vector<int> connections = getConnections();
1356 int csize = connections.size();
1357 content+="CONNECTIONS:";
1358 sprintf (buffer, "%d", csize);
1362 printf("EED %p wxVtkSceneManager::saveDiagram 4\n",this);
1363 for(int i = 0;i<csize;i++)
1365 int id = connections[i];
1366 GObjectController *cont = _controllers[id];
1367 cont->getModel()->save(content);
1372 //=========================================================================
1374 void wxVtkSceneManager::loadDiagram(ifstream &inputStream)
1376 printf("EED %p wxVtkSceneManager::loadDiagram 1\n",this);
1378 std::string line="";
1379 char delims[] = ":";
1380 char *result = NULL;
1381 getline(inputStream,line);
1384 while ( !inputStream.eof() )
1386 if(line=="" || line[0]=='#')
1388 getline(inputStream,line);
1390 else if(line=="APP_START")
1392 printf("EED %p wxVtkSceneManager::loadDiagram 2\n",this);
1401 printf("EED %p wxVtkSceneManager::loadDiagram 3\n",this);
1403 getline(inputStream,line);//COMPLEX_BOX:TRUE|FALSE
1405 strcpy( complex, line.c_str() );
1406 result = strtok( complex, delims );
1407 result = strtok( NULL, delims );
1408 std::string isComplexBox(result);
1410 if(isComplexBox=="TRUE")
1412 printf("EED %p wxVtkSceneManager::loadDiagram 4\n",this);
1415 //-----------------------
1416 //- COMPLEX INPUT PORTS
1417 //-----------------------
1418 getline(inputStream,line);//COMPLEXINPUTS:num
1420 strcpy( inputs, line.c_str() );
1421 result = strtok( inputs, delims );
1422 result = strtok( NULL, delims );
1425 std::istringstream inps(result);
1428 for(int i = 0;i<numInputs;i++)
1431 getline(inputStream,line);//COMPLEX_PORT
1432 getline(inputStream,line);//name
1433 std::string inputPortName(line);
1436 getline(inputStream,line);//xInic:yInic:zInic
1438 strcpy( coord, line.c_str() );
1439 result = strtok( coord, delims );//xInic
1440 std::string xInic(result);
1441 result = strtok( NULL, delims );//yInic
1442 std::string yInic(result);
1443 result = strtok( NULL, delims );//zInic
1444 std::string zInic(result);
1446 double xIn, yIn, zIn;
1447 std::istringstream xSt(xInic);
1449 std::istringstream ySt(yInic);
1451 std::istringstream zSt(zInic);
1454 getline(inputStream,line);//FIN_COMPLEX_PORT
1456 int idInputPort = createGComplexBoxInputPort(inputPortName);
1457 GObjectController *cont = _controllers[idInputPort];
1458 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
1459 cbmod->setInicPoint(xIn,yIn,zIn);
1460 cbmod->notifyObservers(_idManager);
1461 } // for input complex box
1464 //-----------------------
1465 //- COMPLEX OUTPUT PORTS
1466 //-----------------------
1468 getline(inputStream,line);//COMPLEXOUTPUTS:num
1470 strcpy( outputs, line.c_str() );
1471 result = strtok( outputs, delims );
1472 result = strtok( NULL, delims );
1475 std::istringstream outps(result);
1476 outps >> numOutputs;
1478 for(int i = 0;i<numOutputs;i++)
1481 getline(inputStream,line);//COMPLEX_PORT
1482 getline(inputStream,line);//name
1483 std::string outputPortName(line);
1486 getline(inputStream,line);//xInic:yInic:zInic
1488 strcpy( coord, line.c_str() );
1489 result = strtok( coord, delims );//xInic
1490 std::string xInic(result);
1491 result = strtok( NULL, delims );//yInic
1492 std::string yInic(result);
1493 result = strtok( NULL, delims );//zInic
1494 std::string zInic(result);
1496 double xIn, yIn, zIn;
1497 std::istringstream xSt(xInic);
1499 std::istringstream ySt(yInic);
1501 std::istringstream zSt(zInic);
1504 getline(inputStream,line);//FIN_COMPLEX_PORT
1506 int idOutputPort = createGComplexBoxOutputPort(outputPortName);
1507 GObjectController *cont = _controllers[idOutputPort];
1508 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
1509 cbmod->setInicPoint(xIn,yIn,zIn);
1510 cbmod->notifyObservers(_idManager);
1511 } // for output complex box
1516 printf("EED %p wxVtkSceneManager::loadDiagram 4.1\n",this);
1517 getline(inputStream,line);//BOXES:num
1518 printf("EED %p wxVtkSceneManager::loadDiagram 4.2\n",this);
1520 printf("EED %p wxVtkSceneManager::loadDiagram 4.3\n",this);
1521 strcpy( boxes, line.c_str() );
1522 printf("EED %p wxVtkSceneManager::loadDiagram 4.4\n",this);
1523 result = strtok( boxes, delims );
1524 printf("EED %p wxVtkSceneManager::loadDiagram 4.5\n",this);
1525 result = strtok( NULL, delims );
1526 printf("EED %p wxVtkSceneManager::loadDiagram 4.6\n",this);
1529 printf("EED %p wxVtkSceneManager::loadDiagram 4.7\n",this);
1530 std::istringstream is(result);
1531 printf("EED %p wxVtkSceneManager::loadDiagram 4.8\n",this);
1534 printf("EED %p wxVtkSceneManager::loadDiagram 5\n",this);
1535 for(int i = 0;i<numBoxes;i++)
1538 getline(inputStream,line);//BOX
1539 getline(inputStream,line);//package:type:name
1541 strcpy( box, line.c_str() );
1542 result = strtok( box, delims );//package
1543 std::string package(result);
1544 result = strtok( NULL, delims );//type
1545 std::string type(result);
1546 result = strtok( NULL, delims );//name
1547 std::string name(result);
1549 getline(inputStream,line);//ISEXEC:TRUE|FALSE
1551 strcpy( exec, line.c_str() );
1552 result = strtok( exec, delims );//ISEXEC
1553 result = strtok( NULL, delims );//TRUE|FALSE
1554 std::string isExec(result);
1557 getline(inputStream,line);//xInic:yInic:zInic
1559 strcpy( coord, line.c_str() );
1560 result = strtok( coord, delims );//xInic
1561 std::string xInic(result);
1562 result = strtok( NULL, delims );//yInic
1563 std::string yInic(result);
1564 result = strtok( NULL, delims );//zInic
1565 std::string zInic(result);
1567 double xIn, yIn, zIn;
1568 std::istringstream xSt(xInic);
1570 std::istringstream ySt(yInic);
1572 std::istringstream zSt(zInic);
1574 printf("EED %p wxVtkSceneManager::loadDiagram 6\n",this);
1577 getline(inputStream,line);//xEnd:yEnd:zEnd
1578 strcpy( coord, line.c_str() );
1579 result = strtok( coord, delims );//xEnd
1580 std::string xEnd(result);
1581 result = strtok( NULL, delims );//yEnd
1582 std::string yEnd(result);
1583 result = strtok( NULL, delims );//zEnd
1584 std::string zEnd(result);
1585 printf("EED %p wxVtkSceneManager::loadDiagram 6.1\n",this);
1587 double xEn, yEn, zEn;
1588 std::istringstream xEt(xEnd);
1590 std::istringstream yEt(yEnd);
1592 std::istringstream zEt(zEnd);
1595 printf("EED %p wxVtkSceneManager::loadDiagram 6.2\n",this);
1596 int idBox = createGBlackBox(0,0,package,type);
1597 printf("EED %p wxVtkSceneManager::loadDiagram 6.2\n",this);
1598 GObjectController *cont = _controllers[idBox];
1599 printf("EED %p wxVtkSceneManager::loadDiagram 6.2\n",this);
1600 GBlackBoxModel *bbmod = (GBlackBoxModel*)cont->getModel();
1601 printf("EED %p wxVtkSceneManager::loadDiagram 6.2\n",this);
1602 bbmod->setBBTKName(name);
1603 printf("EED %p wxVtkSceneManager::loadDiagram 6.2\n",this);
1604 bbmod->setInicPoint(xIn,yIn,zIn);
1605 printf("EED %p wxVtkSceneManager::loadDiagram 6.2\n",this);
1606 bbmod->setFinalPoint(xEn,yEn,zEn);
1607 printf("EED %p wxVtkSceneManager::loadDiagram 6.2\n",this);
1610 bbmod->setExecutable(true);
1612 else if(isExec=="FALSE")
1614 bbmod->setExecutable(false);
1618 getline(inputStream,line);//PORT o FIN_BOX
1619 std::string port=line.substr(0,4);
1622 printf("EED %p wxVtkSceneManager::loadDiagram 7\n",this);
1623 getline(inputStream,line);//name:value
1625 strcpy( poort, line.c_str() );
1626 result = strtok( poort, delims );//name
1627 std::string name(result);
1628 result = strtok( NULL, delims );//value
1629 std::string value(result);
1631 bbmod->setValueToInput(name,value);
1633 getline(inputStream,line);//PORT o FIN_BOX
1634 port=line.substr(0,4);
1637 bbmod->notifyObservers(_idManager);
1642 getline(inputStream,line);//CONNECTIONS:num
1644 strcpy( conns, line.c_str() );
1645 result = strtok( conns, delims );
1646 result = strtok( NULL, delims );
1649 std::istringstream isCons(result);
1652 printf("EED %p wxVtkSceneManager::loadDiagram 8\n",this);
1653 for(int i = 0;i<numConns;i++)
1655 printf("EED %p wxVtkSceneManager::loadDiagram 9\n",this);
1657 getline(inputStream,line);//CONNECTION
1658 getline(inputStream,line);//Startbox.PortName:EndBox.PortName
1661 strcpy( connec, line.c_str() );
1662 result = strtok( connec, delims );
1663 std::string nameStartBox(result);
1664 result = strtok( NULL, delims );
1665 std::string nameStartPort(result);
1666 result = strtok( NULL, delims );
1667 std::string nameEndBox(result);
1668 result = strtok( NULL, delims );
1669 std::string nameEndPort(result);
1671 std::vector<int> lstB = getBlackBoxes();
1673 GPortModel *startP=NULL;
1674 GPortModel *endP=NULL;
1675 for(int j = 0;j<lstB.size();j++)
1678 GBlackBoxModel *bbMod = (GBlackBoxModel*)_controllers[idB]->getModel();
1679 if(_controllers[idB]->getModel()->getBBTKName()==nameStartBox)
1681 startP = bbMod->getOutputPort(nameStartPort);
1683 else if(_controllers[idB]->getModel()->getBBTKName()==nameEndBox)
1685 endP = bbMod->getInputPort(nameEndPort);
1693 std::vector<int> lstInputs = getComplexInputPorts();
1694 for(int j = 0;j<lstInputs.size();j++)
1696 int idB = lstInputs[j];
1697 GBoxModel *cbMod = (GBoxModel*)_controllers[idB]->getModel();
1698 if(_controllers[idB]->getModel()->getBBTKName()==nameStartBox)
1700 startP = cbMod->getOutputPort(nameStartPort);
1707 std::vector<int> lstOutputs = getComplexOutputPorts();
1708 for(int j = 0;j<lstOutputs.size();j++)
1710 int idB = lstOutputs[j];
1711 GBoxModel *cbMod = (GBoxModel*)_controllers[idB]->getModel();
1712 if(_controllers[idB]->getModel()->getBBTKName()==nameEndBox)
1714 endP = cbMod->getInputPort(nameEndPort);
1720 int idCon = createGConnector(startP);
1721 _worldState = NOTHING_HAPPENS;
1722 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
1724 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
1725 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
1726 tempp->endContourCreation();
1727 conMod->setEndPort(endP);
1728 conView->updateStartEndPoints();
1732 printf("EED %p wxVtkSceneManager::loadDiagram 10\n",this);
1736 //=========================================================================
1738 std::vector<int> wxVtkSceneManager::getBlackBoxes()
1740 std::vector<int> vect;
1741 std::map<int, GObjectController*>::iterator it;
1742 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1744 GObjectController *cont = it->second;
1745 if(cont->getGObjectType()==GBLACKBOX)
1747 vect.push_back(cont->getId());
1753 //=========================================================================
1755 std::vector<int> wxVtkSceneManager::getComplexInputPorts()
1757 std::vector<int> vect;
1758 std::map<int, GObjectController*>::iterator it;
1759 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1761 GObjectController *cont = it->second;
1762 if(cont->getGObjectType()==GCOMPLEXINPUTPORT)
1764 vect.push_back(cont->getId());
1770 //=========================================================================
1772 std::vector<int> wxVtkSceneManager::getComplexOutputPorts()
1774 std::vector<int> vect;
1775 std::map<int, GObjectController*>::iterator it;
1776 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1778 GObjectController *cont = it->second;
1779 if(cont->getGObjectType()==GCOMPLEXOUTPUTPORT)
1781 vect.push_back(cont->getId());
1787 //=========================================================================
1789 std::vector<int> wxVtkSceneManager::getConnections()
1791 std::vector<int> vect;
1792 std::map<int, GObjectController*>::iterator it;
1793 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1795 GObjectController *cont = it->second;
1796 if(cont->getGObjectType()==GCONNECTOR)
1798 vect.push_back(cont->getId());
1804 //=========================================================================
1806 bool wxVtkSceneManager::isComplexBox()
1808 return _isComplexBox;
1811 //=========================================================================
1813 void wxVtkSceneManager::setComplexBox(bool val)
1818 //=========================================================================
1820 int wxVtkSceneManager::addObjectController(GObjectController* objController)
1822 //Register the controller of the new object
1823 registerController((InteractorStyleMaracas*) objController);
1825 //Add the object to the objects list
1826 int newId = _contLastId;//_controllers.size();
1827 objController->setId(newId);
1828 _controllers[newId] = objController;
1833 //=========================================================================
1835 int wxVtkSceneManager::getNumSelectedObjects()
1837 return _selectedObjects.size();
1840 //=========================================================================
1842 std::map<int,GObjectController*> wxVtkSceneManager::getSelectedObjects()
1844 std::map<int,GObjectController*> mapSelected;
1846 std::map<int, GObjectController*>::iterator it;
1847 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1849 GObjectController *cont = it->second;
1850 if(cont->getGObjectType()==GBLACKBOX && cont->getView()->getState()==SELECTED)
1852 mapSelected[cont->getId()]=cont;
1856 std::map<int, GObjectController*>::iterator it2;
1857 for(it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
1859 GObjectController *cont = it2->second;
1860 if(cont->getGObjectType()==GCONNECTOR)
1862 GConnectorModel* cmod = (GConnectorModel*)cont->getModel();
1863 GBoxModel* endPortParentBox = cmod->getEndPort()->getParentBox();
1864 GBoxModel* startPortParentBox = cmod->getStartPort()->getParentBox();
1866 std::map<int, GObjectController*>::iterator iterOBJ1 = mapSelected.find(startPortParentBox->getObjectId());
1867 std::map<int, GObjectController*>::iterator iterOBJ2 = mapSelected.find(endPortParentBox->getObjectId());
1869 if(iterOBJ1 != mapSelected.end() && iterOBJ2 != mapSelected.end())
1871 int ID = cont->getId();
1872 mapSelected[ID]=cont;
1880 //=========================================================================
1882 void wxVtkSceneManager::addObjects(std::map<int,GObjectController*> objectsMap)
1885 std::map<int,int> oldIdNewIdBoxes;
1886 std::vector<int> connections;
1888 std::map<int, GObjectController*>::iterator it;
1889 for(it = objectsMap.begin(); it != objectsMap.end(); ++it)
1891 GObjectController *cont = it->second;
1892 int type = cont->getGObjectType();
1897 double xInic, yInic,zInic;
1898 GBlackBoxModel* copyBox = (GBlackBoxModel*)cont->getModel();
1899 copyBox->getInicPoint(xInic,yInic,zInic);
1900 int idBox = createGBlackBox(0,0,copyBox->getBBTKPackage(),copyBox->getBBTKType());
1902 int idcB = copyBox->getObjectId();
1903 oldIdNewIdBoxes[idcB]=idBox;
1904 cont = _controllers[idBox];
1905 GBlackBoxModel* newbox = (GBlackBoxModel*)cont->getModel();
1906 newbox->setInicPoint(xInic,yInic,zInic);
1907 int num = newbox->getNumInputPorts();
1908 for(int j=0;j<num;j++)
1910 newbox->setValueToInputPort(j,copyBox->getValueInputPort(j));
1912 newbox->notifyObservers(_idManager);
1914 else if(type==GCONNECTOR)
1916 int idCon = cont->getId();
1917 connections.push_back(idCon);
1922 for(int i = 0 ;i<connections.size();i++)
1924 int objId = connections[i];
1925 GObjectController *cont = objectsMap[objId];
1926 GConnectorModel* connectModel = (GConnectorModel*)cont->getModel();
1928 GPortModel* startPort = connectModel->getStartPort();
1929 int startPortIndex = startPort->getPosInBox();
1930 GPortModel* endPort = connectModel->getEndPort();
1931 int endPortIndex = endPort->getPosInBox();
1933 GBlackBoxModel* startPortParentBox = (GBlackBoxModel*)startPort->getParentBox();
1934 GBlackBoxModel* endPortParentBox = (GBlackBoxModel*)endPort->getParentBox();
1936 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
1937 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
1939 GBlackBoxModel* newStartBox = (GBlackBoxModel*)_controllers[idNewStartBox]->getModel();
1940 GBlackBoxModel* newEndBox = (GBlackBoxModel*)_controllers[idNewEndBox]->getModel();
1942 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
1943 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
1945 // Creates connection
1946 int idCon = createGConnector(newStartPort);
1947 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
1948 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
1949 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
1950 tempp->endContourCreation();
1951 conMod->setEndPort(newEndPort);
1952 conView->updateStartEndPoints();
1955 std::map<int, int>::iterator itIds;
1956 for(itIds = oldIdNewIdBoxes.begin(); itIds != oldIdNewIdBoxes.end(); ++itIds)
1958 int idOld = itIds->first;
1959 int idNew = itIds->second;
1961 GBlackBoxModel* oldBox = (GBlackBoxModel*)objectsMap[idOld]->getModel();
1962 GBlackBoxModel* newBox = (GBlackBoxModel*)_controllers[idNew]->getModel();
1964 std::vector<int> oldInputConnections = oldBox->getConnectedInputs();
1965 std::vector<int> oldOutputConnections = oldBox->getConnectedOutputs();
1966 std::vector<int> newInputConnections = newBox->getConnectedInputs();
1967 std::vector<int> newOutputConnections = newBox->getConnectedOutputs();
1969 for(int k = 0; k<oldInputConnections.size();k++)
1973 for(int l = 0; l<newInputConnections.size() && !exist;l++)
1975 if(oldInputConnections[k]==newInputConnections[l])
1983 //Create complex input
1984 int posInBox = oldInputConnections[k];
1985 GPortModel* inputPort = oldBox->getInputPort(posInBox);
1986 std::string inputPortName = inputPort->getBBTKName();
1987 int idInputPort = createGComplexBoxInputPort(inputPortName);
1988 GObjectController *cont = _controllers[idInputPort];
1989 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
1991 inputPort->getInicPoint(xIn,yIn,zIn);
1993 cbmod->setInicPoint(xIn,yIn,zIn);
1994 cbmod->notifyObservers(_idManager);
1996 GPortModel* inputPortEnd = newBox->getInputPort(posInBox);
1998 // Creates connection
1999 int idCon = createGConnector(cbmod->getOutputPort(0));
2000 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
2001 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
2002 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
2003 tempp->endContourCreation();
2004 conMod->setEndPort(inputPortEnd);
2005 conView->updateStartEndPoints();
2012 for(int k = 0; k<oldOutputConnections.size();k++)
2016 for(int l = 0; l<newOutputConnections.size() && !exist;l++)
2018 if(oldOutputConnections[k]==newOutputConnections[l])
2026 //Create complex output
2027 int posInBox = oldOutputConnections[k];
2028 GPortModel* outputPort = oldBox->getOutputPort(posInBox);
2029 std::string outputPortName = outputPort->getBBTKName();
2030 int idOutputPort = createGComplexBoxOutputPort(outputPortName);
2031 GObjectController *cont = _controllers[idOutputPort];
2032 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
2034 outputPort->getInicPoint(xIn,yIn,zIn);
2036 cbmod->setInicPoint(xIn,yIn,zIn);
2037 cbmod->notifyObservers(_idManager);
2039 GPortModel* outputPortEnd = newBox->getOutputPort(posInBox);
2041 // Creates connection
2042 int idCon = createGConnector(outputPortEnd);
2043 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
2044 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
2045 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
2046 tempp->endContourCreation();
2047 conMod->setEndPort(cbmod->getInputPort(0));
2048 conView->updateStartEndPoints();
2059 //=========================================================================
2061 } // EO namespace bbtk