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>
46 //=========================================================================
47 wxVtkSceneManager::wxVtkSceneManager(wxGEditorTabPanel *parent, wxVtk3DBaseView *baseView,int idManager)
49 _cbName = "ComplexBoxName";
50 _cbPackageName = "PackageName";
51 _Author = "Author ??";
53 _Description = "Description ??";
57 _idManager = idManager;
59 _startDragging = false;
60 _isComplexBox = false;
65 printf ("RaC-EED 21-06-2010 %p wxVtkSceneManager::wxVtkSceneManager If you comment this line, the drag and drop functionnality is not initialized.\n" , this );
67 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget((wxDropTarget*)parent);
71 _worldState=NOTHING_HAPPENS;
72 registerController(this);
75 _idConnectionInCreation = -1;
80 //=========================================================================
82 void wxVtkSceneManager::disconnectDrop()
84 printf ("EED %p ~wxVtkSceneManager::disconnectDrop()\n" , this );
85 //EED02JUIN2010 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget(NULL);
86 // _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget( new tmpClasswxTextDropTarget() );
89 //=========================================================================
91 wxVtkSceneManager::~wxVtkSceneManager()
94 printf ("EED %p ~wxVtkSceneManager()\n" , this );
99 //=========================================================================
101 void wxVtkSceneManager::configureBaseView()
103 printf("EED wxVtkSceneManager::configureBaseView 0\n");
104 vtkInteractorStyleBaseView2D *interactorstylebaseview = vtkInteractorStyleBaseView2D::New();
106 _baseView->SetInteractorStyleBaseView(interactorstylebaseview);
108 // Important to activate the 2D interaction system
109 wxVTKRenderWindowInteractor *iren = _baseView->GetWxVTKRenderWindowInteractor();
110 interactorstylebaseview->SetInteractor ( iren );
111 iren->SetInteractorStyle(interactorstylebaseview);
112 interactorstylebaseview->SetwxVtkBaseView(_baseView);
114 _baseView->GetRenderer()->GetActiveCamera()->ParallelProjectionOn();
115 _baseView->GetRenderer()->ResetCamera(-100,100,-100,100,800,1100);
117 _baseView->GetRenderer()->SetBackground(0.9,0.9,0.9);
118 _baseView->GetRenderer()->GradientBackgroundOn();
119 _baseView->Refresh();
122 _textActor = vtkTextActor3D::New();
123 _textActor->SetPosition( -9999 , -9999 , 900 );
124 _textActor->SetInput( "<void>" );
125 _textActor->GetTextProperty()->SetFontSize(60);
126 _textActor->GetTextProperty()->BoldOn();
127 _textActor->GetTextProperty()->SetColor(PORTTEXT_NH_R,PORTTEXT_NH_G,PORTTEXT_NH_B);
129 _baseView->GetRenderer()->AddActor( _textActor );
132 // Actor Fill_Port_Text
139 vtkPolygon *aPolygon = vtkPolygon::New();
140 _fillObjectActor = vtkActor::New();
142 _pts = vtkPoints::New();
144 double w=100,h=10,b=h/15,t=3;
145 _pts->SetNumberOfPoints(21);
146 _pts->InsertPoint(0, xInic+w*0.33-t/2 , yInic , zInic );
147 _pts->InsertPoint(1, xInic+w*0.33 , yInic-t , zInic );
148 _pts->InsertPoint(2, xInic+w*0.33+t/2 , yInic , zInic );
149 _pts->InsertPoint(3, xInic+w*0.33+t/2 , yInic , zInic );
150 _pts->InsertPoint(4, xInic+w-b*4 , yInic+b*0 , zInic );
152 _pts->InsertPoint( 5, xInic+w-b*4 , yInic+b*0 , zInic );
153 _pts->InsertPoint( 6, xInic+w-b*2 , yInic+b*1 , zInic );
154 _pts->InsertPoint( 7, xInic+w-b*1 , yInic+b*2 , zInic );
155 _pts->InsertPoint( 8, xInic+w-b*0 , yInic+b*4 , zInic );
157 _pts->InsertPoint( 9, xInic+w-b*0 , yInic+h-b*4 , zInic );
158 _pts->InsertPoint(10, xInic+w-b*1 , yInic+h-b*2 , zInic );
159 _pts->InsertPoint(11, xInic+w-b*2 , yInic+h-b*1 , zInic );
160 _pts->InsertPoint(12, xInic+w-b*4 , yInic+h-b*0 , zInic );
162 _pts->InsertPoint(13, xInic+b*4 , yInic+h-b*0 , zInic );
163 _pts->InsertPoint(14, xInic+b*2 , yInic+h-b*1 , zInic );
164 _pts->InsertPoint(15, xInic+b*1 , yInic+h-b*2 , zInic );
165 _pts->InsertPoint(16, xInic+b*0 , yInic+h-b*4 , zInic );
167 _pts->InsertPoint(17, xInic+b*0 , yInic+b*4 , zInic );
168 _pts->InsertPoint(18, xInic+b*1 , yInic+b*2 , zInic );
169 _pts->InsertPoint(19, xInic+b*2 , yInic+b*1 , zInic );
170 _pts->InsertPoint(20, xInic+b*4 , yInic+b*0 , zInic );
172 aPolygon->GetPointIds()->SetNumberOfIds(21);
173 for (int i=0;i<21; i++)
175 aPolygon->GetPointIds()->SetId(i, i);
178 vtkUnstructuredGrid *aPolygonGrid = vtkUnstructuredGrid::New();
179 aPolygonGrid->Allocate(1, 1);
180 aPolygonGrid->InsertNextCell(aPolygon->GetCellType(), aPolygon->GetPointIds());
181 aPolygonGrid->SetPoints(_pts);
182 _aPolygonMapper = vtkDataSetMapper::New();
183 _aPolygonMapper->SetInput(aPolygonGrid);
184 _fillObjectActor->SetMapper(_aPolygonMapper);
185 _fillObjectActor->GetProperty()->SetColor(PORTFILL_NH_R,PORTFILL_NH_G,PORTFILL_NH_B);
186 _fillObjectActor->GetProperty()->SetOpacity(0);
187 _aPolygonMapper->Modified();
189 _baseView->GetRenderer()->AddActor( _fillObjectActor );
190 printf("EED wxVtkSceneManager::configureBaseView 1\n");
193 //=========================================================================
195 std::string wxVtkSceneManager::generateANewNameForABox()
197 std::stringstream boxname;
200 boxname << "Box0" << _numBoxes;
202 boxname << "Box" << _numBoxes;
205 return boxname.str();
208 //=========================================================================
210 std::string wxVtkSceneManager::findANewNameForABox()
212 std::string boxname=generateANewNameForABox();
214 while (boxExist(boxname)==true)
216 boxname=generateANewNameForABox();
222 //=========================================================================
223 void wxVtkSceneManager::configGBlackBox(int idBox, double xIn, double yIn, double zIn, std::string name, bool boxExecutable,double xEn,double yEn,double zEn)
225 GObjectController *cont = _controllers[idBox];
226 GBlackBoxModel *bbmod = (GBlackBoxModel*)cont->getModel();
227 bbmod->setBBTKName(name);
228 bbmod->setInicPoint(xIn,yIn,zIn);
229 bbmod->setFinalPoint(xEn,yEn,zEn);
230 bbmod->setExecutable(boxExecutable);
232 bbmod->notifyObservers(_idManager);
237 //=========================================================================
239 int wxVtkSceneManager::createGBlackBox(int x, int y, std::string packageName, std::string boxType)
241 _worldState = NOTHING_HAPPENS;
242 //EED int windowWidth = _baseView->GetRenWin()->GetSize()[0];
243 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
245 int type = GBLACKBOX;
247 //Create the MVC Objects
249 GBlackBoxModel *model = (GBlackBoxModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
250 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
251 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
253 BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxType);
255 //Prepares the initial model
256 //The coordinates obtained are the following. Top-Left:x=0,y=0 Bottom-Right:x=width,y=height
259 double yy = windowHeight-y;
261 //z value is not important yet, because it is only used a parallel projection
263 _baseView->TransCoordScreenToWorld(xx,yy,zz);
264 model->setInicPoint(xx,yy,zz);
266 std::stringstream stream;
268 std::string newBoxName;
269 newBoxName = findANewNameForABox();
272 stream << newBoxName;
274 std::string arraystring = stream.str();
276 model->setBBTKName(arraystring);
277 model->setBBTKType(boxType);
278 model->setBBTKPackage(packageName);
280 model->addObserver(view);
281 model->addObserver(this);
283 //Iterate and create the input ports
284 std::map<std::string, BlackBoxInputDescriptor*> descriptorInMap = descriptor->GetInputDescriptorMap();
285 std::map<std::string, BlackBoxInputDescriptor*>::iterator itInput;
288 for(itInput = descriptorInMap.begin(); itInput != descriptorInMap.end(); ++itInput)
290 BlackBoxInputDescriptor *desc = itInput->second;
291 createGInputPort(GINPUTPORT,i,model,desc);
295 //Iterate and create the output ports
296 std::map<std::string, BlackBoxOutputDescriptor*> descriptorOutMap = descriptor->GetOutputDescriptorMap();
297 std::map<std::string, BlackBoxOutputDescriptor*>::iterator itOutput;
300 for(itOutput = descriptorOutMap.begin();itOutput != descriptorOutMap.end(); ++itOutput)
302 BlackBoxOutputDescriptor *desc = itOutput->second;
303 createGOutputPort(GOUTPUTPORT,i,model,desc);
308 //Associates the view with the correspondent renderer and the model.
309 //(NOTE: Refresh is only made by the view)
310 view->setModel(model);
311 view->setBaseView(_baseView);
312 view->initVtkObjects();
314 //Associates the controller with the correspondent model and view
315 controller->setModelAndView(model,view);
317 //Resgiter change to the observers of the actual model
318 model->notifyObservers(_idManager);
320 int newId = addObjectController(controller);
326 //=========================================================================
328 int wxVtkSceneManager::createGComplexBoxInputPort(std::string inputName)
330 //EED int windowWidth=_baseView->GetRenWin()->GetSize()[0];
331 int windowHeight=_baseView->GetRenWin()->GetSize()[1];
333 int type = GCOMPLEXINPUTPORT;
335 //Create the MVC Objects
337 GComplexBoxPortModel *model = (GComplexBoxPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
338 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
339 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
341 //Prepares the initial model
344 double yy = windowHeight-5;
346 //z value is not important yet, because it is only used a parallel projection
348 printf("EED wxVtkSceneManager::createGComplexBoxInputPort 900-450\n");
350 _baseView->TransCoordScreenToWorld(xx,yy,zz);
351 model->setInicPoint(xx,yy,zz);
353 model->setBBTKName(inputName);
354 model->setBBTKType("ComplexInputPort");
355 model->setComplexPortType(type);
357 model->addObserver(view);
358 model->addObserver(this);
360 //create the output port
361 GPortController* portController = createGPort(GOUTPUTPORT,inputName,"ComplexInputPort",0,model);
362 model->addOutputPort((GPortModel*)portController->getModel());
364 //Associates the view with the correspondent renderer and the model.
365 //(NOTE: Refresh is only made by the view)
366 view->setModel(model);
367 view->setBaseView(_baseView);
368 view->initVtkObjects();
370 //Associates the controller with the correspondent model and view
371 controller->setModelAndView(model,view);
373 //Resgiter change to the observers of the actual model
374 model->notifyObservers(_idManager);
376 int newId = addObjectController(controller);
380 //=========================================================================
382 int wxVtkSceneManager::createGComplexBoxOutputPort(std::string outputName)
384 //EED int windowWidth=_baseView->GetRenWin()->GetSize()[0];
385 int windowHeight=_baseView->GetRenWin()->GetSize()[1];
387 int type = GCOMPLEXOUTPUTPORT;
389 //Create the MVC Objects
391 GComplexBoxPortModel *model = (GComplexBoxPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
392 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
393 GObjectController *controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
395 //Prepares the initial model
398 double yy = windowHeight-5;
400 //z value is not important yet, because it is only used a parallel projection
403 printf("EED wxVtkSceneManager::createGComplexBoxOutputPort 900-450\n");
405 _baseView->TransCoordScreenToWorld(xx,yy,zz);
406 model->setInicPoint(xx,yy,zz);
408 model->setBBTKName(outputName);
409 model->setBBTKType("ComplexOutputPort");
410 model->setComplexPortType(type);
412 model->addObserver(view);
413 model->addObserver(this);
415 //create the output port
416 GPortController* portController = createGPort(GINPUTPORT,outputName,"ComplexInputPort",0,model);
417 model->addInputPort((GPortModel*)portController->getModel());
419 //Associates the view with the correspondent renderer and the model.
420 //(NOTE: Refresh is only made by the view)
421 view->setModel(model);
422 view->setBaseView(_baseView);
423 view->initVtkObjects();
425 //Associates the controller with the correspondent model and view
426 controller->setModelAndView(model,view);
428 //Resgiter change to the observers of the actual model
429 model->notifyObservers(_idManager);
431 int newId = addObjectController(controller);
435 //=========================================================================
437 int wxVtkSceneManager::createGInputPort(int portType, int posinBox,GBoxModel *blackBox, BlackBoxInputDescriptor *desc)
439 GPortController* portController = createGPort(portType,desc->GetName(),desc->GetTypeName(),posinBox,blackBox);
440 blackBox->addInputPort((GPortModel*)portController->getModel());
441 return portController->getId();
444 //=========================================================================
446 int wxVtkSceneManager::createGOutputPort(int portType, int posinBox,GBoxModel *blackBox, BlackBoxOutputDescriptor *desc)
448 GPortController* portController = createGPort(portType,desc->GetName(),desc->GetTypeName(),posinBox,blackBox);
449 blackBox->addOutputPort((GPortModel*)portController->getModel());
450 return portController->getId();
453 //=========================================================================
455 GPortController* wxVtkSceneManager::createGPort(int portType,std::string bbtkName, std::string bbtkType, int posInBox,GBoxModel *blackBox)
459 //Create the MVC Objects
460 GPortModel *model = (GPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
461 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
462 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
464 model->registerInBox(blackBox,portType, posInBox);
466 model->setBBTKType(bbtkType);
467 model->setBBTKName(bbtkName);
469 model->addObserver(view);
470 model->addObserver(this);
472 //Associates the view with the correspondent renderer and the model.
473 //(NOTE: Refresh is only made by the view)
474 view->setModel(model);
475 view->setBaseView(_baseView);
476 view->initVtkObjects();
478 //Associates the controller with the correspondent model and view
479 controller->setModelAndView(model,view);
481 model->notifyObservers(_idManager);
483 addObjectController(controller);
485 return (GPortController*)controller;
488 //=========================================================================
490 int wxVtkSceneManager::createGConnector(GPortModel* startPort)
492 int type = GCONNECTOR;
494 manualConnectorContourController* manContourControl = new manualConnectorContourController();
495 manualConnectorContourView* manContourView = new manualConnectorContourView();
496 manualContourModel* manContourModel = new manualContourModel();
498 GConnectorController* connectorcontroller = new GConnectorController();
499 GConnectorModel* connectorModel = new GConnectorModel();
500 vtkGConnectorView* connectorView = new vtkGConnectorView();
501 connectorModel->setGObjectType(type);
503 manContourModel->SetCloseContour(false);
504 connectorModel->setStartPort(startPort);
506 manContourView->SetModel( manContourModel );
507 manContourView->SetWxVtkBaseView( _baseView );
508 manContourView->SetRange( 0.5 );
509 manContourView->SetZ( 900 );
511 manContourView->SetColorNormalContour(0, 0, 1);
512 manContourView->SetColorEditContour(0.5, 0.5, 0.5);
513 manContourView->SetColorSelectContour(1, 0.8, 0);
514 manContourView->SetWidthLine(1);
515 manContourView->SetShowText(false);
517 manContourControl->SetModelView( manContourModel , manContourView );
519 manContourControl->CreateNewManualContour();
521 manContourView->RefreshContour();
525 connectorModel->getInicPoint(x,y,z);
527 manContourControl->SetState(1);
528 manContourModel->SetCloseContour(false);
530 manContourModel->AddPoint(x,y,z);
531 manContourView->AddPoint();
533 manContourModel->AddPoint(x,y,z);
534 manContourView->AddPoint();
536 int bak= manContourControl->GetNumberOfPointsManualContour() - 1;
537 manContourControl->_bakIdPoint=bak;
538 manContourView->Refresh();
540 manContourControl->SetMoving( false );
542 connectorcontroller->setModelAndView(connectorModel,connectorView);
544 int newId = addObjectController(connectorcontroller);
546 connectorcontroller->setManualContourController(manContourControl);
547 connectorModel->setManualContourModel(manContourModel);
548 connectorView->setManualContourView(manContourView);
549 connectorView->setModel(connectorModel);
550 connectorView->setBaseView(_baseView);
553 connectorModel->addObserver(connectorView);
554 connectorModel->addObserver(this);
559 //=========================================================================
561 void wxVtkSceneManager::registerController(InteractorStyleMaracas *param)
563 vtkInteractorStyleBaseView* baseViewControlManager = (vtkInteractorStyleBaseView*)_baseView->GetInteractorStyleBaseView();
564 baseViewControlManager->AddInteractorStyleMaracas( param );
567 //=========================================================================
569 void wxVtkSceneManager::unregisterController(InteractorStyleMaracas *param)
571 vtkInteractorStyleBaseView* baseViewControlManager = (vtkInteractorStyleBaseView*)_baseView->GetInteractorStyleBaseView();
572 baseViewControlManager->RemoveInteractorStyleMaracas( param );
575 //=========================================================================
577 vtkRenderer* wxVtkSceneManager::getRenderer()
579 return _baseView->GetRenderer();
582 //=========================================================================
584 vtkRenderWindow* wxVtkSceneManager::getRenderWindow()
586 return _baseView->GetRenWin();
588 //=========================================================================
591 //=========================================================================
592 int wxVtkSceneManager::GetIndexInSelected(int idControler)
595 for (int i=0; i<(int)_selectedObjects.size(); i++)
597 if(_selectedObjects[i]==idControler)
605 //=========================================================================
607 void wxVtkSceneManager::update(int idController,int command)
610 if(command != NO_COMMAND)
612 if(command == ADD_TO_SELECTED)
614 //EEDBorrame GObjectController* cont = _controllers[idController];
616 if (GetIndexInSelected(idController)==-1)
618 _selectedObjects.push_back(idController);
622 // bool foundID=false;
623 // for (int i=0; i<(int)_selectedObjects.size() && foundID==false; i++)
625 // if(_selectedObjects[i]==idController)
632 // _selectedObjects.push_back(idController);
635 }else if(command == REMOVE_FROM_SELECTED)
637 int index=GetIndexInSelected(idController);
640 _selectedObjects.erase( _selectedObjects.begin()+index );
643 else if(command == INIT_CREATION_CONTOUR)
645 _worldState = INIT_CREATION_CONTOUR;
646 GObjectController* cont = _controllers[idController];
647 GPortModel* startOutputPort = (GPortModel*)cont->getModel();
650 // The last one is the controller of the connector
651 std::map<int, GObjectController*>::iterator it2;
653 for(it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
655 GObjectController *cont = it2->second;
656 if(cont->getGObjectType() == GPORT )
658 GPortModel* port = (GPortModel*)cont->getModel();
659 if(port->getPortType()==GINPUTPORT)
661 cont->SetActive(true);
665 cont->getView()->setState(NOTHING_HAPPENS);
666 cont->getModel()->notifyObservers(_idManager);
667 cont->SetActive(false);
672 cont->getView()->setState(NOTHING_HAPPENS);
673 cont->getModel()->notifyObservers(_idManager);
674 cont->SetActive(false);
677 _selectedObjects.clear();
678 _idConnectionInCreation=createGConnector(startOutputPort);
680 else if(command == FIN_CREATION_CONTOUR && _worldState == INIT_CREATION_CONTOUR)
682 _worldState = NOTHING_HAPPENS;
683 //int id = _controllers.size()-1;
684 GObjectController *cont = _controllers[_idConnectionInCreation];
685 GConnectorModel *modelContour = (GConnectorModel*)cont->getModel();
686 GObjectController *finPort = _controllers[idController];
688 if(finPort->getGObjectType() == GPORT)
690 GPortModel* modelPort = (GPortModel*)finPort->getModel();
691 modelContour->setEndPort(modelPort);
694 manualConnectorContourController* manCont = ((GConnectorController*)cont)->getManualContourController();
695 manualConnectorContourView* connView = (manualConnectorContourView*)manCont->GetManualViewBaseContour();
698 std::map<int, GObjectController*>::iterator it2;
700 for(it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
702 GObjectController *cont = it2->second;
703 if(cont->getView()!=NULL)
705 cont->getView()->setState(NOTHING_HAPPENS);
706 cont->getModel()->notifyObservers(_idManager);
708 cont->SetActive(true);
716 //=========================================================================
718 bool wxVtkSceneManager::OnMouseMove()
721 bool okStatusMessage = false;
722 bool okPortMessage = false;
723 wxVTKRenderWindowInteractor *wxVTKiren;
724 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
725 wxVTKiren->GetEventPosition(X,Y);
728 if(_worldState == DRAG_OBJECTS)
730 for (int i=0; i<(int)_selectedObjects.size(); i++)
732 int id = _selectedObjects[i];
733 GObjectController* cont = _controllers[id];
736 cont->getView()->setStartDragging(true);
738 cont->getView()->moveObject(X,Y);
739 cont->getView()->setState(DRAG);
740 cont->getModel()->notifyObservers(_idManager);
743 std::map<int, GObjectController*>::iterator it;
746 for(it = _controllers.begin(); it != _controllers.end(); ++it)
748 GObjectController *desc = it->second;
749 if(desc->getGObjectType()==GCONNECTOR)
751 vtkGConnectorView* vconn = (vtkGConnectorView*)desc->getView();
752 vconn->updateStartEndPoints();
756 _startDragging=false;
759 else if(_worldState == NOTHING_HAPPENS || _worldState == INIT_CREATION_CONTOUR)
761 std::map<int, GObjectController*>::iterator it;
763 for(it = _controllers.begin(); it != _controllers.end(); ++it)
765 GObjectController *desc = it->second;
766 int type = desc->getGObjectType();
767 int state = desc->getView()->getState();
768 desc->getModel()->getCenter(px,py,pz);
770 if(state == HIGHLIGHTED){
771 okStatusMessage = true;
772 updateStatusBar(desc->getStatusText());
775 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
776 _parent->displayBlackBoxInfo(mod->getBBTKPackage(),mod->getBBTKType());
781 okPortMessage = true;
783 _textActor->SetInput( desc->getStatusText().c_str() );
784 _textActor->SetScale(0.1);
785 _textActor->SetPosition( px-25 ,py+1 , pz+2 );
790 _fillObjectActor->SetScale(1);
791 _fillObjectActor->GetProperty()->SetOpacity(0.50);
792 _fillObjectActor->SetPosition(px,py,1);
793 _aPolygonMapper->Modified();
796 } // for controllers it
799 if (okStatusMessage==false)
804 if (okPortMessage==false)
806 _textActor->SetScale(0.0001);
807 _fillObjectActor->SetScale(0.0001);
812 //=========================================================================
814 bool wxVtkSceneManager::OnLeftButtonDown()
817 if(_worldState==INIT_CREATION_CONTOUR)
819 bool isOverPort=false;
820 std::map<int, GObjectController*>::iterator it;
821 for(it = _controllers.begin(); it != _controllers.end() && isOverPort==false; ++it)
823 GObjectController *desc = it->second;
824 if(desc->getGObjectType()==GPORT)
826 GPortModel *portmod = (GPortModel*)desc->getModel();
827 vtkGObjectView *portView = desc->getView();
828 if(portmod->getPortType()==GINPUTPORT && portView->getState()==HIGHLIGHTED)
835 if(isOverPort==false)
838 UnSelectBlackBoxes();
841 } else { //_worldState
843 _worldState = DRAG_OBJECTS;
844 _startDragging = true;
846 int shiftkey = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey();
847 int ctrlkey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
848 ctrlkey = ctrlkey + shiftkey;
850 GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
853 if (GetGBlackBoxControlerPointedByMouse()!=NULL)
855 int state=cont->getView()->getState() ;
856 if( (ctrlkey==0) && (state==HIGHLIGHTED) )
858 UnSelectBlackBoxes();
861 for (int i = 0; i < (int)_selectedObjects.size(); i++)
863 int id = _selectedObjects[i];
864 GObjectController* cont = _controllers[id];
865 cont->getView()->setState(DRAG);
866 cont->getModel()->notifyObservers(_idManager);
869 } // if _selectedObjects.size
875 //=========================================================================
877 bool wxVtkSceneManager::OnLeftButtonUp()
879 if(_worldState == DRAG_OBJECTS)
881 _worldState = NOTHING_HAPPENS;
883 for (int i = 0; i < (int)_selectedObjects.size(); i++)
885 int id = _selectedObjects[i];
886 GObjectController* cont = _controllers[id];
887 cont->getView()->setState(SELECTED);
888 cont->getModel()->notifyObservers(_idManager);
894 //=========================================================================
895 void wxVtkSceneManager::CancelConnection()
897 if(_worldState==INIT_CREATION_CONTOUR)
899 _worldState=NOTHING_HAPPENS;
900 //int lastId = _controllers.size()-1;
902 GConnectorController *connector = (GConnectorController*)_controllers[_idConnectionInCreation];
903 connector->removeFromScene();
904 unregisterController(connector);
905 _controllers.erase(_idConnectionInCreation);
907 std::map<int, GObjectController*>::iterator it;
908 for(it = _controllers.begin(); it != _controllers.end(); ++it)
910 GObjectController *desc = it->second;
911 desc->SetActive(true);
912 desc->getView()->setState(NOTHING_HAPPENS);
913 desc->getModel()->notifyObservers(_idManager);
919 //=========================================================================
921 bool wxVtkSceneManager::OnRightButtonUp()
923 if(_worldState==INIT_CREATION_CONTOUR)
927 UnSelectBlackBoxes();
931 //=========================================================================
933 GObjectController *wxVtkSceneManager::GetGBlackBoxControlerPointedByMouse()
935 GObjectController *result=NULL;
937 wxVTKRenderWindowInteractor *wxVTKiren;
938 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
939 wxVTKiren->GetEventPosition(X,Y);
941 std::map<int, GObjectController*>::iterator it;
943 for(it = _controllers.begin(); it != _controllers.end() ; ++it)
945 GObjectController *cont = it->second;
946 int type = cont->getGObjectType();
948 if( cont->getView()->isPointInside(X,Y)==true )
954 } // if isPointInside
959 //=========================================================================
960 void wxVtkSceneManager::UnSelectBlackBoxes()
962 for (int i=0; i< (int)_selectedObjects.size(); i++)
964 int id = _selectedObjects[i];
965 GObjectController* control = _controllers[id];
966 control->getView()->setState(NOTHING_HAPPENS);
967 }// for _selectedObjects
968 _selectedObjects.clear();
971 //=========================================================================
972 bool wxVtkSceneManager::OnLeftDClick()
974 GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
977 UnSelectBlackBoxes();
978 _parent->editBlackBox( (GBlackBoxModel*)cont->getModel() );
984 wxVTKRenderWindowInteractor *wxVTKiren;
985 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
986 wxVTKiren->GetEventPosition(X,Y);
988 std::map<int, GObjectController*>::iterator it;
990 bool clickOnObject = false;
992 for(it = _controllers.begin(); it != _controllers.end() && clickOnObject==false; ++it)
994 GObjectController *cont = it->second;
995 int type = cont->getGObjectType();
997 if(cont->getView()->isPointInside(X,Y))
1001 for (int i=0; i< (int)_selectedObjects.size(); i++)
1003 int id = _selectedObjects[i];
1004 GObjectController* control = _controllers[id];
1005 control->getView()->setState(NOTHING_HAPPENS);
1007 _selectedObjects.clear();
1009 GBlackBoxModel *bbmodel = (GBlackBoxModel*)cont->getModel();
1010 _parent->editBlackBox(bbmodel);
1012 clickOnObject = true;
1016 if(clickOnObject==false)
1018 //_parent->editDiagramParameters(this);
1024 //=========================================================================
1026 bool wxVtkSceneManager::OnChar()
1028 char keyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
1030 // KeyCode 127 : Delete Key
1031 // KeyCode 8 : Backspace Key
1032 if(keyCode == 8 || keyCode == 127)
1034 if(_selectedObjects.size()>0)
1036 for(int i=0;i<(int)_selectedObjects.size();i++)
1038 int id = _selectedObjects[i];
1039 std::map<int,GObjectController*>::iterator it;
1040 it = _controllers.find(id);
1041 if (it!=_controllers.end())
1046 _selectedObjects.clear();
1053 //=========================================================================
1055 void wxVtkSceneManager::AddControlerToBeRemove(std::vector<int> *controllersToRemove, int id)
1060 for(i=0 ; i < (int)controllersToRemove->size() ; i++ )
1062 if (id == (*controllersToRemove)[i] )
1070 controllersToRemove->push_back( id );
1075 //=========================================================================
1077 void wxVtkSceneManager::deleteObject(int id)
1079 GObjectController *control = _controllers[id];
1080 std::vector<int> controllersToRemove;
1082 if(control->getGObjectType()==GBLACKBOX || control->getGObjectType()==GCOMPLEXINPUTPORT || control->getGObjectType()==GCOMPLEXOUTPUTPORT)
1084 GBoxModel *bbmod = (GBoxModel*)control->getModel();
1085 std::vector<GPortModel*> inputs = bbmod->getInputPorts();
1087 bool boxConnected = false;
1089 // Add box input controllers to be removed
1090 for(int i = 0;i< (int)inputs.size();i++)
1092 AddControlerToBeRemove( &controllersToRemove, inputs[i]->getObjectId() );
1093 if(inputs[i]->isConnected())
1095 boxConnected = true;
1099 std::vector<GPortModel*> outputs = bbmod->getOutputPorts();
1101 // Add box output controllers to be removed
1102 for(int i = 0;i<(int)outputs.size();i++)
1104 AddControlerToBeRemove( &controllersToRemove, outputs[i]->getObjectId() );
1105 if(outputs[i]->isConnected())
1107 boxConnected = true;
1111 // Add connection controllers to be removed
1112 std::map<int, GObjectController*>::iterator it;
1113 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1115 GObjectController *cont = it->second;
1116 int type = cont->getGObjectType();
1117 if(type==GCONNECTOR)
1119 GConnectorModel *conMod = (GConnectorModel*)cont->getModel();
1120 if(conMod->getStartPort()!=NULL && conMod->getStartPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
1122 AddControlerToBeRemove( &controllersToRemove, conMod->getObjectId() );
1124 if(conMod->getEndPort()!=NULL && conMod->getEndPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
1126 AddControlerToBeRemove( &controllersToRemove, conMod->getObjectId() );
1131 // Add box controller to be removed
1132 AddControlerToBeRemove( &controllersToRemove, bbmod->getObjectId() );
1134 else if(control->getGObjectType()==GCONNECTOR)
1136 GConnectorModel *conMod = (GConnectorModel*)control->getModel();
1137 AddControlerToBeRemove( &controllersToRemove, conMod->getObjectId() );
1141 std::map<int,GObjectController*>::iterator it;
1143 for(int i = 0;i<(int)controllersToRemove.size();i++)
1145 int key = controllersToRemove[i];
1146 it = _controllers.find( key );
1147 GObjectController *cont = _controllers[ key ];
1150 cont->removeFromScene();
1151 unregisterController((InteractorStyleMaracas*)cont);
1152 _controllers.erase(it);
1157 //=========================================================================
1159 void wxVtkSceneManager::displayBlackBoxInfo(std::string packageName, std::string boxName)
1161 _parent->displayBlackBoxInfo(packageName,boxName);
1164 //=========================================================================
1166 void wxVtkSceneManager::updateStatusBar(std::string textStatus)
1168 _parent->updateStatusBar(textStatus);
1172 //=========================================================================
1173 std::string wxVtkSceneManager::LineNumber(bool withLineNumber, int &value)
1175 std::string result="";
1176 if (withLineNumber==true)
1179 stringstream StrStream;
1181 std::string strValue=StrStream.str();
1185 }else if (value<100)
1190 result+=strValue+": ";
1194 //=========================================================================
1196 std::string wxVtkSceneManager::getDiagramBBS(bool wln)
1198 bool existsExec=false;
1200 std::vector<std::string> packages;
1201 std::vector<int> boxes;
1202 std::vector<int> connections;
1203 std::vector<int> execBoxes;
1205 std::map<int, GObjectController*>::iterator it;
1207 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1209 GObjectController *desc = it->second;
1210 int type = desc->getGObjectType();
1214 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
1216 std::string pkg = mod->getBBTKPackage();
1217 bool existsPkg = false;
1218 for(int t = 0;t< (int)packages.size() && existsPkg == false;t++)
1220 if(packages[t]==pkg)
1227 packages.push_back(pkg);
1231 boxes.push_back(it->first);
1232 if(mod->isExecutable())
1234 execBoxes.push_back(it->first);
1238 else if(type==GCONNECTOR)
1240 connections.push_back(it->first);
1245 std::string script = "";
1246 script+=LineNumber(wln,lnNmbr)+"# BBTK GEditor Script\n";
1247 script+=LineNumber(wln,lnNmbr)+"# ----------------------\n";
1248 script+=LineNumber(wln,lnNmbr)+"\n";
1251 script+=LineNumber(wln,lnNmbr)+"include std\n"; // EED
1252 script+=LineNumber(wln,lnNmbr)+"include itkvtk\n"; // EED
1254 for(i = 0; i< (int)packages.size();i++)
1256 script+=LineNumber(wln,lnNmbr);
1258 script+=packages[i];
1262 script+=LineNumber(wln,lnNmbr);
1268 script+=LineNumber(wln,lnNmbr);
1269 script+="author \"";
1273 script+=LineNumber(wln,lnNmbr);
1274 script+="description \"";
1275 script+=_Description;
1278 script+=LineNumber(wln,lnNmbr);
1279 script+="category \"";
1283 script+=LineNumber(wln,lnNmbr);
1287 // script+="include std\n"; // JPR
1289 for(i = 0; i < (int)boxes.size();i++)
1291 script+=LineNumber(wln,lnNmbr);
1294 GObjectController *control = _controllers[id];
1295 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1297 script+=model->getBBTKType();
1299 script+=model->getBBTKName();
1302 std::vector<GPortModel*> inputs = model->getInputPorts();
1303 for(int j = 0; j < (int)inputs.size();j++)
1305 GPortModel* inputPort = inputs[j];
1306 if(inputPort->isValueSet())
1308 script+=LineNumber(wln,lnNmbr);
1310 script+=model->getBBTKName();
1312 script+=inputPort->getBBTKName();
1314 script+=inputPort->getValue();
1319 script+=LineNumber(wln,lnNmbr);
1324 script+=LineNumber(wln,lnNmbr);
1327 for(i = 0; i<(int)connections.size();i++)
1329 script+=LineNumber(wln,lnNmbr);
1331 int id = connections[i];
1332 GObjectController *control = _controllers[id];
1333 GConnectorModel *model = (GConnectorModel*)control->getModel();
1335 //Start Connection info
1336 GPortModel *start = model->getStartPort();
1337 script+=start->getParentBox()->getBBTKName();
1339 script+=start->getBBTKName();
1343 //End Connection info
1344 GPortModel *end = model->getEndPort();
1345 script+=end->getParentBox()->getBBTKName();
1347 script+=end->getBBTKName();
1352 script+=LineNumber(wln,lnNmbr);
1354 for(i = 0; i<(int)execBoxes.size();i++)
1356 script+=LineNumber(wln,lnNmbr);
1358 int id = execBoxes[i];
1359 GObjectController *control = _controllers[id];
1360 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1362 script+=model->getBBTKName();
1371 //=========================================================================
1373 std::string wxVtkSceneManager::saveComplexBoxBBS()
1375 std::vector<std::string> packages;
1376 std::vector<int> boxes;
1377 std::vector<int> connections;
1378 std::vector<int> execBoxes;
1380 std::map<int, GObjectController*>::iterator it;
1382 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1384 GObjectController *desc = it->second;
1385 int type = desc->getGObjectType();
1389 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
1391 std::string pkg = mod->getBBTKPackage();
1392 bool existsPkg = false;
1393 for(int t = 0;t<(int)packages.size() && existsPkg == false;t++)
1395 if(packages[t]==pkg)
1402 packages.push_back(pkg);
1406 boxes.push_back(it->first);
1407 if(mod->isExecutable())
1409 execBoxes.push_back(it->first);
1412 else if(type==GCONNECTOR)
1414 connections.push_back(it->first);
1418 std::string script = "";
1420 script+="include std\n"; // EED
1421 script+="include itkvtk\n"; // EED
1423 for(i = 0; i<(int)packages.size();i++)
1426 script+=packages[i];
1432 // Definition of a complex box
1434 script+=_cbName+" "+_cbPackageName;
1438 script+="author \"";
1442 script+="description \"";
1443 script+=_Description;
1447 script+="category \"";
1454 for(i = 0; i<(int)boxes.size();i++)
1458 GObjectController *control = _controllers[id];
1459 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1461 script+=model->getBBTKType();
1463 script+=model->getBBTKName();
1466 std::vector<GPortModel*> inputs = model->getInputPorts();
1467 for(int j = 0; j<(int)inputs.size();j++)
1469 GPortModel* inputPort = inputs[j];
1470 if(inputPort->isValueSet())
1473 script+=model->getBBTKName();
1475 script+=inputPort->getBBTKName();
1477 script+=inputPort->getValue();
1485 // Create connections in the script. If the connection is made with a complex port, it is created the input or output
1487 std::string complexInputs="";
1488 std::string complexOutputs="";
1491 for(i = 0; i<(int)connections.size();i++)
1493 int id = connections[i];
1494 GObjectController *control = _controllers[id];
1495 GConnectorModel *model = (GConnectorModel*)control->getModel();
1498 GPortModel *start = model->getStartPort();
1499 GBoxModel *startBox =start->getParentBox();
1501 GPortModel *end = model->getEndPort();
1502 GBoxModel *endBox =end->getParentBox();
1504 if(startBox->getGObjectType()==GCOMPLEXINPUTPORT)
1506 complexInputs+="input ";
1507 complexInputs+=startBox->getBBTKName();
1510 complexInputs+=endBox->getBBTKName();
1512 complexInputs+=end->getBBTKName();
1515 complexInputs+="\" \"";
1517 complexInputs+="\n";
1519 else if(endBox->getGObjectType()==GCOMPLEXOUTPUTPORT)
1521 complexOutputs+="output ";
1522 complexOutputs+=endBox->getBBTKName();
1524 complexOutputs+=" ";
1525 complexOutputs+=startBox->getBBTKName();
1526 complexOutputs+=".";
1527 complexOutputs+=start->getBBTKName();
1529 complexOutputs+=" ";
1530 complexOutputs+="\" \"";
1532 complexOutputs+="\n";
1537 script+=startBox->getBBTKName();
1539 script+=start->getBBTKName();
1543 //End Connection info
1544 script+=endBox->getBBTKName();
1546 script+=end->getBBTKName();
1554 for(i = 0; i<(int)execBoxes.size();i++)
1557 int id = execBoxes[i];
1558 GObjectController *control = _controllers[id];
1559 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1561 script+=model->getBBTKName();
1566 script+="# Complex input ports\n";
1567 script+=complexInputs;
1570 script+="# Complex output ports\n";
1571 script+=complexOutputs;
1580 //=========================================================================
1582 void wxVtkSceneManager::deleteAllBoxes()
1584 std::map<int, GObjectController*>::iterator it;
1585 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1587 GObjectController *cont = it->second;
1588 cont->removeFromScene();
1589 unregisterController((InteractorStyleMaracas*)cont);
1591 _selectedObjects.clear();
1592 _controllers.clear();
1596 //=========================================================================
1599 void wxVtkSceneManager::refresh()
1601 _baseView->Refresh();
1603 //=========================================================================
1605 void wxVtkSceneManager::refreshScene()
1607 _baseView->RefreshView();
1610 //=========================================================================
1612 void wxVtkSceneManager::centerView()
1615 _baseView->GetRenderer()->GetActiveCamera()->GetFocalPoint(temp);
1616 _baseView->GetRenderer()->GetActiveCamera()->SetFocalPoint(0,0,temp[2]);
1617 _baseView->GetRenderer()->GetActiveCamera()->GetPosition(temp);
1618 _baseView->GetRenderer()->GetActiveCamera()->SetPosition(0,0,temp[2]);
1619 _baseView->RefreshView();
1623 //=========================================================================
1625 void wxVtkSceneManager::saveDiagram(std::string &content)
1629 content+="CATEGORY:";
1630 content+=GetCategory();
1633 content+="DESCRIPTION:";
1634 content+=GetDescription();
1638 content+=GetAuthor();
1642 //Print info IF COMPLEX BOX
1643 content+="COMPLEXBOX:";
1648 content+="COMPLEXBOXNAME:";
1649 content+=GetCbName();
1652 content+="PACKAGENAME:";
1653 content+=GetCbPackageName();
1656 //Print info complex input ports
1657 std::vector<int> inputs = getComplexInputPorts();
1658 int insize = inputs.size();
1659 content+="COMPLEXINPUTS:";
1660 sprintf (buffer, "%d", insize);
1664 for(int i = 0;i<insize;i++)
1667 GObjectController *cont = _controllers[id];
1668 cont->getModel()->save(content);
1671 //Print info complex output ports
1672 std::vector<int> outputs = getComplexOutputPorts();
1673 int outsize = outputs.size();
1674 content+="COMPLEXOUTPUTS:";
1675 sprintf (buffer, "%d", outsize);
1679 for(int i = 0;i<outsize;i++)
1681 int id = outputs[i];
1682 GObjectController *cont = _controllers[id];
1683 cont->getModel()->save(content);
1692 std::vector<int> boxes = getBlackBoxes();
1693 int bsize = boxes.size();
1695 sprintf (buffer, "%d", bsize);
1699 for(int i = 0;i<bsize;i++)
1702 GObjectController *cont = _controllers[id];
1703 cont->getModel()->save(content);
1707 std::vector<int> connections = getConnections();
1708 int csize = connections.size();
1709 content+="CONNECTIONS:";
1710 sprintf (buffer, "%d", csize);
1714 for(int i = 0;i<csize;i++)
1716 int id = connections[i];
1717 GObjectController *cont = _controllers[id];
1718 cont->getModel()->save(content);
1723 //=========================================================================
1725 void wxVtkSceneManager::loadDiagram(ifstream &inputStream)
1728 std::string version="<void>";
1729 std::string line="";
1730 char delims[] = ":";
1731 char *result = NULL;
1732 getline(inputStream,line);
1735 while ( !inputStream.eof() )
1737 if(line=="" || line[0]=='#')
1739 getline(inputStream,line);
1740 if (line=="# - BBTKGEditor v 1.0 BBG BlackBox Diagram file")
1742 version=line.substr(18,3);
1744 if (line=="# - BBTKGEditor v 1.1 BBG BlackBox Diagram file")
1746 version=line.substr(18,3);
1748 if (line=="# - BBTKGEditor v 1.2 BBG BlackBox Diagram file")
1750 version=line.substr(18,3);
1753 else if(line=="APP_START")
1760 printf("EED wxVtkSceneManager::loadDiagram version=%s\n",version.c_str());
1765 if ((version!="1.0") && (version!="1.1"))
1767 getline(inputStream,line);//CATEGORY:<category of the box>
1768 char categoryTmp[30];
1769 strcpy( categoryTmp, line.c_str() );
1770 result = strtok( categoryTmp, delims );
1771 result = strtok( NULL, delims );
1772 SetCategory(result);
1774 getline(inputStream,line);//DESCRIPTION:<description of the box>
1775 char descriptionTmp[1024];
1776 strcpy( descriptionTmp, line.c_str() );
1777 result = strtok( descriptionTmp, delims );
1778 result = strtok( NULL, delims );
1779 SetDescription(result);
1781 getline(inputStream,line);//AUTHOR:<author>
1782 char authorTmp[255];
1783 strcpy( authorTmp, line.c_str() );
1784 result = strtok( authorTmp, delims );
1785 result = strtok( NULL, delims );
1790 getline(inputStream,line);//COMPLEX_BOX:TRUE|FALSE
1791 char complexTmp[30];
1792 strcpy( complexTmp, line.c_str() );
1793 result = strtok( complexTmp, delims );
1794 result = strtok( NULL, delims );
1795 std::string isComplexBox(result);
1797 if(isComplexBox=="TRUE")
1801 if ((version!="1.0") && (version!="1.1"))
1803 getline(inputStream,line);//COMPLEXNAME:<name of the complex box>
1804 char complexboxnameTmp[255];
1805 strcpy( complexboxnameTmp, line.c_str() );
1806 result = strtok( complexboxnameTmp, delims );
1807 result = strtok( NULL, delims );
1810 getline(inputStream,line);//PACKAGENAME:<name of the package of the box>
1811 char packagenameTmp[255];
1812 strcpy( packagenameTmp, line.c_str() );
1813 result = strtok( packagenameTmp, delims );
1814 result = strtok( NULL, delims );
1815 SetCbPackageName(result);
1819 //-----------------------
1820 //- COMPLEX INPUT PORTS
1821 //-----------------------
1822 getline(inputStream,line);//COMPLEXINPUTS:num
1824 strcpy( inputs, line.c_str() );
1825 result = strtok( inputs, delims );
1826 result = strtok( NULL, delims );
1829 std::istringstream inps(result);
1832 for(int i = 0;i<numInputs;i++)
1835 getline(inputStream,line);//COMPLEX_PORT
1836 getline(inputStream,line);//name
1837 std::string inputPortName(line);
1840 getline(inputStream,line);//xInic:yInic:zInic
1842 strcpy( coord, line.c_str() );
1843 result = strtok( coord, delims );//xInic
1844 std::string xInic(result);
1845 result = strtok( NULL, delims );//yInic
1846 std::string yInic(result);
1847 result = strtok( NULL, delims );//zInic
1848 std::string zInic(result);
1850 double xIn, yIn, zIn;
1851 std::istringstream xSt(xInic);
1853 std::istringstream ySt(yInic);
1855 std::istringstream zSt(zInic);
1858 getline(inputStream,line);//FIN_COMPLEX_PORT
1860 configGComBoxInputOutputPort(true, inputPortName,xIn,yIn,zIn);
1863 } // for input complex box
1866 //-----------------------
1867 //- COMPLEX OUTPUT PORTS
1868 //-----------------------
1870 getline(inputStream,line);//COMPLEXOUTPUTS:num
1872 strcpy( outputs, line.c_str() );
1873 result = strtok( outputs, delims );
1874 result = strtok( NULL, delims );
1877 std::istringstream outps(result);
1878 outps >> numOutputs;
1880 for(int i = 0;i<numOutputs;i++)
1883 getline(inputStream,line);//COMPLEX_PORT
1884 getline(inputStream,line);//name
1885 std::string outputPortName(line);
1888 getline(inputStream,line);//xInic:yInic:zInic
1890 strcpy( coord, line.c_str() );
1891 result = strtok( coord, delims );//xInic
1892 std::string xInic(result);
1893 result = strtok( NULL, delims );//yInic
1894 std::string yInic(result);
1895 result = strtok( NULL, delims );//zInic
1896 std::string zInic(result);
1898 double xIn, yIn, zIn;
1899 std::istringstream xSt(xInic);
1901 std::istringstream ySt(yInic);
1903 std::istringstream zSt(zInic);
1906 getline(inputStream,line);//FIN_COMPLEX_PORT
1908 configGComBoxInputOutputPort(false, outputPortName,xIn,yIn,zIn);
1910 } // for output complex box
1915 getline(inputStream,line);//BOXES:num
1917 strcpy( boxes, line.c_str() );
1918 result = strtok( boxes, delims );
1919 result = strtok( NULL, delims );
1922 std::istringstream is(result);
1925 for(int i = 0;i<numBoxes;i++)
1928 getline(inputStream,line);//BOX
1929 getline(inputStream,line);//package:type:name
1931 strcpy( box, line.c_str() );
1932 result = strtok( box, delims );//package
1933 std::string package(result);
1934 result = strtok( NULL, delims );//type
1935 std::string type(result);
1936 result = strtok( NULL, delims );//name
1937 std::string name(result);
1939 getline(inputStream,line);//ISEXEC:TRUE|FALSE
1941 strcpy( exec, line.c_str() );
1942 result = strtok( exec, delims );//ISEXEC
1943 result = strtok( NULL, delims );//TRUE|FALSE
1944 std::string isExec(result);
1947 getline(inputStream,line);//xInic:yInic:zInic
1949 strcpy( coord, line.c_str() );
1950 result = strtok( coord, delims );//xInic
1951 std::string xInic(result);
1952 result = strtok( NULL, delims );//yInic
1953 std::string yInic(result);
1954 result = strtok( NULL, delims );//zInic
1955 std::string zInic(result);
1957 double xIn, yIn, zIn;
1958 std::istringstream xSt(xInic);
1960 std::istringstream ySt(yInic);
1962 std::istringstream zSt(zInic);
1966 getline(inputStream,line);//xEnd:yEnd:zEnd
1967 strcpy( coord, line.c_str() );
1968 result = strtok( coord, delims );//xEnd
1969 std::string xEnd(result);
1970 result = strtok( NULL, delims );//yEnd
1971 std::string yEnd(result);
1972 result = strtok( NULL, delims );//zEnd
1973 std::string zEnd(result);
1975 double xEn, yEn, zEn;
1976 std::istringstream xEt(xEnd);
1978 std::istringstream yEt(yEnd);
1980 std::istringstream zEt(zEnd);
1983 bool boxExecutable=false;
1986 boxExecutable= true;
1989 int idBox = createGBlackBox(xIn,yIn,package,type);
1990 configGBlackBox(idBox, xIn,yIn,zIn,name, boxExecutable,xEn,yEn,zEn);
1992 GObjectController *cont = _controllers[idBox];
1993 GBlackBoxModel *bbmod = (GBlackBoxModel*)cont->getModel();
1997 getline(inputStream,line);//PORT o FIN_BOX
1998 std::string port=line.substr(0,4);
2001 getline(inputStream,line);//name:value
2003 strcpy( poort, line.c_str() );
2004 result = strtok( poort, delims );//name
2005 std::string name(result);
2006 result = strtok( NULL, delims );//value
2007 std::string value(result);
2009 bbmod->setValueToInput(name,value);
2011 getline(inputStream,line);//PORT o FIN_BOX
2012 port=line.substr(0,4);
2015 //EED bbmod->notifyObservers(_idManager);
2020 getline(inputStream,line);//CONNECTIONS:num
2022 strcpy( conns, line.c_str() );
2023 result = strtok( conns, delims );
2024 result = strtok( NULL, delims );
2027 std::istringstream isCons(result);
2030 for(int i = 0;i<numConns;i++)
2033 getline(inputStream,line);//CONNECTION
2034 getline(inputStream,line);//Startbox.PortName:EndBox.PortName
2037 strcpy( connec, line.c_str() );
2038 result = strtok( connec, delims );
2039 std::string nameStartBox(result);
2040 result = strtok( NULL, delims );
2041 std::string nameStartPort(result);
2042 result = strtok( NULL, delims );
2043 std::string nameEndBox(result);
2044 result = strtok( NULL, delims );
2045 std::string nameEndPort(result);
2047 int idCon = configGConnetion(nameStartBox, nameStartPort, nameEndBox, nameEndPort);
2051 //Readding control points of the manualContour
2053 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
2054 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
2055 vtkGConnectorView *conView= (vtkGConnectorView*)tempp->getView();
2056 getline(inputStream,line); //NumberOfControlPoints:##
2057 strcpy( conns, line.c_str() );
2058 result = strtok( conns, delims );
2059 result = strtok( NULL, delims );
2061 int numberOfControlPoints;
2062 std::istringstream isCons(result);
2063 isCons >> numberOfControlPoints;
2065 for (int ii=0;ii<numberOfControlPoints;ii++)
2067 getline(inputStream,line); //XX:YY:ZZ
2069 strcpy( connec, line.c_str() );
2072 result = strtok( connec, delims );
2073 std::istringstream isPointX(result);
2075 result = strtok( NULL, delims );
2076 std::istringstream isPointY(result);
2078 result = strtok( NULL, delims );
2079 std::istringstream isPointZ(result);
2082 conMod->getManualContourModel()->InsertPoint_id(ii+1,px,py,pz);
2083 conView->getManualContourView()->AddPoint();
2093 //=========================================================================
2097 //=========================================================================
2098 void wxVtkSceneManager::configGComBoxInputOutputPort(bool inputoutput, std::string portName, double xIn, double yIn,double zIn)
2101 if (inputoutput==true)
2103 idPort = createGComplexBoxInputPort(portName);
2105 idPort = createGComplexBoxOutputPort(portName);
2107 GObjectController *cont = _controllers[idPort];
2108 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
2109 cbmod->setInicPoint(xIn,yIn,zIn);
2110 cbmod->notifyObservers(_idManager);
2112 //=========================================================================
2115 //=========================================================================
2116 GBoxModel* wxVtkSceneManager::findGBox(std::string boxname)
2121 GBoxModel *boxModel = NULL;
2122 std::vector<int> lstB = getBlackBoxes();
2123 for(j = 0;j<(int)lstB.size();j++)
2126 bMod = (GBoxModel*)_controllers[idB]->getModel();
2127 if(_controllers[idB]->getModel()->getBBTKName()==boxname)
2133 if((_isComplexBox) && (boxModel==NULL))
2135 std::vector<int> lstInputs = getComplexInputPorts();
2136 for(j = 0;j<(int)lstInputs.size();j++)
2139 bMod = (GBoxModel*)_controllers[idB]->getModel();
2140 if(_controllers[idB]->getModel()->getBBTKName()==boxname)
2146 std::vector<int> lstOutputs = getComplexOutputPorts();
2147 for(j = 0;j<(int)lstOutputs.size();j++)
2149 int idB = lstOutputs[j];
2150 bMod = (GBoxModel*)_controllers[idB]->getModel();
2151 if(_controllers[idB]->getModel()->getBBTKName()==boxname)
2162 //=========================================================================
2165 int wxVtkSceneManager::configGConnetion(std::string nameStartBox, std::string nameStartPort, std::string
2166 nameEndBox, std::string nameEndPort)
2169 GBoxModel *boxModel;
2170 GPortModel *startP = NULL;
2171 GPortModel *endP = NULL;
2173 boxModel= findGBox(nameStartBox);
2176 startP = boxModel->getOutputPort(nameStartPort);
2179 boxModel= findGBox(nameEndBox);
2182 endP = boxModel->getInputPort(nameEndPort);
2186 int idCon = createGConnector(startP);
2187 _worldState = NOTHING_HAPPENS;
2188 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
2190 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
2191 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
2192 tempp->endContourCreation();
2193 conMod->setEndPort(endP);
2194 conView->updateStartEndPoints();
2198 //=========================================================================
2200 bool wxVtkSceneManager::boxExist(std::string boxname)
2203 std::map<int, GObjectController*>::iterator it;
2204 for(it = _controllers.begin(); it != _controllers.end(); ++it)
2206 GObjectController *cont = it->second;
2207 if(cont->getModel()->getBBTKName()==boxname)
2215 //=========================================================================
2217 std::vector<int> wxVtkSceneManager::getBlackBoxes()
2219 std::vector<int> vect;
2220 std::map<int, GObjectController*>::iterator it;
2221 for(it = _controllers.begin(); it != _controllers.end(); ++it)
2223 GObjectController *cont = it->second;
2224 if(cont->getGObjectType()==GBLACKBOX)
2226 vect.push_back(cont->getId());
2232 //=========================================================================
2234 std::vector<int> wxVtkSceneManager::getComplexInputPorts()
2236 std::vector<int> vect;
2237 std::map<int, GObjectController*>::iterator it;
2238 for(it = _controllers.begin(); it != _controllers.end(); ++it)
2240 GObjectController *cont = it->second;
2241 if(cont->getGObjectType()==GCOMPLEXINPUTPORT)
2243 vect.push_back(cont->getId());
2249 //=========================================================================
2251 std::vector<int> wxVtkSceneManager::getComplexOutputPorts()
2253 std::vector<int> vect;
2254 std::map<int, GObjectController*>::iterator it;
2255 for(it = _controllers.begin(); it != _controllers.end(); ++it)
2257 GObjectController *cont = it->second;
2258 if(cont->getGObjectType()==GCOMPLEXOUTPUTPORT)
2260 vect.push_back(cont->getId());
2266 //=========================================================================
2268 std::vector<int> wxVtkSceneManager::getConnections()
2270 std::vector<int> vect;
2271 std::map<int, GObjectController*>::iterator it;
2272 for(it = _controllers.begin(); it != _controllers.end(); ++it)
2274 GObjectController *cont = it->second;
2275 if(cont->getGObjectType()==GCONNECTOR)
2277 vect.push_back(cont->getId());
2283 //=========================================================================
2285 bool wxVtkSceneManager::isComplexBox()
2287 return _isComplexBox;
2290 //=========================================================================
2292 void wxVtkSceneManager::setComplexBox(bool val)
2297 //=========================================================================
2299 int wxVtkSceneManager::addObjectController(GObjectController* objController)
2301 //Register the controller of the new object
2302 registerController((InteractorStyleMaracas*) objController);
2304 //Add the object to the objects list
2305 int newId = _contLastId;//_controllers.size();
2306 objController->setId(newId);
2307 _controllers[newId] = objController;
2312 //=========================================================================
2314 int wxVtkSceneManager::getNumSelectedObjects()
2316 return _selectedObjects.size();
2319 //=========================================================================
2321 std::map<int,GObjectController*> wxVtkSceneManager::getSelectedObjects()
2323 std::map<int,GObjectController*> mapSelected;
2325 std::map<int, GObjectController*>::iterator it;
2326 for(it = _controllers.begin(); it != _controllers.end(); ++it)
2328 GObjectController *cont = it->second;
2329 if(cont->getGObjectType()==GBLACKBOX && cont->getView()->getState()==SELECTED)
2331 mapSelected[cont->getId()]=cont;
2335 std::map<int, GObjectController*>::iterator it2;
2336 for(it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
2338 GObjectController *cont = it2->second;
2339 if(cont->getGObjectType()==GCONNECTOR)
2341 GConnectorModel* cmod = (GConnectorModel*)cont->getModel();
2342 GBoxModel* endPortParentBox = cmod->getEndPort()->getParentBox();
2343 GBoxModel* startPortParentBox = cmod->getStartPort()->getParentBox();
2345 std::map<int, GObjectController*>::iterator iterOBJ1 = mapSelected.find(startPortParentBox->getObjectId());
2346 std::map<int, GObjectController*>::iterator iterOBJ2 = mapSelected.find(endPortParentBox->getObjectId());
2348 if(iterOBJ1 != mapSelected.end() && iterOBJ2 != mapSelected.end())
2350 int ID = cont->getId();
2351 mapSelected[ID]=cont;
2358 //=========================================================================
2360 void wxVtkSceneManager::addObjects(std::map<int,GObjectController*> objectsMap)
2363 std::map<int,int> oldIdNewIdBoxes;
2364 std::vector<int> connections;
2366 std::map<int, GObjectController*>::iterator it;
2367 for(it = objectsMap.begin(); it != objectsMap.end(); ++it)
2369 GObjectController *cont = it->second;
2370 int type = cont->getGObjectType();
2375 double xInic, yInic,zInic;
2376 GBlackBoxModel* copyBox = (GBlackBoxModel*)cont->getModel();
2377 copyBox->getInicPoint(xInic,yInic,zInic);
2378 int idBox = createGBlackBox(0,0,copyBox->getBBTKPackage(),copyBox->getBBTKType());
2380 int idcB = copyBox->getObjectId();
2381 oldIdNewIdBoxes[idcB]=idBox;
2382 cont = _controllers[idBox];
2383 GBlackBoxModel* newbox = (GBlackBoxModel*)cont->getModel();
2384 newbox->setInicPoint(xInic,yInic,zInic);
2385 int num = newbox->getNumInputPorts();
2386 for(int j=0;j<num;j++)
2388 newbox->setValueToInputPort(j,copyBox->getValueInputPort(j));
2390 newbox->notifyObservers(_idManager);
2392 else if(type==GCONNECTOR)
2394 int idCon = cont->getId();
2395 connections.push_back(idCon);
2400 for(int i = 0 ;i<(int)connections.size();i++)
2402 int objId = connections[i];
2403 GObjectController *cont = objectsMap[objId];
2404 GConnectorModel* connectModel = (GConnectorModel*)cont->getModel();
2406 GPortModel* startPort = connectModel->getStartPort();
2407 int startPortIndex = startPort->getPosInBox();
2408 GPortModel* endPort = connectModel->getEndPort();
2409 int endPortIndex = endPort->getPosInBox();
2411 GBlackBoxModel* startPortParentBox = (GBlackBoxModel*)startPort->getParentBox();
2412 GBlackBoxModel* endPortParentBox = (GBlackBoxModel*)endPort->getParentBox();
2414 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2415 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2417 GBlackBoxModel* newStartBox = (GBlackBoxModel*)_controllers[idNewStartBox]->getModel();
2418 GBlackBoxModel* newEndBox = (GBlackBoxModel*)_controllers[idNewEndBox]->getModel();
2420 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2421 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2423 // Creates connection
2424 int idCon = createGConnector(newStartPort);
2425 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
2426 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
2427 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
2428 tempp->endContourCreation();
2429 conMod->setEndPort(newEndPort);
2430 conView->updateStartEndPoints();
2433 std::map<int, int>::iterator itIds;
2434 for(itIds = oldIdNewIdBoxes.begin(); itIds != oldIdNewIdBoxes.end(); ++itIds)
2436 int idOld = itIds->first;
2437 int idNew = itIds->second;
2439 GBlackBoxModel* oldBox = (GBlackBoxModel*)objectsMap[idOld]->getModel();
2440 GBlackBoxModel* newBox = (GBlackBoxModel*)_controllers[idNew]->getModel();
2442 std::vector<int> oldInputConnections = oldBox->getConnectedInputs();
2443 std::vector<int> oldOutputConnections = oldBox->getConnectedOutputs();
2444 std::vector<int> newInputConnections = newBox->getConnectedInputs();
2445 std::vector<int> newOutputConnections = newBox->getConnectedOutputs();
2447 for(int k = 0; k<(int)oldInputConnections.size();k++)
2450 //EED int toCreate=-1;
2451 for(int l = 0; l<(int)newInputConnections.size() && !exist;l++)
2453 if(oldInputConnections[k]==newInputConnections[l])
2461 //Create complex input
2462 int posInBox = oldInputConnections[k];
2463 GPortModel* inputPort = oldBox->getInputPort(posInBox);
2464 std::string inputPortName = inputPort->getBBTKName();
2465 int idInputPort = createGComplexBoxInputPort(inputPortName);
2466 GObjectController *cont = _controllers[idInputPort];
2467 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
2469 inputPort->getInicPoint(xIn,yIn,zIn);
2471 cbmod->setInicPoint(xIn,yIn,zIn);
2472 cbmod->notifyObservers(_idManager);
2474 GPortModel* inputPortEnd = newBox->getInputPort(posInBox);
2476 // Creates connection
2477 int idCon = createGConnector(cbmod->getOutputPort(0));
2478 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
2479 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
2480 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
2481 tempp->endContourCreation();
2482 conMod->setEndPort(inputPortEnd);
2483 conView->updateStartEndPoints();
2490 for(int k = 0; k<(int)oldOutputConnections.size();k++)
2493 //EED int toCreate=-1;
2494 for(int l = 0; l<(int)newOutputConnections.size() && !exist;l++)
2496 if(oldOutputConnections[k]==newOutputConnections[l])
2504 //Create complex output
2505 int posInBox = oldOutputConnections[k];
2506 GPortModel* outputPort = oldBox->getOutputPort(posInBox);
2507 std::string outputPortName = outputPort->getBBTKName();
2508 int idOutputPort = createGComplexBoxOutputPort(outputPortName);
2509 GObjectController *cont = _controllers[idOutputPort];
2510 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
2512 outputPort->getInicPoint(xIn,yIn,zIn);
2514 cbmod->setInicPoint(xIn,yIn,zIn);
2515 cbmod->notifyObservers(_idManager);
2517 GPortModel* outputPortEnd = newBox->getOutputPort(posInBox);
2519 // Creates connection
2520 int idCon = createGConnector(outputPortEnd);
2521 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
2522 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
2523 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
2524 tempp->endContourCreation();
2525 conMod->setEndPort(cbmod->getInputPort(0));
2526 conView->updateStartEndPoints();
2538 //=========================================================================
2539 void wxVtkSceneManager::SetCbName(std::string cbName)
2544 _cbName="<complex box name>";
2548 //=========================================================================
2549 std::string wxVtkSceneManager::GetCbName()
2554 //=========================================================================
2555 void wxVtkSceneManager::SetCbPackageName(std::string packagename)
2557 _cbPackageName=packagename;
2558 if (_cbPackageName=="")
2560 _cbPackageName="<package name of the complex box>";
2564 //=========================================================================
2565 std::string wxVtkSceneManager::GetCbPackageName()
2567 return _cbPackageName;
2570 //=========================================================================
2571 void wxVtkSceneManager::SetAuthor(std::string author)
2576 _Author="<author of the box>";
2580 //=========================================================================
2581 std::string wxVtkSceneManager::GetAuthor()
2586 //=========================================================================
2587 void wxVtkSceneManager::SetCategory(std::string category)
2592 _Category="<category of the box>";
2596 //=========================================================================
2597 std::string wxVtkSceneManager::GetCategory()
2602 //=========================================================================
2603 void wxVtkSceneManager::SetDescription(std::string description)
2605 _Description=description;
2606 if (_Description=="")
2608 _Description="<description of the box>";
2612 //=========================================================================
2613 std::string wxVtkSceneManager::GetDescription()
2615 return _Description;
2618 //=========================================================================
2626 } // EO namespace bbtk