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)
50 _cbName = "ComplexBoxName";
51 _cbPackageName = "PackageName";
52 _Author = "Author ??";
54 _Description = "Description ??";
58 _idManager = idManager;
60 _startDragging = false;
61 _isComplexBox = false;
66 printf ("RaC-EED 21-06-2010 %p wxVtkSceneManager::wxVtkSceneManager If you comment this line, the drag and drop functionnality is not initialized.\n" , this );
68 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget((wxDropTarget*)parent);
72 _worldState=NOTHING_HAPPENS;
73 registerController(this);
76 _idConnectionInCreation = -1;
81 //=========================================================================
83 void wxVtkSceneManager::disconnectDrop()
85 printf ("EED %p ~wxVtkSceneManager::disconnectDrop()\n" , this );
86 //EED02JUIN2010 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget(NULL);
87 // _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget( new tmpClasswxTextDropTarget() );
90 //=========================================================================
92 wxVtkSceneManager::~wxVtkSceneManager()
94 printf ("EED %p ~wxVtkSceneManager()\n" , this );
98 //=========================================================================
100 void wxVtkSceneManager::configureBaseView()
102 printf("EED wxVtkSceneManager::configureBaseView 0\n");
103 vtkInteractorStyleBaseView2D *interactorstylebaseview = vtkInteractorStyleBaseView2D::New();
105 _baseView->SetInteractorStyleBaseView(interactorstylebaseview);
107 // Important to activate the 2D interaction system
108 wxVTKRenderWindowInteractor *iren = _baseView->GetWxVTKRenderWindowInteractor();
109 interactorstylebaseview->SetInteractor ( iren );
110 iren->SetInteractorStyle(interactorstylebaseview);
111 interactorstylebaseview->SetwxVtkBaseView(_baseView);
113 _baseView->GetRenderer()->GetActiveCamera()->ParallelProjectionOn();
114 _baseView->GetRenderer()->ResetCamera(-100,100,-100,100,800,1100);
116 _baseView->GetRenderer()->SetBackground(0.9,0.9,0.9);
117 _baseView->GetRenderer()->GradientBackgroundOn();
118 _baseView->Refresh();
121 _textActor = vtkTextActor3D::New();
122 _textActor->SetPosition( -9999 , -9999 , 900 );
123 _textActor->SetInput( "<void>" );
124 _textActor->GetTextProperty()->SetFontSize(60);
125 _textActor->GetTextProperty()->BoldOn();
126 _textActor->GetTextProperty()->SetColor(PORTTEXT_NH_R,PORTTEXT_NH_G,PORTTEXT_NH_B);
128 _baseView->GetRenderer()->AddActor( _textActor );
131 // Actor Fill_Port_Text
138 vtkPolygon *aPolygon = vtkPolygon::New();
139 _fillObjectActor = vtkActor::New();
141 _pts = vtkPoints::New();
143 double w=100,h=10,b=h/15,t=3;
144 _pts->SetNumberOfPoints(21);
145 _pts->InsertPoint(0, xInic+w*0.33-t/2 , yInic , zInic );
146 _pts->InsertPoint(1, xInic+w*0.33 , yInic-t , zInic );
147 _pts->InsertPoint(2, xInic+w*0.33+t/2 , yInic , zInic );
148 _pts->InsertPoint(3, xInic+w*0.33+t/2 , yInic , zInic );
149 _pts->InsertPoint(4, xInic+w-b*4 , yInic+b*0 , zInic );
151 _pts->InsertPoint( 5, xInic+w-b*4 , yInic+b*0 , zInic );
152 _pts->InsertPoint( 6, xInic+w-b*2 , yInic+b*1 , zInic );
153 _pts->InsertPoint( 7, xInic+w-b*1 , yInic+b*2 , zInic );
154 _pts->InsertPoint( 8, xInic+w-b*0 , yInic+b*4 , zInic );
156 _pts->InsertPoint( 9, xInic+w-b*0 , yInic+h-b*4 , zInic );
157 _pts->InsertPoint(10, xInic+w-b*1 , yInic+h-b*2 , zInic );
158 _pts->InsertPoint(11, xInic+w-b*2 , yInic+h-b*1 , zInic );
159 _pts->InsertPoint(12, xInic+w-b*4 , yInic+h-b*0 , zInic );
161 _pts->InsertPoint(13, xInic+b*4 , yInic+h-b*0 , zInic );
162 _pts->InsertPoint(14, xInic+b*2 , yInic+h-b*1 , zInic );
163 _pts->InsertPoint(15, xInic+b*1 , yInic+h-b*2 , zInic );
164 _pts->InsertPoint(16, xInic+b*0 , yInic+h-b*4 , zInic );
166 _pts->InsertPoint(17, xInic+b*0 , yInic+b*4 , zInic );
167 _pts->InsertPoint(18, xInic+b*1 , yInic+b*2 , zInic );
168 _pts->InsertPoint(19, xInic+b*2 , yInic+b*1 , zInic );
169 _pts->InsertPoint(20, xInic+b*4 , yInic+b*0 , zInic );
171 aPolygon->GetPointIds()->SetNumberOfIds(21);
172 for (int i=0;i<21; i++)
174 aPolygon->GetPointIds()->SetId(i, i);
177 vtkUnstructuredGrid *aPolygonGrid = vtkUnstructuredGrid::New();
178 aPolygonGrid->Allocate(1, 1);
179 aPolygonGrid->InsertNextCell(aPolygon->GetCellType(), aPolygon->GetPointIds());
180 aPolygonGrid->SetPoints(_pts);
181 _aPolygonMapper = vtkDataSetMapper::New();
182 _aPolygonMapper->SetInput(aPolygonGrid);
183 _fillObjectActor->SetMapper(_aPolygonMapper);
184 _fillObjectActor->GetProperty()->SetColor(PORTFILL_NH_R,PORTFILL_NH_G,PORTFILL_NH_B);
185 _fillObjectActor->GetProperty()->SetOpacity(0);
186 _aPolygonMapper->Modified();
188 _baseView->GetRenderer()->AddActor( _fillObjectActor );
189 printf("EED wxVtkSceneManager::configureBaseView 1\n");
192 //=========================================================================
194 std::string wxVtkSceneManager::generateANewNameForABox()
196 std::stringstream boxname;
199 boxname << "Box0" << _numBoxes;
201 boxname << "Box" << _numBoxes;
204 return boxname.str();
207 //=========================================================================
209 std::string wxVtkSceneManager::findANewNameForABox()
211 std::string boxname=generateANewNameForABox();
213 while (boxExist(boxname)==true)
215 boxname=generateANewNameForABox();
221 //=========================================================================
222 void wxVtkSceneManager::configGBlackBox(int idBox, double xIn, double yIn, double zIn, std::string name, bool boxExecutable,double xEn,double yEn,double zEn)
224 GObjectController *cont = _controllers[idBox];
225 GBlackBoxModel *bbmod = (GBlackBoxModel*)cont->getModel();
226 bbmod->setBBTKName(name);
227 bbmod->setInicPoint(xIn,yIn,zIn);
228 bbmod->setFinalPoint(xEn,yEn,zEn);
229 bbmod->setExecutable(boxExecutable);
231 bbmod->notifyObservers(_idManager);
236 //=========================================================================
238 int wxVtkSceneManager::createGBlackBox(int x, int y, std::string packageName, std::string boxType)
240 _worldState = NOTHING_HAPPENS;
241 //EED int windowWidth = _baseView->GetRenWin()->GetSize()[0];
242 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
244 int type = GBLACKBOX;
246 //Create the MVC Objects
248 GBlackBoxModel *model = (GBlackBoxModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
249 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
250 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
252 BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxType);
254 //Prepares the initial model
255 //The coordinates obtained are the following. Top-Left:x=0,y=0 Bottom-Right:x=width,y=height
258 double yy = windowHeight-y;
260 //z value is not important yet, because it is only used a parallel projection
262 _baseView->TransCoordScreenToWorld(xx,yy,zz);
263 model->setInicPoint(xx,yy,zz);
265 std::stringstream stream;
267 std::string newBoxName;
268 newBoxName = findANewNameForABox();
271 stream << newBoxName;
273 std::string arraystring = stream.str();
275 model->setBBTKName(arraystring);
276 model->setBBTKType(boxType);
277 model->setBBTKPackage(packageName);
279 model->addObserver(view);
280 model->addObserver(this);
282 //Iterate and create the input ports
283 std::map<std::string, BlackBoxInputDescriptor*> descriptorInMap = descriptor->GetInputDescriptorMap();
284 std::map<std::string, BlackBoxInputDescriptor*>::iterator itInput;
287 for(itInput = descriptorInMap.begin(); itInput != descriptorInMap.end(); ++itInput)
289 BlackBoxInputDescriptor *desc = itInput->second;
290 createGInputPort(GINPUTPORT,i,model,desc);
294 //Iterate and create the output ports
295 std::map<std::string, BlackBoxOutputDescriptor*> descriptorOutMap = descriptor->GetOutputDescriptorMap();
296 std::map<std::string, BlackBoxOutputDescriptor*>::iterator itOutput;
299 for(itOutput = descriptorOutMap.begin();itOutput != descriptorOutMap.end(); ++itOutput)
301 BlackBoxOutputDescriptor *desc = itOutput->second;
302 createGOutputPort(GOUTPUTPORT,i,model,desc);
307 //Associates the view with the correspondent renderer and the model.
308 //(NOTE: Refresh is only made by the view)
309 view->setModel(model);
310 view->setBaseView(_baseView);
311 view->initVtkObjects();
313 //Associates the controller with the correspondent model and view
314 controller->setModelAndView(model,view);
316 //Resgiter change to the observers of the actual model
317 model->notifyObservers(_idManager);
319 int newId = addObjectController(controller);
325 //=========================================================================
327 int wxVtkSceneManager::createGComplexBoxInputPort(std::string inputName)
329 //EED int windowWidth=_baseView->GetRenWin()->GetSize()[0];
330 int windowHeight=_baseView->GetRenWin()->GetSize()[1];
332 int type = GCOMPLEXINPUTPORT;
334 //Create the MVC Objects
336 GComplexBoxPortModel *model = (GComplexBoxPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
337 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
338 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
340 //Prepares the initial model
343 double yy = windowHeight-5;
345 //z value is not important yet, because it is only used a parallel projection
347 printf("EED wxVtkSceneManager::createGComplexBoxInputPort 900-450\n");
349 _baseView->TransCoordScreenToWorld(xx,yy,zz);
350 model->setInicPoint(xx,yy,zz);
352 model->setBBTKName(inputName);
353 model->setBBTKType("ComplexInputPort");
354 model->setComplexPortType(type);
356 model->addObserver(view);
357 model->addObserver(this);
359 //create the output port
360 GPortController* portController = createGPort(GOUTPUTPORT,inputName,"ComplexInputPort",0,model);
361 model->addOutputPort((GPortModel*)portController->getModel());
363 //Associates the view with the correspondent renderer and the model.
364 //(NOTE: Refresh is only made by the view)
365 view->setModel(model);
366 view->setBaseView(_baseView);
367 view->initVtkObjects();
369 //Associates the controller with the correspondent model and view
370 controller->setModelAndView(model,view);
372 //Resgiter change to the observers of the actual model
373 model->notifyObservers(_idManager);
375 int newId = addObjectController(controller);
379 //=========================================================================
381 int wxVtkSceneManager::createGComplexBoxOutputPort(std::string outputName)
383 //EED int windowWidth=_baseView->GetRenWin()->GetSize()[0];
384 int windowHeight=_baseView->GetRenWin()->GetSize()[1];
386 int type = GCOMPLEXOUTPUTPORT;
388 //Create the MVC Objects
390 GComplexBoxPortModel *model = (GComplexBoxPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
391 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
392 GObjectController *controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
394 //Prepares the initial model
397 double yy = windowHeight-5;
399 //z value is not important yet, because it is only used a parallel projection
402 printf("EED wxVtkSceneManager::createGComplexBoxOutputPort 900-450\n");
404 _baseView->TransCoordScreenToWorld(xx,yy,zz);
405 model->setInicPoint(xx,yy,zz);
407 model->setBBTKName(outputName);
408 model->setBBTKType("ComplexOutputPort");
409 model->setComplexPortType(type);
411 model->addObserver(view);
412 model->addObserver(this);
414 //create the output port
415 GPortController* portController = createGPort(GINPUTPORT,outputName,"ComplexInputPort",0,model);
416 model->addInputPort((GPortModel*)portController->getModel());
418 //Associates the view with the correspondent renderer and the model.
419 //(NOTE: Refresh is only made by the view)
420 view->setModel(model);
421 view->setBaseView(_baseView);
422 view->initVtkObjects();
424 //Associates the controller with the correspondent model and view
425 controller->setModelAndView(model,view);
427 //Resgiter change to the observers of the actual model
428 model->notifyObservers(_idManager);
430 int newId = addObjectController(controller);
434 //=========================================================================
436 int wxVtkSceneManager::createGInputPort(int portType, int posinBox,GBoxModel *blackBox, BlackBoxInputDescriptor *desc)
438 GPortController* portController = createGPort(portType,desc->GetName(),desc->GetTypeName(),posinBox,blackBox);
439 blackBox->addInputPort((GPortModel*)portController->getModel());
440 return portController->getId();
443 //=========================================================================
445 int wxVtkSceneManager::createGOutputPort(int portType, int posinBox,GBoxModel *blackBox, BlackBoxOutputDescriptor *desc)
447 GPortController* portController = createGPort(portType,desc->GetName(),desc->GetTypeName(),posinBox,blackBox);
448 blackBox->addOutputPort((GPortModel*)portController->getModel());
449 return portController->getId();
452 //=========================================================================
454 GPortController* wxVtkSceneManager::createGPort(int portType,std::string bbtkName, std::string bbtkType, int posInBox,GBoxModel *blackBox)
458 //Create the MVC Objects
459 GPortModel *model = (GPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
460 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
461 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
463 model->registerInBox(blackBox,portType, posInBox);
465 model->setBBTKType(bbtkType);
466 model->setBBTKName(bbtkName);
468 model->addObserver(view);
469 model->addObserver(this);
471 //Associates the view with the correspondent renderer and the model.
472 //(NOTE: Refresh is only made by the view)
473 view->setModel(model);
474 view->setBaseView(_baseView);
475 view->initVtkObjects();
477 //Associates the controller with the correspondent model and view
478 controller->setModelAndView(model,view);
480 model->notifyObservers(_idManager);
482 addObjectController(controller);
484 return (GPortController*)controller;
487 //=========================================================================
489 int wxVtkSceneManager::createGConnector(GPortModel* startPort)
491 int type = GCONNECTOR;
493 manualConnectorContourController* manContourControl = new manualConnectorContourController();
494 manualConnectorContourView* manContourView = new manualConnectorContourView();
495 manualContourModel* manContourModel = new manualContourModel();
497 GConnectorController* connectorcontroller = new GConnectorController();
498 GConnectorModel* connectorModel = new GConnectorModel();
499 vtkGConnectorView* connectorView = new vtkGConnectorView();
500 connectorModel->setGObjectType(type);
502 manContourModel->SetCloseContour(false);
503 connectorModel->setStartPort(startPort);
505 manContourView->SetModel( manContourModel );
506 manContourView->SetWxVtkBaseView( _baseView );
507 manContourView->SetRange( 0.5 );
508 manContourView->SetZ( 900 );
510 manContourView->SetColorNormalContour(0, 0, 1);
511 manContourView->SetColorEditContour(0.5, 0.5, 0.5);
512 manContourView->SetColorSelectContour(1, 0.8, 0);
513 manContourView->SetWidthLine(1);
514 manContourView->SetShowText(false);
516 manContourControl->SetModelView( manContourModel , manContourView );
518 manContourControl->CreateNewManualContour();
520 manContourView->RefreshContour();
524 connectorModel->getInicPoint(x,y,z);
526 manContourControl->SetState(1);
527 manContourModel->SetCloseContour(false);
529 manContourModel->AddPoint(x,y,z);
530 manContourView->AddPoint();
532 manContourModel->AddPoint(x,y,z);
533 manContourView->AddPoint();
535 int bak= manContourControl->GetNumberOfPointsManualContour() - 1;
536 manContourControl->_bakIdPoint=bak;
537 manContourView->Refresh();
539 manContourControl->SetMoving( false );
541 connectorcontroller->setModelAndView(connectorModel,connectorView);
543 int newId = addObjectController(connectorcontroller);
545 connectorcontroller->setManualContourController(manContourControl);
546 connectorModel->setManualContourModel(manContourModel);
547 connectorView->setManualContourView(manContourView);
548 connectorView->setModel(connectorModel);
549 connectorView->setBaseView(_baseView);
552 connectorModel->addObserver(connectorView);
553 connectorModel->addObserver(this);
558 //=========================================================================
560 void wxVtkSceneManager::registerController(InteractorStyleMaracas *param)
562 vtkInteractorStyleBaseView* baseViewControlManager = (vtkInteractorStyleBaseView*)_baseView->GetInteractorStyleBaseView();
563 baseViewControlManager->AddInteractorStyleMaracas( param );
566 //=========================================================================
568 void wxVtkSceneManager::unregisterController(InteractorStyleMaracas *param)
570 vtkInteractorStyleBaseView* baseViewControlManager = (vtkInteractorStyleBaseView*)_baseView->GetInteractorStyleBaseView();
571 baseViewControlManager->RemoveInteractorStyleMaracas( param );
574 //=========================================================================
576 vtkRenderer* wxVtkSceneManager::getRenderer()
578 return _baseView->GetRenderer();
581 //=========================================================================
583 vtkRenderWindow* wxVtkSceneManager::getRenderWindow()
585 return _baseView->GetRenWin();
587 //=========================================================================
590 //=========================================================================
591 int wxVtkSceneManager::GetIndexInSelected(int idControler)
594 for (int i=0; i<(int)_selectedObjects.size(); i++)
596 if(_selectedObjects[i]==idControler)
604 //=========================================================================
606 void wxVtkSceneManager::update(int idController,int command)
609 if(command != NO_COMMAND)
611 if(command == ADD_TO_SELECTED)
613 //EEDBorrame GObjectController* cont = _controllers[idController];
615 if (GetIndexInSelected(idController)==-1)
617 _selectedObjects.push_back(idController);
621 // bool foundID=false;
622 // for (int i=0; i<(int)_selectedObjects.size() && foundID==false; i++)
624 // if(_selectedObjects[i]==idController)
631 // _selectedObjects.push_back(idController);
634 }else if(command == REMOVE_FROM_SELECTED)
636 int index=GetIndexInSelected(idController);
639 _selectedObjects.erase( _selectedObjects.begin()+index );
642 else if(command == INIT_CREATION_CONTOUR)
644 _worldState = INIT_CREATION_CONTOUR;
645 GObjectController* cont = _controllers[idController];
646 GPortModel* startOutputPort = (GPortModel*)cont->getModel();
649 // The last one is the controller of the connector
650 std::map<int, GObjectController*>::iterator it2;
652 for(it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
654 GObjectController *cont = it2->second;
655 if(cont->getGObjectType() == GPORT )
657 GPortModel* port = (GPortModel*)cont->getModel();
658 if(port->getPortType()==GINPUTPORT)
660 cont->SetActive(true);
664 cont->getView()->setState(NOTHING_HAPPENS);
665 cont->getModel()->notifyObservers(_idManager);
666 cont->SetActive(false);
671 cont->getView()->setState(NOTHING_HAPPENS);
672 cont->getModel()->notifyObservers(_idManager);
673 cont->SetActive(false);
676 _selectedObjects.clear();
677 _idConnectionInCreation=createGConnector(startOutputPort);
679 else if(command == FIN_CREATION_CONTOUR && _worldState == INIT_CREATION_CONTOUR)
681 _worldState = NOTHING_HAPPENS;
682 //int id = _controllers.size()-1;
683 GObjectController *cont = _controllers[_idConnectionInCreation];
684 GConnectorModel *modelContour = (GConnectorModel*)cont->getModel();
685 GObjectController *finPort = _controllers[idController];
687 if(finPort->getGObjectType() == GPORT)
689 GPortModel* modelPort = (GPortModel*)finPort->getModel();
690 modelContour->setEndPort(modelPort);
693 manualConnectorContourController* manCont = ((GConnectorController*)cont)->getManualContourController();
694 manualConnectorContourView* connView = (manualConnectorContourView*)manCont->GetManualViewBaseContour();
697 std::map<int, GObjectController*>::iterator it2;
699 for(it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
701 GObjectController *cont = it2->second;
702 if(cont->getView()!=NULL)
704 cont->getView()->setState(NOTHING_HAPPENS);
705 cont->getModel()->notifyObservers(_idManager);
707 cont->SetActive(true);
715 //=========================================================================
717 bool wxVtkSceneManager::OnMouseMove()
720 bool okStatusMessage = false;
721 bool okPortMessage = false;
722 wxVTKRenderWindowInteractor *wxVTKiren;
723 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
724 wxVTKiren->GetEventPosition(X,Y);
727 if(_worldState == DRAG_OBJECTS)
729 for (int i=0; i<(int)_selectedObjects.size(); i++)
731 int id = _selectedObjects[i];
732 GObjectController* cont = _controllers[id];
735 cont->getView()->setStartDragging(true);
737 cont->getView()->moveObject(X,Y);
738 cont->getView()->setState(DRAG);
739 cont->getModel()->notifyObservers(_idManager);
742 std::map<int, GObjectController*>::iterator it;
745 for(it = _controllers.begin(); it != _controllers.end(); ++it)
747 GObjectController *desc = it->second;
748 if(desc->getGObjectType()==GCONNECTOR)
750 vtkGConnectorView* vconn = (vtkGConnectorView*)desc->getView();
751 vconn->updateStartEndPoints();
755 _startDragging=false;
758 else if(_worldState == NOTHING_HAPPENS || _worldState == INIT_CREATION_CONTOUR)
760 std::map<int, GObjectController*>::iterator it;
762 for(it = _controllers.begin(); it != _controllers.end(); ++it)
764 GObjectController *desc = it->second;
765 int type = desc->getGObjectType();
766 int state = desc->getView()->getState();
767 desc->getModel()->getCenter(px,py,pz);
769 if(state == HIGHLIGHTED){
770 okStatusMessage = true;
771 updateStatusBar(desc->getStatusText());
774 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
775 _parent->displayBlackBoxInfo(mod->getBBTKPackage(),mod->getBBTKType());
780 okPortMessage = true;
782 _textActor->SetInput( desc->getStatusText().c_str() );
783 _textActor->SetScale(0.1);
784 _textActor->SetPosition( px-25 ,py+1 , pz+2 );
789 _fillObjectActor->SetScale(1);
790 _fillObjectActor->GetProperty()->SetOpacity(0.50);
791 _fillObjectActor->SetPosition(px,py,1);
792 _aPolygonMapper->Modified();
795 } // for controllers it
798 if (okStatusMessage==false)
803 if (okPortMessage==false)
805 _textActor->SetScale(0.0001);
806 _fillObjectActor->SetScale(0.0001);
811 //=========================================================================
813 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)
837 UnSelectBlackBoxes();
840 } else { //_worldState
842 _worldState = DRAG_OBJECTS;
843 _startDragging = true;
845 int shiftkey = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey();
846 int ctrlkey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
847 ctrlkey = ctrlkey + shiftkey;
849 GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
852 if (GetGBlackBoxControlerPointedByMouse()!=NULL)
854 int state=cont->getView()->getState() ;
855 if( (ctrlkey==0) && (state==HIGHLIGHTED) )
857 UnSelectBlackBoxes();
860 for (int i = 0; i < (int)_selectedObjects.size(); i++)
862 int id = _selectedObjects[i];
863 GObjectController* cont = _controllers[id];
864 cont->getView()->setState(DRAG);
865 cont->getModel()->notifyObservers(_idManager);
868 } // if _selectedObjects.size
874 //=========================================================================
876 bool wxVtkSceneManager::OnLeftButtonUp()
878 if(_worldState == DRAG_OBJECTS)
880 _worldState = NOTHING_HAPPENS;
882 for (int i = 0; i < (int)_selectedObjects.size(); i++)
884 int id = _selectedObjects[i];
885 GObjectController* cont = _controllers[id];
886 cont->getView()->setState(SELECTED);
887 cont->getModel()->notifyObservers(_idManager);
893 //=========================================================================
894 void wxVtkSceneManager::CancelConnection()
896 if(_worldState==INIT_CREATION_CONTOUR)
898 _worldState=NOTHING_HAPPENS;
899 //int lastId = _controllers.size()-1;
901 GConnectorController *connector = (GConnectorController*)_controllers[_idConnectionInCreation];
902 connector->removeFromScene();
903 unregisterController(connector);
904 _controllers.erase(_idConnectionInCreation);
906 std::map<int, GObjectController*>::iterator it;
907 for(it = _controllers.begin(); it != _controllers.end(); ++it)
909 GObjectController *desc = it->second;
910 desc->SetActive(true);
911 desc->getView()->setState(NOTHING_HAPPENS);
912 desc->getModel()->notifyObservers(_idManager);
918 //=========================================================================
920 bool wxVtkSceneManager::OnRightButtonUp()
922 if(_worldState==INIT_CREATION_CONTOUR)
926 UnSelectBlackBoxes();
930 //=========================================================================
932 GObjectController *wxVtkSceneManager::GetGBlackBoxControlerPointedByMouse()
934 GObjectController *result=NULL;
936 wxVTKRenderWindowInteractor *wxVTKiren;
937 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
938 wxVTKiren->GetEventPosition(X,Y);
940 std::map<int, GObjectController*>::iterator it;
942 for(it = _controllers.begin(); it != _controllers.end() ; ++it)
944 GObjectController *cont = it->second;
945 int type = cont->getGObjectType();
947 if( cont->getView()->isPointInside(X,Y)==true )
953 } // if isPointInside
958 //=========================================================================
959 void wxVtkSceneManager::UnSelectBlackBoxes()
961 for (int i=0; i< (int)_selectedObjects.size(); i++)
963 int id = _selectedObjects[i];
964 GObjectController* control = _controllers[id];
965 control->getView()->setState(NOTHING_HAPPENS);
966 }// for _selectedObjects
967 _selectedObjects.clear();
970 //=========================================================================
971 bool wxVtkSceneManager::OnLeftDClick()
973 GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
976 UnSelectBlackBoxes();
977 _parent->editBlackBox( (GBlackBoxModel*)cont->getModel() );
983 wxVTKRenderWindowInteractor *wxVTKiren;
984 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
985 wxVTKiren->GetEventPosition(X,Y);
987 std::map<int, GObjectController*>::iterator it;
989 bool clickOnObject = false;
991 for(it = _controllers.begin(); it != _controllers.end() && clickOnObject==false; ++it)
993 GObjectController *cont = it->second;
994 int type = cont->getGObjectType();
996 if(cont->getView()->isPointInside(X,Y))
1000 for (int i=0; i< (int)_selectedObjects.size(); i++)
1002 int id = _selectedObjects[i];
1003 GObjectController* control = _controllers[id];
1004 control->getView()->setState(NOTHING_HAPPENS);
1006 _selectedObjects.clear();
1008 GBlackBoxModel *bbmodel = (GBlackBoxModel*)cont->getModel();
1009 _parent->editBlackBox(bbmodel);
1011 clickOnObject = true;
1015 if(clickOnObject==false)
1017 //_parent->editDiagramParameters(this);
1023 //=========================================================================
1025 bool wxVtkSceneManager::OnChar()
1027 char keyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
1029 // KeyCode 127 : Delete Key
1030 // KeyCode 8 : Backspace Key
1031 if(keyCode == 8 || keyCode == 127)
1033 if(_selectedObjects.size()>0)
1035 for(int i=0;i<(int)_selectedObjects.size();i++)
1037 int id = _selectedObjects[i];
1038 std::map<int,GObjectController*>::iterator it;
1039 it = _controllers.find(id);
1040 if (it!=_controllers.end())
1045 _selectedObjects.clear();
1052 //=========================================================================
1054 void wxVtkSceneManager::AddControlerToBeRemove(std::vector<int> *controllersToRemove, int id)
1059 for(i=0 ; i < (int)controllersToRemove->size() ; i++ )
1061 if (id == (*controllersToRemove)[i] )
1069 controllersToRemove->push_back( id );
1074 //=========================================================================
1076 void wxVtkSceneManager::deleteObject(int id)
1078 GObjectController *control = _controllers[id];
1079 std::vector<int> controllersToRemove;
1081 if(control->getGObjectType()==GBLACKBOX || control->getGObjectType()==GCOMPLEXINPUTPORT || control->getGObjectType()==GCOMPLEXOUTPUTPORT)
1083 GBoxModel *bbmod = (GBoxModel*)control->getModel();
1084 std::vector<GPortModel*> inputs = bbmod->getInputPorts();
1086 bool boxConnected = false;
1088 // Add box input controllers to be removed
1089 for(int i = 0;i< (int)inputs.size();i++)
1091 AddControlerToBeRemove( &controllersToRemove, inputs[i]->getObjectId() );
1092 if(inputs[i]->isConnected())
1094 boxConnected = true;
1098 std::vector<GPortModel*> outputs = bbmod->getOutputPorts();
1100 // Add box output controllers to be removed
1101 for(int i = 0;i<(int)outputs.size();i++)
1103 AddControlerToBeRemove( &controllersToRemove, outputs[i]->getObjectId() );
1104 if(outputs[i]->isConnected())
1106 boxConnected = true;
1110 // Add connection controllers to be removed
1111 std::map<int, GObjectController*>::iterator it;
1112 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1114 GObjectController *cont = it->second;
1115 int type = cont->getGObjectType();
1116 if(type==GCONNECTOR)
1118 GConnectorModel *conMod = (GConnectorModel*)cont->getModel();
1119 if(conMod->getStartPort()!=NULL && conMod->getStartPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
1121 AddControlerToBeRemove( &controllersToRemove, conMod->getObjectId() );
1123 if(conMod->getEndPort()!=NULL && conMod->getEndPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
1125 AddControlerToBeRemove( &controllersToRemove, conMod->getObjectId() );
1130 // Add box controller to be removed
1131 AddControlerToBeRemove( &controllersToRemove, bbmod->getObjectId() );
1133 else if(control->getGObjectType()==GCONNECTOR)
1135 GConnectorModel *conMod = (GConnectorModel*)control->getModel();
1136 AddControlerToBeRemove( &controllersToRemove, conMod->getObjectId() );
1140 std::map<int,GObjectController*>::iterator it;
1142 for(int i = 0;i<(int)controllersToRemove.size();i++)
1144 int key = controllersToRemove[i];
1145 it = _controllers.find( key );
1146 GObjectController *cont = _controllers[ key ];
1149 cont->removeFromScene();
1150 unregisterController((InteractorStyleMaracas*)cont);
1151 _controllers.erase(it);
1156 //=========================================================================
1158 void wxVtkSceneManager::displayBlackBoxInfo(std::string packageName, std::string boxName)
1160 _parent->displayBlackBoxInfo(packageName,boxName);
1163 //=========================================================================
1165 void wxVtkSceneManager::updateStatusBar(std::string textStatus)
1167 _parent->updateStatusBar(textStatus);
1171 //=========================================================================
1172 std::string wxVtkSceneManager::LineNumber(bool withLineNumber, int &value)
1174 std::string result="";
1175 if (withLineNumber==true)
1178 stringstream StrStream;
1180 std::string strValue=StrStream.str();
1184 }else if (value<100)
1189 result+=strValue+": ";
1193 //=========================================================================
1195 std::string wxVtkSceneManager::getDiagramBBS(bool wln)
1197 bool existsExec=false;
1199 std::vector<std::string> packages;
1200 std::vector<int> boxes;
1201 std::vector<int> connections;
1202 std::vector<int> execBoxes;
1204 std::map<int, GObjectController*>::iterator it;
1206 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1208 GObjectController *desc = it->second;
1209 int type = desc->getGObjectType();
1213 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
1215 std::string pkg = mod->getBBTKPackage();
1216 bool existsPkg = false;
1217 for(int t = 0;t< (int)packages.size() && existsPkg == false;t++)
1219 if(packages[t]==pkg)
1226 packages.push_back(pkg);
1230 boxes.push_back(it->first);
1231 if(mod->isExecutable())
1233 execBoxes.push_back(it->first);
1237 else if(type==GCONNECTOR)
1239 connections.push_back(it->first);
1244 std::string script = "";
1245 script+=LineNumber(wln,lnNmbr)+"# BBTK GEditor Script\n";
1246 script+=LineNumber(wln,lnNmbr)+"# ----------------------\n";
1247 script+=LineNumber(wln,lnNmbr)+"\n";
1250 script+=LineNumber(wln,lnNmbr)+"include std\n"; // EED
1251 script+=LineNumber(wln,lnNmbr)+"include itkvtk\n"; // EED
1253 for(i = 0; i< (int)packages.size();i++)
1255 script+=LineNumber(wln,lnNmbr);
1257 script+=packages[i];
1261 script+=LineNumber(wln,lnNmbr);
1267 script+=LineNumber(wln,lnNmbr);
1268 script+="author \"";
1272 script+=LineNumber(wln,lnNmbr);
1273 script+="description \"";
1274 script+=_Description;
1277 script+=LineNumber(wln,lnNmbr);
1278 script+="category \"";
1282 script+=LineNumber(wln,lnNmbr);
1286 // script+="include std\n"; // JPR
1288 for(i = 0; i < (int)boxes.size();i++)
1290 script+=LineNumber(wln,lnNmbr);
1293 GObjectController *control = _controllers[id];
1294 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1296 script+=model->getBBTKType();
1298 script+=model->getBBTKName();
1301 std::vector<GPortModel*> inputs = model->getInputPorts();
1302 for(int j = 0; j < (int)inputs.size();j++)
1304 GPortModel* inputPort = inputs[j];
1305 if(inputPort->isValueSet())
1307 script+=LineNumber(wln,lnNmbr);
1309 script+=model->getBBTKName();
1311 script+=inputPort->getBBTKName();
1313 script+=inputPort->getValue();
1318 script+=LineNumber(wln,lnNmbr);
1323 script+=LineNumber(wln,lnNmbr);
1326 for(i = 0; i<(int)connections.size();i++)
1328 script+=LineNumber(wln,lnNmbr);
1330 int id = connections[i];
1331 GObjectController *control = _controllers[id];
1332 GConnectorModel *model = (GConnectorModel*)control->getModel();
1334 //Start Connection info
1335 GPortModel *start = model->getStartPort();
1336 script+=start->getParentBox()->getBBTKName();
1338 script+=start->getBBTKName();
1342 //End Connection info
1343 GPortModel *end = model->getEndPort();
1344 script+=end->getParentBox()->getBBTKName();
1346 script+=end->getBBTKName();
1351 script+=LineNumber(wln,lnNmbr);
1353 for(i = 0; i<(int)execBoxes.size();i++)
1355 script+=LineNumber(wln,lnNmbr);
1357 int id = execBoxes[i];
1358 GObjectController *control = _controllers[id];
1359 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1361 script+=model->getBBTKName();
1370 //=========================================================================
1372 std::string wxVtkSceneManager::saveComplexBoxBBS()
1374 std::vector<std::string> packages;
1375 std::vector<int> boxes;
1376 std::vector<int> connections;
1377 std::vector<int> execBoxes;
1379 std::map<int, GObjectController*>::iterator it;
1381 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1383 GObjectController *desc = it->second;
1384 int type = desc->getGObjectType();
1388 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
1390 std::string pkg = mod->getBBTKPackage();
1391 bool existsPkg = false;
1392 for(int t = 0;t<(int)packages.size() && existsPkg == false;t++)
1394 if(packages[t]==pkg)
1401 packages.push_back(pkg);
1405 boxes.push_back(it->first);
1406 if(mod->isExecutable())
1408 execBoxes.push_back(it->first);
1411 else if(type==GCONNECTOR)
1413 connections.push_back(it->first);
1417 std::string script = "";
1419 script+="include std\n"; // EED
1420 script+="include itkvtk\n"; // EED
1422 for(i = 0; i<(int)packages.size();i++)
1425 script+=packages[i];
1431 // Definition of a complex box
1433 script+=_cbName+" "+_cbPackageName;
1437 script+="author \"";
1441 script+="description \"";
1442 script+=_Description;
1446 script+="category \"";
1453 for(i = 0; i<(int)boxes.size();i++)
1457 GObjectController *control = _controllers[id];
1458 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1460 script+=model->getBBTKType();
1462 script+=model->getBBTKName();
1465 std::vector<GPortModel*> inputs = model->getInputPorts();
1466 for(int j = 0; j<(int)inputs.size();j++)
1468 GPortModel* inputPort = inputs[j];
1469 if(inputPort->isValueSet())
1472 script+=model->getBBTKName();
1474 script+=inputPort->getBBTKName();
1476 script+=inputPort->getValue();
1484 // Create connections in the script. If the connection is made with a complex port, it is created the input or output
1486 std::string complexInputs="";
1487 std::string complexOutputs="";
1490 for(i = 0; i<(int)connections.size();i++)
1492 int id = connections[i];
1493 GObjectController *control = _controllers[id];
1494 GConnectorModel *model = (GConnectorModel*)control->getModel();
1497 GPortModel *start = model->getStartPort();
1498 GBoxModel *startBox =start->getParentBox();
1500 GPortModel *end = model->getEndPort();
1501 GBoxModel *endBox =end->getParentBox();
1503 if(startBox->getGObjectType()==GCOMPLEXINPUTPORT)
1505 complexInputs+="input ";
1506 complexInputs+=startBox->getBBTKName();
1509 complexInputs+=endBox->getBBTKName();
1511 complexInputs+=end->getBBTKName();
1514 complexInputs+="\" \"";
1516 complexInputs+="\n";
1518 else if(endBox->getGObjectType()==GCOMPLEXOUTPUTPORT)
1520 complexOutputs+="output ";
1521 complexOutputs+=endBox->getBBTKName();
1523 complexOutputs+=" ";
1524 complexOutputs+=startBox->getBBTKName();
1525 complexOutputs+=".";
1526 complexOutputs+=start->getBBTKName();
1528 complexOutputs+=" ";
1529 complexOutputs+="\" \"";
1531 complexOutputs+="\n";
1536 script+=startBox->getBBTKName();
1538 script+=start->getBBTKName();
1542 //End Connection info
1543 script+=endBox->getBBTKName();
1545 script+=end->getBBTKName();
1553 for(i = 0; i<(int)execBoxes.size();i++)
1556 int id = execBoxes[i];
1557 GObjectController *control = _controllers[id];
1558 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1560 script+=model->getBBTKName();
1565 script+="# Complex input ports\n";
1566 script+=complexInputs;
1569 script+="# Complex output ports\n";
1570 script+=complexOutputs;
1579 //=========================================================================
1581 void wxVtkSceneManager::deleteAllBoxes()
1583 std::map<int, GObjectController*>::iterator it;
1584 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1586 GObjectController *cont = it->second;
1587 cont->removeFromScene();
1588 unregisterController((InteractorStyleMaracas*)cont);
1590 _selectedObjects.clear();
1591 _controllers.clear();
1595 //=========================================================================
1598 void wxVtkSceneManager::refresh()
1600 _baseView->Refresh();
1602 //=========================================================================
1604 void wxVtkSceneManager::refreshScene()
1606 _baseView->RefreshView();
1609 //=========================================================================
1611 void wxVtkSceneManager::centerView()
1614 _baseView->GetRenderer()->GetActiveCamera()->GetFocalPoint(temp);
1615 _baseView->GetRenderer()->GetActiveCamera()->SetFocalPoint(0,0,temp[2]);
1616 _baseView->GetRenderer()->GetActiveCamera()->GetPosition(temp);
1617 _baseView->GetRenderer()->GetActiveCamera()->SetPosition(0,0,temp[2]);
1618 _baseView->RefreshView();
1622 //=========================================================================
1624 void wxVtkSceneManager::saveDiagram(std::string &content)
1628 content+="CATEGORY:";
1629 content+=GetCategory();
1632 content+="DESCRIPTION:";
1633 content+=GetDescription();
1637 content+=GetAuthor();
1641 //Print info IF COMPLEX BOX
1642 content+="COMPLEXBOX:";
1647 content+="COMPLEXBOXNAME:";
1648 content+=GetCbName();
1651 content+="PACKAGENAME:";
1652 content+=GetCbPackageName();
1655 //Print info complex input ports
1656 std::vector<int> inputs = getComplexInputPorts();
1657 int insize = inputs.size();
1658 content+="COMPLEXINPUTS:";
1659 sprintf (buffer, "%d", insize);
1663 for(int i = 0;i<insize;i++)
1666 GObjectController *cont = _controllers[id];
1667 cont->getModel()->save(content);
1670 //Print info complex output ports
1671 std::vector<int> outputs = getComplexOutputPorts();
1672 int outsize = outputs.size();
1673 content+="COMPLEXOUTPUTS:";
1674 sprintf (buffer, "%d", outsize);
1678 for(int i = 0;i<outsize;i++)
1680 int id = outputs[i];
1681 GObjectController *cont = _controllers[id];
1682 cont->getModel()->save(content);
1691 std::vector<int> boxes = getBlackBoxes();
1692 int bsize = boxes.size();
1694 sprintf (buffer, "%d", bsize);
1698 for(int i = 0;i<bsize;i++)
1701 GObjectController *cont = _controllers[id];
1702 cont->getModel()->save(content);
1706 std::vector<int> connections = getConnections();
1707 int csize = connections.size();
1708 content+="CONNECTIONS:";
1709 sprintf (buffer, "%d", csize);
1713 for(int i = 0;i<csize;i++)
1715 int id = connections[i];
1716 GObjectController *cont = _controllers[id];
1717 cont->getModel()->save(content);
1722 //=========================================================================
1724 void wxVtkSceneManager::loadDiagram(ifstream &inputStream)
1727 std::string version="<void>";
1728 std::string line="";
1729 char delims[] = ":";
1730 char *result = NULL;
1731 getline(inputStream,line);
1734 while ( !inputStream.eof() )
1736 if(line=="" || line[0]=='#')
1738 getline(inputStream,line);
1739 if (line=="# - BBTKGEditor v 1.0 BBG BlackBox Diagram file")
1741 version=line.substr(18,3);
1743 if (line=="# - BBTKGEditor v 1.1 BBG BlackBox Diagram file")
1745 version=line.substr(18,3);
1747 if (line=="# - BBTKGEditor v 1.2 BBG BlackBox Diagram file")
1749 version=line.substr(18,3);
1752 else if(line=="APP_START")
1759 printf("EED wxVtkSceneManager::loadDiagram version=%s\n",version.c_str());
1764 if ((version!="1.0") && (version!="1.1"))
1766 getline(inputStream,line);//CATEGORY:<category of the box>
1767 char categoryTmp[30];
1768 strcpy( categoryTmp, line.c_str() );
1769 result = strtok( categoryTmp, delims );
1770 result = strtok( NULL, delims );
1771 SetCategory(result);
1773 getline(inputStream,line);//DESCRIPTION:<description of the box>
1774 char descriptionTmp[1024];
1775 strcpy( descriptionTmp, line.c_str() );
1776 result = strtok( descriptionTmp, delims );
1777 result = strtok( NULL, delims );
1778 SetDescription(result);
1780 getline(inputStream,line);//AUTHOR:<author>
1781 char authorTmp[255];
1782 strcpy( authorTmp, line.c_str() );
1783 result = strtok( authorTmp, delims );
1784 result = strtok( NULL, delims );
1789 getline(inputStream,line);//COMPLEX_BOX:TRUE|FALSE
1790 char complexTmp[30];
1791 strcpy( complexTmp, line.c_str() );
1792 result = strtok( complexTmp, delims );
1793 result = strtok( NULL, delims );
1794 std::string isComplexBox(result);
1796 if(isComplexBox=="TRUE")
1800 if ((version!="1.0") && (version!="1.1"))
1802 getline(inputStream,line);//COMPLEXNAME:<name of the complex box>
1803 char complexboxnameTmp[255];
1804 strcpy( complexboxnameTmp, line.c_str() );
1805 result = strtok( complexboxnameTmp, delims );
1806 result = strtok( NULL, delims );
1809 getline(inputStream,line);//PACKAGENAME:<name of the package of the box>
1810 char packagenameTmp[255];
1811 strcpy( packagenameTmp, line.c_str() );
1812 result = strtok( packagenameTmp, delims );
1813 result = strtok( NULL, delims );
1814 SetCbPackageName(result);
1818 //-----------------------
1819 //- COMPLEX INPUT PORTS
1820 //-----------------------
1821 getline(inputStream,line);//COMPLEXINPUTS:num
1823 strcpy( inputs, line.c_str() );
1824 result = strtok( inputs, delims );
1825 result = strtok( NULL, delims );
1828 std::istringstream inps(result);
1831 for(int i = 0;i<numInputs;i++)
1834 getline(inputStream,line);//COMPLEX_PORT
1835 getline(inputStream,line);//name
1836 std::string inputPortName(line);
1839 getline(inputStream,line);//xInic:yInic:zInic
1841 strcpy( coord, line.c_str() );
1842 result = strtok( coord, delims );//xInic
1843 std::string xInic(result);
1844 result = strtok( NULL, delims );//yInic
1845 std::string yInic(result);
1846 result = strtok( NULL, delims );//zInic
1847 std::string zInic(result);
1849 double xIn, yIn, zIn;
1850 std::istringstream xSt(xInic);
1852 std::istringstream ySt(yInic);
1854 std::istringstream zSt(zInic);
1857 getline(inputStream,line);//FIN_COMPLEX_PORT
1859 configGComBoxInputOutputPort(true, inputPortName,xIn,yIn,zIn);
1862 } // for input complex box
1865 //-----------------------
1866 //- COMPLEX OUTPUT PORTS
1867 //-----------------------
1869 getline(inputStream,line);//COMPLEXOUTPUTS:num
1871 strcpy( outputs, line.c_str() );
1872 result = strtok( outputs, delims );
1873 result = strtok( NULL, delims );
1876 std::istringstream outps(result);
1877 outps >> numOutputs;
1879 for(int i = 0;i<numOutputs;i++)
1882 getline(inputStream,line);//COMPLEX_PORT
1883 getline(inputStream,line);//name
1884 std::string outputPortName(line);
1887 getline(inputStream,line);//xInic:yInic:zInic
1889 strcpy( coord, line.c_str() );
1890 result = strtok( coord, delims );//xInic
1891 std::string xInic(result);
1892 result = strtok( NULL, delims );//yInic
1893 std::string yInic(result);
1894 result = strtok( NULL, delims );//zInic
1895 std::string zInic(result);
1897 double xIn, yIn, zIn;
1898 std::istringstream xSt(xInic);
1900 std::istringstream ySt(yInic);
1902 std::istringstream zSt(zInic);
1905 getline(inputStream,line);//FIN_COMPLEX_PORT
1907 configGComBoxInputOutputPort(false, outputPortName,xIn,yIn,zIn);
1909 } // for output complex box
1914 getline(inputStream,line);//BOXES:num
1916 strcpy( boxes, line.c_str() );
1917 result = strtok( boxes, delims );
1918 result = strtok( NULL, delims );
1921 std::istringstream is(result);
1924 for(int i = 0;i<numBoxes;i++)
1927 getline(inputStream,line);//BOX
1928 getline(inputStream,line);//package:type:name
1930 strcpy( box, line.c_str() );
1931 result = strtok( box, delims );//package
1932 std::string package(result);
1933 result = strtok( NULL, delims );//type
1934 std::string type(result);
1935 result = strtok( NULL, delims );//name
1936 std::string name(result);
1938 getline(inputStream,line);//ISEXEC:TRUE|FALSE
1940 strcpy( exec, line.c_str() );
1941 result = strtok( exec, delims );//ISEXEC
1942 result = strtok( NULL, delims );//TRUE|FALSE
1943 std::string isExec(result);
1946 getline(inputStream,line);//xInic:yInic:zInic
1948 strcpy( coord, line.c_str() );
1949 result = strtok( coord, delims );//xInic
1950 std::string xInic(result);
1951 result = strtok( NULL, delims );//yInic
1952 std::string yInic(result);
1953 result = strtok( NULL, delims );//zInic
1954 std::string zInic(result);
1956 double xIn, yIn, zIn;
1957 std::istringstream xSt(xInic);
1959 std::istringstream ySt(yInic);
1961 std::istringstream zSt(zInic);
1965 getline(inputStream,line);//xEnd:yEnd:zEnd
1966 strcpy( coord, line.c_str() );
1967 result = strtok( coord, delims );//xEnd
1968 std::string xEnd(result);
1969 result = strtok( NULL, delims );//yEnd
1970 std::string yEnd(result);
1971 result = strtok( NULL, delims );//zEnd
1972 std::string zEnd(result);
1974 double xEn, yEn, zEn;
1975 std::istringstream xEt(xEnd);
1977 std::istringstream yEt(yEnd);
1979 std::istringstream zEt(zEnd);
1982 bool boxExecutable=false;
1985 boxExecutable= true;
1988 int idBox = createGBlackBox(xIn,yIn,package,type);
1989 configGBlackBox(idBox, xIn,yIn,zIn,name, boxExecutable,xEn,yEn,zEn);
1991 GObjectController *cont = _controllers[idBox];
1992 GBlackBoxModel *bbmod = (GBlackBoxModel*)cont->getModel();
1996 getline(inputStream,line);//PORT o FIN_BOX
1997 std::string port=line.substr(0,4);
2000 getline(inputStream,line);//name:value
2002 strcpy( poort, line.c_str() );
2003 result = strtok( poort, delims );//name
2004 std::string name(result);
2005 result = strtok( NULL, delims );//value
2006 std::string value(result);
2008 bbmod->setValueToInput(name,value);
2010 getline(inputStream,line);//PORT o FIN_BOX
2011 port=line.substr(0,4);
2014 //EED bbmod->notifyObservers(_idManager);
2019 getline(inputStream,line);//CONNECTIONS:num
2021 strcpy( conns, line.c_str() );
2022 result = strtok( conns, delims );
2023 result = strtok( NULL, delims );
2026 std::istringstream isCons(result);
2029 for(int i = 0;i<numConns;i++)
2032 getline(inputStream,line);//CONNECTION
2033 getline(inputStream,line);//Startbox.PortName:EndBox.PortName
2036 strcpy( connec, line.c_str() );
2037 result = strtok( connec, delims );
2038 std::string nameStartBox(result);
2039 result = strtok( NULL, delims );
2040 std::string nameStartPort(result);
2041 result = strtok( NULL, delims );
2042 std::string nameEndBox(result);
2043 result = strtok( NULL, delims );
2044 std::string nameEndPort(result);
2046 int idCon = configGConnetion(nameStartBox, nameStartPort, nameEndBox, nameEndPort);
2050 //Readding control points of the manualContour
2052 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
2053 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
2054 vtkGConnectorView *conView= (vtkGConnectorView*)tempp->getView();
2055 getline(inputStream,line); //NumberOfControlPoints:##
2056 strcpy( conns, line.c_str() );
2057 result = strtok( conns, delims );
2058 result = strtok( NULL, delims );
2060 int numberOfControlPoints;
2061 std::istringstream isCons(result);
2062 isCons >> numberOfControlPoints;
2064 for (int ii=0;ii<numberOfControlPoints;ii++)
2066 getline(inputStream,line); //XX:YY:ZZ
2068 strcpy( connec, line.c_str() );
2071 result = strtok( connec, delims );
2072 std::istringstream isPointX(result);
2074 result = strtok( NULL, delims );
2075 std::istringstream isPointY(result);
2077 result = strtok( NULL, delims );
2078 std::istringstream isPointZ(result);
2081 conMod->getManualContourModel()->InsertPoint_id(ii+1,px,py,pz);
2082 conView->getManualContourView()->AddPoint();
2092 //=========================================================================
2096 //=========================================================================
2097 void wxVtkSceneManager::configGComBoxInputOutputPort(bool inputoutput, std::string portName, double xIn, double yIn,double zIn)
2100 if (inputoutput==true)
2102 idPort = createGComplexBoxInputPort(portName);
2104 idPort = createGComplexBoxOutputPort(portName);
2106 GObjectController *cont = _controllers[idPort];
2107 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
2108 cbmod->setInicPoint(xIn,yIn,zIn);
2109 cbmod->notifyObservers(_idManager);
2111 //=========================================================================
2114 //=========================================================================
2115 GBoxModel* wxVtkSceneManager::findGBox(std::string boxname)
2120 GBoxModel *boxModel = NULL;
2121 std::vector<int> lstB = getBlackBoxes();
2122 for(j = 0;j<(int)lstB.size();j++)
2125 bMod = (GBoxModel*)_controllers[idB]->getModel();
2126 if(_controllers[idB]->getModel()->getBBTKName()==boxname)
2132 if((_isComplexBox) && (boxModel==NULL))
2134 std::vector<int> lstInputs = getComplexInputPorts();
2135 for(j = 0;j<(int)lstInputs.size();j++)
2138 bMod = (GBoxModel*)_controllers[idB]->getModel();
2139 if(_controllers[idB]->getModel()->getBBTKName()==boxname)
2145 std::vector<int> lstOutputs = getComplexOutputPorts();
2146 for(j = 0;j<(int)lstOutputs.size();j++)
2148 int idB = lstOutputs[j];
2149 bMod = (GBoxModel*)_controllers[idB]->getModel();
2150 if(_controllers[idB]->getModel()->getBBTKName()==boxname)
2161 //=========================================================================
2164 int wxVtkSceneManager::configGConnetion(std::string nameStartBox, std::string nameStartPort, std::string
2165 nameEndBox, std::string nameEndPort)
2168 GBoxModel *boxModel;
2169 GPortModel *startP = NULL;
2170 GPortModel *endP = NULL;
2172 boxModel= findGBox(nameStartBox);
2175 startP = boxModel->getOutputPort(nameStartPort);
2178 boxModel= findGBox(nameEndBox);
2181 endP = boxModel->getInputPort(nameEndPort);
2185 int idCon = createGConnector(startP);
2186 _worldState = NOTHING_HAPPENS;
2187 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
2189 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
2190 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
2191 tempp->endContourCreation();
2192 conMod->setEndPort(endP);
2193 conView->updateStartEndPoints();
2197 //=========================================================================
2199 bool wxVtkSceneManager::boxExist(std::string boxname)
2202 std::map<int, GObjectController*>::iterator it;
2203 for(it = _controllers.begin(); it != _controllers.end(); ++it)
2205 GObjectController *cont = it->second;
2206 if(cont->getModel()->getBBTKName()==boxname)
2214 //=========================================================================
2216 std::vector<int> wxVtkSceneManager::getBlackBoxes()
2218 std::vector<int> vect;
2219 std::map<int, GObjectController*>::iterator it;
2220 for(it = _controllers.begin(); it != _controllers.end(); ++it)
2222 GObjectController *cont = it->second;
2223 if(cont->getGObjectType()==GBLACKBOX)
2225 vect.push_back(cont->getId());
2231 //=========================================================================
2233 std::vector<int> wxVtkSceneManager::getComplexInputPorts()
2235 std::vector<int> vect;
2236 std::map<int, GObjectController*>::iterator it;
2237 for(it = _controllers.begin(); it != _controllers.end(); ++it)
2239 GObjectController *cont = it->second;
2240 if(cont->getGObjectType()==GCOMPLEXINPUTPORT)
2242 vect.push_back(cont->getId());
2248 //=========================================================================
2250 std::vector<int> wxVtkSceneManager::getComplexOutputPorts()
2252 std::vector<int> vect;
2253 std::map<int, GObjectController*>::iterator it;
2254 for(it = _controllers.begin(); it != _controllers.end(); ++it)
2256 GObjectController *cont = it->second;
2257 if(cont->getGObjectType()==GCOMPLEXOUTPUTPORT)
2259 vect.push_back(cont->getId());
2265 //=========================================================================
2267 std::vector<int> wxVtkSceneManager::getConnections()
2269 std::vector<int> vect;
2270 std::map<int, GObjectController*>::iterator it;
2271 for(it = _controllers.begin(); it != _controllers.end(); ++it)
2273 GObjectController *cont = it->second;
2274 if(cont->getGObjectType()==GCONNECTOR)
2276 vect.push_back(cont->getId());
2282 //=========================================================================
2284 bool wxVtkSceneManager::isComplexBox()
2286 return _isComplexBox;
2289 //=========================================================================
2291 void wxVtkSceneManager::setComplexBox(bool val)
2296 //=========================================================================
2298 int wxVtkSceneManager::addObjectController(GObjectController* objController)
2300 //Register the controller of the new object
2301 registerController((InteractorStyleMaracas*) objController);
2303 //Add the object to the objects list
2304 int newId = _contLastId;//_controllers.size();
2305 objController->setId(newId);
2306 _controllers[newId] = objController;
2311 //=========================================================================
2313 int wxVtkSceneManager::getNumSelectedObjects()
2315 return _selectedObjects.size();
2318 //=========================================================================
2320 std::map<int,GObjectController*> wxVtkSceneManager::getSelectedObjects()
2322 std::map<int,GObjectController*> mapSelected;
2324 std::map<int, GObjectController*>::iterator it;
2325 for(it = _controllers.begin(); it != _controllers.end(); ++it)
2327 GObjectController *cont = it->second;
2328 if(cont->getGObjectType()==GBLACKBOX && cont->getView()->getState()==SELECTED)
2330 mapSelected[cont->getId()]=cont;
2334 std::map<int, GObjectController*>::iterator it2;
2335 for(it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
2337 GObjectController *cont = it2->second;
2338 if(cont->getGObjectType()==GCONNECTOR)
2340 GConnectorModel* cmod = (GConnectorModel*)cont->getModel();
2341 GBoxModel* endPortParentBox = cmod->getEndPort()->getParentBox();
2342 GBoxModel* startPortParentBox = cmod->getStartPort()->getParentBox();
2344 std::map<int, GObjectController*>::iterator iterOBJ1 = mapSelected.find(startPortParentBox->getObjectId());
2345 std::map<int, GObjectController*>::iterator iterOBJ2 = mapSelected.find(endPortParentBox->getObjectId());
2347 if(iterOBJ1 != mapSelected.end() && iterOBJ2 != mapSelected.end())
2349 int ID = cont->getId();
2350 mapSelected[ID]=cont;
2357 //=========================================================================
2359 void wxVtkSceneManager::addObjects(std::map<int,GObjectController*> objectsMap)
2362 std::map<int,int> oldIdNewIdBoxes;
2363 std::vector<int> connections;
2365 std::map<int, GObjectController*>::iterator it;
2366 for(it = objectsMap.begin(); it != objectsMap.end(); ++it)
2368 GObjectController *cont = it->second;
2369 int type = cont->getGObjectType();
2374 double xInic, yInic,zInic;
2375 GBlackBoxModel* copyBox = (GBlackBoxModel*)cont->getModel();
2376 copyBox->getInicPoint(xInic,yInic,zInic);
2377 int idBox = createGBlackBox(0,0,copyBox->getBBTKPackage(),copyBox->getBBTKType());
2379 int idcB = copyBox->getObjectId();
2380 oldIdNewIdBoxes[idcB]=idBox;
2381 cont = _controllers[idBox];
2382 GBlackBoxModel* newbox = (GBlackBoxModel*)cont->getModel();
2383 newbox->setInicPoint(xInic,yInic,zInic);
2384 int num = newbox->getNumInputPorts();
2385 for(int j=0;j<num;j++)
2387 newbox->setValueToInputPort(j,copyBox->getValueInputPort(j));
2389 newbox->notifyObservers(_idManager);
2391 else if(type==GCONNECTOR)
2393 int idCon = cont->getId();
2394 connections.push_back(idCon);
2399 for(int i = 0 ;i<(int)connections.size();i++)
2401 int objId = connections[i];
2402 GObjectController *cont = objectsMap[objId];
2403 GConnectorModel* connectModel = (GConnectorModel*)cont->getModel();
2405 GPortModel* startPort = connectModel->getStartPort();
2406 int startPortIndex = startPort->getPosInBox();
2407 GPortModel* endPort = connectModel->getEndPort();
2408 int endPortIndex = endPort->getPosInBox();
2410 GBlackBoxModel* startPortParentBox = (GBlackBoxModel*)startPort->getParentBox();
2411 GBlackBoxModel* endPortParentBox = (GBlackBoxModel*)endPort->getParentBox();
2413 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2414 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2416 GBlackBoxModel* newStartBox = (GBlackBoxModel*)_controllers[idNewStartBox]->getModel();
2417 GBlackBoxModel* newEndBox = (GBlackBoxModel*)_controllers[idNewEndBox]->getModel();
2419 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2420 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2422 // Creates connection
2423 int idCon = createGConnector(newStartPort);
2424 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
2425 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
2426 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
2427 tempp->endContourCreation();
2428 conMod->setEndPort(newEndPort);
2429 conView->updateStartEndPoints();
2432 std::map<int, int>::iterator itIds;
2433 for(itIds = oldIdNewIdBoxes.begin(); itIds != oldIdNewIdBoxes.end(); ++itIds)
2435 int idOld = itIds->first;
2436 int idNew = itIds->second;
2438 GBlackBoxModel* oldBox = (GBlackBoxModel*)objectsMap[idOld]->getModel();
2439 GBlackBoxModel* newBox = (GBlackBoxModel*)_controllers[idNew]->getModel();
2441 std::vector<int> oldInputConnections = oldBox->getConnectedInputs();
2442 std::vector<int> oldOutputConnections = oldBox->getConnectedOutputs();
2443 std::vector<int> newInputConnections = newBox->getConnectedInputs();
2444 std::vector<int> newOutputConnections = newBox->getConnectedOutputs();
2446 for(int k = 0; k<(int)oldInputConnections.size();k++)
2449 //EED int toCreate=-1;
2450 for(int l = 0; l<(int)newInputConnections.size() && !exist;l++)
2452 if(oldInputConnections[k]==newInputConnections[l])
2460 //Create complex input
2461 int posInBox = oldInputConnections[k];
2462 GPortModel* inputPort = oldBox->getInputPort(posInBox);
2463 std::string inputPortName = inputPort->getBBTKName();
2464 int idInputPort = createGComplexBoxInputPort(inputPortName);
2465 GObjectController *cont = _controllers[idInputPort];
2466 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
2468 inputPort->getInicPoint(xIn,yIn,zIn);
2470 cbmod->setInicPoint(xIn,yIn,zIn);
2471 cbmod->notifyObservers(_idManager);
2473 GPortModel* inputPortEnd = newBox->getInputPort(posInBox);
2475 // Creates connection
2476 int idCon = createGConnector(cbmod->getOutputPort(0));
2477 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
2478 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
2479 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
2480 tempp->endContourCreation();
2481 conMod->setEndPort(inputPortEnd);
2482 conView->updateStartEndPoints();
2489 for(int k = 0; k<(int)oldOutputConnections.size();k++)
2492 //EED int toCreate=-1;
2493 for(int l = 0; l<(int)newOutputConnections.size() && !exist;l++)
2495 if(oldOutputConnections[k]==newOutputConnections[l])
2503 //Create complex output
2504 int posInBox = oldOutputConnections[k];
2505 GPortModel* outputPort = oldBox->getOutputPort(posInBox);
2506 std::string outputPortName = outputPort->getBBTKName();
2507 int idOutputPort = createGComplexBoxOutputPort(outputPortName);
2508 GObjectController *cont = _controllers[idOutputPort];
2509 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
2511 outputPort->getInicPoint(xIn,yIn,zIn);
2513 cbmod->setInicPoint(xIn,yIn,zIn);
2514 cbmod->notifyObservers(_idManager);
2516 GPortModel* outputPortEnd = newBox->getOutputPort(posInBox);
2518 // Creates connection
2519 int idCon = createGConnector(outputPortEnd);
2520 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
2521 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
2522 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
2523 tempp->endContourCreation();
2524 conMod->setEndPort(cbmod->getInputPort(0));
2525 conView->updateStartEndPoints();
2537 //=========================================================================
2538 void wxVtkSceneManager::SetCbName(std::string cbName)
2543 _cbName="<complex box name>";
2547 //=========================================================================
2548 std::string wxVtkSceneManager::GetCbName()
2553 //=========================================================================
2554 void wxVtkSceneManager::SetCbPackageName(std::string packagename)
2556 _cbPackageName=packagename;
2557 if (_cbPackageName=="")
2559 _cbPackageName="<package name of the complex box>";
2563 //=========================================================================
2564 std::string wxVtkSceneManager::GetCbPackageName()
2566 return _cbPackageName;
2569 //=========================================================================
2570 void wxVtkSceneManager::SetAuthor(std::string author)
2575 _Author="<author of the box>";
2579 //=========================================================================
2580 std::string wxVtkSceneManager::GetAuthor()
2585 //=========================================================================
2586 void wxVtkSceneManager::SetCategory(std::string category)
2591 _Category="<category of the box>";
2595 //=========================================================================
2596 std::string wxVtkSceneManager::GetCategory()
2601 //=========================================================================
2602 void wxVtkSceneManager::SetDescription(std::string description)
2604 _Description=description;
2605 if (_Description=="")
2607 _Description="<description of the box>";
2611 //=========================================================================
2612 std::string wxVtkSceneManager::GetDescription()
2614 return _Description;
2617 //=========================================================================
2625 } // EO namespace bbtk