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 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 );
165 _pts->InsertPoint(0, xInic , yInic , zInic );
166 _pts->InsertPoint(1, xInic+50 , yInic , zInic );
167 _pts->InsertPoint(2, xInic+50 , yInic+50 , zInic );
168 _pts->InsertPoint(3, xInic+25 , yInic+50 , zInic );
169 _pts->InsertPoint(4, xInic+20 , yInic+55 , zInic );
170 _pts->InsertPoint(5, xInic+15 , yInic+50 , zInic );
171 _pts->InsertPoint(6, xInic , yInic+50 , zInic );
174 aPolygon->GetPointIds()->SetNumberOfIds(21);
175 for (int i=0;i<21; i++)
177 aPolygon->GetPointIds()->SetId(i, i);
180 vtkUnstructuredGrid *aPolygonGrid = vtkUnstructuredGrid::New();
181 aPolygonGrid->Allocate(1, 1);
182 aPolygonGrid->InsertNextCell(aPolygon->GetCellType(), aPolygon->GetPointIds());
183 aPolygonGrid->SetPoints(_pts);
184 _aPolygonMapper = vtkDataSetMapper::New();
185 _aPolygonMapper->SetInput(aPolygonGrid);
186 _fillObjectActor->SetMapper(_aPolygonMapper);
187 _fillObjectActor->GetProperty()->SetColor(PORTFILL_NH_R,PORTFILL_NH_G,PORTFILL_NH_B);
188 _aPolygonMapper->Modified();
190 _baseView->GetRenderer()->AddActor( _fillObjectActor );
193 //=========================================================================
195 std::string wxVtkSceneManager::generateANewNameForABox()
197 std::stringstream boxname;
200 boxname << "Box0" << _numBoxes;
202 boxname << "Box" << _numBoxes;
205 return boxname.str();
208 //=========================================================================
210 std::string wxVtkSceneManager::findANewNameForABox()
212 std::string boxname=generateANewNameForABox();
214 while (boxExist(boxname)==true)
216 boxname=generateANewNameForABox();
222 //=========================================================================
223 void wxVtkSceneManager::configGBlackBox(int idBox, double xIn, double yIn, double zIn, std::string name, bool boxExecutable,double xEn,double yEn,double zEn)
225 GObjectController *cont = _controllers[idBox];
226 GBlackBoxModel *bbmod = (GBlackBoxModel*)cont->getModel();
227 bbmod->setBBTKName(name);
228 bbmod->setInicPoint(xIn,yIn,zIn);
229 bbmod->setFinalPoint(xEn,yEn,zEn);
230 bbmod->setExecutable(boxExecutable);
232 bbmod->notifyObservers(_idManager);
237 //=========================================================================
239 int wxVtkSceneManager::createGBlackBox(int x, int y, std::string packageName, std::string boxType)
241 _worldState = NOTHING_HAPPENS;
242 //EED int windowWidth = _baseView->GetRenWin()->GetSize()[0];
243 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
245 int type = GBLACKBOX;
247 //Create the MVC Objects
249 GBlackBoxModel *model = (GBlackBoxModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
250 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
251 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
253 BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxType);
255 //Prepares the initial model
256 //The coordinates obtained are the following. Top-Left:x=0,y=0 Bottom-Right:x=width,y=height
259 double yy = windowHeight-y;
261 //z value is not important yet, because it is only used a parallel projection
264 _baseView->TransCoordScreenToWorld(xx,yy,zz);
265 model->setInicPoint(xx,yy,zz);
267 std::stringstream stream;
269 std::string newBoxName;
270 newBoxName = findANewNameForABox();
273 stream << newBoxName;
275 std::string arraystring = stream.str();
277 model->setBBTKName(arraystring);
278 model->setBBTKType(boxType);
279 model->setBBTKPackage(packageName);
281 model->addObserver(view);
282 model->addObserver(this);
284 //Iterate and create the input ports
285 std::map<std::string, BlackBoxInputDescriptor*> descriptorInMap = descriptor->GetInputDescriptorMap();
286 std::map<std::string, BlackBoxInputDescriptor*>::iterator itInput;
289 for(itInput = descriptorInMap.begin(); itInput != descriptorInMap.end(); ++itInput)
291 BlackBoxInputDescriptor *desc = itInput->second;
292 createGInputPort(GINPUTPORT,i,model,desc);
296 //Iterate and create the output ports
297 std::map<std::string, BlackBoxOutputDescriptor*> descriptorOutMap = descriptor->GetOutputDescriptorMap();
298 std::map<std::string, BlackBoxOutputDescriptor*>::iterator itOutput;
301 for(itOutput = descriptorOutMap.begin();itOutput != descriptorOutMap.end(); ++itOutput)
303 BlackBoxOutputDescriptor *desc = itOutput->second;
304 createGOutputPort(GOUTPUTPORT,i,model,desc);
309 //Associates the view with the correspondent renderer and the model.
310 //(NOTE: Refresh is only made by the view)
311 view->setModel(model);
312 view->setBaseView(_baseView);
313 view->initVtkObjects();
315 //Associates the controller with the correspondent model and view
316 controller->setModelAndView(model,view);
318 //Resgiter change to the observers of the actual model
319 model->notifyObservers(_idManager);
321 int newId = addObjectController(controller);
327 //=========================================================================
329 int wxVtkSceneManager::createGComplexBoxInputPort(std::string inputName)
331 //EED int windowWidth=_baseView->GetRenWin()->GetSize()[0];
332 int windowHeight=_baseView->GetRenWin()->GetSize()[1];
334 int type = GCOMPLEXINPUTPORT;
336 //Create the MVC Objects
338 GComplexBoxPortModel *model = (GComplexBoxPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
339 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
340 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
342 //Prepares the initial model
345 double yy = windowHeight-5;
347 //z value is not important yet, because it is only used a parallel projection
350 _baseView->TransCoordScreenToWorld(xx,yy,zz);
351 model->setInicPoint(xx,yy,zz);
353 model->setBBTKName(inputName);
354 model->setBBTKType("ComplexInputPort");
355 model->setComplexPortType(type);
357 model->addObserver(view);
358 model->addObserver(this);
360 //create the output port
361 GPortController* portController = createGPort(GOUTPUTPORT,inputName,"ComplexInputPort",0,model);
362 model->addOutputPort((GPortModel*)portController->getModel());
364 //Associates the view with the correspondent renderer and the model.
365 //(NOTE: Refresh is only made by the view)
366 view->setModel(model);
367 view->setBaseView(_baseView);
368 view->initVtkObjects();
370 //Associates the controller with the correspondent model and view
371 controller->setModelAndView(model,view);
373 //Resgiter change to the observers of the actual model
374 model->notifyObservers(_idManager);
376 int newId = addObjectController(controller);
380 //=========================================================================
382 int wxVtkSceneManager::createGComplexBoxOutputPort(std::string outputName)
384 //EED int windowWidth=_baseView->GetRenWin()->GetSize()[0];
385 int windowHeight=_baseView->GetRenWin()->GetSize()[1];
387 int type = GCOMPLEXOUTPUTPORT;
389 //Create the MVC Objects
391 GComplexBoxPortModel *model = (GComplexBoxPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
392 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
393 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
395 //Prepares the initial model
398 double yy = windowHeight-5;
400 //z value is not important yet, because it is only used a parallel projection
403 _baseView->TransCoordScreenToWorld(xx,yy,zz);
404 model->setInicPoint(xx,yy,zz);
406 model->setBBTKName(outputName);
407 model->setBBTKType("ComplexOutputPort");
408 model->setComplexPortType(type);
410 model->addObserver(view);
411 model->addObserver(this);
413 //create the output port
414 GPortController* portController = createGPort(GINPUTPORT,outputName,"ComplexInputPort",0,model);
415 model->addInputPort((GPortModel*)portController->getModel());
417 //Associates the view with the correspondent renderer and the model.
418 //(NOTE: Refresh is only made by the view)
419 view->setModel(model);
420 view->setBaseView(_baseView);
421 view->initVtkObjects();
423 //Associates the controller with the correspondent model and view
424 controller->setModelAndView(model,view);
426 //Resgiter change to the observers of the actual model
427 model->notifyObservers(_idManager);
429 int newId = addObjectController(controller);
433 //=========================================================================
435 int wxVtkSceneManager::createGInputPort(int portType, int posinBox,GBoxModel *blackBox, BlackBoxInputDescriptor *desc)
437 GPortController* portController = createGPort(portType,desc->GetName(),desc->GetTypeName(),posinBox,blackBox);
438 blackBox->addInputPort((GPortModel*)portController->getModel());
439 return portController->getId();
442 //=========================================================================
444 int wxVtkSceneManager::createGOutputPort(int portType, int posinBox,GBoxModel *blackBox, BlackBoxOutputDescriptor *desc)
446 GPortController* portController = createGPort(portType,desc->GetName(),desc->GetTypeName(),posinBox,blackBox);
447 blackBox->addOutputPort((GPortModel*)portController->getModel());
448 return portController->getId();
451 //=========================================================================
453 GPortController* wxVtkSceneManager::createGPort(int portType,std::string bbtkName, std::string bbtkType, int posInBox,GBoxModel *blackBox)
457 //Create the MVC Objects
458 GPortModel *model = (GPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
459 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
460 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
462 model->registerInBox(blackBox,portType, posInBox);
464 model->setBBTKType(bbtkType);
465 model->setBBTKName(bbtkName);
467 model->addObserver(view);
468 model->addObserver(this);
470 //Associates the view with the correspondent renderer and the model.
471 //(NOTE: Refresh is only made by the view)
472 view->setModel(model);
473 view->setBaseView(_baseView);
474 view->initVtkObjects();
476 //Associates the controller with the correspondent model and view
477 controller->setModelAndView(model,view);
479 model->notifyObservers(_idManager);
481 addObjectController(controller);
483 return (GPortController*)controller;
486 //=========================================================================
488 int wxVtkSceneManager::createGConnector(GPortModel* startPort)
490 int type = GCONNECTOR;
492 manualConnectorContourController* manContourControl = new manualConnectorContourController();
493 manualConnectorContourView* manContourView = new manualConnectorContourView();
494 manualContourModel* manContourModel = new manualContourModel();
496 GConnectorController* connectorcontroller = new GConnectorController();
497 GConnectorModel* connectorModel = new GConnectorModel();
498 vtkGConnectorView* connectorView = new vtkGConnectorView();
499 connectorModel->setGObjectType(type);
501 manContourModel->SetCloseContour(false);
502 connectorModel->setStartPort(startPort);
504 manContourView->SetModel( manContourModel );
505 manContourView->SetWxVtkBaseView( _baseView );
506 manContourView->SetRange( 0.5 );
507 manContourView->SetZ( 900 );
509 manContourView->SetColorNormalContour(0, 0, 1);
510 manContourView->SetColorEditContour(0.5, 0.5, 0.5);
511 manContourView->SetColorSelectContour(1, 0.8, 0);
512 manContourView->SetWidthLine(1);
513 manContourView->SetShowText(false);
515 manContourControl->SetModelView( manContourModel , manContourView );
517 manContourControl->CreateNewManualContour();
519 manContourView->RefreshContour();
523 connectorModel->getInicPoint(x,y,z);
525 manContourControl->SetState(1);
526 manContourModel->SetCloseContour(false);
528 manContourModel->AddPoint(x,y,z);
529 manContourView->AddPoint();
531 manContourModel->AddPoint(x,y,z);
532 manContourView->AddPoint();
534 int bak= manContourControl->GetNumberOfPointsManualContour() - 1;
535 manContourControl->_bakIdPoint=bak;
536 manContourView->Refresh();
538 manContourControl->SetMoving( false );
540 connectorcontroller->setModelAndView(connectorModel,connectorView);
542 int newId = addObjectController(connectorcontroller);
544 connectorcontroller->setManualContourController(manContourControl);
545 connectorModel->setManualContourModel(manContourModel);
546 connectorView->setManualContourView(manContourView);
547 connectorView->setModel(connectorModel);
548 connectorView->setBaseView(_baseView);
551 connectorModel->addObserver(connectorView);
552 connectorModel->addObserver(this);
557 //=========================================================================
559 void wxVtkSceneManager::registerController(InteractorStyleMaracas *param)
561 vtkInteractorStyleBaseView* baseViewControlManager = (vtkInteractorStyleBaseView*)_baseView->GetInteractorStyleBaseView();
562 baseViewControlManager->AddInteractorStyleMaracas( param );
565 //=========================================================================
567 void wxVtkSceneManager::unregisterController(InteractorStyleMaracas *param)
569 vtkInteractorStyleBaseView* baseViewControlManager = (vtkInteractorStyleBaseView*)_baseView->GetInteractorStyleBaseView();
570 baseViewControlManager->RemoveInteractorStyleMaracas( param );
573 //=========================================================================
575 vtkRenderer* wxVtkSceneManager::getRenderer()
577 return _baseView->GetRenderer();
580 //=========================================================================
582 vtkRenderWindow* wxVtkSceneManager::getRenderWindow()
584 return _baseView->GetRenWin();
586 //=========================================================================
589 void wxVtkSceneManager::update(int idController,int command)
591 if(command != NO_COMMAND)
593 if(command == ADD_TO_SELECTED)
595 //EED GObjectController* cont = _controllers[idController];
598 for (int i=0; i<(int)_selectedObjects.size() && foundID==false; i++)
600 int id = _selectedObjects[i];
608 int id = idController;
609 _selectedObjects.push_back(id);
613 else if(command == INIT_CREATION_CONTOUR)
615 _worldState = INIT_CREATION_CONTOUR;
616 GObjectController* cont = _controllers[idController];
617 GPortModel* startOutputPort = (GPortModel*)cont->getModel();
620 // The last one is the controller of the connector
621 std::map<int, GObjectController*>::iterator it2;
623 for(it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
625 GObjectController *cont = it2->second;
626 if(cont->getGObjectType() == GPORT )
628 GPortModel* port = (GPortModel*)cont->getModel();
629 if(port->getPortType()==GINPUTPORT)
631 cont->SetActive(true);
635 cont->getView()->setState(NOTHING_HAPPENS);
636 cont->getModel()->notifyObservers(_idManager);
637 cont->SetActive(false);
642 cont->getView()->setState(NOTHING_HAPPENS);
643 cont->getModel()->notifyObservers(_idManager);
644 cont->SetActive(false);
648 _selectedObjects.clear();
650 _idConnectionInCreation=createGConnector(startOutputPort);
653 else if(command == FIN_CREATION_CONTOUR && _worldState == INIT_CREATION_CONTOUR)
655 _worldState = NOTHING_HAPPENS;
656 //int id = _controllers.size()-1;
657 GObjectController* cont = _controllers[_idConnectionInCreation];
658 GConnectorModel* modelContour = (GConnectorModel*)cont->getModel();
660 GObjectController* finPort = _controllers[idController];
661 if(finPort->getGObjectType() == GPORT)
663 GPortModel* modelPort = (GPortModel*)finPort->getModel();
664 modelContour->setEndPort(modelPort);
667 manualConnectorContourController* manCont = ((GConnectorController*)cont)->getManualContourController();
668 manualConnectorContourView* connView = (manualConnectorContourView*)manCont->GetManualViewBaseContour();
671 std::map<int, GObjectController*>::iterator it2;
673 for(it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
675 GObjectController *cont = it2->second;
676 if(cont->getView()!=NULL)
678 cont->getView()->setState(NOTHING_HAPPENS);
679 cont->getModel()->notifyObservers(_idManager);
681 cont->SetActive(true);
688 //=========================================================================
690 bool wxVtkSceneManager::OnMouseMove()
693 bool okStatusMessage = false;
694 bool okPortMessage = false;
695 wxVTKRenderWindowInteractor *wxVTKiren;
696 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
697 wxVTKiren->GetEventPosition(X,Y);
700 if(_worldState == DRAG_OBJECTS)
702 for (int i=0; i<(int)_selectedObjects.size(); i++)
704 int id = _selectedObjects[i];
705 GObjectController* cont = _controllers[id];
708 cont->getView()->setStartDragging(true);
710 cont->getView()->moveObject(X,Y);
711 cont->getView()->setState(DRAG);
712 cont->getModel()->notifyObservers(_idManager);
715 std::map<int, GObjectController*>::iterator it;
717 for(it = _controllers.begin(); it != _controllers.end(); ++it)
719 GObjectController *desc = it->second;
720 if(desc->getGObjectType()==GCONNECTOR)
722 vtkGConnectorView* vconn = (vtkGConnectorView*)desc->getView();
723 vconn->updateStartEndPoints();
727 _startDragging=false;
730 else if(_worldState == NOTHING_HAPPENS || _worldState == INIT_CREATION_CONTOUR)
732 std::map<int, GObjectController*>::iterator it;
734 for(it = _controllers.begin(); it != _controllers.end(); ++it)
736 GObjectController *desc = it->second;
737 int type = desc->getGObjectType();
738 int state = desc->getView()->getState();
739 desc->getModel()->getCenter(px,py,pz);
741 if(state == HIGHLIGHTED){
742 okStatusMessage = true;
743 updateStatusBar(desc->getStatusText());
746 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
747 _parent->displayBlackBoxInfo(mod->getBBTKPackage(),mod->getBBTKType());
752 okPortMessage = true;
754 _textActor->SetInput( desc->getStatusText().c_str() );
755 _textActor->SetScale(0.1);
756 _textActor->SetPosition( px-25 ,py , pz+2 );
762 _pts->SetPoint(0, px , py , 900+1 );
763 _pts->SetPoint(1, px+150 , py , 900+1 );
764 _pts->SetPoint(2, px+150 , py+7 , 900+1 );
765 _pts->SetPoint(3, px-150+40 , py+7 , 900+1 );
766 _pts->SetPoint(4, px-150+40-5 , py+7+5 , 900+1 );
767 _pts->SetPoint(5, px-150+40-10 , py+7 , 900+1 );
768 _pts->SetPoint(6, px , py+7 , 900+1 );
770 _fillObjectActor->SetScale(1);
771 _fillObjectActor->SetPosition(px,py,1);
772 _aPolygonMapper->Modified();
775 } // for controllers it
779 if (okStatusMessage==false)
784 if (okPortMessage==false)
786 _textActor->SetScale(0.0001);
787 _fillObjectActor->SetScale(0.0001);
794 //=========================================================================
796 bool wxVtkSceneManager::OnLeftButtonDown()
798 if(_worldState==INIT_CREATION_CONTOUR)
800 bool isOverPort=false;
801 std::map<int, GObjectController*>::iterator it;
802 for(it = _controllers.begin(); it != _controllers.end() && isOverPort==false; ++it)
804 GObjectController *desc = it->second;
805 if(desc->getGObjectType()==GPORT)
807 GPortModel* portmod=(GPortModel*)desc->getModel();
808 vtkGObjectView* portView=desc->getView();
809 if(portmod->getPortType()==GINPUTPORT && portView->getState()==HIGHLIGHTED)
816 if(isOverPort==false)
818 _worldState=NOTHING_HAPPENS;
819 //int lastId = _controllers.size()-1;
820 GConnectorController *connector = (GConnectorController*)_controllers[_controllers.size()-1];
821 connector->removeFromScene();
822 unregisterController(connector);
823 _controllers.erase(_controllers.size()-1);
825 for(it = _controllers.begin(); it != _controllers.end(); ++it)
827 GObjectController *desc = it->second;
828 desc->SetActive(true);
829 desc->getView()->setState(NOTHING_HAPPENS);
830 desc->getModel()->notifyObservers(_idManager);
835 if(_selectedObjects.size()!=0)
837 _worldState = DRAG_OBJECTS;
838 _startDragging = true;
840 for (int i = 0; i < (int)_selectedObjects.size(); i++)
842 int id = _selectedObjects[i];
843 GObjectController* cont = _controllers[id];
844 cont->getView()->setState(DRAG);
845 cont->getModel()->notifyObservers(_idManager);
854 //=========================================================================
856 bool wxVtkSceneManager::OnLeftButtonUp()
858 if(_worldState == DRAG_OBJECTS)
860 _worldState = NOTHING_HAPPENS;
862 for (int i = 0; i < (int)_selectedObjects.size(); i++)
864 int id = _selectedObjects[i];
865 GObjectController* cont = _controllers[id];
866 cont->getView()->setState(SELECTED);
867 cont->getModel()->notifyObservers(_idManager);
873 //=========================================================================
875 bool wxVtkSceneManager::OnRightButtonUp()
877 if(_worldState==INIT_CREATION_CONTOUR)
879 _worldState=NOTHING_HAPPENS;
880 //int lastId = _controllers.size()-1;
881 GConnectorController *connector = (GConnectorController*)_controllers[_idConnectionInCreation];
882 connector->removeFromScene();
883 unregisterController(connector);
884 _controllers.erase(_idConnectionInCreation);
886 std::map<int, GObjectController*>::iterator it;
887 for(it = _controllers.begin(); it != _controllers.end(); ++it)
889 GObjectController *desc = it->second;
890 desc->SetActive(true);
891 desc->getView()->setState(NOTHING_HAPPENS);
892 desc->getModel()->notifyObservers(_idManager);
897 for (int i = 0; i < (int)_selectedObjects.size(); i++)
899 int id = _selectedObjects[i];
900 GObjectController* cont = _controllers[id];
901 cont->SetActive(true);
902 cont->getView()->setState(NOTHING_HAPPENS);
903 cont->getModel()->notifyObservers(_idManager);
906 _selectedObjects.clear();
911 //=========================================================================
913 bool wxVtkSceneManager::OnLeftDClick()
916 wxVTKRenderWindowInteractor *wxVTKiren;
917 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
918 wxVTKiren->GetEventPosition(X,Y);
920 std::map<int, GObjectController*>::iterator it;
922 bool clickOnObject = false;
924 for(it = _controllers.begin(); it != _controllers.end() && clickOnObject==false; ++it)
926 GObjectController *cont = it->second;
927 int type = cont->getGObjectType();
929 if(cont->getView()->isPointInside(X,Y))
933 for (int i=0; i< (int)_selectedObjects.size(); i++)
935 int id = _selectedObjects[i];
936 GObjectController* control = _controllers[id];
937 control->getView()->setState(NOTHING_HAPPENS);
939 _selectedObjects.clear();
941 GBlackBoxModel *bbmodel = (GBlackBoxModel*)cont->getModel();
942 _parent->editBlackBox(bbmodel);
944 clickOnObject = true;
948 if(clickOnObject==false)
950 //_parent->editDiagramParameters(this);
956 //=========================================================================
958 bool wxVtkSceneManager::OnChar()
960 char keyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
962 // KeyCode 127 : Delete Key
963 // KeyCode 8 : Backspace Key
964 if(keyCode == 8 || keyCode == 127)
966 if(_selectedObjects.size()>0)
968 for(int i=0;i<(int)_selectedObjects.size();i++)
970 int id = _selectedObjects[i];
971 std::map<int,GObjectController*>::iterator it;
972 it = _controllers.find(id);
973 if (it!=_controllers.end())
978 _selectedObjects.clear();
985 //=========================================================================
987 void wxVtkSceneManager::AddControlerToBeRemove(std::vector<int> *controllersToRemove, int id)
992 for(i=0 ; i < (int)controllersToRemove->size() ; i++ )
994 if (id == (*controllersToRemove)[i] )
1002 controllersToRemove->push_back( id );
1007 //=========================================================================
1009 void wxVtkSceneManager::deleteObject(int id)
1011 GObjectController *control = _controllers[id];
1012 std::vector<int> controllersToRemove;
1014 if(control->getGObjectType()==GBLACKBOX || control->getGObjectType()==GCOMPLEXINPUTPORT || control->getGObjectType()==GCOMPLEXOUTPUTPORT)
1016 GBoxModel *bbmod = (GBoxModel*)control->getModel();
1017 std::vector<GPortModel*> inputs = bbmod->getInputPorts();
1019 bool boxConnected = false;
1021 // Add box input controllers to be removed
1022 for(int i = 0;i< (int)inputs.size();i++)
1024 AddControlerToBeRemove( &controllersToRemove, inputs[i]->getObjectId() );
1025 if(inputs[i]->isConnected())
1027 boxConnected = true;
1031 std::vector<GPortModel*> outputs = bbmod->getOutputPorts();
1033 // Add box output controllers to be removed
1034 for(int i = 0;i<(int)outputs.size();i++)
1036 AddControlerToBeRemove( &controllersToRemove, outputs[i]->getObjectId() );
1037 if(outputs[i]->isConnected())
1039 boxConnected = true;
1043 // Add connection controllers to be removed
1044 std::map<int, GObjectController*>::iterator it;
1045 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1047 GObjectController *cont = it->second;
1048 int type = cont->getGObjectType();
1049 if(type==GCONNECTOR)
1051 GConnectorModel *conMod = (GConnectorModel*)cont->getModel();
1052 if(conMod->getStartPort()!=NULL && conMod->getStartPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
1054 AddControlerToBeRemove( &controllersToRemove, conMod->getObjectId() );
1056 if(conMod->getEndPort()!=NULL && conMod->getEndPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
1058 AddControlerToBeRemove( &controllersToRemove, conMod->getObjectId() );
1063 // Add box controller to be removed
1064 AddControlerToBeRemove( &controllersToRemove, bbmod->getObjectId() );
1066 else if(control->getGObjectType()==GCONNECTOR)
1068 GConnectorModel *conMod = (GConnectorModel*)control->getModel();
1069 AddControlerToBeRemove( &controllersToRemove, conMod->getObjectId() );
1073 std::map<int,GObjectController*>::iterator it;
1075 for(int i = 0;i<(int)controllersToRemove.size();i++)
1077 int key = controllersToRemove[i];
1078 it = _controllers.find( key );
1079 GObjectController *cont = _controllers[ key ];
1082 cont->removeFromScene();
1083 unregisterController((InteractorStyleMaracas*)cont);
1084 _controllers.erase(it);
1089 //=========================================================================
1091 void wxVtkSceneManager::displayBlackBoxInfo(std::string packageName, std::string boxName)
1093 _parent->displayBlackBoxInfo(packageName,boxName);
1096 //=========================================================================
1098 void wxVtkSceneManager::updateStatusBar(std::string textStatus)
1100 _parent->updateStatusBar(textStatus);
1103 //=========================================================================
1105 std::string wxVtkSceneManager::getDiagramBBS()
1107 bool existsExec=false;
1109 std::vector<std::string> packages;
1110 std::vector<int> boxes;
1111 std::vector<int> connections;
1112 std::vector<int> execBoxes;
1114 std::map<int, GObjectController*>::iterator it;
1116 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1118 GObjectController *desc = it->second;
1119 int type = desc->getGObjectType();
1123 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
1125 std::string pkg = mod->getBBTKPackage();
1126 bool existsPkg = false;
1127 for(int t = 0;t< (int)packages.size() && existsPkg == false;t++)
1129 if(packages[t]==pkg)
1136 packages.push_back(pkg);
1140 boxes.push_back(it->first);
1141 if(mod->isExecutable())
1143 execBoxes.push_back(it->first);
1147 else if(type==GCONNECTOR)
1149 connections.push_back(it->first);
1153 std::string script = "";
1154 script+="# BBTK GEditor Script\n";
1155 script+="# ----------------------\n";
1159 script+="include std\n"; // EED
1160 script+="include itkvtk\n"; // EED
1162 for(i = 0; i< (int)packages.size();i++)
1165 script+=packages[i];
1170 // script+="include std\n"; // JPR
1172 for(i = 0; i < (int)boxes.size();i++)
1176 GObjectController *control = _controllers[id];
1177 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1179 script+=model->getBBTKType();
1181 script+=model->getBBTKName();
1184 std::vector<GPortModel*> inputs = model->getInputPorts();
1185 for(int j = 0; j < (int)inputs.size();j++)
1187 GPortModel* inputPort = inputs[j];
1188 if(inputPort->isValueSet())
1191 script+=model->getBBTKName();
1193 script+=inputPort->getBBTKName();
1195 script+=inputPort->getValue();
1205 for(i = 0; i<(int)connections.size();i++)
1208 int id = connections[i];
1209 GObjectController *control = _controllers[id];
1210 GConnectorModel *model = (GConnectorModel*)control->getModel();
1212 //Start Connection info
1213 GPortModel *start = model->getStartPort();
1214 script+=start->getParentBox()->getBBTKName();
1216 script+=start->getBBTKName();
1220 //End Connection info
1221 GPortModel *end = model->getEndPort();
1222 script+=end->getParentBox()->getBBTKName();
1224 script+=end->getBBTKName();
1230 for(i = 0; i<(int)execBoxes.size();i++)
1233 int id = execBoxes[i];
1234 GObjectController *control = _controllers[id];
1235 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1237 script+=model->getBBTKName();
1246 //=========================================================================
1248 std::string wxVtkSceneManager::saveComplexBoxBBS(std::string cbName,std::string cbAuthor,std::string cbCategory,std::string cbDescription)
1251 std::vector<std::string> packages;
1252 std::vector<int> boxes;
1253 std::vector<int> connections;
1254 std::vector<int> execBoxes;
1256 std::map<int, GObjectController*>::iterator it;
1258 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1260 GObjectController *desc = it->second;
1261 int type = desc->getGObjectType();
1265 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
1267 std::string pkg = mod->getBBTKPackage();
1268 bool existsPkg = false;
1269 for(int t = 0;t<(int)packages.size() && existsPkg == false;t++)
1271 if(packages[t]==pkg)
1278 packages.push_back(pkg);
1282 boxes.push_back(it->first);
1283 if(mod->isExecutable())
1285 execBoxes.push_back(it->first);
1288 else if(type==GCONNECTOR)
1290 connections.push_back(it->first);
1294 std::string script = "";
1296 script+="include std\n"; // EED
1297 script+="include itkvtk\n"; // EED
1299 for(i = 0; i<(int)packages.size();i++)
1302 script+=packages[i];
1307 // Definition of a complex box
1313 script+="author \" ";
1317 script+="description \" ";
1318 script+=cbDescription;
1323 for(i = 0; i<(int)boxes.size();i++)
1327 GObjectController *control = _controllers[id];
1328 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1330 script+=model->getBBTKType();
1332 script+=model->getBBTKName();
1335 std::vector<GPortModel*> inputs = model->getInputPorts();
1336 for(int j = 0; j<(int)inputs.size();j++)
1338 GPortModel* inputPort = inputs[j];
1339 if(inputPort->isValueSet())
1342 script+=model->getBBTKName();
1344 script+=inputPort->getBBTKName();
1346 script+=inputPort->getValue();
1354 // Create connections in the script. If the connection is made with a complex port, it is created the input or output
1356 std::string complexInputs="";
1357 std::string complexOutputs="";
1360 for(i = 0; i<(int)connections.size();i++)
1362 int id = connections[i];
1363 GObjectController *control = _controllers[id];
1364 GConnectorModel *model = (GConnectorModel*)control->getModel();
1367 GPortModel *start = model->getStartPort();
1368 GBoxModel *startBox =start->getParentBox();
1370 GPortModel *end = model->getEndPort();
1371 GBoxModel *endBox =end->getParentBox();
1373 if(startBox->getGObjectType()==GCOMPLEXINPUTPORT)
1375 complexInputs+="input ";
1376 complexInputs+=startBox->getBBTKName();
1379 complexInputs+=endBox->getBBTKName();
1381 complexInputs+=end->getBBTKName();
1384 complexInputs+="\" \"";
1386 complexInputs+="\n";
1388 else if(endBox->getGObjectType()==GCOMPLEXOUTPUTPORT)
1390 complexOutputs+="output ";
1391 complexOutputs+=endBox->getBBTKName();
1393 complexOutputs+=" ";
1394 complexOutputs+=startBox->getBBTKName();
1395 complexOutputs+=".";
1396 complexOutputs+=start->getBBTKName();
1398 complexOutputs+=" ";
1399 complexOutputs+="\" \"";
1401 complexOutputs+="\n";
1406 script+=startBox->getBBTKName();
1408 script+=start->getBBTKName();
1412 //End Connection info
1413 script+=endBox->getBBTKName();
1415 script+=end->getBBTKName();
1423 for(i = 0; i<(int)execBoxes.size();i++)
1426 int id = execBoxes[i];
1427 GObjectController *control = _controllers[id];
1428 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1430 script+=model->getBBTKName();
1435 script+="# Complex input ports\n";
1436 script+=complexInputs;
1439 script+="# Complex output ports\n";
1440 script+=complexOutputs;
1449 //=========================================================================
1451 void wxVtkSceneManager::deleteAllBoxes()
1453 std::map<int, GObjectController*>::iterator it;
1454 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1456 GObjectController *cont = it->second;
1457 cont->removeFromScene();
1458 unregisterController((InteractorStyleMaracas*)cont);
1460 _selectedObjects.clear();
1461 _controllers.clear();
1465 //=========================================================================
1467 void wxVtkSceneManager::refreshScene()
1469 _baseView->RefreshView();
1472 //=========================================================================
1474 void wxVtkSceneManager::centerView()
1477 _baseView->GetRenderer()->GetActiveCamera()->GetFocalPoint(temp);
1478 _baseView->GetRenderer()->GetActiveCamera()->SetFocalPoint(0,0,temp[2]);
1479 _baseView->GetRenderer()->GetActiveCamera()->GetPosition(temp);
1480 _baseView->GetRenderer()->GetActiveCamera()->SetPosition(0,0,temp[2]);
1481 _baseView->RefreshView();
1485 //=========================================================================
1487 void wxVtkSceneManager::saveDiagram(std::string &content)
1491 //Print info IF COMPLEX BOX
1492 content+="COMPLEXBOX:";
1497 //Print info complex input ports
1498 std::vector<int> inputs = getComplexInputPorts();
1499 int insize = inputs.size();
1500 content+="COMPLEXINPUTS:";
1501 sprintf (buffer, "%d", insize);
1505 for(int i = 0;i<insize;i++)
1508 GObjectController *cont = _controllers[id];
1509 cont->getModel()->save(content);
1512 //Print info complex output ports
1513 std::vector<int> outputs = getComplexOutputPorts();
1514 int outsize = outputs.size();
1515 content+="COMPLEXOUTPUTS:";
1516 sprintf (buffer, "%d", outsize);
1520 for(int i = 0;i<outsize;i++)
1522 int id = outputs[i];
1523 GObjectController *cont = _controllers[id];
1524 cont->getModel()->save(content);
1533 std::vector<int> boxes = getBlackBoxes();
1534 int bsize = boxes.size();
1536 sprintf (buffer, "%d", bsize);
1540 for(int i = 0;i<bsize;i++)
1543 GObjectController *cont = _controllers[id];
1544 cont->getModel()->save(content);
1548 std::vector<int> connections = getConnections();
1549 int csize = connections.size();
1550 content+="CONNECTIONS:";
1551 sprintf (buffer, "%d", csize);
1555 for(int i = 0;i<csize;i++)
1557 int id = connections[i];
1558 GObjectController *cont = _controllers[id];
1559 cont->getModel()->save(content);
1564 //=========================================================================
1566 void wxVtkSceneManager::loadDiagram(ifstream &inputStream)
1569 std::string line="";
1570 char delims[] = ":";
1571 char *result = NULL;
1572 getline(inputStream,line);
1575 while ( !inputStream.eof() )
1577 if(line=="" || line[0]=='#')
1579 getline(inputStream,line);
1581 else if(line=="APP_START")
1592 getline(inputStream,line);//COMPLEX_BOX:TRUE|FALSE
1594 strcpy( complex, line.c_str() );
1595 result = strtok( complex, delims );
1596 result = strtok( NULL, delims );
1597 std::string isComplexBox(result);
1599 if(isComplexBox=="TRUE")
1603 //-----------------------
1604 //- COMPLEX INPUT PORTS
1605 //-----------------------
1606 getline(inputStream,line);//COMPLEXINPUTS:num
1608 strcpy( inputs, line.c_str() );
1609 result = strtok( inputs, delims );
1610 result = strtok( NULL, delims );
1613 std::istringstream inps(result);
1616 for(int i = 0;i<numInputs;i++)
1619 getline(inputStream,line);//COMPLEX_PORT
1620 getline(inputStream,line);//name
1621 std::string inputPortName(line);
1624 getline(inputStream,line);//xInic:yInic:zInic
1626 strcpy( coord, line.c_str() );
1627 result = strtok( coord, delims );//xInic
1628 std::string xInic(result);
1629 result = strtok( NULL, delims );//yInic
1630 std::string yInic(result);
1631 result = strtok( NULL, delims );//zInic
1632 std::string zInic(result);
1634 double xIn, yIn, zIn;
1635 std::istringstream xSt(xInic);
1637 std::istringstream ySt(yInic);
1639 std::istringstream zSt(zInic);
1642 getline(inputStream,line);//FIN_COMPLEX_PORT
1644 configGComBoxInputOutputPort(true, inputPortName,xIn,yIn,zIn);
1647 // int idInputPort = createGComplexBoxInputPort(inputPortName);
1648 // GObjectController *cont = _controllers[idInputPort];
1649 // GBoxModel *cbmod = (GBoxModel*)cont->getModel();
1650 // cbmod->setInicPoint(xIn,yIn,zIn);
1651 // cbmod->notifyObservers(_idManager);
1654 } // for input complex box
1657 //-----------------------
1658 //- COMPLEX OUTPUT PORTS
1659 //-----------------------
1661 getline(inputStream,line);//COMPLEXOUTPUTS:num
1663 strcpy( outputs, line.c_str() );
1664 result = strtok( outputs, delims );
1665 result = strtok( NULL, delims );
1668 std::istringstream outps(result);
1669 outps >> numOutputs;
1671 for(int i = 0;i<numOutputs;i++)
1674 getline(inputStream,line);//COMPLEX_PORT
1675 getline(inputStream,line);//name
1676 std::string outputPortName(line);
1679 getline(inputStream,line);//xInic:yInic:zInic
1681 strcpy( coord, line.c_str() );
1682 result = strtok( coord, delims );//xInic
1683 std::string xInic(result);
1684 result = strtok( NULL, delims );//yInic
1685 std::string yInic(result);
1686 result = strtok( NULL, delims );//zInic
1687 std::string zInic(result);
1689 double xIn, yIn, zIn;
1690 std::istringstream xSt(xInic);
1692 std::istringstream ySt(yInic);
1694 std::istringstream zSt(zInic);
1697 getline(inputStream,line);//FIN_COMPLEX_PORT
1699 configGComBoxInputOutputPort(false, outputPortName,xIn,yIn,zIn);
1702 // int idOutputPort = createGComplexBoxOutputPort(outputPortName);
1703 // GObjectController *cont = _controllers[idOutputPort];
1704 // GBoxModel *cbmod = (GBoxModel*)cont->getModel();
1705 // cbmod->setInicPoint(xIn,yIn,zIn);
1706 // cbmod->notifyObservers(_idManager);
1708 } // for output complex box
1713 getline(inputStream,line);//BOXES:num
1715 strcpy( boxes, line.c_str() );
1716 result = strtok( boxes, delims );
1717 result = strtok( NULL, delims );
1720 std::istringstream is(result);
1723 for(int i = 0;i<numBoxes;i++)
1726 getline(inputStream,line);//BOX
1727 getline(inputStream,line);//package:type:name
1729 strcpy( box, line.c_str() );
1730 result = strtok( box, delims );//package
1731 std::string package(result);
1732 result = strtok( NULL, delims );//type
1733 std::string type(result);
1734 result = strtok( NULL, delims );//name
1735 std::string name(result);
1737 getline(inputStream,line);//ISEXEC:TRUE|FALSE
1739 strcpy( exec, line.c_str() );
1740 result = strtok( exec, delims );//ISEXEC
1741 result = strtok( NULL, delims );//TRUE|FALSE
1742 std::string isExec(result);
1745 getline(inputStream,line);//xInic:yInic:zInic
1747 strcpy( coord, line.c_str() );
1748 result = strtok( coord, delims );//xInic
1749 std::string xInic(result);
1750 result = strtok( NULL, delims );//yInic
1751 std::string yInic(result);
1752 result = strtok( NULL, delims );//zInic
1753 std::string zInic(result);
1755 double xIn, yIn, zIn;
1756 std::istringstream xSt(xInic);
1758 std::istringstream ySt(yInic);
1760 std::istringstream zSt(zInic);
1764 getline(inputStream,line);//xEnd:yEnd:zEnd
1765 strcpy( coord, line.c_str() );
1766 result = strtok( coord, delims );//xEnd
1767 std::string xEnd(result);
1768 result = strtok( NULL, delims );//yEnd
1769 std::string yEnd(result);
1770 result = strtok( NULL, delims );//zEnd
1771 std::string zEnd(result);
1773 double xEn, yEn, zEn;
1774 std::istringstream xEt(xEnd);
1776 std::istringstream yEt(yEnd);
1778 std::istringstream zEt(zEnd);
1781 bool boxExecutable=false;
1784 boxExecutable= true;
1787 int idBox = createGBlackBox(xIn,yIn,package,type);
1788 configGBlackBox(idBox, xIn,yIn,zIn,name, boxExecutable,xEn,yEn,zEn);
1790 GObjectController *cont = _controllers[idBox];
1791 GBlackBoxModel *bbmod = (GBlackBoxModel*)cont->getModel();
1795 // GObjectController *cont = _controllers[idBox];
1796 // GBlackBoxModel *bbmod = (GBlackBoxModel*)cont->getModel();
1797 // bbmod->setBBTKName(name);
1798 // bbmod->setInicPoint(xIn,yIn,zIn);
1799 // bbmod->setFinalPoint(xEn,yEn,zEn);
1800 // bbmod->setExecutable(boxExecutable);
1804 getline(inputStream,line);//PORT o FIN_BOX
1805 std::string port=line.substr(0,4);
1808 getline(inputStream,line);//name:value
1810 strcpy( poort, line.c_str() );
1811 result = strtok( poort, delims );//name
1812 std::string name(result);
1813 result = strtok( NULL, delims );//value
1814 std::string value(result);
1816 bbmod->setValueToInput(name,value);
1818 getline(inputStream,line);//PORT o FIN_BOX
1819 port=line.substr(0,4);
1822 //EED bbmod->notifyObservers(_idManager);
1827 getline(inputStream,line);//CONNECTIONS:num
1829 strcpy( conns, line.c_str() );
1830 result = strtok( conns, delims );
1831 result = strtok( NULL, delims );
1834 std::istringstream isCons(result);
1837 for(int i = 0;i<numConns;i++)
1840 getline(inputStream,line);//CONNECTION
1841 getline(inputStream,line);//Startbox.PortName:EndBox.PortName
1844 strcpy( connec, line.c_str() );
1845 result = strtok( connec, delims );
1846 std::string nameStartBox(result);
1847 result = strtok( NULL, delims );
1848 std::string nameStartPort(result);
1849 result = strtok( NULL, delims );
1850 std::string nameEndBox(result);
1851 result = strtok( NULL, delims );
1852 std::string nameEndPort(result);
1854 configGConnetion(nameStartBox, nameStartPort, nameEndBox, nameEndPort);
1857 std::vector<int> lstB = getBlackBoxes();
1858 GPortModel *startP = NULL;
1859 GPortModel *endP = NULL;
1861 for(j = 0;j<lstB.size();j++)
1864 GBlackBoxModel *bbMod = (GBlackBoxModel*)_controllers[idB]->getModel();
1865 if(_controllers[idB]->getModel()->getBBTKName()==nameStartBox)
1867 startP = bbMod->getOutputPort(nameStartPort);
1869 else if(_controllers[idB]->getModel()->getBBTKName()==nameEndBox)
1871 endP = bbMod->getInputPort(nameEndPort);
1879 std::vector<int> lstInputs = getComplexInputPorts();
1880 for(j = 0;j<lstInputs.size();j++)
1882 int idB = lstInputs[j];
1883 GBoxModel *cbMod = (GBoxModel*)_controllers[idB]->getModel();
1884 if(_controllers[idB]->getModel()->getBBTKName()==nameStartBox)
1886 startP = cbMod->getOutputPort(nameStartPort);
1893 std::vector<int> lstOutputs = getComplexOutputPorts();
1894 for(j = 0;j<lstOutputs.size();j++)
1896 int idB = lstOutputs[j];
1897 GBoxModel *cbMod = (GBoxModel*)_controllers[idB]->getModel();
1898 if(_controllers[idB]->getModel()->getBBTKName()==nameEndBox)
1900 endP = cbMod->getInputPort(nameEndPort);
1906 int idCon = createGConnector(startP);
1907 _worldState = NOTHING_HAPPENS;
1908 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
1910 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
1911 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
1912 tempp->endContourCreation();
1913 conMod->setEndPort(endP);
1914 conView->updateStartEndPoints();
1921 //=========================================================================
1925 //=========================================================================
1926 void wxVtkSceneManager::configGComBoxInputOutputPort(bool inputoutput, std::string portName, double xIn, double yIn,double zIn)
1929 if (inputoutput==true)
1931 idPort = createGComplexBoxInputPort(portName);
1933 idPort = createGComplexBoxOutputPort(portName);
1935 GObjectController *cont = _controllers[idPort];
1936 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
1937 cbmod->setInicPoint(xIn,yIn,zIn);
1938 cbmod->notifyObservers(_idManager);
1940 //=========================================================================
1943 //=========================================================================
1944 GBoxModel* wxVtkSceneManager::findGBox(std::string boxname)
1949 GBoxModel *boxModel = NULL;
1950 std::vector<int> lstB = getBlackBoxes();
1951 for(j = 0;j<(int)lstB.size();j++)
1954 bMod = (GBoxModel*)_controllers[idB]->getModel();
1955 if(_controllers[idB]->getModel()->getBBTKName()==boxname)
1961 if((_isComplexBox) && (boxModel==NULL))
1963 std::vector<int> lstInputs = getComplexInputPorts();
1964 for(j = 0;j<(int)lstInputs.size();j++)
1967 bMod = (GBoxModel*)_controllers[idB]->getModel();
1968 if(_controllers[idB]->getModel()->getBBTKName()==boxname)
1974 std::vector<int> lstOutputs = getComplexOutputPorts();
1975 for(j = 0;j<(int)lstOutputs.size();j++)
1977 int idB = lstOutputs[j];
1978 bMod = (GBoxModel*)_controllers[idB]->getModel();
1979 if(_controllers[idB]->getModel()->getBBTKName()==boxname)
1990 //=========================================================================
1993 void wxVtkSceneManager::configGConnetion(std::string nameStartBox, std::string nameStartPort, std::string
1994 nameEndBox, std::string nameEndPort)
1996 printf("EED wxVtkSceneManager::configGConnetion 1 %s %s %s %s\n", nameStartBox.c_str(), nameStartPort.c_str(), nameEndBox.c_str(), nameEndPort.c_str() );
1998 GBoxModel *boxModel;
1999 GPortModel *startP = NULL;
2000 GPortModel *endP = NULL;
2002 boxModel= findGBox(nameStartBox);
2005 startP = boxModel->getOutputPort(nameStartPort);
2008 boxModel= findGBox(nameEndBox);
2011 endP = boxModel->getInputPort(nameEndPort);
2015 printf("EED wxVtkSceneManager::configGConnetion 2 %p %p \n", startP, endP );
2018 std::vector<int> lstB = getBlackBoxes();
2020 for(j = 0;j<(int)lstB.size();j++)
2023 GBlackBoxModel *bbMod = (GBlackBoxModel*)_controllers[idB]->getModel();
2024 if(_controllers[idB]->getModel()->getBBTKName()==nameStartBox)
2026 startP = bbMod->getOutputPort(nameStartPort);
2028 else if(_controllers[idB]->getModel()->getBBTKName()==nameEndBox)
2030 endP = bbMod->getInputPort(nameEndPort);
2038 std::vector<int> lstInputs = getComplexInputPorts();
2039 for(j = 0;j<(int)lstInputs.size();j++)
2041 int idB = lstInputs[j];
2042 GBoxModel *cbMod = (GBoxModel*)_controllers[idB]->getModel();
2043 if(_controllers[idB]->getModel()->getBBTKName()==nameStartBox)
2045 startP = cbMod->getOutputPort(nameStartPort);
2052 std::vector<int> lstOutputs = getComplexOutputPorts();
2053 for(j = 0;j<(int)lstOutputs.size();j++)
2055 int idB = lstOutputs[j];
2056 GBoxModel *cbMod = (GBoxModel*)_controllers[idB]->getModel();
2057 if(_controllers[idB]->getModel()->getBBTKName()==nameEndBox)
2059 endP = cbMod->getInputPort(nameEndPort);
2066 int idCon = createGConnector(startP);
2067 _worldState = NOTHING_HAPPENS;
2068 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
2070 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
2071 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
2072 tempp->endContourCreation();
2073 conMod->setEndPort(endP);
2074 conView->updateStartEndPoints();
2077 //=========================================================================
2079 bool wxVtkSceneManager::boxExist(std::string boxname)
2082 std::map<int, GObjectController*>::iterator it;
2083 for(it = _controllers.begin(); it != _controllers.end(); ++it)
2085 GObjectController *cont = it->second;
2086 if(cont->getModel()->getBBTKName()==boxname)
2094 //=========================================================================
2096 std::vector<int> wxVtkSceneManager::getBlackBoxes()
2098 std::vector<int> vect;
2099 std::map<int, GObjectController*>::iterator it;
2100 for(it = _controllers.begin(); it != _controllers.end(); ++it)
2102 GObjectController *cont = it->second;
2103 if(cont->getGObjectType()==GBLACKBOX)
2105 vect.push_back(cont->getId());
2111 //=========================================================================
2113 std::vector<int> wxVtkSceneManager::getComplexInputPorts()
2115 std::vector<int> vect;
2116 std::map<int, GObjectController*>::iterator it;
2117 for(it = _controllers.begin(); it != _controllers.end(); ++it)
2119 GObjectController *cont = it->second;
2120 if(cont->getGObjectType()==GCOMPLEXINPUTPORT)
2122 vect.push_back(cont->getId());
2128 //=========================================================================
2130 std::vector<int> wxVtkSceneManager::getComplexOutputPorts()
2132 std::vector<int> vect;
2133 std::map<int, GObjectController*>::iterator it;
2134 for(it = _controllers.begin(); it != _controllers.end(); ++it)
2136 GObjectController *cont = it->second;
2137 if(cont->getGObjectType()==GCOMPLEXOUTPUTPORT)
2139 vect.push_back(cont->getId());
2145 //=========================================================================
2147 std::vector<int> wxVtkSceneManager::getConnections()
2149 std::vector<int> vect;
2150 std::map<int, GObjectController*>::iterator it;
2151 for(it = _controllers.begin(); it != _controllers.end(); ++it)
2153 GObjectController *cont = it->second;
2154 if(cont->getGObjectType()==GCONNECTOR)
2156 vect.push_back(cont->getId());
2162 //=========================================================================
2164 bool wxVtkSceneManager::isComplexBox()
2166 return _isComplexBox;
2169 //=========================================================================
2171 void wxVtkSceneManager::setComplexBox(bool val)
2176 //=========================================================================
2178 int wxVtkSceneManager::addObjectController(GObjectController* objController)
2180 //Register the controller of the new object
2181 registerController((InteractorStyleMaracas*) objController);
2183 //Add the object to the objects list
2184 int newId = _contLastId;//_controllers.size();
2185 objController->setId(newId);
2186 _controllers[newId] = objController;
2191 //=========================================================================
2193 int wxVtkSceneManager::getNumSelectedObjects()
2195 return _selectedObjects.size();
2198 //=========================================================================
2200 std::map<int,GObjectController*> wxVtkSceneManager::getSelectedObjects()
2202 std::map<int,GObjectController*> mapSelected;
2204 std::map<int, GObjectController*>::iterator it;
2205 for(it = _controllers.begin(); it != _controllers.end(); ++it)
2207 GObjectController *cont = it->second;
2208 if(cont->getGObjectType()==GBLACKBOX && cont->getView()->getState()==SELECTED)
2210 mapSelected[cont->getId()]=cont;
2214 std::map<int, GObjectController*>::iterator it2;
2215 for(it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
2217 GObjectController *cont = it2->second;
2218 if(cont->getGObjectType()==GCONNECTOR)
2220 GConnectorModel* cmod = (GConnectorModel*)cont->getModel();
2221 GBoxModel* endPortParentBox = cmod->getEndPort()->getParentBox();
2222 GBoxModel* startPortParentBox = cmod->getStartPort()->getParentBox();
2224 std::map<int, GObjectController*>::iterator iterOBJ1 = mapSelected.find(startPortParentBox->getObjectId());
2225 std::map<int, GObjectController*>::iterator iterOBJ2 = mapSelected.find(endPortParentBox->getObjectId());
2227 if(iterOBJ1 != mapSelected.end() && iterOBJ2 != mapSelected.end())
2229 int ID = cont->getId();
2230 mapSelected[ID]=cont;
2237 //=========================================================================
2239 void wxVtkSceneManager::addObjects(std::map<int,GObjectController*> objectsMap)
2242 std::map<int,int> oldIdNewIdBoxes;
2243 std::vector<int> connections;
2245 std::map<int, GObjectController*>::iterator it;
2246 for(it = objectsMap.begin(); it != objectsMap.end(); ++it)
2248 GObjectController *cont = it->second;
2249 int type = cont->getGObjectType();
2254 double xInic, yInic,zInic;
2255 GBlackBoxModel* copyBox = (GBlackBoxModel*)cont->getModel();
2256 copyBox->getInicPoint(xInic,yInic,zInic);
2257 int idBox = createGBlackBox(0,0,copyBox->getBBTKPackage(),copyBox->getBBTKType());
2259 int idcB = copyBox->getObjectId();
2260 oldIdNewIdBoxes[idcB]=idBox;
2261 cont = _controllers[idBox];
2262 GBlackBoxModel* newbox = (GBlackBoxModel*)cont->getModel();
2263 newbox->setInicPoint(xInic,yInic,zInic);
2264 int num = newbox->getNumInputPorts();
2265 for(int j=0;j<num;j++)
2267 newbox->setValueToInputPort(j,copyBox->getValueInputPort(j));
2269 newbox->notifyObservers(_idManager);
2271 else if(type==GCONNECTOR)
2273 int idCon = cont->getId();
2274 connections.push_back(idCon);
2279 for(int i = 0 ;i<(int)connections.size();i++)
2281 int objId = connections[i];
2282 GObjectController *cont = objectsMap[objId];
2283 GConnectorModel* connectModel = (GConnectorModel*)cont->getModel();
2285 GPortModel* startPort = connectModel->getStartPort();
2286 int startPortIndex = startPort->getPosInBox();
2287 GPortModel* endPort = connectModel->getEndPort();
2288 int endPortIndex = endPort->getPosInBox();
2290 GBlackBoxModel* startPortParentBox = (GBlackBoxModel*)startPort->getParentBox();
2291 GBlackBoxModel* endPortParentBox = (GBlackBoxModel*)endPort->getParentBox();
2293 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2294 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2296 GBlackBoxModel* newStartBox = (GBlackBoxModel*)_controllers[idNewStartBox]->getModel();
2297 GBlackBoxModel* newEndBox = (GBlackBoxModel*)_controllers[idNewEndBox]->getModel();
2299 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2300 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2302 // Creates connection
2303 int idCon = createGConnector(newStartPort);
2304 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
2305 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
2306 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
2307 tempp->endContourCreation();
2308 conMod->setEndPort(newEndPort);
2309 conView->updateStartEndPoints();
2312 std::map<int, int>::iterator itIds;
2313 for(itIds = oldIdNewIdBoxes.begin(); itIds != oldIdNewIdBoxes.end(); ++itIds)
2315 int idOld = itIds->first;
2316 int idNew = itIds->second;
2318 GBlackBoxModel* oldBox = (GBlackBoxModel*)objectsMap[idOld]->getModel();
2319 GBlackBoxModel* newBox = (GBlackBoxModel*)_controllers[idNew]->getModel();
2321 std::vector<int> oldInputConnections = oldBox->getConnectedInputs();
2322 std::vector<int> oldOutputConnections = oldBox->getConnectedOutputs();
2323 std::vector<int> newInputConnections = newBox->getConnectedInputs();
2324 std::vector<int> newOutputConnections = newBox->getConnectedOutputs();
2326 for(int k = 0; k<(int)oldInputConnections.size();k++)
2329 //EED int toCreate=-1;
2330 for(int l = 0; l<(int)newInputConnections.size() && !exist;l++)
2332 if(oldInputConnections[k]==newInputConnections[l])
2340 //Create complex input
2341 int posInBox = oldInputConnections[k];
2342 GPortModel* inputPort = oldBox->getInputPort(posInBox);
2343 std::string inputPortName = inputPort->getBBTKName();
2344 int idInputPort = createGComplexBoxInputPort(inputPortName);
2345 GObjectController *cont = _controllers[idInputPort];
2346 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
2348 inputPort->getInicPoint(xIn,yIn,zIn);
2350 cbmod->setInicPoint(xIn,yIn,zIn);
2351 cbmod->notifyObservers(_idManager);
2353 GPortModel* inputPortEnd = newBox->getInputPort(posInBox);
2355 // Creates connection
2356 int idCon = createGConnector(cbmod->getOutputPort(0));
2357 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
2358 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
2359 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
2360 tempp->endContourCreation();
2361 conMod->setEndPort(inputPortEnd);
2362 conView->updateStartEndPoints();
2369 for(int k = 0; k<(int)oldOutputConnections.size();k++)
2372 //EED int toCreate=-1;
2373 for(int l = 0; l<(int)newOutputConnections.size() && !exist;l++)
2375 if(oldOutputConnections[k]==newOutputConnections[l])
2383 //Create complex output
2384 int posInBox = oldOutputConnections[k];
2385 GPortModel* outputPort = oldBox->getOutputPort(posInBox);
2386 std::string outputPortName = outputPort->getBBTKName();
2387 int idOutputPort = createGComplexBoxOutputPort(outputPortName);
2388 GObjectController *cont = _controllers[idOutputPort];
2389 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
2391 outputPort->getInicPoint(xIn,yIn,zIn);
2393 cbmod->setInicPoint(xIn,yIn,zIn);
2394 cbmod->notifyObservers(_idManager);
2396 GPortModel* outputPortEnd = newBox->getOutputPort(posInBox);
2398 // Creates connection
2399 int idCon = createGConnector(outputPortEnd);
2400 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
2401 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
2402 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
2403 tempp->endContourCreation();
2404 conMod->setEndPort(cbmod->getInputPort(0));
2405 conView->updateStartEndPoints();
2416 //=========================================================================
2418 } // EO namespace bbtk