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)
829 UnSelectBlackBoxes();
832 } else { //_worldState
834 _worldState = DRAG_OBJECTS;
835 _startDragging = true;
837 int shiftkey = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey();
838 int ctrlkey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
839 ctrlkey = ctrlkey + shiftkey;
841 GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
844 if (GetGBlackBoxControlerPointedByMouse()!=NULL)
846 int state=cont->getView()->getState() ;
847 if( (ctrlkey==0) && (state==HIGHLIGHTED) )
849 UnSelectBlackBoxes();
852 for (int i = 0; i < (int)_selectedObjects.size(); i++)
854 int id = _selectedObjects[i];
855 GObjectController* cont = _controllers[id];
856 cont->getView()->setState(DRAG);
857 cont->getModel()->notifyObservers(_idManager);
860 } // if _selectedObjects.size
866 //=========================================================================
868 bool wxVtkSceneManager::OnLeftButtonUp()
870 if(_worldState == DRAG_OBJECTS)
872 _worldState = NOTHING_HAPPENS;
874 for (int i = 0; i < (int)_selectedObjects.size(); i++)
876 int id = _selectedObjects[i];
877 GObjectController* cont = _controllers[id];
878 cont->getView()->setState(SELECTED);
879 cont->getModel()->notifyObservers(_idManager);
885 //=========================================================================
886 void wxVtkSceneManager::CancelConnection()
888 if(_worldState==INIT_CREATION_CONTOUR)
890 _worldState=NOTHING_HAPPENS;
891 //int lastId = _controllers.size()-1;
893 GConnectorController *connector = (GConnectorController*)_controllers[_idConnectionInCreation];
894 connector->removeFromScene();
895 unregisterController(connector);
896 _controllers.erase(_idConnectionInCreation);
898 std::map<int, GObjectController*>::iterator it;
899 for(it = _controllers.begin(); it != _controllers.end(); ++it)
901 GObjectController *desc = it->second;
902 desc->SetActive(true);
903 desc->getView()->setState(NOTHING_HAPPENS);
904 desc->getModel()->notifyObservers(_idManager);
910 //=========================================================================
912 bool wxVtkSceneManager::OnRightButtonUp()
914 if(_worldState==INIT_CREATION_CONTOUR)
918 UnSelectBlackBoxes();
922 //=========================================================================
924 GObjectController *wxVtkSceneManager::GetGBlackBoxControlerPointedByMouse()
926 GObjectController *result=NULL;
928 wxVTKRenderWindowInteractor *wxVTKiren;
929 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
930 wxVTKiren->GetEventPosition(X,Y);
932 std::map<int, GObjectController*>::iterator it;
934 for(it = _controllers.begin(); it != _controllers.end() ; ++it)
936 GObjectController *cont = it->second;
937 int type = cont->getGObjectType();
939 if( cont->getView()->isPointInside(X,Y)==true )
945 } // if isPointInside
950 //=========================================================================
951 void wxVtkSceneManager::UnSelectBlackBoxes()
953 for (int i=0; i< (int)_selectedObjects.size(); i++)
955 int id = _selectedObjects[i];
956 GObjectController* control = _controllers[id];
957 control->getView()->setState(NOTHING_HAPPENS);
958 }// for _selectedObjects
959 _selectedObjects.clear();
962 //=========================================================================
963 bool wxVtkSceneManager::OnLeftDClick()
965 GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
968 UnSelectBlackBoxes();
969 _parent->editBlackBox( (GBlackBoxModel*)cont->getModel() );
975 wxVTKRenderWindowInteractor *wxVTKiren;
976 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
977 wxVTKiren->GetEventPosition(X,Y);
979 std::map<int, GObjectController*>::iterator it;
981 bool clickOnObject = false;
983 for(it = _controllers.begin(); it != _controllers.end() && clickOnObject==false; ++it)
985 GObjectController *cont = it->second;
986 int type = cont->getGObjectType();
988 if(cont->getView()->isPointInside(X,Y))
992 for (int i=0; i< (int)_selectedObjects.size(); i++)
994 int id = _selectedObjects[i];
995 GObjectController* control = _controllers[id];
996 control->getView()->setState(NOTHING_HAPPENS);
998 _selectedObjects.clear();
1000 GBlackBoxModel *bbmodel = (GBlackBoxModel*)cont->getModel();
1001 _parent->editBlackBox(bbmodel);
1003 clickOnObject = true;
1007 if(clickOnObject==false)
1009 //_parent->editDiagramParameters(this);
1015 //=========================================================================
1017 bool wxVtkSceneManager::OnChar()
1019 char keyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
1021 // KeyCode 127 : Delete Key
1022 // KeyCode 8 : Backspace Key
1023 if(keyCode == 8 || keyCode == 127)
1025 if(_selectedObjects.size()>0)
1027 for(int i=0;i<(int)_selectedObjects.size();i++)
1029 int id = _selectedObjects[i];
1030 std::map<int,GObjectController*>::iterator it;
1031 it = _controllers.find(id);
1032 if (it!=_controllers.end())
1037 _selectedObjects.clear();
1044 //=========================================================================
1046 void wxVtkSceneManager::AddControlerToBeRemove(std::vector<int> *controllersToRemove, int id)
1051 for(i=0 ; i < (int)controllersToRemove->size() ; i++ )
1053 if (id == (*controllersToRemove)[i] )
1061 controllersToRemove->push_back( id );
1066 //=========================================================================
1068 void wxVtkSceneManager::deleteObject(int id)
1070 GObjectController *control = _controllers[id];
1071 std::vector<int> controllersToRemove;
1073 if(control->getGObjectType()==GBLACKBOX || control->getGObjectType()==GCOMPLEXINPUTPORT || control->getGObjectType()==GCOMPLEXOUTPUTPORT)
1075 GBoxModel *bbmod = (GBoxModel*)control->getModel();
1076 std::vector<GPortModel*> inputs = bbmod->getInputPorts();
1078 bool boxConnected = false;
1080 // Add box input controllers to be removed
1081 for(int i = 0;i< (int)inputs.size();i++)
1083 AddControlerToBeRemove( &controllersToRemove, inputs[i]->getObjectId() );
1084 if(inputs[i]->isConnected())
1086 boxConnected = true;
1090 std::vector<GPortModel*> outputs = bbmod->getOutputPorts();
1092 // Add box output controllers to be removed
1093 for(int i = 0;i<(int)outputs.size();i++)
1095 AddControlerToBeRemove( &controllersToRemove, outputs[i]->getObjectId() );
1096 if(outputs[i]->isConnected())
1098 boxConnected = true;
1102 // Add connection controllers to be removed
1103 std::map<int, GObjectController*>::iterator it;
1104 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1106 GObjectController *cont = it->second;
1107 int type = cont->getGObjectType();
1108 if(type==GCONNECTOR)
1110 GConnectorModel *conMod = (GConnectorModel*)cont->getModel();
1111 if(conMod->getStartPort()!=NULL && conMod->getStartPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
1113 AddControlerToBeRemove( &controllersToRemove, conMod->getObjectId() );
1115 if(conMod->getEndPort()!=NULL && conMod->getEndPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
1117 AddControlerToBeRemove( &controllersToRemove, conMod->getObjectId() );
1122 // Add box controller to be removed
1123 AddControlerToBeRemove( &controllersToRemove, bbmod->getObjectId() );
1125 else if(control->getGObjectType()==GCONNECTOR)
1127 GConnectorModel *conMod = (GConnectorModel*)control->getModel();
1128 AddControlerToBeRemove( &controllersToRemove, conMod->getObjectId() );
1132 std::map<int,GObjectController*>::iterator it;
1134 for(int i = 0;i<(int)controllersToRemove.size();i++)
1136 int key = controllersToRemove[i];
1137 it = _controllers.find( key );
1138 GObjectController *cont = _controllers[ key ];
1141 cont->removeFromScene();
1142 unregisterController((InteractorStyleMaracas*)cont);
1143 _controllers.erase(it);
1148 //=========================================================================
1150 void wxVtkSceneManager::displayBlackBoxInfo(std::string packageName, std::string boxName)
1152 _parent->displayBlackBoxInfo(packageName,boxName);
1155 //=========================================================================
1157 void wxVtkSceneManager::updateStatusBar(std::string textStatus)
1159 _parent->updateStatusBar(textStatus);
1163 //=========================================================================
1164 std::string wxVtkSceneManager::LineNumber(bool withLineNumber, int &value)
1166 std::string result="";
1167 if (withLineNumber==true)
1170 stringstream StrStream;
1172 std::string strValue=StrStream.str();
1176 }else if (value<100)
1181 result+=strValue+": ";
1185 //=========================================================================
1187 std::string wxVtkSceneManager::getDiagramBBS(bool wln)
1189 bool existsExec=false;
1191 std::vector<std::string> packages;
1192 std::vector<int> boxes;
1193 std::vector<int> connections;
1194 std::vector<int> execBoxes;
1196 std::map<int, GObjectController*>::iterator it;
1198 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1200 GObjectController *desc = it->second;
1201 int type = desc->getGObjectType();
1205 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
1207 std::string pkg = mod->getBBTKPackage();
1208 bool existsPkg = false;
1209 for(int t = 0;t< (int)packages.size() && existsPkg == false;t++)
1211 if(packages[t]==pkg)
1218 packages.push_back(pkg);
1222 boxes.push_back(it->first);
1223 if(mod->isExecutable())
1225 execBoxes.push_back(it->first);
1229 else if(type==GCONNECTOR)
1231 connections.push_back(it->first);
1236 std::string script = "";
1237 script+=LineNumber(wln,lnNmbr)+"# BBTK GEditor Script\n";
1238 script+=LineNumber(wln,lnNmbr)+"# ----------------------\n";
1239 script+=LineNumber(wln,lnNmbr)+"\n";
1242 script+=LineNumber(wln,lnNmbr)+"include std\n"; // EED
1243 script+=LineNumber(wln,lnNmbr)+"include itkvtk\n"; // EED
1245 for(i = 0; i< (int)packages.size();i++)
1247 script+=LineNumber(wln,lnNmbr);
1249 script+=packages[i];
1253 script+=LineNumber(wln,lnNmbr);
1256 // script+="include std\n"; // JPR
1258 for(i = 0; i < (int)boxes.size();i++)
1260 script+=LineNumber(wln,lnNmbr);
1263 GObjectController *control = _controllers[id];
1264 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1266 script+=model->getBBTKType();
1268 script+=model->getBBTKName();
1271 std::vector<GPortModel*> inputs = model->getInputPorts();
1272 for(int j = 0; j < (int)inputs.size();j++)
1274 GPortModel* inputPort = inputs[j];
1275 if(inputPort->isValueSet())
1277 script+=LineNumber(wln,lnNmbr);
1279 script+=model->getBBTKName();
1281 script+=inputPort->getBBTKName();
1283 script+=inputPort->getValue();
1288 script+=LineNumber(wln,lnNmbr);
1293 script+=LineNumber(wln,lnNmbr);
1296 for(i = 0; i<(int)connections.size();i++)
1298 script+=LineNumber(wln,lnNmbr);
1300 int id = connections[i];
1301 GObjectController *control = _controllers[id];
1302 GConnectorModel *model = (GConnectorModel*)control->getModel();
1304 //Start Connection info
1305 GPortModel *start = model->getStartPort();
1306 script+=start->getParentBox()->getBBTKName();
1308 script+=start->getBBTKName();
1312 //End Connection info
1313 GPortModel *end = model->getEndPort();
1314 script+=end->getParentBox()->getBBTKName();
1316 script+=end->getBBTKName();
1321 script+=LineNumber(wln,lnNmbr);
1323 for(i = 0; i<(int)execBoxes.size();i++)
1325 script+=LineNumber(wln,lnNmbr);
1327 int id = execBoxes[i];
1328 GObjectController *control = _controllers[id];
1329 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1331 script+=model->getBBTKName();
1340 //=========================================================================
1342 std::string wxVtkSceneManager::saveComplexBoxBBS(std::string cbName,std::string cbAuthor,std::string cbCategory,std::string cbDescription)
1345 std::vector<std::string> packages;
1346 std::vector<int> boxes;
1347 std::vector<int> connections;
1348 std::vector<int> execBoxes;
1350 std::map<int, GObjectController*>::iterator it;
1352 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1354 GObjectController *desc = it->second;
1355 int type = desc->getGObjectType();
1359 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
1361 std::string pkg = mod->getBBTKPackage();
1362 bool existsPkg = false;
1363 for(int t = 0;t<(int)packages.size() && existsPkg == false;t++)
1365 if(packages[t]==pkg)
1372 packages.push_back(pkg);
1376 boxes.push_back(it->first);
1377 if(mod->isExecutable())
1379 execBoxes.push_back(it->first);
1382 else if(type==GCONNECTOR)
1384 connections.push_back(it->first);
1388 std::string script = "";
1390 script+="include std\n"; // EED
1391 script+="include itkvtk\n"; // EED
1393 for(i = 0; i<(int)packages.size();i++)
1396 script+=packages[i];
1401 // Definition of a complex box
1407 script+="author \" ";
1411 script+="description \" ";
1412 script+=cbDescription;
1417 for(i = 0; i<(int)boxes.size();i++)
1421 GObjectController *control = _controllers[id];
1422 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1424 script+=model->getBBTKType();
1426 script+=model->getBBTKName();
1429 std::vector<GPortModel*> inputs = model->getInputPorts();
1430 for(int j = 0; j<(int)inputs.size();j++)
1432 GPortModel* inputPort = inputs[j];
1433 if(inputPort->isValueSet())
1436 script+=model->getBBTKName();
1438 script+=inputPort->getBBTKName();
1440 script+=inputPort->getValue();
1448 // Create connections in the script. If the connection is made with a complex port, it is created the input or output
1450 std::string complexInputs="";
1451 std::string complexOutputs="";
1454 for(i = 0; i<(int)connections.size();i++)
1456 int id = connections[i];
1457 GObjectController *control = _controllers[id];
1458 GConnectorModel *model = (GConnectorModel*)control->getModel();
1461 GPortModel *start = model->getStartPort();
1462 GBoxModel *startBox =start->getParentBox();
1464 GPortModel *end = model->getEndPort();
1465 GBoxModel *endBox =end->getParentBox();
1467 if(startBox->getGObjectType()==GCOMPLEXINPUTPORT)
1469 complexInputs+="input ";
1470 complexInputs+=startBox->getBBTKName();
1473 complexInputs+=endBox->getBBTKName();
1475 complexInputs+=end->getBBTKName();
1478 complexInputs+="\" \"";
1480 complexInputs+="\n";
1482 else if(endBox->getGObjectType()==GCOMPLEXOUTPUTPORT)
1484 complexOutputs+="output ";
1485 complexOutputs+=endBox->getBBTKName();
1487 complexOutputs+=" ";
1488 complexOutputs+=startBox->getBBTKName();
1489 complexOutputs+=".";
1490 complexOutputs+=start->getBBTKName();
1492 complexOutputs+=" ";
1493 complexOutputs+="\" \"";
1495 complexOutputs+="\n";
1500 script+=startBox->getBBTKName();
1502 script+=start->getBBTKName();
1506 //End Connection info
1507 script+=endBox->getBBTKName();
1509 script+=end->getBBTKName();
1517 for(i = 0; i<(int)execBoxes.size();i++)
1520 int id = execBoxes[i];
1521 GObjectController *control = _controllers[id];
1522 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1524 script+=model->getBBTKName();
1529 script+="# Complex input ports\n";
1530 script+=complexInputs;
1533 script+="# Complex output ports\n";
1534 script+=complexOutputs;
1543 //=========================================================================
1545 void wxVtkSceneManager::deleteAllBoxes()
1547 std::map<int, GObjectController*>::iterator it;
1548 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1550 GObjectController *cont = it->second;
1551 cont->removeFromScene();
1552 unregisterController((InteractorStyleMaracas*)cont);
1554 _selectedObjects.clear();
1555 _controllers.clear();
1559 //=========================================================================
1562 void wxVtkSceneManager::refresh()
1564 _baseView->Refresh();
1566 //=========================================================================
1568 void wxVtkSceneManager::refreshScene()
1570 _baseView->RefreshView();
1573 //=========================================================================
1575 void wxVtkSceneManager::centerView()
1578 _baseView->GetRenderer()->GetActiveCamera()->GetFocalPoint(temp);
1579 _baseView->GetRenderer()->GetActiveCamera()->SetFocalPoint(0,0,temp[2]);
1580 _baseView->GetRenderer()->GetActiveCamera()->GetPosition(temp);
1581 _baseView->GetRenderer()->GetActiveCamera()->SetPosition(0,0,temp[2]);
1582 _baseView->RefreshView();
1586 //=========================================================================
1588 void wxVtkSceneManager::saveDiagram(std::string &content)
1592 //Print info IF COMPLEX BOX
1593 content+="COMPLEXBOX:";
1598 //Print info complex input ports
1599 std::vector<int> inputs = getComplexInputPorts();
1600 int insize = inputs.size();
1601 content+="COMPLEXINPUTS:";
1602 sprintf (buffer, "%d", insize);
1606 for(int i = 0;i<insize;i++)
1609 GObjectController *cont = _controllers[id];
1610 cont->getModel()->save(content);
1613 //Print info complex output ports
1614 std::vector<int> outputs = getComplexOutputPorts();
1615 int outsize = outputs.size();
1616 content+="COMPLEXOUTPUTS:";
1617 sprintf (buffer, "%d", outsize);
1621 for(int i = 0;i<outsize;i++)
1623 int id = outputs[i];
1624 GObjectController *cont = _controllers[id];
1625 cont->getModel()->save(content);
1634 std::vector<int> boxes = getBlackBoxes();
1635 int bsize = boxes.size();
1637 sprintf (buffer, "%d", bsize);
1641 for(int i = 0;i<bsize;i++)
1644 GObjectController *cont = _controllers[id];
1645 cont->getModel()->save(content);
1649 std::vector<int> connections = getConnections();
1650 int csize = connections.size();
1651 content+="CONNECTIONS:";
1652 sprintf (buffer, "%d", csize);
1656 for(int i = 0;i<csize;i++)
1658 int id = connections[i];
1659 GObjectController *cont = _controllers[id];
1660 cont->getModel()->save(content);
1665 //=========================================================================
1667 void wxVtkSceneManager::loadDiagram(ifstream &inputStream)
1670 std::string version;
1671 std::string line="";
1672 char delims[] = ":";
1673 char *result = NULL;
1674 getline(inputStream,line);
1677 while ( !inputStream.eof() )
1679 if(line=="" || line[0]=='#')
1681 getline(inputStream,line);
1682 if (line=="# - BBTKGEditor v 1.0 BBG BlackBox Diagram file")
1684 version=line.substr(18,3);
1685 printf("EED wxVtkSceneManager::loadDiagram version=%s\n",version.c_str());
1689 else if(line=="APP_START")
1700 getline(inputStream,line);//COMPLEX_BOX:TRUE|FALSE
1702 strcpy( complex, line.c_str() );
1703 result = strtok( complex, delims );
1704 result = strtok( NULL, delims );
1705 std::string isComplexBox(result);
1707 if(isComplexBox=="TRUE")
1711 //-----------------------
1712 //- COMPLEX INPUT PORTS
1713 //-----------------------
1714 getline(inputStream,line);//COMPLEXINPUTS:num
1716 strcpy( inputs, line.c_str() );
1717 result = strtok( inputs, delims );
1718 result = strtok( NULL, delims );
1721 std::istringstream inps(result);
1724 for(int i = 0;i<numInputs;i++)
1727 getline(inputStream,line);//COMPLEX_PORT
1728 getline(inputStream,line);//name
1729 std::string inputPortName(line);
1732 getline(inputStream,line);//xInic:yInic:zInic
1734 strcpy( coord, line.c_str() );
1735 result = strtok( coord, delims );//xInic
1736 std::string xInic(result);
1737 result = strtok( NULL, delims );//yInic
1738 std::string yInic(result);
1739 result = strtok( NULL, delims );//zInic
1740 std::string zInic(result);
1742 double xIn, yIn, zIn;
1743 std::istringstream xSt(xInic);
1745 std::istringstream ySt(yInic);
1747 std::istringstream zSt(zInic);
1750 getline(inputStream,line);//FIN_COMPLEX_PORT
1752 configGComBoxInputOutputPort(true, inputPortName,xIn,yIn,zIn);
1755 } // for input complex box
1758 //-----------------------
1759 //- COMPLEX OUTPUT PORTS
1760 //-----------------------
1762 getline(inputStream,line);//COMPLEXOUTPUTS:num
1764 strcpy( outputs, line.c_str() );
1765 result = strtok( outputs, delims );
1766 result = strtok( NULL, delims );
1769 std::istringstream outps(result);
1770 outps >> numOutputs;
1772 for(int i = 0;i<numOutputs;i++)
1775 getline(inputStream,line);//COMPLEX_PORT
1776 getline(inputStream,line);//name
1777 std::string outputPortName(line);
1780 getline(inputStream,line);//xInic:yInic:zInic
1782 strcpy( coord, line.c_str() );
1783 result = strtok( coord, delims );//xInic
1784 std::string xInic(result);
1785 result = strtok( NULL, delims );//yInic
1786 std::string yInic(result);
1787 result = strtok( NULL, delims );//zInic
1788 std::string zInic(result);
1790 double xIn, yIn, zIn;
1791 std::istringstream xSt(xInic);
1793 std::istringstream ySt(yInic);
1795 std::istringstream zSt(zInic);
1798 getline(inputStream,line);//FIN_COMPLEX_PORT
1800 configGComBoxInputOutputPort(false, outputPortName,xIn,yIn,zIn);
1802 } // for output complex box
1807 getline(inputStream,line);//BOXES:num
1809 strcpy( boxes, line.c_str() );
1810 result = strtok( boxes, delims );
1811 result = strtok( NULL, delims );
1814 std::istringstream is(result);
1817 for(int i = 0;i<numBoxes;i++)
1820 getline(inputStream,line);//BOX
1821 getline(inputStream,line);//package:type:name
1823 strcpy( box, line.c_str() );
1824 result = strtok( box, delims );//package
1825 std::string package(result);
1826 result = strtok( NULL, delims );//type
1827 std::string type(result);
1828 result = strtok( NULL, delims );//name
1829 std::string name(result);
1831 getline(inputStream,line);//ISEXEC:TRUE|FALSE
1833 strcpy( exec, line.c_str() );
1834 result = strtok( exec, delims );//ISEXEC
1835 result = strtok( NULL, delims );//TRUE|FALSE
1836 std::string isExec(result);
1839 getline(inputStream,line);//xInic:yInic:zInic
1841 strcpy( coord, line.c_str() );
1842 result = strtok( coord, delims );//xInic
1843 std::string xInic(result);
1844 result = strtok( NULL, delims );//yInic
1845 std::string yInic(result);
1846 result = strtok( NULL, delims );//zInic
1847 std::string zInic(result);
1849 double xIn, yIn, zIn;
1850 std::istringstream xSt(xInic);
1852 std::istringstream ySt(yInic);
1854 std::istringstream zSt(zInic);
1858 getline(inputStream,line);//xEnd:yEnd:zEnd
1859 strcpy( coord, line.c_str() );
1860 result = strtok( coord, delims );//xEnd
1861 std::string xEnd(result);
1862 result = strtok( NULL, delims );//yEnd
1863 std::string yEnd(result);
1864 result = strtok( NULL, delims );//zEnd
1865 std::string zEnd(result);
1867 double xEn, yEn, zEn;
1868 std::istringstream xEt(xEnd);
1870 std::istringstream yEt(yEnd);
1872 std::istringstream zEt(zEnd);
1875 bool boxExecutable=false;
1878 boxExecutable= true;
1881 int idBox = createGBlackBox(xIn,yIn,package,type);
1882 configGBlackBox(idBox, xIn,yIn,zIn,name, boxExecutable,xEn,yEn,zEn);
1884 GObjectController *cont = _controllers[idBox];
1885 GBlackBoxModel *bbmod = (GBlackBoxModel*)cont->getModel();
1889 getline(inputStream,line);//PORT o FIN_BOX
1890 std::string port=line.substr(0,4);
1893 getline(inputStream,line);//name:value
1895 strcpy( poort, line.c_str() );
1896 result = strtok( poort, delims );//name
1897 std::string name(result);
1898 result = strtok( NULL, delims );//value
1899 std::string value(result);
1901 bbmod->setValueToInput(name,value);
1903 getline(inputStream,line);//PORT o FIN_BOX
1904 port=line.substr(0,4);
1907 //EED bbmod->notifyObservers(_idManager);
1912 getline(inputStream,line);//CONNECTIONS:num
1914 strcpy( conns, line.c_str() );
1915 result = strtok( conns, delims );
1916 result = strtok( NULL, delims );
1919 std::istringstream isCons(result);
1922 for(int i = 0;i<numConns;i++)
1925 getline(inputStream,line);//CONNECTION
1926 getline(inputStream,line);//Startbox.PortName:EndBox.PortName
1929 strcpy( connec, line.c_str() );
1930 result = strtok( connec, delims );
1931 std::string nameStartBox(result);
1932 result = strtok( NULL, delims );
1933 std::string nameStartPort(result);
1934 result = strtok( NULL, delims );
1935 std::string nameEndBox(result);
1936 result = strtok( NULL, delims );
1937 std::string nameEndPort(result);
1939 int idCon = configGConnetion(nameStartBox, nameStartPort, nameEndBox, nameEndPort);
1943 //Readding control points of the manualContour
1945 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
1946 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
1947 vtkGConnectorView *conView= (vtkGConnectorView*)tempp->getView();
1948 getline(inputStream,line); //NumberOfControlPoints:##
1949 strcpy( conns, line.c_str() );
1950 result = strtok( conns, delims );
1951 result = strtok( NULL, delims );
1953 int numberOfControlPoints;
1954 std::istringstream isCons(result);
1955 isCons >> numberOfControlPoints;
1957 for (int ii=0;ii<numberOfControlPoints;ii++)
1959 getline(inputStream,line); //XX:YY:ZZ
1961 strcpy( connec, line.c_str() );
1964 result = strtok( connec, delims );
1965 std::istringstream isPointX(result);
1967 result = strtok( NULL, delims );
1968 std::istringstream isPointY(result);
1970 result = strtok( NULL, delims );
1971 std::istringstream isPointZ(result);
1974 conMod->getManualContourModel()->InsertPoint_id(ii+1,px,py,pz);
1975 conView->getManualContourView()->AddPoint();
1985 //=========================================================================
1989 //=========================================================================
1990 void wxVtkSceneManager::configGComBoxInputOutputPort(bool inputoutput, std::string portName, double xIn, double yIn,double zIn)
1993 if (inputoutput==true)
1995 idPort = createGComplexBoxInputPort(portName);
1997 idPort = createGComplexBoxOutputPort(portName);
1999 GObjectController *cont = _controllers[idPort];
2000 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
2001 cbmod->setInicPoint(xIn,yIn,zIn);
2002 cbmod->notifyObservers(_idManager);
2004 //=========================================================================
2007 //=========================================================================
2008 GBoxModel* wxVtkSceneManager::findGBox(std::string boxname)
2013 GBoxModel *boxModel = NULL;
2014 std::vector<int> lstB = getBlackBoxes();
2015 for(j = 0;j<(int)lstB.size();j++)
2018 bMod = (GBoxModel*)_controllers[idB]->getModel();
2019 if(_controllers[idB]->getModel()->getBBTKName()==boxname)
2025 if((_isComplexBox) && (boxModel==NULL))
2027 std::vector<int> lstInputs = getComplexInputPorts();
2028 for(j = 0;j<(int)lstInputs.size();j++)
2031 bMod = (GBoxModel*)_controllers[idB]->getModel();
2032 if(_controllers[idB]->getModel()->getBBTKName()==boxname)
2038 std::vector<int> lstOutputs = getComplexOutputPorts();
2039 for(j = 0;j<(int)lstOutputs.size();j++)
2041 int idB = lstOutputs[j];
2042 bMod = (GBoxModel*)_controllers[idB]->getModel();
2043 if(_controllers[idB]->getModel()->getBBTKName()==boxname)
2054 //=========================================================================
2057 int wxVtkSceneManager::configGConnetion(std::string nameStartBox, std::string nameStartPort, std::string
2058 nameEndBox, std::string nameEndPort)
2061 GBoxModel *boxModel;
2062 GPortModel *startP = NULL;
2063 GPortModel *endP = NULL;
2065 boxModel= findGBox(nameStartBox);
2068 startP = boxModel->getOutputPort(nameStartPort);
2071 boxModel= findGBox(nameEndBox);
2074 endP = boxModel->getInputPort(nameEndPort);
2078 int idCon = createGConnector(startP);
2079 _worldState = NOTHING_HAPPENS;
2080 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
2082 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
2083 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
2084 tempp->endContourCreation();
2085 conMod->setEndPort(endP);
2086 conView->updateStartEndPoints();
2090 //=========================================================================
2092 bool wxVtkSceneManager::boxExist(std::string boxname)
2095 std::map<int, GObjectController*>::iterator it;
2096 for(it = _controllers.begin(); it != _controllers.end(); ++it)
2098 GObjectController *cont = it->second;
2099 if(cont->getModel()->getBBTKName()==boxname)
2107 //=========================================================================
2109 std::vector<int> wxVtkSceneManager::getBlackBoxes()
2111 std::vector<int> vect;
2112 std::map<int, GObjectController*>::iterator it;
2113 for(it = _controllers.begin(); it != _controllers.end(); ++it)
2115 GObjectController *cont = it->second;
2116 if(cont->getGObjectType()==GBLACKBOX)
2118 vect.push_back(cont->getId());
2124 //=========================================================================
2126 std::vector<int> wxVtkSceneManager::getComplexInputPorts()
2128 std::vector<int> vect;
2129 std::map<int, GObjectController*>::iterator it;
2130 for(it = _controllers.begin(); it != _controllers.end(); ++it)
2132 GObjectController *cont = it->second;
2133 if(cont->getGObjectType()==GCOMPLEXINPUTPORT)
2135 vect.push_back(cont->getId());
2141 //=========================================================================
2143 std::vector<int> wxVtkSceneManager::getComplexOutputPorts()
2145 std::vector<int> vect;
2146 std::map<int, GObjectController*>::iterator it;
2147 for(it = _controllers.begin(); it != _controllers.end(); ++it)
2149 GObjectController *cont = it->second;
2150 if(cont->getGObjectType()==GCOMPLEXOUTPUTPORT)
2152 vect.push_back(cont->getId());
2158 //=========================================================================
2160 std::vector<int> wxVtkSceneManager::getConnections()
2162 std::vector<int> vect;
2163 std::map<int, GObjectController*>::iterator it;
2164 for(it = _controllers.begin(); it != _controllers.end(); ++it)
2166 GObjectController *cont = it->second;
2167 if(cont->getGObjectType()==GCONNECTOR)
2169 vect.push_back(cont->getId());
2175 //=========================================================================
2177 bool wxVtkSceneManager::isComplexBox()
2179 return _isComplexBox;
2182 //=========================================================================
2184 void wxVtkSceneManager::setComplexBox(bool val)
2189 //=========================================================================
2191 int wxVtkSceneManager::addObjectController(GObjectController* objController)
2193 //Register the controller of the new object
2194 registerController((InteractorStyleMaracas*) objController);
2196 //Add the object to the objects list
2197 int newId = _contLastId;//_controllers.size();
2198 objController->setId(newId);
2199 _controllers[newId] = objController;
2204 //=========================================================================
2206 int wxVtkSceneManager::getNumSelectedObjects()
2208 return _selectedObjects.size();
2211 //=========================================================================
2213 std::map<int,GObjectController*> wxVtkSceneManager::getSelectedObjects()
2215 std::map<int,GObjectController*> mapSelected;
2217 std::map<int, GObjectController*>::iterator it;
2218 for(it = _controllers.begin(); it != _controllers.end(); ++it)
2220 GObjectController *cont = it->second;
2221 if(cont->getGObjectType()==GBLACKBOX && cont->getView()->getState()==SELECTED)
2223 mapSelected[cont->getId()]=cont;
2227 std::map<int, GObjectController*>::iterator it2;
2228 for(it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
2230 GObjectController *cont = it2->second;
2231 if(cont->getGObjectType()==GCONNECTOR)
2233 GConnectorModel* cmod = (GConnectorModel*)cont->getModel();
2234 GBoxModel* endPortParentBox = cmod->getEndPort()->getParentBox();
2235 GBoxModel* startPortParentBox = cmod->getStartPort()->getParentBox();
2237 std::map<int, GObjectController*>::iterator iterOBJ1 = mapSelected.find(startPortParentBox->getObjectId());
2238 std::map<int, GObjectController*>::iterator iterOBJ2 = mapSelected.find(endPortParentBox->getObjectId());
2240 if(iterOBJ1 != mapSelected.end() && iterOBJ2 != mapSelected.end())
2242 int ID = cont->getId();
2243 mapSelected[ID]=cont;
2250 //=========================================================================
2252 void wxVtkSceneManager::addObjects(std::map<int,GObjectController*> objectsMap)
2255 std::map<int,int> oldIdNewIdBoxes;
2256 std::vector<int> connections;
2258 std::map<int, GObjectController*>::iterator it;
2259 for(it = objectsMap.begin(); it != objectsMap.end(); ++it)
2261 GObjectController *cont = it->second;
2262 int type = cont->getGObjectType();
2267 double xInic, yInic,zInic;
2268 GBlackBoxModel* copyBox = (GBlackBoxModel*)cont->getModel();
2269 copyBox->getInicPoint(xInic,yInic,zInic);
2270 int idBox = createGBlackBox(0,0,copyBox->getBBTKPackage(),copyBox->getBBTKType());
2272 int idcB = copyBox->getObjectId();
2273 oldIdNewIdBoxes[idcB]=idBox;
2274 cont = _controllers[idBox];
2275 GBlackBoxModel* newbox = (GBlackBoxModel*)cont->getModel();
2276 newbox->setInicPoint(xInic,yInic,zInic);
2277 int num = newbox->getNumInputPorts();
2278 for(int j=0;j<num;j++)
2280 newbox->setValueToInputPort(j,copyBox->getValueInputPort(j));
2282 newbox->notifyObservers(_idManager);
2284 else if(type==GCONNECTOR)
2286 int idCon = cont->getId();
2287 connections.push_back(idCon);
2292 for(int i = 0 ;i<(int)connections.size();i++)
2294 int objId = connections[i];
2295 GObjectController *cont = objectsMap[objId];
2296 GConnectorModel* connectModel = (GConnectorModel*)cont->getModel();
2298 GPortModel* startPort = connectModel->getStartPort();
2299 int startPortIndex = startPort->getPosInBox();
2300 GPortModel* endPort = connectModel->getEndPort();
2301 int endPortIndex = endPort->getPosInBox();
2303 GBlackBoxModel* startPortParentBox = (GBlackBoxModel*)startPort->getParentBox();
2304 GBlackBoxModel* endPortParentBox = (GBlackBoxModel*)endPort->getParentBox();
2306 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2307 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2309 GBlackBoxModel* newStartBox = (GBlackBoxModel*)_controllers[idNewStartBox]->getModel();
2310 GBlackBoxModel* newEndBox = (GBlackBoxModel*)_controllers[idNewEndBox]->getModel();
2312 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2313 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2315 // Creates connection
2316 int idCon = createGConnector(newStartPort);
2317 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
2318 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
2319 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
2320 tempp->endContourCreation();
2321 conMod->setEndPort(newEndPort);
2322 conView->updateStartEndPoints();
2325 std::map<int, int>::iterator itIds;
2326 for(itIds = oldIdNewIdBoxes.begin(); itIds != oldIdNewIdBoxes.end(); ++itIds)
2328 int idOld = itIds->first;
2329 int idNew = itIds->second;
2331 GBlackBoxModel* oldBox = (GBlackBoxModel*)objectsMap[idOld]->getModel();
2332 GBlackBoxModel* newBox = (GBlackBoxModel*)_controllers[idNew]->getModel();
2334 std::vector<int> oldInputConnections = oldBox->getConnectedInputs();
2335 std::vector<int> oldOutputConnections = oldBox->getConnectedOutputs();
2336 std::vector<int> newInputConnections = newBox->getConnectedInputs();
2337 std::vector<int> newOutputConnections = newBox->getConnectedOutputs();
2339 for(int k = 0; k<(int)oldInputConnections.size();k++)
2342 //EED int toCreate=-1;
2343 for(int l = 0; l<(int)newInputConnections.size() && !exist;l++)
2345 if(oldInputConnections[k]==newInputConnections[l])
2353 //Create complex input
2354 int posInBox = oldInputConnections[k];
2355 GPortModel* inputPort = oldBox->getInputPort(posInBox);
2356 std::string inputPortName = inputPort->getBBTKName();
2357 int idInputPort = createGComplexBoxInputPort(inputPortName);
2358 GObjectController *cont = _controllers[idInputPort];
2359 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
2361 inputPort->getInicPoint(xIn,yIn,zIn);
2363 cbmod->setInicPoint(xIn,yIn,zIn);
2364 cbmod->notifyObservers(_idManager);
2366 GPortModel* inputPortEnd = newBox->getInputPort(posInBox);
2368 // Creates connection
2369 int idCon = createGConnector(cbmod->getOutputPort(0));
2370 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
2371 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
2372 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
2373 tempp->endContourCreation();
2374 conMod->setEndPort(inputPortEnd);
2375 conView->updateStartEndPoints();
2382 for(int k = 0; k<(int)oldOutputConnections.size();k++)
2385 //EED int toCreate=-1;
2386 for(int l = 0; l<(int)newOutputConnections.size() && !exist;l++)
2388 if(oldOutputConnections[k]==newOutputConnections[l])
2396 //Create complex output
2397 int posInBox = oldOutputConnections[k];
2398 GPortModel* outputPort = oldBox->getOutputPort(posInBox);
2399 std::string outputPortName = outputPort->getBBTKName();
2400 int idOutputPort = createGComplexBoxOutputPort(outputPortName);
2401 GObjectController *cont = _controllers[idOutputPort];
2402 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
2404 outputPort->getInicPoint(xIn,yIn,zIn);
2406 cbmod->setInicPoint(xIn,yIn,zIn);
2407 cbmod->notifyObservers(_idManager);
2409 GPortModel* outputPortEnd = newBox->getOutputPort(posInBox);
2411 // Creates connection
2412 int idCon = createGConnector(outputPortEnd);
2413 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
2414 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
2415 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
2416 tempp->endContourCreation();
2417 conMod->setEndPort(cbmod->getInputPort(0));
2418 conView->updateStartEndPoints();
2429 //=========================================================================
2431 } // EO namespace bbtk