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();
137 double w=100,h=10,b=h/15,t=3;
138 _pts->SetNumberOfPoints(21);
139 _pts->InsertPoint(0, xInic+w*0.33-t/2 , yInic , zInic );
140 _pts->InsertPoint(1, xInic+w*0.33 , yInic-t , zInic );
141 _pts->InsertPoint(2, xInic+w*0.33+t/2 , yInic , zInic );
142 _pts->InsertPoint(3, xInic+w*0.33+t/2 , yInic , zInic );
143 _pts->InsertPoint(4, xInic+w-b*4 , yInic+b*0 , zInic );
145 _pts->InsertPoint( 5, xInic+w-b*4 , yInic+b*0 , zInic );
146 _pts->InsertPoint( 6, xInic+w-b*2 , yInic+b*1 , zInic );
147 _pts->InsertPoint( 7, xInic+w-b*1 , yInic+b*2 , zInic );
148 _pts->InsertPoint( 8, xInic+w-b*0 , yInic+b*4 , zInic );
150 _pts->InsertPoint( 9, xInic+w-b*0 , yInic+h-b*4 , zInic );
151 _pts->InsertPoint(10, xInic+w-b*1 , yInic+h-b*2 , zInic );
152 _pts->InsertPoint(11, xInic+w-b*2 , yInic+h-b*1 , zInic );
153 _pts->InsertPoint(12, xInic+w-b*4 , yInic+h-b*0 , zInic );
155 _pts->InsertPoint(13, xInic+b*4 , yInic+h-b*0 , zInic );
156 _pts->InsertPoint(14, xInic+b*2 , yInic+h-b*1 , zInic );
157 _pts->InsertPoint(15, xInic+b*1 , yInic+h-b*2 , zInic );
158 _pts->InsertPoint(16, xInic+b*0 , yInic+h-b*4 , zInic );
160 _pts->InsertPoint(17, xInic+b*0 , yInic+b*4 , zInic );
161 _pts->InsertPoint(18, xInic+b*1 , yInic+b*2 , zInic );
162 _pts->InsertPoint(19, xInic+b*2 , yInic+b*1 , zInic );
163 _pts->InsertPoint(20, xInic+b*4 , yInic+b*0 , zInic );
165 aPolygon->GetPointIds()->SetNumberOfIds(21);
166 for (int i=0;i<21; i++)
168 aPolygon->GetPointIds()->SetId(i, i);
171 vtkUnstructuredGrid *aPolygonGrid = vtkUnstructuredGrid::New();
172 aPolygonGrid->Allocate(1, 1);
173 aPolygonGrid->InsertNextCell(aPolygon->GetCellType(), aPolygon->GetPointIds());
174 aPolygonGrid->SetPoints(_pts);
175 _aPolygonMapper = vtkDataSetMapper::New();
176 _aPolygonMapper->SetInput(aPolygonGrid);
177 _fillObjectActor->SetMapper(_aPolygonMapper);
178 _fillObjectActor->GetProperty()->SetColor(PORTFILL_NH_R,PORTFILL_NH_G,PORTFILL_NH_B);
179 _fillObjectActor->GetProperty()->SetOpacity(0);
180 _aPolygonMapper->Modified();
182 _baseView->GetRenderer()->AddActor( _fillObjectActor );
185 //=========================================================================
187 std::string wxVtkSceneManager::generateANewNameForABox()
189 std::stringstream boxname;
192 boxname << "Box0" << _numBoxes;
194 boxname << "Box" << _numBoxes;
197 return boxname.str();
200 //=========================================================================
202 std::string wxVtkSceneManager::findANewNameForABox()
204 std::string boxname=generateANewNameForABox();
206 while (boxExist(boxname)==true)
208 boxname=generateANewNameForABox();
214 //=========================================================================
215 void wxVtkSceneManager::configGBlackBox(int idBox, double xIn, double yIn, double zIn, std::string name, bool boxExecutable,double xEn,double yEn,double zEn)
217 GObjectController *cont = _controllers[idBox];
218 GBlackBoxModel *bbmod = (GBlackBoxModel*)cont->getModel();
219 bbmod->setBBTKName(name);
220 bbmod->setInicPoint(xIn,yIn,zIn);
221 bbmod->setFinalPoint(xEn,yEn,zEn);
222 bbmod->setExecutable(boxExecutable);
224 bbmod->notifyObservers(_idManager);
229 //=========================================================================
231 int wxVtkSceneManager::createGBlackBox(int x, int y, std::string packageName, std::string boxType)
233 _worldState = NOTHING_HAPPENS;
234 //EED int windowWidth = _baseView->GetRenWin()->GetSize()[0];
235 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
237 int type = GBLACKBOX;
239 //Create the MVC Objects
241 GBlackBoxModel *model = (GBlackBoxModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
242 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
243 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
245 BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxType);
247 //Prepares the initial model
248 //The coordinates obtained are the following. Top-Left:x=0,y=0 Bottom-Right:x=width,y=height
251 double yy = windowHeight-y;
253 //z value is not important yet, because it is only used a parallel projection
255 _baseView->TransCoordScreenToWorld(xx,yy,zz);
256 model->setInicPoint(xx,yy,zz);
258 std::stringstream stream;
260 std::string newBoxName;
261 newBoxName = findANewNameForABox();
264 stream << newBoxName;
266 std::string arraystring = stream.str();
268 model->setBBTKName(arraystring);
269 model->setBBTKType(boxType);
270 model->setBBTKPackage(packageName);
272 model->addObserver(view);
273 model->addObserver(this);
275 //Iterate and create the input ports
276 std::map<std::string, BlackBoxInputDescriptor*> descriptorInMap = descriptor->GetInputDescriptorMap();
277 std::map<std::string, BlackBoxInputDescriptor*>::iterator itInput;
280 for(itInput = descriptorInMap.begin(); itInput != descriptorInMap.end(); ++itInput)
282 BlackBoxInputDescriptor *desc = itInput->second;
283 createGInputPort(GINPUTPORT,i,model,desc);
287 //Iterate and create the output ports
288 std::map<std::string, BlackBoxOutputDescriptor*> descriptorOutMap = descriptor->GetOutputDescriptorMap();
289 std::map<std::string, BlackBoxOutputDescriptor*>::iterator itOutput;
292 for(itOutput = descriptorOutMap.begin();itOutput != descriptorOutMap.end(); ++itOutput)
294 BlackBoxOutputDescriptor *desc = itOutput->second;
295 createGOutputPort(GOUTPUTPORT,i,model,desc);
300 //Associates the view with the correspondent renderer and the model.
301 //(NOTE: Refresh is only made by the view)
302 view->setModel(model);
303 view->setBaseView(_baseView);
304 view->initVtkObjects();
306 //Associates the controller with the correspondent model and view
307 controller->setModelAndView(model,view);
309 //Resgiter change to the observers of the actual model
310 model->notifyObservers(_idManager);
312 int newId = addObjectController(controller);
318 //=========================================================================
320 int wxVtkSceneManager::createGComplexBoxInputPort(std::string inputName)
322 //EED int windowWidth=_baseView->GetRenWin()->GetSize()[0];
323 int windowHeight=_baseView->GetRenWin()->GetSize()[1];
325 int type = GCOMPLEXINPUTPORT;
327 //Create the MVC Objects
329 GComplexBoxPortModel *model = (GComplexBoxPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
330 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
331 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
333 //Prepares the initial model
336 double yy = windowHeight-5;
338 //z value is not important yet, because it is only used a parallel projection
340 printf("EED wxVtkSceneManager::createGComplexBoxInputPort 900-450\n");
342 _baseView->TransCoordScreenToWorld(xx,yy,zz);
343 model->setInicPoint(xx,yy,zz);
345 model->setBBTKName(inputName);
346 model->setBBTKType("ComplexInputPort");
347 model->setComplexPortType(type);
349 model->addObserver(view);
350 model->addObserver(this);
352 //create the output port
353 GPortController* portController = createGPort(GOUTPUTPORT,inputName,"ComplexInputPort",0,model);
354 model->addOutputPort((GPortModel*)portController->getModel());
356 //Associates the view with the correspondent renderer and the model.
357 //(NOTE: Refresh is only made by the view)
358 view->setModel(model);
359 view->setBaseView(_baseView);
360 view->initVtkObjects();
362 //Associates the controller with the correspondent model and view
363 controller->setModelAndView(model,view);
365 //Resgiter change to the observers of the actual model
366 model->notifyObservers(_idManager);
368 int newId = addObjectController(controller);
372 //=========================================================================
374 int wxVtkSceneManager::createGComplexBoxOutputPort(std::string outputName)
376 //EED int windowWidth=_baseView->GetRenWin()->GetSize()[0];
377 int windowHeight=_baseView->GetRenWin()->GetSize()[1];
379 int type = GCOMPLEXOUTPUTPORT;
381 //Create the MVC Objects
383 GComplexBoxPortModel *model = (GComplexBoxPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
384 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
385 GObjectController *controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
387 //Prepares the initial model
390 double yy = windowHeight-5;
392 //z value is not important yet, because it is only used a parallel projection
395 printf("EED wxVtkSceneManager::createGComplexBoxOutputPort 900-450\n");
397 _baseView->TransCoordScreenToWorld(xx,yy,zz);
398 model->setInicPoint(xx,yy,zz);
400 model->setBBTKName(outputName);
401 model->setBBTKType("ComplexOutputPort");
402 model->setComplexPortType(type);
404 model->addObserver(view);
405 model->addObserver(this);
407 //create the output port
408 GPortController* portController = createGPort(GINPUTPORT,outputName,"ComplexInputPort",0,model);
409 model->addInputPort((GPortModel*)portController->getModel());
411 //Associates the view with the correspondent renderer and the model.
412 //(NOTE: Refresh is only made by the view)
413 view->setModel(model);
414 view->setBaseView(_baseView);
415 view->initVtkObjects();
417 //Associates the controller with the correspondent model and view
418 controller->setModelAndView(model,view);
420 //Resgiter change to the observers of the actual model
421 model->notifyObservers(_idManager);
423 int newId = addObjectController(controller);
427 //=========================================================================
429 int wxVtkSceneManager::createGInputPort(int portType, int posinBox,GBoxModel *blackBox, BlackBoxInputDescriptor *desc)
431 GPortController* portController = createGPort(portType,desc->GetName(),desc->GetTypeName(),posinBox,blackBox);
432 blackBox->addInputPort((GPortModel*)portController->getModel());
433 return portController->getId();
436 //=========================================================================
438 int wxVtkSceneManager::createGOutputPort(int portType, int posinBox,GBoxModel *blackBox, BlackBoxOutputDescriptor *desc)
440 GPortController* portController = createGPort(portType,desc->GetName(),desc->GetTypeName(),posinBox,blackBox);
441 blackBox->addOutputPort((GPortModel*)portController->getModel());
442 return portController->getId();
445 //=========================================================================
447 GPortController* wxVtkSceneManager::createGPort(int portType,std::string bbtkName, std::string bbtkType, int posInBox,GBoxModel *blackBox)
451 //Create the MVC Objects
452 GPortModel *model = (GPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
453 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
454 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
456 model->registerInBox(blackBox,portType, posInBox);
458 model->setBBTKType(bbtkType);
459 model->setBBTKName(bbtkName);
461 model->addObserver(view);
462 model->addObserver(this);
464 //Associates the view with the correspondent renderer and the model.
465 //(NOTE: Refresh is only made by the view)
466 view->setModel(model);
467 view->setBaseView(_baseView);
468 view->initVtkObjects();
470 //Associates the controller with the correspondent model and view
471 controller->setModelAndView(model,view);
473 model->notifyObservers(_idManager);
475 addObjectController(controller);
477 return (GPortController*)controller;
480 //=========================================================================
482 int wxVtkSceneManager::createGConnector(GPortModel* startPort)
484 int type = GCONNECTOR;
486 manualConnectorContourController* manContourControl = new manualConnectorContourController();
487 manualConnectorContourView* manContourView = new manualConnectorContourView();
488 manualContourModel* manContourModel = new manualContourModel();
490 GConnectorController* connectorcontroller = new GConnectorController();
491 GConnectorModel* connectorModel = new GConnectorModel();
492 vtkGConnectorView* connectorView = new vtkGConnectorView();
493 connectorModel->setGObjectType(type);
495 manContourModel->SetCloseContour(false);
496 connectorModel->setStartPort(startPort);
498 manContourView->SetModel( manContourModel );
499 manContourView->SetWxVtkBaseView( _baseView );
500 manContourView->SetRange( 0.5 );
501 manContourView->SetZ( 900 );
503 manContourView->SetColorNormalContour(0, 0, 1);
504 manContourView->SetColorEditContour(0.5, 0.5, 0.5);
505 manContourView->SetColorSelectContour(1, 0.8, 0);
506 manContourView->SetWidthLine(1);
507 manContourView->SetShowText(false);
509 manContourControl->SetModelView( manContourModel , manContourView );
511 manContourControl->CreateNewManualContour();
513 manContourView->RefreshContour();
517 connectorModel->getInicPoint(x,y,z);
519 manContourControl->SetState(1);
520 manContourModel->SetCloseContour(false);
522 manContourModel->AddPoint(x,y,z);
523 manContourView->AddPoint();
525 manContourModel->AddPoint(x,y,z);
526 manContourView->AddPoint();
528 int bak= manContourControl->GetNumberOfPointsManualContour() - 1;
529 manContourControl->_bakIdPoint=bak;
530 manContourView->Refresh();
532 manContourControl->SetMoving( false );
534 connectorcontroller->setModelAndView(connectorModel,connectorView);
536 int newId = addObjectController(connectorcontroller);
538 connectorcontroller->setManualContourController(manContourControl);
539 connectorModel->setManualContourModel(manContourModel);
540 connectorView->setManualContourView(manContourView);
541 connectorView->setModel(connectorModel);
542 connectorView->setBaseView(_baseView);
545 connectorModel->addObserver(connectorView);
546 connectorModel->addObserver(this);
551 //=========================================================================
553 void wxVtkSceneManager::registerController(InteractorStyleMaracas *param)
555 vtkInteractorStyleBaseView* baseViewControlManager = (vtkInteractorStyleBaseView*)_baseView->GetInteractorStyleBaseView();
556 baseViewControlManager->AddInteractorStyleMaracas( param );
559 //=========================================================================
561 void wxVtkSceneManager::unregisterController(InteractorStyleMaracas *param)
563 vtkInteractorStyleBaseView* baseViewControlManager = (vtkInteractorStyleBaseView*)_baseView->GetInteractorStyleBaseView();
564 baseViewControlManager->RemoveInteractorStyleMaracas( param );
567 //=========================================================================
569 vtkRenderer* wxVtkSceneManager::getRenderer()
571 return _baseView->GetRenderer();
574 //=========================================================================
576 vtkRenderWindow* wxVtkSceneManager::getRenderWindow()
578 return _baseView->GetRenWin();
580 //=========================================================================
583 //=========================================================================
584 int wxVtkSceneManager::GetIndexInSelected(int idControler)
587 for (int i=0; i<(int)_selectedObjects.size(); i++)
589 if(_selectedObjects[i]==idControler)
597 //=========================================================================
599 void wxVtkSceneManager::update(int idController,int command)
601 printf("EED wxVtkSceneManager::update 1 \n" );
603 if(command != NO_COMMAND)
605 if(command == ADD_TO_SELECTED)
607 //EEDBorrame GObjectController* cont = _controllers[idController];
609 if (GetIndexInSelected(idController)==-1)
611 _selectedObjects.push_back(idController);
615 // bool foundID=false;
616 // for (int i=0; i<(int)_selectedObjects.size() && foundID==false; i++)
618 // if(_selectedObjects[i]==idController)
625 // _selectedObjects.push_back(idController);
628 }else if(command == REMOVE_FROM_SELECTED)
630 int index=GetIndexInSelected(idController);
633 _selectedObjects.erase( _selectedObjects.begin()+index );
636 else if(command == INIT_CREATION_CONTOUR)
638 _worldState = INIT_CREATION_CONTOUR;
639 GObjectController* cont = _controllers[idController];
640 GPortModel* startOutputPort = (GPortModel*)cont->getModel();
643 // The last one is the controller of the connector
644 std::map<int, GObjectController*>::iterator it2;
646 for(it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
648 GObjectController *cont = it2->second;
649 if(cont->getGObjectType() == GPORT )
651 GPortModel* port = (GPortModel*)cont->getModel();
652 if(port->getPortType()==GINPUTPORT)
654 cont->SetActive(true);
658 cont->getView()->setState(NOTHING_HAPPENS);
659 cont->getModel()->notifyObservers(_idManager);
660 cont->SetActive(false);
665 cont->getView()->setState(NOTHING_HAPPENS);
666 cont->getModel()->notifyObservers(_idManager);
667 cont->SetActive(false);
671 _selectedObjects.clear();
673 _idConnectionInCreation=createGConnector(startOutputPort);
676 else if(command == FIN_CREATION_CONTOUR && _worldState == INIT_CREATION_CONTOUR)
678 _worldState = NOTHING_HAPPENS;
679 //int id = _controllers.size()-1;
680 GObjectController* cont = _controllers[_idConnectionInCreation];
681 GConnectorModel* modelContour = (GConnectorModel*)cont->getModel();
683 GObjectController* finPort = _controllers[idController];
684 if(finPort->getGObjectType() == GPORT)
686 GPortModel* modelPort = (GPortModel*)finPort->getModel();
687 modelContour->setEndPort(modelPort);
690 manualConnectorContourController* manCont = ((GConnectorController*)cont)->getManualContourController();
691 manualConnectorContourView* connView = (manualConnectorContourView*)manCont->GetManualViewBaseContour();
694 std::map<int, GObjectController*>::iterator it2;
696 for(it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
698 GObjectController *cont = it2->second;
699 if(cont->getView()!=NULL)
701 cont->getView()->setState(NOTHING_HAPPENS);
702 cont->getModel()->notifyObservers(_idManager);
704 cont->SetActive(true);
710 printf("EED wxVtkSceneManager::update 2 \n" );
714 //=========================================================================
716 bool wxVtkSceneManager::OnMouseMove()
719 bool okStatusMessage = false;
720 bool okPortMessage = false;
721 wxVTKRenderWindowInteractor *wxVTKiren;
722 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
723 wxVTKiren->GetEventPosition(X,Y);
726 if(_worldState == DRAG_OBJECTS)
728 for (int i=0; i<(int)_selectedObjects.size(); i++)
730 int id = _selectedObjects[i];
731 GObjectController* cont = _controllers[id];
734 cont->getView()->setStartDragging(true);
736 cont->getView()->moveObject(X,Y);
737 cont->getView()->setState(DRAG);
738 cont->getModel()->notifyObservers(_idManager);
741 std::map<int, GObjectController*>::iterator it;
743 for(it = _controllers.begin(); it != _controllers.end(); ++it)
745 GObjectController *desc = it->second;
746 if(desc->getGObjectType()==GCONNECTOR)
748 vtkGConnectorView* vconn = (vtkGConnectorView*)desc->getView();
749 vconn->updateStartEndPoints();
753 _startDragging=false;
756 else if(_worldState == NOTHING_HAPPENS || _worldState == INIT_CREATION_CONTOUR)
758 std::map<int, GObjectController*>::iterator it;
760 for(it = _controllers.begin(); it != _controllers.end(); ++it)
762 GObjectController *desc = it->second;
763 int type = desc->getGObjectType();
764 int state = desc->getView()->getState();
765 desc->getModel()->getCenter(px,py,pz);
767 if(state == HIGHLIGHTED){
768 okStatusMessage = true;
769 updateStatusBar(desc->getStatusText());
772 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
773 _parent->displayBlackBoxInfo(mod->getBBTKPackage(),mod->getBBTKType());
778 okPortMessage = true;
780 _textActor->SetInput( desc->getStatusText().c_str() );
781 _textActor->SetScale(0.1);
782 _textActor->SetPosition( px-25 ,py+1 , pz+2 );
788 _fillObjectActor->SetScale(1);
789 _fillObjectActor->GetProperty()->SetOpacity(0.50);
790 _fillObjectActor->SetPosition(px,py,1);
791 _aPolygonMapper->Modified();
794 } // for controllers it
797 if (okStatusMessage==false)
802 if (okPortMessage==false)
804 _textActor->SetScale(0.0001);
805 _fillObjectActor->SetScale(0.0001);
812 //=========================================================================
814 bool wxVtkSceneManager::OnLeftButtonDown()
816 if(_worldState==INIT_CREATION_CONTOUR)
818 bool isOverPort=false;
819 std::map<int, GObjectController*>::iterator it;
820 for(it = _controllers.begin(); it != _controllers.end() && isOverPort==false; ++it)
822 GObjectController *desc = it->second;
823 if(desc->getGObjectType()==GPORT)
825 GPortModel* portmod=(GPortModel*)desc->getModel();
826 vtkGObjectView* portView=desc->getView();
827 if(portmod->getPortType()==GINPUTPORT && portView->getState()==HIGHLIGHTED)
834 if(isOverPort==false)
836 _worldState=NOTHING_HAPPENS;
837 //int lastId = _controllers.size()-1;
838 //EED2Oct2010 GConnectorController *connector = (GConnectorController*)_controllers[_controllers.size()-1];
839 GConnectorController *connector = (GConnectorController*)_controllers[_idConnectionInCreation];
841 connector->removeFromScene();
842 unregisterController(connector);
843 _controllers.erase(_controllers.size()-1);
845 for(it = _controllers.begin(); it != _controllers.end(); ++it)
847 GObjectController *desc = it->second;
848 desc->SetActive(true);
849 desc->getView()->setState(NOTHING_HAPPENS);
850 desc->getModel()->notifyObservers(_idManager);
855 _worldState = DRAG_OBJECTS;
856 _startDragging = true;
859 printf("EED wxVtkSceneManager::OnLeftButtonDown 1 \n" );
862 int ctrlkey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
863 GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
865 if (GetGBlackBoxControlerPointedByMouse()!=NULL)
867 int state=cont->getView()->getState() ;
868 if( (ctrlkey==0) && (state==HIGHLIGHTED) )
870 UnSelectBlackBoxes();
875 for (int i = 0; i < (int)_selectedObjects.size(); i++)
877 int id = _selectedObjects[i];
878 GObjectController* cont = _controllers[id];
879 cont->getView()->setState(DRAG);
880 cont->getModel()->notifyObservers(_idManager);
883 printf("EED wxVtkSceneManager::OnLeftButtonDown 2 \n" );
888 //=========================================================================
890 bool wxVtkSceneManager::OnLeftButtonUp()
892 if(_worldState == DRAG_OBJECTS)
894 _worldState = NOTHING_HAPPENS;
896 for (int i = 0; i < (int)_selectedObjects.size(); i++)
898 int id = _selectedObjects[i];
899 GObjectController* cont = _controllers[id];
900 cont->getView()->setState(SELECTED);
901 cont->getModel()->notifyObservers(_idManager);
907 //=========================================================================
909 bool wxVtkSceneManager::OnRightButtonUp()
911 if(_worldState==INIT_CREATION_CONTOUR)
913 _worldState=NOTHING_HAPPENS;
914 //int lastId = _controllers.size()-1;
916 GConnectorController *connector = (GConnectorController*)_controllers[_idConnectionInCreation];
917 connector->removeFromScene();
918 unregisterController(connector);
919 _controllers.erase(_idConnectionInCreation);
921 std::map<int, GObjectController*>::iterator it;
922 for(it = _controllers.begin(); it != _controllers.end(); ++it)
924 GObjectController *desc = it->second;
925 desc->SetActive(true);
926 desc->getView()->setState(NOTHING_HAPPENS);
927 desc->getModel()->notifyObservers(_idManager);
932 for (int i = 0; i < (int)_selectedObjects.size(); i++)
934 int id = _selectedObjects[i];
935 GObjectController* cont = _controllers[id];
936 cont->SetActive(true);
937 cont->getView()->setState(NOTHING_HAPPENS);
938 cont->getModel()->notifyObservers(_idManager);
941 _selectedObjects.clear();
946 //=========================================================================
948 GObjectController *wxVtkSceneManager::GetGBlackBoxControlerPointedByMouse()
950 GObjectController *result=NULL;
952 wxVTKRenderWindowInteractor *wxVTKiren;
953 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
954 wxVTKiren->GetEventPosition(X,Y);
956 std::map<int, GObjectController*>::iterator it;
958 for(it = _controllers.begin(); it != _controllers.end() ; ++it)
960 GObjectController *cont = it->second;
961 int type = cont->getGObjectType();
963 if( cont->getView()->isPointInside(X,Y)==true )
969 } // if isPointInside
974 //=========================================================================
975 bool wxVtkSceneManager::UnSelectBlackBoxes()
977 for (int i=0; i< (int)_selectedObjects.size(); i++)
979 int id = _selectedObjects[i];
980 GObjectController* control = _controllers[id];
981 control->getView()->setState(NOTHING_HAPPENS);
982 }// for _selectedObjects
983 _selectedObjects.clear();
986 //=========================================================================
987 bool wxVtkSceneManager::OnLeftDClick()
989 GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
992 UnSelectBlackBoxes();
993 _parent->editBlackBox( (GBlackBoxModel*)cont->getModel() );
999 wxVTKRenderWindowInteractor *wxVTKiren;
1000 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
1001 wxVTKiren->GetEventPosition(X,Y);
1003 std::map<int, GObjectController*>::iterator it;
1005 bool clickOnObject = false;
1007 for(it = _controllers.begin(); it != _controllers.end() && clickOnObject==false; ++it)
1009 GObjectController *cont = it->second;
1010 int type = cont->getGObjectType();
1012 if(cont->getView()->isPointInside(X,Y))
1016 for (int i=0; i< (int)_selectedObjects.size(); i++)
1018 int id = _selectedObjects[i];
1019 GObjectController* control = _controllers[id];
1020 control->getView()->setState(NOTHING_HAPPENS);
1022 _selectedObjects.clear();
1024 GBlackBoxModel *bbmodel = (GBlackBoxModel*)cont->getModel();
1025 _parent->editBlackBox(bbmodel);
1027 clickOnObject = true;
1031 if(clickOnObject==false)
1033 //_parent->editDiagramParameters(this);
1039 //=========================================================================
1041 bool wxVtkSceneManager::OnChar()
1043 char keyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
1045 // KeyCode 127 : Delete Key
1046 // KeyCode 8 : Backspace Key
1047 if(keyCode == 8 || keyCode == 127)
1049 if(_selectedObjects.size()>0)
1051 for(int i=0;i<(int)_selectedObjects.size();i++)
1053 int id = _selectedObjects[i];
1054 std::map<int,GObjectController*>::iterator it;
1055 it = _controllers.find(id);
1056 if (it!=_controllers.end())
1061 _selectedObjects.clear();
1068 //=========================================================================
1070 void wxVtkSceneManager::AddControlerToBeRemove(std::vector<int> *controllersToRemove, int id)
1075 for(i=0 ; i < (int)controllersToRemove->size() ; i++ )
1077 if (id == (*controllersToRemove)[i] )
1085 controllersToRemove->push_back( id );
1090 //=========================================================================
1092 void wxVtkSceneManager::deleteObject(int id)
1094 GObjectController *control = _controllers[id];
1095 std::vector<int> controllersToRemove;
1097 if(control->getGObjectType()==GBLACKBOX || control->getGObjectType()==GCOMPLEXINPUTPORT || control->getGObjectType()==GCOMPLEXOUTPUTPORT)
1099 GBoxModel *bbmod = (GBoxModel*)control->getModel();
1100 std::vector<GPortModel*> inputs = bbmod->getInputPorts();
1102 bool boxConnected = false;
1104 // Add box input controllers to be removed
1105 for(int i = 0;i< (int)inputs.size();i++)
1107 AddControlerToBeRemove( &controllersToRemove, inputs[i]->getObjectId() );
1108 if(inputs[i]->isConnected())
1110 boxConnected = true;
1114 std::vector<GPortModel*> outputs = bbmod->getOutputPorts();
1116 // Add box output controllers to be removed
1117 for(int i = 0;i<(int)outputs.size();i++)
1119 AddControlerToBeRemove( &controllersToRemove, outputs[i]->getObjectId() );
1120 if(outputs[i]->isConnected())
1122 boxConnected = true;
1126 // Add connection controllers to be removed
1127 std::map<int, GObjectController*>::iterator it;
1128 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1130 GObjectController *cont = it->second;
1131 int type = cont->getGObjectType();
1132 if(type==GCONNECTOR)
1134 GConnectorModel *conMod = (GConnectorModel*)cont->getModel();
1135 if(conMod->getStartPort()!=NULL && conMod->getStartPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
1137 AddControlerToBeRemove( &controllersToRemove, conMod->getObjectId() );
1139 if(conMod->getEndPort()!=NULL && conMod->getEndPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
1141 AddControlerToBeRemove( &controllersToRemove, conMod->getObjectId() );
1146 // Add box controller to be removed
1147 AddControlerToBeRemove( &controllersToRemove, bbmod->getObjectId() );
1149 else if(control->getGObjectType()==GCONNECTOR)
1151 GConnectorModel *conMod = (GConnectorModel*)control->getModel();
1152 AddControlerToBeRemove( &controllersToRemove, conMod->getObjectId() );
1156 std::map<int,GObjectController*>::iterator it;
1158 for(int i = 0;i<(int)controllersToRemove.size();i++)
1160 int key = controllersToRemove[i];
1161 it = _controllers.find( key );
1162 GObjectController *cont = _controllers[ key ];
1165 cont->removeFromScene();
1166 unregisterController((InteractorStyleMaracas*)cont);
1167 _controllers.erase(it);
1172 //=========================================================================
1174 void wxVtkSceneManager::displayBlackBoxInfo(std::string packageName, std::string boxName)
1176 _parent->displayBlackBoxInfo(packageName,boxName);
1179 //=========================================================================
1181 void wxVtkSceneManager::updateStatusBar(std::string textStatus)
1183 _parent->updateStatusBar(textStatus);
1187 //=========================================================================
1188 std::string wxVtkSceneManager::LineNumber(bool withLineNumber, int &value)
1190 std::string result="";
1191 if (withLineNumber==true)
1194 stringstream StrStream;
1196 std::string strValue=StrStream.str();
1200 }else if (value<100)
1205 result+=strValue+": ";
1209 //=========================================================================
1211 std::string wxVtkSceneManager::getDiagramBBS(bool wln)
1213 bool existsExec=false;
1215 std::vector<std::string> packages;
1216 std::vector<int> boxes;
1217 std::vector<int> connections;
1218 std::vector<int> execBoxes;
1220 std::map<int, GObjectController*>::iterator it;
1222 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1224 GObjectController *desc = it->second;
1225 int type = desc->getGObjectType();
1229 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
1231 std::string pkg = mod->getBBTKPackage();
1232 bool existsPkg = false;
1233 for(int t = 0;t< (int)packages.size() && existsPkg == false;t++)
1235 if(packages[t]==pkg)
1242 packages.push_back(pkg);
1246 boxes.push_back(it->first);
1247 if(mod->isExecutable())
1249 execBoxes.push_back(it->first);
1253 else if(type==GCONNECTOR)
1255 connections.push_back(it->first);
1260 std::string script = "";
1261 script+=LineNumber(wln,lnNmbr)+"# BBTK GEditor Script\n";
1262 script+=LineNumber(wln,lnNmbr)+"# ----------------------\n";
1263 script+=LineNumber(wln,lnNmbr)+"\n";
1266 script+=LineNumber(wln,lnNmbr)+"include std\n"; // EED
1267 script+=LineNumber(wln,lnNmbr)+"include itkvtk\n"; // EED
1269 for(i = 0; i< (int)packages.size();i++)
1271 script+=LineNumber(wln,lnNmbr);
1273 script+=packages[i];
1277 script+=LineNumber(wln,lnNmbr);
1280 // script+="include std\n"; // JPR
1282 for(i = 0; i < (int)boxes.size();i++)
1284 script+=LineNumber(wln,lnNmbr);
1287 GObjectController *control = _controllers[id];
1288 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1290 script+=model->getBBTKType();
1292 script+=model->getBBTKName();
1295 std::vector<GPortModel*> inputs = model->getInputPorts();
1296 for(int j = 0; j < (int)inputs.size();j++)
1298 GPortModel* inputPort = inputs[j];
1299 if(inputPort->isValueSet())
1301 script+=LineNumber(wln,lnNmbr);
1303 script+=model->getBBTKName();
1305 script+=inputPort->getBBTKName();
1307 script+=inputPort->getValue();
1312 script+=LineNumber(wln,lnNmbr);
1317 script+=LineNumber(wln,lnNmbr);
1320 for(i = 0; i<(int)connections.size();i++)
1322 script+=LineNumber(wln,lnNmbr);
1324 int id = connections[i];
1325 GObjectController *control = _controllers[id];
1326 GConnectorModel *model = (GConnectorModel*)control->getModel();
1328 //Start Connection info
1329 GPortModel *start = model->getStartPort();
1330 script+=start->getParentBox()->getBBTKName();
1332 script+=start->getBBTKName();
1336 //End Connection info
1337 GPortModel *end = model->getEndPort();
1338 script+=end->getParentBox()->getBBTKName();
1340 script+=end->getBBTKName();
1345 script+=LineNumber(wln,lnNmbr);
1347 for(i = 0; i<(int)execBoxes.size();i++)
1349 script+=LineNumber(wln,lnNmbr);
1351 int id = execBoxes[i];
1352 GObjectController *control = _controllers[id];
1353 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1355 script+=model->getBBTKName();
1364 //=========================================================================
1366 std::string wxVtkSceneManager::saveComplexBoxBBS(std::string cbName,std::string cbAuthor,std::string cbCategory,std::string cbDescription)
1369 std::vector<std::string> packages;
1370 std::vector<int> boxes;
1371 std::vector<int> connections;
1372 std::vector<int> execBoxes;
1374 std::map<int, GObjectController*>::iterator it;
1376 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1378 GObjectController *desc = it->second;
1379 int type = desc->getGObjectType();
1383 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
1385 std::string pkg = mod->getBBTKPackage();
1386 bool existsPkg = false;
1387 for(int t = 0;t<(int)packages.size() && existsPkg == false;t++)
1389 if(packages[t]==pkg)
1396 packages.push_back(pkg);
1400 boxes.push_back(it->first);
1401 if(mod->isExecutable())
1403 execBoxes.push_back(it->first);
1406 else if(type==GCONNECTOR)
1408 connections.push_back(it->first);
1412 std::string script = "";
1414 script+="include std\n"; // EED
1415 script+="include itkvtk\n"; // EED
1417 for(i = 0; i<(int)packages.size();i++)
1420 script+=packages[i];
1425 // Definition of a complex box
1431 script+="author \" ";
1435 script+="description \" ";
1436 script+=cbDescription;
1441 for(i = 0; i<(int)boxes.size();i++)
1445 GObjectController *control = _controllers[id];
1446 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1448 script+=model->getBBTKType();
1450 script+=model->getBBTKName();
1453 std::vector<GPortModel*> inputs = model->getInputPorts();
1454 for(int j = 0; j<(int)inputs.size();j++)
1456 GPortModel* inputPort = inputs[j];
1457 if(inputPort->isValueSet())
1460 script+=model->getBBTKName();
1462 script+=inputPort->getBBTKName();
1464 script+=inputPort->getValue();
1472 // Create connections in the script. If the connection is made with a complex port, it is created the input or output
1474 std::string complexInputs="";
1475 std::string complexOutputs="";
1478 for(i = 0; i<(int)connections.size();i++)
1480 int id = connections[i];
1481 GObjectController *control = _controllers[id];
1482 GConnectorModel *model = (GConnectorModel*)control->getModel();
1485 GPortModel *start = model->getStartPort();
1486 GBoxModel *startBox =start->getParentBox();
1488 GPortModel *end = model->getEndPort();
1489 GBoxModel *endBox =end->getParentBox();
1491 if(startBox->getGObjectType()==GCOMPLEXINPUTPORT)
1493 complexInputs+="input ";
1494 complexInputs+=startBox->getBBTKName();
1497 complexInputs+=endBox->getBBTKName();
1499 complexInputs+=end->getBBTKName();
1502 complexInputs+="\" \"";
1504 complexInputs+="\n";
1506 else if(endBox->getGObjectType()==GCOMPLEXOUTPUTPORT)
1508 complexOutputs+="output ";
1509 complexOutputs+=endBox->getBBTKName();
1511 complexOutputs+=" ";
1512 complexOutputs+=startBox->getBBTKName();
1513 complexOutputs+=".";
1514 complexOutputs+=start->getBBTKName();
1516 complexOutputs+=" ";
1517 complexOutputs+="\" \"";
1519 complexOutputs+="\n";
1524 script+=startBox->getBBTKName();
1526 script+=start->getBBTKName();
1530 //End Connection info
1531 script+=endBox->getBBTKName();
1533 script+=end->getBBTKName();
1541 for(i = 0; i<(int)execBoxes.size();i++)
1544 int id = execBoxes[i];
1545 GObjectController *control = _controllers[id];
1546 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1548 script+=model->getBBTKName();
1553 script+="# Complex input ports\n";
1554 script+=complexInputs;
1557 script+="# Complex output ports\n";
1558 script+=complexOutputs;
1567 //=========================================================================
1569 void wxVtkSceneManager::deleteAllBoxes()
1571 std::map<int, GObjectController*>::iterator it;
1572 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1574 GObjectController *cont = it->second;
1575 cont->removeFromScene();
1576 unregisterController((InteractorStyleMaracas*)cont);
1578 _selectedObjects.clear();
1579 _controllers.clear();
1583 //=========================================================================
1586 void wxVtkSceneManager::refresh()
1588 _baseView->Refresh();
1590 //=========================================================================
1592 void wxVtkSceneManager::refreshScene()
1594 _baseView->RefreshView();
1597 //=========================================================================
1599 void wxVtkSceneManager::centerView()
1602 _baseView->GetRenderer()->GetActiveCamera()->GetFocalPoint(temp);
1603 _baseView->GetRenderer()->GetActiveCamera()->SetFocalPoint(0,0,temp[2]);
1604 _baseView->GetRenderer()->GetActiveCamera()->GetPosition(temp);
1605 _baseView->GetRenderer()->GetActiveCamera()->SetPosition(0,0,temp[2]);
1606 _baseView->RefreshView();
1610 //=========================================================================
1612 void wxVtkSceneManager::saveDiagram(std::string &content)
1616 //Print info IF COMPLEX BOX
1617 content+="COMPLEXBOX:";
1622 //Print info complex input ports
1623 std::vector<int> inputs = getComplexInputPorts();
1624 int insize = inputs.size();
1625 content+="COMPLEXINPUTS:";
1626 sprintf (buffer, "%d", insize);
1630 for(int i = 0;i<insize;i++)
1633 GObjectController *cont = _controllers[id];
1634 cont->getModel()->save(content);
1637 //Print info complex output ports
1638 std::vector<int> outputs = getComplexOutputPorts();
1639 int outsize = outputs.size();
1640 content+="COMPLEXOUTPUTS:";
1641 sprintf (buffer, "%d", outsize);
1645 for(int i = 0;i<outsize;i++)
1647 int id = outputs[i];
1648 GObjectController *cont = _controllers[id];
1649 cont->getModel()->save(content);
1658 std::vector<int> boxes = getBlackBoxes();
1659 int bsize = boxes.size();
1661 sprintf (buffer, "%d", bsize);
1665 for(int i = 0;i<bsize;i++)
1668 GObjectController *cont = _controllers[id];
1669 cont->getModel()->save(content);
1673 std::vector<int> connections = getConnections();
1674 int csize = connections.size();
1675 content+="CONNECTIONS:";
1676 sprintf (buffer, "%d", csize);
1680 for(int i = 0;i<csize;i++)
1682 int id = connections[i];
1683 GObjectController *cont = _controllers[id];
1684 cont->getModel()->save(content);
1689 //=========================================================================
1691 void wxVtkSceneManager::loadDiagram(ifstream &inputStream)
1694 std::string line="";
1695 char delims[] = ":";
1696 char *result = NULL;
1697 getline(inputStream,line);
1700 while ( !inputStream.eof() )
1702 if(line=="" || line[0]=='#')
1704 getline(inputStream,line);
1706 else if(line=="APP_START")
1717 getline(inputStream,line);//COMPLEX_BOX:TRUE|FALSE
1719 strcpy( complex, line.c_str() );
1720 result = strtok( complex, delims );
1721 result = strtok( NULL, delims );
1722 std::string isComplexBox(result);
1724 if(isComplexBox=="TRUE")
1728 //-----------------------
1729 //- COMPLEX INPUT PORTS
1730 //-----------------------
1731 getline(inputStream,line);//COMPLEXINPUTS:num
1733 strcpy( inputs, line.c_str() );
1734 result = strtok( inputs, delims );
1735 result = strtok( NULL, delims );
1738 std::istringstream inps(result);
1741 for(int i = 0;i<numInputs;i++)
1744 getline(inputStream,line);//COMPLEX_PORT
1745 getline(inputStream,line);//name
1746 std::string inputPortName(line);
1749 getline(inputStream,line);//xInic:yInic:zInic
1751 strcpy( coord, line.c_str() );
1752 result = strtok( coord, delims );//xInic
1753 std::string xInic(result);
1754 result = strtok( NULL, delims );//yInic
1755 std::string yInic(result);
1756 result = strtok( NULL, delims );//zInic
1757 std::string zInic(result);
1759 double xIn, yIn, zIn;
1760 std::istringstream xSt(xInic);
1762 std::istringstream ySt(yInic);
1764 std::istringstream zSt(zInic);
1767 getline(inputStream,line);//FIN_COMPLEX_PORT
1769 configGComBoxInputOutputPort(true, inputPortName,xIn,yIn,zIn);
1772 } // for input complex box
1775 //-----------------------
1776 //- COMPLEX OUTPUT PORTS
1777 //-----------------------
1779 getline(inputStream,line);//COMPLEXOUTPUTS:num
1781 strcpy( outputs, line.c_str() );
1782 result = strtok( outputs, delims );
1783 result = strtok( NULL, delims );
1786 std::istringstream outps(result);
1787 outps >> numOutputs;
1789 for(int i = 0;i<numOutputs;i++)
1792 getline(inputStream,line);//COMPLEX_PORT
1793 getline(inputStream,line);//name
1794 std::string outputPortName(line);
1797 getline(inputStream,line);//xInic:yInic:zInic
1799 strcpy( coord, line.c_str() );
1800 result = strtok( coord, delims );//xInic
1801 std::string xInic(result);
1802 result = strtok( NULL, delims );//yInic
1803 std::string yInic(result);
1804 result = strtok( NULL, delims );//zInic
1805 std::string zInic(result);
1807 double xIn, yIn, zIn;
1808 std::istringstream xSt(xInic);
1810 std::istringstream ySt(yInic);
1812 std::istringstream zSt(zInic);
1815 getline(inputStream,line);//FIN_COMPLEX_PORT
1817 configGComBoxInputOutputPort(false, outputPortName,xIn,yIn,zIn);
1819 } // for output complex box
1824 getline(inputStream,line);//BOXES:num
1826 strcpy( boxes, line.c_str() );
1827 result = strtok( boxes, delims );
1828 result = strtok( NULL, delims );
1831 std::istringstream is(result);
1834 for(int i = 0;i<numBoxes;i++)
1837 getline(inputStream,line);//BOX
1838 getline(inputStream,line);//package:type:name
1840 strcpy( box, line.c_str() );
1841 result = strtok( box, delims );//package
1842 std::string package(result);
1843 result = strtok( NULL, delims );//type
1844 std::string type(result);
1845 result = strtok( NULL, delims );//name
1846 std::string name(result);
1848 getline(inputStream,line);//ISEXEC:TRUE|FALSE
1850 strcpy( exec, line.c_str() );
1851 result = strtok( exec, delims );//ISEXEC
1852 result = strtok( NULL, delims );//TRUE|FALSE
1853 std::string isExec(result);
1856 getline(inputStream,line);//xInic:yInic:zInic
1858 strcpy( coord, line.c_str() );
1859 result = strtok( coord, delims );//xInic
1860 std::string xInic(result);
1861 result = strtok( NULL, delims );//yInic
1862 std::string yInic(result);
1863 result = strtok( NULL, delims );//zInic
1864 std::string zInic(result);
1866 double xIn, yIn, zIn;
1867 std::istringstream xSt(xInic);
1869 std::istringstream ySt(yInic);
1871 std::istringstream zSt(zInic);
1875 getline(inputStream,line);//xEnd:yEnd:zEnd
1876 strcpy( coord, line.c_str() );
1877 result = strtok( coord, delims );//xEnd
1878 std::string xEnd(result);
1879 result = strtok( NULL, delims );//yEnd
1880 std::string yEnd(result);
1881 result = strtok( NULL, delims );//zEnd
1882 std::string zEnd(result);
1884 double xEn, yEn, zEn;
1885 std::istringstream xEt(xEnd);
1887 std::istringstream yEt(yEnd);
1889 std::istringstream zEt(zEnd);
1892 bool boxExecutable=false;
1895 boxExecutable= true;
1898 int idBox = createGBlackBox(xIn,yIn,package,type);
1899 configGBlackBox(idBox, xIn,yIn,zIn,name, boxExecutable,xEn,yEn,zEn);
1901 GObjectController *cont = _controllers[idBox];
1902 GBlackBoxModel *bbmod = (GBlackBoxModel*)cont->getModel();
1906 getline(inputStream,line);//PORT o FIN_BOX
1907 std::string port=line.substr(0,4);
1910 getline(inputStream,line);//name:value
1912 strcpy( poort, line.c_str() );
1913 result = strtok( poort, delims );//name
1914 std::string name(result);
1915 result = strtok( NULL, delims );//value
1916 std::string value(result);
1918 bbmod->setValueToInput(name,value);
1920 getline(inputStream,line);//PORT o FIN_BOX
1921 port=line.substr(0,4);
1924 //EED bbmod->notifyObservers(_idManager);
1929 getline(inputStream,line);//CONNECTIONS:num
1931 strcpy( conns, line.c_str() );
1932 result = strtok( conns, delims );
1933 result = strtok( NULL, delims );
1936 std::istringstream isCons(result);
1939 for(int i = 0;i<numConns;i++)
1942 getline(inputStream,line);//CONNECTION
1943 getline(inputStream,line);//Startbox.PortName:EndBox.PortName
1946 strcpy( connec, line.c_str() );
1947 result = strtok( connec, delims );
1948 std::string nameStartBox(result);
1949 result = strtok( NULL, delims );
1950 std::string nameStartPort(result);
1951 result = strtok( NULL, delims );
1952 std::string nameEndBox(result);
1953 result = strtok( NULL, delims );
1954 std::string nameEndPort(result);
1956 configGConnetion(nameStartBox, nameStartPort, nameEndBox, nameEndPort);
1962 //=========================================================================
1966 //=========================================================================
1967 void wxVtkSceneManager::configGComBoxInputOutputPort(bool inputoutput, std::string portName, double xIn, double yIn,double zIn)
1970 if (inputoutput==true)
1972 idPort = createGComplexBoxInputPort(portName);
1974 idPort = createGComplexBoxOutputPort(portName);
1976 GObjectController *cont = _controllers[idPort];
1977 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
1978 cbmod->setInicPoint(xIn,yIn,zIn);
1979 cbmod->notifyObservers(_idManager);
1981 //=========================================================================
1984 //=========================================================================
1985 GBoxModel* wxVtkSceneManager::findGBox(std::string boxname)
1990 GBoxModel *boxModel = NULL;
1991 std::vector<int> lstB = getBlackBoxes();
1992 for(j = 0;j<(int)lstB.size();j++)
1995 bMod = (GBoxModel*)_controllers[idB]->getModel();
1996 if(_controllers[idB]->getModel()->getBBTKName()==boxname)
2002 if((_isComplexBox) && (boxModel==NULL))
2004 std::vector<int> lstInputs = getComplexInputPorts();
2005 for(j = 0;j<(int)lstInputs.size();j++)
2008 bMod = (GBoxModel*)_controllers[idB]->getModel();
2009 if(_controllers[idB]->getModel()->getBBTKName()==boxname)
2015 std::vector<int> lstOutputs = getComplexOutputPorts();
2016 for(j = 0;j<(int)lstOutputs.size();j++)
2018 int idB = lstOutputs[j];
2019 bMod = (GBoxModel*)_controllers[idB]->getModel();
2020 if(_controllers[idB]->getModel()->getBBTKName()==boxname)
2031 //=========================================================================
2034 void wxVtkSceneManager::configGConnetion(std::string nameStartBox, std::string nameStartPort, std::string
2035 nameEndBox, std::string nameEndPort)
2038 GBoxModel *boxModel;
2039 GPortModel *startP = NULL;
2040 GPortModel *endP = NULL;
2042 boxModel= findGBox(nameStartBox);
2045 startP = boxModel->getOutputPort(nameStartPort);
2048 boxModel= findGBox(nameEndBox);
2051 endP = boxModel->getInputPort(nameEndPort);
2055 int idCon = createGConnector(startP);
2056 _worldState = NOTHING_HAPPENS;
2057 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
2059 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
2060 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
2061 tempp->endContourCreation();
2062 conMod->setEndPort(endP);
2063 conView->updateStartEndPoints();
2066 //=========================================================================
2068 bool wxVtkSceneManager::boxExist(std::string boxname)
2071 std::map<int, GObjectController*>::iterator it;
2072 for(it = _controllers.begin(); it != _controllers.end(); ++it)
2074 GObjectController *cont = it->second;
2075 if(cont->getModel()->getBBTKName()==boxname)
2083 //=========================================================================
2085 std::vector<int> wxVtkSceneManager::getBlackBoxes()
2087 std::vector<int> vect;
2088 std::map<int, GObjectController*>::iterator it;
2089 for(it = _controllers.begin(); it != _controllers.end(); ++it)
2091 GObjectController *cont = it->second;
2092 if(cont->getGObjectType()==GBLACKBOX)
2094 vect.push_back(cont->getId());
2100 //=========================================================================
2102 std::vector<int> wxVtkSceneManager::getComplexInputPorts()
2104 std::vector<int> vect;
2105 std::map<int, GObjectController*>::iterator it;
2106 for(it = _controllers.begin(); it != _controllers.end(); ++it)
2108 GObjectController *cont = it->second;
2109 if(cont->getGObjectType()==GCOMPLEXINPUTPORT)
2111 vect.push_back(cont->getId());
2117 //=========================================================================
2119 std::vector<int> wxVtkSceneManager::getComplexOutputPorts()
2121 std::vector<int> vect;
2122 std::map<int, GObjectController*>::iterator it;
2123 for(it = _controllers.begin(); it != _controllers.end(); ++it)
2125 GObjectController *cont = it->second;
2126 if(cont->getGObjectType()==GCOMPLEXOUTPUTPORT)
2128 vect.push_back(cont->getId());
2134 //=========================================================================
2136 std::vector<int> wxVtkSceneManager::getConnections()
2138 std::vector<int> vect;
2139 std::map<int, GObjectController*>::iterator it;
2140 for(it = _controllers.begin(); it != _controllers.end(); ++it)
2142 GObjectController *cont = it->second;
2143 if(cont->getGObjectType()==GCONNECTOR)
2145 vect.push_back(cont->getId());
2151 //=========================================================================
2153 bool wxVtkSceneManager::isComplexBox()
2155 return _isComplexBox;
2158 //=========================================================================
2160 void wxVtkSceneManager::setComplexBox(bool val)
2165 //=========================================================================
2167 int wxVtkSceneManager::addObjectController(GObjectController* objController)
2169 //Register the controller of the new object
2170 registerController((InteractorStyleMaracas*) objController);
2172 //Add the object to the objects list
2173 int newId = _contLastId;//_controllers.size();
2174 objController->setId(newId);
2175 _controllers[newId] = objController;
2180 //=========================================================================
2182 int wxVtkSceneManager::getNumSelectedObjects()
2184 return _selectedObjects.size();
2187 //=========================================================================
2189 std::map<int,GObjectController*> wxVtkSceneManager::getSelectedObjects()
2191 std::map<int,GObjectController*> mapSelected;
2193 std::map<int, GObjectController*>::iterator it;
2194 for(it = _controllers.begin(); it != _controllers.end(); ++it)
2196 GObjectController *cont = it->second;
2197 if(cont->getGObjectType()==GBLACKBOX && cont->getView()->getState()==SELECTED)
2199 mapSelected[cont->getId()]=cont;
2203 std::map<int, GObjectController*>::iterator it2;
2204 for(it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
2206 GObjectController *cont = it2->second;
2207 if(cont->getGObjectType()==GCONNECTOR)
2209 GConnectorModel* cmod = (GConnectorModel*)cont->getModel();
2210 GBoxModel* endPortParentBox = cmod->getEndPort()->getParentBox();
2211 GBoxModel* startPortParentBox = cmod->getStartPort()->getParentBox();
2213 std::map<int, GObjectController*>::iterator iterOBJ1 = mapSelected.find(startPortParentBox->getObjectId());
2214 std::map<int, GObjectController*>::iterator iterOBJ2 = mapSelected.find(endPortParentBox->getObjectId());
2216 if(iterOBJ1 != mapSelected.end() && iterOBJ2 != mapSelected.end())
2218 int ID = cont->getId();
2219 mapSelected[ID]=cont;
2226 //=========================================================================
2228 void wxVtkSceneManager::addObjects(std::map<int,GObjectController*> objectsMap)
2231 std::map<int,int> oldIdNewIdBoxes;
2232 std::vector<int> connections;
2234 std::map<int, GObjectController*>::iterator it;
2235 for(it = objectsMap.begin(); it != objectsMap.end(); ++it)
2237 GObjectController *cont = it->second;
2238 int type = cont->getGObjectType();
2243 double xInic, yInic,zInic;
2244 GBlackBoxModel* copyBox = (GBlackBoxModel*)cont->getModel();
2245 copyBox->getInicPoint(xInic,yInic,zInic);
2246 int idBox = createGBlackBox(0,0,copyBox->getBBTKPackage(),copyBox->getBBTKType());
2248 int idcB = copyBox->getObjectId();
2249 oldIdNewIdBoxes[idcB]=idBox;
2250 cont = _controllers[idBox];
2251 GBlackBoxModel* newbox = (GBlackBoxModel*)cont->getModel();
2252 newbox->setInicPoint(xInic,yInic,zInic);
2253 int num = newbox->getNumInputPorts();
2254 for(int j=0;j<num;j++)
2256 newbox->setValueToInputPort(j,copyBox->getValueInputPort(j));
2258 newbox->notifyObservers(_idManager);
2260 else if(type==GCONNECTOR)
2262 int idCon = cont->getId();
2263 connections.push_back(idCon);
2268 for(int i = 0 ;i<(int)connections.size();i++)
2270 int objId = connections[i];
2271 GObjectController *cont = objectsMap[objId];
2272 GConnectorModel* connectModel = (GConnectorModel*)cont->getModel();
2274 GPortModel* startPort = connectModel->getStartPort();
2275 int startPortIndex = startPort->getPosInBox();
2276 GPortModel* endPort = connectModel->getEndPort();
2277 int endPortIndex = endPort->getPosInBox();
2279 GBlackBoxModel* startPortParentBox = (GBlackBoxModel*)startPort->getParentBox();
2280 GBlackBoxModel* endPortParentBox = (GBlackBoxModel*)endPort->getParentBox();
2282 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2283 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2285 GBlackBoxModel* newStartBox = (GBlackBoxModel*)_controllers[idNewStartBox]->getModel();
2286 GBlackBoxModel* newEndBox = (GBlackBoxModel*)_controllers[idNewEndBox]->getModel();
2288 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2289 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2291 // Creates connection
2292 int idCon = createGConnector(newStartPort);
2293 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
2294 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
2295 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
2296 tempp->endContourCreation();
2297 conMod->setEndPort(newEndPort);
2298 conView->updateStartEndPoints();
2301 std::map<int, int>::iterator itIds;
2302 for(itIds = oldIdNewIdBoxes.begin(); itIds != oldIdNewIdBoxes.end(); ++itIds)
2304 int idOld = itIds->first;
2305 int idNew = itIds->second;
2307 GBlackBoxModel* oldBox = (GBlackBoxModel*)objectsMap[idOld]->getModel();
2308 GBlackBoxModel* newBox = (GBlackBoxModel*)_controllers[idNew]->getModel();
2310 std::vector<int> oldInputConnections = oldBox->getConnectedInputs();
2311 std::vector<int> oldOutputConnections = oldBox->getConnectedOutputs();
2312 std::vector<int> newInputConnections = newBox->getConnectedInputs();
2313 std::vector<int> newOutputConnections = newBox->getConnectedOutputs();
2315 for(int k = 0; k<(int)oldInputConnections.size();k++)
2318 //EED int toCreate=-1;
2319 for(int l = 0; l<(int)newInputConnections.size() && !exist;l++)
2321 if(oldInputConnections[k]==newInputConnections[l])
2329 //Create complex input
2330 int posInBox = oldInputConnections[k];
2331 GPortModel* inputPort = oldBox->getInputPort(posInBox);
2332 std::string inputPortName = inputPort->getBBTKName();
2333 int idInputPort = createGComplexBoxInputPort(inputPortName);
2334 GObjectController *cont = _controllers[idInputPort];
2335 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
2337 inputPort->getInicPoint(xIn,yIn,zIn);
2339 cbmod->setInicPoint(xIn,yIn,zIn);
2340 cbmod->notifyObservers(_idManager);
2342 GPortModel* inputPortEnd = newBox->getInputPort(posInBox);
2344 // Creates connection
2345 int idCon = createGConnector(cbmod->getOutputPort(0));
2346 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
2347 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
2348 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
2349 tempp->endContourCreation();
2350 conMod->setEndPort(inputPortEnd);
2351 conView->updateStartEndPoints();
2358 for(int k = 0; k<(int)oldOutputConnections.size();k++)
2361 //EED int toCreate=-1;
2362 for(int l = 0; l<(int)newOutputConnections.size() && !exist;l++)
2364 if(oldOutputConnections[k]==newOutputConnections[l])
2372 //Create complex output
2373 int posInBox = oldOutputConnections[k];
2374 GPortModel* outputPort = oldBox->getOutputPort(posInBox);
2375 std::string outputPortName = outputPort->getBBTKName();
2376 int idOutputPort = createGComplexBoxOutputPort(outputPortName);
2377 GObjectController *cont = _controllers[idOutputPort];
2378 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
2380 outputPort->getInicPoint(xIn,yIn,zIn);
2382 cbmod->setInicPoint(xIn,yIn,zIn);
2383 cbmod->notifyObservers(_idManager);
2385 GPortModel* outputPortEnd = newBox->getOutputPort(posInBox);
2387 // Creates connection
2388 int idCon = createGConnector(outputPortEnd);
2389 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
2390 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
2391 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
2392 tempp->endContourCreation();
2393 conMod->setEndPort(cbmod->getInputPort(0));
2394 conView->updateStartEndPoints();
2405 //=========================================================================
2407 } // EO namespace bbtk