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(40);
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 vtkCellArray *strip = vtkCellArray::New();
130 vtkPolyData *pdFill = vtkPolyData::New();
131 _fillObjectActor = vtkActor::New();
132 _fillPolyMapper = vtkPolyDataMapper::New();
134 printf ("EED wxVtkSceneManager::configureBaseView 1...\n");
136 vtkPolygon *aPolygon = vtkPolygon::New();
137 _fillObjectActor = vtkActor::New();
139 _pts = vtkPoints::New();
141 _pts->SetNumberOfPoints(7);
142 _pts->InsertPoint(0, xInic , yInic , zInic );
143 _pts->InsertPoint(1, xInic+50 , yInic , zInic );
144 _pts->InsertPoint(2, xInic+50 , yInic+50 , zInic );
145 _pts->InsertPoint(3, xInic+25 , yInic+50 , zInic );
146 _pts->InsertPoint(4, xInic+20 , yInic+55 , zInic );
147 _pts->InsertPoint(5, xInic+15 , yInic+50 , zInic );
148 _pts->InsertPoint(6, xInic , yInic+50 , zInic );
151 strip->InsertNextCell(8);
152 strip->InsertCellPoint(0);
153 strip->InsertCellPoint(1);
154 strip->InsertCellPoint(2);
155 strip->InsertCellPoint(0);
156 strip->InsertCellPoint(3);
157 pdFill->SetPoints( _pts );
158 pdFill->SetStrips( strip );
159 _fillPolyMapper->SetInput(pdFill);
162 printf ("EED wxVtkSceneManager::configureBaseView 2...\n");
164 aPolygon->GetPointIds()->SetNumberOfIds(7);
165 aPolygon->GetPointIds()->SetId(0, 0);
166 aPolygon->GetPointIds()->SetId(1, 1);
167 aPolygon->GetPointIds()->SetId(2, 2);
168 aPolygon->GetPointIds()->SetId(3, 3);
169 aPolygon->GetPointIds()->SetId(4, 4);
170 aPolygon->GetPointIds()->SetId(5, 5);
171 aPolygon->GetPointIds()->SetId(6, 6);
173 printf ("EED wxVtkSceneManager::configureBaseView 3...\n");
175 vtkUnstructuredGrid *aPolygonGrid = vtkUnstructuredGrid::New();
176 aPolygonGrid->Allocate(1, 1);
177 aPolygonGrid->InsertNextCell(aPolygon->GetCellType(), aPolygon->GetPointIds());
178 aPolygonGrid->SetPoints(_pts);
179 printf ("EED wxVtkSceneManager::configureBaseView 4...\n");
180 _aPolygonMapper = vtkDataSetMapper::New();
181 _aPolygonMapper->SetInput(aPolygonGrid);
182 _fillObjectActor->SetMapper(_aPolygonMapper);
183 printf ("EED wxVtkSceneManager::configureBaseView 5...\n");
184 _fillObjectActor->GetProperty()->SetColor(PORTFILL_NH_R,PORTFILL_NH_G,PORTFILL_NH_B);
185 _aPolygonMapper->Modified();
187 _baseView->GetRenderer()->AddActor( _fillObjectActor );
188 printf ("EED wxVtkSceneManager::configureBaseView fin...\n");
191 //=========================================================================
193 std::string wxVtkSceneManager::generateANewNameForABox()
195 std::stringstream boxname;
198 boxname << "Box0" << _numBoxes;
200 boxname << "Box" << _numBoxes;
203 return boxname.str();
206 //=========================================================================
208 std::string wxVtkSceneManager::findANewNameForABox()
210 std::string boxname=generateANewNameForABox();
212 while (boxExist(boxname)==true)
214 boxname=generateANewNameForABox();
220 //=========================================================================
221 void wxVtkSceneManager::configGBlackBox(int idBox, double xIn, double yIn, double zIn, std::string name, bool boxExecutable,double xEn,double yEn,double zEn)
223 GObjectController *cont = _controllers[idBox];
224 GBlackBoxModel *bbmod = (GBlackBoxModel*)cont->getModel();
225 bbmod->setBBTKName(name);
226 bbmod->setInicPoint(xIn,yIn,zIn);
227 bbmod->setFinalPoint(xEn,yEn,zEn);
228 bbmod->setExecutable(boxExecutable);
230 bbmod->notifyObservers(_idManager);
235 //=========================================================================
237 int wxVtkSceneManager::createGBlackBox(int x, int y, std::string packageName, std::string boxType)
239 _worldState = NOTHING_HAPPENS;
240 //EED int windowWidth = _baseView->GetRenWin()->GetSize()[0];
241 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
243 int type = GBLACKBOX;
245 //Create the MVC Objects
247 GBlackBoxModel *model = (GBlackBoxModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
248 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
249 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
251 BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxType);
253 //Prepares the initial model
254 //The coordinates obtained are the following. Top-Left:x=0,y=0 Bottom-Right:x=width,y=height
257 double yy = windowHeight-y;
259 //z value is not important yet, because it is only used a parallel projection
262 _baseView->TransCoordScreenToWorld(xx,yy,zz);
263 model->setInicPoint(xx,yy,zz);
265 std::stringstream stream;
267 std::string newBoxName;
268 newBoxName = findANewNameForABox();
271 stream << newBoxName;
273 std::string arraystring = stream.str();
275 model->setBBTKName(arraystring);
276 model->setBBTKType(boxType);
277 model->setBBTKPackage(packageName);
279 model->addObserver(view);
280 model->addObserver(this);
282 //Iterate and create the input ports
283 std::map<std::string, BlackBoxInputDescriptor*> descriptorInMap = descriptor->GetInputDescriptorMap();
284 std::map<std::string, BlackBoxInputDescriptor*>::iterator itInput;
287 for(itInput = descriptorInMap.begin(); itInput != descriptorInMap.end(); ++itInput)
289 BlackBoxInputDescriptor *desc = itInput->second;
290 createGInputPort(GINPUTPORT,i,model,desc);
294 //Iterate and create the output ports
295 std::map<std::string, BlackBoxOutputDescriptor*> descriptorOutMap = descriptor->GetOutputDescriptorMap();
296 std::map<std::string, BlackBoxOutputDescriptor*>::iterator itOutput;
299 for(itOutput = descriptorOutMap.begin();itOutput != descriptorOutMap.end(); ++itOutput)
301 BlackBoxOutputDescriptor *desc = itOutput->second;
302 createGOutputPort(GOUTPUTPORT,i,model,desc);
307 //Associates the view with the correspondent renderer and the model.
308 //(NOTE: Refresh is only made by the view)
309 view->setModel(model);
310 view->setBaseView(_baseView);
311 view->initVtkObjects();
313 //Associates the controller with the correspondent model and view
314 controller->setModelAndView(model,view);
316 //Resgiter change to the observers of the actual model
317 model->notifyObservers(_idManager);
319 int newId = addObjectController(controller);
325 //=========================================================================
327 int wxVtkSceneManager::createGComplexBoxInputPort(std::string inputName)
329 //EED int windowWidth=_baseView->GetRenWin()->GetSize()[0];
330 int windowHeight=_baseView->GetRenWin()->GetSize()[1];
332 int type = GCOMPLEXINPUTPORT;
334 //Create the MVC Objects
336 GComplexBoxPortModel *model = (GComplexBoxPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
337 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
338 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
340 //Prepares the initial model
343 double yy = windowHeight-5;
345 //z value is not important yet, because it is only used a parallel projection
348 _baseView->TransCoordScreenToWorld(xx,yy,zz);
349 model->setInicPoint(xx,yy,zz);
351 model->setBBTKName(inputName);
352 model->setBBTKType("ComplexInputPort");
353 model->setComplexPortType(type);
355 model->addObserver(view);
356 model->addObserver(this);
358 //create the output port
359 GPortController* portController = createGPort(GOUTPUTPORT,inputName,"ComplexInputPort",0,model);
360 model->addOutputPort((GPortModel*)portController->getModel());
362 //Associates the view with the correspondent renderer and the model.
363 //(NOTE: Refresh is only made by the view)
364 view->setModel(model);
365 view->setBaseView(_baseView);
366 view->initVtkObjects();
368 //Associates the controller with the correspondent model and view
369 controller->setModelAndView(model,view);
371 //Resgiter change to the observers of the actual model
372 model->notifyObservers(_idManager);
374 int newId = addObjectController(controller);
378 //=========================================================================
380 int wxVtkSceneManager::createGComplexBoxOutputPort(std::string outputName)
382 //EED int windowWidth=_baseView->GetRenWin()->GetSize()[0];
383 int windowHeight=_baseView->GetRenWin()->GetSize()[1];
385 int type = GCOMPLEXOUTPUTPORT;
387 //Create the MVC Objects
389 GComplexBoxPortModel *model = (GComplexBoxPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
390 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
391 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
393 //Prepares the initial model
396 double yy = windowHeight-5;
398 //z value is not important yet, because it is only used a parallel projection
401 _baseView->TransCoordScreenToWorld(xx,yy,zz);
402 model->setInicPoint(xx,yy,zz);
404 model->setBBTKName(outputName);
405 model->setBBTKType("ComplexOutputPort");
406 model->setComplexPortType(type);
408 model->addObserver(view);
409 model->addObserver(this);
411 //create the output port
412 GPortController* portController = createGPort(GINPUTPORT,outputName,"ComplexInputPort",0,model);
413 model->addInputPort((GPortModel*)portController->getModel());
415 //Associates the view with the correspondent renderer and the model.
416 //(NOTE: Refresh is only made by the view)
417 view->setModel(model);
418 view->setBaseView(_baseView);
419 view->initVtkObjects();
421 //Associates the controller with the correspondent model and view
422 controller->setModelAndView(model,view);
424 //Resgiter change to the observers of the actual model
425 model->notifyObservers(_idManager);
427 int newId = addObjectController(controller);
431 //=========================================================================
433 int wxVtkSceneManager::createGInputPort(int portType, int posinBox,GBoxModel *blackBox, BlackBoxInputDescriptor *desc)
435 GPortController* portController = createGPort(portType,desc->GetName(),desc->GetTypeName(),posinBox,blackBox);
436 blackBox->addInputPort((GPortModel*)portController->getModel());
437 return portController->getId();
440 //=========================================================================
442 int wxVtkSceneManager::createGOutputPort(int portType, int posinBox,GBoxModel *blackBox, BlackBoxOutputDescriptor *desc)
444 GPortController* portController = createGPort(portType,desc->GetName(),desc->GetTypeName(),posinBox,blackBox);
445 blackBox->addOutputPort((GPortModel*)portController->getModel());
446 return portController->getId();
449 //=========================================================================
451 GPortController* wxVtkSceneManager::createGPort(int portType,std::string bbtkName, std::string bbtkType, int posInBox,GBoxModel *blackBox)
455 //Create the MVC Objects
456 GPortModel *model = (GPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
457 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
458 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
460 model->registerInBox(blackBox,portType, posInBox);
462 model->setBBTKType(bbtkType);
463 model->setBBTKName(bbtkName);
465 model->addObserver(view);
466 model->addObserver(this);
468 //Associates the view with the correspondent renderer and the model.
469 //(NOTE: Refresh is only made by the view)
470 view->setModel(model);
471 view->setBaseView(_baseView);
472 view->initVtkObjects();
474 //Associates the controller with the correspondent model and view
475 controller->setModelAndView(model,view);
477 model->notifyObservers(_idManager);
479 addObjectController(controller);
481 return (GPortController*)controller;
484 //=========================================================================
486 int wxVtkSceneManager::createGConnector(GPortModel* startPort)
488 int type = GCONNECTOR;
490 manualConnectorContourController* manContourControl = new manualConnectorContourController();
491 manualConnectorContourView* manContourView = new manualConnectorContourView();
492 manualContourModel* manContourModel = new manualContourModel();
494 GConnectorController* connectorcontroller = new GConnectorController();
495 GConnectorModel* connectorModel = new GConnectorModel();
496 vtkGConnectorView* connectorView = new vtkGConnectorView();
497 connectorModel->setGObjectType(type);
499 manContourModel->SetCloseContour(false);
500 connectorModel->setStartPort(startPort);
502 manContourView->SetModel( manContourModel );
503 manContourView->SetWxVtkBaseView( _baseView );
504 manContourView->SetRange( 0.5 );
505 manContourView->SetZ( 900 );
507 manContourView->SetColorNormalContour(0, 0, 1);
508 manContourView->SetColorEditContour(0.5, 0.5, 0.5);
509 manContourView->SetColorSelectContour(1, 0.8, 0);
510 manContourView->SetWidthLine(1);
511 manContourView->SetShowText(false);
513 manContourControl->SetModelView( manContourModel , manContourView );
515 manContourControl->CreateNewManualContour();
517 manContourView->RefreshContour();
521 connectorModel->getInicPoint(x,y,z);
523 manContourControl->SetState(1);
524 manContourModel->SetCloseContour(false);
526 manContourModel->AddPoint(x,y,z);
527 manContourView->AddPoint();
529 manContourModel->AddPoint(x,y,z);
530 manContourView->AddPoint();
532 int bak= manContourControl->GetNumberOfPointsManualContour() - 1;
533 manContourControl->_bakIdPoint=bak;
534 manContourView->Refresh();
536 manContourControl->SetMoving( false );
538 connectorcontroller->setModelAndView(connectorModel,connectorView);
540 int newId = addObjectController(connectorcontroller);
542 connectorcontroller->setManualContourController(manContourControl);
543 connectorModel->setManualContourModel(manContourModel);
544 connectorView->setManualContourView(manContourView);
545 connectorView->setModel(connectorModel);
546 connectorView->setBaseView(_baseView);
549 connectorModel->addObserver(connectorView);
550 connectorModel->addObserver(this);
555 //=========================================================================
557 void wxVtkSceneManager::registerController(InteractorStyleMaracas *param)
559 vtkInteractorStyleBaseView* baseViewControlManager = (vtkInteractorStyleBaseView*)_baseView->GetInteractorStyleBaseView();
560 baseViewControlManager->AddInteractorStyleMaracas( param );
563 //=========================================================================
565 void wxVtkSceneManager::unregisterController(InteractorStyleMaracas *param)
567 vtkInteractorStyleBaseView* baseViewControlManager = (vtkInteractorStyleBaseView*)_baseView->GetInteractorStyleBaseView();
568 baseViewControlManager->RemoveInteractorStyleMaracas( param );
571 //=========================================================================
573 vtkRenderer* wxVtkSceneManager::getRenderer()
575 return _baseView->GetRenderer();
578 //=========================================================================
580 vtkRenderWindow* wxVtkSceneManager::getRenderWindow()
582 return _baseView->GetRenWin();
584 //=========================================================================
587 void wxVtkSceneManager::update(int idController,int command)
589 if(command != NO_COMMAND)
591 if(command == ADD_TO_SELECTED)
593 //EED GObjectController* cont = _controllers[idController];
596 for (int i=0; i<(int)_selectedObjects.size() && foundID==false; i++)
598 int id = _selectedObjects[i];
606 int id = idController;
607 _selectedObjects.push_back(id);
611 else if(command == INIT_CREATION_CONTOUR)
613 _worldState = INIT_CREATION_CONTOUR;
614 GObjectController* cont = _controllers[idController];
615 GPortModel* startOutputPort = (GPortModel*)cont->getModel();
618 // The last one is the controller of the connector
619 std::map<int, GObjectController*>::iterator it2;
621 for(it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
623 GObjectController *cont = it2->second;
624 if(cont->getGObjectType() == GPORT )
626 GPortModel* port = (GPortModel*)cont->getModel();
627 if(port->getPortType()==GINPUTPORT)
629 cont->SetActive(true);
633 cont->getView()->setState(NOTHING_HAPPENS);
634 cont->getModel()->notifyObservers(_idManager);
635 cont->SetActive(false);
640 cont->getView()->setState(NOTHING_HAPPENS);
641 cont->getModel()->notifyObservers(_idManager);
642 cont->SetActive(false);
646 _selectedObjects.clear();
648 _idConnectionInCreation=createGConnector(startOutputPort);
651 else if(command == FIN_CREATION_CONTOUR && _worldState == INIT_CREATION_CONTOUR)
653 _worldState = NOTHING_HAPPENS;
654 //int id = _controllers.size()-1;
655 GObjectController* cont = _controllers[_idConnectionInCreation];
656 GConnectorModel* modelContour = (GConnectorModel*)cont->getModel();
658 GObjectController* finPort = _controllers[idController];
659 if(finPort->getGObjectType() == GPORT)
661 GPortModel* modelPort = (GPortModel*)finPort->getModel();
662 modelContour->setEndPort(modelPort);
665 manualConnectorContourController* manCont = ((GConnectorController*)cont)->getManualContourController();
666 manualConnectorContourView* connView = (manualConnectorContourView*)manCont->GetManualViewBaseContour();
669 std::map<int, GObjectController*>::iterator it2;
671 for(it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
673 GObjectController *cont = it2->second;
674 if(cont->getView()!=NULL)
676 cont->getView()->setState(NOTHING_HAPPENS);
677 cont->getModel()->notifyObservers(_idManager);
679 cont->SetActive(true);
686 //=========================================================================
688 bool wxVtkSceneManager::OnMouseMove()
691 bool okStatusMessage = false;
692 bool okPortMessage = false;
693 wxVTKRenderWindowInteractor *wxVTKiren;
694 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
695 wxVTKiren->GetEventPosition(X,Y);
698 if(_worldState == DRAG_OBJECTS)
700 for (int i=0; i<(int)_selectedObjects.size(); i++)
702 int id = _selectedObjects[i];
703 GObjectController* cont = _controllers[id];
706 cont->getView()->setStartDragging(true);
708 cont->getView()->moveObject(X,Y);
709 cont->getView()->setState(DRAG);
710 cont->getModel()->notifyObservers(_idManager);
713 std::map<int, GObjectController*>::iterator it;
715 for(it = _controllers.begin(); it != _controllers.end(); ++it)
717 GObjectController *desc = it->second;
718 if(desc->getGObjectType()==GCONNECTOR)
720 vtkGConnectorView* vconn = (vtkGConnectorView*)desc->getView();
721 vconn->updateStartEndPoints();
725 _startDragging=false;
728 else if(_worldState == NOTHING_HAPPENS || _worldState == INIT_CREATION_CONTOUR)
730 std::map<int, GObjectController*>::iterator it;
732 for(it = _controllers.begin(); it != _controllers.end(); ++it)
734 GObjectController *desc = it->second;
735 int type = desc->getGObjectType();
736 int state = desc->getView()->getState();
737 desc->getModel()->getCenter(px,py,pz);
739 if(state == HIGHLIGHTED){
740 okStatusMessage = true;
741 updateStatusBar(desc->getStatusText());
744 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
745 _parent->displayBlackBoxInfo(mod->getBBTKPackage(),mod->getBBTKType());
750 okPortMessage = true;
752 _textActor->SetInput( desc->getStatusText().c_str() );
753 _textActor->SetScale(0.1);
754 _textActor->SetPosition( px-25 ,py , pz+2 );
760 _pts->SetPoint(0, px , py , 900+1 );
761 _pts->SetPoint(1, px+150 , py , 900+1 );
762 _pts->SetPoint(2, px+150 , py+7 , 900+1 );
763 _pts->SetPoint(3, px-150+40 , py+7 , 900+1 );
764 _pts->SetPoint(4, px-150+40-5 , py+7+5 , 900+1 );
765 _pts->SetPoint(5, px-150+40-10 , py+7 , 900+1 );
766 _pts->SetPoint(6, px , py+7 , 900+1 );
768 _fillObjectActor->SetScale(1);
769 _fillObjectActor->SetPosition(px,py,1);
770 _aPolygonMapper->Modified();
773 } // for controllers it
777 if (okStatusMessage==false)
782 if (okPortMessage==false)
784 _textActor->SetScale(0.0001);
785 _fillObjectActor->SetScale(0.0001);
792 //=========================================================================
794 bool wxVtkSceneManager::OnLeftButtonDown()
796 if(_worldState==INIT_CREATION_CONTOUR)
798 bool isOverPort=false;
799 std::map<int, GObjectController*>::iterator it;
800 for(it = _controllers.begin(); it != _controllers.end() && isOverPort==false; ++it)
802 GObjectController *desc = it->second;
803 if(desc->getGObjectType()==GPORT)
805 GPortModel* portmod=(GPortModel*)desc->getModel();
806 vtkGObjectView* portView=desc->getView();
807 if(portmod->getPortType()==GINPUTPORT && portView->getState()==HIGHLIGHTED)
814 if(isOverPort==false)
816 _worldState=NOTHING_HAPPENS;
817 //int lastId = _controllers.size()-1;
818 GConnectorController *connector = (GConnectorController*)_controllers[_controllers.size()-1];
819 connector->removeFromScene();
820 unregisterController(connector);
821 _controllers.erase(_controllers.size()-1);
823 for(it = _controllers.begin(); it != _controllers.end(); ++it)
825 GObjectController *desc = it->second;
826 desc->SetActive(true);
827 desc->getView()->setState(NOTHING_HAPPENS);
828 desc->getModel()->notifyObservers(_idManager);
833 if(_selectedObjects.size()!=0)
835 _worldState = DRAG_OBJECTS;
836 _startDragging = true;
838 for (int i = 0; i < (int)_selectedObjects.size(); i++)
840 int id = _selectedObjects[i];
841 GObjectController* cont = _controllers[id];
842 cont->getView()->setState(DRAG);
843 cont->getModel()->notifyObservers(_idManager);
852 //=========================================================================
854 bool wxVtkSceneManager::OnLeftButtonUp()
856 if(_worldState == DRAG_OBJECTS)
858 _worldState = NOTHING_HAPPENS;
860 for (int i = 0; i < (int)_selectedObjects.size(); i++)
862 int id = _selectedObjects[i];
863 GObjectController* cont = _controllers[id];
864 cont->getView()->setState(SELECTED);
865 cont->getModel()->notifyObservers(_idManager);
871 //=========================================================================
873 bool wxVtkSceneManager::OnRightButtonUp()
875 if(_worldState==INIT_CREATION_CONTOUR)
877 _worldState=NOTHING_HAPPENS;
878 //int lastId = _controllers.size()-1;
879 GConnectorController *connector = (GConnectorController*)_controllers[_idConnectionInCreation];
880 connector->removeFromScene();
881 unregisterController(connector);
882 _controllers.erase(_idConnectionInCreation);
884 std::map<int, GObjectController*>::iterator it;
885 for(it = _controllers.begin(); it != _controllers.end(); ++it)
887 GObjectController *desc = it->second;
888 desc->SetActive(true);
889 desc->getView()->setState(NOTHING_HAPPENS);
890 desc->getModel()->notifyObservers(_idManager);
895 for (int i = 0; i < (int)_selectedObjects.size(); i++)
897 int id = _selectedObjects[i];
898 GObjectController* cont = _controllers[id];
899 cont->SetActive(true);
900 cont->getView()->setState(NOTHING_HAPPENS);
901 cont->getModel()->notifyObservers(_idManager);
904 _selectedObjects.clear();
909 //=========================================================================
911 bool wxVtkSceneManager::OnLeftDClick()
914 wxVTKRenderWindowInteractor *wxVTKiren;
915 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
916 wxVTKiren->GetEventPosition(X,Y);
918 std::map<int, GObjectController*>::iterator it;
920 bool clickOnObject = false;
922 for(it = _controllers.begin(); it != _controllers.end() && clickOnObject==false; ++it)
924 GObjectController *cont = it->second;
925 int type = cont->getGObjectType();
927 if(cont->getView()->isPointInside(X,Y))
931 for (int i=0; i< (int)_selectedObjects.size(); i++)
933 int id = _selectedObjects[i];
934 GObjectController* control = _controllers[id];
935 control->getView()->setState(NOTHING_HAPPENS);
937 _selectedObjects.clear();
939 GBlackBoxModel *bbmodel = (GBlackBoxModel*)cont->getModel();
940 _parent->editBlackBox(bbmodel);
942 clickOnObject = true;
946 if(clickOnObject==false)
948 //_parent->editDiagramParameters(this);
954 //=========================================================================
956 bool wxVtkSceneManager::OnChar()
958 char keyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
960 // KeyCode 127 : Delete Key
961 // KeyCode 8 : Backspace Key
962 if(keyCode == 8 || keyCode == 127)
964 if(_selectedObjects.size()>0)
966 for(int i=0;i<(int)_selectedObjects.size();i++)
968 int id = _selectedObjects[i];
969 std::map<int,GObjectController*>::iterator it;
970 it = _controllers.find(id);
971 if (it!=_controllers.end())
976 _selectedObjects.clear();
983 //=========================================================================
985 void wxVtkSceneManager::AddControlerToBeRemove(std::vector<int> *controllersToRemove, int id)
990 for(i=0 ; i < (int)controllersToRemove->size() ; i++ )
992 if (id == (*controllersToRemove)[i] )
1000 controllersToRemove->push_back( id );
1005 //=========================================================================
1007 void wxVtkSceneManager::deleteObject(int id)
1009 GObjectController *control = _controllers[id];
1010 std::vector<int> controllersToRemove;
1012 if(control->getGObjectType()==GBLACKBOX || control->getGObjectType()==GCOMPLEXINPUTPORT || control->getGObjectType()==GCOMPLEXOUTPUTPORT)
1014 GBoxModel *bbmod = (GBoxModel*)control->getModel();
1015 std::vector<GPortModel*> inputs = bbmod->getInputPorts();
1017 bool boxConnected = false;
1019 // Add box input controllers to be removed
1020 for(int i = 0;i< (int)inputs.size();i++)
1022 AddControlerToBeRemove( &controllersToRemove, inputs[i]->getObjectId() );
1023 if(inputs[i]->isConnected())
1025 boxConnected = true;
1029 std::vector<GPortModel*> outputs = bbmod->getOutputPorts();
1031 // Add box output controllers to be removed
1032 for(int i = 0;i<(int)outputs.size();i++)
1034 AddControlerToBeRemove( &controllersToRemove, outputs[i]->getObjectId() );
1035 if(outputs[i]->isConnected())
1037 boxConnected = true;
1041 // Add connection controllers to be removed
1042 std::map<int, GObjectController*>::iterator it;
1043 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1045 GObjectController *cont = it->second;
1046 int type = cont->getGObjectType();
1047 if(type==GCONNECTOR)
1049 GConnectorModel *conMod = (GConnectorModel*)cont->getModel();
1050 if(conMod->getStartPort()!=NULL && conMod->getStartPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
1052 AddControlerToBeRemove( &controllersToRemove, conMod->getObjectId() );
1054 if(conMod->getEndPort()!=NULL && conMod->getEndPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
1056 AddControlerToBeRemove( &controllersToRemove, conMod->getObjectId() );
1061 // Add box controller to be removed
1062 AddControlerToBeRemove( &controllersToRemove, bbmod->getObjectId() );
1064 else if(control->getGObjectType()==GCONNECTOR)
1066 GConnectorModel *conMod = (GConnectorModel*)control->getModel();
1067 AddControlerToBeRemove( &controllersToRemove, conMod->getObjectId() );
1071 std::map<int,GObjectController*>::iterator it;
1073 for(int i = 0;i<(int)controllersToRemove.size();i++)
1075 int key = controllersToRemove[i];
1076 it = _controllers.find( key );
1077 GObjectController *cont = _controllers[ key ];
1080 cont->removeFromScene();
1081 unregisterController((InteractorStyleMaracas*)cont);
1082 _controllers.erase(it);
1087 //=========================================================================
1089 void wxVtkSceneManager::displayBlackBoxInfo(std::string packageName, std::string boxName)
1091 _parent->displayBlackBoxInfo(packageName,boxName);
1094 //=========================================================================
1096 void wxVtkSceneManager::updateStatusBar(std::string textStatus)
1098 _parent->updateStatusBar(textStatus);
1101 //=========================================================================
1103 std::string wxVtkSceneManager::getDiagramBBS()
1105 bool existsExec=false;
1107 std::vector<std::string> packages;
1108 std::vector<int> boxes;
1109 std::vector<int> connections;
1110 std::vector<int> execBoxes;
1112 std::map<int, GObjectController*>::iterator it;
1114 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1116 GObjectController *desc = it->second;
1117 int type = desc->getGObjectType();
1121 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
1123 std::string pkg = mod->getBBTKPackage();
1124 bool existsPkg = false;
1125 for(int t = 0;t< (int)packages.size() && existsPkg == false;t++)
1127 if(packages[t]==pkg)
1134 packages.push_back(pkg);
1138 boxes.push_back(it->first);
1139 if(mod->isExecutable())
1141 execBoxes.push_back(it->first);
1145 else if(type==GCONNECTOR)
1147 connections.push_back(it->first);
1151 std::string script = "";
1152 script+="# BBTK GEditor Script\n";
1153 script+="# ----------------------\n";
1157 script+="include std\n"; // EED
1158 script+="include itkvtk\n"; // EED
1160 for(i = 0; i< (int)packages.size();i++)
1163 script+=packages[i];
1168 // script+="include std\n"; // JPR
1170 for(i = 0; i < (int)boxes.size();i++)
1174 GObjectController *control = _controllers[id];
1175 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1177 script+=model->getBBTKType();
1179 script+=model->getBBTKName();
1182 std::vector<GPortModel*> inputs = model->getInputPorts();
1183 for(int j = 0; j < (int)inputs.size();j++)
1185 GPortModel* inputPort = inputs[j];
1186 if(inputPort->isValueSet())
1189 script+=model->getBBTKName();
1191 script+=inputPort->getBBTKName();
1193 script+=inputPort->getValue();
1203 for(i = 0; i<(int)connections.size();i++)
1206 int id = connections[i];
1207 GObjectController *control = _controllers[id];
1208 GConnectorModel *model = (GConnectorModel*)control->getModel();
1210 //Start Connection info
1211 GPortModel *start = model->getStartPort();
1212 script+=start->getParentBox()->getBBTKName();
1214 script+=start->getBBTKName();
1218 //End Connection info
1219 GPortModel *end = model->getEndPort();
1220 script+=end->getParentBox()->getBBTKName();
1222 script+=end->getBBTKName();
1228 for(i = 0; i<(int)execBoxes.size();i++)
1231 int id = execBoxes[i];
1232 GObjectController *control = _controllers[id];
1233 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1235 script+=model->getBBTKName();
1244 //=========================================================================
1246 std::string wxVtkSceneManager::saveComplexBoxBBS(std::string cbName,std::string cbAuthor,std::string cbCategory,std::string cbDescription)
1249 std::vector<std::string> packages;
1250 std::vector<int> boxes;
1251 std::vector<int> connections;
1252 std::vector<int> execBoxes;
1254 std::map<int, GObjectController*>::iterator it;
1256 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1258 GObjectController *desc = it->second;
1259 int type = desc->getGObjectType();
1263 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
1265 std::string pkg = mod->getBBTKPackage();
1266 bool existsPkg = false;
1267 for(int t = 0;t<(int)packages.size() && existsPkg == false;t++)
1269 if(packages[t]==pkg)
1276 packages.push_back(pkg);
1280 boxes.push_back(it->first);
1281 if(mod->isExecutable())
1283 execBoxes.push_back(it->first);
1286 else if(type==GCONNECTOR)
1288 connections.push_back(it->first);
1292 std::string script = "";
1294 script+="include std\n"; // EED
1295 script+="include itkvtk\n"; // EED
1297 for(i = 0; i<(int)packages.size();i++)
1300 script+=packages[i];
1305 // Definition of a complex box
1311 script+="author \" ";
1315 script+="description \" ";
1316 script+=cbDescription;
1321 for(i = 0; i<(int)boxes.size();i++)
1325 GObjectController *control = _controllers[id];
1326 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1328 script+=model->getBBTKType();
1330 script+=model->getBBTKName();
1333 std::vector<GPortModel*> inputs = model->getInputPorts();
1334 for(int j = 0; j<(int)inputs.size();j++)
1336 GPortModel* inputPort = inputs[j];
1337 if(inputPort->isValueSet())
1340 script+=model->getBBTKName();
1342 script+=inputPort->getBBTKName();
1344 script+=inputPort->getValue();
1352 // Create connections in the script. If the connection is made with a complex port, it is created the input or output
1354 std::string complexInputs="";
1355 std::string complexOutputs="";
1358 for(i = 0; i<(int)connections.size();i++)
1360 int id = connections[i];
1361 GObjectController *control = _controllers[id];
1362 GConnectorModel *model = (GConnectorModel*)control->getModel();
1365 GPortModel *start = model->getStartPort();
1366 GBoxModel *startBox =start->getParentBox();
1368 GPortModel *end = model->getEndPort();
1369 GBoxModel *endBox =end->getParentBox();
1371 if(startBox->getGObjectType()==GCOMPLEXINPUTPORT)
1373 complexInputs+="input ";
1374 complexInputs+=startBox->getBBTKName();
1377 complexInputs+=endBox->getBBTKName();
1379 complexInputs+=end->getBBTKName();
1382 complexInputs+="\" \"";
1384 complexInputs+="\n";
1386 else if(endBox->getGObjectType()==GCOMPLEXOUTPUTPORT)
1388 complexOutputs+="output ";
1389 complexOutputs+=endBox->getBBTKName();
1391 complexOutputs+=" ";
1392 complexOutputs+=startBox->getBBTKName();
1393 complexOutputs+=".";
1394 complexOutputs+=start->getBBTKName();
1396 complexOutputs+=" ";
1397 complexOutputs+="\" \"";
1399 complexOutputs+="\n";
1404 script+=startBox->getBBTKName();
1406 script+=start->getBBTKName();
1410 //End Connection info
1411 script+=endBox->getBBTKName();
1413 script+=end->getBBTKName();
1421 for(i = 0; i<(int)execBoxes.size();i++)
1424 int id = execBoxes[i];
1425 GObjectController *control = _controllers[id];
1426 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1428 script+=model->getBBTKName();
1433 script+="# Complex input ports\n";
1434 script+=complexInputs;
1437 script+="# Complex output ports\n";
1438 script+=complexOutputs;
1447 //=========================================================================
1449 void wxVtkSceneManager::deleteAllBoxes()
1451 std::map<int, GObjectController*>::iterator it;
1452 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1454 GObjectController *cont = it->second;
1455 cont->removeFromScene();
1456 unregisterController((InteractorStyleMaracas*)cont);
1458 _selectedObjects.clear();
1459 _controllers.clear();
1463 //=========================================================================
1465 void wxVtkSceneManager::refreshScene()
1467 _baseView->RefreshView();
1470 //=========================================================================
1472 void wxVtkSceneManager::centerView()
1475 _baseView->GetRenderer()->GetActiveCamera()->GetFocalPoint(temp);
1476 _baseView->GetRenderer()->GetActiveCamera()->SetFocalPoint(0,0,temp[2]);
1477 _baseView->GetRenderer()->GetActiveCamera()->GetPosition(temp);
1478 _baseView->GetRenderer()->GetActiveCamera()->SetPosition(0,0,temp[2]);
1479 _baseView->RefreshView();
1483 //=========================================================================
1485 void wxVtkSceneManager::saveDiagram(std::string &content)
1489 //Print info IF COMPLEX BOX
1490 content+="COMPLEXBOX:";
1495 //Print info complex input ports
1496 std::vector<int> inputs = getComplexInputPorts();
1497 int insize = inputs.size();
1498 content+="COMPLEXINPUTS:";
1499 sprintf (buffer, "%d", insize);
1503 for(int i = 0;i<insize;i++)
1506 GObjectController *cont = _controllers[id];
1507 cont->getModel()->save(content);
1510 //Print info complex output ports
1511 std::vector<int> outputs = getComplexOutputPorts();
1512 int outsize = outputs.size();
1513 content+="COMPLEXOUTPUTS:";
1514 sprintf (buffer, "%d", outsize);
1518 for(int i = 0;i<outsize;i++)
1520 int id = outputs[i];
1521 GObjectController *cont = _controllers[id];
1522 cont->getModel()->save(content);
1531 std::vector<int> boxes = getBlackBoxes();
1532 int bsize = boxes.size();
1534 sprintf (buffer, "%d", bsize);
1538 for(int i = 0;i<bsize;i++)
1541 GObjectController *cont = _controllers[id];
1542 cont->getModel()->save(content);
1546 std::vector<int> connections = getConnections();
1547 int csize = connections.size();
1548 content+="CONNECTIONS:";
1549 sprintf (buffer, "%d", csize);
1553 for(int i = 0;i<csize;i++)
1555 int id = connections[i];
1556 GObjectController *cont = _controllers[id];
1557 cont->getModel()->save(content);
1562 //=========================================================================
1564 void wxVtkSceneManager::loadDiagram(ifstream &inputStream)
1567 std::string line="";
1568 char delims[] = ":";
1569 char *result = NULL;
1570 getline(inputStream,line);
1573 while ( !inputStream.eof() )
1575 if(line=="" || line[0]=='#')
1577 getline(inputStream,line);
1579 else if(line=="APP_START")
1590 getline(inputStream,line);//COMPLEX_BOX:TRUE|FALSE
1592 strcpy( complex, line.c_str() );
1593 result = strtok( complex, delims );
1594 result = strtok( NULL, delims );
1595 std::string isComplexBox(result);
1597 if(isComplexBox=="TRUE")
1601 //-----------------------
1602 //- COMPLEX INPUT PORTS
1603 //-----------------------
1604 getline(inputStream,line);//COMPLEXINPUTS:num
1606 strcpy( inputs, line.c_str() );
1607 result = strtok( inputs, delims );
1608 result = strtok( NULL, delims );
1611 std::istringstream inps(result);
1614 for(int i = 0;i<numInputs;i++)
1617 getline(inputStream,line);//COMPLEX_PORT
1618 getline(inputStream,line);//name
1619 std::string inputPortName(line);
1622 getline(inputStream,line);//xInic:yInic:zInic
1624 strcpy( coord, line.c_str() );
1625 result = strtok( coord, delims );//xInic
1626 std::string xInic(result);
1627 result = strtok( NULL, delims );//yInic
1628 std::string yInic(result);
1629 result = strtok( NULL, delims );//zInic
1630 std::string zInic(result);
1632 double xIn, yIn, zIn;
1633 std::istringstream xSt(xInic);
1635 std::istringstream ySt(yInic);
1637 std::istringstream zSt(zInic);
1640 getline(inputStream,line);//FIN_COMPLEX_PORT
1642 configGComBoxInputOutputPort(true, inputPortName,xIn,yIn,zIn);
1645 // int idInputPort = createGComplexBoxInputPort(inputPortName);
1646 // GObjectController *cont = _controllers[idInputPort];
1647 // GBoxModel *cbmod = (GBoxModel*)cont->getModel();
1648 // cbmod->setInicPoint(xIn,yIn,zIn);
1649 // cbmod->notifyObservers(_idManager);
1652 } // for input complex box
1655 //-----------------------
1656 //- COMPLEX OUTPUT PORTS
1657 //-----------------------
1659 getline(inputStream,line);//COMPLEXOUTPUTS:num
1661 strcpy( outputs, line.c_str() );
1662 result = strtok( outputs, delims );
1663 result = strtok( NULL, delims );
1666 std::istringstream outps(result);
1667 outps >> numOutputs;
1669 for(int i = 0;i<numOutputs;i++)
1672 getline(inputStream,line);//COMPLEX_PORT
1673 getline(inputStream,line);//name
1674 std::string outputPortName(line);
1677 getline(inputStream,line);//xInic:yInic:zInic
1679 strcpy( coord, line.c_str() );
1680 result = strtok( coord, delims );//xInic
1681 std::string xInic(result);
1682 result = strtok( NULL, delims );//yInic
1683 std::string yInic(result);
1684 result = strtok( NULL, delims );//zInic
1685 std::string zInic(result);
1687 double xIn, yIn, zIn;
1688 std::istringstream xSt(xInic);
1690 std::istringstream ySt(yInic);
1692 std::istringstream zSt(zInic);
1695 getline(inputStream,line);//FIN_COMPLEX_PORT
1697 configGComBoxInputOutputPort(false, outputPortName,xIn,yIn,zIn);
1700 // int idOutputPort = createGComplexBoxOutputPort(outputPortName);
1701 // GObjectController *cont = _controllers[idOutputPort];
1702 // GBoxModel *cbmod = (GBoxModel*)cont->getModel();
1703 // cbmod->setInicPoint(xIn,yIn,zIn);
1704 // cbmod->notifyObservers(_idManager);
1706 } // for output complex box
1711 getline(inputStream,line);//BOXES:num
1713 strcpy( boxes, line.c_str() );
1714 result = strtok( boxes, delims );
1715 result = strtok( NULL, delims );
1718 std::istringstream is(result);
1721 for(int i = 0;i<numBoxes;i++)
1724 getline(inputStream,line);//BOX
1725 getline(inputStream,line);//package:type:name
1727 strcpy( box, line.c_str() );
1728 result = strtok( box, delims );//package
1729 std::string package(result);
1730 result = strtok( NULL, delims );//type
1731 std::string type(result);
1732 result = strtok( NULL, delims );//name
1733 std::string name(result);
1735 getline(inputStream,line);//ISEXEC:TRUE|FALSE
1737 strcpy( exec, line.c_str() );
1738 result = strtok( exec, delims );//ISEXEC
1739 result = strtok( NULL, delims );//TRUE|FALSE
1740 std::string isExec(result);
1743 getline(inputStream,line);//xInic:yInic:zInic
1745 strcpy( coord, line.c_str() );
1746 result = strtok( coord, delims );//xInic
1747 std::string xInic(result);
1748 result = strtok( NULL, delims );//yInic
1749 std::string yInic(result);
1750 result = strtok( NULL, delims );//zInic
1751 std::string zInic(result);
1753 double xIn, yIn, zIn;
1754 std::istringstream xSt(xInic);
1756 std::istringstream ySt(yInic);
1758 std::istringstream zSt(zInic);
1762 getline(inputStream,line);//xEnd:yEnd:zEnd
1763 strcpy( coord, line.c_str() );
1764 result = strtok( coord, delims );//xEnd
1765 std::string xEnd(result);
1766 result = strtok( NULL, delims );//yEnd
1767 std::string yEnd(result);
1768 result = strtok( NULL, delims );//zEnd
1769 std::string zEnd(result);
1771 double xEn, yEn, zEn;
1772 std::istringstream xEt(xEnd);
1774 std::istringstream yEt(yEnd);
1776 std::istringstream zEt(zEnd);
1779 bool boxExecutable=false;
1782 boxExecutable= true;
1785 int idBox = createGBlackBox(xIn,yIn,package,type);
1786 configGBlackBox(idBox, xIn,yIn,zIn,name, boxExecutable,xEn,yEn,zEn);
1788 GObjectController *cont = _controllers[idBox];
1789 GBlackBoxModel *bbmod = (GBlackBoxModel*)cont->getModel();
1793 // GObjectController *cont = _controllers[idBox];
1794 // GBlackBoxModel *bbmod = (GBlackBoxModel*)cont->getModel();
1795 // bbmod->setBBTKName(name);
1796 // bbmod->setInicPoint(xIn,yIn,zIn);
1797 // bbmod->setFinalPoint(xEn,yEn,zEn);
1798 // bbmod->setExecutable(boxExecutable);
1802 getline(inputStream,line);//PORT o FIN_BOX
1803 std::string port=line.substr(0,4);
1806 getline(inputStream,line);//name:value
1808 strcpy( poort, line.c_str() );
1809 result = strtok( poort, delims );//name
1810 std::string name(result);
1811 result = strtok( NULL, delims );//value
1812 std::string value(result);
1814 bbmod->setValueToInput(name,value);
1816 getline(inputStream,line);//PORT o FIN_BOX
1817 port=line.substr(0,4);
1820 //EED bbmod->notifyObservers(_idManager);
1825 getline(inputStream,line);//CONNECTIONS:num
1827 strcpy( conns, line.c_str() );
1828 result = strtok( conns, delims );
1829 result = strtok( NULL, delims );
1832 std::istringstream isCons(result);
1835 for(int i = 0;i<numConns;i++)
1838 getline(inputStream,line);//CONNECTION
1839 getline(inputStream,line);//Startbox.PortName:EndBox.PortName
1842 strcpy( connec, line.c_str() );
1843 result = strtok( connec, delims );
1844 std::string nameStartBox(result);
1845 result = strtok( NULL, delims );
1846 std::string nameStartPort(result);
1847 result = strtok( NULL, delims );
1848 std::string nameEndBox(result);
1849 result = strtok( NULL, delims );
1850 std::string nameEndPort(result);
1852 configGConnetion(nameStartBox, nameStartPort, nameEndBox, nameEndPort);
1855 std::vector<int> lstB = getBlackBoxes();
1856 GPortModel *startP = NULL;
1857 GPortModel *endP = NULL;
1859 for(j = 0;j<lstB.size();j++)
1862 GBlackBoxModel *bbMod = (GBlackBoxModel*)_controllers[idB]->getModel();
1863 if(_controllers[idB]->getModel()->getBBTKName()==nameStartBox)
1865 startP = bbMod->getOutputPort(nameStartPort);
1867 else if(_controllers[idB]->getModel()->getBBTKName()==nameEndBox)
1869 endP = bbMod->getInputPort(nameEndPort);
1877 std::vector<int> lstInputs = getComplexInputPorts();
1878 for(j = 0;j<lstInputs.size();j++)
1880 int idB = lstInputs[j];
1881 GBoxModel *cbMod = (GBoxModel*)_controllers[idB]->getModel();
1882 if(_controllers[idB]->getModel()->getBBTKName()==nameStartBox)
1884 startP = cbMod->getOutputPort(nameStartPort);
1891 std::vector<int> lstOutputs = getComplexOutputPorts();
1892 for(j = 0;j<lstOutputs.size();j++)
1894 int idB = lstOutputs[j];
1895 GBoxModel *cbMod = (GBoxModel*)_controllers[idB]->getModel();
1896 if(_controllers[idB]->getModel()->getBBTKName()==nameEndBox)
1898 endP = cbMod->getInputPort(nameEndPort);
1904 int idCon = createGConnector(startP);
1905 _worldState = NOTHING_HAPPENS;
1906 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
1908 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
1909 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
1910 tempp->endContourCreation();
1911 conMod->setEndPort(endP);
1912 conView->updateStartEndPoints();
1919 //=========================================================================
1923 //=========================================================================
1924 void wxVtkSceneManager::configGComBoxInputOutputPort(bool inputoutput, std::string portName, double xIn, double yIn,double zIn)
1927 if (inputoutput==true)
1929 idPort = createGComplexBoxInputPort(portName);
1931 idPort = createGComplexBoxOutputPort(portName);
1933 GObjectController *cont = _controllers[idPort];
1934 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
1935 cbmod->setInicPoint(xIn,yIn,zIn);
1936 cbmod->notifyObservers(_idManager);
1938 //=========================================================================
1941 //=========================================================================
1942 GBoxModel* wxVtkSceneManager::findGBox(std::string boxname)
1947 GBoxModel *boxModel = NULL;
1948 std::vector<int> lstB = getBlackBoxes();
1949 for(j = 0;j<(int)lstB.size();j++)
1952 bMod = (GBoxModel*)_controllers[idB]->getModel();
1953 if(_controllers[idB]->getModel()->getBBTKName()==boxname)
1959 if((_isComplexBox) && (boxModel==NULL))
1961 std::vector<int> lstInputs = getComplexInputPorts();
1962 for(j = 0;j<(int)lstInputs.size();j++)
1965 bMod = (GBoxModel*)_controllers[idB]->getModel();
1966 if(_controllers[idB]->getModel()->getBBTKName()==boxname)
1972 std::vector<int> lstOutputs = getComplexOutputPorts();
1973 for(j = 0;j<(int)lstOutputs.size();j++)
1975 int idB = lstOutputs[j];
1976 bMod = (GBoxModel*)_controllers[idB]->getModel();
1977 if(_controllers[idB]->getModel()->getBBTKName()==boxname)
1988 //=========================================================================
1991 void wxVtkSceneManager::configGConnetion(std::string nameStartBox, std::string nameStartPort, std::string
1992 nameEndBox, std::string nameEndPort)
1994 printf("EED wxVtkSceneManager::configGConnetion 1 %s %s %s %s\n", nameStartBox.c_str(), nameStartPort.c_str(), nameEndBox.c_str(), nameEndPort.c_str() );
1996 GBoxModel *boxModel;
1997 GPortModel *startP = NULL;
1998 GPortModel *endP = NULL;
2000 boxModel= findGBox(nameStartBox);
2003 startP = boxModel->getOutputPort(nameStartPort);
2006 boxModel= findGBox(nameEndBox);
2009 endP = boxModel->getInputPort(nameEndPort);
2013 printf("EED wxVtkSceneManager::configGConnetion 2 %p %p \n", startP, endP );
2016 std::vector<int> lstB = getBlackBoxes();
2018 for(j = 0;j<(int)lstB.size();j++)
2021 GBlackBoxModel *bbMod = (GBlackBoxModel*)_controllers[idB]->getModel();
2022 if(_controllers[idB]->getModel()->getBBTKName()==nameStartBox)
2024 startP = bbMod->getOutputPort(nameStartPort);
2026 else if(_controllers[idB]->getModel()->getBBTKName()==nameEndBox)
2028 endP = bbMod->getInputPort(nameEndPort);
2036 std::vector<int> lstInputs = getComplexInputPorts();
2037 for(j = 0;j<(int)lstInputs.size();j++)
2039 int idB = lstInputs[j];
2040 GBoxModel *cbMod = (GBoxModel*)_controllers[idB]->getModel();
2041 if(_controllers[idB]->getModel()->getBBTKName()==nameStartBox)
2043 startP = cbMod->getOutputPort(nameStartPort);
2050 std::vector<int> lstOutputs = getComplexOutputPorts();
2051 for(j = 0;j<(int)lstOutputs.size();j++)
2053 int idB = lstOutputs[j];
2054 GBoxModel *cbMod = (GBoxModel*)_controllers[idB]->getModel();
2055 if(_controllers[idB]->getModel()->getBBTKName()==nameEndBox)
2057 endP = cbMod->getInputPort(nameEndPort);
2064 int idCon = createGConnector(startP);
2065 _worldState = NOTHING_HAPPENS;
2066 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
2068 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
2069 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
2070 tempp->endContourCreation();
2071 conMod->setEndPort(endP);
2072 conView->updateStartEndPoints();
2075 //=========================================================================
2077 bool wxVtkSceneManager::boxExist(std::string boxname)
2080 std::map<int, GObjectController*>::iterator it;
2081 for(it = _controllers.begin(); it != _controllers.end(); ++it)
2083 GObjectController *cont = it->second;
2084 if(cont->getModel()->getBBTKName()==boxname)
2092 //=========================================================================
2094 std::vector<int> wxVtkSceneManager::getBlackBoxes()
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()==GBLACKBOX)
2103 vect.push_back(cont->getId());
2109 //=========================================================================
2111 std::vector<int> wxVtkSceneManager::getComplexInputPorts()
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()==GCOMPLEXINPUTPORT)
2120 vect.push_back(cont->getId());
2126 //=========================================================================
2128 std::vector<int> wxVtkSceneManager::getComplexOutputPorts()
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()==GCOMPLEXOUTPUTPORT)
2137 vect.push_back(cont->getId());
2143 //=========================================================================
2145 std::vector<int> wxVtkSceneManager::getConnections()
2147 std::vector<int> vect;
2148 std::map<int, GObjectController*>::iterator it;
2149 for(it = _controllers.begin(); it != _controllers.end(); ++it)
2151 GObjectController *cont = it->second;
2152 if(cont->getGObjectType()==GCONNECTOR)
2154 vect.push_back(cont->getId());
2160 //=========================================================================
2162 bool wxVtkSceneManager::isComplexBox()
2164 return _isComplexBox;
2167 //=========================================================================
2169 void wxVtkSceneManager::setComplexBox(bool val)
2174 //=========================================================================
2176 int wxVtkSceneManager::addObjectController(GObjectController* objController)
2178 //Register the controller of the new object
2179 registerController((InteractorStyleMaracas*) objController);
2181 //Add the object to the objects list
2182 int newId = _contLastId;//_controllers.size();
2183 objController->setId(newId);
2184 _controllers[newId] = objController;
2189 //=========================================================================
2191 int wxVtkSceneManager::getNumSelectedObjects()
2193 return _selectedObjects.size();
2196 //=========================================================================
2198 std::map<int,GObjectController*> wxVtkSceneManager::getSelectedObjects()
2200 std::map<int,GObjectController*> mapSelected;
2202 std::map<int, GObjectController*>::iterator it;
2203 for(it = _controllers.begin(); it != _controllers.end(); ++it)
2205 GObjectController *cont = it->second;
2206 if(cont->getGObjectType()==GBLACKBOX && cont->getView()->getState()==SELECTED)
2208 mapSelected[cont->getId()]=cont;
2212 std::map<int, GObjectController*>::iterator it2;
2213 for(it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
2215 GObjectController *cont = it2->second;
2216 if(cont->getGObjectType()==GCONNECTOR)
2218 GConnectorModel* cmod = (GConnectorModel*)cont->getModel();
2219 GBoxModel* endPortParentBox = cmod->getEndPort()->getParentBox();
2220 GBoxModel* startPortParentBox = cmod->getStartPort()->getParentBox();
2222 std::map<int, GObjectController*>::iterator iterOBJ1 = mapSelected.find(startPortParentBox->getObjectId());
2223 std::map<int, GObjectController*>::iterator iterOBJ2 = mapSelected.find(endPortParentBox->getObjectId());
2225 if(iterOBJ1 != mapSelected.end() && iterOBJ2 != mapSelected.end())
2227 int ID = cont->getId();
2228 mapSelected[ID]=cont;
2235 //=========================================================================
2237 void wxVtkSceneManager::addObjects(std::map<int,GObjectController*> objectsMap)
2240 std::map<int,int> oldIdNewIdBoxes;
2241 std::vector<int> connections;
2243 std::map<int, GObjectController*>::iterator it;
2244 for(it = objectsMap.begin(); it != objectsMap.end(); ++it)
2246 GObjectController *cont = it->second;
2247 int type = cont->getGObjectType();
2252 double xInic, yInic,zInic;
2253 GBlackBoxModel* copyBox = (GBlackBoxModel*)cont->getModel();
2254 copyBox->getInicPoint(xInic,yInic,zInic);
2255 int idBox = createGBlackBox(0,0,copyBox->getBBTKPackage(),copyBox->getBBTKType());
2257 int idcB = copyBox->getObjectId();
2258 oldIdNewIdBoxes[idcB]=idBox;
2259 cont = _controllers[idBox];
2260 GBlackBoxModel* newbox = (GBlackBoxModel*)cont->getModel();
2261 newbox->setInicPoint(xInic,yInic,zInic);
2262 int num = newbox->getNumInputPorts();
2263 for(int j=0;j<num;j++)
2265 newbox->setValueToInputPort(j,copyBox->getValueInputPort(j));
2267 newbox->notifyObservers(_idManager);
2269 else if(type==GCONNECTOR)
2271 int idCon = cont->getId();
2272 connections.push_back(idCon);
2277 for(int i = 0 ;i<(int)connections.size();i++)
2279 int objId = connections[i];
2280 GObjectController *cont = objectsMap[objId];
2281 GConnectorModel* connectModel = (GConnectorModel*)cont->getModel();
2283 GPortModel* startPort = connectModel->getStartPort();
2284 int startPortIndex = startPort->getPosInBox();
2285 GPortModel* endPort = connectModel->getEndPort();
2286 int endPortIndex = endPort->getPosInBox();
2288 GBlackBoxModel* startPortParentBox = (GBlackBoxModel*)startPort->getParentBox();
2289 GBlackBoxModel* endPortParentBox = (GBlackBoxModel*)endPort->getParentBox();
2291 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2292 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2294 GBlackBoxModel* newStartBox = (GBlackBoxModel*)_controllers[idNewStartBox]->getModel();
2295 GBlackBoxModel* newEndBox = (GBlackBoxModel*)_controllers[idNewEndBox]->getModel();
2297 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2298 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2300 // Creates connection
2301 int idCon = createGConnector(newStartPort);
2302 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
2303 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
2304 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
2305 tempp->endContourCreation();
2306 conMod->setEndPort(newEndPort);
2307 conView->updateStartEndPoints();
2310 std::map<int, int>::iterator itIds;
2311 for(itIds = oldIdNewIdBoxes.begin(); itIds != oldIdNewIdBoxes.end(); ++itIds)
2313 int idOld = itIds->first;
2314 int idNew = itIds->second;
2316 GBlackBoxModel* oldBox = (GBlackBoxModel*)objectsMap[idOld]->getModel();
2317 GBlackBoxModel* newBox = (GBlackBoxModel*)_controllers[idNew]->getModel();
2319 std::vector<int> oldInputConnections = oldBox->getConnectedInputs();
2320 std::vector<int> oldOutputConnections = oldBox->getConnectedOutputs();
2321 std::vector<int> newInputConnections = newBox->getConnectedInputs();
2322 std::vector<int> newOutputConnections = newBox->getConnectedOutputs();
2324 for(int k = 0; k<(int)oldInputConnections.size();k++)
2327 //EED int toCreate=-1;
2328 for(int l = 0; l<(int)newInputConnections.size() && !exist;l++)
2330 if(oldInputConnections[k]==newInputConnections[l])
2338 //Create complex input
2339 int posInBox = oldInputConnections[k];
2340 GPortModel* inputPort = oldBox->getInputPort(posInBox);
2341 std::string inputPortName = inputPort->getBBTKName();
2342 int idInputPort = createGComplexBoxInputPort(inputPortName);
2343 GObjectController *cont = _controllers[idInputPort];
2344 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
2346 inputPort->getInicPoint(xIn,yIn,zIn);
2348 cbmod->setInicPoint(xIn,yIn,zIn);
2349 cbmod->notifyObservers(_idManager);
2351 GPortModel* inputPortEnd = newBox->getInputPort(posInBox);
2353 // Creates connection
2354 int idCon = createGConnector(cbmod->getOutputPort(0));
2355 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
2356 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
2357 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
2358 tempp->endContourCreation();
2359 conMod->setEndPort(inputPortEnd);
2360 conView->updateStartEndPoints();
2367 for(int k = 0; k<(int)oldOutputConnections.size();k++)
2370 //EED int toCreate=-1;
2371 for(int l = 0; l<(int)newOutputConnections.size() && !exist;l++)
2373 if(oldOutputConnections[k]==newOutputConnections[l])
2381 //Create complex output
2382 int posInBox = oldOutputConnections[k];
2383 GPortModel* outputPort = oldBox->getOutputPort(posInBox);
2384 std::string outputPortName = outputPort->getBBTKName();
2385 int idOutputPort = createGComplexBoxOutputPort(outputPortName);
2386 GObjectController *cont = _controllers[idOutputPort];
2387 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
2389 outputPort->getInicPoint(xIn,yIn,zIn);
2391 cbmod->setInicPoint(xIn,yIn,zIn);
2392 cbmod->notifyObservers(_idManager);
2394 GPortModel* outputPortEnd = newBox->getOutputPort(posInBox);
2396 // Creates connection
2397 int idCon = createGConnector(outputPortEnd);
2398 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
2399 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
2400 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
2401 tempp->endContourCreation();
2402 conMod->setEndPort(cbmod->getInputPort(0));
2403 conView->updateStartEndPoints();
2414 //=========================================================================
2416 } // EO namespace bbtk