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();
108 _textActor = vtkTextActor3D::New();
109 _textActor->SetPosition( -9999 , -9999 , 900 );
110 _textActor->SetInput( "<void>" );
111 _textActor->GetTextProperty()->SetFontSize(80);
112 _textActor->GetTextProperty()->BoldOn();
113 _textActor->GetTextProperty()->SetColor(PORTTEXT_NH_R,PORTTEXT_NH_G,PORTTEXT_NH_B);
115 _baseView->GetRenderer()->AddActor( _textActor );
118 // Actor Fill_Port_Text
124 vtkCellArray *strip = vtkCellArray::New();
125 vtkPolyData *pdFill = vtkPolyData::New();
126 _fillObjectActor = vtkActor::New();
127 _fillPolyMapper = vtkPolyDataMapper::New();
128 _pts = vtkPoints::New();
130 _pts->SetNumberOfPoints(4);
131 _pts->SetPoint(0, xInic , yInic , zInic );
132 _pts->SetPoint(1, xInic+50 , yInic , zInic );
133 _pts->SetPoint(2, xInic+50 , yInic+50 , zInic );
134 _pts->SetPoint(3, xInic , yInic+50 , zInic );
135 strip->InsertNextCell(5);
136 strip->InsertCellPoint(0);
137 strip->InsertCellPoint(1);
138 strip->InsertCellPoint(2);
139 strip->InsertCellPoint(0);
140 strip->InsertCellPoint(3);
141 pdFill->SetPoints( _pts );
142 pdFill->SetStrips( strip );
143 _fillPolyMapper->SetInput(pdFill);
144 _fillObjectActor->SetMapper(_fillPolyMapper);
145 _fillObjectActor->GetProperty()->SetColor(PORTFILL_NH_R,PORTFILL_NH_G,PORTFILL_NH_B);
146 _fillPolyMapper->Modified();
148 _baseView->GetRenderer()->AddActor( _fillObjectActor );
151 //=========================================================================
153 std::string wxVtkSceneManager::generateANewNameForABox()
155 std::stringstream boxname;
158 boxname << "Box0" << _numBoxes;
160 boxname << "Box" << _numBoxes;
163 return boxname.str();
166 //=========================================================================
168 std::string wxVtkSceneManager::findANewNameForABox()
170 std::string boxname=generateANewNameForABox();
172 while (boxExist(boxname)==true)
174 boxname=generateANewNameForABox();
180 //=========================================================================
181 void wxVtkSceneManager::configGBlackBox(int idBox, double xIn, double yIn, double zIn, std::string name, bool boxExecutable,double xEn,double yEn,double zEn)
183 GObjectController *cont = _controllers[idBox];
184 GBlackBoxModel *bbmod = (GBlackBoxModel*)cont->getModel();
185 bbmod->setBBTKName(name);
186 bbmod->setInicPoint(xIn,yIn,zIn);
187 bbmod->setFinalPoint(xEn,yEn,zEn);
188 bbmod->setExecutable(boxExecutable);
190 bbmod->notifyObservers(_idManager);
195 //=========================================================================
197 int wxVtkSceneManager::createGBlackBox(int x, int y, std::string packageName, std::string boxType)
199 _worldState = NOTHING_HAPPENS;
200 //EED int windowWidth = _baseView->GetRenWin()->GetSize()[0];
201 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
203 int type = GBLACKBOX;
205 //Create the MVC Objects
207 GBlackBoxModel *model = (GBlackBoxModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
208 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
209 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
211 BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxType);
213 //Prepares the initial model
214 //The coordinates obtained are the following. Top-Left:x=0,y=0 Bottom-Right:x=width,y=height
217 double yy = windowHeight-y;
219 //z value is not important yet, because it is only used a parallel projection
222 _baseView->TransCoordScreenToWorld(xx,yy,zz);
223 model->setInicPoint(xx,yy,zz);
225 std::stringstream stream;
227 std::string newBoxName;
228 newBoxName = findANewNameForABox();
231 stream << newBoxName;
233 std::string arraystring = stream.str();
235 model->setBBTKName(arraystring);
236 model->setBBTKType(boxType);
237 model->setBBTKPackage(packageName);
239 model->addObserver(view);
240 model->addObserver(this);
242 //Iterate and create the input ports
243 std::map<std::string, BlackBoxInputDescriptor*> descriptorInMap = descriptor->GetInputDescriptorMap();
244 std::map<std::string, BlackBoxInputDescriptor*>::iterator itInput;
247 for(itInput = descriptorInMap.begin(); itInput != descriptorInMap.end(); ++itInput)
249 BlackBoxInputDescriptor *desc = itInput->second;
250 createGInputPort(GINPUTPORT,i,model,desc);
254 //Iterate and create the output ports
255 std::map<std::string, BlackBoxOutputDescriptor*> descriptorOutMap = descriptor->GetOutputDescriptorMap();
256 std::map<std::string, BlackBoxOutputDescriptor*>::iterator itOutput;
259 for(itOutput = descriptorOutMap.begin();itOutput != descriptorOutMap.end(); ++itOutput)
261 BlackBoxOutputDescriptor *desc = itOutput->second;
262 createGOutputPort(GOUTPUTPORT,i,model,desc);
267 //Associates the view with the correspondent renderer and the model.
268 //(NOTE: Refresh is only made by the view)
269 view->setModel(model);
270 view->setBaseView(_baseView);
271 view->initVtkObjects();
273 //Associates the controller with the correspondent model and view
274 controller->setModelAndView(model,view);
276 //Resgiter change to the observers of the actual model
277 model->notifyObservers(_idManager);
279 int newId = addObjectController(controller);
285 //=========================================================================
287 int wxVtkSceneManager::createGComplexBoxInputPort(std::string inputName)
289 //EED int windowWidth=_baseView->GetRenWin()->GetSize()[0];
290 int windowHeight=_baseView->GetRenWin()->GetSize()[1];
292 int type = GCOMPLEXINPUTPORT;
294 //Create the MVC Objects
296 GComplexBoxPortModel *model = (GComplexBoxPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
297 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
298 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
300 //Prepares the initial model
303 double yy = windowHeight-5;
305 //z value is not important yet, because it is only used a parallel projection
308 _baseView->TransCoordScreenToWorld(xx,yy,zz);
309 model->setInicPoint(xx,yy,zz);
311 model->setBBTKName(inputName);
312 model->setBBTKType("ComplexInputPort");
313 model->setComplexPortType(type);
315 model->addObserver(view);
316 model->addObserver(this);
318 //create the output port
319 GPortController* portController = createGPort(GOUTPUTPORT,inputName,"ComplexInputPort",0,model);
320 model->addOutputPort((GPortModel*)portController->getModel());
322 //Associates the view with the correspondent renderer and the model.
323 //(NOTE: Refresh is only made by the view)
324 view->setModel(model);
325 view->setBaseView(_baseView);
326 view->initVtkObjects();
328 //Associates the controller with the correspondent model and view
329 controller->setModelAndView(model,view);
331 //Resgiter change to the observers of the actual model
332 model->notifyObservers(_idManager);
334 int newId = addObjectController(controller);
338 //=========================================================================
340 int wxVtkSceneManager::createGComplexBoxOutputPort(std::string outputName)
342 //EED int windowWidth=_baseView->GetRenWin()->GetSize()[0];
343 int windowHeight=_baseView->GetRenWin()->GetSize()[1];
345 int type = GCOMPLEXOUTPUTPORT;
347 //Create the MVC Objects
349 GComplexBoxPortModel *model = (GComplexBoxPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
350 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
351 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
353 //Prepares the initial model
356 double yy = windowHeight-5;
358 //z value is not important yet, because it is only used a parallel projection
361 _baseView->TransCoordScreenToWorld(xx,yy,zz);
362 model->setInicPoint(xx,yy,zz);
364 model->setBBTKName(outputName);
365 model->setBBTKType("ComplexOutputPort");
366 model->setComplexPortType(type);
368 model->addObserver(view);
369 model->addObserver(this);
371 //create the output port
372 GPortController* portController = createGPort(GINPUTPORT,outputName,"ComplexInputPort",0,model);
373 model->addInputPort((GPortModel*)portController->getModel());
375 //Associates the view with the correspondent renderer and the model.
376 //(NOTE: Refresh is only made by the view)
377 view->setModel(model);
378 view->setBaseView(_baseView);
379 view->initVtkObjects();
381 //Associates the controller with the correspondent model and view
382 controller->setModelAndView(model,view);
384 //Resgiter change to the observers of the actual model
385 model->notifyObservers(_idManager);
387 int newId = addObjectController(controller);
391 //=========================================================================
393 int wxVtkSceneManager::createGInputPort(int portType, int posinBox,GBoxModel *blackBox, BlackBoxInputDescriptor *desc)
395 GPortController* portController = createGPort(portType,desc->GetName(),desc->GetTypeName(),posinBox,blackBox);
396 blackBox->addInputPort((GPortModel*)portController->getModel());
397 return portController->getId();
400 //=========================================================================
402 int wxVtkSceneManager::createGOutputPort(int portType, int posinBox,GBoxModel *blackBox, BlackBoxOutputDescriptor *desc)
404 GPortController* portController = createGPort(portType,desc->GetName(),desc->GetTypeName(),posinBox,blackBox);
405 blackBox->addOutputPort((GPortModel*)portController->getModel());
406 return portController->getId();
409 //=========================================================================
411 GPortController* wxVtkSceneManager::createGPort(int portType,std::string bbtkName, std::string bbtkType, int posInBox,GBoxModel *blackBox)
415 //Create the MVC Objects
416 GPortModel *model = (GPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
417 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
418 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
420 model->registerInBox(blackBox,portType, posInBox);
422 model->setBBTKType(bbtkType);
423 model->setBBTKName(bbtkName);
425 model->addObserver(view);
426 model->addObserver(this);
428 //Associates the view with the correspondent renderer and the model.
429 //(NOTE: Refresh is only made by the view)
430 view->setModel(model);
431 view->setBaseView(_baseView);
432 view->initVtkObjects();
434 //Associates the controller with the correspondent model and view
435 controller->setModelAndView(model,view);
437 model->notifyObservers(_idManager);
439 addObjectController(controller);
441 return (GPortController*)controller;
444 //=========================================================================
446 int wxVtkSceneManager::createGConnector(GPortModel* startPort)
448 int type = GCONNECTOR;
450 manualConnectorContourController* manContourControl = new manualConnectorContourController();
451 manualConnectorContourView* manContourView = new manualConnectorContourView();
452 manualContourModel* manContourModel = new manualContourModel();
454 GConnectorController* connectorcontroller = new GConnectorController();
455 GConnectorModel* connectorModel = new GConnectorModel();
456 vtkGConnectorView* connectorView = new vtkGConnectorView();
457 connectorModel->setGObjectType(type);
459 manContourModel->SetCloseContour(false);
460 connectorModel->setStartPort(startPort);
462 manContourView->SetModel( manContourModel );
463 manContourView->SetWxVtkBaseView( _baseView );
464 manContourView->SetRange( 0.5 );
465 manContourView->SetZ( 900 );
467 manContourView->SetColorNormalContour(0, 0, 1);
468 manContourView->SetColorEditContour(0.5, 0.5, 0.5);
469 manContourView->SetColorSelectContour(1, 0.8, 0);
470 manContourView->SetWidthLine(1);
471 manContourView->SetShowText(false);
473 manContourControl->SetModelView( manContourModel , manContourView );
475 manContourControl->CreateNewManualContour();
477 manContourView->RefreshContour();
481 connectorModel->getInicPoint(x,y,z);
483 manContourControl->SetState(1);
484 manContourModel->SetCloseContour(false);
486 manContourModel->AddPoint(x,y,z);
487 manContourView->AddPoint();
489 manContourModel->AddPoint(x,y,z);
490 manContourView->AddPoint();
492 int bak= manContourControl->GetNumberOfPointsManualContour() - 1;
493 manContourControl->_bakIdPoint=bak;
494 manContourView->Refresh();
496 manContourControl->SetMoving( false );
498 connectorcontroller->setModelAndView(connectorModel,connectorView);
500 int newId = addObjectController(connectorcontroller);
502 connectorcontroller->setManualContourController(manContourControl);
503 connectorModel->setManualContourModel(manContourModel);
504 connectorView->setManualContourView(manContourView);
505 connectorView->setModel(connectorModel);
506 connectorView->setBaseView(_baseView);
509 connectorModel->addObserver(connectorView);
510 connectorModel->addObserver(this);
515 //=========================================================================
517 void wxVtkSceneManager::registerController(InteractorStyleMaracas *param)
519 vtkInteractorStyleBaseView* baseViewControlManager = (vtkInteractorStyleBaseView*)_baseView->GetInteractorStyleBaseView();
520 baseViewControlManager->AddInteractorStyleMaracas( param );
523 //=========================================================================
525 void wxVtkSceneManager::unregisterController(InteractorStyleMaracas *param)
527 vtkInteractorStyleBaseView* baseViewControlManager = (vtkInteractorStyleBaseView*)_baseView->GetInteractorStyleBaseView();
528 baseViewControlManager->RemoveInteractorStyleMaracas( param );
531 //=========================================================================
533 vtkRenderer* wxVtkSceneManager::getRenderer()
535 return _baseView->GetRenderer();
538 //=========================================================================
540 vtkRenderWindow* wxVtkSceneManager::getRenderWindow()
542 return _baseView->GetRenWin();
544 //=========================================================================
547 void wxVtkSceneManager::update(int idController,int command)
549 if(command != NO_COMMAND)
551 if(command == ADD_TO_SELECTED)
553 //EED GObjectController* cont = _controllers[idController];
556 for (int i=0; i<(int)_selectedObjects.size() && foundID==false; i++)
558 int id = _selectedObjects[i];
566 int id = idController;
567 _selectedObjects.push_back(id);
571 else if(command == INIT_CREATION_CONTOUR)
573 _worldState = INIT_CREATION_CONTOUR;
574 GObjectController* cont = _controllers[idController];
575 GPortModel* startOutputPort = (GPortModel*)cont->getModel();
578 // The last one is the controller of the connector
579 std::map<int, GObjectController*>::iterator it2;
581 for(it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
583 GObjectController *cont = it2->second;
584 if(cont->getGObjectType() == GPORT )
586 GPortModel* port = (GPortModel*)cont->getModel();
587 if(port->getPortType()==GINPUTPORT)
589 cont->SetActive(true);
593 cont->getView()->setState(NOTHING_HAPPENS);
594 cont->getModel()->notifyObservers(_idManager);
595 cont->SetActive(false);
600 cont->getView()->setState(NOTHING_HAPPENS);
601 cont->getModel()->notifyObservers(_idManager);
602 cont->SetActive(false);
606 _selectedObjects.clear();
608 _idConnectionInCreation=createGConnector(startOutputPort);
611 else if(command == FIN_CREATION_CONTOUR && _worldState == INIT_CREATION_CONTOUR)
613 _worldState = NOTHING_HAPPENS;
614 //int id = _controllers.size()-1;
615 GObjectController* cont = _controllers[_idConnectionInCreation];
616 GConnectorModel* modelContour = (GConnectorModel*)cont->getModel();
618 GObjectController* finPort = _controllers[idController];
619 if(finPort->getGObjectType() == GPORT)
621 GPortModel* modelPort = (GPortModel*)finPort->getModel();
622 modelContour->setEndPort(modelPort);
625 manualConnectorContourController* manCont = ((GConnectorController*)cont)->getManualContourController();
626 manualConnectorContourView* connView = (manualConnectorContourView*)manCont->GetManualViewBaseContour();
629 std::map<int, GObjectController*>::iterator it2;
631 for(it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
633 GObjectController *cont = it2->second;
634 if(cont->getView()!=NULL)
636 cont->getView()->setState(NOTHING_HAPPENS);
637 cont->getModel()->notifyObservers(_idManager);
639 cont->SetActive(true);
646 //=========================================================================
648 bool wxVtkSceneManager::OnMouseMove()
651 bool okStatusMessage = false;
652 bool okPortMessage = false;
653 wxVTKRenderWindowInteractor *wxVTKiren;
654 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
655 wxVTKiren->GetEventPosition(X,Y);
658 if(_worldState == DRAG_OBJECTS)
660 for (int i=0; i<(int)_selectedObjects.size(); i++)
662 int id = _selectedObjects[i];
663 GObjectController* cont = _controllers[id];
666 cont->getView()->setStartDragging(true);
668 cont->getView()->moveObject(X,Y);
669 cont->getView()->setState(DRAG);
670 cont->getModel()->notifyObservers(_idManager);
673 std::map<int, GObjectController*>::iterator it;
675 for(it = _controllers.begin(); it != _controllers.end(); ++it)
677 GObjectController *desc = it->second;
678 if(desc->getGObjectType()==GCONNECTOR)
680 vtkGConnectorView* vconn = (vtkGConnectorView*)desc->getView();
681 vconn->updateStartEndPoints();
685 _startDragging=false;
688 else if(_worldState == NOTHING_HAPPENS || _worldState == INIT_CREATION_CONTOUR)
690 std::map<int, GObjectController*>::iterator it;
692 for(it = _controllers.begin(); it != _controllers.end(); ++it)
694 GObjectController *desc = it->second;
695 int type = desc->getGObjectType();
696 int state = desc->getView()->getState();
697 desc->getModel()->getCenter(px,py,pz);
699 if(state == HIGHLIGHTED){
700 okStatusMessage = true;
701 updateStatusBar(desc->getStatusText());
704 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
705 _parent->displayBlackBoxInfo(mod->getBBTKPackage(),mod->getBBTKType());
710 okPortMessage = true;
711 _textActor->SetInput( desc->getStatusText().c_str() );
712 _textActor->SetScale(0.1);
713 _textActor->SetPosition( px-25 ,py , pz+2 );
717 _pts->SetPoint(0, px , py , 900+1 );
718 _pts->SetPoint(1, px+100, py , 900+1 );
719 _pts->SetPoint(2, px+100, py+10 , 900+1 );
720 _pts->SetPoint(3, px , py+10 , 900+1 );
721 _fillPolyMapper->Modified();
725 } // for controllers it
729 if (okStatusMessage==false)
734 if (okPortMessage==false)
736 _textActor->SetScale(0.0001);
743 //=========================================================================
745 bool wxVtkSceneManager::OnLeftButtonDown()
747 if(_worldState==INIT_CREATION_CONTOUR)
749 bool isOverPort=false;
750 std::map<int, GObjectController*>::iterator it;
751 for(it = _controllers.begin(); it != _controllers.end() && isOverPort==false; ++it)
753 GObjectController *desc = it->second;
754 if(desc->getGObjectType()==GPORT)
756 GPortModel* portmod=(GPortModel*)desc->getModel();
757 vtkGObjectView* portView=desc->getView();
758 if(portmod->getPortType()==GINPUTPORT && portView->getState()==HIGHLIGHTED)
765 if(isOverPort==false)
767 _worldState=NOTHING_HAPPENS;
768 //int lastId = _controllers.size()-1;
769 GConnectorController *connector = (GConnectorController*)_controllers[_controllers.size()-1];
770 connector->removeFromScene();
771 unregisterController(connector);
772 _controllers.erase(_controllers.size()-1);
774 for(it = _controllers.begin(); it != _controllers.end(); ++it)
776 GObjectController *desc = it->second;
777 desc->SetActive(true);
778 desc->getView()->setState(NOTHING_HAPPENS);
779 desc->getModel()->notifyObservers(_idManager);
784 if(_selectedObjects.size()!=0)
786 _worldState = DRAG_OBJECTS;
787 _startDragging = true;
789 for (int i = 0; i < (int)_selectedObjects.size(); i++)
791 int id = _selectedObjects[i];
792 GObjectController* cont = _controllers[id];
793 cont->getView()->setState(DRAG);
794 cont->getModel()->notifyObservers(_idManager);
803 //=========================================================================
805 bool wxVtkSceneManager::OnLeftButtonUp()
807 if(_worldState == DRAG_OBJECTS)
809 _worldState = NOTHING_HAPPENS;
811 for (int i = 0; i < (int)_selectedObjects.size(); i++)
813 int id = _selectedObjects[i];
814 GObjectController* cont = _controllers[id];
815 cont->getView()->setState(SELECTED);
816 cont->getModel()->notifyObservers(_idManager);
822 //=========================================================================
824 bool wxVtkSceneManager::OnRightButtonUp()
826 if(_worldState==INIT_CREATION_CONTOUR)
828 _worldState=NOTHING_HAPPENS;
829 //int lastId = _controllers.size()-1;
830 GConnectorController *connector = (GConnectorController*)_controllers[_idConnectionInCreation];
831 connector->removeFromScene();
832 unregisterController(connector);
833 _controllers.erase(_idConnectionInCreation);
835 std::map<int, GObjectController*>::iterator it;
836 for(it = _controllers.begin(); it != _controllers.end(); ++it)
838 GObjectController *desc = it->second;
839 desc->SetActive(true);
840 desc->getView()->setState(NOTHING_HAPPENS);
841 desc->getModel()->notifyObservers(_idManager);
846 for (int i = 0; i < (int)_selectedObjects.size(); i++)
848 int id = _selectedObjects[i];
849 GObjectController* cont = _controllers[id];
850 cont->SetActive(true);
851 cont->getView()->setState(NOTHING_HAPPENS);
852 cont->getModel()->notifyObservers(_idManager);
855 _selectedObjects.clear();
860 //=========================================================================
862 bool wxVtkSceneManager::OnLeftDClick()
865 wxVTKRenderWindowInteractor *wxVTKiren;
866 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
867 wxVTKiren->GetEventPosition(X,Y);
869 std::map<int, GObjectController*>::iterator it;
871 bool clickOnObject = false;
873 for(it = _controllers.begin(); it != _controllers.end() && clickOnObject==false; ++it)
875 GObjectController *cont = it->second;
876 int type = cont->getGObjectType();
878 if(cont->getView()->isPointInside(X,Y))
882 for (int i=0; i< (int)_selectedObjects.size(); i++)
884 int id = _selectedObjects[i];
885 GObjectController* control = _controllers[id];
886 control->getView()->setState(NOTHING_HAPPENS);
888 _selectedObjects.clear();
890 GBlackBoxModel *bbmodel = (GBlackBoxModel*)cont->getModel();
891 _parent->editBlackBox(bbmodel);
893 clickOnObject = true;
897 if(clickOnObject==false)
899 //_parent->editDiagramParameters(this);
905 //=========================================================================
907 bool wxVtkSceneManager::OnChar()
909 char keyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
911 // KeyCode 127 : Delete Key
912 // KeyCode 8 : Backspace Key
913 if(keyCode == 8 || keyCode == 127)
915 if(_selectedObjects.size()>0)
917 for(int i=0;i<(int)_selectedObjects.size();i++)
919 int id = _selectedObjects[i];
920 std::map<int,GObjectController*>::iterator it;
921 it = _controllers.find(id);
922 if (it!=_controllers.end())
927 _selectedObjects.clear();
934 //=========================================================================
936 void wxVtkSceneManager::AddControlerToBeRemove(std::vector<int> *controllersToRemove, int id)
941 for(i=0 ; i < (int)controllersToRemove->size() ; i++ )
943 if (id == (*controllersToRemove)[i] )
951 controllersToRemove->push_back( id );
956 //=========================================================================
958 void wxVtkSceneManager::deleteObject(int id)
960 GObjectController *control = _controllers[id];
961 std::vector<int> controllersToRemove;
963 if(control->getGObjectType()==GBLACKBOX || control->getGObjectType()==GCOMPLEXINPUTPORT || control->getGObjectType()==GCOMPLEXOUTPUTPORT)
965 GBoxModel *bbmod = (GBoxModel*)control->getModel();
966 std::vector<GPortModel*> inputs = bbmod->getInputPorts();
968 bool boxConnected = false;
970 // Add box input controllers to be removed
971 for(int i = 0;i< (int)inputs.size();i++)
973 AddControlerToBeRemove( &controllersToRemove, inputs[i]->getObjectId() );
974 if(inputs[i]->isConnected())
980 std::vector<GPortModel*> outputs = bbmod->getOutputPorts();
982 // Add box output controllers to be removed
983 for(int i = 0;i<(int)outputs.size();i++)
985 AddControlerToBeRemove( &controllersToRemove, outputs[i]->getObjectId() );
986 if(outputs[i]->isConnected())
992 // Add connection controllers to be removed
993 std::map<int, GObjectController*>::iterator it;
994 for(it = _controllers.begin(); it != _controllers.end(); ++it)
996 GObjectController *cont = it->second;
997 int type = cont->getGObjectType();
1000 GConnectorModel *conMod = (GConnectorModel*)cont->getModel();
1001 if(conMod->getStartPort()!=NULL && conMod->getStartPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
1003 AddControlerToBeRemove( &controllersToRemove, conMod->getObjectId() );
1005 if(conMod->getEndPort()!=NULL && conMod->getEndPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
1007 AddControlerToBeRemove( &controllersToRemove, conMod->getObjectId() );
1012 // Add box controller to be removed
1013 AddControlerToBeRemove( &controllersToRemove, bbmod->getObjectId() );
1015 else if(control->getGObjectType()==GCONNECTOR)
1017 GConnectorModel *conMod = (GConnectorModel*)control->getModel();
1018 AddControlerToBeRemove( &controllersToRemove, conMod->getObjectId() );
1022 std::map<int,GObjectController*>::iterator it;
1024 for(int i = 0;i<(int)controllersToRemove.size();i++)
1026 int key = controllersToRemove[i];
1027 it = _controllers.find( key );
1028 GObjectController *cont = _controllers[ key ];
1031 cont->removeFromScene();
1032 unregisterController((InteractorStyleMaracas*)cont);
1033 _controllers.erase(it);
1038 //=========================================================================
1040 void wxVtkSceneManager::displayBlackBoxInfo(std::string packageName, std::string boxName)
1042 _parent->displayBlackBoxInfo(packageName,boxName);
1045 //=========================================================================
1047 void wxVtkSceneManager::updateStatusBar(std::string textStatus)
1049 _parent->updateStatusBar(textStatus);
1052 //=========================================================================
1054 std::string wxVtkSceneManager::getDiagramBBS()
1056 bool existsExec=false;
1058 std::vector<std::string> packages;
1059 std::vector<int> boxes;
1060 std::vector<int> connections;
1061 std::vector<int> execBoxes;
1063 std::map<int, GObjectController*>::iterator it;
1065 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1067 GObjectController *desc = it->second;
1068 int type = desc->getGObjectType();
1072 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
1074 std::string pkg = mod->getBBTKPackage();
1075 bool existsPkg = false;
1076 for(int t = 0;t< (int)packages.size() && existsPkg == false;t++)
1078 if(packages[t]==pkg)
1085 packages.push_back(pkg);
1089 boxes.push_back(it->first);
1090 if(mod->isExecutable())
1092 execBoxes.push_back(it->first);
1096 else if(type==GCONNECTOR)
1098 connections.push_back(it->first);
1102 std::string script = "";
1103 script+="# BBTK GEditor Script\n";
1104 script+="# ----------------------\n";
1108 script+="include std\n"; // EED
1109 script+="include itkvtk\n"; // EED
1111 for(i = 0; i< (int)packages.size();i++)
1114 script+=packages[i];
1119 // script+="include std\n"; // JPR
1121 for(i = 0; i < (int)boxes.size();i++)
1125 GObjectController *control = _controllers[id];
1126 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1128 script+=model->getBBTKType();
1130 script+=model->getBBTKName();
1133 std::vector<GPortModel*> inputs = model->getInputPorts();
1134 for(int j = 0; j < (int)inputs.size();j++)
1136 GPortModel* inputPort = inputs[j];
1137 if(inputPort->isValueSet())
1140 script+=model->getBBTKName();
1142 script+=inputPort->getBBTKName();
1144 script+=inputPort->getValue();
1154 for(i = 0; i<(int)connections.size();i++)
1157 int id = connections[i];
1158 GObjectController *control = _controllers[id];
1159 GConnectorModel *model = (GConnectorModel*)control->getModel();
1161 //Start Connection info
1162 GPortModel *start = model->getStartPort();
1163 script+=start->getParentBox()->getBBTKName();
1165 script+=start->getBBTKName();
1169 //End Connection info
1170 GPortModel *end = model->getEndPort();
1171 script+=end->getParentBox()->getBBTKName();
1173 script+=end->getBBTKName();
1179 for(i = 0; i<(int)execBoxes.size();i++)
1182 int id = execBoxes[i];
1183 GObjectController *control = _controllers[id];
1184 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1186 script+=model->getBBTKName();
1195 //=========================================================================
1197 std::string wxVtkSceneManager::saveComplexBoxBBS(std::string cbName,std::string cbAuthor,std::string cbCategory,std::string cbDescription)
1200 std::vector<std::string> packages;
1201 std::vector<int> boxes;
1202 std::vector<int> connections;
1203 std::vector<int> execBoxes;
1205 std::map<int, GObjectController*>::iterator it;
1207 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1209 GObjectController *desc = it->second;
1210 int type = desc->getGObjectType();
1214 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
1216 std::string pkg = mod->getBBTKPackage();
1217 bool existsPkg = false;
1218 for(int t = 0;t<(int)packages.size() && existsPkg == false;t++)
1220 if(packages[t]==pkg)
1227 packages.push_back(pkg);
1231 boxes.push_back(it->first);
1232 if(mod->isExecutable())
1234 execBoxes.push_back(it->first);
1237 else if(type==GCONNECTOR)
1239 connections.push_back(it->first);
1243 std::string script = "";
1245 script+="include std\n"; // EED
1246 script+="include itkvtk\n"; // EED
1248 for(i = 0; i<(int)packages.size();i++)
1251 script+=packages[i];
1256 // Definition of a complex box
1262 script+="author \" ";
1266 script+="description \" ";
1267 script+=cbDescription;
1272 for(i = 0; i<(int)boxes.size();i++)
1276 GObjectController *control = _controllers[id];
1277 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1279 script+=model->getBBTKType();
1281 script+=model->getBBTKName();
1284 std::vector<GPortModel*> inputs = model->getInputPorts();
1285 for(int j = 0; j<(int)inputs.size();j++)
1287 GPortModel* inputPort = inputs[j];
1288 if(inputPort->isValueSet())
1291 script+=model->getBBTKName();
1293 script+=inputPort->getBBTKName();
1295 script+=inputPort->getValue();
1303 // Create connections in the script. If the connection is made with a complex port, it is created the input or output
1305 std::string complexInputs="";
1306 std::string complexOutputs="";
1309 for(i = 0; i<(int)connections.size();i++)
1311 int id = connections[i];
1312 GObjectController *control = _controllers[id];
1313 GConnectorModel *model = (GConnectorModel*)control->getModel();
1316 GPortModel *start = model->getStartPort();
1317 GBoxModel *startBox =start->getParentBox();
1319 GPortModel *end = model->getEndPort();
1320 GBoxModel *endBox =end->getParentBox();
1322 if(startBox->getGObjectType()==GCOMPLEXINPUTPORT)
1324 complexInputs+="input ";
1325 complexInputs+=startBox->getBBTKName();
1328 complexInputs+=endBox->getBBTKName();
1330 complexInputs+=end->getBBTKName();
1333 complexInputs+="\" \"";
1335 complexInputs+="\n";
1337 else if(endBox->getGObjectType()==GCOMPLEXOUTPUTPORT)
1339 complexOutputs+="output ";
1340 complexOutputs+=endBox->getBBTKName();
1342 complexOutputs+=" ";
1343 complexOutputs+=startBox->getBBTKName();
1344 complexOutputs+=".";
1345 complexOutputs+=start->getBBTKName();
1347 complexOutputs+=" ";
1348 complexOutputs+="\" \"";
1350 complexOutputs+="\n";
1355 script+=startBox->getBBTKName();
1357 script+=start->getBBTKName();
1361 //End Connection info
1362 script+=endBox->getBBTKName();
1364 script+=end->getBBTKName();
1372 for(i = 0; i<(int)execBoxes.size();i++)
1375 int id = execBoxes[i];
1376 GObjectController *control = _controllers[id];
1377 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1379 script+=model->getBBTKName();
1384 script+="# Complex input ports\n";
1385 script+=complexInputs;
1388 script+="# Complex output ports\n";
1389 script+=complexOutputs;
1398 //=========================================================================
1400 void wxVtkSceneManager::deleteAllBoxes()
1402 std::map<int, GObjectController*>::iterator it;
1403 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1405 GObjectController *cont = it->second;
1406 cont->removeFromScene();
1407 unregisterController((InteractorStyleMaracas*)cont);
1409 _selectedObjects.clear();
1410 _controllers.clear();
1414 //=========================================================================
1416 void wxVtkSceneManager::refreshScene()
1418 _baseView->RefreshView();
1421 //=========================================================================
1423 void wxVtkSceneManager::centerView()
1426 _baseView->GetRenderer()->GetActiveCamera()->GetFocalPoint(temp);
1427 _baseView->GetRenderer()->GetActiveCamera()->SetFocalPoint(0,0,temp[2]);
1428 _baseView->GetRenderer()->GetActiveCamera()->GetPosition(temp);
1429 _baseView->GetRenderer()->GetActiveCamera()->SetPosition(0,0,temp[2]);
1430 _baseView->RefreshView();
1434 //=========================================================================
1436 void wxVtkSceneManager::saveDiagram(std::string &content)
1440 //Print info IF COMPLEX BOX
1441 content+="COMPLEXBOX:";
1446 //Print info complex input ports
1447 std::vector<int> inputs = getComplexInputPorts();
1448 int insize = inputs.size();
1449 content+="COMPLEXINPUTS:";
1450 sprintf (buffer, "%d", insize);
1454 for(int i = 0;i<insize;i++)
1457 GObjectController *cont = _controllers[id];
1458 cont->getModel()->save(content);
1461 //Print info complex output ports
1462 std::vector<int> outputs = getComplexOutputPorts();
1463 int outsize = outputs.size();
1464 content+="COMPLEXOUTPUTS:";
1465 sprintf (buffer, "%d", outsize);
1469 for(int i = 0;i<outsize;i++)
1471 int id = outputs[i];
1472 GObjectController *cont = _controllers[id];
1473 cont->getModel()->save(content);
1482 std::vector<int> boxes = getBlackBoxes();
1483 int bsize = boxes.size();
1485 sprintf (buffer, "%d", bsize);
1489 for(int i = 0;i<bsize;i++)
1492 GObjectController *cont = _controllers[id];
1493 cont->getModel()->save(content);
1497 std::vector<int> connections = getConnections();
1498 int csize = connections.size();
1499 content+="CONNECTIONS:";
1500 sprintf (buffer, "%d", csize);
1504 for(int i = 0;i<csize;i++)
1506 int id = connections[i];
1507 GObjectController *cont = _controllers[id];
1508 cont->getModel()->save(content);
1513 //=========================================================================
1515 void wxVtkSceneManager::loadDiagram(ifstream &inputStream)
1518 std::string line="";
1519 char delims[] = ":";
1520 char *result = NULL;
1521 getline(inputStream,line);
1524 while ( !inputStream.eof() )
1526 if(line=="" || line[0]=='#')
1528 getline(inputStream,line);
1530 else if(line=="APP_START")
1541 getline(inputStream,line);//COMPLEX_BOX:TRUE|FALSE
1543 strcpy( complex, line.c_str() );
1544 result = strtok( complex, delims );
1545 result = strtok( NULL, delims );
1546 std::string isComplexBox(result);
1548 if(isComplexBox=="TRUE")
1552 //-----------------------
1553 //- COMPLEX INPUT PORTS
1554 //-----------------------
1555 getline(inputStream,line);//COMPLEXINPUTS:num
1557 strcpy( inputs, line.c_str() );
1558 result = strtok( inputs, delims );
1559 result = strtok( NULL, delims );
1562 std::istringstream inps(result);
1565 for(int i = 0;i<numInputs;i++)
1568 getline(inputStream,line);//COMPLEX_PORT
1569 getline(inputStream,line);//name
1570 std::string inputPortName(line);
1573 getline(inputStream,line);//xInic:yInic:zInic
1575 strcpy( coord, line.c_str() );
1576 result = strtok( coord, delims );//xInic
1577 std::string xInic(result);
1578 result = strtok( NULL, delims );//yInic
1579 std::string yInic(result);
1580 result = strtok( NULL, delims );//zInic
1581 std::string zInic(result);
1583 double xIn, yIn, zIn;
1584 std::istringstream xSt(xInic);
1586 std::istringstream ySt(yInic);
1588 std::istringstream zSt(zInic);
1591 getline(inputStream,line);//FIN_COMPLEX_PORT
1593 configGComBoxInputOutputPort(true, inputPortName,xIn,yIn,zIn);
1596 // int idInputPort = createGComplexBoxInputPort(inputPortName);
1597 // GObjectController *cont = _controllers[idInputPort];
1598 // GBoxModel *cbmod = (GBoxModel*)cont->getModel();
1599 // cbmod->setInicPoint(xIn,yIn,zIn);
1600 // cbmod->notifyObservers(_idManager);
1603 } // for input complex box
1606 //-----------------------
1607 //- COMPLEX OUTPUT PORTS
1608 //-----------------------
1610 getline(inputStream,line);//COMPLEXOUTPUTS:num
1612 strcpy( outputs, line.c_str() );
1613 result = strtok( outputs, delims );
1614 result = strtok( NULL, delims );
1617 std::istringstream outps(result);
1618 outps >> numOutputs;
1620 for(int i = 0;i<numOutputs;i++)
1623 getline(inputStream,line);//COMPLEX_PORT
1624 getline(inputStream,line);//name
1625 std::string outputPortName(line);
1628 getline(inputStream,line);//xInic:yInic:zInic
1630 strcpy( coord, line.c_str() );
1631 result = strtok( coord, delims );//xInic
1632 std::string xInic(result);
1633 result = strtok( NULL, delims );//yInic
1634 std::string yInic(result);
1635 result = strtok( NULL, delims );//zInic
1636 std::string zInic(result);
1638 double xIn, yIn, zIn;
1639 std::istringstream xSt(xInic);
1641 std::istringstream ySt(yInic);
1643 std::istringstream zSt(zInic);
1646 getline(inputStream,line);//FIN_COMPLEX_PORT
1648 configGComBoxInputOutputPort(false, outputPortName,xIn,yIn,zIn);
1651 // int idOutputPort = createGComplexBoxOutputPort(outputPortName);
1652 // GObjectController *cont = _controllers[idOutputPort];
1653 // GBoxModel *cbmod = (GBoxModel*)cont->getModel();
1654 // cbmod->setInicPoint(xIn,yIn,zIn);
1655 // cbmod->notifyObservers(_idManager);
1657 } // for output complex box
1662 getline(inputStream,line);//BOXES:num
1664 strcpy( boxes, line.c_str() );
1665 result = strtok( boxes, delims );
1666 result = strtok( NULL, delims );
1669 std::istringstream is(result);
1672 for(int i = 0;i<numBoxes;i++)
1675 getline(inputStream,line);//BOX
1676 getline(inputStream,line);//package:type:name
1678 strcpy( box, line.c_str() );
1679 result = strtok( box, delims );//package
1680 std::string package(result);
1681 result = strtok( NULL, delims );//type
1682 std::string type(result);
1683 result = strtok( NULL, delims );//name
1684 std::string name(result);
1686 getline(inputStream,line);//ISEXEC:TRUE|FALSE
1688 strcpy( exec, line.c_str() );
1689 result = strtok( exec, delims );//ISEXEC
1690 result = strtok( NULL, delims );//TRUE|FALSE
1691 std::string isExec(result);
1694 getline(inputStream,line);//xInic:yInic:zInic
1696 strcpy( coord, line.c_str() );
1697 result = strtok( coord, delims );//xInic
1698 std::string xInic(result);
1699 result = strtok( NULL, delims );//yInic
1700 std::string yInic(result);
1701 result = strtok( NULL, delims );//zInic
1702 std::string zInic(result);
1704 double xIn, yIn, zIn;
1705 std::istringstream xSt(xInic);
1707 std::istringstream ySt(yInic);
1709 std::istringstream zSt(zInic);
1713 getline(inputStream,line);//xEnd:yEnd:zEnd
1714 strcpy( coord, line.c_str() );
1715 result = strtok( coord, delims );//xEnd
1716 std::string xEnd(result);
1717 result = strtok( NULL, delims );//yEnd
1718 std::string yEnd(result);
1719 result = strtok( NULL, delims );//zEnd
1720 std::string zEnd(result);
1722 double xEn, yEn, zEn;
1723 std::istringstream xEt(xEnd);
1725 std::istringstream yEt(yEnd);
1727 std::istringstream zEt(zEnd);
1730 bool boxExecutable=false;
1733 boxExecutable= true;
1736 int idBox = createGBlackBox(xIn,yIn,package,type);
1737 configGBlackBox(idBox, xIn,yIn,zIn,name, boxExecutable,xEn,yEn,zEn);
1739 GObjectController *cont = _controllers[idBox];
1740 GBlackBoxModel *bbmod = (GBlackBoxModel*)cont->getModel();
1744 // GObjectController *cont = _controllers[idBox];
1745 // GBlackBoxModel *bbmod = (GBlackBoxModel*)cont->getModel();
1746 // bbmod->setBBTKName(name);
1747 // bbmod->setInicPoint(xIn,yIn,zIn);
1748 // bbmod->setFinalPoint(xEn,yEn,zEn);
1749 // bbmod->setExecutable(boxExecutable);
1753 getline(inputStream,line);//PORT o FIN_BOX
1754 std::string port=line.substr(0,4);
1757 getline(inputStream,line);//name:value
1759 strcpy( poort, line.c_str() );
1760 result = strtok( poort, delims );//name
1761 std::string name(result);
1762 result = strtok( NULL, delims );//value
1763 std::string value(result);
1765 bbmod->setValueToInput(name,value);
1767 getline(inputStream,line);//PORT o FIN_BOX
1768 port=line.substr(0,4);
1771 //EED bbmod->notifyObservers(_idManager);
1776 getline(inputStream,line);//CONNECTIONS:num
1778 strcpy( conns, line.c_str() );
1779 result = strtok( conns, delims );
1780 result = strtok( NULL, delims );
1783 std::istringstream isCons(result);
1786 for(int i = 0;i<numConns;i++)
1789 getline(inputStream,line);//CONNECTION
1790 getline(inputStream,line);//Startbox.PortName:EndBox.PortName
1793 strcpy( connec, line.c_str() );
1794 result = strtok( connec, delims );
1795 std::string nameStartBox(result);
1796 result = strtok( NULL, delims );
1797 std::string nameStartPort(result);
1798 result = strtok( NULL, delims );
1799 std::string nameEndBox(result);
1800 result = strtok( NULL, delims );
1801 std::string nameEndPort(result);
1803 configGConnetion(nameStartBox, nameStartPort, nameEndBox, nameEndPort);
1806 std::vector<int> lstB = getBlackBoxes();
1807 GPortModel *startP = NULL;
1808 GPortModel *endP = NULL;
1810 for(j = 0;j<lstB.size();j++)
1813 GBlackBoxModel *bbMod = (GBlackBoxModel*)_controllers[idB]->getModel();
1814 if(_controllers[idB]->getModel()->getBBTKName()==nameStartBox)
1816 startP = bbMod->getOutputPort(nameStartPort);
1818 else if(_controllers[idB]->getModel()->getBBTKName()==nameEndBox)
1820 endP = bbMod->getInputPort(nameEndPort);
1828 std::vector<int> lstInputs = getComplexInputPorts();
1829 for(j = 0;j<lstInputs.size();j++)
1831 int idB = lstInputs[j];
1832 GBoxModel *cbMod = (GBoxModel*)_controllers[idB]->getModel();
1833 if(_controllers[idB]->getModel()->getBBTKName()==nameStartBox)
1835 startP = cbMod->getOutputPort(nameStartPort);
1842 std::vector<int> lstOutputs = getComplexOutputPorts();
1843 for(j = 0;j<lstOutputs.size();j++)
1845 int idB = lstOutputs[j];
1846 GBoxModel *cbMod = (GBoxModel*)_controllers[idB]->getModel();
1847 if(_controllers[idB]->getModel()->getBBTKName()==nameEndBox)
1849 endP = cbMod->getInputPort(nameEndPort);
1855 int idCon = createGConnector(startP);
1856 _worldState = NOTHING_HAPPENS;
1857 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
1859 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
1860 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
1861 tempp->endContourCreation();
1862 conMod->setEndPort(endP);
1863 conView->updateStartEndPoints();
1870 //=========================================================================
1874 //=========================================================================
1875 void wxVtkSceneManager::configGComBoxInputOutputPort(bool inputoutput, std::string portName, double xIn, double yIn,double zIn)
1878 if (inputoutput==true)
1880 idPort = createGComplexBoxInputPort(portName);
1882 idPort = createGComplexBoxOutputPort(portName);
1884 GObjectController *cont = _controllers[idPort];
1885 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
1886 cbmod->setInicPoint(xIn,yIn,zIn);
1887 cbmod->notifyObservers(_idManager);
1889 //=========================================================================
1892 //=========================================================================
1893 GBoxModel* wxVtkSceneManager::findGBox(std::string boxname)
1898 GBoxModel *boxModel = NULL;
1899 std::vector<int> lstB = getBlackBoxes();
1900 for(j = 0;j<(int)lstB.size();j++)
1903 bMod = (GBoxModel*)_controllers[idB]->getModel();
1904 if(_controllers[idB]->getModel()->getBBTKName()==boxname)
1910 if((_isComplexBox) && (boxModel==NULL))
1912 std::vector<int> lstInputs = getComplexInputPorts();
1913 for(j = 0;j<(int)lstInputs.size();j++)
1916 bMod = (GBoxModel*)_controllers[idB]->getModel();
1917 if(_controllers[idB]->getModel()->getBBTKName()==boxname)
1923 std::vector<int> lstOutputs = getComplexOutputPorts();
1924 for(j = 0;j<(int)lstOutputs.size();j++)
1926 int idB = lstOutputs[j];
1927 bMod = (GBoxModel*)_controllers[idB]->getModel();
1928 if(_controllers[idB]->getModel()->getBBTKName()==boxname)
1939 //=========================================================================
1942 void wxVtkSceneManager::configGConnetion(std::string nameStartBox, std::string nameStartPort, std::string
1943 nameEndBox, std::string nameEndPort)
1945 printf("EED wxVtkSceneManager::configGConnetion 1 %s %s %s %s\n", nameStartBox.c_str(), nameStartPort.c_str(), nameEndBox.c_str(), nameEndPort.c_str() );
1947 GBoxModel *boxModel;
1948 GPortModel *startP = NULL;
1949 GPortModel *endP = NULL;
1951 boxModel= findGBox(nameStartBox);
1954 startP = boxModel->getOutputPort(nameStartPort);
1957 boxModel= findGBox(nameEndBox);
1960 endP = boxModel->getInputPort(nameEndPort);
1964 printf("EED wxVtkSceneManager::configGConnetion 2 %p %p \n", startP, endP );
1967 std::vector<int> lstB = getBlackBoxes();
1969 for(j = 0;j<(int)lstB.size();j++)
1972 GBlackBoxModel *bbMod = (GBlackBoxModel*)_controllers[idB]->getModel();
1973 if(_controllers[idB]->getModel()->getBBTKName()==nameStartBox)
1975 startP = bbMod->getOutputPort(nameStartPort);
1977 else if(_controllers[idB]->getModel()->getBBTKName()==nameEndBox)
1979 endP = bbMod->getInputPort(nameEndPort);
1987 std::vector<int> lstInputs = getComplexInputPorts();
1988 for(j = 0;j<(int)lstInputs.size();j++)
1990 int idB = lstInputs[j];
1991 GBoxModel *cbMod = (GBoxModel*)_controllers[idB]->getModel();
1992 if(_controllers[idB]->getModel()->getBBTKName()==nameStartBox)
1994 startP = cbMod->getOutputPort(nameStartPort);
2001 std::vector<int> lstOutputs = getComplexOutputPorts();
2002 for(j = 0;j<(int)lstOutputs.size();j++)
2004 int idB = lstOutputs[j];
2005 GBoxModel *cbMod = (GBoxModel*)_controllers[idB]->getModel();
2006 if(_controllers[idB]->getModel()->getBBTKName()==nameEndBox)
2008 endP = cbMod->getInputPort(nameEndPort);
2015 int idCon = createGConnector(startP);
2016 _worldState = NOTHING_HAPPENS;
2017 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
2019 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
2020 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
2021 tempp->endContourCreation();
2022 conMod->setEndPort(endP);
2023 conView->updateStartEndPoints();
2026 //=========================================================================
2028 bool wxVtkSceneManager::boxExist(std::string boxname)
2031 std::map<int, GObjectController*>::iterator it;
2032 for(it = _controllers.begin(); it != _controllers.end(); ++it)
2034 GObjectController *cont = it->second;
2035 if(cont->getModel()->getBBTKName()==boxname)
2043 //=========================================================================
2045 std::vector<int> wxVtkSceneManager::getBlackBoxes()
2047 std::vector<int> vect;
2048 std::map<int, GObjectController*>::iterator it;
2049 for(it = _controllers.begin(); it != _controllers.end(); ++it)
2051 GObjectController *cont = it->second;
2052 if(cont->getGObjectType()==GBLACKBOX)
2054 vect.push_back(cont->getId());
2060 //=========================================================================
2062 std::vector<int> wxVtkSceneManager::getComplexInputPorts()
2064 std::vector<int> vect;
2065 std::map<int, GObjectController*>::iterator it;
2066 for(it = _controllers.begin(); it != _controllers.end(); ++it)
2068 GObjectController *cont = it->second;
2069 if(cont->getGObjectType()==GCOMPLEXINPUTPORT)
2071 vect.push_back(cont->getId());
2077 //=========================================================================
2079 std::vector<int> wxVtkSceneManager::getComplexOutputPorts()
2081 std::vector<int> vect;
2082 std::map<int, GObjectController*>::iterator it;
2083 for(it = _controllers.begin(); it != _controllers.end(); ++it)
2085 GObjectController *cont = it->second;
2086 if(cont->getGObjectType()==GCOMPLEXOUTPUTPORT)
2088 vect.push_back(cont->getId());
2094 //=========================================================================
2096 std::vector<int> wxVtkSceneManager::getConnections()
2098 std::vector<int> vect;
2099 std::map<int, GObjectController*>::iterator it;
2100 for(it = _controllers.begin(); it != _controllers.end(); ++it)
2102 GObjectController *cont = it->second;
2103 if(cont->getGObjectType()==GCONNECTOR)
2105 vect.push_back(cont->getId());
2111 //=========================================================================
2113 bool wxVtkSceneManager::isComplexBox()
2115 return _isComplexBox;
2118 //=========================================================================
2120 void wxVtkSceneManager::setComplexBox(bool val)
2125 //=========================================================================
2127 int wxVtkSceneManager::addObjectController(GObjectController* objController)
2129 //Register the controller of the new object
2130 registerController((InteractorStyleMaracas*) objController);
2132 //Add the object to the objects list
2133 int newId = _contLastId;//_controllers.size();
2134 objController->setId(newId);
2135 _controllers[newId] = objController;
2140 //=========================================================================
2142 int wxVtkSceneManager::getNumSelectedObjects()
2144 return _selectedObjects.size();
2147 //=========================================================================
2149 std::map<int,GObjectController*> wxVtkSceneManager::getSelectedObjects()
2151 std::map<int,GObjectController*> mapSelected;
2153 std::map<int, GObjectController*>::iterator it;
2154 for(it = _controllers.begin(); it != _controllers.end(); ++it)
2156 GObjectController *cont = it->second;
2157 if(cont->getGObjectType()==GBLACKBOX && cont->getView()->getState()==SELECTED)
2159 mapSelected[cont->getId()]=cont;
2163 std::map<int, GObjectController*>::iterator it2;
2164 for(it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
2166 GObjectController *cont = it2->second;
2167 if(cont->getGObjectType()==GCONNECTOR)
2169 GConnectorModel* cmod = (GConnectorModel*)cont->getModel();
2170 GBoxModel* endPortParentBox = cmod->getEndPort()->getParentBox();
2171 GBoxModel* startPortParentBox = cmod->getStartPort()->getParentBox();
2173 std::map<int, GObjectController*>::iterator iterOBJ1 = mapSelected.find(startPortParentBox->getObjectId());
2174 std::map<int, GObjectController*>::iterator iterOBJ2 = mapSelected.find(endPortParentBox->getObjectId());
2176 if(iterOBJ1 != mapSelected.end() && iterOBJ2 != mapSelected.end())
2178 int ID = cont->getId();
2179 mapSelected[ID]=cont;
2186 //=========================================================================
2188 void wxVtkSceneManager::addObjects(std::map<int,GObjectController*> objectsMap)
2191 std::map<int,int> oldIdNewIdBoxes;
2192 std::vector<int> connections;
2194 std::map<int, GObjectController*>::iterator it;
2195 for(it = objectsMap.begin(); it != objectsMap.end(); ++it)
2197 GObjectController *cont = it->second;
2198 int type = cont->getGObjectType();
2203 double xInic, yInic,zInic;
2204 GBlackBoxModel* copyBox = (GBlackBoxModel*)cont->getModel();
2205 copyBox->getInicPoint(xInic,yInic,zInic);
2206 int idBox = createGBlackBox(0,0,copyBox->getBBTKPackage(),copyBox->getBBTKType());
2208 int idcB = copyBox->getObjectId();
2209 oldIdNewIdBoxes[idcB]=idBox;
2210 cont = _controllers[idBox];
2211 GBlackBoxModel* newbox = (GBlackBoxModel*)cont->getModel();
2212 newbox->setInicPoint(xInic,yInic,zInic);
2213 int num = newbox->getNumInputPorts();
2214 for(int j=0;j<num;j++)
2216 newbox->setValueToInputPort(j,copyBox->getValueInputPort(j));
2218 newbox->notifyObservers(_idManager);
2220 else if(type==GCONNECTOR)
2222 int idCon = cont->getId();
2223 connections.push_back(idCon);
2228 for(int i = 0 ;i<(int)connections.size();i++)
2230 int objId = connections[i];
2231 GObjectController *cont = objectsMap[objId];
2232 GConnectorModel* connectModel = (GConnectorModel*)cont->getModel();
2234 GPortModel* startPort = connectModel->getStartPort();
2235 int startPortIndex = startPort->getPosInBox();
2236 GPortModel* endPort = connectModel->getEndPort();
2237 int endPortIndex = endPort->getPosInBox();
2239 GBlackBoxModel* startPortParentBox = (GBlackBoxModel*)startPort->getParentBox();
2240 GBlackBoxModel* endPortParentBox = (GBlackBoxModel*)endPort->getParentBox();
2242 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2243 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2245 GBlackBoxModel* newStartBox = (GBlackBoxModel*)_controllers[idNewStartBox]->getModel();
2246 GBlackBoxModel* newEndBox = (GBlackBoxModel*)_controllers[idNewEndBox]->getModel();
2248 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2249 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2251 // Creates connection
2252 int idCon = createGConnector(newStartPort);
2253 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
2254 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
2255 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
2256 tempp->endContourCreation();
2257 conMod->setEndPort(newEndPort);
2258 conView->updateStartEndPoints();
2261 std::map<int, int>::iterator itIds;
2262 for(itIds = oldIdNewIdBoxes.begin(); itIds != oldIdNewIdBoxes.end(); ++itIds)
2264 int idOld = itIds->first;
2265 int idNew = itIds->second;
2267 GBlackBoxModel* oldBox = (GBlackBoxModel*)objectsMap[idOld]->getModel();
2268 GBlackBoxModel* newBox = (GBlackBoxModel*)_controllers[idNew]->getModel();
2270 std::vector<int> oldInputConnections = oldBox->getConnectedInputs();
2271 std::vector<int> oldOutputConnections = oldBox->getConnectedOutputs();
2272 std::vector<int> newInputConnections = newBox->getConnectedInputs();
2273 std::vector<int> newOutputConnections = newBox->getConnectedOutputs();
2275 for(int k = 0; k<(int)oldInputConnections.size();k++)
2278 //EED int toCreate=-1;
2279 for(int l = 0; l<(int)newInputConnections.size() && !exist;l++)
2281 if(oldInputConnections[k]==newInputConnections[l])
2289 //Create complex input
2290 int posInBox = oldInputConnections[k];
2291 GPortModel* inputPort = oldBox->getInputPort(posInBox);
2292 std::string inputPortName = inputPort->getBBTKName();
2293 int idInputPort = createGComplexBoxInputPort(inputPortName);
2294 GObjectController *cont = _controllers[idInputPort];
2295 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
2297 inputPort->getInicPoint(xIn,yIn,zIn);
2299 cbmod->setInicPoint(xIn,yIn,zIn);
2300 cbmod->notifyObservers(_idManager);
2302 GPortModel* inputPortEnd = newBox->getInputPort(posInBox);
2304 // Creates connection
2305 int idCon = createGConnector(cbmod->getOutputPort(0));
2306 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
2307 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
2308 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
2309 tempp->endContourCreation();
2310 conMod->setEndPort(inputPortEnd);
2311 conView->updateStartEndPoints();
2318 for(int k = 0; k<(int)oldOutputConnections.size();k++)
2321 //EED int toCreate=-1;
2322 for(int l = 0; l<(int)newOutputConnections.size() && !exist;l++)
2324 if(oldOutputConnections[k]==newOutputConnections[l])
2332 //Create complex output
2333 int posInBox = oldOutputConnections[k];
2334 GPortModel* outputPort = oldBox->getOutputPort(posInBox);
2335 std::string outputPortName = outputPort->getBBTKName();
2336 int idOutputPort = createGComplexBoxOutputPort(outputPortName);
2337 GObjectController *cont = _controllers[idOutputPort];
2338 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
2340 outputPort->getInicPoint(xIn,yIn,zIn);
2342 cbmod->setInicPoint(xIn,yIn,zIn);
2343 cbmod->notifyObservers(_idManager);
2345 GPortModel* outputPortEnd = newBox->getOutputPort(posInBox);
2347 // Creates connection
2348 int idCon = createGConnector(outputPortEnd);
2349 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
2350 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
2351 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
2352 tempp->endContourCreation();
2353 conMod->setEndPort(cbmod->getInputPort(0));
2354 conView->updateStartEndPoints();
2365 //=========================================================================
2367 } // EO namespace bbtk