2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
8 # This software is governed by the CeCILL-B license under French law and
9 # abiding by the rules of distribution of free software. You can use,
10 # modify and/ or redistribute the software under the terms of the CeCILL-B
11 # license as circulated by CEA, CNRS and INRIA at the following URL
12 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
13 # or in the file LICENSE.txt.
15 # As a counterpart to the access to the source code and rights to copy,
16 # modify and redistribute granted by the license, users are provided only
17 # with a limited warranty and the software's author, the holder of the
18 # economic rights, and the successive licensors have only limited
21 # The fact that you are presently reading this means that you have had
22 # knowledge of the CeCILL-B license and that you accept its terms.
23 # ------------------------------------------------------------------------
26 /*=========================================================================
32 =========================================================================*/
34 /* ---------------------------------------------------------------------
36 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
37 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
39 * This software is governed by the CeCILL-B license under French law and
40 * abiding by the rules of distribution of free software. You can use,
41 * modify and/ or redistribute the software under the terms of the CeCILL-B
42 * license as circulated by CEA, CNRS and INRIA at the following URL
43 * http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
44 * or in the file LICENSE.txt.
46 * As a counterpart to the access to the source code and rights to copy,
47 * modify and redistribute granted by the license, users are provided only
48 * with a limited warranty and the software's author, the holder of the
49 * economic rights, and the successive licensors have only limited
52 * The fact that you are presently reading this means that you have had
53 * knowledge of the CeCILL-B license and that you accept its terms.
54 * ------------------------------------------------------------------------ */
58 * \brief Class bbtk::wxVtkSceneManager .
61 #include "wxVtkSceneManager.h"
63 #include <vtkPolygon.h>
64 #include <vtkUnstructuredGrid.h>
68 #define POORT_MAX_LINE_SIZE_INTERPRETER 1500
70 //=========================================================================
72 // EED 15 oct 2012 wxVtkSceneManager::wxVtkSceneManager(wxGEditorTabPanel *parent, wxVtk3DBaseView *baseView, int idManager,Factory::Pointer bbtkfactory)
74 wxVtkSceneManager::wxVtkSceneManager(wxGEditorTabPanel *parent, wxVtk3DBaseView *baseView, int idManager,Factory::Pointer bbtkfactory)
76 _cbName = "ComplexBoxName";
77 _cbPackageName = "PackageName";
78 _Author = "Author ??";
80 _Description = "Description ??";
82 _bugTextActor_text = "void";
83 _bugTextActor_status = 0;
87 _idManager = idManager;
89 _bbtkfactory = bbtkfactory;
91 _startDragging = false;
92 _isComplexBox = false;
94 if (_baseView != NULL) {
97 "RaC-EED 21-06-2010 %p wxVtkSceneManager::wxVtkSceneManager If you comment this line, the drag and drop functionnality is not initialized.\n",
100 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget((wxDropTarget*)parent);
104 _worldState = NOTHING_HAPPENS;
105 registerController(this);
108 _idConnectionInCreation = -1;
113 //=========================================================================
115 void wxVtkSceneManager::disconnectDrop()
117 printf("EED %p ~wxVtkSceneManager::disconnectDrop()\n", this);
118 //EED02JUIN2010 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget(NULL);
119 // _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget( new tmpClasswxTextDropTarget() );
122 //=========================================================================
124 wxVtkSceneManager::~wxVtkSceneManager()
127 printf("EED %p ~wxVtkSceneManager() START\n", this);
130 printf("EED %p ~wxVtkSceneManager() END\n", this);
133 //=========================================================================
135 void wxVtkSceneManager::configureBaseView()
137 vtkInteractorStyleBaseView2D *interactorstylebaseview = vtkInteractorStyleBaseView2D::New();
139 _baseView->SetInteractorStyleBaseView(interactorstylebaseview);
141 // Important to activate the 2D interaction system
142 wxVTKRenderWindowInteractor *iren = _baseView->GetWxVTKRenderWindowInteractor();
143 interactorstylebaseview->SetInteractor(iren);
144 iren->SetInteractorStyle(interactorstylebaseview);
145 interactorstylebaseview->SetwxVtkBaseView(_baseView);
147 _baseView->GetRenderer()->GetActiveCamera()->ParallelProjectionOn();
148 _baseView->GetRenderer()->ResetCamera(-100, 100, -100, 100, -1000, 1000);
149 _baseView->GetRenderer()->GetActiveCamera()->Zoom(10);
152 _baseView->GetRenderer()->SetBackground(0.9, 0.9, 0.9);
153 _baseView->GetRenderer()->GradientBackgroundOn();
156 _textActor = vtkTextActor3D::New();
157 // _textActor = vtkTextActor::New();
158 _textActor->SetPosition(-9999, -9999, GPOSITION_Z);
159 _textActor->SetInput("<void>");
160 _textActor->GetTextProperty()->SetFontSize(60);
161 _textActor->GetTextProperty()->BoldOn();
162 _textActor->GetTextProperty()->SetColor(PORTTEXT_NH_R, PORTTEXT_NH_G,PORTTEXT_NH_B);
164 _baseView->GetRenderer()->AddActor(_textActor);
166 // Actor Fill_Port_Text
171 double zInic = GPOSITION_Z;
173 vtkPolygon *aPolygon = vtkPolygon::New();
174 _fillObjectActor = vtkActor::New();
176 _pts = vtkPoints::New();
178 double w = 100, h = 10, b = h / 15, t = 3;
179 _pts->SetNumberOfPoints(21);
180 _pts->InsertPoint(0, xInic + w * 0.33 - t / 2, yInic, zInic);
181 _pts->InsertPoint(1, xInic + w * 0.33, yInic - t, zInic);
182 _pts->InsertPoint(2, xInic + w * 0.33 + t / 2, yInic, zInic);
183 _pts->InsertPoint(3, xInic + w * 0.33 + t / 2, yInic, zInic);
184 _pts->InsertPoint(4, xInic + w - b * 4, yInic + b * 0, zInic);
186 _pts->InsertPoint(5, xInic + w - b * 4, yInic + b * 0, zInic);
187 _pts->InsertPoint(6, xInic + w - b * 2, yInic + b * 1, zInic);
188 _pts->InsertPoint(7, xInic + w - b * 1, yInic + b * 2, zInic);
189 _pts->InsertPoint(8, xInic + w - b * 0, yInic + b * 4, zInic);
191 _pts->InsertPoint(9, xInic + w - b * 0, yInic + h - b * 4, zInic);
192 _pts->InsertPoint(10, xInic + w - b * 1, yInic + h - b * 2, zInic);
193 _pts->InsertPoint(11, xInic + w - b * 2, yInic + h - b * 1, zInic);
194 _pts->InsertPoint(12, xInic + w - b * 4, yInic + h - b * 0, zInic);
196 _pts->InsertPoint(13, xInic + b * 4, yInic + h - b * 0, zInic);
197 _pts->InsertPoint(14, xInic + b * 2, yInic + h - b * 1, zInic);
198 _pts->InsertPoint(15, xInic + b * 1, yInic + h - b * 2, zInic);
199 _pts->InsertPoint(16, xInic + b * 0, yInic + h - b * 4, zInic);
201 _pts->InsertPoint(17, xInic + b * 0, yInic + b * 4, zInic);
202 _pts->InsertPoint(18, xInic + b * 1, yInic + b * 2, zInic);
203 _pts->InsertPoint(19, xInic + b * 2, yInic + b * 1, zInic);
204 _pts->InsertPoint(20, xInic + b * 4, yInic + b * 0, zInic);
206 aPolygon->GetPointIds()->SetNumberOfIds(21);
207 for (int i = 0; i < 21; i++) {
208 aPolygon->GetPointIds()->SetId(i, i);
211 vtkUnstructuredGrid *aPolygonGrid = vtkUnstructuredGrid::New();
212 aPolygonGrid->Allocate(1, 1);
213 aPolygonGrid->InsertNextCell(aPolygon->GetCellType(),
214 aPolygon->GetPointIds());
215 aPolygonGrid->SetPoints(_pts);
216 _aPolygonMapper = vtkDataSetMapper::New();
217 _aPolygonMapper->SetInput(aPolygonGrid);
218 _fillObjectActor->SetMapper(_aPolygonMapper);
219 _fillObjectActor->GetProperty()->SetColor(PORTFILL_NH_R, PORTFILL_NH_G,
221 _fillObjectActor->GetProperty()->SetOpacity(0);
222 _aPolygonMapper->Modified();
224 _baseView->GetRenderer()->AddActor(_fillObjectActor);
227 //=========================================================================
229 std::string wxVtkSceneManager::generateANewNameForABox() {
230 std::stringstream boxname;
231 if (_numBoxes < 10) {
232 boxname << "Box0" << _numBoxes;
234 boxname << "Box" << _numBoxes;
237 return boxname.str();
240 //=========================================================================
242 std::string wxVtkSceneManager::findANewNameForABox() {
243 std::string boxname = generateANewNameForABox();
245 while (boxExist(boxname) == true) {
246 boxname = generateANewNameForABox();
252 //=========================================================================
253 void wxVtkSceneManager::configGBlackBox(int idBox, double xIn, double yIn,
254 double zIn, std::string name, bool boxExecutable, double xEn,
255 double yEn, double zEn) {
256 GObjectController *cont = _controllers[idBox];
257 GBlackBoxModel *bbmod = (GBlackBoxModel*) cont->getModel();
258 bbmod->setBBTKName(name);
259 bbmod->setInicPoint(xIn, yIn, zIn);
260 bbmod->setFinalPoint(xEn, yEn, zEn);
261 bbmod->setExecutable(boxExecutable);
263 bbmod->notifyObservers(_idManager);
267 //=========================================================================
269 int wxVtkSceneManager::createGBlackBox(int x, int y, std::string packageName,std::string boxType)
271 _worldState = NOTHING_HAPPENS;
272 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
273 int type = GBLACKBOX;
274 //Create the MVC Objects
275 GBlackBoxModel *model = (GBlackBoxModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(type);
276 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
277 GObjectController *controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
279 //EED 15 oct 2012 BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxType);
282 std::map< std::string, BlackBoxDescriptor::Pointer> mapDesc;
284 k = _bbtkfactory->GetPackage(packageName);
285 mapDesc = k->GetDescriptorMap();
287 printf("EED. ERROR!: Exception in wxVtkSceneManager::createGBlackBox for package %s, NOT EXIST\n", packageName.c_str());
290 BlackBoxDescriptor::Pointer descriptor;
292 descriptor = mapDesc[boxType];
294 printf("EED. ERROR!: Exception in wxVtkSceneManager::createGBlackBox for box %s of package %s, NOT EXIST\n", boxType.c_str(),packageName.c_str());
297 if (descriptor == NULL)
299 printf("SCP: ERROR in wxVtkSceneManager::createGBlackBox, box %s probably does not exist.\n", boxType.c_str());
302 //Prepares the initial model
303 //The coordinates obtained are the following. Top-Left:x=0,y=0 Bottom-Right:x=width,y=height
306 double yy = windowHeight - y;
308 //z value is not important yet, because it is only used a parallel projection
309 double zz = GPOSITION_Z;
310 _baseView->TransCoordScreenToWorld(xx, yy, zz);
311 model->setInicPoint(xx, yy, zz);
313 std::stringstream stream;
315 std::string newBoxName;
316 newBoxName = findANewNameForABox();
318 stream << newBoxName;
320 std::string arraystring = stream.str();
322 model->setBBTKName(arraystring);
323 model->setBBTKType(boxType);
324 model->setBBTKPackage(packageName);
326 model->addObserver(view);
327 model->addObserver(this);
329 //Iterate and create the input ports
330 std::map<std::string, BlackBoxInputDescriptor*> descriptorInMap =
331 descriptor->GetInputDescriptorMap();
332 std::map<std::string, BlackBoxInputDescriptor*>::iterator itInput;
335 for (itInput = descriptorInMap.begin(); itInput != descriptorInMap.end(); ++itInput) {
336 BlackBoxInputDescriptor *desc = itInput->second;
337 createGInputPort(GINPUTPORT, i, model, desc);
341 //Iterate and create the output ports
342 std::map<std::string, BlackBoxOutputDescriptor*> descriptorOutMap =
343 descriptor->GetOutputDescriptorMap();
344 std::map<std::string, BlackBoxOutputDescriptor*>::iterator itOutput;
347 for (itOutput = descriptorOutMap.begin(); itOutput
348 != descriptorOutMap.end(); ++itOutput) {
349 BlackBoxOutputDescriptor *desc = itOutput->second;
350 createGOutputPort(GOUTPUTPORT, i, model, desc);
354 //Associates the view with the correspondent renderer and the model.
355 //(NOTE: Refresh is only made by the view)
356 view->setModel(model);
357 view->setBaseView(_baseView);
358 view->initVtkObjects();
360 //Associates the controller with the correspondent model and view
361 controller->setModelAndView(model, view);
363 //Resgiter change to the observers of the actual model
364 model->notifyObservers(_idManager);
366 int newId = addObjectController(controller);
372 //=========================================================================
374 int wxVtkSceneManager::createGComplexBoxInputPort(std::string inputName) {
375 //EED int windowWidth=_baseView->GetRenWin()->GetSize()[0];
376 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
378 int type = GCOMPLEXINPUTPORT;
380 //Create the MVC Objects
382 GComplexBoxPortModel *model = (GComplexBoxPortModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(type);
383 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
384 GObjectController *controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
386 //Prepares the initial model
389 double yy = windowHeight - 5;
391 //z value is not important yet, because it is only used a parallel projection
392 double zz = GPOSITION_Z;
394 _baseView->TransCoordScreenToWorld(xx, yy, zz);
395 model->setInicPoint(xx, yy, zz);
397 model->setBBTKName(inputName);
398 model->setBBTKType("ComplexInputPort");
399 model->setComplexPortType(type);
401 model->addObserver(view);
402 model->addObserver(this);
404 //create the output port
405 GPortController* portController = createGPort(GOUTPUTPORT, inputName,
406 "ComplexOutputPortType","ComplexOutputPortDescriopton", 0, model);
407 model->addOutputPort((GPortModel*) portController->getModel());
409 //Associates the view with the correspondent renderer and the model.
410 //(NOTE: Refresh is only made by the view)
411 view->setModel(model);
412 view->setBaseView(_baseView);
413 view->initVtkObjects();
415 //Associates the controller with the correspondent model and view
416 controller->setModelAndView(model, view);
418 //Resgiter change to the observers of the actual model
419 model->notifyObservers(_idManager);
421 int newId = addObjectController(controller);
425 //=========================================================================
427 int wxVtkSceneManager::createGComplexBoxOutputPort(std::string outputName) {
428 //EED int windowWidth=_baseView->GetRenWin()->GetSize()[0];
429 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
431 int type = GCOMPLEXOUTPUTPORT;
433 //Create the MVC Objects
435 GComplexBoxPortModel *model = (GComplexBoxPortModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(type);
436 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
437 GObjectController *controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
439 //Prepares the initial model
442 double yy = windowHeight - 5;
444 //z value is not important yet, because it is only used a parallel projection
445 double zz = GPOSITION_Z;
447 _baseView->TransCoordScreenToWorld(xx, yy, zz);
448 model->setInicPoint(xx, yy, zz);
450 model->setBBTKName(outputName);
451 model->setBBTKType("ComplexOutputPort");
452 model->setComplexPortType(type);
454 model->addObserver(view);
455 model->addObserver(this);
457 //create the output port
458 GPortController* portController = createGPort(GINPUTPORT, outputName,
459 "ComplexInputPort","ComplexInputPortDescription", 0, model);
460 model->addInputPort((GPortModel*) portController->getModel());
462 //Associates the view with the correspondent renderer and the model.
463 //(NOTE: Refresh is only made by the view)
464 view->setModel(model);
465 view->setBaseView(_baseView);
466 view->initVtkObjects();
468 //Associates the controller with the correspondent model and view
469 controller->setModelAndView(model, view);
471 //Resgiter change to the observers of the actual model
472 model->notifyObservers(_idManager);
474 int newId = addObjectController(controller);
478 //=========================================================================
480 int wxVtkSceneManager::createGInputPort(int portType, int posinBox, GBoxModel *blackBox, BlackBoxInputDescriptor *desc)
482 GPortController* portController = createGPort(portType, desc->GetName(),
483 desc->GetTypeName(), desc->GetDescription(), posinBox, blackBox);
484 blackBox->addInputPort((GPortModel*) portController->getModel());
485 return portController->getId();
488 //=========================================================================
490 int wxVtkSceneManager::createGOutputPort(int portType, int posinBox,GBoxModel *blackBox, BlackBoxOutputDescriptor *desc)
492 GPortController* portController = createGPort(portType, desc->GetName(),
493 desc->GetTypeName(),desc->GetDescription(), posinBox, blackBox);
494 blackBox->addOutputPort((GPortModel*) portController->getModel());
495 return portController->getId();
498 //=========================================================================
500 GPortController* wxVtkSceneManager::createGPort(int portType,std::string bbtkName, std::string bbtkType, std::string bbtkDescription, int posInBox,GBoxModel *blackBox)
504 //Create the MVC Objects
507 (GPortModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(
509 vtkGObjectView *view =
510 GObjectsMVCFactory::getInstance()->createGObjectView(type);
511 GObjectController* controller =
512 GObjectsMVCFactory::getInstance()->createGObjectController(type);
514 model->registerInBox(blackBox, portType, posInBox);
516 model->setBBTKType(bbtkType);
517 model->setBBTKName(bbtkName);
518 model->setBBTKDescription(bbtkDescription);
520 model->addObserver(view);
521 model->addObserver(this);
523 //Associates the view with the correspondent renderer and the model.
524 //(NOTE: Refresh is only made by the view)
525 view->setModel(model);
526 view->setBaseView(_baseView);
527 view->initVtkObjects();
529 //Associates the controller with the correspondent model and view
530 controller->setModelAndView(model, view);
532 model->notifyObservers(_idManager);
534 addObjectController(controller);
536 return (GPortController*) controller;
539 //=========================================================================
541 int wxVtkSceneManager::createGConnector(GPortModel* startPort)
543 int type = GCONNECTOR;
545 manualConnectorContourController *manContourControl = new manualConnectorContourController();
546 manualConnectorContourView *manContourView = new manualConnectorContourView();
547 manualContourModel *manContourModel = new manualContourModel();
548 GConnectorController *connectorcontroller = new GConnectorController();
549 GConnectorModel *connectorModel = new GConnectorModel();
550 vtkGConnectorView *connectorView = new vtkGConnectorView();
551 connectorModel->setGObjectType(type);
553 manContourModel->SetCloseContour(false);
554 connectorModel->setStartPort(startPort);
556 manContourView->SetModel(manContourModel);
557 manContourView->SetWxVtkBaseView(_baseView);
558 manContourView->SetRange(0.5);
559 manContourView->SetZ(GPOSITION_Z);
561 manContourView->SetColorNormalContour(0, 0, 1);
562 manContourView->SetColorEditContour(0.5, 0.5, 0.5);
563 manContourView->SetColorSelectContour(1, 0.8, 0);
569 * Width increased from 2 to 3, it simplifies line handling and spline control :P
572 manContourView->SetWidthLine( 3 ) ;
573 manContourView->SetShowText(false);
575 manContourControl->SetModelView(manContourModel, manContourView);
577 manContourControl->CreateNewManualContour();
581 connectorModel->getInicPoint(x, y, z);
584 manContourControl->SetState(1);
585 manContourModel->SetCloseContour(false);
587 manContourModel->AddPoint(x, y, z);
588 manContourView->AddPoint();
590 manContourModel->AddPoint(x, y, z);
591 manContourView->AddPoint();
593 int bak = manContourControl->GetNumberOfPointsManualContour() - 1;
594 manContourControl->_bakIdPoint = bak;
596 manContourControl->SetMoving(false);
598 connectorcontroller->setModelAndView(connectorModel, connectorView);
600 int newId = addObjectController(connectorcontroller);
602 connectorcontroller->setManualContourController(manContourControl);
603 connectorModel->setManualContourModel(manContourModel);
604 connectorView->setManualContourView(manContourView);
605 connectorView->setModel(connectorModel);
606 connectorView->setBaseView(_baseView);
608 connectorModel->addObserver(connectorView);
609 connectorModel->addObserver(this);
611 // manContourView->Refresh();
616 //=========================================================================
618 void wxVtkSceneManager::registerController(InteractorStyleMaracas *param)
620 vtkInteractorStyleBaseView * baseViewControlManager = (vtkInteractorStyleBaseView*) _baseView->GetInteractorStyleBaseView();
621 baseViewControlManager->AddInteractorStyleMaracas(param);
624 //=========================================================================
626 void wxVtkSceneManager::unregisterController(InteractorStyleMaracas *param)
628 vtkInteractorStyleBaseView *baseViewControlManager = (vtkInteractorStyleBaseView*) _baseView->GetInteractorStyleBaseView();
629 baseViewControlManager->RemoveInteractorStyleMaracas(param);
632 //=========================================================================
634 vtkRenderer* wxVtkSceneManager::getRenderer()
636 return _baseView->GetRenderer();
639 //=========================================================================
641 vtkRenderWindow* wxVtkSceneManager::getRenderWindow()
643 return _baseView->GetRenWin();
645 //=========================================================================
648 //=========================================================================
649 int wxVtkSceneManager::GetIndexInSelected(int idControler)
652 for (int i = 0; i < (int) _selectedObjects.size(); i++)
654 if (_selectedObjects[i] == idControler)
662 //=========================================================================
664 void wxVtkSceneManager::update(int idController, int command) {
666 if (command != NO_COMMAND)
668 if (command == ADD_TO_SELECTED)
670 if (GetIndexInSelected(idController) == -1)
672 _selectedObjects.push_back(idController);
674 } else if (command == REMOVE_FROM_SELECTED) {
675 int index = GetIndexInSelected(idController);
678 _selectedObjects.erase(_selectedObjects.begin() + index);
680 } else if (command == INIT_CREATION_CONTOUR) {
682 typedef std::map<int , GObjectController*>::iterator TIterator ;
685 // Find current item in the controller
686 iter = _controllers.find( idController ) ;
687 iter_end = _controllers.end( ) ;
689 if ( iter != iter_end ) {
690 GObjectController* gobjc = iter->second ;
692 std::string bbtkType = gobjc->getModel( )->getBBTKType( ) ;
693 // And if the item is a port
694 if ( gobjc->getModel( )->getGObjectType( ) == GPORT ) {
695 TIterator c_it = _controllers.begin( ) ;
696 // Go through all componets
697 for ( c_it ; c_it != iter_end ; c_it++ ) {
698 GObjectController* obc = c_it->second ;
699 int obc_type = obc->getModel( )->getGObjectType( ) ;
700 std::string obc_bbtkType = obc->getModel( )->getBBTKType( ) ;
701 // if the component is a port and the type is the same of that selected
702 if ( ( obc_type == GPORT ) && ( obc_bbtkType == bbtkType ) ) {
704 obc->getView( )->setState( POSSIBLE_CONNECTION ) ;
705 //obc->getView( )->setState( HIGHLIGHTED ) ;
713 _worldState = INIT_CREATION_CONTOUR;
714 GObjectController* cont = _controllers[idController];
715 GPortModel* startOutputPort = (GPortModel*) cont->getModel();
717 // The last one is the controller of the connector
718 std::map<int, GObjectController*>::iterator it2;
720 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
722 GObjectController *cont = it2->second;
723 if (cont->getGObjectType() == GPORT)
725 GPortModel* port = (GPortModel*) cont->getModel();
726 if (port->getPortType() == GINPUTPORT)
728 cont->SetActive(true);
730 cont->getView()->setState(NOTHING_HAPPENS);
731 cont->getModel()->notifyObservers(_idManager);
732 cont->SetActive(false);
735 cont->getView()->setState(NOTHING_HAPPENS);
736 cont->getModel()->notifyObservers(_idManager);
737 cont->SetActive(false);
740 _selectedObjects.clear();
741 _idConnectionInCreation = createGConnector(startOutputPort);
742 } else if (command == FIN_CREATION_CONTOUR && _worldState == INIT_CREATION_CONTOUR) {
743 _worldState = NOTHING_HAPPENS;
744 //int id = _controllers.size()-1;
745 GObjectController *cont = _controllers[_idConnectionInCreation];
746 GConnectorModel *modelContour = (GConnectorModel*) cont->getModel();
747 GObjectController *finPort = _controllers[idController];
749 if (finPort->getGObjectType() == GPORT)
751 GPortModel* modelPort = (GPortModel*) finPort->getModel();
752 modelContour->setEndPort(modelPort);
755 typedef std::map<int, GObjectController*>::iterator TIterator;
756 TIterator c_it = _controllers.begin();
757 TIterator iter_end = _controllers.end();
758 // Go through all componets
759 for (c_it; c_it != iter_end; c_it++) {
760 GObjectController* obc = c_it->second;
761 int obc_type = obc->getModel()->getGObjectType();
762 int obc_state = obc->getView()->getState();
763 // if the component is a port and the type is the same of that selected
764 if ((obc_type == GPORT) && (obc_state == POSSIBLE_CONNECTION)) {
765 // Return element to neutral state if not selected
766 obc->getView()->setState(NOTHING_HAPPENS);
768 if ((obc_type == GPORT) && (obc_state == SELECTED_POSSIBLE_CONNECTION)) {
769 // Change element to connected state
770 obc->getView()->setState(HIGHLIGHTED);
777 _parent->saveTempandUpdate("create connection");
780 manualConnectorContourController *manCont = ((GConnectorController*) cont)->getManualContourController();
781 manualConnectorContourView *connView = (manualConnectorContourView*) manCont->GetManualViewBaseContour();
783 std::map<int, GObjectController*>::iterator it2;
785 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
787 GObjectController *cont = it2->second;
788 if (cont->getView() != NULL) {
789 cont->getView()->setState(NOTHING_HAPPENS);
790 cont->getModel()->notifyObservers(_idManager);
792 cont->SetActive(true);
801 //=========================================================================
803 bool wxVtkSceneManager::OnMouseMove()
806 bool okStatusMessage = false;
807 bool okPortMessage = false;
808 wxVTKRenderWindowInteractor *wxVTKiren;
809 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
810 wxVTKiren->GetEventPosition(X, Y);
812 if (_worldState == DRAG_OBJECTS) {
813 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
814 int id = _selectedObjects[i];
815 GObjectController* cont = _controllers[id];
816 if (_startDragging) {
817 cont->getView()->setStartDragging(true);
819 cont->getView()->moveObject(X, Y);
820 cont->getView()->setState(DRAG);
821 cont->getModel()->notifyObservers(_idManager);
824 std::map<int, GObjectController*>::iterator it;
826 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
827 GObjectController *desc = it->second;
828 if (desc->getGObjectType() == GCONNECTOR) {
829 vtkGConnectorView* vconn = (vtkGConnectorView*) desc->getView();
830 vconn->updateStartEndPoints();
834 _startDragging = false;
836 } else if (_worldState == NOTHING_HAPPENS || _worldState == INIT_CREATION_CONTOUR) {
837 std::map<int, GObjectController*>::iterator it;
839 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
840 GObjectController *desc = it->second;
841 int type = desc->getGObjectType();
842 int state = desc->getView()->getState();
843 desc->getModel()->getCenter(px, py, pz);
846 if ((state == HIGHLIGHTED) || (state == SELECTED_POSSIBLE_CONNECTION ))
849 okStatusMessage = true;
850 updateStatusBar(desc->getStatusText());
851 if (type == GBLACKBOX)
853 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
854 _parent->displayBlackBoxInfo(mod->getBBTKPackage(),mod->getBBTKType());
859 if ( ( _bugTextActor_text==desc->getStatusText() ) || (_bugTextActor_status==0) )
861 _bugTextActor_status = 1;
862 okPortMessage = true;
864 _textActor->SetScale(0.1);
865 std::string tmp = desc->getStatusText()+"\n";
866 _textActor->SetInput( tmp.c_str() );
867 _textActor->SetPosition(px - 25, py + 1, pz + 2);
868 _textActor->Modified();
872 _fillObjectActor->SetScale(1);
873 _fillObjectActor->GetProperty()->SetOpacity(0.50);
874 _fillObjectActor->SetPosition(px, py, 1);
875 _aPolygonMapper->Modified();
877 _bugTextActor_status = 2;
878 } // _bugTextActor_tex
879 _bugTextActor_text = desc->getStatusText();
883 } // for controllers it
885 if (okStatusMessage == false)
890 if ((okPortMessage == false) || (_bugTextActor_status== 2 ) )
892 _bugTextActor_status = 0;
893 _textActor->SetScale(0.0001);
894 _textActor->SetInput("a\n");
895 _textActor->Modified();
896 _fillObjectActor->SetScale(0.0001);
901 //=========================================================================
903 bool wxVtkSceneManager::OnLeftButtonDown()
905 if (_worldState == INIT_CREATION_CONTOUR)
907 bool isOverPort = false;
908 std::map<int, GObjectController*>::iterator it;
909 for (it = _controllers.begin(); it != _controllers.end() && isOverPort== false; ++it)
911 GObjectController *desc = it->second;
912 if (desc->getGObjectType() == GPORT)
914 GPortModel *portmod = (GPortModel*) desc->getModel();
915 vtkGObjectView *portView = desc->getView();
916 if (portmod->getPortType() == GINPUTPORT && portView->getState() == HIGHLIGHTED)
921 if ( portmod->getPortType( ) == GINPUTPORT && portView->getState( ) == SELECTED_POSSIBLE_CONNECTION ) {
923 portView->setState( HIGHLIGHTED);
930 if (isOverPort == false)
933 UnSelectBlackBoxes();
937 } else { //_worldState
939 _worldState = DRAG_OBJECTS;
940 _startDragging = true;
942 int shiftkey = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey();
943 int ctrlkey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
944 ctrlkey = ctrlkey + shiftkey;
946 GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
949 int state = cont->getView()->getState();
950 if ((ctrlkey == 0) && (state == HIGHLIGHTED)) {
951 UnSelectBlackBoxes();
954 UnSelectBlackBoxes(); // EED 12/07/2012
956 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
957 int id = _selectedObjects[i];
958 GObjectController *cont = _controllers[id];
959 cont->getView()->setState(DRAG);
960 cont->getModel()->notifyObservers(_idManager);
962 } // if _selectedObjects.size
968 //=========================================================================
970 bool wxVtkSceneManager::OnLeftButtonUp()
972 if (_worldState == DRAG_OBJECTS) {
973 _worldState = NOTHING_HAPPENS;
975 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
976 int id = _selectedObjects[i];
977 GObjectController* cont = _controllers[id];
978 cont->getView()->setState(SELECTED);
979 cont->getModel()->notifyObservers(_idManager);
985 //=========================================================================
986 void wxVtkSceneManager::CancelConnection()
988 if (_worldState == INIT_CREATION_CONTOUR)
990 _worldState = NOTHING_HAPPENS;
991 //int lastId = _controllers.size()-1;
993 GConnectorController *connector =
994 (GConnectorController*) _controllers[_idConnectionInCreation];
995 connector->removeFromScene();
996 unregisterController(connector);
997 _controllers.erase(_idConnectionInCreation);
999 std::map<int, GObjectController*>::iterator it;
1000 for (it = _controllers.begin(); it != _controllers.end(); ++it)
1002 GObjectController *desc = it->second;
1003 desc->SetActive(true);
1004 desc->getView()->setState(NOTHING_HAPPENS);
1005 desc->getModel()->notifyObservers(_idManager);
1010 //=========================================================================
1012 bool wxVtkSceneManager::OnRightButtonUp()
1014 if (_worldState == INIT_CREATION_CONTOUR)
1018 UnSelectBlackBoxes();
1024 bool wxVtkSceneManager::OnMiddleButtonDown() {
1027 this->_vtkInteractorStyleBaseView->StartPan();
1032 bool wxVtkSceneManager::OnMiddleButtonUp() {
1035 this->_vtkInteractorStyleBaseView->EndPan();
1042 //=========================================================================
1044 GObjectController *wxVtkSceneManager::GetGBlackBoxControlerPointedByMouse() {
1045 GObjectController *result = NULL;
1047 wxVTKRenderWindowInteractor *wxVTKiren;
1049 = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
1050 wxVTKiren->GetEventPosition(X, Y);
1052 std::map<int, GObjectController*>::iterator it;
1054 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1055 GObjectController *cont = it->second;
1056 int type = cont->getGObjectType();
1058 if (cont->getView()->isPointInside(X, Y) == true) {
1059 if (type == GBLACKBOX) {
1062 } // if isPointInside
1067 //=========================================================================
1068 void wxVtkSceneManager::UnSelectBlackBoxes() {
1069 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
1070 int id = _selectedObjects[i];
1071 GObjectController* control = _controllers[id];
1072 control->getView()->setState(NOTHING_HAPPENS);
1073 control->getModel()->notifyObservers(_idManager);
1074 }// for _selectedObjects
1075 _selectedObjects.clear();
1078 //=========================================================================
1079 bool wxVtkSceneManager::OnLeftDClick() {
1080 GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
1082 UnSelectBlackBoxes();
1083 _parent->editBlackBox((GBlackBoxModel*) cont->getModel());
1089 wxVTKRenderWindowInteractor *wxVTKiren;
1090 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
1091 wxVTKiren->GetEventPosition(X,Y);
1093 std::map<int, GObjectController*>::iterator it;
1095 bool clickOnObject = false;
1097 for(it = _controllers.begin(); it != _controllers.end() && clickOnObject==false; ++it)
1099 GObjectController *cont = it->second;
1100 int type = cont->getGObjectType();
1102 if(cont->getView()->isPointInside(X,Y))
1106 for (int i=0; i< (int)_selectedObjects.size(); i++)
1108 int id = _selectedObjects[i];
1109 GObjectController* control = _controllers[id];
1110 control->getView()->setState(NOTHING_HAPPENS);
1112 _selectedObjects.clear();
1114 GBlackBoxModel *bbmodel = (GBlackBoxModel*)cont->getModel();
1115 _parent->editBlackBox(bbmodel);
1117 clickOnObject = true;
1121 if(clickOnObject==false)
1123 //_parent->editDiagramParameters(this);
1129 //=========================================================================
1131 bool wxVtkSceneManager::OnChar()
1135 char keyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
1136 int ctrlkey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
1138 // KeyCode 127 : Delete Key
1139 // KeyCode 8 : Backspace Key
1142 if (keyCode == 8 || keyCode == 127 || keyCode == 27)
1144 if (_worldState == INIT_CREATION_CONTOUR)
1147 UnSelectBlackBoxes();
1152 if (keyCode == 8 || keyCode == 127)
1155 for (int i = 0; i < (int) _selectedObjects.size(); i++)
1157 int id = _selectedObjects[i];
1158 std::map<int, GObjectController*>::iterator it;
1159 it = _controllers.find(id);
1160 if (it != _controllers.end())
1162 oktmp = deleteObject(id);
1165 }// for selected objects
1166 if (ok) _selectedObjects.clear();
1167 _parent->saveTempandUpdate("delete object");
1172 if((keyCode==0) && (ctrlkey==1)) {
1177 if(_selectedObjects.size()){
1178 std::cout<<"objects to copy :";
1179 for(int i=0;i<_selectedObjects.size();i++)
1181 std::cout<<_selectedObjects.at(i)<<" ";
1183 DuplicateObjects(getSelectedObjects());
1185 std::cout<<"No objects to copy\n";
1186 } // _selectedObjects.size
1192 //=========================================================================
1194 void wxVtkSceneManager::AddControlerToBeRemove(
1195 std::vector<int> *controllersToRemove, int id) {
1199 for (i = 0; i < (int) controllersToRemove->size(); i++) {
1200 if (id == (*controllersToRemove)[i]) {
1206 controllersToRemove->push_back(id);
1211 //=========================================================================
1213 bool wxVtkSceneManager::deleteObject(int id)
1216 GObjectController *control = _controllers[id];
1217 std::vector<int> controllersToRemove;
1218 if (control->getGObjectType() == GBLACKBOX || control->getGObjectType()
1219 == GCOMPLEXINPUTPORT || control->getGObjectType()
1220 == GCOMPLEXOUTPUTPORT) {
1221 GBoxModel *bbmod = (GBoxModel*) control->getModel();
1222 std::vector<GPortModel*> inputs = bbmod->getInputPorts();
1224 bool boxConnected = false;
1226 // Add box input controllers to be removed
1227 for (int i = 0; i < (int) inputs.size(); i++) {
1228 AddControlerToBeRemove(&controllersToRemove, inputs[i]->getObjectId());
1229 if (inputs[i]->isConnected()) {
1230 boxConnected = true;
1234 std::vector<GPortModel*> outputs = bbmod->getOutputPorts();
1236 // Add box output controllers to be removed
1237 for (int i = 0; i < (int) outputs.size(); i++) {
1238 AddControlerToBeRemove(&controllersToRemove, outputs[i]->getObjectId());
1239 if (outputs[i]->isConnected()) {
1240 boxConnected = true;
1244 // Add connection controllers to be removed
1245 std::map<int, GObjectController*>::iterator it;
1246 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1247 GObjectController *cont = it->second;
1248 int type = cont->getGObjectType();
1249 if (type == GCONNECTOR) {
1250 GConnectorModel *conMod = (GConnectorModel*) cont->getModel();
1251 if (conMod->getStartPort() != NULL && conMod->getStartPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
1253 AddControlerToBeRemove(&controllersToRemove,conMod->getObjectId());
1255 if (conMod->getEndPort() != NULL && conMod->getEndPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
1257 AddControlerToBeRemove(&controllersToRemove,conMod->getObjectId());
1262 // Add box controller to be removed
1263 AddControlerToBeRemove(&controllersToRemove, bbmod->getObjectId());
1264 } else if (control->getGObjectType() == GCONNECTOR) {
1265 GConnectorController *gconnectorcontroler = (GConnectorController*)control;
1266 if (gconnectorcontroler->getManualContourController()->IsEditable()==false)
1268 GConnectorModel *conMod = (GConnectorModel*) control->getModel();
1269 AddControlerToBeRemove(&controllersToRemove, conMod->getObjectId());
1271 gconnectorcontroler->getManualContourController()->OnChar();
1276 std::map<int, GObjectController*>::iterator it;
1278 for (int i = 0; i < (int) controllersToRemove.size(); i++) {
1279 int key = controllersToRemove[i];
1280 it = _controllers.find(key);
1281 GObjectController *cont = _controllers[key];
1283 cont->removeFromScene();
1284 unregisterController((InteractorStyleMaracas*) cont);
1285 _controllers.erase(it);
1293 //=========================================================================
1295 void wxVtkSceneManager::displayBlackBoxInfo(std::string packageName,
1296 std::string boxName) {
1297 _parent->displayBlackBoxInfo(packageName, boxName);
1300 //=========================================================================
1302 void wxVtkSceneManager::updateStatusBar(std::string textStatus) {
1303 _parent->updateStatusBar(textStatus);
1306 //=========================================================================
1307 std::string wxVtkSceneManager::LineNumber(bool withLineNumber, int &value) {
1308 std::string result = "";
1309 if (withLineNumber == true) {
1311 stringstream StrStream;
1313 std::string strValue = StrStream.str();
1316 } else if (value < 100) {
1320 result += strValue + ": ";
1324 //=========================================================================
1326 bool wxVtkSceneManager::MakeBoxExecutable() {
1327 std::map<int, GObjectController*> selected = getSelectedObjects();
1328 if( selected.empty() )
1331 std::map<int, GObjectController*>::iterator it;
1332 for (it = selected.begin(); it != selected.end(); ++it) {
1333 GObjectController* lastSelected = it->second;
1335 vtkGObjectView* view = (vtkGObjectView*) lastSelected->getView();
1336 GBlackBoxModel *bbmodel =
1337 (GBlackBoxModel*) lastSelected->getModel();
1338 view->setState(HIGHLIGHTED);
1339 if (bbmodel->isExecutable()) {
1340 bbmodel->setExecutable(false);
1342 bbmodel->setExecutable(true);
1344 bbmodel->notifyObservers(lastSelected->getId());
1352 //=========================================================================
1354 std::string wxVtkSceneManager::getDiagramBBS(bool wln) {
1355 bool existsExec = false;
1357 std::vector<std::string> packages;
1358 std::vector<int> boxes;
1359 std::vector<int> connections;
1360 std::vector<int> execBoxes;
1362 std::map<int, GObjectController*>::iterator it;
1364 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1365 GObjectController *desc = it->second;
1366 int type = desc->getGObjectType();
1368 if (type == GBLACKBOX) {
1369 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
1371 std::string pkg = mod->getBBTKPackage();
1372 bool existsPkg = false;
1373 for (int t = 0; t < (int) packages.size() && existsPkg == false; t++) {
1374 if (packages[t] == pkg) {
1379 packages.push_back(pkg);
1382 boxes.push_back(it->first);
1383 if (mod->isExecutable()) {
1384 execBoxes.push_back(it->first);
1387 } else if (type == GCONNECTOR) {
1388 connections.push_back(it->first);
1393 std::string script = "";
1394 script += LineNumber(wln, lnNmbr) + "# BBTK GEditor Script\n";
1395 script += LineNumber(wln, lnNmbr) + "# ----------------------\n";
1396 script += LineNumber(wln, lnNmbr) + "\n";
1398 script += LineNumber(wln, lnNmbr) + "include std\n"; // EED
1399 script += LineNumber(wln, lnNmbr) + "include itkvtk\n"; // EED
1401 for (i = 0; i < (int) packages.size(); i++) {
1402 script += LineNumber(wln, lnNmbr);
1403 script += "include ";
1404 script += packages[i];
1408 script += LineNumber(wln, lnNmbr);
1413 script += LineNumber(wln, lnNmbr);
1414 script += "author \"";
1418 script += LineNumber(wln, lnNmbr);
1419 script += "description \"";
1420 script += _Description;
1423 script += LineNumber(wln, lnNmbr);
1424 script += "category \"";
1425 script += _Category;
1428 script += LineNumber(wln, lnNmbr);
1431 // script+="include std\n"; // JPR
1433 for (i = 0; i < (int) boxes.size(); i++) {
1434 script += LineNumber(wln, lnNmbr);
1437 GObjectController *control = _controllers[id];
1438 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1440 script += model->getBBTKType();
1442 script += model->getBBTKName();
1445 std::vector<GPortModel*> inputs = model->getInputPorts();
1446 for (int j = 0; j < (int) inputs.size(); j++) {
1447 GPortModel* inputPort = inputs[j];
1448 if (inputPort->isValueSet()) {
1449 script += LineNumber(wln, lnNmbr);
1451 script += model->getBBTKName();
1453 script += inputPort->getBBTKName();
1455 script += inputPort->getValue();
1460 script += LineNumber(wln, lnNmbr);
1465 script += LineNumber(wln, lnNmbr);
1469 std::string complexInputs="";
1471 for (i = 0; i < (int) connections.size(); i++) {
1472 //script += LineNumber(wln, lnNmbr);
1473 //script += "connect ";
1474 int id = connections[i];
1475 GObjectController *control = _controllers[id];
1476 GConnectorModel *model = (GConnectorModel*) control->getModel();
1480 GPortModel *start = model->getStartPort();
1481 GBoxModel *startBox = start->getParentBox();
1483 GPortModel *end = model->getEndPort();
1484 GBoxModel *endBox = end->getParentBox();
1486 if (startBox->getGObjectType() == GCOMPLEXINPUTPORT)
1488 complexInputs += "input ";
1489 complexInputs += startBox->getBBTKName();
1491 complexInputs += " ";
1492 complexInputs += endBox->getBBTKName();
1493 complexInputs += ".";
1494 complexInputs += end->getBBTKName();
1496 complexInputs += " ";
1497 complexInputs += "\" \"";
1499 complexInputs += "\n";
1503 script += "connect ";
1504 script += startBox->getBBTKName();
1506 script += start->getBBTKName();
1510 //End Connection info
1511 script += endBox->getBBTKName();
1513 script += end->getBBTKName();
1521 script += LineNumber(wln, lnNmbr);
1525 script += "# Complex input ports\n";
1526 script += complexInputs;
1528 for (i = 0; i < (int) execBoxes.size(); i++) {
1529 script += LineNumber(wln, lnNmbr);
1531 int id = execBoxes[i];
1532 GObjectController *control = _controllers[id];
1533 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1535 script += model->getBBTKName();
1544 //=========================================================================
1546 std::string wxVtkSceneManager::saveComplexBoxBBS() {
1547 std::vector<std::string> packages;
1548 std::vector<int> boxes;
1549 std::vector<int> connections;
1550 std::vector<int> execBoxes;
1552 std::map<int, GObjectController*>::iterator it;
1554 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1555 GObjectController *desc = it->second;
1556 int type = desc->getGObjectType();
1558 if (type == GBLACKBOX) {
1559 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
1561 std::string pkg = mod->getBBTKPackage();
1562 bool existsPkg = false;
1563 for (int t = 0; t < (int) packages.size() && existsPkg == false; t++) {
1564 if (packages[t] == pkg) {
1569 packages.push_back(pkg);
1572 boxes.push_back(it->first);
1573 if (mod->isExecutable()) {
1574 execBoxes.push_back(it->first);
1576 } else if (type == GCONNECTOR) {
1577 connections.push_back(it->first);
1581 std::string script = "";
1583 script += "include std\n"; // EED
1584 script += "include itkvtk\n"; // EED
1586 for (i = 0; i < (int) packages.size(); i++) {
1587 script += "include ";
1588 script += packages[i];
1593 // Definition of a complex box
1594 script += "define ";
1595 script += _cbName + " " + _cbPackageName;
1599 script += "author \"";
1603 script += "description \"";
1604 script += _Description;
1608 script += "category \"";
1609 script += _Category;
1614 for (i = 0; i < (int) boxes.size(); i++) {
1617 GObjectController *control = _controllers[id];
1618 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1620 script += model->getBBTKType();
1622 script += model->getBBTKName();
1625 std::vector<GPortModel*> inputs = model->getInputPorts();
1626 for (int j = 0; j < (int) inputs.size(); j++) {
1627 GPortModel* inputPort = inputs[j];
1628 if (inputPort->isValueSet()) {
1630 script += model->getBBTKName();
1632 script += inputPort->getBBTKName();
1634 script += inputPort->getValue();
1642 // Create connections in the script. If the connection is made with a complex port, it is created the input or output
1644 std::string complexInputs = "";
1645 std::string complexOutputs = "";
1648 for (i = 0; i < (int) connections.size(); i++) {
1649 int id = connections[i];
1650 GObjectController *control = _controllers[id];
1651 GConnectorModel *model = (GConnectorModel*) control->getModel();
1654 GPortModel *start = model->getStartPort();
1655 GBoxModel *startBox = start->getParentBox();
1657 GPortModel *end = model->getEndPort();
1658 GBoxModel *endBox = end->getParentBox();
1660 if (startBox->getGObjectType() == GCOMPLEXINPUTPORT) {
1661 complexInputs += "input ";
1662 complexInputs += startBox->getBBTKName();
1664 complexInputs += " ";
1665 complexInputs += endBox->getBBTKName();
1666 complexInputs += ".";
1667 complexInputs += end->getBBTKName();
1669 complexInputs += " ";
1670 complexInputs += "\" \"";
1672 complexInputs += "\n";
1673 } else if (endBox->getGObjectType() == GCOMPLEXOUTPUTPORT) {
1674 complexOutputs += "output ";
1675 complexOutputs += endBox->getBBTKName();
1677 complexOutputs += " ";
1678 complexOutputs += startBox->getBBTKName();
1679 complexOutputs += ".";
1680 complexOutputs += start->getBBTKName();
1682 complexOutputs += " ";
1683 complexOutputs += "\" \"";
1685 complexOutputs += "\n";
1687 script += "connect ";
1688 script += startBox->getBBTKName();
1690 script += start->getBBTKName();
1694 //End Connection info
1695 script += endBox->getBBTKName();
1697 script += end->getBBTKName();
1704 script += "# Complex input ports\n";
1705 script += complexInputs;
1708 script += "# Complex output ports\n";
1709 script += complexOutputs;
1713 for (i = 0; i < (int) execBoxes.size(); i++) {
1715 int id = execBoxes[i];
1716 GObjectController *control = _controllers[id];
1717 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1719 script += model->getBBTKName();
1724 script += "endefine";
1730 //=========================================================================
1732 void wxVtkSceneManager::deleteAllBoxes() {
1733 std::map<int, GObjectController*>::iterator it;
1734 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1735 GObjectController *cont = it->second;
1736 cont->removeFromScene();
1737 unregisterController((InteractorStyleMaracas*) cont);
1739 _selectedObjects.clear();
1740 _controllers.clear();
1743 //=========================================================================
1746 void wxVtkSceneManager::refresh() {
1747 _baseView->Refresh();
1749 //=========================================================================
1751 void wxVtkSceneManager::refreshScene() {
1752 _baseView->RefreshView();
1755 //=========================================================================
1757 void wxVtkSceneManager::centerView() {
1759 _baseView->GetRenderer()->GetActiveCamera()->GetFocalPoint(temp);
1760 _baseView->GetRenderer()->GetActiveCamera()->SetFocalPoint(0, 0, temp[2]);
1761 _baseView->GetRenderer()->GetActiveCamera()->GetPosition(temp);
1762 _baseView->GetRenderer()->GetActiveCamera()->SetPosition(0, 0, temp[2]);
1765 //=========================================================================
1767 void wxVtkSceneManager::saveDiagram(std::string &content) {
1770 content += "CATEGORY:";
1771 content += GetCategory();
1774 content += "DESCRIPTION:";
1775 content += GetDescription();
1778 content += "AUTHOR:";
1779 content += GetAuthor();
1782 //Print info IF COMPLEX BOX
1783 content += "COMPLEXBOX:";
1784 if (_isComplexBox) {
1785 content += "TRUE\n";
1787 content += "COMPLEXBOXNAME:";
1788 content += GetCbName();
1791 content += "PACKAGENAME:";
1792 content += GetCbPackageName();
1795 /* CHANGE TO THE VERSION 1.4 RaC2012 2nd HackFest
1796 * External inputs are possible for applications and complex boxes
1797 //Print info complex input ports
1798 std::vector<int> inputs = getComplexInputPorts();
1799 int insize = inputs.size();
1800 content += "COMPLEXINPUTS:";
1801 sprintf(buffer, "%d", insize);
1805 for (int i = 0; i < insize; i++) {
1807 GObjectController *cont = _controllers[id];
1808 cont->getModel()->save(content);
1812 //Print info complex output ports
1813 std::vector<int> outputs = getComplexOutputPorts();
1814 int outsize = outputs.size();
1815 content += "COMPLEXOUTPUTS:";
1816 sprintf(buffer, "%d", outsize);
1820 for (int i = 0; i < outsize; i++) {
1821 int id = outputs[i];
1822 GObjectController *cont = _controllers[id];
1823 cont->getModel()->save(content);
1827 content += "FALSE\n";
1830 // CHANGE TO THE VERSION 1.4 RaC2012 2nd HackFest
1831 // External inputs are possible for applications and complex boxes
1832 std::vector<int> inputs = getComplexInputPorts();
1833 int insize = inputs.size();
1834 content += "COMPLEXINPUTS:";
1835 sprintf(buffer, "%d", insize);
1839 for (int i = 0; i < insize; i++) {
1841 GObjectController *cont = _controllers[id];
1842 cont->getModel()->save(content);
1846 std::vector<int> boxes = getBlackBoxes();
1847 int bsize = boxes.size();
1848 content += "BOXES:";
1849 sprintf(buffer, "%d", bsize);
1853 for (int i = 0; i < bsize; i++) {
1855 GObjectController *cont = _controllers[id];
1856 cont->getModel()->save(content);
1860 std::vector<int> connections = getConnections();
1861 int csize = connections.size();
1862 content += "CONNECTIONS:";
1863 sprintf(buffer, "%d", csize);
1867 for (int i = 0; i < csize; i++) {
1868 int id = connections[i];
1869 GObjectController *cont = _controllers[id];
1870 cont->getModel()->save(content);
1875 //=========================================================================
1876 void wxVtkSceneManager::getCleanLine(stringstream &inputStream, std::string &line)
1878 getline(inputStream, line,'\n');
1879 int size = line.length();
1882 if ( line[ size-1 ]==13 )
1884 line.erase(size-1,1);
1889 //=========================================================================
1890 void wxVtkSceneManager::loadDiagram(stringstream &inputStream)
1894 std::string version = "<void>";
1895 std::string line = "";
1896 char delims[] = ":";
1897 char *result = NULL;
1898 char poort[POORT_MAX_LINE_SIZE_INTERPRETER];
1900 getCleanLine(inputStream, line);
1903 while (!inputStream.eof()) {
1904 if (line == "" || line[0] == '#') {
1906 getCleanLine(inputStream, line);
1908 if (line == "# - BBTKGEditor v 1.0 BBG BlackBox Diagram file") {
1909 version = line.substr(18, 3);
1911 if (line == "# - BBTKGEditor v 1.1 BBG BlackBox Diagram file") {
1912 version = line.substr(18, 3);
1914 if (line == "# - BBTKGEditor v 1.2 BBG BlackBox Diagram file") {
1915 version = line.substr(18, 3);
1917 if (line == "# - BBTKGEditor v 1.3 BBG BlackBox Diagram file") {
1918 version = line.substr(18, 3);
1920 if (line == "# - BBTKGEditor v 1.4 BBG BlackBox Diagram file") {
1921 version = line.substr(18, 3);
1923 } else if (line == "APP_START") {
1932 if ((version != "1.0") && (version != "1.1")) {
1933 getCleanLine(inputStream, line);//CATEGORY:<category of the box>
1934 char categoryTmp[30];
1935 strcpy(categoryTmp, line.c_str());
1936 result = strtok(categoryTmp, delims);
1937 result = strtok(NULL, delims);
1938 SetCategory(result);
1940 getCleanLine(inputStream, line);//DESCRIPTION:<description of the box>
1941 char descriptionTmp[1024];
1942 strcpy(descriptionTmp, line.c_str());
1943 result = strtok(descriptionTmp, delims);
1944 result = strtok(NULL, delims);
1945 SetDescription(result);
1947 getCleanLine(inputStream, line);//AUTHOR:<author>
1948 char authorTmp[255];
1949 strcpy(authorTmp, line.c_str());
1950 result = strtok(authorTmp, delims);
1951 result = strtok(NULL, delims);
1956 getCleanLine(inputStream, line);//COMPLEX_BOX:TRUE|FALSE
1957 char complexTmp[30];
1958 strcpy(complexTmp, line.c_str());
1959 result = strtok(complexTmp, delims);
1960 result = strtok(NULL, delims);
1961 std::string isComplexBox(result);
1963 if (isComplexBox == "TRUE") {
1964 _isComplexBox = true;
1966 if ((version != "1.0") && (version != "1.1")) {
1967 getCleanLine(inputStream, line);//COMPLEXNAME:<name of the complex box>
1968 char complexboxnameTmp[255];
1969 strcpy(complexboxnameTmp, line.c_str());
1970 result = strtok(complexboxnameTmp, delims);
1971 result = strtok(NULL, delims);
1974 getCleanLine(inputStream, line);//PACKAGENAME:<name of the package of the box>
1975 char packagenameTmp[255];
1976 strcpy(packagenameTmp, line.c_str());
1977 result = strtok(packagenameTmp, delims);
1978 result = strtok(NULL, delims);
1979 SetCbPackageName(result);
1984 //-----------------------
1985 //- COMPLEX INPUT PORTS
1986 //-----------------------
1987 getCleanLine(inputStream, line);//COMPLEXINPUTS:num
1989 strcpy(inputs, line.c_str());
1990 result = strtok(inputs, delims);
1991 result = strtok(NULL, delims);
1994 std::istringstream inps(result);
1997 for (int i = 0; i < numInputs; i++) {
1999 getCleanLine(inputStream, line);//COMPLEX_PORT
2000 getCleanLine(inputStream, line);//name
2001 std::string inputPortName(line);
2004 getCleanLine(inputStream, line);//xInic:yInic:zInic
2006 strcpy(coord, line.c_str());
2007 result = strtok(coord, delims);//xInic
2008 std::string xInic(result);
2009 result = strtok(NULL, delims);//yInic
2010 std::string yInic(result);
2011 result = strtok(NULL, delims);//zInic
2012 std::string zInic(result);
2014 double xIn, yIn, zIn;
2015 std::istringstream xSt(xInic);
2017 std::istringstream ySt(yInic);
2019 std::istringstream zSt(zInic);
2024 if (zIn==900) zIn=GPOSITION_Z;
2027 getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
2029 configGComBoxInputOutputPort(true, inputPortName, xIn, yIn, zIn);
2031 } // for input complex box
2036 //-----------------------
2037 //- COMPLEX OUTPUT PORTS
2038 //-----------------------
2040 getCleanLine(inputStream, line);//COMPLEXOUTPUTS:num
2042 strcpy(outputs, line.c_str());
2043 result = strtok(outputs, delims);
2044 result = strtok(NULL, delims);
2047 std::istringstream outps(result);
2048 outps >> numOutputs;
2050 for (int i = 0; i < numOutputs; i++) {
2052 getCleanLine(inputStream, line);//COMPLEX_PORT
2053 getCleanLine(inputStream, line);//name
2054 std::string outputPortName(line);
2057 getCleanLine(inputStream, line);//xInic:yInic:zInic
2059 strcpy(coord, line.c_str());
2060 result = strtok(coord, delims);//xInic
2061 std::string xInic(result);
2062 result = strtok(NULL, delims);//yInic
2063 std::string yInic(result);
2064 result = strtok(NULL, delims);//zInic
2065 std::string zInic(result);
2067 double xIn, yIn, zIn;
2068 std::istringstream xSt(xInic);
2070 std::istringstream ySt(yInic);
2072 std::istringstream zSt(zInic);
2077 if (zIn==900) zIn=GPOSITION_Z;
2080 getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
2082 configGComBoxInputOutputPort(false, outputPortName, xIn, yIn, zIn);
2084 } // for output complex box
2088 // RaC2012 2nd Hackfest
2089 if(version >= "1.4")
2091 //-----------------------
2092 //- EXTERNAL INPUT PORTS
2093 //-----------------------
2094 getCleanLine(inputStream, line);//COMPLEXINPUTS:num
2096 strcpy(inputs, line.c_str());
2097 result = strtok(inputs, delims);
2098 result = strtok(NULL, delims);
2101 std::istringstream inps(result);
2104 for (int i = 0; i < numInputs; i++) {
2106 getCleanLine(inputStream, line);//COMPLEX_PORT
2107 getCleanLine(inputStream, line);//name
2108 std::string inputPortName(line);
2111 getCleanLine(inputStream, line);//xInic:yInic:zInic
2113 strcpy(coord, line.c_str());
2114 result = strtok(coord, delims);//xInic
2115 std::string xInic(result);
2116 result = strtok(NULL, delims);//yInic
2117 std::string yInic(result);
2118 result = strtok(NULL, delims);//zInic
2119 std::string zInic(result);
2121 double xIn, yIn, zIn;
2122 std::istringstream xSt(xInic);
2124 std::istringstream ySt(yInic);
2126 std::istringstream zSt(zInic);
2131 if (zIn==900) zIn=GPOSITION_Z;
2134 getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
2135 configGComBoxInputOutputPort(true, inputPortName, xIn, yIn, zIn);
2137 } // for external input
2142 getCleanLine(inputStream, line);//BOXES:num
2144 strcpy(boxes, line.c_str());
2145 result = strtok(boxes, delims);
2146 result = strtok(NULL, delims);
2149 std::istringstream is(result);
2152 for (int i = 0; i < numBoxes; i++) {
2154 getCleanLine(inputStream, line);//BOX
2155 getCleanLine(inputStream, line);//package:type:name
2157 strcpy(box, line.c_str());
2158 result = strtok(box, delims);//package
2159 std::string package(result);
2160 result = strtok(NULL, delims);//type
2161 std::string type(result);
2162 result = strtok(NULL, delims);//name
2163 std::string name(result);
2166 getCleanLine(inputStream, line);//ISEXEC:TRUE|FALSE
2168 strcpy(exec, line.c_str());
2169 result = strtok(exec, delims);//ISEXEC
2170 result = strtok(NULL, delims);//TRUE|FALSE
2171 std::string isExec(result);
2174 getCleanLine(inputStream, line);//xInic:yInic:zInic
2176 strcpy(coord, line.c_str());
2177 result = strtok(coord, delims);//xInic
2178 std::string xInic(result);
2179 result = strtok(NULL, delims);//yInic
2180 std::string yInic(result);
2181 result = strtok(NULL, delims);//zInic
2182 std::string zInic(result);
2184 double xIn, yIn, zIn;
2185 std::istringstream xSt(xInic);
2187 std::istringstream ySt(yInic);
2189 std::istringstream zSt(zInic);
2195 if (zIn==900) zIn=GPOSITION_Z;
2200 getCleanLine(inputStream, line);//xEnd:yEnd:zEnd
2201 strcpy(coord, line.c_str());
2202 result = strtok(coord, delims);//xEnd
2203 std::string xEnd(result);
2204 result = strtok(NULL, delims);//yEnd
2205 std::string yEnd(result);
2206 result = strtok(NULL, delims);//zEnd
2207 std::string zEnd(result);
2209 double xEn, yEn, zEn;
2210 std::istringstream xEt(xEnd);
2212 std::istringstream yEt(yEnd);
2214 std::istringstream zEt(zEnd);
2219 if (zEn==900) zEn=GPOSITION_Z;
2223 bool boxExecutable = false;
2224 if (isExec == "TRUE") {
2225 boxExecutable = true;
2228 int idBox = createGBlackBox(xIn, yIn, package, type);
2229 configGBlackBox(idBox, xIn, yIn, zIn, name, boxExecutable, xEn, yEn, zEn);
2231 GObjectController *cont = _controllers[idBox];
2232 GBlackBoxModel *bbmod = (GBlackBoxModel*) cont->getModel();
2235 getCleanLine(inputStream, line);//PORT o FIN_BOX
2236 std::string port = line.substr(0, 4);
2237 while (port == "PORT")
2239 getCleanLine(inputStream, line);//name:value
2240 if (line.length()>=POORT_MAX_LINE_SIZE_INTERPRETER-1)
2242 line=line.substr(0, POORT_MAX_LINE_SIZE_INTERPRETER-1);
2245 strcpy(poort, line.c_str());
2246 result = strtok(poort, delims);//name
2247 std::string name(result);
2249 //EED 16 oct 2012 Adding at the end character " if necesary in the value definition
2250 result = strtok(NULL, delims);//value
2251 if (( result[0]=='"' ) && ( result[ strlen(result)-1 ]!='"' ) )
2253 std::string tmpString=" ";
2254 tmpString[0]=34; // character "
2255 strcat(result,tmpString.c_str());
2257 std::string value(result);
2259 bbmod->setValueToInput(name, value);
2261 getCleanLine(inputStream, line);//PORT o FIN_BOX
2262 port = line.substr(0, 4);
2265 //EED bbmod->notifyObservers(_idManager);
2270 getCleanLine(inputStream, line);//CONNECTIONS:num
2272 strcpy(conns, line.c_str());
2273 result = strtok(conns, delims);
2274 result = strtok(NULL, delims);
2277 std::istringstream isCons(result);
2281 for (int i = 0; i < numConns; i++) {
2283 getCleanLine(inputStream, line);//CONNECTION
2284 getCleanLine(inputStream, line);//Startbox.PortName:EndBox.PortName
2287 strcpy(connec, line.c_str());
2288 result = strtok(connec, delims);
2289 std::string nameStartBox(result);
2290 result = strtok(NULL, delims);
2291 std::string nameStartPort(result);
2292 result = strtok(NULL, delims);
2293 std::string nameEndBox(result);
2294 result = strtok(NULL, delims);
2295 std::string nameEndPort(result);
2298 int idCon = configGConnetion(nameStartBox, nameStartPort,nameEndBox, nameEndPort);
2300 if (version != "1.0") {
2301 //Readding control points of the manualContour
2302 GConnectorController *tempp = (GConnectorController*) _controllers[idCon];
2303 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2304 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2305 getCleanLine(inputStream, line); //NumberOfControlPoints:##
2306 strcpy(conns, line.c_str());
2307 result = strtok(conns, delims);
2308 result = strtok(NULL, delims);
2310 int numberOfControlPoints;
2311 std::istringstream isCons(result);
2312 isCons >> numberOfControlPoints;
2314 for (int ii = 0; ii < numberOfControlPoints; ii++) {
2315 getCleanLine(inputStream, line); //XX:YY:ZZ
2317 strcpy(connec, line.c_str());
2320 result = strtok(connec, delims);
2321 std::istringstream isPointX(result);
2323 result = strtok(NULL, delims);
2324 std::istringstream isPointY(result);
2326 result = strtok(NULL, delims);
2327 std::istringstream isPointZ(result);
2332 if (pz==900) pz=GPOSITION_Z;
2335 conMod->getManualContourModel()->InsertPoint_id(ii + 1, px, py, pz);
2336 conView->getManualContourView()->AddPoint();
2342 //=========================================================================
2345 //=========================================================================
2346 void wxVtkSceneManager::configGComBoxInputOutputPort(bool inputoutput,
2347 std::string portName, double xIn, double yIn, double zIn)
2350 if (inputoutput == true) {
2351 idPort = createGComplexBoxInputPort(portName);
2353 idPort = createGComplexBoxOutputPort(portName);
2355 GObjectController *cont = _controllers[idPort];
2356 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2357 cbmod->setInicPoint(xIn, yIn, zIn);
2358 cbmod->notifyObservers(_idManager);
2360 //=========================================================================
2363 //=========================================================================
2364 GBoxModel* wxVtkSceneManager::findGBox(std::string boxname)
2369 GBoxModel *boxModel = NULL;
2370 std::vector<int> lstB = getBlackBoxes();
2371 for (j = 0; j < (int) lstB.size(); j++) {
2373 bMod = (GBoxModel*) _controllers[idB]->getModel();
2374 if (_controllers[idB]->getModel()->getBBTKName() == boxname)
2382 if (boxModel == NULL) {
2383 std::vector<int> lstInputs = getComplexInputPorts();
2384 for (j = 0; j < (int) lstInputs.size(); j++) {
2386 bMod = (GBoxModel*) _controllers[idB]->getModel();
2387 if (_controllers[idB]->getModel()->getBBTKName() == boxname)
2395 std::vector<int> lstOutputs = getComplexOutputPorts();
2396 for (j = 0; j < (int) lstOutputs.size(); j++) {
2397 int idB = lstOutputs[j];
2398 bMod = (GBoxModel*) _controllers[idB]->getModel();
2399 if (_controllers[idB]->getModel()->getBBTKName() == boxname)
2411 //=========================================================================
2414 int wxVtkSceneManager::configGConnetion(std::string nameStartBox,
2415 std::string nameStartPort, std::string nameEndBox,
2416 std::string nameEndPort) {
2418 GBoxModel *boxModel;
2419 GPortModel *startP = NULL;
2420 GPortModel *endP = NULL;
2422 boxModel = findGBox(nameStartBox);
2423 if(boxModel == NULL)
2425 printf("RaC: ERROR in wxVtkSceneManager::configGConnetion A box to connect start port %s is null. Box name is probably wrong.\n", nameStartPort.c_str());
2427 if (boxModel != NULL) {
2428 startP = boxModel->getOutputPort(nameStartPort);
2430 printf("SCP: ERROR in wxVtkSceneManager::configGConnetion start port is null. Port name is probably wrong. Start>%s::%s End>%s::%s\n", nameStartBox.c_str(), nameStartPort.c_str(), nameEndBox.c_str(), nameEndPort.c_str() );
2434 boxModel = findGBox(nameEndBox);
2435 if(boxModel == NULL)
2437 printf("RaC: ERROR in wxVtkSceneManager::configGConnetion A box to connect start port %s is null. Box name is probably wrong.\n", nameStartPort.c_str());
2439 if (boxModel != NULL) {
2440 endP = boxModel->getInputPort(nameEndPort);
2442 printf("SCP: ERROR in wxVtkSceneManager::configGConnetion end port is null. Port name is probably wrong. Start>%s::%s End>%s::%s \n", nameStartBox.c_str(), nameStartPort.c_str(), nameEndBox.c_str(), nameEndPort.c_str());
2447 int idCon = createGConnector(startP);
2449 _worldState = NOTHING_HAPPENS;
2450 GConnectorController *tempp = (GConnectorController*) _controllers[idCon];
2452 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2453 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2454 tempp->endContourCreation();
2455 conMod->setEndPort(endP);
2456 conView->updateStartEndPoints();
2460 //=========================================================================
2462 bool wxVtkSceneManager::boxExist(std::string boxname) {
2464 std::map<int, GObjectController*>::iterator it;
2465 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2466 GObjectController *cont = it->second;
2467 if (cont->getModel()->getBBTKName() == boxname) {
2474 //=========================================================================
2476 std::vector<int> wxVtkSceneManager::getBlackBoxes() {
2477 std::vector<int> vect;
2478 std::map<int, GObjectController*>::iterator it;
2479 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2480 GObjectController *cont = it->second;
2481 if (cont->getGObjectType() == GBLACKBOX) {
2482 vect.push_back(cont->getId());
2488 //=========================================================================
2490 std::vector<int> wxVtkSceneManager::getComplexInputPorts() {
2491 std::vector<int> vect;
2492 std::map<int, GObjectController*>::iterator it;
2493 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2494 GObjectController *cont = it->second;
2495 if (cont->getGObjectType() == GCOMPLEXINPUTPORT) {
2496 vect.push_back(cont->getId());
2502 //=========================================================================
2504 std::vector<int> wxVtkSceneManager::getComplexOutputPorts() {
2505 std::vector<int> vect;
2506 std::map<int, GObjectController*>::iterator it;
2507 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2508 GObjectController *cont = it->second;
2509 if (cont->getGObjectType() == GCOMPLEXOUTPUTPORT) {
2510 vect.push_back(cont->getId());
2516 //=========================================================================
2518 std::vector<int> wxVtkSceneManager::getConnections() {
2519 std::vector<int> vect;
2520 std::map<int, GObjectController*>::iterator it;
2521 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2522 GObjectController *cont = it->second;
2523 if (cont->getGObjectType() == GCONNECTOR) {
2524 vect.push_back(cont->getId());
2530 //=========================================================================
2532 bool wxVtkSceneManager::isComplexBox() {
2533 return _isComplexBox;
2536 //=========================================================================
2538 void wxVtkSceneManager::setComplexBox(bool val) {
2539 _isComplexBox = val;
2542 //=========================================================================
2544 int wxVtkSceneManager::addObjectController(GObjectController* objController) {
2545 //Register the controller of the new object
2546 registerController((InteractorStyleMaracas*) objController);
2547 //Add the object to the objects list
2548 int newId = _contLastId;//_controllers.size();
2549 objController->setId(newId);
2550 _controllers[newId] = objController;
2551 //std::cout << "DFCH: int wxVtkSceneManager::addObjectController(GObjectController* objController) ---- _contLastId = " << _contLastId << std::endl;
2556 //=========================================================================
2558 void wxVtkSceneManager::DuplicateObjects(std::map<int, GObjectController*> objectsMap) {
2560 std::map<int, int> oldIdNewIdBoxes;
2561 std::vector<int> connections;
2563 std::vector<int> newBoxesID;
2565 std::map<int, GObjectController*>::iterator it;
2566 for (it = objectsMap.begin(); it != objectsMap.end(); ++it) {
2567 GObjectController *cont = it->second;
2568 int type = cont->getGObjectType();
2570 if (type == GBLACKBOX) {
2572 double xInic, yInic, zInic;
2573 GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
2574 copyBox->getInicPoint(xInic, yInic, zInic);
2575 int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(),
2576 copyBox->getBBTKType());
2578 int idcB = copyBox->getObjectId();
2579 oldIdNewIdBoxes[idcB] = idBox;
2580 cont = _controllers[idBox];
2581 GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
2582 newbox->setInicPoint(xInic, yInic, zInic);
2583 int num = newbox->getNumInputPorts();
2584 for (int j = 0; j < num; j++) {
2585 newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
2587 newbox->move(xInic + 20, yInic + 20, zInic);
2588 newbox->notifyObservers(_idManager);
2589 newBoxesID.push_back(newbox->getObjectId());
2591 } else if (type == GCONNECTOR) {
2592 int idCon = cont->getId();
2593 connections.push_back(idCon);
2598 for (int i = 0; i < (int) connections.size(); i++) {
2599 int objId = connections[i];
2600 GObjectController *cont = objectsMap[objId];
2601 GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
2603 GPortModel* startPort = connectModel->getStartPort();
2604 int startPortIndex = startPort->getPosInBox();
2605 GPortModel* endPort = connectModel->getEndPort();
2606 int endPortIndex = endPort->getPosInBox();
2608 GBlackBoxModel* startPortParentBox =
2609 (GBlackBoxModel*) startPort->getParentBox();
2610 GBlackBoxModel* endPortParentBox =
2611 (GBlackBoxModel*) endPort->getParentBox();
2613 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2614 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2616 GBlackBoxModel* newStartBox =
2617 (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
2618 GBlackBoxModel* newEndBox =
2619 (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
2621 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2622 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2624 // Creates connection
2625 int idCon = createGConnector(newStartPort);
2626 GConnectorController *tempp =
2627 (GConnectorController*) _controllers[idCon];
2628 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2629 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2630 tempp->endContourCreation();
2631 conMod->setEndPort(newEndPort);
2632 conView->updateStartEndPoints();
2635 /// the new selected boxes are the duplicate ones
2637 UnSelectBlackBoxes();
2638 for (int i = 0; i < newBoxesID.size(); i++) {
2639 _selectedObjects.push_back(newBoxesID.at(i));
2642 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
2643 int id = _selectedObjects[i];
2644 GObjectController* cont = _controllers[id];
2646 cont->getView()->setState(SELECTED);
2647 cont->getModel()->notifyObservers(_idManager);
2653 //=========================================================================
2655 int wxVtkSceneManager::getNumSelectedObjects() {
2656 return _selectedObjects.size();
2659 //=========================================================================
2661 std::map<int, GObjectController*> wxVtkSceneManager::getSelectedObjects() {
2662 std::map<int, GObjectController*> mapSelected;
2664 std::map<int, GObjectController*>::iterator it;
2665 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2666 GObjectController *cont = it->second;
2667 if (cont->getGObjectType() == GBLACKBOX && cont->getView()->getState()
2669 mapSelected[cont->getId()] = cont;
2673 std::map<int, GObjectController*>::iterator it2;
2674 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2) {
2675 GObjectController *cont = it2->second;
2676 if (cont->getGObjectType() == GCONNECTOR) {
2677 GConnectorModel* cmod = (GConnectorModel*) cont->getModel();
2678 GBoxModel* endPortParentBox = cmod->getEndPort()->getParentBox();
2679 GBoxModel* startPortParentBox =
2680 cmod->getStartPort()->getParentBox();
2682 std::map<int, GObjectController*>::iterator iterOBJ1 =
2683 mapSelected.find(startPortParentBox->getObjectId());
2684 std::map<int, GObjectController*>::iterator iterOBJ2 =
2685 mapSelected.find(endPortParentBox->getObjectId());
2687 if (iterOBJ1 != mapSelected.end() && iterOBJ2 != mapSelected.end()) {
2688 int ID = cont->getId();
2689 mapSelected[ID] = cont;
2696 //=========================================================================
2698 void wxVtkSceneManager::addObjects(std::map<int, GObjectController*> objectsMap) {
2700 std::map<int, int> oldIdNewIdBoxes;
2701 std::vector<int> connections;
2703 std::map<int, GObjectController*>::iterator it;
2704 for (it = objectsMap.begin(); it != objectsMap.end(); ++it) {
2705 GObjectController *cont = it->second;
2706 int type = cont->getGObjectType();
2708 if (type == GBLACKBOX) {
2710 double xInic, yInic, zInic;
2711 GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
2712 copyBox->getInicPoint(xInic, yInic, zInic);
2713 int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(),copyBox->getBBTKType());
2715 int idcB = copyBox->getObjectId();
2716 oldIdNewIdBoxes[idcB] = idBox;
2717 cont = _controllers[idBox];
2718 GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
2719 newbox->setInicPoint(xInic, yInic, zInic);
2720 int num = newbox->getNumInputPorts();
2721 for (int j = 0; j < num; j++)
2723 newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
2725 newbox->notifyObservers(_idManager);
2726 } else if (type == GCONNECTOR) {
2727 int idCon = cont->getId();
2728 connections.push_back(idCon);
2733 for (int i = 0; i < (int) connections.size(); i++) {
2734 int objId = connections[i];
2735 GObjectController *cont = objectsMap[objId];
2736 GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
2738 GPortModel* startPort = connectModel->getStartPort();
2739 int startPortIndex = startPort->getPosInBox();
2740 GPortModel* endPort = connectModel->getEndPort();
2741 int endPortIndex = endPort->getPosInBox();
2743 GBlackBoxModel* startPortParentBox =
2744 (GBlackBoxModel*) startPort->getParentBox();
2745 GBlackBoxModel* endPortParentBox =
2746 (GBlackBoxModel*) endPort->getParentBox();
2748 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2749 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2751 GBlackBoxModel* newStartBox =
2752 (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
2753 GBlackBoxModel* newEndBox =
2754 (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
2756 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2757 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2759 // Creates connection
2760 int idCon = createGConnector(newStartPort);
2761 GConnectorController *tempp =
2762 (GConnectorController*) _controllers[idCon];
2763 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2764 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2765 tempp->endContourCreation();
2766 conMod->setEndPort(newEndPort);
2767 conView->updateStartEndPoints();
2770 std::map<int, int>::iterator itIds;
2771 for (itIds = oldIdNewIdBoxes.begin(); itIds != oldIdNewIdBoxes.end(); ++itIds) {
2772 int idOld = itIds->first;
2773 int idNew = itIds->second;
2775 GBlackBoxModel* oldBox =
2776 (GBlackBoxModel*) objectsMap[idOld]->getModel();
2777 GBlackBoxModel* newBox =
2778 (GBlackBoxModel*) _controllers[idNew]->getModel();
2780 std::vector<int> oldInputConnections = oldBox->getConnectedInputs();
2781 std::vector<int> oldOutputConnections = oldBox->getConnectedOutputs();
2782 std::vector<int> newInputConnections = newBox->getConnectedInputs();
2783 std::vector<int> newOutputConnections = newBox->getConnectedOutputs();
2785 for (int k = 0; k < (int) oldInputConnections.size(); k++) {
2787 //EED int toCreate=-1;
2788 for (int l = 0; l < (int) newInputConnections.size() && !exist; l++) {
2789 if (oldInputConnections[k] == newInputConnections[l]) {
2794 if (exist == false) {
2795 //Create complex input
2796 int posInBox = oldInputConnections[k];
2797 GPortModel* inputPort = oldBox->getInputPort(posInBox);
2798 std::string inputPortName = inputPort->getBBTKName();
2799 int idInputPort = createGComplexBoxInputPort(inputPortName);
2800 GObjectController *cont = _controllers[idInputPort];
2801 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2802 double xIn, yIn, zIn;
2803 inputPort->getInicPoint(xIn, yIn, zIn);
2805 cbmod->setInicPoint(xIn, yIn, zIn);
2806 cbmod->notifyObservers(_idManager);
2808 GPortModel* inputPortEnd = newBox->getInputPort(posInBox);
2810 // Creates connection
2811 int idCon = createGConnector(cbmod->getOutputPort(0));
2812 GConnectorController *tempp =
2813 (GConnectorController*) _controllers[idCon];
2814 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2815 vtkGConnectorView *conView =
2816 (vtkGConnectorView*) tempp->getView();
2817 tempp->endContourCreation();
2818 conMod->setEndPort(inputPortEnd);
2819 conView->updateStartEndPoints();
2825 for (int k = 0; k < (int) oldOutputConnections.size(); k++) {
2827 //EED int toCreate=-1;
2828 for (int l = 0; l < (int) newOutputConnections.size() && !exist; l++) {
2829 if (oldOutputConnections[k] == newOutputConnections[l]) {
2834 if (exist == false) {
2835 //Create complex output
2836 int posInBox = oldOutputConnections[k];
2837 GPortModel* outputPort = oldBox->getOutputPort(posInBox);
2838 std::string outputPortName = outputPort->getBBTKName();
2839 int idOutputPort = createGComplexBoxOutputPort(outputPortName);
2840 GObjectController *cont = _controllers[idOutputPort];
2841 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2842 double xIn, yIn, zIn;
2843 outputPort->getInicPoint(xIn, yIn, zIn);
2845 cbmod->setInicPoint(xIn, yIn, zIn);
2846 cbmod->notifyObservers(_idManager);
2848 GPortModel* outputPortEnd = newBox->getOutputPort(posInBox);
2850 // Creates connection
2851 int idCon = createGConnector(outputPortEnd);
2852 GConnectorController *tempp =
2853 (GConnectorController*) _controllers[idCon];
2854 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2855 vtkGConnectorView *conView =
2856 (vtkGConnectorView*) tempp->getView();
2857 tempp->endContourCreation();
2858 conMod->setEndPort(cbmod->getInputPort(0));
2859 conView->updateStartEndPoints();
2869 //=========================================================================
2870 void wxVtkSceneManager::SetCbName(std::string cbName) {
2872 if (_cbName == "") {
2873 _cbName = "<complex box name>";
2877 //=========================================================================
2878 std::string wxVtkSceneManager::GetCbName() {
2882 //=========================================================================
2883 void wxVtkSceneManager::SetCbPackageName(std::string packagename) {
2884 _cbPackageName = packagename;
2885 if (_cbPackageName == "") {
2886 _cbPackageName = "<package name of the complex box>";
2890 //=========================================================================
2891 std::string wxVtkSceneManager::GetCbPackageName() {
2892 return _cbPackageName;
2895 //=========================================================================
2896 void wxVtkSceneManager::SetAuthor(std::string author) {
2898 if (_Author == "") {
2899 _Author = "<author of the box>";
2903 //=========================================================================
2904 std::string wxVtkSceneManager::GetAuthor() {
2908 //=========================================================================
2909 void wxVtkSceneManager::SetCategory(std::string category) {
2910 _Category = category;
2911 if (_Category == "") {
2912 _Category = "<category of the box>";
2916 //=========================================================================
2917 std::string wxVtkSceneManager::GetCategory() {
2921 //=========================================================================
2922 void wxVtkSceneManager::SetDescription(std::string description) {
2923 _Description = description;
2924 if (_Description == "") {
2925 _Description = "<description of the box>";
2929 //=========================================================================
2930 std::string wxVtkSceneManager::GetDescription() {
2931 return _Description;
2934 //=========================================================================
2936 std::vector< std::string> wxVtkSceneManager::GetExternalInputsNames()
2939 std::vector< std::string> extInputs;
2940 std::map<int, GObjectController*>::iterator it;
2941 for (it = _controllers.begin(); it != _controllers.end(); ++it)
2943 GObjectController *cont = it->second;
2944 if (cont->getGObjectType() == GCOMPLEXINPUTPORT)
2946 extInputs.push_back(cont->getModel()->getBBTKName());
2952 //=========================================================================
2956 void wxVtkSceneManager::printAll(int com , int sta ){
2958 int tmpState = sta ;
2959 if ( tmpState == NOTHING_HAPPENS ) {
2960 std::cout << "CONTROLER STATE---->NOTHING_HAPPENS\n" ;
2962 if ( tmpState == HIGHLIGHTED ) {
2963 std::cout << "CONTROLER STATE---->HIGHLIGHTED\n" ;
2965 if ( tmpState == POSSIBLE_CONNECTION ) {
2966 std::cout << "CONTROLER STATE---->POSSIBLE_CONNECTION\n" ;
2968 if ( tmpState == SELECTED_POSSIBLE_CONNECTION ) {
2969 std::cout << "CONTROLER STATE---->SELECTED_POSSIBLE_CONNECTION\n" ;
2971 if ( tmpState == CLICKED ) {
2972 std::cout << "CONTROLER STATE---->CLICKED\n" ;
2974 if ( tmpState == DRAG ) {
2975 std::cout << "CONTROLER STATE---->DRAG\n" ;
2977 if ( tmpState == SELECTED ) {
2978 std::cout << "CONTROLER STATE---->SELECTED\n" ;
2980 if ( tmpState == CREATING_CONTOUR ) {
2981 std::cout << "CONTROLER STATE---->CREATING_CONTOUR\n" ;
2987 if ( command == INIT_CREATION_CONTOUR ) {
2988 std::cout << "COMMAND ----> INIT_CREATION_CONTOUR \n" ;
2990 if ( command == FIN_CREATION_CONTOUR ) {
2991 std::cout << "COMMAND ----> FIN_CREATION_CONTOUR \n" ;
2993 if ( command == ADD_TO_SELECTED ) {
2994 std::cout << "COMMAND ----> ADD_TO_SELECTED \n" ;
2996 if ( command == DRAG_OBJECTS ) {
2997 std::cout << "COMMAND ----> DRAG_OBJECTS \n" ;
2999 if ( command == EDIT_BLACKBOX ) {
3000 std::cout << "COMMAND ----> EDIT_BLACKBOX \n" ;
3002 if ( command == REMOVE_FROM_SELECTED ) {
3003 std::cout << "COMMAND ----> REMOVE_FROM_SELECTED \n" ;
3009 } // EO namespace bbtk