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 printf ("RaC-EED 21-06-2010 %p wxVtkSceneManager::wxVtkSceneManager If you comment this line, the drag and drop functionnality is not initialized.\n" , this );
58 _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);
200 //=========================================================================
202 int wxVtkSceneManager::createGComplexBoxInputPort(std::string inputName)
204 int windowWidth=_baseView->GetRenWin()->GetSize()[0];
205 int windowHeight=_baseView->GetRenWin()->GetSize()[1];
207 int type = GCOMPLEXINPUTPORT;
209 //Create the MVC Objects
211 GComplexBoxPortModel *model = (GComplexBoxPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
212 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
213 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
215 //Prepares the initial model
218 double yy = windowHeight-5;
220 //z value is not important yet, because it is only used a parallel projection
223 _baseView->TransCoordScreenToWorld(xx,yy,zz);
224 model->setInicPoint(xx,yy,zz);
226 model->setBBTKName(inputName);
227 model->setBBTKType("ComplexInputPort");
228 model->setComplexPortType(type);
230 model->addObserver(view);
231 model->addObserver(this);
233 //create the output port
234 GPortController* portController = createGPort(GOUTPUTPORT,inputName,"ComplexInputPort",0,model);
235 model->addOutputPort((GPortModel*)portController->getModel());
237 //Associates the view with the correspondent renderer and the model.
238 //(NOTE: Refresh is only made by the view)
239 view->setModel(model);
240 view->setBaseView(_baseView);
241 view->initVtkObjects();
243 //Associates the controller with the correspondent model and view
244 controller->setModelAndView(model,view);
246 //Resgiter change to the observers of the actual model
247 model->notifyObservers(_idManager);
249 int newId = addObjectController(controller);
253 //=========================================================================
255 int wxVtkSceneManager::createGComplexBoxOutputPort(std::string outputName)
257 int windowWidth=_baseView->GetRenWin()->GetSize()[0];
258 int windowHeight=_baseView->GetRenWin()->GetSize()[1];
260 int type = GCOMPLEXOUTPUTPORT;
262 //Create the MVC Objects
264 GComplexBoxPortModel *model = (GComplexBoxPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
265 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
266 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
268 //Prepares the initial model
271 double yy = windowHeight-5;
273 //z value is not important yet, because it is only used a parallel projection
276 _baseView->TransCoordScreenToWorld(xx,yy,zz);
277 model->setInicPoint(xx,yy,zz);
279 model->setBBTKName(outputName);
280 model->setBBTKType("ComplexOutputPort");
281 model->setComplexPortType(type);
283 model->addObserver(view);
284 model->addObserver(this);
286 //create the output port
287 GPortController* portController = createGPort(GINPUTPORT,outputName,"ComplexInputPort",0,model);
288 model->addInputPort((GPortModel*)portController->getModel());
290 //Associates the view with the correspondent renderer and the model.
291 //(NOTE: Refresh is only made by the view)
292 view->setModel(model);
293 view->setBaseView(_baseView);
294 view->initVtkObjects();
296 //Associates the controller with the correspondent model and view
297 controller->setModelAndView(model,view);
299 //Resgiter change to the observers of the actual model
300 model->notifyObservers(_idManager);
302 int newId = addObjectController(controller);
306 //=========================================================================
308 int wxVtkSceneManager::createGInputPort(int portType, int posinBox,GBoxModel *blackBox, BlackBoxInputDescriptor *desc)
310 GPortController* portController = createGPort(portType,desc->GetName(),desc->GetTypeName(),posinBox,blackBox);
311 blackBox->addInputPort((GPortModel*)portController->getModel());
312 return portController->getId();
315 //=========================================================================
317 int wxVtkSceneManager::createGOutputPort(int portType, int posinBox,GBoxModel *blackBox, BlackBoxOutputDescriptor *desc)
319 GPortController* portController = createGPort(portType,desc->GetName(),desc->GetTypeName(),posinBox,blackBox);
320 blackBox->addOutputPort((GPortModel*)portController->getModel());
321 return portController->getId();
324 //=========================================================================
326 GPortController* wxVtkSceneManager::createGPort(int portType,std::string bbtkName, std::string bbtkType, int posInBox,GBoxModel *blackBox)
330 //Create the MVC Objects
331 GPortModel *model = (GPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
332 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
333 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
335 model->registerInBox(blackBox,portType, posInBox);
337 model->setBBTKType(bbtkType);
338 model->setBBTKName(bbtkName);
340 model->addObserver(view);
341 model->addObserver(this);
343 //Associates the view with the correspondent renderer and the model.
344 //(NOTE: Refresh is only made by the view)
345 view->setModel(model);
346 view->setBaseView(_baseView);
347 view->initVtkObjects();
349 //Associates the controller with the correspondent model and view
350 controller->setModelAndView(model,view);
352 model->notifyObservers(_idManager);
354 int newId = addObjectController(controller);
356 return (GPortController*)controller;
359 //=========================================================================
361 int wxVtkSceneManager::createGConnector(GPortModel* startPort)
363 int type = GCONNECTOR;
365 manualConnectorContourController* manContourControl = new manualConnectorContourController();
366 manualConnectorContourView* manContourView = new manualConnectorContourView();
367 manualContourModel* manContourModel = new manualContourModel();
369 GConnectorController* connectorcontroller = new GConnectorController();
370 GConnectorModel* connectorModel = new GConnectorModel();
371 vtkGConnectorView* connectorView = new vtkGConnectorView();
372 connectorModel->setGObjectType(type);
374 manContourModel->SetCloseContour(false);
375 connectorModel->setStartPort(startPort);
377 manContourView->SetModel( manContourModel );
378 manContourView->SetWxVtkBaseView( _baseView );
379 manContourView->SetRange( 0.5 );
380 manContourView->SetZ( 900 );
382 manContourView->SetColorNormalContour(0, 0, 1);
383 manContourView->SetColorEditContour(0.5, 0.5, 0.5);
384 manContourView->SetColorSelectContour(1, 0.8, 0);
385 manContourView->SetWidthLine(1);
386 manContourView->SetShowText(false);
388 manContourControl->SetModelView( manContourModel , manContourView );
390 manContourControl->CreateNewManualContour();
392 manContourView->RefreshContour();
396 connectorModel->getInicPoint(x,y,z);
398 manContourControl->SetState(1);
399 manContourModel->SetCloseContour(false);
401 manContourModel->AddPoint(x,y,z);
402 manContourView->AddPoint();
404 manContourModel->AddPoint(x,y,z);
405 manContourView->AddPoint();
407 int bak= manContourControl->GetNumberOfPointsManualContour() - 1;
408 manContourControl->_bakIdPoint=bak;
409 manContourView->Refresh();
411 manContourControl->SetMoving( false );
413 connectorcontroller->setModelAndView(connectorModel,connectorView);
415 int newId = addObjectController(connectorcontroller);
417 connectorcontroller->setManualContourController(manContourControl);
418 connectorModel->setManualContourModel(manContourModel);
419 connectorView->setManualContourView(manContourView);
420 connectorView->setModel(connectorModel);
421 connectorView->setBaseView(_baseView);
424 connectorModel->addObserver(connectorView);
425 connectorModel->addObserver(this);
430 //=========================================================================
432 void wxVtkSceneManager::registerController(InteractorStyleMaracas *param)
434 vtkInteractorStyleBaseView* baseViewControlManager = (vtkInteractorStyleBaseView*)_baseView->GetInteractorStyleBaseView();
435 baseViewControlManager->AddInteractorStyleMaracas( param );
438 //=========================================================================
440 void wxVtkSceneManager::unregisterController(InteractorStyleMaracas *param)
442 vtkInteractorStyleBaseView* baseViewControlManager = (vtkInteractorStyleBaseView*)_baseView->GetInteractorStyleBaseView();
443 baseViewControlManager->RemoveInteractorStyleMaracas( param );
446 //=========================================================================
448 vtkRenderer* wxVtkSceneManager::getRenderer()
450 return _baseView->GetRenderer();
453 //=========================================================================
455 vtkRenderWindow* wxVtkSceneManager::getRenderWindow()
457 return _baseView->GetRenWin();
459 //=========================================================================
462 void wxVtkSceneManager::update(int idController,int command)
464 if(command != NO_COMMAND)
466 if(command == ADD_TO_SELECTED)
468 GObjectController* cont = _controllers[idController];
471 for (int i=0; i<_selectedObjects.size() && foundID==false; i++)
473 int id = _selectedObjects[i];
481 int id = idController;
482 _selectedObjects.push_back(id);
486 else if(command == INIT_CREATION_CONTOUR)
488 _worldState = INIT_CREATION_CONTOUR;
489 GObjectController* cont = _controllers[idController];
490 GPortModel* startOutputPort = (GPortModel*)cont->getModel();
493 // The last one is the controller of the connector
494 std::map<int, GObjectController*>::iterator it2;
496 for(it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
498 GObjectController *cont = it2->second;
499 if(cont->getGObjectType() == GPORT )
501 GPortModel* port = (GPortModel*)cont->getModel();
502 if(port->getPortType()==GINPUTPORT)
504 cont->SetActive(true);
508 cont->getView()->setState(NOTHING_HAPPENS);
509 cont->getModel()->notifyObservers(_idManager);
510 cont->SetActive(false);
515 cont->getView()->setState(NOTHING_HAPPENS);
516 cont->getModel()->notifyObservers(_idManager);
517 cont->SetActive(false);
521 _selectedObjects.clear();
523 _idConnectionInCreation=createGConnector(startOutputPort);
526 else if(command == FIN_CREATION_CONTOUR && _worldState == INIT_CREATION_CONTOUR)
528 _worldState = NOTHING_HAPPENS;
529 //int id = _controllers.size()-1;
530 GObjectController* cont = _controllers[_idConnectionInCreation];
531 GConnectorModel* modelContour = (GConnectorModel*)cont->getModel();
533 GObjectController* finPort = _controllers[idController];
534 if(finPort->getGObjectType() == GPORT)
536 GPortModel* modelPort = (GPortModel*)finPort->getModel();
537 modelContour->setEndPort(modelPort);
540 manualConnectorContourController* manCont = ((GConnectorController*)cont)->getManualContourController();
541 manualConnectorContourView* connView = (manualConnectorContourView*)manCont->GetManualViewBaseContour();
544 std::map<int, GObjectController*>::iterator it2;
546 for(it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
548 GObjectController *cont = it2->second;
549 if(cont->getView()!=NULL)
551 cont->getView()->setState(NOTHING_HAPPENS);
552 cont->getModel()->notifyObservers(_idManager);
554 cont->SetActive(true);
561 //=========================================================================
563 bool wxVtkSceneManager::OnMouseMove()
566 wxVTKRenderWindowInteractor *wxVTKiren;
567 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
568 wxVTKiren->GetEventPosition(X,Y);
571 if(_worldState == DRAG_OBJECTS)
573 for (int i=0; i<_selectedObjects.size(); i++)
575 int id = _selectedObjects[i];
576 GObjectController* cont = _controllers[id];
579 cont->getView()->setStartDragging(true);
581 cont->getView()->moveObject(X,Y);
582 cont->getView()->setState(DRAG);
583 cont->getModel()->notifyObservers(_idManager);
586 std::map<int, GObjectController*>::iterator it;
588 for(it = _controllers.begin(); it != _controllers.end(); ++it)
590 GObjectController *desc = it->second;
591 if(desc->getGObjectType()==GCONNECTOR)
593 vtkGConnectorView* vconn = (vtkGConnectorView*)desc->getView();
594 vconn->updateStartEndPoints();
598 _startDragging=false;
601 else if(_worldState == NOTHING_HAPPENS || _worldState == INIT_CREATION_CONTOUR)
603 std::map<int, GObjectController*>::iterator it;
605 for(it = _controllers.begin(); it != _controllers.end(); ++it)
607 GObjectController *desc = it->second;
608 int type = desc->getGObjectType();
609 int state = desc->getView()->getState();
611 if(state == HIGHLIGHTED){
613 updateStatusBar(desc->getStatusText());
616 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
617 _parent->displayBlackBoxInfo(mod->getBBTKPackage(),mod->getBBTKType());
626 //=========================================================================
628 bool wxVtkSceneManager::OnLeftButtonDown()
630 if(_worldState==INIT_CREATION_CONTOUR)
632 bool isOverPort=false;
633 std::map<int, GObjectController*>::iterator it;
634 for(it = _controllers.begin(); it != _controllers.end() && isOverPort==false; ++it)
636 GObjectController *desc = it->second;
637 if(desc->getGObjectType()==GPORT)
639 GPortModel* portmod=(GPortModel*)desc->getModel();
640 vtkGObjectView* portView=desc->getView();
641 if(portmod->getPortType()==GINPUTPORT && portView->getState()==HIGHLIGHTED)
648 if(isOverPort==false)
650 _worldState=NOTHING_HAPPENS;
651 //int lastId = _controllers.size()-1;
652 GConnectorController *connector = (GConnectorController*)_controllers[_controllers.size()-1];
653 connector->removeFromScene();
654 unregisterController(connector);
655 _controllers.erase(_controllers.size()-1);
657 for(it = _controllers.begin(); it != _controllers.end(); ++it)
659 GObjectController *desc = it->second;
660 desc->SetActive(true);
661 desc->getView()->setState(NOTHING_HAPPENS);
662 desc->getModel()->notifyObservers(_idManager);
667 if(_selectedObjects.size()!=0)
669 _worldState = DRAG_OBJECTS;
670 _startDragging = true;
672 for (int i = 0; i < _selectedObjects.size(); i++)
674 int id = _selectedObjects[i];
675 GObjectController* cont = _controllers[id];
676 cont->getView()->setState(DRAG);
677 cont->getModel()->notifyObservers(_idManager);
686 //=========================================================================
688 bool wxVtkSceneManager::OnLeftButtonUp()
690 if(_worldState == DRAG_OBJECTS)
692 _worldState = NOTHING_HAPPENS;
694 for (int i = 0; i < _selectedObjects.size(); i++)
696 int id = _selectedObjects[i];
697 GObjectController* cont = _controllers[id];
698 cont->getView()->setState(SELECTED);
699 cont->getModel()->notifyObservers(_idManager);
705 //=========================================================================
707 bool wxVtkSceneManager::OnRightButtonUp()
709 if(_worldState==INIT_CREATION_CONTOUR)
711 _worldState=NOTHING_HAPPENS;
712 //int lastId = _controllers.size()-1;
713 GConnectorController *connector = (GConnectorController*)_controllers[_idConnectionInCreation];
714 connector->removeFromScene();
715 unregisterController(connector);
716 _controllers.erase(_idConnectionInCreation);
718 std::map<int, GObjectController*>::iterator it;
719 for(it = _controllers.begin(); it != _controllers.end(); ++it)
721 GObjectController *desc = it->second;
722 desc->SetActive(true);
723 desc->getView()->setState(NOTHING_HAPPENS);
724 desc->getModel()->notifyObservers(_idManager);
729 for (int i = 0; i < _selectedObjects.size(); i++)
731 int id = _selectedObjects[i];
732 GObjectController* cont = _controllers[id];
733 cont->SetActive(true);
734 cont->getView()->setState(NOTHING_HAPPENS);
735 cont->getModel()->notifyObservers(_idManager);
738 _selectedObjects.clear();
743 //=========================================================================
745 bool wxVtkSceneManager::OnLeftDClick()
748 wxVTKRenderWindowInteractor *wxVTKiren;
749 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
750 wxVTKiren->GetEventPosition(X,Y);
752 std::map<int, GObjectController*>::iterator it;
754 bool clickOnObject = false;
756 for(it = _controllers.begin(); it != _controllers.end() && clickOnObject==false; ++it)
758 GObjectController *cont = it->second;
759 int type = cont->getGObjectType();
761 if(cont->getView()->isPointInside(X,Y))
765 for (int i=0; i<_selectedObjects.size(); i++)
767 int id = _selectedObjects[i];
768 GObjectController* control = _controllers[id];
769 control->getView()->setState(NOTHING_HAPPENS);
771 _selectedObjects.clear();
773 GBlackBoxModel *bbmodel = (GBlackBoxModel*)cont->getModel();
774 _parent->editBlackBox(bbmodel);
776 clickOnObject = true;
780 if(clickOnObject==false)
782 //_parent->editDiagramParameters(this);
788 //=========================================================================
790 bool wxVtkSceneManager::OnChar()
792 char keyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
794 // KeyCode 127 : Delete Key
795 // KeyCode 8 : Backspace Key
796 if(keyCode == 8 || keyCode == 127)
798 if(_selectedObjects.size()>0)
800 for(int i=0;i<_selectedObjects.size();i++)
802 int id = _selectedObjects[i];
805 _selectedObjects.clear();
812 //=========================================================================
814 void wxVtkSceneManager::deleteObject(int id)
816 GObjectController *control = _controllers[id];
817 std::vector<int> controllersToRemove;
819 if(control->getGObjectType()==GBLACKBOX || control->getGObjectType()==GCOMPLEXINPUTPORT || control->getGObjectType()==GCOMPLEXOUTPUTPORT)
821 GBoxModel *bbmod = (GBoxModel*)control->getModel();
822 std::vector<GPortModel*> inputs = bbmod->getInputPorts();
824 bool boxConnected = false;
826 // Add box input controllers to be removed
827 for(int i = 0;i<inputs.size();i++)
829 controllersToRemove.push_back(inputs[i]->getObjectId());
830 if(inputs[i]->isConnected())
836 std::vector<GPortModel*> outputs = bbmod->getOutputPorts();
838 // Add box output controllers to be removed
839 for(int i = 0;i<outputs.size();i++)
841 controllersToRemove.push_back(outputs[i]->getObjectId());
842 if(outputs[i]->isConnected())
848 // Add connection controllers to be removed
849 std::map<int, GObjectController*>::iterator it;
850 for(it = _controllers.begin(); it != _controllers.end(); ++it)
852 GObjectController *cont = it->second;
853 int type = cont->getGObjectType();
856 GConnectorModel *conMod = (GConnectorModel*)cont->getModel();
857 if(conMod->getStartPort()!=NULL && conMod->getStartPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
859 controllersToRemove.push_back(conMod->getObjectId());
861 if(conMod->getEndPort()!=NULL && conMod->getEndPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
863 controllersToRemove.push_back(conMod->getObjectId());
868 // Add box controller to be removed
869 controllersToRemove.push_back(bbmod->getObjectId());
871 else if(control->getGObjectType()==GCONNECTOR)
873 GConnectorModel *conMod = (GConnectorModel*)control->getModel();
874 controllersToRemove.push_back(conMod->getObjectId());
877 for(int i = 0;i<controllersToRemove.size();i++)
879 int id = controllersToRemove[i];
880 GObjectController *cont = _controllers[id];
883 cont->removeFromScene();
884 unregisterController((InteractorStyleMaracas*)cont);
885 _controllers.erase(id);
892 //=========================================================================
894 void wxVtkSceneManager::displayBlackBoxInfo(std::string packageName, std::string boxName)
896 _parent->displayBlackBoxInfo(packageName,boxName);
899 //=========================================================================
901 void wxVtkSceneManager::updateStatusBar(std::string textStatus)
903 _parent->updateStatusBar(textStatus);
906 //=========================================================================
908 std::string wxVtkSceneManager::getDiagramBBS()
910 bool existsExec=false;
912 std::vector<std::string> packages;
913 std::vector<int> boxes;
914 std::vector<int> connections;
915 std::vector<int> execBoxes;
917 std::map<int, GObjectController*>::iterator it;
919 for(it = _controllers.begin(); it != _controllers.end(); ++it)
921 GObjectController *desc = it->second;
922 int type = desc->getGObjectType();
926 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
928 std::string pkg = mod->getBBTKPackage();
929 bool existsPkg = false;
930 for(int t = 0;t<packages.size() && existsPkg == false;t++)
939 packages.push_back(pkg);
943 boxes.push_back(it->first);
944 if(mod->isExecutable())
946 execBoxes.push_back(it->first);
950 else if(type==GCONNECTOR)
952 connections.push_back(it->first);
956 std::string script = "";
957 script+="# BBTK GEditor Script\n";
958 script+="# ----------------------\n";
961 script+="include std\n"; // EED
962 script+="include itkvtk\n"; // EED
964 for(i = 0; i<packages.size();i++)
971 // script+="include std\n"; // JPR
973 for(i = 0; i<boxes.size();i++)
977 GObjectController *control = _controllers[id];
978 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
980 script+=model->getBBTKType();
982 script+=model->getBBTKName();
985 std::vector<GPortModel*> inputs = model->getInputPorts();
986 for(int j = 0; j<inputs.size();j++)
988 GPortModel* inputPort = inputs[j];
989 if(inputPort->isValueSet())
992 script+=model->getBBTKName();
994 script+=inputPort->getBBTKName();
996 script+=inputPort->getValue();
1003 for(i = 0; i<connections.size();i++)
1006 int id = connections[i];
1007 GObjectController *control = _controllers[id];
1008 GConnectorModel *model = (GConnectorModel*)control->getModel();
1010 //Start Connection info
1011 GPortModel *start = model->getStartPort();
1012 script+=start->getParentBox()->getBBTKName();
1014 script+=start->getBBTKName();
1018 //End Connection info
1019 GPortModel *end = model->getEndPort();
1020 script+=end->getParentBox()->getBBTKName();
1022 script+=end->getBBTKName();
1027 for(i = 0; i<execBoxes.size();i++)
1030 int id = execBoxes[i];
1031 GObjectController *control = _controllers[id];
1032 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1034 script+=model->getBBTKName();
1043 //=========================================================================
1045 std::string wxVtkSceneManager::saveComplexBoxBBS(std::string cbName,std::string cbAuthor,std::string cbCategory,std::string cbDescription)
1048 std::vector<std::string> packages;
1049 std::vector<int> boxes;
1050 std::vector<int> connections;
1051 std::vector<int> execBoxes;
1053 std::map<int, GObjectController*>::iterator it;
1055 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1057 GObjectController *desc = it->second;
1058 int type = desc->getGObjectType();
1062 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
1064 std::string pkg = mod->getBBTKPackage();
1065 bool existsPkg = false;
1066 for(int t = 0;t<packages.size() && existsPkg == false;t++)
1068 if(packages[t]==pkg)
1075 packages.push_back(pkg);
1079 boxes.push_back(it->first);
1080 if(mod->isExecutable())
1082 execBoxes.push_back(it->first);
1085 else if(type==GCONNECTOR)
1087 connections.push_back(it->first);
1091 std::string script = "";
1093 script+="include std\n"; // EED
1094 script+="include itkvtk\n"; // EED
1096 for(i = 0; i<packages.size();i++)
1099 script+=packages[i];
1103 // Definition of a complex box
1108 script+="author \" ";
1112 script+="description \" ";
1113 script+=cbDescription;
1117 for(i = 0; i<boxes.size();i++)
1121 GObjectController *control = _controllers[id];
1122 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1124 script+=model->getBBTKType();
1126 script+=model->getBBTKName();
1129 std::vector<GPortModel*> inputs = model->getInputPorts();
1130 for(int j = 0; j<inputs.size();j++)
1132 GPortModel* inputPort = inputs[j];
1133 if(inputPort->isValueSet())
1136 script+=model->getBBTKName();
1138 script+=inputPort->getBBTKName();
1140 script+=inputPort->getValue();
1147 // Create connections in the script. If the connection is made with a complex port, it is created the input or output
1149 std::string complexInputs="";
1150 std::string complexOutputs="";
1152 for(i = 0; i<connections.size();i++)
1154 int id = connections[i];
1155 GObjectController *control = _controllers[id];
1156 GConnectorModel *model = (GConnectorModel*)control->getModel();
1159 GPortModel *start = model->getStartPort();
1160 GBoxModel *startBox =start->getParentBox();
1162 GPortModel *end = model->getEndPort();
1163 GBoxModel *endBox =end->getParentBox();
1165 if(startBox->getGObjectType()==GCOMPLEXINPUTPORT)
1167 complexInputs+="input ";
1168 complexInputs+=startBox->getBBTKName();
1171 complexInputs+=endBox->getBBTKName();
1173 complexInputs+=end->getBBTKName();
1176 complexInputs+="\" \"";
1178 complexInputs+="\n";
1180 else if(endBox->getGObjectType()==GCOMPLEXOUTPUTPORT)
1182 complexOutputs+="output ";
1183 complexOutputs+=endBox->getBBTKName();
1185 complexOutputs+=" ";
1186 complexOutputs+=startBox->getBBTKName();
1187 complexOutputs+=".";
1188 complexOutputs+=start->getBBTKName();
1190 complexOutputs+=" ";
1191 complexOutputs+="\" \"";
1193 complexOutputs+="\n";
1198 script+=startBox->getBBTKName();
1200 script+=start->getBBTKName();
1204 //End Connection info
1205 script+=endBox->getBBTKName();
1207 script+=end->getBBTKName();
1213 for(i = 0; i<execBoxes.size();i++)
1216 int id = execBoxes[i];
1217 GObjectController *control = _controllers[id];
1218 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1220 script+=model->getBBTKName();
1225 script+="# Complex input ports\n";
1226 script+=complexInputs;
1229 script+="# Complex output ports\n";
1230 script+=complexOutputs;
1239 //=========================================================================
1241 void wxVtkSceneManager::deleteAllBoxes()
1243 std::map<int, GObjectController*>::iterator it;
1244 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1246 GObjectController *cont = it->second;
1247 cont->removeFromScene();
1248 unregisterController((InteractorStyleMaracas*)cont);
1250 _selectedObjects.clear();
1251 _controllers.clear();
1255 //=========================================================================
1257 void wxVtkSceneManager::refreshScene()
1259 _baseView->RefreshView();
1262 //=========================================================================
1264 void wxVtkSceneManager::centerView()
1267 _baseView->GetRenderer()->GetActiveCamera()->GetFocalPoint(temp);
1268 _baseView->GetRenderer()->GetActiveCamera()->SetFocalPoint(0,0,temp[2]);
1269 _baseView->GetRenderer()->GetActiveCamera()->GetPosition(temp);
1270 _baseView->GetRenderer()->GetActiveCamera()->SetPosition(0,0,temp[2]);
1271 _baseView->RefreshView();
1275 //=========================================================================
1277 void wxVtkSceneManager::saveDiagram(std::string &content)
1281 //Print info IF COMPLEX BOX
1282 content+="COMPLEXBOX:";
1287 //Print info complex input ports
1288 std::vector<int> inputs = getComplexInputPorts();
1289 int insize = inputs.size();
1290 content+="COMPLEXINPUTS:";
1291 sprintf (buffer, "%d", insize);
1295 for(int i = 0;i<insize;i++)
1298 GObjectController *cont = _controllers[id];
1299 cont->getModel()->save(content);
1302 //Print info complex output ports
1303 std::vector<int> outputs = getComplexOutputPorts();
1304 int outsize = outputs.size();
1305 content+="COMPLEXOUTPUTS:";
1306 sprintf (buffer, "%d", outsize);
1310 for(int i = 0;i<outsize;i++)
1312 int id = outputs[i];
1313 GObjectController *cont = _controllers[id];
1314 cont->getModel()->save(content);
1323 std::vector<int> boxes = getBlackBoxes();
1324 int bsize = boxes.size();
1326 sprintf (buffer, "%d", bsize);
1330 for(int i = 0;i<bsize;i++)
1333 GObjectController *cont = _controllers[id];
1334 cont->getModel()->save(content);
1338 std::vector<int> connections = getConnections();
1339 int csize = connections.size();
1340 content+="CONNECTIONS:";
1341 sprintf (buffer, "%d", csize);
1345 for(int i = 0;i<csize;i++)
1347 int id = connections[i];
1348 GObjectController *cont = _controllers[id];
1349 cont->getModel()->save(content);
1354 //=========================================================================
1356 void wxVtkSceneManager::loadDiagram(ifstream &inputStream)
1359 std::string line="";
1360 char delims[] = ":";
1361 char *result = NULL;
1362 getline(inputStream,line);
1365 while ( !inputStream.eof() )
1367 if(line=="" || line[0]=='#')
1369 getline(inputStream,line);
1371 else if(line=="APP_START")
1382 getline(inputStream,line);//COMPLEX_BOX:TRUE|FALSE
1384 strcpy( complex, line.c_str() );
1385 result = strtok( complex, delims );
1386 result = strtok( NULL, delims );
1387 std::string isComplexBox(result);
1389 if(isComplexBox=="TRUE")
1393 //-----------------------
1394 //- COMPLEX INPUT PORTS
1395 //-----------------------
1396 getline(inputStream,line);//COMPLEXINPUTS:num
1398 strcpy( inputs, line.c_str() );
1399 result = strtok( inputs, delims );
1400 result = strtok( NULL, delims );
1403 std::istringstream inps(result);
1406 for(int i = 0;i<numInputs;i++)
1409 getline(inputStream,line);//COMPLEX_PORT
1410 getline(inputStream,line);//name
1411 std::string inputPortName(line);
1414 getline(inputStream,line);//xInic:yInic:zInic
1416 strcpy( coord, line.c_str() );
1417 result = strtok( coord, delims );//xInic
1418 std::string xInic(result);
1419 result = strtok( NULL, delims );//yInic
1420 std::string yInic(result);
1421 result = strtok( NULL, delims );//zInic
1422 std::string zInic(result);
1424 double xIn, yIn, zIn;
1425 std::istringstream xSt(xInic);
1427 std::istringstream ySt(yInic);
1429 std::istringstream zSt(zInic);
1432 getline(inputStream,line);//FIN_COMPLEX_PORT
1434 int idInputPort = createGComplexBoxInputPort(inputPortName);
1435 GObjectController *cont = _controllers[idInputPort];
1436 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
1437 cbmod->setInicPoint(xIn,yIn,zIn);
1438 cbmod->notifyObservers(_idManager);
1442 //-----------------------
1443 //- COMPLEX OUTPUT PORTS
1444 //-----------------------
1446 getline(inputStream,line);//COMPLEXOUTPUTS:num
1448 strcpy( outputs, line.c_str() );
1449 result = strtok( outputs, delims );
1450 result = strtok( NULL, delims );
1453 std::istringstream outps(result);
1454 outps >> numOutputs;
1456 for(int i = 0;i<numOutputs;i++)
1459 getline(inputStream,line);//COMPLEX_PORT
1460 getline(inputStream,line);//name
1461 std::string outputPortName(line);
1464 getline(inputStream,line);//xInic:yInic:zInic
1466 strcpy( coord, line.c_str() );
1467 result = strtok( coord, delims );//xInic
1468 std::string xInic(result);
1469 result = strtok( NULL, delims );//yInic
1470 std::string yInic(result);
1471 result = strtok( NULL, delims );//zInic
1472 std::string zInic(result);
1474 double xIn, yIn, zIn;
1475 std::istringstream xSt(xInic);
1477 std::istringstream ySt(yInic);
1479 std::istringstream zSt(zInic);
1482 getline(inputStream,line);//FIN_COMPLEX_PORT
1484 int idOutputPort = createGComplexBoxOutputPort(outputPortName);
1485 GObjectController *cont = _controllers[idOutputPort];
1486 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
1487 cbmod->setInicPoint(xIn,yIn,zIn);
1488 cbmod->notifyObservers(_idManager);
1494 getline(inputStream,line);//BOXES:num
1496 strcpy( boxes, line.c_str() );
1497 result = strtok( boxes, delims );
1498 result = strtok( NULL, delims );
1501 std::istringstream is(result);
1504 for(int i = 0;i<numBoxes;i++)
1507 getline(inputStream,line);//BOX
1508 getline(inputStream,line);//package:type:name
1510 strcpy( box, line.c_str() );
1511 result = strtok( box, delims );//package
1512 std::string package(result);
1513 result = strtok( NULL, delims );//type
1514 std::string type(result);
1515 result = strtok( NULL, delims );//name
1516 std::string name(result);
1518 getline(inputStream,line);//ISEXEC:TRUE|FALSE
1520 strcpy( exec, line.c_str() );
1521 result = strtok( exec, delims );//ISEXEC
1522 result = strtok( NULL, delims );//TRUE|FALSE
1523 std::string isExec(result);
1526 getline(inputStream,line);//xInic:yInic:zInic
1528 strcpy( coord, line.c_str() );
1529 result = strtok( coord, delims );//xInic
1530 std::string xInic(result);
1531 result = strtok( NULL, delims );//yInic
1532 std::string yInic(result);
1533 result = strtok( NULL, delims );//zInic
1534 std::string zInic(result);
1536 double xIn, yIn, zIn;
1537 std::istringstream xSt(xInic);
1539 std::istringstream ySt(yInic);
1541 std::istringstream zSt(zInic);
1545 getline(inputStream,line);//xEnd:yEnd:zEnd
1546 strcpy( coord, line.c_str() );
1547 result = strtok( coord, delims );//xEnd
1548 std::string xEnd(result);
1549 result = strtok( NULL, delims );//yEnd
1550 std::string yEnd(result);
1551 result = strtok( NULL, delims );//zEnd
1552 std::string zEnd(result);
1554 double xEn, yEn, zEn;
1555 std::istringstream xEt(xEnd);
1557 std::istringstream yEt(yEnd);
1559 std::istringstream zEt(zEnd);
1562 int idBox = createGBlackBox(0,0,package,type);
1563 GObjectController *cont = _controllers[idBox];
1564 GBlackBoxModel *bbmod = (GBlackBoxModel*)cont->getModel();
1565 bbmod->setBBTKName(name);
1566 bbmod->setInicPoint(xIn,yIn,zIn);
1567 bbmod->setFinalPoint(xEn,yEn,zEn);
1570 bbmod->setExecutable(true);
1572 else if(isExec=="FALSE")
1574 bbmod->setExecutable(false);
1578 getline(inputStream,line);//PORT o FIN_BOX
1579 std::string port=line.substr(0,4);
1582 getline(inputStream,line);//name:value
1584 strcpy( poort, line.c_str() );
1585 result = strtok( poort, delims );//name
1586 std::string name(result);
1587 result = strtok( NULL, delims );//value
1588 std::string value(result);
1590 bbmod->setValueToInput(name,value);
1592 getline(inputStream,line);//PORT o FIN_BOX
1593 port=line.substr(0,4);
1596 bbmod->notifyObservers(_idManager);
1601 getline(inputStream,line);//CONNECTIONS:num
1603 strcpy( conns, line.c_str() );
1604 result = strtok( conns, delims );
1605 result = strtok( NULL, delims );
1608 std::istringstream isCons(result);
1611 for(int i = 0;i<numConns;i++)
1614 getline(inputStream,line);//CONNECTION
1615 getline(inputStream,line);//Startbox.PortName:EndBox.PortName
1618 strcpy( connec, line.c_str() );
1619 result = strtok( connec, delims );
1620 std::string nameStartBox(result);
1621 result = strtok( NULL, delims );
1622 std::string nameStartPort(result);
1623 result = strtok( NULL, delims );
1624 std::string nameEndBox(result);
1625 result = strtok( NULL, delims );
1626 std::string nameEndPort(result);
1628 std::vector<int> lstB = getBlackBoxes();
1630 GPortModel *startP=NULL;
1631 GPortModel *endP=NULL;
1632 for(int j = 0;j<lstB.size();j++)
1635 GBlackBoxModel *bbMod = (GBlackBoxModel*)_controllers[idB]->getModel();
1636 if(_controllers[idB]->getModel()->getBBTKName()==nameStartBox)
1638 startP = bbMod->getOutputPort(nameStartPort);
1640 else if(_controllers[idB]->getModel()->getBBTKName()==nameEndBox)
1642 endP = bbMod->getInputPort(nameEndPort);
1650 std::vector<int> lstInputs = getComplexInputPorts();
1651 for(int j = 0;j<lstInputs.size();j++)
1653 int idB = lstInputs[j];
1654 GBoxModel *cbMod = (GBoxModel*)_controllers[idB]->getModel();
1655 if(_controllers[idB]->getModel()->getBBTKName()==nameStartBox)
1657 startP = cbMod->getOutputPort(nameStartPort);
1664 std::vector<int> lstOutputs = getComplexOutputPorts();
1665 for(int j = 0;j<lstOutputs.size();j++)
1667 int idB = lstOutputs[j];
1668 GBoxModel *cbMod = (GBoxModel*)_controllers[idB]->getModel();
1669 if(_controllers[idB]->getModel()->getBBTKName()==nameEndBox)
1671 endP = cbMod->getInputPort(nameEndPort);
1677 int idCon = createGConnector(startP);
1678 _worldState = NOTHING_HAPPENS;
1679 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
1681 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
1682 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
1683 tempp->endContourCreation();
1684 conMod->setEndPort(endP);
1685 conView->updateStartEndPoints();
1692 //=========================================================================
1694 std::vector<int> wxVtkSceneManager::getBlackBoxes()
1696 std::vector<int> vect;
1697 std::map<int, GObjectController*>::iterator it;
1698 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1700 GObjectController *cont = it->second;
1701 if(cont->getGObjectType()==GBLACKBOX)
1703 vect.push_back(cont->getId());
1709 //=========================================================================
1711 std::vector<int> wxVtkSceneManager::getComplexInputPorts()
1713 std::vector<int> vect;
1714 std::map<int, GObjectController*>::iterator it;
1715 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1717 GObjectController *cont = it->second;
1718 if(cont->getGObjectType()==GCOMPLEXINPUTPORT)
1720 vect.push_back(cont->getId());
1726 //=========================================================================
1728 std::vector<int> wxVtkSceneManager::getComplexOutputPorts()
1730 std::vector<int> vect;
1731 std::map<int, GObjectController*>::iterator it;
1732 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1734 GObjectController *cont = it->second;
1735 if(cont->getGObjectType()==GCOMPLEXOUTPUTPORT)
1737 vect.push_back(cont->getId());
1743 //=========================================================================
1745 std::vector<int> wxVtkSceneManager::getConnections()
1747 std::vector<int> vect;
1748 std::map<int, GObjectController*>::iterator it;
1749 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1751 GObjectController *cont = it->second;
1752 if(cont->getGObjectType()==GCONNECTOR)
1754 vect.push_back(cont->getId());
1760 //=========================================================================
1762 bool wxVtkSceneManager::isComplexBox()
1764 return _isComplexBox;
1767 //=========================================================================
1769 void wxVtkSceneManager::setComplexBox(bool val)
1774 //=========================================================================
1776 int wxVtkSceneManager::addObjectController(GObjectController* objController)
1778 //Register the controller of the new object
1779 registerController((InteractorStyleMaracas*) objController);
1781 //Add the object to the objects list
1782 int newId = _contLastId;//_controllers.size();
1783 objController->setId(newId);
1784 _controllers[newId] = objController;
1789 //=========================================================================
1791 int wxVtkSceneManager::getNumSelectedObjects()
1793 return _selectedObjects.size();
1796 //=========================================================================
1798 std::map<int,GObjectController*> wxVtkSceneManager::getSelectedObjects()
1800 std::map<int,GObjectController*> mapSelected;
1802 std::map<int, GObjectController*>::iterator it;
1803 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1805 GObjectController *cont = it->second;
1806 if(cont->getGObjectType()==GBLACKBOX && cont->getView()->getState()==SELECTED)
1808 mapSelected[cont->getId()]=cont;
1812 std::map<int, GObjectController*>::iterator it2;
1813 for(it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
1815 GObjectController *cont = it2->second;
1816 if(cont->getGObjectType()==GCONNECTOR)
1818 GConnectorModel* cmod = (GConnectorModel*)cont->getModel();
1819 GBoxModel* endPortParentBox = cmod->getEndPort()->getParentBox();
1820 GBoxModel* startPortParentBox = cmod->getStartPort()->getParentBox();
1822 std::map<int, GObjectController*>::iterator iterOBJ1 = mapSelected.find(startPortParentBox->getObjectId());
1823 std::map<int, GObjectController*>::iterator iterOBJ2 = mapSelected.find(endPortParentBox->getObjectId());
1825 if(iterOBJ1 != mapSelected.end() && iterOBJ2 != mapSelected.end())
1827 int ID = cont->getId();
1828 mapSelected[ID]=cont;
1836 //=========================================================================
1838 void wxVtkSceneManager::addObjects(std::map<int,GObjectController*> objectsMap)
1841 std::map<int,int> oldIdNewIdBoxes;
1842 std::vector<int> connections;
1844 std::map<int, GObjectController*>::iterator it;
1845 for(it = objectsMap.begin(); it != objectsMap.end(); ++it)
1847 GObjectController *cont = it->second;
1848 int type = cont->getGObjectType();
1853 double xInic, yInic,zInic;
1854 GBlackBoxModel* copyBox = (GBlackBoxModel*)cont->getModel();
1855 copyBox->getInicPoint(xInic,yInic,zInic);
1856 int idBox = createGBlackBox(0,0,copyBox->getBBTKPackage(),copyBox->getBBTKType());
1858 int idcB = copyBox->getObjectId();
1859 oldIdNewIdBoxes[idcB]=idBox;
1860 cont = _controllers[idBox];
1861 GBlackBoxModel* newbox = (GBlackBoxModel*)cont->getModel();
1862 newbox->setInicPoint(xInic,yInic,zInic);
1863 int num = newbox->getNumInputPorts();
1864 for(int j=0;j<num;j++)
1866 newbox->setValueToInputPort(j,copyBox->getValueInputPort(j));
1868 newbox->notifyObservers(_idManager);
1870 else if(type==GCONNECTOR)
1872 int idCon = cont->getId();
1873 connections.push_back(idCon);
1878 for(int i = 0 ;i<connections.size();i++)
1880 int objId = connections[i];
1881 GObjectController *cont = objectsMap[objId];
1882 GConnectorModel* connectModel = (GConnectorModel*)cont->getModel();
1884 GPortModel* startPort = connectModel->getStartPort();
1885 int startPortIndex = startPort->getPosInBox();
1886 GPortModel* endPort = connectModel->getEndPort();
1887 int endPortIndex = endPort->getPosInBox();
1889 GBlackBoxModel* startPortParentBox = (GBlackBoxModel*)startPort->getParentBox();
1890 GBlackBoxModel* endPortParentBox = (GBlackBoxModel*)endPort->getParentBox();
1892 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
1893 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
1895 GBlackBoxModel* newStartBox = (GBlackBoxModel*)_controllers[idNewStartBox]->getModel();
1896 GBlackBoxModel* newEndBox = (GBlackBoxModel*)_controllers[idNewEndBox]->getModel();
1898 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
1899 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
1901 // Creates connection
1902 int idCon = createGConnector(newStartPort);
1903 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
1904 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
1905 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
1906 tempp->endContourCreation();
1907 conMod->setEndPort(newEndPort);
1908 conView->updateStartEndPoints();
1911 std::map<int, int>::iterator itIds;
1912 for(itIds = oldIdNewIdBoxes.begin(); itIds != oldIdNewIdBoxes.end(); ++itIds)
1914 int idOld = itIds->first;
1915 int idNew = itIds->second;
1917 GBlackBoxModel* oldBox = (GBlackBoxModel*)objectsMap[idOld]->getModel();
1918 GBlackBoxModel* newBox = (GBlackBoxModel*)_controllers[idNew]->getModel();
1920 std::vector<int> oldInputConnections = oldBox->getConnectedInputs();
1921 std::vector<int> oldOutputConnections = oldBox->getConnectedOutputs();
1922 std::vector<int> newInputConnections = newBox->getConnectedInputs();
1923 std::vector<int> newOutputConnections = newBox->getConnectedOutputs();
1925 for(int k = 0; k<oldInputConnections.size();k++)
1929 for(int l = 0; l<newInputConnections.size() && !exist;l++)
1931 if(oldInputConnections[k]==newInputConnections[l])
1939 //Create complex input
1940 int posInBox = oldInputConnections[k];
1941 GPortModel* inputPort = oldBox->getInputPort(posInBox);
1942 std::string inputPortName = inputPort->getBBTKName();
1943 int idInputPort = createGComplexBoxInputPort(inputPortName);
1944 GObjectController *cont = _controllers[idInputPort];
1945 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
1947 inputPort->getInicPoint(xIn,yIn,zIn);
1949 cbmod->setInicPoint(xIn,yIn,zIn);
1950 cbmod->notifyObservers(_idManager);
1952 GPortModel* inputPortEnd = newBox->getInputPort(posInBox);
1954 // Creates connection
1955 int idCon = createGConnector(cbmod->getOutputPort(0));
1956 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
1957 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
1958 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
1959 tempp->endContourCreation();
1960 conMod->setEndPort(inputPortEnd);
1961 conView->updateStartEndPoints();
1968 for(int k = 0; k<oldOutputConnections.size();k++)
1972 for(int l = 0; l<newOutputConnections.size() && !exist;l++)
1974 if(oldOutputConnections[k]==newOutputConnections[l])
1982 //Create complex output
1983 int posInBox = oldOutputConnections[k];
1984 GPortModel* outputPort = oldBox->getOutputPort(posInBox);
1985 std::string outputPortName = outputPort->getBBTKName();
1986 int idOutputPort = createGComplexBoxOutputPort(outputPortName);
1987 GObjectController *cont = _controllers[idOutputPort];
1988 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
1990 outputPort->getInicPoint(xIn,yIn,zIn);
1992 cbmod->setInicPoint(xIn,yIn,zIn);
1993 cbmod->notifyObservers(_idManager);
1995 GPortModel* outputPortEnd = newBox->getOutputPort(posInBox);
1997 // Creates connection
1998 int idCon = createGConnector(outputPortEnd);
1999 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
2000 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
2001 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
2002 tempp->endContourCreation();
2003 conMod->setEndPort(cbmod->getInputPort(0));
2004 conView->updateStartEndPoints();
2015 //=========================================================================
2017 } // EO namespace bbtk