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