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