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"
39 #include <vtkPolygon.h>
40 #include <vtkUnstructuredGrid.h>
47 //=========================================================================
48 wxVtkSceneManager::wxVtkSceneManager(wxGEditorTabPanel *parent, wxVtk3DBaseView *baseView,int idManager)
52 _idManager = idManager;
54 _startDragging = false;
55 _isComplexBox = false;
60 printf ("RaC-EED 21-06-2010 %p wxVtkSceneManager::wxVtkSceneManager If you comment this line, the drag and drop functionnality is not initialized.\n" , this );
61 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget((wxDropTarget*)parent);
64 _worldState=NOTHING_HAPPENS;
65 registerController(this);
68 _idConnectionInCreation = -1;
73 //=========================================================================
75 void wxVtkSceneManager::disconnectDrop()
77 printf ("EED %p ~wxVtkSceneManager::disconnectDrop()\n" , this );
78 //EED02JUIN2010 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget(NULL);
79 // _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget( new tmpClasswxTextDropTarget() );
82 //=========================================================================
84 wxVtkSceneManager::~wxVtkSceneManager()
86 printf ("EED %p ~wxVtkSceneManager()\n" , this );
90 //=========================================================================
92 void wxVtkSceneManager::configureBaseView()
94 vtkInteractorStyleBaseView2D *interactorstylebaseview = vtkInteractorStyleBaseView2D::New();
96 _baseView->SetInteractorStyleBaseView(interactorstylebaseview);
98 // Important to activate the 2D interaction system
99 wxVTKRenderWindowInteractor *iren = _baseView->GetWxVTKRenderWindowInteractor();
100 interactorstylebaseview->SetInteractor ( iren );
101 iren->SetInteractorStyle(interactorstylebaseview);
102 interactorstylebaseview->SetwxVtkBaseView(_baseView);
104 _baseView->GetRenderer()->GetActiveCamera()->ParallelProjectionOn();
105 _baseView->GetRenderer()->ResetCamera(-100,100,-100,100,800,1100);
107 _baseView->GetRenderer()->SetBackground(0.9,0.9,0.9);
108 _baseView->GetRenderer()->GradientBackgroundOn();
109 _baseView->Refresh();
112 _textActor = vtkTextActor3D::New();
113 _textActor->SetPosition( -9999 , -9999 , 900 );
114 _textActor->SetInput( "<void>" );
115 _textActor->GetTextProperty()->SetFontSize(60);
116 _textActor->GetTextProperty()->BoldOn();
117 _textActor->GetTextProperty()->SetColor(PORTTEXT_NH_R,PORTTEXT_NH_G,PORTTEXT_NH_B);
119 _baseView->GetRenderer()->AddActor( _textActor );
122 // Actor Fill_Port_Text
129 vtkPolygon *aPolygon = vtkPolygon::New();
130 _fillObjectActor = vtkActor::New();
132 _pts = vtkPoints::New();
135 double w=100,h=10,b=h/15,t=3;
136 _pts->SetNumberOfPoints(21);
137 _pts->InsertPoint(0, xInic+w*0.33-t/2 , yInic , zInic );
138 _pts->InsertPoint(1, xInic+w*0.33 , yInic-t , zInic );
139 _pts->InsertPoint(2, xInic+w*0.33+t/2 , yInic , zInic );
140 _pts->InsertPoint(3, xInic+w*0.33+t/2 , yInic , zInic );
141 _pts->InsertPoint(4, xInic+w-b*4 , yInic+b*0 , zInic );
143 _pts->InsertPoint( 5, xInic+w-b*4 , yInic+b*0 , zInic );
144 _pts->InsertPoint( 6, xInic+w-b*2 , yInic+b*1 , zInic );
145 _pts->InsertPoint( 7, xInic+w-b*1 , yInic+b*2 , zInic );
146 _pts->InsertPoint( 8, xInic+w-b*0 , yInic+b*4 , zInic );
148 _pts->InsertPoint( 9, xInic+w-b*0 , yInic+h-b*4 , zInic );
149 _pts->InsertPoint(10, xInic+w-b*1 , yInic+h-b*2 , zInic );
150 _pts->InsertPoint(11, xInic+w-b*2 , yInic+h-b*1 , zInic );
151 _pts->InsertPoint(12, xInic+w-b*4 , yInic+h-b*0 , zInic );
153 _pts->InsertPoint(13, xInic+b*4 , yInic+h-b*0 , zInic );
154 _pts->InsertPoint(14, xInic+b*2 , yInic+h-b*1 , zInic );
155 _pts->InsertPoint(15, xInic+b*1 , yInic+h-b*2 , zInic );
156 _pts->InsertPoint(16, xInic+b*0 , yInic+h-b*4 , zInic );
158 _pts->InsertPoint(17, xInic+b*0 , yInic+b*4 , zInic );
159 _pts->InsertPoint(18, xInic+b*1 , yInic+b*2 , zInic );
160 _pts->InsertPoint(19, xInic+b*2 , yInic+b*1 , zInic );
161 _pts->InsertPoint(20, xInic+b*4 , yInic+b*0 , zInic );
163 aPolygon->GetPointIds()->SetNumberOfIds(21);
164 for (int i=0;i<21; i++)
166 aPolygon->GetPointIds()->SetId(i, i);
169 vtkUnstructuredGrid *aPolygonGrid = vtkUnstructuredGrid::New();
170 aPolygonGrid->Allocate(1, 1);
171 aPolygonGrid->InsertNextCell(aPolygon->GetCellType(), aPolygon->GetPointIds());
172 aPolygonGrid->SetPoints(_pts);
173 _aPolygonMapper = vtkDataSetMapper::New();
174 _aPolygonMapper->SetInput(aPolygonGrid);
175 _fillObjectActor->SetMapper(_aPolygonMapper);
176 _fillObjectActor->GetProperty()->SetColor(PORTFILL_NH_R,PORTFILL_NH_G,PORTFILL_NH_B);
177 _fillObjectActor->GetProperty()->SetOpacity(0);
178 _aPolygonMapper->Modified();
180 _baseView->GetRenderer()->AddActor( _fillObjectActor );
183 //=========================================================================
185 std::string wxVtkSceneManager::generateANewNameForABox()
187 std::stringstream boxname;
190 boxname << "Box0" << _numBoxes;
192 boxname << "Box" << _numBoxes;
195 return boxname.str();
198 //=========================================================================
200 std::string wxVtkSceneManager::findANewNameForABox()
202 std::string boxname=generateANewNameForABox();
204 while (boxExist(boxname)==true)
206 boxname=generateANewNameForABox();
212 //=========================================================================
213 void wxVtkSceneManager::configGBlackBox(int idBox, double xIn, double yIn, double zIn, std::string name, bool boxExecutable,double xEn,double yEn,double zEn)
215 GObjectController *cont = _controllers[idBox];
216 GBlackBoxModel *bbmod = (GBlackBoxModel*)cont->getModel();
217 bbmod->setBBTKName(name);
218 bbmod->setInicPoint(xIn,yIn,zIn);
219 bbmod->setFinalPoint(xEn,yEn,zEn);
220 bbmod->setExecutable(boxExecutable);
222 bbmod->notifyObservers(_idManager);
227 //=========================================================================
229 int wxVtkSceneManager::createGBlackBox(int x, int y, std::string packageName, std::string boxType)
231 _worldState = NOTHING_HAPPENS;
232 //EED int windowWidth = _baseView->GetRenWin()->GetSize()[0];
233 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
235 int type = GBLACKBOX;
237 //Create the MVC Objects
239 GBlackBoxModel *model = (GBlackBoxModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
240 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
241 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
243 BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxType);
245 //Prepares the initial model
246 //The coordinates obtained are the following. Top-Left:x=0,y=0 Bottom-Right:x=width,y=height
249 double yy = windowHeight-y;
251 //z value is not important yet, because it is only used a parallel projection
253 printf("EED wxVtkSceneManager::createGBlackBox 900-450\n");
254 _baseView->TransCoordScreenToWorld(xx,yy,zz);
255 model->setInicPoint(xx,yy,zz);
257 std::stringstream stream;
259 std::string newBoxName;
260 newBoxName = findANewNameForABox();
263 stream << newBoxName;
265 std::string arraystring = stream.str();
267 model->setBBTKName(arraystring);
268 model->setBBTKType(boxType);
269 model->setBBTKPackage(packageName);
271 model->addObserver(view);
272 model->addObserver(this);
274 //Iterate and create the input ports
275 std::map<std::string, BlackBoxInputDescriptor*> descriptorInMap = descriptor->GetInputDescriptorMap();
276 std::map<std::string, BlackBoxInputDescriptor*>::iterator itInput;
279 for(itInput = descriptorInMap.begin(); itInput != descriptorInMap.end(); ++itInput)
281 BlackBoxInputDescriptor *desc = itInput->second;
282 createGInputPort(GINPUTPORT,i,model,desc);
286 //Iterate and create the output ports
287 std::map<std::string, BlackBoxOutputDescriptor*> descriptorOutMap = descriptor->GetOutputDescriptorMap();
288 std::map<std::string, BlackBoxOutputDescriptor*>::iterator itOutput;
291 for(itOutput = descriptorOutMap.begin();itOutput != descriptorOutMap.end(); ++itOutput)
293 BlackBoxOutputDescriptor *desc = itOutput->second;
294 createGOutputPort(GOUTPUTPORT,i,model,desc);
299 //Associates the view with the correspondent renderer and the model.
300 //(NOTE: Refresh is only made by the view)
301 view->setModel(model);
302 view->setBaseView(_baseView);
303 view->initVtkObjects();
305 //Associates the controller with the correspondent model and view
306 controller->setModelAndView(model,view);
308 //Resgiter change to the observers of the actual model
309 model->notifyObservers(_idManager);
311 int newId = addObjectController(controller);
317 //=========================================================================
319 int wxVtkSceneManager::createGComplexBoxInputPort(std::string inputName)
321 //EED int windowWidth=_baseView->GetRenWin()->GetSize()[0];
322 int windowHeight=_baseView->GetRenWin()->GetSize()[1];
324 int type = GCOMPLEXINPUTPORT;
326 //Create the MVC Objects
328 GComplexBoxPortModel *model = (GComplexBoxPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
329 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
330 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
332 //Prepares the initial model
335 double yy = windowHeight-5;
337 //z value is not important yet, because it is only used a parallel projection
339 printf("EED wxVtkSceneManager::createGComplexBoxInputPort 900-450\n");
341 _baseView->TransCoordScreenToWorld(xx,yy,zz);
342 model->setInicPoint(xx,yy,zz);
344 model->setBBTKName(inputName);
345 model->setBBTKType("ComplexInputPort");
346 model->setComplexPortType(type);
348 model->addObserver(view);
349 model->addObserver(this);
351 //create the output port
352 GPortController* portController = createGPort(GOUTPUTPORT,inputName,"ComplexInputPort",0,model);
353 model->addOutputPort((GPortModel*)portController->getModel());
355 //Associates the view with the correspondent renderer and the model.
356 //(NOTE: Refresh is only made by the view)
357 view->setModel(model);
358 view->setBaseView(_baseView);
359 view->initVtkObjects();
361 //Associates the controller with the correspondent model and view
362 controller->setModelAndView(model,view);
364 //Resgiter change to the observers of the actual model
365 model->notifyObservers(_idManager);
367 int newId = addObjectController(controller);
371 //=========================================================================
373 int wxVtkSceneManager::createGComplexBoxOutputPort(std::string outputName)
375 //EED int windowWidth=_baseView->GetRenWin()->GetSize()[0];
376 int windowHeight=_baseView->GetRenWin()->GetSize()[1];
378 int type = GCOMPLEXOUTPUTPORT;
380 //Create the MVC Objects
382 GComplexBoxPortModel *model = (GComplexBoxPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
383 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
384 GObjectController *controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
386 //Prepares the initial model
389 double yy = windowHeight-5;
391 //z value is not important yet, because it is only used a parallel projection
394 printf("EED wxVtkSceneManager::createGComplexBoxOutputPort 900-450\n");
396 _baseView->TransCoordScreenToWorld(xx,yy,zz);
397 model->setInicPoint(xx,yy,zz);
399 model->setBBTKName(outputName);
400 model->setBBTKType("ComplexOutputPort");
401 model->setComplexPortType(type);
403 model->addObserver(view);
404 model->addObserver(this);
406 //create the output port
407 GPortController* portController = createGPort(GINPUTPORT,outputName,"ComplexInputPort",0,model);
408 model->addInputPort((GPortModel*)portController->getModel());
410 //Associates the view with the correspondent renderer and the model.
411 //(NOTE: Refresh is only made by the view)
412 view->setModel(model);
413 view->setBaseView(_baseView);
414 view->initVtkObjects();
416 //Associates the controller with the correspondent model and view
417 controller->setModelAndView(model,view);
419 //Resgiter change to the observers of the actual model
420 model->notifyObservers(_idManager);
422 int newId = addObjectController(controller);
426 //=========================================================================
428 int wxVtkSceneManager::createGInputPort(int portType, int posinBox,GBoxModel *blackBox, BlackBoxInputDescriptor *desc)
430 GPortController* portController = createGPort(portType,desc->GetName(),desc->GetTypeName(),posinBox,blackBox);
431 blackBox->addInputPort((GPortModel*)portController->getModel());
432 return portController->getId();
435 //=========================================================================
437 int wxVtkSceneManager::createGOutputPort(int portType, int posinBox,GBoxModel *blackBox, BlackBoxOutputDescriptor *desc)
439 GPortController* portController = createGPort(portType,desc->GetName(),desc->GetTypeName(),posinBox,blackBox);
440 blackBox->addOutputPort((GPortModel*)portController->getModel());
441 return portController->getId();
444 //=========================================================================
446 GPortController* wxVtkSceneManager::createGPort(int portType,std::string bbtkName, std::string bbtkType, int posInBox,GBoxModel *blackBox)
450 //Create the MVC Objects
451 GPortModel *model = (GPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
452 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
453 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
455 model->registerInBox(blackBox,portType, posInBox);
457 model->setBBTKType(bbtkType);
458 model->setBBTKName(bbtkName);
460 model->addObserver(view);
461 model->addObserver(this);
463 //Associates the view with the correspondent renderer and the model.
464 //(NOTE: Refresh is only made by the view)
465 view->setModel(model);
466 view->setBaseView(_baseView);
467 view->initVtkObjects();
469 //Associates the controller with the correspondent model and view
470 controller->setModelAndView(model,view);
472 model->notifyObservers(_idManager);
474 addObjectController(controller);
476 return (GPortController*)controller;
479 //=========================================================================
481 int wxVtkSceneManager::createGConnector(GPortModel* startPort)
483 int type = GCONNECTOR;
485 manualConnectorContourController* manContourControl = new manualConnectorContourController();
486 manualConnectorContourView* manContourView = new manualConnectorContourView();
487 manualContourModel* manContourModel = new manualContourModel();
489 GConnectorController* connectorcontroller = new GConnectorController();
490 GConnectorModel* connectorModel = new GConnectorModel();
491 vtkGConnectorView* connectorView = new vtkGConnectorView();
492 connectorModel->setGObjectType(type);
494 manContourModel->SetCloseContour(false);
495 connectorModel->setStartPort(startPort);
497 manContourView->SetModel( manContourModel );
498 manContourView->SetWxVtkBaseView( _baseView );
499 manContourView->SetRange( 0.5 );
500 manContourView->SetZ( 900 );
502 manContourView->SetColorNormalContour(0, 0, 1);
503 manContourView->SetColorEditContour(0.5, 0.5, 0.5);
504 manContourView->SetColorSelectContour(1, 0.8, 0);
505 manContourView->SetWidthLine(1);
506 manContourView->SetShowText(false);
508 manContourControl->SetModelView( manContourModel , manContourView );
510 manContourControl->CreateNewManualContour();
512 manContourView->RefreshContour();
516 connectorModel->getInicPoint(x,y,z);
518 manContourControl->SetState(1);
519 manContourModel->SetCloseContour(false);
521 manContourModel->AddPoint(x,y,z);
522 manContourView->AddPoint();
524 manContourModel->AddPoint(x,y,z);
525 manContourView->AddPoint();
527 int bak= manContourControl->GetNumberOfPointsManualContour() - 1;
528 manContourControl->_bakIdPoint=bak;
529 manContourView->Refresh();
531 manContourControl->SetMoving( false );
533 connectorcontroller->setModelAndView(connectorModel,connectorView);
535 int newId = addObjectController(connectorcontroller);
537 connectorcontroller->setManualContourController(manContourControl);
538 connectorModel->setManualContourModel(manContourModel);
539 connectorView->setManualContourView(manContourView);
540 connectorView->setModel(connectorModel);
541 connectorView->setBaseView(_baseView);
544 connectorModel->addObserver(connectorView);
545 connectorModel->addObserver(this);
550 //=========================================================================
552 void wxVtkSceneManager::registerController(InteractorStyleMaracas *param)
554 vtkInteractorStyleBaseView* baseViewControlManager = (vtkInteractorStyleBaseView*)_baseView->GetInteractorStyleBaseView();
555 baseViewControlManager->AddInteractorStyleMaracas( param );
558 //=========================================================================
560 void wxVtkSceneManager::unregisterController(InteractorStyleMaracas *param)
562 vtkInteractorStyleBaseView* baseViewControlManager = (vtkInteractorStyleBaseView*)_baseView->GetInteractorStyleBaseView();
563 baseViewControlManager->RemoveInteractorStyleMaracas( param );
566 //=========================================================================
568 vtkRenderer* wxVtkSceneManager::getRenderer()
570 return _baseView->GetRenderer();
573 //=========================================================================
575 vtkRenderWindow* wxVtkSceneManager::getRenderWindow()
577 return _baseView->GetRenWin();
579 //=========================================================================
582 void wxVtkSceneManager::update(int idController,int command)
584 if(command != NO_COMMAND)
586 if(command == ADD_TO_SELECTED)
588 //EED GObjectController* cont = _controllers[idController];
591 for (int i=0; i<(int)_selectedObjects.size() && foundID==false; i++)
593 int id = _selectedObjects[i];
601 int id = idController;
602 _selectedObjects.push_back(id);
606 else if(command == INIT_CREATION_CONTOUR)
608 _worldState = INIT_CREATION_CONTOUR;
609 GObjectController* cont = _controllers[idController];
610 GPortModel* startOutputPort = (GPortModel*)cont->getModel();
613 // The last one is the controller of the connector
614 std::map<int, GObjectController*>::iterator it2;
616 for(it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
618 GObjectController *cont = it2->second;
619 if(cont->getGObjectType() == GPORT )
621 GPortModel* port = (GPortModel*)cont->getModel();
622 if(port->getPortType()==GINPUTPORT)
624 cont->SetActive(true);
628 cont->getView()->setState(NOTHING_HAPPENS);
629 cont->getModel()->notifyObservers(_idManager);
630 cont->SetActive(false);
635 cont->getView()->setState(NOTHING_HAPPENS);
636 cont->getModel()->notifyObservers(_idManager);
637 cont->SetActive(false);
641 _selectedObjects.clear();
643 _idConnectionInCreation=createGConnector(startOutputPort);
646 else if(command == FIN_CREATION_CONTOUR && _worldState == INIT_CREATION_CONTOUR)
648 _worldState = NOTHING_HAPPENS;
649 //int id = _controllers.size()-1;
650 GObjectController* cont = _controllers[_idConnectionInCreation];
651 GConnectorModel* modelContour = (GConnectorModel*)cont->getModel();
653 GObjectController* finPort = _controllers[idController];
654 if(finPort->getGObjectType() == GPORT)
656 GPortModel* modelPort = (GPortModel*)finPort->getModel();
657 modelContour->setEndPort(modelPort);
660 manualConnectorContourController* manCont = ((GConnectorController*)cont)->getManualContourController();
661 manualConnectorContourView* connView = (manualConnectorContourView*)manCont->GetManualViewBaseContour();
664 std::map<int, GObjectController*>::iterator it2;
666 for(it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
668 GObjectController *cont = it2->second;
669 if(cont->getView()!=NULL)
671 cont->getView()->setState(NOTHING_HAPPENS);
672 cont->getModel()->notifyObservers(_idManager);
674 cont->SetActive(true);
681 //=========================================================================
683 bool wxVtkSceneManager::OnMouseMove()
686 bool okStatusMessage = false;
687 bool okPortMessage = false;
688 wxVTKRenderWindowInteractor *wxVTKiren;
689 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
690 wxVTKiren->GetEventPosition(X,Y);
693 if(_worldState == DRAG_OBJECTS)
695 for (int i=0; i<(int)_selectedObjects.size(); i++)
697 int id = _selectedObjects[i];
698 GObjectController* cont = _controllers[id];
701 cont->getView()->setStartDragging(true);
703 cont->getView()->moveObject(X,Y);
704 cont->getView()->setState(DRAG);
705 cont->getModel()->notifyObservers(_idManager);
708 std::map<int, GObjectController*>::iterator it;
710 for(it = _controllers.begin(); it != _controllers.end(); ++it)
712 GObjectController *desc = it->second;
713 if(desc->getGObjectType()==GCONNECTOR)
715 vtkGConnectorView* vconn = (vtkGConnectorView*)desc->getView();
716 vconn->updateStartEndPoints();
720 _startDragging=false;
723 else if(_worldState == NOTHING_HAPPENS || _worldState == INIT_CREATION_CONTOUR)
725 std::map<int, GObjectController*>::iterator it;
727 for(it = _controllers.begin(); it != _controllers.end(); ++it)
729 GObjectController *desc = it->second;
730 int type = desc->getGObjectType();
731 int state = desc->getView()->getState();
732 desc->getModel()->getCenter(px,py,pz);
734 if(state == HIGHLIGHTED){
735 okStatusMessage = true;
736 updateStatusBar(desc->getStatusText());
739 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
740 _parent->displayBlackBoxInfo(mod->getBBTKPackage(),mod->getBBTKType());
745 okPortMessage = true;
747 _textActor->SetInput( desc->getStatusText().c_str() );
748 _textActor->SetScale(0.1);
749 _textActor->SetPosition( px-25 ,py+1 , pz+2 );
755 _fillObjectActor->SetScale(1);
756 _fillObjectActor->GetProperty()->SetOpacity(0.50);
757 _fillObjectActor->SetPosition(px,py,1);
758 _aPolygonMapper->Modified();
761 } // for controllers it
764 if (okStatusMessage==false)
769 if (okPortMessage==false)
771 _textActor->SetScale(0.0001);
772 _fillObjectActor->SetScale(0.0001);
779 //=========================================================================
781 bool wxVtkSceneManager::OnLeftButtonDown()
783 if(_worldState==INIT_CREATION_CONTOUR)
785 bool isOverPort=false;
786 std::map<int, GObjectController*>::iterator it;
787 for(it = _controllers.begin(); it != _controllers.end() && isOverPort==false; ++it)
789 GObjectController *desc = it->second;
790 if(desc->getGObjectType()==GPORT)
792 GPortModel* portmod=(GPortModel*)desc->getModel();
793 vtkGObjectView* portView=desc->getView();
794 if(portmod->getPortType()==GINPUTPORT && portView->getState()==HIGHLIGHTED)
801 if(isOverPort==false)
803 _worldState=NOTHING_HAPPENS;
804 //int lastId = _controllers.size()-1;
805 GConnectorController *connector = (GConnectorController*)_controllers[_controllers.size()-1];
806 connector->removeFromScene();
807 unregisterController(connector);
808 _controllers.erase(_controllers.size()-1);
810 for(it = _controllers.begin(); it != _controllers.end(); ++it)
812 GObjectController *desc = it->second;
813 desc->SetActive(true);
814 desc->getView()->setState(NOTHING_HAPPENS);
815 desc->getModel()->notifyObservers(_idManager);
820 if(_selectedObjects.size()!=0)
822 _worldState = DRAG_OBJECTS;
823 _startDragging = true;
825 for (int i = 0; i < (int)_selectedObjects.size(); i++)
827 int id = _selectedObjects[i];
828 GObjectController* cont = _controllers[id];
829 cont->getView()->setState(DRAG);
830 cont->getModel()->notifyObservers(_idManager);
832 } // _selectedObjects
839 //=========================================================================
841 bool wxVtkSceneManager::OnLeftButtonUp()
843 if(_worldState == DRAG_OBJECTS)
845 _worldState = NOTHING_HAPPENS;
847 for (int i = 0; i < (int)_selectedObjects.size(); i++)
849 int id = _selectedObjects[i];
850 GObjectController* cont = _controllers[id];
851 cont->getView()->setState(SELECTED);
852 cont->getModel()->notifyObservers(_idManager);
858 //=========================================================================
860 bool wxVtkSceneManager::OnRightButtonUp()
862 if(_worldState==INIT_CREATION_CONTOUR)
864 _worldState=NOTHING_HAPPENS;
865 //int lastId = _controllers.size()-1;
866 GConnectorController *connector = (GConnectorController*)_controllers[_idConnectionInCreation];
867 connector->removeFromScene();
868 unregisterController(connector);
869 _controllers.erase(_idConnectionInCreation);
871 std::map<int, GObjectController*>::iterator it;
872 for(it = _controllers.begin(); it != _controllers.end(); ++it)
874 GObjectController *desc = it->second;
875 desc->SetActive(true);
876 desc->getView()->setState(NOTHING_HAPPENS);
877 desc->getModel()->notifyObservers(_idManager);
882 for (int i = 0; i < (int)_selectedObjects.size(); i++)
884 int id = _selectedObjects[i];
885 GObjectController* cont = _controllers[id];
886 cont->SetActive(true);
887 cont->getView()->setState(NOTHING_HAPPENS);
888 cont->getModel()->notifyObservers(_idManager);
891 _selectedObjects.clear();
896 //=========================================================================
898 bool wxVtkSceneManager::OnLeftDClick()
901 wxVTKRenderWindowInteractor *wxVTKiren;
902 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
903 wxVTKiren->GetEventPosition(X,Y);
905 std::map<int, GObjectController*>::iterator it;
907 bool clickOnObject = false;
909 for(it = _controllers.begin(); it != _controllers.end() && clickOnObject==false; ++it)
911 GObjectController *cont = it->second;
912 int type = cont->getGObjectType();
914 if(cont->getView()->isPointInside(X,Y))
918 for (int i=0; i< (int)_selectedObjects.size(); i++)
920 int id = _selectedObjects[i];
921 GObjectController* control = _controllers[id];
922 control->getView()->setState(NOTHING_HAPPENS);
924 _selectedObjects.clear();
926 GBlackBoxModel *bbmodel = (GBlackBoxModel*)cont->getModel();
927 _parent->editBlackBox(bbmodel);
929 clickOnObject = true;
933 if(clickOnObject==false)
935 //_parent->editDiagramParameters(this);
941 //=========================================================================
943 bool wxVtkSceneManager::OnChar()
945 char keyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
947 // KeyCode 127 : Delete Key
948 // KeyCode 8 : Backspace Key
949 if(keyCode == 8 || keyCode == 127)
951 if(_selectedObjects.size()>0)
953 for(int i=0;i<(int)_selectedObjects.size();i++)
955 int id = _selectedObjects[i];
956 std::map<int,GObjectController*>::iterator it;
957 it = _controllers.find(id);
958 if (it!=_controllers.end())
963 _selectedObjects.clear();
970 //=========================================================================
972 void wxVtkSceneManager::AddControlerToBeRemove(std::vector<int> *controllersToRemove, int id)
977 for(i=0 ; i < (int)controllersToRemove->size() ; i++ )
979 if (id == (*controllersToRemove)[i] )
987 controllersToRemove->push_back( id );
992 //=========================================================================
994 void wxVtkSceneManager::deleteObject(int id)
996 GObjectController *control = _controllers[id];
997 std::vector<int> controllersToRemove;
999 if(control->getGObjectType()==GBLACKBOX || control->getGObjectType()==GCOMPLEXINPUTPORT || control->getGObjectType()==GCOMPLEXOUTPUTPORT)
1001 GBoxModel *bbmod = (GBoxModel*)control->getModel();
1002 std::vector<GPortModel*> inputs = bbmod->getInputPorts();
1004 bool boxConnected = false;
1006 // Add box input controllers to be removed
1007 for(int i = 0;i< (int)inputs.size();i++)
1009 AddControlerToBeRemove( &controllersToRemove, inputs[i]->getObjectId() );
1010 if(inputs[i]->isConnected())
1012 boxConnected = true;
1016 std::vector<GPortModel*> outputs = bbmod->getOutputPorts();
1018 // Add box output controllers to be removed
1019 for(int i = 0;i<(int)outputs.size();i++)
1021 AddControlerToBeRemove( &controllersToRemove, outputs[i]->getObjectId() );
1022 if(outputs[i]->isConnected())
1024 boxConnected = true;
1028 // Add connection controllers to be removed
1029 std::map<int, GObjectController*>::iterator it;
1030 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1032 GObjectController *cont = it->second;
1033 int type = cont->getGObjectType();
1034 if(type==GCONNECTOR)
1036 GConnectorModel *conMod = (GConnectorModel*)cont->getModel();
1037 if(conMod->getStartPort()!=NULL && conMod->getStartPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
1039 AddControlerToBeRemove( &controllersToRemove, conMod->getObjectId() );
1041 if(conMod->getEndPort()!=NULL && conMod->getEndPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
1043 AddControlerToBeRemove( &controllersToRemove, conMod->getObjectId() );
1048 // Add box controller to be removed
1049 AddControlerToBeRemove( &controllersToRemove, bbmod->getObjectId() );
1051 else if(control->getGObjectType()==GCONNECTOR)
1053 GConnectorModel *conMod = (GConnectorModel*)control->getModel();
1054 AddControlerToBeRemove( &controllersToRemove, conMod->getObjectId() );
1058 std::map<int,GObjectController*>::iterator it;
1060 for(int i = 0;i<(int)controllersToRemove.size();i++)
1062 int key = controllersToRemove[i];
1063 it = _controllers.find( key );
1064 GObjectController *cont = _controllers[ key ];
1067 cont->removeFromScene();
1068 unregisterController((InteractorStyleMaracas*)cont);
1069 _controllers.erase(it);
1074 //=========================================================================
1076 void wxVtkSceneManager::displayBlackBoxInfo(std::string packageName, std::string boxName)
1078 _parent->displayBlackBoxInfo(packageName,boxName);
1081 //=========================================================================
1083 void wxVtkSceneManager::updateStatusBar(std::string textStatus)
1085 _parent->updateStatusBar(textStatus);
1088 //=========================================================================
1090 std::string wxVtkSceneManager::getDiagramBBS()
1092 bool existsExec=false;
1094 std::vector<std::string> packages;
1095 std::vector<int> boxes;
1096 std::vector<int> connections;
1097 std::vector<int> execBoxes;
1099 std::map<int, GObjectController*>::iterator it;
1101 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1103 GObjectController *desc = it->second;
1104 int type = desc->getGObjectType();
1108 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
1110 std::string pkg = mod->getBBTKPackage();
1111 bool existsPkg = false;
1112 for(int t = 0;t< (int)packages.size() && existsPkg == false;t++)
1114 if(packages[t]==pkg)
1121 packages.push_back(pkg);
1125 boxes.push_back(it->first);
1126 if(mod->isExecutable())
1128 execBoxes.push_back(it->first);
1132 else if(type==GCONNECTOR)
1134 connections.push_back(it->first);
1138 std::string script = "";
1139 script+="# BBTK GEditor Script\n";
1140 script+="# ----------------------\n";
1144 script+="include std\n"; // EED
1145 script+="include itkvtk\n"; // EED
1147 for(i = 0; i< (int)packages.size();i++)
1150 script+=packages[i];
1155 // script+="include std\n"; // JPR
1157 for(i = 0; i < (int)boxes.size();i++)
1161 GObjectController *control = _controllers[id];
1162 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1164 script+=model->getBBTKType();
1166 script+=model->getBBTKName();
1169 std::vector<GPortModel*> inputs = model->getInputPorts();
1170 for(int j = 0; j < (int)inputs.size();j++)
1172 GPortModel* inputPort = inputs[j];
1173 if(inputPort->isValueSet())
1176 script+=model->getBBTKName();
1178 script+=inputPort->getBBTKName();
1180 script+=inputPort->getValue();
1190 for(i = 0; i<(int)connections.size();i++)
1193 int id = connections[i];
1194 GObjectController *control = _controllers[id];
1195 GConnectorModel *model = (GConnectorModel*)control->getModel();
1197 //Start Connection info
1198 GPortModel *start = model->getStartPort();
1199 script+=start->getParentBox()->getBBTKName();
1201 script+=start->getBBTKName();
1205 //End Connection info
1206 GPortModel *end = model->getEndPort();
1207 script+=end->getParentBox()->getBBTKName();
1209 script+=end->getBBTKName();
1215 for(i = 0; i<(int)execBoxes.size();i++)
1218 int id = execBoxes[i];
1219 GObjectController *control = _controllers[id];
1220 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1222 script+=model->getBBTKName();
1231 //=========================================================================
1233 std::string wxVtkSceneManager::saveComplexBoxBBS(std::string cbName,std::string cbAuthor,std::string cbCategory,std::string cbDescription)
1236 std::vector<std::string> packages;
1237 std::vector<int> boxes;
1238 std::vector<int> connections;
1239 std::vector<int> execBoxes;
1241 std::map<int, GObjectController*>::iterator it;
1243 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1245 GObjectController *desc = it->second;
1246 int type = desc->getGObjectType();
1250 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
1252 std::string pkg = mod->getBBTKPackage();
1253 bool existsPkg = false;
1254 for(int t = 0;t<(int)packages.size() && existsPkg == false;t++)
1256 if(packages[t]==pkg)
1263 packages.push_back(pkg);
1267 boxes.push_back(it->first);
1268 if(mod->isExecutable())
1270 execBoxes.push_back(it->first);
1273 else if(type==GCONNECTOR)
1275 connections.push_back(it->first);
1279 std::string script = "";
1281 script+="include std\n"; // EED
1282 script+="include itkvtk\n"; // EED
1284 for(i = 0; i<(int)packages.size();i++)
1287 script+=packages[i];
1292 // Definition of a complex box
1298 script+="author \" ";
1302 script+="description \" ";
1303 script+=cbDescription;
1308 for(i = 0; i<(int)boxes.size();i++)
1312 GObjectController *control = _controllers[id];
1313 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1315 script+=model->getBBTKType();
1317 script+=model->getBBTKName();
1320 std::vector<GPortModel*> inputs = model->getInputPorts();
1321 for(int j = 0; j<(int)inputs.size();j++)
1323 GPortModel* inputPort = inputs[j];
1324 if(inputPort->isValueSet())
1327 script+=model->getBBTKName();
1329 script+=inputPort->getBBTKName();
1331 script+=inputPort->getValue();
1339 // Create connections in the script. If the connection is made with a complex port, it is created the input or output
1341 std::string complexInputs="";
1342 std::string complexOutputs="";
1345 for(i = 0; i<(int)connections.size();i++)
1347 int id = connections[i];
1348 GObjectController *control = _controllers[id];
1349 GConnectorModel *model = (GConnectorModel*)control->getModel();
1352 GPortModel *start = model->getStartPort();
1353 GBoxModel *startBox =start->getParentBox();
1355 GPortModel *end = model->getEndPort();
1356 GBoxModel *endBox =end->getParentBox();
1358 if(startBox->getGObjectType()==GCOMPLEXINPUTPORT)
1360 complexInputs+="input ";
1361 complexInputs+=startBox->getBBTKName();
1364 complexInputs+=endBox->getBBTKName();
1366 complexInputs+=end->getBBTKName();
1369 complexInputs+="\" \"";
1371 complexInputs+="\n";
1373 else if(endBox->getGObjectType()==GCOMPLEXOUTPUTPORT)
1375 complexOutputs+="output ";
1376 complexOutputs+=endBox->getBBTKName();
1378 complexOutputs+=" ";
1379 complexOutputs+=startBox->getBBTKName();
1380 complexOutputs+=".";
1381 complexOutputs+=start->getBBTKName();
1383 complexOutputs+=" ";
1384 complexOutputs+="\" \"";
1386 complexOutputs+="\n";
1391 script+=startBox->getBBTKName();
1393 script+=start->getBBTKName();
1397 //End Connection info
1398 script+=endBox->getBBTKName();
1400 script+=end->getBBTKName();
1408 for(i = 0; i<(int)execBoxes.size();i++)
1411 int id = execBoxes[i];
1412 GObjectController *control = _controllers[id];
1413 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1415 script+=model->getBBTKName();
1420 script+="# Complex input ports\n";
1421 script+=complexInputs;
1424 script+="# Complex output ports\n";
1425 script+=complexOutputs;
1434 //=========================================================================
1436 void wxVtkSceneManager::deleteAllBoxes()
1438 std::map<int, GObjectController*>::iterator it;
1439 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1441 GObjectController *cont = it->second;
1442 cont->removeFromScene();
1443 unregisterController((InteractorStyleMaracas*)cont);
1445 _selectedObjects.clear();
1446 _controllers.clear();
1450 //=========================================================================
1452 void wxVtkSceneManager::refreshScene()
1454 _baseView->RefreshView();
1457 //=========================================================================
1459 void wxVtkSceneManager::centerView()
1462 _baseView->GetRenderer()->GetActiveCamera()->GetFocalPoint(temp);
1463 _baseView->GetRenderer()->GetActiveCamera()->SetFocalPoint(0,0,temp[2]);
1464 _baseView->GetRenderer()->GetActiveCamera()->GetPosition(temp);
1465 _baseView->GetRenderer()->GetActiveCamera()->SetPosition(0,0,temp[2]);
1466 _baseView->RefreshView();
1470 //=========================================================================
1472 void wxVtkSceneManager::saveDiagram(std::string &content)
1476 //Print info IF COMPLEX BOX
1477 content+="COMPLEXBOX:";
1482 //Print info complex input ports
1483 std::vector<int> inputs = getComplexInputPorts();
1484 int insize = inputs.size();
1485 content+="COMPLEXINPUTS:";
1486 sprintf (buffer, "%d", insize);
1490 for(int i = 0;i<insize;i++)
1493 GObjectController *cont = _controllers[id];
1494 cont->getModel()->save(content);
1497 //Print info complex output ports
1498 std::vector<int> outputs = getComplexOutputPorts();
1499 int outsize = outputs.size();
1500 content+="COMPLEXOUTPUTS:";
1501 sprintf (buffer, "%d", outsize);
1505 for(int i = 0;i<outsize;i++)
1507 int id = outputs[i];
1508 GObjectController *cont = _controllers[id];
1509 cont->getModel()->save(content);
1518 std::vector<int> boxes = getBlackBoxes();
1519 int bsize = boxes.size();
1521 sprintf (buffer, "%d", bsize);
1525 for(int i = 0;i<bsize;i++)
1528 GObjectController *cont = _controllers[id];
1529 cont->getModel()->save(content);
1533 std::vector<int> connections = getConnections();
1534 int csize = connections.size();
1535 content+="CONNECTIONS:";
1536 sprintf (buffer, "%d", csize);
1540 for(int i = 0;i<csize;i++)
1542 int id = connections[i];
1543 GObjectController *cont = _controllers[id];
1544 cont->getModel()->save(content);
1549 //=========================================================================
1551 void wxVtkSceneManager::loadDiagram(ifstream &inputStream)
1554 std::string line="";
1555 char delims[] = ":";
1556 char *result = NULL;
1557 getline(inputStream,line);
1560 while ( !inputStream.eof() )
1562 if(line=="" || line[0]=='#')
1564 getline(inputStream,line);
1566 else if(line=="APP_START")
1577 getline(inputStream,line);//COMPLEX_BOX:TRUE|FALSE
1579 strcpy( complex, line.c_str() );
1580 result = strtok( complex, delims );
1581 result = strtok( NULL, delims );
1582 std::string isComplexBox(result);
1584 if(isComplexBox=="TRUE")
1588 //-----------------------
1589 //- COMPLEX INPUT PORTS
1590 //-----------------------
1591 getline(inputStream,line);//COMPLEXINPUTS:num
1593 strcpy( inputs, line.c_str() );
1594 result = strtok( inputs, delims );
1595 result = strtok( NULL, delims );
1598 std::istringstream inps(result);
1601 for(int i = 0;i<numInputs;i++)
1604 getline(inputStream,line);//COMPLEX_PORT
1605 getline(inputStream,line);//name
1606 std::string inputPortName(line);
1609 getline(inputStream,line);//xInic:yInic:zInic
1611 strcpy( coord, line.c_str() );
1612 result = strtok( coord, delims );//xInic
1613 std::string xInic(result);
1614 result = strtok( NULL, delims );//yInic
1615 std::string yInic(result);
1616 result = strtok( NULL, delims );//zInic
1617 std::string zInic(result);
1619 double xIn, yIn, zIn;
1620 std::istringstream xSt(xInic);
1622 std::istringstream ySt(yInic);
1624 std::istringstream zSt(zInic);
1627 getline(inputStream,line);//FIN_COMPLEX_PORT
1629 configGComBoxInputOutputPort(true, inputPortName,xIn,yIn,zIn);
1632 } // for input complex box
1635 //-----------------------
1636 //- COMPLEX OUTPUT PORTS
1637 //-----------------------
1639 getline(inputStream,line);//COMPLEXOUTPUTS:num
1641 strcpy( outputs, line.c_str() );
1642 result = strtok( outputs, delims );
1643 result = strtok( NULL, delims );
1646 std::istringstream outps(result);
1647 outps >> numOutputs;
1649 for(int i = 0;i<numOutputs;i++)
1652 getline(inputStream,line);//COMPLEX_PORT
1653 getline(inputStream,line);//name
1654 std::string outputPortName(line);
1657 getline(inputStream,line);//xInic:yInic:zInic
1659 strcpy( coord, line.c_str() );
1660 result = strtok( coord, delims );//xInic
1661 std::string xInic(result);
1662 result = strtok( NULL, delims );//yInic
1663 std::string yInic(result);
1664 result = strtok( NULL, delims );//zInic
1665 std::string zInic(result);
1667 double xIn, yIn, zIn;
1668 std::istringstream xSt(xInic);
1670 std::istringstream ySt(yInic);
1672 std::istringstream zSt(zInic);
1675 getline(inputStream,line);//FIN_COMPLEX_PORT
1677 configGComBoxInputOutputPort(false, outputPortName,xIn,yIn,zIn);
1679 } // for output complex box
1684 getline(inputStream,line);//BOXES:num
1686 strcpy( boxes, line.c_str() );
1687 result = strtok( boxes, delims );
1688 result = strtok( NULL, delims );
1691 std::istringstream is(result);
1694 for(int i = 0;i<numBoxes;i++)
1697 getline(inputStream,line);//BOX
1698 getline(inputStream,line);//package:type:name
1700 strcpy( box, line.c_str() );
1701 result = strtok( box, delims );//package
1702 std::string package(result);
1703 result = strtok( NULL, delims );//type
1704 std::string type(result);
1705 result = strtok( NULL, delims );//name
1706 std::string name(result);
1708 getline(inputStream,line);//ISEXEC:TRUE|FALSE
1710 strcpy( exec, line.c_str() );
1711 result = strtok( exec, delims );//ISEXEC
1712 result = strtok( NULL, delims );//TRUE|FALSE
1713 std::string isExec(result);
1716 getline(inputStream,line);//xInic:yInic:zInic
1718 strcpy( coord, line.c_str() );
1719 result = strtok( coord, delims );//xInic
1720 std::string xInic(result);
1721 result = strtok( NULL, delims );//yInic
1722 std::string yInic(result);
1723 result = strtok( NULL, delims );//zInic
1724 std::string zInic(result);
1726 double xIn, yIn, zIn;
1727 std::istringstream xSt(xInic);
1729 std::istringstream ySt(yInic);
1731 std::istringstream zSt(zInic);
1735 getline(inputStream,line);//xEnd:yEnd:zEnd
1736 strcpy( coord, line.c_str() );
1737 result = strtok( coord, delims );//xEnd
1738 std::string xEnd(result);
1739 result = strtok( NULL, delims );//yEnd
1740 std::string yEnd(result);
1741 result = strtok( NULL, delims );//zEnd
1742 std::string zEnd(result);
1744 double xEn, yEn, zEn;
1745 std::istringstream xEt(xEnd);
1747 std::istringstream yEt(yEnd);
1749 std::istringstream zEt(zEnd);
1752 bool boxExecutable=false;
1755 boxExecutable= true;
1758 int idBox = createGBlackBox(xIn,yIn,package,type);
1759 configGBlackBox(idBox, xIn,yIn,zIn,name, boxExecutable,xEn,yEn,zEn);
1761 GObjectController *cont = _controllers[idBox];
1762 GBlackBoxModel *bbmod = (GBlackBoxModel*)cont->getModel();
1766 getline(inputStream,line);//PORT o FIN_BOX
1767 std::string port=line.substr(0,4);
1770 getline(inputStream,line);//name:value
1772 strcpy( poort, line.c_str() );
1773 result = strtok( poort, delims );//name
1774 std::string name(result);
1775 result = strtok( NULL, delims );//value
1776 std::string value(result);
1778 bbmod->setValueToInput(name,value);
1780 getline(inputStream,line);//PORT o FIN_BOX
1781 port=line.substr(0,4);
1784 //EED bbmod->notifyObservers(_idManager);
1789 getline(inputStream,line);//CONNECTIONS:num
1791 strcpy( conns, line.c_str() );
1792 result = strtok( conns, delims );
1793 result = strtok( NULL, delims );
1796 std::istringstream isCons(result);
1799 for(int i = 0;i<numConns;i++)
1802 getline(inputStream,line);//CONNECTION
1803 getline(inputStream,line);//Startbox.PortName:EndBox.PortName
1806 strcpy( connec, line.c_str() );
1807 result = strtok( connec, delims );
1808 std::string nameStartBox(result);
1809 result = strtok( NULL, delims );
1810 std::string nameStartPort(result);
1811 result = strtok( NULL, delims );
1812 std::string nameEndBox(result);
1813 result = strtok( NULL, delims );
1814 std::string nameEndPort(result);
1816 configGConnetion(nameStartBox, nameStartPort, nameEndBox, nameEndPort);
1822 //=========================================================================
1826 //=========================================================================
1827 void wxVtkSceneManager::configGComBoxInputOutputPort(bool inputoutput, std::string portName, double xIn, double yIn,double zIn)
1830 if (inputoutput==true)
1832 idPort = createGComplexBoxInputPort(portName);
1834 idPort = createGComplexBoxOutputPort(portName);
1836 GObjectController *cont = _controllers[idPort];
1837 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
1838 cbmod->setInicPoint(xIn,yIn,zIn);
1839 cbmod->notifyObservers(_idManager);
1841 //=========================================================================
1844 //=========================================================================
1845 GBoxModel* wxVtkSceneManager::findGBox(std::string boxname)
1850 GBoxModel *boxModel = NULL;
1851 std::vector<int> lstB = getBlackBoxes();
1852 for(j = 0;j<(int)lstB.size();j++)
1855 bMod = (GBoxModel*)_controllers[idB]->getModel();
1856 if(_controllers[idB]->getModel()->getBBTKName()==boxname)
1862 if((_isComplexBox) && (boxModel==NULL))
1864 std::vector<int> lstInputs = getComplexInputPorts();
1865 for(j = 0;j<(int)lstInputs.size();j++)
1868 bMod = (GBoxModel*)_controllers[idB]->getModel();
1869 if(_controllers[idB]->getModel()->getBBTKName()==boxname)
1875 std::vector<int> lstOutputs = getComplexOutputPorts();
1876 for(j = 0;j<(int)lstOutputs.size();j++)
1878 int idB = lstOutputs[j];
1879 bMod = (GBoxModel*)_controllers[idB]->getModel();
1880 if(_controllers[idB]->getModel()->getBBTKName()==boxname)
1891 //=========================================================================
1894 void wxVtkSceneManager::configGConnetion(std::string nameStartBox, std::string nameStartPort, std::string
1895 nameEndBox, std::string nameEndPort)
1897 printf("EED wxVtkSceneManager::configGConnetion 1 %s %s %s %s\n", nameStartBox.c_str(), nameStartPort.c_str(), nameEndBox.c_str(), nameEndPort.c_str() );
1899 GBoxModel *boxModel;
1900 GPortModel *startP = NULL;
1901 GPortModel *endP = NULL;
1903 boxModel= findGBox(nameStartBox);
1906 startP = boxModel->getOutputPort(nameStartPort);
1909 boxModel= findGBox(nameEndBox);
1912 endP = boxModel->getInputPort(nameEndPort);
1916 printf("EED wxVtkSceneManager::configGConnetion 2 %p %p \n", startP, endP );
1919 int idCon = createGConnector(startP);
1920 _worldState = NOTHING_HAPPENS;
1921 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
1923 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
1924 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
1925 tempp->endContourCreation();
1926 conMod->setEndPort(endP);
1927 conView->updateStartEndPoints();
1930 //=========================================================================
1932 bool wxVtkSceneManager::boxExist(std::string boxname)
1935 std::map<int, GObjectController*>::iterator it;
1936 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1938 GObjectController *cont = it->second;
1939 if(cont->getModel()->getBBTKName()==boxname)
1947 //=========================================================================
1949 std::vector<int> wxVtkSceneManager::getBlackBoxes()
1951 std::vector<int> vect;
1952 std::map<int, GObjectController*>::iterator it;
1953 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1955 GObjectController *cont = it->second;
1956 if(cont->getGObjectType()==GBLACKBOX)
1958 vect.push_back(cont->getId());
1964 //=========================================================================
1966 std::vector<int> wxVtkSceneManager::getComplexInputPorts()
1968 std::vector<int> vect;
1969 std::map<int, GObjectController*>::iterator it;
1970 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1972 GObjectController *cont = it->second;
1973 if(cont->getGObjectType()==GCOMPLEXINPUTPORT)
1975 vect.push_back(cont->getId());
1981 //=========================================================================
1983 std::vector<int> wxVtkSceneManager::getComplexOutputPorts()
1985 std::vector<int> vect;
1986 std::map<int, GObjectController*>::iterator it;
1987 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1989 GObjectController *cont = it->second;
1990 if(cont->getGObjectType()==GCOMPLEXOUTPUTPORT)
1992 vect.push_back(cont->getId());
1998 //=========================================================================
2000 std::vector<int> wxVtkSceneManager::getConnections()
2002 std::vector<int> vect;
2003 std::map<int, GObjectController*>::iterator it;
2004 for(it = _controllers.begin(); it != _controllers.end(); ++it)
2006 GObjectController *cont = it->second;
2007 if(cont->getGObjectType()==GCONNECTOR)
2009 vect.push_back(cont->getId());
2015 //=========================================================================
2017 bool wxVtkSceneManager::isComplexBox()
2019 return _isComplexBox;
2022 //=========================================================================
2024 void wxVtkSceneManager::setComplexBox(bool val)
2029 //=========================================================================
2031 int wxVtkSceneManager::addObjectController(GObjectController* objController)
2033 //Register the controller of the new object
2034 registerController((InteractorStyleMaracas*) objController);
2036 //Add the object to the objects list
2037 int newId = _contLastId;//_controllers.size();
2038 objController->setId(newId);
2039 _controllers[newId] = objController;
2044 //=========================================================================
2046 int wxVtkSceneManager::getNumSelectedObjects()
2048 return _selectedObjects.size();
2051 //=========================================================================
2053 std::map<int,GObjectController*> wxVtkSceneManager::getSelectedObjects()
2055 std::map<int,GObjectController*> mapSelected;
2057 std::map<int, GObjectController*>::iterator it;
2058 for(it = _controllers.begin(); it != _controllers.end(); ++it)
2060 GObjectController *cont = it->second;
2061 if(cont->getGObjectType()==GBLACKBOX && cont->getView()->getState()==SELECTED)
2063 mapSelected[cont->getId()]=cont;
2067 std::map<int, GObjectController*>::iterator it2;
2068 for(it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
2070 GObjectController *cont = it2->second;
2071 if(cont->getGObjectType()==GCONNECTOR)
2073 GConnectorModel* cmod = (GConnectorModel*)cont->getModel();
2074 GBoxModel* endPortParentBox = cmod->getEndPort()->getParentBox();
2075 GBoxModel* startPortParentBox = cmod->getStartPort()->getParentBox();
2077 std::map<int, GObjectController*>::iterator iterOBJ1 = mapSelected.find(startPortParentBox->getObjectId());
2078 std::map<int, GObjectController*>::iterator iterOBJ2 = mapSelected.find(endPortParentBox->getObjectId());
2080 if(iterOBJ1 != mapSelected.end() && iterOBJ2 != mapSelected.end())
2082 int ID = cont->getId();
2083 mapSelected[ID]=cont;
2090 //=========================================================================
2092 void wxVtkSceneManager::addObjects(std::map<int,GObjectController*> objectsMap)
2095 std::map<int,int> oldIdNewIdBoxes;
2096 std::vector<int> connections;
2098 std::map<int, GObjectController*>::iterator it;
2099 for(it = objectsMap.begin(); it != objectsMap.end(); ++it)
2101 GObjectController *cont = it->second;
2102 int type = cont->getGObjectType();
2107 double xInic, yInic,zInic;
2108 GBlackBoxModel* copyBox = (GBlackBoxModel*)cont->getModel();
2109 copyBox->getInicPoint(xInic,yInic,zInic);
2110 int idBox = createGBlackBox(0,0,copyBox->getBBTKPackage(),copyBox->getBBTKType());
2112 int idcB = copyBox->getObjectId();
2113 oldIdNewIdBoxes[idcB]=idBox;
2114 cont = _controllers[idBox];
2115 GBlackBoxModel* newbox = (GBlackBoxModel*)cont->getModel();
2116 newbox->setInicPoint(xInic,yInic,zInic);
2117 int num = newbox->getNumInputPorts();
2118 for(int j=0;j<num;j++)
2120 newbox->setValueToInputPort(j,copyBox->getValueInputPort(j));
2122 newbox->notifyObservers(_idManager);
2124 else if(type==GCONNECTOR)
2126 int idCon = cont->getId();
2127 connections.push_back(idCon);
2132 for(int i = 0 ;i<(int)connections.size();i++)
2134 int objId = connections[i];
2135 GObjectController *cont = objectsMap[objId];
2136 GConnectorModel* connectModel = (GConnectorModel*)cont->getModel();
2138 GPortModel* startPort = connectModel->getStartPort();
2139 int startPortIndex = startPort->getPosInBox();
2140 GPortModel* endPort = connectModel->getEndPort();
2141 int endPortIndex = endPort->getPosInBox();
2143 GBlackBoxModel* startPortParentBox = (GBlackBoxModel*)startPort->getParentBox();
2144 GBlackBoxModel* endPortParentBox = (GBlackBoxModel*)endPort->getParentBox();
2146 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2147 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2149 GBlackBoxModel* newStartBox = (GBlackBoxModel*)_controllers[idNewStartBox]->getModel();
2150 GBlackBoxModel* newEndBox = (GBlackBoxModel*)_controllers[idNewEndBox]->getModel();
2152 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2153 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2155 // Creates connection
2156 int idCon = createGConnector(newStartPort);
2157 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
2158 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
2159 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
2160 tempp->endContourCreation();
2161 conMod->setEndPort(newEndPort);
2162 conView->updateStartEndPoints();
2165 std::map<int, int>::iterator itIds;
2166 for(itIds = oldIdNewIdBoxes.begin(); itIds != oldIdNewIdBoxes.end(); ++itIds)
2168 int idOld = itIds->first;
2169 int idNew = itIds->second;
2171 GBlackBoxModel* oldBox = (GBlackBoxModel*)objectsMap[idOld]->getModel();
2172 GBlackBoxModel* newBox = (GBlackBoxModel*)_controllers[idNew]->getModel();
2174 std::vector<int> oldInputConnections = oldBox->getConnectedInputs();
2175 std::vector<int> oldOutputConnections = oldBox->getConnectedOutputs();
2176 std::vector<int> newInputConnections = newBox->getConnectedInputs();
2177 std::vector<int> newOutputConnections = newBox->getConnectedOutputs();
2179 for(int k = 0; k<(int)oldInputConnections.size();k++)
2182 //EED int toCreate=-1;
2183 for(int l = 0; l<(int)newInputConnections.size() && !exist;l++)
2185 if(oldInputConnections[k]==newInputConnections[l])
2193 //Create complex input
2194 int posInBox = oldInputConnections[k];
2195 GPortModel* inputPort = oldBox->getInputPort(posInBox);
2196 std::string inputPortName = inputPort->getBBTKName();
2197 int idInputPort = createGComplexBoxInputPort(inputPortName);
2198 GObjectController *cont = _controllers[idInputPort];
2199 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
2201 inputPort->getInicPoint(xIn,yIn,zIn);
2203 cbmod->setInicPoint(xIn,yIn,zIn);
2204 cbmod->notifyObservers(_idManager);
2206 GPortModel* inputPortEnd = newBox->getInputPort(posInBox);
2208 // Creates connection
2209 int idCon = createGConnector(cbmod->getOutputPort(0));
2210 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
2211 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
2212 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
2213 tempp->endContourCreation();
2214 conMod->setEndPort(inputPortEnd);
2215 conView->updateStartEndPoints();
2222 for(int k = 0; k<(int)oldOutputConnections.size();k++)
2225 //EED int toCreate=-1;
2226 for(int l = 0; l<(int)newOutputConnections.size() && !exist;l++)
2228 if(oldOutputConnections[k]==newOutputConnections[l])
2236 //Create complex output
2237 int posInBox = oldOutputConnections[k];
2238 GPortModel* outputPort = oldBox->getOutputPort(posInBox);
2239 std::string outputPortName = outputPort->getBBTKName();
2240 int idOutputPort = createGComplexBoxOutputPort(outputPortName);
2241 GObjectController *cont = _controllers[idOutputPort];
2242 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
2244 outputPort->getInicPoint(xIn,yIn,zIn);
2246 cbmod->setInicPoint(xIn,yIn,zIn);
2247 cbmod->notifyObservers(_idManager);
2249 GPortModel* outputPortEnd = newBox->getOutputPort(posInBox);
2251 // Creates connection
2252 int idCon = createGConnector(outputPortEnd);
2253 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
2254 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
2255 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
2256 tempp->endContourCreation();
2257 conMod->setEndPort(cbmod->getInputPort(0));
2258 conView->updateStartEndPoints();
2269 //=========================================================================
2271 } // EO namespace bbtk