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