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,900,1000);
107 _baseView->GetRenderer()->SetBackground(0.9,0.9,0.9);
108 _baseView->GetRenderer()->GradientBackgroundOff();
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 _aPolygonMapper->Modified();
179 _baseView->GetRenderer()->AddActor( _fillObjectActor );
182 //=========================================================================
184 std::string wxVtkSceneManager::generateANewNameForABox()
186 std::stringstream boxname;
189 boxname << "Box0" << _numBoxes;
191 boxname << "Box" << _numBoxes;
194 return boxname.str();
197 //=========================================================================
199 std::string wxVtkSceneManager::findANewNameForABox()
201 std::string boxname=generateANewNameForABox();
203 while (boxExist(boxname)==true)
205 boxname=generateANewNameForABox();
211 //=========================================================================
212 void wxVtkSceneManager::configGBlackBox(int idBox, double xIn, double yIn, double zIn, std::string name, bool boxExecutable,double xEn,double yEn,double zEn)
214 GObjectController *cont = _controllers[idBox];
215 GBlackBoxModel *bbmod = (GBlackBoxModel*)cont->getModel();
216 bbmod->setBBTKName(name);
217 bbmod->setInicPoint(xIn,yIn,zIn);
218 bbmod->setFinalPoint(xEn,yEn,zEn);
219 bbmod->setExecutable(boxExecutable);
221 bbmod->notifyObservers(_idManager);
226 //=========================================================================
228 int wxVtkSceneManager::createGBlackBox(int x, int y, std::string packageName, std::string boxType)
230 _worldState = NOTHING_HAPPENS;
231 //EED int windowWidth = _baseView->GetRenWin()->GetSize()[0];
232 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
234 int type = GBLACKBOX;
236 //Create the MVC Objects
238 GBlackBoxModel *model = (GBlackBoxModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
239 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
240 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
242 BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxType);
244 //Prepares the initial model
245 //The coordinates obtained are the following. Top-Left:x=0,y=0 Bottom-Right:x=width,y=height
248 double yy = windowHeight-y;
250 //z value is not important yet, because it is only used a parallel projection
253 _baseView->TransCoordScreenToWorld(xx,yy,zz);
254 model->setInicPoint(xx,yy,zz);
256 std::stringstream stream;
258 std::string newBoxName;
259 newBoxName = findANewNameForABox();
262 stream << newBoxName;
264 std::string arraystring = stream.str();
266 model->setBBTKName(arraystring);
267 model->setBBTKType(boxType);
268 model->setBBTKPackage(packageName);
270 model->addObserver(view);
271 model->addObserver(this);
273 //Iterate and create the input ports
274 std::map<std::string, BlackBoxInputDescriptor*> descriptorInMap = descriptor->GetInputDescriptorMap();
275 std::map<std::string, BlackBoxInputDescriptor*>::iterator itInput;
278 for(itInput = descriptorInMap.begin(); itInput != descriptorInMap.end(); ++itInput)
280 BlackBoxInputDescriptor *desc = itInput->second;
281 createGInputPort(GINPUTPORT,i,model,desc);
285 //Iterate and create the output ports
286 std::map<std::string, BlackBoxOutputDescriptor*> descriptorOutMap = descriptor->GetOutputDescriptorMap();
287 std::map<std::string, BlackBoxOutputDescriptor*>::iterator itOutput;
290 for(itOutput = descriptorOutMap.begin();itOutput != descriptorOutMap.end(); ++itOutput)
292 BlackBoxOutputDescriptor *desc = itOutput->second;
293 createGOutputPort(GOUTPUTPORT,i,model,desc);
298 //Associates the view with the correspondent renderer and the model.
299 //(NOTE: Refresh is only made by the view)
300 view->setModel(model);
301 view->setBaseView(_baseView);
302 view->initVtkObjects();
304 //Associates the controller with the correspondent model and view
305 controller->setModelAndView(model,view);
307 //Resgiter change to the observers of the actual model
308 model->notifyObservers(_idManager);
310 int newId = addObjectController(controller);
316 //=========================================================================
318 int wxVtkSceneManager::createGComplexBoxInputPort(std::string inputName)
320 //EED int windowWidth=_baseView->GetRenWin()->GetSize()[0];
321 int windowHeight=_baseView->GetRenWin()->GetSize()[1];
323 int type = GCOMPLEXINPUTPORT;
325 //Create the MVC Objects
327 GComplexBoxPortModel *model = (GComplexBoxPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
328 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
329 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
331 //Prepares the initial model
334 double yy = windowHeight-5;
336 //z value is not important yet, because it is only used a parallel projection
339 _baseView->TransCoordScreenToWorld(xx,yy,zz);
340 model->setInicPoint(xx,yy,zz);
342 model->setBBTKName(inputName);
343 model->setBBTKType("ComplexInputPort");
344 model->setComplexPortType(type);
346 model->addObserver(view);
347 model->addObserver(this);
349 //create the output port
350 GPortController* portController = createGPort(GOUTPUTPORT,inputName,"ComplexInputPort",0,model);
351 model->addOutputPort((GPortModel*)portController->getModel());
353 //Associates the view with the correspondent renderer and the model.
354 //(NOTE: Refresh is only made by the view)
355 view->setModel(model);
356 view->setBaseView(_baseView);
357 view->initVtkObjects();
359 //Associates the controller with the correspondent model and view
360 controller->setModelAndView(model,view);
362 //Resgiter change to the observers of the actual model
363 model->notifyObservers(_idManager);
365 int newId = addObjectController(controller);
369 //=========================================================================
371 int wxVtkSceneManager::createGComplexBoxOutputPort(std::string outputName)
373 //EED int windowWidth=_baseView->GetRenWin()->GetSize()[0];
374 int windowHeight=_baseView->GetRenWin()->GetSize()[1];
376 int type = GCOMPLEXOUTPUTPORT;
378 //Create the MVC Objects
380 GComplexBoxPortModel *model = (GComplexBoxPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
381 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
382 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
384 //Prepares the initial model
387 double yy = windowHeight-5;
389 //z value is not important yet, because it is only used a parallel projection
392 _baseView->TransCoordScreenToWorld(xx,yy,zz);
393 model->setInicPoint(xx,yy,zz);
395 model->setBBTKName(outputName);
396 model->setBBTKType("ComplexOutputPort");
397 model->setComplexPortType(type);
399 model->addObserver(view);
400 model->addObserver(this);
402 //create the output port
403 GPortController* portController = createGPort(GINPUTPORT,outputName,"ComplexInputPort",0,model);
404 model->addInputPort((GPortModel*)portController->getModel());
406 //Associates the view with the correspondent renderer and the model.
407 //(NOTE: Refresh is only made by the view)
408 view->setModel(model);
409 view->setBaseView(_baseView);
410 view->initVtkObjects();
412 //Associates the controller with the correspondent model and view
413 controller->setModelAndView(model,view);
415 //Resgiter change to the observers of the actual model
416 model->notifyObservers(_idManager);
418 int newId = addObjectController(controller);
422 //=========================================================================
424 int wxVtkSceneManager::createGInputPort(int portType, int posinBox,GBoxModel *blackBox, BlackBoxInputDescriptor *desc)
426 GPortController* portController = createGPort(portType,desc->GetName(),desc->GetTypeName(),posinBox,blackBox);
427 blackBox->addInputPort((GPortModel*)portController->getModel());
428 return portController->getId();
431 //=========================================================================
433 int wxVtkSceneManager::createGOutputPort(int portType, int posinBox,GBoxModel *blackBox, BlackBoxOutputDescriptor *desc)
435 GPortController* portController = createGPort(portType,desc->GetName(),desc->GetTypeName(),posinBox,blackBox);
436 blackBox->addOutputPort((GPortModel*)portController->getModel());
437 return portController->getId();
440 //=========================================================================
442 GPortController* wxVtkSceneManager::createGPort(int portType,std::string bbtkName, std::string bbtkType, int posInBox,GBoxModel *blackBox)
446 //Create the MVC Objects
447 GPortModel *model = (GPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
448 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
449 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
451 model->registerInBox(blackBox,portType, posInBox);
453 model->setBBTKType(bbtkType);
454 model->setBBTKName(bbtkName);
456 model->addObserver(view);
457 model->addObserver(this);
459 //Associates the view with the correspondent renderer and the model.
460 //(NOTE: Refresh is only made by the view)
461 view->setModel(model);
462 view->setBaseView(_baseView);
463 view->initVtkObjects();
465 //Associates the controller with the correspondent model and view
466 controller->setModelAndView(model,view);
468 model->notifyObservers(_idManager);
470 addObjectController(controller);
472 return (GPortController*)controller;
475 //=========================================================================
477 int wxVtkSceneManager::createGConnector(GPortModel* startPort)
479 int type = GCONNECTOR;
481 manualConnectorContourController* manContourControl = new manualConnectorContourController();
482 manualConnectorContourView* manContourView = new manualConnectorContourView();
483 manualContourModel* manContourModel = new manualContourModel();
485 GConnectorController* connectorcontroller = new GConnectorController();
486 GConnectorModel* connectorModel = new GConnectorModel();
487 vtkGConnectorView* connectorView = new vtkGConnectorView();
488 connectorModel->setGObjectType(type);
490 manContourModel->SetCloseContour(false);
491 connectorModel->setStartPort(startPort);
493 manContourView->SetModel( manContourModel );
494 manContourView->SetWxVtkBaseView( _baseView );
495 manContourView->SetRange( 0.5 );
496 manContourView->SetZ( 900 );
498 manContourView->SetColorNormalContour(0, 0, 1);
499 manContourView->SetColorEditContour(0.5, 0.5, 0.5);
500 manContourView->SetColorSelectContour(1, 0.8, 0);
501 manContourView->SetWidthLine(1);
502 manContourView->SetShowText(false);
504 manContourControl->SetModelView( manContourModel , manContourView );
506 manContourControl->CreateNewManualContour();
508 manContourView->RefreshContour();
512 connectorModel->getInicPoint(x,y,z);
514 manContourControl->SetState(1);
515 manContourModel->SetCloseContour(false);
517 manContourModel->AddPoint(x,y,z);
518 manContourView->AddPoint();
520 manContourModel->AddPoint(x,y,z);
521 manContourView->AddPoint();
523 int bak= manContourControl->GetNumberOfPointsManualContour() - 1;
524 manContourControl->_bakIdPoint=bak;
525 manContourView->Refresh();
527 manContourControl->SetMoving( false );
529 connectorcontroller->setModelAndView(connectorModel,connectorView);
531 int newId = addObjectController(connectorcontroller);
533 connectorcontroller->setManualContourController(manContourControl);
534 connectorModel->setManualContourModel(manContourModel);
535 connectorView->setManualContourView(manContourView);
536 connectorView->setModel(connectorModel);
537 connectorView->setBaseView(_baseView);
540 connectorModel->addObserver(connectorView);
541 connectorModel->addObserver(this);
546 //=========================================================================
548 void wxVtkSceneManager::registerController(InteractorStyleMaracas *param)
550 vtkInteractorStyleBaseView* baseViewControlManager = (vtkInteractorStyleBaseView*)_baseView->GetInteractorStyleBaseView();
551 baseViewControlManager->AddInteractorStyleMaracas( param );
554 //=========================================================================
556 void wxVtkSceneManager::unregisterController(InteractorStyleMaracas *param)
558 vtkInteractorStyleBaseView* baseViewControlManager = (vtkInteractorStyleBaseView*)_baseView->GetInteractorStyleBaseView();
559 baseViewControlManager->RemoveInteractorStyleMaracas( param );
562 //=========================================================================
564 vtkRenderer* wxVtkSceneManager::getRenderer()
566 return _baseView->GetRenderer();
569 //=========================================================================
571 vtkRenderWindow* wxVtkSceneManager::getRenderWindow()
573 return _baseView->GetRenWin();
575 //=========================================================================
578 void wxVtkSceneManager::update(int idController,int command)
580 if(command != NO_COMMAND)
582 if(command == ADD_TO_SELECTED)
584 //EED GObjectController* cont = _controllers[idController];
587 for (int i=0; i<(int)_selectedObjects.size() && foundID==false; i++)
589 int id = _selectedObjects[i];
597 int id = idController;
598 _selectedObjects.push_back(id);
602 else if(command == INIT_CREATION_CONTOUR)
604 _worldState = INIT_CREATION_CONTOUR;
605 GObjectController* cont = _controllers[idController];
606 GPortModel* startOutputPort = (GPortModel*)cont->getModel();
609 // The last one is the controller of the connector
610 std::map<int, GObjectController*>::iterator it2;
612 for(it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
614 GObjectController *cont = it2->second;
615 if(cont->getGObjectType() == GPORT )
617 GPortModel* port = (GPortModel*)cont->getModel();
618 if(port->getPortType()==GINPUTPORT)
620 cont->SetActive(true);
624 cont->getView()->setState(NOTHING_HAPPENS);
625 cont->getModel()->notifyObservers(_idManager);
626 cont->SetActive(false);
631 cont->getView()->setState(NOTHING_HAPPENS);
632 cont->getModel()->notifyObservers(_idManager);
633 cont->SetActive(false);
637 _selectedObjects.clear();
639 _idConnectionInCreation=createGConnector(startOutputPort);
642 else if(command == FIN_CREATION_CONTOUR && _worldState == INIT_CREATION_CONTOUR)
644 _worldState = NOTHING_HAPPENS;
645 //int id = _controllers.size()-1;
646 GObjectController* cont = _controllers[_idConnectionInCreation];
647 GConnectorModel* modelContour = (GConnectorModel*)cont->getModel();
649 GObjectController* finPort = _controllers[idController];
650 if(finPort->getGObjectType() == GPORT)
652 GPortModel* modelPort = (GPortModel*)finPort->getModel();
653 modelContour->setEndPort(modelPort);
656 manualConnectorContourController* manCont = ((GConnectorController*)cont)->getManualContourController();
657 manualConnectorContourView* connView = (manualConnectorContourView*)manCont->GetManualViewBaseContour();
660 std::map<int, GObjectController*>::iterator it2;
662 for(it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
664 GObjectController *cont = it2->second;
665 if(cont->getView()!=NULL)
667 cont->getView()->setState(NOTHING_HAPPENS);
668 cont->getModel()->notifyObservers(_idManager);
670 cont->SetActive(true);
677 //=========================================================================
679 bool wxVtkSceneManager::OnMouseMove()
682 bool okStatusMessage = false;
683 bool okPortMessage = false;
684 wxVTKRenderWindowInteractor *wxVTKiren;
685 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
686 wxVTKiren->GetEventPosition(X,Y);
689 if(_worldState == DRAG_OBJECTS)
691 for (int i=0; i<(int)_selectedObjects.size(); i++)
693 int id = _selectedObjects[i];
694 GObjectController* cont = _controllers[id];
697 cont->getView()->setStartDragging(true);
699 cont->getView()->moveObject(X,Y);
700 cont->getView()->setState(DRAG);
701 cont->getModel()->notifyObservers(_idManager);
704 std::map<int, GObjectController*>::iterator it;
706 for(it = _controllers.begin(); it != _controllers.end(); ++it)
708 GObjectController *desc = it->second;
709 if(desc->getGObjectType()==GCONNECTOR)
711 vtkGConnectorView* vconn = (vtkGConnectorView*)desc->getView();
712 vconn->updateStartEndPoints();
716 _startDragging=false;
719 else if(_worldState == NOTHING_HAPPENS || _worldState == INIT_CREATION_CONTOUR)
721 std::map<int, GObjectController*>::iterator it;
723 for(it = _controllers.begin(); it != _controllers.end(); ++it)
725 GObjectController *desc = it->second;
726 int type = desc->getGObjectType();
727 int state = desc->getView()->getState();
728 desc->getModel()->getCenter(px,py,pz);
730 if(state == HIGHLIGHTED){
731 okStatusMessage = true;
732 updateStatusBar(desc->getStatusText());
735 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
736 _parent->displayBlackBoxInfo(mod->getBBTKPackage(),mod->getBBTKType());
741 okPortMessage = true;
743 _textActor->SetInput( desc->getStatusText().c_str() );
744 _textActor->SetScale(0.1);
745 _textActor->SetPosition( px-25 ,py+1 , pz+2 );
751 _fillObjectActor->SetScale(1);
752 _fillObjectActor->GetProperty()->SetOpacity(0.50);
753 _fillObjectActor->SetPosition(px,py,1);
754 _aPolygonMapper->Modified();
757 } // for controllers it
760 if (okStatusMessage==false)
765 if (okPortMessage==false)
767 _textActor->SetScale(0.0001);
768 _fillObjectActor->SetScale(0.0001);
775 //=========================================================================
777 bool wxVtkSceneManager::OnLeftButtonDown()
779 if(_worldState==INIT_CREATION_CONTOUR)
781 bool isOverPort=false;
782 std::map<int, GObjectController*>::iterator it;
783 for(it = _controllers.begin(); it != _controllers.end() && isOverPort==false; ++it)
785 GObjectController *desc = it->second;
786 if(desc->getGObjectType()==GPORT)
788 GPortModel* portmod=(GPortModel*)desc->getModel();
789 vtkGObjectView* portView=desc->getView();
790 if(portmod->getPortType()==GINPUTPORT && portView->getState()==HIGHLIGHTED)
797 if(isOverPort==false)
799 _worldState=NOTHING_HAPPENS;
800 //int lastId = _controllers.size()-1;
801 GConnectorController *connector = (GConnectorController*)_controllers[_controllers.size()-1];
802 connector->removeFromScene();
803 unregisterController(connector);
804 _controllers.erase(_controllers.size()-1);
806 for(it = _controllers.begin(); it != _controllers.end(); ++it)
808 GObjectController *desc = it->second;
809 desc->SetActive(true);
810 desc->getView()->setState(NOTHING_HAPPENS);
811 desc->getModel()->notifyObservers(_idManager);
816 if(_selectedObjects.size()!=0)
818 _worldState = DRAG_OBJECTS;
819 _startDragging = true;
821 for (int i = 0; i < (int)_selectedObjects.size(); i++)
823 int id = _selectedObjects[i];
824 GObjectController* cont = _controllers[id];
825 cont->getView()->setState(DRAG);
826 cont->getModel()->notifyObservers(_idManager);
835 //=========================================================================
837 bool wxVtkSceneManager::OnLeftButtonUp()
839 if(_worldState == DRAG_OBJECTS)
841 _worldState = NOTHING_HAPPENS;
843 for (int i = 0; i < (int)_selectedObjects.size(); i++)
845 int id = _selectedObjects[i];
846 GObjectController* cont = _controllers[id];
847 cont->getView()->setState(SELECTED);
848 cont->getModel()->notifyObservers(_idManager);
854 //=========================================================================
856 bool wxVtkSceneManager::OnRightButtonUp()
858 if(_worldState==INIT_CREATION_CONTOUR)
860 _worldState=NOTHING_HAPPENS;
861 //int lastId = _controllers.size()-1;
862 GConnectorController *connector = (GConnectorController*)_controllers[_idConnectionInCreation];
863 connector->removeFromScene();
864 unregisterController(connector);
865 _controllers.erase(_idConnectionInCreation);
867 std::map<int, GObjectController*>::iterator it;
868 for(it = _controllers.begin(); it != _controllers.end(); ++it)
870 GObjectController *desc = it->second;
871 desc->SetActive(true);
872 desc->getView()->setState(NOTHING_HAPPENS);
873 desc->getModel()->notifyObservers(_idManager);
878 for (int i = 0; i < (int)_selectedObjects.size(); i++)
880 int id = _selectedObjects[i];
881 GObjectController* cont = _controllers[id];
882 cont->SetActive(true);
883 cont->getView()->setState(NOTHING_HAPPENS);
884 cont->getModel()->notifyObservers(_idManager);
887 _selectedObjects.clear();
892 //=========================================================================
894 bool wxVtkSceneManager::OnLeftDClick()
897 wxVTKRenderWindowInteractor *wxVTKiren;
898 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
899 wxVTKiren->GetEventPosition(X,Y);
901 std::map<int, GObjectController*>::iterator it;
903 bool clickOnObject = false;
905 for(it = _controllers.begin(); it != _controllers.end() && clickOnObject==false; ++it)
907 GObjectController *cont = it->second;
908 int type = cont->getGObjectType();
910 if(cont->getView()->isPointInside(X,Y))
914 for (int i=0; i< (int)_selectedObjects.size(); i++)
916 int id = _selectedObjects[i];
917 GObjectController* control = _controllers[id];
918 control->getView()->setState(NOTHING_HAPPENS);
920 _selectedObjects.clear();
922 GBlackBoxModel *bbmodel = (GBlackBoxModel*)cont->getModel();
923 _parent->editBlackBox(bbmodel);
925 clickOnObject = true;
929 if(clickOnObject==false)
931 //_parent->editDiagramParameters(this);
937 //=========================================================================
939 bool wxVtkSceneManager::OnChar()
941 char keyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
943 // KeyCode 127 : Delete Key
944 // KeyCode 8 : Backspace Key
945 if(keyCode == 8 || keyCode == 127)
947 if(_selectedObjects.size()>0)
949 for(int i=0;i<(int)_selectedObjects.size();i++)
951 int id = _selectedObjects[i];
952 std::map<int,GObjectController*>::iterator it;
953 it = _controllers.find(id);
954 if (it!=_controllers.end())
959 _selectedObjects.clear();
966 //=========================================================================
968 void wxVtkSceneManager::AddControlerToBeRemove(std::vector<int> *controllersToRemove, int id)
973 for(i=0 ; i < (int)controllersToRemove->size() ; i++ )
975 if (id == (*controllersToRemove)[i] )
983 controllersToRemove->push_back( id );
988 //=========================================================================
990 void wxVtkSceneManager::deleteObject(int id)
992 GObjectController *control = _controllers[id];
993 std::vector<int> controllersToRemove;
995 if(control->getGObjectType()==GBLACKBOX || control->getGObjectType()==GCOMPLEXINPUTPORT || control->getGObjectType()==GCOMPLEXOUTPUTPORT)
997 GBoxModel *bbmod = (GBoxModel*)control->getModel();
998 std::vector<GPortModel*> inputs = bbmod->getInputPorts();
1000 bool boxConnected = false;
1002 // Add box input controllers to be removed
1003 for(int i = 0;i< (int)inputs.size();i++)
1005 AddControlerToBeRemove( &controllersToRemove, inputs[i]->getObjectId() );
1006 if(inputs[i]->isConnected())
1008 boxConnected = true;
1012 std::vector<GPortModel*> outputs = bbmod->getOutputPorts();
1014 // Add box output controllers to be removed
1015 for(int i = 0;i<(int)outputs.size();i++)
1017 AddControlerToBeRemove( &controllersToRemove, outputs[i]->getObjectId() );
1018 if(outputs[i]->isConnected())
1020 boxConnected = true;
1024 // Add connection controllers to be removed
1025 std::map<int, GObjectController*>::iterator it;
1026 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1028 GObjectController *cont = it->second;
1029 int type = cont->getGObjectType();
1030 if(type==GCONNECTOR)
1032 GConnectorModel *conMod = (GConnectorModel*)cont->getModel();
1033 if(conMod->getStartPort()!=NULL && conMod->getStartPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
1035 AddControlerToBeRemove( &controllersToRemove, conMod->getObjectId() );
1037 if(conMod->getEndPort()!=NULL && conMod->getEndPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
1039 AddControlerToBeRemove( &controllersToRemove, conMod->getObjectId() );
1044 // Add box controller to be removed
1045 AddControlerToBeRemove( &controllersToRemove, bbmod->getObjectId() );
1047 else if(control->getGObjectType()==GCONNECTOR)
1049 GConnectorModel *conMod = (GConnectorModel*)control->getModel();
1050 AddControlerToBeRemove( &controllersToRemove, conMod->getObjectId() );
1054 std::map<int,GObjectController*>::iterator it;
1056 for(int i = 0;i<(int)controllersToRemove.size();i++)
1058 int key = controllersToRemove[i];
1059 it = _controllers.find( key );
1060 GObjectController *cont = _controllers[ key ];
1063 cont->removeFromScene();
1064 unregisterController((InteractorStyleMaracas*)cont);
1065 _controllers.erase(it);
1070 //=========================================================================
1072 void wxVtkSceneManager::displayBlackBoxInfo(std::string packageName, std::string boxName)
1074 _parent->displayBlackBoxInfo(packageName,boxName);
1077 //=========================================================================
1079 void wxVtkSceneManager::updateStatusBar(std::string textStatus)
1081 _parent->updateStatusBar(textStatus);
1084 //=========================================================================
1086 std::string wxVtkSceneManager::getDiagramBBS()
1088 bool existsExec=false;
1090 std::vector<std::string> packages;
1091 std::vector<int> boxes;
1092 std::vector<int> connections;
1093 std::vector<int> execBoxes;
1095 std::map<int, GObjectController*>::iterator it;
1097 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1099 GObjectController *desc = it->second;
1100 int type = desc->getGObjectType();
1104 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
1106 std::string pkg = mod->getBBTKPackage();
1107 bool existsPkg = false;
1108 for(int t = 0;t< (int)packages.size() && existsPkg == false;t++)
1110 if(packages[t]==pkg)
1117 packages.push_back(pkg);
1121 boxes.push_back(it->first);
1122 if(mod->isExecutable())
1124 execBoxes.push_back(it->first);
1128 else if(type==GCONNECTOR)
1130 connections.push_back(it->first);
1134 std::string script = "";
1135 script+="# BBTK GEditor Script\n";
1136 script+="# ----------------------\n";
1140 script+="include std\n"; // EED
1141 script+="include itkvtk\n"; // EED
1143 for(i = 0; i< (int)packages.size();i++)
1146 script+=packages[i];
1151 // script+="include std\n"; // JPR
1153 for(i = 0; i < (int)boxes.size();i++)
1157 GObjectController *control = _controllers[id];
1158 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1160 script+=model->getBBTKType();
1162 script+=model->getBBTKName();
1165 std::vector<GPortModel*> inputs = model->getInputPorts();
1166 for(int j = 0; j < (int)inputs.size();j++)
1168 GPortModel* inputPort = inputs[j];
1169 if(inputPort->isValueSet())
1172 script+=model->getBBTKName();
1174 script+=inputPort->getBBTKName();
1176 script+=inputPort->getValue();
1186 for(i = 0; i<(int)connections.size();i++)
1189 int id = connections[i];
1190 GObjectController *control = _controllers[id];
1191 GConnectorModel *model = (GConnectorModel*)control->getModel();
1193 //Start Connection info
1194 GPortModel *start = model->getStartPort();
1195 script+=start->getParentBox()->getBBTKName();
1197 script+=start->getBBTKName();
1201 //End Connection info
1202 GPortModel *end = model->getEndPort();
1203 script+=end->getParentBox()->getBBTKName();
1205 script+=end->getBBTKName();
1211 for(i = 0; i<(int)execBoxes.size();i++)
1214 int id = execBoxes[i];
1215 GObjectController *control = _controllers[id];
1216 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1218 script+=model->getBBTKName();
1227 //=========================================================================
1229 std::string wxVtkSceneManager::saveComplexBoxBBS(std::string cbName,std::string cbAuthor,std::string cbCategory,std::string cbDescription)
1232 std::vector<std::string> packages;
1233 std::vector<int> boxes;
1234 std::vector<int> connections;
1235 std::vector<int> execBoxes;
1237 std::map<int, GObjectController*>::iterator it;
1239 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1241 GObjectController *desc = it->second;
1242 int type = desc->getGObjectType();
1246 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
1248 std::string pkg = mod->getBBTKPackage();
1249 bool existsPkg = false;
1250 for(int t = 0;t<(int)packages.size() && existsPkg == false;t++)
1252 if(packages[t]==pkg)
1259 packages.push_back(pkg);
1263 boxes.push_back(it->first);
1264 if(mod->isExecutable())
1266 execBoxes.push_back(it->first);
1269 else if(type==GCONNECTOR)
1271 connections.push_back(it->first);
1275 std::string script = "";
1277 script+="include std\n"; // EED
1278 script+="include itkvtk\n"; // EED
1280 for(i = 0; i<(int)packages.size();i++)
1283 script+=packages[i];
1288 // Definition of a complex box
1294 script+="author \" ";
1298 script+="description \" ";
1299 script+=cbDescription;
1304 for(i = 0; i<(int)boxes.size();i++)
1308 GObjectController *control = _controllers[id];
1309 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1311 script+=model->getBBTKType();
1313 script+=model->getBBTKName();
1316 std::vector<GPortModel*> inputs = model->getInputPorts();
1317 for(int j = 0; j<(int)inputs.size();j++)
1319 GPortModel* inputPort = inputs[j];
1320 if(inputPort->isValueSet())
1323 script+=model->getBBTKName();
1325 script+=inputPort->getBBTKName();
1327 script+=inputPort->getValue();
1335 // Create connections in the script. If the connection is made with a complex port, it is created the input or output
1337 std::string complexInputs="";
1338 std::string complexOutputs="";
1341 for(i = 0; i<(int)connections.size();i++)
1343 int id = connections[i];
1344 GObjectController *control = _controllers[id];
1345 GConnectorModel *model = (GConnectorModel*)control->getModel();
1348 GPortModel *start = model->getStartPort();
1349 GBoxModel *startBox =start->getParentBox();
1351 GPortModel *end = model->getEndPort();
1352 GBoxModel *endBox =end->getParentBox();
1354 if(startBox->getGObjectType()==GCOMPLEXINPUTPORT)
1356 complexInputs+="input ";
1357 complexInputs+=startBox->getBBTKName();
1360 complexInputs+=endBox->getBBTKName();
1362 complexInputs+=end->getBBTKName();
1365 complexInputs+="\" \"";
1367 complexInputs+="\n";
1369 else if(endBox->getGObjectType()==GCOMPLEXOUTPUTPORT)
1371 complexOutputs+="output ";
1372 complexOutputs+=endBox->getBBTKName();
1374 complexOutputs+=" ";
1375 complexOutputs+=startBox->getBBTKName();
1376 complexOutputs+=".";
1377 complexOutputs+=start->getBBTKName();
1379 complexOutputs+=" ";
1380 complexOutputs+="\" \"";
1382 complexOutputs+="\n";
1387 script+=startBox->getBBTKName();
1389 script+=start->getBBTKName();
1393 //End Connection info
1394 script+=endBox->getBBTKName();
1396 script+=end->getBBTKName();
1404 for(i = 0; i<(int)execBoxes.size();i++)
1407 int id = execBoxes[i];
1408 GObjectController *control = _controllers[id];
1409 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1411 script+=model->getBBTKName();
1416 script+="# Complex input ports\n";
1417 script+=complexInputs;
1420 script+="# Complex output ports\n";
1421 script+=complexOutputs;
1430 //=========================================================================
1432 void wxVtkSceneManager::deleteAllBoxes()
1434 std::map<int, GObjectController*>::iterator it;
1435 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1437 GObjectController *cont = it->second;
1438 cont->removeFromScene();
1439 unregisterController((InteractorStyleMaracas*)cont);
1441 _selectedObjects.clear();
1442 _controllers.clear();
1446 //=========================================================================
1448 void wxVtkSceneManager::refreshScene()
1450 _baseView->RefreshView();
1453 //=========================================================================
1455 void wxVtkSceneManager::centerView()
1458 _baseView->GetRenderer()->GetActiveCamera()->GetFocalPoint(temp);
1459 _baseView->GetRenderer()->GetActiveCamera()->SetFocalPoint(0,0,temp[2]);
1460 _baseView->GetRenderer()->GetActiveCamera()->GetPosition(temp);
1461 _baseView->GetRenderer()->GetActiveCamera()->SetPosition(0,0,temp[2]);
1462 _baseView->RefreshView();
1466 //=========================================================================
1468 void wxVtkSceneManager::saveDiagram(std::string &content)
1472 //Print info IF COMPLEX BOX
1473 content+="COMPLEXBOX:";
1478 //Print info complex input ports
1479 std::vector<int> inputs = getComplexInputPorts();
1480 int insize = inputs.size();
1481 content+="COMPLEXINPUTS:";
1482 sprintf (buffer, "%d", insize);
1486 for(int i = 0;i<insize;i++)
1489 GObjectController *cont = _controllers[id];
1490 cont->getModel()->save(content);
1493 //Print info complex output ports
1494 std::vector<int> outputs = getComplexOutputPorts();
1495 int outsize = outputs.size();
1496 content+="COMPLEXOUTPUTS:";
1497 sprintf (buffer, "%d", outsize);
1501 for(int i = 0;i<outsize;i++)
1503 int id = outputs[i];
1504 GObjectController *cont = _controllers[id];
1505 cont->getModel()->save(content);
1514 std::vector<int> boxes = getBlackBoxes();
1515 int bsize = boxes.size();
1517 sprintf (buffer, "%d", bsize);
1521 for(int i = 0;i<bsize;i++)
1524 GObjectController *cont = _controllers[id];
1525 cont->getModel()->save(content);
1529 std::vector<int> connections = getConnections();
1530 int csize = connections.size();
1531 content+="CONNECTIONS:";
1532 sprintf (buffer, "%d", csize);
1536 for(int i = 0;i<csize;i++)
1538 int id = connections[i];
1539 GObjectController *cont = _controllers[id];
1540 cont->getModel()->save(content);
1545 //=========================================================================
1547 void wxVtkSceneManager::loadDiagram(ifstream &inputStream)
1550 std::string line="";
1551 char delims[] = ":";
1552 char *result = NULL;
1553 getline(inputStream,line);
1556 while ( !inputStream.eof() )
1558 if(line=="" || line[0]=='#')
1560 getline(inputStream,line);
1562 else if(line=="APP_START")
1573 getline(inputStream,line);//COMPLEX_BOX:TRUE|FALSE
1575 strcpy( complex, line.c_str() );
1576 result = strtok( complex, delims );
1577 result = strtok( NULL, delims );
1578 std::string isComplexBox(result);
1580 if(isComplexBox=="TRUE")
1584 //-----------------------
1585 //- COMPLEX INPUT PORTS
1586 //-----------------------
1587 getline(inputStream,line);//COMPLEXINPUTS:num
1589 strcpy( inputs, line.c_str() );
1590 result = strtok( inputs, delims );
1591 result = strtok( NULL, delims );
1594 std::istringstream inps(result);
1597 for(int i = 0;i<numInputs;i++)
1600 getline(inputStream,line);//COMPLEX_PORT
1601 getline(inputStream,line);//name
1602 std::string inputPortName(line);
1605 getline(inputStream,line);//xInic:yInic:zInic
1607 strcpy( coord, line.c_str() );
1608 result = strtok( coord, delims );//xInic
1609 std::string xInic(result);
1610 result = strtok( NULL, delims );//yInic
1611 std::string yInic(result);
1612 result = strtok( NULL, delims );//zInic
1613 std::string zInic(result);
1615 double xIn, yIn, zIn;
1616 std::istringstream xSt(xInic);
1618 std::istringstream ySt(yInic);
1620 std::istringstream zSt(zInic);
1623 getline(inputStream,line);//FIN_COMPLEX_PORT
1625 configGComBoxInputOutputPort(true, inputPortName,xIn,yIn,zIn);
1628 // int idInputPort = createGComplexBoxInputPort(inputPortName);
1629 // GObjectController *cont = _controllers[idInputPort];
1630 // GBoxModel *cbmod = (GBoxModel*)cont->getModel();
1631 // cbmod->setInicPoint(xIn,yIn,zIn);
1632 // cbmod->notifyObservers(_idManager);
1635 } // for input complex box
1638 //-----------------------
1639 //- COMPLEX OUTPUT PORTS
1640 //-----------------------
1642 getline(inputStream,line);//COMPLEXOUTPUTS:num
1644 strcpy( outputs, line.c_str() );
1645 result = strtok( outputs, delims );
1646 result = strtok( NULL, delims );
1649 std::istringstream outps(result);
1650 outps >> numOutputs;
1652 for(int i = 0;i<numOutputs;i++)
1655 getline(inputStream,line);//COMPLEX_PORT
1656 getline(inputStream,line);//name
1657 std::string outputPortName(line);
1660 getline(inputStream,line);//xInic:yInic:zInic
1662 strcpy( coord, line.c_str() );
1663 result = strtok( coord, delims );//xInic
1664 std::string xInic(result);
1665 result = strtok( NULL, delims );//yInic
1666 std::string yInic(result);
1667 result = strtok( NULL, delims );//zInic
1668 std::string zInic(result);
1670 double xIn, yIn, zIn;
1671 std::istringstream xSt(xInic);
1673 std::istringstream ySt(yInic);
1675 std::istringstream zSt(zInic);
1678 getline(inputStream,line);//FIN_COMPLEX_PORT
1680 configGComBoxInputOutputPort(false, outputPortName,xIn,yIn,zIn);
1683 // int idOutputPort = createGComplexBoxOutputPort(outputPortName);
1684 // GObjectController *cont = _controllers[idOutputPort];
1685 // GBoxModel *cbmod = (GBoxModel*)cont->getModel();
1686 // cbmod->setInicPoint(xIn,yIn,zIn);
1687 // cbmod->notifyObservers(_idManager);
1689 } // for output complex box
1694 getline(inputStream,line);//BOXES:num
1696 strcpy( boxes, line.c_str() );
1697 result = strtok( boxes, delims );
1698 result = strtok( NULL, delims );
1701 std::istringstream is(result);
1704 for(int i = 0;i<numBoxes;i++)
1707 getline(inputStream,line);//BOX
1708 getline(inputStream,line);//package:type:name
1710 strcpy( box, line.c_str() );
1711 result = strtok( box, delims );//package
1712 std::string package(result);
1713 result = strtok( NULL, delims );//type
1714 std::string type(result);
1715 result = strtok( NULL, delims );//name
1716 std::string name(result);
1718 getline(inputStream,line);//ISEXEC:TRUE|FALSE
1720 strcpy( exec, line.c_str() );
1721 result = strtok( exec, delims );//ISEXEC
1722 result = strtok( NULL, delims );//TRUE|FALSE
1723 std::string isExec(result);
1726 getline(inputStream,line);//xInic:yInic:zInic
1728 strcpy( coord, line.c_str() );
1729 result = strtok( coord, delims );//xInic
1730 std::string xInic(result);
1731 result = strtok( NULL, delims );//yInic
1732 std::string yInic(result);
1733 result = strtok( NULL, delims );//zInic
1734 std::string zInic(result);
1736 double xIn, yIn, zIn;
1737 std::istringstream xSt(xInic);
1739 std::istringstream ySt(yInic);
1741 std::istringstream zSt(zInic);
1745 getline(inputStream,line);//xEnd:yEnd:zEnd
1746 strcpy( coord, line.c_str() );
1747 result = strtok( coord, delims );//xEnd
1748 std::string xEnd(result);
1749 result = strtok( NULL, delims );//yEnd
1750 std::string yEnd(result);
1751 result = strtok( NULL, delims );//zEnd
1752 std::string zEnd(result);
1754 double xEn, yEn, zEn;
1755 std::istringstream xEt(xEnd);
1757 std::istringstream yEt(yEnd);
1759 std::istringstream zEt(zEnd);
1762 bool boxExecutable=false;
1765 boxExecutable= true;
1768 int idBox = createGBlackBox(xIn,yIn,package,type);
1769 configGBlackBox(idBox, xIn,yIn,zIn,name, boxExecutable,xEn,yEn,zEn);
1771 GObjectController *cont = _controllers[idBox];
1772 GBlackBoxModel *bbmod = (GBlackBoxModel*)cont->getModel();
1776 // GObjectController *cont = _controllers[idBox];
1777 // GBlackBoxModel *bbmod = (GBlackBoxModel*)cont->getModel();
1778 // bbmod->setBBTKName(name);
1779 // bbmod->setInicPoint(xIn,yIn,zIn);
1780 // bbmod->setFinalPoint(xEn,yEn,zEn);
1781 // bbmod->setExecutable(boxExecutable);
1785 getline(inputStream,line);//PORT o FIN_BOX
1786 std::string port=line.substr(0,4);
1789 getline(inputStream,line);//name:value
1791 strcpy( poort, line.c_str() );
1792 result = strtok( poort, delims );//name
1793 std::string name(result);
1794 result = strtok( NULL, delims );//value
1795 std::string value(result);
1797 bbmod->setValueToInput(name,value);
1799 getline(inputStream,line);//PORT o FIN_BOX
1800 port=line.substr(0,4);
1803 //EED bbmod->notifyObservers(_idManager);
1808 getline(inputStream,line);//CONNECTIONS:num
1810 strcpy( conns, line.c_str() );
1811 result = strtok( conns, delims );
1812 result = strtok( NULL, delims );
1815 std::istringstream isCons(result);
1818 for(int i = 0;i<numConns;i++)
1821 getline(inputStream,line);//CONNECTION
1822 getline(inputStream,line);//Startbox.PortName:EndBox.PortName
1825 strcpy( connec, line.c_str() );
1826 result = strtok( connec, delims );
1827 std::string nameStartBox(result);
1828 result = strtok( NULL, delims );
1829 std::string nameStartPort(result);
1830 result = strtok( NULL, delims );
1831 std::string nameEndBox(result);
1832 result = strtok( NULL, delims );
1833 std::string nameEndPort(result);
1835 configGConnetion(nameStartBox, nameStartPort, nameEndBox, nameEndPort);
1838 std::vector<int> lstB = getBlackBoxes();
1839 GPortModel *startP = NULL;
1840 GPortModel *endP = NULL;
1842 for(j = 0;j<lstB.size();j++)
1845 GBlackBoxModel *bbMod = (GBlackBoxModel*)_controllers[idB]->getModel();
1846 if(_controllers[idB]->getModel()->getBBTKName()==nameStartBox)
1848 startP = bbMod->getOutputPort(nameStartPort);
1850 else if(_controllers[idB]->getModel()->getBBTKName()==nameEndBox)
1852 endP = bbMod->getInputPort(nameEndPort);
1860 std::vector<int> lstInputs = getComplexInputPorts();
1861 for(j = 0;j<lstInputs.size();j++)
1863 int idB = lstInputs[j];
1864 GBoxModel *cbMod = (GBoxModel*)_controllers[idB]->getModel();
1865 if(_controllers[idB]->getModel()->getBBTKName()==nameStartBox)
1867 startP = cbMod->getOutputPort(nameStartPort);
1874 std::vector<int> lstOutputs = getComplexOutputPorts();
1875 for(j = 0;j<lstOutputs.size();j++)
1877 int idB = lstOutputs[j];
1878 GBoxModel *cbMod = (GBoxModel*)_controllers[idB]->getModel();
1879 if(_controllers[idB]->getModel()->getBBTKName()==nameEndBox)
1881 endP = cbMod->getInputPort(nameEndPort);
1887 int idCon = createGConnector(startP);
1888 _worldState = NOTHING_HAPPENS;
1889 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
1891 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
1892 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
1893 tempp->endContourCreation();
1894 conMod->setEndPort(endP);
1895 conView->updateStartEndPoints();
1902 //=========================================================================
1906 //=========================================================================
1907 void wxVtkSceneManager::configGComBoxInputOutputPort(bool inputoutput, std::string portName, double xIn, double yIn,double zIn)
1910 if (inputoutput==true)
1912 idPort = createGComplexBoxInputPort(portName);
1914 idPort = createGComplexBoxOutputPort(portName);
1916 GObjectController *cont = _controllers[idPort];
1917 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
1918 cbmod->setInicPoint(xIn,yIn,zIn);
1919 cbmod->notifyObservers(_idManager);
1921 //=========================================================================
1924 //=========================================================================
1925 GBoxModel* wxVtkSceneManager::findGBox(std::string boxname)
1930 GBoxModel *boxModel = NULL;
1931 std::vector<int> lstB = getBlackBoxes();
1932 for(j = 0;j<(int)lstB.size();j++)
1935 bMod = (GBoxModel*)_controllers[idB]->getModel();
1936 if(_controllers[idB]->getModel()->getBBTKName()==boxname)
1942 if((_isComplexBox) && (boxModel==NULL))
1944 std::vector<int> lstInputs = getComplexInputPorts();
1945 for(j = 0;j<(int)lstInputs.size();j++)
1948 bMod = (GBoxModel*)_controllers[idB]->getModel();
1949 if(_controllers[idB]->getModel()->getBBTKName()==boxname)
1955 std::vector<int> lstOutputs = getComplexOutputPorts();
1956 for(j = 0;j<(int)lstOutputs.size();j++)
1958 int idB = lstOutputs[j];
1959 bMod = (GBoxModel*)_controllers[idB]->getModel();
1960 if(_controllers[idB]->getModel()->getBBTKName()==boxname)
1971 //=========================================================================
1974 void wxVtkSceneManager::configGConnetion(std::string nameStartBox, std::string nameStartPort, std::string
1975 nameEndBox, std::string nameEndPort)
1977 printf("EED wxVtkSceneManager::configGConnetion 1 %s %s %s %s\n", nameStartBox.c_str(), nameStartPort.c_str(), nameEndBox.c_str(), nameEndPort.c_str() );
1979 GBoxModel *boxModel;
1980 GPortModel *startP = NULL;
1981 GPortModel *endP = NULL;
1983 boxModel= findGBox(nameStartBox);
1986 startP = boxModel->getOutputPort(nameStartPort);
1989 boxModel= findGBox(nameEndBox);
1992 endP = boxModel->getInputPort(nameEndPort);
1996 printf("EED wxVtkSceneManager::configGConnetion 2 %p %p \n", startP, endP );
1999 std::vector<int> lstB = getBlackBoxes();
2001 for(j = 0;j<(int)lstB.size();j++)
2004 GBlackBoxModel *bbMod = (GBlackBoxModel*)_controllers[idB]->getModel();
2005 if(_controllers[idB]->getModel()->getBBTKName()==nameStartBox)
2007 startP = bbMod->getOutputPort(nameStartPort);
2009 else if(_controllers[idB]->getModel()->getBBTKName()==nameEndBox)
2011 endP = bbMod->getInputPort(nameEndPort);
2019 std::vector<int> lstInputs = getComplexInputPorts();
2020 for(j = 0;j<(int)lstInputs.size();j++)
2022 int idB = lstInputs[j];
2023 GBoxModel *cbMod = (GBoxModel*)_controllers[idB]->getModel();
2024 if(_controllers[idB]->getModel()->getBBTKName()==nameStartBox)
2026 startP = cbMod->getOutputPort(nameStartPort);
2033 std::vector<int> lstOutputs = getComplexOutputPorts();
2034 for(j = 0;j<(int)lstOutputs.size();j++)
2036 int idB = lstOutputs[j];
2037 GBoxModel *cbMod = (GBoxModel*)_controllers[idB]->getModel();
2038 if(_controllers[idB]->getModel()->getBBTKName()==nameEndBox)
2040 endP = cbMod->getInputPort(nameEndPort);
2047 int idCon = createGConnector(startP);
2048 _worldState = NOTHING_HAPPENS;
2049 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
2051 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
2052 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
2053 tempp->endContourCreation();
2054 conMod->setEndPort(endP);
2055 conView->updateStartEndPoints();
2058 //=========================================================================
2060 bool wxVtkSceneManager::boxExist(std::string boxname)
2063 std::map<int, GObjectController*>::iterator it;
2064 for(it = _controllers.begin(); it != _controllers.end(); ++it)
2066 GObjectController *cont = it->second;
2067 if(cont->getModel()->getBBTKName()==boxname)
2075 //=========================================================================
2077 std::vector<int> wxVtkSceneManager::getBlackBoxes()
2079 std::vector<int> vect;
2080 std::map<int, GObjectController*>::iterator it;
2081 for(it = _controllers.begin(); it != _controllers.end(); ++it)
2083 GObjectController *cont = it->second;
2084 if(cont->getGObjectType()==GBLACKBOX)
2086 vect.push_back(cont->getId());
2092 //=========================================================================
2094 std::vector<int> wxVtkSceneManager::getComplexInputPorts()
2096 std::vector<int> vect;
2097 std::map<int, GObjectController*>::iterator it;
2098 for(it = _controllers.begin(); it != _controllers.end(); ++it)
2100 GObjectController *cont = it->second;
2101 if(cont->getGObjectType()==GCOMPLEXINPUTPORT)
2103 vect.push_back(cont->getId());
2109 //=========================================================================
2111 std::vector<int> wxVtkSceneManager::getComplexOutputPorts()
2113 std::vector<int> vect;
2114 std::map<int, GObjectController*>::iterator it;
2115 for(it = _controllers.begin(); it != _controllers.end(); ++it)
2117 GObjectController *cont = it->second;
2118 if(cont->getGObjectType()==GCOMPLEXOUTPUTPORT)
2120 vect.push_back(cont->getId());
2126 //=========================================================================
2128 std::vector<int> wxVtkSceneManager::getConnections()
2130 std::vector<int> vect;
2131 std::map<int, GObjectController*>::iterator it;
2132 for(it = _controllers.begin(); it != _controllers.end(); ++it)
2134 GObjectController *cont = it->second;
2135 if(cont->getGObjectType()==GCONNECTOR)
2137 vect.push_back(cont->getId());
2143 //=========================================================================
2145 bool wxVtkSceneManager::isComplexBox()
2147 return _isComplexBox;
2150 //=========================================================================
2152 void wxVtkSceneManager::setComplexBox(bool val)
2157 //=========================================================================
2159 int wxVtkSceneManager::addObjectController(GObjectController* objController)
2161 //Register the controller of the new object
2162 registerController((InteractorStyleMaracas*) objController);
2164 //Add the object to the objects list
2165 int newId = _contLastId;//_controllers.size();
2166 objController->setId(newId);
2167 _controllers[newId] = objController;
2172 //=========================================================================
2174 int wxVtkSceneManager::getNumSelectedObjects()
2176 return _selectedObjects.size();
2179 //=========================================================================
2181 std::map<int,GObjectController*> wxVtkSceneManager::getSelectedObjects()
2183 std::map<int,GObjectController*> mapSelected;
2185 std::map<int, GObjectController*>::iterator it;
2186 for(it = _controllers.begin(); it != _controllers.end(); ++it)
2188 GObjectController *cont = it->second;
2189 if(cont->getGObjectType()==GBLACKBOX && cont->getView()->getState()==SELECTED)
2191 mapSelected[cont->getId()]=cont;
2195 std::map<int, GObjectController*>::iterator it2;
2196 for(it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
2198 GObjectController *cont = it2->second;
2199 if(cont->getGObjectType()==GCONNECTOR)
2201 GConnectorModel* cmod = (GConnectorModel*)cont->getModel();
2202 GBoxModel* endPortParentBox = cmod->getEndPort()->getParentBox();
2203 GBoxModel* startPortParentBox = cmod->getStartPort()->getParentBox();
2205 std::map<int, GObjectController*>::iterator iterOBJ1 = mapSelected.find(startPortParentBox->getObjectId());
2206 std::map<int, GObjectController*>::iterator iterOBJ2 = mapSelected.find(endPortParentBox->getObjectId());
2208 if(iterOBJ1 != mapSelected.end() && iterOBJ2 != mapSelected.end())
2210 int ID = cont->getId();
2211 mapSelected[ID]=cont;
2218 //=========================================================================
2220 void wxVtkSceneManager::addObjects(std::map<int,GObjectController*> objectsMap)
2223 std::map<int,int> oldIdNewIdBoxes;
2224 std::vector<int> connections;
2226 std::map<int, GObjectController*>::iterator it;
2227 for(it = objectsMap.begin(); it != objectsMap.end(); ++it)
2229 GObjectController *cont = it->second;
2230 int type = cont->getGObjectType();
2235 double xInic, yInic,zInic;
2236 GBlackBoxModel* copyBox = (GBlackBoxModel*)cont->getModel();
2237 copyBox->getInicPoint(xInic,yInic,zInic);
2238 int idBox = createGBlackBox(0,0,copyBox->getBBTKPackage(),copyBox->getBBTKType());
2240 int idcB = copyBox->getObjectId();
2241 oldIdNewIdBoxes[idcB]=idBox;
2242 cont = _controllers[idBox];
2243 GBlackBoxModel* newbox = (GBlackBoxModel*)cont->getModel();
2244 newbox->setInicPoint(xInic,yInic,zInic);
2245 int num = newbox->getNumInputPorts();
2246 for(int j=0;j<num;j++)
2248 newbox->setValueToInputPort(j,copyBox->getValueInputPort(j));
2250 newbox->notifyObservers(_idManager);
2252 else if(type==GCONNECTOR)
2254 int idCon = cont->getId();
2255 connections.push_back(idCon);
2260 for(int i = 0 ;i<(int)connections.size();i++)
2262 int objId = connections[i];
2263 GObjectController *cont = objectsMap[objId];
2264 GConnectorModel* connectModel = (GConnectorModel*)cont->getModel();
2266 GPortModel* startPort = connectModel->getStartPort();
2267 int startPortIndex = startPort->getPosInBox();
2268 GPortModel* endPort = connectModel->getEndPort();
2269 int endPortIndex = endPort->getPosInBox();
2271 GBlackBoxModel* startPortParentBox = (GBlackBoxModel*)startPort->getParentBox();
2272 GBlackBoxModel* endPortParentBox = (GBlackBoxModel*)endPort->getParentBox();
2274 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2275 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2277 GBlackBoxModel* newStartBox = (GBlackBoxModel*)_controllers[idNewStartBox]->getModel();
2278 GBlackBoxModel* newEndBox = (GBlackBoxModel*)_controllers[idNewEndBox]->getModel();
2280 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2281 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2283 // Creates connection
2284 int idCon = createGConnector(newStartPort);
2285 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
2286 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
2287 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
2288 tempp->endContourCreation();
2289 conMod->setEndPort(newEndPort);
2290 conView->updateStartEndPoints();
2293 std::map<int, int>::iterator itIds;
2294 for(itIds = oldIdNewIdBoxes.begin(); itIds != oldIdNewIdBoxes.end(); ++itIds)
2296 int idOld = itIds->first;
2297 int idNew = itIds->second;
2299 GBlackBoxModel* oldBox = (GBlackBoxModel*)objectsMap[idOld]->getModel();
2300 GBlackBoxModel* newBox = (GBlackBoxModel*)_controllers[idNew]->getModel();
2302 std::vector<int> oldInputConnections = oldBox->getConnectedInputs();
2303 std::vector<int> oldOutputConnections = oldBox->getConnectedOutputs();
2304 std::vector<int> newInputConnections = newBox->getConnectedInputs();
2305 std::vector<int> newOutputConnections = newBox->getConnectedOutputs();
2307 for(int k = 0; k<(int)oldInputConnections.size();k++)
2310 //EED int toCreate=-1;
2311 for(int l = 0; l<(int)newInputConnections.size() && !exist;l++)
2313 if(oldInputConnections[k]==newInputConnections[l])
2321 //Create complex input
2322 int posInBox = oldInputConnections[k];
2323 GPortModel* inputPort = oldBox->getInputPort(posInBox);
2324 std::string inputPortName = inputPort->getBBTKName();
2325 int idInputPort = createGComplexBoxInputPort(inputPortName);
2326 GObjectController *cont = _controllers[idInputPort];
2327 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
2329 inputPort->getInicPoint(xIn,yIn,zIn);
2331 cbmod->setInicPoint(xIn,yIn,zIn);
2332 cbmod->notifyObservers(_idManager);
2334 GPortModel* inputPortEnd = newBox->getInputPort(posInBox);
2336 // Creates connection
2337 int idCon = createGConnector(cbmod->getOutputPort(0));
2338 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
2339 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
2340 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
2341 tempp->endContourCreation();
2342 conMod->setEndPort(inputPortEnd);
2343 conView->updateStartEndPoints();
2350 for(int k = 0; k<(int)oldOutputConnections.size();k++)
2353 //EED int toCreate=-1;
2354 for(int l = 0; l<(int)newOutputConnections.size() && !exist;l++)
2356 if(oldOutputConnections[k]==newOutputConnections[l])
2364 //Create complex output
2365 int posInBox = oldOutputConnections[k];
2366 GPortModel* outputPort = oldBox->getOutputPort(posInBox);
2367 std::string outputPortName = outputPort->getBBTKName();
2368 int idOutputPort = createGComplexBoxOutputPort(outputPortName);
2369 GObjectController *cont = _controllers[idOutputPort];
2370 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
2372 outputPort->getInicPoint(xIn,yIn,zIn);
2374 cbmod->setInicPoint(xIn,yIn,zIn);
2375 cbmod->notifyObservers(_idManager);
2377 GPortModel* outputPortEnd = newBox->getOutputPort(posInBox);
2379 // Creates connection
2380 int idCon = createGConnector(outputPortEnd);
2381 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
2382 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
2383 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
2384 tempp->endContourCreation();
2385 conMod->setEndPort(cbmod->getInputPort(0));
2386 conView->updateStartEndPoints();
2397 //=========================================================================
2399 } // EO namespace bbtk