]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxVtkSceneManager.cxx
efb1439428e855a87277153dd4c4bef69c5aedbd
[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::vector<std::string> packages;
1605         std::vector<int> boxes;
1606         std::vector<int> connections;
1607         std::vector<int> execBoxes;
1608
1609         std::map<int, GObjectController*>::iterator it;
1610
1611         for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1612                 GObjectController *desc = it->second;
1613                 int type = desc->getGObjectType();
1614
1615                 if (type == GBLACKBOX) {
1616                         GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
1617
1618                         std::string pkg = mod->getBBTKPackage();
1619                         bool existsPkg = false;
1620                         for (int t = 0; t < (int) packages.size() && existsPkg == false; t++) {
1621                                 if (packages[t] == pkg) {
1622                                         existsPkg = true;
1623                                 }
1624                         }
1625                         if (!existsPkg) {
1626                                 packages.push_back(pkg);
1627                         }
1628
1629                         boxes.push_back(it->first);
1630                         if (mod->isExecutable()) {
1631                                 execBoxes.push_back(it->first);
1632                         }
1633                 } else if (type == GCONNECTOR) {
1634                         connections.push_back(it->first);
1635                 }
1636         }
1637
1638         std::string script = "";
1639
1640         script += "include std\n"; // EED
1641         script += "include itkvtk\n"; // EED
1642         int i;
1643         for (i = 0; i < (int) packages.size(); i++) {
1644                 script += "include ";
1645                 script += packages[i];
1646                 script += "\n";
1647         }
1648         script += "\n";
1649
1650         // Definition of a complex box
1651         script += "define ";
1652         script += _cbName + " " + _cbPackageName;
1653         script += "\n";
1654         script += "\n";
1655
1656         script += "author \"";
1657         script += _Author;
1658         script += "\"\n";
1659
1660         script += "description \"";
1661         script += _Description;
1662         script += "\"\n";
1663         script += "\n";
1664
1665         script += "category \"";
1666         script += _Category;
1667         script += "\"\n";
1668         script += "\n";
1669
1670         // Create boxes
1671         for (i = 0; i < (int) boxes.size(); i++) {
1672                 script += "new ";
1673                 int id = boxes[i];
1674                 GObjectController *control = _controllers[id];
1675                 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1676
1677                 script += model->getBBTKPackage()+":";
1678                 script += model->getBBTKType();
1679                 script += " ";
1680                 script += model->getBBTKName();
1681                 script += "\n";
1682
1683                 std::vector<GPortModel*> inputs = model->getInputPorts();
1684                 for (int j = 0; j < (int) inputs.size(); j++) {
1685                         GPortModel* inputPort = inputs[j];
1686                         if (inputPort->isValueSet()) {
1687                                 script += "  set ";
1688                                 script += model->getBBTKName();
1689                                 script += ".";
1690                                 script += inputPort->getBBTKName();
1691                                 script += " ";
1692                                 script += inputPort->getValue();
1693                                 script += "\n";
1694                         }
1695                 }
1696                 script += "\n";
1697
1698         }
1699
1700         // Create connections in the script. If the connection is made with a complex port, it is created the input or output
1701
1702         std::string complexInputs = "";
1703         std::string complexOutputs = "";
1704         script += "\n";
1705
1706         for (i = 0; i < (int) connections.size(); i++) {
1707                 int id = connections[i];
1708                 GObjectController *control = _controllers[id];
1709                 GConnectorModel *model = (GConnectorModel*) control->getModel();
1710
1711                 //Connection info
1712                 GPortModel *start = model->getStartPort();
1713                 GBoxModel *startBox = start->getParentBox();
1714
1715                 GPortModel *end = model->getEndPort();
1716                 GBoxModel *endBox = end->getParentBox();
1717
1718                 if (startBox->getGObjectType() == GCOMPLEXINPUTPORT) {
1719                         complexInputs += "input ";
1720                         complexInputs += startBox->getBBTKName();
1721
1722                         complexInputs += " ";
1723                         complexInputs += endBox->getBBTKName();
1724                         complexInputs += ".";
1725                         complexInputs += end->getBBTKName();
1726
1727                         complexInputs += " ";
1728                         complexInputs += "\" \"";
1729
1730                         complexInputs += "\n";
1731                 } else if (endBox->getGObjectType() == GCOMPLEXOUTPUTPORT) {
1732                         complexOutputs += "output ";
1733                         complexOutputs += endBox->getBBTKName();
1734
1735                         complexOutputs += " ";
1736                         complexOutputs += startBox->getBBTKName();
1737                         complexOutputs += ".";
1738                         complexOutputs += start->getBBTKName();
1739
1740                         complexOutputs += " ";
1741                         complexOutputs += "\" \"";
1742
1743                         complexOutputs += "\n";
1744                 } else {
1745                         script += "connect ";
1746                         script += startBox->getBBTKName();
1747                         script += ".";
1748                         script += start->getBBTKName();
1749
1750                         script += " ";
1751
1752                         //End Connection info
1753                         script += endBox->getBBTKName();
1754                         script += ".";
1755                         script += end->getBBTKName();
1756
1757                         script += "\n";
1758                 }
1759         }
1760
1761         script += "\n";
1762         script += "# Complex input ports\n";
1763         script += complexInputs;
1764
1765         script += "\n";
1766         script += "# Complex output ports\n";
1767         script += complexOutputs;
1768
1769         script += "\n";
1770
1771         if((_MessageKind!="-")&&(_MessageLevel!="-"))
1772         {
1773                 script += "message ";
1774                 script += _MessageKind;
1775                 script += " ";
1776                 script += _MessageLevel;
1777                 script += "\n";
1778         }
1779
1780         for (i = 0; i < (int) execBoxes.size(); i++) 
1781         {
1782                 script += "exec ";
1783                 int id = execBoxes[i];
1784                 GObjectController *control = _controllers[id];
1785                 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1786
1787                 script += model->getBBTKName();
1788                 script += "\n";
1789         }
1790
1791         script += "\n";
1792         script += "endefine";
1793         script += "\n";
1794
1795         return script;
1796 }
1797
1798 //=========================================================================
1799
1800 void wxVtkSceneManager::deleteAllBoxes() {
1801         std::map<int, GObjectController*>::iterator it;
1802         for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1803                 GObjectController *cont = it->second;
1804                 cont->removeFromScene();
1805                 unregisterController((InteractorStyleMaracas*) cont);
1806         }
1807         _selectedObjects.clear();
1808         _controllers.clear();
1809 }
1810
1811 //=========================================================================
1812
1813
1814 void wxVtkSceneManager::refresh() {
1815         _baseView->Refresh();
1816 }
1817 //=========================================================================
1818
1819 void wxVtkSceneManager::refreshScene() 
1820 {
1821         _baseView->RefreshView();
1822 }
1823
1824 //=========================================================================
1825
1826 void wxVtkSceneManager::centerView() 
1827 {
1828         double bb[6];
1829         _baseView->GetRenderer()->ComputeVisiblePropBounds(bb);
1830
1831         double temp[3];
1832         _baseView->GetRenderer()->GetActiveCamera()->GetFocalPoint(temp);
1833         _baseView->GetRenderer()->GetActiveCamera()->SetFocalPoint(0, 0, temp[2]);
1834         _baseView->GetRenderer()->GetActiveCamera()->GetPosition(temp);
1835         _baseView->GetRenderer()->GetActiveCamera()->SetPosition(0, 0, temp[2]);
1836
1837         _baseView->GetRenderer()->ResetCamera();
1838         _baseView->GetRenderer()->ResetCameraClippingRange();
1839
1840 /*
1841         double tt=_baseView->GetRenderer()->GetNearClippingPlaneTolerance();
1842         printf("EED wxVtkSceneManager::centerView() tolerance=%f\n",tt);
1843         double cr1,cr2;
1844         _baseView->GetRenderer()->GetActiveCamera()->GetClippingRange(cr1,cr2);
1845         printf("EED wxVtkSceneManager::centerView() cr1=%f  cr2=%f\n",cr1,cr2);
1846         _baseView->GetRenderer()->GetActiveCamera()->SetClippingRange(0.01,100000);
1847         _baseView->GetRenderer()->GetActiveCamera()->GetClippingRange(cr1,cr2);
1848         printf("EED wxVtkSceneManager::centerView() cr1=%f  cr2=%f\n",cr1,cr2);
1849 */
1850
1851         _baseView->GetRenderer()->Render();
1852 }
1853
1854 //=========================================================================
1855
1856 void wxVtkSceneManager::saveDiagram(std::string &content) 
1857 {
1858         char buffer[50];
1859
1860         content += "CATEGORY:";
1861         content += GetCategory();
1862         content += "\n";
1863
1864         content += "DESCRIPTION:";
1865         content += GetDescription();
1866         content += "\n";
1867
1868         content += "AUTHOR:";
1869         content += GetAuthor();
1870         content += "\n";
1871
1872         //Print info IF COMPLEX BOX
1873         content += "COMPLEXBOX:";
1874         if (_isComplexBox) {
1875                 content += "TRUE\n";
1876                 //ups1
1877                 content += "COMPLEXBOXNAME:";
1878                 content += GetCbName();
1879                 content += "\n";
1880
1881                 content += "PACKAGENAME:";
1882                 content += GetCbPackageName();
1883                 content += "\n";
1884
1885         /* CHANGE TO THE VERSION 1.4 RaC2012 2nd HackFest
1886          * External inputs are possible for applications and complex boxes
1887         //Print info complex input ports
1888         std::vector<int> inputs = getComplexInputPorts();
1889         int insize = inputs.size();
1890         content += "COMPLEXINPUTS:";
1891         sprintf(buffer, "%d", insize);
1892         content += buffer;
1893         content += "\n";
1894
1895         for (int i = 0; i < insize; i++) {
1896             int id = inputs[i];
1897             GObjectController *cont = _controllers[id];
1898             cont->getModel()->save(content);
1899         }
1900         */
1901
1902         //Print info complex output ports
1903         std::vector<int> outputs = getComplexOutputPorts();
1904         int outsize = outputs.size();
1905         content += "COMPLEXOUTPUTS:";
1906         sprintf(buffer, "%d", outsize);
1907         content += buffer;
1908         content += "\n";
1909
1910         for (int i = 0; i < outsize; i++) {
1911             int id = outputs[i];
1912             GObjectController *cont = _controllers[id];
1913             cont->getModel()->save(content);
1914         }
1915
1916
1917
1918         } // _isComplexBox
1919         else {
1920                 content += "FALSE\n";
1921         }
1922
1923     
1924         // CHANGE TO THE VERSION 1.4 RaC2012 2nd HackFest
1925         // External inputs are possible for applications and complex boxes
1926         std::vector<int> inputs = getComplexInputPorts();
1927         int insize = inputs.size();
1928         content += "COMPLEXINPUTS:";
1929         sprintf(buffer, "%d", insize);
1930         content += buffer;
1931         content += "\n";
1932
1933         for (int i = 0; i < insize; i++) {
1934                 int id = inputs[i];
1935                 GObjectController *cont = _controllers[id];
1936                 cont->getModel()->save(content);
1937         }
1938
1939         //Print boxes
1940         std::vector<int> boxes = getBlackBoxes();
1941         int bsize = boxes.size();
1942         content += "BOXES:";
1943         sprintf(buffer, "%d", bsize);
1944         content += buffer;
1945         content += "\n";
1946         
1947         for (int i = 0; i < bsize; i++) {
1948                 int id = boxes[i];
1949 //              std::cout<<"id "<<id<<std::endl;//CFT
1950                 GObjectController *cont = _controllers[id];
1951 //              std::cout<<"nombre: "<<cont->getStatusText()<<std::endl;//CFT
1952 //              std::cout<<"tipo: "<<cont->getModel()->getBBTKType()<<std::endl;//CFT
1953 //              //boxesDiagram[i] = cont->getModel()->getBBTKType();//CFT
1954 //              std::cout<<"nname: "<<cont->getModel()->getBBTKName()<<std::endl;//CFT
1955 //              std::cout<<"categorie: "<<GetCategory()<<std::endl;//CFT
1956 //              std::cout<<"type: "<<cont->getModel()->getGObjectType()<<std::endl;//CFT
1957                 cont->getModel()->save(content);
1958         }
1959
1960         //Print connections
1961         std::vector<int> connections = getConnections();
1962         int csize = connections.size();
1963         content += "CONNECTIONS:";
1964         sprintf(buffer, "%d", csize);
1965         content += buffer;
1966         content += "\n";
1967
1968         for (int i = 0; i < csize; i++) {
1969                 int id = connections[i];
1970                 GObjectController *cont = _controllers[id];
1971                 cont->getModel()->save(content);
1972         }
1973
1974 }
1975
1976 //=========================================================================
1977 void wxVtkSceneManager::getCleanLine(stringstream &inputStream, std::string &line)
1978 {
1979         getline(inputStream, line,'\n');
1980         int size = line.length();
1981     if (size>0)
1982         {
1983                 if ( line[ size-1 ]==13  )
1984                 {
1985                         line.erase(size-1,1);
1986                 } // if line
1987         } // if size
1988 }
1989         
1990 //=========================================================================
1991 void wxVtkSceneManager::loadDiagram(stringstream &inputStream) 
1992 {
1993         int size;
1994         std::string version = "<void>";
1995         std::string line = "";
1996         char delims[] = ":";
1997         char *result = NULL;
1998         char poort[POORT_MAX_LINE_SIZE_INTERPRETER];
1999
2000         getCleanLine(inputStream, line);
2001
2002         bool start = false;
2003         while (!inputStream.eof()) {
2004                 if (line == "" || line[0] == '#') {
2005                         line="";
2006                         getCleanLine(inputStream, line);
2007                         
2008                         if (line == "# - BBTKGEditor v 1.0 BBG BlackBox Diagram file") {
2009                                 version = line.substr(18, 3);
2010                         }
2011                         if (line == "# - BBTKGEditor v 1.1 BBG BlackBox Diagram file") {
2012                                 version = line.substr(18, 3);
2013                         }
2014                         if (line == "# - BBTKGEditor v 1.2 BBG BlackBox Diagram file") {
2015                                 version = line.substr(18, 3);
2016                         }
2017                         if (line == "# - BBTKGEditor v 1.3 BBG BlackBox Diagram file") {
2018                                 version = line.substr(18, 3);
2019                         }
2020                         if (line == "# - BBTKGEditor v 1.4 BBG BlackBox Diagram file") {
2021                                 version = line.substr(18, 3);
2022                         }
2023             if (line == "# - BBTKGEditor v 1.5 BBG BlackBox Diagram file") {
2024                 version = line.substr(18, 3);
2025             }
2026                 } else if (line == "APP_START") {
2027                         start = true;
2028                         break;
2029                 }
2030         }
2031
2032
2033         if (start)
2034     {
2035
2036                 if ((version != "1.0") && (version != "1.1")) {
2037                         getCleanLine(inputStream, line);//CATEGORY:<category of the box>
2038                         char categoryTmp[30];
2039                         strcpy(categoryTmp, line.c_str());
2040                         result = strtok(categoryTmp, delims);
2041                         result = strtok(NULL, delims);
2042                         SetCategory(result);
2043
2044                         getCleanLine(inputStream, line);//DESCRIPTION:<description of the box>
2045                         char descriptionTmp[1024];
2046                         strcpy(descriptionTmp, line.c_str());
2047                         result = strtok(descriptionTmp, delims);
2048                         result = strtok(NULL, delims);
2049                         SetDescription(result);
2050
2051                         getCleanLine(inputStream, line);//AUTHOR:<author>
2052                         char authorTmp[255];
2053                         strcpy(authorTmp, line.c_str());
2054                         result = strtok(authorTmp, delims);
2055                         result = strtok(NULL, delims);
2056                         SetAuthor(result);
2057                 }
2058
2059                 //----------
2060                 getCleanLine(inputStream, line);//COMPLEX_BOX:TRUE|FALSE
2061                 char complexTmp[30];
2062                 strcpy(complexTmp, line.c_str());
2063                 result = strtok(complexTmp, delims);
2064                 result = strtok(NULL, delims);
2065                 std::string isComplexBox(result);
2066
2067                 if (isComplexBox == "TRUE")
2068         {
2069                         _isComplexBox = true;
2070
2071                         if ((version != "1.0") && (version != "1.1"))
2072             {
2073                                 getCleanLine(inputStream, line);//COMPLEXNAME:<name of the complex box>
2074                                 char complexboxnameTmp[255];
2075                                 strcpy(complexboxnameTmp, line.c_str());
2076                                 result = strtok(complexboxnameTmp, delims);
2077                                 result = strtok(NULL, delims);
2078                                 SetCbName(result);
2079
2080                                 getCleanLine(inputStream, line);//PACKAGENAME:<name of the package of the box>
2081                                 char packagenameTmp[255];
2082                                 strcpy(packagenameTmp, line.c_str());
2083                                 result = strtok(packagenameTmp, delims);
2084                                 result = strtok(NULL, delims);
2085                                 SetCbPackageName(result);
2086                         } // if version !1.0  !1.1
2087
2088                         if(version < "1.4")
2089                         {
2090                                 //-----------------------
2091                                 //- COMPLEX INPUT PORTS
2092                                 //-----------------------
2093                                 getCleanLine(inputStream, line);//COMPLEXINPUTS:num
2094                                 char inputs[30];
2095                                 strcpy(inputs, line.c_str());
2096                                 result = strtok(inputs, delims);
2097                                 result = strtok(NULL, delims);
2098
2099                                 int numInputs;
2100                                 std::istringstream inps(result);
2101                                 inps >> numInputs;
2102
2103                                 for (int i = 0; i < numInputs; i++)
2104                 {
2105                                         //----------
2106                                         getCleanLine(inputStream, line);//COMPLEX_PORT
2107                                         getCleanLine(inputStream, line);//name
2108                                         std::string inputPortName(line);
2109
2110                                         //----------
2111                                         getCleanLine(inputStream, line);//xInic:yInic:zInic
2112                                         char coord[80];
2113                                         strcpy(coord, line.c_str());
2114                                         result = strtok(coord, delims);//xInic
2115                                         std::string xInic(result);
2116                                         result = strtok(NULL, delims);//yInic
2117                                         std::string yInic(result);
2118                                         result = strtok(NULL, delims);//zInic
2119                                         std::string zInic(result);
2120
2121                                         double xIn, yIn, zIn;
2122                                         std::istringstream xSt(xInic);
2123                                         xSt >> xIn;
2124                                         std::istringstream ySt(yInic);
2125                                         ySt >> yIn;
2126                                         std::istringstream zSt(zInic);
2127                                         zSt >> zIn;
2128
2129                                         if (version<="1.2")
2130                                         {
2131                                                 if (zIn==900) zIn=GPOSITION_Z;
2132                                         } // if version <=1.2
2133
2134                                         getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
2135
2136                                         configGComBoxInputOutputPort(true, inputPortName, xIn, yIn, zIn);
2137
2138                                 } // for input complex box
2139                         } // if version < 1.4
2140
2141
2142
2143                         //-----------------------
2144                         //- COMPLEX OUTPUT PORTS
2145                         //-----------------------
2146
2147                         getCleanLine(inputStream, line);//COMPLEXOUTPUTS:num
2148                         char outputs[30];
2149                         strcpy(outputs, line.c_str());
2150                         result = strtok(outputs, delims);
2151                         result = strtok(NULL, delims);
2152
2153                         int numOutputs;
2154                         std::istringstream outps(result);
2155                         outps >> numOutputs;
2156
2157                         for (int i = 0; i < numOutputs; i++)
2158             {
2159                                 //----------
2160                                 getCleanLine(inputStream, line);//COMPLEX_PORT
2161                                 getCleanLine(inputStream, line);//name
2162                                 std::string outputPortName(line);
2163
2164                                 //----------
2165                                 getCleanLine(inputStream, line);//xInic:yInic:zInic
2166                                 char coord[80];
2167                                 strcpy(coord, line.c_str());
2168                                 result = strtok(coord, delims);//xInic
2169                                 std::string xInic(result);
2170                                 result = strtok(NULL, delims);//yInic
2171                                 std::string yInic(result);
2172                                 result = strtok(NULL, delims);//zInic
2173                                 std::string zInic(result);
2174
2175                                 double xIn, yIn, zIn;
2176                                 std::istringstream xSt(xInic);
2177                                 xSt >> xIn;
2178                                 std::istringstream ySt(yInic);
2179                                 ySt >> yIn;
2180                                 std::istringstream zSt(zInic);
2181                                 zSt >> zIn;
2182
2183                                 if (version<="1.2")
2184                                 {
2185                                         if (zIn==900) zIn=GPOSITION_Z;
2186                                 }
2187 //EED 2022-01-16
2188                 if (version<="1.4")
2189                 {
2190                     xIn = xIn*0.70;
2191                     yIn = yIn*0.30;
2192                 }
2193
2194                                 getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
2195
2196                                 configGComBoxInputOutputPort(false, outputPortName, xIn, yIn, zIn);
2197
2198                         } // for output complex box
2199                 } // if isComplexBox
2200
2201         
2202                 // RaC2012 2nd Hackfest
2203                 if(version >= "1.4")
2204                 {
2205                         //-----------------------
2206                         //- EXTERNAL INPUT PORTS
2207                         //-----------------------
2208                         getCleanLine(inputStream, line);//COMPLEXINPUTS:num
2209                         char inputs[30];
2210                         strcpy(inputs, line.c_str());
2211                         result = strtok(inputs, delims);
2212                         result = strtok(NULL, delims);
2213
2214                         int numInputs;
2215                         std::istringstream inps(result);
2216                         inps >> numInputs;
2217
2218                         for (int i = 0; i < numInputs; i++)
2219             {
2220                                 getCleanLine(inputStream, line);//COMPLEX_PORT
2221                                 getCleanLine(inputStream, line);//name
2222                                 std::string inputPortName(line);
2223                                 getCleanLine(inputStream, line);//xInic:yInic:zInic
2224                                 char coord[80];
2225                                 strcpy(coord, line.c_str());
2226                                 result = strtok(coord, delims);//xInic
2227                                 std::string xInic(result);
2228                                 result = strtok(NULL, delims);//yInic
2229                                 std::string yInic(result);
2230                                 result = strtok(NULL, delims);//zInic
2231                                 std::string zInic(result);
2232                                 double xIn, yIn, zIn;
2233                                 std::istringstream xSt(xInic);
2234                                 xSt >> xIn;
2235                                 std::istringstream ySt(yInic);
2236                                 ySt >> yIn;
2237                                 std::istringstream zSt(zInic);
2238                                 zSt >> zIn;
2239                                 if (version<="1.2")
2240                                 {
2241                                         if (zIn==900) zIn=GPOSITION_Z;
2242                                 }
2243 //EED 2022-01-16
2244                 if (version<="1.4")
2245                 {
2246                     xIn = xIn*0.70;
2247                     yIn = yIn*0.30;
2248                 }
2249                                 getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
2250                                 configGComBoxInputOutputPort(true, inputPortName, xIn, yIn, zIn);
2251                         } // for external input
2252                 }   //      if(version >= "1.4")
2253
2254                 //----------
2255                 getCleanLine(inputStream, line);//BOXES:num
2256                 char boxes[9];
2257                 strcpy(boxes, line.c_str());
2258                 result = strtok(boxes, delims);
2259                 result = strtok(NULL, delims);
2260
2261                 int numBoxes;
2262                 std::istringstream is(result);
2263                 is >> numBoxes;
2264
2265                 for (int i = 0; i < numBoxes; i++) 
2266                 {
2267                         //----------
2268                         getCleanLine(inputStream, line);//BOX
2269                         getCleanLine(inputStream, line);//package:type:name
2270                         char box[150];
2271                         strcpy(box, line.c_str());
2272                         result = strtok(box, delims);//package
2273                         std::string package(result);
2274                         result = strtok(NULL, delims);//type
2275                         std::string type(result);
2276                         result = strtok(NULL, delims);//name
2277                         std::string name(result);
2278
2279
2280                         getCleanLine(inputStream, line);//ISEXEC:TRUE|FALSE
2281                         char exec[15];
2282                         strcpy(exec, line.c_str());
2283                         result = strtok(exec, delims);//ISEXEC
2284                         result = strtok(NULL, delims);//TRUE|FALSE
2285                         std::string isExec(result);
2286
2287                         //----------
2288                         getCleanLine(inputStream, line);//xInic:yInic:zInic
2289                         char coord[80];
2290                         strcpy(coord, line.c_str());
2291                         result = strtok(coord, delims);//xInic
2292                         std::string xInic(result);
2293                         result = strtok(NULL, delims);//yInic
2294                         std::string yInic(result);
2295                         result = strtok(NULL, delims);//zInic
2296                         std::string zInic(result);
2297                         double xIn, yIn, zIn;
2298                         std::istringstream xSt(xInic);
2299                         xSt >> xIn;
2300                         std::istringstream ySt(yInic);
2301                         ySt >> yIn;
2302                         std::istringstream zSt(zInic);
2303                         zSt >> zIn;
2304
2305                         if (version<="1.2")
2306                         {
2307                                 if (zIn==900) zIn=GPOSITION_Z;
2308                         }
2309 //EED 2022-01-16
2310             if (version<="1.4")
2311             {
2312                 xIn = xIn*0.70;
2313                 yIn = yIn*0.30;
2314             }
2315                         //----------
2316                         getCleanLine(inputStream, line);//xEnd:yEnd:zEnd
2317                         strcpy(coord, line.c_str());
2318                         result = strtok(coord, delims);//xEnd
2319                         std::string xEnd(result);
2320                         result = strtok(NULL, delims);//yEnd
2321                         std::string yEnd(result);
2322                         result = strtok(NULL, delims);//zEnd
2323                         std::string zEnd(result);
2324
2325                         double xEn, yEn, zEn;
2326                         std::istringstream xEt(xEnd);
2327                         xEt >> xEn;
2328                         std::istringstream yEt(yEnd);
2329                         yEt >> yEn;
2330                         std::istringstream zEt(zEnd);
2331                         zEt >> zEn;
2332
2333                         if (version<="1.2")
2334                         {
2335                                 if (zEn==900) zEn=GPOSITION_Z;
2336                         }
2337 //EED 2022-01-16
2338             yEn = yIn-BOX_HEIGHT;
2339                         
2340                         bool boxExecutable = false;
2341                         if (isExec == "TRUE") 
2342                         {
2343                                 boxExecutable = true;
2344                         }
2345
2346                         int idBox = createGBlackBox(xIn, yIn, package, type);
2347                         configGBlackBox(idBox, xIn, yIn, zIn, name, boxExecutable, xEn, yEn, zEn);
2348
2349                         GObjectController *cont = _controllers[idBox];
2350                         GBlackBoxModel *bbmod = (GBlackBoxModel*) cont->getModel();
2351
2352                         //----------
2353                         getCleanLine(inputStream, line);//PORT o FIN_BOX
2354                         std::string port = line.substr(0, 4);
2355                         while (port == "PORT") 
2356                         {
2357                                 getCleanLine(inputStream, line);//name:value
2358                                 if (line.length()>=POORT_MAX_LINE_SIZE_INTERPRETER-1)
2359                                 {
2360                                         line=line.substr(0, POORT_MAX_LINE_SIZE_INTERPRETER-1);
2361                                 }
2362                                 
2363                                 strcpy(poort, line.c_str());
2364                                 result = strtok(poort, delims);//name
2365                                 std::string name(result);
2366                                 
2367                                 //EED 16 oct 2012 Adding at the end character " if necesary in the value definition
2368                                 result = strtok(NULL, delims);//value
2369                                 if (( result[0]=='"' ) && ( result[ strlen(result)-1 ]!='"' )  )
2370                                 {
2371                                         std::string tmpString=" ";
2372                                         tmpString[0]=34;         // character "
2373                                         strcat(result,tmpString.c_str());
2374                                 }
2375                                 std::string value(result);
2376                                 bbmod->setValueToInput(name, value);
2377                                 getCleanLine(inputStream, line);//PORT o FIN_BOX
2378                                 port = line.substr(0, 4);
2379                         } // while
2380
2381                         //EED                           bbmod->notifyObservers(_idManager);
2382                 } // for boxes
2383
2384                 /// CONNECTIONS
2385                 //----------
2386                 getCleanLine(inputStream, line);//CONNECTIONS:num
2387                 char conns[30];
2388                 strcpy(conns, line.c_str());
2389                 result = strtok(conns, delims);
2390                 result = strtok(NULL, delims);
2391                 int numConns;
2392                 std::istringstream isCons(result);
2393                 isCons >> numConns;
2394                 
2395                 
2396                 for (int i = 0; i < numConns; i++) 
2397                 {
2398                         //----------
2399                         getCleanLine(inputStream, line);//CONNECTION
2400                         getCleanLine(inputStream, line);//Startbox.PortName:EndBox.PortName
2401                         char connec[200];
2402                         strcpy(connec, line.c_str());
2403                         result = strtok(connec, delims);
2404                         std::string nameStartBox(result);
2405                         result = strtok(NULL, delims);
2406                         std::string nameStartPort(result);
2407                         result = strtok(NULL, delims);
2408                         std::string nameEndBox(result);
2409                         result = strtok(NULL, delims);
2410                         std::string nameEndPort(result);
2411                         int idCon = configGConnetion(nameStartBox, nameStartPort,nameEndBox, nameEndPort);
2412                         if (version != "1.0") {
2413                                 //Readding control points of the manualContour
2414                                 GConnectorController    *tempp          = (GConnectorController*) _controllers[idCon];
2415                                 GConnectorModel         *conMod         = (GConnectorModel*) tempp->getModel();
2416                                 vtkGConnectorView       *conView        = (vtkGConnectorView*) tempp->getView();
2417                                 getCleanLine(inputStream, line); //NumberOfControlPoints:##
2418                                 strcpy(conns, line.c_str());
2419                                 result = strtok(conns, delims);
2420                                 result = strtok(NULL, delims);
2421                                 int numberOfControlPoints;
2422                                 std::istringstream isCons(result);
2423                                 isCons >> numberOfControlPoints;
2424                                 for (int ii = 0; ii < numberOfControlPoints; ii++) {
2425                                         getCleanLine(inputStream, line); //XX:YY:ZZ
2426                                         char connec[200];
2427                                         strcpy(connec, line.c_str());
2428                                         double px, py, pz;
2429                                         result = strtok(connec, delims);
2430                                         std::istringstream isPointX(result);
2431                                         isPointX >> px;
2432                                         result = strtok(NULL, delims);
2433                                         std::istringstream isPointY(result);
2434                                         isPointY >> py;
2435                                         result = strtok(NULL, delims);
2436                                         std::istringstream isPointZ(result);
2437                                         isPointZ >> pz;
2438                                         if (version<="1.2")
2439                                         {
2440                                                 if (pz==900) pz=GPOSITION_Z;
2441                                         }
2442 //EED 2022-01-16
2443                     if (version<="1.4")
2444                     {
2445                         px = px*0.70;
2446                         py = py*0.30;
2447                     }
2448                                         conMod->getManualContourModel()->InsertPoint_id(ii + 1, px, py, pz);
2449                                         conView->getManualContourView()->AddPoint();
2450                                 }
2451                         }// if version !=1.0
2452                 } // for numConns
2453         } // if start
2454 }
2455 //=========================================================================
2456
2457
2458 //=========================================================================
2459 void wxVtkSceneManager::configGComBoxInputOutputPort(bool inputoutput,
2460                 std::string portName, double xIn, double yIn, double zIn) 
2461 {
2462         int idPort;
2463         if (inputoutput == true) {
2464                 idPort = createGComplexBoxInputPort(portName);
2465         } else {
2466                 idPort = createGComplexBoxOutputPort(portName);
2467         }
2468         GObjectController *cont = _controllers[idPort];
2469         GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2470         cbmod->setInicPoint(xIn, yIn, zIn);
2471         cbmod->notifyObservers(_idManager);
2472 }
2473 //=========================================================================
2474
2475
2476 //=========================================================================
2477 GBoxModel* wxVtkSceneManager::findGBox(std::string boxname) 
2478 {
2479         int j;
2480         int idB;
2481         GBoxModel *bMod;
2482         GBoxModel *boxModel = NULL;
2483         std::vector<int> lstB = getBlackBoxes();
2484         for (j = 0; j < (int) lstB.size(); j++) {
2485                 idB = lstB[j];
2486                 bMod = (GBoxModel*) _controllers[idB]->getModel();
2487                 if (_controllers[idB]->getModel()->getBBTKName() == boxname) 
2488                 {
2489                         boxModel = bMod;
2490                 }
2491         } // for
2492
2493
2494
2495         if (boxModel == NULL) {
2496                 std::vector<int> lstInputs = getComplexInputPorts();
2497                 for (j = 0; j < (int) lstInputs.size(); j++) {
2498                         idB = lstInputs[j];
2499                         bMod = (GBoxModel*) _controllers[idB]->getModel();
2500                         if (_controllers[idB]->getModel()->getBBTKName() == boxname) 
2501                         {
2502                                 boxModel = bMod;
2503                         }
2504                 } // for
2505
2506                 if(_isComplexBox)
2507                 {
2508                 std::vector<int> lstOutputs = getComplexOutputPorts();
2509                 for (j = 0; j < (int) lstOutputs.size(); j++) {
2510                         int idB = lstOutputs[j];
2511                         bMod = (GBoxModel*) _controllers[idB]->getModel();
2512                         if (_controllers[idB]->getModel()->getBBTKName() == boxname) 
2513                         {
2514                                 boxModel = bMod;
2515                         }
2516                 } // for
2517                 }
2518
2519         } // inputs/outputs
2520
2521         return boxModel;
2522 }
2523
2524 //=========================================================================
2525
2526
2527 int wxVtkSceneManager::configGConnetion(std::string nameStartBox,
2528                 std::string nameStartPort, std::string nameEndBox,
2529                 std::string nameEndPort) {
2530
2531         GBoxModel *boxModel;
2532         GPortModel *startP = NULL;
2533         GPortModel *endP = NULL;
2534
2535         boxModel = findGBox(nameStartBox);
2536         if(boxModel == NULL)
2537         {
2538                 printf("RaC: ERROR in wxVtkSceneManager::configGConnetion A box to connect start port %s is null. Box name is probably wrong.\n", nameStartPort.c_str());
2539         }
2540         if (boxModel != NULL) {
2541                 startP = boxModel->getOutputPort(nameStartPort);
2542                 if(startP == NULL){
2543                         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() );
2544                 }
2545         }
2546
2547         boxModel = findGBox(nameEndBox);
2548         if(boxModel == NULL)
2549         {
2550                  printf("RaC: ERROR in wxVtkSceneManager::configGConnetion A box to connect start port %s is null. Box name is probably wrong.\n", nameStartPort.c_str());
2551         }
2552         if (boxModel != NULL) {
2553                 endP = boxModel->getInputPort(nameEndPort);
2554                 if(endP == NULL){
2555                         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());
2556                 }
2557         }
2558
2559         //ups2
2560         int idCon = createGConnector(startP);
2561
2562         _worldState = NOTHING_HAPPENS;
2563         GConnectorController *tempp = (GConnectorController*) _controllers[idCon];
2564
2565         GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2566         vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2567         tempp->endContourCreation();
2568         conMod->setEndPort(endP);
2569         conView->updateStartEndPoints();
2570         return idCon;
2571 }
2572
2573 //=========================================================================
2574
2575 bool wxVtkSceneManager::boxExist(std::string boxname) {
2576         bool ok = false;
2577         std::map<int, GObjectController*>::iterator it;
2578         for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2579                 GObjectController *cont = it->second;
2580                 if (cont->getModel()->getBBTKName() == boxname) {
2581                         ok = true;
2582                 }
2583         }
2584         return ok;
2585 }
2586
2587 //=========================================================================
2588
2589 std::vector<int> wxVtkSceneManager::getBlackBoxes() {
2590         std::vector<int> vect;
2591         std::map<int, GObjectController*>::iterator it;
2592         for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2593                 GObjectController *cont = it->second;
2594                 if (cont->getGObjectType() == GBLACKBOX) {
2595                         vect.push_back(cont->getId());
2596                 }
2597         }
2598         return vect;
2599 }
2600
2601 //=========================================================================
2602
2603 std::vector<int> wxVtkSceneManager::getComplexInputPorts() {
2604         std::vector<int> vect;
2605         std::map<int, GObjectController*>::iterator it;
2606         for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2607                 GObjectController *cont = it->second;
2608                 if (cont->getGObjectType() == GCOMPLEXINPUTPORT) {
2609                         vect.push_back(cont->getId());
2610                 }
2611         }
2612         return vect;
2613 }
2614
2615 //=========================================================================
2616
2617 std::vector<int> wxVtkSceneManager::getComplexOutputPorts() {
2618         std::vector<int> vect;
2619         std::map<int, GObjectController*>::iterator it;
2620         for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2621                 GObjectController *cont = it->second;
2622                 if (cont->getGObjectType() == GCOMPLEXOUTPUTPORT) {
2623                         vect.push_back(cont->getId());
2624                 }
2625         }
2626         return vect;
2627 }
2628
2629 //=========================================================================
2630
2631 std::vector<int> wxVtkSceneManager::getConnections() {
2632         std::vector<int> vect;
2633         std::map<int, GObjectController*>::iterator it;
2634         for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2635                 GObjectController *cont = it->second;
2636                 if (cont->getGObjectType() == GCONNECTOR) {
2637                         vect.push_back(cont->getId());
2638                 }
2639         }
2640         return vect;
2641 }
2642
2643 //=========================================================================
2644
2645 bool wxVtkSceneManager::isComplexBox() {
2646         return _isComplexBox;
2647 }
2648
2649 //=========================================================================
2650
2651 void wxVtkSceneManager::setComplexBox(bool val) {
2652         _isComplexBox = val;
2653 }
2654
2655 //=========================================================================
2656
2657 int wxVtkSceneManager::addObjectController(GObjectController* objController) {
2658         //Register the controller of the new object
2659         registerController((InteractorStyleMaracas*) objController);
2660         //Add the object to the objects list
2661         int newId = _contLastId;//_controllers.size();
2662         objController->setId(newId);
2663         _controllers[newId] = objController;
2664         //std::cout << "DFCH: int wxVtkSceneManager::addObjectController(GObjectController* objController) ---- _contLastId = " << _contLastId << std::endl;
2665         _contLastId++;
2666         return newId;
2667 }
2668
2669 //=========================================================================
2670
2671 void wxVtkSceneManager::DuplicateObjects(std::map<int, GObjectController*> objectsMap)
2672 {
2673         std::map<int, int> oldIdNewIdBoxes;
2674         std::vector<int> connections;
2675         std::vector<int> newBoxesID;
2676         std::map<int, GObjectController*>::iterator it;
2677         for (it = objectsMap.begin(); it != objectsMap.end(); ++it)
2678         {
2679             GObjectController *cont = it->second;
2680             int type = cont->getGObjectType();
2681             if (type == GBLACKBOX)
2682             {
2683                 // Copy black box
2684                 double xInic, yInic, zInic;
2685                 GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
2686                 copyBox->getInicPoint(xInic, yInic, zInic);
2687                 int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(), copyBox->getBBTKType());
2688
2689                 int idcB = copyBox->getObjectId();
2690                 oldIdNewIdBoxes[idcB] = idBox;
2691                 cont = _controllers[idBox];
2692                 GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
2693                 newbox->setInicPoint(xInic, yInic, zInic);
2694                 int num = newbox->getNumInputPorts();
2695                 for (int j = 0; j < num; j++)
2696                 {
2697                     newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
2698                 } // if  j
2699
2700 // EED 2022-01-16
2701 //                newbox->move(xInic + 20, yInic + 20, zInic);
2702                 newbox->move(xInic + 14, yInic + 6, zInic);
2703                 
2704                 newbox->notifyObservers(_idManager);
2705                 newBoxesID.push_back(newbox->getObjectId());
2706
2707             } else if (type == GCONNECTOR) {
2708                 int idCon = cont->getId();
2709                 connections.push_back(idCon);
2710             } // if type
2711
2712         } // for it
2713
2714         for (int i = 0; i < (int) connections.size(); i++)
2715         {
2716             int objId = connections[i];
2717             GObjectController *cont = objectsMap[objId];
2718             GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
2719
2720             GPortModel* startPort = connectModel->getStartPort();
2721             int startPortIndex = startPort->getPosInBox();
2722             GPortModel* endPort = connectModel->getEndPort();
2723             int endPortIndex = endPort->getPosInBox();
2724
2725             GBlackBoxModel* startPortParentBox =
2726                     (GBlackBoxModel*) startPort->getParentBox();
2727             GBlackBoxModel* endPortParentBox =
2728                     (GBlackBoxModel*) endPort->getParentBox();
2729
2730             int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2731             int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2732
2733             GBlackBoxModel* newStartBox =
2734                     (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
2735             GBlackBoxModel* newEndBox =
2736                     (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
2737
2738             GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2739             GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2740
2741             // Creates connection
2742             int idCon = createGConnector(newStartPort);
2743             GConnectorController *tempp =
2744                     (GConnectorController*) _controllers[idCon];
2745             GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2746             vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2747             tempp->endContourCreation();
2748             conMod->setEndPort(newEndPort);
2749             conView->updateStartEndPoints();
2750         } // for i
2751
2752         /// the new selected boxes are the duplicate ones
2753
2754         UnSelectBlackBoxes();
2755         for (int i = 0; i < newBoxesID.size(); i++)
2756         {
2757             _selectedObjects.push_back(newBoxesID.at(i));
2758         } // for i
2759
2760         for (int i = 0; i < (int) _selectedObjects.size(); i++)
2761         {
2762             int id = _selectedObjects[i];
2763             GObjectController* cont = _controllers[id];
2764             cont->getView()->setState(SELECTED);
2765             cont->getModel()->notifyObservers(_idManager);
2766         } // for i
2767     }
2768
2769
2770 //=========================================================================
2771
2772 int wxVtkSceneManager::getNumSelectedObjects() {
2773         return _selectedObjects.size();
2774 }
2775
2776 //=========================================================================
2777
2778 std::map<int, GObjectController*> wxVtkSceneManager::getSelectedObjects() {
2779         std::map<int, GObjectController*> mapSelected;
2780
2781         std::map<int, GObjectController*>::iterator it;
2782         for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2783                 GObjectController *cont = it->second;
2784                 if (cont->getGObjectType() == GBLACKBOX && cont->getView()->getState()
2785                                 == SELECTED) {
2786                         mapSelected[cont->getId()] = cont;
2787                 }
2788         }
2789
2790         std::map<int, GObjectController*>::iterator it2;
2791         for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2) {
2792                 GObjectController *cont = it2->second;
2793                 if (cont->getGObjectType() == GCONNECTOR) {
2794                         GConnectorModel* cmod = (GConnectorModel*) cont->getModel();
2795                         GBoxModel* endPortParentBox = cmod->getEndPort()->getParentBox();
2796                         GBoxModel* startPortParentBox =
2797                                         cmod->getStartPort()->getParentBox();
2798
2799                         std::map<int, GObjectController*>::iterator iterOBJ1 =
2800                                         mapSelected.find(startPortParentBox->getObjectId());
2801                         std::map<int, GObjectController*>::iterator iterOBJ2 =
2802                                         mapSelected.find(endPortParentBox->getObjectId());
2803
2804                         if (iterOBJ1 != mapSelected.end() && iterOBJ2 != mapSelected.end()) {
2805                                 int ID = cont->getId();
2806                                 mapSelected[ID] = cont;
2807                         }
2808                 }
2809         }
2810         return mapSelected;
2811 }
2812
2813 //=========================================================================
2814
2815 void wxVtkSceneManager::addObjects(std::map<int, GObjectController*> objectsMap) {
2816
2817         std::map<int, int> oldIdNewIdBoxes;
2818         std::vector<int> connections;
2819
2820         std::map<int, GObjectController*>::iterator it;
2821         for (it = objectsMap.begin(); it != objectsMap.end(); ++it) {
2822                 GObjectController *cont = it->second;
2823                 int type = cont->getGObjectType();
2824
2825                 if (type == GBLACKBOX) {
2826                         // Copy black box
2827                         double xInic, yInic, zInic;
2828                         GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
2829                         copyBox->getInicPoint(xInic, yInic, zInic);
2830                         int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(),copyBox->getBBTKType());
2831
2832                         int idcB = copyBox->getObjectId();
2833                         oldIdNewIdBoxes[idcB] = idBox;
2834                         cont = _controllers[idBox];
2835                         GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
2836                         newbox->setInicPoint(xInic, yInic, zInic);
2837                         int num = newbox->getNumInputPorts();
2838                         for (int j = 0; j < num; j++) 
2839                         {
2840                                 newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
2841                         }// for j
2842                         newbox->notifyObservers(_idManager);
2843                 } else if (type == GCONNECTOR) {
2844                         int idCon = cont->getId();
2845                         connections.push_back(idCon);
2846                 }
2847
2848         }
2849
2850         for (int i = 0; i < (int) connections.size(); i++) {
2851                 int objId = connections[i];
2852                 GObjectController *cont = objectsMap[objId];
2853                 GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
2854
2855                 GPortModel* startPort = connectModel->getStartPort();
2856                 int startPortIndex = startPort->getPosInBox();
2857                 GPortModel* endPort = connectModel->getEndPort();
2858                 int endPortIndex = endPort->getPosInBox();
2859
2860                 GBlackBoxModel* startPortParentBox =
2861                                 (GBlackBoxModel*) startPort->getParentBox();
2862                 GBlackBoxModel* endPortParentBox =
2863                                 (GBlackBoxModel*) endPort->getParentBox();
2864
2865                 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2866                 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2867
2868                 GBlackBoxModel* newStartBox =
2869                                 (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
2870                 GBlackBoxModel* newEndBox =
2871                                 (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
2872
2873                 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2874                 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2875
2876                 // Creates connection
2877                 int idCon = createGConnector(newStartPort);
2878                 GConnectorController *tempp =
2879                                 (GConnectorController*) _controllers[idCon];
2880                 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2881                 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2882                 tempp->endContourCreation();
2883                 conMod->setEndPort(newEndPort);
2884                 conView->updateStartEndPoints();
2885         }
2886
2887         std::map<int, int>::iterator itIds;
2888         for (itIds = oldIdNewIdBoxes.begin(); itIds != oldIdNewIdBoxes.end(); ++itIds) {
2889                 int idOld = itIds->first;
2890                 int idNew = itIds->second;
2891
2892                 GBlackBoxModel* oldBox =
2893                                 (GBlackBoxModel*) objectsMap[idOld]->getModel();
2894                 GBlackBoxModel* newBox =
2895                                 (GBlackBoxModel*) _controllers[idNew]->getModel();
2896
2897                 std::vector<int> oldInputConnections = oldBox->getConnectedInputs();
2898                 std::vector<int> oldOutputConnections = oldBox->getConnectedOutputs();
2899                 std::vector<int> newInputConnections = newBox->getConnectedInputs();
2900                 std::vector<int> newOutputConnections = newBox->getConnectedOutputs();
2901
2902                 for (int k = 0; k < (int) oldInputConnections.size(); k++) {
2903                         bool exist = false;
2904                         //EED                           int toCreate=-1;
2905                         for (int l = 0; l < (int) newInputConnections.size() && !exist; l++) {
2906                                 if (oldInputConnections[k] == newInputConnections[l]) {
2907                                         exist = true;
2908                                 }
2909                         }
2910
2911                         if (exist == false) {
2912                                 //Create complex input
2913                                 int posInBox = oldInputConnections[k];
2914                                 GPortModel* inputPort = oldBox->getInputPort(posInBox);
2915                                 std::string inputPortName = inputPort->getBBTKName();
2916                                 int idInputPort = createGComplexBoxInputPort(inputPortName);
2917                                 GObjectController *cont = _controllers[idInputPort];
2918                                 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2919                                 double xIn, yIn, zIn;
2920                                 inputPort->getInicPoint(xIn, yIn, zIn);
2921                                 yIn += 20;
2922                                 cbmod->setInicPoint(xIn, yIn, zIn);
2923                                 cbmod->notifyObservers(_idManager);
2924
2925                                 GPortModel* inputPortEnd = newBox->getInputPort(posInBox);
2926
2927                                 // Creates connection
2928                                 int idCon = createGConnector(cbmod->getOutputPort(0));
2929                                 GConnectorController *tempp =
2930                                                 (GConnectorController*) _controllers[idCon];
2931                                 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2932                                 vtkGConnectorView *conView =
2933                                                 (vtkGConnectorView*) tempp->getView();
2934                                 tempp->endContourCreation();
2935                                 conMod->setEndPort(inputPortEnd);
2936                                 conView->updateStartEndPoints();
2937
2938                         }
2939
2940                 }
2941
2942                 for (int k = 0; k < (int) oldOutputConnections.size(); k++) {
2943                         bool exist = false;
2944                         //EED                           int toCreate=-1;
2945                         for (int l = 0; l < (int) newOutputConnections.size() && !exist; l++) {
2946                                 if (oldOutputConnections[k] == newOutputConnections[l]) {
2947                                         exist = true;
2948                                 }
2949                         }
2950
2951                         if (exist == false) {
2952                                 //Create complex output
2953                                 int posInBox = oldOutputConnections[k];
2954                                 GPortModel* outputPort = oldBox->getOutputPort(posInBox);
2955                                 std::string outputPortName = outputPort->getBBTKName();
2956                                 int idOutputPort = createGComplexBoxOutputPort(outputPortName);
2957                                 GObjectController *cont = _controllers[idOutputPort];
2958                                 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2959                                 double xIn, yIn, zIn;
2960                                 outputPort->getInicPoint(xIn, yIn, zIn);
2961                                 yIn -= 20;
2962                                 cbmod->setInicPoint(xIn, yIn, zIn);
2963                                 cbmod->notifyObservers(_idManager);
2964
2965                                 GPortModel* outputPortEnd = newBox->getOutputPort(posInBox);
2966
2967                                 // Creates connection
2968                                 int idCon = createGConnector(outputPortEnd);
2969                                 GConnectorController *tempp =
2970                                                 (GConnectorController*) _controllers[idCon];
2971                                 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2972                                 vtkGConnectorView *conView =
2973                                                 (vtkGConnectorView*) tempp->getView();
2974                                 tempp->endContourCreation();
2975                                 conMod->setEndPort(cbmod->getInputPort(0));
2976                                 conView->updateStartEndPoints();
2977
2978                         }
2979
2980                 }
2981
2982         }
2983
2984 }
2985
2986 //=========================================================================
2987 void wxVtkSceneManager::SetCbName(std::string cbName) {
2988         _cbName = cbName;
2989         if (_cbName == "") {
2990                 _cbName = "<complex box name>";
2991         }
2992 }
2993
2994 //=========================================================================
2995 std::string wxVtkSceneManager::GetCbName() {
2996         return _cbName;
2997 }
2998
2999 //=========================================================================
3000 void wxVtkSceneManager::SetCbPackageName(std::string packagename) {
3001         _cbPackageName = packagename;
3002         if (_cbPackageName == "") {
3003                 _cbPackageName = "<package name of the complex box>";
3004         }
3005 }
3006
3007 //=========================================================================
3008 std::string wxVtkSceneManager::GetCbPackageName() {
3009         return _cbPackageName;
3010 }
3011
3012 //=========================================================================
3013 void wxVtkSceneManager::SetAuthor(std::string author) {
3014         _Author = author;
3015         if (_Author == "") {
3016                 _Author = "<author of the box>";
3017         }
3018 }
3019
3020 //=========================================================================
3021 std::string wxVtkSceneManager::GetAuthor() {
3022         return _Author;
3023 }
3024
3025 //=========================================================================
3026 void wxVtkSceneManager::SetCategory(std::string category) {
3027         _Category = category;
3028         if (_Category == "") {
3029                 _Category = "<category of the box>";
3030         }
3031 }
3032
3033 //=========================================================================
3034 std::string wxVtkSceneManager::GetCategory() {
3035         return _Category;
3036 }
3037
3038 //=========================================================================
3039 void wxVtkSceneManager::SetDescription(std::string description) {
3040         _Description = description;
3041         if (_Description == "") {
3042                 _Description = "<description of the box>";
3043         }
3044 }
3045
3046 //=========================================================================
3047 std::string wxVtkSceneManager::GetDescription() {
3048         return _Description;
3049 }
3050
3051 //=========================================================================
3052
3053 void wxVtkSceneManager::SetMessageKind(std::string kind) {
3054                 _MessageKind = kind;
3055         
3056 }
3057                                 
3058 //=========================================================================
3059
3060 std::string wxVtkSceneManager::GetMessageKind(){
3061                 return _MessageKind;
3062 }
3063
3064 //=========================================================================
3065
3066 void wxVtkSceneManager::SetMessageLevel(std::string Level){
3067                 _MessageLevel = Level;
3068 }
3069
3070 //=========================================================================
3071
3072 std::string wxVtkSceneManager::GetMessageLevel(){
3073                 return _MessageLevel;
3074 }
3075
3076 //=========================================================================
3077
3078 std::vector< std::string> wxVtkSceneManager::GetExternalInputsNames()
3079 {
3080
3081         std::vector< std::string> extInputs;
3082         std::map<int, GObjectController*>::iterator it;
3083         for (it = _controllers.begin(); it != _controllers.end(); ++it)
3084         {
3085                 GObjectController *cont = it->second;
3086                 if (cont->getGObjectType() == GCOMPLEXINPUTPORT)
3087                 {
3088                         extInputs.push_back(cont->getModel()->getBBTKName());
3089                 }
3090         }
3091         return extInputs;
3092 }
3093
3094 //=========================================================================
3095 void wxVtkSceneManager::printAll(int com , int sta )
3096 {
3097          int tmpState = sta ;
3098         if ( tmpState == NOTHING_HAPPENS ) {
3099             std::cout << "CONTROLER STATE---->NOTHING_HAPPENS\n" ;
3100         }
3101         if ( tmpState == HIGHLIGHTED ) {
3102             std::cout << "CONTROLER STATE---->HIGHLIGHTED\n" ;
3103         }
3104         if ( tmpState == POSSIBLE_CONNECTION ) {
3105             std::cout << "CONTROLER STATE---->POSSIBLE_CONNECTION\n" ;
3106         }
3107         if ( tmpState == SELECTED_POSSIBLE_CONNECTION ) {
3108             std::cout << "CONTROLER STATE---->SELECTED_POSSIBLE_CONNECTION\n" ;
3109         }
3110         if ( tmpState == CLICKED ) {
3111             std::cout << "CONTROLER STATE---->CLICKED\n" ;
3112         }
3113         if ( tmpState == DRAG ) {
3114             std::cout << "CONTROLER STATE---->DRAG\n" ;
3115         }
3116         if ( tmpState == SELECTED ) {
3117             std::cout << "CONTROLER STATE---->SELECTED\n" ;
3118         }
3119         if ( tmpState == CREATING_CONTOUR ) {
3120             std::cout << "CONTROLER STATE---->CREATING_CONTOUR\n" ;
3121         }   
3122          
3123          // :P 
3124
3125         int command = com ;
3126         if ( command == INIT_CREATION_CONTOUR ) {
3127             std::cout << "COMMAND ----> INIT_CREATION_CONTOUR \n" ;
3128         }
3129         if ( command == FIN_CREATION_CONTOUR ) {
3130             std::cout << "COMMAND ----> FIN_CREATION_CONTOUR \n" ;
3131         }
3132         if ( command == ADD_TO_SELECTED ) {
3133             std::cout << "COMMAND ----> ADD_TO_SELECTED \n" ;
3134         }
3135         if ( command == DRAG_OBJECTS ) {
3136             std::cout << "COMMAND ----> DRAG_OBJECTS \n" ;
3137         }
3138         if ( command == EDIT_BLACKBOX ) {
3139             std::cout << "COMMAND ----> EDIT_BLACKBOX \n" ;
3140         }
3141         if ( command == REMOVE_FROM_SELECTED ) {
3142             std::cout << "COMMAND ----> REMOVE_FROM_SELECTED \n" ;
3143         }
3144         
3145     }
3146
3147 //=========================================================================
3148 //EED 2022-10-28
3149 void wxVtkSceneManager::SelectBoxWithPossibleName( std::string possibleName )
3150
3151     UnSelectBlackBoxes();
3152     std::map<int, GObjectController*>::iterator it;
3153     GObjectController                           *desc;
3154     int                                         type;
3155     int                                         id;
3156     int                                         pos;
3157     std::string possibleNameAA = possibleName;
3158     std::string boxNameBB;
3159     int i,size;
3160     size = possibleNameAA.length();
3161     for (i=0;i<size;i++)
3162     {
3163         if ((possibleNameAA[i]>='A')&&(possibleNameAA[i]<='Z')) { possibleNameAA[i]=possibleNameAA[i]+32; }
3164     } //for  i
3165     for (it = _controllers.begin(); it != _controllers.end(); ++it)
3166     {
3167         desc    = it->second;
3168         type    = desc->getGObjectType();
3169         if ( type==GBLACKBOX)
3170         {
3171             boxNameBB = desc->getModel()->getBBTKType() +":"+ desc->getModel()->getBBTKName();
3172             size=boxNameBB.length();
3173             for (i=0;i<size;i++)
3174             {
3175                 if ((boxNameBB[i]>='A')&&(boxNameBB[i]<='Z')) { boxNameBB[i]=boxNameBB[i]+32; }
3176             } // for  i
3177
3178             pos=boxNameBB.find( possibleNameAA );
3179             if  (pos>=0)
3180             {
3181                 desc->getView()->setState(SELECTED);
3182                 id = desc->getModel()->getObjectId();
3183                 desc->getModel()->notifyObservers( id , ADD_TO_SELECTED );
3184             } // if pos
3185         } // if type == 1
3186     } // for it
3187     refresh();  
3188 }
3189
3190 } // EO namespace bbtk
3191
3192 // EOF
3193