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)
48 _idManager = idManager;
50 _startDragging = false;
51 _isComplexBox = false;
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();
107 _textActor = vtkTextActor3D::New();
108 _textActor->SetPosition( 100 , 100 , 900 );
109 _textActor->SetInput( "Ups EED" );
110 _baseView->GetRenderer()->AddActor( _textActor );
114 //=========================================================================
116 std::string wxVtkSceneManager::generateANewNameForABox()
118 std::stringstream boxname;
121 boxname << "Box0" << _numBoxes;
123 boxname << "Box" << _numBoxes;
126 return boxname.str();
129 //=========================================================================
131 std::string wxVtkSceneManager::findANewNameForABox()
133 std::string boxname=generateANewNameForABox();
135 while (boxExist(boxname)==true)
137 boxname=generateANewNameForABox();
143 //=========================================================================
144 void wxVtkSceneManager::configGBlackBox(int idBox, double xIn, double yIn, double zIn, std::string name, bool boxExecutable,double xEn,double yEn,double zEn)
146 GObjectController *cont = _controllers[idBox];
147 GBlackBoxModel *bbmod = (GBlackBoxModel*)cont->getModel();
148 bbmod->setBBTKName(name);
149 bbmod->setInicPoint(xIn,yIn,zIn);
150 bbmod->setFinalPoint(xEn,yEn,zEn);
151 bbmod->setExecutable(boxExecutable);
153 bbmod->notifyObservers(_idManager);
158 //=========================================================================
160 int wxVtkSceneManager::createGBlackBox(int x, int y, std::string packageName, std::string boxType)
162 _worldState = NOTHING_HAPPENS;
163 //EED int windowWidth = _baseView->GetRenWin()->GetSize()[0];
164 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
166 int type = GBLACKBOX;
168 //Create the MVC Objects
170 GBlackBoxModel *model = (GBlackBoxModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
171 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
172 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
174 BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxType);
176 //Prepares the initial model
177 //The coordinates obtained are the following. Top-Left:x=0,y=0 Bottom-Right:x=width,y=height
180 double yy = windowHeight-y;
182 //z value is not important yet, because it is only used a parallel projection
185 _baseView->TransCoordScreenToWorld(xx,yy,zz);
186 model->setInicPoint(xx,yy,zz);
188 std::stringstream stream;
190 std::string newBoxName;
191 newBoxName = findANewNameForABox();
194 stream << newBoxName;
196 std::string arraystring = stream.str();
198 model->setBBTKName(arraystring);
199 model->setBBTKType(boxType);
200 model->setBBTKPackage(packageName);
202 model->addObserver(view);
203 model->addObserver(this);
205 //Iterate and create the input ports
206 std::map<std::string, BlackBoxInputDescriptor*> descriptorInMap = descriptor->GetInputDescriptorMap();
207 std::map<std::string, BlackBoxInputDescriptor*>::iterator itInput;
210 for(itInput = descriptorInMap.begin(); itInput != descriptorInMap.end(); ++itInput)
212 BlackBoxInputDescriptor *desc = itInput->second;
213 createGInputPort(GINPUTPORT,i,model,desc);
217 //Iterate and create the output ports
218 std::map<std::string, BlackBoxOutputDescriptor*> descriptorOutMap = descriptor->GetOutputDescriptorMap();
219 std::map<std::string, BlackBoxOutputDescriptor*>::iterator itOutput;
222 for(itOutput = descriptorOutMap.begin();itOutput != descriptorOutMap.end(); ++itOutput)
224 BlackBoxOutputDescriptor *desc = itOutput->second;
225 createGOutputPort(GOUTPUTPORT,i,model,desc);
230 //Associates the view with the correspondent renderer and the model.
231 //(NOTE: Refresh is only made by the view)
232 view->setModel(model);
233 view->setBaseView(_baseView);
234 view->initVtkObjects();
236 //Associates the controller with the correspondent model and view
237 controller->setModelAndView(model,view);
239 //Resgiter change to the observers of the actual model
240 model->notifyObservers(_idManager);
242 int newId = addObjectController(controller);
248 //=========================================================================
250 int wxVtkSceneManager::createGComplexBoxInputPort(std::string inputName)
252 //EED int windowWidth=_baseView->GetRenWin()->GetSize()[0];
253 int windowHeight=_baseView->GetRenWin()->GetSize()[1];
255 int type = GCOMPLEXINPUTPORT;
257 //Create the MVC Objects
259 GComplexBoxPortModel *model = (GComplexBoxPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
260 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
261 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
263 //Prepares the initial model
266 double yy = windowHeight-5;
268 //z value is not important yet, because it is only used a parallel projection
271 _baseView->TransCoordScreenToWorld(xx,yy,zz);
272 model->setInicPoint(xx,yy,zz);
274 model->setBBTKName(inputName);
275 model->setBBTKType("ComplexInputPort");
276 model->setComplexPortType(type);
278 model->addObserver(view);
279 model->addObserver(this);
281 //create the output port
282 GPortController* portController = createGPort(GOUTPUTPORT,inputName,"ComplexInputPort",0,model);
283 model->addOutputPort((GPortModel*)portController->getModel());
285 //Associates the view with the correspondent renderer and the model.
286 //(NOTE: Refresh is only made by the view)
287 view->setModel(model);
288 view->setBaseView(_baseView);
289 view->initVtkObjects();
291 //Associates the controller with the correspondent model and view
292 controller->setModelAndView(model,view);
294 //Resgiter change to the observers of the actual model
295 model->notifyObservers(_idManager);
297 int newId = addObjectController(controller);
301 //=========================================================================
303 int wxVtkSceneManager::createGComplexBoxOutputPort(std::string outputName)
305 //EED int windowWidth=_baseView->GetRenWin()->GetSize()[0];
306 int windowHeight=_baseView->GetRenWin()->GetSize()[1];
308 int type = GCOMPLEXOUTPUTPORT;
310 //Create the MVC Objects
312 GComplexBoxPortModel *model = (GComplexBoxPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
313 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
314 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
316 //Prepares the initial model
319 double yy = windowHeight-5;
321 //z value is not important yet, because it is only used a parallel projection
324 _baseView->TransCoordScreenToWorld(xx,yy,zz);
325 model->setInicPoint(xx,yy,zz);
327 model->setBBTKName(outputName);
328 model->setBBTKType("ComplexOutputPort");
329 model->setComplexPortType(type);
331 model->addObserver(view);
332 model->addObserver(this);
334 //create the output port
335 GPortController* portController = createGPort(GINPUTPORT,outputName,"ComplexInputPort",0,model);
336 model->addInputPort((GPortModel*)portController->getModel());
338 //Associates the view with the correspondent renderer and the model.
339 //(NOTE: Refresh is only made by the view)
340 view->setModel(model);
341 view->setBaseView(_baseView);
342 view->initVtkObjects();
344 //Associates the controller with the correspondent model and view
345 controller->setModelAndView(model,view);
347 //Resgiter change to the observers of the actual model
348 model->notifyObservers(_idManager);
350 int newId = addObjectController(controller);
354 //=========================================================================
356 int wxVtkSceneManager::createGInputPort(int portType, int posinBox,GBoxModel *blackBox, BlackBoxInputDescriptor *desc)
358 GPortController* portController = createGPort(portType,desc->GetName(),desc->GetTypeName(),posinBox,blackBox);
359 blackBox->addInputPort((GPortModel*)portController->getModel());
360 return portController->getId();
363 //=========================================================================
365 int wxVtkSceneManager::createGOutputPort(int portType, int posinBox,GBoxModel *blackBox, BlackBoxOutputDescriptor *desc)
367 GPortController* portController = createGPort(portType,desc->GetName(),desc->GetTypeName(),posinBox,blackBox);
368 blackBox->addOutputPort((GPortModel*)portController->getModel());
369 return portController->getId();
372 //=========================================================================
374 GPortController* wxVtkSceneManager::createGPort(int portType,std::string bbtkName, std::string bbtkType, int posInBox,GBoxModel *blackBox)
378 //Create the MVC Objects
379 GPortModel *model = (GPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
380 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
381 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
383 model->registerInBox(blackBox,portType, posInBox);
385 model->setBBTKType(bbtkType);
386 model->setBBTKName(bbtkName);
388 model->addObserver(view);
389 model->addObserver(this);
391 //Associates the view with the correspondent renderer and the model.
392 //(NOTE: Refresh is only made by the view)
393 view->setModel(model);
394 view->setBaseView(_baseView);
395 view->initVtkObjects();
397 //Associates the controller with the correspondent model and view
398 controller->setModelAndView(model,view);
400 model->notifyObservers(_idManager);
402 int newId = addObjectController(controller);
404 return (GPortController*)controller;
407 //=========================================================================
409 int wxVtkSceneManager::createGConnector(GPortModel* startPort)
411 int type = GCONNECTOR;
413 manualConnectorContourController* manContourControl = new manualConnectorContourController();
414 manualConnectorContourView* manContourView = new manualConnectorContourView();
415 manualContourModel* manContourModel = new manualContourModel();
417 GConnectorController* connectorcontroller = new GConnectorController();
418 GConnectorModel* connectorModel = new GConnectorModel();
419 vtkGConnectorView* connectorView = new vtkGConnectorView();
420 connectorModel->setGObjectType(type);
422 manContourModel->SetCloseContour(false);
423 connectorModel->setStartPort(startPort);
425 manContourView->SetModel( manContourModel );
426 manContourView->SetWxVtkBaseView( _baseView );
427 manContourView->SetRange( 0.5 );
428 manContourView->SetZ( 900 );
430 manContourView->SetColorNormalContour(0, 0, 1);
431 manContourView->SetColorEditContour(0.5, 0.5, 0.5);
432 manContourView->SetColorSelectContour(1, 0.8, 0);
433 manContourView->SetWidthLine(1);
434 manContourView->SetShowText(false);
436 manContourControl->SetModelView( manContourModel , manContourView );
438 manContourControl->CreateNewManualContour();
440 manContourView->RefreshContour();
444 connectorModel->getInicPoint(x,y,z);
446 manContourControl->SetState(1);
447 manContourModel->SetCloseContour(false);
449 manContourModel->AddPoint(x,y,z);
450 manContourView->AddPoint();
452 manContourModel->AddPoint(x,y,z);
453 manContourView->AddPoint();
455 int bak= manContourControl->GetNumberOfPointsManualContour() - 1;
456 manContourControl->_bakIdPoint=bak;
457 manContourView->Refresh();
459 manContourControl->SetMoving( false );
461 connectorcontroller->setModelAndView(connectorModel,connectorView);
463 int newId = addObjectController(connectorcontroller);
465 connectorcontroller->setManualContourController(manContourControl);
466 connectorModel->setManualContourModel(manContourModel);
467 connectorView->setManualContourView(manContourView);
468 connectorView->setModel(connectorModel);
469 connectorView->setBaseView(_baseView);
472 connectorModel->addObserver(connectorView);
473 connectorModel->addObserver(this);
478 //=========================================================================
480 void wxVtkSceneManager::registerController(InteractorStyleMaracas *param)
482 vtkInteractorStyleBaseView* baseViewControlManager = (vtkInteractorStyleBaseView*)_baseView->GetInteractorStyleBaseView();
483 baseViewControlManager->AddInteractorStyleMaracas( param );
486 //=========================================================================
488 void wxVtkSceneManager::unregisterController(InteractorStyleMaracas *param)
490 vtkInteractorStyleBaseView* baseViewControlManager = (vtkInteractorStyleBaseView*)_baseView->GetInteractorStyleBaseView();
491 baseViewControlManager->RemoveInteractorStyleMaracas( param );
494 //=========================================================================
496 vtkRenderer* wxVtkSceneManager::getRenderer()
498 return _baseView->GetRenderer();
501 //=========================================================================
503 vtkRenderWindow* wxVtkSceneManager::getRenderWindow()
505 return _baseView->GetRenWin();
507 //=========================================================================
510 void wxVtkSceneManager::update(int idController,int command)
512 if(command != NO_COMMAND)
514 if(command == ADD_TO_SELECTED)
516 //EED GObjectController* cont = _controllers[idController];
519 for (int i=0; i<(int)_selectedObjects.size() && foundID==false; i++)
521 int id = _selectedObjects[i];
529 int id = idController;
530 _selectedObjects.push_back(id);
534 else if(command == INIT_CREATION_CONTOUR)
536 _worldState = INIT_CREATION_CONTOUR;
537 GObjectController* cont = _controllers[idController];
538 GPortModel* startOutputPort = (GPortModel*)cont->getModel();
541 // The last one is the controller of the connector
542 std::map<int, GObjectController*>::iterator it2;
544 for(it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
546 GObjectController *cont = it2->second;
547 if(cont->getGObjectType() == GPORT )
549 GPortModel* port = (GPortModel*)cont->getModel();
550 if(port->getPortType()==GINPUTPORT)
552 cont->SetActive(true);
556 cont->getView()->setState(NOTHING_HAPPENS);
557 cont->getModel()->notifyObservers(_idManager);
558 cont->SetActive(false);
563 cont->getView()->setState(NOTHING_HAPPENS);
564 cont->getModel()->notifyObservers(_idManager);
565 cont->SetActive(false);
569 _selectedObjects.clear();
571 _idConnectionInCreation=createGConnector(startOutputPort);
574 else if(command == FIN_CREATION_CONTOUR && _worldState == INIT_CREATION_CONTOUR)
576 _worldState = NOTHING_HAPPENS;
577 //int id = _controllers.size()-1;
578 GObjectController* cont = _controllers[_idConnectionInCreation];
579 GConnectorModel* modelContour = (GConnectorModel*)cont->getModel();
581 GObjectController* finPort = _controllers[idController];
582 if(finPort->getGObjectType() == GPORT)
584 GPortModel* modelPort = (GPortModel*)finPort->getModel();
585 modelContour->setEndPort(modelPort);
588 manualConnectorContourController* manCont = ((GConnectorController*)cont)->getManualContourController();
589 manualConnectorContourView* connView = (manualConnectorContourView*)manCont->GetManualViewBaseContour();
592 std::map<int, GObjectController*>::iterator it2;
594 for(it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
596 GObjectController *cont = it2->second;
597 if(cont->getView()!=NULL)
599 cont->getView()->setState(NOTHING_HAPPENS);
600 cont->getModel()->notifyObservers(_idManager);
602 cont->SetActive(true);
609 //=========================================================================
611 bool wxVtkSceneManager::OnMouseMove()
614 bool okStatusMessage = false;
615 bool okPortMessage = false;
616 wxVTKRenderWindowInteractor *wxVTKiren;
617 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
618 wxVTKiren->GetEventPosition(X,Y);
621 if(_worldState == DRAG_OBJECTS)
623 for (int i=0; i<(int)_selectedObjects.size(); i++)
625 int id = _selectedObjects[i];
626 GObjectController* cont = _controllers[id];
629 cont->getView()->setStartDragging(true);
631 cont->getView()->moveObject(X,Y);
632 cont->getView()->setState(DRAG);
633 cont->getModel()->notifyObservers(_idManager);
636 std::map<int, GObjectController*>::iterator it;
638 for(it = _controllers.begin(); it != _controllers.end(); ++it)
640 GObjectController *desc = it->second;
641 if(desc->getGObjectType()==GCONNECTOR)
643 vtkGConnectorView* vconn = (vtkGConnectorView*)desc->getView();
644 vconn->updateStartEndPoints();
648 _startDragging=false;
651 else if(_worldState == NOTHING_HAPPENS || _worldState == INIT_CREATION_CONTOUR)
653 std::map<int, GObjectController*>::iterator it;
655 for(it = _controllers.begin(); it != _controllers.end(); ++it)
657 GObjectController *desc = it->second;
658 int type = desc->getGObjectType();
659 int state = desc->getView()->getState();
660 desc->getModel()->getCenter(px,py,pz);
662 if(state == HIGHLIGHTED){
663 okStatusMessage = true;
664 updateStatusBar(desc->getStatusText());
667 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
668 _parent->displayBlackBoxInfo(mod->getBBTKPackage(),mod->getBBTKType());
672 okPortMessage = true;
673 _textActor->SetInput( desc->getStatusText().c_str() );
674 _textActor->SetScale(1);
676 _textActor->SetPosition( px ,py , pz+1 );
679 } // for controllers it
683 if (okStatusMessage==false)
688 if (okPortMessage==false)
690 _textActor->SetScale(0.0001);
697 //=========================================================================
699 bool wxVtkSceneManager::OnLeftButtonDown()
701 if(_worldState==INIT_CREATION_CONTOUR)
703 bool isOverPort=false;
704 std::map<int, GObjectController*>::iterator it;
705 for(it = _controllers.begin(); it != _controllers.end() && isOverPort==false; ++it)
707 GObjectController *desc = it->second;
708 if(desc->getGObjectType()==GPORT)
710 GPortModel* portmod=(GPortModel*)desc->getModel();
711 vtkGObjectView* portView=desc->getView();
712 if(portmod->getPortType()==GINPUTPORT && portView->getState()==HIGHLIGHTED)
719 if(isOverPort==false)
721 _worldState=NOTHING_HAPPENS;
722 //int lastId = _controllers.size()-1;
723 GConnectorController *connector = (GConnectorController*)_controllers[_controllers.size()-1];
724 connector->removeFromScene();
725 unregisterController(connector);
726 _controllers.erase(_controllers.size()-1);
728 for(it = _controllers.begin(); it != _controllers.end(); ++it)
730 GObjectController *desc = it->second;
731 desc->SetActive(true);
732 desc->getView()->setState(NOTHING_HAPPENS);
733 desc->getModel()->notifyObservers(_idManager);
738 if(_selectedObjects.size()!=0)
740 _worldState = DRAG_OBJECTS;
741 _startDragging = true;
743 for (int i = 0; i < (int)_selectedObjects.size(); i++)
745 int id = _selectedObjects[i];
746 GObjectController* cont = _controllers[id];
747 cont->getView()->setState(DRAG);
748 cont->getModel()->notifyObservers(_idManager);
757 //=========================================================================
759 bool wxVtkSceneManager::OnLeftButtonUp()
761 if(_worldState == DRAG_OBJECTS)
763 _worldState = NOTHING_HAPPENS;
765 for (int i = 0; i < (int)_selectedObjects.size(); i++)
767 int id = _selectedObjects[i];
768 GObjectController* cont = _controllers[id];
769 cont->getView()->setState(SELECTED);
770 cont->getModel()->notifyObservers(_idManager);
776 //=========================================================================
778 bool wxVtkSceneManager::OnRightButtonUp()
780 if(_worldState==INIT_CREATION_CONTOUR)
782 _worldState=NOTHING_HAPPENS;
783 //int lastId = _controllers.size()-1;
784 GConnectorController *connector = (GConnectorController*)_controllers[_idConnectionInCreation];
785 connector->removeFromScene();
786 unregisterController(connector);
787 _controllers.erase(_idConnectionInCreation);
789 std::map<int, GObjectController*>::iterator it;
790 for(it = _controllers.begin(); it != _controllers.end(); ++it)
792 GObjectController *desc = it->second;
793 desc->SetActive(true);
794 desc->getView()->setState(NOTHING_HAPPENS);
795 desc->getModel()->notifyObservers(_idManager);
800 for (int i = 0; i < (int)_selectedObjects.size(); i++)
802 int id = _selectedObjects[i];
803 GObjectController* cont = _controllers[id];
804 cont->SetActive(true);
805 cont->getView()->setState(NOTHING_HAPPENS);
806 cont->getModel()->notifyObservers(_idManager);
809 _selectedObjects.clear();
814 //=========================================================================
816 bool wxVtkSceneManager::OnLeftDClick()
819 wxVTKRenderWindowInteractor *wxVTKiren;
820 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
821 wxVTKiren->GetEventPosition(X,Y);
823 std::map<int, GObjectController*>::iterator it;
825 bool clickOnObject = false;
827 for(it = _controllers.begin(); it != _controllers.end() && clickOnObject==false; ++it)
829 GObjectController *cont = it->second;
830 int type = cont->getGObjectType();
832 if(cont->getView()->isPointInside(X,Y))
836 for (int i=0; i< (int)_selectedObjects.size(); i++)
838 int id = _selectedObjects[i];
839 GObjectController* control = _controllers[id];
840 control->getView()->setState(NOTHING_HAPPENS);
842 _selectedObjects.clear();
844 GBlackBoxModel *bbmodel = (GBlackBoxModel*)cont->getModel();
845 _parent->editBlackBox(bbmodel);
847 clickOnObject = true;
851 if(clickOnObject==false)
853 //_parent->editDiagramParameters(this);
859 //=========================================================================
861 bool wxVtkSceneManager::OnChar()
863 char keyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
865 // KeyCode 127 : Delete Key
866 // KeyCode 8 : Backspace Key
867 if(keyCode == 8 || keyCode == 127)
869 if(_selectedObjects.size()>0)
871 for(int i=0;i<(int)_selectedObjects.size();i++)
873 int id = _selectedObjects[i];
874 std::map<int,GObjectController*>::iterator it;
875 it = _controllers.find(id);
876 if (it!=_controllers.end())
881 _selectedObjects.clear();
888 //=========================================================================
890 void wxVtkSceneManager::AddControlerToBeRemove(std::vector<int> *controllersToRemove, int id)
895 for(i=0 ; i < (int)controllersToRemove->size() ; i++ )
897 if (id == (*controllersToRemove)[i] )
905 controllersToRemove->push_back( id );
910 //=========================================================================
912 void wxVtkSceneManager::deleteObject(int id)
914 GObjectController *control = _controllers[id];
915 std::vector<int> controllersToRemove;
917 if(control->getGObjectType()==GBLACKBOX || control->getGObjectType()==GCOMPLEXINPUTPORT || control->getGObjectType()==GCOMPLEXOUTPUTPORT)
919 GBoxModel *bbmod = (GBoxModel*)control->getModel();
920 std::vector<GPortModel*> inputs = bbmod->getInputPorts();
922 bool boxConnected = false;
924 // Add box input controllers to be removed
925 for(int i = 0;i< (int)inputs.size();i++)
927 AddControlerToBeRemove( &controllersToRemove, inputs[i]->getObjectId() );
928 if(inputs[i]->isConnected())
934 std::vector<GPortModel*> outputs = bbmod->getOutputPorts();
936 // Add box output controllers to be removed
937 for(int i = 0;i<(int)outputs.size();i++)
939 AddControlerToBeRemove( &controllersToRemove, outputs[i]->getObjectId() );
940 if(outputs[i]->isConnected())
946 // Add connection controllers to be removed
947 std::map<int, GObjectController*>::iterator it;
948 for(it = _controllers.begin(); it != _controllers.end(); ++it)
950 GObjectController *cont = it->second;
951 int type = cont->getGObjectType();
954 GConnectorModel *conMod = (GConnectorModel*)cont->getModel();
955 if(conMod->getStartPort()!=NULL && conMod->getStartPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
957 AddControlerToBeRemove( &controllersToRemove, conMod->getObjectId() );
959 if(conMod->getEndPort()!=NULL && conMod->getEndPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
961 AddControlerToBeRemove( &controllersToRemove, conMod->getObjectId() );
966 // Add box controller to be removed
967 AddControlerToBeRemove( &controllersToRemove, bbmod->getObjectId() );
969 else if(control->getGObjectType()==GCONNECTOR)
971 GConnectorModel *conMod = (GConnectorModel*)control->getModel();
972 AddControlerToBeRemove( &controllersToRemove, conMod->getObjectId() );
976 std::map<int,GObjectController*>::iterator it;
978 for(int i = 0;i<(int)controllersToRemove.size();i++)
980 int key = controllersToRemove[i];
981 it = _controllers.find( key );
982 GObjectController *cont = _controllers[ key ];
985 cont->removeFromScene();
986 unregisterController((InteractorStyleMaracas*)cont);
987 _controllers.erase(it);
992 //=========================================================================
994 void wxVtkSceneManager::displayBlackBoxInfo(std::string packageName, std::string boxName)
996 _parent->displayBlackBoxInfo(packageName,boxName);
999 //=========================================================================
1001 void wxVtkSceneManager::updateStatusBar(std::string textStatus)
1003 _parent->updateStatusBar(textStatus);
1006 //=========================================================================
1008 std::string wxVtkSceneManager::getDiagramBBS()
1010 bool existsExec=false;
1012 std::vector<std::string> packages;
1013 std::vector<int> boxes;
1014 std::vector<int> connections;
1015 std::vector<int> execBoxes;
1017 std::map<int, GObjectController*>::iterator it;
1019 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1021 GObjectController *desc = it->second;
1022 int type = desc->getGObjectType();
1026 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
1028 std::string pkg = mod->getBBTKPackage();
1029 bool existsPkg = false;
1030 for(int t = 0;t< (int)packages.size() && existsPkg == false;t++)
1032 if(packages[t]==pkg)
1039 packages.push_back(pkg);
1043 boxes.push_back(it->first);
1044 if(mod->isExecutable())
1046 execBoxes.push_back(it->first);
1050 else if(type==GCONNECTOR)
1052 connections.push_back(it->first);
1056 std::string script = "";
1057 script+="# BBTK GEditor Script\n";
1058 script+="# ----------------------\n";
1062 script+="include std\n"; // EED
1063 script+="include itkvtk\n"; // EED
1065 for(i = 0; i< (int)packages.size();i++)
1068 script+=packages[i];
1073 // script+="include std\n"; // JPR
1075 for(i = 0; i < (int)boxes.size();i++)
1079 GObjectController *control = _controllers[id];
1080 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1082 script+=model->getBBTKType();
1084 script+=model->getBBTKName();
1087 std::vector<GPortModel*> inputs = model->getInputPorts();
1088 for(int j = 0; j < (int)inputs.size();j++)
1090 GPortModel* inputPort = inputs[j];
1091 if(inputPort->isValueSet())
1094 script+=model->getBBTKName();
1096 script+=inputPort->getBBTKName();
1098 script+=inputPort->getValue();
1108 for(i = 0; i<(int)connections.size();i++)
1111 int id = connections[i];
1112 GObjectController *control = _controllers[id];
1113 GConnectorModel *model = (GConnectorModel*)control->getModel();
1115 //Start Connection info
1116 GPortModel *start = model->getStartPort();
1117 script+=start->getParentBox()->getBBTKName();
1119 script+=start->getBBTKName();
1123 //End Connection info
1124 GPortModel *end = model->getEndPort();
1125 script+=end->getParentBox()->getBBTKName();
1127 script+=end->getBBTKName();
1133 for(i = 0; i<(int)execBoxes.size();i++)
1136 int id = execBoxes[i];
1137 GObjectController *control = _controllers[id];
1138 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1140 script+=model->getBBTKName();
1149 //=========================================================================
1151 std::string wxVtkSceneManager::saveComplexBoxBBS(std::string cbName,std::string cbAuthor,std::string cbCategory,std::string cbDescription)
1154 std::vector<std::string> packages;
1155 std::vector<int> boxes;
1156 std::vector<int> connections;
1157 std::vector<int> execBoxes;
1159 std::map<int, GObjectController*>::iterator it;
1161 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1163 GObjectController *desc = it->second;
1164 int type = desc->getGObjectType();
1168 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
1170 std::string pkg = mod->getBBTKPackage();
1171 bool existsPkg = false;
1172 for(int t = 0;t<(int)packages.size() && existsPkg == false;t++)
1174 if(packages[t]==pkg)
1181 packages.push_back(pkg);
1185 boxes.push_back(it->first);
1186 if(mod->isExecutable())
1188 execBoxes.push_back(it->first);
1191 else if(type==GCONNECTOR)
1193 connections.push_back(it->first);
1197 std::string script = "";
1199 script+="include std\n"; // EED
1200 script+="include itkvtk\n"; // EED
1202 for(i = 0; i<(int)packages.size();i++)
1205 script+=packages[i];
1210 // Definition of a complex box
1216 script+="author \" ";
1220 script+="description \" ";
1221 script+=cbDescription;
1226 for(i = 0; i<(int)boxes.size();i++)
1230 GObjectController *control = _controllers[id];
1231 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1233 script+=model->getBBTKType();
1235 script+=model->getBBTKName();
1238 std::vector<GPortModel*> inputs = model->getInputPorts();
1239 for(int j = 0; j<(int)inputs.size();j++)
1241 GPortModel* inputPort = inputs[j];
1242 if(inputPort->isValueSet())
1245 script+=model->getBBTKName();
1247 script+=inputPort->getBBTKName();
1249 script+=inputPort->getValue();
1257 // Create connections in the script. If the connection is made with a complex port, it is created the input or output
1259 std::string complexInputs="";
1260 std::string complexOutputs="";
1263 for(i = 0; i<(int)connections.size();i++)
1265 int id = connections[i];
1266 GObjectController *control = _controllers[id];
1267 GConnectorModel *model = (GConnectorModel*)control->getModel();
1270 GPortModel *start = model->getStartPort();
1271 GBoxModel *startBox =start->getParentBox();
1273 GPortModel *end = model->getEndPort();
1274 GBoxModel *endBox =end->getParentBox();
1276 if(startBox->getGObjectType()==GCOMPLEXINPUTPORT)
1278 complexInputs+="input ";
1279 complexInputs+=startBox->getBBTKName();
1282 complexInputs+=endBox->getBBTKName();
1284 complexInputs+=end->getBBTKName();
1287 complexInputs+="\" \"";
1289 complexInputs+="\n";
1291 else if(endBox->getGObjectType()==GCOMPLEXOUTPUTPORT)
1293 complexOutputs+="output ";
1294 complexOutputs+=endBox->getBBTKName();
1296 complexOutputs+=" ";
1297 complexOutputs+=startBox->getBBTKName();
1298 complexOutputs+=".";
1299 complexOutputs+=start->getBBTKName();
1301 complexOutputs+=" ";
1302 complexOutputs+="\" \"";
1304 complexOutputs+="\n";
1309 script+=startBox->getBBTKName();
1311 script+=start->getBBTKName();
1315 //End Connection info
1316 script+=endBox->getBBTKName();
1318 script+=end->getBBTKName();
1326 for(i = 0; i<(int)execBoxes.size();i++)
1329 int id = execBoxes[i];
1330 GObjectController *control = _controllers[id];
1331 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1333 script+=model->getBBTKName();
1338 script+="# Complex input ports\n";
1339 script+=complexInputs;
1342 script+="# Complex output ports\n";
1343 script+=complexOutputs;
1352 //=========================================================================
1354 void wxVtkSceneManager::deleteAllBoxes()
1356 std::map<int, GObjectController*>::iterator it;
1357 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1359 GObjectController *cont = it->second;
1360 cont->removeFromScene();
1361 unregisterController((InteractorStyleMaracas*)cont);
1363 _selectedObjects.clear();
1364 _controllers.clear();
1368 //=========================================================================
1370 void wxVtkSceneManager::refreshScene()
1372 _baseView->RefreshView();
1375 //=========================================================================
1377 void wxVtkSceneManager::centerView()
1380 _baseView->GetRenderer()->GetActiveCamera()->GetFocalPoint(temp);
1381 _baseView->GetRenderer()->GetActiveCamera()->SetFocalPoint(0,0,temp[2]);
1382 _baseView->GetRenderer()->GetActiveCamera()->GetPosition(temp);
1383 _baseView->GetRenderer()->GetActiveCamera()->SetPosition(0,0,temp[2]);
1384 _baseView->RefreshView();
1388 //=========================================================================
1390 void wxVtkSceneManager::saveDiagram(std::string &content)
1394 //Print info IF COMPLEX BOX
1395 content+="COMPLEXBOX:";
1400 //Print info complex input ports
1401 std::vector<int> inputs = getComplexInputPorts();
1402 int insize = inputs.size();
1403 content+="COMPLEXINPUTS:";
1404 sprintf (buffer, "%d", insize);
1408 for(int i = 0;i<insize;i++)
1411 GObjectController *cont = _controllers[id];
1412 cont->getModel()->save(content);
1415 //Print info complex output ports
1416 std::vector<int> outputs = getComplexOutputPorts();
1417 int outsize = outputs.size();
1418 content+="COMPLEXOUTPUTS:";
1419 sprintf (buffer, "%d", outsize);
1423 for(int i = 0;i<outsize;i++)
1425 int id = outputs[i];
1426 GObjectController *cont = _controllers[id];
1427 cont->getModel()->save(content);
1436 std::vector<int> boxes = getBlackBoxes();
1437 int bsize = boxes.size();
1439 sprintf (buffer, "%d", bsize);
1443 for(int i = 0;i<bsize;i++)
1446 GObjectController *cont = _controllers[id];
1447 cont->getModel()->save(content);
1451 std::vector<int> connections = getConnections();
1452 int csize = connections.size();
1453 content+="CONNECTIONS:";
1454 sprintf (buffer, "%d", csize);
1458 for(int i = 0;i<csize;i++)
1460 int id = connections[i];
1461 GObjectController *cont = _controllers[id];
1462 cont->getModel()->save(content);
1467 //=========================================================================
1469 void wxVtkSceneManager::loadDiagram(ifstream &inputStream)
1472 std::string line="";
1473 char delims[] = ":";
1474 char *result = NULL;
1475 getline(inputStream,line);
1478 while ( !inputStream.eof() )
1480 if(line=="" || line[0]=='#')
1482 getline(inputStream,line);
1484 else if(line=="APP_START")
1495 getline(inputStream,line);//COMPLEX_BOX:TRUE|FALSE
1497 strcpy( complex, line.c_str() );
1498 result = strtok( complex, delims );
1499 result = strtok( NULL, delims );
1500 std::string isComplexBox(result);
1502 if(isComplexBox=="TRUE")
1506 //-----------------------
1507 //- COMPLEX INPUT PORTS
1508 //-----------------------
1509 getline(inputStream,line);//COMPLEXINPUTS:num
1511 strcpy( inputs, line.c_str() );
1512 result = strtok( inputs, delims );
1513 result = strtok( NULL, delims );
1516 std::istringstream inps(result);
1519 for(int i = 0;i<numInputs;i++)
1522 getline(inputStream,line);//COMPLEX_PORT
1523 getline(inputStream,line);//name
1524 std::string inputPortName(line);
1527 getline(inputStream,line);//xInic:yInic:zInic
1529 strcpy( coord, line.c_str() );
1530 result = strtok( coord, delims );//xInic
1531 std::string xInic(result);
1532 result = strtok( NULL, delims );//yInic
1533 std::string yInic(result);
1534 result = strtok( NULL, delims );//zInic
1535 std::string zInic(result);
1537 double xIn, yIn, zIn;
1538 std::istringstream xSt(xInic);
1540 std::istringstream ySt(yInic);
1542 std::istringstream zSt(zInic);
1545 getline(inputStream,line);//FIN_COMPLEX_PORT
1547 configGComBoxInputOutputPort(true, inputPortName,xIn,yIn,zIn);
1550 // int idInputPort = createGComplexBoxInputPort(inputPortName);
1551 // GObjectController *cont = _controllers[idInputPort];
1552 // GBoxModel *cbmod = (GBoxModel*)cont->getModel();
1553 // cbmod->setInicPoint(xIn,yIn,zIn);
1554 // cbmod->notifyObservers(_idManager);
1557 } // for input complex box
1560 //-----------------------
1561 //- COMPLEX OUTPUT PORTS
1562 //-----------------------
1564 getline(inputStream,line);//COMPLEXOUTPUTS:num
1566 strcpy( outputs, line.c_str() );
1567 result = strtok( outputs, delims );
1568 result = strtok( NULL, delims );
1571 std::istringstream outps(result);
1572 outps >> numOutputs;
1574 for(int i = 0;i<numOutputs;i++)
1577 getline(inputStream,line);//COMPLEX_PORT
1578 getline(inputStream,line);//name
1579 std::string outputPortName(line);
1582 getline(inputStream,line);//xInic:yInic:zInic
1584 strcpy( coord, line.c_str() );
1585 result = strtok( coord, delims );//xInic
1586 std::string xInic(result);
1587 result = strtok( NULL, delims );//yInic
1588 std::string yInic(result);
1589 result = strtok( NULL, delims );//zInic
1590 std::string zInic(result);
1592 double xIn, yIn, zIn;
1593 std::istringstream xSt(xInic);
1595 std::istringstream ySt(yInic);
1597 std::istringstream zSt(zInic);
1600 getline(inputStream,line);//FIN_COMPLEX_PORT
1602 configGComBoxInputOutputPort(false, outputPortName,xIn,yIn,zIn);
1605 // int idOutputPort = createGComplexBoxOutputPort(outputPortName);
1606 // GObjectController *cont = _controllers[idOutputPort];
1607 // GBoxModel *cbmod = (GBoxModel*)cont->getModel();
1608 // cbmod->setInicPoint(xIn,yIn,zIn);
1609 // cbmod->notifyObservers(_idManager);
1611 } // for output complex box
1616 getline(inputStream,line);//BOXES:num
1618 strcpy( boxes, line.c_str() );
1619 result = strtok( boxes, delims );
1620 result = strtok( NULL, delims );
1623 std::istringstream is(result);
1626 for(int i = 0;i<numBoxes;i++)
1629 getline(inputStream,line);//BOX
1630 getline(inputStream,line);//package:type:name
1632 strcpy( box, line.c_str() );
1633 result = strtok( box, delims );//package
1634 std::string package(result);
1635 result = strtok( NULL, delims );//type
1636 std::string type(result);
1637 result = strtok( NULL, delims );//name
1638 std::string name(result);
1640 getline(inputStream,line);//ISEXEC:TRUE|FALSE
1642 strcpy( exec, line.c_str() );
1643 result = strtok( exec, delims );//ISEXEC
1644 result = strtok( NULL, delims );//TRUE|FALSE
1645 std::string isExec(result);
1648 getline(inputStream,line);//xInic:yInic:zInic
1650 strcpy( coord, line.c_str() );
1651 result = strtok( coord, delims );//xInic
1652 std::string xInic(result);
1653 result = strtok( NULL, delims );//yInic
1654 std::string yInic(result);
1655 result = strtok( NULL, delims );//zInic
1656 std::string zInic(result);
1658 double xIn, yIn, zIn;
1659 std::istringstream xSt(xInic);
1661 std::istringstream ySt(yInic);
1663 std::istringstream zSt(zInic);
1667 getline(inputStream,line);//xEnd:yEnd:zEnd
1668 strcpy( coord, line.c_str() );
1669 result = strtok( coord, delims );//xEnd
1670 std::string xEnd(result);
1671 result = strtok( NULL, delims );//yEnd
1672 std::string yEnd(result);
1673 result = strtok( NULL, delims );//zEnd
1674 std::string zEnd(result);
1676 double xEn, yEn, zEn;
1677 std::istringstream xEt(xEnd);
1679 std::istringstream yEt(yEnd);
1681 std::istringstream zEt(zEnd);
1684 bool boxExecutable=false;
1687 boxExecutable= true;
1690 int idBox = createGBlackBox(xIn,yIn,package,type);
1691 configGBlackBox(idBox, xIn,yIn,zIn,name, boxExecutable,xEn,yEn,zEn);
1693 GObjectController *cont = _controllers[idBox];
1694 GBlackBoxModel *bbmod = (GBlackBoxModel*)cont->getModel();
1698 // GObjectController *cont = _controllers[idBox];
1699 // GBlackBoxModel *bbmod = (GBlackBoxModel*)cont->getModel();
1700 // bbmod->setBBTKName(name);
1701 // bbmod->setInicPoint(xIn,yIn,zIn);
1702 // bbmod->setFinalPoint(xEn,yEn,zEn);
1703 // bbmod->setExecutable(boxExecutable);
1707 getline(inputStream,line);//PORT o FIN_BOX
1708 std::string port=line.substr(0,4);
1711 getline(inputStream,line);//name:value
1713 strcpy( poort, line.c_str() );
1714 result = strtok( poort, delims );//name
1715 std::string name(result);
1716 result = strtok( NULL, delims );//value
1717 std::string value(result);
1719 bbmod->setValueToInput(name,value);
1721 getline(inputStream,line);//PORT o FIN_BOX
1722 port=line.substr(0,4);
1725 //EED bbmod->notifyObservers(_idManager);
1730 getline(inputStream,line);//CONNECTIONS:num
1732 strcpy( conns, line.c_str() );
1733 result = strtok( conns, delims );
1734 result = strtok( NULL, delims );
1737 std::istringstream isCons(result);
1740 for(int i = 0;i<numConns;i++)
1743 getline(inputStream,line);//CONNECTION
1744 getline(inputStream,line);//Startbox.PortName:EndBox.PortName
1747 strcpy( connec, line.c_str() );
1748 result = strtok( connec, delims );
1749 std::string nameStartBox(result);
1750 result = strtok( NULL, delims );
1751 std::string nameStartPort(result);
1752 result = strtok( NULL, delims );
1753 std::string nameEndBox(result);
1754 result = strtok( NULL, delims );
1755 std::string nameEndPort(result);
1757 configGConnetion(nameStartBox, nameStartPort, nameEndBox, nameEndPort);
1760 std::vector<int> lstB = getBlackBoxes();
1761 GPortModel *startP = NULL;
1762 GPortModel *endP = NULL;
1764 for(j = 0;j<lstB.size();j++)
1767 GBlackBoxModel *bbMod = (GBlackBoxModel*)_controllers[idB]->getModel();
1768 if(_controllers[idB]->getModel()->getBBTKName()==nameStartBox)
1770 startP = bbMod->getOutputPort(nameStartPort);
1772 else if(_controllers[idB]->getModel()->getBBTKName()==nameEndBox)
1774 endP = bbMod->getInputPort(nameEndPort);
1782 std::vector<int> lstInputs = getComplexInputPorts();
1783 for(j = 0;j<lstInputs.size();j++)
1785 int idB = lstInputs[j];
1786 GBoxModel *cbMod = (GBoxModel*)_controllers[idB]->getModel();
1787 if(_controllers[idB]->getModel()->getBBTKName()==nameStartBox)
1789 startP = cbMod->getOutputPort(nameStartPort);
1796 std::vector<int> lstOutputs = getComplexOutputPorts();
1797 for(j = 0;j<lstOutputs.size();j++)
1799 int idB = lstOutputs[j];
1800 GBoxModel *cbMod = (GBoxModel*)_controllers[idB]->getModel();
1801 if(_controllers[idB]->getModel()->getBBTKName()==nameEndBox)
1803 endP = cbMod->getInputPort(nameEndPort);
1809 int idCon = createGConnector(startP);
1810 _worldState = NOTHING_HAPPENS;
1811 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
1813 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
1814 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
1815 tempp->endContourCreation();
1816 conMod->setEndPort(endP);
1817 conView->updateStartEndPoints();
1824 //=========================================================================
1828 //=========================================================================
1829 void wxVtkSceneManager::configGComBoxInputOutputPort(bool inputoutput, std::string portName, double xIn, double yIn,double zIn)
1832 if (inputoutput==true)
1834 idPort = createGComplexBoxInputPort(portName);
1836 idPort = createGComplexBoxOutputPort(portName);
1838 GObjectController *cont = _controllers[idPort];
1839 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
1840 cbmod->setInicPoint(xIn,yIn,zIn);
1841 cbmod->notifyObservers(_idManager);
1843 //=========================================================================
1846 //=========================================================================
1847 GBoxModel* wxVtkSceneManager::findGBox(std::string boxname)
1852 GBoxModel *boxModel = NULL;
1853 std::vector<int> lstB = getBlackBoxes();
1854 for(j = 0;j<(int)lstB.size();j++)
1857 bMod = (GBoxModel*)_controllers[idB]->getModel();
1858 if(_controllers[idB]->getModel()->getBBTKName()==boxname)
1864 if((_isComplexBox) && (boxModel==NULL))
1866 std::vector<int> lstInputs = getComplexInputPorts();
1867 for(j = 0;j<(int)lstInputs.size();j++)
1870 bMod = (GBoxModel*)_controllers[idB]->getModel();
1871 if(_controllers[idB]->getModel()->getBBTKName()==boxname)
1877 std::vector<int> lstOutputs = getComplexOutputPorts();
1878 for(j = 0;j<(int)lstOutputs.size();j++)
1880 int idB = lstOutputs[j];
1881 bMod = (GBoxModel*)_controllers[idB]->getModel();
1882 if(_controllers[idB]->getModel()->getBBTKName()==boxname)
1893 //=========================================================================
1896 void wxVtkSceneManager::configGConnetion(std::string nameStartBox, std::string nameStartPort, std::string
1897 nameEndBox, std::string nameEndPort)
1899 printf("EED wxVtkSceneManager::configGConnetion 1 %s %s %s %s\n", nameStartBox.c_str(), nameStartPort.c_str(), nameEndBox.c_str(), nameEndPort.c_str() );
1901 GBoxModel *boxModel;
1902 GPortModel *startP = NULL;
1903 GPortModel *endP = NULL;
1905 boxModel= findGBox(nameStartBox);
1908 startP = boxModel->getOutputPort(nameStartPort);
1911 boxModel= findGBox(nameEndBox);
1914 endP = boxModel->getInputPort(nameEndPort);
1918 printf("EED wxVtkSceneManager::configGConnetion 2 %p %p \n", startP, endP );
1921 std::vector<int> lstB = getBlackBoxes();
1923 for(j = 0;j<(int)lstB.size();j++)
1926 GBlackBoxModel *bbMod = (GBlackBoxModel*)_controllers[idB]->getModel();
1927 if(_controllers[idB]->getModel()->getBBTKName()==nameStartBox)
1929 startP = bbMod->getOutputPort(nameStartPort);
1931 else if(_controllers[idB]->getModel()->getBBTKName()==nameEndBox)
1933 endP = bbMod->getInputPort(nameEndPort);
1941 std::vector<int> lstInputs = getComplexInputPorts();
1942 for(j = 0;j<(int)lstInputs.size();j++)
1944 int idB = lstInputs[j];
1945 GBoxModel *cbMod = (GBoxModel*)_controllers[idB]->getModel();
1946 if(_controllers[idB]->getModel()->getBBTKName()==nameStartBox)
1948 startP = cbMod->getOutputPort(nameStartPort);
1955 std::vector<int> lstOutputs = getComplexOutputPorts();
1956 for(j = 0;j<(int)lstOutputs.size();j++)
1958 int idB = lstOutputs[j];
1959 GBoxModel *cbMod = (GBoxModel*)_controllers[idB]->getModel();
1960 if(_controllers[idB]->getModel()->getBBTKName()==nameEndBox)
1962 endP = cbMod->getInputPort(nameEndPort);
1969 int idCon = createGConnector(startP);
1970 _worldState = NOTHING_HAPPENS;
1971 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
1973 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
1974 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
1975 tempp->endContourCreation();
1976 conMod->setEndPort(endP);
1977 conView->updateStartEndPoints();
1980 //=========================================================================
1982 bool wxVtkSceneManager::boxExist(std::string boxname)
1985 std::map<int, GObjectController*>::iterator it;
1986 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1988 GObjectController *cont = it->second;
1989 if(cont->getModel()->getBBTKName()==boxname)
1997 //=========================================================================
1999 std::vector<int> wxVtkSceneManager::getBlackBoxes()
2001 std::vector<int> vect;
2002 std::map<int, GObjectController*>::iterator it;
2003 for(it = _controllers.begin(); it != _controllers.end(); ++it)
2005 GObjectController *cont = it->second;
2006 if(cont->getGObjectType()==GBLACKBOX)
2008 vect.push_back(cont->getId());
2014 //=========================================================================
2016 std::vector<int> wxVtkSceneManager::getComplexInputPorts()
2018 std::vector<int> vect;
2019 std::map<int, GObjectController*>::iterator it;
2020 for(it = _controllers.begin(); it != _controllers.end(); ++it)
2022 GObjectController *cont = it->second;
2023 if(cont->getGObjectType()==GCOMPLEXINPUTPORT)
2025 vect.push_back(cont->getId());
2031 //=========================================================================
2033 std::vector<int> wxVtkSceneManager::getComplexOutputPorts()
2035 std::vector<int> vect;
2036 std::map<int, GObjectController*>::iterator it;
2037 for(it = _controllers.begin(); it != _controllers.end(); ++it)
2039 GObjectController *cont = it->second;
2040 if(cont->getGObjectType()==GCOMPLEXOUTPUTPORT)
2042 vect.push_back(cont->getId());
2048 //=========================================================================
2050 std::vector<int> wxVtkSceneManager::getConnections()
2052 std::vector<int> vect;
2053 std::map<int, GObjectController*>::iterator it;
2054 for(it = _controllers.begin(); it != _controllers.end(); ++it)
2056 GObjectController *cont = it->second;
2057 if(cont->getGObjectType()==GCONNECTOR)
2059 vect.push_back(cont->getId());
2065 //=========================================================================
2067 bool wxVtkSceneManager::isComplexBox()
2069 return _isComplexBox;
2072 //=========================================================================
2074 void wxVtkSceneManager::setComplexBox(bool val)
2079 //=========================================================================
2081 int wxVtkSceneManager::addObjectController(GObjectController* objController)
2083 //Register the controller of the new object
2084 registerController((InteractorStyleMaracas*) objController);
2086 //Add the object to the objects list
2087 int newId = _contLastId;//_controllers.size();
2088 objController->setId(newId);
2089 _controllers[newId] = objController;
2094 //=========================================================================
2096 int wxVtkSceneManager::getNumSelectedObjects()
2098 return _selectedObjects.size();
2101 //=========================================================================
2103 std::map<int,GObjectController*> wxVtkSceneManager::getSelectedObjects()
2105 std::map<int,GObjectController*> mapSelected;
2107 std::map<int, GObjectController*>::iterator it;
2108 for(it = _controllers.begin(); it != _controllers.end(); ++it)
2110 GObjectController *cont = it->second;
2111 if(cont->getGObjectType()==GBLACKBOX && cont->getView()->getState()==SELECTED)
2113 mapSelected[cont->getId()]=cont;
2117 std::map<int, GObjectController*>::iterator it2;
2118 for(it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
2120 GObjectController *cont = it2->second;
2121 if(cont->getGObjectType()==GCONNECTOR)
2123 GConnectorModel* cmod = (GConnectorModel*)cont->getModel();
2124 GBoxModel* endPortParentBox = cmod->getEndPort()->getParentBox();
2125 GBoxModel* startPortParentBox = cmod->getStartPort()->getParentBox();
2127 std::map<int, GObjectController*>::iterator iterOBJ1 = mapSelected.find(startPortParentBox->getObjectId());
2128 std::map<int, GObjectController*>::iterator iterOBJ2 = mapSelected.find(endPortParentBox->getObjectId());
2130 if(iterOBJ1 != mapSelected.end() && iterOBJ2 != mapSelected.end())
2132 int ID = cont->getId();
2133 mapSelected[ID]=cont;
2141 //=========================================================================
2143 void wxVtkSceneManager::addObjects(std::map<int,GObjectController*> objectsMap)
2146 std::map<int,int> oldIdNewIdBoxes;
2147 std::vector<int> connections;
2149 std::map<int, GObjectController*>::iterator it;
2150 for(it = objectsMap.begin(); it != objectsMap.end(); ++it)
2152 GObjectController *cont = it->second;
2153 int type = cont->getGObjectType();
2158 double xInic, yInic,zInic;
2159 GBlackBoxModel* copyBox = (GBlackBoxModel*)cont->getModel();
2160 copyBox->getInicPoint(xInic,yInic,zInic);
2161 int idBox = createGBlackBox(0,0,copyBox->getBBTKPackage(),copyBox->getBBTKType());
2163 int idcB = copyBox->getObjectId();
2164 oldIdNewIdBoxes[idcB]=idBox;
2165 cont = _controllers[idBox];
2166 GBlackBoxModel* newbox = (GBlackBoxModel*)cont->getModel();
2167 newbox->setInicPoint(xInic,yInic,zInic);
2168 int num = newbox->getNumInputPorts();
2169 for(int j=0;j<num;j++)
2171 newbox->setValueToInputPort(j,copyBox->getValueInputPort(j));
2173 newbox->notifyObservers(_idManager);
2175 else if(type==GCONNECTOR)
2177 int idCon = cont->getId();
2178 connections.push_back(idCon);
2183 for(int i = 0 ;i<connections.size();i++)
2185 int objId = connections[i];
2186 GObjectController *cont = objectsMap[objId];
2187 GConnectorModel* connectModel = (GConnectorModel*)cont->getModel();
2189 GPortModel* startPort = connectModel->getStartPort();
2190 int startPortIndex = startPort->getPosInBox();
2191 GPortModel* endPort = connectModel->getEndPort();
2192 int endPortIndex = endPort->getPosInBox();
2194 GBlackBoxModel* startPortParentBox = (GBlackBoxModel*)startPort->getParentBox();
2195 GBlackBoxModel* endPortParentBox = (GBlackBoxModel*)endPort->getParentBox();
2197 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2198 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2200 GBlackBoxModel* newStartBox = (GBlackBoxModel*)_controllers[idNewStartBox]->getModel();
2201 GBlackBoxModel* newEndBox = (GBlackBoxModel*)_controllers[idNewEndBox]->getModel();
2203 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2204 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2206 // Creates connection
2207 int idCon = createGConnector(newStartPort);
2208 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
2209 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
2210 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
2211 tempp->endContourCreation();
2212 conMod->setEndPort(newEndPort);
2213 conView->updateStartEndPoints();
2216 std::map<int, int>::iterator itIds;
2217 for(itIds = oldIdNewIdBoxes.begin(); itIds != oldIdNewIdBoxes.end(); ++itIds)
2219 int idOld = itIds->first;
2220 int idNew = itIds->second;
2222 GBlackBoxModel* oldBox = (GBlackBoxModel*)objectsMap[idOld]->getModel();
2223 GBlackBoxModel* newBox = (GBlackBoxModel*)_controllers[idNew]->getModel();
2225 std::vector<int> oldInputConnections = oldBox->getConnectedInputs();
2226 std::vector<int> oldOutputConnections = oldBox->getConnectedOutputs();
2227 std::vector<int> newInputConnections = newBox->getConnectedInputs();
2228 std::vector<int> newOutputConnections = newBox->getConnectedOutputs();
2230 for(int k = 0; k<(int)oldInputConnections.size();k++)
2233 //EED int toCreate=-1;
2234 for(int l = 0; l<(int)newInputConnections.size() && !exist;l++)
2236 if(oldInputConnections[k]==newInputConnections[l])
2244 //Create complex input
2245 int posInBox = oldInputConnections[k];
2246 GPortModel* inputPort = oldBox->getInputPort(posInBox);
2247 std::string inputPortName = inputPort->getBBTKName();
2248 int idInputPort = createGComplexBoxInputPort(inputPortName);
2249 GObjectController *cont = _controllers[idInputPort];
2250 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
2252 inputPort->getInicPoint(xIn,yIn,zIn);
2254 cbmod->setInicPoint(xIn,yIn,zIn);
2255 cbmod->notifyObservers(_idManager);
2257 GPortModel* inputPortEnd = newBox->getInputPort(posInBox);
2259 // Creates connection
2260 int idCon = createGConnector(cbmod->getOutputPort(0));
2261 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
2262 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
2263 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
2264 tempp->endContourCreation();
2265 conMod->setEndPort(inputPortEnd);
2266 conView->updateStartEndPoints();
2273 for(int k = 0; k<(int)oldOutputConnections.size();k++)
2276 //EED int toCreate=-1;
2277 for(int l = 0; l<(int)newOutputConnections.size() && !exist;l++)
2279 if(oldOutputConnections[k]==newOutputConnections[l])
2287 //Create complex output
2288 int posInBox = oldOutputConnections[k];
2289 GPortModel* outputPort = oldBox->getOutputPort(posInBox);
2290 std::string outputPortName = outputPort->getBBTKName();
2291 int idOutputPort = createGComplexBoxOutputPort(outputPortName);
2292 GObjectController *cont = _controllers[idOutputPort];
2293 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
2295 outputPort->getInicPoint(xIn,yIn,zIn);
2297 cbmod->setInicPoint(xIn,yIn,zIn);
2298 cbmod->notifyObservers(_idManager);
2300 GPortModel* outputPortEnd = newBox->getOutputPort(posInBox);
2302 // Creates connection
2303 int idCon = createGConnector(outputPortEnd);
2304 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
2305 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
2306 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
2307 tempp->endContourCreation();
2308 conMod->setEndPort(cbmod->getInputPort(0));
2309 conView->updateStartEndPoints();
2320 //=========================================================================
2322 } // EO namespace bbtk