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 int wxVtkSceneManager::createGBlackBox(int x, int y, std::string packageName, std::string boxType)
112 _worldState = NOTHING_HAPPENS;
113 int windowWidth=_baseView->GetRenWin()->GetSize()[0];
114 int windowHeight=_baseView->GetRenWin()->GetSize()[1];
116 int type = GBLACKBOX;
118 //Create the MVC Objects
120 GBlackBoxModel *model = (GBlackBoxModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
121 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
122 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
124 BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxType);
126 //Prepares the initial model
127 //The coordinates obtained are the following. Top-Left:x=0,y=0 Bottom-Right:x=width,y=height
130 double yy = windowHeight-y;
132 //z value is not important yet, because it is only used a parallel projection
135 _baseView->TransCoordScreenToWorld(xx,yy,zz);
136 model->setInicPoint(xx,yy,zz);
139 std::stringstream stream;
143 stream << "Box0" << _numBoxes;
147 stream << "Box" << _numBoxes;
149 std::string arraystring = stream.str();
151 model->setBBTKName(arraystring);
152 model->setBBTKType(boxType);
153 model->setBBTKPackage(packageName);
155 model->addObserver(view);
156 model->addObserver(this);
158 //Iterate and create the input ports
159 std::map<std::string, BlackBoxInputDescriptor*> descriptorInMap = descriptor->GetInputDescriptorMap();
160 std::map<std::string, BlackBoxInputDescriptor*>::iterator itInput;
163 for(itInput = descriptorInMap.begin(); itInput != descriptorInMap.end(); ++itInput)
165 BlackBoxInputDescriptor *desc = itInput->second;
166 createGInputPort(GINPUTPORT,i,model,desc);
170 //Iterate and create the output ports
171 std::map<std::string, BlackBoxOutputDescriptor*> descriptorOutMap = descriptor->GetOutputDescriptorMap();
172 std::map<std::string, BlackBoxOutputDescriptor*>::iterator itOutput;
175 for(itOutput = descriptorOutMap.begin();itOutput != descriptorOutMap.end(); ++itOutput)
177 BlackBoxOutputDescriptor *desc = itOutput->second;
178 createGOutputPort(GOUTPUTPORT,i,model,desc);
183 //Associates the view with the correspondent renderer and the model.
184 //(NOTE: Refresh is only made by the view)
185 view->setModel(model);
186 view->setBaseView(_baseView);
187 view->initVtkObjects();
189 //Associates the controller with the correspondent model and view
190 controller->setModelAndView(model,view);
192 //Resgiter change to the observers of the actual model
193 model->notifyObservers(_idManager);
195 int newId = addObjectController(controller);
201 //=========================================================================
203 int wxVtkSceneManager::createGComplexBoxInputPort(std::string inputName)
205 int windowWidth=_baseView->GetRenWin()->GetSize()[0];
206 int windowHeight=_baseView->GetRenWin()->GetSize()[1];
208 int type = GCOMPLEXINPUTPORT;
210 //Create the MVC Objects
212 GComplexBoxPortModel *model = (GComplexBoxPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
213 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
214 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
216 //Prepares the initial model
219 double yy = windowHeight-5;
221 //z value is not important yet, because it is only used a parallel projection
224 _baseView->TransCoordScreenToWorld(xx,yy,zz);
225 model->setInicPoint(xx,yy,zz);
227 model->setBBTKName(inputName);
228 model->setBBTKType("ComplexInputPort");
229 model->setComplexPortType(type);
231 model->addObserver(view);
232 model->addObserver(this);
234 //create the output port
235 GPortController* portController = createGPort(GOUTPUTPORT,inputName,"ComplexInputPort",0,model);
236 model->addOutputPort((GPortModel*)portController->getModel());
238 //Associates the view with the correspondent renderer and the model.
239 //(NOTE: Refresh is only made by the view)
240 view->setModel(model);
241 view->setBaseView(_baseView);
242 view->initVtkObjects();
244 //Associates the controller with the correspondent model and view
245 controller->setModelAndView(model,view);
247 //Resgiter change to the observers of the actual model
248 model->notifyObservers(_idManager);
250 int newId = addObjectController(controller);
254 //=========================================================================
256 int wxVtkSceneManager::createGComplexBoxOutputPort(std::string outputName)
258 int windowWidth=_baseView->GetRenWin()->GetSize()[0];
259 int windowHeight=_baseView->GetRenWin()->GetSize()[1];
261 int type = GCOMPLEXOUTPUTPORT;
263 //Create the MVC Objects
265 GComplexBoxPortModel *model = (GComplexBoxPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
266 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
267 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
269 //Prepares the initial model
272 double yy = windowHeight-5;
274 //z value is not important yet, because it is only used a parallel projection
277 _baseView->TransCoordScreenToWorld(xx,yy,zz);
278 model->setInicPoint(xx,yy,zz);
280 model->setBBTKName(outputName);
281 model->setBBTKType("ComplexOutputPort");
282 model->setComplexPortType(type);
284 model->addObserver(view);
285 model->addObserver(this);
287 //create the output port
288 GPortController* portController = createGPort(GINPUTPORT,outputName,"ComplexInputPort",0,model);
289 model->addInputPort((GPortModel*)portController->getModel());
291 //Associates the view with the correspondent renderer and the model.
292 //(NOTE: Refresh is only made by the view)
293 view->setModel(model);
294 view->setBaseView(_baseView);
295 view->initVtkObjects();
297 //Associates the controller with the correspondent model and view
298 controller->setModelAndView(model,view);
300 //Resgiter change to the observers of the actual model
301 model->notifyObservers(_idManager);
303 int newId = addObjectController(controller);
307 //=========================================================================
309 int wxVtkSceneManager::createGInputPort(int portType, int posinBox,GBoxModel *blackBox, BlackBoxInputDescriptor *desc)
311 GPortController* portController = createGPort(portType,desc->GetName(),desc->GetTypeName(),posinBox,blackBox);
312 blackBox->addInputPort((GPortModel*)portController->getModel());
313 return portController->getId();
316 //=========================================================================
318 int wxVtkSceneManager::createGOutputPort(int portType, int posinBox,GBoxModel *blackBox, BlackBoxOutputDescriptor *desc)
320 GPortController* portController = createGPort(portType,desc->GetName(),desc->GetTypeName(),posinBox,blackBox);
321 blackBox->addOutputPort((GPortModel*)portController->getModel());
322 return portController->getId();
325 //=========================================================================
327 GPortController* wxVtkSceneManager::createGPort(int portType,std::string bbtkName, std::string bbtkType, int posInBox,GBoxModel *blackBox)
331 //Create the MVC Objects
332 GPortModel *model = (GPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
333 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
334 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
336 model->registerInBox(blackBox,portType, posInBox);
338 model->setBBTKType(bbtkType);
339 model->setBBTKName(bbtkName);
341 model->addObserver(view);
342 model->addObserver(this);
344 //Associates the view with the correspondent renderer and the model.
345 //(NOTE: Refresh is only made by the view)
346 view->setModel(model);
347 view->setBaseView(_baseView);
348 view->initVtkObjects();
350 //Associates the controller with the correspondent model and view
351 controller->setModelAndView(model,view);
353 model->notifyObservers(_idManager);
355 int newId = addObjectController(controller);
357 return (GPortController*)controller;
360 //=========================================================================
362 int wxVtkSceneManager::createGConnector(GPortModel* startPort)
364 int type = GCONNECTOR;
366 manualConnectorContourController* manContourControl = new manualConnectorContourController();
367 manualConnectorContourView* manContourView = new manualConnectorContourView();
368 manualContourModel* manContourModel = new manualContourModel();
370 GConnectorController* connectorcontroller = new GConnectorController();
371 GConnectorModel* connectorModel = new GConnectorModel();
372 vtkGConnectorView* connectorView = new vtkGConnectorView();
373 connectorModel->setGObjectType(type);
375 manContourModel->SetCloseContour(false);
376 connectorModel->setStartPort(startPort);
378 manContourView->SetModel( manContourModel );
379 manContourView->SetWxVtkBaseView( _baseView );
380 manContourView->SetRange( 0.5 );
381 manContourView->SetZ( 900 );
383 manContourView->SetColorNormalContour(0, 0, 1);
384 manContourView->SetColorEditContour(0.5, 0.5, 0.5);
385 manContourView->SetColorSelectContour(1, 0.8, 0);
386 manContourView->SetWidthLine(1);
387 manContourView->SetShowText(false);
389 manContourControl->SetModelView( manContourModel , manContourView );
391 manContourControl->CreateNewManualContour();
393 manContourView->RefreshContour();
397 connectorModel->getInicPoint(x,y,z);
399 manContourControl->SetState(1);
400 manContourModel->SetCloseContour(false);
402 manContourModel->AddPoint(x,y,z);
403 manContourView->AddPoint();
405 manContourModel->AddPoint(x,y,z);
406 manContourView->AddPoint();
408 int bak= manContourControl->GetNumberOfPointsManualContour() - 1;
409 manContourControl->_bakIdPoint=bak;
410 manContourView->Refresh();
412 manContourControl->SetMoving( false );
414 connectorcontroller->setModelAndView(connectorModel,connectorView);
416 int newId = addObjectController(connectorcontroller);
418 connectorcontroller->setManualContourController(manContourControl);
419 connectorModel->setManualContourModel(manContourModel);
420 connectorView->setManualContourView(manContourView);
421 connectorView->setModel(connectorModel);
422 connectorView->setBaseView(_baseView);
425 connectorModel->addObserver(connectorView);
426 connectorModel->addObserver(this);
431 //=========================================================================
433 void wxVtkSceneManager::registerController(InteractorStyleMaracas *param)
435 vtkInteractorStyleBaseView* baseViewControlManager = (vtkInteractorStyleBaseView*)_baseView->GetInteractorStyleBaseView();
436 baseViewControlManager->AddInteractorStyleMaracas( param );
439 //=========================================================================
441 void wxVtkSceneManager::unregisterController(InteractorStyleMaracas *param)
443 vtkInteractorStyleBaseView* baseViewControlManager = (vtkInteractorStyleBaseView*)_baseView->GetInteractorStyleBaseView();
444 baseViewControlManager->RemoveInteractorStyleMaracas( param );
447 //=========================================================================
449 vtkRenderer* wxVtkSceneManager::getRenderer()
451 return _baseView->GetRenderer();
454 //=========================================================================
456 vtkRenderWindow* wxVtkSceneManager::getRenderWindow()
458 return _baseView->GetRenWin();
460 //=========================================================================
463 void wxVtkSceneManager::update(int idController,int command)
465 if(command != NO_COMMAND)
467 if(command == ADD_TO_SELECTED)
469 GObjectController* cont = _controllers[idController];
472 for (int i=0; i<_selectedObjects.size() && foundID==false; i++)
474 int id = _selectedObjects[i];
482 int id = idController;
483 _selectedObjects.push_back(id);
487 else if(command == INIT_CREATION_CONTOUR)
489 _worldState = INIT_CREATION_CONTOUR;
490 GObjectController* cont = _controllers[idController];
491 GPortModel* startOutputPort = (GPortModel*)cont->getModel();
494 // The last one is the controller of the connector
495 std::map<int, GObjectController*>::iterator it2;
497 for(it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
499 GObjectController *cont = it2->second;
500 if(cont->getGObjectType() == GPORT )
502 GPortModel* port = (GPortModel*)cont->getModel();
503 if(port->getPortType()==GINPUTPORT)
505 cont->SetActive(true);
509 cont->getView()->setState(NOTHING_HAPPENS);
510 cont->getModel()->notifyObservers(_idManager);
511 cont->SetActive(false);
516 cont->getView()->setState(NOTHING_HAPPENS);
517 cont->getModel()->notifyObservers(_idManager);
518 cont->SetActive(false);
522 _selectedObjects.clear();
524 _idConnectionInCreation=createGConnector(startOutputPort);
527 else if(command == FIN_CREATION_CONTOUR && _worldState == INIT_CREATION_CONTOUR)
529 _worldState = NOTHING_HAPPENS;
530 //int id = _controllers.size()-1;
531 GObjectController* cont = _controllers[_idConnectionInCreation];
532 GConnectorModel* modelContour = (GConnectorModel*)cont->getModel();
534 GObjectController* finPort = _controllers[idController];
535 if(finPort->getGObjectType() == GPORT)
537 GPortModel* modelPort = (GPortModel*)finPort->getModel();
538 modelContour->setEndPort(modelPort);
541 manualConnectorContourController* manCont = ((GConnectorController*)cont)->getManualContourController();
542 manualConnectorContourView* connView = (manualConnectorContourView*)manCont->GetManualViewBaseContour();
545 std::map<int, GObjectController*>::iterator it2;
547 for(it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
549 GObjectController *cont = it2->second;
550 if(cont->getView()!=NULL)
552 cont->getView()->setState(NOTHING_HAPPENS);
553 cont->getModel()->notifyObservers(_idManager);
555 cont->SetActive(true);
562 //=========================================================================
564 bool wxVtkSceneManager::OnMouseMove()
567 wxVTKRenderWindowInteractor *wxVTKiren;
568 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
569 wxVTKiren->GetEventPosition(X,Y);
572 if(_worldState == DRAG_OBJECTS)
574 for (int i=0; i<_selectedObjects.size(); i++)
576 int id = _selectedObjects[i];
577 GObjectController* cont = _controllers[id];
580 cont->getView()->setStartDragging(true);
582 cont->getView()->moveObject(X,Y);
583 cont->getView()->setState(DRAG);
584 cont->getModel()->notifyObservers(_idManager);
587 std::map<int, GObjectController*>::iterator it;
589 for(it = _controllers.begin(); it != _controllers.end(); ++it)
591 GObjectController *desc = it->second;
592 if(desc->getGObjectType()==GCONNECTOR)
594 vtkGConnectorView* vconn = (vtkGConnectorView*)desc->getView();
595 vconn->updateStartEndPoints();
599 _startDragging=false;
602 else if(_worldState == NOTHING_HAPPENS || _worldState == INIT_CREATION_CONTOUR)
604 std::map<int, GObjectController*>::iterator it;
606 for(it = _controllers.begin(); it != _controllers.end(); ++it)
608 GObjectController *desc = it->second;
609 int type = desc->getGObjectType();
610 int state = desc->getView()->getState();
612 if(state == HIGHLIGHTED){
614 updateStatusBar(desc->getStatusText());
617 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
618 _parent->displayBlackBoxInfo(mod->getBBTKPackage(),mod->getBBTKType());
627 //=========================================================================
629 bool wxVtkSceneManager::OnLeftButtonDown()
631 if(_worldState==INIT_CREATION_CONTOUR)
633 bool isOverPort=false;
634 std::map<int, GObjectController*>::iterator it;
635 for(it = _controllers.begin(); it != _controllers.end() && isOverPort==false; ++it)
637 GObjectController *desc = it->second;
638 if(desc->getGObjectType()==GPORT)
640 GPortModel* portmod=(GPortModel*)desc->getModel();
641 vtkGObjectView* portView=desc->getView();
642 if(portmod->getPortType()==GINPUTPORT && portView->getState()==HIGHLIGHTED)
649 if(isOverPort==false)
651 _worldState=NOTHING_HAPPENS;
652 //int lastId = _controllers.size()-1;
653 GConnectorController *connector = (GConnectorController*)_controllers[_controllers.size()-1];
654 connector->removeFromScene();
655 unregisterController(connector);
656 _controllers.erase(_controllers.size()-1);
658 for(it = _controllers.begin(); it != _controllers.end(); ++it)
660 GObjectController *desc = it->second;
661 desc->SetActive(true);
662 desc->getView()->setState(NOTHING_HAPPENS);
663 desc->getModel()->notifyObservers(_idManager);
668 if(_selectedObjects.size()!=0)
670 _worldState = DRAG_OBJECTS;
671 _startDragging = true;
673 for (int i = 0; i < _selectedObjects.size(); i++)
675 int id = _selectedObjects[i];
676 GObjectController* cont = _controllers[id];
677 cont->getView()->setState(DRAG);
678 cont->getModel()->notifyObservers(_idManager);
687 //=========================================================================
689 bool wxVtkSceneManager::OnLeftButtonUp()
691 if(_worldState == DRAG_OBJECTS)
693 _worldState = NOTHING_HAPPENS;
695 for (int i = 0; i < _selectedObjects.size(); i++)
697 int id = _selectedObjects[i];
698 GObjectController* cont = _controllers[id];
699 cont->getView()->setState(SELECTED);
700 cont->getModel()->notifyObservers(_idManager);
706 //=========================================================================
708 bool wxVtkSceneManager::OnRightButtonUp()
710 if(_worldState==INIT_CREATION_CONTOUR)
712 _worldState=NOTHING_HAPPENS;
713 //int lastId = _controllers.size()-1;
714 GConnectorController *connector = (GConnectorController*)_controllers[_idConnectionInCreation];
715 connector->removeFromScene();
716 unregisterController(connector);
717 _controllers.erase(_idConnectionInCreation);
719 std::map<int, GObjectController*>::iterator it;
720 for(it = _controllers.begin(); it != _controllers.end(); ++it)
722 GObjectController *desc = it->second;
723 desc->SetActive(true);
724 desc->getView()->setState(NOTHING_HAPPENS);
725 desc->getModel()->notifyObservers(_idManager);
730 for (int i = 0; i < _selectedObjects.size(); i++)
732 int id = _selectedObjects[i];
733 GObjectController* cont = _controllers[id];
734 cont->SetActive(true);
735 cont->getView()->setState(NOTHING_HAPPENS);
736 cont->getModel()->notifyObservers(_idManager);
739 _selectedObjects.clear();
744 //=========================================================================
746 bool wxVtkSceneManager::OnLeftDClick()
749 wxVTKRenderWindowInteractor *wxVTKiren;
750 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
751 wxVTKiren->GetEventPosition(X,Y);
753 std::map<int, GObjectController*>::iterator it;
755 bool clickOnObject = false;
757 for(it = _controllers.begin(); it != _controllers.end() && clickOnObject==false; ++it)
759 GObjectController *cont = it->second;
760 int type = cont->getGObjectType();
762 if(cont->getView()->isPointInside(X,Y))
766 for (int i=0; i<_selectedObjects.size(); i++)
768 int id = _selectedObjects[i];
769 GObjectController* control = _controllers[id];
770 control->getView()->setState(NOTHING_HAPPENS);
772 _selectedObjects.clear();
774 GBlackBoxModel *bbmodel = (GBlackBoxModel*)cont->getModel();
775 _parent->editBlackBox(bbmodel);
777 clickOnObject = true;
781 if(clickOnObject==false)
783 //_parent->editDiagramParameters(this);
789 //=========================================================================
791 bool wxVtkSceneManager::OnChar()
793 char keyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
795 // KeyCode 127 : Delete Key
796 // KeyCode 8 : Backspace Key
797 if(keyCode == 8 || keyCode == 127)
799 if(_selectedObjects.size()>0)
801 for(int i=0;i<(int)_selectedObjects.size();i++)
803 int id = _selectedObjects[i];
804 std::map<int,GObjectController*>::iterator it;
805 it = _controllers.find(id);
806 if (it!=_controllers.end())
811 _selectedObjects.clear();
818 //=========================================================================
820 void wxVtkSceneManager::AddControlerToBeRemove(std::vector<int> *controllersToRemove, int id)
825 for(i=0 ; i < (int)controllersToRemove->size() ; i++ )
827 if (id == (*controllersToRemove)[i] )
835 controllersToRemove->push_back( id );
840 //=========================================================================
842 void wxVtkSceneManager::deleteObject(int id)
844 GObjectController *control = _controllers[id];
845 std::vector<int> controllersToRemove;
847 if(control->getGObjectType()==GBLACKBOX || control->getGObjectType()==GCOMPLEXINPUTPORT || control->getGObjectType()==GCOMPLEXOUTPUTPORT)
849 GBoxModel *bbmod = (GBoxModel*)control->getModel();
850 std::vector<GPortModel*> inputs = bbmod->getInputPorts();
852 bool boxConnected = false;
854 // Add box input controllers to be removed
855 for(int i = 0;i< (int)inputs.size();i++)
857 AddControlerToBeRemove( &controllersToRemove, inputs[i]->getObjectId() );
858 if(inputs[i]->isConnected())
864 std::vector<GPortModel*> outputs = bbmod->getOutputPorts();
866 // Add box output controllers to be removed
867 for(int i = 0;i<(int)outputs.size();i++)
869 AddControlerToBeRemove( &controllersToRemove, outputs[i]->getObjectId() );
870 if(outputs[i]->isConnected())
876 // Add connection controllers to be removed
877 std::map<int, GObjectController*>::iterator it;
878 for(it = _controllers.begin(); it != _controllers.end(); ++it)
880 GObjectController *cont = it->second;
881 int type = cont->getGObjectType();
884 GConnectorModel *conMod = (GConnectorModel*)cont->getModel();
885 if(conMod->getStartPort()!=NULL && conMod->getStartPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
887 AddControlerToBeRemove( &controllersToRemove, conMod->getObjectId() );
889 if(conMod->getEndPort()!=NULL && conMod->getEndPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
891 AddControlerToBeRemove( &controllersToRemove, conMod->getObjectId() );
896 // Add box controller to be removed
897 AddControlerToBeRemove( &controllersToRemove, bbmod->getObjectId() );
899 else if(control->getGObjectType()==GCONNECTOR)
901 GConnectorModel *conMod = (GConnectorModel*)control->getModel();
902 AddControlerToBeRemove( &controllersToRemove, conMod->getObjectId() );
906 std::map<int,GObjectController*>::iterator it;
908 for(int i = 0;i<(int)controllersToRemove.size();i++)
910 int key = controllersToRemove[i];
911 it = _controllers.find( key );
912 GObjectController *cont = _controllers[ key ];
915 cont->removeFromScene();
916 unregisterController((InteractorStyleMaracas*)cont);
917 _controllers.erase(it);
922 //=========================================================================
924 void wxVtkSceneManager::displayBlackBoxInfo(std::string packageName, std::string boxName)
926 _parent->displayBlackBoxInfo(packageName,boxName);
929 //=========================================================================
931 void wxVtkSceneManager::updateStatusBar(std::string textStatus)
933 _parent->updateStatusBar(textStatus);
936 //=========================================================================
938 std::string wxVtkSceneManager::getDiagramBBS()
940 bool existsExec=false;
942 std::vector<std::string> packages;
943 std::vector<int> boxes;
944 std::vector<int> connections;
945 std::vector<int> execBoxes;
947 std::map<int, GObjectController*>::iterator it;
949 for(it = _controllers.begin(); it != _controllers.end(); ++it)
951 GObjectController *desc = it->second;
952 int type = desc->getGObjectType();
956 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
958 std::string pkg = mod->getBBTKPackage();
959 bool existsPkg = false;
960 for(int t = 0;t<packages.size() && existsPkg == false;t++)
969 packages.push_back(pkg);
973 boxes.push_back(it->first);
974 if(mod->isExecutable())
976 execBoxes.push_back(it->first);
980 else if(type==GCONNECTOR)
982 connections.push_back(it->first);
986 std::string script = "";
987 script+="# BBTK GEditor Script\n";
988 script+="# ----------------------\n";
991 script+="include std\n"; // EED
992 script+="include itkvtk\n"; // EED
994 for(i = 0; i<packages.size();i++)
1001 // script+="include std\n"; // JPR
1003 for(i = 0; i<boxes.size();i++)
1007 GObjectController *control = _controllers[id];
1008 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1010 script+=model->getBBTKType();
1012 script+=model->getBBTKName();
1015 std::vector<GPortModel*> inputs = model->getInputPorts();
1016 for(int j = 0; j<inputs.size();j++)
1018 GPortModel* inputPort = inputs[j];
1019 if(inputPort->isValueSet())
1022 script+=model->getBBTKName();
1024 script+=inputPort->getBBTKName();
1026 script+=inputPort->getValue();
1033 for(i = 0; i<connections.size();i++)
1036 int id = connections[i];
1037 GObjectController *control = _controllers[id];
1038 GConnectorModel *model = (GConnectorModel*)control->getModel();
1040 //Start Connection info
1041 GPortModel *start = model->getStartPort();
1042 script+=start->getParentBox()->getBBTKName();
1044 script+=start->getBBTKName();
1048 //End Connection info
1049 GPortModel *end = model->getEndPort();
1050 script+=end->getParentBox()->getBBTKName();
1052 script+=end->getBBTKName();
1057 for(i = 0; i<execBoxes.size();i++)
1060 int id = execBoxes[i];
1061 GObjectController *control = _controllers[id];
1062 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1064 script+=model->getBBTKName();
1073 //=========================================================================
1075 std::string wxVtkSceneManager::saveComplexBoxBBS(std::string cbName,std::string cbAuthor,std::string cbCategory,std::string cbDescription)
1078 std::vector<std::string> packages;
1079 std::vector<int> boxes;
1080 std::vector<int> connections;
1081 std::vector<int> execBoxes;
1083 std::map<int, GObjectController*>::iterator it;
1085 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1087 GObjectController *desc = it->second;
1088 int type = desc->getGObjectType();
1092 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
1094 std::string pkg = mod->getBBTKPackage();
1095 bool existsPkg = false;
1096 for(int t = 0;t<packages.size() && existsPkg == false;t++)
1098 if(packages[t]==pkg)
1105 packages.push_back(pkg);
1109 boxes.push_back(it->first);
1110 if(mod->isExecutable())
1112 execBoxes.push_back(it->first);
1115 else if(type==GCONNECTOR)
1117 connections.push_back(it->first);
1121 std::string script = "";
1123 script+="include std\n"; // EED
1124 script+="include itkvtk\n"; // EED
1126 for(i = 0; i<packages.size();i++)
1129 script+=packages[i];
1133 // Definition of a complex box
1138 script+="author \" ";
1142 script+="description \" ";
1143 script+=cbDescription;
1147 for(i = 0; i<boxes.size();i++)
1151 GObjectController *control = _controllers[id];
1152 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1154 script+=model->getBBTKType();
1156 script+=model->getBBTKName();
1159 std::vector<GPortModel*> inputs = model->getInputPorts();
1160 for(int j = 0; j<inputs.size();j++)
1162 GPortModel* inputPort = inputs[j];
1163 if(inputPort->isValueSet())
1166 script+=model->getBBTKName();
1168 script+=inputPort->getBBTKName();
1170 script+=inputPort->getValue();
1177 // Create connections in the script. If the connection is made with a complex port, it is created the input or output
1179 std::string complexInputs="";
1180 std::string complexOutputs="";
1182 for(i = 0; i<connections.size();i++)
1184 int id = connections[i];
1185 GObjectController *control = _controllers[id];
1186 GConnectorModel *model = (GConnectorModel*)control->getModel();
1189 GPortModel *start = model->getStartPort();
1190 GBoxModel *startBox =start->getParentBox();
1192 GPortModel *end = model->getEndPort();
1193 GBoxModel *endBox =end->getParentBox();
1195 if(startBox->getGObjectType()==GCOMPLEXINPUTPORT)
1197 complexInputs+="input ";
1198 complexInputs+=startBox->getBBTKName();
1201 complexInputs+=endBox->getBBTKName();
1203 complexInputs+=end->getBBTKName();
1206 complexInputs+="\" \"";
1208 complexInputs+="\n";
1210 else if(endBox->getGObjectType()==GCOMPLEXOUTPUTPORT)
1212 complexOutputs+="output ";
1213 complexOutputs+=endBox->getBBTKName();
1215 complexOutputs+=" ";
1216 complexOutputs+=startBox->getBBTKName();
1217 complexOutputs+=".";
1218 complexOutputs+=start->getBBTKName();
1220 complexOutputs+=" ";
1221 complexOutputs+="\" \"";
1223 complexOutputs+="\n";
1228 script+=startBox->getBBTKName();
1230 script+=start->getBBTKName();
1234 //End Connection info
1235 script+=endBox->getBBTKName();
1237 script+=end->getBBTKName();
1243 for(i = 0; i<execBoxes.size();i++)
1246 int id = execBoxes[i];
1247 GObjectController *control = _controllers[id];
1248 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1250 script+=model->getBBTKName();
1255 script+="# Complex input ports\n";
1256 script+=complexInputs;
1259 script+="# Complex output ports\n";
1260 script+=complexOutputs;
1269 //=========================================================================
1271 void wxVtkSceneManager::deleteAllBoxes()
1273 std::map<int, GObjectController*>::iterator it;
1274 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1276 GObjectController *cont = it->second;
1277 cont->removeFromScene();
1278 unregisterController((InteractorStyleMaracas*)cont);
1280 _selectedObjects.clear();
1281 _controllers.clear();
1285 //=========================================================================
1287 void wxVtkSceneManager::refreshScene()
1289 _baseView->RefreshView();
1292 //=========================================================================
1294 void wxVtkSceneManager::centerView()
1297 _baseView->GetRenderer()->GetActiveCamera()->GetFocalPoint(temp);
1298 _baseView->GetRenderer()->GetActiveCamera()->SetFocalPoint(0,0,temp[2]);
1299 _baseView->GetRenderer()->GetActiveCamera()->GetPosition(temp);
1300 _baseView->GetRenderer()->GetActiveCamera()->SetPosition(0,0,temp[2]);
1301 _baseView->RefreshView();
1305 //=========================================================================
1307 void wxVtkSceneManager::saveDiagram(std::string &content)
1311 //Print info IF COMPLEX BOX
1312 content+="COMPLEXBOX:";
1317 //Print info complex input ports
1318 std::vector<int> inputs = getComplexInputPorts();
1319 int insize = inputs.size();
1320 content+="COMPLEXINPUTS:";
1321 sprintf (buffer, "%d", insize);
1325 for(int i = 0;i<insize;i++)
1328 GObjectController *cont = _controllers[id];
1329 cont->getModel()->save(content);
1332 //Print info complex output ports
1333 std::vector<int> outputs = getComplexOutputPorts();
1334 int outsize = outputs.size();
1335 content+="COMPLEXOUTPUTS:";
1336 sprintf (buffer, "%d", outsize);
1340 for(int i = 0;i<outsize;i++)
1342 int id = outputs[i];
1343 GObjectController *cont = _controllers[id];
1344 cont->getModel()->save(content);
1353 std::vector<int> boxes = getBlackBoxes();
1354 int bsize = boxes.size();
1356 sprintf (buffer, "%d", bsize);
1360 for(int i = 0;i<bsize;i++)
1363 GObjectController *cont = _controllers[id];
1364 cont->getModel()->save(content);
1368 std::vector<int> connections = getConnections();
1369 int csize = connections.size();
1370 content+="CONNECTIONS:";
1371 sprintf (buffer, "%d", csize);
1375 for(int i = 0;i<csize;i++)
1377 int id = connections[i];
1378 GObjectController *cont = _controllers[id];
1379 cont->getModel()->save(content);
1384 //=========================================================================
1386 void wxVtkSceneManager::loadDiagram(ifstream &inputStream)
1389 std::string line="";
1390 char delims[] = ":";
1391 char *result = NULL;
1392 getline(inputStream,line);
1395 while ( !inputStream.eof() )
1397 if(line=="" || line[0]=='#')
1399 getline(inputStream,line);
1401 else if(line=="APP_START")
1412 getline(inputStream,line);//COMPLEX_BOX:TRUE|FALSE
1414 strcpy( complex, line.c_str() );
1415 result = strtok( complex, delims );
1416 result = strtok( NULL, delims );
1417 std::string isComplexBox(result);
1419 if(isComplexBox=="TRUE")
1423 //-----------------------
1424 //- COMPLEX INPUT PORTS
1425 //-----------------------
1426 getline(inputStream,line);//COMPLEXINPUTS:num
1428 strcpy( inputs, line.c_str() );
1429 result = strtok( inputs, delims );
1430 result = strtok( NULL, delims );
1433 std::istringstream inps(result);
1436 for(int i = 0;i<numInputs;i++)
1439 getline(inputStream,line);//COMPLEX_PORT
1440 getline(inputStream,line);//name
1441 std::string inputPortName(line);
1444 getline(inputStream,line);//xInic:yInic:zInic
1446 strcpy( coord, line.c_str() );
1447 result = strtok( coord, delims );//xInic
1448 std::string xInic(result);
1449 result = strtok( NULL, delims );//yInic
1450 std::string yInic(result);
1451 result = strtok( NULL, delims );//zInic
1452 std::string zInic(result);
1454 double xIn, yIn, zIn;
1455 std::istringstream xSt(xInic);
1457 std::istringstream ySt(yInic);
1459 std::istringstream zSt(zInic);
1462 getline(inputStream,line);//FIN_COMPLEX_PORT
1464 int idInputPort = createGComplexBoxInputPort(inputPortName);
1465 GObjectController *cont = _controllers[idInputPort];
1466 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
1467 cbmod->setInicPoint(xIn,yIn,zIn);
1468 cbmod->notifyObservers(_idManager);
1469 } // for input complex box
1472 //-----------------------
1473 //- COMPLEX OUTPUT PORTS
1474 //-----------------------
1476 getline(inputStream,line);//COMPLEXOUTPUTS:num
1478 strcpy( outputs, line.c_str() );
1479 result = strtok( outputs, delims );
1480 result = strtok( NULL, delims );
1483 std::istringstream outps(result);
1484 outps >> numOutputs;
1486 for(int i = 0;i<numOutputs;i++)
1489 getline(inputStream,line);//COMPLEX_PORT
1490 getline(inputStream,line);//name
1491 std::string outputPortName(line);
1494 getline(inputStream,line);//xInic:yInic:zInic
1496 strcpy( coord, line.c_str() );
1497 result = strtok( coord, delims );//xInic
1498 std::string xInic(result);
1499 result = strtok( NULL, delims );//yInic
1500 std::string yInic(result);
1501 result = strtok( NULL, delims );//zInic
1502 std::string zInic(result);
1504 double xIn, yIn, zIn;
1505 std::istringstream xSt(xInic);
1507 std::istringstream ySt(yInic);
1509 std::istringstream zSt(zInic);
1512 getline(inputStream,line);//FIN_COMPLEX_PORT
1514 int idOutputPort = createGComplexBoxOutputPort(outputPortName);
1515 GObjectController *cont = _controllers[idOutputPort];
1516 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
1517 cbmod->setInicPoint(xIn,yIn,zIn);
1518 cbmod->notifyObservers(_idManager);
1519 } // for output complex box
1524 getline(inputStream,line);//BOXES:num
1526 strcpy( boxes, line.c_str() );
1527 result = strtok( boxes, delims );
1528 result = strtok( NULL, delims );
1531 std::istringstream is(result);
1534 for(int i = 0;i<numBoxes;i++)
1537 getline(inputStream,line);//BOX
1538 getline(inputStream,line);//package:type:name
1540 strcpy( box, line.c_str() );
1541 result = strtok( box, delims );//package
1542 std::string package(result);
1543 result = strtok( NULL, delims );//type
1544 std::string type(result);
1545 result = strtok( NULL, delims );//name
1546 std::string name(result);
1548 getline(inputStream,line);//ISEXEC:TRUE|FALSE
1550 strcpy( exec, line.c_str() );
1551 result = strtok( exec, delims );//ISEXEC
1552 result = strtok( NULL, delims );//TRUE|FALSE
1553 std::string isExec(result);
1556 getline(inputStream,line);//xInic:yInic:zInic
1558 strcpy( coord, line.c_str() );
1559 result = strtok( coord, delims );//xInic
1560 std::string xInic(result);
1561 result = strtok( NULL, delims );//yInic
1562 std::string yInic(result);
1563 result = strtok( NULL, delims );//zInic
1564 std::string zInic(result);
1566 double xIn, yIn, zIn;
1567 std::istringstream xSt(xInic);
1569 std::istringstream ySt(yInic);
1571 std::istringstream zSt(zInic);
1575 getline(inputStream,line);//xEnd:yEnd:zEnd
1576 strcpy( coord, line.c_str() );
1577 result = strtok( coord, delims );//xEnd
1578 std::string xEnd(result);
1579 result = strtok( NULL, delims );//yEnd
1580 std::string yEnd(result);
1581 result = strtok( NULL, delims );//zEnd
1582 std::string zEnd(result);
1584 double xEn, yEn, zEn;
1585 std::istringstream xEt(xEnd);
1587 std::istringstream yEt(yEnd);
1589 std::istringstream zEt(zEnd);
1592 int idBox = createGBlackBox(0,0,package,type);
1593 GObjectController *cont = _controllers[idBox];
1594 GBlackBoxModel *bbmod = (GBlackBoxModel*)cont->getModel();
1595 bbmod->setBBTKName(name);
1596 bbmod->setInicPoint(xIn,yIn,zIn);
1597 bbmod->setFinalPoint(xEn,yEn,zEn);
1600 bbmod->setExecutable(true);
1602 else if(isExec=="FALSE")
1604 bbmod->setExecutable(false);
1608 getline(inputStream,line);//PORT o FIN_BOX
1609 std::string port=line.substr(0,4);
1612 getline(inputStream,line);//name:value
1614 strcpy( poort, line.c_str() );
1615 result = strtok( poort, delims );//name
1616 std::string name(result);
1617 result = strtok( NULL, delims );//value
1618 std::string value(result);
1620 bbmod->setValueToInput(name,value);
1622 getline(inputStream,line);//PORT o FIN_BOX
1623 port=line.substr(0,4);
1626 bbmod->notifyObservers(_idManager);
1631 getline(inputStream,line);//CONNECTIONS:num
1633 strcpy( conns, line.c_str() );
1634 result = strtok( conns, delims );
1635 result = strtok( NULL, delims );
1638 std::istringstream isCons(result);
1641 for(int i = 0;i<numConns;i++)
1644 getline(inputStream,line);//CONNECTION
1645 getline(inputStream,line);//Startbox.PortName:EndBox.PortName
1648 strcpy( connec, line.c_str() );
1649 result = strtok( connec, delims );
1650 std::string nameStartBox(result);
1651 result = strtok( NULL, delims );
1652 std::string nameStartPort(result);
1653 result = strtok( NULL, delims );
1654 std::string nameEndBox(result);
1655 result = strtok( NULL, delims );
1656 std::string nameEndPort(result);
1658 std::vector<int> lstB = getBlackBoxes();
1660 GPortModel *startP=NULL;
1661 GPortModel *endP=NULL;
1662 for(int j = 0;j<lstB.size();j++)
1665 GBlackBoxModel *bbMod = (GBlackBoxModel*)_controllers[idB]->getModel();
1666 if(_controllers[idB]->getModel()->getBBTKName()==nameStartBox)
1668 startP = bbMod->getOutputPort(nameStartPort);
1670 else if(_controllers[idB]->getModel()->getBBTKName()==nameEndBox)
1672 endP = bbMod->getInputPort(nameEndPort);
1680 std::vector<int> lstInputs = getComplexInputPorts();
1681 for(int j = 0;j<lstInputs.size();j++)
1683 int idB = lstInputs[j];
1684 GBoxModel *cbMod = (GBoxModel*)_controllers[idB]->getModel();
1685 if(_controllers[idB]->getModel()->getBBTKName()==nameStartBox)
1687 startP = cbMod->getOutputPort(nameStartPort);
1694 std::vector<int> lstOutputs = getComplexOutputPorts();
1695 for(int j = 0;j<lstOutputs.size();j++)
1697 int idB = lstOutputs[j];
1698 GBoxModel *cbMod = (GBoxModel*)_controllers[idB]->getModel();
1699 if(_controllers[idB]->getModel()->getBBTKName()==nameEndBox)
1701 endP = cbMod->getInputPort(nameEndPort);
1707 int idCon = createGConnector(startP);
1708 _worldState = NOTHING_HAPPENS;
1709 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
1711 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
1712 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
1713 tempp->endContourCreation();
1714 conMod->setEndPort(endP);
1715 conView->updateStartEndPoints();
1722 //=========================================================================
1724 std::vector<int> wxVtkSceneManager::getBlackBoxes()
1726 std::vector<int> vect;
1727 std::map<int, GObjectController*>::iterator it;
1728 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1730 GObjectController *cont = it->second;
1731 if(cont->getGObjectType()==GBLACKBOX)
1733 vect.push_back(cont->getId());
1739 //=========================================================================
1741 std::vector<int> wxVtkSceneManager::getComplexInputPorts()
1743 std::vector<int> vect;
1744 std::map<int, GObjectController*>::iterator it;
1745 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1747 GObjectController *cont = it->second;
1748 if(cont->getGObjectType()==GCOMPLEXINPUTPORT)
1750 vect.push_back(cont->getId());
1756 //=========================================================================
1758 std::vector<int> wxVtkSceneManager::getComplexOutputPorts()
1760 std::vector<int> vect;
1761 std::map<int, GObjectController*>::iterator it;
1762 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1764 GObjectController *cont = it->second;
1765 if(cont->getGObjectType()==GCOMPLEXOUTPUTPORT)
1767 vect.push_back(cont->getId());
1773 //=========================================================================
1775 std::vector<int> wxVtkSceneManager::getConnections()
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()==GCONNECTOR)
1784 vect.push_back(cont->getId());
1790 //=========================================================================
1792 bool wxVtkSceneManager::isComplexBox()
1794 return _isComplexBox;
1797 //=========================================================================
1799 void wxVtkSceneManager::setComplexBox(bool val)
1804 //=========================================================================
1806 int wxVtkSceneManager::addObjectController(GObjectController* objController)
1808 //Register the controller of the new object
1809 registerController((InteractorStyleMaracas*) objController);
1811 //Add the object to the objects list
1812 int newId = _contLastId;//_controllers.size();
1813 objController->setId(newId);
1814 _controllers[newId] = objController;
1819 //=========================================================================
1821 int wxVtkSceneManager::getNumSelectedObjects()
1823 return _selectedObjects.size();
1826 //=========================================================================
1828 std::map<int,GObjectController*> wxVtkSceneManager::getSelectedObjects()
1830 std::map<int,GObjectController*> mapSelected;
1832 std::map<int, GObjectController*>::iterator it;
1833 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1835 GObjectController *cont = it->second;
1836 if(cont->getGObjectType()==GBLACKBOX && cont->getView()->getState()==SELECTED)
1838 mapSelected[cont->getId()]=cont;
1842 std::map<int, GObjectController*>::iterator it2;
1843 for(it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
1845 GObjectController *cont = it2->second;
1846 if(cont->getGObjectType()==GCONNECTOR)
1848 GConnectorModel* cmod = (GConnectorModel*)cont->getModel();
1849 GBoxModel* endPortParentBox = cmod->getEndPort()->getParentBox();
1850 GBoxModel* startPortParentBox = cmod->getStartPort()->getParentBox();
1852 std::map<int, GObjectController*>::iterator iterOBJ1 = mapSelected.find(startPortParentBox->getObjectId());
1853 std::map<int, GObjectController*>::iterator iterOBJ2 = mapSelected.find(endPortParentBox->getObjectId());
1855 if(iterOBJ1 != mapSelected.end() && iterOBJ2 != mapSelected.end())
1857 int ID = cont->getId();
1858 mapSelected[ID]=cont;
1866 //=========================================================================
1868 void wxVtkSceneManager::addObjects(std::map<int,GObjectController*> objectsMap)
1871 std::map<int,int> oldIdNewIdBoxes;
1872 std::vector<int> connections;
1874 std::map<int, GObjectController*>::iterator it;
1875 for(it = objectsMap.begin(); it != objectsMap.end(); ++it)
1877 GObjectController *cont = it->second;
1878 int type = cont->getGObjectType();
1883 double xInic, yInic,zInic;
1884 GBlackBoxModel* copyBox = (GBlackBoxModel*)cont->getModel();
1885 copyBox->getInicPoint(xInic,yInic,zInic);
1886 int idBox = createGBlackBox(0,0,copyBox->getBBTKPackage(),copyBox->getBBTKType());
1888 int idcB = copyBox->getObjectId();
1889 oldIdNewIdBoxes[idcB]=idBox;
1890 cont = _controllers[idBox];
1891 GBlackBoxModel* newbox = (GBlackBoxModel*)cont->getModel();
1892 newbox->setInicPoint(xInic,yInic,zInic);
1893 int num = newbox->getNumInputPorts();
1894 for(int j=0;j<num;j++)
1896 newbox->setValueToInputPort(j,copyBox->getValueInputPort(j));
1898 newbox->notifyObservers(_idManager);
1900 else if(type==GCONNECTOR)
1902 int idCon = cont->getId();
1903 connections.push_back(idCon);
1908 for(int i = 0 ;i<connections.size();i++)
1910 int objId = connections[i];
1911 GObjectController *cont = objectsMap[objId];
1912 GConnectorModel* connectModel = (GConnectorModel*)cont->getModel();
1914 GPortModel* startPort = connectModel->getStartPort();
1915 int startPortIndex = startPort->getPosInBox();
1916 GPortModel* endPort = connectModel->getEndPort();
1917 int endPortIndex = endPort->getPosInBox();
1919 GBlackBoxModel* startPortParentBox = (GBlackBoxModel*)startPort->getParentBox();
1920 GBlackBoxModel* endPortParentBox = (GBlackBoxModel*)endPort->getParentBox();
1922 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
1923 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
1925 GBlackBoxModel* newStartBox = (GBlackBoxModel*)_controllers[idNewStartBox]->getModel();
1926 GBlackBoxModel* newEndBox = (GBlackBoxModel*)_controllers[idNewEndBox]->getModel();
1928 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
1929 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
1931 // Creates connection
1932 int idCon = createGConnector(newStartPort);
1933 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
1934 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
1935 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
1936 tempp->endContourCreation();
1937 conMod->setEndPort(newEndPort);
1938 conView->updateStartEndPoints();
1941 std::map<int, int>::iterator itIds;
1942 for(itIds = oldIdNewIdBoxes.begin(); itIds != oldIdNewIdBoxes.end(); ++itIds)
1944 int idOld = itIds->first;
1945 int idNew = itIds->second;
1947 GBlackBoxModel* oldBox = (GBlackBoxModel*)objectsMap[idOld]->getModel();
1948 GBlackBoxModel* newBox = (GBlackBoxModel*)_controllers[idNew]->getModel();
1950 std::vector<int> oldInputConnections = oldBox->getConnectedInputs();
1951 std::vector<int> oldOutputConnections = oldBox->getConnectedOutputs();
1952 std::vector<int> newInputConnections = newBox->getConnectedInputs();
1953 std::vector<int> newOutputConnections = newBox->getConnectedOutputs();
1955 for(int k = 0; k<oldInputConnections.size();k++)
1959 for(int l = 0; l<newInputConnections.size() && !exist;l++)
1961 if(oldInputConnections[k]==newInputConnections[l])
1969 //Create complex input
1970 int posInBox = oldInputConnections[k];
1971 GPortModel* inputPort = oldBox->getInputPort(posInBox);
1972 std::string inputPortName = inputPort->getBBTKName();
1973 int idInputPort = createGComplexBoxInputPort(inputPortName);
1974 GObjectController *cont = _controllers[idInputPort];
1975 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
1977 inputPort->getInicPoint(xIn,yIn,zIn);
1979 cbmod->setInicPoint(xIn,yIn,zIn);
1980 cbmod->notifyObservers(_idManager);
1982 GPortModel* inputPortEnd = newBox->getInputPort(posInBox);
1984 // Creates connection
1985 int idCon = createGConnector(cbmod->getOutputPort(0));
1986 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
1987 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
1988 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
1989 tempp->endContourCreation();
1990 conMod->setEndPort(inputPortEnd);
1991 conView->updateStartEndPoints();
1998 for(int k = 0; k<oldOutputConnections.size();k++)
2002 for(int l = 0; l<newOutputConnections.size() && !exist;l++)
2004 if(oldOutputConnections[k]==newOutputConnections[l])
2012 //Create complex output
2013 int posInBox = oldOutputConnections[k];
2014 GPortModel* outputPort = oldBox->getOutputPort(posInBox);
2015 std::string outputPortName = outputPort->getBBTKName();
2016 int idOutputPort = createGComplexBoxOutputPort(outputPortName);
2017 GObjectController *cont = _controllers[idOutputPort];
2018 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
2020 outputPort->getInicPoint(xIn,yIn,zIn);
2022 cbmod->setInicPoint(xIn,yIn,zIn);
2023 cbmod->notifyObservers(_idManager);
2025 GPortModel* outputPortEnd = newBox->getOutputPort(posInBox);
2027 // Creates connection
2028 int idCon = createGConnector(outputPortEnd);
2029 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
2030 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
2031 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
2032 tempp->endContourCreation();
2033 conMod->setEndPort(cbmod->getInputPort(0));
2034 conView->updateStartEndPoints();
2045 //=========================================================================
2047 } // EO namespace bbtk