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 );
62 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget((wxDropTarget*)parent);
66 _worldState=NOTHING_HAPPENS;
67 registerController(this);
70 _idConnectionInCreation = -1;
75 //=========================================================================
77 void wxVtkSceneManager::disconnectDrop()
79 printf ("EED %p ~wxVtkSceneManager::disconnectDrop()\n" , this );
80 //EED02JUIN2010 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget(NULL);
81 // _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget( new tmpClasswxTextDropTarget() );
84 //=========================================================================
86 wxVtkSceneManager::~wxVtkSceneManager()
88 printf ("EED %p ~wxVtkSceneManager()\n" , this );
92 //=========================================================================
94 void wxVtkSceneManager::configureBaseView()
96 vtkInteractorStyleBaseView2D *interactorstylebaseview = vtkInteractorStyleBaseView2D::New();
98 _baseView->SetInteractorStyleBaseView(interactorstylebaseview);
100 // Important to activate the 2D interaction system
101 wxVTKRenderWindowInteractor *iren = _baseView->GetWxVTKRenderWindowInteractor();
102 interactorstylebaseview->SetInteractor ( iren );
103 iren->SetInteractorStyle(interactorstylebaseview);
104 interactorstylebaseview->SetwxVtkBaseView(_baseView);
106 _baseView->GetRenderer()->GetActiveCamera()->ParallelProjectionOn();
107 _baseView->GetRenderer()->ResetCamera(-100,100,-100,100,800,1100);
109 _baseView->GetRenderer()->SetBackground(0.9,0.9,0.9);
110 _baseView->GetRenderer()->GradientBackgroundOn();
111 _baseView->Refresh();
114 _textActor = vtkTextActor3D::New();
115 _textActor->SetPosition( -9999 , -9999 , 900 );
116 _textActor->SetInput( "<void>" );
117 _textActor->GetTextProperty()->SetFontSize(60);
118 _textActor->GetTextProperty()->BoldOn();
119 _textActor->GetTextProperty()->SetColor(PORTTEXT_NH_R,PORTTEXT_NH_G,PORTTEXT_NH_B);
121 _baseView->GetRenderer()->AddActor( _textActor );
124 // Actor Fill_Port_Text
131 vtkPolygon *aPolygon = vtkPolygon::New();
132 _fillObjectActor = vtkActor::New();
134 _pts = vtkPoints::New();
136 double w=100,h=10,b=h/15,t=3;
137 _pts->SetNumberOfPoints(21);
138 _pts->InsertPoint(0, xInic+w*0.33-t/2 , yInic , zInic );
139 _pts->InsertPoint(1, xInic+w*0.33 , yInic-t , zInic );
140 _pts->InsertPoint(2, xInic+w*0.33+t/2 , yInic , zInic );
141 _pts->InsertPoint(3, xInic+w*0.33+t/2 , yInic , zInic );
142 _pts->InsertPoint(4, xInic+w-b*4 , yInic+b*0 , zInic );
144 _pts->InsertPoint( 5, xInic+w-b*4 , yInic+b*0 , zInic );
145 _pts->InsertPoint( 6, xInic+w-b*2 , yInic+b*1 , zInic );
146 _pts->InsertPoint( 7, xInic+w-b*1 , yInic+b*2 , zInic );
147 _pts->InsertPoint( 8, xInic+w-b*0 , yInic+b*4 , zInic );
149 _pts->InsertPoint( 9, xInic+w-b*0 , yInic+h-b*4 , zInic );
150 _pts->InsertPoint(10, xInic+w-b*1 , yInic+h-b*2 , zInic );
151 _pts->InsertPoint(11, xInic+w-b*2 , yInic+h-b*1 , zInic );
152 _pts->InsertPoint(12, xInic+w-b*4 , yInic+h-b*0 , zInic );
154 _pts->InsertPoint(13, xInic+b*4 , yInic+h-b*0 , zInic );
155 _pts->InsertPoint(14, xInic+b*2 , yInic+h-b*1 , zInic );
156 _pts->InsertPoint(15, xInic+b*1 , yInic+h-b*2 , zInic );
157 _pts->InsertPoint(16, xInic+b*0 , yInic+h-b*4 , zInic );
159 _pts->InsertPoint(17, xInic+b*0 , yInic+b*4 , zInic );
160 _pts->InsertPoint(18, xInic+b*1 , yInic+b*2 , zInic );
161 _pts->InsertPoint(19, xInic+b*2 , yInic+b*1 , zInic );
162 _pts->InsertPoint(20, xInic+b*4 , yInic+b*0 , zInic );
164 aPolygon->GetPointIds()->SetNumberOfIds(21);
165 for (int i=0;i<21; i++)
167 aPolygon->GetPointIds()->SetId(i, i);
170 vtkUnstructuredGrid *aPolygonGrid = vtkUnstructuredGrid::New();
171 aPolygonGrid->Allocate(1, 1);
172 aPolygonGrid->InsertNextCell(aPolygon->GetCellType(), aPolygon->GetPointIds());
173 aPolygonGrid->SetPoints(_pts);
174 _aPolygonMapper = vtkDataSetMapper::New();
175 _aPolygonMapper->SetInput(aPolygonGrid);
176 _fillObjectActor->SetMapper(_aPolygonMapper);
177 _fillObjectActor->GetProperty()->SetColor(PORTFILL_NH_R,PORTFILL_NH_G,PORTFILL_NH_B);
178 _fillObjectActor->GetProperty()->SetOpacity(0);
179 _aPolygonMapper->Modified();
181 _baseView->GetRenderer()->AddActor( _fillObjectActor );
184 //=========================================================================
186 std::string wxVtkSceneManager::generateANewNameForABox()
188 std::stringstream boxname;
191 boxname << "Box0" << _numBoxes;
193 boxname << "Box" << _numBoxes;
196 return boxname.str();
199 //=========================================================================
201 std::string wxVtkSceneManager::findANewNameForABox()
203 std::string boxname=generateANewNameForABox();
205 while (boxExist(boxname)==true)
207 boxname=generateANewNameForABox();
213 //=========================================================================
214 void wxVtkSceneManager::configGBlackBox(int idBox, double xIn, double yIn, double zIn, std::string name, bool boxExecutable,double xEn,double yEn,double zEn)
216 GObjectController *cont = _controllers[idBox];
217 GBlackBoxModel *bbmod = (GBlackBoxModel*)cont->getModel();
218 bbmod->setBBTKName(name);
219 bbmod->setInicPoint(xIn,yIn,zIn);
220 bbmod->setFinalPoint(xEn,yEn,zEn);
221 bbmod->setExecutable(boxExecutable);
223 bbmod->notifyObservers(_idManager);
228 //=========================================================================
230 int wxVtkSceneManager::createGBlackBox(int x, int y, std::string packageName, std::string boxType)
232 _worldState = NOTHING_HAPPENS;
233 //EED int windowWidth = _baseView->GetRenWin()->GetSize()[0];
234 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
236 int type = GBLACKBOX;
238 //Create the MVC Objects
240 GBlackBoxModel *model = (GBlackBoxModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
241 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
242 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
244 BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxType);
246 //Prepares the initial model
247 //The coordinates obtained are the following. Top-Left:x=0,y=0 Bottom-Right:x=width,y=height
250 double yy = windowHeight-y;
252 //z value is not important yet, because it is only used a parallel projection
254 _baseView->TransCoordScreenToWorld(xx,yy,zz);
255 model->setInicPoint(xx,yy,zz);
257 std::stringstream stream;
259 std::string newBoxName;
260 newBoxName = findANewNameForABox();
263 stream << newBoxName;
265 std::string arraystring = stream.str();
267 model->setBBTKName(arraystring);
268 model->setBBTKType(boxType);
269 model->setBBTKPackage(packageName);
271 model->addObserver(view);
272 model->addObserver(this);
274 //Iterate and create the input ports
275 std::map<std::string, BlackBoxInputDescriptor*> descriptorInMap = descriptor->GetInputDescriptorMap();
276 std::map<std::string, BlackBoxInputDescriptor*>::iterator itInput;
279 for(itInput = descriptorInMap.begin(); itInput != descriptorInMap.end(); ++itInput)
281 BlackBoxInputDescriptor *desc = itInput->second;
282 createGInputPort(GINPUTPORT,i,model,desc);
286 //Iterate and create the output ports
287 std::map<std::string, BlackBoxOutputDescriptor*> descriptorOutMap = descriptor->GetOutputDescriptorMap();
288 std::map<std::string, BlackBoxOutputDescriptor*>::iterator itOutput;
291 for(itOutput = descriptorOutMap.begin();itOutput != descriptorOutMap.end(); ++itOutput)
293 BlackBoxOutputDescriptor *desc = itOutput->second;
294 createGOutputPort(GOUTPUTPORT,i,model,desc);
299 //Associates the view with the correspondent renderer and the model.
300 //(NOTE: Refresh is only made by the view)
301 view->setModel(model);
302 view->setBaseView(_baseView);
303 view->initVtkObjects();
305 //Associates the controller with the correspondent model and view
306 controller->setModelAndView(model,view);
308 //Resgiter change to the observers of the actual model
309 model->notifyObservers(_idManager);
311 int newId = addObjectController(controller);
317 //=========================================================================
319 int wxVtkSceneManager::createGComplexBoxInputPort(std::string inputName)
321 //EED int windowWidth=_baseView->GetRenWin()->GetSize()[0];
322 int windowHeight=_baseView->GetRenWin()->GetSize()[1];
324 int type = GCOMPLEXINPUTPORT;
326 //Create the MVC Objects
328 GComplexBoxPortModel *model = (GComplexBoxPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
329 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
330 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
332 //Prepares the initial model
335 double yy = windowHeight-5;
337 //z value is not important yet, because it is only used a parallel projection
339 printf("EED wxVtkSceneManager::createGComplexBoxInputPort 900-450\n");
341 _baseView->TransCoordScreenToWorld(xx,yy,zz);
342 model->setInicPoint(xx,yy,zz);
344 model->setBBTKName(inputName);
345 model->setBBTKType("ComplexInputPort");
346 model->setComplexPortType(type);
348 model->addObserver(view);
349 model->addObserver(this);
351 //create the output port
352 GPortController* portController = createGPort(GOUTPUTPORT,inputName,"ComplexInputPort",0,model);
353 model->addOutputPort((GPortModel*)portController->getModel());
355 //Associates the view with the correspondent renderer and the model.
356 //(NOTE: Refresh is only made by the view)
357 view->setModel(model);
358 view->setBaseView(_baseView);
359 view->initVtkObjects();
361 //Associates the controller with the correspondent model and view
362 controller->setModelAndView(model,view);
364 //Resgiter change to the observers of the actual model
365 model->notifyObservers(_idManager);
367 int newId = addObjectController(controller);
371 //=========================================================================
373 int wxVtkSceneManager::createGComplexBoxOutputPort(std::string outputName)
375 //EED int windowWidth=_baseView->GetRenWin()->GetSize()[0];
376 int windowHeight=_baseView->GetRenWin()->GetSize()[1];
378 int type = GCOMPLEXOUTPUTPORT;
380 //Create the MVC Objects
382 GComplexBoxPortModel *model = (GComplexBoxPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
383 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
384 GObjectController *controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
386 //Prepares the initial model
389 double yy = windowHeight-5;
391 //z value is not important yet, because it is only used a parallel projection
394 printf("EED wxVtkSceneManager::createGComplexBoxOutputPort 900-450\n");
396 _baseView->TransCoordScreenToWorld(xx,yy,zz);
397 model->setInicPoint(xx,yy,zz);
399 model->setBBTKName(outputName);
400 model->setBBTKType("ComplexOutputPort");
401 model->setComplexPortType(type);
403 model->addObserver(view);
404 model->addObserver(this);
406 //create the output port
407 GPortController* portController = createGPort(GINPUTPORT,outputName,"ComplexInputPort",0,model);
408 model->addInputPort((GPortModel*)portController->getModel());
410 //Associates the view with the correspondent renderer and the model.
411 //(NOTE: Refresh is only made by the view)
412 view->setModel(model);
413 view->setBaseView(_baseView);
414 view->initVtkObjects();
416 //Associates the controller with the correspondent model and view
417 controller->setModelAndView(model,view);
419 //Resgiter change to the observers of the actual model
420 model->notifyObservers(_idManager);
422 int newId = addObjectController(controller);
426 //=========================================================================
428 int wxVtkSceneManager::createGInputPort(int portType, int posinBox,GBoxModel *blackBox, BlackBoxInputDescriptor *desc)
430 GPortController* portController = createGPort(portType,desc->GetName(),desc->GetTypeName(),posinBox,blackBox);
431 blackBox->addInputPort((GPortModel*)portController->getModel());
432 return portController->getId();
435 //=========================================================================
437 int wxVtkSceneManager::createGOutputPort(int portType, int posinBox,GBoxModel *blackBox, BlackBoxOutputDescriptor *desc)
439 GPortController* portController = createGPort(portType,desc->GetName(),desc->GetTypeName(),posinBox,blackBox);
440 blackBox->addOutputPort((GPortModel*)portController->getModel());
441 return portController->getId();
444 //=========================================================================
446 GPortController* wxVtkSceneManager::createGPort(int portType,std::string bbtkName, std::string bbtkType, int posInBox,GBoxModel *blackBox)
450 //Create the MVC Objects
451 GPortModel *model = (GPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
452 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
453 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
455 model->registerInBox(blackBox,portType, posInBox);
457 model->setBBTKType(bbtkType);
458 model->setBBTKName(bbtkName);
460 model->addObserver(view);
461 model->addObserver(this);
463 //Associates the view with the correspondent renderer and the model.
464 //(NOTE: Refresh is only made by the view)
465 view->setModel(model);
466 view->setBaseView(_baseView);
467 view->initVtkObjects();
469 //Associates the controller with the correspondent model and view
470 controller->setModelAndView(model,view);
472 model->notifyObservers(_idManager);
474 addObjectController(controller);
476 return (GPortController*)controller;
479 //=========================================================================
481 int wxVtkSceneManager::createGConnector(GPortModel* startPort)
483 int type = GCONNECTOR;
485 manualConnectorContourController* manContourControl = new manualConnectorContourController();
486 manualConnectorContourView* manContourView = new manualConnectorContourView();
487 manualContourModel* manContourModel = new manualContourModel();
489 GConnectorController* connectorcontroller = new GConnectorController();
490 GConnectorModel* connectorModel = new GConnectorModel();
491 vtkGConnectorView* connectorView = new vtkGConnectorView();
492 connectorModel->setGObjectType(type);
494 manContourModel->SetCloseContour(false);
495 connectorModel->setStartPort(startPort);
497 manContourView->SetModel( manContourModel );
498 manContourView->SetWxVtkBaseView( _baseView );
499 manContourView->SetRange( 0.5 );
500 manContourView->SetZ( 900 );
502 manContourView->SetColorNormalContour(0, 0, 1);
503 manContourView->SetColorEditContour(0.5, 0.5, 0.5);
504 manContourView->SetColorSelectContour(1, 0.8, 0);
505 manContourView->SetWidthLine(1);
506 manContourView->SetShowText(false);
508 manContourControl->SetModelView( manContourModel , manContourView );
510 manContourControl->CreateNewManualContour();
512 manContourView->RefreshContour();
516 connectorModel->getInicPoint(x,y,z);
518 manContourControl->SetState(1);
519 manContourModel->SetCloseContour(false);
521 manContourModel->AddPoint(x,y,z);
522 manContourView->AddPoint();
524 manContourModel->AddPoint(x,y,z);
525 manContourView->AddPoint();
527 int bak= manContourControl->GetNumberOfPointsManualContour() - 1;
528 manContourControl->_bakIdPoint=bak;
529 manContourView->Refresh();
531 manContourControl->SetMoving( false );
533 connectorcontroller->setModelAndView(connectorModel,connectorView);
535 int newId = addObjectController(connectorcontroller);
537 connectorcontroller->setManualContourController(manContourControl);
538 connectorModel->setManualContourModel(manContourModel);
539 connectorView->setManualContourView(manContourView);
540 connectorView->setModel(connectorModel);
541 connectorView->setBaseView(_baseView);
544 connectorModel->addObserver(connectorView);
545 connectorModel->addObserver(this);
550 //=========================================================================
552 void wxVtkSceneManager::registerController(InteractorStyleMaracas *param)
554 vtkInteractorStyleBaseView* baseViewControlManager = (vtkInteractorStyleBaseView*)_baseView->GetInteractorStyleBaseView();
555 baseViewControlManager->AddInteractorStyleMaracas( param );
558 //=========================================================================
560 void wxVtkSceneManager::unregisterController(InteractorStyleMaracas *param)
562 vtkInteractorStyleBaseView* baseViewControlManager = (vtkInteractorStyleBaseView*)_baseView->GetInteractorStyleBaseView();
563 baseViewControlManager->RemoveInteractorStyleMaracas( param );
566 //=========================================================================
568 vtkRenderer* wxVtkSceneManager::getRenderer()
570 return _baseView->GetRenderer();
573 //=========================================================================
575 vtkRenderWindow* wxVtkSceneManager::getRenderWindow()
577 return _baseView->GetRenWin();
579 //=========================================================================
582 //=========================================================================
583 int wxVtkSceneManager::GetIndexInSelected(int idControler)
586 for (int i=0; i<(int)_selectedObjects.size(); i++)
588 if(_selectedObjects[i]==idControler)
596 //=========================================================================
598 void wxVtkSceneManager::update(int idController,int command)
601 if(command != NO_COMMAND)
603 if(command == ADD_TO_SELECTED)
605 //EEDBorrame GObjectController* cont = _controllers[idController];
607 if (GetIndexInSelected(idController)==-1)
609 _selectedObjects.push_back(idController);
613 // bool foundID=false;
614 // for (int i=0; i<(int)_selectedObjects.size() && foundID==false; i++)
616 // if(_selectedObjects[i]==idController)
623 // _selectedObjects.push_back(idController);
626 }else if(command == REMOVE_FROM_SELECTED)
628 int index=GetIndexInSelected(idController);
631 _selectedObjects.erase( _selectedObjects.begin()+index );
634 else if(command == INIT_CREATION_CONTOUR)
636 _worldState = INIT_CREATION_CONTOUR;
637 GObjectController* cont = _controllers[idController];
638 GPortModel* startOutputPort = (GPortModel*)cont->getModel();
641 // The last one is the controller of the connector
642 std::map<int, GObjectController*>::iterator it2;
644 for(it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
646 GObjectController *cont = it2->second;
647 if(cont->getGObjectType() == GPORT )
649 GPortModel* port = (GPortModel*)cont->getModel();
650 if(port->getPortType()==GINPUTPORT)
652 cont->SetActive(true);
656 cont->getView()->setState(NOTHING_HAPPENS);
657 cont->getModel()->notifyObservers(_idManager);
658 cont->SetActive(false);
663 cont->getView()->setState(NOTHING_HAPPENS);
664 cont->getModel()->notifyObservers(_idManager);
665 cont->SetActive(false);
668 _selectedObjects.clear();
669 _idConnectionInCreation=createGConnector(startOutputPort);
671 else if(command == FIN_CREATION_CONTOUR && _worldState == INIT_CREATION_CONTOUR)
673 _worldState = NOTHING_HAPPENS;
674 //int id = _controllers.size()-1;
675 GObjectController *cont = _controllers[_idConnectionInCreation];
676 GConnectorModel *modelContour = (GConnectorModel*)cont->getModel();
677 GObjectController *finPort = _controllers[idController];
679 if(finPort->getGObjectType() == GPORT)
681 GPortModel* modelPort = (GPortModel*)finPort->getModel();
682 modelContour->setEndPort(modelPort);
685 manualConnectorContourController* manCont = ((GConnectorController*)cont)->getManualContourController();
686 manualConnectorContourView* connView = (manualConnectorContourView*)manCont->GetManualViewBaseContour();
689 std::map<int, GObjectController*>::iterator it2;
691 for(it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
693 GObjectController *cont = it2->second;
694 if(cont->getView()!=NULL)
696 cont->getView()->setState(NOTHING_HAPPENS);
697 cont->getModel()->notifyObservers(_idManager);
699 cont->SetActive(true);
707 //=========================================================================
709 bool wxVtkSceneManager::OnMouseMove()
712 bool okStatusMessage = false;
713 bool okPortMessage = false;
714 wxVTKRenderWindowInteractor *wxVTKiren;
715 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
716 wxVTKiren->GetEventPosition(X,Y);
719 if(_worldState == DRAG_OBJECTS)
721 for (int i=0; i<(int)_selectedObjects.size(); i++)
723 int id = _selectedObjects[i];
724 GObjectController* cont = _controllers[id];
727 cont->getView()->setStartDragging(true);
729 cont->getView()->moveObject(X,Y);
730 cont->getView()->setState(DRAG);
731 cont->getModel()->notifyObservers(_idManager);
734 std::map<int, GObjectController*>::iterator it;
737 for(it = _controllers.begin(); it != _controllers.end(); ++it)
739 GObjectController *desc = it->second;
740 if(desc->getGObjectType()==GCONNECTOR)
742 vtkGConnectorView* vconn = (vtkGConnectorView*)desc->getView();
743 vconn->updateStartEndPoints();
747 _startDragging=false;
750 else if(_worldState == NOTHING_HAPPENS || _worldState == INIT_CREATION_CONTOUR)
752 std::map<int, GObjectController*>::iterator it;
754 for(it = _controllers.begin(); it != _controllers.end(); ++it)
756 GObjectController *desc = it->second;
757 int type = desc->getGObjectType();
758 int state = desc->getView()->getState();
759 desc->getModel()->getCenter(px,py,pz);
761 if(state == HIGHLIGHTED){
762 okStatusMessage = true;
763 updateStatusBar(desc->getStatusText());
766 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
767 _parent->displayBlackBoxInfo(mod->getBBTKPackage(),mod->getBBTKType());
772 okPortMessage = true;
774 _textActor->SetInput( desc->getStatusText().c_str() );
775 _textActor->SetScale(0.1);
776 _textActor->SetPosition( px-25 ,py+1 , pz+2 );
781 _fillObjectActor->SetScale(1);
782 _fillObjectActor->GetProperty()->SetOpacity(0.50);
783 _fillObjectActor->SetPosition(px,py,1);
784 _aPolygonMapper->Modified();
787 } // for controllers it
790 if (okStatusMessage==false)
795 if (okPortMessage==false)
797 _textActor->SetScale(0.0001);
798 _fillObjectActor->SetScale(0.0001);
803 //=========================================================================
805 bool wxVtkSceneManager::OnLeftButtonDown()
808 if(_worldState==INIT_CREATION_CONTOUR)
810 bool isOverPort=false;
811 std::map<int, GObjectController*>::iterator it;
812 for(it = _controllers.begin(); it != _controllers.end() && isOverPort==false; ++it)
814 GObjectController *desc = it->second;
815 if(desc->getGObjectType()==GPORT)
817 GPortModel *portmod = (GPortModel*)desc->getModel();
818 vtkGObjectView *portView = desc->getView();
819 if(portmod->getPortType()==GINPUTPORT && portView->getState()==HIGHLIGHTED)
826 if(isOverPort==false)
828 _worldState=NOTHING_HAPPENS;
829 //int lastId = _controllers.size()-1;
830 //EED2Oct2010 GConnectorController *connector = (GConnectorController*)_controllers[_controllers.size()-1];
831 GConnectorController *connector = (GConnectorController*)_controllers[_idConnectionInCreation];
833 connector->removeFromScene();
834 unregisterController(connector);
835 _controllers.erase(_controllers.size()-1);
837 for(it = _controllers.begin(); it != _controllers.end(); ++it)
839 GObjectController *desc = it->second;
840 desc->SetActive(true);
841 desc->getView()->setState(NOTHING_HAPPENS);
842 desc->getModel()->notifyObservers(_idManager);
846 } else { //_worldState
848 _worldState = DRAG_OBJECTS;
849 _startDragging = true;
851 int shiftkey = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey();
852 int ctrlkey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
853 ctrlkey = ctrlkey + shiftkey;
855 GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
858 if (GetGBlackBoxControlerPointedByMouse()!=NULL)
860 int state=cont->getView()->getState() ;
861 if( (ctrlkey==0) && (state==HIGHLIGHTED) )
863 UnSelectBlackBoxes();
866 for (int i = 0; i < (int)_selectedObjects.size(); i++)
868 int id = _selectedObjects[i];
869 GObjectController* cont = _controllers[id];
870 cont->getView()->setState(DRAG);
871 cont->getModel()->notifyObservers(_idManager);
874 } // if _selectedObjects.size
880 //=========================================================================
882 bool wxVtkSceneManager::OnLeftButtonUp()
884 if(_worldState == DRAG_OBJECTS)
886 _worldState = NOTHING_HAPPENS;
888 for (int i = 0; i < (int)_selectedObjects.size(); i++)
890 int id = _selectedObjects[i];
891 GObjectController* cont = _controllers[id];
892 cont->getView()->setState(SELECTED);
893 cont->getModel()->notifyObservers(_idManager);
899 //=========================================================================
901 bool wxVtkSceneManager::OnRightButtonUp()
903 if(_worldState==INIT_CREATION_CONTOUR)
905 _worldState=NOTHING_HAPPENS;
906 //int lastId = _controllers.size()-1;
908 GConnectorController *connector = (GConnectorController*)_controllers[_idConnectionInCreation];
909 connector->removeFromScene();
910 unregisterController(connector);
911 _controllers.erase(_idConnectionInCreation);
913 std::map<int, GObjectController*>::iterator it;
914 for(it = _controllers.begin(); it != _controllers.end(); ++it)
916 GObjectController *desc = it->second;
917 desc->SetActive(true);
918 desc->getView()->setState(NOTHING_HAPPENS);
919 desc->getModel()->notifyObservers(_idManager);
924 for (int i = 0; i < (int)_selectedObjects.size(); i++)
926 int id = _selectedObjects[i];
927 GObjectController* cont = _controllers[id];
928 cont->SetActive(true);
929 cont->getView()->setState(NOTHING_HAPPENS);
930 cont->getModel()->notifyObservers(_idManager);
933 _selectedObjects.clear();
938 //=========================================================================
940 GObjectController *wxVtkSceneManager::GetGBlackBoxControlerPointedByMouse()
942 GObjectController *result=NULL;
944 wxVTKRenderWindowInteractor *wxVTKiren;
945 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
946 wxVTKiren->GetEventPosition(X,Y);
948 std::map<int, GObjectController*>::iterator it;
950 for(it = _controllers.begin(); it != _controllers.end() ; ++it)
952 GObjectController *cont = it->second;
953 int type = cont->getGObjectType();
955 if( cont->getView()->isPointInside(X,Y)==true )
961 } // if isPointInside
966 //=========================================================================
967 void wxVtkSceneManager::UnSelectBlackBoxes()
969 for (int i=0; i< (int)_selectedObjects.size(); i++)
971 int id = _selectedObjects[i];
972 GObjectController* control = _controllers[id];
973 control->getView()->setState(NOTHING_HAPPENS);
974 }// for _selectedObjects
975 _selectedObjects.clear();
978 //=========================================================================
979 bool wxVtkSceneManager::OnLeftDClick()
981 GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
984 UnSelectBlackBoxes();
985 _parent->editBlackBox( (GBlackBoxModel*)cont->getModel() );
991 wxVTKRenderWindowInteractor *wxVTKiren;
992 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
993 wxVTKiren->GetEventPosition(X,Y);
995 std::map<int, GObjectController*>::iterator it;
997 bool clickOnObject = false;
999 for(it = _controllers.begin(); it != _controllers.end() && clickOnObject==false; ++it)
1001 GObjectController *cont = it->second;
1002 int type = cont->getGObjectType();
1004 if(cont->getView()->isPointInside(X,Y))
1008 for (int i=0; i< (int)_selectedObjects.size(); i++)
1010 int id = _selectedObjects[i];
1011 GObjectController* control = _controllers[id];
1012 control->getView()->setState(NOTHING_HAPPENS);
1014 _selectedObjects.clear();
1016 GBlackBoxModel *bbmodel = (GBlackBoxModel*)cont->getModel();
1017 _parent->editBlackBox(bbmodel);
1019 clickOnObject = true;
1023 if(clickOnObject==false)
1025 //_parent->editDiagramParameters(this);
1031 //=========================================================================
1033 bool wxVtkSceneManager::OnChar()
1035 char keyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
1037 // KeyCode 127 : Delete Key
1038 // KeyCode 8 : Backspace Key
1039 if(keyCode == 8 || keyCode == 127)
1041 if(_selectedObjects.size()>0)
1043 for(int i=0;i<(int)_selectedObjects.size();i++)
1045 int id = _selectedObjects[i];
1046 std::map<int,GObjectController*>::iterator it;
1047 it = _controllers.find(id);
1048 if (it!=_controllers.end())
1053 _selectedObjects.clear();
1060 //=========================================================================
1062 void wxVtkSceneManager::AddControlerToBeRemove(std::vector<int> *controllersToRemove, int id)
1067 for(i=0 ; i < (int)controllersToRemove->size() ; i++ )
1069 if (id == (*controllersToRemove)[i] )
1077 controllersToRemove->push_back( id );
1082 //=========================================================================
1084 void wxVtkSceneManager::deleteObject(int id)
1086 GObjectController *control = _controllers[id];
1087 std::vector<int> controllersToRemove;
1089 if(control->getGObjectType()==GBLACKBOX || control->getGObjectType()==GCOMPLEXINPUTPORT || control->getGObjectType()==GCOMPLEXOUTPUTPORT)
1091 GBoxModel *bbmod = (GBoxModel*)control->getModel();
1092 std::vector<GPortModel*> inputs = bbmod->getInputPorts();
1094 bool boxConnected = false;
1096 // Add box input controllers to be removed
1097 for(int i = 0;i< (int)inputs.size();i++)
1099 AddControlerToBeRemove( &controllersToRemove, inputs[i]->getObjectId() );
1100 if(inputs[i]->isConnected())
1102 boxConnected = true;
1106 std::vector<GPortModel*> outputs = bbmod->getOutputPorts();
1108 // Add box output controllers to be removed
1109 for(int i = 0;i<(int)outputs.size();i++)
1111 AddControlerToBeRemove( &controllersToRemove, outputs[i]->getObjectId() );
1112 if(outputs[i]->isConnected())
1114 boxConnected = true;
1118 // Add connection controllers to be removed
1119 std::map<int, GObjectController*>::iterator it;
1120 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1122 GObjectController *cont = it->second;
1123 int type = cont->getGObjectType();
1124 if(type==GCONNECTOR)
1126 GConnectorModel *conMod = (GConnectorModel*)cont->getModel();
1127 if(conMod->getStartPort()!=NULL && conMod->getStartPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
1129 AddControlerToBeRemove( &controllersToRemove, conMod->getObjectId() );
1131 if(conMod->getEndPort()!=NULL && conMod->getEndPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
1133 AddControlerToBeRemove( &controllersToRemove, conMod->getObjectId() );
1138 // Add box controller to be removed
1139 AddControlerToBeRemove( &controllersToRemove, bbmod->getObjectId() );
1141 else if(control->getGObjectType()==GCONNECTOR)
1143 GConnectorModel *conMod = (GConnectorModel*)control->getModel();
1144 AddControlerToBeRemove( &controllersToRemove, conMod->getObjectId() );
1148 std::map<int,GObjectController*>::iterator it;
1150 for(int i = 0;i<(int)controllersToRemove.size();i++)
1152 int key = controllersToRemove[i];
1153 it = _controllers.find( key );
1154 GObjectController *cont = _controllers[ key ];
1157 cont->removeFromScene();
1158 unregisterController((InteractorStyleMaracas*)cont);
1159 _controllers.erase(it);
1164 //=========================================================================
1166 void wxVtkSceneManager::displayBlackBoxInfo(std::string packageName, std::string boxName)
1168 _parent->displayBlackBoxInfo(packageName,boxName);
1171 //=========================================================================
1173 void wxVtkSceneManager::updateStatusBar(std::string textStatus)
1175 _parent->updateStatusBar(textStatus);
1179 //=========================================================================
1180 std::string wxVtkSceneManager::LineNumber(bool withLineNumber, int &value)
1182 std::string result="";
1183 if (withLineNumber==true)
1186 stringstream StrStream;
1188 std::string strValue=StrStream.str();
1192 }else if (value<100)
1197 result+=strValue+": ";
1201 //=========================================================================
1203 std::string wxVtkSceneManager::getDiagramBBS(bool wln)
1205 bool existsExec=false;
1207 std::vector<std::string> packages;
1208 std::vector<int> boxes;
1209 std::vector<int> connections;
1210 std::vector<int> execBoxes;
1212 std::map<int, GObjectController*>::iterator it;
1214 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1216 GObjectController *desc = it->second;
1217 int type = desc->getGObjectType();
1221 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
1223 std::string pkg = mod->getBBTKPackage();
1224 bool existsPkg = false;
1225 for(int t = 0;t< (int)packages.size() && existsPkg == false;t++)
1227 if(packages[t]==pkg)
1234 packages.push_back(pkg);
1238 boxes.push_back(it->first);
1239 if(mod->isExecutable())
1241 execBoxes.push_back(it->first);
1245 else if(type==GCONNECTOR)
1247 connections.push_back(it->first);
1252 std::string script = "";
1253 script+=LineNumber(wln,lnNmbr)+"# BBTK GEditor Script\n";
1254 script+=LineNumber(wln,lnNmbr)+"# ----------------------\n";
1255 script+=LineNumber(wln,lnNmbr)+"\n";
1258 script+=LineNumber(wln,lnNmbr)+"include std\n"; // EED
1259 script+=LineNumber(wln,lnNmbr)+"include itkvtk\n"; // EED
1261 for(i = 0; i< (int)packages.size();i++)
1263 script+=LineNumber(wln,lnNmbr);
1265 script+=packages[i];
1269 script+=LineNumber(wln,lnNmbr);
1272 // script+="include std\n"; // JPR
1274 for(i = 0; i < (int)boxes.size();i++)
1276 script+=LineNumber(wln,lnNmbr);
1279 GObjectController *control = _controllers[id];
1280 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1282 script+=model->getBBTKType();
1284 script+=model->getBBTKName();
1287 std::vector<GPortModel*> inputs = model->getInputPorts();
1288 for(int j = 0; j < (int)inputs.size();j++)
1290 GPortModel* inputPort = inputs[j];
1291 if(inputPort->isValueSet())
1293 script+=LineNumber(wln,lnNmbr);
1295 script+=model->getBBTKName();
1297 script+=inputPort->getBBTKName();
1299 script+=inputPort->getValue();
1304 script+=LineNumber(wln,lnNmbr);
1309 script+=LineNumber(wln,lnNmbr);
1312 for(i = 0; i<(int)connections.size();i++)
1314 script+=LineNumber(wln,lnNmbr);
1316 int id = connections[i];
1317 GObjectController *control = _controllers[id];
1318 GConnectorModel *model = (GConnectorModel*)control->getModel();
1320 //Start Connection info
1321 GPortModel *start = model->getStartPort();
1322 script+=start->getParentBox()->getBBTKName();
1324 script+=start->getBBTKName();
1328 //End Connection info
1329 GPortModel *end = model->getEndPort();
1330 script+=end->getParentBox()->getBBTKName();
1332 script+=end->getBBTKName();
1337 script+=LineNumber(wln,lnNmbr);
1339 for(i = 0; i<(int)execBoxes.size();i++)
1341 script+=LineNumber(wln,lnNmbr);
1343 int id = execBoxes[i];
1344 GObjectController *control = _controllers[id];
1345 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1347 script+=model->getBBTKName();
1356 //=========================================================================
1358 std::string wxVtkSceneManager::saveComplexBoxBBS(std::string cbName,std::string cbAuthor,std::string cbCategory,std::string cbDescription)
1361 std::vector<std::string> packages;
1362 std::vector<int> boxes;
1363 std::vector<int> connections;
1364 std::vector<int> execBoxes;
1366 std::map<int, GObjectController*>::iterator it;
1368 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1370 GObjectController *desc = it->second;
1371 int type = desc->getGObjectType();
1375 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
1377 std::string pkg = mod->getBBTKPackage();
1378 bool existsPkg = false;
1379 for(int t = 0;t<(int)packages.size() && existsPkg == false;t++)
1381 if(packages[t]==pkg)
1388 packages.push_back(pkg);
1392 boxes.push_back(it->first);
1393 if(mod->isExecutable())
1395 execBoxes.push_back(it->first);
1398 else if(type==GCONNECTOR)
1400 connections.push_back(it->first);
1404 std::string script = "";
1406 script+="include std\n"; // EED
1407 script+="include itkvtk\n"; // EED
1409 for(i = 0; i<(int)packages.size();i++)
1412 script+=packages[i];
1417 // Definition of a complex box
1423 script+="author \" ";
1427 script+="description \" ";
1428 script+=cbDescription;
1433 for(i = 0; i<(int)boxes.size();i++)
1437 GObjectController *control = _controllers[id];
1438 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1440 script+=model->getBBTKType();
1442 script+=model->getBBTKName();
1445 std::vector<GPortModel*> inputs = model->getInputPorts();
1446 for(int j = 0; j<(int)inputs.size();j++)
1448 GPortModel* inputPort = inputs[j];
1449 if(inputPort->isValueSet())
1452 script+=model->getBBTKName();
1454 script+=inputPort->getBBTKName();
1456 script+=inputPort->getValue();
1464 // Create connections in the script. If the connection is made with a complex port, it is created the input or output
1466 std::string complexInputs="";
1467 std::string complexOutputs="";
1470 for(i = 0; i<(int)connections.size();i++)
1472 int id = connections[i];
1473 GObjectController *control = _controllers[id];
1474 GConnectorModel *model = (GConnectorModel*)control->getModel();
1477 GPortModel *start = model->getStartPort();
1478 GBoxModel *startBox =start->getParentBox();
1480 GPortModel *end = model->getEndPort();
1481 GBoxModel *endBox =end->getParentBox();
1483 if(startBox->getGObjectType()==GCOMPLEXINPUTPORT)
1485 complexInputs+="input ";
1486 complexInputs+=startBox->getBBTKName();
1489 complexInputs+=endBox->getBBTKName();
1491 complexInputs+=end->getBBTKName();
1494 complexInputs+="\" \"";
1496 complexInputs+="\n";
1498 else if(endBox->getGObjectType()==GCOMPLEXOUTPUTPORT)
1500 complexOutputs+="output ";
1501 complexOutputs+=endBox->getBBTKName();
1503 complexOutputs+=" ";
1504 complexOutputs+=startBox->getBBTKName();
1505 complexOutputs+=".";
1506 complexOutputs+=start->getBBTKName();
1508 complexOutputs+=" ";
1509 complexOutputs+="\" \"";
1511 complexOutputs+="\n";
1516 script+=startBox->getBBTKName();
1518 script+=start->getBBTKName();
1522 //End Connection info
1523 script+=endBox->getBBTKName();
1525 script+=end->getBBTKName();
1533 for(i = 0; i<(int)execBoxes.size();i++)
1536 int id = execBoxes[i];
1537 GObjectController *control = _controllers[id];
1538 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1540 script+=model->getBBTKName();
1545 script+="# Complex input ports\n";
1546 script+=complexInputs;
1549 script+="# Complex output ports\n";
1550 script+=complexOutputs;
1559 //=========================================================================
1561 void wxVtkSceneManager::deleteAllBoxes()
1563 std::map<int, GObjectController*>::iterator it;
1564 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1566 GObjectController *cont = it->second;
1567 cont->removeFromScene();
1568 unregisterController((InteractorStyleMaracas*)cont);
1570 _selectedObjects.clear();
1571 _controllers.clear();
1575 //=========================================================================
1578 void wxVtkSceneManager::refresh()
1580 _baseView->Refresh();
1582 //=========================================================================
1584 void wxVtkSceneManager::refreshScene()
1586 _baseView->RefreshView();
1589 //=========================================================================
1591 void wxVtkSceneManager::centerView()
1594 _baseView->GetRenderer()->GetActiveCamera()->GetFocalPoint(temp);
1595 _baseView->GetRenderer()->GetActiveCamera()->SetFocalPoint(0,0,temp[2]);
1596 _baseView->GetRenderer()->GetActiveCamera()->GetPosition(temp);
1597 _baseView->GetRenderer()->GetActiveCamera()->SetPosition(0,0,temp[2]);
1598 _baseView->RefreshView();
1602 //=========================================================================
1604 void wxVtkSceneManager::saveDiagram(std::string &content)
1608 //Print info IF COMPLEX BOX
1609 content+="COMPLEXBOX:";
1614 //Print info complex input ports
1615 std::vector<int> inputs = getComplexInputPorts();
1616 int insize = inputs.size();
1617 content+="COMPLEXINPUTS:";
1618 sprintf (buffer, "%d", insize);
1622 for(int i = 0;i<insize;i++)
1625 GObjectController *cont = _controllers[id];
1626 cont->getModel()->save(content);
1629 //Print info complex output ports
1630 std::vector<int> outputs = getComplexOutputPorts();
1631 int outsize = outputs.size();
1632 content+="COMPLEXOUTPUTS:";
1633 sprintf (buffer, "%d", outsize);
1637 for(int i = 0;i<outsize;i++)
1639 int id = outputs[i];
1640 GObjectController *cont = _controllers[id];
1641 cont->getModel()->save(content);
1650 std::vector<int> boxes = getBlackBoxes();
1651 int bsize = boxes.size();
1653 sprintf (buffer, "%d", bsize);
1657 for(int i = 0;i<bsize;i++)
1660 GObjectController *cont = _controllers[id];
1661 cont->getModel()->save(content);
1665 std::vector<int> connections = getConnections();
1666 int csize = connections.size();
1667 content+="CONNECTIONS:";
1668 sprintf (buffer, "%d", csize);
1672 for(int i = 0;i<csize;i++)
1674 int id = connections[i];
1675 GObjectController *cont = _controllers[id];
1676 cont->getModel()->save(content);
1681 //=========================================================================
1683 void wxVtkSceneManager::loadDiagram(ifstream &inputStream)
1686 std::string version;
1687 std::string line="";
1688 char delims[] = ":";
1689 char *result = NULL;
1690 getline(inputStream,line);
1693 while ( !inputStream.eof() )
1695 if(line=="" || line[0]=='#')
1697 getline(inputStream,line);
1698 if (line=="# - BBTKGEditor v 1.0 BBG BlackBox Diagram file")
1700 version=line.substr(18,3);
1701 printf("EED wxVtkSceneManager::loadDiagram version=%s\n",version.c_str());
1705 else if(line=="APP_START")
1716 getline(inputStream,line);//COMPLEX_BOX:TRUE|FALSE
1718 strcpy( complex, line.c_str() );
1719 result = strtok( complex, delims );
1720 result = strtok( NULL, delims );
1721 std::string isComplexBox(result);
1723 if(isComplexBox=="TRUE")
1727 //-----------------------
1728 //- COMPLEX INPUT PORTS
1729 //-----------------------
1730 getline(inputStream,line);//COMPLEXINPUTS:num
1732 strcpy( inputs, line.c_str() );
1733 result = strtok( inputs, delims );
1734 result = strtok( NULL, delims );
1737 std::istringstream inps(result);
1740 for(int i = 0;i<numInputs;i++)
1743 getline(inputStream,line);//COMPLEX_PORT
1744 getline(inputStream,line);//name
1745 std::string inputPortName(line);
1748 getline(inputStream,line);//xInic:yInic:zInic
1750 strcpy( coord, line.c_str() );
1751 result = strtok( coord, delims );//xInic
1752 std::string xInic(result);
1753 result = strtok( NULL, delims );//yInic
1754 std::string yInic(result);
1755 result = strtok( NULL, delims );//zInic
1756 std::string zInic(result);
1758 double xIn, yIn, zIn;
1759 std::istringstream xSt(xInic);
1761 std::istringstream ySt(yInic);
1763 std::istringstream zSt(zInic);
1766 getline(inputStream,line);//FIN_COMPLEX_PORT
1768 configGComBoxInputOutputPort(true, inputPortName,xIn,yIn,zIn);
1771 } // for input complex box
1774 //-----------------------
1775 //- COMPLEX OUTPUT PORTS
1776 //-----------------------
1778 getline(inputStream,line);//COMPLEXOUTPUTS:num
1780 strcpy( outputs, line.c_str() );
1781 result = strtok( outputs, delims );
1782 result = strtok( NULL, delims );
1785 std::istringstream outps(result);
1786 outps >> numOutputs;
1788 for(int i = 0;i<numOutputs;i++)
1791 getline(inputStream,line);//COMPLEX_PORT
1792 getline(inputStream,line);//name
1793 std::string outputPortName(line);
1796 getline(inputStream,line);//xInic:yInic:zInic
1798 strcpy( coord, line.c_str() );
1799 result = strtok( coord, delims );//xInic
1800 std::string xInic(result);
1801 result = strtok( NULL, delims );//yInic
1802 std::string yInic(result);
1803 result = strtok( NULL, delims );//zInic
1804 std::string zInic(result);
1806 double xIn, yIn, zIn;
1807 std::istringstream xSt(xInic);
1809 std::istringstream ySt(yInic);
1811 std::istringstream zSt(zInic);
1814 getline(inputStream,line);//FIN_COMPLEX_PORT
1816 configGComBoxInputOutputPort(false, outputPortName,xIn,yIn,zIn);
1818 } // for output complex box
1823 getline(inputStream,line);//BOXES:num
1825 strcpy( boxes, line.c_str() );
1826 result = strtok( boxes, delims );
1827 result = strtok( NULL, delims );
1830 std::istringstream is(result);
1833 for(int i = 0;i<numBoxes;i++)
1836 getline(inputStream,line);//BOX
1837 getline(inputStream,line);//package:type:name
1839 strcpy( box, line.c_str() );
1840 result = strtok( box, delims );//package
1841 std::string package(result);
1842 result = strtok( NULL, delims );//type
1843 std::string type(result);
1844 result = strtok( NULL, delims );//name
1845 std::string name(result);
1847 getline(inputStream,line);//ISEXEC:TRUE|FALSE
1849 strcpy( exec, line.c_str() );
1850 result = strtok( exec, delims );//ISEXEC
1851 result = strtok( NULL, delims );//TRUE|FALSE
1852 std::string isExec(result);
1855 getline(inputStream,line);//xInic:yInic:zInic
1857 strcpy( coord, line.c_str() );
1858 result = strtok( coord, delims );//xInic
1859 std::string xInic(result);
1860 result = strtok( NULL, delims );//yInic
1861 std::string yInic(result);
1862 result = strtok( NULL, delims );//zInic
1863 std::string zInic(result);
1865 double xIn, yIn, zIn;
1866 std::istringstream xSt(xInic);
1868 std::istringstream ySt(yInic);
1870 std::istringstream zSt(zInic);
1874 getline(inputStream,line);//xEnd:yEnd:zEnd
1875 strcpy( coord, line.c_str() );
1876 result = strtok( coord, delims );//xEnd
1877 std::string xEnd(result);
1878 result = strtok( NULL, delims );//yEnd
1879 std::string yEnd(result);
1880 result = strtok( NULL, delims );//zEnd
1881 std::string zEnd(result);
1883 double xEn, yEn, zEn;
1884 std::istringstream xEt(xEnd);
1886 std::istringstream yEt(yEnd);
1888 std::istringstream zEt(zEnd);
1891 bool boxExecutable=false;
1894 boxExecutable= true;
1897 int idBox = createGBlackBox(xIn,yIn,package,type);
1898 configGBlackBox(idBox, xIn,yIn,zIn,name, boxExecutable,xEn,yEn,zEn);
1900 GObjectController *cont = _controllers[idBox];
1901 GBlackBoxModel *bbmod = (GBlackBoxModel*)cont->getModel();
1905 getline(inputStream,line);//PORT o FIN_BOX
1906 std::string port=line.substr(0,4);
1909 getline(inputStream,line);//name:value
1911 strcpy( poort, line.c_str() );
1912 result = strtok( poort, delims );//name
1913 std::string name(result);
1914 result = strtok( NULL, delims );//value
1915 std::string value(result);
1917 bbmod->setValueToInput(name,value);
1919 getline(inputStream,line);//PORT o FIN_BOX
1920 port=line.substr(0,4);
1923 //EED bbmod->notifyObservers(_idManager);
1928 getline(inputStream,line);//CONNECTIONS:num
1930 strcpy( conns, line.c_str() );
1931 result = strtok( conns, delims );
1932 result = strtok( NULL, delims );
1935 std::istringstream isCons(result);
1938 for(int i = 0;i<numConns;i++)
1941 getline(inputStream,line);//CONNECTION
1942 getline(inputStream,line);//Startbox.PortName:EndBox.PortName
1945 strcpy( connec, line.c_str() );
1946 result = strtok( connec, delims );
1947 std::string nameStartBox(result);
1948 result = strtok( NULL, delims );
1949 std::string nameStartPort(result);
1950 result = strtok( NULL, delims );
1951 std::string nameEndBox(result);
1952 result = strtok( NULL, delims );
1953 std::string nameEndPort(result);
1955 int idCon = configGConnetion(nameStartBox, nameStartPort, nameEndBox, nameEndPort);
1959 //Readding control points of the manualContour
1961 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
1962 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
1963 vtkGConnectorView *conView= (vtkGConnectorView*)tempp->getView();
1964 getline(inputStream,line); //NumberOfControlPoints:##
1965 strcpy( conns, line.c_str() );
1966 result = strtok( conns, delims );
1967 result = strtok( NULL, delims );
1969 int numberOfControlPoints;
1970 std::istringstream isCons(result);
1971 isCons >> numberOfControlPoints;
1973 for (int ii=0;ii<numberOfControlPoints;ii++)
1975 getline(inputStream,line); //XX:YY:ZZ
1977 strcpy( connec, line.c_str() );
1980 result = strtok( connec, delims );
1981 std::istringstream isPointX(result);
1983 result = strtok( NULL, delims );
1984 std::istringstream isPointY(result);
1986 result = strtok( NULL, delims );
1987 std::istringstream isPointZ(result);
1990 conMod->getManualContourModel()->InsertPoint_id(ii+1,px,py,pz);
1991 conView->getManualContourView()->AddPoint();
2001 //=========================================================================
2005 //=========================================================================
2006 void wxVtkSceneManager::configGComBoxInputOutputPort(bool inputoutput, std::string portName, double xIn, double yIn,double zIn)
2009 if (inputoutput==true)
2011 idPort = createGComplexBoxInputPort(portName);
2013 idPort = createGComplexBoxOutputPort(portName);
2015 GObjectController *cont = _controllers[idPort];
2016 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
2017 cbmod->setInicPoint(xIn,yIn,zIn);
2018 cbmod->notifyObservers(_idManager);
2020 //=========================================================================
2023 //=========================================================================
2024 GBoxModel* wxVtkSceneManager::findGBox(std::string boxname)
2029 GBoxModel *boxModel = NULL;
2030 std::vector<int> lstB = getBlackBoxes();
2031 for(j = 0;j<(int)lstB.size();j++)
2034 bMod = (GBoxModel*)_controllers[idB]->getModel();
2035 if(_controllers[idB]->getModel()->getBBTKName()==boxname)
2041 if((_isComplexBox) && (boxModel==NULL))
2043 std::vector<int> lstInputs = getComplexInputPorts();
2044 for(j = 0;j<(int)lstInputs.size();j++)
2047 bMod = (GBoxModel*)_controllers[idB]->getModel();
2048 if(_controllers[idB]->getModel()->getBBTKName()==boxname)
2054 std::vector<int> lstOutputs = getComplexOutputPorts();
2055 for(j = 0;j<(int)lstOutputs.size();j++)
2057 int idB = lstOutputs[j];
2058 bMod = (GBoxModel*)_controllers[idB]->getModel();
2059 if(_controllers[idB]->getModel()->getBBTKName()==boxname)
2070 //=========================================================================
2073 int wxVtkSceneManager::configGConnetion(std::string nameStartBox, std::string nameStartPort, std::string
2074 nameEndBox, std::string nameEndPort)
2077 GBoxModel *boxModel;
2078 GPortModel *startP = NULL;
2079 GPortModel *endP = NULL;
2081 boxModel= findGBox(nameStartBox);
2084 startP = boxModel->getOutputPort(nameStartPort);
2087 boxModel= findGBox(nameEndBox);
2090 endP = boxModel->getInputPort(nameEndPort);
2094 int idCon = createGConnector(startP);
2095 _worldState = NOTHING_HAPPENS;
2096 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
2098 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
2099 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
2100 tempp->endContourCreation();
2101 conMod->setEndPort(endP);
2102 conView->updateStartEndPoints();
2106 //=========================================================================
2108 bool wxVtkSceneManager::boxExist(std::string boxname)
2111 std::map<int, GObjectController*>::iterator it;
2112 for(it = _controllers.begin(); it != _controllers.end(); ++it)
2114 GObjectController *cont = it->second;
2115 if(cont->getModel()->getBBTKName()==boxname)
2123 //=========================================================================
2125 std::vector<int> wxVtkSceneManager::getBlackBoxes()
2127 std::vector<int> vect;
2128 std::map<int, GObjectController*>::iterator it;
2129 for(it = _controllers.begin(); it != _controllers.end(); ++it)
2131 GObjectController *cont = it->second;
2132 if(cont->getGObjectType()==GBLACKBOX)
2134 vect.push_back(cont->getId());
2140 //=========================================================================
2142 std::vector<int> wxVtkSceneManager::getComplexInputPorts()
2144 std::vector<int> vect;
2145 std::map<int, GObjectController*>::iterator it;
2146 for(it = _controllers.begin(); it != _controllers.end(); ++it)
2148 GObjectController *cont = it->second;
2149 if(cont->getGObjectType()==GCOMPLEXINPUTPORT)
2151 vect.push_back(cont->getId());
2157 //=========================================================================
2159 std::vector<int> wxVtkSceneManager::getComplexOutputPorts()
2161 std::vector<int> vect;
2162 std::map<int, GObjectController*>::iterator it;
2163 for(it = _controllers.begin(); it != _controllers.end(); ++it)
2165 GObjectController *cont = it->second;
2166 if(cont->getGObjectType()==GCOMPLEXOUTPUTPORT)
2168 vect.push_back(cont->getId());
2174 //=========================================================================
2176 std::vector<int> wxVtkSceneManager::getConnections()
2178 std::vector<int> vect;
2179 std::map<int, GObjectController*>::iterator it;
2180 for(it = _controllers.begin(); it != _controllers.end(); ++it)
2182 GObjectController *cont = it->second;
2183 if(cont->getGObjectType()==GCONNECTOR)
2185 vect.push_back(cont->getId());
2191 //=========================================================================
2193 bool wxVtkSceneManager::isComplexBox()
2195 return _isComplexBox;
2198 //=========================================================================
2200 void wxVtkSceneManager::setComplexBox(bool val)
2205 //=========================================================================
2207 int wxVtkSceneManager::addObjectController(GObjectController* objController)
2209 //Register the controller of the new object
2210 registerController((InteractorStyleMaracas*) objController);
2212 //Add the object to the objects list
2213 int newId = _contLastId;//_controllers.size();
2214 objController->setId(newId);
2215 _controllers[newId] = objController;
2220 //=========================================================================
2222 int wxVtkSceneManager::getNumSelectedObjects()
2224 return _selectedObjects.size();
2227 //=========================================================================
2229 std::map<int,GObjectController*> wxVtkSceneManager::getSelectedObjects()
2231 std::map<int,GObjectController*> mapSelected;
2233 std::map<int, GObjectController*>::iterator it;
2234 for(it = _controllers.begin(); it != _controllers.end(); ++it)
2236 GObjectController *cont = it->second;
2237 if(cont->getGObjectType()==GBLACKBOX && cont->getView()->getState()==SELECTED)
2239 mapSelected[cont->getId()]=cont;
2243 std::map<int, GObjectController*>::iterator it2;
2244 for(it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
2246 GObjectController *cont = it2->second;
2247 if(cont->getGObjectType()==GCONNECTOR)
2249 GConnectorModel* cmod = (GConnectorModel*)cont->getModel();
2250 GBoxModel* endPortParentBox = cmod->getEndPort()->getParentBox();
2251 GBoxModel* startPortParentBox = cmod->getStartPort()->getParentBox();
2253 std::map<int, GObjectController*>::iterator iterOBJ1 = mapSelected.find(startPortParentBox->getObjectId());
2254 std::map<int, GObjectController*>::iterator iterOBJ2 = mapSelected.find(endPortParentBox->getObjectId());
2256 if(iterOBJ1 != mapSelected.end() && iterOBJ2 != mapSelected.end())
2258 int ID = cont->getId();
2259 mapSelected[ID]=cont;
2266 //=========================================================================
2268 void wxVtkSceneManager::addObjects(std::map<int,GObjectController*> objectsMap)
2271 std::map<int,int> oldIdNewIdBoxes;
2272 std::vector<int> connections;
2274 std::map<int, GObjectController*>::iterator it;
2275 for(it = objectsMap.begin(); it != objectsMap.end(); ++it)
2277 GObjectController *cont = it->second;
2278 int type = cont->getGObjectType();
2283 double xInic, yInic,zInic;
2284 GBlackBoxModel* copyBox = (GBlackBoxModel*)cont->getModel();
2285 copyBox->getInicPoint(xInic,yInic,zInic);
2286 int idBox = createGBlackBox(0,0,copyBox->getBBTKPackage(),copyBox->getBBTKType());
2288 int idcB = copyBox->getObjectId();
2289 oldIdNewIdBoxes[idcB]=idBox;
2290 cont = _controllers[idBox];
2291 GBlackBoxModel* newbox = (GBlackBoxModel*)cont->getModel();
2292 newbox->setInicPoint(xInic,yInic,zInic);
2293 int num = newbox->getNumInputPorts();
2294 for(int j=0;j<num;j++)
2296 newbox->setValueToInputPort(j,copyBox->getValueInputPort(j));
2298 newbox->notifyObservers(_idManager);
2300 else if(type==GCONNECTOR)
2302 int idCon = cont->getId();
2303 connections.push_back(idCon);
2308 for(int i = 0 ;i<(int)connections.size();i++)
2310 int objId = connections[i];
2311 GObjectController *cont = objectsMap[objId];
2312 GConnectorModel* connectModel = (GConnectorModel*)cont->getModel();
2314 GPortModel* startPort = connectModel->getStartPort();
2315 int startPortIndex = startPort->getPosInBox();
2316 GPortModel* endPort = connectModel->getEndPort();
2317 int endPortIndex = endPort->getPosInBox();
2319 GBlackBoxModel* startPortParentBox = (GBlackBoxModel*)startPort->getParentBox();
2320 GBlackBoxModel* endPortParentBox = (GBlackBoxModel*)endPort->getParentBox();
2322 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2323 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2325 GBlackBoxModel* newStartBox = (GBlackBoxModel*)_controllers[idNewStartBox]->getModel();
2326 GBlackBoxModel* newEndBox = (GBlackBoxModel*)_controllers[idNewEndBox]->getModel();
2328 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2329 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2331 // Creates connection
2332 int idCon = createGConnector(newStartPort);
2333 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
2334 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
2335 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
2336 tempp->endContourCreation();
2337 conMod->setEndPort(newEndPort);
2338 conView->updateStartEndPoints();
2341 std::map<int, int>::iterator itIds;
2342 for(itIds = oldIdNewIdBoxes.begin(); itIds != oldIdNewIdBoxes.end(); ++itIds)
2344 int idOld = itIds->first;
2345 int idNew = itIds->second;
2347 GBlackBoxModel* oldBox = (GBlackBoxModel*)objectsMap[idOld]->getModel();
2348 GBlackBoxModel* newBox = (GBlackBoxModel*)_controllers[idNew]->getModel();
2350 std::vector<int> oldInputConnections = oldBox->getConnectedInputs();
2351 std::vector<int> oldOutputConnections = oldBox->getConnectedOutputs();
2352 std::vector<int> newInputConnections = newBox->getConnectedInputs();
2353 std::vector<int> newOutputConnections = newBox->getConnectedOutputs();
2355 for(int k = 0; k<(int)oldInputConnections.size();k++)
2358 //EED int toCreate=-1;
2359 for(int l = 0; l<(int)newInputConnections.size() && !exist;l++)
2361 if(oldInputConnections[k]==newInputConnections[l])
2369 //Create complex input
2370 int posInBox = oldInputConnections[k];
2371 GPortModel* inputPort = oldBox->getInputPort(posInBox);
2372 std::string inputPortName = inputPort->getBBTKName();
2373 int idInputPort = createGComplexBoxInputPort(inputPortName);
2374 GObjectController *cont = _controllers[idInputPort];
2375 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
2377 inputPort->getInicPoint(xIn,yIn,zIn);
2379 cbmod->setInicPoint(xIn,yIn,zIn);
2380 cbmod->notifyObservers(_idManager);
2382 GPortModel* inputPortEnd = newBox->getInputPort(posInBox);
2384 // Creates connection
2385 int idCon = createGConnector(cbmod->getOutputPort(0));
2386 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
2387 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
2388 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
2389 tempp->endContourCreation();
2390 conMod->setEndPort(inputPortEnd);
2391 conView->updateStartEndPoints();
2398 for(int k = 0; k<(int)oldOutputConnections.size();k++)
2401 //EED int toCreate=-1;
2402 for(int l = 0; l<(int)newOutputConnections.size() && !exist;l++)
2404 if(oldOutputConnections[k]==newOutputConnections[l])
2412 //Create complex output
2413 int posInBox = oldOutputConnections[k];
2414 GPortModel* outputPort = oldBox->getOutputPort(posInBox);
2415 std::string outputPortName = outputPort->getBBTKName();
2416 int idOutputPort = createGComplexBoxOutputPort(outputPortName);
2417 GObjectController *cont = _controllers[idOutputPort];
2418 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
2420 outputPort->getInicPoint(xIn,yIn,zIn);
2422 cbmod->setInicPoint(xIn,yIn,zIn);
2423 cbmod->notifyObservers(_idManager);
2425 GPortModel* outputPortEnd = newBox->getOutputPort(posInBox);
2427 // Creates connection
2428 int idCon = createGConnector(outputPortEnd);
2429 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
2430 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
2431 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
2432 tempp->endContourCreation();
2433 conMod->setEndPort(cbmod->getInputPort(0));
2434 conView->updateStartEndPoints();
2445 //=========================================================================
2447 } // EO namespace bbtk