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)
78 _cbName = "ComplexBoxName";
79 _cbPackageName = "PackageName";
80 _Author = "Author ??";
82 _Description = "Description ??";
86 _bugTextActor_text = "void";
87 _bugTextActor_status = 0;
91 _idManager = idManager;
93 _bbtkfactory = bbtkfactory;
95 _startDragging = false;
96 _isComplexBox = false;
98 if (_baseView != NULL) {
101 "RaC-EED 21-06-2010 %p wxVtkSceneManager::wxVtkSceneManager If you comment this line, the drag and drop functionnality is not initialized.\n",
104 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget((wxDropTarget*)parent);
108 _worldState = NOTHING_HAPPENS;
109 registerController(this);
112 _idConnectionInCreation = -1;
117 //=========================================================================
119 void wxVtkSceneManager::disconnectDrop()
121 //EED02JUIN2010 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget(NULL);
122 // _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget( new tmpClasswxTextDropTarget() );
125 //=========================================================================
127 wxVtkSceneManager::~wxVtkSceneManager()
134 //=========================================================================
136 void wxVtkSceneManager::configureBaseView()
138 vtkInteractorStyleBaseView2D *interactorstylebaseview = vtkInteractorStyleBaseView2D::New();
139 _baseView->SetInteractorStyleBaseView(interactorstylebaseview);
140 // Important to activate the 2D interaction system
141 crea::wxVTKRenderWindowInteractor *iren = _baseView->GetWxVTKRenderWindowInteractor();
142 interactorstylebaseview->SetInteractor(iren);
143 iren->SetInteractorStyle(interactorstylebaseview);
144 interactorstylebaseview->SetwxVtkBaseView(_baseView);
145 _baseView->GetRenderer()->GetActiveCamera()->ParallelProjectionOn();
146 _baseView->GetRenderer()->ResetCamera(-100, 100, -100, 100, -1000, 1000);
147 _baseView->GetRenderer()->GetActiveCamera()->Zoom(20);
148 _baseView->GetRenderer()->SetBackground(0.9, 0.9, 0.9);
149 _baseView->GetRenderer()->GradientBackgroundOn();
151 _textActor = vtkTextActor3D::New();
152 // _textActor = vtkTextActor::New();
153 _textActor->SetPosition(-9999, -9999, GPOSITION_Z);
154 _textActor->SetInput("<void>");
156 // _textActor->GetTextProperty()->SetFontSize(60);
157 _textActor->GetTextProperty()->SetFontSize(40);
158 _textActor->GetTextProperty()->BoldOn();
159 _textActor->GetTextProperty()->SetFontFamilyToArial();
160 _textActor->GetTextProperty()->ShadowOff();
161 _textActor->GetTextProperty()->SetColor(PORTTEXT_NH_R, PORTTEXT_NH_G,PORTTEXT_NH_B);
162 _baseView->GetRenderer()->AddActor(_textActor);
163 // Actor Fill_Port_Text
167 double zInic = GPOSITION_Z;
168 vtkPolygon *aPolygon = vtkPolygon::New();
169 _fillObjectActor = vtkActor::New();
170 _pts = vtkPoints::New();
173 double w = 100, h = 10, b = h / 15, t = 3;
174 _pts->SetNumberOfPoints(21);
175 _pts->InsertPoint(0, xInic + w * 0.33 - t / 2, yInic, zInic);
176 _pts->InsertPoint(1, xInic + w * 0.33, yInic - t, zInic);
177 _pts->InsertPoint(2, xInic + w * 0.33 + t / 2, yInic, zInic);
178 _pts->InsertPoint(3, xInic + w * 0.33 + t / 2, yInic, zInic);
179 _pts->InsertPoint(4, xInic + w - b * 4, yInic + b * 0, zInic);
181 _pts->InsertPoint(5, xInic + w - b * 4, yInic + b * 0, zInic);
182 _pts->InsertPoint(6, xInic + w - b * 2, yInic + b * 1, zInic);
183 _pts->InsertPoint(7, xInic + w - b * 1, yInic + b * 2, zInic);
184 _pts->InsertPoint(8, xInic + w - b * 0, yInic + b * 4, zInic);
186 _pts->InsertPoint(9, xInic + w - b * 0, yInic + h - b * 4, zInic);
187 _pts->InsertPoint(10, xInic + w - b * 1, yInic + h - b * 2, zInic);
188 _pts->InsertPoint(11, xInic + w - b * 2, yInic + h - b * 1, zInic);
189 _pts->InsertPoint(12, xInic + w - b * 4, yInic + h - b * 0, zInic);
191 _pts->InsertPoint(13, xInic + b * 4, yInic + h - b * 0, zInic);
192 _pts->InsertPoint(14, xInic + b * 2, yInic + h - b * 1, zInic);
193 _pts->InsertPoint(15, xInic + b * 1, yInic + h - b * 2, zInic);
194 _pts->InsertPoint(16, xInic + b * 0, yInic + h - b * 4, zInic);
196 _pts->InsertPoint(17, xInic + b * 0, yInic + b * 4, zInic);
197 _pts->InsertPoint(18, xInic + b * 1, yInic + b * 2, zInic);
198 _pts->InsertPoint(19, xInic + b * 2, yInic + b * 1, zInic);
199 _pts->InsertPoint(20, xInic + b * 4, yInic + b * 0, zInic);
200 aPolygon->GetPointIds()->SetNumberOfIds(21);
201 for (int i = 0; i < 21; i++) {
203 aPolygon->GetPointIds()->SetId(i, i);
207 double w = BOX_WIDTH, h = BOX_HEIGHT, t = PORT_HEIGHT;
208 _pts->SetNumberOfPoints(7);
209 _pts->InsertPoint(0, xInic + t/2.0 , yInic + t , zInic );
210 _pts->InsertPoint(1, xInic + w , yInic + t , zInic );
211 _pts->InsertPoint(2, xInic + w , yInic + t + h , zInic );
212 _pts->InsertPoint(3, xInic - t*1.5 , yInic + t + h , zInic );
213 _pts->InsertPoint(4, xInic - t*1.5 , yInic + t , zInic );
214 _pts->InsertPoint(5, xInic - t/2 , yInic + t , zInic );
215 _pts->InsertPoint(6, xInic , yInic , zInic );
216 aPolygon->GetPointIds()->SetNumberOfIds(8);
217 for (int i = 0; i < 8; i++)
219 aPolygon->GetPointIds()->SetId(i, i);
220 if (i==7) aPolygon->GetPointIds()->SetId(i, 0);
222 vtkUnstructuredGrid *aPolygonGrid = vtkUnstructuredGrid::New();
223 aPolygonGrid->Allocate(1, 1);
224 aPolygonGrid->InsertNextCell(aPolygon->GetCellType(),aPolygon->GetPointIds());
225 aPolygonGrid->SetPoints(_pts);
226 _aPolygonMapper = vtkDataSetMapper::New();
227 //EED 2017-01-01 Migration VTK7
228 #if VTK_MAJOR_VERSION <= 5
229 _aPolygonMapper->SetInput(aPolygonGrid);
231 _aPolygonMapper->SetInputData(aPolygonGrid);
233 _fillObjectActor->SetMapper(_aPolygonMapper);
234 _fillObjectActor->GetProperty()->SetColor(PORTFILL_NH_R, PORTFILL_NH_G,PORTFILL_NH_B);
235 _fillObjectActor->GetProperty()->SetOpacity(0);
236 _aPolygonMapper->Modified();
237 _baseView->GetRenderer()->AddActor(_fillObjectActor);
240 //=========================================================================
242 std::string wxVtkSceneManager::generateANewNameForABox() {
243 std::stringstream boxname;
244 if (_numBoxes < 10) {
245 boxname << "Box0" << _numBoxes;
247 boxname << "Box" << _numBoxes;
250 return boxname.str();
253 //=========================================================================
255 std::string wxVtkSceneManager::findANewNameForABox() {
256 std::string boxname = generateANewNameForABox();
258 while (boxExist(boxname) == true) {
259 boxname = generateANewNameForABox();
265 //=========================================================================
266 void wxVtkSceneManager::configGBlackBox(int idBox, double xIn, double yIn,
267 double zIn, std::string name, bool boxExecutable, double xEn,
268 double yEn, double zEn) {
269 GObjectController *cont = _controllers[idBox];
270 GBlackBoxModel *bbmod = (GBlackBoxModel*) cont->getModel();
271 bbmod->setBBTKName(name);
272 bbmod->setInicPoint(xIn, yIn, zIn);
273 bbmod->setFinalPoint(xEn, yEn, zEn);
274 bbmod->setExecutable(boxExecutable);
276 bbmod->notifyObservers(_idManager);
280 //=========================================================================
282 int wxVtkSceneManager::createGBlackBox(int x, int y, std::string packageName,std::string boxType)
284 _worldState = NOTHING_HAPPENS;
285 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
286 int type = GBLACKBOX;
287 //Create the MVC Objects
288 GBlackBoxModel *model = (GBlackBoxModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(type);
289 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
290 GObjectController *controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
292 //EED 15 oct 2012 BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxType);
296 std::map< std::string, BlackBoxDescriptor::Pointer> mapDesc;
298 k = _bbtkfactory->GetPackage(packageName);
299 mapDesc = k->GetDescriptorMap();
301 printf("EED. ERROR!: Exception in wxVtkSceneManager::createGBlackBox for package %s, NOT EXIST\n", packageName.c_str());
304 BlackBoxDescriptor::Pointer descriptor;
306 descriptor = mapDesc[boxType];
308 printf("EED. ERROR!: Exception in wxVtkSceneManager::createGBlackBox for box %s of package %s, NOT EXIST\n", boxType.c_str(),packageName.c_str());
311 if (descriptor == NULL)
313 printf("SCP: ERROR in wxVtkSceneManager::createGBlackBox, box %s probably does not exist.\n", boxType.c_str());
316 //Prepares the initial model
317 //The coordinates obtained are the following. Top-Left:x=0,y=0 Bottom-Right:x=width,y=height
320 double yy = windowHeight - y;
322 //z value is not important yet, because it is only used a parallel projection
323 double zz = GPOSITION_Z;
324 _baseView->TransCoordScreenToWorld(xx, yy, zz);
325 model->setInicPoint(xx, yy, zz);
327 std::stringstream stream;
329 std::string newBoxName;
330 newBoxName = findANewNameForABox();
332 stream << newBoxName;
334 std::string arraystring = stream.str();
336 model->setBBTKName(arraystring);
337 model->setBBTKType(boxType);
338 model->setBBTKPackage(packageName);
340 model->addObserver(view);
341 model->addObserver(this);
344 //EED2017 change order
345 //Associates the view with the correspondent renderer and the model.
346 //(NOTE: Refresh is only made by the view)
347 view->setModel(model);
348 view->setBaseView(_baseView);
350 //Associates the controller with the correspondent model and view
351 controller->setModelAndView(model, view);
354 //Iterate and create the input ports
355 std::map<std::string, BlackBoxInputDescriptor*> descriptorInMap =
356 descriptor->GetInputDescriptorMap();
357 std::map<std::string, BlackBoxInputDescriptor*>::iterator itInput;
359 for (itInput = descriptorInMap.begin(); itInput != descriptorInMap.end(); ++itInput)
361 BlackBoxInputDescriptor *desc = itInput->second;
363 // createGInputPort(GINPUTPORT, i, model, desc);
364 createGInputPort(GINPUTPORT, i, controller, desc);
368 //Iterate and create the output ports
369 std::map<std::string, BlackBoxOutputDescriptor*> descriptorOutMap =
370 descriptor->GetOutputDescriptorMap();
371 std::map<std::string, BlackBoxOutputDescriptor*>::iterator itOutput;
373 for (itOutput = descriptorOutMap.begin(); itOutput!= descriptorOutMap.end(); ++itOutput)
375 BlackBoxOutputDescriptor *desc = itOutput->second;
377 // createGOutputPort(GOUTPUTPORT, i, model, desc);
378 createGOutputPort(GOUTPUTPORT, i, controller, desc);
382 //EED2017 change order
383 view->initVtkObjects();
385 //Resgiter change to the observers of the actual model
386 model->notifyObservers(_idManager);
387 int newId = addObjectController(controller);
393 //=========================================================================
395 int wxVtkSceneManager::createGComplexBoxInputPort(std::string inputName) {
396 //EED int windowWidth=_baseView->GetRenWin()->GetSize()[0];
397 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
399 int type = GCOMPLEXINPUTPORT;
401 //Create the MVC Objects
403 GComplexBoxPortModel *model = (GComplexBoxPortModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(type);
404 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
405 GObjectController *controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
407 //Prepares the initial model
410 double yy = windowHeight - 5;
412 //z value is not important yet, because it is only used a parallel projection
413 double zz = GPOSITION_Z;
415 _baseView->TransCoordScreenToWorld(xx, yy, zz);
416 model->setInicPoint(xx, yy, zz);
418 model->setBBTKName(inputName);
419 model->setBBTKType("ComplexInputPort");
420 model->setComplexPortType(type);
422 model->addObserver(view);
423 model->addObserver(this);
425 //create the output port
426 GPortController* portController = createGPort(GOUTPUTPORT, inputName,
427 "ComplexOutputPortType","ComplexOutputPortDescriopton", 0, model);
428 model->addOutputPort((GPortModel*) portController->getModel());
430 //Associates the view with the correspondent renderer and the model.
431 //(NOTE: Refresh is only made by the view)
432 view->setModel(model);
433 view->setBaseView(_baseView);
434 view->initVtkObjects();
436 //Associates the controller with the correspondent model and view
437 controller->setModelAndView(model, view);
439 //Resgiter change to the observers of the actual model
440 model->notifyObservers(_idManager);
442 int newId = addObjectController(controller);
446 //=========================================================================
448 int wxVtkSceneManager::createGComplexBoxOutputPort(std::string outputName) {
449 //EED int windowWidth=_baseView->GetRenWin()->GetSize()[0];
450 int windowHeight = _baseView->GetRenWin()->GetSize()[1];
452 int type = GCOMPLEXOUTPUTPORT;
454 //Create the MVC Objects
456 GComplexBoxPortModel *model = (GComplexBoxPortModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(type);
457 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
458 GObjectController *controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
460 //Prepares the initial model
463 double yy = windowHeight - 5;
465 //z value is not important yet, because it is only used a parallel projection
466 double zz = GPOSITION_Z;
468 _baseView->TransCoordScreenToWorld(xx, yy, zz);
469 model->setInicPoint(xx, yy, zz);
471 model->setBBTKName(outputName);
472 model->setBBTKType("ComplexOutputPort");
473 model->setComplexPortType(type);
475 model->addObserver(view);
476 model->addObserver(this);
478 //create the output port
479 GPortController* portController = createGPort(GINPUTPORT, outputName,
480 "ComplexInputPort","ComplexInputPortDescription", 0, model);
481 model->addInputPort((GPortModel*) portController->getModel());
483 //Associates the view with the correspondent renderer and the model.
484 //(NOTE: Refresh is only made by the view)
485 view->setModel(model);
486 view->setBaseView(_baseView);
487 view->initVtkObjects();
489 //Associates the controller with the correspondent model and view
490 controller->setModelAndView(model, view);
492 //Resgiter change to the observers of the actual model
493 model->notifyObservers(_idManager);
495 int newId = addObjectController(controller);
499 //=========================================================================
502 //int wxVtkSceneManager::createGInputPort(int portType, int posinBox, GBoxModel *blackBox, BlackBoxInputDescriptor *desc)
503 int wxVtkSceneManager::createGInputPort(int portType, int posinBox, GObjectController *gBoxControler, BlackBoxInputDescriptor *desc)
505 GBoxModel *blackBox=(GBoxModel*)gBoxControler->getModel();
506 GPortController* portController = createGPort(portType, desc->GetName(),
507 desc->GetTypeName(), desc->GetDescription(), posinBox, blackBox);
508 blackBox->addInputPort( (GPortModel*)portController->getModel() );
510 vtkGBoxView *vtkgboxView=(vtkGBoxView*)gBoxControler->getView();
511 vtkgboxView->addInputPort( (vtkGPortView*)portController->getView() );
513 return portController->getId();
516 //=========================================================================
519 //int wxVtkSceneManager::createGOutputPort(int portType, int posinBox,GBoxModel *blackBox, BlackBoxOutputDescriptor *desc)
520 int wxVtkSceneManager::createGOutputPort(int portType, int posinBox,GObjectController *gBoxControler, BlackBoxOutputDescriptor *desc)
522 GBoxModel *blackBox=(GBoxModel*)gBoxControler->getModel();
523 GPortController* portController = createGPort(portType, desc->GetName(),
524 desc->GetTypeName(),desc->GetDescription(), posinBox, blackBox);
525 blackBox->addOutputPort((GPortModel*) portController->getModel());
527 vtkGBoxView *vtkgboxView=(vtkGBoxView*)gBoxControler->getView();
528 vtkgboxView->addOutputPort( (vtkGPortView*)portController->getView() );
530 return portController->getId();
533 //=========================================================================
535 GPortController* wxVtkSceneManager::createGPort(int portType,std::string bbtkName, std::string bbtkType, std::string bbtkDescription, int posInBox,GBoxModel *blackBox)
539 //Create the MVC Objects
540 GPortModel *model = (GPortModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(type);
541 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
542 GObjectController *controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
543 model->registerInBox(blackBox, portType, posInBox);
544 model->setBBTKType(bbtkType);
545 model->setBBTKName(bbtkName);
546 model->setBBTKDescription(bbtkDescription);
547 model->addObserver(view);
548 model->addObserver(this);
549 //Associates the view with the correspondent renderer and the model.
550 //(NOTE: Refresh is only made by the view)
551 view->setModel(model);
552 view->setBaseView(_baseView);
553 //EED017 view->initVtkObjects();
554 view->createVtkObjects();
555 // view->addVtkActors();
557 //Associates the controller with the correspondent model and view
558 controller->setModelAndView(model, view);
559 model->notifyObservers(_idManager);
560 addObjectController(controller);
561 return (GPortController*) controller;
564 //=========================================================================
566 int wxVtkSceneManager::createGConnector(GPortModel* startPort)
568 int type = GCONNECTOR;
570 manualConnectorContourController *manContourControl = new manualConnectorContourController();
571 manualConnectorContourView *manContourView = new manualConnectorContourView();
572 manualContourModel *manContourModel = new manualContourModel();
573 GConnectorController *connectorcontroller = new GConnectorController();
574 GConnectorModel *connectorModel = new GConnectorModel();
575 vtkGConnectorView *connectorView = new vtkGConnectorView();
576 connectorModel->setGObjectType(type);
578 manContourModel->SetCloseContour(false);
579 connectorModel->setStartPort(startPort);
581 manContourView->SetModel(manContourModel);
582 manContourView->SetWxVtkBaseView(_baseView);
583 manContourView->SetRange(0.5);
584 manContourView->SetZ(GPOSITION_Z);
586 manContourView->SetColorNormalContour(0, 0, 1);
587 manContourView->SetColorEditContour(0.5, 0.5, 0.5);
588 manContourView->SetColorSelectContour(1, 0.8, 0);
594 * Width increased from 2 to 3, it simplifies line handling and spline control :P
598 // manContourView->SetWidthLine( 3 ) ;
600 manContourView->SetWidthLine( 1 ) ;
602 manContourView->SetShowText(false);
604 manContourControl->SetModelView(manContourModel, manContourView);
606 manContourControl->CreateNewManualContour();
610 connectorModel->getInicPoint(x, y, z);
613 manContourControl->SetState(1);
614 manContourModel->SetCloseContour(false);
616 manContourModel->AddPoint(x, y, z);
617 manContourView->AddPoint();
619 manContourModel->AddPoint(x, y, z);
620 manContourView->AddPoint();
622 int bak = manContourControl->GetNumberOfPointsManualContour() - 1;
623 manContourControl->_bakIdPoint = bak;
625 manContourControl->SetMoving(false);
627 connectorcontroller->setModelAndView(connectorModel, connectorView);
629 int newId = addObjectController(connectorcontroller);
631 connectorcontroller->setManualContourController(manContourControl);
632 connectorModel->setManualContourModel(manContourModel);
633 connectorView->setManualContourView(manContourView);
634 connectorView->setModel(connectorModel);
635 connectorView->setBaseView(_baseView);
637 connectorModel->addObserver(connectorView);
638 connectorModel->addObserver(this);
640 // manContourView->Refresh();
645 //=========================================================================
647 void wxVtkSceneManager::registerController(InteractorStyleMaracas *param)
649 vtkInteractorStyleBaseView * baseViewControlManager = (vtkInteractorStyleBaseView*) _baseView->GetInteractorStyleBaseView();
650 baseViewControlManager->AddInteractorStyleMaracas(param);
653 //=========================================================================
655 void wxVtkSceneManager::unregisterController(InteractorStyleMaracas *param)
657 vtkInteractorStyleBaseView *baseViewControlManager = (vtkInteractorStyleBaseView*) _baseView->GetInteractorStyleBaseView();
658 baseViewControlManager->RemoveInteractorStyleMaracas(param);
661 //=========================================================================
663 vtkRenderer* wxVtkSceneManager::getRenderer()
665 return _baseView->GetRenderer();
668 //=========================================================================
670 vtkRenderWindow* wxVtkSceneManager::getRenderWindow()
672 return _baseView->GetRenWin();
674 //=========================================================================
677 //=========================================================================
678 int wxVtkSceneManager::GetIndexInSelected(int idControler)
681 for (int i = 0; i < (int) _selectedObjects.size(); i++)
683 if (_selectedObjects[i] == idControler)
691 //=========================================================================
693 void wxVtkSceneManager::update(int idController, int command) {
695 if (command != NO_COMMAND)
697 if (command == ADD_TO_SELECTED)
699 if (GetIndexInSelected(idController) == -1)
701 _selectedObjects.push_back(idController);
703 } else if (command == REMOVE_FROM_SELECTED) {
704 int index = GetIndexInSelected(idController);
707 _selectedObjects.erase(_selectedObjects.begin() + index);
709 } else if (command == INIT_CREATION_CONTOUR) {
711 typedef std::map<int , GObjectController*>::iterator TIterator ;
714 // Find current item in the controller
715 iter = _controllers.find( idController ) ;
716 iter_end = _controllers.end( ) ;
718 if ( iter != iter_end ) {
719 GObjectController* gobjc = iter->second ;
721 std::string bbtkType = gobjc->getModel( )->getBBTKType( ) ;
722 // And if the item is a port
723 if ( gobjc->getModel( )->getGObjectType( ) == GPORT ) {
724 TIterator c_it = _controllers.begin( ) ;
725 // Go through all componets
726 for ( c_it ; c_it != iter_end ; c_it++ ) {
727 GObjectController* obc = c_it->second ;
728 int obc_type = obc->getModel( )->getGObjectType( ) ;
729 std::string obc_bbtkType = obc->getModel( )->getBBTKType( ) ;
730 // if the component is a port and the type is the same of that selected
731 if ( ( obc_type == GPORT ) && ( obc_bbtkType == bbtkType ) ) {
733 obc->getView( )->setState( POSSIBLE_CONNECTION ) ;
734 //obc->getView( )->setState( HIGHLIGHTED ) ;
742 _worldState = INIT_CREATION_CONTOUR;
743 GObjectController* cont = _controllers[idController];
744 GPortModel* startOutputPort = (GPortModel*) cont->getModel();
746 // The last one is the controller of the connector
747 std::map<int, GObjectController*>::iterator it2;
749 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
751 GObjectController *cont = it2->second;
752 if (cont->getGObjectType() == GPORT)
754 GPortModel* port = (GPortModel*) cont->getModel();
755 if (port->getPortType() == GINPUTPORT)
757 cont->SetActive(true);
759 cont->getView()->setState(NOTHING_HAPPENS);
760 cont->getModel()->notifyObservers(_idManager);
761 cont->SetActive(false);
764 cont->getView()->setState(NOTHING_HAPPENS);
765 cont->getModel()->notifyObservers(_idManager);
766 cont->SetActive(false);
769 _selectedObjects.clear();
770 _idConnectionInCreation = createGConnector(startOutputPort);
771 } else if (command == FIN_CREATION_CONTOUR && _worldState == INIT_CREATION_CONTOUR) {
772 _worldState = NOTHING_HAPPENS;
773 //int id = _controllers.size()-1;
774 GObjectController *cont = _controllers[_idConnectionInCreation];
775 GConnectorModel *modelContour = (GConnectorModel*) cont->getModel();
776 GObjectController *finPort = _controllers[idController];
778 if (finPort->getGObjectType() == GPORT)
780 GPortModel* modelPort = (GPortModel*) finPort->getModel();
781 modelContour->setEndPort(modelPort);
784 typedef std::map<int, GObjectController*>::iterator TIterator;
785 TIterator c_it = _controllers.begin();
786 TIterator iter_end = _controllers.end();
787 // Go through all componets
788 for (c_it; c_it != iter_end; c_it++) {
789 GObjectController* obc = c_it->second;
790 int obc_type = obc->getModel()->getGObjectType();
791 int obc_state = obc->getView()->getState();
792 // if the component is a port and the type is the same of that selected
793 if ((obc_type == GPORT) && (obc_state == POSSIBLE_CONNECTION)) {
794 // Return element to neutral state if not selected
795 obc->getView()->setState(NOTHING_HAPPENS);
797 if ((obc_type == GPORT) && (obc_state == SELECTED_POSSIBLE_CONNECTION)) {
798 // Change element to connected state
799 obc->getView()->setState(HIGHLIGHTED);
805 _parent->saveTempandUpdate("create connection");
808 manualConnectorContourController *manCont = ((GConnectorController*) cont)->getManualContourController();
809 manualConnectorContourView *connView = (manualConnectorContourView*) manCont->GetManualViewBaseContour();
811 std::map<int, GObjectController*>::iterator it2;
813 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
815 GObjectController *cont = it2->second;
816 if (cont->getView() != NULL) {
817 cont->getView()->setState(NOTHING_HAPPENS);
818 cont->getModel()->notifyObservers(_idManager);
820 cont->SetActive(true);
829 //=========================================================================
831 bool wxVtkSceneManager::OnMouseMove()
834 bool okStatusMessage = false;
835 bool okPortMessage = false;
836 crea::wxVTKRenderWindowInteractor *wxVTKiren;
837 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
838 wxVTKiren->GetEventPosition(X, Y);
840 if (_worldState == DRAG_OBJECTS) {
841 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
842 int id = _selectedObjects[i];
843 GObjectController* cont = _controllers[id];
844 if (_startDragging) {
845 cont->getView()->setStartDragging(true);
847 cont->getView()->moveObject(X, Y);
848 cont->getView()->setState(DRAG);
849 cont->getModel()->notifyObservers(_idManager);
852 std::map<int, GObjectController*>::iterator it;
854 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
855 GObjectController *desc = it->second;
856 if (desc->getGObjectType() == GCONNECTOR) {
857 vtkGConnectorView* vconn = (vtkGConnectorView*) desc->getView();
858 vconn->updateStartEndPoints();
862 _startDragging = false;
864 } else if (_worldState == NOTHING_HAPPENS || _worldState == INIT_CREATION_CONTOUR) {
865 std::map<int, GObjectController*>::iterator it;
867 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
868 GObjectController *desc = it->second;
869 int type = desc->getGObjectType();
870 int state = desc->getView()->getState();
871 desc->getModel()->getCenter(px, py, pz);
874 if ((state == HIGHLIGHTED) || (state == SELECTED_POSSIBLE_CONNECTION ))
877 okStatusMessage = true;
878 updateStatusBar(desc->getStatusText());
879 if (type == GBLACKBOX)
881 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
882 _parent->displayBlackBoxInfo(mod->getBBTKPackage(),mod->getBBTKType());
887 if ( ( _bugTextActor_text==desc->getStatusText() ) || (_bugTextActor_status==0) )
889 _bugTextActor_status = 1;
890 okPortMessage = true;
893 // _textActor->SetScale(0.1);
895 _textActor->SetScale(0.05,0.05,1);
897 std::string tmp = desc->getStatusText()+"\n";
898 _textActor->SetInput( tmp.c_str() );
899 // _textActor->SetPosition(px - 25, py + 1, pz + 2);
900 // _textActor->SetPosition(px , py-PORT_HEIGHT/4 , pz + 2);
901 _textActor->SetPosition(px , py-PORT_HEIGHT , pz + 2);
902 _textActor->Modified();
906 _fillObjectActor->SetScale(1);
908 // _fillObjectActor->SetScale(0.7,0.5,1);
909 _fillObjectActor->GetProperty()->SetOpacity(0.75);
910 _fillObjectActor->SetPosition( px, py + PORT_HEIGHT/2.0 , 1);
911 _aPolygonMapper->Modified();
913 _bugTextActor_status= 2;
914 } // _bugTextActor_tex
915 _bugTextActor_text = desc->getStatusText();
919 } // for controllers it
921 if (okStatusMessage == false)
926 if ((okPortMessage == false) || (_bugTextActor_status== 2 ) )
928 _bugTextActor_status = 0;
929 _textActor->SetScale(0.0001);
930 _textActor->SetInput("a\n");
931 _textActor->Modified();
932 _fillObjectActor->SetScale(0.0001);
937 //=========================================================================
939 bool wxVtkSceneManager::OnLeftButtonDown()
941 if (_worldState == INIT_CREATION_CONTOUR)
943 bool isOverPort = false;
944 std::map<int, GObjectController*>::iterator it;
945 for (it = _controllers.begin(); it != _controllers.end() && isOverPort== false; ++it)
947 GObjectController *desc = it->second;
948 if (desc->getGObjectType() == GPORT)
950 GPortModel *portmod = (GPortModel*) desc->getModel();
951 vtkGObjectView *portView = desc->getView();
952 if (portmod->getPortType() == GINPUTPORT && portView->getState() == HIGHLIGHTED)
957 if ( portmod->getPortType( ) == GINPUTPORT && portView->getState( ) == SELECTED_POSSIBLE_CONNECTION ) {
959 portView->setState( HIGHLIGHTED);
966 if (isOverPort == false)
969 UnSelectBlackBoxes();
973 } else { //_worldState
975 _worldState = DRAG_OBJECTS;
976 _startDragging = true;
978 int shiftkey = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey();
979 int ctrlkey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
980 ctrlkey = ctrlkey + shiftkey;
982 GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
985 int state = cont->getView()->getState();
986 if ((ctrlkey == 0) && (state == HIGHLIGHTED)) {
987 UnSelectBlackBoxes();
990 UnSelectBlackBoxes(); // EED 12/07/2012
992 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
993 int id = _selectedObjects[i];
994 GObjectController *cont = _controllers[id];
995 cont->getView()->setState(DRAG);
996 cont->getModel()->notifyObservers(_idManager);
998 } // if _selectedObjects.size
1004 //=========================================================================
1006 bool wxVtkSceneManager::OnLeftButtonUp()
1008 if (_worldState == DRAG_OBJECTS) {
1009 _worldState = NOTHING_HAPPENS;
1011 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
1012 int id = _selectedObjects[i];
1013 GObjectController* cont = _controllers[id];
1014 cont->getView()->setState(SELECTED);
1015 cont->getModel()->notifyObservers(_idManager);
1021 //=========================================================================
1022 void wxVtkSceneManager::CancelConnection()
1024 if (_worldState == INIT_CREATION_CONTOUR)
1026 _worldState = NOTHING_HAPPENS;
1027 //int lastId = _controllers.size()-1;
1029 GConnectorController *connector =
1030 (GConnectorController*) _controllers[_idConnectionInCreation];
1031 connector->removeFromScene();
1032 unregisterController(connector);
1033 _controllers.erase(_idConnectionInCreation);
1035 std::map<int, GObjectController*>::iterator it;
1036 for (it = _controllers.begin(); it != _controllers.end(); ++it)
1038 GObjectController *desc = it->second;
1039 desc->SetActive(true);
1040 desc->getView()->setState(NOTHING_HAPPENS);
1041 desc->getModel()->notifyObservers(_idManager);
1046 //=========================================================================
1048 bool wxVtkSceneManager::OnRightButtonUp()
1050 if (_worldState == INIT_CREATION_CONTOUR)
1054 UnSelectBlackBoxes();
1060 bool wxVtkSceneManager::OnMiddleButtonDown() {
1063 this->_vtkInteractorStyleBaseView->StartPan();
1068 bool wxVtkSceneManager::OnMiddleButtonUp() {
1071 this->_vtkInteractorStyleBaseView->EndPan();
1078 //=========================================================================
1080 GObjectController *wxVtkSceneManager::GetGBlackBoxControlerPointedByMouse() {
1081 GObjectController *result = NULL;
1083 crea::wxVTKRenderWindowInteractor *wxVTKiren;
1085 = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
1086 wxVTKiren->GetEventPosition(X, Y);
1088 std::map<int, GObjectController*>::iterator it;
1090 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1091 GObjectController *cont = it->second;
1092 int type = cont->getGObjectType();
1094 if (cont->getView()->isPointInside(X, Y) == true) {
1095 if (type == GBLACKBOX) {
1098 } // if isPointInside
1103 //=========================================================================
1104 void wxVtkSceneManager::UnSelectBlackBoxes() {
1105 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
1106 int id = _selectedObjects[i];
1107 GObjectController* control = _controllers[id];
1108 control->getView()->setState(NOTHING_HAPPENS);
1109 control->getModel()->notifyObservers(_idManager);
1110 }// for _selectedObjects
1111 _selectedObjects.clear();
1114 //=========================================================================
1115 bool wxVtkSceneManager::OnLeftDClick() {
1116 GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
1118 UnSelectBlackBoxes();
1119 _parent->editBlackBox((GBlackBoxModel*) cont->getModel());
1124 //=========================================================================
1126 bool wxVtkSceneManager::OnChar()
1130 char keyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
1131 int ctrlkey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
1133 // KeyCode 127 : Delete Key
1134 // KeyCode 8 : Backspace Key
1137 if (keyCode == 8 || keyCode == 127 || keyCode == 27)
1139 if (_worldState == INIT_CREATION_CONTOUR)
1142 UnSelectBlackBoxes();
1147 if (keyCode == 8 || keyCode == 127)
1150 for (int i = 0; i < (int) _selectedObjects.size(); i++)
1152 int id = _selectedObjects[i];
1153 std::map<int, GObjectController*>::iterator it;
1154 it = _controllers.find(id);
1155 if (it != _controllers.end())
1157 oktmp = deleteObject(id);
1160 }// for selected objects
1161 if (ok) _selectedObjects.clear();
1162 _parent->saveTempandUpdate("delete object");
1168 if(_selectedObjects.size()){
1169 std::cout<<"objects to copy :";
1170 for(int i=0;i<_selectedObjects.size();i++)
1172 std::cout<<_selectedObjects.at(i)<<" ";
1174 DuplicateObjects(getSelectedObjects());
1176 std::cout<<"No objects to copy\n";
1177 } // _selectedObjects.size
1183 //=========================================================================
1185 void wxVtkSceneManager::AddControlerToBeRemove(
1186 std::vector<int> *controllersToRemove, int id) {
1190 for (i = 0; i < (int) controllersToRemove->size(); i++) {
1191 if (id == (*controllersToRemove)[i]) {
1197 controllersToRemove->push_back(id);
1202 //=========================================================================
1204 bool wxVtkSceneManager::deleteObject(int id)
1207 GObjectController *control = _controllers[id];
1208 std::vector<int> controllersToRemove;
1209 if (control->getGObjectType() == GBLACKBOX || control->getGObjectType()
1210 == GCOMPLEXINPUTPORT || control->getGObjectType()
1211 == GCOMPLEXOUTPUTPORT) {
1212 GBoxModel *bbmod = (GBoxModel*) control->getModel();
1213 std::vector<GPortModel*> inputs = bbmod->getInputPorts();
1215 bool boxConnected = false;
1217 // Add box input controllers to be removed
1218 for (int i = 0; i < (int) inputs.size(); i++) {
1219 AddControlerToBeRemove(&controllersToRemove, inputs[i]->getObjectId());
1220 if (inputs[i]->isConnected()) {
1221 boxConnected = true;
1225 std::vector<GPortModel*> outputs = bbmod->getOutputPorts();
1227 // Add box output controllers to be removed
1228 for (int i = 0; i < (int) outputs.size(); i++) {
1229 AddControlerToBeRemove(&controllersToRemove, outputs[i]->getObjectId());
1230 if (outputs[i]->isConnected()) {
1231 boxConnected = true;
1235 // Add connection controllers to be removed
1236 std::map<int, GObjectController*>::iterator it;
1237 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1238 GObjectController *cont = it->second;
1239 int type = cont->getGObjectType();
1240 if (type == GCONNECTOR) {
1241 GConnectorModel *conMod = (GConnectorModel*) cont->getModel();
1242 if (conMod->getStartPort() != NULL && conMod->getStartPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
1244 AddControlerToBeRemove(&controllersToRemove,conMod->getObjectId());
1246 if (conMod->getEndPort() != NULL && conMod->getEndPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
1248 AddControlerToBeRemove(&controllersToRemove,conMod->getObjectId());
1253 // Add box controller to be removed
1254 AddControlerToBeRemove(&controllersToRemove, bbmod->getObjectId());
1255 } else if (control->getGObjectType() == GCONNECTOR) {
1256 GConnectorController *gconnectorcontroler = (GConnectorController*)control;
1257 if (gconnectorcontroler->getManualContourController()->IsEditable()==false)
1259 GConnectorModel *conMod = (GConnectorModel*) control->getModel();
1260 AddControlerToBeRemove(&controllersToRemove, conMod->getObjectId());
1262 gconnectorcontroler->getManualContourController()->OnChar();
1267 std::map<int, GObjectController*>::iterator it;
1269 for (int i = 0; i < (int) controllersToRemove.size(); i++) {
1270 int key = controllersToRemove[i];
1271 it = _controllers.find(key);
1272 GObjectController *cont = _controllers[key];
1274 cont->removeFromScene();
1275 unregisterController((InteractorStyleMaracas*) cont);
1276 _controllers.erase(it);
1284 //=========================================================================
1286 void wxVtkSceneManager::displayBlackBoxInfo(std::string packageName,
1287 std::string boxName) {
1288 _parent->displayBlackBoxInfo(packageName, boxName);
1291 //=========================================================================
1293 void wxVtkSceneManager::updateStatusBar(std::string textStatus) {
1294 _parent->updateStatusBar(textStatus);
1297 //=========================================================================
1298 std::string wxVtkSceneManager::LineNumber(bool withLineNumber, int &value) {
1299 std::string result = "";
1300 if (withLineNumber == true) {
1302 stringstream StrStream;
1304 std::string strValue = StrStream.str();
1307 } else if (value < 100) {
1311 result += strValue + ": ";
1315 //=========================================================================
1317 bool wxVtkSceneManager::MakeBoxExecutable() {
1318 std::map<int, GObjectController*> selected = getSelectedObjects();
1319 if( selected.empty() )
1322 std::map<int, GObjectController*>::iterator it;
1323 for (it = selected.begin(); it != selected.end(); ++it) {
1324 GObjectController* lastSelected = it->second;
1326 vtkGObjectView* view = (vtkGObjectView*) lastSelected->getView();
1327 GBlackBoxModel *bbmodel =
1328 (GBlackBoxModel*) lastSelected->getModel();
1329 view->setState(HIGHLIGHTED);
1330 if (bbmodel->isExecutable()) {
1331 bbmodel->setExecutable(false);
1333 bbmodel->setExecutable(true);
1335 bbmodel->notifyObservers(lastSelected->getId());
1343 //=========================================================================
1345 std::string wxVtkSceneManager::getDiagramBBS(bool wln) {
1346 std::cout << "wxVtkSceneManager::getDiagramBBS" << std::endl;
1347 bool existsExec = false;
1349 std::vector<std::string> packages;
1350 std::vector<int> boxes;
1351 std::vector<int> connections;
1352 std::vector<int> execBoxes;
1354 std::map<int, GObjectController*>::iterator it;
1356 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1357 GObjectController *desc = it->second;
1358 int type = desc->getGObjectType();
1360 if (type == GBLACKBOX) {
1361 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
1363 std::string pkg = mod->getBBTKPackage();
1364 bool existsPkg = false;
1365 for (int t = 0; t < (int) packages.size() && existsPkg == false; t++) {
1366 if (packages[t] == pkg) {
1371 packages.push_back(pkg);
1374 boxes.push_back(it->first);
1375 if (mod->isExecutable()) {
1376 execBoxes.push_back(it->first);
1379 } else if (type == GCONNECTOR) {
1380 connections.push_back(it->first);
1385 std::string script = "";
1386 script += LineNumber(wln, lnNmbr) + "# BBTK GEditor Script\n";
1387 script += LineNumber(wln, lnNmbr) + "# ----------------------\n";
1388 script += LineNumber(wln, lnNmbr) + "\n";
1390 script += LineNumber(wln, lnNmbr) + "include std\n"; // EED
1391 script += LineNumber(wln, lnNmbr) + "include itkvtk\n"; // EED
1393 for (i = 0; i < (int) packages.size(); i++) {
1394 script += LineNumber(wln, lnNmbr);
1395 script += "include ";
1396 script += packages[i];
1400 script += LineNumber(wln, lnNmbr);
1405 script += LineNumber(wln, lnNmbr);
1406 script += "author \"";
1410 script += LineNumber(wln, lnNmbr);
1411 script += "description \"";
1412 script += _Description;
1415 script += LineNumber(wln, lnNmbr);
1416 script += "category \"";
1417 script += _Category;
1420 script += LineNumber(wln, lnNmbr);
1423 // script+="include std\n"; // JPR
1425 for (i = 0; i < (int) boxes.size(); i++) {
1426 script += LineNumber(wln, lnNmbr);
1429 GObjectController *control = _controllers[id];
1430 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1432 script += model->getBBTKPackage()+":";
1433 script += model->getBBTKType();
1435 script += model->getBBTKName();
1438 std::vector<GPortModel*> inputs = model->getInputPorts();
1439 for (int j = 0; j < (int) inputs.size(); j++) {
1440 GPortModel* inputPort = inputs[j];
1441 if (inputPort->isValueSet()) {
1442 script += LineNumber(wln, lnNmbr);
1444 script += model->getBBTKName();
1446 script += inputPort->getBBTKName();
1448 script += inputPort->getValue();
1453 script += LineNumber(wln, lnNmbr);
1458 script += LineNumber(wln, lnNmbr);
1462 std::string complexInputs="";
1464 for (i = 0; i < (int) connections.size(); i++) {
1465 //script += LineNumber(wln, lnNmbr);
1466 //script += "connect ";
1467 int id = connections[i];
1468 GObjectController *control = _controllers[id];
1469 GConnectorModel *model = (GConnectorModel*) control->getModel();
1473 GPortModel *start = model->getStartPort();
1474 GBoxModel *startBox = start->getParentBox();
1476 GPortModel *end = model->getEndPort();
1477 GBoxModel *endBox = end->getParentBox();
1479 if (startBox->getGObjectType() == GCOMPLEXINPUTPORT)
1481 complexInputs += "input ";
1482 complexInputs += startBox->getBBTKName();
1484 complexInputs += " ";
1485 complexInputs += endBox->getBBTKName();
1486 complexInputs += ".";
1487 complexInputs += end->getBBTKName();
1489 complexInputs += " ";
1490 complexInputs += "\" \"";
1492 complexInputs += "\n";
1496 script += LineNumber(wln, lnNmbr);
1497 script += "connect ";
1498 script += startBox->getBBTKName();
1500 script += start->getBBTKName();
1504 //End Connection info
1505 script += endBox->getBBTKName();
1507 script += end->getBBTKName();
1512 script += LineNumber(wln, lnNmbr);
1516 script += LineNumber(wln, lnNmbr);
1519 script += LineNumber(wln, lnNmbr);
1522 script += LineNumber(wln, lnNmbr);
1523 script += "# Complex input ports\n";
1524 script += complexInputs;
1526 if((_MessageKind!="-")&&(_MessageLevel!="-")){
1527 script += LineNumber(wln, lnNmbr);
1528 script += "message ";
1529 script += _MessageKind;
1531 script += _MessageLevel;
1535 for (i = 0; i < (int) execBoxes.size(); i++) {
1536 script += LineNumber(wln, lnNmbr);
1538 int id = execBoxes[i];
1539 GObjectController *control = _controllers[id];
1540 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1541 script += model->getBBTKName();
1550 //=========================================================================
1552 std::string wxVtkSceneManager::saveComplexBoxBBS() {
1553 std::cout<<"wxVtkSceneManager::saveComplexBoxBBS"<<std::endl;
1554 std::vector<std::string> packages;
1555 std::vector<int> boxes;
1556 std::vector<int> connections;
1557 std::vector<int> execBoxes;
1559 std::map<int, GObjectController*>::iterator it;
1561 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1562 GObjectController *desc = it->second;
1563 int type = desc->getGObjectType();
1565 if (type == GBLACKBOX) {
1566 GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
1568 std::string pkg = mod->getBBTKPackage();
1569 bool existsPkg = false;
1570 for (int t = 0; t < (int) packages.size() && existsPkg == false; t++) {
1571 if (packages[t] == pkg) {
1576 packages.push_back(pkg);
1579 boxes.push_back(it->first);
1580 if (mod->isExecutable()) {
1581 execBoxes.push_back(it->first);
1583 } else if (type == GCONNECTOR) {
1584 connections.push_back(it->first);
1588 std::string script = "";
1590 script += "include std\n"; // EED
1591 script += "include itkvtk\n"; // EED
1593 for (i = 0; i < (int) packages.size(); i++) {
1594 script += "include ";
1595 script += packages[i];
1600 // Definition of a complex box
1601 script += "define ";
1602 script += _cbName + " " + _cbPackageName;
1606 script += "author \"";
1610 script += "description \"";
1611 script += _Description;
1615 script += "category \"";
1616 script += _Category;
1621 for (i = 0; i < (int) boxes.size(); i++) {
1624 GObjectController *control = _controllers[id];
1625 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1627 script += model->getBBTKPackage()+":";
1628 script += model->getBBTKType();
1630 script += model->getBBTKName();
1633 std::vector<GPortModel*> inputs = model->getInputPorts();
1634 for (int j = 0; j < (int) inputs.size(); j++) {
1635 GPortModel* inputPort = inputs[j];
1636 if (inputPort->isValueSet()) {
1638 script += model->getBBTKName();
1640 script += inputPort->getBBTKName();
1642 script += inputPort->getValue();
1650 // Create connections in the script. If the connection is made with a complex port, it is created the input or output
1652 std::string complexInputs = "";
1653 std::string complexOutputs = "";
1656 for (i = 0; i < (int) connections.size(); i++) {
1657 int id = connections[i];
1658 GObjectController *control = _controllers[id];
1659 GConnectorModel *model = (GConnectorModel*) control->getModel();
1662 GPortModel *start = model->getStartPort();
1663 GBoxModel *startBox = start->getParentBox();
1665 GPortModel *end = model->getEndPort();
1666 GBoxModel *endBox = end->getParentBox();
1668 if (startBox->getGObjectType() == GCOMPLEXINPUTPORT) {
1669 complexInputs += "input ";
1670 complexInputs += startBox->getBBTKName();
1672 complexInputs += " ";
1673 complexInputs += endBox->getBBTKName();
1674 complexInputs += ".";
1675 complexInputs += end->getBBTKName();
1677 complexInputs += " ";
1678 complexInputs += "\" \"";
1680 complexInputs += "\n";
1681 } else if (endBox->getGObjectType() == GCOMPLEXOUTPUTPORT) {
1682 complexOutputs += "output ";
1683 complexOutputs += endBox->getBBTKName();
1685 complexOutputs += " ";
1686 complexOutputs += startBox->getBBTKName();
1687 complexOutputs += ".";
1688 complexOutputs += start->getBBTKName();
1690 complexOutputs += " ";
1691 complexOutputs += "\" \"";
1693 complexOutputs += "\n";
1695 script += "connect ";
1696 script += startBox->getBBTKName();
1698 script += start->getBBTKName();
1702 //End Connection info
1703 script += endBox->getBBTKName();
1705 script += end->getBBTKName();
1712 script += "# Complex input ports\n";
1713 script += complexInputs;
1716 script += "# Complex output ports\n";
1717 script += complexOutputs;
1721 if((_MessageKind!="-")&&(_MessageLevel!="-"))
1723 script += "message ";
1724 script += _MessageKind;
1726 script += _MessageLevel;
1730 for (i = 0; i < (int) execBoxes.size(); i++)
1733 int id = execBoxes[i];
1734 GObjectController *control = _controllers[id];
1735 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1737 script += model->getBBTKName();
1742 script += "endefine";
1748 //=========================================================================
1750 void wxVtkSceneManager::deleteAllBoxes() {
1751 std::map<int, GObjectController*>::iterator it;
1752 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1753 GObjectController *cont = it->second;
1754 cont->removeFromScene();
1755 unregisterController((InteractorStyleMaracas*) cont);
1757 _selectedObjects.clear();
1758 _controllers.clear();
1761 //=========================================================================
1764 void wxVtkSceneManager::refresh() {
1765 _baseView->Refresh();
1767 //=========================================================================
1769 void wxVtkSceneManager::refreshScene()
1771 _baseView->RefreshView();
1774 //=========================================================================
1776 void wxVtkSceneManager::centerView()
1779 _baseView->GetRenderer()->ComputeVisiblePropBounds(bb);
1782 _baseView->GetRenderer()->GetActiveCamera()->GetFocalPoint(temp);
1783 _baseView->GetRenderer()->GetActiveCamera()->SetFocalPoint(0, 0, temp[2]);
1784 _baseView->GetRenderer()->GetActiveCamera()->GetPosition(temp);
1785 _baseView->GetRenderer()->GetActiveCamera()->SetPosition(0, 0, temp[2]);
1787 _baseView->GetRenderer()->ResetCamera();
1788 _baseView->GetRenderer()->ResetCameraClippingRange();
1791 double tt=_baseView->GetRenderer()->GetNearClippingPlaneTolerance();
1792 printf("EED wxVtkSceneManager::centerView() tolerance=%f\n",tt);
1794 _baseView->GetRenderer()->GetActiveCamera()->GetClippingRange(cr1,cr2);
1795 printf("EED wxVtkSceneManager::centerView() cr1=%f cr2=%f\n",cr1,cr2);
1796 _baseView->GetRenderer()->GetActiveCamera()->SetClippingRange(0.01,100000);
1797 _baseView->GetRenderer()->GetActiveCamera()->GetClippingRange(cr1,cr2);
1798 printf("EED wxVtkSceneManager::centerView() cr1=%f cr2=%f\n",cr1,cr2);
1801 _baseView->GetRenderer()->Render();
1804 //=========================================================================
1806 void wxVtkSceneManager::saveDiagram(std::string &content)
1810 content += "CATEGORY:";
1811 content += GetCategory();
1814 content += "DESCRIPTION:";
1815 content += GetDescription();
1818 content += "AUTHOR:";
1819 content += GetAuthor();
1822 //Print info IF COMPLEX BOX
1823 content += "COMPLEXBOX:";
1824 if (_isComplexBox) {
1825 content += "TRUE\n";
1827 content += "COMPLEXBOXNAME:";
1828 content += GetCbName();
1831 content += "PACKAGENAME:";
1832 content += GetCbPackageName();
1835 /* CHANGE TO THE VERSION 1.4 RaC2012 2nd HackFest
1836 * External inputs are possible for applications and complex boxes
1837 //Print info complex input ports
1838 std::vector<int> inputs = getComplexInputPorts();
1839 int insize = inputs.size();
1840 content += "COMPLEXINPUTS:";
1841 sprintf(buffer, "%d", insize);
1845 for (int i = 0; i < insize; i++) {
1847 GObjectController *cont = _controllers[id];
1848 cont->getModel()->save(content);
1852 //Print info complex output ports
1853 std::vector<int> outputs = getComplexOutputPorts();
1854 int outsize = outputs.size();
1855 content += "COMPLEXOUTPUTS:";
1856 sprintf(buffer, "%d", outsize);
1860 for (int i = 0; i < outsize; i++) {
1861 int id = outputs[i];
1862 GObjectController *cont = _controllers[id];
1863 cont->getModel()->save(content);
1867 content += "FALSE\n";
1870 // CHANGE TO THE VERSION 1.4 RaC2012 2nd HackFest
1871 // External inputs are possible for applications and complex boxes
1872 std::vector<int> inputs = getComplexInputPorts();
1873 int insize = inputs.size();
1874 content += "COMPLEXINPUTS:";
1875 sprintf(buffer, "%d", insize);
1879 for (int i = 0; i < insize; i++) {
1881 GObjectController *cont = _controllers[id];
1882 cont->getModel()->save(content);
1886 std::vector<int> boxes = getBlackBoxes();
1887 int bsize = boxes.size();
1888 content += "BOXES:";
1889 sprintf(buffer, "%d", bsize);
1893 for (int i = 0; i < bsize; i++) {
1895 // std::cout<<"id "<<id<<std::endl;//CFT
1896 GObjectController *cont = _controllers[id];
1897 // std::cout<<"nombre: "<<cont->getStatusText()<<std::endl;//CFT
1898 // std::cout<<"tipo: "<<cont->getModel()->getBBTKType()<<std::endl;//CFT
1899 // //boxesDiagram[i] = cont->getModel()->getBBTKType();//CFT
1900 // std::cout<<"nname: "<<cont->getModel()->getBBTKName()<<std::endl;//CFT
1901 // std::cout<<"categorie: "<<GetCategory()<<std::endl;//CFT
1902 // std::cout<<"type: "<<cont->getModel()->getGObjectType()<<std::endl;//CFT
1903 cont->getModel()->save(content);
1907 std::vector<int> connections = getConnections();
1908 int csize = connections.size();
1909 content += "CONNECTIONS:";
1910 sprintf(buffer, "%d", csize);
1914 for (int i = 0; i < csize; i++) {
1915 int id = connections[i];
1916 GObjectController *cont = _controllers[id];
1917 cont->getModel()->save(content);
1922 //=========================================================================
1923 void wxVtkSceneManager::getCleanLine(stringstream &inputStream, std::string &line)
1925 getline(inputStream, line,'\n');
1926 int size = line.length();
1929 if ( line[ size-1 ]==13 )
1931 line.erase(size-1,1);
1936 //=========================================================================
1937 void wxVtkSceneManager::loadDiagram(stringstream &inputStream)
1940 std::string version = "<void>";
1941 std::string line = "";
1942 char delims[] = ":";
1943 char *result = NULL;
1944 char poort[POORT_MAX_LINE_SIZE_INTERPRETER];
1946 getCleanLine(inputStream, line);
1949 while (!inputStream.eof()) {
1950 if (line == "" || line[0] == '#') {
1952 getCleanLine(inputStream, line);
1954 if (line == "# - BBTKGEditor v 1.0 BBG BlackBox Diagram file") {
1955 version = line.substr(18, 3);
1957 if (line == "# - BBTKGEditor v 1.1 BBG BlackBox Diagram file") {
1958 version = line.substr(18, 3);
1960 if (line == "# - BBTKGEditor v 1.2 BBG BlackBox Diagram file") {
1961 version = line.substr(18, 3);
1963 if (line == "# - BBTKGEditor v 1.3 BBG BlackBox Diagram file") {
1964 version = line.substr(18, 3);
1966 if (line == "# - BBTKGEditor v 1.4 BBG BlackBox Diagram file") {
1967 version = line.substr(18, 3);
1969 if (line == "# - BBTKGEditor v 1.5 BBG BlackBox Diagram file") {
1970 version = line.substr(18, 3);
1972 } else if (line == "APP_START") {
1982 if ((version != "1.0") && (version != "1.1")) {
1983 getCleanLine(inputStream, line);//CATEGORY:<category of the box>
1984 char categoryTmp[30];
1985 strcpy(categoryTmp, line.c_str());
1986 result = strtok(categoryTmp, delims);
1987 result = strtok(NULL, delims);
1988 SetCategory(result);
1990 getCleanLine(inputStream, line);//DESCRIPTION:<description of the box>
1991 char descriptionTmp[1024];
1992 strcpy(descriptionTmp, line.c_str());
1993 result = strtok(descriptionTmp, delims);
1994 result = strtok(NULL, delims);
1995 SetDescription(result);
1997 getCleanLine(inputStream, line);//AUTHOR:<author>
1998 char authorTmp[255];
1999 strcpy(authorTmp, line.c_str());
2000 result = strtok(authorTmp, delims);
2001 result = strtok(NULL, delims);
2006 getCleanLine(inputStream, line);//COMPLEX_BOX:TRUE|FALSE
2007 char complexTmp[30];
2008 strcpy(complexTmp, line.c_str());
2009 result = strtok(complexTmp, delims);
2010 result = strtok(NULL, delims);
2011 std::string isComplexBox(result);
2013 if (isComplexBox == "TRUE")
2015 _isComplexBox = true;
2017 if ((version != "1.0") && (version != "1.1"))
2019 getCleanLine(inputStream, line);//COMPLEXNAME:<name of the complex box>
2020 char complexboxnameTmp[255];
2021 strcpy(complexboxnameTmp, line.c_str());
2022 result = strtok(complexboxnameTmp, delims);
2023 result = strtok(NULL, delims);
2026 getCleanLine(inputStream, line);//PACKAGENAME:<name of the package of the box>
2027 char packagenameTmp[255];
2028 strcpy(packagenameTmp, line.c_str());
2029 result = strtok(packagenameTmp, delims);
2030 result = strtok(NULL, delims);
2031 SetCbPackageName(result);
2032 } // if version !1.0 !1.1
2036 //-----------------------
2037 //- COMPLEX INPUT PORTS
2038 //-----------------------
2039 getCleanLine(inputStream, line);//COMPLEXINPUTS:num
2041 strcpy(inputs, line.c_str());
2042 result = strtok(inputs, delims);
2043 result = strtok(NULL, delims);
2046 std::istringstream inps(result);
2049 for (int i = 0; i < numInputs; i++)
2052 getCleanLine(inputStream, line);//COMPLEX_PORT
2053 getCleanLine(inputStream, line);//name
2054 std::string inputPortName(line);
2057 getCleanLine(inputStream, line);//xInic:yInic:zInic
2059 strcpy(coord, line.c_str());
2060 result = strtok(coord, delims);//xInic
2061 std::string xInic(result);
2062 result = strtok(NULL, delims);//yInic
2063 std::string yInic(result);
2064 result = strtok(NULL, delims);//zInic
2065 std::string zInic(result);
2067 double xIn, yIn, zIn;
2068 std::istringstream xSt(xInic);
2070 std::istringstream ySt(yInic);
2072 std::istringstream zSt(zInic);
2077 if (zIn==900) zIn=GPOSITION_Z;
2078 } // if version <=1.2
2080 getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
2082 configGComBoxInputOutputPort(true, inputPortName, xIn, yIn, zIn);
2084 } // for input complex box
2085 } // if version < 1.4
2089 //-----------------------
2090 //- COMPLEX OUTPUT PORTS
2091 //-----------------------
2093 getCleanLine(inputStream, line);//COMPLEXOUTPUTS:num
2095 strcpy(outputs, line.c_str());
2096 result = strtok(outputs, delims);
2097 result = strtok(NULL, delims);
2100 std::istringstream outps(result);
2101 outps >> numOutputs;
2103 for (int i = 0; i < numOutputs; i++)
2106 getCleanLine(inputStream, line);//COMPLEX_PORT
2107 getCleanLine(inputStream, line);//name
2108 std::string outputPortName(line);
2111 getCleanLine(inputStream, line);//xInic:yInic:zInic
2113 strcpy(coord, line.c_str());
2114 result = strtok(coord, delims);//xInic
2115 std::string xInic(result);
2116 result = strtok(NULL, delims);//yInic
2117 std::string yInic(result);
2118 result = strtok(NULL, delims);//zInic
2119 std::string zInic(result);
2121 double xIn, yIn, zIn;
2122 std::istringstream xSt(xInic);
2124 std::istringstream ySt(yInic);
2126 std::istringstream zSt(zInic);
2131 if (zIn==900) zIn=GPOSITION_Z;
2140 getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
2142 configGComBoxInputOutputPort(false, outputPortName, xIn, yIn, zIn);
2144 } // for output complex box
2145 } // if isComplexBox
2148 // RaC2012 2nd Hackfest
2149 if(version >= "1.4")
2151 //-----------------------
2152 //- EXTERNAL INPUT PORTS
2153 //-----------------------
2154 getCleanLine(inputStream, line);//COMPLEXINPUTS:num
2156 strcpy(inputs, line.c_str());
2157 result = strtok(inputs, delims);
2158 result = strtok(NULL, delims);
2161 std::istringstream inps(result);
2164 for (int i = 0; i < numInputs; i++)
2166 getCleanLine(inputStream, line);//COMPLEX_PORT
2167 getCleanLine(inputStream, line);//name
2168 std::string inputPortName(line);
2169 getCleanLine(inputStream, line);//xInic:yInic:zInic
2171 strcpy(coord, line.c_str());
2172 result = strtok(coord, delims);//xInic
2173 std::string xInic(result);
2174 result = strtok(NULL, delims);//yInic
2175 std::string yInic(result);
2176 result = strtok(NULL, delims);//zInic
2177 std::string zInic(result);
2178 double xIn, yIn, zIn;
2179 std::istringstream xSt(xInic);
2181 std::istringstream ySt(yInic);
2183 std::istringstream zSt(zInic);
2187 if (zIn==900) zIn=GPOSITION_Z;
2195 getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
2196 configGComBoxInputOutputPort(true, inputPortName, xIn, yIn, zIn);
2197 } // for external input
2198 } // if(version >= "1.4")
2201 getCleanLine(inputStream, line);//BOXES:num
2203 strcpy(boxes, line.c_str());
2204 result = strtok(boxes, delims);
2205 result = strtok(NULL, delims);
2208 std::istringstream is(result);
2211 for (int i = 0; i < numBoxes; i++)
2214 getCleanLine(inputStream, line);//BOX
2215 getCleanLine(inputStream, line);//package:type:name
2217 strcpy(box, line.c_str());
2218 result = strtok(box, delims);//package
2219 std::string package(result);
2220 result = strtok(NULL, delims);//type
2221 std::string type(result);
2222 result = strtok(NULL, delims);//name
2223 std::string name(result);
2226 getCleanLine(inputStream, line);//ISEXEC:TRUE|FALSE
2228 strcpy(exec, line.c_str());
2229 result = strtok(exec, delims);//ISEXEC
2230 result = strtok(NULL, delims);//TRUE|FALSE
2231 std::string isExec(result);
2234 getCleanLine(inputStream, line);//xInic:yInic:zInic
2236 strcpy(coord, line.c_str());
2237 result = strtok(coord, delims);//xInic
2238 std::string xInic(result);
2239 result = strtok(NULL, delims);//yInic
2240 std::string yInic(result);
2241 result = strtok(NULL, delims);//zInic
2242 std::string zInic(result);
2243 double xIn, yIn, zIn;
2244 std::istringstream xSt(xInic);
2246 std::istringstream ySt(yInic);
2248 std::istringstream zSt(zInic);
2253 if (zIn==900) zIn=GPOSITION_Z;
2262 getCleanLine(inputStream, line);//xEnd:yEnd:zEnd
2263 strcpy(coord, line.c_str());
2264 result = strtok(coord, delims);//xEnd
2265 std::string xEnd(result);
2266 result = strtok(NULL, delims);//yEnd
2267 std::string yEnd(result);
2268 result = strtok(NULL, delims);//zEnd
2269 std::string zEnd(result);
2271 double xEn, yEn, zEn;
2272 std::istringstream xEt(xEnd);
2274 std::istringstream yEt(yEnd);
2276 std::istringstream zEt(zEnd);
2281 if (zEn==900) zEn=GPOSITION_Z;
2284 yEn = yIn-BOX_HEIGHT;
2286 bool boxExecutable = false;
2287 if (isExec == "TRUE")
2289 boxExecutable = true;
2292 int idBox = createGBlackBox(xIn, yIn, package, type);
2293 configGBlackBox(idBox, xIn, yIn, zIn, name, boxExecutable, xEn, yEn, zEn);
2295 GObjectController *cont = _controllers[idBox];
2296 GBlackBoxModel *bbmod = (GBlackBoxModel*) cont->getModel();
2299 getCleanLine(inputStream, line);//PORT o FIN_BOX
2300 std::string port = line.substr(0, 4);
2301 while (port == "PORT")
2303 getCleanLine(inputStream, line);//name:value
2304 if (line.length()>=POORT_MAX_LINE_SIZE_INTERPRETER-1)
2306 line=line.substr(0, POORT_MAX_LINE_SIZE_INTERPRETER-1);
2309 strcpy(poort, line.c_str());
2310 result = strtok(poort, delims);//name
2311 std::string name(result);
2313 //EED 16 oct 2012 Adding at the end character " if necesary in the value definition
2314 result = strtok(NULL, delims);//value
2315 if (( result[0]=='"' ) && ( result[ strlen(result)-1 ]!='"' ) )
2317 std::string tmpString=" ";
2318 tmpString[0]=34; // character "
2319 strcat(result,tmpString.c_str());
2321 std::string value(result);
2322 bbmod->setValueToInput(name, value);
2323 getCleanLine(inputStream, line);//PORT o FIN_BOX
2324 port = line.substr(0, 4);
2327 //EED bbmod->notifyObservers(_idManager);
2332 getCleanLine(inputStream, line);//CONNECTIONS:num
2334 strcpy(conns, line.c_str());
2335 result = strtok(conns, delims);
2336 result = strtok(NULL, delims);
2338 std::istringstream isCons(result);
2342 for (int i = 0; i < numConns; i++)
2345 getCleanLine(inputStream, line);//CONNECTION
2346 getCleanLine(inputStream, line);//Startbox.PortName:EndBox.PortName
2348 strcpy(connec, line.c_str());
2349 result = strtok(connec, delims);
2350 std::string nameStartBox(result);
2351 result = strtok(NULL, delims);
2352 std::string nameStartPort(result);
2353 result = strtok(NULL, delims);
2354 std::string nameEndBox(result);
2355 result = strtok(NULL, delims);
2356 std::string nameEndPort(result);
2357 int idCon = configGConnetion(nameStartBox, nameStartPort,nameEndBox, nameEndPort);
2358 if (version != "1.0") {
2359 //Readding control points of the manualContour
2360 GConnectorController *tempp = (GConnectorController*) _controllers[idCon];
2361 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2362 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2363 getCleanLine(inputStream, line); //NumberOfControlPoints:##
2364 strcpy(conns, line.c_str());
2365 result = strtok(conns, delims);
2366 result = strtok(NULL, delims);
2367 int numberOfControlPoints;
2368 std::istringstream isCons(result);
2369 isCons >> numberOfControlPoints;
2370 for (int ii = 0; ii < numberOfControlPoints; ii++) {
2371 getCleanLine(inputStream, line); //XX:YY:ZZ
2373 strcpy(connec, line.c_str());
2375 result = strtok(connec, delims);
2376 std::istringstream isPointX(result);
2378 result = strtok(NULL, delims);
2379 std::istringstream isPointY(result);
2381 result = strtok(NULL, delims);
2382 std::istringstream isPointZ(result);
2386 if (pz==900) pz=GPOSITION_Z;
2394 conMod->getManualContourModel()->InsertPoint_id(ii + 1, px, py, pz);
2395 conView->getManualContourView()->AddPoint();
2397 }// if version !=1.0
2401 //=========================================================================
2404 //=========================================================================
2405 void wxVtkSceneManager::configGComBoxInputOutputPort(bool inputoutput,
2406 std::string portName, double xIn, double yIn, double zIn)
2409 if (inputoutput == true) {
2410 idPort = createGComplexBoxInputPort(portName);
2412 idPort = createGComplexBoxOutputPort(portName);
2414 GObjectController *cont = _controllers[idPort];
2415 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2416 cbmod->setInicPoint(xIn, yIn, zIn);
2417 cbmod->notifyObservers(_idManager);
2419 //=========================================================================
2422 //=========================================================================
2423 GBoxModel* wxVtkSceneManager::findGBox(std::string boxname)
2428 GBoxModel *boxModel = NULL;
2429 std::vector<int> lstB = getBlackBoxes();
2430 for (j = 0; j < (int) lstB.size(); j++) {
2432 bMod = (GBoxModel*) _controllers[idB]->getModel();
2433 if (_controllers[idB]->getModel()->getBBTKName() == boxname)
2441 if (boxModel == NULL) {
2442 std::vector<int> lstInputs = getComplexInputPorts();
2443 for (j = 0; j < (int) lstInputs.size(); j++) {
2445 bMod = (GBoxModel*) _controllers[idB]->getModel();
2446 if (_controllers[idB]->getModel()->getBBTKName() == boxname)
2454 std::vector<int> lstOutputs = getComplexOutputPorts();
2455 for (j = 0; j < (int) lstOutputs.size(); j++) {
2456 int idB = lstOutputs[j];
2457 bMod = (GBoxModel*) _controllers[idB]->getModel();
2458 if (_controllers[idB]->getModel()->getBBTKName() == boxname)
2470 //=========================================================================
2473 int wxVtkSceneManager::configGConnetion(std::string nameStartBox,
2474 std::string nameStartPort, std::string nameEndBox,
2475 std::string nameEndPort) {
2477 GBoxModel *boxModel;
2478 GPortModel *startP = NULL;
2479 GPortModel *endP = NULL;
2481 boxModel = findGBox(nameStartBox);
2482 if(boxModel == NULL)
2484 printf("RaC: ERROR in wxVtkSceneManager::configGConnetion A box to connect start port %s is null. Box name is probably wrong.\n", nameStartPort.c_str());
2486 if (boxModel != NULL) {
2487 startP = boxModel->getOutputPort(nameStartPort);
2489 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() );
2493 boxModel = findGBox(nameEndBox);
2494 if(boxModel == NULL)
2496 printf("RaC: ERROR in wxVtkSceneManager::configGConnetion A box to connect start port %s is null. Box name is probably wrong.\n", nameStartPort.c_str());
2498 if (boxModel != NULL) {
2499 endP = boxModel->getInputPort(nameEndPort);
2501 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());
2506 int idCon = createGConnector(startP);
2508 _worldState = NOTHING_HAPPENS;
2509 GConnectorController *tempp = (GConnectorController*) _controllers[idCon];
2511 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2512 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2513 tempp->endContourCreation();
2514 conMod->setEndPort(endP);
2515 conView->updateStartEndPoints();
2519 //=========================================================================
2521 bool wxVtkSceneManager::boxExist(std::string boxname) {
2523 std::map<int, GObjectController*>::iterator it;
2524 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2525 GObjectController *cont = it->second;
2526 if (cont->getModel()->getBBTKName() == boxname) {
2533 //=========================================================================
2535 std::vector<int> wxVtkSceneManager::getBlackBoxes() {
2536 std::vector<int> vect;
2537 std::map<int, GObjectController*>::iterator it;
2538 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2539 GObjectController *cont = it->second;
2540 if (cont->getGObjectType() == GBLACKBOX) {
2541 vect.push_back(cont->getId());
2547 //=========================================================================
2549 std::vector<int> wxVtkSceneManager::getComplexInputPorts() {
2550 std::vector<int> vect;
2551 std::map<int, GObjectController*>::iterator it;
2552 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2553 GObjectController *cont = it->second;
2554 if (cont->getGObjectType() == GCOMPLEXINPUTPORT) {
2555 vect.push_back(cont->getId());
2561 //=========================================================================
2563 std::vector<int> wxVtkSceneManager::getComplexOutputPorts() {
2564 std::vector<int> vect;
2565 std::map<int, GObjectController*>::iterator it;
2566 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2567 GObjectController *cont = it->second;
2568 if (cont->getGObjectType() == GCOMPLEXOUTPUTPORT) {
2569 vect.push_back(cont->getId());
2575 //=========================================================================
2577 std::vector<int> wxVtkSceneManager::getConnections() {
2578 std::vector<int> vect;
2579 std::map<int, GObjectController*>::iterator it;
2580 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2581 GObjectController *cont = it->second;
2582 if (cont->getGObjectType() == GCONNECTOR) {
2583 vect.push_back(cont->getId());
2589 //=========================================================================
2591 bool wxVtkSceneManager::isComplexBox() {
2592 return _isComplexBox;
2595 //=========================================================================
2597 void wxVtkSceneManager::setComplexBox(bool val) {
2598 _isComplexBox = val;
2601 //=========================================================================
2603 int wxVtkSceneManager::addObjectController(GObjectController* objController) {
2604 //Register the controller of the new object
2605 registerController((InteractorStyleMaracas*) objController);
2606 //Add the object to the objects list
2607 int newId = _contLastId;//_controllers.size();
2608 objController->setId(newId);
2609 _controllers[newId] = objController;
2610 //std::cout << "DFCH: int wxVtkSceneManager::addObjectController(GObjectController* objController) ---- _contLastId = " << _contLastId << std::endl;
2615 //=========================================================================
2617 void wxVtkSceneManager::DuplicateObjects(std::map<int, GObjectController*> objectsMap)
2619 std::map<int, int> oldIdNewIdBoxes;
2620 std::vector<int> connections;
2621 std::vector<int> newBoxesID;
2622 std::map<int, GObjectController*>::iterator it;
2623 for (it = objectsMap.begin(); it != objectsMap.end(); ++it)
2625 GObjectController *cont = it->second;
2626 int type = cont->getGObjectType();
2627 if (type == GBLACKBOX)
2630 double xInic, yInic, zInic;
2631 GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
2632 copyBox->getInicPoint(xInic, yInic, zInic);
2633 int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(), copyBox->getBBTKType());
2635 int idcB = copyBox->getObjectId();
2636 oldIdNewIdBoxes[idcB] = idBox;
2637 cont = _controllers[idBox];
2638 GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
2639 newbox->setInicPoint(xInic, yInic, zInic);
2640 int num = newbox->getNumInputPorts();
2641 for (int j = 0; j < num; j++)
2643 newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
2647 // newbox->move(xInic + 20, yInic + 20, zInic);
2648 newbox->move(xInic + 14, yInic + 6, zInic);
2650 newbox->notifyObservers(_idManager);
2651 newBoxesID.push_back(newbox->getObjectId());
2653 } else if (type == GCONNECTOR) {
2654 int idCon = cont->getId();
2655 connections.push_back(idCon);
2660 for (int i = 0; i < (int) connections.size(); i++)
2662 int objId = connections[i];
2663 GObjectController *cont = objectsMap[objId];
2664 GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
2666 GPortModel* startPort = connectModel->getStartPort();
2667 int startPortIndex = startPort->getPosInBox();
2668 GPortModel* endPort = connectModel->getEndPort();
2669 int endPortIndex = endPort->getPosInBox();
2671 GBlackBoxModel* startPortParentBox =
2672 (GBlackBoxModel*) startPort->getParentBox();
2673 GBlackBoxModel* endPortParentBox =
2674 (GBlackBoxModel*) endPort->getParentBox();
2676 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2677 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2679 GBlackBoxModel* newStartBox =
2680 (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
2681 GBlackBoxModel* newEndBox =
2682 (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
2684 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2685 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2687 // Creates connection
2688 int idCon = createGConnector(newStartPort);
2689 GConnectorController *tempp =
2690 (GConnectorController*) _controllers[idCon];
2691 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2692 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2693 tempp->endContourCreation();
2694 conMod->setEndPort(newEndPort);
2695 conView->updateStartEndPoints();
2698 /// the new selected boxes are the duplicate ones
2700 UnSelectBlackBoxes();
2701 for (int i = 0; i < newBoxesID.size(); i++)
2703 _selectedObjects.push_back(newBoxesID.at(i));
2706 for (int i = 0; i < (int) _selectedObjects.size(); i++)
2708 int id = _selectedObjects[i];
2709 GObjectController* cont = _controllers[id];
2710 cont->getView()->setState(SELECTED);
2711 cont->getModel()->notifyObservers(_idManager);
2716 //=========================================================================
2718 int wxVtkSceneManager::getNumSelectedObjects() {
2719 return _selectedObjects.size();
2722 //=========================================================================
2724 std::map<int, GObjectController*> wxVtkSceneManager::getSelectedObjects() {
2725 std::map<int, GObjectController*> mapSelected;
2727 std::map<int, GObjectController*>::iterator it;
2728 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2729 GObjectController *cont = it->second;
2730 if (cont->getGObjectType() == GBLACKBOX && cont->getView()->getState()
2732 mapSelected[cont->getId()] = cont;
2736 std::map<int, GObjectController*>::iterator it2;
2737 for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2) {
2738 GObjectController *cont = it2->second;
2739 if (cont->getGObjectType() == GCONNECTOR) {
2740 GConnectorModel* cmod = (GConnectorModel*) cont->getModel();
2741 GBoxModel* endPortParentBox = cmod->getEndPort()->getParentBox();
2742 GBoxModel* startPortParentBox =
2743 cmod->getStartPort()->getParentBox();
2745 std::map<int, GObjectController*>::iterator iterOBJ1 =
2746 mapSelected.find(startPortParentBox->getObjectId());
2747 std::map<int, GObjectController*>::iterator iterOBJ2 =
2748 mapSelected.find(endPortParentBox->getObjectId());
2750 if (iterOBJ1 != mapSelected.end() && iterOBJ2 != mapSelected.end()) {
2751 int ID = cont->getId();
2752 mapSelected[ID] = cont;
2759 //=========================================================================
2761 void wxVtkSceneManager::addObjects(std::map<int, GObjectController*> objectsMap) {
2763 std::map<int, int> oldIdNewIdBoxes;
2764 std::vector<int> connections;
2766 std::map<int, GObjectController*>::iterator it;
2767 for (it = objectsMap.begin(); it != objectsMap.end(); ++it) {
2768 GObjectController *cont = it->second;
2769 int type = cont->getGObjectType();
2771 if (type == GBLACKBOX) {
2773 double xInic, yInic, zInic;
2774 GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
2775 copyBox->getInicPoint(xInic, yInic, zInic);
2776 int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(),copyBox->getBBTKType());
2778 int idcB = copyBox->getObjectId();
2779 oldIdNewIdBoxes[idcB] = idBox;
2780 cont = _controllers[idBox];
2781 GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
2782 newbox->setInicPoint(xInic, yInic, zInic);
2783 int num = newbox->getNumInputPorts();
2784 for (int j = 0; j < num; j++)
2786 newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
2788 newbox->notifyObservers(_idManager);
2789 } else if (type == GCONNECTOR) {
2790 int idCon = cont->getId();
2791 connections.push_back(idCon);
2796 for (int i = 0; i < (int) connections.size(); i++) {
2797 int objId = connections[i];
2798 GObjectController *cont = objectsMap[objId];
2799 GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
2801 GPortModel* startPort = connectModel->getStartPort();
2802 int startPortIndex = startPort->getPosInBox();
2803 GPortModel* endPort = connectModel->getEndPort();
2804 int endPortIndex = endPort->getPosInBox();
2806 GBlackBoxModel* startPortParentBox =
2807 (GBlackBoxModel*) startPort->getParentBox();
2808 GBlackBoxModel* endPortParentBox =
2809 (GBlackBoxModel*) endPort->getParentBox();
2811 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2812 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2814 GBlackBoxModel* newStartBox =
2815 (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
2816 GBlackBoxModel* newEndBox =
2817 (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
2819 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2820 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2822 // Creates connection
2823 int idCon = createGConnector(newStartPort);
2824 GConnectorController *tempp =
2825 (GConnectorController*) _controllers[idCon];
2826 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2827 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2828 tempp->endContourCreation();
2829 conMod->setEndPort(newEndPort);
2830 conView->updateStartEndPoints();
2833 std::map<int, int>::iterator itIds;
2834 for (itIds = oldIdNewIdBoxes.begin(); itIds != oldIdNewIdBoxes.end(); ++itIds) {
2835 int idOld = itIds->first;
2836 int idNew = itIds->second;
2838 GBlackBoxModel* oldBox =
2839 (GBlackBoxModel*) objectsMap[idOld]->getModel();
2840 GBlackBoxModel* newBox =
2841 (GBlackBoxModel*) _controllers[idNew]->getModel();
2843 std::vector<int> oldInputConnections = oldBox->getConnectedInputs();
2844 std::vector<int> oldOutputConnections = oldBox->getConnectedOutputs();
2845 std::vector<int> newInputConnections = newBox->getConnectedInputs();
2846 std::vector<int> newOutputConnections = newBox->getConnectedOutputs();
2848 for (int k = 0; k < (int) oldInputConnections.size(); k++) {
2850 //EED int toCreate=-1;
2851 for (int l = 0; l < (int) newInputConnections.size() && !exist; l++) {
2852 if (oldInputConnections[k] == newInputConnections[l]) {
2857 if (exist == false) {
2858 //Create complex input
2859 int posInBox = oldInputConnections[k];
2860 GPortModel* inputPort = oldBox->getInputPort(posInBox);
2861 std::string inputPortName = inputPort->getBBTKName();
2862 int idInputPort = createGComplexBoxInputPort(inputPortName);
2863 GObjectController *cont = _controllers[idInputPort];
2864 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2865 double xIn, yIn, zIn;
2866 inputPort->getInicPoint(xIn, yIn, zIn);
2868 cbmod->setInicPoint(xIn, yIn, zIn);
2869 cbmod->notifyObservers(_idManager);
2871 GPortModel* inputPortEnd = newBox->getInputPort(posInBox);
2873 // Creates connection
2874 int idCon = createGConnector(cbmod->getOutputPort(0));
2875 GConnectorController *tempp =
2876 (GConnectorController*) _controllers[idCon];
2877 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2878 vtkGConnectorView *conView =
2879 (vtkGConnectorView*) tempp->getView();
2880 tempp->endContourCreation();
2881 conMod->setEndPort(inputPortEnd);
2882 conView->updateStartEndPoints();
2888 for (int k = 0; k < (int) oldOutputConnections.size(); k++) {
2890 //EED int toCreate=-1;
2891 for (int l = 0; l < (int) newOutputConnections.size() && !exist; l++) {
2892 if (oldOutputConnections[k] == newOutputConnections[l]) {
2897 if (exist == false) {
2898 //Create complex output
2899 int posInBox = oldOutputConnections[k];
2900 GPortModel* outputPort = oldBox->getOutputPort(posInBox);
2901 std::string outputPortName = outputPort->getBBTKName();
2902 int idOutputPort = createGComplexBoxOutputPort(outputPortName);
2903 GObjectController *cont = _controllers[idOutputPort];
2904 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2905 double xIn, yIn, zIn;
2906 outputPort->getInicPoint(xIn, yIn, zIn);
2908 cbmod->setInicPoint(xIn, yIn, zIn);
2909 cbmod->notifyObservers(_idManager);
2911 GPortModel* outputPortEnd = newBox->getOutputPort(posInBox);
2913 // Creates connection
2914 int idCon = createGConnector(outputPortEnd);
2915 GConnectorController *tempp =
2916 (GConnectorController*) _controllers[idCon];
2917 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2918 vtkGConnectorView *conView =
2919 (vtkGConnectorView*) tempp->getView();
2920 tempp->endContourCreation();
2921 conMod->setEndPort(cbmod->getInputPort(0));
2922 conView->updateStartEndPoints();
2932 //=========================================================================
2933 void wxVtkSceneManager::SetCbName(std::string cbName) {
2935 if (_cbName == "") {
2936 _cbName = "<complex box name>";
2940 //=========================================================================
2941 std::string wxVtkSceneManager::GetCbName() {
2945 //=========================================================================
2946 void wxVtkSceneManager::SetCbPackageName(std::string packagename) {
2947 _cbPackageName = packagename;
2948 if (_cbPackageName == "") {
2949 _cbPackageName = "<package name of the complex box>";
2953 //=========================================================================
2954 std::string wxVtkSceneManager::GetCbPackageName() {
2955 return _cbPackageName;
2958 //=========================================================================
2959 void wxVtkSceneManager::SetAuthor(std::string author) {
2961 if (_Author == "") {
2962 _Author = "<author of the box>";
2966 //=========================================================================
2967 std::string wxVtkSceneManager::GetAuthor() {
2971 //=========================================================================
2972 void wxVtkSceneManager::SetCategory(std::string category) {
2973 _Category = category;
2974 if (_Category == "") {
2975 _Category = "<category of the box>";
2979 //=========================================================================
2980 std::string wxVtkSceneManager::GetCategory() {
2984 //=========================================================================
2985 void wxVtkSceneManager::SetDescription(std::string description) {
2986 _Description = description;
2987 if (_Description == "") {
2988 _Description = "<description of the box>";
2992 //=========================================================================
2993 std::string wxVtkSceneManager::GetDescription() {
2994 return _Description;
2997 //=========================================================================
2999 void wxVtkSceneManager::SetMessageKind(std::string kind) {
3000 _MessageKind = kind;
3004 //=========================================================================
3006 std::string wxVtkSceneManager::GetMessageKind(){
3007 return _MessageKind;
3010 //=========================================================================
3012 void wxVtkSceneManager::SetMessageLevel(std::string Level){
3013 _MessageLevel = Level;
3016 //=========================================================================
3018 std::string wxVtkSceneManager::GetMessageLevel(){
3019 return _MessageLevel;
3022 //=========================================================================
3024 std::vector< std::string> wxVtkSceneManager::GetExternalInputsNames()
3027 std::vector< std::string> extInputs;
3028 std::map<int, GObjectController*>::iterator it;
3029 for (it = _controllers.begin(); it != _controllers.end(); ++it)
3031 GObjectController *cont = it->second;
3032 if (cont->getGObjectType() == GCOMPLEXINPUTPORT)
3034 extInputs.push_back(cont->getModel()->getBBTKName());
3040 //=========================================================================
3044 void wxVtkSceneManager::printAll(int com , int sta ){
3046 int tmpState = sta ;
3047 if ( tmpState == NOTHING_HAPPENS ) {
3048 std::cout << "CONTROLER STATE---->NOTHING_HAPPENS\n" ;
3050 if ( tmpState == HIGHLIGHTED ) {
3051 std::cout << "CONTROLER STATE---->HIGHLIGHTED\n" ;
3053 if ( tmpState == POSSIBLE_CONNECTION ) {
3054 std::cout << "CONTROLER STATE---->POSSIBLE_CONNECTION\n" ;
3056 if ( tmpState == SELECTED_POSSIBLE_CONNECTION ) {
3057 std::cout << "CONTROLER STATE---->SELECTED_POSSIBLE_CONNECTION\n" ;
3059 if ( tmpState == CLICKED ) {
3060 std::cout << "CONTROLER STATE---->CLICKED\n" ;
3062 if ( tmpState == DRAG ) {
3063 std::cout << "CONTROLER STATE---->DRAG\n" ;
3065 if ( tmpState == SELECTED ) {
3066 std::cout << "CONTROLER STATE---->SELECTED\n" ;
3068 if ( tmpState == CREATING_CONTOUR ) {
3069 std::cout << "CONTROLER STATE---->CREATING_CONTOUR\n" ;
3075 if ( command == INIT_CREATION_CONTOUR ) {
3076 std::cout << "COMMAND ----> INIT_CREATION_CONTOUR \n" ;
3078 if ( command == FIN_CREATION_CONTOUR ) {
3079 std::cout << "COMMAND ----> FIN_CREATION_CONTOUR \n" ;
3081 if ( command == ADD_TO_SELECTED ) {
3082 std::cout << "COMMAND ----> ADD_TO_SELECTED \n" ;
3084 if ( command == DRAG_OBJECTS ) {
3085 std::cout << "COMMAND ----> DRAG_OBJECTS \n" ;
3087 if ( command == EDIT_BLACKBOX ) {
3088 std::cout << "COMMAND ----> EDIT_BLACKBOX \n" ;
3090 if ( command == REMOVE_FROM_SELECTED ) {
3091 std::cout << "COMMAND ----> REMOVE_FROM_SELECTED \n" ;
3097 } // EO namespace bbtk