1 /*=========================================================================
7 =========================================================================*/
9 /* ---------------------------------------------------------------------
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
14 * This software is governed by the CeCILL-B license under French law and
15 * abiding by the rules of distribution of free software. You can use,
16 * modify and/ or redistribute the software under the terms of the CeCILL-B
17 * license as circulated by CEA, CNRS and INRIA at the following URL
18 * http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
19 * or in the file LICENSE.txt.
21 * As a counterpart to the access to the source code and rights to copy,
22 * modify and redistribute granted by the license, users are provided only
23 * with a limited warranty and the software's author, the holder of the
24 * economic rights, and the successive licensors have only limited
27 * The fact that you are presently reading this means that you have had
28 * knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */
33 * \brief Class bbtk::wxVtkSceneManager .
37 #include "wxVtkSceneManager.h"
43 //=========================================================================
44 wxVtkSceneManager::wxVtkSceneManager(wxGEditorTabPanel *parent, wxVtk3DBaseView *baseView,int idManager)
46 printf ("EED %p wxVtkSceneManager()\n" , this );
57 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget((wxDropTarget*)parent);
59 _worldState=NOTHING_HAPPENS;
60 registerController(this);
66 //=========================================================================
68 void wxVtkSceneManager::disconnectDrop()
70 printf ("EED %p ~wxVtkSceneManager::disconnectDrop()\n" , this );
71 //EED02JUIN2010 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget(NULL);
72 // _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget( new tmpClasswxTextDropTarget() );
75 //=========================================================================
77 wxVtkSceneManager::~wxVtkSceneManager()
79 printf ("EED %p ~wxVtkSceneManager()\n" , this );
83 //=========================================================================
85 void wxVtkSceneManager::configureBaseView()
87 vtkInteractorStyleBaseView2D *interactorstylebaseview = vtkInteractorStyleBaseView2D::New();
89 _baseView->SetInteractorStyleBaseView(interactorstylebaseview);
91 // Important to activate the 2D interaction system
92 wxVTKRenderWindowInteractor *iren = _baseView->GetWxVTKRenderWindowInteractor();
93 interactorstylebaseview->SetInteractor ( iren );
94 iren->SetInteractorStyle(interactorstylebaseview);
95 interactorstylebaseview->SetwxVtkBaseView(_baseView);
97 _baseView->GetRenderer()->GetActiveCamera()->ParallelProjectionOn();
98 _baseView->GetRenderer()->ResetCamera(-100,100,-100,100,900,1000);
100 _baseView->GetRenderer()->SetBackground(0.9,0.9,0.9);
101 _baseView->GetRenderer()->GradientBackgroundOff();
102 _baseView->Refresh();
105 //=========================================================================
107 int wxVtkSceneManager::createGBlackBox(int x, int y, std::string packageName, std::string boxType)
109 int windowWidth=_baseView->GetRenWin()->GetSize()[0];
110 int windowHeight=_baseView->GetRenWin()->GetSize()[1];
112 int type = GBLACKBOX;
114 //Create the MVC Objects
116 GBlackBoxModel *model = (GBlackBoxModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
117 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
118 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
120 BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxType);
122 //Prepares the initial model
123 //The coordinates obtained are the following. Top-Left:x=0,y=0 Bottom-Right:x=width,y=height
126 double yy = windowHeight-y;
128 //z value is not important yet, because it is only used a parallel projection
131 _baseView->TransCoordScreenToWorld(xx,yy,zz);
132 model->setInicPoint(xx,yy,zz);
135 std::stringstream stream;
139 stream << "Box0" << _numBoxes;
143 stream << "Box" << _numBoxes;
145 std::string arraystring = stream.str();
147 model->setBBTKName(arraystring);
148 model->setBBTKType(boxType);
149 model->setBBTKPackage(packageName);
151 model->addObserver(view);
152 model->addObserver(this);
154 //Iterate and create the input ports
155 std::map<std::string, BlackBoxInputDescriptor*> descriptorInMap = descriptor->GetInputDescriptorMap();
156 std::map<std::string, BlackBoxInputDescriptor*>::iterator itInput;
159 for(itInput = descriptorInMap.begin(); itInput != descriptorInMap.end(); ++itInput)
161 BlackBoxInputDescriptor *desc = itInput->second;
162 createGInputPort(GINPUTPORT,i,model,desc);
166 //Iterate and create the output ports
167 std::map<std::string, BlackBoxOutputDescriptor*> descriptorOutMap = descriptor->GetOutputDescriptorMap();
168 std::map<std::string, BlackBoxOutputDescriptor*>::iterator itOutput;
171 for(itOutput = descriptorOutMap.begin();itOutput != descriptorOutMap.end(); ++itOutput)
173 BlackBoxOutputDescriptor *desc = itOutput->second;
174 createGOutputPort(GOUTPUTPORT,i,model,desc);
179 //Associates the view with the correspondent renderer and the model.
180 //(NOTE: Refresh is only made by the view)
181 view->setModel(model);
182 view->setBaseView(_baseView);
183 view->initVtkObjects();
185 //Associates the controller with the correspondent model and view
186 controller->setModelAndView(model,view);
188 //Resgiter change to the observers of the actual model
189 model->notifyObservers(_idManager);
191 int newId = addObjectController(controller);
196 //=========================================================================
198 int wxVtkSceneManager::createGComplexBoxInputPort(std::string inputName)
200 int windowWidth=_baseView->GetRenWin()->GetSize()[0];
201 int windowHeight=_baseView->GetRenWin()->GetSize()[1];
203 int type = GCOMPLEXINPUTPORT;
205 //Create the MVC Objects
207 GComplexBoxPortModel *model = (GComplexBoxPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
208 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
209 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
211 //Prepares the initial model
214 double yy = windowHeight-5;
216 //z value is not important yet, because it is only used a parallel projection
219 _baseView->TransCoordScreenToWorld(xx,yy,zz);
220 model->setInicPoint(xx,yy,zz);
222 model->setBBTKName(inputName);
223 model->setBBTKType("ComplexInputPort");
224 model->setComplexPortType(type);
226 model->addObserver(view);
227 model->addObserver(this);
229 //create the output port
230 GPortController* portController = createGPort(GOUTPUTPORT,inputName,"ComplexInputPort",0,model);
231 model->addOutputPort((GPortModel*)portController->getModel());
233 //Associates the view with the correspondent renderer and the model.
234 //(NOTE: Refresh is only made by the view)
235 view->setModel(model);
236 view->setBaseView(_baseView);
237 view->initVtkObjects();
239 //Associates the controller with the correspondent model and view
240 controller->setModelAndView(model,view);
242 //Resgiter change to the observers of the actual model
243 model->notifyObservers(_idManager);
245 int newId = addObjectController(controller);
249 //=========================================================================
251 int wxVtkSceneManager::createGComplexBoxOutputPort(std::string outputName)
253 int windowWidth=_baseView->GetRenWin()->GetSize()[0];
254 int windowHeight=_baseView->GetRenWin()->GetSize()[1];
256 int type = GCOMPLEXOUTPUTPORT;
258 //Create the MVC Objects
260 GComplexBoxPortModel *model = (GComplexBoxPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
261 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
262 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
264 //Prepares the initial model
267 double yy = windowHeight-5;
269 //z value is not important yet, because it is only used a parallel projection
272 _baseView->TransCoordScreenToWorld(xx,yy,zz);
273 model->setInicPoint(xx,yy,zz);
275 model->setBBTKName(outputName);
276 model->setBBTKType("ComplexOutputPort");
277 model->setComplexPortType(type);
279 model->addObserver(view);
280 model->addObserver(this);
282 //create the output port
283 GPortController* portController = createGPort(GINPUTPORT,outputName,"ComplexInputPort",0,model);
284 model->addInputPort((GPortModel*)portController->getModel());
286 //Associates the view with the correspondent renderer and the model.
287 //(NOTE: Refresh is only made by the view)
288 view->setModel(model);
289 view->setBaseView(_baseView);
290 view->initVtkObjects();
292 //Associates the controller with the correspondent model and view
293 controller->setModelAndView(model,view);
295 //Resgiter change to the observers of the actual model
296 model->notifyObservers(_idManager);
298 int newId = addObjectController(controller);
302 //=========================================================================
304 int wxVtkSceneManager::createGInputPort(int portType, int posinBox,GBoxModel *blackBox, BlackBoxInputDescriptor *desc)
306 GPortController* portController = createGPort(portType,desc->GetName(),desc->GetTypeName(),posinBox,blackBox);
307 blackBox->addInputPort((GPortModel*)portController->getModel());
308 return portController->getId();
311 //=========================================================================
313 int wxVtkSceneManager::createGOutputPort(int portType, int posinBox,GBoxModel *blackBox, BlackBoxOutputDescriptor *desc)
315 GPortController* portController = createGPort(portType,desc->GetName(),desc->GetTypeName(),posinBox,blackBox);
316 blackBox->addOutputPort((GPortModel*)portController->getModel());
317 return portController->getId();
320 //=========================================================================
322 GPortController* wxVtkSceneManager::createGPort(int portType,std::string bbtkName, std::string bbtkType, int posInBox,GBoxModel *blackBox)
326 //Create the MVC Objects
327 GPortModel *model = (GPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
328 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
329 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
331 model->registerInBox(blackBox,portType, posInBox);
333 model->setBBTKType(bbtkType);
334 model->setBBTKName(bbtkName);
336 model->addObserver(view);
337 model->addObserver(this);
339 //Associates the view with the correspondent renderer and the model.
340 //(NOTE: Refresh is only made by the view)
341 view->setModel(model);
342 view->setBaseView(_baseView);
343 view->initVtkObjects();
345 //Associates the controller with the correspondent model and view
346 controller->setModelAndView(model,view);
348 model->notifyObservers(_idManager);
350 int newId = addObjectController(controller);
352 return (GPortController*)controller;
355 //=========================================================================
357 int wxVtkSceneManager::createGConnector(GPortModel* startPort)
359 int type = GCONNECTOR;
361 manualConnectorContourController* manContourControl = new manualConnectorContourController();
362 manualConnectorContourView* manContourView = new manualConnectorContourView();
363 manualContourModel* manContourModel = new manualContourModel();
365 GConnectorController* connectorcontroller = new GConnectorController();
366 GConnectorModel* connectorModel = new GConnectorModel();
367 vtkGConnectorView* connectorView = new vtkGConnectorView();
368 connectorModel->setGObjectType(type);
370 manContourModel->SetCloseContour(false);
371 connectorModel->setStartPort(startPort);
373 manContourView->SetModel( manContourModel );
374 manContourView->SetWxVtkBaseView( _baseView );
375 manContourView->SetRange( 0.5 );
376 manContourView->SetZ( 900 );
378 manContourView->SetColorNormalContour(0, 0, 1);
379 manContourView->SetColorEditContour(0.5, 0.5, 0.5);
380 manContourView->SetColorSelectContour(1, 0.8, 0);
381 manContourView->SetWidthLine(1);
382 manContourView->SetShowText(false);
384 manContourControl->SetModelView( manContourModel , manContourView );
386 manContourControl->CreateNewManualContour();
388 manContourView->RefreshContour();
392 connectorModel->getInicPoint(x,y,z);
394 manContourControl->SetState(1);
395 manContourModel->SetCloseContour(false);
397 manContourModel->AddPoint(x,y,z);
398 manContourView->AddPoint();
400 manContourModel->AddPoint(x,y,z);
401 manContourView->AddPoint();
403 int bak= manContourControl->GetNumberOfPointsManualContour() - 1;
404 manContourControl->_bakIdPoint=bak;
405 manContourView->Refresh();
407 manContourControl->SetMoving( false );
409 connectorcontroller->setModelAndView(connectorModel,connectorView);
411 int newId = addObjectController(connectorcontroller);
413 connectorcontroller->setManualContourController(manContourControl);
414 connectorModel->setManualContourModel(manContourModel);
415 connectorView->setManualContourView(manContourView);
416 connectorView->setModel(connectorModel);
417 connectorView->setBaseView(_baseView);
420 connectorModel->addObserver(connectorView);
421 connectorModel->addObserver(this);
426 //=========================================================================
428 void wxVtkSceneManager::registerController(InteractorStyleMaracas *param)
430 vtkInteractorStyleBaseView* baseViewControlManager = (vtkInteractorStyleBaseView*)_baseView->GetInteractorStyleBaseView();
431 baseViewControlManager->AddInteractorStyleMaracas( param );
434 //=========================================================================
436 void wxVtkSceneManager::unregisterController(InteractorStyleMaracas *param)
438 vtkInteractorStyleBaseView* baseViewControlManager = (vtkInteractorStyleBaseView*)_baseView->GetInteractorStyleBaseView();
439 baseViewControlManager->RemoveInteractorStyleMaracas( param );
442 //=========================================================================
444 vtkRenderer* wxVtkSceneManager::getRenderer()
446 return _baseView->GetRenderer();
449 //=========================================================================
451 vtkRenderWindow* wxVtkSceneManager::getRenderWindow()
453 return _baseView->GetRenWin();
455 //=========================================================================
458 void wxVtkSceneManager::update(int idController,int command)
460 if(command != NO_COMMAND)
462 if(command == ADD_TO_SELECTED)
464 GObjectController* cont = _controllers[idController];
467 for (int i=0; i<_selectedObjects.size() && foundID==false; i++)
469 int id = _selectedObjects[i];
477 int id = idController;
478 _selectedObjects.push_back(id);
482 else if(command == INIT_CREATION_CONTOUR)
484 _worldState = INIT_CREATION_CONTOUR;
485 GObjectController* cont = _controllers[idController];
486 GPortModel* startOutputPort = (GPortModel*)cont->getModel();
489 // The last one is the controller of the connector
490 for(int i=0;i<_controllers.size();i++)
492 GObjectController* cont = _controllers[i];
493 if(cont->getGObjectType() == GPORT )
495 GPortModel* port = (GPortModel*)cont->getModel();
496 if(port->getPortType()==GINPUTPORT)
498 cont->SetActive(true);
502 cont->getView()->setState(NOTHING_HAPPENS);
503 cont->getModel()->notifyObservers(_idManager);
504 cont->SetActive(false);
509 cont->getView()->setState(NOTHING_HAPPENS);
510 cont->getModel()->notifyObservers(_idManager);
511 cont->SetActive(false);
515 _selectedObjects.clear();
517 createGConnector(startOutputPort);
520 else if(command == FIN_CREATION_CONTOUR && _worldState == INIT_CREATION_CONTOUR)
522 _worldState = NOTHING_HAPPENS;
523 int id = _controllers.size()-1;
524 GObjectController* cont = _controllers[id];
525 GConnectorModel* modelContour = (GConnectorModel*)cont->getModel();
527 GObjectController* finPort = _controllers[idController];
528 if(finPort->getGObjectType() == GPORT)
530 GPortModel* modelPort = (GPortModel*)finPort->getModel();
531 modelContour->setEndPort(modelPort);
534 manualConnectorContourController* manCont = ((GConnectorController*)cont)->getManualContourController();
535 manualConnectorContourView* connView = (manualConnectorContourView*)manCont->GetManualViewBaseContour();
538 for(int i=0;i<_controllers.size();i++)
540 GObjectController* cont = _controllers[i];
541 if(cont->getView()!=NULL)
543 cont->getView()->setState(NOTHING_HAPPENS);
544 cont->getModel()->notifyObservers(_idManager);
546 cont->SetActive(true);
553 //=========================================================================
555 bool wxVtkSceneManager::OnMouseMove()
558 wxVTKRenderWindowInteractor *wxVTKiren;
559 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
560 wxVTKiren->GetEventPosition(X,Y);
563 if(_worldState == DRAG_OBJECTS)
565 for (int i=0; i<_selectedObjects.size(); i++)
567 int id = _selectedObjects[i];
568 GObjectController* cont = _controllers[id];
571 cont->getView()->setStartDragging(true);
573 cont->getView()->moveObject(X,Y);
574 cont->getView()->setState(DRAG);
575 cont->getModel()->notifyObservers(_idManager);
578 std::map<int, GObjectController*>::iterator it;
580 for(it = _controllers.begin(); it != _controllers.end(); ++it)
582 GObjectController *desc = it->second;
583 if(desc->getGObjectType()==GCONNECTOR)
585 vtkGConnectorView* vconn = (vtkGConnectorView*)desc->getView();
586 vconn->updateStartEndPoints();
590 _startDragging=false;
593 else if(_worldState == NOTHING_HAPPENS || _worldState == INIT_CREATION_CONTOUR)
595 std::map<int, GObjectController*>::iterator it;
597 for(it = _controllers.begin(); it != _controllers.end(); ++it)
599 GObjectController *desc = it->second;
600 int type = desc->getGObjectType();
601 int state = desc->getView()->getState();
603 if(state == HIGHLIGHTED){
605 updateStatusBar(desc->getStatusText());
608 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
609 _parent->displayBlackBoxInfo(mod->getBBTKPackage(),mod->getBBTKType());
618 //=========================================================================
620 bool wxVtkSceneManager::OnLeftButtonDown()
622 if(_worldState==INIT_CREATION_CONTOUR)
624 bool isOverPort=false;
625 std::map<int, GObjectController*>::iterator it;
626 for(it = _controllers.begin(); it != _controllers.end() && isOverPort==false; ++it)
628 GObjectController *desc = it->second;
629 if(desc->getGObjectType()==GPORT)
631 GPortModel* portmod=(GPortModel*)desc->getModel();
632 vtkGObjectView* portView=desc->getView();
633 if(portmod->getPortType()==GINPUTPORT && portView->getState()==HIGHLIGHTED)
640 if(isOverPort==false)
642 _worldState=NOTHING_HAPPENS;
643 int lastId = _controllers.size()-1;
644 GConnectorController *connector = (GConnectorController*)_controllers[lastId];
645 connector->removeFromScene();
646 unregisterController(connector);
647 _controllers.erase(lastId);
649 for(it = _controllers.begin(); it != _controllers.end(); ++it)
651 GObjectController *desc = it->second;
652 desc->SetActive(true);
653 desc->getView()->setState(NOTHING_HAPPENS);
654 desc->getModel()->notifyObservers(_idManager);
659 if(_selectedObjects.size()!=0)
661 _worldState = DRAG_OBJECTS;
662 _startDragging = true;
664 for (int i = 0; i < _selectedObjects.size(); i++)
666 int id = _selectedObjects[i];
667 GObjectController* cont = _controllers[id];
668 cont->getView()->setState(DRAG);
669 cont->getModel()->notifyObservers(_idManager);
678 //=========================================================================
680 bool wxVtkSceneManager::OnLeftButtonUp()
682 if(_worldState == DRAG_OBJECTS)
684 _worldState = NOTHING_HAPPENS;
686 for (int i = 0; i < _selectedObjects.size(); i++)
688 int id = _selectedObjects[i];
689 GObjectController* cont = _controllers[id];
690 cont->getView()->setState(SELECTED);
691 cont->getModel()->notifyObservers(_idManager);
697 //=========================================================================
699 bool wxVtkSceneManager::OnRightButtonUp()
701 if(_worldState==INIT_CREATION_CONTOUR)
703 _worldState=NOTHING_HAPPENS;
704 int lastId = _controllers.size()-1;
705 GConnectorController *connector = (GConnectorController*)_controllers[lastId];
706 connector->removeFromScene();
707 unregisterController(connector);
708 _controllers.erase(lastId);
710 std::map<int, GObjectController*>::iterator it;
711 for(it = _controllers.begin(); it != _controllers.end(); ++it)
713 GObjectController *desc = it->second;
714 desc->SetActive(true);
715 desc->getView()->setState(NOTHING_HAPPENS);
716 desc->getModel()->notifyObservers(_idManager);
721 for (int i = 0; i < _selectedObjects.size(); i++)
723 int id = _selectedObjects[i];
724 GObjectController* cont = _controllers[id];
725 cont->SetActive(true);
726 cont->getView()->setState(NOTHING_HAPPENS);
727 cont->getModel()->notifyObservers(_idManager);
730 _selectedObjects.clear();
735 //=========================================================================
737 bool wxVtkSceneManager::OnLeftDClick()
740 wxVTKRenderWindowInteractor *wxVTKiren;
741 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
742 wxVTKiren->GetEventPosition(X,Y);
744 std::map<int, GObjectController*>::iterator it;
746 bool clickOnObject = false;
748 for(it = _controllers.begin(); it != _controllers.end() && clickOnObject==false; ++it)
750 GObjectController *cont = it->second;
751 int type = cont->getGObjectType();
753 if(cont->getView()->isPointInside(X,Y))
757 for (int i=0; i<_selectedObjects.size(); i++)
759 int id = _selectedObjects[i];
760 GObjectController* control = _controllers[id];
761 control->getView()->setState(NOTHING_HAPPENS);
763 _selectedObjects.clear();
765 GBlackBoxModel *bbmodel = (GBlackBoxModel*)cont->getModel();
766 _parent->editBlackBox(bbmodel);
768 clickOnObject = true;
772 if(clickOnObject==false)
774 //_parent->editDiagramParameters(this);
780 //=========================================================================
782 bool wxVtkSceneManager::OnChar()
784 char keyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
786 // KeyCode 127 : Delete Key
787 // KeyCode 8 : Backspace Key
788 if(keyCode == 8 || keyCode == 127)
790 if(_selectedObjects.size()>0)
792 for(int i=0;i<_selectedObjects.size();i++)
794 int id = _selectedObjects[i];
797 _selectedObjects.clear();
804 //=========================================================================
806 void wxVtkSceneManager::deleteObject(int id)
808 GObjectController *control = _controllers[id];
809 std::vector<int> controllersToRemove;
811 if(control->getGObjectType()==GBLACKBOX || control->getGObjectType()==GCOMPLEXINPUTPORT || control->getGObjectType()==GCOMPLEXOUTPUTPORT)
813 GBoxModel *bbmod = (GBoxModel*)control->getModel();
814 std::vector<GPortModel*> inputs = bbmod->getInputPorts();
816 bool boxConnected = false;
818 // Add box input controllers to be removed
819 for(int i = 0;i<inputs.size();i++)
821 controllersToRemove.push_back(inputs[i]->getObjectId());
822 if(inputs[i]->isConnected())
828 std::vector<GPortModel*> outputs = bbmod->getOutputPorts();
830 // Add box output controllers to be removed
831 for(int i = 0;i<outputs.size();i++)
833 controllersToRemove.push_back(outputs[i]->getObjectId());
834 if(outputs[i]->isConnected())
840 // Add connection controllers to be removed
841 std::map<int, GObjectController*>::iterator it;
842 for(it = _controllers.begin(); it != _controllers.end(); ++it)
844 GObjectController *cont = it->second;
845 int type = cont->getGObjectType();
848 GConnectorModel *conMod = (GConnectorModel*)cont->getModel();
849 if(conMod->getStartPort()!=NULL && conMod->getStartPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
851 controllersToRemove.push_back(conMod->getObjectId());
853 if(conMod->getEndPort()!=NULL && conMod->getEndPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
855 controllersToRemove.push_back(conMod->getObjectId());
860 // Add box controller to be removed
861 controllersToRemove.push_back(bbmod->getObjectId());
863 else if(control->getGObjectType()==GCONNECTOR)
865 GConnectorModel *conMod = (GConnectorModel*)control->getModel();
866 controllersToRemove.push_back(conMod->getObjectId());
869 for(int i = 0;i<controllersToRemove.size();i++)
871 int id = controllersToRemove[i];
872 GObjectController *cont = _controllers[id];
873 cont->removeFromScene();
874 unregisterController((InteractorStyleMaracas*)cont);
875 _controllers.erase(id);
881 //=========================================================================
883 void wxVtkSceneManager::displayBlackBoxInfo(std::string packageName, std::string boxName)
885 _parent->displayBlackBoxInfo(packageName,boxName);
888 //=========================================================================
890 void wxVtkSceneManager::updateStatusBar(std::string textStatus)
892 _parent->updateStatusBar(textStatus);
895 //=========================================================================
897 std::string wxVtkSceneManager::getDiagramBBS()
899 bool existsExec=false;
901 std::vector<std::string> packages;
902 std::vector<int> boxes;
903 std::vector<int> connections;
904 std::vector<int> execBoxes;
906 std::map<int, GObjectController*>::iterator it;
908 for(it = _controllers.begin(); it != _controllers.end(); ++it)
910 GObjectController *desc = it->second;
911 int type = desc->getGObjectType();
915 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
917 std::string pkg = mod->getBBTKPackage();
918 bool existsPkg = false;
919 for(int t = 0;t<packages.size() && existsPkg == false;t++)
928 packages.push_back(pkg);
932 boxes.push_back(it->first);
933 if(mod->isExecutable())
935 execBoxes.push_back(it->first);
939 else if(type==GCONNECTOR)
941 connections.push_back(it->first);
945 std::string script = "";
946 script+="# BBTK GEditor Script\n";
947 script+="# ----------------------\n";
950 script+="include std\n"; // EED
951 script+="include itkvtk\n"; // EED
953 for(i = 0; i<packages.size();i++)
960 // script+="include std\n"; // JPR
962 for(i = 0; i<boxes.size();i++)
966 GObjectController *control = _controllers[id];
967 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
969 script+=model->getBBTKType();
971 script+=model->getBBTKName();
974 std::vector<GPortModel*> inputs = model->getInputPorts();
975 for(int j = 0; j<inputs.size();j++)
977 GPortModel* inputPort = inputs[j];
978 if(inputPort->isValueSet())
981 script+=model->getBBTKName();
983 script+=inputPort->getBBTKName();
985 script+=inputPort->getValue();
992 for(i = 0; i<connections.size();i++)
995 int id = connections[i];
996 GObjectController *control = _controllers[id];
997 GConnectorModel *model = (GConnectorModel*)control->getModel();
999 //Start Connection info
1000 GPortModel *start = model->getStartPort();
1001 script+=start->getParentBox()->getBBTKName();
1003 script+=start->getBBTKName();
1007 //End Connection info
1008 GPortModel *end = model->getEndPort();
1009 script+=end->getParentBox()->getBBTKName();
1011 script+=end->getBBTKName();
1016 for(i = 0; i<execBoxes.size();i++)
1019 int id = execBoxes[i];
1020 GObjectController *control = _controllers[id];
1021 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1023 script+=model->getBBTKName();
1032 //=========================================================================
1034 std::string wxVtkSceneManager::saveComplexBoxBBS(std::string cbName,std::string cbAuthor,std::string cbCategory,std::string cbDescription)
1037 std::vector<std::string> packages;
1038 std::vector<int> boxes;
1039 std::vector<int> connections;
1040 std::vector<int> execBoxes;
1042 std::map<int, GObjectController*>::iterator it;
1044 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1046 GObjectController *desc = it->second;
1047 int type = desc->getGObjectType();
1051 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
1053 std::string pkg = mod->getBBTKPackage();
1054 bool existsPkg = false;
1055 for(int t = 0;t<packages.size() && existsPkg == false;t++)
1057 if(packages[t]==pkg)
1064 packages.push_back(pkg);
1068 boxes.push_back(it->first);
1069 if(mod->isExecutable())
1071 execBoxes.push_back(it->first);
1074 else if(type==GCONNECTOR)
1076 connections.push_back(it->first);
1080 std::string script = "";
1082 script+="include std\n"; // EED
1083 script+="include itkvtk\n"; // EED
1085 for(i = 0; i<packages.size();i++)
1088 script+=packages[i];
1092 // Definition of a complex box
1097 script+="author \" ";
1101 script+="description \" ";
1102 script+=cbDescription;
1106 for(i = 0; i<boxes.size();i++)
1110 GObjectController *control = _controllers[id];
1111 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1113 script+=model->getBBTKType();
1115 script+=model->getBBTKName();
1118 std::vector<GPortModel*> inputs = model->getInputPorts();
1119 for(int j = 0; j<inputs.size();j++)
1121 GPortModel* inputPort = inputs[j];
1122 if(inputPort->isValueSet())
1125 script+=model->getBBTKName();
1127 script+=inputPort->getBBTKName();
1129 script+=inputPort->getValue();
1136 // Create connections in the script. If the connection is made with a complex port, it is created the input or output
1138 std::string complexInputs="";
1139 std::string complexOutputs="";
1141 for(i = 0; i<connections.size();i++)
1143 int id = connections[i];
1144 GObjectController *control = _controllers[id];
1145 GConnectorModel *model = (GConnectorModel*)control->getModel();
1148 GPortModel *start = model->getStartPort();
1149 GBoxModel *startBox =start->getParentBox();
1151 GPortModel *end = model->getEndPort();
1152 GBoxModel *endBox =end->getParentBox();
1154 if(startBox->getGObjectType()==GCOMPLEXINPUTPORT)
1156 complexInputs+="input ";
1157 complexInputs+=startBox->getBBTKName();
1160 complexInputs+=endBox->getBBTKName();
1162 complexInputs+=end->getBBTKName();
1165 complexInputs+="\" \"";
1167 complexInputs+="\n";
1169 else if(endBox->getGObjectType()==GCOMPLEXOUTPUTPORT)
1171 complexOutputs+="output ";
1172 complexOutputs+=endBox->getBBTKName();
1174 complexOutputs+=" ";
1175 complexOutputs+=startBox->getBBTKName();
1176 complexOutputs+=".";
1177 complexOutputs+=start->getBBTKName();
1179 complexOutputs+=" ";
1180 complexOutputs+="\" \"";
1182 complexOutputs+="\n";
1187 script+=startBox->getBBTKName();
1189 script+=start->getBBTKName();
1193 //End Connection info
1194 script+=endBox->getBBTKName();
1196 script+=end->getBBTKName();
1202 for(i = 0; i<execBoxes.size();i++)
1205 int id = execBoxes[i];
1206 GObjectController *control = _controllers[id];
1207 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1209 script+=model->getBBTKName();
1214 script+="# Complex input ports\n";
1215 script+=complexInputs;
1218 script+="# Complex output ports\n";
1219 script+=complexOutputs;
1228 //=========================================================================
1230 void wxVtkSceneManager::deleteAllBoxes()
1232 std::map<int, GObjectController*>::iterator it;
1233 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1235 GObjectController *cont = it->second;
1236 cont->removeFromScene();
1237 unregisterController((InteractorStyleMaracas*)cont);
1239 _selectedObjects.clear();
1240 _controllers.clear();
1244 //=========================================================================
1246 void wxVtkSceneManager::refreshScene()
1248 _baseView->RefreshView();
1251 //=========================================================================
1253 void wxVtkSceneManager::centerView()
1256 _baseView->GetRenderer()->GetActiveCamera()->GetFocalPoint(temp);
1257 _baseView->GetRenderer()->GetActiveCamera()->SetFocalPoint(0,0,temp[2]);
1258 _baseView->GetRenderer()->GetActiveCamera()->GetPosition(temp);
1259 _baseView->GetRenderer()->GetActiveCamera()->SetPosition(0,0,temp[2]);
1260 _baseView->RefreshView();
1264 //=========================================================================
1266 void wxVtkSceneManager::saveDiagram(std::string &content)
1270 //Print info IF COMPLEX BOX
1271 content+="COMPLEXBOX:";
1276 //Print info complex input ports
1277 std::vector<int> inputs = getComplexInputPorts();
1278 int insize = inputs.size();
1279 content+="COMPLEXINPUTS:";
1280 sprintf (buffer, "%d", insize);
1284 for(int i = 0;i<insize;i++)
1287 GObjectController *cont = _controllers[id];
1288 cont->getModel()->save(content);
1291 //Print info complex output ports
1292 std::vector<int> outputs = getComplexOutputPorts();
1293 int outsize = outputs.size();
1294 content+="COMPLEXOUTPUTS:";
1295 sprintf (buffer, "%d", outsize);
1299 for(int i = 0;i<outsize;i++)
1301 int id = outputs[i];
1302 GObjectController *cont = _controllers[id];
1303 cont->getModel()->save(content);
1312 std::vector<int> boxes = getBlackBoxes();
1313 int bsize = boxes.size();
1315 sprintf (buffer, "%d", bsize);
1319 for(int i = 0;i<bsize;i++)
1322 GObjectController *cont = _controllers[id];
1323 cont->getModel()->save(content);
1327 std::vector<int> connections = getConnections();
1328 int csize = connections.size();
1329 content+="CONNECTIONS:";
1330 sprintf (buffer, "%d", csize);
1334 for(int i = 0;i<csize;i++)
1336 int id = connections[i];
1337 GObjectController *cont = _controllers[id];
1338 cont->getModel()->save(content);
1343 //=========================================================================
1345 void wxVtkSceneManager::loadDiagram(ifstream &inputStream)
1348 std::string line="";
1349 char delims[] = ":";
1350 char *result = NULL;
1351 getline(inputStream,line);
1354 while ( !inputStream.eof() )
1356 if(line=="" || line[0]=='#')
1358 getline(inputStream,line);
1360 else if(line=="APP_START")
1371 getline(inputStream,line);//COMPLEX_BOX:TRUE|FALSE
1373 strcpy( complex, line.c_str() );
1374 result = strtok( complex, delims );
1375 result = strtok( NULL, delims );
1376 std::string isComplexBox(result);
1378 if(isComplexBox=="TRUE")
1382 //-----------------------
1383 //- COMPLEX INPUT PORTS
1384 //-----------------------
1385 getline(inputStream,line);//COMPLEXINPUTS:num
1387 strcpy( inputs, line.c_str() );
1388 result = strtok( inputs, delims );
1389 result = strtok( NULL, delims );
1392 std::istringstream inps(result);
1395 for(int i = 0;i<numInputs;i++)
1398 getline(inputStream,line);//COMPLEX_PORT
1399 getline(inputStream,line);//name
1400 std::string inputPortName(line);
1403 getline(inputStream,line);//xInic:yInic:zInic
1405 strcpy( coord, line.c_str() );
1406 result = strtok( coord, delims );//xInic
1407 std::string xInic(result);
1408 result = strtok( NULL, delims );//yInic
1409 std::string yInic(result);
1410 result = strtok( NULL, delims );//zInic
1411 std::string zInic(result);
1413 double xIn, yIn, zIn;
1414 std::istringstream xSt(xInic);
1416 std::istringstream ySt(yInic);
1418 std::istringstream zSt(zInic);
1421 getline(inputStream,line);//FIN_COMPLEX_PORT
1423 int idInputPort = createGComplexBoxInputPort(inputPortName);
1424 GObjectController *cont = _controllers[idInputPort];
1425 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
1426 cbmod->setInicPoint(xIn,yIn,zIn);
1427 cbmod->notifyObservers(_idManager);
1431 //-----------------------
1432 //- COMPLEX OUTPUT PORTS
1433 //-----------------------
1435 getline(inputStream,line);//COMPLEXOUTPUTS:num
1437 strcpy( outputs, line.c_str() );
1438 result = strtok( outputs, delims );
1439 result = strtok( NULL, delims );
1442 std::istringstream outps(result);
1443 outps >> numOutputs;
1445 for(int i = 0;i<numOutputs;i++)
1448 getline(inputStream,line);//COMPLEX_PORT
1449 getline(inputStream,line);//name
1450 std::string outputPortName(line);
1453 getline(inputStream,line);//xInic:yInic:zInic
1455 strcpy( coord, line.c_str() );
1456 result = strtok( coord, delims );//xInic
1457 std::string xInic(result);
1458 result = strtok( NULL, delims );//yInic
1459 std::string yInic(result);
1460 result = strtok( NULL, delims );//zInic
1461 std::string zInic(result);
1463 double xIn, yIn, zIn;
1464 std::istringstream xSt(xInic);
1466 std::istringstream ySt(yInic);
1468 std::istringstream zSt(zInic);
1471 getline(inputStream,line);//FIN_COMPLEX_PORT
1473 int idOutputPort = createGComplexBoxOutputPort(outputPortName);
1474 GObjectController *cont = _controllers[idOutputPort];
1475 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
1476 cbmod->setInicPoint(xIn,yIn,zIn);
1477 cbmod->notifyObservers(_idManager);
1483 getline(inputStream,line);//BOXES:num
1485 strcpy( boxes, line.c_str() );
1486 result = strtok( boxes, delims );
1487 result = strtok( NULL, delims );
1490 std::istringstream is(result);
1493 for(int i = 0;i<numBoxes;i++)
1496 getline(inputStream,line);//BOX
1497 getline(inputStream,line);//package:type:name
1499 strcpy( box, line.c_str() );
1500 result = strtok( box, delims );//package
1501 std::string package(result);
1502 result = strtok( NULL, delims );//type
1503 std::string type(result);
1504 result = strtok( NULL, delims );//name
1505 std::string name(result);
1507 getline(inputStream,line);//ISEXEC:TRUE|FALSE
1509 strcpy( exec, line.c_str() );
1510 result = strtok( exec, delims );//ISEXEC
1511 result = strtok( NULL, delims );//TRUE|FALSE
1512 std::string isExec(result);
1515 getline(inputStream,line);//xInic:yInic:zInic
1517 strcpy( coord, line.c_str() );
1518 result = strtok( coord, delims );//xInic
1519 std::string xInic(result);
1520 result = strtok( NULL, delims );//yInic
1521 std::string yInic(result);
1522 result = strtok( NULL, delims );//zInic
1523 std::string zInic(result);
1525 double xIn, yIn, zIn;
1526 std::istringstream xSt(xInic);
1528 std::istringstream ySt(yInic);
1530 std::istringstream zSt(zInic);
1534 getline(inputStream,line);//xEnd:yEnd:zEnd
1535 strcpy( coord, line.c_str() );
1536 result = strtok( coord, delims );//xEnd
1537 std::string xEnd(result);
1538 result = strtok( NULL, delims );//yEnd
1539 std::string yEnd(result);
1540 result = strtok( NULL, delims );//zEnd
1541 std::string zEnd(result);
1543 double xEn, yEn, zEn;
1544 std::istringstream xEt(xEnd);
1546 std::istringstream yEt(yEnd);
1548 std::istringstream zEt(zEnd);
1551 int idBox = createGBlackBox(0,0,package,type);
1552 GObjectController *cont = _controllers[idBox];
1553 GBlackBoxModel *bbmod = (GBlackBoxModel*)cont->getModel();
1554 bbmod->setBBTKName(name);
1555 bbmod->setInicPoint(xIn,yIn,zIn);
1556 bbmod->setFinalPoint(xEn,yEn,zEn);
1559 bbmod->setExecutable(true);
1561 else if(isExec=="FALSE")
1563 bbmod->setExecutable(false);
1567 getline(inputStream,line);//PORT o FIN_BOX
1568 std::string port=line.substr(0,4);
1571 getline(inputStream,line);//name:value
1573 strcpy( poort, line.c_str() );
1574 result = strtok( poort, delims );//name
1575 std::string name(result);
1576 result = strtok( NULL, delims );//value
1577 std::string value(result);
1579 bbmod->setValueToInput(name,value);
1581 getline(inputStream,line);//PORT o FIN_BOX
1582 port=line.substr(0,4);
1585 bbmod->notifyObservers(_idManager);
1590 getline(inputStream,line);//CONNECTIONS:num
1592 strcpy( conns, line.c_str() );
1593 result = strtok( conns, delims );
1594 result = strtok( NULL, delims );
1597 std::istringstream isCons(result);
1600 for(int i = 0;i<numConns;i++)
1603 getline(inputStream,line);//CONNECTION
1604 getline(inputStream,line);//Startbox.PortName:EndBox.PortName
1607 strcpy( connec, line.c_str() );
1608 result = strtok( connec, delims );
1609 std::string nameStartBox(result);
1610 result = strtok( NULL, delims );
1611 std::string nameStartPort(result);
1612 result = strtok( NULL, delims );
1613 std::string nameEndBox(result);
1614 result = strtok( NULL, delims );
1615 std::string nameEndPort(result);
1617 std::vector<int> lstB = getBlackBoxes();
1619 GPortModel *startP=NULL;
1620 GPortModel *endP=NULL;
1621 for(int j = 0;j<lstB.size();j++)
1624 GBlackBoxModel *bbMod = (GBlackBoxModel*)_controllers[idB]->getModel();
1625 if(_controllers[idB]->getModel()->getBBTKName()==nameStartBox)
1627 startP = bbMod->getOutputPort(nameStartPort);
1629 else if(_controllers[idB]->getModel()->getBBTKName()==nameEndBox)
1631 endP = bbMod->getInputPort(nameEndPort);
1639 std::vector<int> lstInputs = getComplexInputPorts();
1640 for(int j = 0;j<lstInputs.size();j++)
1642 int idB = lstInputs[j];
1643 GBoxModel *cbMod = (GBoxModel*)_controllers[idB]->getModel();
1644 if(_controllers[idB]->getModel()->getBBTKName()==nameStartBox)
1646 startP = cbMod->getOutputPort(nameStartPort);
1653 std::vector<int> lstOutputs = getComplexOutputPorts();
1654 for(int j = 0;j<lstOutputs.size();j++)
1656 int idB = lstOutputs[j];
1657 GBoxModel *cbMod = (GBoxModel*)_controllers[idB]->getModel();
1658 if(_controllers[idB]->getModel()->getBBTKName()==nameEndBox)
1660 endP = cbMod->getInputPort(nameEndPort);
1666 int idCon = createGConnector(startP);
1667 _worldState = NOTHING_HAPPENS;
1668 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
1670 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
1671 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
1672 tempp->endContourCreation();
1673 conMod->setEndPort(endP);
1674 conView->updateStartEndPoints();
1681 //=========================================================================
1683 std::vector<int> wxVtkSceneManager::getBlackBoxes()
1685 std::vector<int> vect;
1686 std::map<int, GObjectController*>::iterator it;
1687 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1689 GObjectController *cont = it->second;
1690 if(cont->getGObjectType()==GBLACKBOX)
1692 vect.push_back(cont->getId());
1698 //=========================================================================
1700 std::vector<int> wxVtkSceneManager::getComplexInputPorts()
1702 std::vector<int> vect;
1703 std::map<int, GObjectController*>::iterator it;
1704 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1706 GObjectController *cont = it->second;
1707 if(cont->getGObjectType()==GCOMPLEXINPUTPORT)
1709 vect.push_back(cont->getId());
1715 //=========================================================================
1717 std::vector<int> wxVtkSceneManager::getComplexOutputPorts()
1719 std::vector<int> vect;
1720 std::map<int, GObjectController*>::iterator it;
1721 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1723 GObjectController *cont = it->second;
1724 if(cont->getGObjectType()==GCOMPLEXOUTPUTPORT)
1726 vect.push_back(cont->getId());
1732 //=========================================================================
1734 std::vector<int> wxVtkSceneManager::getConnections()
1736 std::vector<int> vect;
1737 std::map<int, GObjectController*>::iterator it;
1738 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1740 GObjectController *cont = it->second;
1741 if(cont->getGObjectType()==GCONNECTOR)
1743 vect.push_back(cont->getId());
1749 //=========================================================================
1751 bool wxVtkSceneManager::isComplexBox()
1753 return _isComplexBox;
1756 //=========================================================================
1758 void wxVtkSceneManager::setComplexBox(bool val)
1763 //=========================================================================
1765 int wxVtkSceneManager::addObjectController(GObjectController* objController)
1767 //Register the controller of the new object
1768 registerController((InteractorStyleMaracas*) objController);
1770 //Add the object to the objects list
1771 int newId = _controllers.size();
1772 objController->setId(newId);
1773 _controllers[newId] = objController;
1777 //=========================================================================
1779 int wxVtkSceneManager::getNumSelectedObjects()
1781 return _selectedObjects.size();
1784 //=========================================================================
1786 std::map<int,GObjectController*> wxVtkSceneManager::getSelectedObjects()
1788 std::map<int,GObjectController*> mapSelected;
1790 std::map<int, GObjectController*>::iterator it;
1791 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1793 GObjectController *cont = it->second;
1794 if(cont->getGObjectType()==GBLACKBOX && cont->getView()->getState()==SELECTED)
1796 mapSelected[cont->getId()]=cont;
1800 std::map<int, GObjectController*>::iterator it2;
1801 for(it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
1803 GObjectController *cont = it2->second;
1804 if(cont->getGObjectType()==GCONNECTOR)
1806 GConnectorModel* cmod = (GConnectorModel*)cont->getModel();
1807 GBoxModel* endPortParentBox = cmod->getEndPort()->getParentBox();
1808 GBoxModel* startPortParentBox = cmod->getStartPort()->getParentBox();
1810 std::map<int, GObjectController*>::iterator iterOBJ1 = mapSelected.find(startPortParentBox->getObjectId());
1811 std::map<int, GObjectController*>::iterator iterOBJ2 = mapSelected.find(endPortParentBox->getObjectId());
1813 if(iterOBJ1 != mapSelected.end() && iterOBJ2 != mapSelected.end())
1815 int ID = cont->getId();
1816 mapSelected[ID]=cont;
1824 //=========================================================================
1826 void wxVtkSceneManager::addObjects(std::map<int,GObjectController*> objectsMap)
1829 std::map<int,int> oldIdNewIdBoxes;
1830 std::vector<int> connections;
1832 std::map<int, GObjectController*>::iterator it;
1833 for(it = objectsMap.begin(); it != objectsMap.end(); ++it)
1835 GObjectController *cont = it->second;
1836 int type = cont->getGObjectType();
1841 double xInic, yInic,zInic;
1842 GBlackBoxModel* copyBox = (GBlackBoxModel*)cont->getModel();
1843 copyBox->getInicPoint(xInic,yInic,zInic);
1844 int idBox = createGBlackBox(0,0,copyBox->getBBTKPackage(),copyBox->getBBTKType());
1846 int idcB = copyBox->getObjectId();
1847 oldIdNewIdBoxes[idcB]=idBox;
1848 cont = _controllers[idBox];
1849 GBlackBoxModel* newbox = (GBlackBoxModel*)cont->getModel();
1850 newbox->setInicPoint(xInic,yInic,zInic);
1851 int num = newbox->getNumInputPorts();
1852 for(int j=0;j<num;j++)
1854 newbox->setValueToInputPort(j,copyBox->getValueInputPort(j));
1856 newbox->notifyObservers(_idManager);
1858 else if(type==GCONNECTOR)
1860 int idCon = cont->getId();
1861 connections.push_back(idCon);
1866 for(int i = 0 ;i<connections.size();i++)
1868 int objId = connections[i];
1869 GObjectController *cont = objectsMap[objId];
1870 GConnectorModel* connectModel = (GConnectorModel*)cont->getModel();
1872 GPortModel* startPort = connectModel->getStartPort();
1873 int startPortIndex = startPort->getPosInBox();
1874 GPortModel* endPort = connectModel->getEndPort();
1875 int endPortIndex = endPort->getPosInBox();
1877 GBlackBoxModel* startPortParentBox = (GBlackBoxModel*)startPort->getParentBox();
1878 GBlackBoxModel* endPortParentBox = (GBlackBoxModel*)endPort->getParentBox();
1880 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
1881 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
1883 GBlackBoxModel* newStartBox = (GBlackBoxModel*)_controllers[idNewStartBox]->getModel();
1884 GBlackBoxModel* newEndBox = (GBlackBoxModel*)_controllers[idNewEndBox]->getModel();
1886 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
1887 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
1889 // Creates connection
1890 int idCon = createGConnector(newStartPort);
1891 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
1892 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
1893 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
1894 tempp->endContourCreation();
1895 conMod->setEndPort(newEndPort);
1896 conView->updateStartEndPoints();
1899 std::map<int, int>::iterator itIds;
1900 for(itIds = oldIdNewIdBoxes.begin(); itIds != oldIdNewIdBoxes.end(); ++itIds)
1902 int idOld = itIds->first;
1903 int idNew = itIds->second;
1905 GBlackBoxModel* oldBox = (GBlackBoxModel*)objectsMap[idOld]->getModel();
1906 GBlackBoxModel* newBox = (GBlackBoxModel*)_controllers[idNew]->getModel();
1908 std::vector<int> oldInputConnections = oldBox->getConnectedInputs();
1909 std::vector<int> oldOutputConnections = oldBox->getConnectedOutputs();
1910 std::vector<int> newInputConnections = newBox->getConnectedInputs();
1911 std::vector<int> newOutputConnections = newBox->getConnectedOutputs();
1913 for(int k = 0; k<oldInputConnections.size();k++)
1917 for(int l = 0; l<newInputConnections.size() && !exist;l++)
1919 if(oldInputConnections[k]==newInputConnections[l])
1927 //Create complex input
1928 int posInBox = oldInputConnections[k];
1929 GPortModel* inputPort = oldBox->getInputPort(posInBox);
1930 std::string inputPortName = inputPort->getBBTKName();
1931 int idInputPort = createGComplexBoxInputPort(inputPortName);
1932 GObjectController *cont = _controllers[idInputPort];
1933 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
1935 inputPort->getInicPoint(xIn,yIn,zIn);
1937 cbmod->setInicPoint(xIn,yIn,zIn);
1938 cbmod->notifyObservers(_idManager);
1940 GPortModel* inputPortEnd = newBox->getInputPort(posInBox);
1942 // Creates connection
1943 int idCon = createGConnector(cbmod->getOutputPort(0));
1944 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
1945 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
1946 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
1947 tempp->endContourCreation();
1948 conMod->setEndPort(inputPortEnd);
1949 conView->updateStartEndPoints();
1956 for(int k = 0; k<oldOutputConnections.size();k++)
1960 for(int l = 0; l<newOutputConnections.size() && !exist;l++)
1962 if(oldOutputConnections[k]==newOutputConnections[l])
1970 //Create complex output
1971 int posInBox = oldOutputConnections[k];
1972 GPortModel* outputPort = oldBox->getOutputPort(posInBox);
1973 std::string outputPortName = outputPort->getBBTKName();
1974 int idOutputPort = createGComplexBoxOutputPort(outputPortName);
1975 GObjectController *cont = _controllers[idOutputPort];
1976 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
1978 outputPort->getInicPoint(xIn,yIn,zIn);
1980 cbmod->setInicPoint(xIn,yIn,zIn);
1981 cbmod->notifyObservers(_idManager);
1983 GPortModel* outputPortEnd = newBox->getOutputPort(posInBox);
1985 // Creates connection
1986 int idCon = createGConnector(outputPortEnd);
1987 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
1988 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
1989 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
1990 tempp->endContourCreation();
1991 conMod->setEndPort(cbmod->getInputPort(0));
1992 conView->updateStartEndPoints();
2003 //=========================================================================
2005 } // EO namespace bbtk