]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxVtkSceneManager.cxx
#3259 Export Format Python and JavaScript
[bbtkGEditor.git] / lib / EditorGraphicBBS / bbsWxGUIEditorGraphic / wxVtkSceneManager.cxx
1 /*
2 # ---------------------------------------------------------------------
3 #
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image 
5 #                        pour la Santé)
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 #
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.
14 #
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
19 #  liability. 
20 #
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 # ------------------------------------------------------------------------  
24 */
25
26 /*=========================================================================
27  Program:   bbtk
28  Module:    $RCSfile$
29  Language:  C++
30  Date:      $Date$
31  Version:   $Revision$
32  =========================================================================*/
33
34 /* ---------------------------------------------------------------------
35
36  * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
37  * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
38  *
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.
45  *
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
50  *  liability.
51  *
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  * ------------------------------------------------------------------------ */
55
56 /**
57  *  \file
58  *  \brief Class bbtk::wxVtkSceneManager .
59  */
60
61 #include "wxVtkSceneManager.h"
62
63 #include <vtkPolygon.h>
64 #include <vtkUnstructuredGrid.h>
65
66 namespace bbtk {
67
68 #define POORT_MAX_LINE_SIZE_INTERPRETER 1500
69
70 //=========================================================================
71         
72 // EED 15 oct 2012  wxVtkSceneManager::wxVtkSceneManager(wxGEditorTabPanel *parent, wxVtk3DBaseView *baseView, int idManager,Factory::Pointer bbtkfactory) 
73         
74         
75 wxVtkSceneManager::wxVtkSceneManager(wxGEditorTabPanel *parent, wxVtk3DBaseView *baseView, int idManager,Factory::Pointer bbtkfactory) 
76 {
77         _cbName                                 = "ComplexBoxName";
78         _cbPackageName                  = "PackageName";
79         _Author                                 = "Author ??";
80     _ExportFormat           = 0;
81         _Category                               = "<VOID>";
82         _Description                    = "Description ??";
83         _MessageKind                    = "-";
84         _MessageLevel                   = "-";
85
86         _bugTextActor_text              = "void";
87         _bugTextActor_status    = 0;
88
89         _parent                                 = parent;
90         _numBoxes                               = 0;
91         _idManager                              = idManager;
92         _baseView                               = baseView;
93         _bbtkfactory                    = bbtkfactory;
94         
95         _startDragging                  = false;
96         _isComplexBox                   = false;
97
98         if (_baseView != NULL) {
99                 //EED02JUIN2010
100                 printf(
101                                 "RaC-EED 21-06-2010 %p wxVtkSceneManager::wxVtkSceneManager If you comment this line, the drag and drop functionnality is not initialized.\n",
102                                 this);
103 //#ifdef __APPLE__
104                 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget((wxDropTarget*)parent);
105 //#endif
106
107                 configureBaseView();
108                 _worldState = NOTHING_HAPPENS;
109                 registerController(this);
110
111         }
112         _idConnectionInCreation = -1;
113         _contLastId                             = 0;
114     
115     selectRegionX1          = -1;
116     selectRegionY1          = -1;
117     selectRegionX2          = -1;
118     selectRegionY2          = -1;
119 }
120
121 //=========================================================================
122
123 void wxVtkSceneManager::disconnectDrop() 
124 {
125         //EED02JUIN2010         _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget(NULL);
126         //      _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget( new tmpClasswxTextDropTarget() );
127 }
128
129 //=========================================================================
130
131 wxVtkSceneManager::~wxVtkSceneManager() 
132 {
133         //FCY memory leaks
134         disconnectDrop();
135         delete _baseView;
136 }
137
138 //=========================================================================
139
140 void wxVtkSceneManager::configureBaseView() 
141 {
142         vtkInteractorStyleBaseView2D *interactorstylebaseview = vtkInteractorStyleBaseView2D::New();
143         _baseView->SetInteractorStyleBaseView(interactorstylebaseview);
144         // Important to activate the 2D interaction system
145         crea::wxVTKRenderWindowInteractor *iren =       _baseView->GetWxVTKRenderWindowInteractor();
146         interactorstylebaseview->SetInteractor(iren);
147         iren->SetInteractorStyle(interactorstylebaseview);
148         interactorstylebaseview->SetwxVtkBaseView(_baseView);
149         _baseView->GetRenderer()->GetActiveCamera()->ParallelProjectionOn();
150         _baseView->GetRenderer()->ResetCamera(-100, 100, -100, 100, -1000, 1000);
151         _baseView->GetRenderer()->GetActiveCamera()->Zoom(20);
152         _baseView->GetRenderer()->SetBackground(0.9, 0.9, 0.9);
153         _baseView->GetRenderer()->GradientBackgroundOn();
154         // Actos Port_Text
155         _textActor = vtkTextActor3D::New();
156 //      _textActor = vtkTextActor::New();
157         _textActor->SetPosition(-9999, -9999, GPOSITION_Z);
158         _textActor->SetInput("<void>");
159 //EED 2022-01-16
160 //    _textActor->GetTextProperty()->SetFontSize(60);
161         _textActor->GetTextProperty()->SetFontSize(40);
162         _textActor->GetTextProperty()->BoldOn();
163     _textActor->GetTextProperty()->SetFontFamilyToArial();
164     _textActor->GetTextProperty()->ShadowOff();
165         _textActor->GetTextProperty()->SetColor(PORTTEXT_NH_R, PORTTEXT_NH_G,PORTTEXT_NH_B);
166         _baseView->GetRenderer()->AddActor(_textActor);
167         // Actor  Fill_Port_Text
168         //------------
169         double xInic            = 0;
170         double yInic            = 0;
171         double zInic            = GPOSITION_Z;
172         vtkPolygon *aPolygon    = vtkPolygon::New();
173         _fillObjectActor        = vtkActor::New();
174         _pts                    = vtkPoints::New();
175
176 /*
177     double w = 100, h = 10, b = h / 15, t = 3;
178         _pts->SetNumberOfPoints(21);
179         _pts->InsertPoint(0, xInic + w * 0.33 - t / 2, yInic, zInic);
180         _pts->InsertPoint(1, xInic + w * 0.33, yInic - t, zInic);
181         _pts->InsertPoint(2, xInic + w * 0.33 + t / 2, yInic, zInic);
182         _pts->InsertPoint(3, xInic + w * 0.33 + t / 2, yInic, zInic);
183         _pts->InsertPoint(4, xInic + w - b * 4, yInic + b * 0, zInic);
184
185         _pts->InsertPoint(5, xInic + w - b * 4, yInic + b * 0, zInic);
186         _pts->InsertPoint(6, xInic + w - b * 2, yInic + b * 1, zInic);
187         _pts->InsertPoint(7, xInic + w - b * 1, yInic + b * 2, zInic);
188         _pts->InsertPoint(8, xInic + w - b * 0, yInic + b * 4, zInic);
189
190         _pts->InsertPoint(9, xInic + w - b * 0, yInic + h - b * 4, zInic);
191         _pts->InsertPoint(10, xInic + w - b * 1, yInic + h - b * 2, zInic);
192         _pts->InsertPoint(11, xInic + w - b * 2, yInic + h - b * 1, zInic);
193         _pts->InsertPoint(12, xInic + w - b * 4, yInic + h - b * 0, zInic);
194
195         _pts->InsertPoint(13, xInic + b * 4, yInic + h - b * 0, zInic);
196         _pts->InsertPoint(14, xInic + b * 2, yInic + h - b * 1, zInic);
197         _pts->InsertPoint(15, xInic + b * 1, yInic + h - b * 2, zInic);
198         _pts->InsertPoint(16, xInic + b * 0, yInic + h - b * 4, zInic);
199
200         _pts->InsertPoint(17, xInic + b * 0, yInic + b * 4, zInic);
201         _pts->InsertPoint(18, xInic + b * 1, yInic + b * 2, zInic);
202         _pts->InsertPoint(19, xInic + b * 2, yInic + b * 1, zInic);
203         _pts->InsertPoint(20, xInic + b * 4, yInic + b * 0, zInic);
204     aPolygon->GetPointIds()->SetNumberOfIds(21);
205     for (int i = 0; i < 21; i++) {
206     {
207         aPolygon->GetPointIds()->SetId(i, i);
208     }
209 */
210
211     double w = BOX_WIDTH, h = BOX_HEIGHT, t = PORT_HEIGHT;
212     _pts->SetNumberOfPoints(7);
213     _pts->InsertPoint(0, xInic + t/2.0  , yInic + t     , zInic );
214     _pts->InsertPoint(1, xInic + w      , yInic + t     , zInic );
215     _pts->InsertPoint(2, xInic + w      , yInic + t + h , zInic );
216     _pts->InsertPoint(3, xInic - t*1.5  , yInic + t + h , zInic );
217     _pts->InsertPoint(4, xInic - t*1.5  , yInic + t     , zInic );
218     _pts->InsertPoint(5, xInic - t/2    , yInic + t     , zInic );
219     _pts->InsertPoint(6, xInic          , yInic         , zInic );
220     aPolygon->GetPointIds()->SetNumberOfIds(8);
221         for (int i = 0; i < 8; i++)
222     {
223                 aPolygon->GetPointIds()->SetId(i, i);
224         if (i==7) aPolygon->GetPointIds()->SetId(i, 0);
225         }
226         vtkUnstructuredGrid *aPolygonGrid = vtkUnstructuredGrid::New();
227         aPolygonGrid->Allocate(1, 1);
228         aPolygonGrid->InsertNextCell(aPolygon->GetCellType(),aPolygon->GetPointIds());
229         aPolygonGrid->SetPoints(_pts);
230         _aPolygonMapper = vtkDataSetMapper::New();
231 //EED 2017-01-01 Migration VTK7
232 #if VTK_MAJOR_VERSION <= 5
233         _aPolygonMapper->SetInput(aPolygonGrid);
234 #else
235         _aPolygonMapper->SetInputData(aPolygonGrid);
236 #endif
237         _fillObjectActor->SetMapper(_aPolygonMapper);
238         _fillObjectActor->GetProperty()->SetColor(PORTFILL_NH_R, PORTFILL_NH_G,PORTFILL_NH_B);
239         _fillObjectActor->GetProperty()->SetOpacity(0);
240         _aPolygonMapper->Modified();
241         _baseView->GetRenderer()->AddActor(_fillObjectActor);
242     
243 }
244
245 //=========================================================================
246
247 std::string wxVtkSceneManager::generateANewNameForABox() {
248         std::stringstream boxname;
249         if (_numBoxes < 10) {
250                 boxname << "Box0" << _numBoxes;
251         } else {
252                 boxname << "Box" << _numBoxes;
253         }
254         _numBoxes++;
255         return boxname.str();
256 }
257
258 //=========================================================================
259
260 std::string wxVtkSceneManager::findANewNameForABox()
261 {
262         std::string boxname = generateANewNameForABox();
263         while (boxExist(boxname) == true)
264     {
265                 boxname = generateANewNameForABox();
266         } // while
267         return boxname;
268 }
269
270 //=========================================================================
271 void wxVtkSceneManager::configGBlackBox(int idBox, double xIn, double yIn,
272                 double zIn, std::string name, bool boxExecutable, double xEn,
273                 double yEn, double zEn)
274 {
275         GObjectController *cont = _controllers[idBox];
276         GBlackBoxModel *bbmod = (GBlackBoxModel*) cont->getModel();
277         bbmod->setBBTKName(name);
278         bbmod->setInicPoint(xIn, yIn, zIn);
279         bbmod->setFinalPoint(xEn, yEn, zEn);
280         bbmod->setExecutable(boxExecutable);
281         bbmod->notifyObservers(_idManager);
282 }
283
284 //=========================================================================
285
286 int wxVtkSceneManager::createGBlackBox(int x, int y, std::string packageName,std::string boxType) 
287 {
288         _worldState                                             = NOTHING_HAPPENS;
289         int windowHeight                                = _baseView->GetRenWin()->GetSize()[1];
290         int type                                                = GBLACKBOX;
291         //Create the MVC Objects
292         GBlackBoxModel *model                   =       (GBlackBoxModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(type);
293         vtkGObjectView *view                    =       GObjectsMVCFactory::getInstance()->createGObjectView(type);
294         GObjectController *controller   =       GObjectsMVCFactory::getInstance()->createGObjectController(type);
295
296 //EED 15 oct 2012       BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxType);
297         
298
299         Package::Pointer k;
300         std::map< std::string, BlackBoxDescriptor::Pointer> mapDesc;
301         try{
302                 k               = _bbtkfactory->GetPackage(packageName);
303                 mapDesc = k->GetDescriptorMap();
304         }catch(Exception e){
305                 printf("EED. ERROR!: Exception in wxVtkSceneManager::createGBlackBox for package %s, NOT EXIST\n", packageName.c_str());
306         }
307
308         BlackBoxDescriptor::Pointer descriptor;
309         try{
310                 descriptor = mapDesc[boxType];
311         }catch(Exception e){
312                 printf("EED. ERROR!: Exception in wxVtkSceneManager::createGBlackBox for box %s of package %s, NOT EXIST\n", boxType.c_str(),packageName.c_str());
313         }
314         
315         if (descriptor == NULL)
316         {
317                         printf("SCP: ERROR in wxVtkSceneManager::createGBlackBox, box %s probably does not exist.\n",  boxType.c_str());
318         }
319         
320         //Prepares the initial model
321         //The coordinates obtained are the following. Top-Left:x=0,y=0 Bottom-Right:x=width,y=height
322
323         double xx = x;
324         double yy = windowHeight - y;
325
326         //z value is not important yet, because it is only used a parallel projection
327         double zz = GPOSITION_Z;
328         _baseView->TransCoordScreenToWorld(xx, yy, zz);
329         model->setInicPoint(xx, yy, zz);
330
331         std::stringstream stream;
332
333         std::string newBoxName;
334         newBoxName = findANewNameForABox();
335
336         stream << newBoxName;
337
338         std::string arraystring = stream.str();
339
340         model->setBBTKName(arraystring);
341         model->setBBTKType(boxType);
342         model->setBBTKPackage(packageName);
343
344         model->addObserver(view);
345         model->addObserver(this);
346
347
348 //EED2017 change order
349         //Associates the view with the correspondent renderer and the  model.
350         //(NOTE: Refresh is only made by the view)
351         view->setModel(model);
352         view->setBaseView(_baseView);
353
354         //Associates the controller with the correspondent model and view
355         controller->setModelAndView(model, view);
356
357
358         //Iterate and create the input ports
359         std::map<std::string, BlackBoxInputDescriptor*> descriptorInMap =
360                         descriptor->GetInputDescriptorMap();
361         std::map<std::string, BlackBoxInputDescriptor*>::iterator itInput;
362         int i = 0;
363         for (itInput = descriptorInMap.begin(); itInput != descriptorInMap.end(); ++itInput) 
364         {
365                 BlackBoxInputDescriptor *desc = itInput->second;
366 //EED2017-04-07
367 //              createGInputPort(GINPUTPORT, i, model, desc);
368                 createGInputPort(GINPUTPORT, i, controller, desc);
369                 i++;
370         }
371
372         //Iterate and create the output ports
373         std::map<std::string, BlackBoxOutputDescriptor*> descriptorOutMap =
374                         descriptor->GetOutputDescriptorMap();
375         std::map<std::string, BlackBoxOutputDescriptor*>::iterator itOutput;
376         i = 0;
377         for (itOutput = descriptorOutMap.begin(); itOutput!= descriptorOutMap.end(); ++itOutput) 
378         {
379                 BlackBoxOutputDescriptor *desc = itOutput->second;
380 //EED2017-04-07
381 //              createGOutputPort(GOUTPUTPORT, i, model, desc);
382                 createGOutputPort(GOUTPUTPORT, i, controller, desc);
383                 i++;
384         }
385
386 //EED2017 change order
387         view->initVtkObjects();
388
389         //Resgiter change to the observers of the actual model
390         model->notifyObservers(_idManager);
391         int newId = addObjectController(controller);
392
393         return newId;
394
395 }
396
397 //=========================================================================
398
399 int wxVtkSceneManager::createGComplexBoxInputPort(std::string inputName) {
400         //EED           int windowWidth=_baseView->GetRenWin()->GetSize()[0];
401         int windowHeight = _baseView->GetRenWin()->GetSize()[1];
402
403         int type = GCOMPLEXINPUTPORT;
404
405         //Create the MVC Objects
406
407         GComplexBoxPortModel    *model          = (GComplexBoxPortModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(type);
408         vtkGObjectView                  *view           = GObjectsMVCFactory::getInstance()->createGObjectView(type);
409         GObjectController               *controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
410
411         //Prepares the initial model
412
413         double xx = 5;
414         double yy = windowHeight - 5;
415
416         //z value is not important yet, because it is only used a parallel projection
417         double zz = GPOSITION_Z;
418
419         _baseView->TransCoordScreenToWorld(xx, yy, zz);
420         model->setInicPoint(xx, yy, zz);
421
422         model->setBBTKName(inputName);
423         model->setBBTKType("ComplexInputPort");
424         model->setComplexPortType(type);
425
426         model->addObserver(view);
427         model->addObserver(this);
428
429         //create the output port
430         GPortController* portController = createGPort(GOUTPUTPORT, inputName,
431                         "ComplexOutputPortType","ComplexOutputPortDescriopton", 0, model);
432         model->addOutputPort((GPortModel*) portController->getModel());
433
434         //Associates the view with the correspondent renderer and the  model.
435         //(NOTE: Refresh is only made by the view)
436         view->setModel(model);
437         view->setBaseView(_baseView);
438         view->initVtkObjects();
439
440         //Associates the controller with the correspondent model and view
441         controller->setModelAndView(model, view);
442
443         //Resgiter change to the observers of the actual model
444         model->notifyObservers(_idManager);
445
446         int newId = addObjectController(controller);
447         return newId;
448 }
449
450 //=========================================================================
451
452 int wxVtkSceneManager::createGComplexBoxOutputPort(std::string outputName) {
453         //EED           int windowWidth=_baseView->GetRenWin()->GetSize()[0];
454         int windowHeight = _baseView->GetRenWin()->GetSize()[1];
455
456         int type = GCOMPLEXOUTPUTPORT;
457
458         //Create the MVC Objects
459
460         GComplexBoxPortModel    *model          = (GComplexBoxPortModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(type);
461         vtkGObjectView                  *view           = GObjectsMVCFactory::getInstance()->createGObjectView(type);
462         GObjectController               *controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
463
464         //Prepares the initial model
465
466         double xx = 5;
467         double yy = windowHeight - 5;
468
469         //z value is not important yet, because it is only used a parallel projection
470         double zz = GPOSITION_Z;
471
472         _baseView->TransCoordScreenToWorld(xx, yy, zz);
473         model->setInicPoint(xx, yy, zz);
474
475         model->setBBTKName(outputName);
476         model->setBBTKType("ComplexOutputPort");
477         model->setComplexPortType(type);
478
479         model->addObserver(view);
480         model->addObserver(this);
481
482         //create the output port
483         GPortController* portController = createGPort(GINPUTPORT, outputName,
484                         "ComplexInputPort","ComplexInputPortDescription", 0, model);
485         model->addInputPort((GPortModel*) portController->getModel());
486
487         //Associates the view with the correspondent renderer and the  model.
488         //(NOTE: Refresh is only made by the view)
489         view->setModel(model);
490         view->setBaseView(_baseView);
491         view->initVtkObjects();
492
493         //Associates the controller with the correspondent model and view
494         controller->setModelAndView(model, view);
495
496         //Resgiter change to the observers of the actual model
497         model->notifyObservers(_idManager);
498
499         int newId = addObjectController(controller);
500         return newId;
501 }
502
503 //=========================================================================
504
505 //EED2017-04-08
506 //int wxVtkSceneManager::createGInputPort(int portType, int posinBox, GBoxModel *blackBox, BlackBoxInputDescriptor *desc) 
507 int wxVtkSceneManager::createGInputPort(int portType, int posinBox, GObjectController *gBoxControler, BlackBoxInputDescriptor *desc) 
508 {
509         GBoxModel *blackBox=(GBoxModel*)gBoxControler->getModel();
510         GPortController* portController = createGPort(portType, desc->GetName(),
511                         desc->GetTypeName(), desc->GetDescription(), posinBox, blackBox);
512         blackBox->addInputPort( (GPortModel*)portController->getModel() );
513
514         vtkGBoxView *vtkgboxView=(vtkGBoxView*)gBoxControler->getView();
515         vtkgboxView->addInputPort( (vtkGPortView*)portController->getView() );
516
517         return portController->getId();
518 }
519
520 //=========================================================================
521
522 //EED2017-04-08
523 //int wxVtkSceneManager::createGOutputPort(int portType, int posinBox,GBoxModel *blackBox, BlackBoxOutputDescriptor *desc) 
524 int wxVtkSceneManager::createGOutputPort(int portType, int posinBox,GObjectController *gBoxControler, BlackBoxOutputDescriptor *desc) 
525         {
526         GBoxModel *blackBox=(GBoxModel*)gBoxControler->getModel();
527         GPortController* portController = createGPort(portType, desc->GetName(),
528                         desc->GetTypeName(),desc->GetDescription(), posinBox, blackBox);
529         blackBox->addOutputPort((GPortModel*) portController->getModel());
530
531         vtkGBoxView *vtkgboxView=(vtkGBoxView*)gBoxControler->getView();
532         vtkgboxView->addOutputPort( (vtkGPortView*)portController->getView() );
533
534         return portController->getId();
535 }
536
537 //=========================================================================
538
539 GPortController* wxVtkSceneManager::createGPort(int portType,std::string bbtkName, std::string bbtkType, std::string bbtkDescription, int posInBox,GBoxModel *blackBox) 
540 {
541         int type = GPORT;
542
543         //Create the MVC Objects
544         GPortModel                      *model          =       (GPortModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(type);
545         vtkGObjectView          *view           =       GObjectsMVCFactory::getInstance()->createGObjectView(type);
546         GObjectController       *controller =   GObjectsMVCFactory::getInstance()->createGObjectController(type);
547         model->registerInBox(blackBox, portType, posInBox);
548         model->setBBTKType(bbtkType);
549         model->setBBTKName(bbtkName);
550         model->setBBTKDescription(bbtkDescription);
551         model->addObserver(view);
552         model->addObserver(this);
553         //Associates the view with the correspondent renderer and the  model.
554         //(NOTE: Refresh is only made by the view)
555         view->setModel(model);
556         view->setBaseView(_baseView);
557 //EED017        view->initVtkObjects();
558         view->createVtkObjects();
559 //  view->addVtkActors();
560
561         //Associates the controller with the correspondent model and view
562         controller->setModelAndView(model, view);
563         model->notifyObservers(_idManager);
564         addObjectController(controller);
565         return (GPortController*) controller;
566 }
567
568 //=========================================================================
569
570 int wxVtkSceneManager::createGConnector(GPortModel* startPort) 
571 {
572         int type = GCONNECTOR;
573
574         manualConnectorContourController        *manContourControl              = new manualConnectorContourController();
575         manualConnectorContourView                      *manContourView                 = new manualConnectorContourView();
576         manualContourModel                                      *manContourModel                = new manualContourModel();
577         GConnectorController                            *connectorcontroller    = new GConnectorController();
578         GConnectorModel                                         *connectorModel                 = new GConnectorModel();
579         vtkGConnectorView                                       *connectorView                  = new vtkGConnectorView();
580         connectorModel->setGObjectType(type);
581
582         manContourModel->SetCloseContour(false);
583         connectorModel->setStartPort(startPort);
584
585         manContourView->SetModel(manContourModel);
586         manContourView->SetWxVtkBaseView(_baseView);
587         manContourView->SetRange(0.5);
588         manContourView->SetZ(GPOSITION_Z);
589
590         manContourView->SetColorNormalContour(0, 0, 1);
591         manContourView->SetColorEditContour(0.5, 0.5, 0.5);
592         manContourView->SetColorSelectContour(1, 0.8, 0);
593         
594         
595
596         /**
597          * JGRR AND CM
598          * Width increased from 2 to 3, it simplifies line handling and spline control :P
599          * @param WidthLine  
600          */
601  //EED2017
602 //        manContourView->SetWidthLine( 3 ) ;
603 //EED 2022-01-16
604           manContourView->SetWidthLine( 1 ) ;
605
606     manContourView->SetShowText(false);
607
608         manContourControl->SetModelView(manContourModel, manContourView);
609
610         manContourControl->CreateNewManualContour();
611
612
613         double x, y, z;
614         connectorModel->getInicPoint(x, y, z);
615         
616         
617         manContourControl->SetState(1);
618         manContourModel->SetCloseContour(false);
619
620         manContourModel->AddPoint(x, y, z);
621         manContourView->AddPoint();
622
623         manContourModel->AddPoint(x, y, z);
624         manContourView->AddPoint();
625
626         int bak = manContourControl->GetNumberOfPointsManualContour() - 1;
627         manContourControl->_bakIdPoint = bak;
628         
629         manContourControl->SetMoving(false);
630
631         connectorcontroller->setModelAndView(connectorModel, connectorView);
632
633         int newId = addObjectController(connectorcontroller);
634
635         connectorcontroller->setManualContourController(manContourControl);
636         connectorModel->setManualContourModel(manContourModel);
637         connectorView->setManualContourView(manContourView);
638         connectorView->setModel(connectorModel);
639         connectorView->setBaseView(_baseView);
640
641         connectorModel->addObserver(connectorView);
642         connectorModel->addObserver(this);
643
644 //      manContourView->Refresh();
645         
646         return newId;
647 }
648
649 //=========================================================================
650
651 void wxVtkSceneManager::registerController(InteractorStyleMaracas *param) 
652 {
653         vtkInteractorStyleBaseView * baseViewControlManager = (vtkInteractorStyleBaseView*) _baseView->GetInteractorStyleBaseView();
654         baseViewControlManager->AddInteractorStyleMaracas(param);
655 }
656
657 //=========================================================================
658
659 void wxVtkSceneManager::unregisterController(InteractorStyleMaracas *param) 
660 {
661         vtkInteractorStyleBaseView *baseViewControlManager = (vtkInteractorStyleBaseView*) _baseView->GetInteractorStyleBaseView();
662         baseViewControlManager->RemoveInteractorStyleMaracas(param);
663 }
664
665 //=========================================================================
666
667 vtkRenderer* wxVtkSceneManager::getRenderer() 
668 {
669         return _baseView->GetRenderer();
670 }
671
672 //=========================================================================
673
674 vtkRenderWindow* wxVtkSceneManager::getRenderWindow() 
675 {
676         return _baseView->GetRenWin();
677 }
678 //=========================================================================
679
680
681 //=========================================================================
682 int wxVtkSceneManager::GetIndexInSelected(int idControler) 
683 {
684         int index = -1;
685         for (int i = 0; i < (int) _selectedObjects.size(); i++) 
686         {
687                 if (_selectedObjects[i] == idControler) 
688                 {
689                         index = i;
690                         break;
691                 }
692         }
693         return index;
694 }
695 //=========================================================================
696
697 void wxVtkSceneManager::update(int idController, int command) {
698
699         if (command != NO_COMMAND) 
700         {
701                 if (command == ADD_TO_SELECTED) 
702                 {
703                         if (GetIndexInSelected(idController) == -1) 
704                         {
705                                 _selectedObjects.push_back(idController);
706                         }
707                 } else if (command == REMOVE_FROM_SELECTED) {
708                         int index = GetIndexInSelected(idController);
709                         if (index >= 0) 
710                         {
711                                 _selectedObjects.erase(_selectedObjects.begin() + index);
712                         }
713                 } else if (command == INIT_CREATION_CONTOUR) {
714                 // JGRR & CM WH
715                 typedef std::map<int , GObjectController*>::iterator TIterator ;
716                 TIterator iter ;
717                 TIterator iter_end ;
718                 // Find current item in the controller
719                 iter = _controllers.find( idController ) ;
720                 iter_end = _controllers.end( ) ;
721                 // If item exist 
722                 if ( iter != iter_end ) {
723                     GObjectController* gobjc = iter->second ;
724
725                     std::string bbtkType = gobjc->getModel( )->getBBTKType( ) ;
726                     // And if the item is a port
727                     if ( gobjc->getModel( )->getGObjectType( ) == GPORT ) {
728                         TIterator c_it = _controllers.begin( ) ;
729                         // Go through all componets 
730                         for ( c_it ; c_it != iter_end ; c_it++ ) {
731                             GObjectController* obc = c_it->second ;
732                             int obc_type = obc->getModel( )->getGObjectType( ) ;
733                             std::string obc_bbtkType = obc->getModel( )->getBBTKType( ) ;
734                             // if the component is a port and the type is the same of that selected
735                             if ( ( obc_type == GPORT ) && ( obc_bbtkType == bbtkType ) ) {
736                                 // Highliht element 
737                                 obc->getView( )->setState( POSSIBLE_CONNECTION ) ;                             
738                                 //obc->getView( )->setState( HIGHLIGHTED ) ;
739                             } // if obc_type
740                         } // for c_it
741                     } // if
742                 } // if iter
743
744                 // EO JGRR & CM WH  
745                      
746                         _worldState                                     = INIT_CREATION_CONTOUR;
747                         GObjectController* cont         = _controllers[idController];
748                         GPortModel* startOutputPort = (GPortModel*) cont->getModel();
749
750                         // The last one is the controller of the connector
751                         std::map<int, GObjectController*>::iterator it2;
752
753                         for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2) 
754                         {
755                                 GObjectController *cont = it2->second;
756                                 if (cont->getGObjectType() == GPORT) 
757                                 {
758                                         GPortModel* port = (GPortModel*) cont->getModel();
759                                         if (port->getPortType() == GINPUTPORT) 
760                                         {
761                                                 cont->SetActive(true);
762                                         } else {
763                                                 cont->getView()->setState(NOTHING_HAPPENS);
764                                                 cont->getModel()->notifyObservers(_idManager);
765                                                 cont->SetActive(false);
766                                         }
767                                 } else {
768                                         cont->getView()->setState(NOTHING_HAPPENS);
769                                         cont->getModel()->notifyObservers(_idManager);
770                                         cont->SetActive(false);
771                                 }
772                         }
773                         _selectedObjects.clear();
774                         _idConnectionInCreation = createGConnector(startOutputPort);
775                 } else if (command == FIN_CREATION_CONTOUR && _worldState == INIT_CREATION_CONTOUR) {
776                         _worldState = NOTHING_HAPPENS;
777                         //int id = _controllers.size()-1;
778                         GObjectController       *cont                   = _controllers[_idConnectionInCreation];
779                         GConnectorModel         *modelContour   = (GConnectorModel*) cont->getModel();
780                         GObjectController       *finPort                = _controllers[idController];
781
782                         if (finPort->getGObjectType() == GPORT) 
783                         {
784                                 GPortModel* modelPort = (GPortModel*) finPort->getModel();
785                                 modelContour->setEndPort(modelPort);
786
787                                 // JGRR CM                     
788                                 typedef std::map<int, GObjectController*>::iterator TIterator;
789                                 TIterator c_it = _controllers.begin();
790                                 TIterator iter_end = _controllers.end();
791                                 // Go through all componets 
792                                 for (c_it; c_it != iter_end; c_it++) {
793                                     GObjectController* obc = c_it->second;
794                                     int obc_type = obc->getModel()->getGObjectType();
795                                     int obc_state = obc->getView()->getState();
796                                     // if the component is a port and the type is the same of that selected
797                                     if ((obc_type == GPORT) && (obc_state == POSSIBLE_CONNECTION)) {
798                                         // Return element to neutral state if not selected
799                                         obc->getView()->setState(NOTHING_HAPPENS);
800                                     }
801                                     if ((obc_type == GPORT) && (obc_state == SELECTED_POSSIBLE_CONNECTION)) {
802                                         // Change element to connected state
803                                         obc->getView()->setState(HIGHLIGHTED);
804                                     }
805
806                                 }
807                                 // EO JGRR CM                                
808                     
809                                                                 _parent->saveTempandUpdate("create connection");
810                         }
811
812                         manualConnectorContourController        *manCont        = ((GConnectorController*) cont)->getManualContourController();
813                         manualConnectorContourView                      *connView       = (manualConnectorContourView*) manCont->GetManualViewBaseContour();
814                                      
815                         std::map<int, GObjectController*>::iterator it2;
816
817                         for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2) 
818                         {
819                                 GObjectController *cont = it2->second;
820                                 if (cont->getView() != NULL) {
821                                         cont->getView()->setState(NOTHING_HAPPENS);
822                                         cont->getModel()->notifyObservers(_idManager);
823                                 }
824                                 cont->SetActive(true);
825                         }
826                         connView->Refresh();          
827                 }
828
829         }
830         
831 }
832
833 //=========================================================================
834
835 bool wxVtkSceneManager::OnMouseMove() 
836 {
837         int X, Y;
838         bool okStatusMessage    = false;
839         bool okPortMessage          = false;
840         crea::wxVTKRenderWindowInteractor *wxVTKiren;
841         wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
842         wxVTKiren->GetEventPosition(X, Y);
843
844         if (_worldState == DRAG_OBJECTS)
845     {
846                 for (int i = 0; i < (int) _selectedObjects.size(); i++)
847         {
848                         int id = _selectedObjects[i];
849                         GObjectController* cont = _controllers[id];
850                         if (_startDragging)
851             {
852                                 cont->getView()->setStartDragging(true);
853                         }
854                         cont->getView()->moveObject(X, Y);
855                         cont->getView()->setState(DRAG);
856                         cont->getModel()->notifyObservers(_idManager);
857                 }
858
859                 std::map<int, GObjectController*>::iterator it;
860
861                 for (it = _controllers.begin(); it != _controllers.end(); ++it)
862         {
863                         GObjectController *desc = it->second;
864                         if (desc->getGObjectType() == GCONNECTOR)
865             {
866                                 vtkGConnectorView* vconn = (vtkGConnectorView*) desc->getView();
867                                 vconn->updateStartEndPoints();
868                         } // if
869                 } // for
870
871                 _startDragging = false;
872
873         } else if (_worldState == NOTHING_HAPPENS || _worldState == INIT_CREATION_CONTOUR) {
874                 std::map<int, GObjectController*>::iterator it;
875                 double px, py, pz;
876                 for (it = _controllers.begin(); it != _controllers.end(); ++it)
877         {
878                         GObjectController *desc = it->second;
879                         int type        = desc->getGObjectType();
880                         int state       = desc->getView()->getState();
881                         desc->getModel()->getCenter(px, py, pz);
882
883                         // JGRR & CM
884                         if ((state == HIGHLIGHTED) || (state == SELECTED_POSSIBLE_CONNECTION )) 
885                         {
886                         // EO JGRR & CM    
887                                 okStatusMessage         = true;
888                                 updateStatusBar(desc->getStatusText());
889                                 if (type == GBLACKBOX) 
890                                 {
891                                         GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
892                                         _parent->displayBlackBoxInfo(mod->getBBTKPackage(),mod->getBBTKType());
893                                 } // if GBLACKBOX
894                                 if (type == GPORT) 
895                                 {
896                                         // PortText
897                                         if ( ( _bugTextActor_text==desc->getStatusText() ) || (_bugTextActor_status==0) )
898                                         {
899                         _bugTextActor_status    = 1;
900                                                 okPortMessage               = true;
901 //EED 2022-01-16
902 //                        py                      = py + 5;
903 //                                              _textActor->SetScale(0.1);
904 //                        py                         = py + 5*0.5;
905                         _textActor->SetScale(0.05,0.05,1);
906
907                                                 std::string tmp         = desc->getStatusText()+"\n";
908                                                 _textActor->SetInput( tmp.c_str() );
909 //                      _textActor->SetPosition(px - 25, py + 1, pz + 2);
910 //                      _textActor->SetPosition(px  , py-PORT_HEIGHT/4 , pz + 2);
911                                                 _textActor->SetPosition(px  , py-PORT_HEIGHT , pz + 2);
912                                                 _textActor->Modified();
913                                                 // FillPortText
914 //EED 2022-01-16
915 //                        px                         = px - 33;
916                         _fillObjectActor->SetScale(1);
917 //                        px                         = px - 33*0.7;
918 //                                              _fillObjectActor->SetScale(0.7,0.5,1);
919                                                 _fillObjectActor->GetProperty()->SetOpacity(0.75);
920                                                 _fillObjectActor->SetPosition( px, py + PORT_HEIGHT/2.0 , 1);
921                                                 _aPolygonMapper->Modified();
922                                         } else {
923                                                 _bugTextActor_status= 2;
924                                         } //  _bugTextActor_tex
925                                         _bugTextActor_text                  = desc->getStatusText();
926                                 } // if GPORT
927             } // if  state
928                 } // for controllers it
929     } else if (_worldState == SELECTING_BOXES ) {
930
931
932         int sX1,sX2,sY1,sY2;
933         if (X<selectRegionX1)
934         {
935             sX1=X; sX2=selectRegionX1;
936         } else {
937             sX1=selectRegionX1; sX2=X;
938         }
939
940         if (Y<selectRegionY1)
941         {
942             sY1=Y; sY2=selectRegionY1;
943         } else {
944             sY1=selectRegionY1; sY2=Y;
945         }
946
947         UnSelectBlackBoxes();
948         
949         std::map<int, GObjectController*>::iterator it;
950         GObjectController                           *desc;
951         int                                         type;
952         int                                         state;
953         int                                         id;
954         for (it = _controllers.begin(); it != _controllers.end(); ++it)
955         {
956             desc    = it->second;
957             type    = desc->getGObjectType();
958             state   = desc->getView()->getState();
959             
960             if ( (type==GBLACKBOX) || (type==GCOMPLEXINPUTPORT) || (type==GCOMPLEXOUTPUTPORT) )
961             {
962                 if ( desc->getView()->isBoxInsideRectangle( sX1 , sY1,sX2 , sY2 ) )
963                 {
964                     desc->getView()->setState(SELECTED);
965                     id = desc->getModel()->getObjectId();
966                     desc->getModel()->notifyObservers( id , ADD_TO_SELECTED );
967                 }
968             } // if type == 1
969         } // for
970         
971         
972     } //  if _worldState
973     
974         if (okStatusMessage == false)
975         {
976                 updateStatusBar("");
977         }
978
979         if ((okPortMessage == false) || (_bugTextActor_status== 2 ) )
980         {
981                 _bugTextActor_status    = 0; 
982                 _textActor->SetScale(0.0001);
983                 _textActor->SetInput("a\n");
984                 _textActor->Modified();
985                 _fillObjectActor->SetScale(0.0001);
986         }
987         return true;
988 }
989
990 //=========================================================================
991
992 bool wxVtkSceneManager::OnLeftButtonDown() 
993 {
994         if (_worldState == INIT_CREATION_CONTOUR) 
995         {
996                 bool isOverPort = false;
997                 std::map<int, GObjectController*>::iterator it;
998                 for (it = _controllers.begin(); it != _controllers.end() && isOverPort== false; ++it) 
999                 {
1000                         GObjectController *desc = it->second;
1001                         if (desc->getGObjectType() == GPORT) 
1002                         {
1003                                 GPortModel *portmod = (GPortModel*) desc->getModel();
1004                                 vtkGObjectView *portView = desc->getView();
1005                                 if (portmod->getPortType() == GINPUTPORT && portView->getState() == HIGHLIGHTED) 
1006                                 {
1007                                         isOverPort = true;
1008                                 } // if
1009                                 // JGRR & CM                    
1010                                 if ( portmod->getPortType( ) == GINPUTPORT &&  portView->getState( ) == SELECTED_POSSIBLE_CONNECTION   ) {
1011                                         isOverPort = true ;
1012                                         portView->setState( HIGHLIGHTED);
1013                                 }                    
1014                                 // EO JGRR & CM 
1015
1016                         } // if
1017                 } // for
1018                 if (isOverPort == false) 
1019                 {
1020                         CancelConnection();
1021                         UnSelectBlackBoxes();
1022                 } // isOverPort
1023         } else { //_worldState
1024                 _startDragging          = true;
1025                 int shiftkey            = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey();
1026                 int ctrlkey                     = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
1027                 ctrlkey                         = ctrlkey + shiftkey;
1028                 GObjectController *cont = GetGBoxControlerPointedByMouse();
1029                 if (cont != NULL)
1030         {
1031             _worldState        = DRAG_OBJECTS;
1032                         int state = cont->getView()->getState();
1033                         if ((ctrlkey == 0) && (state == HIGHLIGHTED))
1034             {
1035                                 UnSelectBlackBoxes();
1036                         } // if ctrlkey state
1037                 } else {
1038                         UnSelectBlackBoxes();  // EED 12/07/2012
1039             _worldState        = SELECTING_BOXES;
1040                 } // if cont
1041         
1042         if (_worldState==SELECTING_BOXES)
1043         {
1044             crea::wxVTKRenderWindowInteractor *wxVTKiren;
1045             wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
1046             wxVTKiren->GetEventPosition(selectRegionX1, selectRegionY1);
1047         } // if _worldState SELECTING_BOXES
1048         
1049         if (_worldState==DRAG_OBJECTS)
1050         {
1051             for (int i = 0; i < (int) _selectedObjects.size(); i++)
1052             {
1053                 int id = _selectedObjects[i];
1054                 GObjectController *cont = _controllers[id];
1055                 cont->getView()->setState(DRAG);
1056                 cont->getModel()->notifyObservers(_idManager);
1057             } // for
1058         } // if  _worldState DRAG_OBJECTS
1059
1060         } // if _selectedObjects.size
1061         return true;
1062 }
1063
1064 //=========================================================================
1065
1066 bool wxVtkSceneManager::OnLeftButtonUp() 
1067 {
1068         if ( (_worldState == DRAG_OBJECTS) || (_worldState == SELECTING_BOXES) )
1069     {
1070                 _worldState = NOTHING_HAPPENS;
1071                 for (int i = 0; i < (int) _selectedObjects.size(); i++)
1072         {
1073                         int id = _selectedObjects[i];
1074                         GObjectController* cont = _controllers[id];
1075                         cont->getView()->setState(SELECTED);
1076                         cont->getModel()->notifyObservers(_idManager);
1077                 }
1078         }
1079         return true;
1080 }
1081
1082 //=========================================================================
1083 void wxVtkSceneManager::CancelConnection() 
1084 {
1085         if (_worldState == INIT_CREATION_CONTOUR) 
1086         {
1087                 _worldState = NOTHING_HAPPENS;
1088                 //int lastId = _controllers.size()-1;
1089
1090                 GConnectorController *connector =
1091                                 (GConnectorController*) _controllers[_idConnectionInCreation];
1092                 connector->removeFromScene();
1093                 unregisterController(connector);
1094                 _controllers.erase(_idConnectionInCreation);
1095
1096                 std::map<int, GObjectController*>::iterator it;
1097                 for (it = _controllers.begin(); it != _controllers.end(); ++it) 
1098                 {
1099                         GObjectController *desc = it->second;
1100                         desc->SetActive(true);
1101                         desc->getView()->setState(NOTHING_HAPPENS);
1102                         desc->getModel()->notifyObservers(_idManager);
1103                 } // for
1104         }// if
1105 }
1106
1107 //=========================================================================
1108 bool wxVtkSceneManager::OnRightButtonUp() 
1109 {
1110         if (_worldState == INIT_CREATION_CONTOUR) 
1111         {
1112                 CancelConnection();
1113         }
1114         UnSelectBlackBoxes();
1115         return true;
1116 }
1117
1118  ///JLGR 21-05-2012
1119 //=========================================================================
1120 bool wxVtkSceneManager::OnMiddleButtonDown()
1121 {
1122         this->_vtkInteractorStyleBaseView->StartPan();
1123         return true;
1124 }
1125
1126 //=========================================================================
1127 bool wxVtkSceneManager::OnMiddleButtonUp()
1128 {
1129         this->_vtkInteractorStyleBaseView->EndPan();
1130         return true;
1131 }
1132
1133 //=========================================================================
1134 GObjectController *wxVtkSceneManager::GetGBoxControlerPointedByMouse()
1135 {
1136         GObjectController *result = NULL;
1137         int X, Y;
1138         crea::wxVTKRenderWindowInteractor *wxVTKiren;
1139         wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
1140         wxVTKiren->GetEventPosition(X, Y);
1141         std::map<int, GObjectController*>::iterator it;
1142         for (it = _controllers.begin(); it != _controllers.end(); ++it)
1143     {
1144                 GObjectController *cont = it->second;
1145                 int type = cont->getGObjectType();
1146                 if (cont->getView()->isPointInside(X, Y) == true)
1147         {
1148                         if ( (type == GBLACKBOX) ||  (type == GCOMPLEXINPUTPORT) || (type == GCOMPLEXOUTPUTPORT))
1149             {
1150                                 result = cont;
1151                         } // if type
1152                 } // if isPointInside
1153         } // for it
1154         return result;
1155 }
1156
1157 //=========================================================================
1158 void wxVtkSceneManager::UnSelectBlackBoxes()
1159 {
1160         for (int i = 0; i < (int) _selectedObjects.size(); i++)
1161     {
1162                 int id = _selectedObjects[i];
1163                 GObjectController* control = _controllers[id];
1164                 control->getView()->setState(NOTHING_HAPPENS);
1165                 control->getModel()->notifyObservers(_idManager);
1166         }// for _selectedObjects
1167         _selectedObjects.clear();
1168 }
1169
1170 //=========================================================================
1171 bool wxVtkSceneManager::OnLeftDClick()
1172 {
1173         GObjectController *cont = GetGBoxControlerPointedByMouse();
1174         if (cont != NULL)
1175     {
1176         int type    = cont->getGObjectType();
1177         if (type==GBLACKBOX)
1178         {
1179             UnSelectBlackBoxes();
1180             _parent->editBlackBox((GBlackBoxModel*) cont->getModel());
1181         } // if type
1182         } // if cont
1183         return true;
1184 }
1185
1186 //=========================================================================
1187 bool wxVtkSceneManager::OnChar() 
1188 {
1189         bool ok=false;
1190         bool oktmp;
1191         char keyCode    = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
1192         int  ctrlkey            = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
1193         // KeyCode 127 : Delete Key
1194         // KeyCode 8 : Backspace Key
1195         if (keyCode == 8 || keyCode == 127 || keyCode == 27) 
1196         {
1197                 if (_worldState == INIT_CREATION_CONTOUR) 
1198                 {
1199                         CancelConnection();
1200             UnSelectBlackBoxes();
1201                 } // if _worldState
1202         }
1203         if (keyCode == 8 || keyCode == 127) 
1204         {
1205                         for (int i = 0; i < (int) _selectedObjects.size(); i++) 
1206                         {
1207                                 int id = _selectedObjects[i];
1208                                 std::map<int, GObjectController*>::iterator it;
1209                                 it = _controllers.find(id);
1210                                 if (it != _controllers.end()) 
1211                                 {
1212                                         oktmp   =       deleteObject(id);
1213                                         ok              =       ok||oktmp;
1214                                 } // if
1215                         }// for selected objects                
1216                         if (ok) _selectedObjects.clear();
1217                         _parent->saveTempandUpdate("delete object");
1218         }// if keyCode
1219         // Duplicate
1220         ctrlkey+=keyCode;
1221         if(ctrlkey==5){                
1222                 if(_selectedObjects.size()){
1223                         std::cout<<"objects to copy :";
1224                         for(int i=0;i<_selectedObjects.size();i++)
1225                         {
1226                                 std::cout<<_selectedObjects.at(i)<<" ";
1227                         }
1228                         DuplicateObjects(getSelectedObjects());   
1229                 }else{
1230                         std::cout<<"No objects to copy\n";
1231                 } // _selectedObjects.size
1232         } // ctrlkey 5
1233         return true;
1234 }
1235
1236 //=========================================================================
1237 void wxVtkSceneManager::AddControlerToBeRemove( std::vector<int> *controllersToRemove, int id)
1238 {
1239         int i;
1240         bool ok = true;
1241         for (i = 0; i < (int) controllersToRemove->size(); i++)
1242     {
1243                 if (id == (*controllersToRemove)[i])
1244         {
1245                         ok = false;
1246                 } // if  id
1247         } //  for i
1248         if (ok == true)
1249     {
1250                 controllersToRemove->push_back(id);
1251         } //if ok
1252 }
1253
1254 //=========================================================================
1255
1256 bool wxVtkSceneManager::deleteObject(int id) 
1257 {
1258         bool result=true;
1259         GObjectController *control = _controllers[id];
1260         std::vector<int> controllersToRemove;
1261         if (control->getGObjectType() == GBLACKBOX || control->getGObjectType()
1262                         == GCOMPLEXINPUTPORT || control->getGObjectType()
1263                         == GCOMPLEXOUTPUTPORT) {
1264                 GBoxModel *bbmod = (GBoxModel*) control->getModel();
1265                 std::vector<GPortModel*> inputs = bbmod->getInputPorts();
1266
1267                 bool boxConnected = false;
1268
1269                 // Add box input controllers to be removed
1270                 for (int i = 0; i < (int) inputs.size(); i++) {
1271                         AddControlerToBeRemove(&controllersToRemove, inputs[i]->getObjectId());
1272                         if (inputs[i]->isConnected()) {
1273                                 boxConnected = true;
1274                         }
1275                 }
1276
1277                 std::vector<GPortModel*> outputs = bbmod->getOutputPorts();
1278
1279                 // Add box output controllers to be removed
1280                 for (int i = 0; i < (int) outputs.size(); i++) {
1281                         AddControlerToBeRemove(&controllersToRemove, outputs[i]->getObjectId());
1282                         if (outputs[i]->isConnected()) {
1283                                 boxConnected = true;
1284                         }
1285                 }
1286
1287                 // Add connection controllers to be removed
1288                 std::map<int, GObjectController*>::iterator it;
1289                 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1290                         GObjectController *cont = it->second;
1291                         int type = cont->getGObjectType();
1292                         if (type == GCONNECTOR) {
1293                                 GConnectorModel *conMod = (GConnectorModel*) cont->getModel();
1294                                 if (conMod->getStartPort() != NULL && conMod->getStartPort()->getParentBox()->getObjectId() == bbmod->getObjectId()) 
1295                                 {
1296                                         AddControlerToBeRemove(&controllersToRemove,conMod->getObjectId());
1297                                 }
1298                                 if (conMod->getEndPort() != NULL && conMod->getEndPort()->getParentBox()->getObjectId() == bbmod->getObjectId()) 
1299                                 {
1300                                         AddControlerToBeRemove(&controllersToRemove,conMod->getObjectId());
1301                                 }
1302                         }
1303                 }
1304
1305                 // Add box controller to be removed
1306                 AddControlerToBeRemove(&controllersToRemove, bbmod->getObjectId());
1307         } else if (control->getGObjectType() == GCONNECTOR) {
1308                 GConnectorController *gconnectorcontroler = (GConnectorController*)control;
1309                 if (gconnectorcontroler->getManualContourController()->IsEditable()==false)
1310                 {
1311                         GConnectorModel *conMod = (GConnectorModel*) control->getModel();
1312                         AddControlerToBeRemove(&controllersToRemove, conMod->getObjectId());
1313                 } else{
1314                         gconnectorcontroler->getManualContourController()->OnChar();
1315                         result = false;
1316                 }
1317         }
1318
1319         std::map<int, GObjectController*>::iterator it;
1320
1321         for (int i = 0; i < (int) controllersToRemove.size(); i++) {
1322                 int key = controllersToRemove[i];
1323                 it = _controllers.find(key);
1324                 GObjectController *cont = _controllers[key];
1325                 if (cont != NULL) {
1326                         cont->removeFromScene();
1327                         unregisterController((InteractorStyleMaracas*) cont);
1328                         _controllers.erase(it);
1329                 }//if
1330         }// for
1331         
1332         
1333         return result;
1334 }
1335
1336 //=========================================================================
1337
1338 void wxVtkSceneManager::displayBlackBoxInfo(std::string packageName,
1339                 std::string boxName) {
1340         _parent->displayBlackBoxInfo(packageName, boxName);
1341 }
1342
1343 //=========================================================================
1344
1345 void wxVtkSceneManager::updateStatusBar(std::string textStatus) {
1346         _parent->updateStatusBar(textStatus);
1347 }
1348
1349 //=========================================================================
1350 std::string wxVtkSceneManager::LineNumber(bool withLineNumber, int &value) {
1351         std::string result = "";
1352         if (withLineNumber == true) {
1353                 value++;
1354                 stringstream StrStream;
1355                 StrStream << value;
1356                 std::string strValue = StrStream.str();
1357                 if (value < 10) {
1358                         result += "  ";
1359                 } else if (value < 100) {
1360                         result += " ";
1361                 }
1362
1363                 result += strValue + ": ";
1364         }
1365         return result;
1366 }
1367 //=========================================================================
1368 //DFCH
1369 bool wxVtkSceneManager::MakeBoxExecutable() {
1370         std::map<int, GObjectController*> selected = getSelectedObjects();
1371         if( selected.empty() )
1372                 return false;
1373         bool ret = false;
1374         std::map<int, GObjectController*>::iterator it;
1375         for (it = selected.begin(); it != selected.end(); ++it) {
1376                 GObjectController* lastSelected = it->second;
1377                 if (lastSelected) {
1378                         vtkGObjectView* view = (vtkGObjectView*) lastSelected->getView();
1379                         GBlackBoxModel *bbmodel =
1380                                         (GBlackBoxModel*) lastSelected->getModel();
1381                         view->setState(HIGHLIGHTED);
1382                         if (bbmodel->isExecutable()) {
1383                                 bbmodel->setExecutable(false);
1384                         } else {
1385                                 bbmodel->setExecutable(true);
1386                         }
1387                         bbmodel->notifyObservers(lastSelected->getId());
1388                         ret = true;
1389                 }
1390         }
1391         return ret;
1392 }
1393 //DFCH
1394
1395 //=========================================================================
1396
1397 std::string wxVtkSceneManager::getDiagramBBS(bool wln) {
1398         std::cout << "wxVtkSceneManager::getDiagramBBS" << std::endl;
1399         bool existsExec = false;
1400
1401         std::vector<std::string> packages;
1402         std::vector<int> boxes;
1403         std::vector<int> connections;
1404         std::vector<int> execBoxes;
1405
1406         std::map<int, GObjectController*>::iterator it;
1407
1408         for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1409                 GObjectController *desc = it->second;
1410                 int type = desc->getGObjectType();
1411
1412                 if (type == GBLACKBOX) {
1413                         GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
1414
1415                         std::string pkg = mod->getBBTKPackage();
1416                         bool existsPkg = false;
1417                         for (int t = 0; t < (int) packages.size() && existsPkg == false; t++) {
1418                                 if (packages[t] == pkg) {
1419                                         existsPkg = true;
1420                                 }
1421                         }
1422                         if (!existsPkg) {
1423                                 packages.push_back(pkg);
1424                         }
1425
1426                         boxes.push_back(it->first);
1427                         if (mod->isExecutable()) {
1428                                 execBoxes.push_back(it->first);
1429                                 existsExec = true;
1430                         }
1431                 } else if (type == GCONNECTOR) {
1432                         connections.push_back(it->first);
1433                 }
1434         }
1435
1436         int lnNmbr = 0;
1437         std::string script = "";
1438         script += LineNumber(wln, lnNmbr) + "# BBTK GEditor Script\n";
1439         script += LineNumber(wln, lnNmbr) + "# ----------------------\n";
1440         script += LineNumber(wln, lnNmbr) + "\n";
1441         if (existsExec) {
1442                 script += LineNumber(wln, lnNmbr) + "include std\n"; // EED
1443                 script += LineNumber(wln, lnNmbr) + "include itkvtk\n"; // EED
1444                 int i;
1445                 for (i = 0; i < (int) packages.size(); i++) {
1446                         script += LineNumber(wln, lnNmbr);
1447                         script += "include ";
1448                         script += packages[i];
1449                         script += "\n";
1450                 }
1451
1452                 script += LineNumber(wln, lnNmbr);
1453                 script += "\n";
1454
1455                 //ups2
1456                 
1457                 script += LineNumber(wln, lnNmbr);
1458                 script += "author \"";
1459                 script += _Author;
1460                 script += "\"\n";
1461
1462                 script += LineNumber(wln, lnNmbr);
1463                 script += "description \"";
1464                 script += _Description;
1465                 script += "\"\n";
1466
1467                 script += LineNumber(wln, lnNmbr);
1468                 script += "category \"";
1469                 script += _Category;
1470                 script += "\"\n";
1471
1472                 script += LineNumber(wln, lnNmbr);
1473                 script += "\n";
1474
1475                 // script+="include std\n"; // JPR
1476
1477                 for (i = 0; i < (int) boxes.size(); i++) {
1478                         script += LineNumber(wln, lnNmbr);
1479                         script += "new ";
1480                         int id = boxes[i];
1481                         GObjectController *control      = _controllers[id];
1482                         GBlackBoxModel *model           = (GBlackBoxModel*) control->getModel();
1483
1484                         script += model->getBBTKPackage()+":";
1485                         script += model->getBBTKType();
1486                         script += " ";
1487                         script += model->getBBTKName();
1488                         script += "\n";
1489
1490                         std::vector<GPortModel*> inputs = model->getInputPorts();
1491                         for (int j = 0; j < (int) inputs.size(); j++) {
1492                                 GPortModel* inputPort = inputs[j];
1493                                 if (inputPort->isValueSet()) {
1494                                         script += LineNumber(wln, lnNmbr);
1495                                         script += "  set ";
1496                                         script += model->getBBTKName();
1497                                         script += ".";
1498                                         script += inputPort->getBBTKName();
1499                                         script += " ";
1500                                         script += inputPort->getValue();
1501                                         script += "\n";
1502                                 }
1503                         }
1504
1505                         script += LineNumber(wln, lnNmbr);
1506                         script += "\n";
1507
1508                 }
1509
1510                 script += LineNumber(wln, lnNmbr);
1511                 script += "\n";
1512
1513
1514                 std::string complexInputs="";
1515
1516                 for (i = 0; i < (int) connections.size(); i++) {
1517                         //script += LineNumber(wln, lnNmbr);
1518                         //script += "connect ";
1519                         int                 id          = connections[i];
1520                         GObjectController   *control    = _controllers[id];
1521                         GConnectorModel     *model      = (GConnectorModel*) control->getModel();
1522
1523
1524                         //Connection info
1525                         GPortModel          *start      = model->getStartPort();
1526                         GBoxModel           *startBox   = start->getParentBox();
1527
1528                         GPortModel *end = model->getEndPort();
1529                         GBoxModel *endBox = end->getParentBox();
1530
1531                         if (startBox->getGObjectType() == GCOMPLEXINPUTPORT)
1532                         {
1533                                         complexInputs += "input ";
1534                                         complexInputs += startBox->getBBTKName();
1535
1536                                         complexInputs += " ";
1537                                         complexInputs += endBox->getBBTKName();
1538                                         complexInputs += ".";
1539                                         complexInputs += end->getBBTKName();
1540
1541                                         complexInputs += " ";
1542                                         complexInputs += "\" \"";
1543
1544                                         complexInputs += "\n";
1545                         }
1546                         else
1547                         {
1548                                         script += LineNumber(wln, lnNmbr);
1549                                         script += "connect ";
1550                                         script += startBox->getBBTKName();
1551                                         script += ".";
1552                                         script += start->getBBTKName();
1553
1554                                         script += " ";
1555
1556                                         //End Connection info
1557                                         script += endBox->getBBTKName();
1558                                         script += ".";
1559                                         script += end->getBBTKName();
1560
1561                                         script += "\n";
1562                         }
1563
1564                         script += LineNumber(wln, lnNmbr);
1565                         script += "\n";
1566                 }
1567
1568                 script += LineNumber(wln, lnNmbr);
1569                 script += "\n";
1570
1571                 script += LineNumber(wln, lnNmbr);
1572                 script += "\n";
1573
1574                 script += LineNumber(wln, lnNmbr);
1575                 script += "# Complex input ports\n";
1576                 script += complexInputs;
1577
1578                 if((_MessageKind!="-")&&(_MessageLevel!="-")){
1579                         script += LineNumber(wln, lnNmbr);
1580                         script += "message ";
1581                         script += _MessageKind;
1582                         script += " ";
1583                         script += _MessageLevel;
1584                         script += "\n";
1585                 }
1586
1587                 for (i = 0; i < (int) execBoxes.size(); i++) {
1588                         script += LineNumber(wln, lnNmbr);
1589                         script += "exec ";
1590                         int id = execBoxes[i];
1591                         GObjectController *control = _controllers[id];
1592                         GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1593                         script += model->getBBTKName();
1594                         script += "\n";
1595                 }
1596
1597         }
1598
1599         return script;
1600 }
1601
1602 //=========================================================================
1603
1604 std::string wxVtkSceneManager::saveComplexBoxBBS() {
1605         std::vector<std::string> packages;
1606         std::vector<int> boxes;
1607         std::vector<int> connections;
1608         std::vector<int> execBoxes;
1609
1610         std::map<int, GObjectController*>::iterator it;
1611
1612         for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1613                 GObjectController *desc = it->second;
1614                 int type = desc->getGObjectType();
1615
1616                 if (type == GBLACKBOX) {
1617                         GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
1618
1619                         std::string pkg = mod->getBBTKPackage();
1620                         bool existsPkg = false;
1621                         for (int t = 0; t < (int) packages.size() && existsPkg == false; t++) {
1622                                 if (packages[t] == pkg) {
1623                                         existsPkg = true;
1624                                 }
1625                         }
1626                         if (!existsPkg) {
1627                                 packages.push_back(pkg);
1628                         }
1629
1630                         boxes.push_back(it->first);
1631                         if (mod->isExecutable()) {
1632                                 execBoxes.push_back(it->first);
1633                         }
1634                 } else if (type == GCONNECTOR) {
1635                         connections.push_back(it->first);
1636                 }
1637         }
1638
1639         std::string script = "";
1640
1641         script += "include std\n"; // EED
1642         script += "include itkvtk\n"; // EED
1643         int i;
1644         for (i = 0; i < (int) packages.size(); i++) {
1645                 script += "include ";
1646                 script += packages[i];
1647                 script += "\n";
1648         }
1649         script += "\n";
1650
1651         // Definition of a complex box
1652         script += "define ";
1653         script += _cbName + " " + _cbPackageName;
1654         script += "\n";
1655         script += "\n";
1656
1657         script += "author \"";
1658         script += _Author;
1659         script += "\"\n";
1660
1661         script += "description \"";
1662         script += _Description;
1663         script += "\"\n";
1664         script += "\n";
1665
1666         script += "category \"";
1667         script += _Category;
1668         script += "\"\n";
1669         script += "\n";
1670
1671         // Create boxes
1672         for (i = 0; i < (int) boxes.size(); i++) {
1673                 script += "new ";
1674                 int id = boxes[i];
1675                 GObjectController *control = _controllers[id];
1676                 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1677
1678                 script += model->getBBTKPackage()+":";
1679                 script += model->getBBTKType();
1680                 script += " ";
1681                 script += model->getBBTKName();
1682                 script += "\n";
1683
1684                 std::vector<GPortModel*> inputs = model->getInputPorts();
1685                 for (int j = 0; j < (int) inputs.size(); j++) {
1686                         GPortModel* inputPort = inputs[j];
1687                         if (inputPort->isValueSet()) {
1688                                 script += "  set ";
1689                                 script += model->getBBTKName();
1690                                 script += ".";
1691                                 script += inputPort->getBBTKName();
1692                                 script += " ";
1693                                 script += inputPort->getValue();
1694                                 script += "\n";
1695                         }
1696                 }
1697                 script += "\n";
1698
1699         }
1700
1701         // Create connections in the script. If the connection is made with a complex port, it is created the input or output
1702
1703         std::string complexInputs = "";
1704         std::string complexOutputs = "";
1705         script += "\n";
1706
1707         for (i = 0; i < (int) connections.size(); i++) {
1708                 int id = connections[i];
1709                 GObjectController *control = _controllers[id];
1710                 GConnectorModel *model = (GConnectorModel*) control->getModel();
1711
1712                 //Connection info
1713                 GPortModel *start = model->getStartPort();
1714                 GBoxModel *startBox = start->getParentBox();
1715
1716                 GPortModel *end = model->getEndPort();
1717                 GBoxModel *endBox = end->getParentBox();
1718
1719                 if (startBox->getGObjectType() == GCOMPLEXINPUTPORT) {
1720                         complexInputs += "input ";
1721                         complexInputs += startBox->getBBTKName();
1722
1723                         complexInputs += " ";
1724                         complexInputs += endBox->getBBTKName();
1725                         complexInputs += ".";
1726                         complexInputs += end->getBBTKName();
1727
1728                         complexInputs += " ";
1729                         complexInputs += "\" \"";
1730
1731                         complexInputs += "\n";
1732                 } else if (endBox->getGObjectType() == GCOMPLEXOUTPUTPORT) {
1733                         complexOutputs += "output ";
1734                         complexOutputs += endBox->getBBTKName();
1735
1736                         complexOutputs += " ";
1737                         complexOutputs += startBox->getBBTKName();
1738                         complexOutputs += ".";
1739                         complexOutputs += start->getBBTKName();
1740
1741                         complexOutputs += " ";
1742                         complexOutputs += "\" \"";
1743
1744                         complexOutputs += "\n";
1745                 } else {
1746                         script += "connect ";
1747                         script += startBox->getBBTKName();
1748                         script += ".";
1749                         script += start->getBBTKName();
1750
1751                         script += " ";
1752
1753                         //End Connection info
1754                         script += endBox->getBBTKName();
1755                         script += ".";
1756                         script += end->getBBTKName();
1757
1758                         script += "\n";
1759                 }
1760         }
1761
1762         script += "\n";
1763         script += "# Complex input ports\n";
1764         script += complexInputs;
1765
1766         script += "\n";
1767         script += "# Complex output ports\n";
1768         script += complexOutputs;
1769
1770         script += "\n";
1771
1772         if((_MessageKind!="-")&&(_MessageLevel!="-"))
1773         {
1774                 script += "message ";
1775                 script += _MessageKind;
1776                 script += " ";
1777                 script += _MessageLevel;
1778                 script += "\n";
1779         }
1780
1781         for (i = 0; i < (int) execBoxes.size(); i++) 
1782         {
1783                 script += "exec ";
1784                 int id = execBoxes[i];
1785                 GObjectController *control = _controllers[id];
1786                 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1787
1788                 script += model->getBBTKName();
1789                 script += "\n";
1790         }
1791
1792         script += "\n";
1793         script += "endefine";
1794         script += "\n";
1795
1796         return script;
1797 }
1798
1799 //=========================================================================
1800
1801 void wxVtkSceneManager::deleteAllBoxes() {
1802         std::map<int, GObjectController*>::iterator it;
1803         for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1804                 GObjectController *cont = it->second;
1805                 cont->removeFromScene();
1806                 unregisterController((InteractorStyleMaracas*) cont);
1807         }
1808         _selectedObjects.clear();
1809         _controllers.clear();
1810 }
1811
1812 //=========================================================================
1813
1814
1815 void wxVtkSceneManager::refresh() {
1816         _baseView->Refresh();
1817 }
1818 //=========================================================================
1819
1820 void wxVtkSceneManager::refreshScene() 
1821 {
1822         _baseView->RefreshView();
1823 }
1824
1825 //=========================================================================
1826
1827 void wxVtkSceneManager::centerView() 
1828 {
1829         double bb[6];
1830         _baseView->GetRenderer()->ComputeVisiblePropBounds(bb);
1831
1832         double temp[3];
1833         _baseView->GetRenderer()->GetActiveCamera()->GetFocalPoint(temp);
1834         _baseView->GetRenderer()->GetActiveCamera()->SetFocalPoint(0, 0, temp[2]);
1835         _baseView->GetRenderer()->GetActiveCamera()->GetPosition(temp);
1836         _baseView->GetRenderer()->GetActiveCamera()->SetPosition(0, 0, temp[2]);
1837
1838         _baseView->GetRenderer()->ResetCamera();
1839         _baseView->GetRenderer()->ResetCameraClippingRange();
1840
1841 /*
1842         double tt=_baseView->GetRenderer()->GetNearClippingPlaneTolerance();
1843         printf("EED wxVtkSceneManager::centerView() tolerance=%f\n",tt);
1844         double cr1,cr2;
1845         _baseView->GetRenderer()->GetActiveCamera()->GetClippingRange(cr1,cr2);
1846         printf("EED wxVtkSceneManager::centerView() cr1=%f  cr2=%f\n",cr1,cr2);
1847         _baseView->GetRenderer()->GetActiveCamera()->SetClippingRange(0.01,100000);
1848         _baseView->GetRenderer()->GetActiveCamera()->GetClippingRange(cr1,cr2);
1849         printf("EED wxVtkSceneManager::centerView() cr1=%f  cr2=%f\n",cr1,cr2);
1850 */
1851
1852         _baseView->GetRenderer()->Render();
1853 }
1854
1855 //=========================================================================
1856
1857 void wxVtkSceneManager::saveDiagram(std::string &content) 
1858 {
1859         char buffer[50];
1860
1861         content += "CATEGORY:";
1862         content += GetCategory();
1863         content += "\n";
1864
1865         content += "DESCRIPTION:";
1866         content += GetDescription();
1867         content += "\n";
1868
1869         content += "AUTHOR:";
1870         content += GetAuthor();
1871         content += "\n";
1872
1873     content += "EXPORTFORMAT:";
1874     sprintf(buffer, "%d", GetExportFormat()) ;
1875     content += buffer;
1876     content += "\n";
1877     
1878         //Print info IF COMPLEX BOX
1879         content += "COMPLEXBOX:";
1880         if (_isComplexBox) {
1881                 content += "TRUE\n";
1882                 //ups1
1883                 content += "COMPLEXBOXNAME:";
1884                 content += GetCbName();
1885                 content += "\n";
1886
1887                 content += "PACKAGENAME:";
1888                 content += GetCbPackageName();
1889                 content += "\n";
1890
1891         /* CHANGE TO THE VERSION 1.4 RaC2012 2nd HackFest
1892          * External inputs are possible for applications and complex boxes
1893         //Print info complex input ports
1894         std::vector<int> inputs = getComplexInputPorts();
1895         int insize = inputs.size();
1896         content += "COMPLEXINPUTS:";
1897         sprintf(buffer, "%d", insize);
1898         content += buffer;
1899         content += "\n";
1900
1901         for (int i = 0; i < insize; i++) {
1902             int id = inputs[i];
1903             GObjectController *cont = _controllers[id];
1904             cont->getModel()->save(content);
1905         }
1906         */
1907
1908         //Print info complex output ports
1909         std::vector<int> outputs = getComplexOutputPorts();
1910         int outsize = outputs.size();
1911         content += "COMPLEXOUTPUTS:";
1912         sprintf(buffer, "%d", outsize);
1913         content += buffer;
1914         content += "\n";
1915
1916         for (int i = 0; i < outsize; i++) {
1917             int id = outputs[i];
1918             GObjectController *cont = _controllers[id];
1919             cont->getModel()->save(content);
1920         }
1921
1922
1923
1924         } // _isComplexBox
1925         else {
1926                 content += "FALSE\n";
1927         }
1928
1929     
1930         // CHANGE TO THE VERSION 1.4 RaC2012 2nd HackFest
1931         // External inputs are possible for applications and complex boxes
1932         std::vector<int> inputs = getComplexInputPorts();
1933         int insize = inputs.size();
1934         content += "COMPLEXINPUTS:";
1935         sprintf(buffer, "%d", insize);
1936         content += buffer;
1937         content += "\n";
1938
1939         for (int i = 0; i < insize; i++) {
1940                 int id = inputs[i];
1941                 GObjectController *cont = _controllers[id];
1942                 cont->getModel()->save(content);
1943         }
1944
1945         //Print boxes
1946         std::vector<int> boxes = getBlackBoxes();
1947         int bsize = boxes.size();
1948         content += "BOXES:";
1949         sprintf(buffer, "%d", bsize);
1950         content += buffer;
1951         content += "\n";
1952         
1953         for (int i = 0; i < bsize; i++) {
1954                 int id = boxes[i];
1955 //              std::cout<<"id "<<id<<std::endl;//CFT
1956                 GObjectController *cont = _controllers[id];
1957 //              std::cout<<"nombre: "<<cont->getStatusText()<<std::endl;//CFT
1958 //              std::cout<<"tipo: "<<cont->getModel()->getBBTKType()<<std::endl;//CFT
1959 //              //boxesDiagram[i] = cont->getModel()->getBBTKType();//CFT
1960 //              std::cout<<"nname: "<<cont->getModel()->getBBTKName()<<std::endl;//CFT
1961 //              std::cout<<"categorie: "<<GetCategory()<<std::endl;//CFT
1962 //              std::cout<<"type: "<<cont->getModel()->getGObjectType()<<std::endl;//CFT
1963                 cont->getModel()->save(content);
1964         }
1965
1966         //Print connections
1967         std::vector<int> connections = getConnections();
1968         int csize = connections.size();
1969         content += "CONNECTIONS:";
1970         sprintf(buffer, "%d", csize);
1971         content += buffer;
1972         content += "\n";
1973
1974         for (int i = 0; i < csize; i++) {
1975                 int id = connections[i];
1976                 GObjectController *cont = _controllers[id];
1977                 cont->getModel()->save(content);
1978         }
1979
1980 }
1981
1982 //=========================================================================
1983 void wxVtkSceneManager::getCleanLine(stringstream &inputStream, std::string &line)
1984 {
1985         getline(inputStream, line,'\n');
1986         int size = line.length();
1987     if (size>0)
1988         {
1989                 if ( line[ size-1 ]==13  )
1990                 {
1991                         line.erase(size-1,1);
1992                 } // if line
1993         } // if size
1994 }
1995         
1996 //=========================================================================
1997 void wxVtkSceneManager::loadDiagram(stringstream &inputStream) 
1998 {
1999         int size;
2000         std::string version = "<void>";
2001         std::string line = "";
2002         char delims[] = ":";
2003         char *result = NULL;
2004         char poort[POORT_MAX_LINE_SIZE_INTERPRETER];
2005
2006         getCleanLine(inputStream, line);
2007
2008         bool start = false;
2009         while (!inputStream.eof()) {
2010                 if (line == "" || line[0] == '#') {
2011                         line="";
2012                         getCleanLine(inputStream, line);
2013                         
2014                         if (line == "# - BBTKGEditor v 1.0 BBG BlackBox Diagram file") {
2015                                 version = line.substr(18, 3);
2016                         }
2017                         if (line == "# - BBTKGEditor v 1.1 BBG BlackBox Diagram file") {
2018                                 version = line.substr(18, 3);
2019                         }
2020                         if (line == "# - BBTKGEditor v 1.2 BBG BlackBox Diagram file") {
2021                                 version = line.substr(18, 3);
2022                         }
2023                         if (line == "# - BBTKGEditor v 1.3 BBG BlackBox Diagram file") {
2024                                 version = line.substr(18, 3);
2025                         }
2026                         if (line == "# - BBTKGEditor v 1.4 BBG BlackBox Diagram file") {
2027                                 version = line.substr(18, 3);
2028                         }
2029             if (line == "# - BBTKGEditor v 1.5 BBG BlackBox Diagram file") {
2030                 version = line.substr(18, 3);
2031             }
2032             if (line == "# - BBTKGEditor v 1.6 BBG BlackBox Diagram file") {
2033                 version = line.substr(18, 3);
2034             }
2035                 } else if (line == "APP_START") {
2036                         start = true;
2037                         break;
2038                 }
2039         }
2040
2041
2042         if (start)
2043     {
2044
2045                 if ((version != "1.0") && (version != "1.1")) {
2046                         getCleanLine(inputStream, line);//CATEGORY:<category of the box>
2047                         char categoryTmp[30];
2048                         strcpy(categoryTmp, line.c_str());
2049                         result = strtok(categoryTmp, delims);
2050                         result = strtok(NULL, delims);
2051                         SetCategory(result);
2052
2053                         getCleanLine(inputStream, line);//DESCRIPTION:<description of the box>
2054                         char descriptionTmp[1024];
2055                         strcpy(descriptionTmp, line.c_str());
2056                         result = strtok(descriptionTmp, delims);
2057                         result = strtok(NULL, delims);
2058                         SetDescription(result);
2059
2060                         getCleanLine(inputStream, line);//AUTHOR:<author>
2061                         char authorTmp[255];
2062                         strcpy(authorTmp, line.c_str());
2063                         result = strtok(authorTmp, delims);
2064                         result = strtok(NULL, delims);
2065                         SetAuthor(result);
2066             
2067             if(version >= "1.6")
2068             {
2069                 getCleanLine(inputStream, line);//EXPORTFORMAT:<0:bbs 1:ALL 2:bbs,Python 3:bbs,JavaScript>
2070                 char authorTmp[255];
2071                 strcpy(authorTmp, line.c_str());
2072                 result = strtok(authorTmp, delims);
2073                 result = strtok(NULL, delims);
2074                 int exportformatTMP;
2075                 std::istringstream inps(result);
2076                 inps >> exportformatTMP;
2077                 SetExportFormat( exportformatTMP );
2078             }
2079             
2080                 }
2081
2082                 //----------
2083                 getCleanLine(inputStream, line);//COMPLEX_BOX:TRUE|FALSE
2084                 char complexTmp[30];
2085                 strcpy(complexTmp, line.c_str());
2086                 result = strtok(complexTmp, delims);
2087                 result = strtok(NULL, delims);
2088                 std::string isComplexBox(result);
2089
2090                 if (isComplexBox == "TRUE")
2091         {
2092                         _isComplexBox = true;
2093
2094                         if ((version != "1.0") && (version != "1.1"))
2095             {
2096                                 getCleanLine(inputStream, line);//COMPLEXNAME:<name of the complex box>
2097                                 char complexboxnameTmp[255];
2098                                 strcpy(complexboxnameTmp, line.c_str());
2099                                 result = strtok(complexboxnameTmp, delims);
2100                                 result = strtok(NULL, delims);
2101                                 SetCbName(result);
2102
2103                                 getCleanLine(inputStream, line);//PACKAGENAME:<name of the package of the box>
2104                                 char packagenameTmp[255];
2105                                 strcpy(packagenameTmp, line.c_str());
2106                                 result = strtok(packagenameTmp, delims);
2107                                 result = strtok(NULL, delims);
2108                                 SetCbPackageName(result);
2109                         } // if version !1.0  !1.1
2110
2111                         if(version < "1.4")
2112                         {
2113                                 //-----------------------
2114                                 //- COMPLEX INPUT PORTS
2115                                 //-----------------------
2116                                 getCleanLine(inputStream, line);//COMPLEXINPUTS:num
2117                                 char inputs[30];
2118                                 strcpy(inputs, line.c_str());
2119                                 result = strtok(inputs, delims);
2120                                 result = strtok(NULL, delims);
2121
2122                                 int numInputs;
2123                                 std::istringstream inps(result);
2124                                 inps >> numInputs;
2125
2126                                 for (int i = 0; i < numInputs; i++)
2127                 {
2128                                         //----------
2129                                         getCleanLine(inputStream, line);//COMPLEX_PORT
2130                                         getCleanLine(inputStream, line);//name
2131                                         std::string inputPortName(line);
2132
2133                                         //----------
2134                                         getCleanLine(inputStream, line);//xInic:yInic:zInic
2135                                         char coord[80];
2136                                         strcpy(coord, line.c_str());
2137                                         result = strtok(coord, delims);//xInic
2138                                         std::string xInic(result);
2139                                         result = strtok(NULL, delims);//yInic
2140                                         std::string yInic(result);
2141                                         result = strtok(NULL, delims);//zInic
2142                                         std::string zInic(result);
2143
2144                                         double xIn, yIn, zIn;
2145                                         std::istringstream xSt(xInic);
2146                                         xSt >> xIn;
2147                                         std::istringstream ySt(yInic);
2148                                         ySt >> yIn;
2149                                         std::istringstream zSt(zInic);
2150                                         zSt >> zIn;
2151
2152                                         if (version<="1.2")
2153                                         {
2154                                                 if (zIn==900) zIn=GPOSITION_Z;
2155                                         } // if version <=1.2
2156
2157                                         getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
2158
2159                                         configGComBoxInputOutputPort(true, inputPortName, xIn, yIn, zIn);
2160
2161                                 } // for input complex box
2162                         } // if version < 1.4
2163
2164
2165
2166                         //-----------------------
2167                         //- COMPLEX OUTPUT PORTS
2168                         //-----------------------
2169
2170                         getCleanLine(inputStream, line);//COMPLEXOUTPUTS:num
2171                         char outputs[30];
2172                         strcpy(outputs, line.c_str());
2173                         result = strtok(outputs, delims);
2174                         result = strtok(NULL, delims);
2175
2176                         int numOutputs;
2177                         std::istringstream outps(result);
2178                         outps >> numOutputs;
2179
2180                         for (int i = 0; i < numOutputs; i++)
2181             {
2182                                 //----------
2183                                 getCleanLine(inputStream, line);//COMPLEX_PORT
2184                                 getCleanLine(inputStream, line);//name
2185                                 std::string outputPortName(line);
2186
2187                                 //----------
2188                                 getCleanLine(inputStream, line);//xInic:yInic:zInic
2189                                 char coord[80];
2190                                 strcpy(coord, line.c_str());
2191                                 result = strtok(coord, delims);//xInic
2192                                 std::string xInic(result);
2193                                 result = strtok(NULL, delims);//yInic
2194                                 std::string yInic(result);
2195                                 result = strtok(NULL, delims);//zInic
2196                                 std::string zInic(result);
2197
2198                                 double xIn, yIn, zIn;
2199                                 std::istringstream xSt(xInic);
2200                                 xSt >> xIn;
2201                                 std::istringstream ySt(yInic);
2202                                 ySt >> yIn;
2203                                 std::istringstream zSt(zInic);
2204                                 zSt >> zIn;
2205
2206                                 if (version<="1.2")
2207                                 {
2208                                         if (zIn==900) zIn=GPOSITION_Z;
2209                                 }
2210 //EED 2022-01-16
2211                 if (version<="1.4")
2212                 {
2213                     xIn = xIn*0.70;
2214                     yIn = yIn*0.30;
2215                 }
2216
2217                                 getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
2218
2219                                 configGComBoxInputOutputPort(false, outputPortName, xIn, yIn, zIn);
2220
2221                         } // for output complex box
2222                 } // if isComplexBox
2223
2224         
2225                 // RaC2012 2nd Hackfest
2226                 if(version >= "1.4")
2227                 {
2228                         //-----------------------
2229                         //- EXTERNAL INPUT PORTS
2230                         //-----------------------
2231                         getCleanLine(inputStream, line);//COMPLEXINPUTS:num
2232                         char inputs[30];
2233                         strcpy(inputs, line.c_str());
2234                         result = strtok(inputs, delims);
2235                         result = strtok(NULL, delims);
2236
2237                         int numInputs;
2238                         std::istringstream inps(result);
2239                         inps >> numInputs;
2240
2241                         for (int i = 0; i < numInputs; i++)
2242             {
2243                                 getCleanLine(inputStream, line);//COMPLEX_PORT
2244                                 getCleanLine(inputStream, line);//name
2245                                 std::string inputPortName(line);
2246                                 getCleanLine(inputStream, line);//xInic:yInic:zInic
2247                                 char coord[80];
2248                                 strcpy(coord, line.c_str());
2249                                 result = strtok(coord, delims);//xInic
2250                                 std::string xInic(result);
2251                                 result = strtok(NULL, delims);//yInic
2252                                 std::string yInic(result);
2253                                 result = strtok(NULL, delims);//zInic
2254                                 std::string zInic(result);
2255                                 double xIn, yIn, zIn;
2256                                 std::istringstream xSt(xInic);
2257                                 xSt >> xIn;
2258                                 std::istringstream ySt(yInic);
2259                                 ySt >> yIn;
2260                                 std::istringstream zSt(zInic);
2261                                 zSt >> zIn;
2262                                 if (version<="1.2")
2263                                 {
2264                                         if (zIn==900) zIn=GPOSITION_Z;
2265                                 }
2266 //EED 2022-01-16
2267                 if (version<="1.4")
2268                 {
2269                     xIn = xIn*0.70;
2270                     yIn = yIn*0.30;
2271                 }
2272                                 getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
2273                                 configGComBoxInputOutputPort(true, inputPortName, xIn, yIn, zIn);
2274                         } // for external input
2275                 }   //      if(version >= "1.4")
2276
2277                 //----------
2278                 getCleanLine(inputStream, line);//BOXES:num
2279                 char boxes[9];
2280                 strcpy(boxes, line.c_str());
2281                 result = strtok(boxes, delims);
2282                 result = strtok(NULL, delims);
2283
2284                 int numBoxes;
2285                 std::istringstream is(result);
2286                 is >> numBoxes;
2287
2288                 for (int i = 0; i < numBoxes; i++) 
2289                 {
2290                         //----------
2291                         getCleanLine(inputStream, line);//BOX
2292                         getCleanLine(inputStream, line);//package:type:name
2293                         char box[150];
2294                         strcpy(box, line.c_str());
2295                         result = strtok(box, delims);//package
2296                         std::string package(result);
2297                         result = strtok(NULL, delims);//type
2298                         std::string type(result);
2299                         result = strtok(NULL, delims);//name
2300                         std::string name(result);
2301
2302
2303                         getCleanLine(inputStream, line);//ISEXEC:TRUE|FALSE
2304                         char exec[15];
2305                         strcpy(exec, line.c_str());
2306                         result = strtok(exec, delims);//ISEXEC
2307                         result = strtok(NULL, delims);//TRUE|FALSE
2308                         std::string isExec(result);
2309
2310                         //----------
2311                         getCleanLine(inputStream, line);//xInic:yInic:zInic
2312                         char coord[80];
2313                         strcpy(coord, line.c_str());
2314                         result = strtok(coord, delims);//xInic
2315                         std::string xInic(result);
2316                         result = strtok(NULL, delims);//yInic
2317                         std::string yInic(result);
2318                         result = strtok(NULL, delims);//zInic
2319                         std::string zInic(result);
2320                         double xIn, yIn, zIn;
2321                         std::istringstream xSt(xInic);
2322                         xSt >> xIn;
2323                         std::istringstream ySt(yInic);
2324                         ySt >> yIn;
2325                         std::istringstream zSt(zInic);
2326                         zSt >> zIn;
2327
2328                         if (version<="1.2")
2329                         {
2330                                 if (zIn==900) zIn=GPOSITION_Z;
2331                         }
2332 //EED 2022-01-16
2333             if (version<="1.4")
2334             {
2335                 xIn = xIn*0.70;
2336                 yIn = yIn*0.30;
2337             }
2338                         //----------
2339                         getCleanLine(inputStream, line);//xEnd:yEnd:zEnd
2340                         strcpy(coord, line.c_str());
2341                         result = strtok(coord, delims);//xEnd
2342                         std::string xEnd(result);
2343                         result = strtok(NULL, delims);//yEnd
2344                         std::string yEnd(result);
2345                         result = strtok(NULL, delims);//zEnd
2346                         std::string zEnd(result);
2347
2348                         double xEn, yEn, zEn;
2349                         std::istringstream xEt(xEnd);
2350                         xEt >> xEn;
2351                         std::istringstream yEt(yEnd);
2352                         yEt >> yEn;
2353                         std::istringstream zEt(zEnd);
2354                         zEt >> zEn;
2355
2356                         if (version<="1.2")
2357                         {
2358                                 if (zEn==900) zEn=GPOSITION_Z;
2359                         }
2360 //EED 2022-01-16
2361             yEn = yIn-BOX_HEIGHT;
2362                         
2363                         bool boxExecutable = false;
2364                         if (isExec == "TRUE") 
2365                         {
2366                                 boxExecutable = true;
2367                         }
2368
2369                         int idBox = createGBlackBox(xIn, yIn, package, type);
2370                         configGBlackBox(idBox, xIn, yIn, zIn, name, boxExecutable, xEn, yEn, zEn);
2371
2372                         GObjectController *cont = _controllers[idBox];
2373                         GBlackBoxModel *bbmod = (GBlackBoxModel*) cont->getModel();
2374
2375                         //----------
2376                         getCleanLine(inputStream, line);//PORT o FIN_BOX
2377                         std::string port = line.substr(0, 4);
2378                         while (port == "PORT") 
2379                         {
2380                                 getCleanLine(inputStream, line);//name:value
2381                                 if (line.length()>=POORT_MAX_LINE_SIZE_INTERPRETER-1)
2382                                 {
2383                                         line=line.substr(0, POORT_MAX_LINE_SIZE_INTERPRETER-1);
2384                                 }
2385                                 
2386                                 strcpy(poort, line.c_str());
2387                                 result = strtok(poort, delims);//name
2388                                 std::string name(result);
2389                                 
2390                                 //EED 16 oct 2012 Adding at the end character " if necesary in the value definition
2391                                 result = strtok(NULL, delims);//value
2392                                 if (( result[0]=='"' ) && ( result[ strlen(result)-1 ]!='"' )  )
2393                                 {
2394                                         std::string tmpString=" ";
2395                                         tmpString[0]=34;         // character "
2396                                         strcat(result,tmpString.c_str());
2397                                 }
2398                                 std::string value(result);
2399                                 bbmod->setValueToInput(name, value);
2400                                 getCleanLine(inputStream, line);//PORT o FIN_BOX
2401                                 port = line.substr(0, 4);
2402                         } // while
2403
2404                         //EED                           bbmod->notifyObservers(_idManager);
2405                 } // for boxes
2406
2407                 /// CONNECTIONS
2408                 //----------
2409                 getCleanLine(inputStream, line);//CONNECTIONS:num
2410                 char conns[30];
2411                 strcpy(conns, line.c_str());
2412                 result = strtok(conns, delims);
2413                 result = strtok(NULL, delims);
2414                 int numConns;
2415                 std::istringstream isCons(result);
2416                 isCons >> numConns;
2417                 
2418                 
2419                 for (int i = 0; i < numConns; i++) 
2420                 {
2421                         //----------
2422                         getCleanLine(inputStream, line);//CONNECTION
2423                         getCleanLine(inputStream, line);//Startbox.PortName:EndBox.PortName
2424                         char connec[200];
2425                         strcpy(connec, line.c_str());
2426                         result = strtok(connec, delims);
2427                         std::string nameStartBox(result);
2428                         result = strtok(NULL, delims);
2429                         std::string nameStartPort(result);
2430                         result = strtok(NULL, delims);
2431                         std::string nameEndBox(result);
2432                         result = strtok(NULL, delims);
2433                         std::string nameEndPort(result);
2434                         int idCon = configGConnetion(nameStartBox, nameStartPort,nameEndBox, nameEndPort);
2435                         if (version != "1.0") {
2436                                 //Readding control points of the manualContour
2437                                 GConnectorController    *tempp          = (GConnectorController*) _controllers[idCon];
2438                                 GConnectorModel         *conMod         = (GConnectorModel*) tempp->getModel();
2439                                 vtkGConnectorView       *conView        = (vtkGConnectorView*) tempp->getView();
2440                                 getCleanLine(inputStream, line); //NumberOfControlPoints:##
2441                                 strcpy(conns, line.c_str());
2442                                 result = strtok(conns, delims);
2443                                 result = strtok(NULL, delims);
2444                                 int numberOfControlPoints;
2445                                 std::istringstream isCons(result);
2446                                 isCons >> numberOfControlPoints;
2447                                 for (int ii = 0; ii < numberOfControlPoints; ii++) {
2448                                         getCleanLine(inputStream, line); //XX:YY:ZZ
2449                                         char connec[200];
2450                                         strcpy(connec, line.c_str());
2451                                         double px, py, pz;
2452                                         result = strtok(connec, delims);
2453                                         std::istringstream isPointX(result);
2454                                         isPointX >> px;
2455                                         result = strtok(NULL, delims);
2456                                         std::istringstream isPointY(result);
2457                                         isPointY >> py;
2458                                         result = strtok(NULL, delims);
2459                                         std::istringstream isPointZ(result);
2460                                         isPointZ >> pz;
2461                                         if (version<="1.2")
2462                                         {
2463                                                 if (pz==900) pz=GPOSITION_Z;
2464                                         }
2465 //EED 2022-01-16
2466                     if (version<="1.4")
2467                     {
2468                         px = px*0.70;
2469                         py = py*0.30;
2470                     }
2471                                         conMod->getManualContourModel()->InsertPoint_id(ii + 1, px, py, pz);
2472                                         conView->getManualContourView()->AddPoint();
2473                                 }
2474                         }// if version !=1.0
2475                 } // for numConns
2476         } // if start
2477 }
2478 //=========================================================================
2479
2480
2481 //=========================================================================
2482 void wxVtkSceneManager::configGComBoxInputOutputPort(bool inputoutput,
2483                 std::string portName, double xIn, double yIn, double zIn) 
2484 {
2485         int idPort;
2486         if (inputoutput == true) {
2487                 idPort = createGComplexBoxInputPort(portName);
2488         } else {
2489                 idPort = createGComplexBoxOutputPort(portName);
2490         }
2491         GObjectController *cont = _controllers[idPort];
2492         GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2493         cbmod->setInicPoint(xIn, yIn, zIn);
2494         cbmod->notifyObservers(_idManager);
2495 }
2496 //=========================================================================
2497
2498
2499 //=========================================================================
2500 GBoxModel* wxVtkSceneManager::findGBox(std::string boxname) 
2501 {
2502         int j;
2503         int idB;
2504         GBoxModel *bMod;
2505         GBoxModel *boxModel = NULL;
2506         std::vector<int> lstB = getBlackBoxes();
2507         for (j = 0; j < (int) lstB.size(); j++) {
2508                 idB = lstB[j];
2509                 bMod = (GBoxModel*) _controllers[idB]->getModel();
2510                 if (_controllers[idB]->getModel()->getBBTKName() == boxname) 
2511                 {
2512                         boxModel = bMod;
2513                 }
2514         } // for
2515
2516
2517
2518         if (boxModel == NULL) {
2519                 std::vector<int> lstInputs = getComplexInputPorts();
2520                 for (j = 0; j < (int) lstInputs.size(); j++) {
2521                         idB = lstInputs[j];
2522                         bMod = (GBoxModel*) _controllers[idB]->getModel();
2523                         if (_controllers[idB]->getModel()->getBBTKName() == boxname) 
2524                         {
2525                                 boxModel = bMod;
2526                         }
2527                 } // for
2528
2529                 if(_isComplexBox)
2530                 {
2531                 std::vector<int> lstOutputs = getComplexOutputPorts();
2532                 for (j = 0; j < (int) lstOutputs.size(); j++) {
2533                         int idB = lstOutputs[j];
2534                         bMod = (GBoxModel*) _controllers[idB]->getModel();
2535                         if (_controllers[idB]->getModel()->getBBTKName() == boxname) 
2536                         {
2537                                 boxModel = bMod;
2538                         }
2539                 } // for
2540                 }
2541
2542         } // inputs/outputs
2543
2544         return boxModel;
2545 }
2546
2547 //=========================================================================
2548
2549
2550 int wxVtkSceneManager::configGConnetion(std::string nameStartBox,
2551                 std::string nameStartPort, std::string nameEndBox,
2552                 std::string nameEndPort) {
2553
2554         GBoxModel *boxModel;
2555         GPortModel *startP = NULL;
2556         GPortModel *endP = NULL;
2557
2558         boxModel = findGBox(nameStartBox);
2559         if(boxModel == NULL)
2560         {
2561                 printf("RaC: ERROR in wxVtkSceneManager::configGConnetion A box to connect start port %s is null. Box name is probably wrong.\n", nameStartPort.c_str());
2562         }
2563         if (boxModel != NULL) {
2564                 startP = boxModel->getOutputPort(nameStartPort);
2565                 if(startP == NULL){
2566                         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() );
2567                 }
2568         }
2569
2570         boxModel = findGBox(nameEndBox);
2571         if(boxModel == NULL)
2572         {
2573                  printf("RaC: ERROR in wxVtkSceneManager::configGConnetion A box to connect start port %s is null. Box name is probably wrong.\n", nameStartPort.c_str());
2574         }
2575         if (boxModel != NULL) {
2576                 endP = boxModel->getInputPort(nameEndPort);
2577                 if(endP == NULL){
2578                         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());
2579                 }
2580         }
2581
2582         //ups2
2583         int idCon = createGConnector(startP);
2584
2585         _worldState = NOTHING_HAPPENS;
2586         GConnectorController *tempp = (GConnectorController*) _controllers[idCon];
2587
2588         GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2589         vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2590         tempp->endContourCreation();
2591         conMod->setEndPort(endP);
2592         conView->updateStartEndPoints();
2593         return idCon;
2594 }
2595
2596 //=========================================================================
2597
2598 bool wxVtkSceneManager::boxExist(std::string boxname) {
2599         bool ok = false;
2600         std::map<int, GObjectController*>::iterator it;
2601         for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2602                 GObjectController *cont = it->second;
2603                 if (cont->getModel()->getBBTKName() == boxname) {
2604                         ok = true;
2605                 }
2606         }
2607         return ok;
2608 }
2609
2610 //=========================================================================
2611
2612 std::vector<int> wxVtkSceneManager::getBlackBoxes() {
2613         std::vector<int> vect;
2614         std::map<int, GObjectController*>::iterator it;
2615         for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2616                 GObjectController *cont = it->second;
2617                 if (cont->getGObjectType() == GBLACKBOX) {
2618                         vect.push_back(cont->getId());
2619                 }
2620         }
2621         return vect;
2622 }
2623
2624 //=========================================================================
2625
2626 std::vector<int> wxVtkSceneManager::getComplexInputPorts() {
2627         std::vector<int> vect;
2628         std::map<int, GObjectController*>::iterator it;
2629         for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2630                 GObjectController *cont = it->second;
2631                 if (cont->getGObjectType() == GCOMPLEXINPUTPORT) {
2632                         vect.push_back(cont->getId());
2633                 }
2634         }
2635         return vect;
2636 }
2637
2638 //=========================================================================
2639
2640 std::vector<int> wxVtkSceneManager::getComplexOutputPorts() {
2641         std::vector<int> vect;
2642         std::map<int, GObjectController*>::iterator it;
2643         for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2644                 GObjectController *cont = it->second;
2645                 if (cont->getGObjectType() == GCOMPLEXOUTPUTPORT) {
2646                         vect.push_back(cont->getId());
2647                 }
2648         }
2649         return vect;
2650 }
2651
2652 //=========================================================================
2653
2654 std::vector<int> wxVtkSceneManager::getConnections() {
2655         std::vector<int> vect;
2656         std::map<int, GObjectController*>::iterator it;
2657         for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2658                 GObjectController *cont = it->second;
2659                 if (cont->getGObjectType() == GCONNECTOR) {
2660                         vect.push_back(cont->getId());
2661                 }
2662         }
2663         return vect;
2664 }
2665
2666 //=========================================================================
2667
2668 bool wxVtkSceneManager::isComplexBox() {
2669         return _isComplexBox;
2670 }
2671
2672 //=========================================================================
2673
2674 void wxVtkSceneManager::setComplexBox(bool val) {
2675         _isComplexBox = val;
2676 }
2677
2678 //=========================================================================
2679
2680 int wxVtkSceneManager::addObjectController(GObjectController* objController) {
2681         //Register the controller of the new object
2682         registerController((InteractorStyleMaracas*) objController);
2683         //Add the object to the objects list
2684         int newId = _contLastId;//_controllers.size();
2685         objController->setId(newId);
2686         _controllers[newId] = objController;
2687         //std::cout << "DFCH: int wxVtkSceneManager::addObjectController(GObjectController* objController) ---- _contLastId = " << _contLastId << std::endl;
2688         _contLastId++;
2689         return newId;
2690 }
2691
2692 //=========================================================================
2693
2694 void wxVtkSceneManager::DuplicateObjects(std::map<int, GObjectController*> objectsMap)
2695 {
2696         std::map<int, int> oldIdNewIdBoxes;
2697         std::vector<int> connections;
2698         std::vector<int> newBoxesID;
2699         std::map<int, GObjectController*>::iterator it;
2700         for (it = objectsMap.begin(); it != objectsMap.end(); ++it)
2701         {
2702             GObjectController *cont = it->second;
2703             int type = cont->getGObjectType();
2704             if (type == GBLACKBOX)
2705             {
2706                 // Copy black box
2707                 double xInic, yInic, zInic;
2708                 GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
2709                 copyBox->getInicPoint(xInic, yInic, zInic);
2710                 int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(), copyBox->getBBTKType());
2711
2712                 int idcB = copyBox->getObjectId();
2713                 oldIdNewIdBoxes[idcB] = idBox;
2714                 cont = _controllers[idBox];
2715                 GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
2716                 newbox->setInicPoint(xInic, yInic, zInic);
2717                 int num = newbox->getNumInputPorts();
2718                 for (int j = 0; j < num; j++)
2719                 {
2720                     newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
2721                 } // if  j
2722
2723 // EED 2022-01-16
2724 //                newbox->move(xInic + 20, yInic + 20, zInic);
2725                 newbox->move(xInic + 14, yInic + 6, zInic);
2726                 
2727                 newbox->notifyObservers(_idManager);
2728                 newBoxesID.push_back(newbox->getObjectId());
2729
2730             } else if (type == GCONNECTOR) {
2731                 int idCon = cont->getId();
2732                 connections.push_back(idCon);
2733             } // if type
2734
2735         } // for it
2736
2737         for (int i = 0; i < (int) connections.size(); i++)
2738         {
2739             int objId = connections[i];
2740             GObjectController *cont = objectsMap[objId];
2741             GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
2742
2743             GPortModel* startPort = connectModel->getStartPort();
2744             int startPortIndex = startPort->getPosInBox();
2745             GPortModel* endPort = connectModel->getEndPort();
2746             int endPortIndex = endPort->getPosInBox();
2747
2748             GBlackBoxModel* startPortParentBox =
2749                     (GBlackBoxModel*) startPort->getParentBox();
2750             GBlackBoxModel* endPortParentBox =
2751                     (GBlackBoxModel*) endPort->getParentBox();
2752
2753             int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2754             int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2755
2756             GBlackBoxModel* newStartBox =
2757                     (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
2758             GBlackBoxModel* newEndBox =
2759                     (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
2760
2761             GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2762             GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2763
2764             // Creates connection
2765             int idCon = createGConnector(newStartPort);
2766             GConnectorController *tempp =
2767                     (GConnectorController*) _controllers[idCon];
2768             GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2769             vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2770             tempp->endContourCreation();
2771             conMod->setEndPort(newEndPort);
2772             conView->updateStartEndPoints();
2773         } // for i
2774
2775         /// the new selected boxes are the duplicate ones
2776
2777         UnSelectBlackBoxes();
2778         for (int i = 0; i < newBoxesID.size(); i++)
2779         {
2780             _selectedObjects.push_back(newBoxesID.at(i));
2781         } // for i
2782
2783         for (int i = 0; i < (int) _selectedObjects.size(); i++)
2784         {
2785             int id = _selectedObjects[i];
2786             GObjectController* cont = _controllers[id];
2787             cont->getView()->setState(SELECTED);
2788             cont->getModel()->notifyObservers(_idManager);
2789         } // for i
2790     }
2791
2792
2793 //=========================================================================
2794
2795 int wxVtkSceneManager::getNumSelectedObjects() {
2796         return _selectedObjects.size();
2797 }
2798
2799 //=========================================================================
2800
2801 std::map<int, GObjectController*> wxVtkSceneManager::getSelectedObjects() {
2802         std::map<int, GObjectController*> mapSelected;
2803
2804         std::map<int, GObjectController*>::iterator it;
2805         for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2806                 GObjectController *cont = it->second;
2807                 if (cont->getGObjectType() == GBLACKBOX && cont->getView()->getState()
2808                                 == SELECTED) {
2809                         mapSelected[cont->getId()] = cont;
2810                 }
2811         }
2812
2813         std::map<int, GObjectController*>::iterator it2;
2814         for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2) {
2815                 GObjectController *cont = it2->second;
2816                 if (cont->getGObjectType() == GCONNECTOR) {
2817                         GConnectorModel* cmod = (GConnectorModel*) cont->getModel();
2818                         GBoxModel* endPortParentBox = cmod->getEndPort()->getParentBox();
2819                         GBoxModel* startPortParentBox =
2820                                         cmod->getStartPort()->getParentBox();
2821
2822                         std::map<int, GObjectController*>::iterator iterOBJ1 =
2823                                         mapSelected.find(startPortParentBox->getObjectId());
2824                         std::map<int, GObjectController*>::iterator iterOBJ2 =
2825                                         mapSelected.find(endPortParentBox->getObjectId());
2826
2827                         if (iterOBJ1 != mapSelected.end() && iterOBJ2 != mapSelected.end()) {
2828                                 int ID = cont->getId();
2829                                 mapSelected[ID] = cont;
2830                         }
2831                 }
2832         }
2833         return mapSelected;
2834 }
2835
2836 //=========================================================================
2837
2838 void wxVtkSceneManager::addObjects(std::map<int, GObjectController*> objectsMap) {
2839
2840         std::map<int, int> oldIdNewIdBoxes;
2841         std::vector<int> connections;
2842
2843         std::map<int, GObjectController*>::iterator it;
2844         for (it = objectsMap.begin(); it != objectsMap.end(); ++it) {
2845                 GObjectController *cont = it->second;
2846                 int type = cont->getGObjectType();
2847
2848                 if (type == GBLACKBOX) {
2849                         // Copy black box
2850                         double xInic, yInic, zInic;
2851                         GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
2852                         copyBox->getInicPoint(xInic, yInic, zInic);
2853                         int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(),copyBox->getBBTKType());
2854
2855                         int idcB = copyBox->getObjectId();
2856                         oldIdNewIdBoxes[idcB] = idBox;
2857                         cont = _controllers[idBox];
2858                         GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
2859                         newbox->setInicPoint(xInic, yInic, zInic);
2860                         int num = newbox->getNumInputPorts();
2861                         for (int j = 0; j < num; j++) 
2862                         {
2863                                 newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
2864                         }// for j
2865                         newbox->notifyObservers(_idManager);
2866                 } else if (type == GCONNECTOR) {
2867                         int idCon = cont->getId();
2868                         connections.push_back(idCon);
2869                 }
2870
2871         }
2872
2873         for (int i = 0; i < (int) connections.size(); i++) {
2874                 int objId = connections[i];
2875                 GObjectController *cont = objectsMap[objId];
2876                 GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
2877
2878                 GPortModel* startPort = connectModel->getStartPort();
2879                 int startPortIndex = startPort->getPosInBox();
2880                 GPortModel* endPort = connectModel->getEndPort();
2881                 int endPortIndex = endPort->getPosInBox();
2882
2883                 GBlackBoxModel* startPortParentBox =
2884                                 (GBlackBoxModel*) startPort->getParentBox();
2885                 GBlackBoxModel* endPortParentBox =
2886                                 (GBlackBoxModel*) endPort->getParentBox();
2887
2888                 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2889                 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2890
2891                 GBlackBoxModel* newStartBox =
2892                                 (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
2893                 GBlackBoxModel* newEndBox =
2894                                 (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
2895
2896                 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2897                 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2898
2899                 // Creates connection
2900                 int idCon = createGConnector(newStartPort);
2901                 GConnectorController *tempp =
2902                                 (GConnectorController*) _controllers[idCon];
2903                 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2904                 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2905                 tempp->endContourCreation();
2906                 conMod->setEndPort(newEndPort);
2907                 conView->updateStartEndPoints();
2908         }
2909
2910         std::map<int, int>::iterator itIds;
2911         for (itIds = oldIdNewIdBoxes.begin(); itIds != oldIdNewIdBoxes.end(); ++itIds) {
2912                 int idOld = itIds->first;
2913                 int idNew = itIds->second;
2914
2915                 GBlackBoxModel* oldBox =
2916                                 (GBlackBoxModel*) objectsMap[idOld]->getModel();
2917                 GBlackBoxModel* newBox =
2918                                 (GBlackBoxModel*) _controllers[idNew]->getModel();
2919
2920                 std::vector<int> oldInputConnections = oldBox->getConnectedInputs();
2921                 std::vector<int> oldOutputConnections = oldBox->getConnectedOutputs();
2922                 std::vector<int> newInputConnections = newBox->getConnectedInputs();
2923                 std::vector<int> newOutputConnections = newBox->getConnectedOutputs();
2924
2925                 for (int k = 0; k < (int) oldInputConnections.size(); k++) {
2926                         bool exist = false;
2927                         //EED                           int toCreate=-1;
2928                         for (int l = 0; l < (int) newInputConnections.size() && !exist; l++) {
2929                                 if (oldInputConnections[k] == newInputConnections[l]) {
2930                                         exist = true;
2931                                 }
2932                         }
2933
2934                         if (exist == false) {
2935                                 //Create complex input
2936                                 int posInBox = oldInputConnections[k];
2937                                 GPortModel* inputPort = oldBox->getInputPort(posInBox);
2938                                 std::string inputPortName = inputPort->getBBTKName();
2939                                 int idInputPort = createGComplexBoxInputPort(inputPortName);
2940                                 GObjectController *cont = _controllers[idInputPort];
2941                                 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2942                                 double xIn, yIn, zIn;
2943                                 inputPort->getInicPoint(xIn, yIn, zIn);
2944                                 yIn += 20;
2945                                 cbmod->setInicPoint(xIn, yIn, zIn);
2946                                 cbmod->notifyObservers(_idManager);
2947
2948                                 GPortModel* inputPortEnd = newBox->getInputPort(posInBox);
2949
2950                                 // Creates connection
2951                                 int idCon = createGConnector(cbmod->getOutputPort(0));
2952                                 GConnectorController *tempp =
2953                                                 (GConnectorController*) _controllers[idCon];
2954                                 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2955                                 vtkGConnectorView *conView =
2956                                                 (vtkGConnectorView*) tempp->getView();
2957                                 tempp->endContourCreation();
2958                                 conMod->setEndPort(inputPortEnd);
2959                                 conView->updateStartEndPoints();
2960
2961                         }
2962
2963                 }
2964
2965                 for (int k = 0; k < (int) oldOutputConnections.size(); k++) {
2966                         bool exist = false;
2967                         //EED                           int toCreate=-1;
2968                         for (int l = 0; l < (int) newOutputConnections.size() && !exist; l++) {
2969                                 if (oldOutputConnections[k] == newOutputConnections[l]) {
2970                                         exist = true;
2971                                 }
2972                         }
2973
2974                         if (exist == false) {
2975                                 //Create complex output
2976                                 int posInBox = oldOutputConnections[k];
2977                                 GPortModel* outputPort = oldBox->getOutputPort(posInBox);
2978                                 std::string outputPortName = outputPort->getBBTKName();
2979                                 int idOutputPort = createGComplexBoxOutputPort(outputPortName);
2980                                 GObjectController *cont = _controllers[idOutputPort];
2981                                 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2982                                 double xIn, yIn, zIn;
2983                                 outputPort->getInicPoint(xIn, yIn, zIn);
2984                                 yIn -= 20;
2985                                 cbmod->setInicPoint(xIn, yIn, zIn);
2986                                 cbmod->notifyObservers(_idManager);
2987
2988                                 GPortModel* outputPortEnd = newBox->getOutputPort(posInBox);
2989
2990                                 // Creates connection
2991                                 int idCon = createGConnector(outputPortEnd);
2992                                 GConnectorController *tempp =
2993                                                 (GConnectorController*) _controllers[idCon];
2994                                 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2995                                 vtkGConnectorView *conView =
2996                                                 (vtkGConnectorView*) tempp->getView();
2997                                 tempp->endContourCreation();
2998                                 conMod->setEndPort(cbmod->getInputPort(0));
2999                                 conView->updateStartEndPoints();
3000
3001                         }
3002
3003                 }
3004
3005         }
3006
3007 }
3008
3009 //=========================================================================
3010 void wxVtkSceneManager::SetCbName(std::string cbName) {
3011         _cbName = cbName;
3012         if (_cbName == "") {
3013                 _cbName = "<complex box name>";
3014         }
3015 }
3016
3017 //=========================================================================
3018 std::string wxVtkSceneManager::GetCbName() {
3019         return _cbName;
3020 }
3021
3022 //=========================================================================
3023 void wxVtkSceneManager::SetCbPackageName(std::string packagename) {
3024         _cbPackageName = packagename;
3025         if (_cbPackageName == "") {
3026                 _cbPackageName = "<package name of the complex box>";
3027         }
3028 }
3029
3030 //=========================================================================
3031 std::string wxVtkSceneManager::GetCbPackageName() 
3032 {
3033         return _cbPackageName;
3034 }
3035
3036 //=========================================================================
3037 void wxVtkSceneManager::SetAuthor(std::string author) 
3038 {
3039     _Author = author;
3040     if (_Author == "") 
3041     {
3042         _Author = "<author of the box>";
3043     }
3044 }
3045
3046 //=========================================================================
3047 std::string wxVtkSceneManager::GetAuthor() 
3048 {
3049     return _Author;
3050 }
3051
3052 //=========================================================================
3053 void wxVtkSceneManager::SetExportFormat(int exportformat) 
3054 {
3055     _ExportFormat = exportformat;
3056 }
3057
3058 //=========================================================================
3059 int wxVtkSceneManager::GetExportFormat()
3060 {
3061     return _ExportFormat;
3062 }
3063
3064 //=========================================================================
3065 void wxVtkSceneManager::SetCategory(std::string category) 
3066 {
3067         _Category = category;
3068         if (_Category == "") 
3069     {
3070                 _Category = "<category of the box>";
3071         }
3072 }
3073
3074 //=========================================================================
3075 std::string wxVtkSceneManager::GetCategory() 
3076 {
3077         return _Category;
3078 }
3079
3080 //=========================================================================
3081 void wxVtkSceneManager::SetDescription(std::string description) {
3082         _Description = description;
3083         if (_Description == "") {
3084                 _Description = "<description of the box>";
3085         }
3086 }
3087
3088 //=========================================================================
3089 std::string wxVtkSceneManager::GetDescription() {
3090         return _Description;
3091 }
3092
3093 //=========================================================================
3094
3095 void wxVtkSceneManager::SetMessageKind(std::string kind) {
3096                 _MessageKind = kind;
3097         
3098 }
3099                                 
3100 //=========================================================================
3101
3102 std::string wxVtkSceneManager::GetMessageKind(){
3103                 return _MessageKind;
3104 }
3105
3106 //=========================================================================
3107
3108 void wxVtkSceneManager::SetMessageLevel(std::string Level){
3109                 _MessageLevel = Level;
3110 }
3111
3112 //=========================================================================
3113
3114 std::string wxVtkSceneManager::GetMessageLevel(){
3115                 return _MessageLevel;
3116 }
3117
3118 //=========================================================================
3119
3120 std::vector< std::string> wxVtkSceneManager::GetExternalInputsNames()
3121 {
3122
3123         std::vector< std::string> extInputs;
3124         std::map<int, GObjectController*>::iterator it;
3125         for (it = _controllers.begin(); it != _controllers.end(); ++it)
3126         {
3127                 GObjectController *cont = it->second;
3128                 if (cont->getGObjectType() == GCOMPLEXINPUTPORT)
3129                 {
3130                         extInputs.push_back(cont->getModel()->getBBTKName());
3131                 }
3132         }
3133         return extInputs;
3134 }
3135
3136 //=========================================================================
3137 void wxVtkSceneManager::printAll(int com , int sta )
3138 {
3139          int tmpState = sta ;
3140         if ( tmpState == NOTHING_HAPPENS ) {
3141             std::cout << "CONTROLER STATE---->NOTHING_HAPPENS\n" ;
3142         }
3143         if ( tmpState == HIGHLIGHTED ) {
3144             std::cout << "CONTROLER STATE---->HIGHLIGHTED\n" ;
3145         }
3146         if ( tmpState == POSSIBLE_CONNECTION ) {
3147             std::cout << "CONTROLER STATE---->POSSIBLE_CONNECTION\n" ;
3148         }
3149         if ( tmpState == SELECTED_POSSIBLE_CONNECTION ) {
3150             std::cout << "CONTROLER STATE---->SELECTED_POSSIBLE_CONNECTION\n" ;
3151         }
3152         if ( tmpState == CLICKED ) {
3153             std::cout << "CONTROLER STATE---->CLICKED\n" ;
3154         }
3155         if ( tmpState == DRAG ) {
3156             std::cout << "CONTROLER STATE---->DRAG\n" ;
3157         }
3158         if ( tmpState == SELECTED ) {
3159             std::cout << "CONTROLER STATE---->SELECTED\n" ;
3160         }
3161         if ( tmpState == CREATING_CONTOUR ) {
3162             std::cout << "CONTROLER STATE---->CREATING_CONTOUR\n" ;
3163         }   
3164          
3165          // :P 
3166
3167         int command = com ;
3168         if ( command == INIT_CREATION_CONTOUR ) {
3169             std::cout << "COMMAND ----> INIT_CREATION_CONTOUR \n" ;
3170         }
3171         if ( command == FIN_CREATION_CONTOUR ) {
3172             std::cout << "COMMAND ----> FIN_CREATION_CONTOUR \n" ;
3173         }
3174         if ( command == ADD_TO_SELECTED ) {
3175             std::cout << "COMMAND ----> ADD_TO_SELECTED \n" ;
3176         }
3177         if ( command == DRAG_OBJECTS ) {
3178             std::cout << "COMMAND ----> DRAG_OBJECTS \n" ;
3179         }
3180         if ( command == EDIT_BLACKBOX ) {
3181             std::cout << "COMMAND ----> EDIT_BLACKBOX \n" ;
3182         }
3183         if ( command == REMOVE_FROM_SELECTED ) {
3184             std::cout << "COMMAND ----> REMOVE_FROM_SELECTED \n" ;
3185         }
3186         
3187     }
3188
3189 //=========================================================================
3190 //EED 2022-10-28
3191 void wxVtkSceneManager::SelectBoxWithPossibleName( std::string possibleName )
3192
3193     UnSelectBlackBoxes();
3194     std::map<int, GObjectController*>::iterator it;
3195     GObjectController                           *desc;
3196     int                                         type;
3197     int                                         id;
3198     int                                         pos;
3199     std::string possibleNameAA = possibleName;
3200     std::string boxNameBB;
3201     int i,size;
3202     size = possibleNameAA.length();
3203     for (i=0;i<size;i++)
3204     {
3205         if ((possibleNameAA[i]>='A')&&(possibleNameAA[i]<='Z')) { possibleNameAA[i]=possibleNameAA[i]+32; }
3206     } //for  i
3207     for (it = _controllers.begin(); it != _controllers.end(); ++it)
3208     {
3209         desc    = it->second;
3210         type    = desc->getGObjectType();
3211         if ( type==GBLACKBOX)
3212         {
3213             boxNameBB = desc->getModel()->getBBTKType() +":"+ desc->getModel()->getBBTKName();
3214             size=boxNameBB.length();
3215             for (i=0;i<size;i++)
3216             {
3217                 if ((boxNameBB[i]>='A')&&(boxNameBB[i]<='Z')) { boxNameBB[i]=boxNameBB[i]+32; }
3218             } // for  i
3219
3220             pos=boxNameBB.find( possibleNameAA );
3221             if  (pos>=0)
3222             {
3223                 desc->getView()->setState(SELECTED);
3224                 id = desc->getModel()->getObjectId();
3225                 desc->getModel()->notifyObservers( id , ADD_TO_SELECTED );
3226             } // if pos
3227         } // if type == 1
3228     } // for it
3229     refresh();  
3230 }
3231
3232 } // EO namespace bbtk
3233
3234 // EOF
3235