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";
1034 script+="include std\n"; // EED
1035 script+="include itkvtk\n"; // EED
1037 for(i = 0; i< (int)packages.size();i++)
1040 script+=packages[i];
1045 // script+="include std\n"; // JPR
1047 for(i = 0; i < (int)boxes.size();i++)
1051 GObjectController *control = _controllers[id];
1052 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1054 script+=model->getBBTKType();
1056 script+=model->getBBTKName();
1059 std::vector<GPortModel*> inputs = model->getInputPorts();
1060 for(int j = 0; j < (int)inputs.size();j++)
1062 GPortModel* inputPort = inputs[j];
1063 if(inputPort->isValueSet())
1066 script+=model->getBBTKName();
1068 script+=inputPort->getBBTKName();
1070 script+=inputPort->getValue();
1080 for(i = 0; i<(int)connections.size();i++)
1083 int id = connections[i];
1084 GObjectController *control = _controllers[id];
1085 GConnectorModel *model = (GConnectorModel*)control->getModel();
1087 //Start Connection info
1088 GPortModel *start = model->getStartPort();
1089 script+=start->getParentBox()->getBBTKName();
1091 script+=start->getBBTKName();
1095 //End Connection info
1096 GPortModel *end = model->getEndPort();
1097 script+=end->getParentBox()->getBBTKName();
1099 script+=end->getBBTKName();
1105 for(i = 0; i<(int)execBoxes.size();i++)
1108 int id = execBoxes[i];
1109 GObjectController *control = _controllers[id];
1110 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1112 script+=model->getBBTKName();
1121 //=========================================================================
1123 std::string wxVtkSceneManager::saveComplexBoxBBS(std::string cbName,std::string cbAuthor,std::string cbCategory,std::string cbDescription)
1126 std::vector<std::string> packages;
1127 std::vector<int> boxes;
1128 std::vector<int> connections;
1129 std::vector<int> execBoxes;
1131 std::map<int, GObjectController*>::iterator it;
1133 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1135 GObjectController *desc = it->second;
1136 int type = desc->getGObjectType();
1140 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
1142 std::string pkg = mod->getBBTKPackage();
1143 bool existsPkg = false;
1144 for(int t = 0;t<(int)packages.size() && existsPkg == false;t++)
1146 if(packages[t]==pkg)
1153 packages.push_back(pkg);
1157 boxes.push_back(it->first);
1158 if(mod->isExecutable())
1160 execBoxes.push_back(it->first);
1163 else if(type==GCONNECTOR)
1165 connections.push_back(it->first);
1169 std::string script = "";
1171 script+="include std\n"; // EED
1172 script+="include itkvtk\n"; // EED
1174 for(i = 0; i<(int)packages.size();i++)
1177 script+=packages[i];
1182 // Definition of a complex box
1188 script+="author \" ";
1192 script+="description \" ";
1193 script+=cbDescription;
1198 for(i = 0; i<(int)boxes.size();i++)
1202 GObjectController *control = _controllers[id];
1203 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1205 script+=model->getBBTKType();
1207 script+=model->getBBTKName();
1210 std::vector<GPortModel*> inputs = model->getInputPorts();
1211 for(int j = 0; j<(int)inputs.size();j++)
1213 GPortModel* inputPort = inputs[j];
1214 if(inputPort->isValueSet())
1217 script+=model->getBBTKName();
1219 script+=inputPort->getBBTKName();
1221 script+=inputPort->getValue();
1229 // Create connections in the script. If the connection is made with a complex port, it is created the input or output
1231 std::string complexInputs="";
1232 std::string complexOutputs="";
1235 for(i = 0; i<(int)connections.size();i++)
1237 int id = connections[i];
1238 GObjectController *control = _controllers[id];
1239 GConnectorModel *model = (GConnectorModel*)control->getModel();
1242 GPortModel *start = model->getStartPort();
1243 GBoxModel *startBox =start->getParentBox();
1245 GPortModel *end = model->getEndPort();
1246 GBoxModel *endBox =end->getParentBox();
1248 if(startBox->getGObjectType()==GCOMPLEXINPUTPORT)
1250 complexInputs+="input ";
1251 complexInputs+=startBox->getBBTKName();
1254 complexInputs+=endBox->getBBTKName();
1256 complexInputs+=end->getBBTKName();
1259 complexInputs+="\" \"";
1261 complexInputs+="\n";
1263 else if(endBox->getGObjectType()==GCOMPLEXOUTPUTPORT)
1265 complexOutputs+="output ";
1266 complexOutputs+=endBox->getBBTKName();
1268 complexOutputs+=" ";
1269 complexOutputs+=startBox->getBBTKName();
1270 complexOutputs+=".";
1271 complexOutputs+=start->getBBTKName();
1273 complexOutputs+=" ";
1274 complexOutputs+="\" \"";
1276 complexOutputs+="\n";
1281 script+=startBox->getBBTKName();
1283 script+=start->getBBTKName();
1287 //End Connection info
1288 script+=endBox->getBBTKName();
1290 script+=end->getBBTKName();
1298 for(i = 0; i<(int)execBoxes.size();i++)
1301 int id = execBoxes[i];
1302 GObjectController *control = _controllers[id];
1303 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1305 script+=model->getBBTKName();
1310 script+="# Complex input ports\n";
1311 script+=complexInputs;
1314 script+="# Complex output ports\n";
1315 script+=complexOutputs;
1324 //=========================================================================
1326 void wxVtkSceneManager::deleteAllBoxes()
1328 std::map<int, GObjectController*>::iterator it;
1329 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1331 GObjectController *cont = it->second;
1332 cont->removeFromScene();
1333 unregisterController((InteractorStyleMaracas*)cont);
1335 _selectedObjects.clear();
1336 _controllers.clear();
1340 //=========================================================================
1342 void wxVtkSceneManager::refreshScene()
1344 _baseView->RefreshView();
1347 //=========================================================================
1349 void wxVtkSceneManager::centerView()
1352 _baseView->GetRenderer()->GetActiveCamera()->GetFocalPoint(temp);
1353 _baseView->GetRenderer()->GetActiveCamera()->SetFocalPoint(0,0,temp[2]);
1354 _baseView->GetRenderer()->GetActiveCamera()->GetPosition(temp);
1355 _baseView->GetRenderer()->GetActiveCamera()->SetPosition(0,0,temp[2]);
1356 _baseView->RefreshView();
1360 //=========================================================================
1362 void wxVtkSceneManager::saveDiagram(std::string &content)
1366 //Print info IF COMPLEX BOX
1367 content+="COMPLEXBOX:";
1372 //Print info complex input ports
1373 std::vector<int> inputs = getComplexInputPorts();
1374 int insize = inputs.size();
1375 content+="COMPLEXINPUTS:";
1376 sprintf (buffer, "%d", insize);
1380 for(int i = 0;i<insize;i++)
1383 GObjectController *cont = _controllers[id];
1384 cont->getModel()->save(content);
1387 //Print info complex output ports
1388 std::vector<int> outputs = getComplexOutputPorts();
1389 int outsize = outputs.size();
1390 content+="COMPLEXOUTPUTS:";
1391 sprintf (buffer, "%d", outsize);
1395 for(int i = 0;i<outsize;i++)
1397 int id = outputs[i];
1398 GObjectController *cont = _controllers[id];
1399 cont->getModel()->save(content);
1408 std::vector<int> boxes = getBlackBoxes();
1409 int bsize = boxes.size();
1411 sprintf (buffer, "%d", bsize);
1415 for(int i = 0;i<bsize;i++)
1418 GObjectController *cont = _controllers[id];
1419 cont->getModel()->save(content);
1423 std::vector<int> connections = getConnections();
1424 int csize = connections.size();
1425 content+="CONNECTIONS:";
1426 sprintf (buffer, "%d", csize);
1430 for(int i = 0;i<csize;i++)
1432 int id = connections[i];
1433 GObjectController *cont = _controllers[id];
1434 cont->getModel()->save(content);
1439 //=========================================================================
1441 void wxVtkSceneManager::loadDiagram(ifstream &inputStream)
1444 std::string line="";
1445 char delims[] = ":";
1446 char *result = NULL;
1447 getline(inputStream,line);
1450 while ( !inputStream.eof() )
1452 if(line=="" || line[0]=='#')
1454 getline(inputStream,line);
1456 else if(line=="APP_START")
1467 getline(inputStream,line);//COMPLEX_BOX:TRUE|FALSE
1469 strcpy( complex, line.c_str() );
1470 result = strtok( complex, delims );
1471 result = strtok( NULL, delims );
1472 std::string isComplexBox(result);
1474 if(isComplexBox=="TRUE")
1478 //-----------------------
1479 //- COMPLEX INPUT PORTS
1480 //-----------------------
1481 getline(inputStream,line);//COMPLEXINPUTS:num
1483 strcpy( inputs, line.c_str() );
1484 result = strtok( inputs, delims );
1485 result = strtok( NULL, delims );
1488 std::istringstream inps(result);
1491 for(int i = 0;i<numInputs;i++)
1494 getline(inputStream,line);//COMPLEX_PORT
1495 getline(inputStream,line);//name
1496 std::string inputPortName(line);
1499 getline(inputStream,line);//xInic:yInic:zInic
1501 strcpy( coord, line.c_str() );
1502 result = strtok( coord, delims );//xInic
1503 std::string xInic(result);
1504 result = strtok( NULL, delims );//yInic
1505 std::string yInic(result);
1506 result = strtok( NULL, delims );//zInic
1507 std::string zInic(result);
1509 double xIn, yIn, zIn;
1510 std::istringstream xSt(xInic);
1512 std::istringstream ySt(yInic);
1514 std::istringstream zSt(zInic);
1517 getline(inputStream,line);//FIN_COMPLEX_PORT
1519 int idInputPort = createGComplexBoxInputPort(inputPortName);
1520 GObjectController *cont = _controllers[idInputPort];
1521 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
1522 cbmod->setInicPoint(xIn,yIn,zIn);
1523 cbmod->notifyObservers(_idManager);
1524 } // for input complex box
1527 //-----------------------
1528 //- COMPLEX OUTPUT PORTS
1529 //-----------------------
1531 getline(inputStream,line);//COMPLEXOUTPUTS:num
1533 strcpy( outputs, line.c_str() );
1534 result = strtok( outputs, delims );
1535 result = strtok( NULL, delims );
1538 std::istringstream outps(result);
1539 outps >> numOutputs;
1541 for(int i = 0;i<numOutputs;i++)
1544 getline(inputStream,line);//COMPLEX_PORT
1545 getline(inputStream,line);//name
1546 std::string outputPortName(line);
1549 getline(inputStream,line);//xInic:yInic:zInic
1551 strcpy( coord, line.c_str() );
1552 result = strtok( coord, delims );//xInic
1553 std::string xInic(result);
1554 result = strtok( NULL, delims );//yInic
1555 std::string yInic(result);
1556 result = strtok( NULL, delims );//zInic
1557 std::string zInic(result);
1559 double xIn, yIn, zIn;
1560 std::istringstream xSt(xInic);
1562 std::istringstream ySt(yInic);
1564 std::istringstream zSt(zInic);
1567 getline(inputStream,line);//FIN_COMPLEX_PORT
1570 int idOutputPort = createGComplexBoxOutputPort(outputPortName);
1571 GObjectController *cont = _controllers[idOutputPort];
1572 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
1573 cbmod->setInicPoint(xIn,yIn,zIn);
1574 cbmod->notifyObservers(_idManager);
1575 } // for output complex box
1580 getline(inputStream,line);//BOXES:num
1582 strcpy( boxes, line.c_str() );
1583 result = strtok( boxes, delims );
1584 result = strtok( NULL, delims );
1587 std::istringstream is(result);
1590 for(int i = 0;i<numBoxes;i++)
1593 getline(inputStream,line);//BOX
1594 getline(inputStream,line);//package:type:name
1596 strcpy( box, line.c_str() );
1597 result = strtok( box, delims );//package
1598 std::string package(result);
1599 result = strtok( NULL, delims );//type
1600 std::string type(result);
1601 result = strtok( NULL, delims );//name
1602 std::string name(result);
1604 getline(inputStream,line);//ISEXEC:TRUE|FALSE
1606 strcpy( exec, line.c_str() );
1607 result = strtok( exec, delims );//ISEXEC
1608 result = strtok( NULL, delims );//TRUE|FALSE
1609 std::string isExec(result);
1612 getline(inputStream,line);//xInic:yInic:zInic
1614 strcpy( coord, line.c_str() );
1615 result = strtok( coord, delims );//xInic
1616 std::string xInic(result);
1617 result = strtok( NULL, delims );//yInic
1618 std::string yInic(result);
1619 result = strtok( NULL, delims );//zInic
1620 std::string zInic(result);
1622 double xIn, yIn, zIn;
1623 std::istringstream xSt(xInic);
1625 std::istringstream ySt(yInic);
1627 std::istringstream zSt(zInic);
1631 getline(inputStream,line);//xEnd:yEnd:zEnd
1632 strcpy( coord, line.c_str() );
1633 result = strtok( coord, delims );//xEnd
1634 std::string xEnd(result);
1635 result = strtok( NULL, delims );//yEnd
1636 std::string yEnd(result);
1637 result = strtok( NULL, delims );//zEnd
1638 std::string zEnd(result);
1640 double xEn, yEn, zEn;
1641 std::istringstream xEt(xEnd);
1643 std::istringstream yEt(yEnd);
1645 std::istringstream zEt(zEnd);
1648 bool boxExecutable=false;
1651 boxExecutable= true;
1654 int idBox = createGBlackBox(xIn,yIn,package,type);
1655 configGBlackBox(idBox, xIn,yIn,zIn,name, boxExecutable,xEn,yEn,zEn);
1657 GObjectController *cont = _controllers[idBox];
1658 GBlackBoxModel *bbmod = (GBlackBoxModel*)cont->getModel();
1662 // GObjectController *cont = _controllers[idBox];
1663 // GBlackBoxModel *bbmod = (GBlackBoxModel*)cont->getModel();
1664 // bbmod->setBBTKName(name);
1665 // bbmod->setInicPoint(xIn,yIn,zIn);
1666 // bbmod->setFinalPoint(xEn,yEn,zEn);
1667 // bbmod->setExecutable(boxExecutable);
1671 getline(inputStream,line);//PORT o FIN_BOX
1672 std::string port=line.substr(0,4);
1675 getline(inputStream,line);//name:value
1677 strcpy( poort, line.c_str() );
1678 result = strtok( poort, delims );//name
1679 std::string name(result);
1680 result = strtok( NULL, delims );//value
1681 std::string value(result);
1683 bbmod->setValueToInput(name,value);
1685 getline(inputStream,line);//PORT o FIN_BOX
1686 port=line.substr(0,4);
1689 //EED bbmod->notifyObservers(_idManager);
1694 getline(inputStream,line);//CONNECTIONS:num
1696 strcpy( conns, line.c_str() );
1697 result = strtok( conns, delims );
1698 result = strtok( NULL, delims );
1701 std::istringstream isCons(result);
1704 for(int i = 0;i<numConns;i++)
1707 getline(inputStream,line);//CONNECTION
1708 getline(inputStream,line);//Startbox.PortName:EndBox.PortName
1711 strcpy( connec, line.c_str() );
1712 result = strtok( connec, delims );
1713 std::string nameStartBox(result);
1714 result = strtok( NULL, delims );
1715 std::string nameStartPort(result);
1716 result = strtok( NULL, delims );
1717 std::string nameEndBox(result);
1718 result = strtok( NULL, delims );
1719 std::string nameEndPort(result);
1721 configGConnetion(nameStartBox, nameStartPort, nameEndBox, nameEndPort);
1724 std::vector<int> lstB = getBlackBoxes();
1725 GPortModel *startP = NULL;
1726 GPortModel *endP = NULL;
1728 for(j = 0;j<lstB.size();j++)
1731 GBlackBoxModel *bbMod = (GBlackBoxModel*)_controllers[idB]->getModel();
1732 if(_controllers[idB]->getModel()->getBBTKName()==nameStartBox)
1734 startP = bbMod->getOutputPort(nameStartPort);
1736 else if(_controllers[idB]->getModel()->getBBTKName()==nameEndBox)
1738 endP = bbMod->getInputPort(nameEndPort);
1746 std::vector<int> lstInputs = getComplexInputPorts();
1747 for(j = 0;j<lstInputs.size();j++)
1749 int idB = lstInputs[j];
1750 GBoxModel *cbMod = (GBoxModel*)_controllers[idB]->getModel();
1751 if(_controllers[idB]->getModel()->getBBTKName()==nameStartBox)
1753 startP = cbMod->getOutputPort(nameStartPort);
1760 std::vector<int> lstOutputs = getComplexOutputPorts();
1761 for(j = 0;j<lstOutputs.size();j++)
1763 int idB = lstOutputs[j];
1764 GBoxModel *cbMod = (GBoxModel*)_controllers[idB]->getModel();
1765 if(_controllers[idB]->getModel()->getBBTKName()==nameEndBox)
1767 endP = cbMod->getInputPort(nameEndPort);
1773 int idCon = createGConnector(startP);
1774 _worldState = NOTHING_HAPPENS;
1775 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
1777 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
1778 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
1779 tempp->endContourCreation();
1780 conMod->setEndPort(endP);
1781 conView->updateStartEndPoints();
1789 //=========================================================================
1791 GBoxModel* wxVtkSceneManager::findGBox(std::string boxname)
1796 GBoxModel *boxModel = NULL;
1797 std::vector<int> lstB = getBlackBoxes();
1798 for(j = 0;j<(int)lstB.size();j++)
1801 bMod = (GBoxModel*)_controllers[idB]->getModel();
1802 if(_controllers[idB]->getModel()->getBBTKName()==boxname)
1808 if((_isComplexBox) && (boxModel==NULL))
1810 std::vector<int> lstInputs = getComplexInputPorts();
1811 for(j = 0;j<(int)lstInputs.size();j++)
1814 bMod = (GBoxModel*)_controllers[idB]->getModel();
1815 if(_controllers[idB]->getModel()->getBBTKName()==boxname)
1821 std::vector<int> lstOutputs = getComplexOutputPorts();
1822 for(j = 0;j<(int)lstOutputs.size();j++)
1824 int idB = lstOutputs[j];
1825 bMod = (GBoxModel*)_controllers[idB]->getModel();
1826 if(_controllers[idB]->getModel()->getBBTKName()==boxname)
1837 //=========================================================================
1840 void wxVtkSceneManager::configGConnetion(std::string nameStartBox, std::string nameStartPort, std::string
1841 nameEndBox, std::string nameEndPort)
1843 printf("EED wxVtkSceneManager::configGConnetion 1 %s %s %s %s\n", nameStartBox.c_str(), nameStartPort.c_str(), nameEndBox.c_str(), nameEndPort.c_str() );
1845 GBoxModel *boxModel;
1846 GPortModel *startP = NULL;
1847 GPortModel *endP = NULL;
1849 boxModel= findGBox(nameStartBox);
1852 startP = boxModel->getOutputPort(nameStartPort);
1855 boxModel= findGBox(nameEndBox);
1858 endP = boxModel->getInputPort(nameEndPort);
1862 printf("EED wxVtkSceneManager::configGConnetion 2 %p %p \n", startP, endP );
1865 std::vector<int> lstB = getBlackBoxes();
1867 for(j = 0;j<(int)lstB.size();j++)
1870 GBlackBoxModel *bbMod = (GBlackBoxModel*)_controllers[idB]->getModel();
1871 if(_controllers[idB]->getModel()->getBBTKName()==nameStartBox)
1873 startP = bbMod->getOutputPort(nameStartPort);
1875 else if(_controllers[idB]->getModel()->getBBTKName()==nameEndBox)
1877 endP = bbMod->getInputPort(nameEndPort);
1885 std::vector<int> lstInputs = getComplexInputPorts();
1886 for(j = 0;j<(int)lstInputs.size();j++)
1888 int idB = lstInputs[j];
1889 GBoxModel *cbMod = (GBoxModel*)_controllers[idB]->getModel();
1890 if(_controllers[idB]->getModel()->getBBTKName()==nameStartBox)
1892 startP = cbMod->getOutputPort(nameStartPort);
1899 std::vector<int> lstOutputs = getComplexOutputPorts();
1900 for(j = 0;j<(int)lstOutputs.size();j++)
1902 int idB = lstOutputs[j];
1903 GBoxModel *cbMod = (GBoxModel*)_controllers[idB]->getModel();
1904 if(_controllers[idB]->getModel()->getBBTKName()==nameEndBox)
1906 endP = cbMod->getInputPort(nameEndPort);
1913 int idCon = createGConnector(startP);
1914 _worldState = NOTHING_HAPPENS;
1915 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
1917 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
1918 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
1919 tempp->endContourCreation();
1920 conMod->setEndPort(endP);
1921 conView->updateStartEndPoints();
1924 //=========================================================================
1926 bool wxVtkSceneManager::boxExist(std::string boxname)
1929 std::map<int, GObjectController*>::iterator it;
1930 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1932 GObjectController *cont = it->second;
1933 if(cont->getModel()->getBBTKName()==boxname)
1941 //=========================================================================
1943 std::vector<int> wxVtkSceneManager::getBlackBoxes()
1945 std::vector<int> vect;
1946 std::map<int, GObjectController*>::iterator it;
1947 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1949 GObjectController *cont = it->second;
1950 if(cont->getGObjectType()==GBLACKBOX)
1952 vect.push_back(cont->getId());
1958 //=========================================================================
1960 std::vector<int> wxVtkSceneManager::getComplexInputPorts()
1962 std::vector<int> vect;
1963 std::map<int, GObjectController*>::iterator it;
1964 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1966 GObjectController *cont = it->second;
1967 if(cont->getGObjectType()==GCOMPLEXINPUTPORT)
1969 vect.push_back(cont->getId());
1975 //=========================================================================
1977 std::vector<int> wxVtkSceneManager::getComplexOutputPorts()
1979 std::vector<int> vect;
1980 std::map<int, GObjectController*>::iterator it;
1981 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1983 GObjectController *cont = it->second;
1984 if(cont->getGObjectType()==GCOMPLEXOUTPUTPORT)
1986 vect.push_back(cont->getId());
1992 //=========================================================================
1994 std::vector<int> wxVtkSceneManager::getConnections()
1996 std::vector<int> vect;
1997 std::map<int, GObjectController*>::iterator it;
1998 for(it = _controllers.begin(); it != _controllers.end(); ++it)
2000 GObjectController *cont = it->second;
2001 if(cont->getGObjectType()==GCONNECTOR)
2003 vect.push_back(cont->getId());
2009 //=========================================================================
2011 bool wxVtkSceneManager::isComplexBox()
2013 return _isComplexBox;
2016 //=========================================================================
2018 void wxVtkSceneManager::setComplexBox(bool val)
2023 //=========================================================================
2025 int wxVtkSceneManager::addObjectController(GObjectController* objController)
2027 //Register the controller of the new object
2028 registerController((InteractorStyleMaracas*) objController);
2030 //Add the object to the objects list
2031 int newId = _contLastId;//_controllers.size();
2032 objController->setId(newId);
2033 _controllers[newId] = objController;
2038 //=========================================================================
2040 int wxVtkSceneManager::getNumSelectedObjects()
2042 return _selectedObjects.size();
2045 //=========================================================================
2047 std::map<int,GObjectController*> wxVtkSceneManager::getSelectedObjects()
2049 std::map<int,GObjectController*> mapSelected;
2051 std::map<int, GObjectController*>::iterator it;
2052 for(it = _controllers.begin(); it != _controllers.end(); ++it)
2054 GObjectController *cont = it->second;
2055 if(cont->getGObjectType()==GBLACKBOX && cont->getView()->getState()==SELECTED)
2057 mapSelected[cont->getId()]=cont;
2061 std::map<int, GObjectController*>::iterator it2;
2062 for(it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
2064 GObjectController *cont = it2->second;
2065 if(cont->getGObjectType()==GCONNECTOR)
2067 GConnectorModel* cmod = (GConnectorModel*)cont->getModel();
2068 GBoxModel* endPortParentBox = cmod->getEndPort()->getParentBox();
2069 GBoxModel* startPortParentBox = cmod->getStartPort()->getParentBox();
2071 std::map<int, GObjectController*>::iterator iterOBJ1 = mapSelected.find(startPortParentBox->getObjectId());
2072 std::map<int, GObjectController*>::iterator iterOBJ2 = mapSelected.find(endPortParentBox->getObjectId());
2074 if(iterOBJ1 != mapSelected.end() && iterOBJ2 != mapSelected.end())
2076 int ID = cont->getId();
2077 mapSelected[ID]=cont;
2085 //=========================================================================
2087 void wxVtkSceneManager::addObjects(std::map<int,GObjectController*> objectsMap)
2090 std::map<int,int> oldIdNewIdBoxes;
2091 std::vector<int> connections;
2093 std::map<int, GObjectController*>::iterator it;
2094 for(it = objectsMap.begin(); it != objectsMap.end(); ++it)
2096 GObjectController *cont = it->second;
2097 int type = cont->getGObjectType();
2102 double xInic, yInic,zInic;
2103 GBlackBoxModel* copyBox = (GBlackBoxModel*)cont->getModel();
2104 copyBox->getInicPoint(xInic,yInic,zInic);
2105 int idBox = createGBlackBox(0,0,copyBox->getBBTKPackage(),copyBox->getBBTKType());
2107 int idcB = copyBox->getObjectId();
2108 oldIdNewIdBoxes[idcB]=idBox;
2109 cont = _controllers[idBox];
2110 GBlackBoxModel* newbox = (GBlackBoxModel*)cont->getModel();
2111 newbox->setInicPoint(xInic,yInic,zInic);
2112 int num = newbox->getNumInputPorts();
2113 for(int j=0;j<num;j++)
2115 newbox->setValueToInputPort(j,copyBox->getValueInputPort(j));
2117 newbox->notifyObservers(_idManager);
2119 else if(type==GCONNECTOR)
2121 int idCon = cont->getId();
2122 connections.push_back(idCon);
2127 for(int i = 0 ;i<connections.size();i++)
2129 int objId = connections[i];
2130 GObjectController *cont = objectsMap[objId];
2131 GConnectorModel* connectModel = (GConnectorModel*)cont->getModel();
2133 GPortModel* startPort = connectModel->getStartPort();
2134 int startPortIndex = startPort->getPosInBox();
2135 GPortModel* endPort = connectModel->getEndPort();
2136 int endPortIndex = endPort->getPosInBox();
2138 GBlackBoxModel* startPortParentBox = (GBlackBoxModel*)startPort->getParentBox();
2139 GBlackBoxModel* endPortParentBox = (GBlackBoxModel*)endPort->getParentBox();
2141 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2142 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2144 GBlackBoxModel* newStartBox = (GBlackBoxModel*)_controllers[idNewStartBox]->getModel();
2145 GBlackBoxModel* newEndBox = (GBlackBoxModel*)_controllers[idNewEndBox]->getModel();
2147 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2148 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2150 // Creates connection
2151 int idCon = createGConnector(newStartPort);
2152 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
2153 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
2154 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
2155 tempp->endContourCreation();
2156 conMod->setEndPort(newEndPort);
2157 conView->updateStartEndPoints();
2160 std::map<int, int>::iterator itIds;
2161 for(itIds = oldIdNewIdBoxes.begin(); itIds != oldIdNewIdBoxes.end(); ++itIds)
2163 int idOld = itIds->first;
2164 int idNew = itIds->second;
2166 GBlackBoxModel* oldBox = (GBlackBoxModel*)objectsMap[idOld]->getModel();
2167 GBlackBoxModel* newBox = (GBlackBoxModel*)_controllers[idNew]->getModel();
2169 std::vector<int> oldInputConnections = oldBox->getConnectedInputs();
2170 std::vector<int> oldOutputConnections = oldBox->getConnectedOutputs();
2171 std::vector<int> newInputConnections = newBox->getConnectedInputs();
2172 std::vector<int> newOutputConnections = newBox->getConnectedOutputs();
2174 for(int k = 0; k<(int)oldInputConnections.size();k++)
2177 //EED int toCreate=-1;
2178 for(int l = 0; l<(int)newInputConnections.size() && !exist;l++)
2180 if(oldInputConnections[k]==newInputConnections[l])
2188 //Create complex input
2189 int posInBox = oldInputConnections[k];
2190 GPortModel* inputPort = oldBox->getInputPort(posInBox);
2191 std::string inputPortName = inputPort->getBBTKName();
2192 int idInputPort = createGComplexBoxInputPort(inputPortName);
2193 GObjectController *cont = _controllers[idInputPort];
2194 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
2196 inputPort->getInicPoint(xIn,yIn,zIn);
2198 cbmod->setInicPoint(xIn,yIn,zIn);
2199 cbmod->notifyObservers(_idManager);
2201 GPortModel* inputPortEnd = newBox->getInputPort(posInBox);
2203 // Creates connection
2204 int idCon = createGConnector(cbmod->getOutputPort(0));
2205 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
2206 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
2207 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
2208 tempp->endContourCreation();
2209 conMod->setEndPort(inputPortEnd);
2210 conView->updateStartEndPoints();
2217 for(int k = 0; k<(int)oldOutputConnections.size();k++)
2220 //EED int toCreate=-1;
2221 for(int l = 0; l<(int)newOutputConnections.size() && !exist;l++)
2223 if(oldOutputConnections[k]==newOutputConnections[l])
2231 //Create complex output
2232 int posInBox = oldOutputConnections[k];
2233 GPortModel* outputPort = oldBox->getOutputPort(posInBox);
2234 std::string outputPortName = outputPort->getBBTKName();
2235 int idOutputPort = createGComplexBoxOutputPort(outputPortName);
2236 GObjectController *cont = _controllers[idOutputPort];
2237 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
2239 outputPort->getInicPoint(xIn,yIn,zIn);
2241 cbmod->setInicPoint(xIn,yIn,zIn);
2242 cbmod->notifyObservers(_idManager);
2244 GPortModel* outputPortEnd = newBox->getOutputPort(posInBox);
2246 // Creates connection
2247 int idCon = createGConnector(outputPortEnd);
2248 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
2249 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
2250 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
2251 tempp->endContourCreation();
2252 conMod->setEndPort(cbmod->getInputPort(0));
2253 conView->updateStartEndPoints();
2264 //=========================================================================
2266 } // EO namespace bbtk