1 /*=========================================================================
7 =========================================================================*/
9 /* ---------------------------------------------------------------------
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
14 * This software is governed by the CeCILL-B license under French law and
15 * abiding by the rules of distribution of free software. You can use,
16 * modify and/ or redistribute the software under the terms of the CeCILL-B
17 * license as circulated by CEA, CNRS and INRIA at the following URL
18 * http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
19 * or in the file LICENSE.txt.
21 * As a counterpart to the access to the source code and rights to copy,
22 * modify and redistribute granted by the license, users are provided only
23 * with a limited warranty and the software's author, the holder of the
24 * economic rights, and the successive licensors have only limited
27 * The fact that you are presently reading this means that you have had
28 * knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */
33 * \brief Class bbtk::wxVtkSceneManager .
37 #include "wxVtkSceneManager.h"
43 //=========================================================================
44 wxVtkSceneManager::wxVtkSceneManager(wxGEditorTabPanel *parent, wxVtk3DBaseView *baseView,int idManager)
56 printf ("RaC-EED 21-06-2010 %p wxVtkSceneManager::wxVtkSceneManager If you comment this line, the drag and drop functionnality is not initialized.\n" , this );
57 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget((wxDropTarget*)parent);
60 _worldState=NOTHING_HAPPENS;
61 registerController(this);
64 _idConnectionInCreation=-1;
69 //=========================================================================
71 void wxVtkSceneManager::disconnectDrop()
73 printf ("EED %p ~wxVtkSceneManager::disconnectDrop()\n" , this );
74 //EED02JUIN2010 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget(NULL);
75 // _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget( new tmpClasswxTextDropTarget() );
78 //=========================================================================
80 wxVtkSceneManager::~wxVtkSceneManager()
82 printf ("EED %p ~wxVtkSceneManager()\n" , this );
86 //=========================================================================
88 void wxVtkSceneManager::configureBaseView()
90 vtkInteractorStyleBaseView2D *interactorstylebaseview = vtkInteractorStyleBaseView2D::New();
92 _baseView->SetInteractorStyleBaseView(interactorstylebaseview);
94 // Important to activate the 2D interaction system
95 wxVTKRenderWindowInteractor *iren = _baseView->GetWxVTKRenderWindowInteractor();
96 interactorstylebaseview->SetInteractor ( iren );
97 iren->SetInteractorStyle(interactorstylebaseview);
98 interactorstylebaseview->SetwxVtkBaseView(_baseView);
100 _baseView->GetRenderer()->GetActiveCamera()->ParallelProjectionOn();
101 _baseView->GetRenderer()->ResetCamera(-100,100,-100,100,900,1000);
103 _baseView->GetRenderer()->SetBackground(0.9,0.9,0.9);
104 _baseView->GetRenderer()->GradientBackgroundOff();
105 _baseView->Refresh();
108 //=========================================================================
110 int wxVtkSceneManager::createGBlackBox(int x, int y, std::string packageName, std::string boxType)
112 _worldState = NOTHING_HAPPENS;
113 int windowWidth=_baseView->GetRenWin()->GetSize()[0];
114 int windowHeight=_baseView->GetRenWin()->GetSize()[1];
116 int type = GBLACKBOX;
118 //Create the MVC Objects
120 GBlackBoxModel *model = (GBlackBoxModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
121 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
122 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
124 BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxType);
126 //Prepares the initial model
127 //The coordinates obtained are the following. Top-Left:x=0,y=0 Bottom-Right:x=width,y=height
130 double yy = windowHeight-y;
132 //z value is not important yet, because it is only used a parallel projection
135 _baseView->TransCoordScreenToWorld(xx,yy,zz);
136 model->setInicPoint(xx,yy,zz);
139 std::stringstream stream;
143 stream << "Box0" << _numBoxes;
147 stream << "Box" << _numBoxes;
149 std::string arraystring = stream.str();
151 model->setBBTKName(arraystring);
152 model->setBBTKType(boxType);
153 model->setBBTKPackage(packageName);
155 model->addObserver(view);
156 model->addObserver(this);
158 //Iterate and create the input ports
159 std::map<std::string, BlackBoxInputDescriptor*> descriptorInMap = descriptor->GetInputDescriptorMap();
160 std::map<std::string, BlackBoxInputDescriptor*>::iterator itInput;
163 for(itInput = descriptorInMap.begin(); itInput != descriptorInMap.end(); ++itInput)
165 BlackBoxInputDescriptor *desc = itInput->second;
166 createGInputPort(GINPUTPORT,i,model,desc);
170 //Iterate and create the output ports
171 std::map<std::string, BlackBoxOutputDescriptor*> descriptorOutMap = descriptor->GetOutputDescriptorMap();
172 std::map<std::string, BlackBoxOutputDescriptor*>::iterator itOutput;
175 for(itOutput = descriptorOutMap.begin();itOutput != descriptorOutMap.end(); ++itOutput)
177 BlackBoxOutputDescriptor *desc = itOutput->second;
178 createGOutputPort(GOUTPUTPORT,i,model,desc);
183 //Associates the view with the correspondent renderer and the model.
184 //(NOTE: Refresh is only made by the view)
185 view->setModel(model);
186 view->setBaseView(_baseView);
187 view->initVtkObjects();
189 //Associates the controller with the correspondent model and view
190 controller->setModelAndView(model,view);
192 //Resgiter change to the observers of the actual model
193 model->notifyObservers(_idManager);
195 int newId = addObjectController(controller);
201 //=========================================================================
203 int wxVtkSceneManager::createGComplexBoxInputPort(std::string inputName)
205 int windowWidth=_baseView->GetRenWin()->GetSize()[0];
206 int windowHeight=_baseView->GetRenWin()->GetSize()[1];
208 int type = GCOMPLEXINPUTPORT;
210 //Create the MVC Objects
212 GComplexBoxPortModel *model = (GComplexBoxPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
213 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
214 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
216 //Prepares the initial model
219 double yy = windowHeight-5;
221 //z value is not important yet, because it is only used a parallel projection
224 _baseView->TransCoordScreenToWorld(xx,yy,zz);
225 model->setInicPoint(xx,yy,zz);
227 model->setBBTKName(inputName);
228 model->setBBTKType("ComplexInputPort");
229 model->setComplexPortType(type);
231 model->addObserver(view);
232 model->addObserver(this);
234 //create the output port
235 GPortController* portController = createGPort(GOUTPUTPORT,inputName,"ComplexInputPort",0,model);
236 model->addOutputPort((GPortModel*)portController->getModel());
238 //Associates the view with the correspondent renderer and the model.
239 //(NOTE: Refresh is only made by the view)
240 view->setModel(model);
241 view->setBaseView(_baseView);
242 view->initVtkObjects();
244 //Associates the controller with the correspondent model and view
245 controller->setModelAndView(model,view);
247 //Resgiter change to the observers of the actual model
248 model->notifyObservers(_idManager);
250 int newId = addObjectController(controller);
254 //=========================================================================
256 int wxVtkSceneManager::createGComplexBoxOutputPort(std::string outputName)
258 int windowWidth=_baseView->GetRenWin()->GetSize()[0];
259 int windowHeight=_baseView->GetRenWin()->GetSize()[1];
261 int type = GCOMPLEXOUTPUTPORT;
263 //Create the MVC Objects
265 GComplexBoxPortModel *model = (GComplexBoxPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
266 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
267 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
269 //Prepares the initial model
272 double yy = windowHeight-5;
274 //z value is not important yet, because it is only used a parallel projection
277 _baseView->TransCoordScreenToWorld(xx,yy,zz);
278 model->setInicPoint(xx,yy,zz);
280 model->setBBTKName(outputName);
281 model->setBBTKType("ComplexOutputPort");
282 model->setComplexPortType(type);
284 model->addObserver(view);
285 model->addObserver(this);
287 //create the output port
288 GPortController* portController = createGPort(GINPUTPORT,outputName,"ComplexInputPort",0,model);
289 model->addInputPort((GPortModel*)portController->getModel());
291 //Associates the view with the correspondent renderer and the model.
292 //(NOTE: Refresh is only made by the view)
293 view->setModel(model);
294 view->setBaseView(_baseView);
295 view->initVtkObjects();
297 //Associates the controller with the correspondent model and view
298 controller->setModelAndView(model,view);
300 //Resgiter change to the observers of the actual model
301 model->notifyObservers(_idManager);
303 int newId = addObjectController(controller);
307 //=========================================================================
309 int wxVtkSceneManager::createGInputPort(int portType, int posinBox,GBoxModel *blackBox, BlackBoxInputDescriptor *desc)
311 GPortController* portController = createGPort(portType,desc->GetName(),desc->GetTypeName(),posinBox,blackBox);
312 blackBox->addInputPort((GPortModel*)portController->getModel());
313 return portController->getId();
316 //=========================================================================
318 int wxVtkSceneManager::createGOutputPort(int portType, int posinBox,GBoxModel *blackBox, BlackBoxOutputDescriptor *desc)
320 GPortController* portController = createGPort(portType,desc->GetName(),desc->GetTypeName(),posinBox,blackBox);
321 blackBox->addOutputPort((GPortModel*)portController->getModel());
322 return portController->getId();
325 //=========================================================================
327 GPortController* wxVtkSceneManager::createGPort(int portType,std::string bbtkName, std::string bbtkType, int posInBox,GBoxModel *blackBox)
331 //Create the MVC Objects
332 GPortModel *model = (GPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
333 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
334 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
336 model->registerInBox(blackBox,portType, posInBox);
338 model->setBBTKType(bbtkType);
339 model->setBBTKName(bbtkName);
341 model->addObserver(view);
342 model->addObserver(this);
344 //Associates the view with the correspondent renderer and the model.
345 //(NOTE: Refresh is only made by the view)
346 view->setModel(model);
347 view->setBaseView(_baseView);
348 view->initVtkObjects();
350 //Associates the controller with the correspondent model and view
351 controller->setModelAndView(model,view);
353 model->notifyObservers(_idManager);
355 int newId = addObjectController(controller);
357 return (GPortController*)controller;
360 //=========================================================================
362 int wxVtkSceneManager::createGConnector(GPortModel* startPort)
364 int type = GCONNECTOR;
366 manualConnectorContourController* manContourControl = new manualConnectorContourController();
367 manualConnectorContourView* manContourView = new manualConnectorContourView();
368 manualContourModel* manContourModel = new manualContourModel();
370 GConnectorController* connectorcontroller = new GConnectorController();
371 GConnectorModel* connectorModel = new GConnectorModel();
372 vtkGConnectorView* connectorView = new vtkGConnectorView();
373 connectorModel->setGObjectType(type);
375 manContourModel->SetCloseContour(false);
376 connectorModel->setStartPort(startPort);
378 manContourView->SetModel( manContourModel );
379 manContourView->SetWxVtkBaseView( _baseView );
380 manContourView->SetRange( 0.5 );
381 manContourView->SetZ( 900 );
383 manContourView->SetColorNormalContour(0, 0, 1);
384 manContourView->SetColorEditContour(0.5, 0.5, 0.5);
385 manContourView->SetColorSelectContour(1, 0.8, 0);
386 manContourView->SetWidthLine(1);
387 manContourView->SetShowText(false);
389 manContourControl->SetModelView( manContourModel , manContourView );
391 manContourControl->CreateNewManualContour();
393 manContourView->RefreshContour();
397 connectorModel->getInicPoint(x,y,z);
399 manContourControl->SetState(1);
400 manContourModel->SetCloseContour(false);
402 manContourModel->AddPoint(x,y,z);
403 manContourView->AddPoint();
405 manContourModel->AddPoint(x,y,z);
406 manContourView->AddPoint();
408 int bak= manContourControl->GetNumberOfPointsManualContour() - 1;
409 manContourControl->_bakIdPoint=bak;
410 manContourView->Refresh();
412 manContourControl->SetMoving( false );
414 connectorcontroller->setModelAndView(connectorModel,connectorView);
416 int newId = addObjectController(connectorcontroller);
418 connectorcontroller->setManualContourController(manContourControl);
419 connectorModel->setManualContourModel(manContourModel);
420 connectorView->setManualContourView(manContourView);
421 connectorView->setModel(connectorModel);
422 connectorView->setBaseView(_baseView);
425 connectorModel->addObserver(connectorView);
426 connectorModel->addObserver(this);
431 //=========================================================================
433 void wxVtkSceneManager::registerController(InteractorStyleMaracas *param)
435 vtkInteractorStyleBaseView* baseViewControlManager = (vtkInteractorStyleBaseView*)_baseView->GetInteractorStyleBaseView();
436 baseViewControlManager->AddInteractorStyleMaracas( param );
439 //=========================================================================
441 void wxVtkSceneManager::unregisterController(InteractorStyleMaracas *param)
443 vtkInteractorStyleBaseView* baseViewControlManager = (vtkInteractorStyleBaseView*)_baseView->GetInteractorStyleBaseView();
444 baseViewControlManager->RemoveInteractorStyleMaracas( param );
447 //=========================================================================
449 vtkRenderer* wxVtkSceneManager::getRenderer()
451 return _baseView->GetRenderer();
454 //=========================================================================
456 vtkRenderWindow* wxVtkSceneManager::getRenderWindow()
458 return _baseView->GetRenWin();
460 //=========================================================================
463 void wxVtkSceneManager::update(int idController,int command)
465 if(command != NO_COMMAND)
467 if(command == ADD_TO_SELECTED)
469 GObjectController* cont = _controllers[idController];
472 for (int i=0; i<_selectedObjects.size() && foundID==false; i++)
474 int id = _selectedObjects[i];
482 int id = idController;
483 _selectedObjects.push_back(id);
487 else if(command == INIT_CREATION_CONTOUR)
489 _worldState = INIT_CREATION_CONTOUR;
490 GObjectController* cont = _controllers[idController];
491 GPortModel* startOutputPort = (GPortModel*)cont->getModel();
494 // The last one is the controller of the connector
495 std::map<int, GObjectController*>::iterator it2;
497 for(it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
499 GObjectController *cont = it2->second;
500 if(cont->getGObjectType() == GPORT )
502 GPortModel* port = (GPortModel*)cont->getModel();
503 if(port->getPortType()==GINPUTPORT)
505 cont->SetActive(true);
509 cont->getView()->setState(NOTHING_HAPPENS);
510 cont->getModel()->notifyObservers(_idManager);
511 cont->SetActive(false);
516 cont->getView()->setState(NOTHING_HAPPENS);
517 cont->getModel()->notifyObservers(_idManager);
518 cont->SetActive(false);
522 _selectedObjects.clear();
524 _idConnectionInCreation=createGConnector(startOutputPort);
527 else if(command == FIN_CREATION_CONTOUR && _worldState == INIT_CREATION_CONTOUR)
529 _worldState = NOTHING_HAPPENS;
530 //int id = _controllers.size()-1;
531 GObjectController* cont = _controllers[_idConnectionInCreation];
532 GConnectorModel* modelContour = (GConnectorModel*)cont->getModel();
534 GObjectController* finPort = _controllers[idController];
535 if(finPort->getGObjectType() == GPORT)
537 GPortModel* modelPort = (GPortModel*)finPort->getModel();
538 modelContour->setEndPort(modelPort);
541 manualConnectorContourController* manCont = ((GConnectorController*)cont)->getManualContourController();
542 manualConnectorContourView* connView = (manualConnectorContourView*)manCont->GetManualViewBaseContour();
545 std::map<int, GObjectController*>::iterator it2;
547 for(it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
549 GObjectController *cont = it2->second;
550 if(cont->getView()!=NULL)
552 cont->getView()->setState(NOTHING_HAPPENS);
553 cont->getModel()->notifyObservers(_idManager);
555 cont->SetActive(true);
562 //=========================================================================
564 bool wxVtkSceneManager::OnMouseMove()
567 wxVTKRenderWindowInteractor *wxVTKiren;
568 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
569 wxVTKiren->GetEventPosition(X,Y);
572 if(_worldState == DRAG_OBJECTS)
574 for (int i=0; i<_selectedObjects.size(); i++)
576 int id = _selectedObjects[i];
577 GObjectController* cont = _controllers[id];
580 cont->getView()->setStartDragging(true);
582 cont->getView()->moveObject(X,Y);
583 cont->getView()->setState(DRAG);
584 cont->getModel()->notifyObservers(_idManager);
587 std::map<int, GObjectController*>::iterator it;
589 for(it = _controllers.begin(); it != _controllers.end(); ++it)
591 GObjectController *desc = it->second;
592 if(desc->getGObjectType()==GCONNECTOR)
594 vtkGConnectorView* vconn = (vtkGConnectorView*)desc->getView();
595 vconn->updateStartEndPoints();
599 _startDragging=false;
602 else if(_worldState == NOTHING_HAPPENS || _worldState == INIT_CREATION_CONTOUR)
604 std::map<int, GObjectController*>::iterator it;
606 for(it = _controllers.begin(); it != _controllers.end(); ++it)
608 GObjectController *desc = it->second;
609 int type = desc->getGObjectType();
610 int state = desc->getView()->getState();
612 if(state == HIGHLIGHTED){
614 updateStatusBar(desc->getStatusText());
617 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
618 _parent->displayBlackBoxInfo(mod->getBBTKPackage(),mod->getBBTKType());
627 //=========================================================================
629 bool wxVtkSceneManager::OnLeftButtonDown()
631 if(_worldState==INIT_CREATION_CONTOUR)
633 bool isOverPort=false;
634 std::map<int, GObjectController*>::iterator it;
635 for(it = _controllers.begin(); it != _controllers.end() && isOverPort==false; ++it)
637 GObjectController *desc = it->second;
638 if(desc->getGObjectType()==GPORT)
640 GPortModel* portmod=(GPortModel*)desc->getModel();
641 vtkGObjectView* portView=desc->getView();
642 if(portmod->getPortType()==GINPUTPORT && portView->getState()==HIGHLIGHTED)
649 if(isOverPort==false)
651 _worldState=NOTHING_HAPPENS;
652 //int lastId = _controllers.size()-1;
653 GConnectorController *connector = (GConnectorController*)_controllers[_controllers.size()-1];
654 connector->removeFromScene();
655 unregisterController(connector);
656 _controllers.erase(_controllers.size()-1);
658 for(it = _controllers.begin(); it != _controllers.end(); ++it)
660 GObjectController *desc = it->second;
661 desc->SetActive(true);
662 desc->getView()->setState(NOTHING_HAPPENS);
663 desc->getModel()->notifyObservers(_idManager);
668 if(_selectedObjects.size()!=0)
670 _worldState = DRAG_OBJECTS;
671 _startDragging = true;
673 for (int i = 0; i < _selectedObjects.size(); i++)
675 int id = _selectedObjects[i];
676 GObjectController* cont = _controllers[id];
677 cont->getView()->setState(DRAG);
678 cont->getModel()->notifyObservers(_idManager);
687 //=========================================================================
689 bool wxVtkSceneManager::OnLeftButtonUp()
691 if(_worldState == DRAG_OBJECTS)
693 _worldState = NOTHING_HAPPENS;
695 for (int i = 0; i < _selectedObjects.size(); i++)
697 int id = _selectedObjects[i];
698 GObjectController* cont = _controllers[id];
699 cont->getView()->setState(SELECTED);
700 cont->getModel()->notifyObservers(_idManager);
706 //=========================================================================
708 bool wxVtkSceneManager::OnRightButtonUp()
710 if(_worldState==INIT_CREATION_CONTOUR)
712 _worldState=NOTHING_HAPPENS;
713 //int lastId = _controllers.size()-1;
714 GConnectorController *connector = (GConnectorController*)_controllers[_idConnectionInCreation];
715 connector->removeFromScene();
716 unregisterController(connector);
717 _controllers.erase(_idConnectionInCreation);
719 std::map<int, GObjectController*>::iterator it;
720 for(it = _controllers.begin(); it != _controllers.end(); ++it)
722 GObjectController *desc = it->second;
723 desc->SetActive(true);
724 desc->getView()->setState(NOTHING_HAPPENS);
725 desc->getModel()->notifyObservers(_idManager);
730 for (int i = 0; i < _selectedObjects.size(); i++)
732 int id = _selectedObjects[i];
733 GObjectController* cont = _controllers[id];
734 cont->SetActive(true);
735 cont->getView()->setState(NOTHING_HAPPENS);
736 cont->getModel()->notifyObservers(_idManager);
739 _selectedObjects.clear();
744 //=========================================================================
746 bool wxVtkSceneManager::OnLeftDClick()
749 wxVTKRenderWindowInteractor *wxVTKiren;
750 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
751 wxVTKiren->GetEventPosition(X,Y);
753 std::map<int, GObjectController*>::iterator it;
755 bool clickOnObject = false;
757 for(it = _controllers.begin(); it != _controllers.end() && clickOnObject==false; ++it)
759 GObjectController *cont = it->second;
760 int type = cont->getGObjectType();
762 if(cont->getView()->isPointInside(X,Y))
766 for (int i=0; i<_selectedObjects.size(); i++)
768 int id = _selectedObjects[i];
769 GObjectController* control = _controllers[id];
770 control->getView()->setState(NOTHING_HAPPENS);
772 _selectedObjects.clear();
774 GBlackBoxModel *bbmodel = (GBlackBoxModel*)cont->getModel();
775 _parent->editBlackBox(bbmodel);
777 clickOnObject = true;
781 if(clickOnObject==false)
783 //_parent->editDiagramParameters(this);
789 //=========================================================================
791 bool wxVtkSceneManager::OnChar()
793 char keyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
795 // KeyCode 127 : Delete Key
796 // KeyCode 8 : Backspace Key
797 if(keyCode == 8 || keyCode == 127)
799 if(_selectedObjects.size()>0)
801 for(int i=0;i<_selectedObjects.size();i++)
803 int id = _selectedObjects[i];
806 _selectedObjects.clear();
813 //=========================================================================
815 void wxVtkSceneManager::deleteObject(int id)
817 GObjectController *control = _controllers[id];
818 std::vector<int> controllersToRemove;
820 if(control->getGObjectType()==GBLACKBOX || control->getGObjectType()==GCOMPLEXINPUTPORT || control->getGObjectType()==GCOMPLEXOUTPUTPORT)
822 GBoxModel *bbmod = (GBoxModel*)control->getModel();
823 std::vector<GPortModel*> inputs = bbmod->getInputPorts();
825 bool boxConnected = false;
827 // Add box input controllers to be removed
828 for(int i = 0;i<inputs.size();i++)
830 controllersToRemove.push_back(inputs[i]->getObjectId());
831 if(inputs[i]->isConnected())
837 std::vector<GPortModel*> outputs = bbmod->getOutputPorts();
839 // Add box output controllers to be removed
840 for(int i = 0;i<outputs.size();i++)
842 controllersToRemove.push_back(outputs[i]->getObjectId());
843 if(outputs[i]->isConnected())
849 // Add connection controllers to be removed
850 std::map<int, GObjectController*>::iterator it;
851 for(it = _controllers.begin(); it != _controllers.end(); ++it)
853 GObjectController *cont = it->second;
854 int type = cont->getGObjectType();
857 GConnectorModel *conMod = (GConnectorModel*)cont->getModel();
858 if(conMod->getStartPort()!=NULL && conMod->getStartPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
860 controllersToRemove.push_back(conMod->getObjectId());
862 if(conMod->getEndPort()!=NULL && conMod->getEndPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
864 controllersToRemove.push_back(conMod->getObjectId());
869 // Add box controller to be removed
870 controllersToRemove.push_back(bbmod->getObjectId());
872 else if(control->getGObjectType()==GCONNECTOR)
874 GConnectorModel *conMod = (GConnectorModel*)control->getModel();
875 controllersToRemove.push_back(conMod->getObjectId());
878 for(int i = 0;i<controllersToRemove.size();i++)
880 int id = controllersToRemove[i];
881 GObjectController *cont = _controllers[id];
884 cont->removeFromScene();
885 unregisterController((InteractorStyleMaracas*)cont);
886 _controllers.erase(id);
893 //=========================================================================
895 void wxVtkSceneManager::displayBlackBoxInfo(std::string packageName, std::string boxName)
897 _parent->displayBlackBoxInfo(packageName,boxName);
900 //=========================================================================
902 void wxVtkSceneManager::updateStatusBar(std::string textStatus)
904 _parent->updateStatusBar(textStatus);
907 //=========================================================================
909 std::string wxVtkSceneManager::getDiagramBBS()
911 bool existsExec=false;
913 std::vector<std::string> packages;
914 std::vector<int> boxes;
915 std::vector<int> connections;
916 std::vector<int> execBoxes;
918 std::map<int, GObjectController*>::iterator it;
920 for(it = _controllers.begin(); it != _controllers.end(); ++it)
922 GObjectController *desc = it->second;
923 int type = desc->getGObjectType();
927 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
929 std::string pkg = mod->getBBTKPackage();
930 bool existsPkg = false;
931 for(int t = 0;t<packages.size() && existsPkg == false;t++)
940 packages.push_back(pkg);
944 boxes.push_back(it->first);
945 if(mod->isExecutable())
947 execBoxes.push_back(it->first);
951 else if(type==GCONNECTOR)
953 connections.push_back(it->first);
957 std::string script = "";
958 script+="# BBTK GEditor Script\n";
959 script+="# ----------------------\n";
962 script+="include std\n"; // EED
963 script+="include itkvtk\n"; // EED
965 for(i = 0; i<packages.size();i++)
972 // script+="include std\n"; // JPR
974 for(i = 0; i<boxes.size();i++)
978 GObjectController *control = _controllers[id];
979 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
981 script+=model->getBBTKType();
983 script+=model->getBBTKName();
986 std::vector<GPortModel*> inputs = model->getInputPorts();
987 for(int j = 0; j<inputs.size();j++)
989 GPortModel* inputPort = inputs[j];
990 if(inputPort->isValueSet())
993 script+=model->getBBTKName();
995 script+=inputPort->getBBTKName();
997 script+=inputPort->getValue();
1004 for(i = 0; i<connections.size();i++)
1007 int id = connections[i];
1008 GObjectController *control = _controllers[id];
1009 GConnectorModel *model = (GConnectorModel*)control->getModel();
1011 //Start Connection info
1012 GPortModel *start = model->getStartPort();
1013 script+=start->getParentBox()->getBBTKName();
1015 script+=start->getBBTKName();
1019 //End Connection info
1020 GPortModel *end = model->getEndPort();
1021 script+=end->getParentBox()->getBBTKName();
1023 script+=end->getBBTKName();
1028 for(i = 0; i<execBoxes.size();i++)
1031 int id = execBoxes[i];
1032 GObjectController *control = _controllers[id];
1033 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1035 script+=model->getBBTKName();
1044 //=========================================================================
1046 std::string wxVtkSceneManager::saveComplexBoxBBS(std::string cbName,std::string cbAuthor,std::string cbCategory,std::string cbDescription)
1049 std::vector<std::string> packages;
1050 std::vector<int> boxes;
1051 std::vector<int> connections;
1052 std::vector<int> execBoxes;
1054 std::map<int, GObjectController*>::iterator it;
1056 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1058 GObjectController *desc = it->second;
1059 int type = desc->getGObjectType();
1063 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
1065 std::string pkg = mod->getBBTKPackage();
1066 bool existsPkg = false;
1067 for(int t = 0;t<packages.size() && existsPkg == false;t++)
1069 if(packages[t]==pkg)
1076 packages.push_back(pkg);
1080 boxes.push_back(it->first);
1081 if(mod->isExecutable())
1083 execBoxes.push_back(it->first);
1086 else if(type==GCONNECTOR)
1088 connections.push_back(it->first);
1092 std::string script = "";
1094 script+="include std\n"; // EED
1095 script+="include itkvtk\n"; // EED
1097 for(i = 0; i<packages.size();i++)
1100 script+=packages[i];
1104 // Definition of a complex box
1109 script+="author \" ";
1113 script+="description \" ";
1114 script+=cbDescription;
1118 for(i = 0; i<boxes.size();i++)
1122 GObjectController *control = _controllers[id];
1123 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1125 script+=model->getBBTKType();
1127 script+=model->getBBTKName();
1130 std::vector<GPortModel*> inputs = model->getInputPorts();
1131 for(int j = 0; j<inputs.size();j++)
1133 GPortModel* inputPort = inputs[j];
1134 if(inputPort->isValueSet())
1137 script+=model->getBBTKName();
1139 script+=inputPort->getBBTKName();
1141 script+=inputPort->getValue();
1148 // Create connections in the script. If the connection is made with a complex port, it is created the input or output
1150 std::string complexInputs="";
1151 std::string complexOutputs="";
1153 for(i = 0; i<connections.size();i++)
1155 int id = connections[i];
1156 GObjectController *control = _controllers[id];
1157 GConnectorModel *model = (GConnectorModel*)control->getModel();
1160 GPortModel *start = model->getStartPort();
1161 GBoxModel *startBox =start->getParentBox();
1163 GPortModel *end = model->getEndPort();
1164 GBoxModel *endBox =end->getParentBox();
1166 if(startBox->getGObjectType()==GCOMPLEXINPUTPORT)
1168 complexInputs+="input ";
1169 complexInputs+=startBox->getBBTKName();
1172 complexInputs+=endBox->getBBTKName();
1174 complexInputs+=end->getBBTKName();
1177 complexInputs+="\" \"";
1179 complexInputs+="\n";
1181 else if(endBox->getGObjectType()==GCOMPLEXOUTPUTPORT)
1183 complexOutputs+="output ";
1184 complexOutputs+=endBox->getBBTKName();
1186 complexOutputs+=" ";
1187 complexOutputs+=startBox->getBBTKName();
1188 complexOutputs+=".";
1189 complexOutputs+=start->getBBTKName();
1191 complexOutputs+=" ";
1192 complexOutputs+="\" \"";
1194 complexOutputs+="\n";
1199 script+=startBox->getBBTKName();
1201 script+=start->getBBTKName();
1205 //End Connection info
1206 script+=endBox->getBBTKName();
1208 script+=end->getBBTKName();
1214 for(i = 0; i<execBoxes.size();i++)
1217 int id = execBoxes[i];
1218 GObjectController *control = _controllers[id];
1219 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1221 script+=model->getBBTKName();
1226 script+="# Complex input ports\n";
1227 script+=complexInputs;
1230 script+="# Complex output ports\n";
1231 script+=complexOutputs;
1240 //=========================================================================
1242 void wxVtkSceneManager::deleteAllBoxes()
1244 std::map<int, GObjectController*>::iterator it;
1245 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1247 GObjectController *cont = it->second;
1248 cont->removeFromScene();
1249 unregisterController((InteractorStyleMaracas*)cont);
1251 _selectedObjects.clear();
1252 _controllers.clear();
1256 //=========================================================================
1258 void wxVtkSceneManager::refreshScene()
1260 _baseView->RefreshView();
1263 //=========================================================================
1265 void wxVtkSceneManager::centerView()
1268 _baseView->GetRenderer()->GetActiveCamera()->GetFocalPoint(temp);
1269 _baseView->GetRenderer()->GetActiveCamera()->SetFocalPoint(0,0,temp[2]);
1270 _baseView->GetRenderer()->GetActiveCamera()->GetPosition(temp);
1271 _baseView->GetRenderer()->GetActiveCamera()->SetPosition(0,0,temp[2]);
1272 _baseView->RefreshView();
1276 //=========================================================================
1278 void wxVtkSceneManager::saveDiagram(std::string &content)
1282 //Print info IF COMPLEX BOX
1283 content+="COMPLEXBOX:";
1288 //Print info complex input ports
1289 std::vector<int> inputs = getComplexInputPorts();
1290 int insize = inputs.size();
1291 content+="COMPLEXINPUTS:";
1292 sprintf (buffer, "%d", insize);
1296 for(int i = 0;i<insize;i++)
1299 GObjectController *cont = _controllers[id];
1300 cont->getModel()->save(content);
1303 //Print info complex output ports
1304 std::vector<int> outputs = getComplexOutputPorts();
1305 int outsize = outputs.size();
1306 content+="COMPLEXOUTPUTS:";
1307 sprintf (buffer, "%d", outsize);
1311 for(int i = 0;i<outsize;i++)
1313 int id = outputs[i];
1314 GObjectController *cont = _controllers[id];
1315 cont->getModel()->save(content);
1324 std::vector<int> boxes = getBlackBoxes();
1325 int bsize = boxes.size();
1327 sprintf (buffer, "%d", bsize);
1331 for(int i = 0;i<bsize;i++)
1334 GObjectController *cont = _controllers[id];
1335 cont->getModel()->save(content);
1339 std::vector<int> connections = getConnections();
1340 int csize = connections.size();
1341 content+="CONNECTIONS:";
1342 sprintf (buffer, "%d", csize);
1346 for(int i = 0;i<csize;i++)
1348 int id = connections[i];
1349 GObjectController *cont = _controllers[id];
1350 cont->getModel()->save(content);
1355 //=========================================================================
1357 void wxVtkSceneManager::loadDiagram(ifstream &inputStream)
1360 std::string line="";
1361 char delims[] = ":";
1362 char *result = NULL;
1363 getline(inputStream,line);
1366 while ( !inputStream.eof() )
1368 if(line=="" || line[0]=='#')
1370 getline(inputStream,line);
1372 else if(line=="APP_START")
1383 getline(inputStream,line);//COMPLEX_BOX:TRUE|FALSE
1385 strcpy( complex, line.c_str() );
1386 result = strtok( complex, delims );
1387 result = strtok( NULL, delims );
1388 std::string isComplexBox(result);
1390 if(isComplexBox=="TRUE")
1394 //-----------------------
1395 //- COMPLEX INPUT PORTS
1396 //-----------------------
1397 getline(inputStream,line);//COMPLEXINPUTS:num
1399 strcpy( inputs, line.c_str() );
1400 result = strtok( inputs, delims );
1401 result = strtok( NULL, delims );
1404 std::istringstream inps(result);
1407 for(int i = 0;i<numInputs;i++)
1410 getline(inputStream,line);//COMPLEX_PORT
1411 getline(inputStream,line);//name
1412 std::string inputPortName(line);
1415 getline(inputStream,line);//xInic:yInic:zInic
1417 strcpy( coord, line.c_str() );
1418 result = strtok( coord, delims );//xInic
1419 std::string xInic(result);
1420 result = strtok( NULL, delims );//yInic
1421 std::string yInic(result);
1422 result = strtok( NULL, delims );//zInic
1423 std::string zInic(result);
1425 double xIn, yIn, zIn;
1426 std::istringstream xSt(xInic);
1428 std::istringstream ySt(yInic);
1430 std::istringstream zSt(zInic);
1433 getline(inputStream,line);//FIN_COMPLEX_PORT
1435 int idInputPort = createGComplexBoxInputPort(inputPortName);
1436 GObjectController *cont = _controllers[idInputPort];
1437 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
1438 cbmod->setInicPoint(xIn,yIn,zIn);
1439 cbmod->notifyObservers(_idManager);
1440 } // for input complex box
1443 //-----------------------
1444 //- COMPLEX OUTPUT PORTS
1445 //-----------------------
1447 getline(inputStream,line);//COMPLEXOUTPUTS:num
1449 strcpy( outputs, line.c_str() );
1450 result = strtok( outputs, delims );
1451 result = strtok( NULL, delims );
1454 std::istringstream outps(result);
1455 outps >> numOutputs;
1457 for(int i = 0;i<numOutputs;i++)
1460 getline(inputStream,line);//COMPLEX_PORT
1461 getline(inputStream,line);//name
1462 std::string outputPortName(line);
1465 getline(inputStream,line);//xInic:yInic:zInic
1467 strcpy( coord, line.c_str() );
1468 result = strtok( coord, delims );//xInic
1469 std::string xInic(result);
1470 result = strtok( NULL, delims );//yInic
1471 std::string yInic(result);
1472 result = strtok( NULL, delims );//zInic
1473 std::string zInic(result);
1475 double xIn, yIn, zIn;
1476 std::istringstream xSt(xInic);
1478 std::istringstream ySt(yInic);
1480 std::istringstream zSt(zInic);
1483 getline(inputStream,line);//FIN_COMPLEX_PORT
1485 int idOutputPort = createGComplexBoxOutputPort(outputPortName);
1486 GObjectController *cont = _controllers[idOutputPort];
1487 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
1488 cbmod->setInicPoint(xIn,yIn,zIn);
1489 cbmod->notifyObservers(_idManager);
1490 } // for output complex box
1495 getline(inputStream,line);//BOXES:num
1497 strcpy( boxes, line.c_str() );
1498 result = strtok( boxes, delims );
1499 result = strtok( NULL, delims );
1502 std::istringstream is(result);
1505 for(int i = 0;i<numBoxes;i++)
1508 getline(inputStream,line);//BOX
1509 getline(inputStream,line);//package:type:name
1511 strcpy( box, line.c_str() );
1512 result = strtok( box, delims );//package
1513 std::string package(result);
1514 result = strtok( NULL, delims );//type
1515 std::string type(result);
1516 result = strtok( NULL, delims );//name
1517 std::string name(result);
1519 getline(inputStream,line);//ISEXEC:TRUE|FALSE
1521 strcpy( exec, line.c_str() );
1522 result = strtok( exec, delims );//ISEXEC
1523 result = strtok( NULL, delims );//TRUE|FALSE
1524 std::string isExec(result);
1527 getline(inputStream,line);//xInic:yInic:zInic
1529 strcpy( coord, line.c_str() );
1530 result = strtok( coord, delims );//xInic
1531 std::string xInic(result);
1532 result = strtok( NULL, delims );//yInic
1533 std::string yInic(result);
1534 result = strtok( NULL, delims );//zInic
1535 std::string zInic(result);
1537 double xIn, yIn, zIn;
1538 std::istringstream xSt(xInic);
1540 std::istringstream ySt(yInic);
1542 std::istringstream zSt(zInic);
1546 getline(inputStream,line);//xEnd:yEnd:zEnd
1547 strcpy( coord, line.c_str() );
1548 result = strtok( coord, delims );//xEnd
1549 std::string xEnd(result);
1550 result = strtok( NULL, delims );//yEnd
1551 std::string yEnd(result);
1552 result = strtok( NULL, delims );//zEnd
1553 std::string zEnd(result);
1555 double xEn, yEn, zEn;
1556 std::istringstream xEt(xEnd);
1558 std::istringstream yEt(yEnd);
1560 std::istringstream zEt(zEnd);
1563 int idBox = createGBlackBox(0,0,package,type);
1564 GObjectController *cont = _controllers[idBox];
1565 GBlackBoxModel *bbmod = (GBlackBoxModel*)cont->getModel();
1566 bbmod->setBBTKName(name);
1567 bbmod->setInicPoint(xIn,yIn,zIn);
1568 bbmod->setFinalPoint(xEn,yEn,zEn);
1571 bbmod->setExecutable(true);
1573 else if(isExec=="FALSE")
1575 bbmod->setExecutable(false);
1579 getline(inputStream,line);//PORT o FIN_BOX
1580 std::string port=line.substr(0,4);
1583 getline(inputStream,line);//name:value
1585 strcpy( poort, line.c_str() );
1586 result = strtok( poort, delims );//name
1587 std::string name(result);
1588 result = strtok( NULL, delims );//value
1589 std::string value(result);
1591 bbmod->setValueToInput(name,value);
1593 getline(inputStream,line);//PORT o FIN_BOX
1594 port=line.substr(0,4);
1597 bbmod->notifyObservers(_idManager);
1602 getline(inputStream,line);//CONNECTIONS:num
1604 strcpy( conns, line.c_str() );
1605 result = strtok( conns, delims );
1606 result = strtok( NULL, delims );
1609 std::istringstream isCons(result);
1612 for(int i = 0;i<numConns;i++)
1615 getline(inputStream,line);//CONNECTION
1616 getline(inputStream,line);//Startbox.PortName:EndBox.PortName
1619 strcpy( connec, line.c_str() );
1620 result = strtok( connec, delims );
1621 std::string nameStartBox(result);
1622 result = strtok( NULL, delims );
1623 std::string nameStartPort(result);
1624 result = strtok( NULL, delims );
1625 std::string nameEndBox(result);
1626 result = strtok( NULL, delims );
1627 std::string nameEndPort(result);
1629 std::vector<int> lstB = getBlackBoxes();
1631 GPortModel *startP=NULL;
1632 GPortModel *endP=NULL;
1633 for(int j = 0;j<lstB.size();j++)
1636 GBlackBoxModel *bbMod = (GBlackBoxModel*)_controllers[idB]->getModel();
1637 if(_controllers[idB]->getModel()->getBBTKName()==nameStartBox)
1639 startP = bbMod->getOutputPort(nameStartPort);
1641 else if(_controllers[idB]->getModel()->getBBTKName()==nameEndBox)
1643 endP = bbMod->getInputPort(nameEndPort);
1651 std::vector<int> lstInputs = getComplexInputPorts();
1652 for(int j = 0;j<lstInputs.size();j++)
1654 int idB = lstInputs[j];
1655 GBoxModel *cbMod = (GBoxModel*)_controllers[idB]->getModel();
1656 if(_controllers[idB]->getModel()->getBBTKName()==nameStartBox)
1658 startP = cbMod->getOutputPort(nameStartPort);
1665 std::vector<int> lstOutputs = getComplexOutputPorts();
1666 for(int j = 0;j<lstOutputs.size();j++)
1668 int idB = lstOutputs[j];
1669 GBoxModel *cbMod = (GBoxModel*)_controllers[idB]->getModel();
1670 if(_controllers[idB]->getModel()->getBBTKName()==nameEndBox)
1672 endP = cbMod->getInputPort(nameEndPort);
1678 int idCon = createGConnector(startP);
1679 _worldState = NOTHING_HAPPENS;
1680 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
1682 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
1683 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
1684 tempp->endContourCreation();
1685 conMod->setEndPort(endP);
1686 conView->updateStartEndPoints();
1693 //=========================================================================
1695 std::vector<int> wxVtkSceneManager::getBlackBoxes()
1697 std::vector<int> vect;
1698 std::map<int, GObjectController*>::iterator it;
1699 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1701 GObjectController *cont = it->second;
1702 if(cont->getGObjectType()==GBLACKBOX)
1704 vect.push_back(cont->getId());
1710 //=========================================================================
1712 std::vector<int> wxVtkSceneManager::getComplexInputPorts()
1714 std::vector<int> vect;
1715 std::map<int, GObjectController*>::iterator it;
1716 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1718 GObjectController *cont = it->second;
1719 if(cont->getGObjectType()==GCOMPLEXINPUTPORT)
1721 vect.push_back(cont->getId());
1727 //=========================================================================
1729 std::vector<int> wxVtkSceneManager::getComplexOutputPorts()
1731 std::vector<int> vect;
1732 std::map<int, GObjectController*>::iterator it;
1733 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1735 GObjectController *cont = it->second;
1736 if(cont->getGObjectType()==GCOMPLEXOUTPUTPORT)
1738 vect.push_back(cont->getId());
1744 //=========================================================================
1746 std::vector<int> wxVtkSceneManager::getConnections()
1748 std::vector<int> vect;
1749 std::map<int, GObjectController*>::iterator it;
1750 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1752 GObjectController *cont = it->second;
1753 if(cont->getGObjectType()==GCONNECTOR)
1755 vect.push_back(cont->getId());
1761 //=========================================================================
1763 bool wxVtkSceneManager::isComplexBox()
1765 return _isComplexBox;
1768 //=========================================================================
1770 void wxVtkSceneManager::setComplexBox(bool val)
1775 //=========================================================================
1777 int wxVtkSceneManager::addObjectController(GObjectController* objController)
1779 //Register the controller of the new object
1780 registerController((InteractorStyleMaracas*) objController);
1782 //Add the object to the objects list
1783 int newId = _contLastId;//_controllers.size();
1784 objController->setId(newId);
1785 _controllers[newId] = objController;
1790 //=========================================================================
1792 int wxVtkSceneManager::getNumSelectedObjects()
1794 return _selectedObjects.size();
1797 //=========================================================================
1799 std::map<int,GObjectController*> wxVtkSceneManager::getSelectedObjects()
1801 std::map<int,GObjectController*> mapSelected;
1803 std::map<int, GObjectController*>::iterator it;
1804 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1806 GObjectController *cont = it->second;
1807 if(cont->getGObjectType()==GBLACKBOX && cont->getView()->getState()==SELECTED)
1809 mapSelected[cont->getId()]=cont;
1813 std::map<int, GObjectController*>::iterator it2;
1814 for(it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
1816 GObjectController *cont = it2->second;
1817 if(cont->getGObjectType()==GCONNECTOR)
1819 GConnectorModel* cmod = (GConnectorModel*)cont->getModel();
1820 GBoxModel* endPortParentBox = cmod->getEndPort()->getParentBox();
1821 GBoxModel* startPortParentBox = cmod->getStartPort()->getParentBox();
1823 std::map<int, GObjectController*>::iterator iterOBJ1 = mapSelected.find(startPortParentBox->getObjectId());
1824 std::map<int, GObjectController*>::iterator iterOBJ2 = mapSelected.find(endPortParentBox->getObjectId());
1826 if(iterOBJ1 != mapSelected.end() && iterOBJ2 != mapSelected.end())
1828 int ID = cont->getId();
1829 mapSelected[ID]=cont;
1837 //=========================================================================
1839 void wxVtkSceneManager::addObjects(std::map<int,GObjectController*> objectsMap)
1842 std::map<int,int> oldIdNewIdBoxes;
1843 std::vector<int> connections;
1845 std::map<int, GObjectController*>::iterator it;
1846 for(it = objectsMap.begin(); it != objectsMap.end(); ++it)
1848 GObjectController *cont = it->second;
1849 int type = cont->getGObjectType();
1854 double xInic, yInic,zInic;
1855 GBlackBoxModel* copyBox = (GBlackBoxModel*)cont->getModel();
1856 copyBox->getInicPoint(xInic,yInic,zInic);
1857 int idBox = createGBlackBox(0,0,copyBox->getBBTKPackage(),copyBox->getBBTKType());
1859 int idcB = copyBox->getObjectId();
1860 oldIdNewIdBoxes[idcB]=idBox;
1861 cont = _controllers[idBox];
1862 GBlackBoxModel* newbox = (GBlackBoxModel*)cont->getModel();
1863 newbox->setInicPoint(xInic,yInic,zInic);
1864 int num = newbox->getNumInputPorts();
1865 for(int j=0;j<num;j++)
1867 newbox->setValueToInputPort(j,copyBox->getValueInputPort(j));
1869 newbox->notifyObservers(_idManager);
1871 else if(type==GCONNECTOR)
1873 int idCon = cont->getId();
1874 connections.push_back(idCon);
1879 for(int i = 0 ;i<connections.size();i++)
1881 int objId = connections[i];
1882 GObjectController *cont = objectsMap[objId];
1883 GConnectorModel* connectModel = (GConnectorModel*)cont->getModel();
1885 GPortModel* startPort = connectModel->getStartPort();
1886 int startPortIndex = startPort->getPosInBox();
1887 GPortModel* endPort = connectModel->getEndPort();
1888 int endPortIndex = endPort->getPosInBox();
1890 GBlackBoxModel* startPortParentBox = (GBlackBoxModel*)startPort->getParentBox();
1891 GBlackBoxModel* endPortParentBox = (GBlackBoxModel*)endPort->getParentBox();
1893 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
1894 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
1896 GBlackBoxModel* newStartBox = (GBlackBoxModel*)_controllers[idNewStartBox]->getModel();
1897 GBlackBoxModel* newEndBox = (GBlackBoxModel*)_controllers[idNewEndBox]->getModel();
1899 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
1900 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
1902 // Creates connection
1903 int idCon = createGConnector(newStartPort);
1904 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
1905 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
1906 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
1907 tempp->endContourCreation();
1908 conMod->setEndPort(newEndPort);
1909 conView->updateStartEndPoints();
1912 std::map<int, int>::iterator itIds;
1913 for(itIds = oldIdNewIdBoxes.begin(); itIds != oldIdNewIdBoxes.end(); ++itIds)
1915 int idOld = itIds->first;
1916 int idNew = itIds->second;
1918 GBlackBoxModel* oldBox = (GBlackBoxModel*)objectsMap[idOld]->getModel();
1919 GBlackBoxModel* newBox = (GBlackBoxModel*)_controllers[idNew]->getModel();
1921 std::vector<int> oldInputConnections = oldBox->getConnectedInputs();
1922 std::vector<int> oldOutputConnections = oldBox->getConnectedOutputs();
1923 std::vector<int> newInputConnections = newBox->getConnectedInputs();
1924 std::vector<int> newOutputConnections = newBox->getConnectedOutputs();
1926 for(int k = 0; k<oldInputConnections.size();k++)
1930 for(int l = 0; l<newInputConnections.size() && !exist;l++)
1932 if(oldInputConnections[k]==newInputConnections[l])
1940 //Create complex input
1941 int posInBox = oldInputConnections[k];
1942 GPortModel* inputPort = oldBox->getInputPort(posInBox);
1943 std::string inputPortName = inputPort->getBBTKName();
1944 int idInputPort = createGComplexBoxInputPort(inputPortName);
1945 GObjectController *cont = _controllers[idInputPort];
1946 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
1948 inputPort->getInicPoint(xIn,yIn,zIn);
1950 cbmod->setInicPoint(xIn,yIn,zIn);
1951 cbmod->notifyObservers(_idManager);
1953 GPortModel* inputPortEnd = newBox->getInputPort(posInBox);
1955 // Creates connection
1956 int idCon = createGConnector(cbmod->getOutputPort(0));
1957 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
1958 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
1959 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
1960 tempp->endContourCreation();
1961 conMod->setEndPort(inputPortEnd);
1962 conView->updateStartEndPoints();
1969 for(int k = 0; k<oldOutputConnections.size();k++)
1973 for(int l = 0; l<newOutputConnections.size() && !exist;l++)
1975 if(oldOutputConnections[k]==newOutputConnections[l])
1983 //Create complex output
1984 int posInBox = oldOutputConnections[k];
1985 GPortModel* outputPort = oldBox->getOutputPort(posInBox);
1986 std::string outputPortName = outputPort->getBBTKName();
1987 int idOutputPort = createGComplexBoxOutputPort(outputPortName);
1988 GObjectController *cont = _controllers[idOutputPort];
1989 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
1991 outputPort->getInicPoint(xIn,yIn,zIn);
1993 cbmod->setInicPoint(xIn,yIn,zIn);
1994 cbmod->notifyObservers(_idManager);
1996 GPortModel* outputPortEnd = newBox->getOutputPort(posInBox);
1998 // Creates connection
1999 int idCon = createGConnector(outputPortEnd);
2000 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
2001 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
2002 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
2003 tempp->endContourCreation();
2004 conMod->setEndPort(cbmod->getInputPort(0));
2005 conView->updateStartEndPoints();
2016 //=========================================================================
2018 } // EO namespace bbtk