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();
1542 script += model->getBBTKName();
1551 //=========================================================================
1553 std::string wxVtkSceneManager::saveComplexBoxBBS() {
1554 std::cout<<"wxVtkSceneManager::saveComplexBoxBBS"<<std::endl;
1555 std::vector<std::string> packages;
1556 std::vector<int> boxes;
1557 std::vector<int> connections;
1558 std::vector<int> execBoxes;
1560 std::map<int, GObjectController*>::iterator it;
1562 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1563 GObjectController *desc = it->second;
1564 int type = desc->getGObjectType();
1566 if (type == GBLACKBOX) {
1567 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
1569 std::string pkg = mod->getBBTKPackage();
1570 bool existsPkg = false;
1571 for (int t = 0; t < (int) packages.size() && existsPkg == false; t++) {
1572 if (packages[t] == pkg) {
1577 packages.push_back(pkg);
1580 boxes.push_back(it->first);
1581 if (mod->isExecutable()) {
1582 execBoxes.push_back(it->first);
1584 } else if (type == GCONNECTOR) {
1585 connections.push_back(it->first);
1589 std::string script = "";
1591 script += "include std\n"; // EED
1592 script += "include itkvtk\n"; // EED
1594 for (i = 0; i < (int) packages.size(); i++) {
1595 script += "include ";
1596 script += packages[i];
1601 // Definition of a complex box
1602 script += "define ";
1603 script += _cbName + " " + _cbPackageName;
1607 script += "author \"";
1611 script += "description \"";
1612 script += _Description;
1616 script += "category \"";
1617 script += _Category;
1622 for (i = 0; i < (int) boxes.size(); i++) {
1625 GObjectController *control = _controllers[id];
1626 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1628 script += model->getBBTKPackage()+":";
1629 script += model->getBBTKType();
1631 script += model->getBBTKName();
1634 std::vector<GPortModel*> inputs = model->getInputPorts();
1635 for (int j = 0; j < (int) inputs.size(); j++) {
1636 GPortModel* inputPort = inputs[j];
1637 if (inputPort->isValueSet()) {
1639 script += model->getBBTKName();
1641 script += inputPort->getBBTKName();
1643 script += inputPort->getValue();
1651 // Create connections in the script. If the connection is made with a complex port, it is created the input or output
1653 std::string complexInputs = "";
1654 std::string complexOutputs = "";
1657 for (i = 0; i < (int) connections.size(); i++) {
1658 int id = connections[i];
1659 GObjectController *control = _controllers[id];
1660 GConnectorModel *model = (GConnectorModel*) control->getModel();
1663 GPortModel *start = model->getStartPort();
1664 GBoxModel *startBox = start->getParentBox();
1666 GPortModel *end = model->getEndPort();
1667 GBoxModel *endBox = end->getParentBox();
1669 if (startBox->getGObjectType() == GCOMPLEXINPUTPORT) {
1670 complexInputs += "input ";
1671 complexInputs += startBox->getBBTKName();
1673 complexInputs += " ";
1674 complexInputs += endBox->getBBTKName();
1675 complexInputs += ".";
1676 complexInputs += end->getBBTKName();
1678 complexInputs += " ";
1679 complexInputs += "\" \"";
1681 complexInputs += "\n";
1682 } else if (endBox->getGObjectType() == GCOMPLEXOUTPUTPORT) {
1683 complexOutputs += "output ";
1684 complexOutputs += endBox->getBBTKName();
1686 complexOutputs += " ";
1687 complexOutputs += startBox->getBBTKName();
1688 complexOutputs += ".";
1689 complexOutputs += start->getBBTKName();
1691 complexOutputs += " ";
1692 complexOutputs += "\" \"";
1694 complexOutputs += "\n";
1696 script += "connect ";
1697 script += startBox->getBBTKName();
1699 script += start->getBBTKName();
1703 //End Connection info
1704 script += endBox->getBBTKName();
1706 script += end->getBBTKName();
1713 script += "# Complex input ports\n";
1714 script += complexInputs;
1717 script += "# Complex output ports\n";
1718 script += complexOutputs;
1722 if((_MessageKind!="-")&&(_MessageLevel!="-"))
1724 script += "message ";
1725 script += _MessageKind;
1727 script += _MessageLevel;
1731 for (i = 0; i < (int) execBoxes.size(); i++)
1734 int id = execBoxes[i];
1735 GObjectController *control = _controllers[id];
1736 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1738 script += model->getBBTKName();
1743 script += "endefine";
1749 //=========================================================================
1751 void wxVtkSceneManager::deleteAllBoxes() {
1752 std::map<int, GObjectController*>::iterator it;
1753 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1754 GObjectController *cont = it->second;
1755 cont->removeFromScene();
1756 unregisterController((InteractorStyleMaracas*) cont);
1758 _selectedObjects.clear();
1759 _controllers.clear();
1762 //=========================================================================
1765 void wxVtkSceneManager::refresh() {
1766 _baseView->Refresh();
1768 //=========================================================================
1770 void wxVtkSceneManager::refreshScene()
1772 _baseView->RefreshView();
1775 //=========================================================================
1777 void wxVtkSceneManager::centerView()
1780 _baseView->GetRenderer()->ComputeVisiblePropBounds(bb);
1783 _baseView->GetRenderer()->GetActiveCamera()->GetFocalPoint(temp);
1784 _baseView->GetRenderer()->GetActiveCamera()->SetFocalPoint(0, 0, temp[2]);
1785 _baseView->GetRenderer()->GetActiveCamera()->GetPosition(temp);
1786 _baseView->GetRenderer()->GetActiveCamera()->SetPosition(0, 0, temp[2]);
1788 _baseView->GetRenderer()->ResetCamera();
1789 _baseView->GetRenderer()->ResetCameraClippingRange();
1792 double tt=_baseView->GetRenderer()->GetNearClippingPlaneTolerance();
1793 printf("EED wxVtkSceneManager::centerView() tolerance=%f\n",tt);
1795 _baseView->GetRenderer()->GetActiveCamera()->GetClippingRange(cr1,cr2);
1796 printf("EED wxVtkSceneManager::centerView() cr1=%f cr2=%f\n",cr1,cr2);
1797 _baseView->GetRenderer()->GetActiveCamera()->SetClippingRange(0.01,100000);
1798 _baseView->GetRenderer()->GetActiveCamera()->GetClippingRange(cr1,cr2);
1799 printf("EED wxVtkSceneManager::centerView() cr1=%f cr2=%f\n",cr1,cr2);
1802 _baseView->GetRenderer()->Render();
1805 //=========================================================================
1807 void wxVtkSceneManager::saveDiagram(std::string &content)
1811 content += "CATEGORY:";
1812 content += GetCategory();
1815 content += "DESCRIPTION:";
1816 content += GetDescription();
1819 content += "AUTHOR:";
1820 content += GetAuthor();
1823 //Print info IF COMPLEX BOX
1824 content += "COMPLEXBOX:";
1825 if (_isComplexBox) {
1826 content += "TRUE\n";
1828 content += "COMPLEXBOXNAME:";
1829 content += GetCbName();
1832 content += "PACKAGENAME:";
1833 content += GetCbPackageName();
1836 /* CHANGE TO THE VERSION 1.4 RaC2012 2nd HackFest
1837 * External inputs are possible for applications and complex boxes
1838 //Print info complex input ports
1839 std::vector<int> inputs = getComplexInputPorts();
1840 int insize = inputs.size();
1841 content += "COMPLEXINPUTS:";
1842 sprintf(buffer, "%d", insize);
1846 for (int i = 0; i < insize; i++) {
1848 GObjectController *cont = _controllers[id];
1849 cont->getModel()->save(content);
1853 //Print info complex output ports
1854 std::vector<int> outputs = getComplexOutputPorts();
1855 int outsize = outputs.size();
1856 content += "COMPLEXOUTPUTS:";
1857 sprintf(buffer, "%d", outsize);
1861 for (int i = 0; i < outsize; i++) {
1862 int id = outputs[i];
1863 GObjectController *cont = _controllers[id];
1864 cont->getModel()->save(content);
1868 content += "FALSE\n";
1871 // CHANGE TO THE VERSION 1.4 RaC2012 2nd HackFest
1872 // External inputs are possible for applications and complex boxes
1873 std::vector<int> inputs = getComplexInputPorts();
1874 int insize = inputs.size();
1875 content += "COMPLEXINPUTS:";
1876 sprintf(buffer, "%d", insize);
1880 for (int i = 0; i < insize; i++) {
1882 GObjectController *cont = _controllers[id];
1883 cont->getModel()->save(content);
1887 std::vector<int> boxes = getBlackBoxes();
1888 int bsize = boxes.size();
1889 content += "BOXES:";
1890 sprintf(buffer, "%d", bsize);
1894 for (int i = 0; i < bsize; i++) {
1896 // std::cout<<"id "<<id<<std::endl;//CFT
1897 GObjectController *cont = _controllers[id];
1898 // std::cout<<"nombre: "<<cont->getStatusText()<<std::endl;//CFT
1899 // std::cout<<"tipo: "<<cont->getModel()->getBBTKType()<<std::endl;//CFT
1900 // //boxesDiagram[i] = cont->getModel()->getBBTKType();//CFT
1901 // std::cout<<"nname: "<<cont->getModel()->getBBTKName()<<std::endl;//CFT
1902 // std::cout<<"categorie: "<<GetCategory()<<std::endl;//CFT
1903 // std::cout<<"type: "<<cont->getModel()->getGObjectType()<<std::endl;//CFT
1904 cont->getModel()->save(content);
1908 std::vector<int> connections = getConnections();
1909 int csize = connections.size();
1910 content += "CONNECTIONS:";
1911 sprintf(buffer, "%d", csize);
1915 for (int i = 0; i < csize; i++) {
1916 int id = connections[i];
1917 GObjectController *cont = _controllers[id];
1918 cont->getModel()->save(content);
1923 //=========================================================================
1924 void wxVtkSceneManager::getCleanLine(stringstream &inputStream, std::string &line)
1926 getline(inputStream, line,'\n');
1927 int size = line.length();
1930 if ( line[ size-1 ]==13 )
1932 line.erase(size-1,1);
1937 //=========================================================================
1938 void wxVtkSceneManager::loadDiagram(stringstream &inputStream)
1941 std::string version = "<void>";
1942 std::string line = "";
1943 char delims[] = ":";
1944 char *result = NULL;
1945 char poort[POORT_MAX_LINE_SIZE_INTERPRETER];
1947 getCleanLine(inputStream, line);
1950 while (!inputStream.eof()) {
1951 if (line == "" || line[0] == '#') {
1953 getCleanLine(inputStream, line);
1955 if (line == "# - BBTKGEditor v 1.0 BBG BlackBox Diagram file") {
1956 version = line.substr(18, 3);
1958 if (line == "# - BBTKGEditor v 1.1 BBG BlackBox Diagram file") {
1959 version = line.substr(18, 3);
1961 if (line == "# - BBTKGEditor v 1.2 BBG BlackBox Diagram file") {
1962 version = line.substr(18, 3);
1964 if (line == "# - BBTKGEditor v 1.3 BBG BlackBox Diagram file") {
1965 version = line.substr(18, 3);
1967 if (line == "# - BBTKGEditor v 1.4 BBG BlackBox Diagram file") {
1968 version = line.substr(18, 3);
1970 if (line == "# - BBTKGEditor v 1.5 BBG BlackBox Diagram file") {
1971 version = line.substr(18, 3);
1973 } else if (line == "APP_START") {
1983 if ((version != "1.0") && (version != "1.1")) {
1984 getCleanLine(inputStream, line);//CATEGORY:<category of the box>
1985 char categoryTmp[30];
1986 strcpy(categoryTmp, line.c_str());
1987 result = strtok(categoryTmp, delims);
1988 result = strtok(NULL, delims);
1989 SetCategory(result);
1991 getCleanLine(inputStream, line);//DESCRIPTION:<description of the box>
1992 char descriptionTmp[1024];
1993 strcpy(descriptionTmp, line.c_str());
1994 result = strtok(descriptionTmp, delims);
1995 result = strtok(NULL, delims);
1996 SetDescription(result);
1998 getCleanLine(inputStream, line);//AUTHOR:<author>
1999 char authorTmp[255];
2000 strcpy(authorTmp, line.c_str());
2001 result = strtok(authorTmp, delims);
2002 result = strtok(NULL, delims);
2007 getCleanLine(inputStream, line);//COMPLEX_BOX:TRUE|FALSE
2008 char complexTmp[30];
2009 strcpy(complexTmp, line.c_str());
2010 result = strtok(complexTmp, delims);
2011 result = strtok(NULL, delims);
2012 std::string isComplexBox(result);
2014 if (isComplexBox == "TRUE")
2016 _isComplexBox = true;
2018 if ((version != "1.0") && (version != "1.1"))
2020 getCleanLine(inputStream, line);//COMPLEXNAME:<name of the complex box>
2021 char complexboxnameTmp[255];
2022 strcpy(complexboxnameTmp, line.c_str());
2023 result = strtok(complexboxnameTmp, delims);
2024 result = strtok(NULL, delims);
2027 getCleanLine(inputStream, line);//PACKAGENAME:<name of the package of the box>
2028 char packagenameTmp[255];
2029 strcpy(packagenameTmp, line.c_str());
2030 result = strtok(packagenameTmp, delims);
2031 result = strtok(NULL, delims);
2032 SetCbPackageName(result);
2033 } // if version !1.0 !1.1
2037 //-----------------------
2038 //- COMPLEX INPUT PORTS
2039 //-----------------------
2040 getCleanLine(inputStream, line);//COMPLEXINPUTS:num
2042 strcpy(inputs, line.c_str());
2043 result = strtok(inputs, delims);
2044 result = strtok(NULL, delims);
2047 std::istringstream inps(result);
2050 for (int i = 0; i < numInputs; i++)
2053 getCleanLine(inputStream, line);//COMPLEX_PORT
2054 getCleanLine(inputStream, line);//name
2055 std::string inputPortName(line);
2058 getCleanLine(inputStream, line);//xInic:yInic:zInic
2060 strcpy(coord, line.c_str());
2061 result = strtok(coord, delims);//xInic
2062 std::string xInic(result);
2063 result = strtok(NULL, delims);//yInic
2064 std::string yInic(result);
2065 result = strtok(NULL, delims);//zInic
2066 std::string zInic(result);
2068 double xIn, yIn, zIn;
2069 std::istringstream xSt(xInic);
2071 std::istringstream ySt(yInic);
2073 std::istringstream zSt(zInic);
2078 if (zIn==900) zIn=GPOSITION_Z;
2079 } // if version <=1.2
2081 getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
2083 configGComBoxInputOutputPort(true, inputPortName, xIn, yIn, zIn);
2085 } // for input complex box
2086 } // if version < 1.4
2090 //-----------------------
2091 //- COMPLEX OUTPUT PORTS
2092 //-----------------------
2094 getCleanLine(inputStream, line);//COMPLEXOUTPUTS:num
2096 strcpy(outputs, line.c_str());
2097 result = strtok(outputs, delims);
2098 result = strtok(NULL, delims);
2101 std::istringstream outps(result);
2102 outps >> numOutputs;
2104 for (int i = 0; i < numOutputs; i++)
2107 getCleanLine(inputStream, line);//COMPLEX_PORT
2108 getCleanLine(inputStream, line);//name
2109 std::string outputPortName(line);
2112 getCleanLine(inputStream, line);//xInic:yInic:zInic
2114 strcpy(coord, line.c_str());
2115 result = strtok(coord, delims);//xInic
2116 std::string xInic(result);
2117 result = strtok(NULL, delims);//yInic
2118 std::string yInic(result);
2119 result = strtok(NULL, delims);//zInic
2120 std::string zInic(result);
2122 double xIn, yIn, zIn;
2123 std::istringstream xSt(xInic);
2125 std::istringstream ySt(yInic);
2127 std::istringstream zSt(zInic);
2132 if (zIn==900) zIn=GPOSITION_Z;
2141 getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
2143 configGComBoxInputOutputPort(false, outputPortName, xIn, yIn, zIn);
2145 } // for output complex box
2146 } // if isComplexBox
2149 // RaC2012 2nd Hackfest
2150 if(version >= "1.4")
2152 //-----------------------
2153 //- EXTERNAL INPUT PORTS
2154 //-----------------------
2155 getCleanLine(inputStream, line);//COMPLEXINPUTS:num
2157 strcpy(inputs, line.c_str());
2158 result = strtok(inputs, delims);
2159 result = strtok(NULL, delims);
2162 std::istringstream inps(result);
2165 for (int i = 0; i < numInputs; i++)
2167 getCleanLine(inputStream, line);//COMPLEX_PORT
2168 getCleanLine(inputStream, line);//name
2169 std::string inputPortName(line);
2170 getCleanLine(inputStream, line);//xInic:yInic:zInic
2172 strcpy(coord, line.c_str());
2173 result = strtok(coord, delims);//xInic
2174 std::string xInic(result);
2175 result = strtok(NULL, delims);//yInic
2176 std::string yInic(result);
2177 result = strtok(NULL, delims);//zInic
2178 std::string zInic(result);
2179 double xIn, yIn, zIn;
2180 std::istringstream xSt(xInic);
2182 std::istringstream ySt(yInic);
2184 std::istringstream zSt(zInic);
2188 if (zIn==900) zIn=GPOSITION_Z;
2196 getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
2197 configGComBoxInputOutputPort(true, inputPortName, xIn, yIn, zIn);
2198 } // for external input
2199 } // if(version >= "1.4")
2202 getCleanLine(inputStream, line);//BOXES:num
2204 strcpy(boxes, line.c_str());
2205 result = strtok(boxes, delims);
2206 result = strtok(NULL, delims);
2209 std::istringstream is(result);
2212 for (int i = 0; i < numBoxes; i++)
2215 getCleanLine(inputStream, line);//BOX
2216 getCleanLine(inputStream, line);//package:type:name
2218 strcpy(box, line.c_str());
2219 result = strtok(box, delims);//package
2220 std::string package(result);
2221 result = strtok(NULL, delims);//type
2222 std::string type(result);
2223 result = strtok(NULL, delims);//name
2224 std::string name(result);
2227 getCleanLine(inputStream, line);//ISEXEC:TRUE|FALSE
2229 strcpy(exec, line.c_str());
2230 result = strtok(exec, delims);//ISEXEC
2231 result = strtok(NULL, delims);//TRUE|FALSE
2232 std::string isExec(result);
2235 getCleanLine(inputStream, line);//xInic:yInic:zInic
2237 strcpy(coord, line.c_str());
2238 result = strtok(coord, delims);//xInic
2239 std::string xInic(result);
2240 result = strtok(NULL, delims);//yInic
2241 std::string yInic(result);
2242 result = strtok(NULL, delims);//zInic
2243 std::string zInic(result);
2244 double xIn, yIn, zIn;
2245 std::istringstream xSt(xInic);
2247 std::istringstream ySt(yInic);
2249 std::istringstream zSt(zInic);
2254 if (zIn==900) zIn=GPOSITION_Z;
2263 getCleanLine(inputStream, line);//xEnd:yEnd:zEnd
2264 strcpy(coord, line.c_str());
2265 result = strtok(coord, delims);//xEnd
2266 std::string xEnd(result);
2267 result = strtok(NULL, delims);//yEnd
2268 std::string yEnd(result);
2269 result = strtok(NULL, delims);//zEnd
2270 std::string zEnd(result);
2272 double xEn, yEn, zEn;
2273 std::istringstream xEt(xEnd);
2275 std::istringstream yEt(yEnd);
2277 std::istringstream zEt(zEnd);
2282 if (zEn==900) zEn=GPOSITION_Z;
2285 yEn = yIn-BOX_HEIGHT;
2287 bool boxExecutable = false;
2288 if (isExec == "TRUE")
2290 boxExecutable = true;
2293 int idBox = createGBlackBox(xIn, yIn, package, type);
2294 configGBlackBox(idBox, xIn, yIn, zIn, name, boxExecutable, xEn, yEn, zEn);
2296 GObjectController *cont = _controllers[idBox];
2297 GBlackBoxModel *bbmod = (GBlackBoxModel*) cont->getModel();
2300 getCleanLine(inputStream, line);//PORT o FIN_BOX
2301 std::string port = line.substr(0, 4);
2302 while (port == "PORT")
2304 getCleanLine(inputStream, line);//name:value
2305 if (line.length()>=POORT_MAX_LINE_SIZE_INTERPRETER-1)
2307 line=line.substr(0, POORT_MAX_LINE_SIZE_INTERPRETER-1);
2310 strcpy(poort, line.c_str());
2311 result = strtok(poort, delims);//name
2312 std::string name(result);
2314 //EED 16 oct 2012 Adding at the end character " if necesary in the value definition
2315 result = strtok(NULL, delims);//value
2316 if (( result[0]=='"' ) && ( result[ strlen(result)-1 ]!='"' ) )
2318 std::string tmpString=" ";
2319 tmpString[0]=34; // character "
2320 strcat(result,tmpString.c_str());
2322 std::string value(result);
2323 bbmod->setValueToInput(name, value);
2324 getCleanLine(inputStream, line);//PORT o FIN_BOX
2325 port = line.substr(0, 4);
2328 //EED bbmod->notifyObservers(_idManager);
2333 getCleanLine(inputStream, line);//CONNECTIONS:num
2335 strcpy(conns, line.c_str());
2336 result = strtok(conns, delims);
2337 result = strtok(NULL, delims);
2339 std::istringstream isCons(result);
2343 for (int i = 0; i < numConns; i++)
2346 getCleanLine(inputStream, line);//CONNECTION
2347 getCleanLine(inputStream, line);//Startbox.PortName:EndBox.PortName
2349 strcpy(connec, line.c_str());
2350 result = strtok(connec, delims);
2351 std::string nameStartBox(result);
2352 result = strtok(NULL, delims);
2353 std::string nameStartPort(result);
2354 result = strtok(NULL, delims);
2355 std::string nameEndBox(result);
2356 result = strtok(NULL, delims);
2357 std::string nameEndPort(result);
2358 int idCon = configGConnetion(nameStartBox, nameStartPort,nameEndBox, nameEndPort);
2359 if (version != "1.0") {
2360 //Readding control points of the manualContour
2361 GConnectorController *tempp = (GConnectorController*) _controllers[idCon];
2362 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2363 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2364 getCleanLine(inputStream, line); //NumberOfControlPoints:##
2365 strcpy(conns, line.c_str());
2366 result = strtok(conns, delims);
2367 result = strtok(NULL, delims);
2368 int numberOfControlPoints;
2369 std::istringstream isCons(result);
2370 isCons >> numberOfControlPoints;
2371 for (int ii = 0; ii < numberOfControlPoints; ii++) {
2372 getCleanLine(inputStream, line); //XX:YY:ZZ
2374 strcpy(connec, line.c_str());
2376 result = strtok(connec, delims);
2377 std::istringstream isPointX(result);
2379 result = strtok(NULL, delims);
2380 std::istringstream isPointY(result);
2382 result = strtok(NULL, delims);
2383 std::istringstream isPointZ(result);
2387 if (pz==900) pz=GPOSITION_Z;
2395 conMod->getManualContourModel()->InsertPoint_id(ii + 1, px, py, pz);
2396 conView->getManualContourView()->AddPoint();
2398 }// if version !=1.0
2402 //=========================================================================
2405 //=========================================================================
2406 void wxVtkSceneManager::configGComBoxInputOutputPort(bool inputoutput,
2407 std::string portName, double xIn, double yIn, double zIn)
2410 if (inputoutput == true) {
2411 idPort = createGComplexBoxInputPort(portName);
2413 idPort = createGComplexBoxOutputPort(portName);
2415 GObjectController *cont = _controllers[idPort];
2416 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2417 cbmod->setInicPoint(xIn, yIn, zIn);
2418 cbmod->notifyObservers(_idManager);
2420 //=========================================================================
2423 //=========================================================================
2424 GBoxModel* wxVtkSceneManager::findGBox(std::string boxname)
2429 GBoxModel *boxModel = NULL;
2430 std::vector<int> lstB = getBlackBoxes();
2431 for (j = 0; j < (int) lstB.size(); j++) {
2433 bMod = (GBoxModel*) _controllers[idB]->getModel();
2434 if (_controllers[idB]->getModel()->getBBTKName() == boxname)
2442 if (boxModel == NULL) {
2443 std::vector<int> lstInputs = getComplexInputPorts();
2444 for (j = 0; j < (int) lstInputs.size(); j++) {
2446 bMod = (GBoxModel*) _controllers[idB]->getModel();
2447 if (_controllers[idB]->getModel()->getBBTKName() == boxname)
2455 std::vector<int> lstOutputs = getComplexOutputPorts();
2456 for (j = 0; j < (int) lstOutputs.size(); j++) {
2457 int idB = lstOutputs[j];
2458 bMod = (GBoxModel*) _controllers[idB]->getModel();
2459 if (_controllers[idB]->getModel()->getBBTKName() == boxname)
2471 //=========================================================================
2474 int wxVtkSceneManager::configGConnetion(std::string nameStartBox,
2475 std::string nameStartPort, std::string nameEndBox,
2476 std::string nameEndPort) {
2478 GBoxModel *boxModel;
2479 GPortModel *startP = NULL;
2480 GPortModel *endP = NULL;
2482 boxModel = findGBox(nameStartBox);
2483 if(boxModel == NULL)
2485 printf("RaC: ERROR in wxVtkSceneManager::configGConnetion A box to connect start port %s is null. Box name is probably wrong.\n", nameStartPort.c_str());
2487 if (boxModel != NULL) {
2488 startP = boxModel->getOutputPort(nameStartPort);
2490 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() );
2494 boxModel = findGBox(nameEndBox);
2495 if(boxModel == NULL)
2497 printf("RaC: ERROR in wxVtkSceneManager::configGConnetion A box to connect start port %s is null. Box name is probably wrong.\n", nameStartPort.c_str());
2499 if (boxModel != NULL) {
2500 endP = boxModel->getInputPort(nameEndPort);
2502 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());
2507 int idCon = createGConnector(startP);
2509 _worldState = NOTHING_HAPPENS;
2510 GConnectorController *tempp = (GConnectorController*) _controllers[idCon];
2512 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2513 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2514 tempp->endContourCreation();
2515 conMod->setEndPort(endP);
2516 conView->updateStartEndPoints();
2520 //=========================================================================
2522 bool wxVtkSceneManager::boxExist(std::string boxname) {
2524 std::map<int, GObjectController*>::iterator it;
2525 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2526 GObjectController *cont = it->second;
2527 if (cont->getModel()->getBBTKName() == boxname) {
2534 //=========================================================================
2536 std::vector<int> wxVtkSceneManager::getBlackBoxes() {
2537 std::vector<int> vect;
2538 std::map<int, GObjectController*>::iterator it;
2539 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2540 GObjectController *cont = it->second;
2541 if (cont->getGObjectType() == GBLACKBOX) {
2542 vect.push_back(cont->getId());
2548 //=========================================================================
2550 std::vector<int> wxVtkSceneManager::getComplexInputPorts() {
2551 std::vector<int> vect;
2552 std::map<int, GObjectController*>::iterator it;
2553 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2554 GObjectController *cont = it->second;
2555 if (cont->getGObjectType() == GCOMPLEXINPUTPORT) {
2556 vect.push_back(cont->getId());
2562 //=========================================================================
2564 std::vector<int> wxVtkSceneManager::getComplexOutputPorts() {
2565 std::vector<int> vect;
2566 std::map<int, GObjectController*>::iterator it;
2567 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2568 GObjectController *cont = it->second;
2569 if (cont->getGObjectType() == GCOMPLEXOUTPUTPORT) {
2570 vect.push_back(cont->getId());
2576 //=========================================================================
2578 std::vector<int> wxVtkSceneManager::getConnections() {
2579 std::vector<int> vect;
2580 std::map<int, GObjectController*>::iterator it;
2581 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2582 GObjectController *cont = it->second;
2583 if (cont->getGObjectType() == GCONNECTOR) {
2584 vect.push_back(cont->getId());
2590 //=========================================================================
2592 bool wxVtkSceneManager::isComplexBox() {
2593 return _isComplexBox;
2596 //=========================================================================
2598 void wxVtkSceneManager::setComplexBox(bool val) {
2599 _isComplexBox = val;
2602 //=========================================================================
2604 int wxVtkSceneManager::addObjectController(GObjectController* objController) {
2605 //Register the controller of the new object
2606 registerController((InteractorStyleMaracas*) objController);
2607 //Add the object to the objects list
2608 int newId = _contLastId;//_controllers.size();
2609 objController->setId(newId);
2610 _controllers[newId] = objController;
2611 //std::cout << "DFCH: int wxVtkSceneManager::addObjectController(GObjectController* objController) ---- _contLastId = " << _contLastId << std::endl;
2616 //=========================================================================
2618 void wxVtkSceneManager::DuplicateObjects(std::map<int, GObjectController*> objectsMap)
2620 std::map<int, int> oldIdNewIdBoxes;
2621 std::vector<int> connections;
2622 std::vector<int> newBoxesID;
2623 std::map<int, GObjectController*>::iterator it;
2624 for (it = objectsMap.begin(); it != objectsMap.end(); ++it)
2626 GObjectController *cont = it->second;
2627 int type = cont->getGObjectType();
2628 if (type == GBLACKBOX)
2631 double xInic, yInic, zInic;
2632 GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
2633 copyBox->getInicPoint(xInic, yInic, zInic);
2634 int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(), copyBox->getBBTKType());
2636 int idcB = copyBox->getObjectId();
2637 oldIdNewIdBoxes[idcB] = idBox;
2638 cont = _controllers[idBox];
2639 GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
2640 newbox->setInicPoint(xInic, yInic, zInic);
2641 int num = newbox->getNumInputPorts();
2642 for (int j = 0; j < num; j++)
2644 newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
2648 // newbox->move(xInic + 20, yInic + 20, zInic);
2649 newbox->move(xInic + 14, yInic + 6, zInic);
2651 newbox->notifyObservers(_idManager);
2652 newBoxesID.push_back(newbox->getObjectId());
2654 } else if (type == GCONNECTOR) {
2655 int idCon = cont->getId();
2656 connections.push_back(idCon);
2661 for (int i = 0; i < (int) connections.size(); i++)
2663 int objId = connections[i];
2664 GObjectController *cont = objectsMap[objId];
2665 GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
2667 GPortModel* startPort = connectModel->getStartPort();
2668 int startPortIndex = startPort->getPosInBox();
2669 GPortModel* endPort = connectModel->getEndPort();
2670 int endPortIndex = endPort->getPosInBox();
2672 GBlackBoxModel* startPortParentBox =
2673 (GBlackBoxModel*) startPort->getParentBox();
2674 GBlackBoxModel* endPortParentBox =
2675 (GBlackBoxModel*) endPort->getParentBox();
2677 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2678 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2680 GBlackBoxModel* newStartBox =
2681 (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
2682 GBlackBoxModel* newEndBox =
2683 (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
2685 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2686 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2688 // Creates connection
2689 int idCon = createGConnector(newStartPort);
2690 GConnectorController *tempp =
2691 (GConnectorController*) _controllers[idCon];
2692 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2693 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2694 tempp->endContourCreation();
2695 conMod->setEndPort(newEndPort);
2696 conView->updateStartEndPoints();
2699 /// the new selected boxes are the duplicate ones
2701 UnSelectBlackBoxes();
2702 for (int i = 0; i < newBoxesID.size(); i++)
2704 _selectedObjects.push_back(newBoxesID.at(i));
2707 for (int i = 0; i < (int) _selectedObjects.size(); i++)
2709 int id = _selectedObjects[i];
2710 GObjectController* cont = _controllers[id];
2711 cont->getView()->setState(SELECTED);
2712 cont->getModel()->notifyObservers(_idManager);
2717 //=========================================================================
2719 int wxVtkSceneManager::getNumSelectedObjects() {
2720 return _selectedObjects.size();
2723 //=========================================================================
2725 std::map<int, GObjectController*> wxVtkSceneManager::getSelectedObjects() {
2726 std::map<int, GObjectController*> mapSelected;
2728 std::map<int, GObjectController*>::iterator it;
2729 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2730 GObjectController *cont = it->second;
2731 if (cont->getGObjectType() == GBLACKBOX && cont->getView()->getState()
2733 mapSelected[cont->getId()] = cont;
2737 std::map<int, GObjectController*>::iterator it2;
2738 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2) {
2739 GObjectController *cont = it2->second;
2740 if (cont->getGObjectType() == GCONNECTOR) {
2741 GConnectorModel* cmod = (GConnectorModel*) cont->getModel();
2742 GBoxModel* endPortParentBox = cmod->getEndPort()->getParentBox();
2743 GBoxModel* startPortParentBox =
2744 cmod->getStartPort()->getParentBox();
2746 std::map<int, GObjectController*>::iterator iterOBJ1 =
2747 mapSelected.find(startPortParentBox->getObjectId());
2748 std::map<int, GObjectController*>::iterator iterOBJ2 =
2749 mapSelected.find(endPortParentBox->getObjectId());
2751 if (iterOBJ1 != mapSelected.end() && iterOBJ2 != mapSelected.end()) {
2752 int ID = cont->getId();
2753 mapSelected[ID] = cont;
2760 //=========================================================================
2762 void wxVtkSceneManager::addObjects(std::map<int, GObjectController*> objectsMap) {
2764 std::map<int, int> oldIdNewIdBoxes;
2765 std::vector<int> connections;
2767 std::map<int, GObjectController*>::iterator it;
2768 for (it = objectsMap.begin(); it != objectsMap.end(); ++it) {
2769 GObjectController *cont = it->second;
2770 int type = cont->getGObjectType();
2772 if (type == GBLACKBOX) {
2774 double xInic, yInic, zInic;
2775 GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
2776 copyBox->getInicPoint(xInic, yInic, zInic);
2777 int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(),copyBox->getBBTKType());
2779 int idcB = copyBox->getObjectId();
2780 oldIdNewIdBoxes[idcB] = idBox;
2781 cont = _controllers[idBox];
2782 GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
2783 newbox->setInicPoint(xInic, yInic, zInic);
2784 int num = newbox->getNumInputPorts();
2785 for (int j = 0; j < num; j++)
2787 newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
2789 newbox->notifyObservers(_idManager);
2790 } else if (type == GCONNECTOR) {
2791 int idCon = cont->getId();
2792 connections.push_back(idCon);
2797 for (int i = 0; i < (int) connections.size(); i++) {
2798 int objId = connections[i];
2799 GObjectController *cont = objectsMap[objId];
2800 GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
2802 GPortModel* startPort = connectModel->getStartPort();
2803 int startPortIndex = startPort->getPosInBox();
2804 GPortModel* endPort = connectModel->getEndPort();
2805 int endPortIndex = endPort->getPosInBox();
2807 GBlackBoxModel* startPortParentBox =
2808 (GBlackBoxModel*) startPort->getParentBox();
2809 GBlackBoxModel* endPortParentBox =
2810 (GBlackBoxModel*) endPort->getParentBox();
2812 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2813 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2815 GBlackBoxModel* newStartBox =
2816 (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
2817 GBlackBoxModel* newEndBox =
2818 (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
2820 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2821 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2823 // Creates connection
2824 int idCon = createGConnector(newStartPort);
2825 GConnectorController *tempp =
2826 (GConnectorController*) _controllers[idCon];
2827 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2828 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2829 tempp->endContourCreation();
2830 conMod->setEndPort(newEndPort);
2831 conView->updateStartEndPoints();
2834 std::map<int, int>::iterator itIds;
2835 for (itIds = oldIdNewIdBoxes.begin(); itIds != oldIdNewIdBoxes.end(); ++itIds) {
2836 int idOld = itIds->first;
2837 int idNew = itIds->second;
2839 GBlackBoxModel* oldBox =
2840 (GBlackBoxModel*) objectsMap[idOld]->getModel();
2841 GBlackBoxModel* newBox =
2842 (GBlackBoxModel*) _controllers[idNew]->getModel();
2844 std::vector<int> oldInputConnections = oldBox->getConnectedInputs();
2845 std::vector<int> oldOutputConnections = oldBox->getConnectedOutputs();
2846 std::vector<int> newInputConnections = newBox->getConnectedInputs();
2847 std::vector<int> newOutputConnections = newBox->getConnectedOutputs();
2849 for (int k = 0; k < (int) oldInputConnections.size(); k++) {
2851 //EED int toCreate=-1;
2852 for (int l = 0; l < (int) newInputConnections.size() && !exist; l++) {
2853 if (oldInputConnections[k] == newInputConnections[l]) {
2858 if (exist == false) {
2859 //Create complex input
2860 int posInBox = oldInputConnections[k];
2861 GPortModel* inputPort = oldBox->getInputPort(posInBox);
2862 std::string inputPortName = inputPort->getBBTKName();
2863 int idInputPort = createGComplexBoxInputPort(inputPortName);
2864 GObjectController *cont = _controllers[idInputPort];
2865 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2866 double xIn, yIn, zIn;
2867 inputPort->getInicPoint(xIn, yIn, zIn);
2869 cbmod->setInicPoint(xIn, yIn, zIn);
2870 cbmod->notifyObservers(_idManager);
2872 GPortModel* inputPortEnd = newBox->getInputPort(posInBox);
2874 // Creates connection
2875 int idCon = createGConnector(cbmod->getOutputPort(0));
2876 GConnectorController *tempp =
2877 (GConnectorController*) _controllers[idCon];
2878 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2879 vtkGConnectorView *conView =
2880 (vtkGConnectorView*) tempp->getView();
2881 tempp->endContourCreation();
2882 conMod->setEndPort(inputPortEnd);
2883 conView->updateStartEndPoints();
2889 for (int k = 0; k < (int) oldOutputConnections.size(); k++) {
2891 //EED int toCreate=-1;
2892 for (int l = 0; l < (int) newOutputConnections.size() && !exist; l++) {
2893 if (oldOutputConnections[k] == newOutputConnections[l]) {
2898 if (exist == false) {
2899 //Create complex output
2900 int posInBox = oldOutputConnections[k];
2901 GPortModel* outputPort = oldBox->getOutputPort(posInBox);
2902 std::string outputPortName = outputPort->getBBTKName();
2903 int idOutputPort = createGComplexBoxOutputPort(outputPortName);
2904 GObjectController *cont = _controllers[idOutputPort];
2905 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2906 double xIn, yIn, zIn;
2907 outputPort->getInicPoint(xIn, yIn, zIn);
2909 cbmod->setInicPoint(xIn, yIn, zIn);
2910 cbmod->notifyObservers(_idManager);
2912 GPortModel* outputPortEnd = newBox->getOutputPort(posInBox);
2914 // Creates connection
2915 int idCon = createGConnector(outputPortEnd);
2916 GConnectorController *tempp =
2917 (GConnectorController*) _controllers[idCon];
2918 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2919 vtkGConnectorView *conView =
2920 (vtkGConnectorView*) tempp->getView();
2921 tempp->endContourCreation();
2922 conMod->setEndPort(cbmod->getInputPort(0));
2923 conView->updateStartEndPoints();
2933 //=========================================================================
2934 void wxVtkSceneManager::SetCbName(std::string cbName) {
2936 if (_cbName == "") {
2937 _cbName = "<complex box name>";
2941 //=========================================================================
2942 std::string wxVtkSceneManager::GetCbName() {
2946 //=========================================================================
2947 void wxVtkSceneManager::SetCbPackageName(std::string packagename) {
2948 _cbPackageName = packagename;
2949 if (_cbPackageName == "") {
2950 _cbPackageName = "<package name of the complex box>";
2954 //=========================================================================
2955 std::string wxVtkSceneManager::GetCbPackageName() {
2956 return _cbPackageName;
2959 //=========================================================================
2960 void wxVtkSceneManager::SetAuthor(std::string author) {
2962 if (_Author == "") {
2963 _Author = "<author of the box>";
2967 //=========================================================================
2968 std::string wxVtkSceneManager::GetAuthor() {
2972 //=========================================================================
2973 void wxVtkSceneManager::SetCategory(std::string category) {
2974 _Category = category;
2975 if (_Category == "") {
2976 _Category = "<category of the box>";
2980 //=========================================================================
2981 std::string wxVtkSceneManager::GetCategory() {
2985 //=========================================================================
2986 void wxVtkSceneManager::SetDescription(std::string description) {
2987 _Description = description;
2988 if (_Description == "") {
2989 _Description = "<description of the box>";
2993 //=========================================================================
2994 std::string wxVtkSceneManager::GetDescription() {
2995 return _Description;
2998 //=========================================================================
3000 void wxVtkSceneManager::SetMessageKind(std::string kind) {
3001 _MessageKind = kind;
3005 //=========================================================================
3007 std::string wxVtkSceneManager::GetMessageKind(){
3008 return _MessageKind;
3011 //=========================================================================
3013 void wxVtkSceneManager::SetMessageLevel(std::string Level){
3014 _MessageLevel = Level;
3017 //=========================================================================
3019 std::string wxVtkSceneManager::GetMessageLevel(){
3020 return _MessageLevel;
3023 //=========================================================================
3025 std::vector< std::string> wxVtkSceneManager::GetExternalInputsNames()
3028 std::vector< std::string> extInputs;
3029 std::map<int, GObjectController*>::iterator it;
3030 for (it = _controllers.begin(); it != _controllers.end(); ++it)
3032 GObjectController *cont = it->second;
3033 if (cont->getGObjectType() == GCOMPLEXINPUTPORT)
3035 extInputs.push_back(cont->getModel()->getBBTKName());
3041 //=========================================================================
3045 void wxVtkSceneManager::printAll(int com , int sta ){
3047 int tmpState = sta ;
3048 if ( tmpState == NOTHING_HAPPENS ) {
3049 std::cout << "CONTROLER STATE---->NOTHING_HAPPENS\n" ;
3051 if ( tmpState == HIGHLIGHTED ) {
3052 std::cout << "CONTROLER STATE---->HIGHLIGHTED\n" ;
3054 if ( tmpState == POSSIBLE_CONNECTION ) {
3055 std::cout << "CONTROLER STATE---->POSSIBLE_CONNECTION\n" ;
3057 if ( tmpState == SELECTED_POSSIBLE_CONNECTION ) {
3058 std::cout << "CONTROLER STATE---->SELECTED_POSSIBLE_CONNECTION\n" ;
3060 if ( tmpState == CLICKED ) {
3061 std::cout << "CONTROLER STATE---->CLICKED\n" ;
3063 if ( tmpState == DRAG ) {
3064 std::cout << "CONTROLER STATE---->DRAG\n" ;
3066 if ( tmpState == SELECTED ) {
3067 std::cout << "CONTROLER STATE---->SELECTED\n" ;
3069 if ( tmpState == CREATING_CONTOUR ) {
3070 std::cout << "CONTROLER STATE---->CREATING_CONTOUR\n" ;
3076 if ( command == INIT_CREATION_CONTOUR ) {
3077 std::cout << "COMMAND ----> INIT_CREATION_CONTOUR \n" ;
3079 if ( command == FIN_CREATION_CONTOUR ) {
3080 std::cout << "COMMAND ----> FIN_CREATION_CONTOUR \n" ;
3082 if ( command == ADD_TO_SELECTED ) {
3083 std::cout << "COMMAND ----> ADD_TO_SELECTED \n" ;
3085 if ( command == DRAG_OBJECTS ) {
3086 std::cout << "COMMAND ----> DRAG_OBJECTS \n" ;
3088 if ( command == EDIT_BLACKBOX ) {
3089 std::cout << "COMMAND ----> EDIT_BLACKBOX \n" ;
3091 if ( command == REMOVE_FROM_SELECTED ) {
3092 std::cout << "COMMAND ----> REMOVE_FROM_SELECTED \n" ;
3098 } // EO namespace bbtk