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)
55 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget((wxDropTarget*)parent);
57 _worldState=NOTHING_HAPPENS;
58 registerController(this);
64 //=========================================================================
66 void wxVtkSceneManager::disconnectDrop()
68 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget(NULL);
71 //=========================================================================
73 wxVtkSceneManager::~wxVtkSceneManager()
77 //=========================================================================
79 void wxVtkSceneManager::configureBaseView()
81 vtkInteractorStyleBaseView2D *interactorstylebaseview = vtkInteractorStyleBaseView2D::New();
83 _baseView->SetInteractorStyleBaseView(interactorstylebaseview);
85 // Important to activate the 2D interaction system
86 wxVTKRenderWindowInteractor *iren = _baseView->GetWxVTKRenderWindowInteractor();
87 interactorstylebaseview->SetInteractor ( iren );
88 iren->SetInteractorStyle(interactorstylebaseview);
89 interactorstylebaseview->SetwxVtkBaseView(_baseView);
91 _baseView->GetRenderer()->GetActiveCamera()->ParallelProjectionOn();
92 _baseView->GetRenderer()->ResetCamera(-100,100,-100,100,900,1000);
94 _baseView->GetRenderer()->SetBackground(0.9,0.9,0.9);
95 _baseView->GetRenderer()->GradientBackgroundOff();
99 //=========================================================================
101 int wxVtkSceneManager::createGBlackBox(int x, int y, std::string packageName, std::string boxType)
103 int windowWidth=_baseView->GetRenWin()->GetSize()[0];
104 int windowHeight=_baseView->GetRenWin()->GetSize()[1];
106 int type = GBLACKBOX;
108 //Create the MVC Objects
110 GBlackBoxModel *model = (GBlackBoxModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
111 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
112 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
114 BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxType);
116 //Prepares the initial model
117 //The coordinates obtained are the following. Top-Left:x=0,y=0 Bottom-Right:x=width,y=height
120 double yy = windowHeight-y;
122 //z value is not important yet, because it is only used a parallel projection
125 _baseView->TransCoordScreenToWorld(xx,yy,zz);
126 model->setInicPoint(xx,yy,zz);
129 std::stringstream stream;
133 stream << "Box0" << _numBoxes;
137 stream << "Box" << _numBoxes;
139 std::string arraystring = stream.str();
141 model->setBBTKName(arraystring);
142 model->setBBTKType(boxType);
143 model->setBBTKPackage(packageName);
145 model->addObserver(view);
146 model->addObserver(this);
148 //Iterate and create the input ports
149 std::map<std::string, BlackBoxInputDescriptor*> descriptorInMap = descriptor->GetInputDescriptorMap();
150 std::map<std::string, BlackBoxInputDescriptor*>::iterator itInput;
153 for(itInput = descriptorInMap.begin(); itInput != descriptorInMap.end(); ++itInput)
155 BlackBoxInputDescriptor *desc = itInput->second;
156 createGInputPort(GINPUTPORT,i,model,desc);
160 //Iterate and create the output ports
161 std::map<std::string, BlackBoxOutputDescriptor*> descriptorOutMap = descriptor->GetOutputDescriptorMap();
162 std::map<std::string, BlackBoxOutputDescriptor*>::iterator itOutput;
165 for(itOutput = descriptorOutMap.begin();itOutput != descriptorOutMap.end(); ++itOutput)
167 BlackBoxOutputDescriptor *desc = itOutput->second;
168 createGOutputPort(GOUTPUTPORT,i,model,desc);
173 //Associates the view with the correspondent renderer and the model.
174 //(NOTE: Refresh is only made by the view)
175 view->setModel(model);
176 view->setBaseView(_baseView);
177 view->initVtkObjects();
179 //Associates the controller with the correspondent model and view
180 controller->setModelAndView(model,view);
182 //Resgiter change to the observers of the actual model
183 model->notifyObservers(_idManager);
185 int newId = addObjectController(controller);
190 //=========================================================================
192 int wxVtkSceneManager::createGComplexBoxInputPort(std::string inputName)
194 int windowWidth=_baseView->GetRenWin()->GetSize()[0];
195 int windowHeight=_baseView->GetRenWin()->GetSize()[1];
197 int type = GCOMPLEXINPUTPORT;
199 //Create the MVC Objects
201 GComplexBoxPortModel *model = (GComplexBoxPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
202 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
203 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
205 //Prepares the initial model
208 double yy = windowHeight-5;
210 //z value is not important yet, because it is only used a parallel projection
213 _baseView->TransCoordScreenToWorld(xx,yy,zz);
214 model->setInicPoint(xx,yy,zz);
216 model->setBBTKName(inputName);
217 model->setBBTKType("ComplexInputPort");
218 model->setComplexPortType(type);
220 model->addObserver(view);
221 model->addObserver(this);
223 //create the output port
224 GPortController* portController = createGPort(GOUTPUTPORT,inputName,"ComplexInputPort",0,model);
225 model->addOutputPort((GPortModel*)portController->getModel());
227 //Associates the view with the correspondent renderer and the model.
228 //(NOTE: Refresh is only made by the view)
229 view->setModel(model);
230 view->setBaseView(_baseView);
231 view->initVtkObjects();
233 //Associates the controller with the correspondent model and view
234 controller->setModelAndView(model,view);
236 //Resgiter change to the observers of the actual model
237 model->notifyObservers(_idManager);
239 int newId = addObjectController(controller);
243 //=========================================================================
245 int wxVtkSceneManager::createGComplexBoxOutputPort(std::string outputName)
247 int windowWidth=_baseView->GetRenWin()->GetSize()[0];
248 int windowHeight=_baseView->GetRenWin()->GetSize()[1];
250 int type = GCOMPLEXOUTPUTPORT;
252 //Create the MVC Objects
254 GComplexBoxPortModel *model = (GComplexBoxPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
255 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
256 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
258 //Prepares the initial model
261 double yy = windowHeight-5;
263 //z value is not important yet, because it is only used a parallel projection
266 _baseView->TransCoordScreenToWorld(xx,yy,zz);
267 model->setInicPoint(xx,yy,zz);
269 model->setBBTKName(outputName);
270 model->setBBTKType("ComplexOutputPort");
271 model->setComplexPortType(type);
273 model->addObserver(view);
274 model->addObserver(this);
276 //create the output port
277 GPortController* portController = createGPort(GINPUTPORT,outputName,"ComplexInputPort",0,model);
278 model->addInputPort((GPortModel*)portController->getModel());
280 //Associates the view with the correspondent renderer and the model.
281 //(NOTE: Refresh is only made by the view)
282 view->setModel(model);
283 view->setBaseView(_baseView);
284 view->initVtkObjects();
286 //Associates the controller with the correspondent model and view
287 controller->setModelAndView(model,view);
289 //Resgiter change to the observers of the actual model
290 model->notifyObservers(_idManager);
292 int newId = addObjectController(controller);
296 //=========================================================================
298 int wxVtkSceneManager::createGInputPort(int portType, int posinBox,GBoxModel *blackBox, BlackBoxInputDescriptor *desc)
300 GPortController* portController = createGPort(portType,desc->GetName(),desc->GetTypeName(),posinBox,blackBox);
301 blackBox->addInputPort((GPortModel*)portController->getModel());
302 return portController->getId();
305 //=========================================================================
307 int wxVtkSceneManager::createGOutputPort(int portType, int posinBox,GBoxModel *blackBox, BlackBoxOutputDescriptor *desc)
309 GPortController* portController = createGPort(portType,desc->GetName(),desc->GetTypeName(),posinBox,blackBox);
310 blackBox->addOutputPort((GPortModel*)portController->getModel());
311 return portController->getId();
314 //=========================================================================
316 GPortController* wxVtkSceneManager::createGPort(int portType,std::string bbtkName, std::string bbtkType, int posInBox,GBoxModel *blackBox)
320 //Create the MVC Objects
321 GPortModel *model = (GPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
322 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
323 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
325 model->registerInBox(blackBox,portType, posInBox);
327 model->setBBTKType(bbtkType);
328 model->setBBTKName(bbtkName);
330 model->addObserver(view);
331 model->addObserver(this);
333 //Associates the view with the correspondent renderer and the model.
334 //(NOTE: Refresh is only made by the view)
335 view->setModel(model);
336 view->setBaseView(_baseView);
337 view->initVtkObjects();
339 //Associates the controller with the correspondent model and view
340 controller->setModelAndView(model,view);
342 model->notifyObservers(_idManager);
344 int newId = addObjectController(controller);
346 return (GPortController*)controller;
349 //=========================================================================
351 int wxVtkSceneManager::createGConnector(GPortModel* startPort)
353 int type = GCONNECTOR;
355 manualConnectorContourController* manContourControl = new manualConnectorContourController();
356 manualConnectorContourView* manContourView = new manualConnectorContourView();
357 manualContourModel* manContourModel = new manualContourModel();
359 GConnectorController* connectorcontroller = new GConnectorController();
360 GConnectorModel* connectorModel = new GConnectorModel();
361 vtkGConnectorView* connectorView = new vtkGConnectorView();
362 connectorModel->setGObjectType(type);
364 manContourModel->SetCloseContour(false);
365 connectorModel->setStartPort(startPort);
367 manContourView->SetModel( manContourModel );
368 manContourView->SetWxVtkBaseView( _baseView );
369 manContourView->SetRange( 0.5 );
370 manContourView->SetZ( 900 );
372 manContourView->SetColorNormalContour(0, 0, 1);
373 manContourView->SetColorEditContour(0.5, 0.5, 0.5);
374 manContourView->SetColorSelectContour(1, 0.8, 0);
375 manContourView->SetWidthLine(1);
376 manContourView->SetShowText(false);
378 manContourControl->SetModelView( manContourModel , manContourView );
380 manContourControl->CreateNewManualContour();
382 manContourView->RefreshContour();
386 connectorModel->getInicPoint(x,y,z);
388 manContourControl->SetState(1);
389 manContourModel->SetCloseContour(false);
391 manContourModel->AddPoint(x,y,z);
392 manContourView->AddPoint();
394 manContourModel->AddPoint(x,y,z);
395 manContourView->AddPoint();
397 int bak= manContourControl->GetNumberOfPointsManualContour() - 1;
398 manContourControl->_bakIdPoint=bak;
399 manContourView->Refresh();
401 manContourControl->SetMoving( false );
403 connectorcontroller->setModelAndView(connectorModel,connectorView);
405 int newId = addObjectController(connectorcontroller);
407 connectorcontroller->setManualContourController(manContourControl);
408 connectorModel->setManualContourModel(manContourModel);
409 connectorView->setManualContourView(manContourView);
410 connectorView->setModel(connectorModel);
411 connectorView->setBaseView(_baseView);
414 connectorModel->addObserver(connectorView);
415 connectorModel->addObserver(this);
420 //=========================================================================
422 void wxVtkSceneManager::registerController(InteractorStyleMaracas *param)
424 vtkInteractorStyleBaseView* baseViewControlManager = (vtkInteractorStyleBaseView*)_baseView->GetInteractorStyleBaseView();
425 baseViewControlManager->AddInteractorStyleMaracas( param );
428 //=========================================================================
430 void wxVtkSceneManager::unregisterController(InteractorStyleMaracas *param)
432 vtkInteractorStyleBaseView* baseViewControlManager = (vtkInteractorStyleBaseView*)_baseView->GetInteractorStyleBaseView();
433 baseViewControlManager->RemoveInteractorStyleMaracas( param );
436 //=========================================================================
438 vtkRenderer* wxVtkSceneManager::getRenderer()
440 return _baseView->GetRenderer();
443 //=========================================================================
445 vtkRenderWindow* wxVtkSceneManager::getRenderWindow()
447 return _baseView->GetRenWin();
449 //=========================================================================
452 void wxVtkSceneManager::update(int idController,int command)
454 if(command != NO_COMMAND)
456 if(command == ADD_TO_SELECTED)
458 GObjectController* cont = _controllers[idController];
461 for (int i=0; i<_selectedObjects.size() && foundID==false; i++)
463 int id = _selectedObjects[i];
471 int id = idController;
472 _selectedObjects.push_back(id);
476 else if(command == INIT_CREATION_CONTOUR)
478 _worldState = INIT_CREATION_CONTOUR;
479 GObjectController* cont = _controllers[idController];
480 GPortModel* startOutputPort = (GPortModel*)cont->getModel();
483 // The last one is the controller of the connector
484 for(int i=0;i<_controllers.size();i++)
486 GObjectController* cont = _controllers[i];
487 if(cont->getGObjectType() == GPORT )
489 GPortModel* port = (GPortModel*)cont->getModel();
490 if(port->getPortType()==GINPUTPORT)
492 cont->SetActive(true);
496 cont->getView()->setState(NOTHING_HAPPENS);
497 cont->getModel()->notifyObservers(_idManager);
498 cont->SetActive(false);
503 cont->getView()->setState(NOTHING_HAPPENS);
504 cont->getModel()->notifyObservers(_idManager);
505 cont->SetActive(false);
509 _selectedObjects.clear();
511 createGConnector(startOutputPort);
514 else if(command == FIN_CREATION_CONTOUR && _worldState == INIT_CREATION_CONTOUR)
516 _worldState = NOTHING_HAPPENS;
517 int id = _controllers.size()-1;
518 GObjectController* cont = _controllers[id];
519 GConnectorModel* modelContour = (GConnectorModel*)cont->getModel();
521 GObjectController* finPort = _controllers[idController];
522 if(finPort->getGObjectType() == GPORT)
524 GPortModel* modelPort = (GPortModel*)finPort->getModel();
525 modelContour->setEndPort(modelPort);
528 manualConnectorContourController* manCont = ((GConnectorController*)cont)->getManualContourController();
529 manualConnectorContourView* connView = (manualConnectorContourView*)manCont->GetManualViewBaseContour();
532 for(int i=0;i<_controllers.size();i++)
534 GObjectController* cont = _controllers[i];
535 if(cont->getView()!=NULL)
537 cont->getView()->setState(NOTHING_HAPPENS);
538 cont->getModel()->notifyObservers(_idManager);
540 cont->SetActive(true);
547 //=========================================================================
549 bool wxVtkSceneManager::OnMouseMove()
552 wxVTKRenderWindowInteractor *wxVTKiren;
553 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
554 wxVTKiren->GetEventPosition(X,Y);
557 if(_worldState == DRAG_OBJECTS)
559 for (int i=0; i<_selectedObjects.size(); i++)
561 int id = _selectedObjects[i];
562 GObjectController* cont = _controllers[id];
565 cont->getView()->setStartDragging(true);
567 cont->getView()->moveObject(X,Y);
568 cont->getView()->setState(DRAG);
569 cont->getModel()->notifyObservers(_idManager);
572 std::map<int, GObjectController*>::iterator it;
574 for(it = _controllers.begin(); it != _controllers.end(); ++it)
576 GObjectController *desc = it->second;
577 if(desc->getGObjectType()==GCONNECTOR)
579 vtkGConnectorView* vconn = (vtkGConnectorView*)desc->getView();
580 vconn->updateStartEndPoints();
584 _startDragging=false;
587 else if(_worldState == NOTHING_HAPPENS || _worldState == INIT_CREATION_CONTOUR)
589 std::map<int, GObjectController*>::iterator it;
591 for(it = _controllers.begin(); it != _controllers.end(); ++it)
593 GObjectController *desc = it->second;
594 int type = desc->getGObjectType();
595 int state = desc->getView()->getState();
597 if(state == HIGHLIGHTED){
599 updateStatusBar(desc->getStatusText());
602 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
603 _parent->displayBlackBoxInfo(mod->getBBTKPackage(),mod->getBBTKType());
612 //=========================================================================
614 bool wxVtkSceneManager::OnLeftButtonDown()
616 if(_worldState==INIT_CREATION_CONTOUR)
618 bool isOverPort=false;
619 std::map<int, GObjectController*>::iterator it;
620 for(it = _controllers.begin(); it != _controllers.end() && isOverPort==false; ++it)
622 GObjectController *desc = it->second;
623 if(desc->getGObjectType()==GPORT)
625 GPortModel* portmod=(GPortModel*)desc->getModel();
626 vtkGObjectView* portView=desc->getView();
627 if(portmod->getPortType()==GINPUTPORT && portView->getState()==HIGHLIGHTED)
634 if(isOverPort==false)
636 _worldState=NOTHING_HAPPENS;
637 int lastId = _controllers.size()-1;
638 GConnectorController *connector = (GConnectorController*)_controllers[lastId];
639 connector->removeFromScene();
640 unregisterController(connector);
641 _controllers.erase(lastId);
643 for(it = _controllers.begin(); it != _controllers.end(); ++it)
645 GObjectController *desc = it->second;
646 desc->SetActive(true);
647 desc->getView()->setState(NOTHING_HAPPENS);
648 desc->getModel()->notifyObservers(_idManager);
653 if(_selectedObjects.size()!=0)
655 _worldState = DRAG_OBJECTS;
656 _startDragging = true;
658 for (int i = 0; i < _selectedObjects.size(); i++)
660 int id = _selectedObjects[i];
661 GObjectController* cont = _controllers[id];
662 cont->getView()->setState(DRAG);
663 cont->getModel()->notifyObservers(_idManager);
672 //=========================================================================
674 bool wxVtkSceneManager::OnLeftButtonUp()
676 if(_worldState == DRAG_OBJECTS)
678 _worldState = NOTHING_HAPPENS;
680 for (int i = 0; i < _selectedObjects.size(); i++)
682 int id = _selectedObjects[i];
683 GObjectController* cont = _controllers[id];
684 cont->getView()->setState(SELECTED);
685 cont->getModel()->notifyObservers(_idManager);
691 //=========================================================================
693 bool wxVtkSceneManager::OnRightButtonUp()
695 if(_worldState==INIT_CREATION_CONTOUR)
697 _worldState=NOTHING_HAPPENS;
698 int lastId = _controllers.size()-1;
699 GConnectorController *connector = (GConnectorController*)_controllers[lastId];
700 connector->removeFromScene();
701 unregisterController(connector);
702 _controllers.erase(lastId);
704 std::map<int, GObjectController*>::iterator it;
705 for(it = _controllers.begin(); it != _controllers.end(); ++it)
707 GObjectController *desc = it->second;
708 desc->SetActive(true);
709 desc->getView()->setState(NOTHING_HAPPENS);
710 desc->getModel()->notifyObservers(_idManager);
715 for (int i = 0; i < _selectedObjects.size(); i++)
717 int id = _selectedObjects[i];
718 GObjectController* cont = _controllers[id];
719 cont->SetActive(true);
720 cont->getView()->setState(NOTHING_HAPPENS);
721 cont->getModel()->notifyObservers(_idManager);
724 _selectedObjects.clear();
729 //=========================================================================
731 bool wxVtkSceneManager::OnLeftDClick()
734 wxVTKRenderWindowInteractor *wxVTKiren;
735 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
736 wxVTKiren->GetEventPosition(X,Y);
738 std::map<int, GObjectController*>::iterator it;
740 bool clickOnObject = false;
742 for(it = _controllers.begin(); it != _controllers.end() && clickOnObject==false; ++it)
744 GObjectController *cont = it->second;
745 int type = cont->getGObjectType();
747 if(cont->getView()->isPointInside(X,Y))
751 for (int i=0; i<_selectedObjects.size(); i++)
753 int id = _selectedObjects[i];
754 GObjectController* control = _controllers[id];
755 control->getView()->setState(NOTHING_HAPPENS);
757 _selectedObjects.clear();
759 GBlackBoxModel *bbmodel = (GBlackBoxModel*)cont->getModel();
760 _parent->editBlackBox(bbmodel);
762 clickOnObject = true;
766 if(clickOnObject==false)
768 //_parent->editDiagramParameters(this);
774 //=========================================================================
776 bool wxVtkSceneManager::OnChar()
778 char keyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
780 // KeyCode 127 : Delete Key
781 // KeyCode 8 : Backspace Key
782 if(keyCode == 8 || keyCode == 127)
784 if(_selectedObjects.size()>0)
786 for(int i=0;i<_selectedObjects.size();i++)
788 int id = _selectedObjects[i];
791 _selectedObjects.clear();
798 //=========================================================================
800 void wxVtkSceneManager::deleteObject(int id)
802 GObjectController *control = _controllers[id];
803 std::vector<int> controllersToRemove;
805 if(control->getGObjectType()==GBLACKBOX || control->getGObjectType()==GCOMPLEXINPUTPORT || control->getGObjectType()==GCOMPLEXOUTPUTPORT)
807 GBoxModel *bbmod = (GBoxModel*)control->getModel();
808 std::vector<GPortModel*> inputs = bbmod->getInputPorts();
810 bool boxConnected = false;
812 // Add box input controllers to be removed
813 for(int i = 0;i<inputs.size();i++)
815 controllersToRemove.push_back(inputs[i]->getObjectId());
816 if(inputs[i]->isConnected())
822 std::vector<GPortModel*> outputs = bbmod->getOutputPorts();
824 // Add box output controllers to be removed
825 for(int i = 0;i<outputs.size();i++)
827 controllersToRemove.push_back(outputs[i]->getObjectId());
828 if(outputs[i]->isConnected())
834 // Add connection controllers to be removed
835 std::map<int, GObjectController*>::iterator it;
836 for(it = _controllers.begin(); it != _controllers.end(); ++it)
838 GObjectController *cont = it->second;
839 int type = cont->getGObjectType();
842 GConnectorModel *conMod = (GConnectorModel*)cont->getModel();
843 if(conMod->getStartPort()!=NULL && conMod->getStartPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
845 controllersToRemove.push_back(conMod->getObjectId());
847 if(conMod->getEndPort()!=NULL && conMod->getEndPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
849 controllersToRemove.push_back(conMod->getObjectId());
854 // Add box controller to be removed
855 controllersToRemove.push_back(bbmod->getObjectId());
857 else if(control->getGObjectType()==GCONNECTOR)
859 GConnectorModel *conMod = (GConnectorModel*)control->getModel();
860 controllersToRemove.push_back(conMod->getObjectId());
863 for(int i = 0;i<controllersToRemove.size();i++)
865 int id = controllersToRemove[i];
866 GObjectController *cont = _controllers[id];
867 cont->removeFromScene();
868 unregisterController((InteractorStyleMaracas*)cont);
869 _controllers.erase(id);
875 //=========================================================================
877 void wxVtkSceneManager::displayBlackBoxInfo(std::string packageName, std::string boxName)
879 _parent->displayBlackBoxInfo(packageName,boxName);
882 //=========================================================================
884 void wxVtkSceneManager::updateStatusBar(std::string textStatus)
886 _parent->updateStatusBar(textStatus);
889 //=========================================================================
891 std::string wxVtkSceneManager::getDiagramBBS()
893 bool existsExec=false;
895 std::vector<std::string> packages;
896 std::vector<int> boxes;
897 std::vector<int> connections;
898 std::vector<int> execBoxes;
900 std::map<int, GObjectController*>::iterator it;
902 for(it = _controllers.begin(); it != _controllers.end(); ++it)
904 GObjectController *desc = it->second;
905 int type = desc->getGObjectType();
909 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
911 std::string pkg = mod->getBBTKPackage();
912 bool existsPkg = false;
913 for(int t = 0;t<packages.size() && existsPkg == false;t++)
922 packages.push_back(pkg);
926 boxes.push_back(it->first);
927 if(mod->isExecutable())
929 execBoxes.push_back(it->first);
933 else if(type==GCONNECTOR)
935 connections.push_back(it->first);
939 std::string script = "";
940 script+="# BBTK GEditor Script\n";
941 script+="# ----------------------\n";
945 for(i = 0; i<packages.size();i++)
952 script+="include std\n";
954 for(i = 0; i<boxes.size();i++)
958 GObjectController *control = _controllers[id];
959 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
961 script+=model->getBBTKType();
963 script+=model->getBBTKName();
966 std::vector<GPortModel*> inputs = model->getInputPorts();
967 for(int j = 0; j<inputs.size();j++)
969 GPortModel* inputPort = inputs[j];
970 if(inputPort->isValueSet())
973 script+=model->getBBTKName();
975 script+=inputPort->getBBTKName();
977 script+=inputPort->getValue();
984 for(i = 0; i<connections.size();i++)
987 int id = connections[i];
988 GObjectController *control = _controllers[id];
989 GConnectorModel *model = (GConnectorModel*)control->getModel();
991 //Start Connection info
992 GPortModel *start = model->getStartPort();
993 script+=start->getParentBox()->getBBTKName();
995 script+=start->getBBTKName();
999 //End Connection info
1000 GPortModel *end = model->getEndPort();
1001 script+=end->getParentBox()->getBBTKName();
1003 script+=end->getBBTKName();
1008 for(i = 0; i<execBoxes.size();i++)
1011 int id = execBoxes[i];
1012 GObjectController *control = _controllers[id];
1013 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1015 script+=model->getBBTKName();
1024 //=========================================================================
1026 std::string wxVtkSceneManager::saveComplexBoxBBS(std::string cbName,std::string cbAuthor,std::string cbCategory,std::string cbDescription)
1029 std::vector<std::string> packages;
1030 std::vector<int> boxes;
1031 std::vector<int> connections;
1032 std::vector<int> execBoxes;
1034 std::map<int, GObjectController*>::iterator it;
1036 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1038 GObjectController *desc = it->second;
1039 int type = desc->getGObjectType();
1043 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
1045 std::string pkg = mod->getBBTKPackage();
1046 bool existsPkg = false;
1047 for(int t = 0;t<packages.size() && existsPkg == false;t++)
1049 if(packages[t]==pkg)
1056 packages.push_back(pkg);
1060 boxes.push_back(it->first);
1061 if(mod->isExecutable())
1063 execBoxes.push_back(it->first);
1066 else if(type==GCONNECTOR)
1068 connections.push_back(it->first);
1072 std::string script = "";
1074 for(i = 0; i<packages.size();i++)
1077 script+=packages[i];
1081 script+="include std\n";
1083 // Definition of a complex box
1088 script+="author \" ";
1092 script+="description \" ";
1093 script+=cbDescription;
1097 for(i = 0; i<boxes.size();i++)
1101 GObjectController *control = _controllers[id];
1102 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1104 script+=model->getBBTKType();
1106 script+=model->getBBTKName();
1109 std::vector<GPortModel*> inputs = model->getInputPorts();
1110 for(int j = 0; j<inputs.size();j++)
1112 GPortModel* inputPort = inputs[j];
1113 if(inputPort->isValueSet())
1116 script+=model->getBBTKName();
1118 script+=inputPort->getBBTKName();
1120 script+=inputPort->getValue();
1127 // Create connections in the script. If the connection is made with a complex port, it is created the input or output
1129 std::string complexInputs="";
1130 std::string complexOutputs="";
1132 for(i = 0; i<connections.size();i++)
1134 int id = connections[i];
1135 GObjectController *control = _controllers[id];
1136 GConnectorModel *model = (GConnectorModel*)control->getModel();
1139 GPortModel *start = model->getStartPort();
1140 GBoxModel *startBox =start->getParentBox();
1142 GPortModel *end = model->getEndPort();
1143 GBoxModel *endBox =end->getParentBox();
1145 if(startBox->getGObjectType()==GCOMPLEXINPUTPORT)
1147 complexInputs+="input ";
1148 complexInputs+=startBox->getBBTKName();
1151 complexInputs+=endBox->getBBTKName();
1153 complexInputs+=end->getBBTKName();
1156 complexInputs+="\" \"";
1158 complexInputs+="\n";
1160 else if(endBox->getGObjectType()==GCOMPLEXOUTPUTPORT)
1162 complexOutputs+="output ";
1163 complexOutputs+=endBox->getBBTKName();
1165 complexOutputs+=" ";
1166 complexOutputs+=startBox->getBBTKName();
1167 complexOutputs+=".";
1168 complexOutputs+=start->getBBTKName();
1170 complexOutputs+=" ";
1171 complexOutputs+="\" \"";
1173 complexOutputs+="\n";
1178 script+=startBox->getBBTKName();
1180 script+=start->getBBTKName();
1184 //End Connection info
1185 script+=endBox->getBBTKName();
1187 script+=end->getBBTKName();
1193 for(i = 0; i<execBoxes.size();i++)
1196 int id = execBoxes[i];
1197 GObjectController *control = _controllers[id];
1198 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1200 script+=model->getBBTKName();
1205 script+="# Complex input ports\n";
1206 script+=complexInputs;
1209 script+="# Complex output ports\n";
1210 script+=complexOutputs;
1219 //=========================================================================
1221 void wxVtkSceneManager::deleteAllBoxes()
1223 std::map<int, GObjectController*>::iterator it;
1224 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1226 GObjectController *cont = it->second;
1227 cont->removeFromScene();
1228 unregisterController((InteractorStyleMaracas*)cont);
1230 _selectedObjects.clear();
1231 _controllers.clear();
1235 //=========================================================================
1237 void wxVtkSceneManager::refreshScene()
1239 _baseView->RefreshView();
1242 //=========================================================================
1244 void wxVtkSceneManager::centerView()
1247 _baseView->GetRenderer()->GetActiveCamera()->GetFocalPoint(temp);
1248 _baseView->GetRenderer()->GetActiveCamera()->SetFocalPoint(0,0,temp[2]);
1249 _baseView->GetRenderer()->GetActiveCamera()->GetPosition(temp);
1250 _baseView->GetRenderer()->GetActiveCamera()->SetPosition(0,0,temp[2]);
1251 _baseView->RefreshView();
1255 //=========================================================================
1257 void wxVtkSceneManager::saveDiagram(std::string &content)
1261 //Print info IF COMPLEX BOX
1262 content+="COMPLEXBOX:";
1267 //Print info complex input ports
1268 std::vector<int> inputs = getComplexInputPorts();
1269 int insize = inputs.size();
1270 content+="COMPLEXINPUTS:";
1271 sprintf (buffer, "%d", insize);
1275 for(int i = 0;i<insize;i++)
1278 GObjectController *cont = _controllers[id];
1279 cont->getModel()->save(content);
1282 //Print info complex output ports
1283 std::vector<int> outputs = getComplexOutputPorts();
1284 int outsize = outputs.size();
1285 content+="COMPLEXOUTPUTS:";
1286 sprintf (buffer, "%d", outsize);
1290 for(int i = 0;i<outsize;i++)
1292 int id = outputs[i];
1293 GObjectController *cont = _controllers[id];
1294 cont->getModel()->save(content);
1303 std::vector<int> boxes = getBlackBoxes();
1304 int bsize = boxes.size();
1306 sprintf (buffer, "%d", bsize);
1310 for(int i = 0;i<bsize;i++)
1313 GObjectController *cont = _controllers[id];
1314 cont->getModel()->save(content);
1318 std::vector<int> connections = getConnections();
1319 int csize = connections.size();
1320 content+="CONNECTIONS:";
1321 sprintf (buffer, "%d", csize);
1325 for(int i = 0;i<csize;i++)
1327 int id = connections[i];
1328 GObjectController *cont = _controllers[id];
1329 cont->getModel()->save(content);
1334 //=========================================================================
1336 void wxVtkSceneManager::loadDiagram(ifstream &inputStream)
1339 std::string line="";
1340 char delims[] = ":";
1341 char *result = NULL;
1342 getline(inputStream,line);
1345 while ( !inputStream.eof() )
1347 if(line=="" || line[0]=='#')
1349 getline(inputStream,line);
1351 else if(line=="APP_START")
1362 getline(inputStream,line);//COMPLEX_BOX:TRUE|FALSE
1364 strcpy( complex, line.c_str() );
1365 result = strtok( complex, delims );
1366 result = strtok( NULL, delims );
1367 std::string isComplexBox(result);
1369 if(isComplexBox=="TRUE")
1373 //-----------------------
1374 //- COMPLEX INPUT PORTS
1375 //-----------------------
1376 getline(inputStream,line);//COMPLEXINPUTS:num
1378 strcpy( inputs, line.c_str() );
1379 result = strtok( inputs, delims );
1380 result = strtok( NULL, delims );
1383 std::istringstream inps(result);
1386 for(int i = 0;i<numInputs;i++)
1389 getline(inputStream,line);//COMPLEX_PORT
1390 getline(inputStream,line);//name
1391 std::string inputPortName(line);
1394 getline(inputStream,line);//xInic:yInic:zInic
1396 strcpy( coord, line.c_str() );
1397 result = strtok( coord, delims );//xInic
1398 std::string xInic(result);
1399 result = strtok( NULL, delims );//yInic
1400 std::string yInic(result);
1401 result = strtok( NULL, delims );//zInic
1402 std::string zInic(result);
1404 double xIn, yIn, zIn;
1405 std::istringstream xSt(xInic);
1407 std::istringstream ySt(yInic);
1409 std::istringstream zSt(zInic);
1412 getline(inputStream,line);//FIN_COMPLEX_PORT
1414 int idInputPort = createGComplexBoxInputPort(inputPortName);
1415 GObjectController *cont = _controllers[idInputPort];
1416 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
1417 cbmod->setInicPoint(xIn,yIn,zIn);
1418 cbmod->notifyObservers(_idManager);
1422 //-----------------------
1423 //- COMPLEX OUTPUT PORTS
1424 //-----------------------
1426 getline(inputStream,line);//COMPLEXOUTPUTS:num
1428 strcpy( outputs, line.c_str() );
1429 result = strtok( outputs, delims );
1430 result = strtok( NULL, delims );
1433 std::istringstream outps(result);
1434 outps >> numOutputs;
1436 for(int i = 0;i<numOutputs;i++)
1439 getline(inputStream,line);//COMPLEX_PORT
1440 getline(inputStream,line);//name
1441 std::string outputPortName(line);
1444 getline(inputStream,line);//xInic:yInic:zInic
1446 strcpy( coord, line.c_str() );
1447 result = strtok( coord, delims );//xInic
1448 std::string xInic(result);
1449 result = strtok( NULL, delims );//yInic
1450 std::string yInic(result);
1451 result = strtok( NULL, delims );//zInic
1452 std::string zInic(result);
1454 double xIn, yIn, zIn;
1455 std::istringstream xSt(xInic);
1457 std::istringstream ySt(yInic);
1459 std::istringstream zSt(zInic);
1462 getline(inputStream,line);//FIN_COMPLEX_PORT
1464 int idOutputPort = createGComplexBoxOutputPort(outputPortName);
1465 GObjectController *cont = _controllers[idOutputPort];
1466 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
1467 cbmod->setInicPoint(xIn,yIn,zIn);
1468 cbmod->notifyObservers(_idManager);
1474 getline(inputStream,line);//BOXES:num
1476 strcpy( boxes, line.c_str() );
1477 result = strtok( boxes, delims );
1478 result = strtok( NULL, delims );
1481 std::istringstream is(result);
1484 for(int i = 0;i<numBoxes;i++)
1487 getline(inputStream,line);//BOX
1488 getline(inputStream,line);//package:type:name
1490 strcpy( box, line.c_str() );
1491 result = strtok( box, delims );//package
1492 std::string package(result);
1493 result = strtok( NULL, delims );//type
1494 std::string type(result);
1495 result = strtok( NULL, delims );//name
1496 std::string name(result);
1498 getline(inputStream,line);//ISEXEC:TRUE|FALSE
1500 strcpy( exec, line.c_str() );
1501 result = strtok( exec, delims );//ISEXEC
1502 result = strtok( NULL, delims );//TRUE|FALSE
1503 std::string isExec(result);
1506 getline(inputStream,line);//xInic:yInic:zInic
1508 strcpy( coord, line.c_str() );
1509 result = strtok( coord, delims );//xInic
1510 std::string xInic(result);
1511 result = strtok( NULL, delims );//yInic
1512 std::string yInic(result);
1513 result = strtok( NULL, delims );//zInic
1514 std::string zInic(result);
1516 double xIn, yIn, zIn;
1517 std::istringstream xSt(xInic);
1519 std::istringstream ySt(yInic);
1521 std::istringstream zSt(zInic);
1525 getline(inputStream,line);//xEnd:yEnd:zEnd
1526 strcpy( coord, line.c_str() );
1527 result = strtok( coord, delims );//xEnd
1528 std::string xEnd(result);
1529 result = strtok( NULL, delims );//yEnd
1530 std::string yEnd(result);
1531 result = strtok( NULL, delims );//zEnd
1532 std::string zEnd(result);
1534 double xEn, yEn, zEn;
1535 std::istringstream xEt(xEnd);
1537 std::istringstream yEt(yEnd);
1539 std::istringstream zEt(zEnd);
1542 int idBox = createGBlackBox(0,0,package,type);
1543 GObjectController *cont = _controllers[idBox];
1544 GBlackBoxModel *bbmod = (GBlackBoxModel*)cont->getModel();
1545 bbmod->setBBTKName(name);
1546 bbmod->setInicPoint(xIn,yIn,zIn);
1547 bbmod->setFinalPoint(xEn,yEn,zEn);
1550 bbmod->setExecutable(true);
1552 else if(isExec=="FALSE")
1554 bbmod->setExecutable(false);
1558 getline(inputStream,line);//PORT o FIN_BOX
1559 std::string port=line.substr(0,4);
1562 getline(inputStream,line);//name:value
1564 strcpy( poort, line.c_str() );
1565 result = strtok( poort, delims );//name
1566 std::string name(result);
1567 result = strtok( NULL, delims );//value
1568 std::string value(result);
1570 bbmod->setValueToInput(name,value);
1572 getline(inputStream,line);//PORT o FIN_BOX
1573 port=line.substr(0,4);
1576 bbmod->notifyObservers(_idManager);
1581 getline(inputStream,line);//CONNECTIONS:num
1583 strcpy( conns, line.c_str() );
1584 result = strtok( conns, delims );
1585 result = strtok( NULL, delims );
1588 std::istringstream isCons(result);
1591 for(int i = 0;i<numConns;i++)
1594 getline(inputStream,line);//CONNECTION
1595 getline(inputStream,line);//Startbox.PortName:EndBox.PortName
1598 strcpy( connec, line.c_str() );
1599 result = strtok( connec, delims );
1600 std::string nameStartBox(result);
1601 result = strtok( NULL, delims );
1602 std::string nameStartPort(result);
1603 result = strtok( NULL, delims );
1604 std::string nameEndBox(result);
1605 result = strtok( NULL, delims );
1606 std::string nameEndPort(result);
1608 std::vector<int> lstB = getBlackBoxes();
1610 GPortModel *startP=NULL;
1611 GPortModel *endP=NULL;
1612 for(int j = 0;j<lstB.size();j++)
1615 GBlackBoxModel *bbMod = (GBlackBoxModel*)_controllers[idB]->getModel();
1616 if(_controllers[idB]->getModel()->getBBTKName()==nameStartBox)
1618 startP = bbMod->getOutputPort(nameStartPort);
1620 else if(_controllers[idB]->getModel()->getBBTKName()==nameEndBox)
1622 endP = bbMod->getInputPort(nameEndPort);
1630 std::vector<int> lstInputs = getComplexInputPorts();
1631 for(int j = 0;j<lstInputs.size();j++)
1633 int idB = lstInputs[j];
1634 GBoxModel *cbMod = (GBoxModel*)_controllers[idB]->getModel();
1635 if(_controllers[idB]->getModel()->getBBTKName()==nameStartBox)
1637 startP = cbMod->getOutputPort(nameStartPort);
1644 std::vector<int> lstOutputs = getComplexOutputPorts();
1645 for(int j = 0;j<lstOutputs.size();j++)
1647 int idB = lstOutputs[j];
1648 GBoxModel *cbMod = (GBoxModel*)_controllers[idB]->getModel();
1649 if(_controllers[idB]->getModel()->getBBTKName()==nameEndBox)
1651 endP = cbMod->getInputPort(nameEndPort);
1657 int idCon = createGConnector(startP);
1658 _worldState = NOTHING_HAPPENS;
1659 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
1661 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
1662 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
1663 tempp->endContourCreation();
1664 conMod->setEndPort(endP);
1665 conView->updateStartEndPoints();
1672 //=========================================================================
1674 std::vector<int> wxVtkSceneManager::getBlackBoxes()
1676 std::vector<int> vect;
1677 std::map<int, GObjectController*>::iterator it;
1678 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1680 GObjectController *cont = it->second;
1681 if(cont->getGObjectType()==GBLACKBOX)
1683 vect.push_back(cont->getId());
1689 //=========================================================================
1691 std::vector<int> wxVtkSceneManager::getComplexInputPorts()
1693 std::vector<int> vect;
1694 std::map<int, GObjectController*>::iterator it;
1695 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1697 GObjectController *cont = it->second;
1698 if(cont->getGObjectType()==GCOMPLEXINPUTPORT)
1700 vect.push_back(cont->getId());
1706 //=========================================================================
1708 std::vector<int> wxVtkSceneManager::getComplexOutputPorts()
1710 std::vector<int> vect;
1711 std::map<int, GObjectController*>::iterator it;
1712 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1714 GObjectController *cont = it->second;
1715 if(cont->getGObjectType()==GCOMPLEXOUTPUTPORT)
1717 vect.push_back(cont->getId());
1723 //=========================================================================
1725 std::vector<int> wxVtkSceneManager::getConnections()
1727 std::vector<int> vect;
1728 std::map<int, GObjectController*>::iterator it;
1729 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1731 GObjectController *cont = it->second;
1732 if(cont->getGObjectType()==GCONNECTOR)
1734 vect.push_back(cont->getId());
1740 //=========================================================================
1742 bool wxVtkSceneManager::isComplexBox()
1744 return _isComplexBox;
1747 //=========================================================================
1749 void wxVtkSceneManager::setComplexBox(bool val)
1754 //=========================================================================
1756 int wxVtkSceneManager::addObjectController(GObjectController* objController)
1758 //Register the controller of the new object
1759 registerController((InteractorStyleMaracas*) objController);
1761 //Add the object to the objects list
1762 int newId = _controllers.size();
1763 objController->setId(newId);
1764 _controllers[newId] = objController;
1768 //=========================================================================
1770 int wxVtkSceneManager::getNumSelectedObjects()
1772 return _selectedObjects.size();
1775 //=========================================================================
1777 std::map<int,GObjectController*> wxVtkSceneManager::getSelectedObjects()
1779 std::map<int,GObjectController*> mapSelected;
1781 std::map<int, GObjectController*>::iterator it;
1782 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1784 GObjectController *cont = it->second;
1785 if(cont->getGObjectType()==GBLACKBOX && cont->getView()->getState()==SELECTED)
1787 mapSelected[cont->getId()]=cont;
1791 std::map<int, GObjectController*>::iterator it2;
1792 for(it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
1794 GObjectController *cont = it2->second;
1795 if(cont->getGObjectType()==GCONNECTOR)
1797 GConnectorModel* cmod = (GConnectorModel*)cont->getModel();
1798 GBoxModel* endPortParentBox = cmod->getEndPort()->getParentBox();
1799 GBoxModel* startPortParentBox = cmod->getStartPort()->getParentBox();
1801 std::map<int, GObjectController*>::iterator iterOBJ1 = mapSelected.find(startPortParentBox->getObjectId());
1802 std::map<int, GObjectController*>::iterator iterOBJ2 = mapSelected.find(endPortParentBox->getObjectId());
1804 if(iterOBJ1 != mapSelected.end() && iterOBJ2 != mapSelected.end())
1806 int ID = cont->getId();
1807 mapSelected[ID]=cont;
1815 //=========================================================================
1817 void wxVtkSceneManager::addObjects(std::map<int,GObjectController*> objectsMap)
1820 std::map<int,int> oldIdNewIdBoxes;
1821 std::vector<int> connections;
1823 std::map<int, GObjectController*>::iterator it;
1824 for(it = objectsMap.begin(); it != objectsMap.end(); ++it)
1826 GObjectController *cont = it->second;
1827 int type = cont->getGObjectType();
1832 double xInic, yInic,zInic;
1833 GBlackBoxModel* copyBox = (GBlackBoxModel*)cont->getModel();
1834 copyBox->getInicPoint(xInic,yInic,zInic);
1835 int idBox = createGBlackBox(0,0,copyBox->getBBTKPackage(),copyBox->getBBTKType());
1837 int idcB = copyBox->getObjectId();
1838 oldIdNewIdBoxes[idcB]=idBox;
1839 cont = _controllers[idBox];
1840 GBlackBoxModel* newbox = (GBlackBoxModel*)cont->getModel();
1841 newbox->setInicPoint(xInic,yInic,zInic);
1842 int num = newbox->getNumInputPorts();
1843 for(int j=0;j<num;j++)
1845 newbox->setValueToInputPort(j,copyBox->getValueInputPort(j));
1847 newbox->notifyObservers(_idManager);
1849 else if(type==GCONNECTOR)
1851 int idCon = cont->getId();
1852 connections.push_back(idCon);
1857 for(int i = 0 ;i<connections.size();i++)
1859 int objId = connections[i];
1860 GObjectController *cont = objectsMap[objId];
1861 GConnectorModel* connectModel = (GConnectorModel*)cont->getModel();
1863 GPortModel* startPort = connectModel->getStartPort();
1864 int startPortIndex = startPort->getPosInBox();
1865 GPortModel* endPort = connectModel->getEndPort();
1866 int endPortIndex = endPort->getPosInBox();
1868 GBlackBoxModel* startPortParentBox = (GBlackBoxModel*)startPort->getParentBox();
1869 GBlackBoxModel* endPortParentBox = (GBlackBoxModel*)endPort->getParentBox();
1871 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
1872 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
1874 GBlackBoxModel* newStartBox = (GBlackBoxModel*)_controllers[idNewStartBox]->getModel();
1875 GBlackBoxModel* newEndBox = (GBlackBoxModel*)_controllers[idNewEndBox]->getModel();
1877 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
1878 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
1880 // Creates connection
1881 int idCon = createGConnector(newStartPort);
1882 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
1883 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
1884 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
1885 tempp->endContourCreation();
1886 conMod->setEndPort(newEndPort);
1887 conView->updateStartEndPoints();
1890 std::map<int, int>::iterator itIds;
1891 for(itIds = oldIdNewIdBoxes.begin(); itIds != oldIdNewIdBoxes.end(); ++itIds)
1893 int idOld = itIds->first;
1894 int idNew = itIds->second;
1896 GBlackBoxModel* oldBox = (GBlackBoxModel*)objectsMap[idOld]->getModel();
1897 GBlackBoxModel* newBox = (GBlackBoxModel*)_controllers[idNew]->getModel();
1899 std::vector<int> oldInputConnections = oldBox->getConnectedInputs();
1900 std::vector<int> oldOutputConnections = oldBox->getConnectedOutputs();
1901 std::vector<int> newInputConnections = newBox->getConnectedInputs();
1902 std::vector<int> newOutputConnections = newBox->getConnectedOutputs();
1904 for(int k = 0; k<oldInputConnections.size();k++)
1908 for(int l = 0; l<newInputConnections.size() && !exist;l++)
1910 if(oldInputConnections[k]==newInputConnections[l])
1918 //Create complex input
1919 int posInBox = oldInputConnections[k];
1920 GPortModel* inputPort = oldBox->getInputPort(posInBox);
1921 std::string inputPortName = inputPort->getBBTKName();
1922 int idInputPort = createGComplexBoxInputPort(inputPortName);
1923 GObjectController *cont = _controllers[idInputPort];
1924 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
1926 inputPort->getInicPoint(xIn,yIn,zIn);
1928 cbmod->setInicPoint(xIn,yIn,zIn);
1929 cbmod->notifyObservers(_idManager);
1931 GPortModel* inputPortEnd = newBox->getInputPort(posInBox);
1933 // Creates connection
1934 int idCon = createGConnector(cbmod->getOutputPort(0));
1935 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
1936 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
1937 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
1938 tempp->endContourCreation();
1939 conMod->setEndPort(inputPortEnd);
1940 conView->updateStartEndPoints();
1947 for(int k = 0; k<oldOutputConnections.size();k++)
1951 for(int l = 0; l<newOutputConnections.size() && !exist;l++)
1953 if(oldOutputConnections[k]==newOutputConnections[l])
1961 //Create complex output
1962 int posInBox = oldOutputConnections[k];
1963 GPortModel* outputPort = oldBox->getOutputPort(posInBox);
1964 std::string outputPortName = outputPort->getBBTKName();
1965 int idOutputPort = createGComplexBoxOutputPort(outputPortName);
1966 GObjectController *cont = _controllers[idOutputPort];
1967 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
1969 outputPort->getInicPoint(xIn,yIn,zIn);
1971 cbmod->setInicPoint(xIn,yIn,zIn);
1972 cbmod->notifyObservers(_idManager);
1974 GPortModel* outputPortEnd = newBox->getOutputPort(posInBox);
1976 // Creates connection
1977 int idCon = createGConnector(outputPortEnd);
1978 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
1979 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
1980 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
1981 tempp->endContourCreation();
1982 conMod->setEndPort(cbmod->getInputPort(0));
1983 conView->updateStartEndPoints();
1994 //=========================================================================
1996 } // EO namespace bbtk