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 vtkInteractorStyleBaseView2D *interactorstylebaseview = vtkInteractorStyleBaseView2D::New();
104 _baseView->SetInteractorStyleBaseView(interactorstylebaseview);
106 // Important to activate the 2D interaction system
107 wxVTKRenderWindowInteractor *iren = _baseView->GetWxVTKRenderWindowInteractor();
108 interactorstylebaseview->SetInteractor ( iren );
109 iren->SetInteractorStyle(interactorstylebaseview);
110 interactorstylebaseview->SetwxVtkBaseView(_baseView);
112 _baseView->GetRenderer()->GetActiveCamera()->ParallelProjectionOn();
113 _baseView->GetRenderer()->ResetCamera(-100,100,-100,100,800,1100);
115 _baseView->GetRenderer()->SetBackground(0.9,0.9,0.9);
116 _baseView->GetRenderer()->GradientBackgroundOn();
117 _baseView->Refresh();
120 _textActor = vtkTextActor3D::New();
121 _textActor->SetPosition( -9999 , -9999 , 900 );
122 _textActor->SetInput( "<void>" );
123 _textActor->GetTextProperty()->SetFontSize(60);
124 _textActor->GetTextProperty()->BoldOn();
125 _textActor->GetTextProperty()->SetColor(PORTTEXT_NH_R,PORTTEXT_NH_G,PORTTEXT_NH_B);
127 _baseView->GetRenderer()->AddActor( _textActor );
130 // Actor Fill_Port_Text
137 vtkPolygon *aPolygon = vtkPolygon::New();
138 _fillObjectActor = vtkActor::New();
140 _pts = vtkPoints::New();
142 double w=100,h=10,b=h/15,t=3;
143 _pts->SetNumberOfPoints(21);
144 _pts->InsertPoint(0, xInic+w*0.33-t/2 , yInic , zInic );
145 _pts->InsertPoint(1, xInic+w*0.33 , yInic-t , zInic );
146 _pts->InsertPoint(2, xInic+w*0.33+t/2 , yInic , zInic );
147 _pts->InsertPoint(3, xInic+w*0.33+t/2 , yInic , zInic );
148 _pts->InsertPoint(4, xInic+w-b*4 , yInic+b*0 , zInic );
150 _pts->InsertPoint( 5, xInic+w-b*4 , yInic+b*0 , zInic );
151 _pts->InsertPoint( 6, xInic+w-b*2 , yInic+b*1 , zInic );
152 _pts->InsertPoint( 7, xInic+w-b*1 , yInic+b*2 , zInic );
153 _pts->InsertPoint( 8, xInic+w-b*0 , yInic+b*4 , zInic );
155 _pts->InsertPoint( 9, xInic+w-b*0 , yInic+h-b*4 , zInic );
156 _pts->InsertPoint(10, xInic+w-b*1 , yInic+h-b*2 , zInic );
157 _pts->InsertPoint(11, xInic+w-b*2 , yInic+h-b*1 , zInic );
158 _pts->InsertPoint(12, xInic+w-b*4 , yInic+h-b*0 , zInic );
160 _pts->InsertPoint(13, xInic+b*4 , yInic+h-b*0 , zInic );
161 _pts->InsertPoint(14, xInic+b*2 , yInic+h-b*1 , zInic );
162 _pts->InsertPoint(15, xInic+b*1 , yInic+h-b*2 , zInic );
163 _pts->InsertPoint(16, xInic+b*0 , yInic+h-b*4 , zInic );
165 _pts->InsertPoint(17, xInic+b*0 , yInic+b*4 , zInic );
166 _pts->InsertPoint(18, xInic+b*1 , yInic+b*2 , zInic );
167 _pts->InsertPoint(19, xInic+b*2 , yInic+b*1 , zInic );
168 _pts->InsertPoint(20, xInic+b*4 , yInic+b*0 , zInic );
170 aPolygon->GetPointIds()->SetNumberOfIds(21);
171 for (int i=0;i<21; i++)
173 aPolygon->GetPointIds()->SetId(i, i);
176 vtkUnstructuredGrid *aPolygonGrid = vtkUnstructuredGrid::New();
177 aPolygonGrid->Allocate(1, 1);
178 aPolygonGrid->InsertNextCell(aPolygon->GetCellType(), aPolygon->GetPointIds());
179 aPolygonGrid->SetPoints(_pts);
180 _aPolygonMapper = vtkDataSetMapper::New();
181 _aPolygonMapper->SetInput(aPolygonGrid);
182 _fillObjectActor->SetMapper(_aPolygonMapper);
183 _fillObjectActor->GetProperty()->SetColor(PORTFILL_NH_R,PORTFILL_NH_G,PORTFILL_NH_B);
184 _fillObjectActor->GetProperty()->SetOpacity(0);
185 _aPolygonMapper->Modified();
187 _baseView->GetRenderer()->AddActor( _fillObjectActor );
190 //=========================================================================
192 std::string wxVtkSceneManager::generateANewNameForABox()
194 std::stringstream boxname;
197 boxname << "Box0" << _numBoxes;
199 boxname << "Box" << _numBoxes;
202 return boxname.str();
205 //=========================================================================
207 std::string wxVtkSceneManager::findANewNameForABox()
209 std::string boxname=generateANewNameForABox();
211 while (boxExist(boxname)==true)
213 boxname=generateANewNameForABox();
219 //=========================================================================
220 void wxVtkSceneManager::configGBlackBox(int idBox, double xIn, double yIn, double zIn, std::string name, bool boxExecutable,double xEn,double yEn,double zEn)
222 GObjectController *cont = _controllers[idBox];
223 GBlackBoxModel *bbmod = (GBlackBoxModel*)cont->getModel();
224 bbmod->setBBTKName(name);
225 bbmod->setInicPoint(xIn,yIn,zIn);
226 bbmod->setFinalPoint(xEn,yEn,zEn);
227 bbmod->setExecutable(boxExecutable);
229 bbmod->notifyObservers(_idManager);
234 //=========================================================================
236 int wxVtkSceneManager::createGBlackBox(int x, int y, std::string packageName, std::string boxType)
238 _worldState = NOTHING_HAPPENS;
239 //EED int windowWidth = _baseView->GetRenWin()->GetSize()[0];
240 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
242 int type = GBLACKBOX;
244 //Create the MVC Objects
246 GBlackBoxModel *model = (GBlackBoxModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
247 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
248 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
250 BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxType);
252 //Prepares the initial model
253 //The coordinates obtained are the following. Top-Left:x=0,y=0 Bottom-Right:x=width,y=height
256 double yy = windowHeight-y;
258 //z value is not important yet, because it is only used a parallel projection
260 _baseView->TransCoordScreenToWorld(xx,yy,zz);
261 model->setInicPoint(xx,yy,zz);
263 std::stringstream stream;
265 std::string newBoxName;
266 newBoxName = findANewNameForABox();
269 stream << newBoxName;
271 std::string arraystring = stream.str();
273 model->setBBTKName(arraystring);
274 model->setBBTKType(boxType);
275 model->setBBTKPackage(packageName);
277 model->addObserver(view);
278 model->addObserver(this);
280 //Iterate and create the input ports
281 std::map<std::string, BlackBoxInputDescriptor*> descriptorInMap = descriptor->GetInputDescriptorMap();
282 std::map<std::string, BlackBoxInputDescriptor*>::iterator itInput;
285 for(itInput = descriptorInMap.begin(); itInput != descriptorInMap.end(); ++itInput)
287 BlackBoxInputDescriptor *desc = itInput->second;
288 createGInputPort(GINPUTPORT,i,model,desc);
292 //Iterate and create the output ports
293 std::map<std::string, BlackBoxOutputDescriptor*> descriptorOutMap = descriptor->GetOutputDescriptorMap();
294 std::map<std::string, BlackBoxOutputDescriptor*>::iterator itOutput;
297 for(itOutput = descriptorOutMap.begin();itOutput != descriptorOutMap.end(); ++itOutput)
299 BlackBoxOutputDescriptor *desc = itOutput->second;
300 createGOutputPort(GOUTPUTPORT,i,model,desc);
305 //Associates the view with the correspondent renderer and the model.
306 //(NOTE: Refresh is only made by the view)
307 view->setModel(model);
308 view->setBaseView(_baseView);
309 view->initVtkObjects();
311 //Associates the controller with the correspondent model and view
312 controller->setModelAndView(model,view);
314 //Resgiter change to the observers of the actual model
315 model->notifyObservers(_idManager);
317 int newId = addObjectController(controller);
323 //=========================================================================
325 int wxVtkSceneManager::createGComplexBoxInputPort(std::string inputName)
327 //EED int windowWidth=_baseView->GetRenWin()->GetSize()[0];
328 int windowHeight=_baseView->GetRenWin()->GetSize()[1];
330 int type = GCOMPLEXINPUTPORT;
332 //Create the MVC Objects
334 GComplexBoxPortModel *model = (GComplexBoxPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
335 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
336 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
338 //Prepares the initial model
341 double yy = windowHeight-5;
343 //z value is not important yet, because it is only used a parallel projection
345 printf("EED wxVtkSceneManager::createGComplexBoxInputPort 900-450\n");
347 _baseView->TransCoordScreenToWorld(xx,yy,zz);
348 model->setInicPoint(xx,yy,zz);
350 model->setBBTKName(inputName);
351 model->setBBTKType("ComplexInputPort");
352 model->setComplexPortType(type);
354 model->addObserver(view);
355 model->addObserver(this);
357 //create the output port
358 GPortController* portController = createGPort(GOUTPUTPORT,inputName,"ComplexInputPort",0,model);
359 model->addOutputPort((GPortModel*)portController->getModel());
361 //Associates the view with the correspondent renderer and the model.
362 //(NOTE: Refresh is only made by the view)
363 view->setModel(model);
364 view->setBaseView(_baseView);
365 view->initVtkObjects();
367 //Associates the controller with the correspondent model and view
368 controller->setModelAndView(model,view);
370 //Resgiter change to the observers of the actual model
371 model->notifyObservers(_idManager);
373 int newId = addObjectController(controller);
377 //=========================================================================
379 int wxVtkSceneManager::createGComplexBoxOutputPort(std::string outputName)
381 //EED int windowWidth=_baseView->GetRenWin()->GetSize()[0];
382 int windowHeight=_baseView->GetRenWin()->GetSize()[1];
384 int type = GCOMPLEXOUTPUTPORT;
386 //Create the MVC Objects
388 GComplexBoxPortModel *model = (GComplexBoxPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
389 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
390 GObjectController *controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
392 //Prepares the initial model
395 double yy = windowHeight-5;
397 //z value is not important yet, because it is only used a parallel projection
400 printf("EED wxVtkSceneManager::createGComplexBoxOutputPort 900-450\n");
402 _baseView->TransCoordScreenToWorld(xx,yy,zz);
403 model->setInicPoint(xx,yy,zz);
405 model->setBBTKName(outputName);
406 model->setBBTKType("ComplexOutputPort");
407 model->setComplexPortType(type);
409 model->addObserver(view);
410 model->addObserver(this);
412 //create the output port
413 GPortController* portController = createGPort(GINPUTPORT,outputName,"ComplexInputPort",0,model);
414 model->addInputPort((GPortModel*)portController->getModel());
416 //Associates the view with the correspondent renderer and the model.
417 //(NOTE: Refresh is only made by the view)
418 view->setModel(model);
419 view->setBaseView(_baseView);
420 view->initVtkObjects();
422 //Associates the controller with the correspondent model and view
423 controller->setModelAndView(model,view);
425 //Resgiter change to the observers of the actual model
426 model->notifyObservers(_idManager);
428 int newId = addObjectController(controller);
432 //=========================================================================
434 int wxVtkSceneManager::createGInputPort(int portType, int posinBox,GBoxModel *blackBox, BlackBoxInputDescriptor *desc)
436 GPortController* portController = createGPort(portType,desc->GetName(),desc->GetTypeName(),posinBox,blackBox);
437 blackBox->addInputPort((GPortModel*)portController->getModel());
438 return portController->getId();
441 //=========================================================================
443 int wxVtkSceneManager::createGOutputPort(int portType, int posinBox,GBoxModel *blackBox, BlackBoxOutputDescriptor *desc)
445 GPortController* portController = createGPort(portType,desc->GetName(),desc->GetTypeName(),posinBox,blackBox);
446 blackBox->addOutputPort((GPortModel*)portController->getModel());
447 return portController->getId();
450 //=========================================================================
452 GPortController* wxVtkSceneManager::createGPort(int portType,std::string bbtkName, std::string bbtkType, int posInBox,GBoxModel *blackBox)
456 //Create the MVC Objects
457 GPortModel *model = (GPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
458 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
459 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
461 model->registerInBox(blackBox,portType, posInBox);
463 model->setBBTKType(bbtkType);
464 model->setBBTKName(bbtkName);
466 model->addObserver(view);
467 model->addObserver(this);
469 //Associates the view with the correspondent renderer and the model.
470 //(NOTE: Refresh is only made by the view)
471 view->setModel(model);
472 view->setBaseView(_baseView);
473 view->initVtkObjects();
475 //Associates the controller with the correspondent model and view
476 controller->setModelAndView(model,view);
478 model->notifyObservers(_idManager);
480 addObjectController(controller);
482 return (GPortController*)controller;
485 //=========================================================================
487 int wxVtkSceneManager::createGConnector(GPortModel* startPort)
489 int type = GCONNECTOR;
491 manualConnectorContourController* manContourControl = new manualConnectorContourController();
492 manualConnectorContourView* manContourView = new manualConnectorContourView();
493 manualContourModel* manContourModel = new manualContourModel();
495 GConnectorController* connectorcontroller = new GConnectorController();
496 GConnectorModel* connectorModel = new GConnectorModel();
497 vtkGConnectorView* connectorView = new vtkGConnectorView();
498 connectorModel->setGObjectType(type);
500 manContourModel->SetCloseContour(false);
501 connectorModel->setStartPort(startPort);
503 manContourView->SetModel( manContourModel );
504 manContourView->SetWxVtkBaseView( _baseView );
505 manContourView->SetRange( 0.5 );
506 manContourView->SetZ( 900 );
508 manContourView->SetColorNormalContour(0, 0, 1);
509 manContourView->SetColorEditContour(0.5, 0.5, 0.5);
510 manContourView->SetColorSelectContour(1, 0.8, 0);
511 manContourView->SetWidthLine(1);
512 manContourView->SetShowText(false);
514 manContourControl->SetModelView( manContourModel , manContourView );
516 manContourControl->CreateNewManualContour();
518 manContourView->RefreshContour();
522 connectorModel->getInicPoint(x,y,z);
524 manContourControl->SetState(1);
525 manContourModel->SetCloseContour(false);
527 manContourModel->AddPoint(x,y,z);
528 manContourView->AddPoint();
530 manContourModel->AddPoint(x,y,z);
531 manContourView->AddPoint();
533 int bak= manContourControl->GetNumberOfPointsManualContour() - 1;
534 manContourControl->_bakIdPoint=bak;
535 manContourView->Refresh();
537 manContourControl->SetMoving( false );
539 connectorcontroller->setModelAndView(connectorModel,connectorView);
541 int newId = addObjectController(connectorcontroller);
543 connectorcontroller->setManualContourController(manContourControl);
544 connectorModel->setManualContourModel(manContourModel);
545 connectorView->setManualContourView(manContourView);
546 connectorView->setModel(connectorModel);
547 connectorView->setBaseView(_baseView);
550 connectorModel->addObserver(connectorView);
551 connectorModel->addObserver(this);
556 //=========================================================================
558 void wxVtkSceneManager::registerController(InteractorStyleMaracas *param)
560 vtkInteractorStyleBaseView* baseViewControlManager = (vtkInteractorStyleBaseView*)_baseView->GetInteractorStyleBaseView();
561 baseViewControlManager->AddInteractorStyleMaracas( param );
564 //=========================================================================
566 void wxVtkSceneManager::unregisterController(InteractorStyleMaracas *param)
568 vtkInteractorStyleBaseView* baseViewControlManager = (vtkInteractorStyleBaseView*)_baseView->GetInteractorStyleBaseView();
569 baseViewControlManager->RemoveInteractorStyleMaracas( param );
572 //=========================================================================
574 vtkRenderer* wxVtkSceneManager::getRenderer()
576 return _baseView->GetRenderer();
579 //=========================================================================
581 vtkRenderWindow* wxVtkSceneManager::getRenderWindow()
583 return _baseView->GetRenWin();
585 //=========================================================================
588 //=========================================================================
589 int wxVtkSceneManager::GetIndexInSelected(int idControler)
592 for (int i=0; i<(int)_selectedObjects.size(); i++)
594 if(_selectedObjects[i]==idControler)
602 //=========================================================================
604 void wxVtkSceneManager::update(int idController,int command)
607 if(command != NO_COMMAND)
609 if(command == ADD_TO_SELECTED)
611 //EEDBorrame GObjectController* cont = _controllers[idController];
613 if (GetIndexInSelected(idController)==-1)
615 _selectedObjects.push_back(idController);
619 // bool foundID=false;
620 // for (int i=0; i<(int)_selectedObjects.size() && foundID==false; i++)
622 // if(_selectedObjects[i]==idController)
629 // _selectedObjects.push_back(idController);
632 }else if(command == REMOVE_FROM_SELECTED)
634 int index=GetIndexInSelected(idController);
637 _selectedObjects.erase( _selectedObjects.begin()+index );
640 else if(command == INIT_CREATION_CONTOUR)
642 _worldState = INIT_CREATION_CONTOUR;
643 GObjectController* cont = _controllers[idController];
644 GPortModel* startOutputPort = (GPortModel*)cont->getModel();
647 // The last one is the controller of the connector
648 std::map<int, GObjectController*>::iterator it2;
650 for(it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
652 GObjectController *cont = it2->second;
653 if(cont->getGObjectType() == GPORT )
655 GPortModel* port = (GPortModel*)cont->getModel();
656 if(port->getPortType()==GINPUTPORT)
658 cont->SetActive(true);
662 cont->getView()->setState(NOTHING_HAPPENS);
663 cont->getModel()->notifyObservers(_idManager);
664 cont->SetActive(false);
669 cont->getView()->setState(NOTHING_HAPPENS);
670 cont->getModel()->notifyObservers(_idManager);
671 cont->SetActive(false);
674 _selectedObjects.clear();
675 _idConnectionInCreation=createGConnector(startOutputPort);
677 else if(command == FIN_CREATION_CONTOUR && _worldState == INIT_CREATION_CONTOUR)
679 _worldState = NOTHING_HAPPENS;
680 //int id = _controllers.size()-1;
681 GObjectController *cont = _controllers[_idConnectionInCreation];
682 GConnectorModel *modelContour = (GConnectorModel*)cont->getModel();
683 GObjectController *finPort = _controllers[idController];
685 if(finPort->getGObjectType() == GPORT)
687 GPortModel* modelPort = (GPortModel*)finPort->getModel();
688 modelContour->setEndPort(modelPort);
691 manualConnectorContourController* manCont = ((GConnectorController*)cont)->getManualContourController();
692 manualConnectorContourView* connView = (manualConnectorContourView*)manCont->GetManualViewBaseContour();
695 std::map<int, GObjectController*>::iterator it2;
697 for(it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
699 GObjectController *cont = it2->second;
700 if(cont->getView()!=NULL)
702 cont->getView()->setState(NOTHING_HAPPENS);
703 cont->getModel()->notifyObservers(_idManager);
705 cont->SetActive(true);
713 //=========================================================================
715 bool wxVtkSceneManager::OnMouseMove()
718 bool okStatusMessage = false;
719 bool okPortMessage = false;
720 wxVTKRenderWindowInteractor *wxVTKiren;
721 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
722 wxVTKiren->GetEventPosition(X,Y);
725 if(_worldState == DRAG_OBJECTS)
727 for (int i=0; i<(int)_selectedObjects.size(); i++)
729 int id = _selectedObjects[i];
730 GObjectController* cont = _controllers[id];
733 cont->getView()->setStartDragging(true);
735 cont->getView()->moveObject(X,Y);
736 cont->getView()->setState(DRAG);
737 cont->getModel()->notifyObservers(_idManager);
740 std::map<int, GObjectController*>::iterator it;
743 for(it = _controllers.begin(); it != _controllers.end(); ++it)
745 GObjectController *desc = it->second;
746 if(desc->getGObjectType()==GCONNECTOR)
748 vtkGConnectorView* vconn = (vtkGConnectorView*)desc->getView();
749 vconn->updateStartEndPoints();
753 _startDragging=false;
756 else if(_worldState == NOTHING_HAPPENS || _worldState == INIT_CREATION_CONTOUR)
758 std::map<int, GObjectController*>::iterator it;
760 for(it = _controllers.begin(); it != _controllers.end(); ++it)
762 GObjectController *desc = it->second;
763 int type = desc->getGObjectType();
764 int state = desc->getView()->getState();
765 desc->getModel()->getCenter(px,py,pz);
767 if(state == HIGHLIGHTED){
768 okStatusMessage = true;
769 updateStatusBar(desc->getStatusText());
772 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
773 _parent->displayBlackBoxInfo(mod->getBBTKPackage(),mod->getBBTKType());
778 okPortMessage = true;
780 _textActor->SetInput( desc->getStatusText().c_str() );
781 _textActor->SetScale(0.1);
782 _textActor->SetPosition( px-25 ,py+1 , pz+2 );
787 _fillObjectActor->SetScale(1);
788 _fillObjectActor->GetProperty()->SetOpacity(0.50);
789 _fillObjectActor->SetPosition(px,py,1);
790 _aPolygonMapper->Modified();
793 } // for controllers it
796 if (okStatusMessage==false)
801 if (okPortMessage==false)
803 _textActor->SetScale(0.0001);
804 _fillObjectActor->SetScale(0.0001);
809 //=========================================================================
811 bool wxVtkSceneManager::OnLeftButtonDown()
814 if(_worldState==INIT_CREATION_CONTOUR)
816 bool isOverPort=false;
817 std::map<int, GObjectController*>::iterator it;
818 for(it = _controllers.begin(); it != _controllers.end() && isOverPort==false; ++it)
820 GObjectController *desc = it->second;
821 if(desc->getGObjectType()==GPORT)
823 GPortModel *portmod = (GPortModel*)desc->getModel();
824 vtkGObjectView *portView = desc->getView();
825 if(portmod->getPortType()==GINPUTPORT && portView->getState()==HIGHLIGHTED)
832 if(isOverPort==false)
835 UnSelectBlackBoxes();
838 } else { //_worldState
840 _worldState = DRAG_OBJECTS;
841 _startDragging = true;
843 int shiftkey = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey();
844 int ctrlkey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
845 ctrlkey = ctrlkey + shiftkey;
847 GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
850 if (GetGBlackBoxControlerPointedByMouse()!=NULL)
852 int state=cont->getView()->getState() ;
853 if( (ctrlkey==0) && (state==HIGHLIGHTED) )
855 UnSelectBlackBoxes();
858 for (int i = 0; i < (int)_selectedObjects.size(); i++)
860 int id = _selectedObjects[i];
861 GObjectController* cont = _controllers[id];
862 cont->getView()->setState(DRAG);
863 cont->getModel()->notifyObservers(_idManager);
866 } // if _selectedObjects.size
872 //=========================================================================
874 bool wxVtkSceneManager::OnLeftButtonUp()
876 if(_worldState == DRAG_OBJECTS)
878 _worldState = NOTHING_HAPPENS;
880 for (int i = 0; i < (int)_selectedObjects.size(); i++)
882 int id = _selectedObjects[i];
883 GObjectController* cont = _controllers[id];
884 cont->getView()->setState(SELECTED);
885 cont->getModel()->notifyObservers(_idManager);
891 //=========================================================================
892 void wxVtkSceneManager::CancelConnection()
894 if(_worldState==INIT_CREATION_CONTOUR)
896 _worldState=NOTHING_HAPPENS;
897 //int lastId = _controllers.size()-1;
899 GConnectorController *connector = (GConnectorController*)_controllers[_idConnectionInCreation];
900 connector->removeFromScene();
901 unregisterController(connector);
902 _controllers.erase(_idConnectionInCreation);
904 std::map<int, GObjectController*>::iterator it;
905 for(it = _controllers.begin(); it != _controllers.end(); ++it)
907 GObjectController *desc = it->second;
908 desc->SetActive(true);
909 desc->getView()->setState(NOTHING_HAPPENS);
910 desc->getModel()->notifyObservers(_idManager);
916 //=========================================================================
918 bool wxVtkSceneManager::OnRightButtonUp()
920 if(_worldState==INIT_CREATION_CONTOUR)
924 UnSelectBlackBoxes();
928 //=========================================================================
930 GObjectController *wxVtkSceneManager::GetGBlackBoxControlerPointedByMouse()
932 GObjectController *result=NULL;
934 wxVTKRenderWindowInteractor *wxVTKiren;
935 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
936 wxVTKiren->GetEventPosition(X,Y);
938 std::map<int, GObjectController*>::iterator it;
940 for(it = _controllers.begin(); it != _controllers.end() ; ++it)
942 GObjectController *cont = it->second;
943 int type = cont->getGObjectType();
945 if( cont->getView()->isPointInside(X,Y)==true )
951 } // if isPointInside
956 //=========================================================================
957 void wxVtkSceneManager::UnSelectBlackBoxes()
959 for (int i=0; i< (int)_selectedObjects.size(); i++)
961 int id = _selectedObjects[i];
962 GObjectController* control = _controllers[id];
963 control->getView()->setState(NOTHING_HAPPENS);
964 }// for _selectedObjects
965 _selectedObjects.clear();
968 //=========================================================================
969 bool wxVtkSceneManager::OnLeftDClick()
971 GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
974 UnSelectBlackBoxes();
975 _parent->editBlackBox( (GBlackBoxModel*)cont->getModel() );
981 wxVTKRenderWindowInteractor *wxVTKiren;
982 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
983 wxVTKiren->GetEventPosition(X,Y);
985 std::map<int, GObjectController*>::iterator it;
987 bool clickOnObject = false;
989 for(it = _controllers.begin(); it != _controllers.end() && clickOnObject==false; ++it)
991 GObjectController *cont = it->second;
992 int type = cont->getGObjectType();
994 if(cont->getView()->isPointInside(X,Y))
998 for (int i=0; i< (int)_selectedObjects.size(); i++)
1000 int id = _selectedObjects[i];
1001 GObjectController* control = _controllers[id];
1002 control->getView()->setState(NOTHING_HAPPENS);
1004 _selectedObjects.clear();
1006 GBlackBoxModel *bbmodel = (GBlackBoxModel*)cont->getModel();
1007 _parent->editBlackBox(bbmodel);
1009 clickOnObject = true;
1013 if(clickOnObject==false)
1015 //_parent->editDiagramParameters(this);
1021 //=========================================================================
1023 bool wxVtkSceneManager::OnChar()
1025 char keyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
1027 // KeyCode 127 : Delete Key
1028 // KeyCode 8 : Backspace Key
1029 if(keyCode == 8 || keyCode == 127)
1031 if(_selectedObjects.size()>0)
1033 for(int i=0;i<(int)_selectedObjects.size();i++)
1035 int id = _selectedObjects[i];
1036 std::map<int,GObjectController*>::iterator it;
1037 it = _controllers.find(id);
1038 if (it!=_controllers.end())
1043 _selectedObjects.clear();
1050 //=========================================================================
1052 void wxVtkSceneManager::AddControlerToBeRemove(std::vector<int> *controllersToRemove, int id)
1057 for(i=0 ; i < (int)controllersToRemove->size() ; i++ )
1059 if (id == (*controllersToRemove)[i] )
1067 controllersToRemove->push_back( id );
1072 //=========================================================================
1074 void wxVtkSceneManager::deleteObject(int id)
1076 GObjectController *control = _controllers[id];
1077 std::vector<int> controllersToRemove;
1079 if(control->getGObjectType()==GBLACKBOX || control->getGObjectType()==GCOMPLEXINPUTPORT || control->getGObjectType()==GCOMPLEXOUTPUTPORT)
1081 GBoxModel *bbmod = (GBoxModel*)control->getModel();
1082 std::vector<GPortModel*> inputs = bbmod->getInputPorts();
1084 bool boxConnected = false;
1086 // Add box input controllers to be removed
1087 for(int i = 0;i< (int)inputs.size();i++)
1089 AddControlerToBeRemove( &controllersToRemove, inputs[i]->getObjectId() );
1090 if(inputs[i]->isConnected())
1092 boxConnected = true;
1096 std::vector<GPortModel*> outputs = bbmod->getOutputPorts();
1098 // Add box output controllers to be removed
1099 for(int i = 0;i<(int)outputs.size();i++)
1101 AddControlerToBeRemove( &controllersToRemove, outputs[i]->getObjectId() );
1102 if(outputs[i]->isConnected())
1104 boxConnected = true;
1108 // Add connection controllers to be removed
1109 std::map<int, GObjectController*>::iterator it;
1110 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1112 GObjectController *cont = it->second;
1113 int type = cont->getGObjectType();
1114 if(type==GCONNECTOR)
1116 GConnectorModel *conMod = (GConnectorModel*)cont->getModel();
1117 if(conMod->getStartPort()!=NULL && conMod->getStartPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
1119 AddControlerToBeRemove( &controllersToRemove, conMod->getObjectId() );
1121 if(conMod->getEndPort()!=NULL && conMod->getEndPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
1123 AddControlerToBeRemove( &controllersToRemove, conMod->getObjectId() );
1128 // Add box controller to be removed
1129 AddControlerToBeRemove( &controllersToRemove, bbmod->getObjectId() );
1131 else if(control->getGObjectType()==GCONNECTOR)
1133 GConnectorModel *conMod = (GConnectorModel*)control->getModel();
1134 AddControlerToBeRemove( &controllersToRemove, conMod->getObjectId() );
1138 std::map<int,GObjectController*>::iterator it;
1140 for(int i = 0;i<(int)controllersToRemove.size();i++)
1142 int key = controllersToRemove[i];
1143 it = _controllers.find( key );
1144 GObjectController *cont = _controllers[ key ];
1147 cont->removeFromScene();
1148 unregisterController((InteractorStyleMaracas*)cont);
1149 _controllers.erase(it);
1154 //=========================================================================
1156 void wxVtkSceneManager::displayBlackBoxInfo(std::string packageName, std::string boxName)
1158 _parent->displayBlackBoxInfo(packageName,boxName);
1161 //=========================================================================
1163 void wxVtkSceneManager::updateStatusBar(std::string textStatus)
1165 _parent->updateStatusBar(textStatus);
1169 //=========================================================================
1170 std::string wxVtkSceneManager::LineNumber(bool withLineNumber, int &value)
1172 std::string result="";
1173 if (withLineNumber==true)
1176 stringstream StrStream;
1178 std::string strValue=StrStream.str();
1182 }else if (value<100)
1187 result+=strValue+": ";
1191 //=========================================================================
1193 std::string wxVtkSceneManager::getDiagramBBS(bool wln)
1195 bool existsExec=false;
1197 std::vector<std::string> packages;
1198 std::vector<int> boxes;
1199 std::vector<int> connections;
1200 std::vector<int> execBoxes;
1202 std::map<int, GObjectController*>::iterator it;
1204 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1206 GObjectController *desc = it->second;
1207 int type = desc->getGObjectType();
1211 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
1213 std::string pkg = mod->getBBTKPackage();
1214 bool existsPkg = false;
1215 for(int t = 0;t< (int)packages.size() && existsPkg == false;t++)
1217 if(packages[t]==pkg)
1224 packages.push_back(pkg);
1228 boxes.push_back(it->first);
1229 if(mod->isExecutable())
1231 execBoxes.push_back(it->first);
1235 else if(type==GCONNECTOR)
1237 connections.push_back(it->first);
1242 std::string script = "";
1243 script+=LineNumber(wln,lnNmbr)+"# BBTK GEditor Script\n";
1244 script+=LineNumber(wln,lnNmbr)+"# ----------------------\n";
1245 script+=LineNumber(wln,lnNmbr)+"\n";
1248 script+=LineNumber(wln,lnNmbr)+"include std\n"; // EED
1249 script+=LineNumber(wln,lnNmbr)+"include itkvtk\n"; // EED
1251 for(i = 0; i< (int)packages.size();i++)
1253 script+=LineNumber(wln,lnNmbr);
1255 script+=packages[i];
1259 script+=LineNumber(wln,lnNmbr);
1265 script+=LineNumber(wln,lnNmbr);
1266 script+="author \"";
1270 script+=LineNumber(wln,lnNmbr);
1271 script+="description \"";
1272 script+=_Description;
1275 script+=LineNumber(wln,lnNmbr);
1276 script+="category \"";
1280 script+=LineNumber(wln,lnNmbr);
1284 // script+="include std\n"; // JPR
1286 for(i = 0; i < (int)boxes.size();i++)
1288 script+=LineNumber(wln,lnNmbr);
1291 GObjectController *control = _controllers[id];
1292 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1294 script+=model->getBBTKType();
1296 script+=model->getBBTKName();
1299 std::vector<GPortModel*> inputs = model->getInputPorts();
1300 for(int j = 0; j < (int)inputs.size();j++)
1302 GPortModel* inputPort = inputs[j];
1303 if(inputPort->isValueSet())
1305 script+=LineNumber(wln,lnNmbr);
1307 script+=model->getBBTKName();
1309 script+=inputPort->getBBTKName();
1311 script+=inputPort->getValue();
1316 script+=LineNumber(wln,lnNmbr);
1321 script+=LineNumber(wln,lnNmbr);
1324 for(i = 0; i<(int)connections.size();i++)
1326 script+=LineNumber(wln,lnNmbr);
1328 int id = connections[i];
1329 GObjectController *control = _controllers[id];
1330 GConnectorModel *model = (GConnectorModel*)control->getModel();
1332 //Start Connection info
1333 GPortModel *start = model->getStartPort();
1334 script+=start->getParentBox()->getBBTKName();
1336 script+=start->getBBTKName();
1340 //End Connection info
1341 GPortModel *end = model->getEndPort();
1342 script+=end->getParentBox()->getBBTKName();
1344 script+=end->getBBTKName();
1349 script+=LineNumber(wln,lnNmbr);
1351 for(i = 0; i<(int)execBoxes.size();i++)
1353 script+=LineNumber(wln,lnNmbr);
1355 int id = execBoxes[i];
1356 GObjectController *control = _controllers[id];
1357 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1359 script+=model->getBBTKName();
1368 //=========================================================================
1370 std::string wxVtkSceneManager::saveComplexBoxBBS()
1372 std::vector<std::string> packages;
1373 std::vector<int> boxes;
1374 std::vector<int> connections;
1375 std::vector<int> execBoxes;
1377 std::map<int, GObjectController*>::iterator it;
1379 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1381 GObjectController *desc = it->second;
1382 int type = desc->getGObjectType();
1386 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
1388 std::string pkg = mod->getBBTKPackage();
1389 bool existsPkg = false;
1390 for(int t = 0;t<(int)packages.size() && existsPkg == false;t++)
1392 if(packages[t]==pkg)
1399 packages.push_back(pkg);
1403 boxes.push_back(it->first);
1404 if(mod->isExecutable())
1406 execBoxes.push_back(it->first);
1409 else if(type==GCONNECTOR)
1411 connections.push_back(it->first);
1415 std::string script = "";
1417 script+="include std\n"; // EED
1418 script+="include itkvtk\n"; // EED
1420 for(i = 0; i<(int)packages.size();i++)
1423 script+=packages[i];
1429 // Definition of a complex box
1431 script+=_cbName+" "+_cbPackageName;
1435 script+="author \"";
1439 script+="description \"";
1440 script+=_Description;
1444 script+="category \"";
1451 for(i = 0; i<(int)boxes.size();i++)
1455 GObjectController *control = _controllers[id];
1456 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1458 script+=model->getBBTKType();
1460 script+=model->getBBTKName();
1463 std::vector<GPortModel*> inputs = model->getInputPorts();
1464 for(int j = 0; j<(int)inputs.size();j++)
1466 GPortModel* inputPort = inputs[j];
1467 if(inputPort->isValueSet())
1470 script+=model->getBBTKName();
1472 script+=inputPort->getBBTKName();
1474 script+=inputPort->getValue();
1482 // Create connections in the script. If the connection is made with a complex port, it is created the input or output
1484 std::string complexInputs="";
1485 std::string complexOutputs="";
1488 for(i = 0; i<(int)connections.size();i++)
1490 int id = connections[i];
1491 GObjectController *control = _controllers[id];
1492 GConnectorModel *model = (GConnectorModel*)control->getModel();
1495 GPortModel *start = model->getStartPort();
1496 GBoxModel *startBox =start->getParentBox();
1498 GPortModel *end = model->getEndPort();
1499 GBoxModel *endBox =end->getParentBox();
1501 if(startBox->getGObjectType()==GCOMPLEXINPUTPORT)
1503 complexInputs+="input ";
1504 complexInputs+=startBox->getBBTKName();
1507 complexInputs+=endBox->getBBTKName();
1509 complexInputs+=end->getBBTKName();
1512 complexInputs+="\" \"";
1514 complexInputs+="\n";
1516 else if(endBox->getGObjectType()==GCOMPLEXOUTPUTPORT)
1518 complexOutputs+="output ";
1519 complexOutputs+=endBox->getBBTKName();
1521 complexOutputs+=" ";
1522 complexOutputs+=startBox->getBBTKName();
1523 complexOutputs+=".";
1524 complexOutputs+=start->getBBTKName();
1526 complexOutputs+=" ";
1527 complexOutputs+="\" \"";
1529 complexOutputs+="\n";
1534 script+=startBox->getBBTKName();
1536 script+=start->getBBTKName();
1540 //End Connection info
1541 script+=endBox->getBBTKName();
1543 script+=end->getBBTKName();
1551 for(i = 0; i<(int)execBoxes.size();i++)
1554 int id = execBoxes[i];
1555 GObjectController *control = _controllers[id];
1556 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1558 script+=model->getBBTKName();
1563 script+="# Complex input ports\n";
1564 script+=complexInputs;
1567 script+="# Complex output ports\n";
1568 script+=complexOutputs;
1577 //=========================================================================
1579 void wxVtkSceneManager::deleteAllBoxes()
1581 std::map<int, GObjectController*>::iterator it;
1582 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1584 GObjectController *cont = it->second;
1585 cont->removeFromScene();
1586 unregisterController((InteractorStyleMaracas*)cont);
1588 _selectedObjects.clear();
1589 _controllers.clear();
1593 //=========================================================================
1596 void wxVtkSceneManager::refresh()
1598 _baseView->Refresh();
1600 //=========================================================================
1602 void wxVtkSceneManager::refreshScene()
1604 _baseView->RefreshView();
1607 //=========================================================================
1609 void wxVtkSceneManager::centerView()
1612 _baseView->GetRenderer()->GetActiveCamera()->GetFocalPoint(temp);
1613 _baseView->GetRenderer()->GetActiveCamera()->SetFocalPoint(0,0,temp[2]);
1614 _baseView->GetRenderer()->GetActiveCamera()->GetPosition(temp);
1615 _baseView->GetRenderer()->GetActiveCamera()->SetPosition(0,0,temp[2]);
1616 _baseView->RefreshView();
1620 //=========================================================================
1622 void wxVtkSceneManager::saveDiagram(std::string &content)
1626 content+="CATEGORY:";
1627 content+=GetCategory();
1630 content+="DESCRIPTION:";
1631 content+=GetDescription();
1635 content+=GetAuthor();
1639 //Print info IF COMPLEX BOX
1640 content+="COMPLEXBOX:";
1645 content+="COMPLEXBOXNAME:";
1646 content+=GetCbName();
1649 content+="PACKAGENAME:";
1650 content+=GetCbPackageName();
1653 //Print info complex input ports
1654 std::vector<int> inputs = getComplexInputPorts();
1655 int insize = inputs.size();
1656 content+="COMPLEXINPUTS:";
1657 sprintf (buffer, "%d", insize);
1661 for(int i = 0;i<insize;i++)
1664 GObjectController *cont = _controllers[id];
1665 cont->getModel()->save(content);
1668 //Print info complex output ports
1669 std::vector<int> outputs = getComplexOutputPorts();
1670 int outsize = outputs.size();
1671 content+="COMPLEXOUTPUTS:";
1672 sprintf (buffer, "%d", outsize);
1676 for(int i = 0;i<outsize;i++)
1678 int id = outputs[i];
1679 GObjectController *cont = _controllers[id];
1680 cont->getModel()->save(content);
1689 std::vector<int> boxes = getBlackBoxes();
1690 int bsize = boxes.size();
1692 sprintf (buffer, "%d", bsize);
1696 for(int i = 0;i<bsize;i++)
1699 GObjectController *cont = _controllers[id];
1700 cont->getModel()->save(content);
1704 std::vector<int> connections = getConnections();
1705 int csize = connections.size();
1706 content+="CONNECTIONS:";
1707 sprintf (buffer, "%d", csize);
1711 for(int i = 0;i<csize;i++)
1713 int id = connections[i];
1714 GObjectController *cont = _controllers[id];
1715 cont->getModel()->save(content);
1720 //=========================================================================
1722 void wxVtkSceneManager::loadDiagram(ifstream &inputStream)
1725 std::string version="<void>";
1726 std::string line="";
1727 char delims[] = ":";
1728 char *result = NULL;
1729 getline(inputStream,line);
1732 while ( !inputStream.eof() )
1734 if(line=="" || line[0]=='#')
1736 getline(inputStream,line);
1737 if (line=="# - BBTKGEditor v 1.0 BBG BlackBox Diagram file")
1739 version=line.substr(18,3);
1741 if (line=="# - BBTKGEditor v 1.1 BBG BlackBox Diagram file")
1743 version=line.substr(18,3);
1745 if (line=="# - BBTKGEditor v 1.2 BBG BlackBox Diagram file")
1747 version=line.substr(18,3);
1750 else if(line=="APP_START")
1757 printf("EED wxVtkSceneManager::loadDiagram version=%s\n",version.c_str());
1762 if ((version!="1.0") && (version!="1.1"))
1764 getline(inputStream,line);//CATEGORY:<category of the box>
1765 char categoryTmp[30];
1766 strcpy( categoryTmp, line.c_str() );
1767 result = strtok( categoryTmp, delims );
1768 result = strtok( NULL, delims );
1769 SetCategory(result);
1771 getline(inputStream,line);//DESCRIPTION:<description of the box>
1772 char descriptionTmp[1024];
1773 strcpy( descriptionTmp, line.c_str() );
1774 result = strtok( descriptionTmp, delims );
1775 result = strtok( NULL, delims );
1776 SetDescription(result);
1778 getline(inputStream,line);//AUTHOR:<author>
1779 char authorTmp[255];
1780 strcpy( authorTmp, line.c_str() );
1781 result = strtok( authorTmp, delims );
1782 result = strtok( NULL, delims );
1787 getline(inputStream,line);//COMPLEX_BOX:TRUE|FALSE
1788 char complexTmp[30];
1789 strcpy( complexTmp, line.c_str() );
1790 result = strtok( complexTmp, delims );
1791 result = strtok( NULL, delims );
1792 std::string isComplexBox(result);
1794 if(isComplexBox=="TRUE")
1798 if ((version!="1.0") && (version!="1.1"))
1800 getline(inputStream,line);//COMPLEXNAME:<name of the complex box>
1801 char complexboxnameTmp[255];
1802 strcpy( complexboxnameTmp, line.c_str() );
1803 result = strtok( complexboxnameTmp, delims );
1804 result = strtok( NULL, delims );
1807 getline(inputStream,line);//PACKAGENAME:<name of the package of the box>
1808 char packagenameTmp[255];
1809 strcpy( packagenameTmp, line.c_str() );
1810 result = strtok( packagenameTmp, delims );
1811 result = strtok( NULL, delims );
1812 SetCbPackageName(result);
1816 //-----------------------
1817 //- COMPLEX INPUT PORTS
1818 //-----------------------
1819 getline(inputStream,line);//COMPLEXINPUTS:num
1821 strcpy( inputs, line.c_str() );
1822 result = strtok( inputs, delims );
1823 result = strtok( NULL, delims );
1826 std::istringstream inps(result);
1829 for(int i = 0;i<numInputs;i++)
1832 getline(inputStream,line);//COMPLEX_PORT
1833 getline(inputStream,line);//name
1834 std::string inputPortName(line);
1837 getline(inputStream,line);//xInic:yInic:zInic
1839 strcpy( coord, line.c_str() );
1840 result = strtok( coord, delims );//xInic
1841 std::string xInic(result);
1842 result = strtok( NULL, delims );//yInic
1843 std::string yInic(result);
1844 result = strtok( NULL, delims );//zInic
1845 std::string zInic(result);
1847 double xIn, yIn, zIn;
1848 std::istringstream xSt(xInic);
1850 std::istringstream ySt(yInic);
1852 std::istringstream zSt(zInic);
1855 getline(inputStream,line);//FIN_COMPLEX_PORT
1857 configGComBoxInputOutputPort(true, inputPortName,xIn,yIn,zIn);
1860 } // for input complex box
1863 //-----------------------
1864 //- COMPLEX OUTPUT PORTS
1865 //-----------------------
1867 getline(inputStream,line);//COMPLEXOUTPUTS:num
1869 strcpy( outputs, line.c_str() );
1870 result = strtok( outputs, delims );
1871 result = strtok( NULL, delims );
1874 std::istringstream outps(result);
1875 outps >> numOutputs;
1877 for(int i = 0;i<numOutputs;i++)
1880 getline(inputStream,line);//COMPLEX_PORT
1881 getline(inputStream,line);//name
1882 std::string outputPortName(line);
1885 getline(inputStream,line);//xInic:yInic:zInic
1887 strcpy( coord, line.c_str() );
1888 result = strtok( coord, delims );//xInic
1889 std::string xInic(result);
1890 result = strtok( NULL, delims );//yInic
1891 std::string yInic(result);
1892 result = strtok( NULL, delims );//zInic
1893 std::string zInic(result);
1895 double xIn, yIn, zIn;
1896 std::istringstream xSt(xInic);
1898 std::istringstream ySt(yInic);
1900 std::istringstream zSt(zInic);
1903 getline(inputStream,line);//FIN_COMPLEX_PORT
1905 configGComBoxInputOutputPort(false, outputPortName,xIn,yIn,zIn);
1907 } // for output complex box
1912 getline(inputStream,line);//BOXES:num
1914 strcpy( boxes, line.c_str() );
1915 result = strtok( boxes, delims );
1916 result = strtok( NULL, delims );
1919 std::istringstream is(result);
1922 for(int i = 0;i<numBoxes;i++)
1925 getline(inputStream,line);//BOX
1926 getline(inputStream,line);//package:type:name
1928 strcpy( box, line.c_str() );
1929 result = strtok( box, delims );//package
1930 std::string package(result);
1931 result = strtok( NULL, delims );//type
1932 std::string type(result);
1933 result = strtok( NULL, delims );//name
1934 std::string name(result);
1936 getline(inputStream,line);//ISEXEC:TRUE|FALSE
1938 strcpy( exec, line.c_str() );
1939 result = strtok( exec, delims );//ISEXEC
1940 result = strtok( NULL, delims );//TRUE|FALSE
1941 std::string isExec(result);
1944 getline(inputStream,line);//xInic:yInic:zInic
1946 strcpy( coord, line.c_str() );
1947 result = strtok( coord, delims );//xInic
1948 std::string xInic(result);
1949 result = strtok( NULL, delims );//yInic
1950 std::string yInic(result);
1951 result = strtok( NULL, delims );//zInic
1952 std::string zInic(result);
1954 double xIn, yIn, zIn;
1955 std::istringstream xSt(xInic);
1957 std::istringstream ySt(yInic);
1959 std::istringstream zSt(zInic);
1963 getline(inputStream,line);//xEnd:yEnd:zEnd
1964 strcpy( coord, line.c_str() );
1965 result = strtok( coord, delims );//xEnd
1966 std::string xEnd(result);
1967 result = strtok( NULL, delims );//yEnd
1968 std::string yEnd(result);
1969 result = strtok( NULL, delims );//zEnd
1970 std::string zEnd(result);
1972 double xEn, yEn, zEn;
1973 std::istringstream xEt(xEnd);
1975 std::istringstream yEt(yEnd);
1977 std::istringstream zEt(zEnd);
1980 bool boxExecutable=false;
1983 boxExecutable= true;
1986 int idBox = createGBlackBox(xIn,yIn,package,type);
1987 configGBlackBox(idBox, xIn,yIn,zIn,name, boxExecutable,xEn,yEn,zEn);
1989 GObjectController *cont = _controllers[idBox];
1990 GBlackBoxModel *bbmod = (GBlackBoxModel*)cont->getModel();
1994 getline(inputStream,line);//PORT o FIN_BOX
1995 std::string port=line.substr(0,4);
1998 getline(inputStream,line);//name:value
2000 strcpy( poort, line.c_str() );
2001 result = strtok( poort, delims );//name
2002 std::string name(result);
2003 result = strtok( NULL, delims );//value
2004 std::string value(result);
2006 bbmod->setValueToInput(name,value);
2008 getline(inputStream,line);//PORT o FIN_BOX
2009 port=line.substr(0,4);
2012 //EED bbmod->notifyObservers(_idManager);
2017 getline(inputStream,line);//CONNECTIONS:num
2019 strcpy( conns, line.c_str() );
2020 result = strtok( conns, delims );
2021 result = strtok( NULL, delims );
2024 std::istringstream isCons(result);
2027 for(int i = 0;i<numConns;i++)
2030 getline(inputStream,line);//CONNECTION
2031 getline(inputStream,line);//Startbox.PortName:EndBox.PortName
2034 strcpy( connec, line.c_str() );
2035 result = strtok( connec, delims );
2036 std::string nameStartBox(result);
2037 result = strtok( NULL, delims );
2038 std::string nameStartPort(result);
2039 result = strtok( NULL, delims );
2040 std::string nameEndBox(result);
2041 result = strtok( NULL, delims );
2042 std::string nameEndPort(result);
2044 int idCon = configGConnetion(nameStartBox, nameStartPort, nameEndBox, nameEndPort);
2048 //Readding control points of the manualContour
2050 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
2051 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
2052 vtkGConnectorView *conView= (vtkGConnectorView*)tempp->getView();
2053 getline(inputStream,line); //NumberOfControlPoints:##
2054 strcpy( conns, line.c_str() );
2055 result = strtok( conns, delims );
2056 result = strtok( NULL, delims );
2058 int numberOfControlPoints;
2059 std::istringstream isCons(result);
2060 isCons >> numberOfControlPoints;
2062 for (int ii=0;ii<numberOfControlPoints;ii++)
2064 getline(inputStream,line); //XX:YY:ZZ
2066 strcpy( connec, line.c_str() );
2069 result = strtok( connec, delims );
2070 std::istringstream isPointX(result);
2072 result = strtok( NULL, delims );
2073 std::istringstream isPointY(result);
2075 result = strtok( NULL, delims );
2076 std::istringstream isPointZ(result);
2079 conMod->getManualContourModel()->InsertPoint_id(ii+1,px,py,pz);
2080 conView->getManualContourView()->AddPoint();
2090 //=========================================================================
2094 //=========================================================================
2095 void wxVtkSceneManager::configGComBoxInputOutputPort(bool inputoutput, std::string portName, double xIn, double yIn,double zIn)
2098 if (inputoutput==true)
2100 idPort = createGComplexBoxInputPort(portName);
2102 idPort = createGComplexBoxOutputPort(portName);
2104 GObjectController *cont = _controllers[idPort];
2105 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
2106 cbmod->setInicPoint(xIn,yIn,zIn);
2107 cbmod->notifyObservers(_idManager);
2109 //=========================================================================
2112 //=========================================================================
2113 GBoxModel* wxVtkSceneManager::findGBox(std::string boxname)
2118 GBoxModel *boxModel = NULL;
2119 std::vector<int> lstB = getBlackBoxes();
2120 for(j = 0;j<(int)lstB.size();j++)
2123 bMod = (GBoxModel*)_controllers[idB]->getModel();
2124 if(_controllers[idB]->getModel()->getBBTKName()==boxname)
2130 if((_isComplexBox) && (boxModel==NULL))
2132 std::vector<int> lstInputs = getComplexInputPorts();
2133 for(j = 0;j<(int)lstInputs.size();j++)
2136 bMod = (GBoxModel*)_controllers[idB]->getModel();
2137 if(_controllers[idB]->getModel()->getBBTKName()==boxname)
2143 std::vector<int> lstOutputs = getComplexOutputPorts();
2144 for(j = 0;j<(int)lstOutputs.size();j++)
2146 int idB = lstOutputs[j];
2147 bMod = (GBoxModel*)_controllers[idB]->getModel();
2148 if(_controllers[idB]->getModel()->getBBTKName()==boxname)
2159 //=========================================================================
2162 int wxVtkSceneManager::configGConnetion(std::string nameStartBox, std::string nameStartPort, std::string
2163 nameEndBox, std::string nameEndPort)
2166 GBoxModel *boxModel;
2167 GPortModel *startP = NULL;
2168 GPortModel *endP = NULL;
2170 boxModel= findGBox(nameStartBox);
2173 startP = boxModel->getOutputPort(nameStartPort);
2176 boxModel= findGBox(nameEndBox);
2179 endP = boxModel->getInputPort(nameEndPort);
2183 int idCon = createGConnector(startP);
2184 _worldState = NOTHING_HAPPENS;
2185 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
2187 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
2188 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
2189 tempp->endContourCreation();
2190 conMod->setEndPort(endP);
2191 conView->updateStartEndPoints();
2195 //=========================================================================
2197 bool wxVtkSceneManager::boxExist(std::string boxname)
2200 std::map<int, GObjectController*>::iterator it;
2201 for(it = _controllers.begin(); it != _controllers.end(); ++it)
2203 GObjectController *cont = it->second;
2204 if(cont->getModel()->getBBTKName()==boxname)
2212 //=========================================================================
2214 std::vector<int> wxVtkSceneManager::getBlackBoxes()
2216 std::vector<int> vect;
2217 std::map<int, GObjectController*>::iterator it;
2218 for(it = _controllers.begin(); it != _controllers.end(); ++it)
2220 GObjectController *cont = it->second;
2221 if(cont->getGObjectType()==GBLACKBOX)
2223 vect.push_back(cont->getId());
2229 //=========================================================================
2231 std::vector<int> wxVtkSceneManager::getComplexInputPorts()
2233 std::vector<int> vect;
2234 std::map<int, GObjectController*>::iterator it;
2235 for(it = _controllers.begin(); it != _controllers.end(); ++it)
2237 GObjectController *cont = it->second;
2238 if(cont->getGObjectType()==GCOMPLEXINPUTPORT)
2240 vect.push_back(cont->getId());
2246 //=========================================================================
2248 std::vector<int> wxVtkSceneManager::getComplexOutputPorts()
2250 std::vector<int> vect;
2251 std::map<int, GObjectController*>::iterator it;
2252 for(it = _controllers.begin(); it != _controllers.end(); ++it)
2254 GObjectController *cont = it->second;
2255 if(cont->getGObjectType()==GCOMPLEXOUTPUTPORT)
2257 vect.push_back(cont->getId());
2263 //=========================================================================
2265 std::vector<int> wxVtkSceneManager::getConnections()
2267 std::vector<int> vect;
2268 std::map<int, GObjectController*>::iterator it;
2269 for(it = _controllers.begin(); it != _controllers.end(); ++it)
2271 GObjectController *cont = it->second;
2272 if(cont->getGObjectType()==GCONNECTOR)
2274 vect.push_back(cont->getId());
2280 //=========================================================================
2282 bool wxVtkSceneManager::isComplexBox()
2284 return _isComplexBox;
2287 //=========================================================================
2289 void wxVtkSceneManager::setComplexBox(bool val)
2294 //=========================================================================
2296 int wxVtkSceneManager::addObjectController(GObjectController* objController)
2298 //Register the controller of the new object
2299 registerController((InteractorStyleMaracas*) objController);
2301 //Add the object to the objects list
2302 int newId = _contLastId;//_controllers.size();
2303 objController->setId(newId);
2304 _controllers[newId] = objController;
2309 //=========================================================================
2311 int wxVtkSceneManager::getNumSelectedObjects()
2313 return _selectedObjects.size();
2316 //=========================================================================
2318 std::map<int,GObjectController*> wxVtkSceneManager::getSelectedObjects()
2320 std::map<int,GObjectController*> mapSelected;
2322 std::map<int, GObjectController*>::iterator it;
2323 for(it = _controllers.begin(); it != _controllers.end(); ++it)
2325 GObjectController *cont = it->second;
2326 if(cont->getGObjectType()==GBLACKBOX && cont->getView()->getState()==SELECTED)
2328 mapSelected[cont->getId()]=cont;
2332 std::map<int, GObjectController*>::iterator it2;
2333 for(it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
2335 GObjectController *cont = it2->second;
2336 if(cont->getGObjectType()==GCONNECTOR)
2338 GConnectorModel* cmod = (GConnectorModel*)cont->getModel();
2339 GBoxModel* endPortParentBox = cmod->getEndPort()->getParentBox();
2340 GBoxModel* startPortParentBox = cmod->getStartPort()->getParentBox();
2342 std::map<int, GObjectController*>::iterator iterOBJ1 = mapSelected.find(startPortParentBox->getObjectId());
2343 std::map<int, GObjectController*>::iterator iterOBJ2 = mapSelected.find(endPortParentBox->getObjectId());
2345 if(iterOBJ1 != mapSelected.end() && iterOBJ2 != mapSelected.end())
2347 int ID = cont->getId();
2348 mapSelected[ID]=cont;
2355 //=========================================================================
2357 void wxVtkSceneManager::addObjects(std::map<int,GObjectController*> objectsMap)
2360 std::map<int,int> oldIdNewIdBoxes;
2361 std::vector<int> connections;
2363 std::map<int, GObjectController*>::iterator it;
2364 for(it = objectsMap.begin(); it != objectsMap.end(); ++it)
2366 GObjectController *cont = it->second;
2367 int type = cont->getGObjectType();
2372 double xInic, yInic,zInic;
2373 GBlackBoxModel* copyBox = (GBlackBoxModel*)cont->getModel();
2374 copyBox->getInicPoint(xInic,yInic,zInic);
2375 int idBox = createGBlackBox(0,0,copyBox->getBBTKPackage(),copyBox->getBBTKType());
2377 int idcB = copyBox->getObjectId();
2378 oldIdNewIdBoxes[idcB]=idBox;
2379 cont = _controllers[idBox];
2380 GBlackBoxModel* newbox = (GBlackBoxModel*)cont->getModel();
2381 newbox->setInicPoint(xInic,yInic,zInic);
2382 int num = newbox->getNumInputPorts();
2383 for(int j=0;j<num;j++)
2385 newbox->setValueToInputPort(j,copyBox->getValueInputPort(j));
2387 newbox->notifyObservers(_idManager);
2389 else if(type==GCONNECTOR)
2391 int idCon = cont->getId();
2392 connections.push_back(idCon);
2397 for(int i = 0 ;i<(int)connections.size();i++)
2399 int objId = connections[i];
2400 GObjectController *cont = objectsMap[objId];
2401 GConnectorModel* connectModel = (GConnectorModel*)cont->getModel();
2403 GPortModel* startPort = connectModel->getStartPort();
2404 int startPortIndex = startPort->getPosInBox();
2405 GPortModel* endPort = connectModel->getEndPort();
2406 int endPortIndex = endPort->getPosInBox();
2408 GBlackBoxModel* startPortParentBox = (GBlackBoxModel*)startPort->getParentBox();
2409 GBlackBoxModel* endPortParentBox = (GBlackBoxModel*)endPort->getParentBox();
2411 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2412 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2414 GBlackBoxModel* newStartBox = (GBlackBoxModel*)_controllers[idNewStartBox]->getModel();
2415 GBlackBoxModel* newEndBox = (GBlackBoxModel*)_controllers[idNewEndBox]->getModel();
2417 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2418 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2420 // Creates connection
2421 int idCon = createGConnector(newStartPort);
2422 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
2423 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
2424 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
2425 tempp->endContourCreation();
2426 conMod->setEndPort(newEndPort);
2427 conView->updateStartEndPoints();
2430 std::map<int, int>::iterator itIds;
2431 for(itIds = oldIdNewIdBoxes.begin(); itIds != oldIdNewIdBoxes.end(); ++itIds)
2433 int idOld = itIds->first;
2434 int idNew = itIds->second;
2436 GBlackBoxModel* oldBox = (GBlackBoxModel*)objectsMap[idOld]->getModel();
2437 GBlackBoxModel* newBox = (GBlackBoxModel*)_controllers[idNew]->getModel();
2439 std::vector<int> oldInputConnections = oldBox->getConnectedInputs();
2440 std::vector<int> oldOutputConnections = oldBox->getConnectedOutputs();
2441 std::vector<int> newInputConnections = newBox->getConnectedInputs();
2442 std::vector<int> newOutputConnections = newBox->getConnectedOutputs();
2444 for(int k = 0; k<(int)oldInputConnections.size();k++)
2447 //EED int toCreate=-1;
2448 for(int l = 0; l<(int)newInputConnections.size() && !exist;l++)
2450 if(oldInputConnections[k]==newInputConnections[l])
2458 //Create complex input
2459 int posInBox = oldInputConnections[k];
2460 GPortModel* inputPort = oldBox->getInputPort(posInBox);
2461 std::string inputPortName = inputPort->getBBTKName();
2462 int idInputPort = createGComplexBoxInputPort(inputPortName);
2463 GObjectController *cont = _controllers[idInputPort];
2464 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
2466 inputPort->getInicPoint(xIn,yIn,zIn);
2468 cbmod->setInicPoint(xIn,yIn,zIn);
2469 cbmod->notifyObservers(_idManager);
2471 GPortModel* inputPortEnd = newBox->getInputPort(posInBox);
2473 // Creates connection
2474 int idCon = createGConnector(cbmod->getOutputPort(0));
2475 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
2476 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
2477 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
2478 tempp->endContourCreation();
2479 conMod->setEndPort(inputPortEnd);
2480 conView->updateStartEndPoints();
2487 for(int k = 0; k<(int)oldOutputConnections.size();k++)
2490 //EED int toCreate=-1;
2491 for(int l = 0; l<(int)newOutputConnections.size() && !exist;l++)
2493 if(oldOutputConnections[k]==newOutputConnections[l])
2501 //Create complex output
2502 int posInBox = oldOutputConnections[k];
2503 GPortModel* outputPort = oldBox->getOutputPort(posInBox);
2504 std::string outputPortName = outputPort->getBBTKName();
2505 int idOutputPort = createGComplexBoxOutputPort(outputPortName);
2506 GObjectController *cont = _controllers[idOutputPort];
2507 GBoxModel *cbmod = (GBoxModel*)cont->getModel();
2509 outputPort->getInicPoint(xIn,yIn,zIn);
2511 cbmod->setInicPoint(xIn,yIn,zIn);
2512 cbmod->notifyObservers(_idManager);
2514 GPortModel* outputPortEnd = newBox->getOutputPort(posInBox);
2516 // Creates connection
2517 int idCon = createGConnector(outputPortEnd);
2518 GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
2519 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
2520 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
2521 tempp->endContourCreation();
2522 conMod->setEndPort(cbmod->getInputPort(0));
2523 conView->updateStartEndPoints();
2535 //=========================================================================
2536 void wxVtkSceneManager::SetCbName(std::string cbName)
2541 _cbName="<complex box name>";
2545 //=========================================================================
2546 std::string wxVtkSceneManager::GetCbName()
2551 //=========================================================================
2552 void wxVtkSceneManager::SetCbPackageName(std::string packagename)
2554 _cbPackageName=packagename;
2555 if (_cbPackageName=="")
2557 _cbPackageName="<package name of the complex box>";
2561 //=========================================================================
2562 std::string wxVtkSceneManager::GetCbPackageName()
2564 return _cbPackageName;
2567 //=========================================================================
2568 void wxVtkSceneManager::SetAuthor(std::string author)
2573 _Author="<author of the box>";
2577 //=========================================================================
2578 std::string wxVtkSceneManager::GetAuthor()
2583 //=========================================================================
2584 void wxVtkSceneManager::SetCategory(std::string category)
2589 _Category="<category of the box>";
2593 //=========================================================================
2594 std::string wxVtkSceneManager::GetCategory()
2599 //=========================================================================
2600 void wxVtkSceneManager::SetDescription(std::string description)
2602 _Description=description;
2603 if (_Description=="")
2605 _Description="<description of the box>";
2609 //=========================================================================
2610 std::string wxVtkSceneManager::GetDescription()
2612 return _Description;
2615 //=========================================================================
2623 } // EO namespace bbtk