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)
56 printf ("RaC-EED 21-06-2010 %p wxVtkSceneManager::wxVtkSceneManager If you comment this line, the drag and drop functionnality is not initialized.\n" , this );
57 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget((wxDropTarget*)parent);
60 _worldState=NOTHING_HAPPENS;
61 registerController(this);
64 _idConnectionInCreation=-1;
69 //=========================================================================
71 void wxVtkSceneManager::disconnectDrop()
73 printf ("EED %p ~wxVtkSceneManager::disconnectDrop()\n" , this );
74 //EED02JUIN2010 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget(NULL);
75 // _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget( new tmpClasswxTextDropTarget() );
78 //=========================================================================
80 wxVtkSceneManager::~wxVtkSceneManager()
82 printf ("EED %p ~wxVtkSceneManager()\n" , this );
86 //=========================================================================
88 void wxVtkSceneManager::configureBaseView()
90 vtkInteractorStyleBaseView2D *interactorstylebaseview = vtkInteractorStyleBaseView2D::New();
92 _baseView->SetInteractorStyleBaseView(interactorstylebaseview);
94 // Important to activate the 2D interaction system
95 wxVTKRenderWindowInteractor *iren = _baseView->GetWxVTKRenderWindowInteractor();
96 interactorstylebaseview->SetInteractor ( iren );
97 iren->SetInteractorStyle(interactorstylebaseview);
98 interactorstylebaseview->SetwxVtkBaseView(_baseView);
100 _baseView->GetRenderer()->GetActiveCamera()->ParallelProjectionOn();
101 _baseView->GetRenderer()->ResetCamera(-100,100,-100,100,900,1000);
103 _baseView->GetRenderer()->SetBackground(0.9,0.9,0.9);
104 _baseView->GetRenderer()->GradientBackgroundOff();
105 _baseView->Refresh();
108 //=========================================================================
110 std::string wxVtkSceneManager::generateANewNameForABox()
113 std::stringstream boxname;
116 boxname << "Box0" << _numBoxes;
118 boxname << "Box" << _numBoxes;
120 return boxname.str();
123 //=========================================================================
125 std::string wxVtkSceneManager::findANewNameForABox()
127 std::string boxname=generateANewNameForABox();
129 while (boxExist(boxname)==true)
131 boxname=generateANewNameForABox();
137 //=========================================================================
139 int wxVtkSceneManager::createGBlackBox(int x, int y, std::string packageName, std::string boxType)
141 _worldState = NOTHING_HAPPENS;
142 int windowWidth = _baseView->GetRenWin()->GetSize()[0];
143 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
145 int type = GBLACKBOX;
147 //Create the MVC Objects
149 GBlackBoxModel *model = (GBlackBoxModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
150 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
151 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
153 BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxType);
155 //Prepares the initial model
156 //The coordinates obtained are the following. Top-Left:x=0,y=0 Bottom-Right:x=width,y=height
159 double yy = windowHeight-y;
161 //z value is not important yet, because it is only used a parallel projection
164 _baseView->TransCoordScreenToWorld(xx,yy,zz);
165 model->setInicPoint(xx,yy,zz);
167 //EED Borrame _numBoxes++;
168 std::stringstream stream;
170 str:string newBoxName = findANewNameForABox();
171 stream << newBoxName;
175 stream << "Box0" << _numBoxes;
179 stream << "Box" << _numBoxes;
182 std::string arraystring = stream.str();
184 model->setBBTKName(arraystring);
185 model->setBBTKType(boxType);
186 model->setBBTKPackage(packageName);
188 model->addObserver(view);
189 model->addObserver(this);
191 //Iterate and create the input ports
192 std::map<std::string, BlackBoxInputDescriptor*> descriptorInMap = descriptor->GetInputDescriptorMap();
193 std::map<std::string, BlackBoxInputDescriptor*>::iterator itInput;
196 for(itInput = descriptorInMap.begin(); itInput != descriptorInMap.end(); ++itInput)
198 BlackBoxInputDescriptor *desc = itInput->second;
199 createGInputPort(GINPUTPORT,i,model,desc);
203 //Iterate and create the output ports
204 std::map<std::string, BlackBoxOutputDescriptor*> descriptorOutMap = descriptor->GetOutputDescriptorMap();
205 std::map<std::string, BlackBoxOutputDescriptor*>::iterator itOutput;
208 for(itOutput = descriptorOutMap.begin();itOutput != descriptorOutMap.end(); ++itOutput)
210 BlackBoxOutputDescriptor *desc = itOutput->second;
211 createGOutputPort(GOUTPUTPORT,i,model,desc);
216 //Associates the view with the correspondent renderer and the model.
217 //(NOTE: Refresh is only made by the view)
218 view->setModel(model);
219 view->setBaseView(_baseView);
220 view->initVtkObjects();
222 //Associates the controller with the correspondent model and view
223 controller->setModelAndView(model,view);
225 //Resgiter change to the observers of the actual model
226 model->notifyObservers(_idManager);
228 int newId = addObjectController(controller);
234 //=========================================================================
236 int wxVtkSceneManager::createGComplexBoxInputPort(std::string inputName)
238 int windowWidth=_baseView->GetRenWin()->GetSize()[0];
239 int windowHeight=_baseView->GetRenWin()->GetSize()[1];
241 int type = GCOMPLEXINPUTPORT;
243 //Create the MVC Objects
245 GComplexBoxPortModel *model = (GComplexBoxPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
246 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
247 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
249 //Prepares the initial model
252 double yy = windowHeight-5;
254 //z value is not important yet, because it is only used a parallel projection
257 _baseView->TransCoordScreenToWorld(xx,yy,zz);
258 model->setInicPoint(xx,yy,zz);
260 model->setBBTKName(inputName);
261 model->setBBTKType("ComplexInputPort");
262 model->setComplexPortType(type);
264 model->addObserver(view);
265 model->addObserver(this);
267 //create the output port
268 GPortController* portController = createGPort(GOUTPUTPORT,inputName,"ComplexInputPort",0,model);
269 model->addOutputPort((GPortModel*)portController->getModel());
271 //Associates the view with the correspondent renderer and the model.
272 //(NOTE: Refresh is only made by the view)
273 view->setModel(model);
274 view->setBaseView(_baseView);
275 view->initVtkObjects();
277 //Associates the controller with the correspondent model and view
278 controller->setModelAndView(model,view);
280 //Resgiter change to the observers of the actual model
281 model->notifyObservers(_idManager);
283 int newId = addObjectController(controller);
287 //=========================================================================
289 int wxVtkSceneManager::createGComplexBoxOutputPort(std::string outputName)
291 int windowWidth=_baseView->GetRenWin()->GetSize()[0];
292 int windowHeight=_baseView->GetRenWin()->GetSize()[1];
294 int type = GCOMPLEXOUTPUTPORT;
296 //Create the MVC Objects
298 GComplexBoxPortModel *model = (GComplexBoxPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
299 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
300 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
302 //Prepares the initial model
305 double yy = windowHeight-5;
307 //z value is not important yet, because it is only used a parallel projection
310 _baseView->TransCoordScreenToWorld(xx,yy,zz);
311 model->setInicPoint(xx,yy,zz);
313 model->setBBTKName(outputName);
314 model->setBBTKType("ComplexOutputPort");
315 model->setComplexPortType(type);
317 model->addObserver(view);
318 model->addObserver(this);
320 //create the output port
321 GPortController* portController = createGPort(GINPUTPORT,outputName,"ComplexInputPort",0,model);
322 model->addInputPort((GPortModel*)portController->getModel());
324 //Associates the view with the correspondent renderer and the model.
325 //(NOTE: Refresh is only made by the view)
326 view->setModel(model);
327 view->setBaseView(_baseView);
328 view->initVtkObjects();
330 //Associates the controller with the correspondent model and view
331 controller->setModelAndView(model,view);
333 //Resgiter change to the observers of the actual model
334 model->notifyObservers(_idManager);
336 int newId = addObjectController(controller);
340 //=========================================================================
342 int wxVtkSceneManager::createGInputPort(int portType, int posinBox,GBoxModel *blackBox, BlackBoxInputDescriptor *desc)
344 GPortController* portController = createGPort(portType,desc->GetName(),desc->GetTypeName(),posinBox,blackBox);
345 blackBox->addInputPort((GPortModel*)portController->getModel());
346 return portController->getId();
349 //=========================================================================
351 int wxVtkSceneManager::createGOutputPort(int portType, int posinBox,GBoxModel *blackBox, BlackBoxOutputDescriptor *desc)
353 GPortController* portController = createGPort(portType,desc->GetName(),desc->GetTypeName(),posinBox,blackBox);
354 blackBox->addOutputPort((GPortModel*)portController->getModel());
355 return portController->getId();
358 //=========================================================================
360 GPortController* wxVtkSceneManager::createGPort(int portType,std::string bbtkName, std::string bbtkType, int posInBox,GBoxModel *blackBox)
364 //Create the MVC Objects
365 GPortModel *model = (GPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
366 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
367 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
369 model->registerInBox(blackBox,portType, posInBox);
371 model->setBBTKType(bbtkType);
372 model->setBBTKName(bbtkName);
374 model->addObserver(view);
375 model->addObserver(this);
377 //Associates the view with the correspondent renderer and the model.
378 //(NOTE: Refresh is only made by the view)
379 view->setModel(model);
380 view->setBaseView(_baseView);
381 view->initVtkObjects();
383 //Associates the controller with the correspondent model and view
384 controller->setModelAndView(model,view);
386 model->notifyObservers(_idManager);
388 int newId = addObjectController(controller);
390 return (GPortController*)controller;
393 //=========================================================================
395 int wxVtkSceneManager::createGConnector(GPortModel* startPort)
397 int type = GCONNECTOR;
399 manualConnectorContourController* manContourControl = new manualConnectorContourController();
400 manualConnectorContourView* manContourView = new manualConnectorContourView();
401 manualContourModel* manContourModel = new manualContourModel();
403 GConnectorController* connectorcontroller = new GConnectorController();
404 GConnectorModel* connectorModel = new GConnectorModel();
405 vtkGConnectorView* connectorView = new vtkGConnectorView();
406 connectorModel->setGObjectType(type);
408 manContourModel->SetCloseContour(false);
409 connectorModel->setStartPort(startPort);
411 manContourView->SetModel( manContourModel );
412 manContourView->SetWxVtkBaseView( _baseView );
413 manContourView->SetRange( 0.5 );
414 manContourView->SetZ( 900 );
416 manContourView->SetColorNormalContour(0, 0, 1);
417 manContourView->SetColorEditContour(0.5, 0.5, 0.5);
418 manContourView->SetColorSelectContour(1, 0.8, 0);
419 manContourView->SetWidthLine(1);
420 manContourView->SetShowText(false);
422 manContourControl->SetModelView( manContourModel , manContourView );
424 manContourControl->CreateNewManualContour();
426 manContourView->RefreshContour();
430 connectorModel->getInicPoint(x,y,z);
432 manContourControl->SetState(1);
433 manContourModel->SetCloseContour(false);
435 manContourModel->AddPoint(x,y,z);
436 manContourView->AddPoint();
438 manContourModel->AddPoint(x,y,z);
439 manContourView->AddPoint();
441 int bak= manContourControl->GetNumberOfPointsManualContour() - 1;
442 manContourControl->_bakIdPoint=bak;
443 manContourView->Refresh();
445 manContourControl->SetMoving( false );
447 connectorcontroller->setModelAndView(connectorModel,connectorView);
449 int newId = addObjectController(connectorcontroller);
451 connectorcontroller->setManualContourController(manContourControl);
452 connectorModel->setManualContourModel(manContourModel);
453 connectorView->setManualContourView(manContourView);
454 connectorView->setModel(connectorModel);
455 connectorView->setBaseView(_baseView);
458 connectorModel->addObserver(connectorView);
459 connectorModel->addObserver(this);
464 //=========================================================================
466 void wxVtkSceneManager::registerController(InteractorStyleMaracas *param)
468 vtkInteractorStyleBaseView* baseViewControlManager = (vtkInteractorStyleBaseView*)_baseView->GetInteractorStyleBaseView();
469 baseViewControlManager->AddInteractorStyleMaracas( param );
472 //=========================================================================
474 void wxVtkSceneManager::unregisterController(InteractorStyleMaracas *param)
476 vtkInteractorStyleBaseView* baseViewControlManager = (vtkInteractorStyleBaseView*)_baseView->GetInteractorStyleBaseView();
477 baseViewControlManager->RemoveInteractorStyleMaracas( param );
480 //=========================================================================
482 vtkRenderer* wxVtkSceneManager::getRenderer()
484 return _baseView->GetRenderer();
487 //=========================================================================
489 vtkRenderWindow* wxVtkSceneManager::getRenderWindow()
491 return _baseView->GetRenWin();
493 //=========================================================================
496 void wxVtkSceneManager::update(int idController,int command)
498 if(command != NO_COMMAND)
500 if(command == ADD_TO_SELECTED)
502 GObjectController* cont = _controllers[idController];
505 for (int i=0; i<_selectedObjects.size() && foundID==false; i++)
507 int id = _selectedObjects[i];
515 int id = idController;
516 _selectedObjects.push_back(id);
520 else if(command == INIT_CREATION_CONTOUR)
522 _worldState = INIT_CREATION_CONTOUR;
523 GObjectController* cont = _controllers[idController];
524 GPortModel* startOutputPort = (GPortModel*)cont->getModel();
527 // The last one is the controller of the connector
528 std::map<int, GObjectController*>::iterator it2;
530 for(it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
532 GObjectController *cont = it2->second;
533 if(cont->getGObjectType() == GPORT )
535 GPortModel* port = (GPortModel*)cont->getModel();
536 if(port->getPortType()==GINPUTPORT)
538 cont->SetActive(true);
542 cont->getView()->setState(NOTHING_HAPPENS);
543 cont->getModel()->notifyObservers(_idManager);
544 cont->SetActive(false);
549 cont->getView()->setState(NOTHING_HAPPENS);
550 cont->getModel()->notifyObservers(_idManager);
551 cont->SetActive(false);
555 _selectedObjects.clear();
557 _idConnectionInCreation=createGConnector(startOutputPort);
560 else if(command == FIN_CREATION_CONTOUR && _worldState == INIT_CREATION_CONTOUR)
562 _worldState = NOTHING_HAPPENS;
563 //int id = _controllers.size()-1;
564 GObjectController* cont = _controllers[_idConnectionInCreation];
565 GConnectorModel* modelContour = (GConnectorModel*)cont->getModel();
567 GObjectController* finPort = _controllers[idController];
568 if(finPort->getGObjectType() == GPORT)
570 GPortModel* modelPort = (GPortModel*)finPort->getModel();
571 modelContour->setEndPort(modelPort);
574 manualConnectorContourController* manCont = ((GConnectorController*)cont)->getManualContourController();
575 manualConnectorContourView* connView = (manualConnectorContourView*)manCont->GetManualViewBaseContour();
578 std::map<int, GObjectController*>::iterator it2;
580 for(it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
582 GObjectController *cont = it2->second;
583 if(cont->getView()!=NULL)
585 cont->getView()->setState(NOTHING_HAPPENS);
586 cont->getModel()->notifyObservers(_idManager);
588 cont->SetActive(true);
595 //=========================================================================
597 bool wxVtkSceneManager::OnMouseMove()
600 wxVTKRenderWindowInteractor *wxVTKiren;
601 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
602 wxVTKiren->GetEventPosition(X,Y);
605 if(_worldState == DRAG_OBJECTS)
607 for (int i=0; i<_selectedObjects.size(); i++)
609 int id = _selectedObjects[i];
610 GObjectController* cont = _controllers[id];
613 cont->getView()->setStartDragging(true);
615 cont->getView()->moveObject(X,Y);
616 cont->getView()->setState(DRAG);
617 cont->getModel()->notifyObservers(_idManager);
620 std::map<int, GObjectController*>::iterator it;
622 for(it = _controllers.begin(); it != _controllers.end(); ++it)
624 GObjectController *desc = it->second;
625 if(desc->getGObjectType()==GCONNECTOR)
627 vtkGConnectorView* vconn = (vtkGConnectorView*)desc->getView();
628 vconn->updateStartEndPoints();
632 _startDragging=false;
635 else if(_worldState == NOTHING_HAPPENS || _worldState == INIT_CREATION_CONTOUR)
637 std::map<int, GObjectController*>::iterator it;
639 for(it = _controllers.begin(); it != _controllers.end(); ++it)
641 GObjectController *desc = it->second;
642 int type = desc->getGObjectType();
643 int state = desc->getView()->getState();
645 if(state == HIGHLIGHTED){
647 updateStatusBar(desc->getStatusText());
650 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
651 _parent->displayBlackBoxInfo(mod->getBBTKPackage(),mod->getBBTKType());
660 //=========================================================================
662 bool wxVtkSceneManager::OnLeftButtonDown()
664 if(_worldState==INIT_CREATION_CONTOUR)
666 bool isOverPort=false;
667 std::map<int, GObjectController*>::iterator it;
668 for(it = _controllers.begin(); it != _controllers.end() && isOverPort==false; ++it)
670 GObjectController *desc = it->second;
671 if(desc->getGObjectType()==GPORT)
673 GPortModel* portmod=(GPortModel*)desc->getModel();
674 vtkGObjectView* portView=desc->getView();
675 if(portmod->getPortType()==GINPUTPORT && portView->getState()==HIGHLIGHTED)
682 if(isOverPort==false)
684 _worldState=NOTHING_HAPPENS;
685 //int lastId = _controllers.size()-1;
686 GConnectorController *connector = (GConnectorController*)_controllers[_controllers.size()-1];
687 connector->removeFromScene();
688 unregisterController(connector);
689 _controllers.erase(_controllers.size()-1);
691 for(it = _controllers.begin(); it != _controllers.end(); ++it)
693 GObjectController *desc = it->second;
694 desc->SetActive(true);
695 desc->getView()->setState(NOTHING_HAPPENS);
696 desc->getModel()->notifyObservers(_idManager);
701 if(_selectedObjects.size()!=0)
703 _worldState = DRAG_OBJECTS;
704 _startDragging = true;
706 for (int i = 0; i < _selectedObjects.size(); i++)
708 int id = _selectedObjects[i];
709 GObjectController* cont = _controllers[id];
710 cont->getView()->setState(DRAG);
711 cont->getModel()->notifyObservers(_idManager);
720 //=========================================================================
722 bool wxVtkSceneManager::OnLeftButtonUp()
724 if(_worldState == DRAG_OBJECTS)
726 _worldState = NOTHING_HAPPENS;
728 for (int i = 0; i < _selectedObjects.size(); i++)
730 int id = _selectedObjects[i];
731 GObjectController* cont = _controllers[id];
732 cont->getView()->setState(SELECTED);
733 cont->getModel()->notifyObservers(_idManager);
739 //=========================================================================
741 bool wxVtkSceneManager::OnRightButtonUp()
743 if(_worldState==INIT_CREATION_CONTOUR)
745 _worldState=NOTHING_HAPPENS;
746 //int lastId = _controllers.size()-1;
747 GConnectorController *connector = (GConnectorController*)_controllers[_idConnectionInCreation];
748 connector->removeFromScene();
749 unregisterController(connector);
750 _controllers.erase(_idConnectionInCreation);
752 std::map<int, GObjectController*>::iterator it;
753 for(it = _controllers.begin(); it != _controllers.end(); ++it)
755 GObjectController *desc = it->second;
756 desc->SetActive(true);
757 desc->getView()->setState(NOTHING_HAPPENS);
758 desc->getModel()->notifyObservers(_idManager);
763 for (int i = 0; i < _selectedObjects.size(); i++)
765 int id = _selectedObjects[i];
766 GObjectController* cont = _controllers[id];
767 cont->SetActive(true);
768 cont->getView()->setState(NOTHING_HAPPENS);
769 cont->getModel()->notifyObservers(_idManager);
772 _selectedObjects.clear();
777 //=========================================================================
779 bool wxVtkSceneManager::OnLeftDClick()
782 wxVTKRenderWindowInteractor *wxVTKiren;
783 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
784 wxVTKiren->GetEventPosition(X,Y);
786 std::map<int, GObjectController*>::iterator it;
788 bool clickOnObject = false;
790 for(it = _controllers.begin(); it != _controllers.end() && clickOnObject==false; ++it)
792 GObjectController *cont = it->second;
793 int type = cont->getGObjectType();
795 if(cont->getView()->isPointInside(X,Y))
799 for (int i=0; i<_selectedObjects.size(); i++)
801 int id = _selectedObjects[i];
802 GObjectController* control = _controllers[id];
803 control->getView()->setState(NOTHING_HAPPENS);
805 _selectedObjects.clear();
807 GBlackBoxModel *bbmodel = (GBlackBoxModel*)cont->getModel();
808 _parent->editBlackBox(bbmodel);
810 clickOnObject = true;
814 if(clickOnObject==false)
816 //_parent->editDiagramParameters(this);
822 //=========================================================================
824 bool wxVtkSceneManager::OnChar()
826 char keyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
828 // KeyCode 127 : Delete Key
829 // KeyCode 8 : Backspace Key
830 if(keyCode == 8 || keyCode == 127)
832 if(_selectedObjects.size()>0)
834 for(int i=0;i<(int)_selectedObjects.size();i++)
836 int id = _selectedObjects[i];
837 std::map<int,GObjectController*>::iterator it;
838 it = _controllers.find(id);
839 if (it!=_controllers.end())
844 _selectedObjects.clear();
851 //=========================================================================
853 void wxVtkSceneManager::AddControlerToBeRemove(std::vector<int> *controllersToRemove, int id)
858 for(i=0 ; i < (int)controllersToRemove->size() ; i++ )
860 if (id == (*controllersToRemove)[i] )
868 controllersToRemove->push_back( id );
873 //=========================================================================
875 void wxVtkSceneManager::deleteObject(int id)
877 GObjectController *control = _controllers[id];
878 std::vector<int> controllersToRemove;
880 if(control->getGObjectType()==GBLACKBOX || control->getGObjectType()==GCOMPLEXINPUTPORT || control->getGObjectType()==GCOMPLEXOUTPUTPORT)
882 GBoxModel *bbmod = (GBoxModel*)control->getModel();
883 std::vector<GPortModel*> inputs = bbmod->getInputPorts();
885 bool boxConnected = false;
887 // Add box input controllers to be removed
888 for(int i = 0;i< (int)inputs.size();i++)
890 AddControlerToBeRemove( &controllersToRemove, inputs[i]->getObjectId() );
891 if(inputs[i]->isConnected())
897 std::vector<GPortModel*> outputs = bbmod->getOutputPorts();
899 // Add box output controllers to be removed
900 for(int i = 0;i<(int)outputs.size();i++)
902 AddControlerToBeRemove( &controllersToRemove, outputs[i]->getObjectId() );
903 if(outputs[i]->isConnected())
909 // Add connection controllers to be removed
910 std::map<int, GObjectController*>::iterator it;
911 for(it = _controllers.begin(); it != _controllers.end(); ++it)
913 GObjectController *cont = it->second;
914 int type = cont->getGObjectType();
917 GConnectorModel *conMod = (GConnectorModel*)cont->getModel();
918 if(conMod->getStartPort()!=NULL && conMod->getStartPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
920 AddControlerToBeRemove( &controllersToRemove, conMod->getObjectId() );
922 if(conMod->getEndPort()!=NULL && conMod->getEndPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
924 AddControlerToBeRemove( &controllersToRemove, conMod->getObjectId() );
929 // Add box controller to be removed
930 AddControlerToBeRemove( &controllersToRemove, bbmod->getObjectId() );
932 else if(control->getGObjectType()==GCONNECTOR)
934 GConnectorModel *conMod = (GConnectorModel*)control->getModel();
935 AddControlerToBeRemove( &controllersToRemove, conMod->getObjectId() );
939 std::map<int,GObjectController*>::iterator it;
941 for(int i = 0;i<(int)controllersToRemove.size();i++)
943 int key = controllersToRemove[i];
944 it = _controllers.find( key );
945 GObjectController *cont = _controllers[ key ];
948 cont->removeFromScene();
949 unregisterController((InteractorStyleMaracas*)cont);
950 _controllers.erase(it);
955 //=========================================================================
957 void wxVtkSceneManager::displayBlackBoxInfo(std::string packageName, std::string boxName)
959 _parent->displayBlackBoxInfo(packageName,boxName);
962 //=========================================================================
964 void wxVtkSceneManager::updateStatusBar(std::string textStatus)
966 _parent->updateStatusBar(textStatus);
969 //=========================================================================
971 std::string wxVtkSceneManager::getDiagramBBS()
973 bool existsExec=false;
975 std::vector<std::string> packages;
976 std::vector<int> boxes;
977 std::vector<int> connections;
978 std::vector<int> execBoxes;
980 std::map<int, GObjectController*>::iterator it;
982 for(it = _controllers.begin(); it != _controllers.end(); ++it)
984 GObjectController *desc = it->second;
985 int type = desc->getGObjectType();
989 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
991 std::string pkg = mod->getBBTKPackage();
992 bool existsPkg = false;
993 for(int t = 0;t<packages.size() && existsPkg == false;t++)
1002 packages.push_back(pkg);
1006 boxes.push_back(it->first);
1007 if(mod->isExecutable())
1009 execBoxes.push_back(it->first);
1013 else if(type==GCONNECTOR)
1015 connections.push_back(it->first);
1019 std::string script = "";
1020 script+="# BBTK GEditor Script\n";
1021 script+="# ----------------------\n";
1024 script+="include std\n"; // EED
1025 script+="include itkvtk\n"; // EED
1027 for(i = 0; i<packages.size();i++)
1030 script+=packages[i];
1034 // script+="include std\n"; // JPR
1036 for(i = 0; i<boxes.size();i++)
1040 GObjectController *control = _controllers[id];
1041 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1043 script+=model->getBBTKType();
1045 script+=model->getBBTKName();
1048 std::vector<GPortModel*> inputs = model->getInputPorts();
1049 for(int j = 0; j<inputs.size();j++)
1051 GPortModel* inputPort = inputs[j];
1052 if(inputPort->isValueSet())
1055 script+=model->getBBTKName();
1057 script+=inputPort->getBBTKName();
1059 script+=inputPort->getValue();
1066 for(i = 0; i<connections.size();i++)
1069 int id = connections[i];
1070 GObjectController *control = _controllers[id];
1071 GConnectorModel *model = (GConnectorModel*)control->getModel();
1073 //Start Connection info
1074 GPortModel *start = model->getStartPort();
1075 script+=start->getParentBox()->getBBTKName();
1077 script+=start->getBBTKName();
1081 //End Connection info
1082 GPortModel *end = model->getEndPort();
1083 script+=end->getParentBox()->getBBTKName();
1085 script+=end->getBBTKName();
1090 for(i = 0; i<execBoxes.size();i++)
1093 int id = execBoxes[i];
1094 GObjectController *control = _controllers[id];
1095 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1097 script+=model->getBBTKName();
1106 //=========================================================================
1108 std::string wxVtkSceneManager::saveComplexBoxBBS(std::string cbName,std::string cbAuthor,std::string cbCategory,std::string cbDescription)
1111 std::vector<std::string> packages;
1112 std::vector<int> boxes;
1113 std::vector<int> connections;
1114 std::vector<int> execBoxes;
1116 std::map<int, GObjectController*>::iterator it;
1118 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1120 GObjectController *desc = it->second;
1121 int type = desc->getGObjectType();
1125 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
1127 std::string pkg = mod->getBBTKPackage();
1128 bool existsPkg = false;
1129 for(int t = 0;t<packages.size() && existsPkg == false;t++)
1131 if(packages[t]==pkg)
1138 packages.push_back(pkg);
1142 boxes.push_back(it->first);
1143 if(mod->isExecutable())
1145 execBoxes.push_back(it->first);
1148 else if(type==GCONNECTOR)
1150 connections.push_back(it->first);
1154 std::string script = "";
1156 script+="include std\n"; // EED
1157 script+="include itkvtk\n"; // EED
1159 for(i = 0; i<packages.size();i++)
1162 script+=packages[i];
1166 // Definition of a complex box
1171 script+="author \" ";
1175 script+="description \" ";
1176 script+=cbDescription;
1180 for(i = 0; i<boxes.size();i++)
1184 GObjectController *control = _controllers[id];
1185 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1187 script+=model->getBBTKType();
1189 script+=model->getBBTKName();
1192 std::vector<GPortModel*> inputs = model->getInputPorts();
1193 for(int j = 0; j<inputs.size();j++)
1195 GPortModel* inputPort = inputs[j];
1196 if(inputPort->isValueSet())
1199 script+=model->getBBTKName();
1201 script+=inputPort->getBBTKName();
1203 script+=inputPort->getValue();
1210 // Create connections in the script. If the connection is made with a complex port, it is created the input or output
1212 std::string complexInputs="";
1213 std::string complexOutputs="";
1215 for(i = 0; i<connections.size();i++)
1217 int id = connections[i];
1218 GObjectController *control = _controllers[id];
1219 GConnectorModel *model = (GConnectorModel*)control->getModel();
1222 GPortModel *start = model->getStartPort();
1223 GBoxModel *startBox =start->getParentBox();
1225 GPortModel *end = model->getEndPort();
1226 GBoxModel *endBox =end->getParentBox();
1228 if(startBox->getGObjectType()==GCOMPLEXINPUTPORT)
1230 complexInputs+="input ";
1231 complexInputs+=startBox->getBBTKName();
1234 complexInputs+=endBox->getBBTKName();
1236 complexInputs+=end->getBBTKName();
1239 complexInputs+="\" \"";
1241 complexInputs+="\n";
1243 else if(endBox->getGObjectType()==GCOMPLEXOUTPUTPORT)
1245 complexOutputs+="output ";
1246 complexOutputs+=endBox->getBBTKName();
1248 complexOutputs+=" ";
1249 complexOutputs+=startBox->getBBTKName();
1250 complexOutputs+=".";
1251 complexOutputs+=start->getBBTKName();
1253 complexOutputs+=" ";
1254 complexOutputs+="\" \"";
1256 complexOutputs+="\n";
1261 script+=startBox->getBBTKName();
1263 script+=start->getBBTKName();
1267 //End Connection info
1268 script+=endBox->getBBTKName();
1270 script+=end->getBBTKName();
1276 for(i = 0; i<execBoxes.size();i++)
1279 int id = execBoxes[i];
1280 GObjectController *control = _controllers[id];
1281 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1283 script+=model->getBBTKName();
1288 script+="# Complex input ports\n";
1289 script+=complexInputs;
1292 script+="# Complex output ports\n";
1293 script+=complexOutputs;
1302 //=========================================================================
1304 void wxVtkSceneManager::deleteAllBoxes()
1306 std::map<int, GObjectController*>::iterator it;
1307 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1309 GObjectController *cont = it->second;
1310 cont->removeFromScene();
1311 unregisterController((InteractorStyleMaracas*)cont);
1313 _selectedObjects.clear();
1314 _controllers.clear();
1318 //=========================================================================
1320 void wxVtkSceneManager::refreshScene()
1322 _baseView->RefreshView();
1325 //=========================================================================
1327 void wxVtkSceneManager::centerView()
1330 _baseView->GetRenderer()->GetActiveCamera()->GetFocalPoint(temp);
1331 _baseView->GetRenderer()->GetActiveCamera()->SetFocalPoint(0,0,temp[2]);
1332 _baseView->GetRenderer()->GetActiveCamera()->GetPosition(temp);
1333 _baseView->GetRenderer()->GetActiveCamera()->SetPosition(0,0,temp[2]);
1334 _baseView->RefreshView();
1338 //=========================================================================
1340 void wxVtkSceneManager::saveDiagram(std::string &content)
1344 //Print info IF COMPLEX BOX
1345 content+="COMPLEXBOX:";
1350 //Print info complex input ports
1351 std::vector<int> inputs = getComplexInputPorts();
1352 int insize = inputs.size();
1353 content+="COMPLEXINPUTS:";
1354 sprintf (buffer, "%d", insize);
1358 for(int i = 0;i<insize;i++)
1361 GObjectController *cont = _controllers[id];
1362 cont->getModel()->save(content);
1365 //Print info complex output ports
1366 std::vector<int> outputs = getComplexOutputPorts();
1367 int outsize = outputs.size();
1368 content+="COMPLEXOUTPUTS:";
1369 sprintf (buffer, "%d", outsize);
1373 for(int i = 0;i<outsize;i++)
1375 int id = outputs[i];
1376 GObjectController *cont = _controllers[id];
1377 cont->getModel()->save(content);
1386 std::vector<int> boxes = getBlackBoxes();
1387 int bsize = boxes.size();
1389 sprintf (buffer, "%d", bsize);
1393 for(int i = 0;i<bsize;i++)
1396 GObjectController *cont = _controllers[id];
1397 cont->getModel()->save(content);
1401 std::vector<int> connections = getConnections();
1402 int csize = connections.size();
1403 content+="CONNECTIONS:";
1404 sprintf (buffer, "%d", csize);
1408 for(int i = 0;i<csize;i++)
1410 int id = connections[i];
1411 GObjectController *cont = _controllers[id];
1412 cont->getModel()->save(content);
1417 //=========================================================================
1419 void wxVtkSceneManager::loadDiagram(ifstream &inputStream)
1422 std::string line="";
1423 char delims[] = ":";
1424 char *result = NULL;
1425 getline(inputStream,line);
1428 while ( !inputStream.eof() )
1430 if(line=="" || line[0]=='#')
1432 getline(inputStream,line);
1434 else if(line=="APP_START")
1445 getline(inputStream,line);//COMPLEX_BOX:TRUE|FALSE
1447 strcpy( complex, line.c_str() );
1448 result = strtok( complex, delims );
1449 result = strtok( NULL, delims );
1450 std::string isComplexBox(result);
1452 if(isComplexBox=="TRUE")
1456 //-----------------------
1457 //- COMPLEX INPUT PORTS
1458 //-----------------------
1459 getline(inputStream,line);//COMPLEXINPUTS:num
1461 strcpy( inputs, line.c_str() );
1462 result = strtok( inputs, delims );
1463 result = strtok( NULL, delims );
1466 std::istringstream inps(result);
1469 for(int i = 0;i<numInputs;i++)
1472 getline(inputStream,line);//COMPLEX_PORT
1473 getline(inputStream,line);//name
1474 std::string inputPortName(line);
1477 getline(inputStream,line);//xInic:yInic:zInic
1479 strcpy( coord, line.c_str() );
1480 result = strtok( coord, delims );//xInic
1481 std::string xInic(result);
1482 result = strtok( NULL, delims );//yInic
1483 std::string yInic(result);
1484 result = strtok( NULL, delims );//zInic
1485 std::string zInic(result);
1487 double xIn, yIn, zIn;
1488 std::istringstream xSt(xInic);
1490 std::istringstream ySt(yInic);
1492 std::istringstream zSt(zInic);
1495 getline(inputStream,line);//FIN_COMPLEX_PORT
1497 int idInputPort = createGComplexBoxInputPort(inputPortName);
1498 GObjectController *cont = _controllers[idInputPort];
1499 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
1500 cbmod->setInicPoint(xIn,yIn,zIn);
1501 cbmod->notifyObservers(_idManager);
1502 } // for input complex box
1505 //-----------------------
1506 //- COMPLEX OUTPUT PORTS
1507 //-----------------------
1509 getline(inputStream,line);//COMPLEXOUTPUTS:num
1511 strcpy( outputs, line.c_str() );
1512 result = strtok( outputs, delims );
1513 result = strtok( NULL, delims );
1516 std::istringstream outps(result);
1517 outps >> numOutputs;
1519 for(int i = 0;i<numOutputs;i++)
1522 getline(inputStream,line);//COMPLEX_PORT
1523 getline(inputStream,line);//name
1524 std::string outputPortName(line);
1527 getline(inputStream,line);//xInic:yInic:zInic
1529 strcpy( coord, line.c_str() );
1530 result = strtok( coord, delims );//xInic
1531 std::string xInic(result);
1532 result = strtok( NULL, delims );//yInic
1533 std::string yInic(result);
1534 result = strtok( NULL, delims );//zInic
1535 std::string zInic(result);
1537 double xIn, yIn, zIn;
1538 std::istringstream xSt(xInic);
1540 std::istringstream ySt(yInic);
1542 std::istringstream zSt(zInic);
1545 getline(inputStream,line);//FIN_COMPLEX_PORT
1547 int idOutputPort = createGComplexBoxOutputPort(outputPortName);
1548 GObjectController *cont = _controllers[idOutputPort];
1549 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
1550 cbmod->setInicPoint(xIn,yIn,zIn);
1551 cbmod->notifyObservers(_idManager);
1552 } // for output complex box
1557 getline(inputStream,line);//BOXES:num
1559 strcpy( boxes, line.c_str() );
1560 result = strtok( boxes, delims );
1561 result = strtok( NULL, delims );
1564 std::istringstream is(result);
1567 for(int i = 0;i<numBoxes;i++)
1570 getline(inputStream,line);//BOX
1571 getline(inputStream,line);//package:type:name
1573 strcpy( box, line.c_str() );
1574 result = strtok( box, delims );//package
1575 std::string package(result);
1576 result = strtok( NULL, delims );//type
1577 std::string type(result);
1578 result = strtok( NULL, delims );//name
1579 std::string name(result);
1581 getline(inputStream,line);//ISEXEC:TRUE|FALSE
1583 strcpy( exec, line.c_str() );
1584 result = strtok( exec, delims );//ISEXEC
1585 result = strtok( NULL, delims );//TRUE|FALSE
1586 std::string isExec(result);
1589 getline(inputStream,line);//xInic:yInic:zInic
1591 strcpy( coord, line.c_str() );
1592 result = strtok( coord, delims );//xInic
1593 std::string xInic(result);
1594 result = strtok( NULL, delims );//yInic
1595 std::string yInic(result);
1596 result = strtok( NULL, delims );//zInic
1597 std::string zInic(result);
1599 double xIn, yIn, zIn;
1600 std::istringstream xSt(xInic);
1602 std::istringstream ySt(yInic);
1604 std::istringstream zSt(zInic);
1608 getline(inputStream,line);//xEnd:yEnd:zEnd
1609 strcpy( coord, line.c_str() );
1610 result = strtok( coord, delims );//xEnd
1611 std::string xEnd(result);
1612 result = strtok( NULL, delims );//yEnd
1613 std::string yEnd(result);
1614 result = strtok( NULL, delims );//zEnd
1615 std::string zEnd(result);
1617 double xEn, yEn, zEn;
1618 std::istringstream xEt(xEnd);
1620 std::istringstream yEt(yEnd);
1622 std::istringstream zEt(zEnd);
1625 int idBox = createGBlackBox(0,0,package,type);
1626 GObjectController *cont = _controllers[idBox];
1627 GBlackBoxModel *bbmod = (GBlackBoxModel*)cont->getModel();
1628 bbmod->setBBTKName(name);
1629 bbmod->setInicPoint(xIn,yIn,zIn);
1630 bbmod->setFinalPoint(xEn,yEn,zEn);
1634 bbmod->setExecutable(true);
1636 else if(isExec=="FALSE")
1638 bbmod->setExecutable(false);
1642 getline(inputStream,line);//PORT o FIN_BOX
1643 std::string port=line.substr(0,4);
1646 getline(inputStream,line);//name:value
1648 strcpy( poort, line.c_str() );
1649 result = strtok( poort, delims );//name
1650 std::string name(result);
1651 result = strtok( NULL, delims );//value
1652 std::string value(result);
1654 bbmod->setValueToInput(name,value);
1656 getline(inputStream,line);//PORT o FIN_BOX
1657 port=line.substr(0,4);
1660 bbmod->notifyObservers(_idManager);
1665 getline(inputStream,line);//CONNECTIONS:num
1667 strcpy( conns, line.c_str() );
1668 result = strtok( conns, delims );
1669 result = strtok( NULL, delims );
1672 std::istringstream isCons(result);
1675 for(int i = 0;i<numConns;i++)
1678 getline(inputStream,line);//CONNECTION
1679 getline(inputStream,line);//Startbox.PortName:EndBox.PortName
1682 strcpy( connec, line.c_str() );
1683 result = strtok( connec, delims );
1684 std::string nameStartBox(result);
1685 result = strtok( NULL, delims );
1686 std::string nameStartPort(result);
1687 result = strtok( NULL, delims );
1688 std::string nameEndBox(result);
1689 result = strtok( NULL, delims );
1690 std::string nameEndPort(result);
1692 std::vector<int> lstB = getBlackBoxes();
1694 GPortModel *startP=NULL;
1695 GPortModel *endP=NULL;
1696 for(int j = 0;j<lstB.size();j++)
1699 GBlackBoxModel *bbMod = (GBlackBoxModel*)_controllers[idB]->getModel();
1700 if(_controllers[idB]->getModel()->getBBTKName()==nameStartBox)
1702 startP = bbMod->getOutputPort(nameStartPort);
1704 else if(_controllers[idB]->getModel()->getBBTKName()==nameEndBox)
1706 endP = bbMod->getInputPort(nameEndPort);
1714 std::vector<int> lstInputs = getComplexInputPorts();
1715 for(int j = 0;j<lstInputs.size();j++)
1717 int idB = lstInputs[j];
1718 GBoxModel *cbMod = (GBoxModel*)_controllers[idB]->getModel();
1719 if(_controllers[idB]->getModel()->getBBTKName()==nameStartBox)
1721 startP = cbMod->getOutputPort(nameStartPort);
1728 std::vector<int> lstOutputs = getComplexOutputPorts();
1729 for(int j = 0;j<lstOutputs.size();j++)
1731 int idB = lstOutputs[j];
1732 GBoxModel *cbMod = (GBoxModel*)_controllers[idB]->getModel();
1733 if(_controllers[idB]->getModel()->getBBTKName()==nameEndBox)
1735 endP = cbMod->getInputPort(nameEndPort);
1741 int idCon = createGConnector(startP);
1742 _worldState = NOTHING_HAPPENS;
1743 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
1745 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
1746 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
1747 tempp->endContourCreation();
1748 conMod->setEndPort(endP);
1749 conView->updateStartEndPoints();
1756 //=========================================================================
1758 bool wxVtkSceneManager::boxExist(std::string boxname)
1761 std::map<int, GObjectController*>::iterator it;
1762 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1764 GObjectController *cont = it->second;
1765 if(cont->getModel()->getBBTKName()==boxname)
1773 //=========================================================================
1775 std::vector<int> wxVtkSceneManager::getBlackBoxes()
1777 std::vector<int> vect;
1778 std::map<int, GObjectController*>::iterator it;
1779 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1781 GObjectController *cont = it->second;
1782 if(cont->getGObjectType()==GBLACKBOX)
1784 vect.push_back(cont->getId());
1790 //=========================================================================
1792 std::vector<int> wxVtkSceneManager::getComplexInputPorts()
1794 std::vector<int> vect;
1795 std::map<int, GObjectController*>::iterator it;
1796 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1798 GObjectController *cont = it->second;
1799 if(cont->getGObjectType()==GCOMPLEXINPUTPORT)
1801 vect.push_back(cont->getId());
1807 //=========================================================================
1809 std::vector<int> wxVtkSceneManager::getComplexOutputPorts()
1811 std::vector<int> vect;
1812 std::map<int, GObjectController*>::iterator it;
1813 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1815 GObjectController *cont = it->second;
1816 if(cont->getGObjectType()==GCOMPLEXOUTPUTPORT)
1818 vect.push_back(cont->getId());
1824 //=========================================================================
1826 std::vector<int> wxVtkSceneManager::getConnections()
1828 std::vector<int> vect;
1829 std::map<int, GObjectController*>::iterator it;
1830 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1832 GObjectController *cont = it->second;
1833 if(cont->getGObjectType()==GCONNECTOR)
1835 vect.push_back(cont->getId());
1841 //=========================================================================
1843 bool wxVtkSceneManager::isComplexBox()
1845 return _isComplexBox;
1848 //=========================================================================
1850 void wxVtkSceneManager::setComplexBox(bool val)
1855 //=========================================================================
1857 int wxVtkSceneManager::addObjectController(GObjectController* objController)
1859 //Register the controller of the new object
1860 registerController((InteractorStyleMaracas*) objController);
1862 //Add the object to the objects list
1863 int newId = _contLastId;//_controllers.size();
1864 objController->setId(newId);
1865 _controllers[newId] = objController;
1870 //=========================================================================
1872 int wxVtkSceneManager::getNumSelectedObjects()
1874 return _selectedObjects.size();
1877 //=========================================================================
1879 std::map<int,GObjectController*> wxVtkSceneManager::getSelectedObjects()
1881 std::map<int,GObjectController*> mapSelected;
1883 std::map<int, GObjectController*>::iterator it;
1884 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1886 GObjectController *cont = it->second;
1887 if(cont->getGObjectType()==GBLACKBOX && cont->getView()->getState()==SELECTED)
1889 mapSelected[cont->getId()]=cont;
1893 std::map<int, GObjectController*>::iterator it2;
1894 for(it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
1896 GObjectController *cont = it2->second;
1897 if(cont->getGObjectType()==GCONNECTOR)
1899 GConnectorModel* cmod = (GConnectorModel*)cont->getModel();
1900 GBoxModel* endPortParentBox = cmod->getEndPort()->getParentBox();
1901 GBoxModel* startPortParentBox = cmod->getStartPort()->getParentBox();
1903 std::map<int, GObjectController*>::iterator iterOBJ1 = mapSelected.find(startPortParentBox->getObjectId());
1904 std::map<int, GObjectController*>::iterator iterOBJ2 = mapSelected.find(endPortParentBox->getObjectId());
1906 if(iterOBJ1 != mapSelected.end() && iterOBJ2 != mapSelected.end())
1908 int ID = cont->getId();
1909 mapSelected[ID]=cont;
1917 //=========================================================================
1919 void wxVtkSceneManager::addObjects(std::map<int,GObjectController*> objectsMap)
1922 std::map<int,int> oldIdNewIdBoxes;
1923 std::vector<int> connections;
1925 std::map<int, GObjectController*>::iterator it;
1926 for(it = objectsMap.begin(); it != objectsMap.end(); ++it)
1928 GObjectController *cont = it->second;
1929 int type = cont->getGObjectType();
1934 double xInic, yInic,zInic;
1935 GBlackBoxModel* copyBox = (GBlackBoxModel*)cont->getModel();
1936 copyBox->getInicPoint(xInic,yInic,zInic);
1937 int idBox = createGBlackBox(0,0,copyBox->getBBTKPackage(),copyBox->getBBTKType());
1939 int idcB = copyBox->getObjectId();
1940 oldIdNewIdBoxes[idcB]=idBox;
1941 cont = _controllers[idBox];
1942 GBlackBoxModel* newbox = (GBlackBoxModel*)cont->getModel();
1943 newbox->setInicPoint(xInic,yInic,zInic);
1944 int num = newbox->getNumInputPorts();
1945 for(int j=0;j<num;j++)
1947 newbox->setValueToInputPort(j,copyBox->getValueInputPort(j));
1949 newbox->notifyObservers(_idManager);
1951 else if(type==GCONNECTOR)
1953 int idCon = cont->getId();
1954 connections.push_back(idCon);
1959 for(int i = 0 ;i<connections.size();i++)
1961 int objId = connections[i];
1962 GObjectController *cont = objectsMap[objId];
1963 GConnectorModel* connectModel = (GConnectorModel*)cont->getModel();
1965 GPortModel* startPort = connectModel->getStartPort();
1966 int startPortIndex = startPort->getPosInBox();
1967 GPortModel* endPort = connectModel->getEndPort();
1968 int endPortIndex = endPort->getPosInBox();
1970 GBlackBoxModel* startPortParentBox = (GBlackBoxModel*)startPort->getParentBox();
1971 GBlackBoxModel* endPortParentBox = (GBlackBoxModel*)endPort->getParentBox();
1973 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
1974 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
1976 GBlackBoxModel* newStartBox = (GBlackBoxModel*)_controllers[idNewStartBox]->getModel();
1977 GBlackBoxModel* newEndBox = (GBlackBoxModel*)_controllers[idNewEndBox]->getModel();
1979 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
1980 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
1982 // Creates connection
1983 int idCon = createGConnector(newStartPort);
1984 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
1985 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
1986 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
1987 tempp->endContourCreation();
1988 conMod->setEndPort(newEndPort);
1989 conView->updateStartEndPoints();
1992 std::map<int, int>::iterator itIds;
1993 for(itIds = oldIdNewIdBoxes.begin(); itIds != oldIdNewIdBoxes.end(); ++itIds)
1995 int idOld = itIds->first;
1996 int idNew = itIds->second;
1998 GBlackBoxModel* oldBox = (GBlackBoxModel*)objectsMap[idOld]->getModel();
1999 GBlackBoxModel* newBox = (GBlackBoxModel*)_controllers[idNew]->getModel();
2001 std::vector<int> oldInputConnections = oldBox->getConnectedInputs();
2002 std::vector<int> oldOutputConnections = oldBox->getConnectedOutputs();
2003 std::vector<int> newInputConnections = newBox->getConnectedInputs();
2004 std::vector<int> newOutputConnections = newBox->getConnectedOutputs();
2006 for(int k = 0; k<oldInputConnections.size();k++)
2010 for(int l = 0; l<newInputConnections.size() && !exist;l++)
2012 if(oldInputConnections[k]==newInputConnections[l])
2020 //Create complex input
2021 int posInBox = oldInputConnections[k];
2022 GPortModel* inputPort = oldBox->getInputPort(posInBox);
2023 std::string inputPortName = inputPort->getBBTKName();
2024 int idInputPort = createGComplexBoxInputPort(inputPortName);
2025 GObjectController *cont = _controllers[idInputPort];
2026 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
2028 inputPort->getInicPoint(xIn,yIn,zIn);
2030 cbmod->setInicPoint(xIn,yIn,zIn);
2031 cbmod->notifyObservers(_idManager);
2033 GPortModel* inputPortEnd = newBox->getInputPort(posInBox);
2035 // Creates connection
2036 int idCon = createGConnector(cbmod->getOutputPort(0));
2037 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
2038 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
2039 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
2040 tempp->endContourCreation();
2041 conMod->setEndPort(inputPortEnd);
2042 conView->updateStartEndPoints();
2049 for(int k = 0; k<oldOutputConnections.size();k++)
2053 for(int l = 0; l<newOutputConnections.size() && !exist;l++)
2055 if(oldOutputConnections[k]==newOutputConnections[l])
2063 //Create complex output
2064 int posInBox = oldOutputConnections[k];
2065 GPortModel* outputPort = oldBox->getOutputPort(posInBox);
2066 std::string outputPortName = outputPort->getBBTKName();
2067 int idOutputPort = createGComplexBoxOutputPort(outputPortName);
2068 GObjectController *cont = _controllers[idOutputPort];
2069 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
2071 outputPort->getInicPoint(xIn,yIn,zIn);
2073 cbmod->setInicPoint(xIn,yIn,zIn);
2074 cbmod->notifyObservers(_idManager);
2076 GPortModel* outputPortEnd = newBox->getOutputPort(posInBox);
2078 // Creates connection
2079 int idCon = createGConnector(outputPortEnd);
2080 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
2081 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
2082 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
2083 tempp->endContourCreation();
2084 conMod->setEndPort(cbmod->getInputPort(0));
2085 conView->updateStartEndPoints();
2096 //=========================================================================
2098 } // EO namespace bbtk