1 /*=========================================================================
7 =========================================================================*/
9 /* ---------------------------------------------------------------------
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
14 * This software is governed by the CeCILL-B license under French law and
15 * abiding by the rules of distribution of free software. You can use,
16 * modify and/ or redistribute the software under the terms of the CeCILL-B
17 * license as circulated by CEA, CNRS and INRIA at the following URL
18 * http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
19 * or in the file LICENSE.txt.
21 * As a counterpart to the access to the source code and rights to copy,
22 * modify and redistribute granted by the license, users are provided only
23 * with a limited warranty and the software's author, the holder of the
24 * economic rights, and the successive licensors have only limited
27 * The fact that you are presently reading this means that you have had
28 * knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */
33 * \brief Class bbtk::wxVtkSceneManager .
37 #include "wxVtkSceneManager.h"
43 //=========================================================================
44 wxVtkSceneManager::wxVtkSceneManager(wxGEditorTabPanel *parent, wxVtk3DBaseView *baseView,int idManager)
56 printf ("RaC-EED 21-06-2010 %p wxVtkSceneManager::wxVtkSceneManager If you comment this line, the drag and drop functionnality is not initialized.\n" , this );
57 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget((wxDropTarget*)parent);
60 _worldState=NOTHING_HAPPENS;
61 registerController(this);
64 _idConnectionInCreation=-1;
69 //=========================================================================
71 void wxVtkSceneManager::disconnectDrop()
73 printf ("EED %p ~wxVtkSceneManager::disconnectDrop()\n" , this );
74 //EED02JUIN2010 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget(NULL);
75 // _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget( new tmpClasswxTextDropTarget() );
78 //=========================================================================
80 wxVtkSceneManager::~wxVtkSceneManager()
82 printf ("EED %p ~wxVtkSceneManager()\n" , this );
86 //=========================================================================
88 void wxVtkSceneManager::configureBaseView()
90 vtkInteractorStyleBaseView2D *interactorstylebaseview = vtkInteractorStyleBaseView2D::New();
92 _baseView->SetInteractorStyleBaseView(interactorstylebaseview);
94 // Important to activate the 2D interaction system
95 wxVTKRenderWindowInteractor *iren = _baseView->GetWxVTKRenderWindowInteractor();
96 interactorstylebaseview->SetInteractor ( iren );
97 iren->SetInteractorStyle(interactorstylebaseview);
98 interactorstylebaseview->SetwxVtkBaseView(_baseView);
100 _baseView->GetRenderer()->GetActiveCamera()->ParallelProjectionOn();
101 _baseView->GetRenderer()->ResetCamera(-100,100,-100,100,900,1000);
103 _baseView->GetRenderer()->SetBackground(0.9,0.9,0.9);
104 _baseView->GetRenderer()->GradientBackgroundOff();
105 _baseView->Refresh();
108 //=========================================================================
110 std::string wxVtkSceneManager::generateANewNameForABox()
112 std::stringstream boxname;
115 boxname << "Box0" << _numBoxes;
117 boxname << "Box" << _numBoxes;
120 return boxname.str();
123 //=========================================================================
125 std::string wxVtkSceneManager::findANewNameForABox()
127 std::string boxname=generateANewNameForABox();
129 while (boxExist(boxname)==true)
131 boxname=generateANewNameForABox();
137 //=========================================================================
139 void wxVtkSceneManager::configGBlackBox(int idBox, double xIn, double yIn, double zIn, std::string name, bool boxExecutable,double xEn,double yEn,double zEn)
141 GObjectController *cont = _controllers[idBox];
142 GBlackBoxModel *bbmod = (GBlackBoxModel*)cont->getModel();
143 bbmod->setBBTKName(name);
144 bbmod->setInicPoint(xIn,yIn,zIn);
145 bbmod->setFinalPoint(xEn,yEn,zEn);
146 bbmod->setExecutable(boxExecutable);
148 bbmod->notifyObservers(_idManager);
153 //=========================================================================
155 int wxVtkSceneManager::createGBlackBox(int x, int y, std::string packageName, std::string boxType)
157 _worldState = NOTHING_HAPPENS;
158 //EED int windowWidth = _baseView->GetRenWin()->GetSize()[0];
159 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
161 int type = GBLACKBOX;
163 //Create the MVC Objects
165 GBlackBoxModel *model = (GBlackBoxModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
166 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
167 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
169 BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxType);
171 //Prepares the initial model
172 //The coordinates obtained are the following. Top-Left:x=0,y=0 Bottom-Right:x=width,y=height
175 double yy = windowHeight-y;
177 //z value is not important yet, because it is only used a parallel projection
180 _baseView->TransCoordScreenToWorld(xx,yy,zz);
181 model->setInicPoint(xx,yy,zz);
183 std::stringstream stream;
185 std::string newBoxName;
186 newBoxName = findANewNameForABox();
189 stream << newBoxName;
191 std::string arraystring = stream.str();
193 model->setBBTKName(arraystring);
194 model->setBBTKType(boxType);
195 model->setBBTKPackage(packageName);
197 model->addObserver(view);
198 model->addObserver(this);
200 //Iterate and create the input ports
201 std::map<std::string, BlackBoxInputDescriptor*> descriptorInMap = descriptor->GetInputDescriptorMap();
202 std::map<std::string, BlackBoxInputDescriptor*>::iterator itInput;
205 for(itInput = descriptorInMap.begin(); itInput != descriptorInMap.end(); ++itInput)
207 BlackBoxInputDescriptor *desc = itInput->second;
208 createGInputPort(GINPUTPORT,i,model,desc);
212 //Iterate and create the output ports
213 std::map<std::string, BlackBoxOutputDescriptor*> descriptorOutMap = descriptor->GetOutputDescriptorMap();
214 std::map<std::string, BlackBoxOutputDescriptor*>::iterator itOutput;
217 for(itOutput = descriptorOutMap.begin();itOutput != descriptorOutMap.end(); ++itOutput)
219 BlackBoxOutputDescriptor *desc = itOutput->second;
220 createGOutputPort(GOUTPUTPORT,i,model,desc);
225 //Associates the view with the correspondent renderer and the model.
226 //(NOTE: Refresh is only made by the view)
227 view->setModel(model);
228 view->setBaseView(_baseView);
229 view->initVtkObjects();
231 //Associates the controller with the correspondent model and view
232 controller->setModelAndView(model,view);
234 //Resgiter change to the observers of the actual model
235 model->notifyObservers(_idManager);
237 int newId = addObjectController(controller);
243 //=========================================================================
245 int wxVtkSceneManager::createGComplexBoxInputPort(std::string inputName)
247 //EED int windowWidth=_baseView->GetRenWin()->GetSize()[0];
248 int windowHeight=_baseView->GetRenWin()->GetSize()[1];
250 int type = GCOMPLEXINPUTPORT;
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(inputName);
270 model->setBBTKType("ComplexInputPort");
271 model->setComplexPortType(type);
273 model->addObserver(view);
274 model->addObserver(this);
276 //create the output port
277 GPortController* portController = createGPort(GOUTPUTPORT,inputName,"ComplexInputPort",0,model);
278 model->addOutputPort((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::createGComplexBoxOutputPort(std::string outputName)
300 //EED int windowWidth=_baseView->GetRenWin()->GetSize()[0];
301 int windowHeight=_baseView->GetRenWin()->GetSize()[1];
303 int type = GCOMPLEXOUTPUTPORT;
305 //Create the MVC Objects
307 GComplexBoxPortModel *model = (GComplexBoxPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
308 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
309 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
311 //Prepares the initial model
314 double yy = windowHeight-5;
316 //z value is not important yet, because it is only used a parallel projection
319 _baseView->TransCoordScreenToWorld(xx,yy,zz);
320 model->setInicPoint(xx,yy,zz);
322 model->setBBTKName(outputName);
323 model->setBBTKType("ComplexOutputPort");
324 model->setComplexPortType(type);
326 model->addObserver(view);
327 model->addObserver(this);
329 //create the output port
330 GPortController* portController = createGPort(GINPUTPORT,outputName,"ComplexInputPort",0,model);
331 model->addInputPort((GPortModel*)portController->getModel());
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 //Resgiter change to the observers of the actual model
343 model->notifyObservers(_idManager);
345 int newId = addObjectController(controller);
349 //=========================================================================
351 int wxVtkSceneManager::createGInputPort(int portType, int posinBox,GBoxModel *blackBox, BlackBoxInputDescriptor *desc)
353 GPortController* portController = createGPort(portType,desc->GetName(),desc->GetTypeName(),posinBox,blackBox);
354 blackBox->addInputPort((GPortModel*)portController->getModel());
355 return portController->getId();
358 //=========================================================================
360 int wxVtkSceneManager::createGOutputPort(int portType, int posinBox,GBoxModel *blackBox, BlackBoxOutputDescriptor *desc)
362 GPortController* portController = createGPort(portType,desc->GetName(),desc->GetTypeName(),posinBox,blackBox);
363 blackBox->addOutputPort((GPortModel*)portController->getModel());
364 return portController->getId();
367 //=========================================================================
369 GPortController* wxVtkSceneManager::createGPort(int portType,std::string bbtkName, std::string bbtkType, int posInBox,GBoxModel *blackBox)
373 //Create the MVC Objects
374 GPortModel *model = (GPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
375 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
376 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
378 model->registerInBox(blackBox,portType, posInBox);
380 model->setBBTKType(bbtkType);
381 model->setBBTKName(bbtkName);
383 model->addObserver(view);
384 model->addObserver(this);
386 //Associates the view with the correspondent renderer and the model.
387 //(NOTE: Refresh is only made by the view)
388 view->setModel(model);
389 view->setBaseView(_baseView);
390 view->initVtkObjects();
392 //Associates the controller with the correspondent model and view
393 controller->setModelAndView(model,view);
395 model->notifyObservers(_idManager);
397 int newId = addObjectController(controller);
399 return (GPortController*)controller;
402 //=========================================================================
404 int wxVtkSceneManager::createGConnector(GPortModel* startPort)
406 int type = GCONNECTOR;
408 manualConnectorContourController* manContourControl = new manualConnectorContourController();
409 manualConnectorContourView* manContourView = new manualConnectorContourView();
410 manualContourModel* manContourModel = new manualContourModel();
412 GConnectorController* connectorcontroller = new GConnectorController();
413 GConnectorModel* connectorModel = new GConnectorModel();
414 vtkGConnectorView* connectorView = new vtkGConnectorView();
415 connectorModel->setGObjectType(type);
417 manContourModel->SetCloseContour(false);
418 connectorModel->setStartPort(startPort);
420 manContourView->SetModel( manContourModel );
421 manContourView->SetWxVtkBaseView( _baseView );
422 manContourView->SetRange( 0.5 );
423 manContourView->SetZ( 900 );
425 manContourView->SetColorNormalContour(0, 0, 1);
426 manContourView->SetColorEditContour(0.5, 0.5, 0.5);
427 manContourView->SetColorSelectContour(1, 0.8, 0);
428 manContourView->SetWidthLine(1);
429 manContourView->SetShowText(false);
431 manContourControl->SetModelView( manContourModel , manContourView );
433 manContourControl->CreateNewManualContour();
435 manContourView->RefreshContour();
439 connectorModel->getInicPoint(x,y,z);
441 manContourControl->SetState(1);
442 manContourModel->SetCloseContour(false);
444 manContourModel->AddPoint(x,y,z);
445 manContourView->AddPoint();
447 manContourModel->AddPoint(x,y,z);
448 manContourView->AddPoint();
450 int bak= manContourControl->GetNumberOfPointsManualContour() - 1;
451 manContourControl->_bakIdPoint=bak;
452 manContourView->Refresh();
454 manContourControl->SetMoving( false );
456 connectorcontroller->setModelAndView(connectorModel,connectorView);
458 int newId = addObjectController(connectorcontroller);
460 connectorcontroller->setManualContourController(manContourControl);
461 connectorModel->setManualContourModel(manContourModel);
462 connectorView->setManualContourView(manContourView);
463 connectorView->setModel(connectorModel);
464 connectorView->setBaseView(_baseView);
467 connectorModel->addObserver(connectorView);
468 connectorModel->addObserver(this);
473 //=========================================================================
475 void wxVtkSceneManager::registerController(InteractorStyleMaracas *param)
477 vtkInteractorStyleBaseView* baseViewControlManager = (vtkInteractorStyleBaseView*)_baseView->GetInteractorStyleBaseView();
478 baseViewControlManager->AddInteractorStyleMaracas( param );
481 //=========================================================================
483 void wxVtkSceneManager::unregisterController(InteractorStyleMaracas *param)
485 vtkInteractorStyleBaseView* baseViewControlManager = (vtkInteractorStyleBaseView*)_baseView->GetInteractorStyleBaseView();
486 baseViewControlManager->RemoveInteractorStyleMaracas( param );
489 //=========================================================================
491 vtkRenderer* wxVtkSceneManager::getRenderer()
493 return _baseView->GetRenderer();
496 //=========================================================================
498 vtkRenderWindow* wxVtkSceneManager::getRenderWindow()
500 return _baseView->GetRenWin();
502 //=========================================================================
505 void wxVtkSceneManager::update(int idController,int command)
507 if(command != NO_COMMAND)
509 if(command == ADD_TO_SELECTED)
511 //EED GObjectController* cont = _controllers[idController];
514 for (int i=0; i<(int)_selectedObjects.size() && foundID==false; i++)
516 int id = _selectedObjects[i];
524 int id = idController;
525 _selectedObjects.push_back(id);
529 else if(command == INIT_CREATION_CONTOUR)
531 _worldState = INIT_CREATION_CONTOUR;
532 GObjectController* cont = _controllers[idController];
533 GPortModel* startOutputPort = (GPortModel*)cont->getModel();
536 // The last one is the controller of the connector
537 std::map<int, GObjectController*>::iterator it2;
539 for(it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
541 GObjectController *cont = it2->second;
542 if(cont->getGObjectType() == GPORT )
544 GPortModel* port = (GPortModel*)cont->getModel();
545 if(port->getPortType()==GINPUTPORT)
547 cont->SetActive(true);
551 cont->getView()->setState(NOTHING_HAPPENS);
552 cont->getModel()->notifyObservers(_idManager);
553 cont->SetActive(false);
558 cont->getView()->setState(NOTHING_HAPPENS);
559 cont->getModel()->notifyObservers(_idManager);
560 cont->SetActive(false);
564 _selectedObjects.clear();
566 _idConnectionInCreation=createGConnector(startOutputPort);
569 else if(command == FIN_CREATION_CONTOUR && _worldState == INIT_CREATION_CONTOUR)
571 _worldState = NOTHING_HAPPENS;
572 //int id = _controllers.size()-1;
573 GObjectController* cont = _controllers[_idConnectionInCreation];
574 GConnectorModel* modelContour = (GConnectorModel*)cont->getModel();
576 GObjectController* finPort = _controllers[idController];
577 if(finPort->getGObjectType() == GPORT)
579 GPortModel* modelPort = (GPortModel*)finPort->getModel();
580 modelContour->setEndPort(modelPort);
583 manualConnectorContourController* manCont = ((GConnectorController*)cont)->getManualContourController();
584 manualConnectorContourView* connView = (manualConnectorContourView*)manCont->GetManualViewBaseContour();
587 std::map<int, GObjectController*>::iterator it2;
589 for(it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
591 GObjectController *cont = it2->second;
592 if(cont->getView()!=NULL)
594 cont->getView()->setState(NOTHING_HAPPENS);
595 cont->getModel()->notifyObservers(_idManager);
597 cont->SetActive(true);
604 //=========================================================================
606 bool wxVtkSceneManager::OnMouseMove()
609 wxVTKRenderWindowInteractor *wxVTKiren;
610 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
611 wxVTKiren->GetEventPosition(X,Y);
614 if(_worldState == DRAG_OBJECTS)
616 for (int i=0; i<(int)_selectedObjects.size(); i++)
618 int id = _selectedObjects[i];
619 GObjectController* cont = _controllers[id];
622 cont->getView()->setStartDragging(true);
624 cont->getView()->moveObject(X,Y);
625 cont->getView()->setState(DRAG);
626 cont->getModel()->notifyObservers(_idManager);
629 std::map<int, GObjectController*>::iterator it;
631 for(it = _controllers.begin(); it != _controllers.end(); ++it)
633 GObjectController *desc = it->second;
634 if(desc->getGObjectType()==GCONNECTOR)
636 vtkGConnectorView* vconn = (vtkGConnectorView*)desc->getView();
637 vconn->updateStartEndPoints();
641 _startDragging=false;
644 else if(_worldState == NOTHING_HAPPENS || _worldState == INIT_CREATION_CONTOUR)
646 std::map<int, GObjectController*>::iterator it;
648 for(it = _controllers.begin(); it != _controllers.end(); ++it)
650 GObjectController *desc = it->second;
651 int type = desc->getGObjectType();
652 int state = desc->getView()->getState();
654 if(state == HIGHLIGHTED){
656 updateStatusBar(desc->getStatusText());
659 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
660 _parent->displayBlackBoxInfo(mod->getBBTKPackage(),mod->getBBTKType());
669 //=========================================================================
671 bool wxVtkSceneManager::OnLeftButtonDown()
673 if(_worldState==INIT_CREATION_CONTOUR)
675 bool isOverPort=false;
676 std::map<int, GObjectController*>::iterator it;
677 for(it = _controllers.begin(); it != _controllers.end() && isOverPort==false; ++it)
679 GObjectController *desc = it->second;
680 if(desc->getGObjectType()==GPORT)
682 GPortModel* portmod=(GPortModel*)desc->getModel();
683 vtkGObjectView* portView=desc->getView();
684 if(portmod->getPortType()==GINPUTPORT && portView->getState()==HIGHLIGHTED)
691 if(isOverPort==false)
693 _worldState=NOTHING_HAPPENS;
694 //int lastId = _controllers.size()-1;
695 GConnectorController *connector = (GConnectorController*)_controllers[_controllers.size()-1];
696 connector->removeFromScene();
697 unregisterController(connector);
698 _controllers.erase(_controllers.size()-1);
700 for(it = _controllers.begin(); it != _controllers.end(); ++it)
702 GObjectController *desc = it->second;
703 desc->SetActive(true);
704 desc->getView()->setState(NOTHING_HAPPENS);
705 desc->getModel()->notifyObservers(_idManager);
710 if(_selectedObjects.size()!=0)
712 _worldState = DRAG_OBJECTS;
713 _startDragging = true;
715 for (int i = 0; i < (int)_selectedObjects.size(); i++)
717 int id = _selectedObjects[i];
718 GObjectController* cont = _controllers[id];
719 cont->getView()->setState(DRAG);
720 cont->getModel()->notifyObservers(_idManager);
729 //=========================================================================
731 bool wxVtkSceneManager::OnLeftButtonUp()
733 if(_worldState == DRAG_OBJECTS)
735 _worldState = NOTHING_HAPPENS;
737 for (int i = 0; i < (int)_selectedObjects.size(); i++)
739 int id = _selectedObjects[i];
740 GObjectController* cont = _controllers[id];
741 cont->getView()->setState(SELECTED);
742 cont->getModel()->notifyObservers(_idManager);
748 //=========================================================================
750 bool wxVtkSceneManager::OnRightButtonUp()
752 if(_worldState==INIT_CREATION_CONTOUR)
754 _worldState=NOTHING_HAPPENS;
755 //int lastId = _controllers.size()-1;
756 GConnectorController *connector = (GConnectorController*)_controllers[_idConnectionInCreation];
757 connector->removeFromScene();
758 unregisterController(connector);
759 _controllers.erase(_idConnectionInCreation);
761 std::map<int, GObjectController*>::iterator it;
762 for(it = _controllers.begin(); it != _controllers.end(); ++it)
764 GObjectController *desc = it->second;
765 desc->SetActive(true);
766 desc->getView()->setState(NOTHING_HAPPENS);
767 desc->getModel()->notifyObservers(_idManager);
772 for (int i = 0; i < (int)_selectedObjects.size(); i++)
774 int id = _selectedObjects[i];
775 GObjectController* cont = _controllers[id];
776 cont->SetActive(true);
777 cont->getView()->setState(NOTHING_HAPPENS);
778 cont->getModel()->notifyObservers(_idManager);
781 _selectedObjects.clear();
786 //=========================================================================
788 bool wxVtkSceneManager::OnLeftDClick()
791 wxVTKRenderWindowInteractor *wxVTKiren;
792 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
793 wxVTKiren->GetEventPosition(X,Y);
795 std::map<int, GObjectController*>::iterator it;
797 bool clickOnObject = false;
799 for(it = _controllers.begin(); it != _controllers.end() && clickOnObject==false; ++it)
801 GObjectController *cont = it->second;
802 int type = cont->getGObjectType();
804 if(cont->getView()->isPointInside(X,Y))
808 for (int i=0; i< (int)_selectedObjects.size(); i++)
810 int id = _selectedObjects[i];
811 GObjectController* control = _controllers[id];
812 control->getView()->setState(NOTHING_HAPPENS);
814 _selectedObjects.clear();
816 GBlackBoxModel *bbmodel = (GBlackBoxModel*)cont->getModel();
817 _parent->editBlackBox(bbmodel);
819 clickOnObject = true;
823 if(clickOnObject==false)
825 //_parent->editDiagramParameters(this);
831 //=========================================================================
833 bool wxVtkSceneManager::OnChar()
835 char keyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
837 // KeyCode 127 : Delete Key
838 // KeyCode 8 : Backspace Key
839 if(keyCode == 8 || keyCode == 127)
841 if(_selectedObjects.size()>0)
843 for(int i=0;i<(int)_selectedObjects.size();i++)
845 int id = _selectedObjects[i];
846 std::map<int,GObjectController*>::iterator it;
847 it = _controllers.find(id);
848 if (it!=_controllers.end())
853 _selectedObjects.clear();
860 //=========================================================================
862 void wxVtkSceneManager::AddControlerToBeRemove(std::vector<int> *controllersToRemove, int id)
867 for(i=0 ; i < (int)controllersToRemove->size() ; i++ )
869 if (id == (*controllersToRemove)[i] )
877 controllersToRemove->push_back( id );
882 //=========================================================================
884 void wxVtkSceneManager::deleteObject(int id)
886 GObjectController *control = _controllers[id];
887 std::vector<int> controllersToRemove;
889 if(control->getGObjectType()==GBLACKBOX || control->getGObjectType()==GCOMPLEXINPUTPORT || control->getGObjectType()==GCOMPLEXOUTPUTPORT)
891 GBoxModel *bbmod = (GBoxModel*)control->getModel();
892 std::vector<GPortModel*> inputs = bbmod->getInputPorts();
894 bool boxConnected = false;
896 // Add box input controllers to be removed
897 for(int i = 0;i< (int)inputs.size();i++)
899 AddControlerToBeRemove( &controllersToRemove, inputs[i]->getObjectId() );
900 if(inputs[i]->isConnected())
906 std::vector<GPortModel*> outputs = bbmod->getOutputPorts();
908 // Add box output controllers to be removed
909 for(int i = 0;i<(int)outputs.size();i++)
911 AddControlerToBeRemove( &controllersToRemove, outputs[i]->getObjectId() );
912 if(outputs[i]->isConnected())
918 // Add connection controllers to be removed
919 std::map<int, GObjectController*>::iterator it;
920 for(it = _controllers.begin(); it != _controllers.end(); ++it)
922 GObjectController *cont = it->second;
923 int type = cont->getGObjectType();
926 GConnectorModel *conMod = (GConnectorModel*)cont->getModel();
927 if(conMod->getStartPort()!=NULL && conMod->getStartPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
929 AddControlerToBeRemove( &controllersToRemove, conMod->getObjectId() );
931 if(conMod->getEndPort()!=NULL && conMod->getEndPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
933 AddControlerToBeRemove( &controllersToRemove, conMod->getObjectId() );
938 // Add box controller to be removed
939 AddControlerToBeRemove( &controllersToRemove, bbmod->getObjectId() );
941 else if(control->getGObjectType()==GCONNECTOR)
943 GConnectorModel *conMod = (GConnectorModel*)control->getModel();
944 AddControlerToBeRemove( &controllersToRemove, conMod->getObjectId() );
948 std::map<int,GObjectController*>::iterator it;
950 for(int i = 0;i<(int)controllersToRemove.size();i++)
952 int key = controllersToRemove[i];
953 it = _controllers.find( key );
954 GObjectController *cont = _controllers[ key ];
957 cont->removeFromScene();
958 unregisterController((InteractorStyleMaracas*)cont);
959 _controllers.erase(it);
964 //=========================================================================
966 void wxVtkSceneManager::displayBlackBoxInfo(std::string packageName, std::string boxName)
968 _parent->displayBlackBoxInfo(packageName,boxName);
971 //=========================================================================
973 void wxVtkSceneManager::updateStatusBar(std::string textStatus)
975 _parent->updateStatusBar(textStatus);
978 //=========================================================================
980 std::string wxVtkSceneManager::getDiagramBBS()
982 bool existsExec=false;
984 std::vector<std::string> packages;
985 std::vector<int> boxes;
986 std::vector<int> connections;
987 std::vector<int> execBoxes;
989 std::map<int, GObjectController*>::iterator it;
991 for(it = _controllers.begin(); it != _controllers.end(); ++it)
993 GObjectController *desc = it->second;
994 int type = desc->getGObjectType();
998 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
1000 std::string pkg = mod->getBBTKPackage();
1001 bool existsPkg = false;
1002 for(int t = 0;t< (int)packages.size() && existsPkg == false;t++)
1004 if(packages[t]==pkg)
1011 packages.push_back(pkg);
1015 boxes.push_back(it->first);
1016 if(mod->isExecutable())
1018 execBoxes.push_back(it->first);
1022 else if(type==GCONNECTOR)
1024 connections.push_back(it->first);
1028 std::string script = "";
1029 script+="# BBTK GEditor Script\n";
1030 script+="# ----------------------\n";
1033 script+="include std\n"; // EED
1034 script+="include itkvtk\n"; // EED
1036 for(i = 0; i< (int)packages.size();i++)
1039 script+=packages[i];
1043 // script+="include std\n"; // JPR
1045 for(i = 0; i < (int)boxes.size();i++)
1049 GObjectController *control = _controllers[id];
1050 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1052 script+=model->getBBTKType();
1054 script+=model->getBBTKName();
1057 std::vector<GPortModel*> inputs = model->getInputPorts();
1058 for(int j = 0; j < (int)inputs.size();j++)
1060 GPortModel* inputPort = inputs[j];
1061 if(inputPort->isValueSet())
1064 script+=model->getBBTKName();
1066 script+=inputPort->getBBTKName();
1068 script+=inputPort->getValue();
1075 for(i = 0; i<(int)connections.size();i++)
1078 int id = connections[i];
1079 GObjectController *control = _controllers[id];
1080 GConnectorModel *model = (GConnectorModel*)control->getModel();
1082 //Start Connection info
1083 GPortModel *start = model->getStartPort();
1084 script+=start->getParentBox()->getBBTKName();
1086 script+=start->getBBTKName();
1090 //End Connection info
1091 GPortModel *end = model->getEndPort();
1092 script+=end->getParentBox()->getBBTKName();
1094 script+=end->getBBTKName();
1099 for(i = 0; i<execBoxes.size();i++)
1102 int id = execBoxes[i];
1103 GObjectController *control = _controllers[id];
1104 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1106 script+=model->getBBTKName();
1115 //=========================================================================
1117 std::string wxVtkSceneManager::saveComplexBoxBBS(std::string cbName,std::string cbAuthor,std::string cbCategory,std::string cbDescription)
1120 std::vector<std::string> packages;
1121 std::vector<int> boxes;
1122 std::vector<int> connections;
1123 std::vector<int> execBoxes;
1125 std::map<int, GObjectController*>::iterator it;
1127 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1129 GObjectController *desc = it->second;
1130 int type = desc->getGObjectType();
1134 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
1136 std::string pkg = mod->getBBTKPackage();
1137 bool existsPkg = false;
1138 for(int t = 0;t<(int)packages.size() && existsPkg == false;t++)
1140 if(packages[t]==pkg)
1147 packages.push_back(pkg);
1151 boxes.push_back(it->first);
1152 if(mod->isExecutable())
1154 execBoxes.push_back(it->first);
1157 else if(type==GCONNECTOR)
1159 connections.push_back(it->first);
1163 std::string script = "";
1165 script+="include std\n"; // EED
1166 script+="include itkvtk\n"; // EED
1168 for(i = 0; i<(int)packages.size();i++)
1171 script+=packages[i];
1175 // Definition of a complex box
1180 script+="author \" ";
1184 script+="description \" ";
1185 script+=cbDescription;
1189 for(i = 0; i<boxes.size();i++)
1193 GObjectController *control = _controllers[id];
1194 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1196 script+=model->getBBTKType();
1198 script+=model->getBBTKName();
1201 std::vector<GPortModel*> inputs = model->getInputPorts();
1202 for(int j = 0; j<(int)inputs.size();j++)
1204 GPortModel* inputPort = inputs[j];
1205 if(inputPort->isValueSet())
1208 script+=model->getBBTKName();
1210 script+=inputPort->getBBTKName();
1212 script+=inputPort->getValue();
1219 // Create connections in the script. If the connection is made with a complex port, it is created the input or output
1221 std::string complexInputs="";
1222 std::string complexOutputs="";
1224 for(i = 0; i<(int)connections.size();i++)
1226 int id = connections[i];
1227 GObjectController *control = _controllers[id];
1228 GConnectorModel *model = (GConnectorModel*)control->getModel();
1231 GPortModel *start = model->getStartPort();
1232 GBoxModel *startBox =start->getParentBox();
1234 GPortModel *end = model->getEndPort();
1235 GBoxModel *endBox =end->getParentBox();
1237 if(startBox->getGObjectType()==GCOMPLEXINPUTPORT)
1239 complexInputs+="input ";
1240 complexInputs+=startBox->getBBTKName();
1243 complexInputs+=endBox->getBBTKName();
1245 complexInputs+=end->getBBTKName();
1248 complexInputs+="\" \"";
1250 complexInputs+="\n";
1252 else if(endBox->getGObjectType()==GCOMPLEXOUTPUTPORT)
1254 complexOutputs+="output ";
1255 complexOutputs+=endBox->getBBTKName();
1257 complexOutputs+=" ";
1258 complexOutputs+=startBox->getBBTKName();
1259 complexOutputs+=".";
1260 complexOutputs+=start->getBBTKName();
1262 complexOutputs+=" ";
1263 complexOutputs+="\" \"";
1265 complexOutputs+="\n";
1270 script+=startBox->getBBTKName();
1272 script+=start->getBBTKName();
1276 //End Connection info
1277 script+=endBox->getBBTKName();
1279 script+=end->getBBTKName();
1285 for(i = 0; i<(int)execBoxes.size();i++)
1288 int id = execBoxes[i];
1289 GObjectController *control = _controllers[id];
1290 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1292 script+=model->getBBTKName();
1297 script+="# Complex input ports\n";
1298 script+=complexInputs;
1301 script+="# Complex output ports\n";
1302 script+=complexOutputs;
1311 //=========================================================================
1313 void wxVtkSceneManager::deleteAllBoxes()
1315 std::map<int, GObjectController*>::iterator it;
1316 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1318 GObjectController *cont = it->second;
1319 cont->removeFromScene();
1320 unregisterController((InteractorStyleMaracas*)cont);
1322 _selectedObjects.clear();
1323 _controllers.clear();
1327 //=========================================================================
1329 void wxVtkSceneManager::refreshScene()
1331 _baseView->RefreshView();
1334 //=========================================================================
1336 void wxVtkSceneManager::centerView()
1339 _baseView->GetRenderer()->GetActiveCamera()->GetFocalPoint(temp);
1340 _baseView->GetRenderer()->GetActiveCamera()->SetFocalPoint(0,0,temp[2]);
1341 _baseView->GetRenderer()->GetActiveCamera()->GetPosition(temp);
1342 _baseView->GetRenderer()->GetActiveCamera()->SetPosition(0,0,temp[2]);
1343 _baseView->RefreshView();
1347 //=========================================================================
1349 void wxVtkSceneManager::saveDiagram(std::string &content)
1353 //Print info IF COMPLEX BOX
1354 content+="COMPLEXBOX:";
1359 //Print info complex input ports
1360 std::vector<int> inputs = getComplexInputPorts();
1361 int insize = inputs.size();
1362 content+="COMPLEXINPUTS:";
1363 sprintf (buffer, "%d", insize);
1367 for(int i = 0;i<insize;i++)
1370 GObjectController *cont = _controllers[id];
1371 cont->getModel()->save(content);
1374 //Print info complex output ports
1375 std::vector<int> outputs = getComplexOutputPorts();
1376 int outsize = outputs.size();
1377 content+="COMPLEXOUTPUTS:";
1378 sprintf (buffer, "%d", outsize);
1382 for(int i = 0;i<outsize;i++)
1384 int id = outputs[i];
1385 GObjectController *cont = _controllers[id];
1386 cont->getModel()->save(content);
1395 std::vector<int> boxes = getBlackBoxes();
1396 int bsize = boxes.size();
1398 sprintf (buffer, "%d", bsize);
1402 for(int i = 0;i<bsize;i++)
1405 GObjectController *cont = _controllers[id];
1406 cont->getModel()->save(content);
1410 std::vector<int> connections = getConnections();
1411 int csize = connections.size();
1412 content+="CONNECTIONS:";
1413 sprintf (buffer, "%d", csize);
1417 for(int i = 0;i<csize;i++)
1419 int id = connections[i];
1420 GObjectController *cont = _controllers[id];
1421 cont->getModel()->save(content);
1426 //=========================================================================
1428 void wxVtkSceneManager::loadDiagram(ifstream &inputStream)
1431 std::string line="";
1432 char delims[] = ":";
1433 char *result = NULL;
1434 getline(inputStream,line);
1437 while ( !inputStream.eof() )
1439 if(line=="" || line[0]=='#')
1441 getline(inputStream,line);
1443 else if(line=="APP_START")
1454 getline(inputStream,line);//COMPLEX_BOX:TRUE|FALSE
1456 strcpy( complex, line.c_str() );
1457 result = strtok( complex, delims );
1458 result = strtok( NULL, delims );
1459 std::string isComplexBox(result);
1461 if(isComplexBox=="TRUE")
1465 //-----------------------
1466 //- COMPLEX INPUT PORTS
1467 //-----------------------
1468 getline(inputStream,line);//COMPLEXINPUTS:num
1470 strcpy( inputs, line.c_str() );
1471 result = strtok( inputs, delims );
1472 result = strtok( NULL, delims );
1475 std::istringstream inps(result);
1478 for(int i = 0;i<numInputs;i++)
1481 getline(inputStream,line);//COMPLEX_PORT
1482 getline(inputStream,line);//name
1483 std::string inputPortName(line);
1486 getline(inputStream,line);//xInic:yInic:zInic
1488 strcpy( coord, line.c_str() );
1489 result = strtok( coord, delims );//xInic
1490 std::string xInic(result);
1491 result = strtok( NULL, delims );//yInic
1492 std::string yInic(result);
1493 result = strtok( NULL, delims );//zInic
1494 std::string zInic(result);
1496 double xIn, yIn, zIn;
1497 std::istringstream xSt(xInic);
1499 std::istringstream ySt(yInic);
1501 std::istringstream zSt(zInic);
1504 getline(inputStream,line);//FIN_COMPLEX_PORT
1506 int idInputPort = createGComplexBoxInputPort(inputPortName);
1507 GObjectController *cont = _controllers[idInputPort];
1508 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
1509 cbmod->setInicPoint(xIn,yIn,zIn);
1510 cbmod->notifyObservers(_idManager);
1511 } // for input complex box
1514 //-----------------------
1515 //- COMPLEX OUTPUT PORTS
1516 //-----------------------
1518 getline(inputStream,line);//COMPLEXOUTPUTS:num
1520 strcpy( outputs, line.c_str() );
1521 result = strtok( outputs, delims );
1522 result = strtok( NULL, delims );
1525 std::istringstream outps(result);
1526 outps >> numOutputs;
1528 for(int i = 0;i<numOutputs;i++)
1531 getline(inputStream,line);//COMPLEX_PORT
1532 getline(inputStream,line);//name
1533 std::string outputPortName(line);
1536 getline(inputStream,line);//xInic:yInic:zInic
1538 strcpy( coord, line.c_str() );
1539 result = strtok( coord, delims );//xInic
1540 std::string xInic(result);
1541 result = strtok( NULL, delims );//yInic
1542 std::string yInic(result);
1543 result = strtok( NULL, delims );//zInic
1544 std::string zInic(result);
1546 double xIn, yIn, zIn;
1547 std::istringstream xSt(xInic);
1549 std::istringstream ySt(yInic);
1551 std::istringstream zSt(zInic);
1554 getline(inputStream,line);//FIN_COMPLEX_PORT
1557 int idOutputPort = createGComplexBoxOutputPort(outputPortName);
1558 GObjectController *cont = _controllers[idOutputPort];
1559 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
1560 cbmod->setInicPoint(xIn,yIn,zIn);
1561 cbmod->notifyObservers(_idManager);
1562 } // for output complex box
1567 getline(inputStream,line);//BOXES:num
1569 strcpy( boxes, line.c_str() );
1570 result = strtok( boxes, delims );
1571 result = strtok( NULL, delims );
1574 std::istringstream is(result);
1577 for(int i = 0;i<numBoxes;i++)
1580 getline(inputStream,line);//BOX
1581 getline(inputStream,line);//package:type:name
1583 strcpy( box, line.c_str() );
1584 result = strtok( box, delims );//package
1585 std::string package(result);
1586 result = strtok( NULL, delims );//type
1587 std::string type(result);
1588 result = strtok( NULL, delims );//name
1589 std::string name(result);
1591 getline(inputStream,line);//ISEXEC:TRUE|FALSE
1593 strcpy( exec, line.c_str() );
1594 result = strtok( exec, delims );//ISEXEC
1595 result = strtok( NULL, delims );//TRUE|FALSE
1596 std::string isExec(result);
1599 getline(inputStream,line);//xInic:yInic:zInic
1601 strcpy( coord, line.c_str() );
1602 result = strtok( coord, delims );//xInic
1603 std::string xInic(result);
1604 result = strtok( NULL, delims );//yInic
1605 std::string yInic(result);
1606 result = strtok( NULL, delims );//zInic
1607 std::string zInic(result);
1609 double xIn, yIn, zIn;
1610 std::istringstream xSt(xInic);
1612 std::istringstream ySt(yInic);
1614 std::istringstream zSt(zInic);
1618 getline(inputStream,line);//xEnd:yEnd:zEnd
1619 strcpy( coord, line.c_str() );
1620 result = strtok( coord, delims );//xEnd
1621 std::string xEnd(result);
1622 result = strtok( NULL, delims );//yEnd
1623 std::string yEnd(result);
1624 result = strtok( NULL, delims );//zEnd
1625 std::string zEnd(result);
1627 double xEn, yEn, zEn;
1628 std::istringstream xEt(xEnd);
1630 std::istringstream yEt(yEnd);
1632 std::istringstream zEt(zEnd);
1635 bool boxExecutable=false;
1638 boxExecutable= true;
1641 int idBox = createGBlackBox(xIn,yIn,package,type);
1642 configGBlackBox(idBox, xIn,yIn,zIn,name, boxExecutable,xEn,yEn,zEn);
1644 GObjectController *cont = _controllers[idBox];
1645 GBlackBoxModel *bbmod = (GBlackBoxModel*)cont->getModel();
1649 // GObjectController *cont = _controllers[idBox];
1650 // GBlackBoxModel *bbmod = (GBlackBoxModel*)cont->getModel();
1651 // bbmod->setBBTKName(name);
1652 // bbmod->setInicPoint(xIn,yIn,zIn);
1653 // bbmod->setFinalPoint(xEn,yEn,zEn);
1654 // bbmod->setExecutable(boxExecutable);
1658 getline(inputStream,line);//PORT o FIN_BOX
1659 std::string port=line.substr(0,4);
1662 getline(inputStream,line);//name:value
1664 strcpy( poort, line.c_str() );
1665 result = strtok( poort, delims );//name
1666 std::string name(result);
1667 result = strtok( NULL, delims );//value
1668 std::string value(result);
1670 bbmod->setValueToInput(name,value);
1672 getline(inputStream,line);//PORT o FIN_BOX
1673 port=line.substr(0,4);
1676 //EED bbmod->notifyObservers(_idManager);
1681 getline(inputStream,line);//CONNECTIONS:num
1683 strcpy( conns, line.c_str() );
1684 result = strtok( conns, delims );
1685 result = strtok( NULL, delims );
1688 std::istringstream isCons(result);
1691 for(int i = 0;i<numConns;i++)
1694 getline(inputStream,line);//CONNECTION
1695 getline(inputStream,line);//Startbox.PortName:EndBox.PortName
1698 strcpy( connec, line.c_str() );
1699 result = strtok( connec, delims );
1700 std::string nameStartBox(result);
1701 result = strtok( NULL, delims );
1702 std::string nameStartPort(result);
1703 result = strtok( NULL, delims );
1704 std::string nameEndBox(result);
1705 result = strtok( NULL, delims );
1706 std::string nameEndPort(result);
1708 configGConnetion(_isComplexBox, nameStartBox, nameStartPort, nameEndBox, nameEndPort);
1711 std::vector<int> lstB = getBlackBoxes();
1712 GPortModel *startP = NULL;
1713 GPortModel *endP = NULL;
1715 for(j = 0;j<lstB.size();j++)
1718 GBlackBoxModel *bbMod = (GBlackBoxModel*)_controllers[idB]->getModel();
1719 if(_controllers[idB]->getModel()->getBBTKName()==nameStartBox)
1721 startP = bbMod->getOutputPort(nameStartPort);
1723 else if(_controllers[idB]->getModel()->getBBTKName()==nameEndBox)
1725 endP = bbMod->getInputPort(nameEndPort);
1733 std::vector<int> lstInputs = getComplexInputPorts();
1734 for(j = 0;j<lstInputs.size();j++)
1736 int idB = lstInputs[j];
1737 GBoxModel *cbMod = (GBoxModel*)_controllers[idB]->getModel();
1738 if(_controllers[idB]->getModel()->getBBTKName()==nameStartBox)
1740 startP = cbMod->getOutputPort(nameStartPort);
1747 std::vector<int> lstOutputs = getComplexOutputPorts();
1748 for(j = 0;j<lstOutputs.size();j++)
1750 int idB = lstOutputs[j];
1751 GBoxModel *cbMod = (GBoxModel*)_controllers[idB]->getModel();
1752 if(_controllers[idB]->getModel()->getBBTKName()==nameEndBox)
1754 endP = cbMod->getInputPort(nameEndPort);
1760 int idCon = createGConnector(startP);
1761 _worldState = NOTHING_HAPPENS;
1762 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
1764 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
1765 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
1766 tempp->endContourCreation();
1767 conMod->setEndPort(endP);
1768 conView->updateStartEndPoints();
1776 //=========================================================================
1778 GBlackBoxModel* wxVtkSceneManager::findGBox(std::string boxname)
1780 GBlackBoxModel *boxModel = NULL;
1781 GBlackBoxModel *bbMod;
1782 std::vector<int> lstB = getBlackBoxes();
1785 for(j = 0;j<(int)lstB.size();j++)
1788 bbMod = (GBlackBoxModel*)_controllers[idB]->getModel();
1789 if(_controllers[idB]->getModel()->getBBTKName()==boxname)
1797 //=========================================================================
1800 void wxVtkSceneManager::configGConnetion(bool _isComplexBox,
1801 std::string nameStartBox, std::string nameStartPort, std::string
1802 nameEndBox, std::string nameEndPort)
1804 GPortModel *startP = findGBox(nameStartBox)->getOutputPort(nameStartPort);
1805 GPortModel *endP = findGBox(nameEndBox)->getInputPort(nameEndPort);
1808 std::vector<int> lstB = getBlackBoxes();
1810 for(j = 0;j<(int)lstB.size();j++)
1813 GBlackBoxModel *bbMod = (GBlackBoxModel*)_controllers[idB]->getModel();
1814 if(_controllers[idB]->getModel()->getBBTKName()==nameStartBox)
1816 startP = bbMod->getOutputPort(nameStartPort);
1818 else if(_controllers[idB]->getModel()->getBBTKName()==nameEndBox)
1820 endP = bbMod->getInputPort(nameEndPort);
1829 std::vector<int> lstInputs = getComplexInputPorts();
1830 for(j = 0;j<(int)lstInputs.size();j++)
1832 int idB = lstInputs[j];
1833 GBoxModel *cbMod = (GBoxModel*)_controllers[idB]->getModel();
1834 if(_controllers[idB]->getModel()->getBBTKName()==nameStartBox)
1836 startP = cbMod->getOutputPort(nameStartPort);
1843 std::vector<int> lstOutputs = getComplexOutputPorts();
1844 for(j = 0;j<(int)lstOutputs.size();j++)
1846 int idB = lstOutputs[j];
1847 GBoxModel *cbMod = (GBoxModel*)_controllers[idB]->getModel();
1848 if(_controllers[idB]->getModel()->getBBTKName()==nameEndBox)
1850 endP = cbMod->getInputPort(nameEndPort);
1856 int idCon = createGConnector(startP);
1857 _worldState = NOTHING_HAPPENS;
1858 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
1860 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
1861 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
1862 tempp->endContourCreation();
1863 conMod->setEndPort(endP);
1864 conView->updateStartEndPoints();
1867 //=========================================================================
1869 bool wxVtkSceneManager::boxExist(std::string boxname)
1872 std::map<int, GObjectController*>::iterator it;
1873 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1875 GObjectController *cont = it->second;
1876 if(cont->getModel()->getBBTKName()==boxname)
1884 //=========================================================================
1886 std::vector<int> wxVtkSceneManager::getBlackBoxes()
1888 std::vector<int> vect;
1889 std::map<int, GObjectController*>::iterator it;
1890 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1892 GObjectController *cont = it->second;
1893 if(cont->getGObjectType()==GBLACKBOX)
1895 vect.push_back(cont->getId());
1901 //=========================================================================
1903 std::vector<int> wxVtkSceneManager::getComplexInputPorts()
1905 std::vector<int> vect;
1906 std::map<int, GObjectController*>::iterator it;
1907 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1909 GObjectController *cont = it->second;
1910 if(cont->getGObjectType()==GCOMPLEXINPUTPORT)
1912 vect.push_back(cont->getId());
1918 //=========================================================================
1920 std::vector<int> wxVtkSceneManager::getComplexOutputPorts()
1922 std::vector<int> vect;
1923 std::map<int, GObjectController*>::iterator it;
1924 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1926 GObjectController *cont = it->second;
1927 if(cont->getGObjectType()==GCOMPLEXOUTPUTPORT)
1929 vect.push_back(cont->getId());
1935 //=========================================================================
1937 std::vector<int> wxVtkSceneManager::getConnections()
1939 std::vector<int> vect;
1940 std::map<int, GObjectController*>::iterator it;
1941 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1943 GObjectController *cont = it->second;
1944 if(cont->getGObjectType()==GCONNECTOR)
1946 vect.push_back(cont->getId());
1952 //=========================================================================
1954 bool wxVtkSceneManager::isComplexBox()
1956 return _isComplexBox;
1959 //=========================================================================
1961 void wxVtkSceneManager::setComplexBox(bool val)
1966 //=========================================================================
1968 int wxVtkSceneManager::addObjectController(GObjectController* objController)
1970 //Register the controller of the new object
1971 registerController((InteractorStyleMaracas*) objController);
1973 //Add the object to the objects list
1974 int newId = _contLastId;//_controllers.size();
1975 objController->setId(newId);
1976 _controllers[newId] = objController;
1981 //=========================================================================
1983 int wxVtkSceneManager::getNumSelectedObjects()
1985 return _selectedObjects.size();
1988 //=========================================================================
1990 std::map<int,GObjectController*> wxVtkSceneManager::getSelectedObjects()
1992 std::map<int,GObjectController*> mapSelected;
1994 std::map<int, GObjectController*>::iterator it;
1995 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1997 GObjectController *cont = it->second;
1998 if(cont->getGObjectType()==GBLACKBOX && cont->getView()->getState()==SELECTED)
2000 mapSelected[cont->getId()]=cont;
2004 std::map<int, GObjectController*>::iterator it2;
2005 for(it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
2007 GObjectController *cont = it2->second;
2008 if(cont->getGObjectType()==GCONNECTOR)
2010 GConnectorModel* cmod = (GConnectorModel*)cont->getModel();
2011 GBoxModel* endPortParentBox = cmod->getEndPort()->getParentBox();
2012 GBoxModel* startPortParentBox = cmod->getStartPort()->getParentBox();
2014 std::map<int, GObjectController*>::iterator iterOBJ1 = mapSelected.find(startPortParentBox->getObjectId());
2015 std::map<int, GObjectController*>::iterator iterOBJ2 = mapSelected.find(endPortParentBox->getObjectId());
2017 if(iterOBJ1 != mapSelected.end() && iterOBJ2 != mapSelected.end())
2019 int ID = cont->getId();
2020 mapSelected[ID]=cont;
2028 //=========================================================================
2030 void wxVtkSceneManager::addObjects(std::map<int,GObjectController*> objectsMap)
2033 std::map<int,int> oldIdNewIdBoxes;
2034 std::vector<int> connections;
2036 std::map<int, GObjectController*>::iterator it;
2037 for(it = objectsMap.begin(); it != objectsMap.end(); ++it)
2039 GObjectController *cont = it->second;
2040 int type = cont->getGObjectType();
2045 double xInic, yInic,zInic;
2046 GBlackBoxModel* copyBox = (GBlackBoxModel*)cont->getModel();
2047 copyBox->getInicPoint(xInic,yInic,zInic);
2048 int idBox = createGBlackBox(0,0,copyBox->getBBTKPackage(),copyBox->getBBTKType());
2050 int idcB = copyBox->getObjectId();
2051 oldIdNewIdBoxes[idcB]=idBox;
2052 cont = _controllers[idBox];
2053 GBlackBoxModel* newbox = (GBlackBoxModel*)cont->getModel();
2054 newbox->setInicPoint(xInic,yInic,zInic);
2055 int num = newbox->getNumInputPorts();
2056 for(int j=0;j<num;j++)
2058 newbox->setValueToInputPort(j,copyBox->getValueInputPort(j));
2060 newbox->notifyObservers(_idManager);
2062 else if(type==GCONNECTOR)
2064 int idCon = cont->getId();
2065 connections.push_back(idCon);
2070 for(int i = 0 ;i<connections.size();i++)
2072 int objId = connections[i];
2073 GObjectController *cont = objectsMap[objId];
2074 GConnectorModel* connectModel = (GConnectorModel*)cont->getModel();
2076 GPortModel* startPort = connectModel->getStartPort();
2077 int startPortIndex = startPort->getPosInBox();
2078 GPortModel* endPort = connectModel->getEndPort();
2079 int endPortIndex = endPort->getPosInBox();
2081 GBlackBoxModel* startPortParentBox = (GBlackBoxModel*)startPort->getParentBox();
2082 GBlackBoxModel* endPortParentBox = (GBlackBoxModel*)endPort->getParentBox();
2084 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2085 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2087 GBlackBoxModel* newStartBox = (GBlackBoxModel*)_controllers[idNewStartBox]->getModel();
2088 GBlackBoxModel* newEndBox = (GBlackBoxModel*)_controllers[idNewEndBox]->getModel();
2090 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2091 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2093 // Creates connection
2094 int idCon = createGConnector(newStartPort);
2095 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
2096 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
2097 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
2098 tempp->endContourCreation();
2099 conMod->setEndPort(newEndPort);
2100 conView->updateStartEndPoints();
2103 std::map<int, int>::iterator itIds;
2104 for(itIds = oldIdNewIdBoxes.begin(); itIds != oldIdNewIdBoxes.end(); ++itIds)
2106 int idOld = itIds->first;
2107 int idNew = itIds->second;
2109 GBlackBoxModel* oldBox = (GBlackBoxModel*)objectsMap[idOld]->getModel();
2110 GBlackBoxModel* newBox = (GBlackBoxModel*)_controllers[idNew]->getModel();
2112 std::vector<int> oldInputConnections = oldBox->getConnectedInputs();
2113 std::vector<int> oldOutputConnections = oldBox->getConnectedOutputs();
2114 std::vector<int> newInputConnections = newBox->getConnectedInputs();
2115 std::vector<int> newOutputConnections = newBox->getConnectedOutputs();
2117 for(int k = 0; k<(int)oldInputConnections.size();k++)
2120 //EED int toCreate=-1;
2121 for(int l = 0; l<(int)newInputConnections.size() && !exist;l++)
2123 if(oldInputConnections[k]==newInputConnections[l])
2131 //Create complex input
2132 int posInBox = oldInputConnections[k];
2133 GPortModel* inputPort = oldBox->getInputPort(posInBox);
2134 std::string inputPortName = inputPort->getBBTKName();
2135 int idInputPort = createGComplexBoxInputPort(inputPortName);
2136 GObjectController *cont = _controllers[idInputPort];
2137 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
2139 inputPort->getInicPoint(xIn,yIn,zIn);
2141 cbmod->setInicPoint(xIn,yIn,zIn);
2142 cbmod->notifyObservers(_idManager);
2144 GPortModel* inputPortEnd = newBox->getInputPort(posInBox);
2146 // Creates connection
2147 int idCon = createGConnector(cbmod->getOutputPort(0));
2148 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
2149 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
2150 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
2151 tempp->endContourCreation();
2152 conMod->setEndPort(inputPortEnd);
2153 conView->updateStartEndPoints();
2160 for(int k = 0; k<(int)oldOutputConnections.size();k++)
2163 //EED int toCreate=-1;
2164 for(int l = 0; l<(int)newOutputConnections.size() && !exist;l++)
2166 if(oldOutputConnections[k]==newOutputConnections[l])
2174 //Create complex output
2175 int posInBox = oldOutputConnections[k];
2176 GPortModel* outputPort = oldBox->getOutputPort(posInBox);
2177 std::string outputPortName = outputPort->getBBTKName();
2178 int idOutputPort = createGComplexBoxOutputPort(outputPortName);
2179 GObjectController *cont = _controllers[idOutputPort];
2180 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
2182 outputPort->getInicPoint(xIn,yIn,zIn);
2184 cbmod->setInicPoint(xIn,yIn,zIn);
2185 cbmod->notifyObservers(_idManager);
2187 GPortModel* outputPortEnd = newBox->getOutputPort(posInBox);
2189 // Creates connection
2190 int idCon = createGConnector(outputPortEnd);
2191 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
2192 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
2193 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
2194 tempp->endContourCreation();
2195 conMod->setEndPort(cbmod->getInputPort(0));
2196 conView->updateStartEndPoints();
2207 //=========================================================================
2209 } // EO namespace bbtk