]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxVtkSceneManager.cxx
Reduce Refresh Calls to Boost Speed
[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() START\n", this);
91         disconnectDrop();
92         delete _baseView;
93         printf("EED %p ~wxVtkSceneManager() END\n", this);
94 }
95
96 //=========================================================================
97
98 void wxVtkSceneManager::configureBaseView() {
99         printf("EED wxVtkSceneManager::configureBaseView 0\n");
100         vtkInteractorStyleBaseView2D *interactorstylebaseview =
101                         vtkInteractorStyleBaseView2D::New();
102
103         _baseView->SetInteractorStyleBaseView(interactorstylebaseview);
104
105         // Important to activate the 2D interaction system
106         wxVTKRenderWindowInteractor *iren =
107                         _baseView->GetWxVTKRenderWindowInteractor();
108         interactorstylebaseview->SetInteractor(iren);
109         iren->SetInteractorStyle(interactorstylebaseview);
110         interactorstylebaseview->SetwxVtkBaseView(_baseView);
111
112         _baseView->GetRenderer()->GetActiveCamera()->ParallelProjectionOn();
113         _baseView->GetRenderer()->ResetCamera(-100, 100, -100, 100, 800, 1100);
114
115         _baseView->GetRenderer()->SetBackground(0.9, 0.9, 0.9);
116         _baseView->GetRenderer()->GradientBackgroundOn();
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( 3 ) ;
540         manContourView->SetShowText(false);
541
542         manContourControl->SetModelView(manContourModel, manContourView);
543
544         manContourControl->CreateNewManualContour();
545
546
547         double x, y, z;
548         connectorModel->getInicPoint(x, y, z);
549
550         manContourControl->SetState(1);
551         manContourModel->SetCloseContour(false);
552
553         manContourModel->AddPoint(x, y, z);
554         manContourView->AddPoint();
555
556         manContourModel->AddPoint(x, y, z);
557         manContourView->AddPoint();
558
559         int bak = manContourControl->GetNumberOfPointsManualContour() - 1;
560         manContourControl->_bakIdPoint = bak;
561         
562         manContourControl->SetMoving(false);
563
564         connectorcontroller->setModelAndView(connectorModel, connectorView);
565
566         int newId = addObjectController(connectorcontroller);
567
568         connectorcontroller->setManualContourController(manContourControl);
569         connectorModel->setManualContourModel(manContourModel);
570         connectorView->setManualContourView(manContourView);
571         connectorView->setModel(connectorModel);
572         connectorView->setBaseView(_baseView);
573
574         connectorModel->addObserver(connectorView);
575         connectorModel->addObserver(this);
576
577         manContourView->Refresh();
578         return newId;
579 }
580
581 //=========================================================================
582
583 void wxVtkSceneManager::registerController(InteractorStyleMaracas *param) {
584         vtkInteractorStyleBaseView
585                         * baseViewControlManager =
586                                         (vtkInteractorStyleBaseView*) _baseView->GetInteractorStyleBaseView();
587         baseViewControlManager->AddInteractorStyleMaracas(param);
588 }
589
590 //=========================================================================
591
592 void wxVtkSceneManager::unregisterController(InteractorStyleMaracas *param) {
593         vtkInteractorStyleBaseView
594                         * baseViewControlManager =
595                                         (vtkInteractorStyleBaseView*) _baseView->GetInteractorStyleBaseView();
596         baseViewControlManager->RemoveInteractorStyleMaracas(param);
597 }
598
599 //=========================================================================
600
601 vtkRenderer* wxVtkSceneManager::getRenderer() {
602         return _baseView->GetRenderer();
603 }
604
605 //=========================================================================
606
607 vtkRenderWindow* wxVtkSceneManager::getRenderWindow() {
608         return _baseView->GetRenWin();
609 }
610 //=========================================================================
611
612
613 //=========================================================================
614 int wxVtkSceneManager::GetIndexInSelected(int idControler) {
615         int index = -1;
616         for (int i = 0; i < (int) _selectedObjects.size(); i++) {
617                 if (_selectedObjects[i] == idControler) {
618                         index = i;
619                         break;
620                 }
621         }
622         return index;
623 }
624 //=========================================================================
625
626 void wxVtkSceneManager::update(int idController, int command) {
627
628         if (command != NO_COMMAND) {
629                 if (command == ADD_TO_SELECTED) {
630                         //EEDBorrame                            GObjectController* cont = _controllers[idController];
631
632                         if (GetIndexInSelected(idController) == -1) {
633                                 _selectedObjects.push_back(idController);
634                         }
635
636                         //EEDBorrame
637                         //                              bool foundID=false;
638                         //                              for (int i=0; i<(int)_selectedObjects.size() && foundID==false; i++)
639                         //                              {
640                         //                                      if(_selectedObjects[i]==idController)
641                         //                                      {
642                         //                                              foundID = true;
643                         //                                      }
644                         //                              }
645                         //                              if(!foundID)
646                         //                              {
647                         //                                      _selectedObjects.push_back(idController);
648                         //                              }
649
650                 } else if (command == REMOVE_FROM_SELECTED) {
651                         int index = GetIndexInSelected(idController);
652                         if (index >= 0) {
653                                 _selectedObjects.erase(_selectedObjects.begin() + index);
654                         }
655                 } else if (command == INIT_CREATION_CONTOUR) {
656
657                 // JGRR & CM WH
658                 typedef std::map<int , GObjectController*>::iterator TIterator ;
659                 TIterator iter ;
660                 TIterator iter_end ;
661                 // Find current item in the controller
662                 iter = _controllers.find( idController ) ;
663                 iter_end = _controllers.end( ) ;
664                 // If item exist 
665                 if ( iter != iter_end ) {
666                     GObjectController* gobjc = iter->second ;
667
668                     std::string bbtkType = gobjc->getModel( )->getBBTKType( ) ;
669                     // And if the item is a port
670                     if ( gobjc->getModel( )->getGObjectType( ) == GPORT ) {
671                         TIterator c_it = _controllers.begin( ) ;
672                         // Go through all componets 
673                         for ( c_it ; c_it != iter_end ; c_it++ ) {
674                             GObjectController* obc = c_it->second ;
675                             int obc_type = obc->getModel( )->getGObjectType( ) ;
676                             std::string obc_bbtkType = obc->getModel( )->getBBTKType( ) ;
677                             // if the component is a port and the type is the same of that selected
678                             if ( ( obc_type == GPORT ) && ( obc_bbtkType == bbtkType ) ) {
679                                 // Highliht element 
680                                 obc->getView( )->setState( POSSIBLE_CONNECTION ) ;                             
681                                 //obc->getView( )->setState( HIGHLIGHTED ) ;
682                             }
683                         }
684                     }
685                 }
686
687                 // EO JGRR & CM WH  
688                      
689                         _worldState = INIT_CREATION_CONTOUR;
690                         GObjectController* cont = _controllers[idController];
691                         GPortModel* startOutputPort = (GPortModel*) cont->getModel();
692
693                         // The last one is the controller of the connector
694                         std::map<int, GObjectController*>::iterator it2;
695
696                         for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2) {
697                                 GObjectController *cont = it2->second;
698                                 if (cont->getGObjectType() == GPORT) {
699                                         GPortModel* port = (GPortModel*) cont->getModel();
700                                         if (port->getPortType() == GINPUTPORT) {
701                                                 cont->SetActive(true);
702                                         } else {
703                                                 cont->getView()->setState(NOTHING_HAPPENS);
704                                                 cont->getModel()->notifyObservers(_idManager);
705                                                 cont->SetActive(false);
706                                         }
707                                 } else {
708                                         cont->getView()->setState(NOTHING_HAPPENS);
709                                         cont->getModel()->notifyObservers(_idManager);
710                                         cont->SetActive(false);
711                                 }
712                         }
713                         _selectedObjects.clear();
714                         _idConnectionInCreation = createGConnector(startOutputPort);
715                 } else if (command == FIN_CREATION_CONTOUR && _worldState
716                                 == INIT_CREATION_CONTOUR) {
717                         _worldState = NOTHING_HAPPENS;
718                         //int id = _controllers.size()-1;
719                         GObjectController *cont = _controllers[_idConnectionInCreation];
720                         GConnectorModel *modelContour = (GConnectorModel*) cont->getModel();
721                         GObjectController *finPort = _controllers[idController];
722
723                         if (finPort->getGObjectType() == GPORT) {
724                                 GPortModel* modelPort = (GPortModel*) finPort->getModel();
725                                 modelContour->setEndPort(modelPort);
726
727                                 // JGRR CM                     
728                                 typedef std::map<int, GObjectController*>::iterator TIterator;
729                                 TIterator c_it = _controllers.begin();
730                                 TIterator iter_end = _controllers.end();
731                                 // Go through all componets 
732                                 for (c_it; c_it != iter_end; c_it++) {
733                                     GObjectController* obc = c_it->second;
734                                     int obc_type = obc->getModel()->getGObjectType();
735                                     int obc_state = obc->getView()->getState();
736                                     // if the component is a port and the type is the same of that selected
737                                     if ((obc_type == GPORT) && (obc_state == POSSIBLE_CONNECTION)) {
738                                         // Return element to neutral state if not selected
739                                         obc->getView()->setState(NOTHING_HAPPENS);
740                                     }
741                                     if ((obc_type == GPORT) && (obc_state == SELECTED_POSSIBLE_CONNECTION)) {
742                                         // Change element to connected state
743                                         obc->getView()->setState(HIGHLIGHTED);
744
745                                     }
746
747                                 }
748                                 // EO JGRR CM                                
749                     
750                                 _parent->saveTempDiagram();
751                         }
752
753                         manualConnectorContourController
754                                         * manCont =
755                                                         ((GConnectorController*) cont)->getManualContourController();
756                         manualConnectorContourView
757                                         * connView =
758                                                         (manualConnectorContourView*) manCont->GetManualViewBaseContour();
759                                      
760                         std::map<int, GObjectController*>::iterator it2;
761
762                         for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2) {
763                                 GObjectController *cont = it2->second;
764                                 if (cont->getView() != NULL) {
765                                         cont->getView()->setState(NOTHING_HAPPENS);
766                                         cont->getModel()->notifyObservers(_idManager);
767                                 }
768                                 cont->SetActive(true);
769                         }
770                         connView->Refresh();          
771                 }
772
773         }
774         
775 }
776
777 //=========================================================================
778
779 bool wxVtkSceneManager::OnMouseMove() {
780         int X, Y;
781         bool okStatusMessage = false;
782         bool okPortMessage = false;
783         wxVTKRenderWindowInteractor *wxVTKiren;
784         wxVTKiren
785                         = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
786         wxVTKiren->GetEventPosition(X, Y);
787
788         if (_worldState == DRAG_OBJECTS) {
789                 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
790                         int id = _selectedObjects[i];
791                         GObjectController* cont = _controllers[id];
792                         if (_startDragging) {
793                                 cont->getView()->setStartDragging(true);
794                         }
795                         cont->getView()->moveObject(X, Y);
796                         cont->getView()->setState(DRAG);
797                         cont->getModel()->notifyObservers(_idManager);
798                 }
799
800                 std::map<int, GObjectController*>::iterator it;
801
802                 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
803                         GObjectController *desc = it->second;
804                         if (desc->getGObjectType() == GCONNECTOR) {
805                                 vtkGConnectorView* vconn = (vtkGConnectorView*) desc->getView();
806                                 vconn->updateStartEndPoints();
807                         }
808                 }
809
810                 _startDragging = false;
811
812         } else if (_worldState == NOTHING_HAPPENS || _worldState
813                         == INIT_CREATION_CONTOUR) {
814                 std::map<int, GObjectController*>::iterator it;
815                 double px, py, pz;
816                 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
817                         GObjectController *desc = it->second;
818                         int type = desc->getGObjectType();
819                         int state = desc->getView()->getState();
820                         desc->getModel()->getCenter(px, py, pz);
821
822                         // JGRR & CM
823                         if ((state == HIGHLIGHTED) || (state == SELECTED_POSSIBLE_CONNECTION )) {
824                         // EO JGRR & CM    
825                                 okStatusMessage = true;
826                                 updateStatusBar(desc->getStatusText());
827                                 if (type == GBLACKBOX) {
828                                         GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
829                                         _parent->displayBlackBoxInfo(mod->getBBTKPackage(),
830                                                         mod->getBBTKType());
831                                 } // if GBLACKBOX
832                                 if (type == GPORT) {
833                                         // PortText
834                                         okPortMessage = true;
835                                         py = py + 5;
836                                         _textActor->SetInput(desc->getStatusText().c_str());
837                                         _textActor->SetScale(0.1);
838                                         _textActor->SetPosition(px - 25, py + 1, pz + 2);
839
840                                         // FillPortText
841                                         px = px - 33;
842                                         py = py;
843                                         _fillObjectActor->SetScale(1);
844                                         _fillObjectActor->GetProperty()->SetOpacity(0.50);
845                                         _fillObjectActor->SetPosition(px, py, 1);
846                                         _aPolygonMapper->Modified();
847                                 } // if GPORT
848
849                         } // for controllers it
850                 }
851         }
852         if (okStatusMessage == false) {
853                 updateStatusBar("");
854         }
855
856         if (okPortMessage == false) {
857                 _textActor->SetScale(0.0001);
858                 _fillObjectActor->SetScale(0.0001);
859         }
860         return true;
861 }
862
863 //=========================================================================
864
865 bool wxVtkSceneManager::OnLeftButtonDown() {
866
867         if (_worldState == INIT_CREATION_CONTOUR) {
868                 bool isOverPort = false;
869                 std::map<int, GObjectController*>::iterator it;
870                 for (it = _controllers.begin(); it != _controllers.end() && isOverPort
871                                 == false; ++it) {
872                         GObjectController *desc = it->second;
873                         if (desc->getGObjectType() == GPORT) {
874                                 GPortModel *portmod = (GPortModel*) desc->getModel();
875                                 vtkGObjectView *portView = desc->getView();
876                                 if (portmod->getPortType() == GINPUTPORT
877                                                 && portView->getState() == HIGHLIGHTED) {
878                                         isOverPort = true;
879                                  } // if
880                                 // JGRR & CM                    
881                                 if ( portmod->getPortType( ) == GINPUTPORT &&  portView->getState( ) == SELECTED_POSSIBLE_CONNECTION   ) {
882                                     isOverPort = true ;
883                                     portView->setState( HIGHLIGHTED);
884                                 }                    
885                                 // EO JGRR & CM 
886
887                         } // if
888                 } // for
889
890                 if (isOverPort == false) {
891                         CancelConnection();
892                         UnSelectBlackBoxes();
893                 } // isOverPort
894         
895
896         } else { //_worldState
897
898                 _worldState = DRAG_OBJECTS;
899                 _startDragging = true;
900
901                 int shiftkey =
902                                 _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey();
903                 int ctrlkey =
904                                 _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
905                 ctrlkey = ctrlkey + shiftkey;
906
907                 GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
908
909                 if (GetGBlackBoxControlerPointedByMouse() != NULL) {
910                         int state = cont->getView()->getState();
911                         if ((ctrlkey == 0) && (state == HIGHLIGHTED)) {
912                                 UnSelectBlackBoxes();
913                         }
914                 }
915                 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
916                         int id = _selectedObjects[i];
917                         GObjectController* cont = _controllers[id];
918                         cont->getView()->setState(DRAG);
919                         cont->getModel()->notifyObservers(_idManager);
920                 } // for
921                 
922         } // if _selectedObjects.size
923
924
925         return true;
926 }
927
928 //=========================================================================
929
930 bool wxVtkSceneManager::OnLeftButtonUp() {
931         if (_worldState == DRAG_OBJECTS) {
932                 _worldState = NOTHING_HAPPENS;
933
934                 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
935                         int id = _selectedObjects[i];
936                         GObjectController* cont = _controllers[id];
937                         cont->getView()->setState(SELECTED);
938                         cont->getModel()->notifyObservers(_idManager);
939                 }
940         }
941         return true;
942 }
943
944 //=========================================================================
945 void wxVtkSceneManager::CancelConnection() {
946         if (_worldState == INIT_CREATION_CONTOUR) {
947                 _worldState = NOTHING_HAPPENS;
948                 //int lastId = _controllers.size()-1;
949
950                 GConnectorController *connector =
951                                 (GConnectorController*) _controllers[_idConnectionInCreation];
952                 connector->removeFromScene();
953                 unregisterController(connector);
954                 _controllers.erase(_idConnectionInCreation);
955
956                 std::map<int, GObjectController*>::iterator it;
957                 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
958                         GObjectController *desc = it->second;
959                         desc->SetActive(true);
960                         desc->getView()->setState(NOTHING_HAPPENS);
961                         desc->getModel()->notifyObservers(_idManager);
962                 } // for
963         }// if
964 }
965
966 //=========================================================================
967
968 bool wxVtkSceneManager::OnRightButtonUp() {
969         if (_worldState == INIT_CREATION_CONTOUR) {
970                 CancelConnection();
971         }
972         UnSelectBlackBoxes();
973         return true;
974 }
975
976  ///JLGR 21-05-2012
977
978 bool wxVtkSceneManager::OnMiddleButtonDown() {
979
980
981         this->_vtkInteractorStyleBaseView->StartPan();
982
983         return true;
984     }
985
986 bool wxVtkSceneManager::OnMiddleButtonUp() {
987
988
989         this->_vtkInteractorStyleBaseView->EndPan();
990
991
992         return true;
993     }
994
995
996 //=========================================================================
997
998 GObjectController *wxVtkSceneManager::GetGBlackBoxControlerPointedByMouse() {
999         GObjectController *result = NULL;
1000         int X, Y;
1001         wxVTKRenderWindowInteractor *wxVTKiren;
1002         wxVTKiren
1003                         = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
1004         wxVTKiren->GetEventPosition(X, Y);
1005
1006         std::map<int, GObjectController*>::iterator it;
1007
1008         for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1009                 GObjectController *cont = it->second;
1010                 int type = cont->getGObjectType();
1011
1012                 if (cont->getView()->isPointInside(X, Y) == true) {
1013                         if (type == GBLACKBOX) {
1014                                 result = cont;
1015                         } // if type
1016                 } // if isPointInside
1017         } // for it
1018         return result;
1019 }
1020
1021 //=========================================================================
1022 void wxVtkSceneManager::UnSelectBlackBoxes() {
1023         for (int i = 0; i < (int) _selectedObjects.size(); i++) {
1024                 int id = _selectedObjects[i];
1025                 GObjectController* control = _controllers[id];
1026                 control->getView()->setState(NOTHING_HAPPENS);
1027                 control->getModel()->notifyObservers(_idManager);
1028         }// for _selectedObjects
1029         _selectedObjects.clear();
1030 }
1031
1032 //=========================================================================
1033 bool wxVtkSceneManager::OnLeftDClick() {
1034         GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
1035         if (cont != NULL) {
1036                 UnSelectBlackBoxes();
1037                 _parent->editBlackBox((GBlackBoxModel*) cont->getModel());
1038         }
1039
1040         /*EED Borrame
1041
1042          int X,Y;
1043          wxVTKRenderWindowInteractor *wxVTKiren;
1044          wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
1045          wxVTKiren->GetEventPosition(X,Y);
1046
1047          std::map<int, GObjectController*>::iterator it;
1048
1049          bool clickOnObject = false;
1050
1051          for(it = _controllers.begin(); it != _controllers.end() && clickOnObject==false; ++it)
1052          {
1053          GObjectController *cont = it->second;
1054          int type = cont->getGObjectType();
1055
1056          if(cont->getView()->isPointInside(X,Y))
1057          {
1058          if(type==GBLACKBOX)
1059          {
1060          for (int i=0; i< (int)_selectedObjects.size(); i++)
1061          {
1062          int id = _selectedObjects[i];
1063          GObjectController* control = _controllers[id];
1064          control->getView()->setState(NOTHING_HAPPENS);
1065          }
1066          _selectedObjects.clear();
1067
1068          GBlackBoxModel *bbmodel = (GBlackBoxModel*)cont->getModel();
1069          _parent->editBlackBox(bbmodel);
1070          }
1071          clickOnObject = true;
1072          }
1073          }
1074
1075          if(clickOnObject==false)
1076          {
1077          //_parent->editDiagramParameters(this);
1078          }
1079          */
1080         return true;
1081 }
1082
1083 //=========================================================================
1084
1085 bool wxVtkSceneManager::OnChar() {
1086         char keyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
1087         int ctrlkey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
1088         
1089         // KeyCode 127 : Delete Key
1090         // KeyCode 8 : Backspace Key
1091         if (keyCode == 8 || keyCode == 127) {
1092                 if (_selectedObjects.size() > 0) {
1093                         for (int i = 0; i < (int) _selectedObjects.size(); i++) {
1094                                 int id = _selectedObjects[i];
1095                                 std::map<int, GObjectController*>::iterator it;
1096                                 it = _controllers.find(id);
1097                                 if (it != _controllers.end()) {
1098                                         deleteObject(id);
1099                                 }
1100                         }
1101                         _selectedObjects.clear();
1102                 }
1103         }
1104         ctrlkey+=keyCode;
1105         /// Duplicate 
1106              if(ctrlkey==5){                
1107                 if(_selectedObjects.size()){
1108                     std::cout<<"objects to copy :";
1109                     for(int i=0;i<_selectedObjects.size();i++){
1110                        std::cout<<_selectedObjects.at(i)<<" ";
1111                     }
1112                     DuplicateObjects(getSelectedObjects());   
1113                 }else{
1114                     std::cout<<"No objects to copy\n";
1115                 }
1116             }  
1117
1118         return true;
1119 }
1120
1121 //=========================================================================
1122
1123 void wxVtkSceneManager::AddControlerToBeRemove(
1124                 std::vector<int> *controllersToRemove, int id) {
1125
1126         int i;
1127         bool ok = true;
1128         for (i = 0; i < (int) controllersToRemove->size(); i++) {
1129                 if (id == (*controllersToRemove)[i]) {
1130                         ok = false;
1131                 }
1132         }
1133
1134         if (ok == true) {
1135                 controllersToRemove->push_back(id);
1136         }
1137
1138 }
1139
1140 //=========================================================================
1141
1142 void wxVtkSceneManager::deleteObject(int id) {
1143         GObjectController *control = _controllers[id];
1144         std::vector<int> controllersToRemove;
1145
1146         if (control->getGObjectType() == GBLACKBOX || control->getGObjectType()
1147                         == GCOMPLEXINPUTPORT || control->getGObjectType()
1148                         == GCOMPLEXOUTPUTPORT) {
1149                 GBoxModel *bbmod = (GBoxModel*) control->getModel();
1150                 std::vector<GPortModel*> inputs = bbmod->getInputPorts();
1151
1152                 bool boxConnected = false;
1153
1154                 // Add box input controllers to be removed
1155                 for (int i = 0; i < (int) inputs.size(); i++) {
1156                         AddControlerToBeRemove(&controllersToRemove,
1157                                         inputs[i]->getObjectId());
1158                         if (inputs[i]->isConnected()) {
1159                                 boxConnected = true;
1160                         }
1161                 }
1162
1163                 std::vector<GPortModel*> outputs = bbmod->getOutputPorts();
1164
1165                 // Add box output controllers to be removed
1166                 for (int i = 0; i < (int) outputs.size(); i++) {
1167                         AddControlerToBeRemove(&controllersToRemove,
1168                                         outputs[i]->getObjectId());
1169                         if (outputs[i]->isConnected()) {
1170                                 boxConnected = true;
1171                         }
1172                 }
1173
1174                 // Add connection controllers to be removed
1175                 std::map<int, GObjectController*>::iterator it;
1176                 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1177                         GObjectController *cont = it->second;
1178                         int type = cont->getGObjectType();
1179                         if (type == GCONNECTOR) {
1180                                 GConnectorModel *conMod = (GConnectorModel*) cont->getModel();
1181                                 if (conMod->getStartPort() != NULL
1182                                                 && conMod->getStartPort()->getParentBox()->getObjectId()
1183                                                                 == bbmod->getObjectId()) {
1184                                         AddControlerToBeRemove(&controllersToRemove,
1185                                                         conMod->getObjectId());
1186                                 }
1187                                 if (conMod->getEndPort() != NULL
1188                                                 && conMod->getEndPort()->getParentBox()->getObjectId()
1189                                                                 == bbmod->getObjectId()) {
1190                                         AddControlerToBeRemove(&controllersToRemove,
1191                                                         conMod->getObjectId());
1192                                 }
1193                         }
1194                 }
1195
1196                 // Add box controller to be removed
1197                 AddControlerToBeRemove(&controllersToRemove, bbmod->getObjectId());
1198         } else if (control->getGObjectType() == GCONNECTOR) {
1199                 GConnectorModel *conMod = (GConnectorModel*) control->getModel();
1200                 AddControlerToBeRemove(&controllersToRemove, conMod->getObjectId());
1201         }
1202
1203         std::map<int, GObjectController*>::iterator it;
1204
1205         for (int i = 0; i < (int) controllersToRemove.size(); i++) {
1206                 int key = controllersToRemove[i];
1207                 it = _controllers.find(key);
1208                 GObjectController *cont = _controllers[key];
1209                 if (cont != NULL) {
1210                         cont->removeFromScene();
1211                         unregisterController((InteractorStyleMaracas*) cont);
1212                         _controllers.erase(it);
1213                 }//if
1214         }// for
1215         _parent->saveTempandUpdate();
1216 }
1217
1218 //=========================================================================
1219
1220 void wxVtkSceneManager::displayBlackBoxInfo(std::string packageName,
1221                 std::string boxName) {
1222         _parent->displayBlackBoxInfo(packageName, boxName);
1223 }
1224
1225 //=========================================================================
1226
1227 void wxVtkSceneManager::updateStatusBar(std::string textStatus) {
1228         _parent->updateStatusBar(textStatus);
1229 }
1230
1231 //=========================================================================
1232 std::string wxVtkSceneManager::LineNumber(bool withLineNumber, int &value) {
1233         std::string result = "";
1234         if (withLineNumber == true) {
1235                 value++;
1236                 stringstream StrStream;
1237                 StrStream << value;
1238                 std::string strValue = StrStream.str();
1239                 if (value < 10) {
1240                         result += "  ";
1241                 } else if (value < 100) {
1242                         result += " ";
1243                 }
1244
1245                 result += strValue + ": ";
1246         }
1247         return result;
1248 }
1249 //=========================================================================
1250 //DFCH
1251 bool wxVtkSceneManager::MakeBoxExecutable() {
1252         std::map<int, GObjectController*> selected = getSelectedObjects();
1253         if( selected.empty() )
1254                 return false;
1255         bool ret = false;
1256         std::map<int, GObjectController*>::iterator it;
1257         for (it = selected.begin(); it != selected.end(); ++it) {
1258                 GObjectController* lastSelected = it->second;
1259                 if (lastSelected) {
1260                         vtkGObjectView* view = (vtkGObjectView*) lastSelected->getView();
1261                         GBlackBoxModel *bbmodel =
1262                                         (GBlackBoxModel*) lastSelected->getModel();
1263                         view->setState(HIGHLIGHTED);
1264                         if (bbmodel->isExecutable()) {
1265                                 bbmodel->setExecutable(false);
1266                         } else {
1267                                 bbmodel->setExecutable(true);
1268                         }
1269                         bbmodel->notifyObservers(lastSelected->getId());
1270                         ret = true;
1271                 }
1272         }
1273         return ret;
1274 }
1275 //DFCH
1276
1277 //=========================================================================
1278
1279 std::string wxVtkSceneManager::getDiagramBBS(bool wln) {
1280         bool existsExec = false;
1281
1282         std::vector<std::string> packages;
1283         std::vector<int> boxes;
1284         std::vector<int> connections;
1285         std::vector<int> execBoxes;
1286
1287         std::map<int, GObjectController*>::iterator it;
1288
1289         for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1290                 GObjectController *desc = it->second;
1291                 int type = desc->getGObjectType();
1292
1293                 if (type == GBLACKBOX) {
1294                         GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
1295
1296                         std::string pkg = mod->getBBTKPackage();
1297                         bool existsPkg = false;
1298                         for (int t = 0; t < (int) packages.size() && existsPkg == false; t++) {
1299                                 if (packages[t] == pkg) {
1300                                         existsPkg = true;
1301                                 }
1302                         }
1303                         if (!existsPkg) {
1304                                 packages.push_back(pkg);
1305                         }
1306
1307                         boxes.push_back(it->first);
1308                         if (mod->isExecutable()) {
1309                                 execBoxes.push_back(it->first);
1310                                 existsExec = true;
1311                         }
1312                 } else if (type == GCONNECTOR) {
1313                         connections.push_back(it->first);
1314                 }
1315         }
1316
1317         int lnNmbr = 0;
1318         std::string script = "";
1319         script += LineNumber(wln, lnNmbr) + "# BBTK GEditor Script\n";
1320         script += LineNumber(wln, lnNmbr) + "# ----------------------\n";
1321         script += LineNumber(wln, lnNmbr) + "\n";
1322         if (existsExec) {
1323                 script += LineNumber(wln, lnNmbr) + "include std\n"; // EED
1324                 script += LineNumber(wln, lnNmbr) + "include itkvtk\n"; // EED
1325                 int i;
1326                 for (i = 0; i < (int) packages.size(); i++) {
1327                         script += LineNumber(wln, lnNmbr);
1328                         script += "include ";
1329                         script += packages[i];
1330                         script += "\n";
1331                 }
1332
1333                 script += LineNumber(wln, lnNmbr);
1334                 script += "\n";
1335
1336                 //ups2
1337
1338                 script += LineNumber(wln, lnNmbr);
1339                 script += "author \"";
1340                 script += _Author;
1341                 script += "\"\n";
1342
1343                 script += LineNumber(wln, lnNmbr);
1344                 script += "description \"";
1345                 script += _Description;
1346                 script += "\"\n";
1347
1348                 script += LineNumber(wln, lnNmbr);
1349                 script += "category \"";
1350                 script += _Category;
1351                 script += "\"\n";
1352
1353                 script += LineNumber(wln, lnNmbr);
1354                 script += "\n";
1355
1356                 // script+="include std\n"; // JPR
1357
1358                 for (i = 0; i < (int) boxes.size(); i++) {
1359                         script += LineNumber(wln, lnNmbr);
1360                         script += "new ";
1361                         int id = boxes[i];
1362                         GObjectController *control = _controllers[id];
1363                         GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1364
1365                         script += model->getBBTKType();
1366                         script += " ";
1367                         script += model->getBBTKName();
1368                         script += "\n";
1369
1370                         std::vector<GPortModel*> inputs = model->getInputPorts();
1371                         for (int j = 0; j < (int) inputs.size(); j++) {
1372                                 GPortModel* inputPort = inputs[j];
1373                                 if (inputPort->isValueSet()) {
1374                                         script += LineNumber(wln, lnNmbr);
1375                                         script += "  set ";
1376                                         script += model->getBBTKName();
1377                                         script += ".";
1378                                         script += inputPort->getBBTKName();
1379                                         script += " ";
1380                                         script += inputPort->getValue();
1381                                         script += "\n";
1382                                 }
1383                         }
1384
1385                         script += LineNumber(wln, lnNmbr);
1386                         script += "\n";
1387
1388                 }
1389
1390                 script += LineNumber(wln, lnNmbr);
1391                 script += "\n";
1392
1393                 for (i = 0; i < (int) connections.size(); i++) {
1394                         script += LineNumber(wln, lnNmbr);
1395                         script += "connect ";
1396                         int id = connections[i];
1397                         GObjectController *control = _controllers[id];
1398                         GConnectorModel *model = (GConnectorModel*) control->getModel();
1399
1400                         //Start Connection info
1401                         GPortModel *start = model->getStartPort();
1402                         script += start->getParentBox()->getBBTKName();
1403                         script += ".";
1404                         script += start->getBBTKName();
1405
1406                         script += " ";
1407
1408                         //End Connection info
1409                         GPortModel *end = model->getEndPort();
1410                         script += end->getParentBox()->getBBTKName();
1411                         script += ".";
1412                         script += end->getBBTKName();
1413
1414                         script += "\n";
1415                 }
1416
1417                 script += LineNumber(wln, lnNmbr);
1418                 script += "\n";
1419                 for (i = 0; i < (int) execBoxes.size(); i++) {
1420                         script += LineNumber(wln, lnNmbr);
1421                         script += "exec ";
1422                         int id = execBoxes[i];
1423                         GObjectController *control = _controllers[id];
1424                         GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1425
1426                         script += model->getBBTKName();
1427                         script += "\n";
1428                 }
1429
1430         }
1431
1432         return script;
1433 }
1434
1435 //=========================================================================
1436
1437 std::string wxVtkSceneManager::saveComplexBoxBBS() {
1438         std::vector<std::string> packages;
1439         std::vector<int> boxes;
1440         std::vector<int> connections;
1441         std::vector<int> execBoxes;
1442
1443         std::map<int, GObjectController*>::iterator it;
1444
1445         for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1446                 GObjectController *desc = it->second;
1447                 int type = desc->getGObjectType();
1448
1449                 if (type == GBLACKBOX) {
1450                         GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
1451
1452                         std::string pkg = mod->getBBTKPackage();
1453                         bool existsPkg = false;
1454                         for (int t = 0; t < (int) packages.size() && existsPkg == false; t++) {
1455                                 if (packages[t] == pkg) {
1456                                         existsPkg = true;
1457                                 }
1458                         }
1459                         if (!existsPkg) {
1460                                 packages.push_back(pkg);
1461                         }
1462
1463                         boxes.push_back(it->first);
1464                         if (mod->isExecutable()) {
1465                                 execBoxes.push_back(it->first);
1466                         }
1467                 } else if (type == GCONNECTOR) {
1468                         connections.push_back(it->first);
1469                 }
1470         }
1471
1472         std::string script = "";
1473
1474         script += "include std\n"; // EED
1475         script += "include itkvtk\n"; // EED
1476         int i;
1477         for (i = 0; i < (int) packages.size(); i++) {
1478                 script += "include ";
1479                 script += packages[i];
1480                 script += "\n";
1481         }
1482         script += "\n";
1483
1484         // Definition of a complex box
1485         script += "define ";
1486         script += _cbName + " " + _cbPackageName;
1487         script += "\n";
1488         script += "\n";
1489
1490         script += "author \"";
1491         script += _Author;
1492         script += "\"\n";
1493
1494         script += "description \"";
1495         script += _Description;
1496         script += "\"\n";
1497         script += "\n";
1498
1499         script += "category \"";
1500         script += _Category;
1501         script += "\"\n";
1502         script += "\n";
1503
1504         // Create boxes
1505         for (i = 0; i < (int) boxes.size(); i++) {
1506                 script += "new ";
1507                 int id = boxes[i];
1508                 GObjectController *control = _controllers[id];
1509                 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1510
1511                 script += model->getBBTKType();
1512                 script += " ";
1513                 script += model->getBBTKName();
1514                 script += "\n";
1515
1516                 std::vector<GPortModel*> inputs = model->getInputPorts();
1517                 for (int j = 0; j < (int) inputs.size(); j++) {
1518                         GPortModel* inputPort = inputs[j];
1519                         if (inputPort->isValueSet()) {
1520                                 script += "  set ";
1521                                 script += model->getBBTKName();
1522                                 script += ".";
1523                                 script += inputPort->getBBTKName();
1524                                 script += " ";
1525                                 script += inputPort->getValue();
1526                                 script += "\n";
1527                         }
1528                 }
1529                 script += "\n";
1530
1531         }
1532
1533         // Create connections in the script. If the connection is made with a complex port, it is created the input or output
1534
1535         std::string complexInputs = "";
1536         std::string complexOutputs = "";
1537         script += "\n";
1538
1539         for (i = 0; i < (int) connections.size(); i++) {
1540                 int id = connections[i];
1541                 GObjectController *control = _controllers[id];
1542                 GConnectorModel *model = (GConnectorModel*) control->getModel();
1543
1544                 //Connection info
1545                 GPortModel *start = model->getStartPort();
1546                 GBoxModel *startBox = start->getParentBox();
1547
1548                 GPortModel *end = model->getEndPort();
1549                 GBoxModel *endBox = end->getParentBox();
1550
1551                 if (startBox->getGObjectType() == GCOMPLEXINPUTPORT) {
1552                         complexInputs += "input ";
1553                         complexInputs += startBox->getBBTKName();
1554
1555                         complexInputs += " ";
1556                         complexInputs += endBox->getBBTKName();
1557                         complexInputs += ".";
1558                         complexInputs += end->getBBTKName();
1559
1560                         complexInputs += " ";
1561                         complexInputs += "\" \"";
1562
1563                         complexInputs += "\n";
1564                 } else if (endBox->getGObjectType() == GCOMPLEXOUTPUTPORT) {
1565                         complexOutputs += "output ";
1566                         complexOutputs += endBox->getBBTKName();
1567
1568                         complexOutputs += " ";
1569                         complexOutputs += startBox->getBBTKName();
1570                         complexOutputs += ".";
1571                         complexOutputs += start->getBBTKName();
1572
1573                         complexOutputs += " ";
1574                         complexOutputs += "\" \"";
1575
1576                         complexOutputs += "\n";
1577                 } else {
1578                         script += "connect ";
1579                         script += startBox->getBBTKName();
1580                         script += ".";
1581                         script += start->getBBTKName();
1582
1583                         script += " ";
1584
1585                         //End Connection info
1586                         script += endBox->getBBTKName();
1587                         script += ".";
1588                         script += end->getBBTKName();
1589
1590                         script += "\n";
1591                 }
1592         }
1593
1594         script += "\n";
1595
1596         for (i = 0; i < (int) execBoxes.size(); i++) {
1597                 script += "exec ";
1598                 int id = execBoxes[i];
1599                 GObjectController *control = _controllers[id];
1600                 GBlackBoxModel *model = (GBlackBoxModel*) control->getModel();
1601
1602                 script += model->getBBTKName();
1603                 script += "\n";
1604         }
1605
1606         script += "\n";
1607         script += "# Complex input ports\n";
1608         script += complexInputs;
1609
1610         script += "\n";
1611         script += "# Complex output ports\n";
1612         script += complexOutputs;
1613
1614         script += "\n";
1615         script += "endefine";
1616         script += "\n";
1617
1618         return script;
1619 }
1620
1621 //=========================================================================
1622
1623 void wxVtkSceneManager::deleteAllBoxes() {
1624         std::map<int, GObjectController*>::iterator it;
1625         for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1626                 GObjectController *cont = it->second;
1627                 cont->removeFromScene();
1628                 unregisterController((InteractorStyleMaracas*) cont);
1629         }
1630         _selectedObjects.clear();
1631         _controllers.clear();
1632 }
1633
1634 //=========================================================================
1635
1636
1637 void wxVtkSceneManager::refresh() {
1638         _baseView->Refresh();
1639 }
1640 //=========================================================================
1641
1642 void wxVtkSceneManager::refreshScene() {
1643         _baseView->RefreshView();
1644 }
1645
1646 //=========================================================================
1647
1648 void wxVtkSceneManager::centerView() {
1649         double temp[3];
1650         _baseView->GetRenderer()->GetActiveCamera()->GetFocalPoint(temp);
1651         _baseView->GetRenderer()->GetActiveCamera()->SetFocalPoint(0, 0, temp[2]);
1652         _baseView->GetRenderer()->GetActiveCamera()->GetPosition(temp);
1653         _baseView->GetRenderer()->GetActiveCamera()->SetPosition(0, 0, temp[2]);
1654 }
1655
1656 //=========================================================================
1657
1658 void wxVtkSceneManager::saveDiagram(std::string &content) {
1659         char buffer[50];
1660
1661         content += "CATEGORY:";
1662         content += GetCategory();
1663         content += "\n";
1664
1665         content += "DESCRIPTION:";
1666         content += GetDescription();
1667         content += "\n";
1668
1669         content += "AUTHOR:";
1670         content += GetAuthor();
1671         content += "\n";
1672
1673         //Print info IF COMPLEX BOX
1674         content += "COMPLEXBOX:";
1675         if (_isComplexBox) {
1676                 content += "TRUE\n";
1677                 //ups1
1678                 content += "COMPLEXBOXNAME:";
1679                 content += GetCbName();
1680                 content += "\n";
1681
1682                 content += "PACKAGENAME:";
1683                 content += GetCbPackageName();
1684                 content += "\n";
1685
1686                 //Print info complex input ports
1687                 std::vector<int> inputs = getComplexInputPorts();
1688                 int insize = inputs.size();
1689                 content += "COMPLEXINPUTS:";
1690                 sprintf(buffer, "%d", insize);
1691                 content += buffer;
1692                 content += "\n";
1693
1694                 for (int i = 0; i < insize; i++) {
1695                         int id = inputs[i];
1696                         GObjectController *cont = _controllers[id];
1697                         cont->getModel()->save(content);
1698                 }
1699
1700                 //Print info complex output ports
1701                 std::vector<int> outputs = getComplexOutputPorts();
1702                 int outsize = outputs.size();
1703                 content += "COMPLEXOUTPUTS:";
1704                 sprintf(buffer, "%d", outsize);
1705                 content += buffer;
1706                 content += "\n";
1707
1708                 for (int i = 0; i < outsize; i++) {
1709                         int id = outputs[i];
1710                         GObjectController *cont = _controllers[id];
1711                         cont->getModel()->save(content);
1712                 }
1713         } // _isComplexBox
1714         else {
1715                 content += "FALSE\n";
1716         }
1717
1718         //Print boxes
1719         std::vector<int> boxes = getBlackBoxes();
1720         int bsize = boxes.size();
1721         content += "BOXES:";
1722         sprintf(buffer, "%d", bsize);
1723         content += buffer;
1724         content += "\n";
1725
1726         for (int i = 0; i < bsize; i++) {
1727                 int id = boxes[i];
1728                 GObjectController *cont = _controllers[id];
1729                 cont->getModel()->save(content);
1730         }
1731
1732         //Print connections
1733         std::vector<int> connections = getConnections();
1734         int csize = connections.size();
1735         content += "CONNECTIONS:";
1736         sprintf(buffer, "%d", csize);
1737         content += buffer;
1738         content += "\n";
1739
1740         for (int i = 0; i < csize; i++) {
1741                 int id = connections[i];
1742                 GObjectController *cont = _controllers[id];
1743                 cont->getModel()->save(content);
1744         }
1745
1746 }
1747
1748 //=========================================================================
1749
1750 void wxVtkSceneManager::loadDiagram(stringstream &inputStream) {
1751
1752         std::string version = "<void>";
1753         std::string line = "";
1754         char delims[] = ":";
1755         char *result = NULL;
1756
1757         getline(inputStream, line);
1758
1759         bool start = false;
1760         while (!inputStream.eof()) {
1761                 if (line == "" || line[0] == '#') {
1762                         getline(inputStream, line);
1763                         if (line == "# - BBTKGEditor v 1.0 BBG BlackBox Diagram file") {
1764                                 version = line.substr(18, 3);
1765                         }
1766                         if (line == "# - BBTKGEditor v 1.1 BBG BlackBox Diagram file") {
1767                                 version = line.substr(18, 3);
1768                         }
1769                         if (line == "# - BBTKGEditor v 1.2 BBG BlackBox Diagram file") {
1770                                 version = line.substr(18, 3);
1771                         }
1772                 } else if (line == "APP_START") {
1773                         start = true;
1774                         break;
1775                 }
1776         }
1777
1778         printf("EED wxVtkSceneManager::loadDiagram  version=%s\n", version.c_str());
1779
1780         if (start) {
1781
1782                 if ((version != "1.0") && (version != "1.1")) {
1783                         getline(inputStream, line);//CATEGORY:<category of the box>
1784                         char categoryTmp[30];
1785                         strcpy(categoryTmp, line.c_str());
1786                         result = strtok(categoryTmp, delims);
1787                         result = strtok(NULL, delims);
1788                         SetCategory(result);
1789
1790                         getline(inputStream, line);//DESCRIPTION:<description of the box>
1791                         char descriptionTmp[1024];
1792                         strcpy(descriptionTmp, line.c_str());
1793                         result = strtok(descriptionTmp, delims);
1794                         result = strtok(NULL, delims);
1795                         SetDescription(result);
1796
1797                         getline(inputStream, line);//AUTHOR:<author>
1798                         char authorTmp[255];
1799                         strcpy(authorTmp, line.c_str());
1800                         result = strtok(authorTmp, delims);
1801                         result = strtok(NULL, delims);
1802                         SetAuthor(result);
1803                 }
1804
1805                 //----------
1806                 getline(inputStream, line);//COMPLEX_BOX:TRUE|FALSE
1807                 char complexTmp[30];
1808                 strcpy(complexTmp, line.c_str());
1809                 result = strtok(complexTmp, delims);
1810                 result = strtok(NULL, delims);
1811                 std::string isComplexBox(result);
1812
1813                 if (isComplexBox == "TRUE") {
1814                         _isComplexBox = true;
1815
1816                         if ((version != "1.0") && (version != "1.1")) {
1817                                 getline(inputStream, line);//COMPLEXNAME:<name of the complex box>
1818                                 char complexboxnameTmp[255];
1819                                 strcpy(complexboxnameTmp, line.c_str());
1820                                 result = strtok(complexboxnameTmp, delims);
1821                                 result = strtok(NULL, delims);
1822                                 SetCbName(result);
1823
1824                                 getline(inputStream, line);//PACKAGENAME:<name of the package of the box>
1825                                 char packagenameTmp[255];
1826                                 strcpy(packagenameTmp, line.c_str());
1827                                 result = strtok(packagenameTmp, delims);
1828                                 result = strtok(NULL, delims);
1829                                 SetCbPackageName(result);
1830                         }
1831
1832                         //-----------------------
1833                         //- COMPLEX INPUT PORTS
1834                         //-----------------------
1835                         getline(inputStream, line);//COMPLEXINPUTS:num
1836                         char inputs[30];
1837                         strcpy(inputs, line.c_str());
1838                         result = strtok(inputs, delims);
1839                         result = strtok(NULL, delims);
1840
1841                         int numInputs;
1842                         std::istringstream inps(result);
1843                         inps >> numInputs;
1844
1845                         for (int i = 0; i < numInputs; i++) {
1846                                 //----------
1847                                 getline(inputStream, line);//COMPLEX_PORT
1848                                 getline(inputStream, line);//name
1849                                 std::string inputPortName(line);
1850
1851                                 //----------
1852                                 getline(inputStream, line);//xInic:yInic:zInic
1853                                 char coord[80];
1854                                 strcpy(coord, line.c_str());
1855                                 result = strtok(coord, delims);//xInic
1856                                 std::string xInic(result);
1857                                 result = strtok(NULL, delims);//yInic
1858                                 std::string yInic(result);
1859                                 result = strtok(NULL, delims);//zInic
1860                                 std::string zInic(result);
1861
1862                                 double xIn, yIn, zIn;
1863                                 std::istringstream xSt(xInic);
1864                                 xSt >> xIn;
1865                                 std::istringstream ySt(yInic);
1866                                 ySt >> yIn;
1867                                 std::istringstream zSt(zInic);
1868                                 zSt >> zIn;
1869
1870                                 getline(inputStream, line);//FIN_COMPLEX_PORT
1871
1872                                 configGComBoxInputOutputPort(true, inputPortName, xIn, yIn, zIn);
1873
1874                         } // for input complex box
1875
1876
1877                         //-----------------------
1878                         //- COMPLEX OUTPUT PORTS
1879                         //-----------------------
1880
1881                         getline(inputStream, line);//COMPLEXOUTPUTS:num
1882                         char outputs[30];
1883                         strcpy(outputs, line.c_str());
1884                         result = strtok(outputs, delims);
1885                         result = strtok(NULL, delims);
1886
1887                         int numOutputs;
1888                         std::istringstream outps(result);
1889                         outps >> numOutputs;
1890
1891                         for (int i = 0; i < numOutputs; i++) {
1892                                 //----------
1893                                 getline(inputStream, line);//COMPLEX_PORT
1894                                 getline(inputStream, line);//name
1895                                 std::string outputPortName(line);
1896
1897                                 //----------
1898                                 getline(inputStream, line);//xInic:yInic:zInic
1899                                 char coord[80];
1900                                 strcpy(coord, line.c_str());
1901                                 result = strtok(coord, delims);//xInic
1902                                 std::string xInic(result);
1903                                 result = strtok(NULL, delims);//yInic
1904                                 std::string yInic(result);
1905                                 result = strtok(NULL, delims);//zInic
1906                                 std::string zInic(result);
1907
1908                                 double xIn, yIn, zIn;
1909                                 std::istringstream xSt(xInic);
1910                                 xSt >> xIn;
1911                                 std::istringstream ySt(yInic);
1912                                 ySt >> yIn;
1913                                 std::istringstream zSt(zInic);
1914                                 zSt >> zIn;
1915
1916                                 getline(inputStream, line);//FIN_COMPLEX_PORT
1917
1918                                 configGComBoxInputOutputPort(false, outputPortName, xIn, yIn,
1919                                                 zIn);
1920
1921                         } // for output complex box
1922
1923                 } // complex box
1924
1925                 //----------
1926                 getline(inputStream, line);//BOXES:num
1927                 char boxes[9];
1928                 strcpy(boxes, line.c_str());
1929                 result = strtok(boxes, delims);
1930                 result = strtok(NULL, delims);
1931
1932                 int numBoxes;
1933                 std::istringstream is(result);
1934                 is >> numBoxes;
1935
1936                 for (int i = 0; i < numBoxes; i++) {
1937                         //----------
1938                         getline(inputStream, line);//BOX
1939                         getline(inputStream, line);//package:type:name
1940                         char box[150];
1941                         strcpy(box, line.c_str());
1942                         result = strtok(box, delims);//package
1943                         std::string package(result);
1944                         result = strtok(NULL, delims);//type
1945                         std::string type(result);
1946                         result = strtok(NULL, delims);//name
1947                         std::string name(result);
1948
1949                         getline(inputStream, line);//ISEXEC:TRUE|FALSE
1950                         char exec[15];
1951                         strcpy(exec, line.c_str());
1952                         result = strtok(exec, delims);//ISEXEC
1953                         result = strtok(NULL, delims);//TRUE|FALSE
1954                         std::string isExec(result);
1955
1956                         //----------
1957                         getline(inputStream, line);//xInic:yInic:zInic
1958                         char coord[80];
1959                         strcpy(coord, line.c_str());
1960                         result = strtok(coord, delims);//xInic
1961                         std::string xInic(result);
1962                         result = strtok(NULL, delims);//yInic
1963                         std::string yInic(result);
1964                         result = strtok(NULL, delims);//zInic
1965                         std::string zInic(result);
1966
1967                         double xIn, yIn, zIn;
1968                         std::istringstream xSt(xInic);
1969                         xSt >> xIn;
1970                         std::istringstream ySt(yInic);
1971                         ySt >> yIn;
1972                         std::istringstream zSt(zInic);
1973                         zSt >> zIn;
1974
1975                         //----------
1976                         getline(inputStream, line);//xEnd:yEnd:zEnd
1977                         strcpy(coord, line.c_str());
1978                         result = strtok(coord, delims);//xEnd
1979                         std::string xEnd(result);
1980                         result = strtok(NULL, delims);//yEnd
1981                         std::string yEnd(result);
1982                         result = strtok(NULL, delims);//zEnd
1983                         std::string zEnd(result);
1984
1985                         double xEn, yEn, zEn;
1986                         std::istringstream xEt(xEnd);
1987                         xEt >> xEn;
1988                         std::istringstream yEt(yEnd);
1989                         yEt >> yEn;
1990                         std::istringstream zEt(zEnd);
1991                         zEt >> zEn;
1992
1993                         bool boxExecutable = false;
1994                         if (isExec == "TRUE") {
1995                                 boxExecutable = true;
1996                         }
1997
1998                         int idBox = createGBlackBox(xIn, yIn, package, type);
1999                         configGBlackBox(idBox, xIn, yIn, zIn, name, boxExecutable, xEn,
2000                                         yEn, zEn);
2001
2002                         GObjectController *cont = _controllers[idBox];
2003                         GBlackBoxModel *bbmod = (GBlackBoxModel*) cont->getModel();
2004
2005                         //----------
2006                         getline(inputStream, line);//PORT o FIN_BOX
2007                         std::string port = line.substr(0, 4);
2008                         while (port == "PORT") {
2009                                 getline(inputStream, line);//name:value
2010                                 char poort[150];
2011                                 strcpy(poort, line.c_str());
2012                                 result = strtok(poort, delims);//name
2013                                 std::string name(result);
2014                                 result = strtok(NULL, delims);//value
2015                                 std::string value(result);
2016
2017                                 bbmod->setValueToInput(name, value);
2018
2019                                 getline(inputStream, line);//PORT o FIN_BOX
2020                                 port = line.substr(0, 4);
2021                         } // while
2022
2023                         //EED                           bbmod->notifyObservers(_idManager);
2024                 } // for boxes
2025
2026                 /// CONNECTIONS
2027                 //----------
2028                 getline(inputStream, line);//CONNECTIONS:num
2029                 char conns[30];
2030                 strcpy(conns, line.c_str());
2031                 result = strtok(conns, delims);
2032                 result = strtok(NULL, delims);
2033
2034                 int numConns;
2035                 std::istringstream isCons(result);
2036                 isCons >> numConns;
2037
2038                 for (int i = 0; i < numConns; i++) {
2039                         //----------
2040                         getline(inputStream, line);//CONNECTION
2041                         getline(inputStream, line);//Startbox.PortName:EndBox.PortName
2042
2043                         char connec[200];
2044                         strcpy(connec, line.c_str());
2045                         result = strtok(connec, delims);
2046                         std::string nameStartBox(result);
2047                         result = strtok(NULL, delims);
2048                         std::string nameStartPort(result);
2049                         result = strtok(NULL, delims);
2050                         std::string nameEndBox(result);
2051                         result = strtok(NULL, delims);
2052                         std::string nameEndPort(result);
2053
2054                         int idCon = configGConnetion(nameStartBox, nameStartPort,
2055                                         nameEndBox, nameEndPort);
2056
2057                         if (version != "1.0") {
2058                                 //Readding control points of the manualContour
2059                                 //ups1
2060                                 GConnectorController *tempp =
2061                                                 (GConnectorController*) _controllers[idCon];
2062                                 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2063                                 vtkGConnectorView *conView =
2064                                                 (vtkGConnectorView*) tempp->getView();
2065                                 getline(inputStream, line); //NumberOfControlPoints:##
2066                                 strcpy(conns, line.c_str());
2067                                 result = strtok(conns, delims);
2068                                 result = strtok(NULL, delims);
2069
2070                                 int numberOfControlPoints;
2071                                 std::istringstream isCons(result);
2072                                 isCons >> numberOfControlPoints;
2073
2074                                 for (int ii = 0; ii < numberOfControlPoints; ii++) {
2075                                         getline(inputStream, line); //XX:YY:ZZ
2076                                         char connec[200];
2077                                         strcpy(connec, line.c_str());
2078
2079                                         double px, py, pz;
2080                                         result = strtok(connec, delims);
2081                                         std::istringstream isPointX(result);
2082                                         isPointX >> px;
2083                                         result = strtok(NULL, delims);
2084                                         std::istringstream isPointY(result);
2085                                         isPointY >> py;
2086                                         result = strtok(NULL, delims);
2087                                         std::istringstream isPointZ(result);
2088                                         isPointZ >> pz;
2089
2090                                         conMod->getManualContourModel()->InsertPoint_id(ii + 1, px,
2091                                                         py, pz);
2092                                         conView->getManualContourView()->AddPoint();
2093                                 }
2094                         }// version !=1.0
2095
2096                 } // for numConns
2097
2098         } // start
2099
2100 }
2101 //=========================================================================
2102
2103
2104 //=========================================================================
2105 void wxVtkSceneManager::configGComBoxInputOutputPort(bool inputoutput,
2106                 std::string portName, double xIn, double yIn, double zIn) {
2107         int idPort;
2108         if (inputoutput == true) {
2109                 idPort = createGComplexBoxInputPort(portName);
2110         } else {
2111                 idPort = createGComplexBoxOutputPort(portName);
2112         }
2113         GObjectController *cont = _controllers[idPort];
2114         GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2115         cbmod->setInicPoint(xIn, yIn, zIn);
2116         cbmod->notifyObservers(_idManager);
2117 }
2118 //=========================================================================
2119
2120
2121 //=========================================================================
2122 GBoxModel* wxVtkSceneManager::findGBox(std::string boxname) {
2123         int j;
2124         int idB;
2125         GBoxModel *bMod;
2126         GBoxModel *boxModel = NULL;
2127         std::vector<int> lstB = getBlackBoxes();
2128         for (j = 0; j < (int) lstB.size(); j++) {
2129                 idB = lstB[j];
2130                 bMod = (GBoxModel*) _controllers[idB]->getModel();
2131                 if (_controllers[idB]->getModel()->getBBTKName() == boxname) {
2132                         boxModel = bMod;
2133                 }
2134         } // for
2135
2136         if ((_isComplexBox) && (boxModel == NULL)) {
2137                 std::vector<int> lstInputs = getComplexInputPorts();
2138                 for (j = 0; j < (int) lstInputs.size(); j++) {
2139                         idB = lstInputs[j];
2140                         bMod = (GBoxModel*) _controllers[idB]->getModel();
2141                         if (_controllers[idB]->getModel()->getBBTKName() == boxname) {
2142                                 boxModel = bMod;
2143                         }
2144                 } // for
2145
2146                 std::vector<int> lstOutputs = getComplexOutputPorts();
2147                 for (j = 0; j < (int) lstOutputs.size(); j++) {
2148                         int idB = lstOutputs[j];
2149                         bMod = (GBoxModel*) _controllers[idB]->getModel();
2150                         if (_controllers[idB]->getModel()->getBBTKName() == boxname) {
2151                                 boxModel = bMod;
2152                         }
2153                 } // for
2154
2155         } // complex box
2156
2157         return boxModel;
2158 }
2159
2160 //=========================================================================
2161
2162
2163 int wxVtkSceneManager::configGConnetion(std::string nameStartBox,
2164                 std::string nameStartPort, std::string nameEndBox,
2165                 std::string nameEndPort) {
2166
2167         GBoxModel *boxModel;
2168         GPortModel *startP = NULL;
2169         GPortModel *endP = NULL;
2170
2171         boxModel = findGBox(nameStartBox);
2172         if (boxModel != NULL) {
2173                 startP = boxModel->getOutputPort(nameStartPort);
2174         }
2175
2176         boxModel = findGBox(nameEndBox);
2177         if (boxModel != NULL) {
2178                 endP = boxModel->getInputPort(nameEndPort);
2179         }
2180
2181         //ups2
2182         int idCon = createGConnector(startP);
2183         _worldState = NOTHING_HAPPENS;
2184         GConnectorController *tempp = (GConnectorController*) _controllers[idCon];
2185
2186         GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2187         vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2188         tempp->endContourCreation();
2189         conMod->setEndPort(endP);
2190         conView->updateStartEndPoints();
2191         return idCon;
2192 }
2193
2194 //=========================================================================
2195
2196 bool wxVtkSceneManager::boxExist(std::string boxname) {
2197         bool ok = false;
2198         std::map<int, GObjectController*>::iterator it;
2199         for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2200                 GObjectController *cont = it->second;
2201                 if (cont->getModel()->getBBTKName() == boxname) {
2202                         ok = true;
2203                 }
2204         }
2205         return ok;
2206 }
2207
2208 //=========================================================================
2209
2210 std::vector<int> wxVtkSceneManager::getBlackBoxes() {
2211         std::vector<int> vect;
2212         std::map<int, GObjectController*>::iterator it;
2213         for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2214                 GObjectController *cont = it->second;
2215                 if (cont->getGObjectType() == GBLACKBOX) {
2216                         vect.push_back(cont->getId());
2217                 }
2218         }
2219         return vect;
2220 }
2221
2222 //=========================================================================
2223
2224 std::vector<int> wxVtkSceneManager::getComplexInputPorts() {
2225         std::vector<int> vect;
2226         std::map<int, GObjectController*>::iterator it;
2227         for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2228                 GObjectController *cont = it->second;
2229                 if (cont->getGObjectType() == GCOMPLEXINPUTPORT) {
2230                         vect.push_back(cont->getId());
2231                 }
2232         }
2233         return vect;
2234 }
2235
2236 //=========================================================================
2237
2238 std::vector<int> wxVtkSceneManager::getComplexOutputPorts() {
2239         std::vector<int> vect;
2240         std::map<int, GObjectController*>::iterator it;
2241         for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2242                 GObjectController *cont = it->second;
2243                 if (cont->getGObjectType() == GCOMPLEXOUTPUTPORT) {
2244                         vect.push_back(cont->getId());
2245                 }
2246         }
2247         return vect;
2248 }
2249
2250 //=========================================================================
2251
2252 std::vector<int> wxVtkSceneManager::getConnections() {
2253         std::vector<int> vect;
2254         std::map<int, GObjectController*>::iterator it;
2255         for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2256                 GObjectController *cont = it->second;
2257                 if (cont->getGObjectType() == GCONNECTOR) {
2258                         vect.push_back(cont->getId());
2259                 }
2260         }
2261         return vect;
2262 }
2263
2264 //=========================================================================
2265
2266 bool wxVtkSceneManager::isComplexBox() {
2267         return _isComplexBox;
2268 }
2269
2270 //=========================================================================
2271
2272 void wxVtkSceneManager::setComplexBox(bool val) {
2273         _isComplexBox = val;
2274 }
2275
2276 //=========================================================================
2277
2278 int wxVtkSceneManager::addObjectController(GObjectController* objController) {
2279         //Register the controller of the new object
2280         registerController((InteractorStyleMaracas*) objController);
2281         //Add the object to the objects list
2282         int newId = _contLastId;//_controllers.size();
2283         objController->setId(newId);
2284         _controllers[newId] = objController;
2285         //std::cout << "DFCH: int wxVtkSceneManager::addObjectController(GObjectController* objController) ---- _contLastId = " << _contLastId << std::endl;
2286         _contLastId++;
2287         return newId;
2288 }
2289
2290 //=========================================================================
2291
2292 void wxVtkSceneManager::DuplicateObjects(std::map<int, GObjectController*> objectsMap) {
2293
2294         std::map<int, int> oldIdNewIdBoxes;
2295         std::vector<int> connections;
2296
2297         std::vector<int> newBoxesID;
2298
2299         std::map<int, GObjectController*>::iterator it;
2300         for (it = objectsMap.begin(); it != objectsMap.end(); ++it) {
2301             GObjectController *cont = it->second;
2302             int type = cont->getGObjectType();
2303
2304             if (type == GBLACKBOX) {
2305                 // Copy black box
2306                 double xInic, yInic, zInic;
2307                 GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
2308                 copyBox->getInicPoint(xInic, yInic, zInic);
2309                 int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(),
2310                         copyBox->getBBTKType());
2311
2312                 int idcB = copyBox->getObjectId();
2313                 oldIdNewIdBoxes[idcB] = idBox;
2314                 cont = _controllers[idBox];
2315                 GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
2316                 newbox->setInicPoint(xInic, yInic, zInic);
2317                 int num = newbox->getNumInputPorts();
2318                 for (int j = 0; j < num; j++) {
2319                     newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
2320                 }
2321                 newbox->move(xInic + 20, yInic + 20, zInic);
2322                 newbox->notifyObservers(_idManager);
2323                 newBoxesID.push_back(newbox->getObjectId());
2324
2325             } else if (type == GCONNECTOR) {
2326                 int idCon = cont->getId();
2327                 connections.push_back(idCon);
2328             }
2329
2330         }
2331
2332         for (int i = 0; i < (int) connections.size(); i++) {
2333             int objId = connections[i];
2334             GObjectController *cont = objectsMap[objId];
2335             GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
2336
2337             GPortModel* startPort = connectModel->getStartPort();
2338             int startPortIndex = startPort->getPosInBox();
2339             GPortModel* endPort = connectModel->getEndPort();
2340             int endPortIndex = endPort->getPosInBox();
2341
2342             GBlackBoxModel* startPortParentBox =
2343                     (GBlackBoxModel*) startPort->getParentBox();
2344             GBlackBoxModel* endPortParentBox =
2345                     (GBlackBoxModel*) endPort->getParentBox();
2346
2347             int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2348             int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2349
2350             GBlackBoxModel* newStartBox =
2351                     (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
2352             GBlackBoxModel* newEndBox =
2353                     (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
2354
2355             GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2356             GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2357
2358             // Creates connection
2359             int idCon = createGConnector(newStartPort);
2360             GConnectorController *tempp =
2361                     (GConnectorController*) _controllers[idCon];
2362             GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2363             vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2364             tempp->endContourCreation();
2365             conMod->setEndPort(newEndPort);
2366             conView->updateStartEndPoints();
2367         }
2368
2369         /// the new selected boxes are the duplicate ones
2370
2371         UnSelectBlackBoxes();
2372         for (int i = 0; i < newBoxesID.size(); i++) {
2373             _selectedObjects.push_back(newBoxesID.at(i));
2374         }
2375
2376         for (int i = 0; i < (int) _selectedObjects.size(); i++) {
2377             int id = _selectedObjects[i];
2378             GObjectController* cont = _controllers[id];
2379
2380             cont->getView()->setState(SELECTED);
2381             cont->getModel()->notifyObservers(_idManager);
2382
2383         }
2384     }
2385
2386
2387 //=========================================================================
2388
2389 int wxVtkSceneManager::getNumSelectedObjects() {
2390         return _selectedObjects.size();
2391 }
2392
2393 //=========================================================================
2394
2395 std::map<int, GObjectController*> wxVtkSceneManager::getSelectedObjects() {
2396         std::map<int, GObjectController*> mapSelected;
2397
2398         std::map<int, GObjectController*>::iterator it;
2399         for (it = _controllers.begin(); it != _controllers.end(); ++it) {
2400                 GObjectController *cont = it->second;
2401                 if (cont->getGObjectType() == GBLACKBOX && cont->getView()->getState()
2402                                 == SELECTED) {
2403                         mapSelected[cont->getId()] = cont;
2404                 }
2405         }
2406
2407         std::map<int, GObjectController*>::iterator it2;
2408         for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2) {
2409                 GObjectController *cont = it2->second;
2410                 if (cont->getGObjectType() == GCONNECTOR) {
2411                         GConnectorModel* cmod = (GConnectorModel*) cont->getModel();
2412                         GBoxModel* endPortParentBox = cmod->getEndPort()->getParentBox();
2413                         GBoxModel* startPortParentBox =
2414                                         cmod->getStartPort()->getParentBox();
2415
2416                         std::map<int, GObjectController*>::iterator iterOBJ1 =
2417                                         mapSelected.find(startPortParentBox->getObjectId());
2418                         std::map<int, GObjectController*>::iterator iterOBJ2 =
2419                                         mapSelected.find(endPortParentBox->getObjectId());
2420
2421                         if (iterOBJ1 != mapSelected.end() && iterOBJ2 != mapSelected.end()) {
2422                                 int ID = cont->getId();
2423                                 mapSelected[ID] = cont;
2424                         }
2425                 }
2426         }
2427         return mapSelected;
2428 }
2429
2430 //=========================================================================
2431
2432 void wxVtkSceneManager::addObjects(std::map<int, GObjectController*> objectsMap) {
2433
2434         std::map<int, int> oldIdNewIdBoxes;
2435         std::vector<int> connections;
2436
2437         std::map<int, GObjectController*>::iterator it;
2438         for (it = objectsMap.begin(); it != objectsMap.end(); ++it) {
2439                 GObjectController *cont = it->second;
2440                 int type = cont->getGObjectType();
2441
2442                 if (type == GBLACKBOX) {
2443                         // Copy black box
2444                         double xInic, yInic, zInic;
2445                         GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
2446                         copyBox->getInicPoint(xInic, yInic, zInic);
2447                         int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(),
2448                                         copyBox->getBBTKType());
2449
2450                         int idcB = copyBox->getObjectId();
2451                         oldIdNewIdBoxes[idcB] = idBox;
2452                         cont = _controllers[idBox];
2453                         GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
2454                         newbox->setInicPoint(xInic, yInic, zInic);
2455                         int num = newbox->getNumInputPorts();
2456                         for (int j = 0; j < num; j++) {
2457                                 newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
2458                         }
2459                         newbox->notifyObservers(_idManager);
2460                 } else if (type == GCONNECTOR) {
2461                         int idCon = cont->getId();
2462                         connections.push_back(idCon);
2463                 }
2464
2465         }
2466
2467         for (int i = 0; i < (int) connections.size(); i++) {
2468                 int objId = connections[i];
2469                 GObjectController *cont = objectsMap[objId];
2470                 GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
2471
2472                 GPortModel* startPort = connectModel->getStartPort();
2473                 int startPortIndex = startPort->getPosInBox();
2474                 GPortModel* endPort = connectModel->getEndPort();
2475                 int endPortIndex = endPort->getPosInBox();
2476
2477                 GBlackBoxModel* startPortParentBox =
2478                                 (GBlackBoxModel*) startPort->getParentBox();
2479                 GBlackBoxModel* endPortParentBox =
2480                                 (GBlackBoxModel*) endPort->getParentBox();
2481
2482                 int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
2483                 int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
2484
2485                 GBlackBoxModel* newStartBox =
2486                                 (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
2487                 GBlackBoxModel* newEndBox =
2488                                 (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
2489
2490                 GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
2491                 GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
2492
2493                 // Creates connection
2494                 int idCon = createGConnector(newStartPort);
2495                 GConnectorController *tempp =
2496                                 (GConnectorController*) _controllers[idCon];
2497                 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2498                 vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
2499                 tempp->endContourCreation();
2500                 conMod->setEndPort(newEndPort);
2501                 conView->updateStartEndPoints();
2502         }
2503
2504         std::map<int, int>::iterator itIds;
2505         for (itIds = oldIdNewIdBoxes.begin(); itIds != oldIdNewIdBoxes.end(); ++itIds) {
2506                 int idOld = itIds->first;
2507                 int idNew = itIds->second;
2508
2509                 GBlackBoxModel* oldBox =
2510                                 (GBlackBoxModel*) objectsMap[idOld]->getModel();
2511                 GBlackBoxModel* newBox =
2512                                 (GBlackBoxModel*) _controllers[idNew]->getModel();
2513
2514                 std::vector<int> oldInputConnections = oldBox->getConnectedInputs();
2515                 std::vector<int> oldOutputConnections = oldBox->getConnectedOutputs();
2516                 std::vector<int> newInputConnections = newBox->getConnectedInputs();
2517                 std::vector<int> newOutputConnections = newBox->getConnectedOutputs();
2518
2519                 for (int k = 0; k < (int) oldInputConnections.size(); k++) {
2520                         bool exist = false;
2521                         //EED                           int toCreate=-1;
2522                         for (int l = 0; l < (int) newInputConnections.size() && !exist; l++) {
2523                                 if (oldInputConnections[k] == newInputConnections[l]) {
2524                                         exist = true;
2525                                 }
2526                         }
2527
2528                         if (exist == false) {
2529                                 //Create complex input
2530                                 int posInBox = oldInputConnections[k];
2531                                 GPortModel* inputPort = oldBox->getInputPort(posInBox);
2532                                 std::string inputPortName = inputPort->getBBTKName();
2533                                 int idInputPort = createGComplexBoxInputPort(inputPortName);
2534                                 GObjectController *cont = _controllers[idInputPort];
2535                                 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2536                                 double xIn, yIn, zIn;
2537                                 inputPort->getInicPoint(xIn, yIn, zIn);
2538                                 yIn += 20;
2539                                 cbmod->setInicPoint(xIn, yIn, zIn);
2540                                 cbmod->notifyObservers(_idManager);
2541
2542                                 GPortModel* inputPortEnd = newBox->getInputPort(posInBox);
2543
2544                                 // Creates connection
2545                                 int idCon = createGConnector(cbmod->getOutputPort(0));
2546                                 GConnectorController *tempp =
2547                                                 (GConnectorController*) _controllers[idCon];
2548                                 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2549                                 vtkGConnectorView *conView =
2550                                                 (vtkGConnectorView*) tempp->getView();
2551                                 tempp->endContourCreation();
2552                                 conMod->setEndPort(inputPortEnd);
2553                                 conView->updateStartEndPoints();
2554
2555                         }
2556
2557                 }
2558
2559                 for (int k = 0; k < (int) oldOutputConnections.size(); k++) {
2560                         bool exist = false;
2561                         //EED                           int toCreate=-1;
2562                         for (int l = 0; l < (int) newOutputConnections.size() && !exist; l++) {
2563                                 if (oldOutputConnections[k] == newOutputConnections[l]) {
2564                                         exist = true;
2565                                 }
2566                         }
2567
2568                         if (exist == false) {
2569                                 //Create complex output
2570                                 int posInBox = oldOutputConnections[k];
2571                                 GPortModel* outputPort = oldBox->getOutputPort(posInBox);
2572                                 std::string outputPortName = outputPort->getBBTKName();
2573                                 int idOutputPort = createGComplexBoxOutputPort(outputPortName);
2574                                 GObjectController *cont = _controllers[idOutputPort];
2575                                 GBoxModel *cbmod = (GBoxModel*) cont->getModel();
2576                                 double xIn, yIn, zIn;
2577                                 outputPort->getInicPoint(xIn, yIn, zIn);
2578                                 yIn -= 20;
2579                                 cbmod->setInicPoint(xIn, yIn, zIn);
2580                                 cbmod->notifyObservers(_idManager);
2581
2582                                 GPortModel* outputPortEnd = newBox->getOutputPort(posInBox);
2583
2584                                 // Creates connection
2585                                 int idCon = createGConnector(outputPortEnd);
2586                                 GConnectorController *tempp =
2587                                                 (GConnectorController*) _controllers[idCon];
2588                                 GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
2589                                 vtkGConnectorView *conView =
2590                                                 (vtkGConnectorView*) tempp->getView();
2591                                 tempp->endContourCreation();
2592                                 conMod->setEndPort(cbmod->getInputPort(0));
2593                                 conView->updateStartEndPoints();
2594
2595                         }
2596
2597                 }
2598
2599         }
2600
2601 }
2602
2603 //=========================================================================
2604 void wxVtkSceneManager::SetCbName(std::string cbName) {
2605         _cbName = cbName;
2606         if (_cbName == "") {
2607                 _cbName = "<complex box name>";
2608         }
2609 }
2610
2611 //=========================================================================
2612 std::string wxVtkSceneManager::GetCbName() {
2613         return _cbName;
2614 }
2615
2616 //=========================================================================
2617 void wxVtkSceneManager::SetCbPackageName(std::string packagename) {
2618         _cbPackageName = packagename;
2619         if (_cbPackageName == "") {
2620                 _cbPackageName = "<package name of the complex box>";
2621         }
2622 }
2623
2624 //=========================================================================
2625 std::string wxVtkSceneManager::GetCbPackageName() {
2626         return _cbPackageName;
2627 }
2628
2629 //=========================================================================
2630 void wxVtkSceneManager::SetAuthor(std::string author) {
2631         _Author = author;
2632         if (_Author == "") {
2633                 _Author = "<author of the box>";
2634         }
2635 }
2636
2637 //=========================================================================
2638 std::string wxVtkSceneManager::GetAuthor() {
2639         return _Author;
2640 }
2641
2642 //=========================================================================
2643 void wxVtkSceneManager::SetCategory(std::string category) {
2644         _Category = category;
2645         if (_Category == "") {
2646                 _Category = "<category of the box>";
2647         }
2648 }
2649
2650 //=========================================================================
2651 std::string wxVtkSceneManager::GetCategory() {
2652         return _Category;
2653 }
2654
2655 //=========================================================================
2656 void wxVtkSceneManager::SetDescription(std::string description) {
2657         _Description = description;
2658         if (_Description == "") {
2659                 _Description = "<description of the box>";
2660         }
2661 }
2662
2663 //=========================================================================
2664 std::string wxVtkSceneManager::GetDescription() {
2665         return _Description;
2666 }
2667
2668 //=========================================================================
2669
2670
2671 void wxVtkSceneManager::printAll(int com , int sta ){
2672         
2673          int tmpState = sta ;
2674         if ( tmpState == NOTHING_HAPPENS ) {
2675             std::cout << "CONTROLER STATE---->NOTHING_HAPPENS\n" ;
2676         }
2677         if ( tmpState == HIGHLIGHTED ) {
2678             std::cout << "CONTROLER STATE---->HIGHLIGHTED\n" ;
2679         }
2680         if ( tmpState == POSSIBLE_CONNECTION ) {
2681             std::cout << "CONTROLER STATE---->POSSIBLE_CONNECTION\n" ;
2682         }
2683         if ( tmpState == SELECTED_POSSIBLE_CONNECTION ) {
2684             std::cout << "CONTROLER STATE---->SELECTED_POSSIBLE_CONNECTION\n" ;
2685         }
2686         if ( tmpState == CLICKED ) {
2687             std::cout << "CONTROLER STATE---->CLICKED\n" ;
2688         }
2689         if ( tmpState == DRAG ) {
2690             std::cout << "CONTROLER STATE---->DRAG\n" ;
2691         }
2692         if ( tmpState == SELECTED ) {
2693             std::cout << "CONTROLER STATE---->SELECTED\n" ;
2694         }
2695         if ( tmpState == CREATING_CONTOUR ) {
2696             std::cout << "CONTROLER STATE---->CREATING_CONTOUR\n" ;
2697         }   
2698          
2699          // :P 
2700
2701         int command = com ;
2702         if ( command == INIT_CREATION_CONTOUR ) {
2703             std::cout << "COMMAND ----> INIT_CREATION_CONTOUR \n" ;
2704         }
2705         if ( command == FIN_CREATION_CONTOUR ) {
2706             std::cout << "COMMAND ----> FIN_CREATION_CONTOUR \n" ;
2707         }
2708         if ( command == ADD_TO_SELECTED ) {
2709             std::cout << "COMMAND ----> ADD_TO_SELECTED \n" ;
2710         }
2711         if ( command == DRAG_OBJECTS ) {
2712             std::cout << "COMMAND ----> DRAG_OBJECTS \n" ;
2713         }
2714         if ( command == EDIT_BLACKBOX ) {
2715             std::cout << "COMMAND ----> EDIT_BLACKBOX \n" ;
2716         }
2717         if ( command == REMOVE_FROM_SELECTED ) {
2718             std::cout << "COMMAND ----> REMOVE_FROM_SELECTED \n" ;
2719         }
2720         
2721     }
2722
2723
2724 } // EO namespace bbtk
2725
2726 // EOF
2727