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)
75 wxVtkSceneManager::wxVtkSceneManager(wxGEditorTabPanel *parent, wxVtk3DBaseView *baseView, int idManager,Factory::Pointer bbtkfactory)
79 _cbName = "ComplexBoxName";
80 _cbPackageName = "PackageName";
81 _Author = "Author ??";
83 _Description = "Description ??";
87 _bugTextActor_text = "void";
88 _bugTextActor_status = 0;
92 _idManager = idManager;
94 _bbtkfactory = bbtkfactory;
96 _startDragging = false;
97 _isComplexBox = false;
99 if (_baseView != NULL) {
102 "RaC-EED 21-06-2010 %p wxVtkSceneManager::wxVtkSceneManager If you comment this line, the drag and drop functionnality is not initialized.\n",
105 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget((wxDropTarget*)parent);
109 _worldState = NOTHING_HAPPENS;
110 registerController(this);
113 _idConnectionInCreation = -1;
118 //=========================================================================
120 void wxVtkSceneManager::disconnectDrop()
122 //EED02JUIN2010 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget(NULL);
123 // _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget( new tmpClasswxTextDropTarget() );
126 //=========================================================================
128 wxVtkSceneManager::~wxVtkSceneManager()
135 //=========================================================================
137 void wxVtkSceneManager::configureBaseView()
139 vtkInteractorStyleBaseView2D *interactorstylebaseview = vtkInteractorStyleBaseView2D::New();
140 _baseView->SetInteractorStyleBaseView(interactorstylebaseview);
141 // Important to activate the 2D interaction system
142 crea::wxVTKRenderWindowInteractor *iren = _baseView->GetWxVTKRenderWindowInteractor();
143 interactorstylebaseview->SetInteractor(iren);
144 iren->SetInteractorStyle(interactorstylebaseview);
145 interactorstylebaseview->SetwxVtkBaseView(_baseView);
146 _baseView->GetRenderer()->GetActiveCamera()->ParallelProjectionOn();
147 _baseView->GetRenderer()->ResetCamera(-100, 100, -100, 100, -1000, 1000);
148 _baseView->GetRenderer()->GetActiveCamera()->Zoom(20);
149 _baseView->GetRenderer()->SetBackground(0.9, 0.9, 0.9);
150 _baseView->GetRenderer()->GradientBackgroundOn();
152 _textActor = vtkTextActor3D::New();
153 // _textActor = vtkTextActor::New();
154 _textActor->SetPosition(-9999, -9999, GPOSITION_Z);
155 _textActor->SetInput("<void>");
157 // _textActor->GetTextProperty()->SetFontSize(60);
158 _textActor->GetTextProperty()->SetFontSize(40);
159 _textActor->GetTextProperty()->BoldOn();
160 _textActor->GetTextProperty()->SetFontFamilyToArial();
161 _textActor->GetTextProperty()->ShadowOff();
162 _textActor->GetTextProperty()->SetColor(PORTTEXT_NH_R, PORTTEXT_NH_G,PORTTEXT_NH_B);
163 _baseView->GetRenderer()->AddActor(_textActor);
164 // Actor Fill_Port_Text
168 double zInic = GPOSITION_Z;
169 vtkPolygon *aPolygon = vtkPolygon::New();
170 _fillObjectActor = vtkActor::New();
171 _pts = vtkPoints::New();
174 double w = 100, h = 10, b = h / 15, t = 3;
175 _pts->SetNumberOfPoints(21);
176 _pts->InsertPoint(0, xInic + w * 0.33 - t / 2, yInic, zInic);
177 _pts->InsertPoint(1, xInic + w * 0.33, yInic - t, zInic);
178 _pts->InsertPoint(2, xInic + w * 0.33 + t / 2, yInic, zInic);
179 _pts->InsertPoint(3, xInic + w * 0.33 + t / 2, yInic, zInic);
180 _pts->InsertPoint(4, xInic + w - b * 4, yInic + b * 0, zInic);
182 _pts->InsertPoint(5, xInic + w - b * 4, yInic + b * 0, zInic);
183 _pts->InsertPoint(6, xInic + w - b * 2, yInic + b * 1, zInic);
184 _pts->InsertPoint(7, xInic + w - b * 1, yInic + b * 2, zInic);
185 _pts->InsertPoint(8, xInic + w - b * 0, yInic + b * 4, zInic);
187 _pts->InsertPoint(9, xInic + w - b * 0, yInic + h - b * 4, zInic);
188 _pts->InsertPoint(10, xInic + w - b * 1, yInic + h - b * 2, zInic);
189 _pts->InsertPoint(11, xInic + w - b * 2, yInic + h - b * 1, zInic);
190 _pts->InsertPoint(12, xInic + w - b * 4, yInic + h - b * 0, zInic);
192 _pts->InsertPoint(13, xInic + b * 4, yInic + h - b * 0, zInic);
193 _pts->InsertPoint(14, xInic + b * 2, yInic + h - b * 1, zInic);
194 _pts->InsertPoint(15, xInic + b * 1, yInic + h - b * 2, zInic);
195 _pts->InsertPoint(16, xInic + b * 0, yInic + h - b * 4, zInic);
197 _pts->InsertPoint(17, xInic + b * 0, yInic + b * 4, zInic);
198 _pts->InsertPoint(18, xInic + b * 1, yInic + b * 2, zInic);
199 _pts->InsertPoint(19, xInic + b * 2, yInic + b * 1, zInic);
200 _pts->InsertPoint(20, xInic + b * 4, yInic + b * 0, zInic);
201 aPolygon->GetPointIds()->SetNumberOfIds(21);
202 for (int i = 0; i < 21; i++) {
204 aPolygon->GetPointIds()->SetId(i, i);
208 double w = BOX_WIDTH, h = BOX_HEIGHT, t = PORT_HEIGHT;
209 _pts->SetNumberOfPoints(7);
210 _pts->InsertPoint(0, xInic + t/2.0 , yInic + t , zInic );
211 _pts->InsertPoint(1, xInic + w , yInic + t , zInic );
212 _pts->InsertPoint(2, xInic + w , yInic + t + h , zInic );
213 _pts->InsertPoint(3, xInic - t*1.5 , yInic + t + h , zInic );
214 _pts->InsertPoint(4, xInic - t*1.5 , yInic + t , zInic );
215 _pts->InsertPoint(5, xInic - t/2 , yInic + t , zInic );
216 _pts->InsertPoint(6, xInic , yInic , zInic );
217 aPolygon->GetPointIds()->SetNumberOfIds(8);
218 for (int i = 0; i < 8; i++)
220 aPolygon->GetPointIds()->SetId(i, i);
221 if (i==7) aPolygon->GetPointIds()->SetId(i, 0);
223 vtkUnstructuredGrid *aPolygonGrid = vtkUnstructuredGrid::New();
224 aPolygonGrid->Allocate(1, 1);
225 aPolygonGrid->InsertNextCell(aPolygon->GetCellType(),aPolygon->GetPointIds());
226 aPolygonGrid->SetPoints(_pts);
227 _aPolygonMapper = vtkDataSetMapper::New();
228 //EED 2017-01-01 Migration VTK7
229 #if VTK_MAJOR_VERSION <= 5
230 _aPolygonMapper->SetInput(aPolygonGrid);
232 _aPolygonMapper->SetInputData(aPolygonGrid);
234 _fillObjectActor->SetMapper(_aPolygonMapper);
235 _fillObjectActor->GetProperty()->SetColor(PORTFILL_NH_R, PORTFILL_NH_G,PORTFILL_NH_B);
236 _fillObjectActor->GetProperty()->SetOpacity(0);
237 _aPolygonMapper->Modified();
238 _baseView->GetRenderer()->AddActor(_fillObjectActor);
241 //=========================================================================
243 std::string wxVtkSceneManager::generateANewNameForABox() {
244 std::stringstream boxname;
245 if (_numBoxes < 10) {
246 boxname << "Box0" << _numBoxes;
248 boxname << "Box" << _numBoxes;
251 return boxname.str();
254 //=========================================================================
256 std::string wxVtkSceneManager::findANewNameForABox() {
257 std::string boxname = generateANewNameForABox();
259 while (boxExist(boxname) == true) {
260 boxname = generateANewNameForABox();
266 //=========================================================================
267 void wxVtkSceneManager::configGBlackBox(int idBox, double xIn, double yIn,
268 double zIn, std::string name, bool boxExecutable, double xEn,
269 double yEn, double zEn) {
270 GObjectController *cont = _controllers[idBox];
271 GBlackBoxModel *bbmod = (GBlackBoxModel*) cont->getModel();
272 bbmod->setBBTKName(name);
273 bbmod->setInicPoint(xIn, yIn, zIn);
274 bbmod->setFinalPoint(xEn, yEn, zEn);
275 bbmod->setExecutable(boxExecutable);
277 bbmod->notifyObservers(_idManager);
281 //=========================================================================
283 int wxVtkSceneManager::createGBlackBox(int x, int y, std::string packageName,std::string boxType)
285 _worldState = NOTHING_HAPPENS;
286 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
287 int type = GBLACKBOX;
288 //Create the MVC Objects
289 GBlackBoxModel *model = (GBlackBoxModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(type);
290 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
291 GObjectController *controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
293 //EED 15 oct 2012 BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxType);
297 std::map< std::string, BlackBoxDescriptor::Pointer> mapDesc;
299 k = _bbtkfactory->GetPackage(packageName);
300 mapDesc = k->GetDescriptorMap();
302 printf("EED. ERROR!: Exception in wxVtkSceneManager::createGBlackBox for package %s, NOT EXIST\n", packageName.c_str());
305 BlackBoxDescriptor::Pointer descriptor;
307 descriptor = mapDesc[boxType];
309 printf("EED. ERROR!: Exception in wxVtkSceneManager::createGBlackBox for box %s of package %s, NOT EXIST\n", boxType.c_str(),packageName.c_str());
312 if (descriptor == NULL)
314 printf("SCP: ERROR in wxVtkSceneManager::createGBlackBox, box %s probably does not exist.\n", boxType.c_str());
317 //Prepares the initial model
318 //The coordinates obtained are the following. Top-Left:x=0,y=0 Bottom-Right:x=width,y=height
321 double yy = windowHeight - y;
323 //z value is not important yet, because it is only used a parallel projection
324 double zz = GPOSITION_Z;
325 _baseView->TransCoordScreenToWorld(xx, yy, zz);
326 model->setInicPoint(xx, yy, zz);
328 std::stringstream stream;
330 std::string newBoxName;
331 newBoxName = findANewNameForABox();
333 stream << newBoxName;
335 std::string arraystring = stream.str();
337 model->setBBTKName(arraystring);
338 model->setBBTKType(boxType);
339 model->setBBTKPackage(packageName);
341 model->addObserver(view);
342 model->addObserver(this);
345 //EED2017 change order
346 //Associates the view with the correspondent renderer and the model.
347 //(NOTE: Refresh is only made by the view)
348 view->setModel(model);
349 view->setBaseView(_baseView);
351 //Associates the controller with the correspondent model and view
352 controller->setModelAndView(model, view);
355 //Iterate and create the input ports
356 std::map<std::string, BlackBoxInputDescriptor*> descriptorInMap =
357 descriptor->GetInputDescriptorMap();
358 std::map<std::string, BlackBoxInputDescriptor*>::iterator itInput;
360 for (itInput = descriptorInMap.begin(); itInput != descriptorInMap.end(); ++itInput)
362 BlackBoxInputDescriptor *desc = itInput->second;
364 // createGInputPort(GINPUTPORT, i, model, desc);
365 createGInputPort(GINPUTPORT, i, controller, desc);
369 //Iterate and create the output ports
370 std::map<std::string, BlackBoxOutputDescriptor*> descriptorOutMap =
371 descriptor->GetOutputDescriptorMap();
372 std::map<std::string, BlackBoxOutputDescriptor*>::iterator itOutput;
374 for (itOutput = descriptorOutMap.begin(); itOutput!= descriptorOutMap.end(); ++itOutput)
376 BlackBoxOutputDescriptor *desc = itOutput->second;
378 // createGOutputPort(GOUTPUTPORT, i, model, desc);
379 createGOutputPort(GOUTPUTPORT, i, controller, desc);
383 //EED2017 change order
384 view->initVtkObjects();
386 //Resgiter change to the observers of the actual model
387 model->notifyObservers(_idManager);
388 int newId = addObjectController(controller);
394 //=========================================================================
396 int wxVtkSceneManager::createGComplexBoxInputPort(std::string inputName) {
397 //EED int windowWidth=_baseView->GetRenWin()->GetSize()[0];
398 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
400 int type = GCOMPLEXINPUTPORT;
402 //Create the MVC Objects
404 GComplexBoxPortModel *model = (GComplexBoxPortModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(type);
405 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
406 GObjectController *controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
408 //Prepares the initial model
411 double yy = windowHeight - 5;
413 //z value is not important yet, because it is only used a parallel projection
414 double zz = GPOSITION_Z;
416 _baseView->TransCoordScreenToWorld(xx, yy, zz);
417 model->setInicPoint(xx, yy, zz);
419 model->setBBTKName(inputName);
420 model->setBBTKType("ComplexInputPort");
421 model->setComplexPortType(type);
423 model->addObserver(view);
424 model->addObserver(this);
426 //create the output port
427 GPortController* portController = createGPort(GOUTPUTPORT, inputName,
428 "ComplexOutputPortType","ComplexOutputPortDescriopton", 0, model);
429 model->addOutputPort((GPortModel*) portController->getModel());
431 //Associates the view with the correspondent renderer and the model.
432 //(NOTE: Refresh is only made by the view)
433 view->setModel(model);
434 view->setBaseView(_baseView);
435 view->initVtkObjects();
437 //Associates the controller with the correspondent model and view
438 controller->setModelAndView(model, view);
440 //Resgiter change to the observers of the actual model
441 model->notifyObservers(_idManager);
443 int newId = addObjectController(controller);
447 //=========================================================================
449 int wxVtkSceneManager::createGComplexBoxOutputPort(std::string outputName) {
450 //EED int windowWidth=_baseView->GetRenWin()->GetSize()[0];
451 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
453 int type = GCOMPLEXOUTPUTPORT;
455 //Create the MVC Objects
457 GComplexBoxPortModel *model = (GComplexBoxPortModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(type);
458 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
459 GObjectController *controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
461 //Prepares the initial model
464 double yy = windowHeight - 5;
466 //z value is not important yet, because it is only used a parallel projection
467 double zz = GPOSITION_Z;
469 _baseView->TransCoordScreenToWorld(xx, yy, zz);
470 model->setInicPoint(xx, yy, zz);
472 model->setBBTKName(outputName);
473 model->setBBTKType("ComplexOutputPort");
474 model->setComplexPortType(type);
476 model->addObserver(view);
477 model->addObserver(this);
479 //create the output port
480 GPortController* portController = createGPort(GINPUTPORT, outputName,
481 "ComplexInputPort","ComplexInputPortDescription", 0, model);
482 model->addInputPort((GPortModel*) portController->getModel());
484 //Associates the view with the correspondent renderer and the model.
485 //(NOTE: Refresh is only made by the view)
486 view->setModel(model);
487 view->setBaseView(_baseView);
488 view->initVtkObjects();
490 //Associates the controller with the correspondent model and view
491 controller->setModelAndView(model, view);
493 //Resgiter change to the observers of the actual model
494 model->notifyObservers(_idManager);
496 int newId = addObjectController(controller);
500 //=========================================================================
503 //int wxVtkSceneManager::createGInputPort(int portType, int posinBox, GBoxModel *blackBox, BlackBoxInputDescriptor *desc)
504 int wxVtkSceneManager::createGInputPort(int portType, int posinBox, GObjectController *gBoxControler, BlackBoxInputDescriptor *desc)
506 GBoxModel *blackBox=(GBoxModel*)gBoxControler->getModel();
507 GPortController* portController = createGPort(portType, desc->GetName(),
508 desc->GetTypeName(), desc->GetDescription(), posinBox, blackBox);
509 blackBox->addInputPort( (GPortModel*)portController->getModel() );
511 vtkGBoxView *vtkgboxView=(vtkGBoxView*)gBoxControler->getView();
512 vtkgboxView->addInputPort( (vtkGPortView*)portController->getView() );
514 return portController->getId();
517 //=========================================================================
520 //int wxVtkSceneManager::createGOutputPort(int portType, int posinBox,GBoxModel *blackBox, BlackBoxOutputDescriptor *desc)
521 int wxVtkSceneManager::createGOutputPort(int portType, int posinBox,GObjectController *gBoxControler, BlackBoxOutputDescriptor *desc)
523 GBoxModel *blackBox=(GBoxModel*)gBoxControler->getModel();
524 GPortController* portController = createGPort(portType, desc->GetName(),
525 desc->GetTypeName(),desc->GetDescription(), posinBox, blackBox);
526 blackBox->addOutputPort((GPortModel*) portController->getModel());
528 vtkGBoxView *vtkgboxView=(vtkGBoxView*)gBoxControler->getView();
529 vtkgboxView->addOutputPort( (vtkGPortView*)portController->getView() );
531 return portController->getId();
534 //=========================================================================
536 GPortController* wxVtkSceneManager::createGPort(int portType,std::string bbtkName, std::string bbtkType, std::string bbtkDescription, int posInBox,GBoxModel *blackBox)
540 //Create the MVC Objects
541 GPortModel *model = (GPortModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(type);
542 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
543 GObjectController *controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
544 model->registerInBox(blackBox, portType, posInBox);
545 model->setBBTKType(bbtkType);
546 model->setBBTKName(bbtkName);
547 model->setBBTKDescription(bbtkDescription);
548 model->addObserver(view);
549 model->addObserver(this);
550 //Associates the view with the correspondent renderer and the model.
551 //(NOTE: Refresh is only made by the view)
552 view->setModel(model);
553 view->setBaseView(_baseView);
554 //EED017 view->initVtkObjects();
555 view->createVtkObjects();
556 // view->addVtkActors();
558 //Associates the controller with the correspondent model and view
559 controller->setModelAndView(model, view);
560 model->notifyObservers(_idManager);
561 addObjectController(controller);
562 return (GPortController*) controller;
565 //=========================================================================
567 int wxVtkSceneManager::createGConnector(GPortModel* startPort)
569 int type = GCONNECTOR;
571 manualConnectorContourController *manContourControl = new manualConnectorContourController();
572 manualConnectorContourView *manContourView = new manualConnectorContourView();
573 manualContourModel *manContourModel = new manualContourModel();
574 GConnectorController *connectorcontroller = new GConnectorController();
575 GConnectorModel *connectorModel = new GConnectorModel();
576 vtkGConnectorView *connectorView = new vtkGConnectorView();
577 connectorModel->setGObjectType(type);
579 manContourModel->SetCloseContour(false);
580 connectorModel->setStartPort(startPort);
582 manContourView->SetModel(manContourModel);
583 manContourView->SetWxVtkBaseView(_baseView);
584 manContourView->SetRange(0.5);
585 manContourView->SetZ(GPOSITION_Z);
587 manContourView->SetColorNormalContour(0, 0, 1);
588 manContourView->SetColorEditContour(0.5, 0.5, 0.5);
589 manContourView->SetColorSelectContour(1, 0.8, 0);
595 * Width increased from 2 to 3, it simplifies line handling and spline control :P
599 // manContourView->SetWidthLine( 3 ) ;
601 manContourView->SetWidthLine( 1 ) ;
603 manContourView->SetShowText(false);
605 manContourControl->SetModelView(manContourModel, manContourView);
607 manContourControl->CreateNewManualContour();
611 connectorModel->getInicPoint(x, y, z);
614 manContourControl->SetState(1);
615 manContourModel->SetCloseContour(false);
617 manContourModel->AddPoint(x, y, z);
618 manContourView->AddPoint();
620 manContourModel->AddPoint(x, y, z);
621 manContourView->AddPoint();
623 int bak = manContourControl->GetNumberOfPointsManualContour() - 1;
624 manContourControl->_bakIdPoint = bak;
626 manContourControl->SetMoving(false);
628 connectorcontroller->setModelAndView(connectorModel, connectorView);
630 int newId = addObjectController(connectorcontroller);
632 connectorcontroller->setManualContourController(manContourControl);
633 connectorModel->setManualContourModel(manContourModel);
634 connectorView->setManualContourView(manContourView);
635 connectorView->setModel(connectorModel);
636 connectorView->setBaseView(_baseView);
638 connectorModel->addObserver(connectorView);
639 connectorModel->addObserver(this);
641 // manContourView->Refresh();
646 //=========================================================================
648 void wxVtkSceneManager::registerController(InteractorStyleMaracas *param)
650 vtkInteractorStyleBaseView * baseViewControlManager = (vtkInteractorStyleBaseView*) _baseView->GetInteractorStyleBaseView();
651 baseViewControlManager->AddInteractorStyleMaracas(param);
654 //=========================================================================
656 void wxVtkSceneManager::unregisterController(InteractorStyleMaracas *param)
658 vtkInteractorStyleBaseView *baseViewControlManager = (vtkInteractorStyleBaseView*) _baseView->GetInteractorStyleBaseView();
659 baseViewControlManager->RemoveInteractorStyleMaracas(param);
662 //=========================================================================
664 vtkRenderer* wxVtkSceneManager::getRenderer()
666 return _baseView->GetRenderer();
669 //=========================================================================
671 vtkRenderWindow* wxVtkSceneManager::getRenderWindow()
673 return _baseView->GetRenWin();
675 //=========================================================================
678 //=========================================================================
679 int wxVtkSceneManager::GetIndexInSelected(int idControler)
682 for (int i = 0; i < (int) _selectedObjects.size(); i++)
684 if (_selectedObjects[i] == idControler)
692 //=========================================================================
694 void wxVtkSceneManager::update(int idController, int command) {
696 if (command != NO_COMMAND)
698 if (command == ADD_TO_SELECTED)
700 if (GetIndexInSelected(idController) == -1)
702 _selectedObjects.push_back(idController);
704 } else if (command == REMOVE_FROM_SELECTED) {
705 int index = GetIndexInSelected(idController);
708 _selectedObjects.erase(_selectedObjects.begin() + index);
710 } else if (command == INIT_CREATION_CONTOUR) {
712 typedef std::map<int , GObjectController*>::iterator TIterator ;
715 // Find current item in the controller
716 iter = _controllers.find( idController ) ;
717 iter_end = _controllers.end( ) ;
719 if ( iter != iter_end ) {
720 GObjectController* gobjc = iter->second ;
722 std::string bbtkType = gobjc->getModel( )->getBBTKType( ) ;
723 // And if the item is a port
724 if ( gobjc->getModel( )->getGObjectType( ) == GPORT ) {
725 TIterator c_it = _controllers.begin( ) ;
726 // Go through all componets
727 for ( c_it ; c_it != iter_end ; c_it++ ) {
728 GObjectController* obc = c_it->second ;
729 int obc_type = obc->getModel( )->getGObjectType( ) ;
730 std::string obc_bbtkType = obc->getModel( )->getBBTKType( ) ;
731 // if the component is a port and the type is the same of that selected
732 if ( ( obc_type == GPORT ) && ( obc_bbtkType == bbtkType ) ) {
734 obc->getView( )->setState( POSSIBLE_CONNECTION ) ;
735 //obc->getView( )->setState( HIGHLIGHTED ) ;
743 _worldState = INIT_CREATION_CONTOUR;
744 GObjectController* cont = _controllers[idController];
745 GPortModel* startOutputPort = (GPortModel*) cont->getModel();
747 // The last one is the controller of the connector
748 std::map<int, GObjectController*>::iterator it2;
750 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
752 GObjectController *cont = it2->second;
753 if (cont->getGObjectType() == GPORT)
755 GPortModel* port = (GPortModel*) cont->getModel();
756 if (port->getPortType() == GINPUTPORT)
758 cont->SetActive(true);
760 cont->getView()->setState(NOTHING_HAPPENS);
761 cont->getModel()->notifyObservers(_idManager);
762 cont->SetActive(false);
765 cont->getView()->setState(NOTHING_HAPPENS);
766 cont->getModel()->notifyObservers(_idManager);
767 cont->SetActive(false);
770 _selectedObjects.clear();
771 _idConnectionInCreation = createGConnector(startOutputPort);
772 } else if (command == FIN_CREATION_CONTOUR && _worldState == INIT_CREATION_CONTOUR) {
773 _worldState = NOTHING_HAPPENS;
774 //int id = _controllers.size()-1;
775 GObjectController *cont = _controllers[_idConnectionInCreation];
776 GConnectorModel *modelContour = (GConnectorModel*) cont->getModel();
777 GObjectController *finPort = _controllers[idController];
779 if (finPort->getGObjectType() == GPORT)
781 GPortModel* modelPort = (GPortModel*) finPort->getModel();
782 modelContour->setEndPort(modelPort);
785 typedef std::map<int, GObjectController*>::iterator TIterator;
786 TIterator c_it = _controllers.begin();
787 TIterator iter_end = _controllers.end();
788 // Go through all componets
789 for (c_it; c_it != iter_end; c_it++) {
790 GObjectController* obc = c_it->second;
791 int obc_type = obc->getModel()->getGObjectType();
792 int obc_state = obc->getView()->getState();
793 // if the component is a port and the type is the same of that selected
794 if ((obc_type == GPORT) && (obc_state == POSSIBLE_CONNECTION)) {
795 // Return element to neutral state if not selected
796 obc->getView()->setState(NOTHING_HAPPENS);
798 if ((obc_type == GPORT) && (obc_state == SELECTED_POSSIBLE_CONNECTION)) {
799 // Change element to connected state
800 obc->getView()->setState(HIGHLIGHTED);
806 _parent->saveTempandUpdate("create connection");
809 manualConnectorContourController *manCont = ((GConnectorController*) cont)->getManualContourController();
810 manualConnectorContourView *connView = (manualConnectorContourView*) manCont->GetManualViewBaseContour();
812 std::map<int, GObjectController*>::iterator it2;
814 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
816 GObjectController *cont = it2->second;
817 if (cont->getView() != NULL) {
818 cont->getView()->setState(NOTHING_HAPPENS);
819 cont->getModel()->notifyObservers(_idManager);
821 cont->SetActive(true);
830 //=========================================================================
832 bool wxVtkSceneManager::OnMouseMove()
835 bool okStatusMessage = false;
836 bool okPortMessage = false;
837 crea::wxVTKRenderWindowInteractor *wxVTKiren;
838 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
839 wxVTKiren->GetEventPosition(X, Y);
841 if (_worldState == DRAG_OBJECTS) {
842 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
843 int id = _selectedObjects[i];
844 GObjectController* cont = _controllers[id];
845 if (_startDragging) {
846 cont->getView()->setStartDragging(true);
848 cont->getView()->moveObject(X, Y);
849 cont->getView()->setState(DRAG);
850 cont->getModel()->notifyObservers(_idManager);
853 std::map<int, GObjectController*>::iterator it;
855 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
856 GObjectController *desc = it->second;
857 if (desc->getGObjectType() == GCONNECTOR) {
858 vtkGConnectorView* vconn = (vtkGConnectorView*) desc->getView();
859 vconn->updateStartEndPoints();
863 _startDragging = false;
865 } else if (_worldState == NOTHING_HAPPENS || _worldState == INIT_CREATION_CONTOUR) {
866 std::map<int, GObjectController*>::iterator it;
868 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
869 GObjectController *desc = it->second;
870 int type = desc->getGObjectType();
871 int state = desc->getView()->getState();
872 desc->getModel()->getCenter(px, py, pz);
875 if ((state == HIGHLIGHTED) || (state == SELECTED_POSSIBLE_CONNECTION ))
878 okStatusMessage = true;
879 updateStatusBar(desc->getStatusText());
880 if (type == GBLACKBOX)
882 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
883 _parent->displayBlackBoxInfo(mod->getBBTKPackage(),mod->getBBTKType());
888 if ( ( _bugTextActor_text==desc->getStatusText() ) || (_bugTextActor_status==0) )
890 _bugTextActor_status = 1;
891 okPortMessage = true;
894 // _textActor->SetScale(0.1);
896 _textActor->SetScale(0.05,0.05,1);
898 std::string tmp = desc->getStatusText()+"\n";
899 _textActor->SetInput( tmp.c_str() );
900 // _textActor->SetPosition(px - 25, py + 1, pz + 2);
901 // _textActor->SetPosition(px , py-PORT_HEIGHT/4 , pz + 2);
902 _textActor->SetPosition(px , py-PORT_HEIGHT , pz + 2);
903 _textActor->Modified();
907 _fillObjectActor->SetScale(1);
909 // _fillObjectActor->SetScale(0.7,0.5,1);
910 _fillObjectActor->GetProperty()->SetOpacity(0.75);
911 _fillObjectActor->SetPosition( px, py + PORT_HEIGHT/2.0 , 1);
912 _aPolygonMapper->Modified();
914 _bugTextActor_status= 2;
915 } // _bugTextActor_tex
916 _bugTextActor_text = desc->getStatusText();
920 } // for controllers it
922 if (okStatusMessage == false)
927 if ((okPortMessage == false) || (_bugTextActor_status== 2 ) )
929 _bugTextActor_status = 0;
930 _textActor->SetScale(0.0001);
931 _textActor->SetInput("a\n");
932 _textActor->Modified();
933 _fillObjectActor->SetScale(0.0001);
938 //=========================================================================
940 bool wxVtkSceneManager::OnLeftButtonDown()
942 if (_worldState == INIT_CREATION_CONTOUR)
944 bool isOverPort = false;
945 std::map<int, GObjectController*>::iterator it;
946 for (it = _controllers.begin(); it != _controllers.end() && isOverPort== false; ++it)
948 GObjectController *desc = it->second;
949 if (desc->getGObjectType() == GPORT)
951 GPortModel *portmod = (GPortModel*) desc->getModel();
952 vtkGObjectView *portView = desc->getView();
953 if (portmod->getPortType() == GINPUTPORT && portView->getState() == HIGHLIGHTED)
958 if ( portmod->getPortType( ) == GINPUTPORT && portView->getState( ) == SELECTED_POSSIBLE_CONNECTION ) {
960 portView->setState( HIGHLIGHTED);
967 if (isOverPort == false)
970 UnSelectBlackBoxes();
974 } else { //_worldState
976 _worldState = DRAG_OBJECTS;
977 _startDragging = true;
979 int shiftkey = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey();
980 int ctrlkey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
981 ctrlkey = ctrlkey + shiftkey;
983 GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
986 int state = cont->getView()->getState();
987 if ((ctrlkey == 0) && (state == HIGHLIGHTED)) {
988 UnSelectBlackBoxes();
991 UnSelectBlackBoxes(); // EED 12/07/2012
993 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
994 int id = _selectedObjects[i];
995 GObjectController *cont = _controllers[id];
996 cont->getView()->setState(DRAG);
997 cont->getModel()->notifyObservers(_idManager);
999 } // if _selectedObjects.size
1005 //=========================================================================
1007 bool wxVtkSceneManager::OnLeftButtonUp()
1009 if (_worldState == DRAG_OBJECTS) {
1010 _worldState = NOTHING_HAPPENS;
1012 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
1013 int id = _selectedObjects[i];
1014 GObjectController* cont = _controllers[id];
1015 cont->getView()->setState(SELECTED);
1016 cont->getModel()->notifyObservers(_idManager);
1022 //=========================================================================
1023 void wxVtkSceneManager::CancelConnection()
1025 if (_worldState == INIT_CREATION_CONTOUR)
1027 _worldState = NOTHING_HAPPENS;
1028 //int lastId = _controllers.size()-1;
1030 GConnectorController *connector =
1031 (GConnectorController*) _controllers[_idConnectionInCreation];
1032 connector->removeFromScene();
1033 unregisterController(connector);
1034 _controllers.erase(_idConnectionInCreation);
1036 std::map<int, GObjectController*>::iterator it;
1037 for (it = _controllers.begin(); it != _controllers.end(); ++it)
1039 GObjectController *desc = it->second;
1040 desc->SetActive(true);
1041 desc->getView()->setState(NOTHING_HAPPENS);
1042 desc->getModel()->notifyObservers(_idManager);
1047 //=========================================================================
1049 bool wxVtkSceneManager::OnRightButtonUp()
1051 if (_worldState == INIT_CREATION_CONTOUR)
1055 UnSelectBlackBoxes();
1061 bool wxVtkSceneManager::OnMiddleButtonDown() {
1064 this->_vtkInteractorStyleBaseView->StartPan();
1069 bool wxVtkSceneManager::OnMiddleButtonUp() {
1072 this->_vtkInteractorStyleBaseView->EndPan();
1079 //=========================================================================
1081 GObjectController *wxVtkSceneManager::GetGBlackBoxControlerPointedByMouse() {
1082 GObjectController *result = NULL;
1084 crea::wxVTKRenderWindowInteractor *wxVTKiren;
1086 = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
1087 wxVTKiren->GetEventPosition(X, Y);
1089 std::map<int, GObjectController*>::iterator it;
1091 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1092 GObjectController *cont = it->second;
1093 int type = cont->getGObjectType();
1095 if (cont->getView()->isPointInside(X, Y) == true) {
1096 if (type == GBLACKBOX) {
1099 } // if isPointInside
1104 //=========================================================================
1105 void wxVtkSceneManager::UnSelectBlackBoxes() {
1106 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
1107 int id = _selectedObjects[i];
1108 GObjectController* control = _controllers[id];
1109 control->getView()->setState(NOTHING_HAPPENS);
1110 control->getModel()->notifyObservers(_idManager);
1111 }// for _selectedObjects
1112 _selectedObjects.clear();
1115 //=========================================================================
1116 bool wxVtkSceneManager::OnLeftDClick() {
1117 GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
1119 UnSelectBlackBoxes();
1120 _parent->editBlackBox((GBlackBoxModel*) cont->getModel());
1125 //=========================================================================
1127 bool wxVtkSceneManager::OnChar()
1131 char keyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
1132 int ctrlkey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
1134 // KeyCode 127 : Delete Key
1135 // KeyCode 8 : Backspace Key
1138 if (keyCode == 8 || keyCode == 127 || keyCode == 27)
1140 if (_worldState == INIT_CREATION_CONTOUR)
1143 UnSelectBlackBoxes();
1148 if (keyCode == 8 || keyCode == 127)
1151 for (int i = 0; i < (int) _selectedObjects.size(); i++)
1153 int id = _selectedObjects[i];
1154 std::map<int, GObjectController*>::iterator it;
1155 it = _controllers.find(id);
1156 if (it != _controllers.end())
1158 oktmp = deleteObject(id);
1161 }// for selected objects
1162 if (ok) _selectedObjects.clear();
1163 _parent->saveTempandUpdate("delete object");
1169 if(_selectedObjects.size()){
1170 std::cout<<"objects to copy :";
1171 for(int i=0;i<_selectedObjects.size();i++)
1173 std::cout<<_selectedObjects.at(i)<<" ";
1175 DuplicateObjects(getSelectedObjects());
1177 std::cout<<"No objects to copy\n";
1178 } // _selectedObjects.size
1184 //=========================================================================
1186 void wxVtkSceneManager::AddControlerToBeRemove(
1187 std::vector<int> *controllersToRemove, int id) {
1191 for (i = 0; i < (int) controllersToRemove->size(); i++) {
1192 if (id == (*controllersToRemove)[i]) {
1198 controllersToRemove->push_back(id);
1203 //=========================================================================
1205 bool wxVtkSceneManager::deleteObject(int id)
1208 GObjectController *control = _controllers[id];
1209 std::vector<int> controllersToRemove;
1210 if (control->getGObjectType() == GBLACKBOX || control->getGObjectType()
1211 == GCOMPLEXINPUTPORT || control->getGObjectType()
1212 == GCOMPLEXOUTPUTPORT) {
1213 GBoxModel *bbmod = (GBoxModel*) control->getModel();
1214 std::vector<GPortModel*> inputs = bbmod->getInputPorts();
1216 bool boxConnected = false;
1218 // Add box input controllers to be removed
1219 for (int i = 0; i < (int) inputs.size(); i++) {
1220 AddControlerToBeRemove(&controllersToRemove, inputs[i]->getObjectId());
1221 if (inputs[i]->isConnected()) {
1222 boxConnected = true;
1226 std::vector<GPortModel*> outputs = bbmod->getOutputPorts();
1228 // Add box output controllers to be removed
1229 for (int i = 0; i < (int) outputs.size(); i++) {
1230 AddControlerToBeRemove(&controllersToRemove, outputs[i]->getObjectId());
1231 if (outputs[i]->isConnected()) {
1232 boxConnected = true;
1236 // Add connection controllers to be removed
1237 std::map<int, GObjectController*>::iterator it;
1238 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1239 GObjectController *cont = it->second;
1240 int type = cont->getGObjectType();
1241 if (type == GCONNECTOR) {
1242 GConnectorModel *conMod = (GConnectorModel*) cont->getModel();
1243 if (conMod->getStartPort() != NULL && conMod->getStartPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
1245 AddControlerToBeRemove(&controllersToRemove,conMod->getObjectId());
1247 if (conMod->getEndPort() != NULL && conMod->getEndPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
1249 AddControlerToBeRemove(&controllersToRemove,conMod->getObjectId());
1254 // Add box controller to be removed
1255 AddControlerToBeRemove(&controllersToRemove, bbmod->getObjectId());
1256 } else if (control->getGObjectType() == GCONNECTOR) {
1257 GConnectorController *gconnectorcontroler = (GConnectorController*)control;
1258 if (gconnectorcontroler->getManualContourController()->IsEditable()==false)
1260 GConnectorModel *conMod = (GConnectorModel*) control->getModel();
1261 AddControlerToBeRemove(&controllersToRemove, conMod->getObjectId());
1263 gconnectorcontroler->getManualContourController()->OnChar();
1268 std::map<int, GObjectController*>::iterator it;
1270 for (int i = 0; i < (int) controllersToRemove.size(); i++) {
1271 int key = controllersToRemove[i];
1272 it = _controllers.find(key);
1273 GObjectController *cont = _controllers[key];
1275 cont->removeFromScene();
1276 unregisterController((InteractorStyleMaracas*) cont);
1277 _controllers.erase(it);
1285 //=========================================================================
1287 void wxVtkSceneManager::displayBlackBoxInfo(std::string packageName,
1288 std::string boxName) {
1289 _parent->displayBlackBoxInfo(packageName, boxName);
1292 //=========================================================================
1294 void wxVtkSceneManager::updateStatusBar(std::string textStatus) {
1295 _parent->updateStatusBar(textStatus);
1298 //=========================================================================
1299 std::string wxVtkSceneManager::LineNumber(bool withLineNumber, int &value) {
1300 std::string result = "";
1301 if (withLineNumber == true) {
1303 stringstream StrStream;
1305 std::string strValue = StrStream.str();
1308 } else if (value < 100) {
1312 result += strValue + ": ";
1316 //=========================================================================
1318 bool wxVtkSceneManager::MakeBoxExecutable() {
1319 std::map<int, GObjectController*> selected = getSelectedObjects();
1320 if( selected.empty() )
1323 std::map<int, GObjectController*>::iterator it;
1324 for (it = selected.begin(); it != selected.end(); ++it) {
1325 GObjectController* lastSelected = it->second;
1327 vtkGObjectView* view = (vtkGObjectView*) lastSelected->getView();
1328 GBlackBoxModel *bbmodel =
1329 (GBlackBoxModel*) lastSelected->getModel();
1330 view->setState(HIGHLIGHTED);
1331 if (bbmodel->isExecutable()) {
1332 bbmodel->setExecutable(false);
1334 bbmodel->setExecutable(true);
1336 bbmodel->notifyObservers(lastSelected->getId());
1344 //=========================================================================
1346 std::string wxVtkSceneManager::getDiagramBBS(bool wln) {
1347 std::cout << "wxVtkSceneManager::getDiagramBBS" << std::endl;
1348 bool existsExec = false;
1350 std::vector<std::string> packages;
1351 std::vector<int> boxes;
1352 std::vector<int> connections;
1353 std::vector<int> execBoxes;
1355 std::map<int, GObjectController*>::iterator it;
1357 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1358 GObjectController *desc = it->second;
1359 int type = desc->getGObjectType();
1361 if (type == GBLACKBOX) {
1362 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
1364 std::string pkg = mod->getBBTKPackage();
1365 bool existsPkg = false;
1366 for (int t = 0; t < (int) packages.size() && existsPkg == false; t++) {
1367 if (packages[t] == pkg) {
1372 packages.push_back(pkg);
1375 boxes.push_back(it->first);
1376 if (mod->isExecutable()) {
1377 execBoxes.push_back(it->first);
1380 } else if (type == GCONNECTOR) {
1381 connections.push_back(it->first);
1386 std::string script = "";
1387 script += LineNumber(wln, lnNmbr) + "# BBTK GEditor Script\n";
1388 script += LineNumber(wln, lnNmbr) + "# ----------------------\n";
1389 script += LineNumber(wln, lnNmbr) + "\n";
1391 script += LineNumber(wln, lnNmbr) + "include std\n"; // EED
1392 script += LineNumber(wln, lnNmbr) + "include itkvtk\n"; // EED
1394 for (i = 0; i < (int) packages.size(); i++) {
1395 script += LineNumber(wln, lnNmbr);
1396 script += "include ";
1397 script += packages[i];
1401 script += LineNumber(wln, lnNmbr);
1406 script += LineNumber(wln, lnNmbr);
1407 script += "author \"";
1411 script += LineNumber(wln, lnNmbr);
1412 script += "description \"";
1413 script += _Description;
1416 script += LineNumber(wln, lnNmbr);
1417 script += "category \"";
1418 script += _Category;
1421 script += LineNumber(wln, lnNmbr);
1424 // script+="include std\n"; // JPR
1426 for (i = 0; i < (int) boxes.size(); i++) {
1427 script += LineNumber(wln, lnNmbr);
1430 GObjectController *control = _controllers[id];
1431 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1433 script += model->getBBTKPackage()+":";
1434 script += model->getBBTKType();
1436 script += model->getBBTKName();
1439 std::vector<GPortModel*> inputs = model->getInputPorts();
1440 for (int j = 0; j < (int) inputs.size(); j++) {
1441 GPortModel* inputPort = inputs[j];
1442 if (inputPort->isValueSet()) {
1443 script += LineNumber(wln, lnNmbr);
1445 script += model->getBBTKName();
1447 script += inputPort->getBBTKName();
1449 script += inputPort->getValue();
1454 script += LineNumber(wln, lnNmbr);
1459 script += LineNumber(wln, lnNmbr);
1463 std::string complexInputs="";
1465 for (i = 0; i < (int) connections.size(); i++) {
1466 //script += LineNumber(wln, lnNmbr);
1467 //script += "connect ";
1468 int id = connections[i];
1469 GObjectController *control = _controllers[id];
1470 GConnectorModel *model = (GConnectorModel*) control->getModel();
1474 GPortModel *start = model->getStartPort();
1475 GBoxModel *startBox = start->getParentBox();
1477 GPortModel *end = model->getEndPort();
1478 GBoxModel *endBox = end->getParentBox();
1480 if (startBox->getGObjectType() == GCOMPLEXINPUTPORT)
1482 complexInputs += "input ";
1483 complexInputs += startBox->getBBTKName();
1485 complexInputs += " ";
1486 complexInputs += endBox->getBBTKName();
1487 complexInputs += ".";
1488 complexInputs += end->getBBTKName();
1490 complexInputs += " ";
1491 complexInputs += "\" \"";
1493 complexInputs += "\n";
1497 script += LineNumber(wln, lnNmbr);
1498 script += "connect ";
1499 script += startBox->getBBTKName();
1501 script += start->getBBTKName();
1505 //End Connection info
1506 script += endBox->getBBTKName();
1508 script += end->getBBTKName();
1513 script += LineNumber(wln, lnNmbr);
1517 script += LineNumber(wln, lnNmbr);
1520 script += LineNumber(wln, lnNmbr);
1523 script += LineNumber(wln, lnNmbr);
1524 script += "# Complex input ports\n";
1525 script += complexInputs;
1527 if((_MessageKind!="-")&&(_MessageLevel!="-")){
1528 script += LineNumber(wln, lnNmbr);
1529 script += "message ";
1530 script += _MessageKind;
1532 script += _MessageLevel;
1536 for (i = 0; i < (int) execBoxes.size(); i++) {
1537 script += LineNumber(wln, lnNmbr);
1539 int id = execBoxes[i];
1540 GObjectController *control = _controllers[id];
1541 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1543 script += model->getBBTKName();
1552 //=========================================================================
1554 std::string wxVtkSceneManager::saveComplexBoxBBS() {
1555 std::cout<<"wxVtkSceneManager::saveComplexBoxBBS"<<std::endl;
1556 std::vector<std::string> packages;
1557 std::vector<int> boxes;
1558 std::vector<int> connections;
1559 std::vector<int> execBoxes;
1561 std::map<int, GObjectController*>::iterator it;
1563 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1564 GObjectController *desc = it->second;
1565 int type = desc->getGObjectType();
1567 if (type == GBLACKBOX) {
1568 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
1570 std::string pkg = mod->getBBTKPackage();
1571 bool existsPkg = false;
1572 for (int t = 0; t < (int) packages.size() && existsPkg == false; t++) {
1573 if (packages[t] == pkg) {
1578 packages.push_back(pkg);
1581 boxes.push_back(it->first);
1582 if (mod->isExecutable()) {
1583 execBoxes.push_back(it->first);
1585 } else if (type == GCONNECTOR) {
1586 connections.push_back(it->first);
1590 std::string script = "";
1592 script += "include std\n"; // EED
1593 script += "include itkvtk\n"; // EED
1595 for (i = 0; i < (int) packages.size(); i++) {
1596 script += "include ";
1597 script += packages[i];
1602 // Definition of a complex box
1603 script += "define ";
1604 script += _cbName + " " + _cbPackageName;
1608 script += "author \"";
1612 script += "description \"";
1613 script += _Description;
1617 script += "category \"";
1618 script += _Category;
1623 for (i = 0; i < (int) boxes.size(); i++) {
1626 GObjectController *control = _controllers[id];
1627 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1629 script += model->getBBTKPackage()+":";
1630 script += model->getBBTKType();
1632 script += model->getBBTKName();
1635 std::vector<GPortModel*> inputs = model->getInputPorts();
1636 for (int j = 0; j < (int) inputs.size(); j++) {
1637 GPortModel* inputPort = inputs[j];
1638 if (inputPort->isValueSet()) {
1640 script += model->getBBTKName();
1642 script += inputPort->getBBTKName();
1644 script += inputPort->getValue();
1652 // Create connections in the script. If the connection is made with a complex port, it is created the input or output
1654 std::string complexInputs = "";
1655 std::string complexOutputs = "";
1658 for (i = 0; i < (int) connections.size(); i++) {
1659 int id = connections[i];
1660 GObjectController *control = _controllers[id];
1661 GConnectorModel *model = (GConnectorModel*) control->getModel();
1664 GPortModel *start = model->getStartPort();
1665 GBoxModel *startBox = start->getParentBox();
1667 GPortModel *end = model->getEndPort();
1668 GBoxModel *endBox = end->getParentBox();
1670 if (startBox->getGObjectType() == GCOMPLEXINPUTPORT) {
1671 complexInputs += "input ";
1672 complexInputs += startBox->getBBTKName();
1674 complexInputs += " ";
1675 complexInputs += endBox->getBBTKName();
1676 complexInputs += ".";
1677 complexInputs += end->getBBTKName();
1679 complexInputs += " ";
1680 complexInputs += "\" \"";
1682 complexInputs += "\n";
1683 } else if (endBox->getGObjectType() == GCOMPLEXOUTPUTPORT) {
1684 complexOutputs += "output ";
1685 complexOutputs += endBox->getBBTKName();
1687 complexOutputs += " ";
1688 complexOutputs += startBox->getBBTKName();
1689 complexOutputs += ".";
1690 complexOutputs += start->getBBTKName();
1692 complexOutputs += " ";
1693 complexOutputs += "\" \"";
1695 complexOutputs += "\n";
1697 script += "connect ";
1698 script += startBox->getBBTKName();
1700 script += start->getBBTKName();
1704 //End Connection info
1705 script += endBox->getBBTKName();
1707 script += end->getBBTKName();
1714 script += "# Complex input ports\n";
1715 script += complexInputs;
1718 script += "# Complex output ports\n";
1719 script += complexOutputs;
1723 if((_MessageKind!="-")&&(_MessageLevel!="-"))
1725 script += "message ";
1726 script += _MessageKind;
1728 script += _MessageLevel;
1732 for (i = 0; i < (int) execBoxes.size(); i++)
1735 int id = execBoxes[i];
1736 GObjectController *control = _controllers[id];
1737 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1739 script += model->getBBTKName();
1744 script += "endefine";
1750 //=========================================================================
1752 void wxVtkSceneManager::deleteAllBoxes() {
1753 std::map<int, GObjectController*>::iterator it;
1754 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1755 GObjectController *cont = it->second;
1756 cont->removeFromScene();
1757 unregisterController((InteractorStyleMaracas*) cont);
1759 _selectedObjects.clear();
1760 _controllers.clear();
1763 //=========================================================================
1766 void wxVtkSceneManager::refresh() {
1767 _baseView->Refresh();
1769 //=========================================================================
1771 void wxVtkSceneManager::refreshScene()
1773 _baseView->RefreshView();
1776 //=========================================================================
1778 void wxVtkSceneManager::centerView()
1781 _baseView->GetRenderer()->ComputeVisiblePropBounds(bb);
1784 _baseView->GetRenderer()->GetActiveCamera()->GetFocalPoint(temp);
1785 _baseView->GetRenderer()->GetActiveCamera()->SetFocalPoint(0, 0, temp[2]);
1786 _baseView->GetRenderer()->GetActiveCamera()->GetPosition(temp);
1787 _baseView->GetRenderer()->GetActiveCamera()->SetPosition(0, 0, temp[2]);
1789 _baseView->GetRenderer()->ResetCamera();
1790 _baseView->GetRenderer()->ResetCameraClippingRange();
1793 double tt=_baseView->GetRenderer()->GetNearClippingPlaneTolerance();
1794 printf("EED wxVtkSceneManager::centerView() tolerance=%f\n",tt);
1796 _baseView->GetRenderer()->GetActiveCamera()->GetClippingRange(cr1,cr2);
1797 printf("EED wxVtkSceneManager::centerView() cr1=%f cr2=%f\n",cr1,cr2);
1798 _baseView->GetRenderer()->GetActiveCamera()->SetClippingRange(0.01,100000);
1799 _baseView->GetRenderer()->GetActiveCamera()->GetClippingRange(cr1,cr2);
1800 printf("EED wxVtkSceneManager::centerView() cr1=%f cr2=%f\n",cr1,cr2);
1803 _baseView->GetRenderer()->Render();
1806 //=========================================================================
1808 void wxVtkSceneManager::saveDiagram(std::string &content)
1812 content += "CATEGORY:";
1813 content += GetCategory();
1816 content += "DESCRIPTION:";
1817 content += GetDescription();
1820 content += "AUTHOR:";
1821 content += GetAuthor();
1824 //Print info IF COMPLEX BOX
1825 content += "COMPLEXBOX:";
1826 if (_isComplexBox) {
1827 content += "TRUE\n";
1829 content += "COMPLEXBOXNAME:";
1830 content += GetCbName();
1833 content += "PACKAGENAME:";
1834 content += GetCbPackageName();
1837 /* CHANGE TO THE VERSION 1.4 RaC2012 2nd HackFest
1838 * External inputs are possible for applications and complex boxes
1839 //Print info complex input ports
1840 std::vector<int> inputs = getComplexInputPorts();
1841 int insize = inputs.size();
1842 content += "COMPLEXINPUTS:";
1843 sprintf(buffer, "%d", insize);
1847 for (int i = 0; i < insize; i++) {
1849 GObjectController *cont = _controllers[id];
1850 cont->getModel()->save(content);
1854 //Print info complex output ports
1855 std::vector<int> outputs = getComplexOutputPorts();
1856 int outsize = outputs.size();
1857 content += "COMPLEXOUTPUTS:";
1858 sprintf(buffer, "%d", outsize);
1862 for (int i = 0; i < outsize; i++) {
1863 int id = outputs[i];
1864 GObjectController *cont = _controllers[id];
1865 cont->getModel()->save(content);
1869 content += "FALSE\n";
1872 // CHANGE TO THE VERSION 1.4 RaC2012 2nd HackFest
1873 // External inputs are possible for applications and complex boxes
1874 std::vector<int> inputs = getComplexInputPorts();
1875 int insize = inputs.size();
1876 content += "COMPLEXINPUTS:";
1877 sprintf(buffer, "%d", insize);
1881 for (int i = 0; i < insize; i++) {
1883 GObjectController *cont = _controllers[id];
1884 cont->getModel()->save(content);
1888 std::vector<int> boxes = getBlackBoxes();
1889 int bsize = boxes.size();
1890 content += "BOXES:";
1891 sprintf(buffer, "%d", bsize);
1895 for (int i = 0; i < bsize; i++) {
1897 // std::cout<<"id "<<id<<std::endl;//CFT
1898 GObjectController *cont = _controllers[id];
1899 // std::cout<<"nombre: "<<cont->getStatusText()<<std::endl;//CFT
1900 // std::cout<<"tipo: "<<cont->getModel()->getBBTKType()<<std::endl;//CFT
1901 // //boxesDiagram[i] = cont->getModel()->getBBTKType();//CFT
1902 // std::cout<<"nname: "<<cont->getModel()->getBBTKName()<<std::endl;//CFT
1903 // std::cout<<"categorie: "<<GetCategory()<<std::endl;//CFT
1904 // std::cout<<"type: "<<cont->getModel()->getGObjectType()<<std::endl;//CFT
1905 cont->getModel()->save(content);
1909 std::vector<int> connections = getConnections();
1910 int csize = connections.size();
1911 content += "CONNECTIONS:";
1912 sprintf(buffer, "%d", csize);
1916 for (int i = 0; i < csize; i++) {
1917 int id = connections[i];
1918 GObjectController *cont = _controllers[id];
1919 cont->getModel()->save(content);
1924 //=========================================================================
1925 void wxVtkSceneManager::getCleanLine(stringstream &inputStream, std::string &line)
1927 getline(inputStream, line,'\n');
1928 int size = line.length();
1931 if ( line[ size-1 ]==13 )
1933 line.erase(size-1,1);
1938 //=========================================================================
1939 void wxVtkSceneManager::loadDiagram(stringstream &inputStream)
1942 std::string version = "<void>";
1943 std::string line = "";
1944 char delims[] = ":";
1945 char *result = NULL;
1946 char poort[POORT_MAX_LINE_SIZE_INTERPRETER];
1948 getCleanLine(inputStream, line);
1951 while (!inputStream.eof()) {
1952 if (line == "" || line[0] == '#') {
1954 getCleanLine(inputStream, line);
1956 if (line == "# - BBTKGEditor v 1.0 BBG BlackBox Diagram file") {
1957 version = line.substr(18, 3);
1959 if (line == "# - BBTKGEditor v 1.1 BBG BlackBox Diagram file") {
1960 version = line.substr(18, 3);
1962 if (line == "# - BBTKGEditor v 1.2 BBG BlackBox Diagram file") {
1963 version = line.substr(18, 3);
1965 if (line == "# - BBTKGEditor v 1.3 BBG BlackBox Diagram file") {
1966 version = line.substr(18, 3);
1968 if (line == "# - BBTKGEditor v 1.4 BBG BlackBox Diagram file") {
1969 version = line.substr(18, 3);
1971 if (line == "# - BBTKGEditor v 1.5 BBG BlackBox Diagram file") {
1972 version = line.substr(18, 3);
1974 } else if (line == "APP_START") {
1984 if ((version != "1.0") && (version != "1.1")) {
1985 getCleanLine(inputStream, line);//CATEGORY:<category of the box>
1986 char categoryTmp[30];
1987 strcpy(categoryTmp, line.c_str());
1988 result = strtok(categoryTmp, delims);
1989 result = strtok(NULL, delims);
1990 SetCategory(result);
1992 getCleanLine(inputStream, line);//DESCRIPTION:<description of the box>
1993 char descriptionTmp[1024];
1994 strcpy(descriptionTmp, line.c_str());
1995 result = strtok(descriptionTmp, delims);
1996 result = strtok(NULL, delims);
1997 SetDescription(result);
1999 getCleanLine(inputStream, line);//AUTHOR:<author>
2000 char authorTmp[255];
2001 strcpy(authorTmp, line.c_str());
2002 result = strtok(authorTmp, delims);
2003 result = strtok(NULL, delims);
2008 getCleanLine(inputStream, line);//COMPLEX_BOX:TRUE|FALSE
2009 char complexTmp[30];
2010 strcpy(complexTmp, line.c_str());
2011 result = strtok(complexTmp, delims);
2012 result = strtok(NULL, delims);
2013 std::string isComplexBox(result);
2015 if (isComplexBox == "TRUE")
2017 _isComplexBox = true;
2019 if ((version != "1.0") && (version != "1.1"))
2021 getCleanLine(inputStream, line);//COMPLEXNAME:<name of the complex box>
2022 char complexboxnameTmp[255];
2023 strcpy(complexboxnameTmp, line.c_str());
2024 result = strtok(complexboxnameTmp, delims);
2025 result = strtok(NULL, delims);
2028 getCleanLine(inputStream, line);//PACKAGENAME:<name of the package of the box>
2029 char packagenameTmp[255];
2030 strcpy(packagenameTmp, line.c_str());
2031 result = strtok(packagenameTmp, delims);
2032 result = strtok(NULL, delims);
2033 SetCbPackageName(result);
2034 } // if version !1.0 !1.1
2038 //-----------------------
2039 //- COMPLEX INPUT PORTS
2040 //-----------------------
2041 getCleanLine(inputStream, line);//COMPLEXINPUTS:num
2043 strcpy(inputs, line.c_str());
2044 result = strtok(inputs, delims);
2045 result = strtok(NULL, delims);
2048 std::istringstream inps(result);
2051 for (int i = 0; i < numInputs; i++)
2054 getCleanLine(inputStream, line);//COMPLEX_PORT
2055 getCleanLine(inputStream, line);//name
2056 std::string inputPortName(line);
2059 getCleanLine(inputStream, line);//xInic:yInic:zInic
2061 strcpy(coord, line.c_str());
2062 result = strtok(coord, delims);//xInic
2063 std::string xInic(result);
2064 result = strtok(NULL, delims);//yInic
2065 std::string yInic(result);
2066 result = strtok(NULL, delims);//zInic
2067 std::string zInic(result);
2069 double xIn, yIn, zIn;
2070 std::istringstream xSt(xInic);
2072 std::istringstream ySt(yInic);
2074 std::istringstream zSt(zInic);
2079 if (zIn==900) zIn=GPOSITION_Z;
2080 } // if version <=1.2
2082 getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
2084 configGComBoxInputOutputPort(true, inputPortName, xIn, yIn, zIn);
2086 } // for input complex box
2087 } // if version < 1.4
2091 //-----------------------
2092 //- COMPLEX OUTPUT PORTS
2093 //-----------------------
2095 getCleanLine(inputStream, line);//COMPLEXOUTPUTS:num
2097 strcpy(outputs, line.c_str());
2098 result = strtok(outputs, delims);
2099 result = strtok(NULL, delims);
2102 std::istringstream outps(result);
2103 outps >> numOutputs;
2105 for (int i = 0; i < numOutputs; i++)
2108 getCleanLine(inputStream, line);//COMPLEX_PORT
2109 getCleanLine(inputStream, line);//name
2110 std::string outputPortName(line);
2113 getCleanLine(inputStream, line);//xInic:yInic:zInic
2115 strcpy(coord, line.c_str());
2116 result = strtok(coord, delims);//xInic
2117 std::string xInic(result);
2118 result = strtok(NULL, delims);//yInic
2119 std::string yInic(result);
2120 result = strtok(NULL, delims);//zInic
2121 std::string zInic(result);
2123 double xIn, yIn, zIn;
2124 std::istringstream xSt(xInic);
2126 std::istringstream ySt(yInic);
2128 std::istringstream zSt(zInic);
2133 if (zIn==900) zIn=GPOSITION_Z;
2142 getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
2144 configGComBoxInputOutputPort(false, outputPortName, xIn, yIn, zIn);
2146 } // for output complex box
2147 } // if isComplexBox
2150 // RaC2012 2nd Hackfest
2151 if(version >= "1.4")
2153 //-----------------------
2154 //- EXTERNAL INPUT PORTS
2155 //-----------------------
2156 getCleanLine(inputStream, line);//COMPLEXINPUTS:num
2158 strcpy(inputs, line.c_str());
2159 result = strtok(inputs, delims);
2160 result = strtok(NULL, delims);
2163 std::istringstream inps(result);
2166 for (int i = 0; i < numInputs; i++)
2168 getCleanLine(inputStream, line);//COMPLEX_PORT
2169 getCleanLine(inputStream, line);//name
2170 std::string inputPortName(line);
2171 getCleanLine(inputStream, line);//xInic:yInic:zInic
2173 strcpy(coord, line.c_str());
2174 result = strtok(coord, delims);//xInic
2175 std::string xInic(result);
2176 result = strtok(NULL, delims);//yInic
2177 std::string yInic(result);
2178 result = strtok(NULL, delims);//zInic
2179 std::string zInic(result);
2180 double xIn, yIn, zIn;
2181 std::istringstream xSt(xInic);
2183 std::istringstream ySt(yInic);
2185 std::istringstream zSt(zInic);
2189 if (zIn==900) zIn=GPOSITION_Z;
2197 getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
2198 configGComBoxInputOutputPort(true, inputPortName, xIn, yIn, zIn);
2199 } // for external input
2200 } // if(version >= "1.4")
2203 getCleanLine(inputStream, line);//BOXES:num
2205 strcpy(boxes, line.c_str());
2206 result = strtok(boxes, delims);
2207 result = strtok(NULL, delims);
2210 std::istringstream is(result);
2213 for (int i = 0; i < numBoxes; i++)
2216 getCleanLine(inputStream, line);//BOX
2217 getCleanLine(inputStream, line);//package:type:name
2219 strcpy(box, line.c_str());
2220 result = strtok(box, delims);//package
2221 std::string package(result);
2222 result = strtok(NULL, delims);//type
2223 std::string type(result);
2224 result = strtok(NULL, delims);//name
2225 std::string name(result);
2228 getCleanLine(inputStream, line);//ISEXEC:TRUE|FALSE
2230 strcpy(exec, line.c_str());
2231 result = strtok(exec, delims);//ISEXEC
2232 result = strtok(NULL, delims);//TRUE|FALSE
2233 std::string isExec(result);
2236 getCleanLine(inputStream, line);//xInic:yInic:zInic
2238 strcpy(coord, line.c_str());
2239 result = strtok(coord, delims);//xInic
2240 std::string xInic(result);
2241 result = strtok(NULL, delims);//yInic
2242 std::string yInic(result);
2243 result = strtok(NULL, delims);//zInic
2244 std::string zInic(result);
2245 double xIn, yIn, zIn;
2246 std::istringstream xSt(xInic);
2248 std::istringstream ySt(yInic);
2250 std::istringstream zSt(zInic);
2255 if (zIn==900) zIn=GPOSITION_Z;
2264 getCleanLine(inputStream, line);//xEnd:yEnd:zEnd
2265 strcpy(coord, line.c_str());
2266 result = strtok(coord, delims);//xEnd
2267 std::string xEnd(result);
2268 result = strtok(NULL, delims);//yEnd
2269 std::string yEnd(result);
2270 result = strtok(NULL, delims);//zEnd
2271 std::string zEnd(result);
2273 double xEn, yEn, zEn;
2274 std::istringstream xEt(xEnd);
2276 std::istringstream yEt(yEnd);
2278 std::istringstream zEt(zEnd);
2283 if (zEn==900) zEn=GPOSITION_Z;
2286 yEn = yIn-BOX_HEIGHT;
2288 bool boxExecutable = false;
2289 if (isExec == "TRUE")
2291 boxExecutable = true;
2294 int idBox = createGBlackBox(xIn, yIn, package, type);
2295 configGBlackBox(idBox, xIn, yIn, zIn, name, boxExecutable, xEn, yEn, zEn);
2297 GObjectController *cont = _controllers[idBox];
2298 GBlackBoxModel *bbmod = (GBlackBoxModel*) cont->getModel();
2301 getCleanLine(inputStream, line);//PORT o FIN_BOX
2302 std::string port = line.substr(0, 4);
2303 while (port == "PORT")
2305 getCleanLine(inputStream, line);//name:value
2306 if (line.length()>=POORT_MAX_LINE_SIZE_INTERPRETER-1)
2308 line=line.substr(0, POORT_MAX_LINE_SIZE_INTERPRETER-1);
2311 strcpy(poort, line.c_str());
2312 result = strtok(poort, delims);//name
2313 std::string name(result);
2315 //EED 16 oct 2012 Adding at the end character " if necesary in the value definition
2316 result = strtok(NULL, delims);//value
2317 if (( result[0]=='"' ) && ( result[ strlen(result)-1 ]!='"' ) )
2319 std::string tmpString=" ";
2320 tmpString[0]=34; // character "
2321 strcat(result,tmpString.c_str());
2323 std::string value(result);
2324 bbmod->setValueToInput(name, value);
2325 getCleanLine(inputStream, line);//PORT o FIN_BOX
2326 port = line.substr(0, 4);
2329 //EED bbmod->notifyObservers(_idManager);
2334 getCleanLine(inputStream, line);//CONNECTIONS:num
2336 strcpy(conns, line.c_str());
2337 result = strtok(conns, delims);
2338 result = strtok(NULL, delims);
2340 std::istringstream isCons(result);
2344 for (int i = 0; i < numConns; i++)
2347 getCleanLine(inputStream, line);//CONNECTION
2348 getCleanLine(inputStream, line);//Startbox.PortName:EndBox.PortName
2350 strcpy(connec, line.c_str());
2351 result = strtok(connec, delims);
2352 std::string nameStartBox(result);
2353 result = strtok(NULL, delims);
2354 std::string nameStartPort(result);
2355 result = strtok(NULL, delims);
2356 std::string nameEndBox(result);
2357 result = strtok(NULL, delims);
2358 std::string nameEndPort(result);
2359 int idCon = configGConnetion(nameStartBox, nameStartPort,nameEndBox, nameEndPort);
2360 if (version != "1.0") {
2361 //Readding control points of the manualContour
2362 GConnectorController *tempp = (GConnectorController*) _controllers[idCon];
2363 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2364 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2365 getCleanLine(inputStream, line); //NumberOfControlPoints:##
2366 strcpy(conns, line.c_str());
2367 result = strtok(conns, delims);
2368 result = strtok(NULL, delims);
2369 int numberOfControlPoints;
2370 std::istringstream isCons(result);
2371 isCons >> numberOfControlPoints;
2372 for (int ii = 0; ii < numberOfControlPoints; ii++) {
2373 getCleanLine(inputStream, line); //XX:YY:ZZ
2375 strcpy(connec, line.c_str());
2377 result = strtok(connec, delims);
2378 std::istringstream isPointX(result);
2380 result = strtok(NULL, delims);
2381 std::istringstream isPointY(result);
2383 result = strtok(NULL, delims);
2384 std::istringstream isPointZ(result);
2388 if (pz==900) pz=GPOSITION_Z;
2396 conMod->getManualContourModel()->InsertPoint_id(ii + 1, px, py, pz);
2397 conView->getManualContourView()->AddPoint();
2399 }// if version !=1.0
2403 //=========================================================================
2406 //=========================================================================
2407 void wxVtkSceneManager::configGComBoxInputOutputPort(bool inputoutput,
2408 std::string portName, double xIn, double yIn, double zIn)
2411 if (inputoutput == true) {
2412 idPort = createGComplexBoxInputPort(portName);
2414 idPort = createGComplexBoxOutputPort(portName);
2416 GObjectController *cont = _controllers[idPort];
2417 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2418 cbmod->setInicPoint(xIn, yIn, zIn);
2419 cbmod->notifyObservers(_idManager);
2421 //=========================================================================
2424 //=========================================================================
2425 GBoxModel* wxVtkSceneManager::findGBox(std::string boxname)
2430 GBoxModel *boxModel = NULL;
2431 std::vector<int> lstB = getBlackBoxes();
2432 for (j = 0; j < (int) lstB.size(); j++) {
2434 bMod = (GBoxModel*) _controllers[idB]->getModel();
2435 if (_controllers[idB]->getModel()->getBBTKName() == boxname)
2443 if (boxModel == NULL) {
2444 std::vector<int> lstInputs = getComplexInputPorts();
2445 for (j = 0; j < (int) lstInputs.size(); j++) {
2447 bMod = (GBoxModel*) _controllers[idB]->getModel();
2448 if (_controllers[idB]->getModel()->getBBTKName() == boxname)
2456 std::vector<int> lstOutputs = getComplexOutputPorts();
2457 for (j = 0; j < (int) lstOutputs.size(); j++) {
2458 int idB = lstOutputs[j];
2459 bMod = (GBoxModel*) _controllers[idB]->getModel();
2460 if (_controllers[idB]->getModel()->getBBTKName() == boxname)
2472 //=========================================================================
2475 int wxVtkSceneManager::configGConnetion(std::string nameStartBox,
2476 std::string nameStartPort, std::string nameEndBox,
2477 std::string nameEndPort) {
2479 GBoxModel *boxModel;
2480 GPortModel *startP = NULL;
2481 GPortModel *endP = NULL;
2483 boxModel = findGBox(nameStartBox);
2484 if(boxModel == NULL)
2486 printf("RaC: ERROR in wxVtkSceneManager::configGConnetion A box to connect start port %s is null. Box name is probably wrong.\n", nameStartPort.c_str());
2488 if (boxModel != NULL) {
2489 startP = boxModel->getOutputPort(nameStartPort);
2491 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() );
2495 boxModel = findGBox(nameEndBox);
2496 if(boxModel == NULL)
2498 printf("RaC: ERROR in wxVtkSceneManager::configGConnetion A box to connect start port %s is null. Box name is probably wrong.\n", nameStartPort.c_str());
2500 if (boxModel != NULL) {
2501 endP = boxModel->getInputPort(nameEndPort);
2503 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());
2508 int idCon = createGConnector(startP);
2510 _worldState = NOTHING_HAPPENS;
2511 GConnectorController *tempp = (GConnectorController*) _controllers[idCon];
2513 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2514 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2515 tempp->endContourCreation();
2516 conMod->setEndPort(endP);
2517 conView->updateStartEndPoints();
2521 //=========================================================================
2523 bool wxVtkSceneManager::boxExist(std::string boxname) {
2525 std::map<int, GObjectController*>::iterator it;
2526 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2527 GObjectController *cont = it->second;
2528 if (cont->getModel()->getBBTKName() == boxname) {
2535 //=========================================================================
2537 std::vector<int> wxVtkSceneManager::getBlackBoxes() {
2538 std::vector<int> vect;
2539 std::map<int, GObjectController*>::iterator it;
2540 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2541 GObjectController *cont = it->second;
2542 if (cont->getGObjectType() == GBLACKBOX) {
2543 vect.push_back(cont->getId());
2549 //=========================================================================
2551 std::vector<int> wxVtkSceneManager::getComplexInputPorts() {
2552 std::vector<int> vect;
2553 std::map<int, GObjectController*>::iterator it;
2554 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2555 GObjectController *cont = it->second;
2556 if (cont->getGObjectType() == GCOMPLEXINPUTPORT) {
2557 vect.push_back(cont->getId());
2563 //=========================================================================
2565 std::vector<int> wxVtkSceneManager::getComplexOutputPorts() {
2566 std::vector<int> vect;
2567 std::map<int, GObjectController*>::iterator it;
2568 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2569 GObjectController *cont = it->second;
2570 if (cont->getGObjectType() == GCOMPLEXOUTPUTPORT) {
2571 vect.push_back(cont->getId());
2577 //=========================================================================
2579 std::vector<int> wxVtkSceneManager::getConnections() {
2580 std::vector<int> vect;
2581 std::map<int, GObjectController*>::iterator it;
2582 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2583 GObjectController *cont = it->second;
2584 if (cont->getGObjectType() == GCONNECTOR) {
2585 vect.push_back(cont->getId());
2591 //=========================================================================
2593 bool wxVtkSceneManager::isComplexBox() {
2594 return _isComplexBox;
2597 //=========================================================================
2599 void wxVtkSceneManager::setComplexBox(bool val) {
2600 _isComplexBox = val;
2603 //=========================================================================
2605 int wxVtkSceneManager::addObjectController(GObjectController* objController) {
2606 //Register the controller of the new object
2607 registerController((InteractorStyleMaracas*) objController);
2608 //Add the object to the objects list
2609 int newId = _contLastId;//_controllers.size();
2610 objController->setId(newId);
2611 _controllers[newId] = objController;
2612 //std::cout << "DFCH: int wxVtkSceneManager::addObjectController(GObjectController* objController) ---- _contLastId = " << _contLastId << std::endl;
2617 //=========================================================================
2619 void wxVtkSceneManager::DuplicateObjects(std::map<int, GObjectController*> objectsMap) {
2621 std::map<int, int> oldIdNewIdBoxes;
2622 std::vector<int> connections;
2624 std::vector<int> newBoxesID;
2626 std::map<int, GObjectController*>::iterator it;
2627 for (it = objectsMap.begin(); it != objectsMap.end(); ++it) {
2628 GObjectController *cont = it->second;
2629 int type = cont->getGObjectType();
2631 if (type == GBLACKBOX) {
2633 double xInic, yInic, zInic;
2634 GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
2635 copyBox->getInicPoint(xInic, yInic, zInic);
2636 int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(),
2637 copyBox->getBBTKType());
2639 int idcB = copyBox->getObjectId();
2640 oldIdNewIdBoxes[idcB] = idBox;
2641 cont = _controllers[idBox];
2642 GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
2643 newbox->setInicPoint(xInic, yInic, zInic);
2644 int num = newbox->getNumInputPorts();
2645 for (int j = 0; j < num; j++) {
2646 newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
2648 newbox->move(xInic + 20, yInic + 20, zInic);
2649 newbox->notifyObservers(_idManager);
2650 newBoxesID.push_back(newbox->getObjectId());
2652 } else if (type == GCONNECTOR) {
2653 int idCon = cont->getId();
2654 connections.push_back(idCon);
2659 for (int i = 0; i < (int) connections.size(); i++) {
2660 int objId = connections[i];
2661 GObjectController *cont = objectsMap[objId];
2662 GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
2664 GPortModel* startPort = connectModel->getStartPort();
2665 int startPortIndex = startPort->getPosInBox();
2666 GPortModel* endPort = connectModel->getEndPort();
2667 int endPortIndex = endPort->getPosInBox();
2669 GBlackBoxModel* startPortParentBox =
2670 (GBlackBoxModel*) startPort->getParentBox();
2671 GBlackBoxModel* endPortParentBox =
2672 (GBlackBoxModel*) endPort->getParentBox();
2674 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2675 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2677 GBlackBoxModel* newStartBox =
2678 (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
2679 GBlackBoxModel* newEndBox =
2680 (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
2682 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2683 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2685 // Creates connection
2686 int idCon = createGConnector(newStartPort);
2687 GConnectorController *tempp =
2688 (GConnectorController*) _controllers[idCon];
2689 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2690 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2691 tempp->endContourCreation();
2692 conMod->setEndPort(newEndPort);
2693 conView->updateStartEndPoints();
2696 /// the new selected boxes are the duplicate ones
2698 UnSelectBlackBoxes();
2699 for (int i = 0; i < newBoxesID.size(); i++) {
2700 _selectedObjects.push_back(newBoxesID.at(i));
2703 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
2704 int id = _selectedObjects[i];
2705 GObjectController* cont = _controllers[id];
2707 cont->getView()->setState(SELECTED);
2708 cont->getModel()->notifyObservers(_idManager);
2714 //=========================================================================
2716 int wxVtkSceneManager::getNumSelectedObjects() {
2717 return _selectedObjects.size();
2720 //=========================================================================
2722 std::map<int, GObjectController*> wxVtkSceneManager::getSelectedObjects() {
2723 std::map<int, GObjectController*> mapSelected;
2725 std::map<int, GObjectController*>::iterator it;
2726 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2727 GObjectController *cont = it->second;
2728 if (cont->getGObjectType() == GBLACKBOX && cont->getView()->getState()
2730 mapSelected[cont->getId()] = cont;
2734 std::map<int, GObjectController*>::iterator it2;
2735 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2) {
2736 GObjectController *cont = it2->second;
2737 if (cont->getGObjectType() == GCONNECTOR) {
2738 GConnectorModel* cmod = (GConnectorModel*) cont->getModel();
2739 GBoxModel* endPortParentBox = cmod->getEndPort()->getParentBox();
2740 GBoxModel* startPortParentBox =
2741 cmod->getStartPort()->getParentBox();
2743 std::map<int, GObjectController*>::iterator iterOBJ1 =
2744 mapSelected.find(startPortParentBox->getObjectId());
2745 std::map<int, GObjectController*>::iterator iterOBJ2 =
2746 mapSelected.find(endPortParentBox->getObjectId());
2748 if (iterOBJ1 != mapSelected.end() && iterOBJ2 != mapSelected.end()) {
2749 int ID = cont->getId();
2750 mapSelected[ID] = cont;
2757 //=========================================================================
2759 void wxVtkSceneManager::addObjects(std::map<int, GObjectController*> objectsMap) {
2761 std::map<int, int> oldIdNewIdBoxes;
2762 std::vector<int> connections;
2764 std::map<int, GObjectController*>::iterator it;
2765 for (it = objectsMap.begin(); it != objectsMap.end(); ++it) {
2766 GObjectController *cont = it->second;
2767 int type = cont->getGObjectType();
2769 if (type == GBLACKBOX) {
2771 double xInic, yInic, zInic;
2772 GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
2773 copyBox->getInicPoint(xInic, yInic, zInic);
2774 int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(),copyBox->getBBTKType());
2776 int idcB = copyBox->getObjectId();
2777 oldIdNewIdBoxes[idcB] = idBox;
2778 cont = _controllers[idBox];
2779 GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
2780 newbox->setInicPoint(xInic, yInic, zInic);
2781 int num = newbox->getNumInputPorts();
2782 for (int j = 0; j < num; j++)
2784 newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
2786 newbox->notifyObservers(_idManager);
2787 } else if (type == GCONNECTOR) {
2788 int idCon = cont->getId();
2789 connections.push_back(idCon);
2794 for (int i = 0; i < (int) connections.size(); i++) {
2795 int objId = connections[i];
2796 GObjectController *cont = objectsMap[objId];
2797 GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
2799 GPortModel* startPort = connectModel->getStartPort();
2800 int startPortIndex = startPort->getPosInBox();
2801 GPortModel* endPort = connectModel->getEndPort();
2802 int endPortIndex = endPort->getPosInBox();
2804 GBlackBoxModel* startPortParentBox =
2805 (GBlackBoxModel*) startPort->getParentBox();
2806 GBlackBoxModel* endPortParentBox =
2807 (GBlackBoxModel*) endPort->getParentBox();
2809 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2810 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2812 GBlackBoxModel* newStartBox =
2813 (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
2814 GBlackBoxModel* newEndBox =
2815 (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
2817 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2818 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2820 // Creates connection
2821 int idCon = createGConnector(newStartPort);
2822 GConnectorController *tempp =
2823 (GConnectorController*) _controllers[idCon];
2824 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2825 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2826 tempp->endContourCreation();
2827 conMod->setEndPort(newEndPort);
2828 conView->updateStartEndPoints();
2831 std::map<int, int>::iterator itIds;
2832 for (itIds = oldIdNewIdBoxes.begin(); itIds != oldIdNewIdBoxes.end(); ++itIds) {
2833 int idOld = itIds->first;
2834 int idNew = itIds->second;
2836 GBlackBoxModel* oldBox =
2837 (GBlackBoxModel*) objectsMap[idOld]->getModel();
2838 GBlackBoxModel* newBox =
2839 (GBlackBoxModel*) _controllers[idNew]->getModel();
2841 std::vector<int> oldInputConnections = oldBox->getConnectedInputs();
2842 std::vector<int> oldOutputConnections = oldBox->getConnectedOutputs();
2843 std::vector<int> newInputConnections = newBox->getConnectedInputs();
2844 std::vector<int> newOutputConnections = newBox->getConnectedOutputs();
2846 for (int k = 0; k < (int) oldInputConnections.size(); k++) {
2848 //EED int toCreate=-1;
2849 for (int l = 0; l < (int) newInputConnections.size() && !exist; l++) {
2850 if (oldInputConnections[k] == newInputConnections[l]) {
2855 if (exist == false) {
2856 //Create complex input
2857 int posInBox = oldInputConnections[k];
2858 GPortModel* inputPort = oldBox->getInputPort(posInBox);
2859 std::string inputPortName = inputPort->getBBTKName();
2860 int idInputPort = createGComplexBoxInputPort(inputPortName);
2861 GObjectController *cont = _controllers[idInputPort];
2862 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2863 double xIn, yIn, zIn;
2864 inputPort->getInicPoint(xIn, yIn, zIn);
2866 cbmod->setInicPoint(xIn, yIn, zIn);
2867 cbmod->notifyObservers(_idManager);
2869 GPortModel* inputPortEnd = newBox->getInputPort(posInBox);
2871 // Creates connection
2872 int idCon = createGConnector(cbmod->getOutputPort(0));
2873 GConnectorController *tempp =
2874 (GConnectorController*) _controllers[idCon];
2875 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2876 vtkGConnectorView *conView =
2877 (vtkGConnectorView*) tempp->getView();
2878 tempp->endContourCreation();
2879 conMod->setEndPort(inputPortEnd);
2880 conView->updateStartEndPoints();
2886 for (int k = 0; k < (int) oldOutputConnections.size(); k++) {
2888 //EED int toCreate=-1;
2889 for (int l = 0; l < (int) newOutputConnections.size() && !exist; l++) {
2890 if (oldOutputConnections[k] == newOutputConnections[l]) {
2895 if (exist == false) {
2896 //Create complex output
2897 int posInBox = oldOutputConnections[k];
2898 GPortModel* outputPort = oldBox->getOutputPort(posInBox);
2899 std::string outputPortName = outputPort->getBBTKName();
2900 int idOutputPort = createGComplexBoxOutputPort(outputPortName);
2901 GObjectController *cont = _controllers[idOutputPort];
2902 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2903 double xIn, yIn, zIn;
2904 outputPort->getInicPoint(xIn, yIn, zIn);
2906 cbmod->setInicPoint(xIn, yIn, zIn);
2907 cbmod->notifyObservers(_idManager);
2909 GPortModel* outputPortEnd = newBox->getOutputPort(posInBox);
2911 // Creates connection
2912 int idCon = createGConnector(outputPortEnd);
2913 GConnectorController *tempp =
2914 (GConnectorController*) _controllers[idCon];
2915 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2916 vtkGConnectorView *conView =
2917 (vtkGConnectorView*) tempp->getView();
2918 tempp->endContourCreation();
2919 conMod->setEndPort(cbmod->getInputPort(0));
2920 conView->updateStartEndPoints();
2930 //=========================================================================
2931 void wxVtkSceneManager::SetCbName(std::string cbName) {
2933 if (_cbName == "") {
2934 _cbName = "<complex box name>";
2938 //=========================================================================
2939 std::string wxVtkSceneManager::GetCbName() {
2943 //=========================================================================
2944 void wxVtkSceneManager::SetCbPackageName(std::string packagename) {
2945 _cbPackageName = packagename;
2946 if (_cbPackageName == "") {
2947 _cbPackageName = "<package name of the complex box>";
2951 //=========================================================================
2952 std::string wxVtkSceneManager::GetCbPackageName() {
2953 return _cbPackageName;
2956 //=========================================================================
2957 void wxVtkSceneManager::SetAuthor(std::string author) {
2959 if (_Author == "") {
2960 _Author = "<author of the box>";
2964 //=========================================================================
2965 std::string wxVtkSceneManager::GetAuthor() {
2969 //=========================================================================
2970 void wxVtkSceneManager::SetCategory(std::string category) {
2971 _Category = category;
2972 if (_Category == "") {
2973 _Category = "<category of the box>";
2977 //=========================================================================
2978 std::string wxVtkSceneManager::GetCategory() {
2982 //=========================================================================
2983 void wxVtkSceneManager::SetDescription(std::string description) {
2984 _Description = description;
2985 if (_Description == "") {
2986 _Description = "<description of the box>";
2990 //=========================================================================
2991 std::string wxVtkSceneManager::GetDescription() {
2992 return _Description;
2995 //=========================================================================
2997 void wxVtkSceneManager::SetMessageKind(std::string kind) {
2998 _MessageKind = kind;
3002 //=========================================================================
3004 std::string wxVtkSceneManager::GetMessageKind(){
3005 return _MessageKind;
3008 //=========================================================================
3010 void wxVtkSceneManager::SetMessageLevel(std::string Level){
3011 _MessageLevel = Level;
3014 //=========================================================================
3016 std::string wxVtkSceneManager::GetMessageLevel(){
3017 return _MessageLevel;
3020 //=========================================================================
3022 std::vector< std::string> wxVtkSceneManager::GetExternalInputsNames()
3025 std::vector< std::string> extInputs;
3026 std::map<int, GObjectController*>::iterator it;
3027 for (it = _controllers.begin(); it != _controllers.end(); ++it)
3029 GObjectController *cont = it->second;
3030 if (cont->getGObjectType() == GCOMPLEXINPUTPORT)
3032 extInputs.push_back(cont->getModel()->getBBTKName());
3038 //=========================================================================
3042 void wxVtkSceneManager::printAll(int com , int sta ){
3044 int tmpState = sta ;
3045 if ( tmpState == NOTHING_HAPPENS ) {
3046 std::cout << "CONTROLER STATE---->NOTHING_HAPPENS\n" ;
3048 if ( tmpState == HIGHLIGHTED ) {
3049 std::cout << "CONTROLER STATE---->HIGHLIGHTED\n" ;
3051 if ( tmpState == POSSIBLE_CONNECTION ) {
3052 std::cout << "CONTROLER STATE---->POSSIBLE_CONNECTION\n" ;
3054 if ( tmpState == SELECTED_POSSIBLE_CONNECTION ) {
3055 std::cout << "CONTROLER STATE---->SELECTED_POSSIBLE_CONNECTION\n" ;
3057 if ( tmpState == CLICKED ) {
3058 std::cout << "CONTROLER STATE---->CLICKED\n" ;
3060 if ( tmpState == DRAG ) {
3061 std::cout << "CONTROLER STATE---->DRAG\n" ;
3063 if ( tmpState == SELECTED ) {
3064 std::cout << "CONTROLER STATE---->SELECTED\n" ;
3066 if ( tmpState == CREATING_CONTOUR ) {
3067 std::cout << "CONTROLER STATE---->CREATING_CONTOUR\n" ;
3073 if ( command == INIT_CREATION_CONTOUR ) {
3074 std::cout << "COMMAND ----> INIT_CREATION_CONTOUR \n" ;
3076 if ( command == FIN_CREATION_CONTOUR ) {
3077 std::cout << "COMMAND ----> FIN_CREATION_CONTOUR \n" ;
3079 if ( command == ADD_TO_SELECTED ) {
3080 std::cout << "COMMAND ----> ADD_TO_SELECTED \n" ;
3082 if ( command == DRAG_OBJECTS ) {
3083 std::cout << "COMMAND ----> DRAG_OBJECTS \n" ;
3085 if ( command == EDIT_BLACKBOX ) {
3086 std::cout << "COMMAND ----> EDIT_BLACKBOX \n" ;
3088 if ( command == REMOVE_FROM_SELECTED ) {
3089 std::cout << "COMMAND ----> REMOVE_FROM_SELECTED \n" ;
3095 } // EO namespace bbtk