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";
951 for(i = 0; i<packages.size();i++)
958 script+="include std\n";
960 for(i = 0; i<boxes.size();i++)
964 GObjectController *control = _controllers[id];
965 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
967 script+=model->getBBTKType();
969 script+=model->getBBTKName();
972 std::vector<GPortModel*> inputs = model->getInputPorts();
973 for(int j = 0; j<inputs.size();j++)
975 GPortModel* inputPort = inputs[j];
976 if(inputPort->isValueSet())
979 script+=model->getBBTKName();
981 script+=inputPort->getBBTKName();
983 script+=inputPort->getValue();
990 for(i = 0; i<connections.size();i++)
993 int id = connections[i];
994 GObjectController *control = _controllers[id];
995 GConnectorModel *model = (GConnectorModel*)control->getModel();
997 //Start Connection info
998 GPortModel *start = model->getStartPort();
999 script+=start->getParentBox()->getBBTKName();
1001 script+=start->getBBTKName();
1005 //End Connection info
1006 GPortModel *end = model->getEndPort();
1007 script+=end->getParentBox()->getBBTKName();
1009 script+=end->getBBTKName();
1014 for(i = 0; i<execBoxes.size();i++)
1017 int id = execBoxes[i];
1018 GObjectController *control = _controllers[id];
1019 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1021 script+=model->getBBTKName();
1030 //=========================================================================
1032 std::string wxVtkSceneManager::saveComplexBoxBBS(std::string cbName,std::string cbAuthor,std::string cbCategory,std::string cbDescription)
1035 std::vector<std::string> packages;
1036 std::vector<int> boxes;
1037 std::vector<int> connections;
1038 std::vector<int> execBoxes;
1040 std::map<int, GObjectController*>::iterator it;
1042 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1044 GObjectController *desc = it->second;
1045 int type = desc->getGObjectType();
1049 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
1051 std::string pkg = mod->getBBTKPackage();
1052 bool existsPkg = false;
1053 for(int t = 0;t<packages.size() && existsPkg == false;t++)
1055 if(packages[t]==pkg)
1062 packages.push_back(pkg);
1066 boxes.push_back(it->first);
1067 if(mod->isExecutable())
1069 execBoxes.push_back(it->first);
1072 else if(type==GCONNECTOR)
1074 connections.push_back(it->first);
1078 std::string script = "";
1080 for(i = 0; i<packages.size();i++)
1083 script+=packages[i];
1087 script+="include std\n";
1089 // Definition of a complex box
1094 script+="author \" ";
1098 script+="description \" ";
1099 script+=cbDescription;
1103 for(i = 0; i<boxes.size();i++)
1107 GObjectController *control = _controllers[id];
1108 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1110 script+=model->getBBTKType();
1112 script+=model->getBBTKName();
1115 std::vector<GPortModel*> inputs = model->getInputPorts();
1116 for(int j = 0; j<inputs.size();j++)
1118 GPortModel* inputPort = inputs[j];
1119 if(inputPort->isValueSet())
1122 script+=model->getBBTKName();
1124 script+=inputPort->getBBTKName();
1126 script+=inputPort->getValue();
1133 // Create connections in the script. If the connection is made with a complex port, it is created the input or output
1135 std::string complexInputs="";
1136 std::string complexOutputs="";
1138 for(i = 0; i<connections.size();i++)
1140 int id = connections[i];
1141 GObjectController *control = _controllers[id];
1142 GConnectorModel *model = (GConnectorModel*)control->getModel();
1145 GPortModel *start = model->getStartPort();
1146 GBoxModel *startBox =start->getParentBox();
1148 GPortModel *end = model->getEndPort();
1149 GBoxModel *endBox =end->getParentBox();
1151 if(startBox->getGObjectType()==GCOMPLEXINPUTPORT)
1153 complexInputs+="input ";
1154 complexInputs+=startBox->getBBTKName();
1157 complexInputs+=endBox->getBBTKName();
1159 complexInputs+=end->getBBTKName();
1162 complexInputs+="\" \"";
1164 complexInputs+="\n";
1166 else if(endBox->getGObjectType()==GCOMPLEXOUTPUTPORT)
1168 complexOutputs+="output ";
1169 complexOutputs+=endBox->getBBTKName();
1171 complexOutputs+=" ";
1172 complexOutputs+=startBox->getBBTKName();
1173 complexOutputs+=".";
1174 complexOutputs+=start->getBBTKName();
1176 complexOutputs+=" ";
1177 complexOutputs+="\" \"";
1179 complexOutputs+="\n";
1184 script+=startBox->getBBTKName();
1186 script+=start->getBBTKName();
1190 //End Connection info
1191 script+=endBox->getBBTKName();
1193 script+=end->getBBTKName();
1199 for(i = 0; i<execBoxes.size();i++)
1202 int id = execBoxes[i];
1203 GObjectController *control = _controllers[id];
1204 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1206 script+=model->getBBTKName();
1211 script+="# Complex input ports\n";
1212 script+=complexInputs;
1215 script+="# Complex output ports\n";
1216 script+=complexOutputs;
1225 //=========================================================================
1227 void wxVtkSceneManager::deleteAllBoxes()
1229 std::map<int, GObjectController*>::iterator it;
1230 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1232 GObjectController *cont = it->second;
1233 cont->removeFromScene();
1234 unregisterController((InteractorStyleMaracas*)cont);
1236 _selectedObjects.clear();
1237 _controllers.clear();
1241 //=========================================================================
1243 void wxVtkSceneManager::refreshScene()
1245 _baseView->RefreshView();
1248 //=========================================================================
1250 void wxVtkSceneManager::centerView()
1253 _baseView->GetRenderer()->GetActiveCamera()->GetFocalPoint(temp);
1254 _baseView->GetRenderer()->GetActiveCamera()->SetFocalPoint(0,0,temp[2]);
1255 _baseView->GetRenderer()->GetActiveCamera()->GetPosition(temp);
1256 _baseView->GetRenderer()->GetActiveCamera()->SetPosition(0,0,temp[2]);
1257 _baseView->RefreshView();
1261 //=========================================================================
1263 void wxVtkSceneManager::saveDiagram(std::string &content)
1267 //Print info IF COMPLEX BOX
1268 content+="COMPLEXBOX:";
1273 //Print info complex input ports
1274 std::vector<int> inputs = getComplexInputPorts();
1275 int insize = inputs.size();
1276 content+="COMPLEXINPUTS:";
1277 sprintf (buffer, "%d", insize);
1281 for(int i = 0;i<insize;i++)
1284 GObjectController *cont = _controllers[id];
1285 cont->getModel()->save(content);
1288 //Print info complex output ports
1289 std::vector<int> outputs = getComplexOutputPorts();
1290 int outsize = outputs.size();
1291 content+="COMPLEXOUTPUTS:";
1292 sprintf (buffer, "%d", outsize);
1296 for(int i = 0;i<outsize;i++)
1298 int id = outputs[i];
1299 GObjectController *cont = _controllers[id];
1300 cont->getModel()->save(content);
1309 std::vector<int> boxes = getBlackBoxes();
1310 int bsize = boxes.size();
1312 sprintf (buffer, "%d", bsize);
1316 for(int i = 0;i<bsize;i++)
1319 GObjectController *cont = _controllers[id];
1320 cont->getModel()->save(content);
1324 std::vector<int> connections = getConnections();
1325 int csize = connections.size();
1326 content+="CONNECTIONS:";
1327 sprintf (buffer, "%d", csize);
1331 for(int i = 0;i<csize;i++)
1333 int id = connections[i];
1334 GObjectController *cont = _controllers[id];
1335 cont->getModel()->save(content);
1340 //=========================================================================
1342 void wxVtkSceneManager::loadDiagram(ifstream &inputStream)
1345 std::string line="";
1346 char delims[] = ":";
1347 char *result = NULL;
1348 getline(inputStream,line);
1351 while ( !inputStream.eof() )
1353 if(line=="" || line[0]=='#')
1355 getline(inputStream,line);
1357 else if(line=="APP_START")
1368 getline(inputStream,line);//COMPLEX_BOX:TRUE|FALSE
1370 strcpy( complex, line.c_str() );
1371 result = strtok( complex, delims );
1372 result = strtok( NULL, delims );
1373 std::string isComplexBox(result);
1375 if(isComplexBox=="TRUE")
1379 //-----------------------
1380 //- COMPLEX INPUT PORTS
1381 //-----------------------
1382 getline(inputStream,line);//COMPLEXINPUTS:num
1384 strcpy( inputs, line.c_str() );
1385 result = strtok( inputs, delims );
1386 result = strtok( NULL, delims );
1389 std::istringstream inps(result);
1392 for(int i = 0;i<numInputs;i++)
1395 getline(inputStream,line);//COMPLEX_PORT
1396 getline(inputStream,line);//name
1397 std::string inputPortName(line);
1400 getline(inputStream,line);//xInic:yInic:zInic
1402 strcpy( coord, line.c_str() );
1403 result = strtok( coord, delims );//xInic
1404 std::string xInic(result);
1405 result = strtok( NULL, delims );//yInic
1406 std::string yInic(result);
1407 result = strtok( NULL, delims );//zInic
1408 std::string zInic(result);
1410 double xIn, yIn, zIn;
1411 std::istringstream xSt(xInic);
1413 std::istringstream ySt(yInic);
1415 std::istringstream zSt(zInic);
1418 getline(inputStream,line);//FIN_COMPLEX_PORT
1420 int idInputPort = createGComplexBoxInputPort(inputPortName);
1421 GObjectController *cont = _controllers[idInputPort];
1422 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
1423 cbmod->setInicPoint(xIn,yIn,zIn);
1424 cbmod->notifyObservers(_idManager);
1428 //-----------------------
1429 //- COMPLEX OUTPUT PORTS
1430 //-----------------------
1432 getline(inputStream,line);//COMPLEXOUTPUTS:num
1434 strcpy( outputs, line.c_str() );
1435 result = strtok( outputs, delims );
1436 result = strtok( NULL, delims );
1439 std::istringstream outps(result);
1440 outps >> numOutputs;
1442 for(int i = 0;i<numOutputs;i++)
1445 getline(inputStream,line);//COMPLEX_PORT
1446 getline(inputStream,line);//name
1447 std::string outputPortName(line);
1450 getline(inputStream,line);//xInic:yInic:zInic
1452 strcpy( coord, line.c_str() );
1453 result = strtok( coord, delims );//xInic
1454 std::string xInic(result);
1455 result = strtok( NULL, delims );//yInic
1456 std::string yInic(result);
1457 result = strtok( NULL, delims );//zInic
1458 std::string zInic(result);
1460 double xIn, yIn, zIn;
1461 std::istringstream xSt(xInic);
1463 std::istringstream ySt(yInic);
1465 std::istringstream zSt(zInic);
1468 getline(inputStream,line);//FIN_COMPLEX_PORT
1470 int idOutputPort = createGComplexBoxOutputPort(outputPortName);
1471 GObjectController *cont = _controllers[idOutputPort];
1472 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
1473 cbmod->setInicPoint(xIn,yIn,zIn);
1474 cbmod->notifyObservers(_idManager);
1480 getline(inputStream,line);//BOXES:num
1482 strcpy( boxes, line.c_str() );
1483 result = strtok( boxes, delims );
1484 result = strtok( NULL, delims );
1487 std::istringstream is(result);
1490 for(int i = 0;i<numBoxes;i++)
1493 getline(inputStream,line);//BOX
1494 getline(inputStream,line);//package:type:name
1496 strcpy( box, line.c_str() );
1497 result = strtok( box, delims );//package
1498 std::string package(result);
1499 result = strtok( NULL, delims );//type
1500 std::string type(result);
1501 result = strtok( NULL, delims );//name
1502 std::string name(result);
1504 getline(inputStream,line);//ISEXEC:TRUE|FALSE
1506 strcpy( exec, line.c_str() );
1507 result = strtok( exec, delims );//ISEXEC
1508 result = strtok( NULL, delims );//TRUE|FALSE
1509 std::string isExec(result);
1512 getline(inputStream,line);//xInic:yInic:zInic
1514 strcpy( coord, line.c_str() );
1515 result = strtok( coord, delims );//xInic
1516 std::string xInic(result);
1517 result = strtok( NULL, delims );//yInic
1518 std::string yInic(result);
1519 result = strtok( NULL, delims );//zInic
1520 std::string zInic(result);
1522 double xIn, yIn, zIn;
1523 std::istringstream xSt(xInic);
1525 std::istringstream ySt(yInic);
1527 std::istringstream zSt(zInic);
1531 getline(inputStream,line);//xEnd:yEnd:zEnd
1532 strcpy( coord, line.c_str() );
1533 result = strtok( coord, delims );//xEnd
1534 std::string xEnd(result);
1535 result = strtok( NULL, delims );//yEnd
1536 std::string yEnd(result);
1537 result = strtok( NULL, delims );//zEnd
1538 std::string zEnd(result);
1540 double xEn, yEn, zEn;
1541 std::istringstream xEt(xEnd);
1543 std::istringstream yEt(yEnd);
1545 std::istringstream zEt(zEnd);
1548 int idBox = createGBlackBox(0,0,package,type);
1549 GObjectController *cont = _controllers[idBox];
1550 GBlackBoxModel *bbmod = (GBlackBoxModel*)cont->getModel();
1551 bbmod->setBBTKName(name);
1552 bbmod->setInicPoint(xIn,yIn,zIn);
1553 bbmod->setFinalPoint(xEn,yEn,zEn);
1556 bbmod->setExecutable(true);
1558 else if(isExec=="FALSE")
1560 bbmod->setExecutable(false);
1564 getline(inputStream,line);//PORT o FIN_BOX
1565 std::string port=line.substr(0,4);
1568 getline(inputStream,line);//name:value
1570 strcpy( poort, line.c_str() );
1571 result = strtok( poort, delims );//name
1572 std::string name(result);
1573 result = strtok( NULL, delims );//value
1574 std::string value(result);
1576 bbmod->setValueToInput(name,value);
1578 getline(inputStream,line);//PORT o FIN_BOX
1579 port=line.substr(0,4);
1582 bbmod->notifyObservers(_idManager);
1587 getline(inputStream,line);//CONNECTIONS:num
1589 strcpy( conns, line.c_str() );
1590 result = strtok( conns, delims );
1591 result = strtok( NULL, delims );
1594 std::istringstream isCons(result);
1597 for(int i = 0;i<numConns;i++)
1600 getline(inputStream,line);//CONNECTION
1601 getline(inputStream,line);//Startbox.PortName:EndBox.PortName
1604 strcpy( connec, line.c_str() );
1605 result = strtok( connec, delims );
1606 std::string nameStartBox(result);
1607 result = strtok( NULL, delims );
1608 std::string nameStartPort(result);
1609 result = strtok( NULL, delims );
1610 std::string nameEndBox(result);
1611 result = strtok( NULL, delims );
1612 std::string nameEndPort(result);
1614 std::vector<int> lstB = getBlackBoxes();
1616 GPortModel *startP=NULL;
1617 GPortModel *endP=NULL;
1618 for(int j = 0;j<lstB.size();j++)
1621 GBlackBoxModel *bbMod = (GBlackBoxModel*)_controllers[idB]->getModel();
1622 if(_controllers[idB]->getModel()->getBBTKName()==nameStartBox)
1624 startP = bbMod->getOutputPort(nameStartPort);
1626 else if(_controllers[idB]->getModel()->getBBTKName()==nameEndBox)
1628 endP = bbMod->getInputPort(nameEndPort);
1636 std::vector<int> lstInputs = getComplexInputPorts();
1637 for(int j = 0;j<lstInputs.size();j++)
1639 int idB = lstInputs[j];
1640 GBoxModel *cbMod = (GBoxModel*)_controllers[idB]->getModel();
1641 if(_controllers[idB]->getModel()->getBBTKName()==nameStartBox)
1643 startP = cbMod->getOutputPort(nameStartPort);
1650 std::vector<int> lstOutputs = getComplexOutputPorts();
1651 for(int j = 0;j<lstOutputs.size();j++)
1653 int idB = lstOutputs[j];
1654 GBoxModel *cbMod = (GBoxModel*)_controllers[idB]->getModel();
1655 if(_controllers[idB]->getModel()->getBBTKName()==nameEndBox)
1657 endP = cbMod->getInputPort(nameEndPort);
1663 int idCon = createGConnector(startP);
1664 _worldState = NOTHING_HAPPENS;
1665 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
1667 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
1668 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
1669 tempp->endContourCreation();
1670 conMod->setEndPort(endP);
1671 conView->updateStartEndPoints();
1678 //=========================================================================
1680 std::vector<int> wxVtkSceneManager::getBlackBoxes()
1682 std::vector<int> vect;
1683 std::map<int, GObjectController*>::iterator it;
1684 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1686 GObjectController *cont = it->second;
1687 if(cont->getGObjectType()==GBLACKBOX)
1689 vect.push_back(cont->getId());
1695 //=========================================================================
1697 std::vector<int> wxVtkSceneManager::getComplexInputPorts()
1699 std::vector<int> vect;
1700 std::map<int, GObjectController*>::iterator it;
1701 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1703 GObjectController *cont = it->second;
1704 if(cont->getGObjectType()==GCOMPLEXINPUTPORT)
1706 vect.push_back(cont->getId());
1712 //=========================================================================
1714 std::vector<int> wxVtkSceneManager::getComplexOutputPorts()
1716 std::vector<int> vect;
1717 std::map<int, GObjectController*>::iterator it;
1718 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1720 GObjectController *cont = it->second;
1721 if(cont->getGObjectType()==GCOMPLEXOUTPUTPORT)
1723 vect.push_back(cont->getId());
1729 //=========================================================================
1731 std::vector<int> wxVtkSceneManager::getConnections()
1733 std::vector<int> vect;
1734 std::map<int, GObjectController*>::iterator it;
1735 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1737 GObjectController *cont = it->second;
1738 if(cont->getGObjectType()==GCONNECTOR)
1740 vect.push_back(cont->getId());
1746 //=========================================================================
1748 bool wxVtkSceneManager::isComplexBox()
1750 return _isComplexBox;
1753 //=========================================================================
1755 void wxVtkSceneManager::setComplexBox(bool val)
1760 //=========================================================================
1762 int wxVtkSceneManager::addObjectController(GObjectController* objController)
1764 //Register the controller of the new object
1765 registerController((InteractorStyleMaracas*) objController);
1767 //Add the object to the objects list
1768 int newId = _controllers.size();
1769 objController->setId(newId);
1770 _controllers[newId] = objController;
1774 //=========================================================================
1776 int wxVtkSceneManager::getNumSelectedObjects()
1778 return _selectedObjects.size();
1781 //=========================================================================
1783 std::map<int,GObjectController*> wxVtkSceneManager::getSelectedObjects()
1785 std::map<int,GObjectController*> mapSelected;
1787 std::map<int, GObjectController*>::iterator it;
1788 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1790 GObjectController *cont = it->second;
1791 if(cont->getGObjectType()==GBLACKBOX && cont->getView()->getState()==SELECTED)
1793 mapSelected[cont->getId()]=cont;
1797 std::map<int, GObjectController*>::iterator it2;
1798 for(it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
1800 GObjectController *cont = it2->second;
1801 if(cont->getGObjectType()==GCONNECTOR)
1803 GConnectorModel* cmod = (GConnectorModel*)cont->getModel();
1804 GBoxModel* endPortParentBox = cmod->getEndPort()->getParentBox();
1805 GBoxModel* startPortParentBox = cmod->getStartPort()->getParentBox();
1807 std::map<int, GObjectController*>::iterator iterOBJ1 = mapSelected.find(startPortParentBox->getObjectId());
1808 std::map<int, GObjectController*>::iterator iterOBJ2 = mapSelected.find(endPortParentBox->getObjectId());
1810 if(iterOBJ1 != mapSelected.end() && iterOBJ2 != mapSelected.end())
1812 int ID = cont->getId();
1813 mapSelected[ID]=cont;
1821 //=========================================================================
1823 void wxVtkSceneManager::addObjects(std::map<int,GObjectController*> objectsMap)
1826 std::map<int,int> oldIdNewIdBoxes;
1827 std::vector<int> connections;
1829 std::map<int, GObjectController*>::iterator it;
1830 for(it = objectsMap.begin(); it != objectsMap.end(); ++it)
1832 GObjectController *cont = it->second;
1833 int type = cont->getGObjectType();
1838 double xInic, yInic,zInic;
1839 GBlackBoxModel* copyBox = (GBlackBoxModel*)cont->getModel();
1840 copyBox->getInicPoint(xInic,yInic,zInic);
1841 int idBox = createGBlackBox(0,0,copyBox->getBBTKPackage(),copyBox->getBBTKType());
1843 int idcB = copyBox->getObjectId();
1844 oldIdNewIdBoxes[idcB]=idBox;
1845 cont = _controllers[idBox];
1846 GBlackBoxModel* newbox = (GBlackBoxModel*)cont->getModel();
1847 newbox->setInicPoint(xInic,yInic,zInic);
1848 int num = newbox->getNumInputPorts();
1849 for(int j=0;j<num;j++)
1851 newbox->setValueToInputPort(j,copyBox->getValueInputPort(j));
1853 newbox->notifyObservers(_idManager);
1855 else if(type==GCONNECTOR)
1857 int idCon = cont->getId();
1858 connections.push_back(idCon);
1863 for(int i = 0 ;i<connections.size();i++)
1865 int objId = connections[i];
1866 GObjectController *cont = objectsMap[objId];
1867 GConnectorModel* connectModel = (GConnectorModel*)cont->getModel();
1869 GPortModel* startPort = connectModel->getStartPort();
1870 int startPortIndex = startPort->getPosInBox();
1871 GPortModel* endPort = connectModel->getEndPort();
1872 int endPortIndex = endPort->getPosInBox();
1874 GBlackBoxModel* startPortParentBox = (GBlackBoxModel*)startPort->getParentBox();
1875 GBlackBoxModel* endPortParentBox = (GBlackBoxModel*)endPort->getParentBox();
1877 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
1878 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
1880 GBlackBoxModel* newStartBox = (GBlackBoxModel*)_controllers[idNewStartBox]->getModel();
1881 GBlackBoxModel* newEndBox = (GBlackBoxModel*)_controllers[idNewEndBox]->getModel();
1883 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
1884 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
1886 // Creates connection
1887 int idCon = createGConnector(newStartPort);
1888 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
1889 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
1890 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
1891 tempp->endContourCreation();
1892 conMod->setEndPort(newEndPort);
1893 conView->updateStartEndPoints();
1896 std::map<int, int>::iterator itIds;
1897 for(itIds = oldIdNewIdBoxes.begin(); itIds != oldIdNewIdBoxes.end(); ++itIds)
1899 int idOld = itIds->first;
1900 int idNew = itIds->second;
1902 GBlackBoxModel* oldBox = (GBlackBoxModel*)objectsMap[idOld]->getModel();
1903 GBlackBoxModel* newBox = (GBlackBoxModel*)_controllers[idNew]->getModel();
1905 std::vector<int> oldInputConnections = oldBox->getConnectedInputs();
1906 std::vector<int> oldOutputConnections = oldBox->getConnectedOutputs();
1907 std::vector<int> newInputConnections = newBox->getConnectedInputs();
1908 std::vector<int> newOutputConnections = newBox->getConnectedOutputs();
1910 for(int k = 0; k<oldInputConnections.size();k++)
1914 for(int l = 0; l<newInputConnections.size() && !exist;l++)
1916 if(oldInputConnections[k]==newInputConnections[l])
1924 //Create complex input
1925 int posInBox = oldInputConnections[k];
1926 GPortModel* inputPort = oldBox->getInputPort(posInBox);
1927 std::string inputPortName = inputPort->getBBTKName();
1928 int idInputPort = createGComplexBoxInputPort(inputPortName);
1929 GObjectController *cont = _controllers[idInputPort];
1930 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
1932 inputPort->getInicPoint(xIn,yIn,zIn);
1934 cbmod->setInicPoint(xIn,yIn,zIn);
1935 cbmod->notifyObservers(_idManager);
1937 GPortModel* inputPortEnd = newBox->getInputPort(posInBox);
1939 // Creates connection
1940 int idCon = createGConnector(cbmod->getOutputPort(0));
1941 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
1942 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
1943 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
1944 tempp->endContourCreation();
1945 conMod->setEndPort(inputPortEnd);
1946 conView->updateStartEndPoints();
1953 for(int k = 0; k<oldOutputConnections.size();k++)
1957 for(int l = 0; l<newOutputConnections.size() && !exist;l++)
1959 if(oldOutputConnections[k]==newOutputConnections[l])
1967 //Create complex output
1968 int posInBox = oldOutputConnections[k];
1969 GPortModel* outputPort = oldBox->getOutputPort(posInBox);
1970 std::string outputPortName = outputPort->getBBTKName();
1971 int idOutputPort = createGComplexBoxOutputPort(outputPortName);
1972 GObjectController *cont = _controllers[idOutputPort];
1973 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
1975 outputPort->getInicPoint(xIn,yIn,zIn);
1977 cbmod->setInicPoint(xIn,yIn,zIn);
1978 cbmod->notifyObservers(_idManager);
1980 GPortModel* outputPortEnd = newBox->getOutputPort(posInBox);
1982 // Creates connection
1983 int idCon = createGConnector(outputPortEnd);
1984 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
1985 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
1986 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
1987 tempp->endContourCreation();
1988 conMod->setEndPort(cbmod->getInputPort(0));
1989 conView->updateStartEndPoints();
2000 //=========================================================================
2002 } // EO namespace bbtk