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);
67 //=========================================================================
69 void wxVtkSceneManager::disconnectDrop()
71 printf ("EED %p ~wxVtkSceneManager::disconnectDrop()\n" , this );
72 //EED02JUIN2010 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget(NULL);
73 // _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget( new tmpClasswxTextDropTarget() );
76 //=========================================================================
78 wxVtkSceneManager::~wxVtkSceneManager()
80 printf ("EED %p ~wxVtkSceneManager()\n" , this );
84 //=========================================================================
86 void wxVtkSceneManager::configureBaseView()
88 vtkInteractorStyleBaseView2D *interactorstylebaseview = vtkInteractorStyleBaseView2D::New();
90 _baseView->SetInteractorStyleBaseView(interactorstylebaseview);
92 // Important to activate the 2D interaction system
93 wxVTKRenderWindowInteractor *iren = _baseView->GetWxVTKRenderWindowInteractor();
94 interactorstylebaseview->SetInteractor ( iren );
95 iren->SetInteractorStyle(interactorstylebaseview);
96 interactorstylebaseview->SetwxVtkBaseView(_baseView);
98 _baseView->GetRenderer()->GetActiveCamera()->ParallelProjectionOn();
99 _baseView->GetRenderer()->ResetCamera(-100,100,-100,100,900,1000);
101 _baseView->GetRenderer()->SetBackground(0.9,0.9,0.9);
102 _baseView->GetRenderer()->GradientBackgroundOff();
103 _baseView->Refresh();
106 //=========================================================================
108 int wxVtkSceneManager::createGBlackBox(int x, int y, std::string packageName, std::string boxType)
110 int windowWidth=_baseView->GetRenWin()->GetSize()[0];
111 int windowHeight=_baseView->GetRenWin()->GetSize()[1];
113 int type = GBLACKBOX;
115 //Create the MVC Objects
117 GBlackBoxModel *model = (GBlackBoxModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
118 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
119 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
121 BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxType);
123 //Prepares the initial model
124 //The coordinates obtained are the following. Top-Left:x=0,y=0 Bottom-Right:x=width,y=height
127 double yy = windowHeight-y;
129 //z value is not important yet, because it is only used a parallel projection
132 _baseView->TransCoordScreenToWorld(xx,yy,zz);
133 model->setInicPoint(xx,yy,zz);
136 std::stringstream stream;
140 stream << "Box0" << _numBoxes;
144 stream << "Box" << _numBoxes;
146 std::string arraystring = stream.str();
148 model->setBBTKName(arraystring);
149 model->setBBTKType(boxType);
150 model->setBBTKPackage(packageName);
152 model->addObserver(view);
153 model->addObserver(this);
155 //Iterate and create the input ports
156 std::map<std::string, BlackBoxInputDescriptor*> descriptorInMap = descriptor->GetInputDescriptorMap();
157 std::map<std::string, BlackBoxInputDescriptor*>::iterator itInput;
160 for(itInput = descriptorInMap.begin(); itInput != descriptorInMap.end(); ++itInput)
162 BlackBoxInputDescriptor *desc = itInput->second;
163 createGInputPort(GINPUTPORT,i,model,desc);
167 //Iterate and create the output ports
168 std::map<std::string, BlackBoxOutputDescriptor*> descriptorOutMap = descriptor->GetOutputDescriptorMap();
169 std::map<std::string, BlackBoxOutputDescriptor*>::iterator itOutput;
172 for(itOutput = descriptorOutMap.begin();itOutput != descriptorOutMap.end(); ++itOutput)
174 BlackBoxOutputDescriptor *desc = itOutput->second;
175 createGOutputPort(GOUTPUTPORT,i,model,desc);
180 //Associates the view with the correspondent renderer and the model.
181 //(NOTE: Refresh is only made by the view)
182 view->setModel(model);
183 view->setBaseView(_baseView);
184 view->initVtkObjects();
186 //Associates the controller with the correspondent model and view
187 controller->setModelAndView(model,view);
189 //Resgiter change to the observers of the actual model
190 model->notifyObservers(_idManager);
192 int newId = addObjectController(controller);
197 //=========================================================================
199 int wxVtkSceneManager::createGComplexBoxInputPort(std::string inputName)
201 int windowWidth=_baseView->GetRenWin()->GetSize()[0];
202 int windowHeight=_baseView->GetRenWin()->GetSize()[1];
204 int type = GCOMPLEXINPUTPORT;
206 //Create the MVC Objects
208 GComplexBoxPortModel *model = (GComplexBoxPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
209 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
210 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
212 //Prepares the initial model
215 double yy = windowHeight-5;
217 //z value is not important yet, because it is only used a parallel projection
220 _baseView->TransCoordScreenToWorld(xx,yy,zz);
221 model->setInicPoint(xx,yy,zz);
223 model->setBBTKName(inputName);
224 model->setBBTKType("ComplexInputPort");
225 model->setComplexPortType(type);
227 model->addObserver(view);
228 model->addObserver(this);
230 //create the output port
231 GPortController* portController = createGPort(GOUTPUTPORT,inputName,"ComplexInputPort",0,model);
232 model->addOutputPort((GPortModel*)portController->getModel());
234 //Associates the view with the correspondent renderer and the model.
235 //(NOTE: Refresh is only made by the view)
236 view->setModel(model);
237 view->setBaseView(_baseView);
238 view->initVtkObjects();
240 //Associates the controller with the correspondent model and view
241 controller->setModelAndView(model,view);
243 //Resgiter change to the observers of the actual model
244 model->notifyObservers(_idManager);
246 int newId = addObjectController(controller);
250 //=========================================================================
252 int wxVtkSceneManager::createGComplexBoxOutputPort(std::string outputName)
254 int windowWidth=_baseView->GetRenWin()->GetSize()[0];
255 int windowHeight=_baseView->GetRenWin()->GetSize()[1];
257 int type = GCOMPLEXOUTPUTPORT;
259 //Create the MVC Objects
261 GComplexBoxPortModel *model = (GComplexBoxPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
262 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
263 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
265 //Prepares the initial model
268 double yy = windowHeight-5;
270 //z value is not important yet, because it is only used a parallel projection
273 _baseView->TransCoordScreenToWorld(xx,yy,zz);
274 model->setInicPoint(xx,yy,zz);
276 model->setBBTKName(outputName);
277 model->setBBTKType("ComplexOutputPort");
278 model->setComplexPortType(type);
280 model->addObserver(view);
281 model->addObserver(this);
283 //create the output port
284 GPortController* portController = createGPort(GINPUTPORT,outputName,"ComplexInputPort",0,model);
285 model->addInputPort((GPortModel*)portController->getModel());
287 //Associates the view with the correspondent renderer and the model.
288 //(NOTE: Refresh is only made by the view)
289 view->setModel(model);
290 view->setBaseView(_baseView);
291 view->initVtkObjects();
293 //Associates the controller with the correspondent model and view
294 controller->setModelAndView(model,view);
296 //Resgiter change to the observers of the actual model
297 model->notifyObservers(_idManager);
299 int newId = addObjectController(controller);
303 //=========================================================================
305 int wxVtkSceneManager::createGInputPort(int portType, int posinBox,GBoxModel *blackBox, BlackBoxInputDescriptor *desc)
307 GPortController* portController = createGPort(portType,desc->GetName(),desc->GetTypeName(),posinBox,blackBox);
308 blackBox->addInputPort((GPortModel*)portController->getModel());
309 return portController->getId();
312 //=========================================================================
314 int wxVtkSceneManager::createGOutputPort(int portType, int posinBox,GBoxModel *blackBox, BlackBoxOutputDescriptor *desc)
316 GPortController* portController = createGPort(portType,desc->GetName(),desc->GetTypeName(),posinBox,blackBox);
317 blackBox->addOutputPort((GPortModel*)portController->getModel());
318 return portController->getId();
321 //=========================================================================
323 GPortController* wxVtkSceneManager::createGPort(int portType,std::string bbtkName, std::string bbtkType, int posInBox,GBoxModel *blackBox)
327 //Create the MVC Objects
328 GPortModel *model = (GPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
329 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
330 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
332 model->registerInBox(blackBox,portType, posInBox);
334 model->setBBTKType(bbtkType);
335 model->setBBTKName(bbtkName);
337 model->addObserver(view);
338 model->addObserver(this);
340 //Associates the view with the correspondent renderer and the model.
341 //(NOTE: Refresh is only made by the view)
342 view->setModel(model);
343 view->setBaseView(_baseView);
344 view->initVtkObjects();
346 //Associates the controller with the correspondent model and view
347 controller->setModelAndView(model,view);
349 model->notifyObservers(_idManager);
351 int newId = addObjectController(controller);
353 return (GPortController*)controller;
356 //=========================================================================
358 int wxVtkSceneManager::createGConnector(GPortModel* startPort)
360 int type = GCONNECTOR;
362 manualConnectorContourController* manContourControl = new manualConnectorContourController();
363 manualConnectorContourView* manContourView = new manualConnectorContourView();
364 manualContourModel* manContourModel = new manualContourModel();
366 GConnectorController* connectorcontroller = new GConnectorController();
367 GConnectorModel* connectorModel = new GConnectorModel();
368 vtkGConnectorView* connectorView = new vtkGConnectorView();
369 connectorModel->setGObjectType(type);
371 manContourModel->SetCloseContour(false);
372 connectorModel->setStartPort(startPort);
374 manContourView->SetModel( manContourModel );
375 manContourView->SetWxVtkBaseView( _baseView );
376 manContourView->SetRange( 0.5 );
377 manContourView->SetZ( 900 );
379 manContourView->SetColorNormalContour(0, 0, 1);
380 manContourView->SetColorEditContour(0.5, 0.5, 0.5);
381 manContourView->SetColorSelectContour(1, 0.8, 0);
382 manContourView->SetWidthLine(1);
383 manContourView->SetShowText(false);
385 manContourControl->SetModelView( manContourModel , manContourView );
387 manContourControl->CreateNewManualContour();
389 manContourView->RefreshContour();
393 connectorModel->getInicPoint(x,y,z);
395 manContourControl->SetState(1);
396 manContourModel->SetCloseContour(false);
398 manContourModel->AddPoint(x,y,z);
399 manContourView->AddPoint();
401 manContourModel->AddPoint(x,y,z);
402 manContourView->AddPoint();
404 int bak= manContourControl->GetNumberOfPointsManualContour() - 1;
405 manContourControl->_bakIdPoint=bak;
406 manContourView->Refresh();
408 manContourControl->SetMoving( false );
410 connectorcontroller->setModelAndView(connectorModel,connectorView);
412 int newId = addObjectController(connectorcontroller);
414 connectorcontroller->setManualContourController(manContourControl);
415 connectorModel->setManualContourModel(manContourModel);
416 connectorView->setManualContourView(manContourView);
417 connectorView->setModel(connectorModel);
418 connectorView->setBaseView(_baseView);
421 connectorModel->addObserver(connectorView);
422 connectorModel->addObserver(this);
427 //=========================================================================
429 void wxVtkSceneManager::registerController(InteractorStyleMaracas *param)
431 vtkInteractorStyleBaseView* baseViewControlManager = (vtkInteractorStyleBaseView*)_baseView->GetInteractorStyleBaseView();
432 baseViewControlManager->AddInteractorStyleMaracas( param );
435 //=========================================================================
437 void wxVtkSceneManager::unregisterController(InteractorStyleMaracas *param)
439 vtkInteractorStyleBaseView* baseViewControlManager = (vtkInteractorStyleBaseView*)_baseView->GetInteractorStyleBaseView();
440 baseViewControlManager->RemoveInteractorStyleMaracas( param );
443 //=========================================================================
445 vtkRenderer* wxVtkSceneManager::getRenderer()
447 return _baseView->GetRenderer();
450 //=========================================================================
452 vtkRenderWindow* wxVtkSceneManager::getRenderWindow()
454 return _baseView->GetRenWin();
456 //=========================================================================
459 void wxVtkSceneManager::update(int idController,int command)
461 if(command != NO_COMMAND)
463 if(command == ADD_TO_SELECTED)
465 GObjectController* cont = _controllers[idController];
468 for (int i=0; i<_selectedObjects.size() && foundID==false; i++)
470 int id = _selectedObjects[i];
478 int id = idController;
479 _selectedObjects.push_back(id);
483 else if(command == INIT_CREATION_CONTOUR)
485 _worldState = INIT_CREATION_CONTOUR;
486 GObjectController* cont = _controllers[idController];
487 GPortModel* startOutputPort = (GPortModel*)cont->getModel();
490 // The last one is the controller of the connector
491 for(int i=0;i<_controllers.size();i++)
493 GObjectController* cont = _controllers[i];
494 if(cont->getGObjectType() == GPORT )
496 GPortModel* port = (GPortModel*)cont->getModel();
497 if(port->getPortType()==GINPUTPORT)
499 cont->SetActive(true);
503 cont->getView()->setState(NOTHING_HAPPENS);
504 cont->getModel()->notifyObservers(_idManager);
505 cont->SetActive(false);
510 cont->getView()->setState(NOTHING_HAPPENS);
511 cont->getModel()->notifyObservers(_idManager);
512 cont->SetActive(false);
516 _selectedObjects.clear();
518 createGConnector(startOutputPort);
521 else if(command == FIN_CREATION_CONTOUR && _worldState == INIT_CREATION_CONTOUR)
523 _worldState = NOTHING_HAPPENS;
524 int id = _controllers.size()-1;
525 GObjectController* cont = _controllers[id];
526 GConnectorModel* modelContour = (GConnectorModel*)cont->getModel();
528 GObjectController* finPort = _controllers[idController];
529 if(finPort->getGObjectType() == GPORT)
531 GPortModel* modelPort = (GPortModel*)finPort->getModel();
532 modelContour->setEndPort(modelPort);
535 manualConnectorContourController* manCont = ((GConnectorController*)cont)->getManualContourController();
536 manualConnectorContourView* connView = (manualConnectorContourView*)manCont->GetManualViewBaseContour();
539 for(int i=0;i<_controllers.size();i++)
541 GObjectController* cont = _controllers[i];
542 if(cont->getView()!=NULL)
544 cont->getView()->setState(NOTHING_HAPPENS);
545 cont->getModel()->notifyObservers(_idManager);
547 cont->SetActive(true);
554 //=========================================================================
556 bool wxVtkSceneManager::OnMouseMove()
559 wxVTKRenderWindowInteractor *wxVTKiren;
560 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
561 wxVTKiren->GetEventPosition(X,Y);
564 if(_worldState == DRAG_OBJECTS)
566 for (int i=0; i<_selectedObjects.size(); i++)
568 int id = _selectedObjects[i];
569 GObjectController* cont = _controllers[id];
572 cont->getView()->setStartDragging(true);
574 cont->getView()->moveObject(X,Y);
575 cont->getView()->setState(DRAG);
576 cont->getModel()->notifyObservers(_idManager);
579 std::map<int, GObjectController*>::iterator it;
581 for(it = _controllers.begin(); it != _controllers.end(); ++it)
583 GObjectController *desc = it->second;
584 if(desc->getGObjectType()==GCONNECTOR)
586 vtkGConnectorView* vconn = (vtkGConnectorView*)desc->getView();
587 vconn->updateStartEndPoints();
591 _startDragging=false;
594 else if(_worldState == NOTHING_HAPPENS || _worldState == INIT_CREATION_CONTOUR)
596 std::map<int, GObjectController*>::iterator it;
598 for(it = _controllers.begin(); it != _controllers.end(); ++it)
600 GObjectController *desc = it->second;
601 int type = desc->getGObjectType();
602 int state = desc->getView()->getState();
604 if(state == HIGHLIGHTED){
606 updateStatusBar(desc->getStatusText());
609 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
610 _parent->displayBlackBoxInfo(mod->getBBTKPackage(),mod->getBBTKType());
619 //=========================================================================
621 bool wxVtkSceneManager::OnLeftButtonDown()
623 if(_worldState==INIT_CREATION_CONTOUR)
625 bool isOverPort=false;
626 std::map<int, GObjectController*>::iterator it;
627 for(it = _controllers.begin(); it != _controllers.end() && isOverPort==false; ++it)
629 GObjectController *desc = it->second;
630 if(desc->getGObjectType()==GPORT)
632 GPortModel* portmod=(GPortModel*)desc->getModel();
633 vtkGObjectView* portView=desc->getView();
634 if(portmod->getPortType()==GINPUTPORT && portView->getState()==HIGHLIGHTED)
641 if(isOverPort==false)
643 _worldState=NOTHING_HAPPENS;
644 int lastId = _controllers.size()-1;
645 GConnectorController *connector = (GConnectorController*)_controllers[lastId];
646 connector->removeFromScene();
647 unregisterController(connector);
648 _controllers.erase(lastId);
650 for(it = _controllers.begin(); it != _controllers.end(); ++it)
652 GObjectController *desc = it->second;
653 desc->SetActive(true);
654 desc->getView()->setState(NOTHING_HAPPENS);
655 desc->getModel()->notifyObservers(_idManager);
660 if(_selectedObjects.size()!=0)
662 _worldState = DRAG_OBJECTS;
663 _startDragging = true;
665 for (int i = 0; i < _selectedObjects.size(); i++)
667 int id = _selectedObjects[i];
668 GObjectController* cont = _controllers[id];
669 cont->getView()->setState(DRAG);
670 cont->getModel()->notifyObservers(_idManager);
679 //=========================================================================
681 bool wxVtkSceneManager::OnLeftButtonUp()
683 if(_worldState == DRAG_OBJECTS)
685 _worldState = NOTHING_HAPPENS;
687 for (int i = 0; i < _selectedObjects.size(); i++)
689 int id = _selectedObjects[i];
690 GObjectController* cont = _controllers[id];
691 cont->getView()->setState(SELECTED);
692 cont->getModel()->notifyObservers(_idManager);
698 //=========================================================================
700 bool wxVtkSceneManager::OnRightButtonUp()
702 if(_worldState==INIT_CREATION_CONTOUR)
704 _worldState=NOTHING_HAPPENS;
705 int lastId = _controllers.size()-1;
706 GConnectorController *connector = (GConnectorController*)_controllers[lastId];
707 connector->removeFromScene();
708 unregisterController(connector);
709 _controllers.erase(lastId);
711 std::map<int, GObjectController*>::iterator it;
712 for(it = _controllers.begin(); it != _controllers.end(); ++it)
714 GObjectController *desc = it->second;
715 desc->SetActive(true);
716 desc->getView()->setState(NOTHING_HAPPENS);
717 desc->getModel()->notifyObservers(_idManager);
722 for (int i = 0; i < _selectedObjects.size(); i++)
724 int id = _selectedObjects[i];
725 GObjectController* cont = _controllers[id];
726 cont->SetActive(true);
727 cont->getView()->setState(NOTHING_HAPPENS);
728 cont->getModel()->notifyObservers(_idManager);
731 _selectedObjects.clear();
736 //=========================================================================
738 bool wxVtkSceneManager::OnLeftDClick()
741 wxVTKRenderWindowInteractor *wxVTKiren;
742 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
743 wxVTKiren->GetEventPosition(X,Y);
745 std::map<int, GObjectController*>::iterator it;
747 bool clickOnObject = false;
749 for(it = _controllers.begin(); it != _controllers.end() && clickOnObject==false; ++it)
751 GObjectController *cont = it->second;
752 int type = cont->getGObjectType();
754 if(cont->getView()->isPointInside(X,Y))
758 for (int i=0; i<_selectedObjects.size(); i++)
760 int id = _selectedObjects[i];
761 GObjectController* control = _controllers[id];
762 control->getView()->setState(NOTHING_HAPPENS);
764 _selectedObjects.clear();
766 GBlackBoxModel *bbmodel = (GBlackBoxModel*)cont->getModel();
767 _parent->editBlackBox(bbmodel);
769 clickOnObject = true;
773 if(clickOnObject==false)
775 //_parent->editDiagramParameters(this);
781 //=========================================================================
783 bool wxVtkSceneManager::OnChar()
785 char keyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
787 // KeyCode 127 : Delete Key
788 // KeyCode 8 : Backspace Key
789 if(keyCode == 8 || keyCode == 127)
791 if(_selectedObjects.size()>0)
793 for(int i=0;i<_selectedObjects.size();i++)
795 int id = _selectedObjects[i];
798 _selectedObjects.clear();
805 //=========================================================================
807 void wxVtkSceneManager::deleteObject(int id)
809 GObjectController *control = _controllers[id];
810 std::vector<int> controllersToRemove;
812 if(control->getGObjectType()==GBLACKBOX || control->getGObjectType()==GCOMPLEXINPUTPORT || control->getGObjectType()==GCOMPLEXOUTPUTPORT)
814 GBoxModel *bbmod = (GBoxModel*)control->getModel();
815 std::vector<GPortModel*> inputs = bbmod->getInputPorts();
817 bool boxConnected = false;
819 // Add box input controllers to be removed
820 for(int i = 0;i<inputs.size();i++)
822 controllersToRemove.push_back(inputs[i]->getObjectId());
823 if(inputs[i]->isConnected())
829 std::vector<GPortModel*> outputs = bbmod->getOutputPorts();
831 // Add box output controllers to be removed
832 for(int i = 0;i<outputs.size();i++)
834 controllersToRemove.push_back(outputs[i]->getObjectId());
835 if(outputs[i]->isConnected())
841 // Add connection controllers to be removed
842 std::map<int, GObjectController*>::iterator it;
843 for(it = _controllers.begin(); it != _controllers.end(); ++it)
845 GObjectController *cont = it->second;
846 int type = cont->getGObjectType();
849 GConnectorModel *conMod = (GConnectorModel*)cont->getModel();
850 if(conMod->getStartPort()!=NULL && conMod->getStartPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
852 controllersToRemove.push_back(conMod->getObjectId());
854 if(conMod->getEndPort()!=NULL && conMod->getEndPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
856 controllersToRemove.push_back(conMod->getObjectId());
861 // Add box controller to be removed
862 controllersToRemove.push_back(bbmod->getObjectId());
864 else if(control->getGObjectType()==GCONNECTOR)
866 GConnectorModel *conMod = (GConnectorModel*)control->getModel();
867 controllersToRemove.push_back(conMod->getObjectId());
870 for(int i = 0;i<controllersToRemove.size();i++)
872 int id = controllersToRemove[i];
873 GObjectController *cont = _controllers[id];
874 cont->removeFromScene();
875 unregisterController((InteractorStyleMaracas*)cont);
876 _controllers.erase(id);
882 //=========================================================================
884 void wxVtkSceneManager::displayBlackBoxInfo(std::string packageName, std::string boxName)
886 _parent->displayBlackBoxInfo(packageName,boxName);
889 //=========================================================================
891 void wxVtkSceneManager::updateStatusBar(std::string textStatus)
893 _parent->updateStatusBar(textStatus);
896 //=========================================================================
898 std::string wxVtkSceneManager::getDiagramBBS()
900 bool existsExec=false;
902 std::vector<std::string> packages;
903 std::vector<int> boxes;
904 std::vector<int> connections;
905 std::vector<int> execBoxes;
907 std::map<int, GObjectController*>::iterator it;
909 for(it = _controllers.begin(); it != _controllers.end(); ++it)
911 GObjectController *desc = it->second;
912 int type = desc->getGObjectType();
916 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
918 std::string pkg = mod->getBBTKPackage();
919 bool existsPkg = false;
920 for(int t = 0;t<packages.size() && existsPkg == false;t++)
929 packages.push_back(pkg);
933 boxes.push_back(it->first);
934 if(mod->isExecutable())
936 execBoxes.push_back(it->first);
940 else if(type==GCONNECTOR)
942 connections.push_back(it->first);
946 std::string script = "";
947 script+="# BBTK GEditor Script\n";
948 script+="# ----------------------\n";
951 script+="include std\n"; // EED
952 script+="include itkvtk\n"; // EED
954 for(i = 0; i<packages.size();i++)
961 // script+="include std\n"; // JPR
963 for(i = 0; i<boxes.size();i++)
967 GObjectController *control = _controllers[id];
968 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
970 script+=model->getBBTKType();
972 script+=model->getBBTKName();
975 std::vector<GPortModel*> inputs = model->getInputPorts();
976 for(int j = 0; j<inputs.size();j++)
978 GPortModel* inputPort = inputs[j];
979 if(inputPort->isValueSet())
982 script+=model->getBBTKName();
984 script+=inputPort->getBBTKName();
986 script+=inputPort->getValue();
993 for(i = 0; i<connections.size();i++)
996 int id = connections[i];
997 GObjectController *control = _controllers[id];
998 GConnectorModel *model = (GConnectorModel*)control->getModel();
1000 //Start Connection info
1001 GPortModel *start = model->getStartPort();
1002 script+=start->getParentBox()->getBBTKName();
1004 script+=start->getBBTKName();
1008 //End Connection info
1009 GPortModel *end = model->getEndPort();
1010 script+=end->getParentBox()->getBBTKName();
1012 script+=end->getBBTKName();
1017 for(i = 0; i<execBoxes.size();i++)
1020 int id = execBoxes[i];
1021 GObjectController *control = _controllers[id];
1022 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1024 script+=model->getBBTKName();
1033 //=========================================================================
1035 std::string wxVtkSceneManager::saveComplexBoxBBS(std::string cbName,std::string cbAuthor,std::string cbCategory,std::string cbDescription)
1038 std::vector<std::string> packages;
1039 std::vector<int> boxes;
1040 std::vector<int> connections;
1041 std::vector<int> execBoxes;
1043 std::map<int, GObjectController*>::iterator it;
1045 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1047 GObjectController *desc = it->second;
1048 int type = desc->getGObjectType();
1052 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
1054 std::string pkg = mod->getBBTKPackage();
1055 bool existsPkg = false;
1056 for(int t = 0;t<packages.size() && existsPkg == false;t++)
1058 if(packages[t]==pkg)
1065 packages.push_back(pkg);
1069 boxes.push_back(it->first);
1070 if(mod->isExecutable())
1072 execBoxes.push_back(it->first);
1075 else if(type==GCONNECTOR)
1077 connections.push_back(it->first);
1081 std::string script = "";
1083 script+="include std\n"; // EED
1084 script+="include itkvtk\n"; // EED
1086 for(i = 0; i<packages.size();i++)
1089 script+=packages[i];
1093 // Definition of a complex box
1098 script+="author \" ";
1102 script+="description \" ";
1103 script+=cbDescription;
1107 for(i = 0; i<boxes.size();i++)
1111 GObjectController *control = _controllers[id];
1112 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1114 script+=model->getBBTKType();
1116 script+=model->getBBTKName();
1119 std::vector<GPortModel*> inputs = model->getInputPorts();
1120 for(int j = 0; j<inputs.size();j++)
1122 GPortModel* inputPort = inputs[j];
1123 if(inputPort->isValueSet())
1126 script+=model->getBBTKName();
1128 script+=inputPort->getBBTKName();
1130 script+=inputPort->getValue();
1137 // Create connections in the script. If the connection is made with a complex port, it is created the input or output
1139 std::string complexInputs="";
1140 std::string complexOutputs="";
1142 for(i = 0; i<connections.size();i++)
1144 int id = connections[i];
1145 GObjectController *control = _controllers[id];
1146 GConnectorModel *model = (GConnectorModel*)control->getModel();
1149 GPortModel *start = model->getStartPort();
1150 GBoxModel *startBox =start->getParentBox();
1152 GPortModel *end = model->getEndPort();
1153 GBoxModel *endBox =end->getParentBox();
1155 if(startBox->getGObjectType()==GCOMPLEXINPUTPORT)
1157 complexInputs+="input ";
1158 complexInputs+=startBox->getBBTKName();
1161 complexInputs+=endBox->getBBTKName();
1163 complexInputs+=end->getBBTKName();
1166 complexInputs+="\" \"";
1168 complexInputs+="\n";
1170 else if(endBox->getGObjectType()==GCOMPLEXOUTPUTPORT)
1172 complexOutputs+="output ";
1173 complexOutputs+=endBox->getBBTKName();
1175 complexOutputs+=" ";
1176 complexOutputs+=startBox->getBBTKName();
1177 complexOutputs+=".";
1178 complexOutputs+=start->getBBTKName();
1180 complexOutputs+=" ";
1181 complexOutputs+="\" \"";
1183 complexOutputs+="\n";
1188 script+=startBox->getBBTKName();
1190 script+=start->getBBTKName();
1194 //End Connection info
1195 script+=endBox->getBBTKName();
1197 script+=end->getBBTKName();
1203 for(i = 0; i<execBoxes.size();i++)
1206 int id = execBoxes[i];
1207 GObjectController *control = _controllers[id];
1208 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1210 script+=model->getBBTKName();
1215 script+="# Complex input ports\n";
1216 script+=complexInputs;
1219 script+="# Complex output ports\n";
1220 script+=complexOutputs;
1229 //=========================================================================
1231 void wxVtkSceneManager::deleteAllBoxes()
1233 std::map<int, GObjectController*>::iterator it;
1234 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1236 GObjectController *cont = it->second;
1237 cont->removeFromScene();
1238 unregisterController((InteractorStyleMaracas*)cont);
1240 _selectedObjects.clear();
1241 _controllers.clear();
1245 //=========================================================================
1247 void wxVtkSceneManager::refreshScene()
1249 _baseView->RefreshView();
1252 //=========================================================================
1254 void wxVtkSceneManager::centerView()
1257 _baseView->GetRenderer()->GetActiveCamera()->GetFocalPoint(temp);
1258 _baseView->GetRenderer()->GetActiveCamera()->SetFocalPoint(0,0,temp[2]);
1259 _baseView->GetRenderer()->GetActiveCamera()->GetPosition(temp);
1260 _baseView->GetRenderer()->GetActiveCamera()->SetPosition(0,0,temp[2]);
1261 _baseView->RefreshView();
1265 //=========================================================================
1267 void wxVtkSceneManager::saveDiagram(std::string &content)
1271 //Print info IF COMPLEX BOX
1272 content+="COMPLEXBOX:";
1277 //Print info complex input ports
1278 std::vector<int> inputs = getComplexInputPorts();
1279 int insize = inputs.size();
1280 content+="COMPLEXINPUTS:";
1281 sprintf (buffer, "%d", insize);
1285 for(int i = 0;i<insize;i++)
1288 GObjectController *cont = _controllers[id];
1289 cont->getModel()->save(content);
1292 //Print info complex output ports
1293 std::vector<int> outputs = getComplexOutputPorts();
1294 int outsize = outputs.size();
1295 content+="COMPLEXOUTPUTS:";
1296 sprintf (buffer, "%d", outsize);
1300 for(int i = 0;i<outsize;i++)
1302 int id = outputs[i];
1303 GObjectController *cont = _controllers[id];
1304 cont->getModel()->save(content);
1313 std::vector<int> boxes = getBlackBoxes();
1314 int bsize = boxes.size();
1316 sprintf (buffer, "%d", bsize);
1320 for(int i = 0;i<bsize;i++)
1323 GObjectController *cont = _controllers[id];
1324 cont->getModel()->save(content);
1328 std::vector<int> connections = getConnections();
1329 int csize = connections.size();
1330 content+="CONNECTIONS:";
1331 sprintf (buffer, "%d", csize);
1335 for(int i = 0;i<csize;i++)
1337 int id = connections[i];
1338 GObjectController *cont = _controllers[id];
1339 cont->getModel()->save(content);
1344 //=========================================================================
1346 void wxVtkSceneManager::loadDiagram(ifstream &inputStream)
1349 std::string line="";
1350 char delims[] = ":";
1351 char *result = NULL;
1352 getline(inputStream,line);
1355 while ( !inputStream.eof() )
1357 if(line=="" || line[0]=='#')
1359 getline(inputStream,line);
1361 else if(line=="APP_START")
1372 getline(inputStream,line);//COMPLEX_BOX:TRUE|FALSE
1374 strcpy( complex, line.c_str() );
1375 result = strtok( complex, delims );
1376 result = strtok( NULL, delims );
1377 std::string isComplexBox(result);
1379 if(isComplexBox=="TRUE")
1383 //-----------------------
1384 //- COMPLEX INPUT PORTS
1385 //-----------------------
1386 getline(inputStream,line);//COMPLEXINPUTS:num
1388 strcpy( inputs, line.c_str() );
1389 result = strtok( inputs, delims );
1390 result = strtok( NULL, delims );
1393 std::istringstream inps(result);
1396 for(int i = 0;i<numInputs;i++)
1399 getline(inputStream,line);//COMPLEX_PORT
1400 getline(inputStream,line);//name
1401 std::string inputPortName(line);
1404 getline(inputStream,line);//xInic:yInic:zInic
1406 strcpy( coord, line.c_str() );
1407 result = strtok( coord, delims );//xInic
1408 std::string xInic(result);
1409 result = strtok( NULL, delims );//yInic
1410 std::string yInic(result);
1411 result = strtok( NULL, delims );//zInic
1412 std::string zInic(result);
1414 double xIn, yIn, zIn;
1415 std::istringstream xSt(xInic);
1417 std::istringstream ySt(yInic);
1419 std::istringstream zSt(zInic);
1422 getline(inputStream,line);//FIN_COMPLEX_PORT
1424 int idInputPort = createGComplexBoxInputPort(inputPortName);
1425 GObjectController *cont = _controllers[idInputPort];
1426 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
1427 cbmod->setInicPoint(xIn,yIn,zIn);
1428 cbmod->notifyObservers(_idManager);
1432 //-----------------------
1433 //- COMPLEX OUTPUT PORTS
1434 //-----------------------
1436 getline(inputStream,line);//COMPLEXOUTPUTS:num
1438 strcpy( outputs, line.c_str() );
1439 result = strtok( outputs, delims );
1440 result = strtok( NULL, delims );
1443 std::istringstream outps(result);
1444 outps >> numOutputs;
1446 for(int i = 0;i<numOutputs;i++)
1449 getline(inputStream,line);//COMPLEX_PORT
1450 getline(inputStream,line);//name
1451 std::string outputPortName(line);
1454 getline(inputStream,line);//xInic:yInic:zInic
1456 strcpy( coord, line.c_str() );
1457 result = strtok( coord, delims );//xInic
1458 std::string xInic(result);
1459 result = strtok( NULL, delims );//yInic
1460 std::string yInic(result);
1461 result = strtok( NULL, delims );//zInic
1462 std::string zInic(result);
1464 double xIn, yIn, zIn;
1465 std::istringstream xSt(xInic);
1467 std::istringstream ySt(yInic);
1469 std::istringstream zSt(zInic);
1472 getline(inputStream,line);//FIN_COMPLEX_PORT
1474 int idOutputPort = createGComplexBoxOutputPort(outputPortName);
1475 GObjectController *cont = _controllers[idOutputPort];
1476 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
1477 cbmod->setInicPoint(xIn,yIn,zIn);
1478 cbmod->notifyObservers(_idManager);
1484 getline(inputStream,line);//BOXES:num
1486 strcpy( boxes, line.c_str() );
1487 result = strtok( boxes, delims );
1488 result = strtok( NULL, delims );
1491 std::istringstream is(result);
1494 for(int i = 0;i<numBoxes;i++)
1497 getline(inputStream,line);//BOX
1498 getline(inputStream,line);//package:type:name
1500 strcpy( box, line.c_str() );
1501 result = strtok( box, delims );//package
1502 std::string package(result);
1503 result = strtok( NULL, delims );//type
1504 std::string type(result);
1505 result = strtok( NULL, delims );//name
1506 std::string name(result);
1508 getline(inputStream,line);//ISEXEC:TRUE|FALSE
1510 strcpy( exec, line.c_str() );
1511 result = strtok( exec, delims );//ISEXEC
1512 result = strtok( NULL, delims );//TRUE|FALSE
1513 std::string isExec(result);
1516 getline(inputStream,line);//xInic:yInic:zInic
1518 strcpy( coord, line.c_str() );
1519 result = strtok( coord, delims );//xInic
1520 std::string xInic(result);
1521 result = strtok( NULL, delims );//yInic
1522 std::string yInic(result);
1523 result = strtok( NULL, delims );//zInic
1524 std::string zInic(result);
1526 double xIn, yIn, zIn;
1527 std::istringstream xSt(xInic);
1529 std::istringstream ySt(yInic);
1531 std::istringstream zSt(zInic);
1535 getline(inputStream,line);//xEnd:yEnd:zEnd
1536 strcpy( coord, line.c_str() );
1537 result = strtok( coord, delims );//xEnd
1538 std::string xEnd(result);
1539 result = strtok( NULL, delims );//yEnd
1540 std::string yEnd(result);
1541 result = strtok( NULL, delims );//zEnd
1542 std::string zEnd(result);
1544 double xEn, yEn, zEn;
1545 std::istringstream xEt(xEnd);
1547 std::istringstream yEt(yEnd);
1549 std::istringstream zEt(zEnd);
1552 int idBox = createGBlackBox(0,0,package,type);
1553 GObjectController *cont = _controllers[idBox];
1554 GBlackBoxModel *bbmod = (GBlackBoxModel*)cont->getModel();
1555 bbmod->setBBTKName(name);
1556 bbmod->setInicPoint(xIn,yIn,zIn);
1557 bbmod->setFinalPoint(xEn,yEn,zEn);
1560 bbmod->setExecutable(true);
1562 else if(isExec=="FALSE")
1564 bbmod->setExecutable(false);
1568 getline(inputStream,line);//PORT o FIN_BOX
1569 std::string port=line.substr(0,4);
1572 getline(inputStream,line);//name:value
1574 strcpy( poort, line.c_str() );
1575 result = strtok( poort, delims );//name
1576 std::string name(result);
1577 result = strtok( NULL, delims );//value
1578 std::string value(result);
1580 bbmod->setValueToInput(name,value);
1582 getline(inputStream,line);//PORT o FIN_BOX
1583 port=line.substr(0,4);
1586 bbmod->notifyObservers(_idManager);
1591 getline(inputStream,line);//CONNECTIONS:num
1593 strcpy( conns, line.c_str() );
1594 result = strtok( conns, delims );
1595 result = strtok( NULL, delims );
1598 std::istringstream isCons(result);
1601 for(int i = 0;i<numConns;i++)
1604 getline(inputStream,line);//CONNECTION
1605 getline(inputStream,line);//Startbox.PortName:EndBox.PortName
1608 strcpy( connec, line.c_str() );
1609 result = strtok( connec, delims );
1610 std::string nameStartBox(result);
1611 result = strtok( NULL, delims );
1612 std::string nameStartPort(result);
1613 result = strtok( NULL, delims );
1614 std::string nameEndBox(result);
1615 result = strtok( NULL, delims );
1616 std::string nameEndPort(result);
1618 std::vector<int> lstB = getBlackBoxes();
1620 GPortModel *startP=NULL;
1621 GPortModel *endP=NULL;
1622 for(int j = 0;j<lstB.size();j++)
1625 GBlackBoxModel *bbMod = (GBlackBoxModel*)_controllers[idB]->getModel();
1626 if(_controllers[idB]->getModel()->getBBTKName()==nameStartBox)
1628 startP = bbMod->getOutputPort(nameStartPort);
1630 else if(_controllers[idB]->getModel()->getBBTKName()==nameEndBox)
1632 endP = bbMod->getInputPort(nameEndPort);
1640 std::vector<int> lstInputs = getComplexInputPorts();
1641 for(int j = 0;j<lstInputs.size();j++)
1643 int idB = lstInputs[j];
1644 GBoxModel *cbMod = (GBoxModel*)_controllers[idB]->getModel();
1645 if(_controllers[idB]->getModel()->getBBTKName()==nameStartBox)
1647 startP = cbMod->getOutputPort(nameStartPort);
1654 std::vector<int> lstOutputs = getComplexOutputPorts();
1655 for(int j = 0;j<lstOutputs.size();j++)
1657 int idB = lstOutputs[j];
1658 GBoxModel *cbMod = (GBoxModel*)_controllers[idB]->getModel();
1659 if(_controllers[idB]->getModel()->getBBTKName()==nameEndBox)
1661 endP = cbMod->getInputPort(nameEndPort);
1667 int idCon = createGConnector(startP);
1668 _worldState = NOTHING_HAPPENS;
1669 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
1671 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
1672 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
1673 tempp->endContourCreation();
1674 conMod->setEndPort(endP);
1675 conView->updateStartEndPoints();
1682 //=========================================================================
1684 std::vector<int> wxVtkSceneManager::getBlackBoxes()
1686 std::vector<int> vect;
1687 std::map<int, GObjectController*>::iterator it;
1688 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1690 GObjectController *cont = it->second;
1691 if(cont->getGObjectType()==GBLACKBOX)
1693 vect.push_back(cont->getId());
1699 //=========================================================================
1701 std::vector<int> wxVtkSceneManager::getComplexInputPorts()
1703 std::vector<int> vect;
1704 std::map<int, GObjectController*>::iterator it;
1705 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1707 GObjectController *cont = it->second;
1708 if(cont->getGObjectType()==GCOMPLEXINPUTPORT)
1710 vect.push_back(cont->getId());
1716 //=========================================================================
1718 std::vector<int> wxVtkSceneManager::getComplexOutputPorts()
1720 std::vector<int> vect;
1721 std::map<int, GObjectController*>::iterator it;
1722 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1724 GObjectController *cont = it->second;
1725 if(cont->getGObjectType()==GCOMPLEXOUTPUTPORT)
1727 vect.push_back(cont->getId());
1733 //=========================================================================
1735 std::vector<int> wxVtkSceneManager::getConnections()
1737 std::vector<int> vect;
1738 std::map<int, GObjectController*>::iterator it;
1739 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1741 GObjectController *cont = it->second;
1742 if(cont->getGObjectType()==GCONNECTOR)
1744 vect.push_back(cont->getId());
1750 //=========================================================================
1752 bool wxVtkSceneManager::isComplexBox()
1754 return _isComplexBox;
1757 //=========================================================================
1759 void wxVtkSceneManager::setComplexBox(bool val)
1764 //=========================================================================
1766 int wxVtkSceneManager::addObjectController(GObjectController* objController)
1768 //Register the controller of the new object
1769 registerController((InteractorStyleMaracas*) objController);
1771 //Add the object to the objects list
1772 int newId = _controllers.size();
1773 objController->setId(newId);
1774 _controllers[newId] = objController;
1778 //=========================================================================
1780 int wxVtkSceneManager::getNumSelectedObjects()
1782 return _selectedObjects.size();
1785 //=========================================================================
1787 std::map<int,GObjectController*> wxVtkSceneManager::getSelectedObjects()
1789 std::map<int,GObjectController*> mapSelected;
1791 std::map<int, GObjectController*>::iterator it;
1792 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1794 GObjectController *cont = it->second;
1795 if(cont->getGObjectType()==GBLACKBOX && cont->getView()->getState()==SELECTED)
1797 mapSelected[cont->getId()]=cont;
1801 std::map<int, GObjectController*>::iterator it2;
1802 for(it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
1804 GObjectController *cont = it2->second;
1805 if(cont->getGObjectType()==GCONNECTOR)
1807 GConnectorModel* cmod = (GConnectorModel*)cont->getModel();
1808 GBoxModel* endPortParentBox = cmod->getEndPort()->getParentBox();
1809 GBoxModel* startPortParentBox = cmod->getStartPort()->getParentBox();
1811 std::map<int, GObjectController*>::iterator iterOBJ1 = mapSelected.find(startPortParentBox->getObjectId());
1812 std::map<int, GObjectController*>::iterator iterOBJ2 = mapSelected.find(endPortParentBox->getObjectId());
1814 if(iterOBJ1 != mapSelected.end() && iterOBJ2 != mapSelected.end())
1816 int ID = cont->getId();
1817 mapSelected[ID]=cont;
1825 //=========================================================================
1827 void wxVtkSceneManager::addObjects(std::map<int,GObjectController*> objectsMap)
1830 std::map<int,int> oldIdNewIdBoxes;
1831 std::vector<int> connections;
1833 std::map<int, GObjectController*>::iterator it;
1834 for(it = objectsMap.begin(); it != objectsMap.end(); ++it)
1836 GObjectController *cont = it->second;
1837 int type = cont->getGObjectType();
1842 double xInic, yInic,zInic;
1843 GBlackBoxModel* copyBox = (GBlackBoxModel*)cont->getModel();
1844 copyBox->getInicPoint(xInic,yInic,zInic);
1845 int idBox = createGBlackBox(0,0,copyBox->getBBTKPackage(),copyBox->getBBTKType());
1847 int idcB = copyBox->getObjectId();
1848 oldIdNewIdBoxes[idcB]=idBox;
1849 cont = _controllers[idBox];
1850 GBlackBoxModel* newbox = (GBlackBoxModel*)cont->getModel();
1851 newbox->setInicPoint(xInic,yInic,zInic);
1852 int num = newbox->getNumInputPorts();
1853 for(int j=0;j<num;j++)
1855 newbox->setValueToInputPort(j,copyBox->getValueInputPort(j));
1857 newbox->notifyObservers(_idManager);
1859 else if(type==GCONNECTOR)
1861 int idCon = cont->getId();
1862 connections.push_back(idCon);
1867 for(int i = 0 ;i<connections.size();i++)
1869 int objId = connections[i];
1870 GObjectController *cont = objectsMap[objId];
1871 GConnectorModel* connectModel = (GConnectorModel*)cont->getModel();
1873 GPortModel* startPort = connectModel->getStartPort();
1874 int startPortIndex = startPort->getPosInBox();
1875 GPortModel* endPort = connectModel->getEndPort();
1876 int endPortIndex = endPort->getPosInBox();
1878 GBlackBoxModel* startPortParentBox = (GBlackBoxModel*)startPort->getParentBox();
1879 GBlackBoxModel* endPortParentBox = (GBlackBoxModel*)endPort->getParentBox();
1881 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
1882 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
1884 GBlackBoxModel* newStartBox = (GBlackBoxModel*)_controllers[idNewStartBox]->getModel();
1885 GBlackBoxModel* newEndBox = (GBlackBoxModel*)_controllers[idNewEndBox]->getModel();
1887 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
1888 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
1890 // Creates connection
1891 int idCon = createGConnector(newStartPort);
1892 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
1893 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
1894 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
1895 tempp->endContourCreation();
1896 conMod->setEndPort(newEndPort);
1897 conView->updateStartEndPoints();
1900 std::map<int, int>::iterator itIds;
1901 for(itIds = oldIdNewIdBoxes.begin(); itIds != oldIdNewIdBoxes.end(); ++itIds)
1903 int idOld = itIds->first;
1904 int idNew = itIds->second;
1906 GBlackBoxModel* oldBox = (GBlackBoxModel*)objectsMap[idOld]->getModel();
1907 GBlackBoxModel* newBox = (GBlackBoxModel*)_controllers[idNew]->getModel();
1909 std::vector<int> oldInputConnections = oldBox->getConnectedInputs();
1910 std::vector<int> oldOutputConnections = oldBox->getConnectedOutputs();
1911 std::vector<int> newInputConnections = newBox->getConnectedInputs();
1912 std::vector<int> newOutputConnections = newBox->getConnectedOutputs();
1914 for(int k = 0; k<oldInputConnections.size();k++)
1918 for(int l = 0; l<newInputConnections.size() && !exist;l++)
1920 if(oldInputConnections[k]==newInputConnections[l])
1928 //Create complex input
1929 int posInBox = oldInputConnections[k];
1930 GPortModel* inputPort = oldBox->getInputPort(posInBox);
1931 std::string inputPortName = inputPort->getBBTKName();
1932 int idInputPort = createGComplexBoxInputPort(inputPortName);
1933 GObjectController *cont = _controllers[idInputPort];
1934 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
1936 inputPort->getInicPoint(xIn,yIn,zIn);
1938 cbmod->setInicPoint(xIn,yIn,zIn);
1939 cbmod->notifyObservers(_idManager);
1941 GPortModel* inputPortEnd = newBox->getInputPort(posInBox);
1943 // Creates connection
1944 int idCon = createGConnector(cbmod->getOutputPort(0));
1945 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
1946 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
1947 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
1948 tempp->endContourCreation();
1949 conMod->setEndPort(inputPortEnd);
1950 conView->updateStartEndPoints();
1957 for(int k = 0; k<oldOutputConnections.size();k++)
1961 for(int l = 0; l<newOutputConnections.size() && !exist;l++)
1963 if(oldOutputConnections[k]==newOutputConnections[l])
1971 //Create complex output
1972 int posInBox = oldOutputConnections[k];
1973 GPortModel* outputPort = oldBox->getOutputPort(posInBox);
1974 std::string outputPortName = outputPort->getBBTKName();
1975 int idOutputPort = createGComplexBoxOutputPort(outputPortName);
1976 GObjectController *cont = _controllers[idOutputPort];
1977 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
1979 outputPort->getInicPoint(xIn,yIn,zIn);
1981 cbmod->setInicPoint(xIn,yIn,zIn);
1982 cbmod->notifyObservers(_idManager);
1984 GPortModel* outputPortEnd = newBox->getOutputPort(posInBox);
1986 // Creates connection
1987 int idCon = createGConnector(outputPortEnd);
1988 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
1989 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
1990 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
1991 tempp->endContourCreation();
1992 conMod->setEndPort(cbmod->getInputPort(0));
1993 conView->updateStartEndPoints();
2004 //=========================================================================
2006 } // EO namespace bbtk