]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxVtkSceneManager.cxx
Bug #1374 - Drag and drop
[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
65 //#ifdef __APPLE__
66                 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget((wxDropTarget*)parent);
67 //#endif
68
69                 configureBaseView();
70                 _worldState = NOTHING_HAPPENS;
71                 registerController(this);
72
73         }
74         _idConnectionInCreation = -1;
75         _contLastId = 0;
76
77 }
78
79 //=========================================================================
80
81 void wxVtkSceneManager::disconnectDrop() {
82         printf("EED %p ~wxVtkSceneManager::disconnectDrop()\n", this);
83         //EED02JUIN2010         _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget(NULL);
84         //      _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget( new tmpClasswxTextDropTarget() );
85 }
86
87 //=========================================================================
88
89 wxVtkSceneManager::~wxVtkSceneManager() {
90         //FCY memory leaks
91         printf("EED %p ~wxVtkSceneManager() START\n", this);
92         disconnectDrop();
93         delete _baseView;
94         printf("EED %p ~wxVtkSceneManager() END\n", this);
95 }
96
97 //=========================================================================
98
99 void wxVtkSceneManager::configureBaseView() {
100         printf("EED wxVtkSceneManager::configureBaseView 0\n");
101         vtkInteractorStyleBaseView2D *interactorstylebaseview =
102                         vtkInteractorStyleBaseView2D::New();
103
104         _baseView->SetInteractorStyleBaseView(interactorstylebaseview);
105
106         // Important to activate the 2D interaction system
107         wxVTKRenderWindowInteractor *iren =
108                         _baseView->GetWxVTKRenderWindowInteractor();
109         interactorstylebaseview->SetInteractor(iren);
110         iren->SetInteractorStyle(interactorstylebaseview);
111         interactorstylebaseview->SetwxVtkBaseView(_baseView);
112
113         _baseView->GetRenderer()->GetActiveCamera()->ParallelProjectionOn();
114         _baseView->GetRenderer()->ResetCamera(-100, 100, -100, 100, 800, 1100);
115
116         _baseView->GetRenderer()->SetBackground(0.9, 0.9, 0.9);
117         _baseView->GetRenderer()->GradientBackgroundOn();
118         _baseView->Refresh();
119
120         // Actos Port_Text
121         _textActor = vtkTextActor3D::New();
122         _textActor->SetPosition(-9999, -9999, 900);
123         _textActor->SetInput("<void>");
124         _textActor->GetTextProperty()->SetFontSize(60);
125         _textActor->GetTextProperty()->BoldOn();
126         _textActor->GetTextProperty()->SetColor(PORTTEXT_NH_R, PORTTEXT_NH_G,
127                         PORTTEXT_NH_B);
128
129         _baseView->GetRenderer()->AddActor(_textActor);
130
131         // Actor  Fill_Port_Text
132
133         //------------
134         double xInic = 0;
135         double yInic = 0;
136         double zInic = 900;
137
138         vtkPolygon *aPolygon = vtkPolygon::New();
139         _fillObjectActor = vtkActor::New();
140
141         _pts = vtkPoints::New();
142
143         double w = 100, h = 10, b = h / 15, t = 3;
144         _pts->SetNumberOfPoints(21);
145         _pts->InsertPoint(0, xInic + w * 0.33 - t / 2, yInic, zInic);
146         _pts->InsertPoint(1, xInic + w * 0.33, yInic - t, zInic);
147         _pts->InsertPoint(2, xInic + w * 0.33 + t / 2, yInic, zInic);
148         _pts->InsertPoint(3, xInic + w * 0.33 + t / 2, yInic, zInic);
149         _pts->InsertPoint(4, xInic + w - b * 4, yInic + b * 0, zInic);
150
151         _pts->InsertPoint(5, xInic + w - b * 4, yInic + b * 0, zInic);
152         _pts->InsertPoint(6, xInic + w - b * 2, yInic + b * 1, zInic);
153         _pts->InsertPoint(7, xInic + w - b * 1, yInic + b * 2, zInic);
154         _pts->InsertPoint(8, xInic + w - b * 0, yInic + b * 4, zInic);
155
156         _pts->InsertPoint(9, xInic + w - b * 0, yInic + h - b * 4, zInic);
157         _pts->InsertPoint(10, xInic + w - b * 1, yInic + h - b * 2, zInic);
158         _pts->InsertPoint(11, xInic + w - b * 2, yInic + h - b * 1, zInic);
159         _pts->InsertPoint(12, xInic + w - b * 4, yInic + h - b * 0, zInic);
160
161         _pts->InsertPoint(13, xInic + b * 4, yInic + h - b * 0, zInic);
162         _pts->InsertPoint(14, xInic + b * 2, yInic + h - b * 1, zInic);
163         _pts->InsertPoint(15, xInic + b * 1, yInic + h - b * 2, zInic);
164         _pts->InsertPoint(16, xInic + b * 0, yInic + h - b * 4, zInic);
165
166         _pts->InsertPoint(17, xInic + b * 0, yInic + b * 4, zInic);
167         _pts->InsertPoint(18, xInic + b * 1, yInic + b * 2, zInic);
168         _pts->InsertPoint(19, xInic + b * 2, yInic + b * 1, zInic);
169         _pts->InsertPoint(20, xInic + b * 4, yInic + b * 0, zInic);
170
171         aPolygon->GetPointIds()->SetNumberOfIds(21);
172         for (int i = 0; i < 21; i++) {
173                 aPolygon->GetPointIds()->SetId(i, i);
174         }
175
176         vtkUnstructuredGrid *aPolygonGrid = vtkUnstructuredGrid::New();
177         aPolygonGrid->Allocate(1, 1);
178         aPolygonGrid->InsertNextCell(aPolygon->GetCellType(),
179                         aPolygon->GetPointIds());
180         aPolygonGrid->SetPoints(_pts);
181         _aPolygonMapper = vtkDataSetMapper::New();
182         _aPolygonMapper->SetInput(aPolygonGrid);
183         _fillObjectActor->SetMapper(_aPolygonMapper);
184         _fillObjectActor->GetProperty()->SetColor(PORTFILL_NH_R, PORTFILL_NH_G,
185                         PORTFILL_NH_B);
186         _fillObjectActor->GetProperty()->SetOpacity(0);
187         _aPolygonMapper->Modified();
188
189         _baseView->GetRenderer()->AddActor(_fillObjectActor);
190         printf("EED wxVtkSceneManager::configureBaseView 1\n");
191 }
192
193 //=========================================================================
194
195 std::string wxVtkSceneManager::generateANewNameForABox() {
196         std::stringstream boxname;
197         if (_numBoxes < 10) {
198                 boxname << "Box0" << _numBoxes;
199         } else {
200                 boxname << "Box" << _numBoxes;
201         }
202         _numBoxes++;
203         return boxname.str();
204 }
205
206 //=========================================================================
207
208 std::string wxVtkSceneManager::findANewNameForABox() {
209         std::string boxname = generateANewNameForABox();
210
211         while (boxExist(boxname) == true) {
212                 boxname = generateANewNameForABox();
213         } // while
214
215         return boxname;
216 }
217
218 //=========================================================================
219 void wxVtkSceneManager::configGBlackBox(int idBox, double xIn, double yIn,
220                 double zIn, std::string name, bool boxExecutable, double xEn,
221                 double yEn, double zEn) {
222         GObjectController *cont = _controllers[idBox];
223         GBlackBoxModel *bbmod = (GBlackBoxModel*) cont->getModel();
224         bbmod->setBBTKName(name);
225         bbmod->setInicPoint(xIn, yIn, zIn);
226         bbmod->setFinalPoint(xEn, yEn, zEn);
227         bbmod->setExecutable(boxExecutable);
228
229         bbmod->notifyObservers(_idManager);
230
231 }
232
233 //=========================================================================
234
235 int wxVtkSceneManager::createGBlackBox(int x, int y, std::string packageName,
236                 std::string boxType) {
237         _worldState = NOTHING_HAPPENS;
238         //EED           int windowWidth                                                 = _baseView->GetRenWin()->GetSize()[0];
239         int windowHeight = _baseView->GetRenWin()->GetSize()[1];
240
241         int type = GBLACKBOX;
242
243         //Create the MVC Objects
244
245         GBlackBoxModel
246                         *model =
247                                         (GBlackBoxModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(
248                                                         type);
249         vtkGObjectView *view =
250                         GObjectsMVCFactory::getInstance()->createGObjectView(type);
251         GObjectController* controller =
252                         GObjectsMVCFactory::getInstance()->createGObjectController(type);
253
254         BlackBoxDescriptor::Pointer descriptor =
255                         GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(
256                                         packageName, boxType);
257
258         //Prepares the initial model
259         //The coordinates obtained are the following. Top-Left:x=0,y=0 Bottom-Right:x=width,y=height
260
261         double xx = x;
262         double yy = windowHeight - y;
263
264         //z value is not important yet, because it is only used a parallel projection
265         double zz = 900;
266         _baseView->TransCoordScreenToWorld(xx, yy, zz);
267         model->setInicPoint(xx, yy, zz);
268
269         std::stringstream stream;
270
271         std::string newBoxName;
272         newBoxName = findANewNameForABox();
273
274         stream << newBoxName;
275
276         std::string arraystring = stream.str();
277
278         model->setBBTKName(arraystring);
279         model->setBBTKType(boxType);
280         model->setBBTKPackage(packageName);
281
282         model->addObserver(view);
283         model->addObserver(this);
284
285         //Iterate and create the input ports
286         std::map<std::string, BlackBoxInputDescriptor*> descriptorInMap =
287                         descriptor->GetInputDescriptorMap();
288         std::map<std::string, BlackBoxInputDescriptor*>::iterator itInput;
289
290         int i = 0;
291         for (itInput = descriptorInMap.begin(); itInput != descriptorInMap.end(); ++itInput) {
292                 BlackBoxInputDescriptor *desc = itInput->second;
293                 createGInputPort(GINPUTPORT, i, model, desc);
294                 i++;
295         }
296
297         //Iterate and create the output ports
298         std::map<std::string, BlackBoxOutputDescriptor*> descriptorOutMap =
299                         descriptor->GetOutputDescriptorMap();
300         std::map<std::string, BlackBoxOutputDescriptor*>::iterator itOutput;
301
302         i = 0;
303         for (itOutput = descriptorOutMap.begin(); itOutput
304                         != descriptorOutMap.end(); ++itOutput) {
305                 BlackBoxOutputDescriptor *desc = itOutput->second;
306                 createGOutputPort(GOUTPUTPORT, i, model, desc);
307                 i++;
308         }
309
310         //Associates the view with the correspondent renderer and the  model.
311         //(NOTE: Refresh is only made by the view)
312         view->setModel(model);
313         view->setBaseView(_baseView);
314         view->initVtkObjects();
315
316         //Associates the controller with the correspondent model and view
317         controller->setModelAndView(model, view);
318
319         //Resgiter change to the observers of the actual model
320         model->notifyObservers(_idManager);
321
322         int newId = addObjectController(controller);
323
324         return newId;
325
326 }
327
328 //=========================================================================
329
330 int wxVtkSceneManager::createGComplexBoxInputPort(std::string inputName) {
331         //EED           int windowWidth=_baseView->GetRenWin()->GetSize()[0];
332         int windowHeight = _baseView->GetRenWin()->GetSize()[1];
333
334         int type = GCOMPLEXINPUTPORT;
335
336         //Create the MVC Objects
337
338         GComplexBoxPortModel
339                         *model =
340                                         (GComplexBoxPortModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(
341                                                         type);
342         vtkGObjectView *view =
343                         GObjectsMVCFactory::getInstance()->createGObjectView(type);
344         GObjectController* controller =
345                         GObjectsMVCFactory::getInstance()->createGObjectController(type);
346
347         //Prepares the initial model
348
349         double xx = 5;
350         double yy = windowHeight - 5;
351
352         //z value is not important yet, because it is only used a parallel projection
353         double zz = 900;
354         printf("EED  wxVtkSceneManager::createGComplexBoxInputPort 900-450\n");
355
356         _baseView->TransCoordScreenToWorld(xx, yy, zz);
357         model->setInicPoint(xx, yy, zz);
358
359         model->setBBTKName(inputName);
360         model->setBBTKType("ComplexInputPort");
361         model->setComplexPortType(type);
362
363         model->addObserver(view);
364         model->addObserver(this);
365
366         //create the output port
367         GPortController* portController = createGPort(GOUTPUTPORT, inputName,
368                         "ComplexInputPort", 0, model);
369         model->addOutputPort((GPortModel*) portController->getModel());
370
371         //Associates the view with the correspondent renderer and the  model.
372         //(NOTE: Refresh is only made by the view)
373         view->setModel(model);
374         view->setBaseView(_baseView);
375         view->initVtkObjects();
376
377         //Associates the controller with the correspondent model and view
378         controller->setModelAndView(model, view);
379
380         //Resgiter change to the observers of the actual model
381         model->notifyObservers(_idManager);
382
383         int newId = addObjectController(controller);
384         return newId;
385 }
386
387 //=========================================================================
388
389 int wxVtkSceneManager::createGComplexBoxOutputPort(std::string outputName) {
390         //EED           int windowWidth=_baseView->GetRenWin()->GetSize()[0];
391         int windowHeight = _baseView->GetRenWin()->GetSize()[1];
392
393         int type = GCOMPLEXOUTPUTPORT;
394
395         //Create the MVC Objects
396
397         GComplexBoxPortModel
398                         *model =
399                                         (GComplexBoxPortModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(
400                                                         type);
401         vtkGObjectView *view =
402                         GObjectsMVCFactory::getInstance()->createGObjectView(type);
403         GObjectController *controller =
404                         GObjectsMVCFactory::getInstance()->createGObjectController(type);
405
406         //Prepares the initial model
407
408         double xx = 5;
409         double yy = windowHeight - 5;
410
411         //z value is not important yet, because it is only used a parallel projection
412         double zz = 900;
413
414         printf("EED  wxVtkSceneManager::createGComplexBoxOutputPort 900-450\n");
415
416         _baseView->TransCoordScreenToWorld(xx, yy, zz);
417         model->setInicPoint(xx, yy, zz);
418
419         model->setBBTKName(outputName);
420         model->setBBTKType("ComplexOutputPort");
421         model->setComplexPortType(type);
422
423         model->addObserver(view);
424         model->addObserver(this);
425
426         //create the output port
427         GPortController* portController = createGPort(GINPUTPORT, outputName,
428                         "ComplexInputPort", 0, model);
429         model->addInputPort((GPortModel*) portController->getModel());
430
431         //Associates the view with the correspondent renderer and the  model.
432         //(NOTE: Refresh is only made by the view)
433         view->setModel(model);
434         view->setBaseView(_baseView);
435         view->initVtkObjects();
436
437         //Associates the controller with the correspondent model and view
438         controller->setModelAndView(model, view);
439
440         //Resgiter change to the observers of the actual model
441         model->notifyObservers(_idManager);
442
443         int newId = addObjectController(controller);
444         return newId;
445 }
446
447 //=========================================================================
448
449 int wxVtkSceneManager::createGInputPort(int portType, int posinBox,
450                 GBoxModel *blackBox, BlackBoxInputDescriptor *desc) {
451         GPortController* portController = createGPort(portType, desc->GetName(),
452                         desc->GetTypeName(), posinBox, blackBox);
453         blackBox->addInputPort((GPortModel*) portController->getModel());
454         return portController->getId();
455 }
456
457 //=========================================================================
458
459 int wxVtkSceneManager::createGOutputPort(int portType, int posinBox,
460                 GBoxModel *blackBox, BlackBoxOutputDescriptor *desc) {
461         GPortController* portController = createGPort(portType, desc->GetName(),
462                         desc->GetTypeName(), posinBox, blackBox);
463         blackBox->addOutputPort((GPortModel*) portController->getModel());
464         return portController->getId();
465 }
466
467 //=========================================================================
468
469 GPortController* wxVtkSceneManager::createGPort(int portType,
470                 std::string bbtkName, std::string bbtkType, int posInBox,
471                 GBoxModel *blackBox) {
472         int type = GPORT;
473
474         //Create the MVC Objects
475         GPortModel
476                         *model =
477                                         (GPortModel*) GObjectsMVCFactory::getInstance()->createGObjectModel(
478                                                         type);
479         vtkGObjectView *view =
480                         GObjectsMVCFactory::getInstance()->createGObjectView(type);
481         GObjectController* controller =
482                         GObjectsMVCFactory::getInstance()->createGObjectController(type);
483
484         model->registerInBox(blackBox, portType, posInBox);
485
486         model->setBBTKType(bbtkType);
487         model->setBBTKName(bbtkName);
488
489         model->addObserver(view);
490         model->addObserver(this);
491
492         //Associates the view with the correspondent renderer and the  model.
493         //(NOTE: Refresh is only made by the view)
494         view->setModel(model);
495         view->setBaseView(_baseView);
496         view->initVtkObjects();
497
498         //Associates the controller with the correspondent model and view
499         controller->setModelAndView(model, view);
500
501         model->notifyObservers(_idManager);
502
503         addObjectController(controller);
504
505         return (GPortController*) controller;
506 }
507
508 //=========================================================================
509
510 int wxVtkSceneManager::createGConnector(GPortModel* startPort) {
511         int type = GCONNECTOR;
512
513         manualConnectorContourController* manContourControl =
514                         new manualConnectorContourController();
515         manualConnectorContourView* manContourView =
516                         new manualConnectorContourView();
517         manualContourModel* manContourModel = new manualContourModel();
518
519         GConnectorController* connectorcontroller = new GConnectorController();
520         GConnectorModel* connectorModel = new GConnectorModel();
521         vtkGConnectorView* connectorView = new vtkGConnectorView();
522         connectorModel->setGObjectType(type);
523
524         manContourModel->SetCloseContour(false);
525         connectorModel->setStartPort(startPort);
526
527         manContourView->SetModel(manContourModel);
528         manContourView->SetWxVtkBaseView(_baseView);
529         manContourView->SetRange(0.5);
530         manContourView->SetZ(900);
531
532         manContourView->SetColorNormalContour(0, 0, 1);
533         manContourView->SetColorEditContour(0.5, 0.5, 0.5);
534         manContourView->SetColorSelectContour(1, 0.8, 0);
535         
536         /**
537          * JGRR AND CM
538          * Width increased from 2 to 5, it simplifies line handling and spline control :P
539          * @param WidthLine  
540          */ 
541         manContourView->SetWidthLine( 3 ) ;
542         manContourView->SetShowText(false);
543
544         manContourControl->SetModelView(manContourModel, manContourView);
545
546         manContourControl->CreateNewManualContour();
547
548         manContourView->RefreshContour();
549
550         double x, y, z;
551         connectorModel->getInicPoint(x, y, z);
552
553         manContourControl->SetState(1);
554         manContourModel->SetCloseContour(false);
555
556         manContourModel->AddPoint(x, y, z);
557         manContourView->AddPoint();
558
559         manContourModel->AddPoint(x, y, z);
560         manContourView->AddPoint();
561
562         int bak = manContourControl->GetNumberOfPointsManualContour() - 1;
563         manContourControl->_bakIdPoint = bak;
564         manContourView->Refresh();
565
566         manContourControl->SetMoving(false);
567
568         connectorcontroller->setModelAndView(connectorModel, connectorView);
569
570         int newId = addObjectController(connectorcontroller);
571
572         connectorcontroller->setManualContourController(manContourControl);
573         connectorModel->setManualContourModel(manContourModel);
574         connectorView->setManualContourView(manContourView);
575         connectorView->setModel(connectorModel);
576         connectorView->setBaseView(_baseView);
577
578         connectorModel->addObserver(connectorView);
579         connectorModel->addObserver(this);
580
581         return newId;
582 }
583
584 //=========================================================================
585
586 void wxVtkSceneManager::registerController(InteractorStyleMaracas *param) {
587         vtkInteractorStyleBaseView
588                         * baseViewControlManager =
589                                         (vtkInteractorStyleBaseView*) _baseView->GetInteractorStyleBaseView();
590         baseViewControlManager->AddInteractorStyleMaracas(param);
591 }
592
593 //=========================================================================
594
595 void wxVtkSceneManager::unregisterController(InteractorStyleMaracas *param) {
596         vtkInteractorStyleBaseView
597                         * baseViewControlManager =
598                                         (vtkInteractorStyleBaseView*) _baseView->GetInteractorStyleBaseView();
599         baseViewControlManager->RemoveInteractorStyleMaracas(param);
600 }
601
602 //=========================================================================
603
604 vtkRenderer* wxVtkSceneManager::getRenderer() {
605         return _baseView->GetRenderer();
606 }
607
608 //=========================================================================
609
610 vtkRenderWindow* wxVtkSceneManager::getRenderWindow() {
611         return _baseView->GetRenWin();
612 }
613 //=========================================================================
614
615
616 //=========================================================================
617 int wxVtkSceneManager::GetIndexInSelected(int idControler) {
618         int index = -1;
619         for (int i = 0; i < (int) _selectedObjects.size(); i++) {
620                 if (_selectedObjects[i] == idControler) {
621                         index = i;
622                         break;
623                 }
624         }
625         return index;
626 }
627 //=========================================================================
628
629 void wxVtkSceneManager::update(int idController, int command) {
630
631         if (command != NO_COMMAND) {
632                 if (command == ADD_TO_SELECTED) {
633                         //EEDBorrame                            GObjectController* cont = _controllers[idController];
634
635                         if (GetIndexInSelected(idController) == -1) {
636                                 _selectedObjects.push_back(idController);
637                         }
638
639                         //EEDBorrame
640                         //                              bool foundID=false;
641                         //                              for (int i=0; i<(int)_selectedObjects.size() && foundID==false; i++)
642                         //                              {
643                         //                                      if(_selectedObjects[i]==idController)
644                         //                                      {
645                         //                                              foundID = true;
646                         //                                      }
647                         //                              }
648                         //                              if(!foundID)
649                         //                              {
650                         //                                      _selectedObjects.push_back(idController);
651                         //                              }
652
653                 } else if (command == REMOVE_FROM_SELECTED) {
654                         int index = GetIndexInSelected(idController);
655                         if (index >= 0) {
656                                 _selectedObjects.erase(_selectedObjects.begin() + index);
657                         }
658                 } else if (command == INIT_CREATION_CONTOUR) {
659
660                 // JGRR & CM WH
661                 typedef std::map<int , GObjectController*>::iterator TIterator ;
662                 TIterator iter ;
663                 TIterator iter_end ;
664                 // Find current item in the controller
665                 iter = _controllers.find( idController ) ;
666                 iter_end = _controllers.end( ) ;
667                 // If item exist 
668                 if ( iter != iter_end ) {
669                     GObjectController* gobjc = iter->second ;
670
671                     std::string bbtkType = gobjc->getModel( )->getBBTKType( ) ;
672                     // And if the item is a port
673                     if ( gobjc->getModel( )->getGObjectType( ) == GPORT ) {
674                         TIterator c_it = _controllers.begin( ) ;
675                         // Go through all componets 
676                         for ( c_it ; c_it != iter_end ; c_it++ ) {
677                             GObjectController* obc = c_it->second ;
678                             int obc_type = obc->getModel( )->getGObjectType( ) ;
679                             std::string obc_bbtkType = obc->getModel( )->getBBTKType( ) ;
680                             // if the component is a port and the type is the same of that selected
681                             if ( ( obc_type == GPORT ) && ( obc_bbtkType == bbtkType ) ) {
682                                 // Highliht element 
683                                 obc->getView( )->setState( POSSIBLE_CONNECTION ) ;                             
684                                 //obc->getView( )->setState( HIGHLIGHTED ) ;
685                             }
686                         }
687                     }
688                 }
689
690                 // EO JGRR & CM WH  
691                      
692                         _worldState = INIT_CREATION_CONTOUR;
693                         GObjectController* cont = _controllers[idController];
694                         GPortModel* startOutputPort = (GPortModel*) cont->getModel();
695
696                         // The last one is the controller of the connector
697                         std::map<int, GObjectController*>::iterator it2;
698
699                         for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2) {
700                                 GObjectController *cont = it2->second;
701                                 if (cont->getGObjectType() == GPORT) {
702                                         GPortModel* port = (GPortModel*) cont->getModel();
703                                         if (port->getPortType() == GINPUTPORT) {
704                                                 cont->SetActive(true);
705                                         } else {
706                                                 cont->getView()->setState(NOTHING_HAPPENS);
707                                                 cont->getModel()->notifyObservers(_idManager);
708                                                 cont->SetActive(false);
709                                         }
710                                 } else {
711                                         cont->getView()->setState(NOTHING_HAPPENS);
712                                         cont->getModel()->notifyObservers(_idManager);
713                                         cont->SetActive(false);
714                                 }
715                         }
716                         _selectedObjects.clear();
717                         _idConnectionInCreation = createGConnector(startOutputPort);
718                 } else if (command == FIN_CREATION_CONTOUR && _worldState
719                                 == INIT_CREATION_CONTOUR) {
720                         _worldState = NOTHING_HAPPENS;
721                         //int id = _controllers.size()-1;
722                         GObjectController *cont = _controllers[_idConnectionInCreation];
723                         GConnectorModel *modelContour = (GConnectorModel*) cont->getModel();
724                         GObjectController *finPort = _controllers[idController];
725
726                         if (finPort->getGObjectType() == GPORT) {
727                                 GPortModel* modelPort = (GPortModel*) finPort->getModel();
728                                 modelContour->setEndPort(modelPort);
729
730                                 // JGRR CM                     
731                                 typedef std::map<int, GObjectController*>::iterator TIterator;
732                                 TIterator c_it = _controllers.begin();
733                                 TIterator iter_end = _controllers.end();
734                                 // Go through all componets 
735                                 for (c_it; c_it != iter_end; c_it++) {
736                                     GObjectController* obc = c_it->second;
737                                     int obc_type = obc->getModel()->getGObjectType();
738                                     int obc_state = obc->getView()->getState();
739                                     // if the component is a port and the type is the same of that selected
740                                     if ((obc_type == GPORT) && (obc_state == POSSIBLE_CONNECTION)) {
741                                         // Return element to neutral state if not selected
742                                         obc->getView()->setState(NOTHING_HAPPENS);
743                                     }
744                                     if ((obc_type == GPORT) && (obc_state == SELECTED_POSSIBLE_CONNECTION)) {
745                                         // Change element to connected state
746                                         obc->getView()->setState(HIGHLIGHTED);
747
748                                     }
749
750                                 }
751                                 // EO JGRR CM                                
752                     
753                                 _parent->saveTempDiagram();
754                         }
755
756                         manualConnectorContourController
757                                         * manCont =
758                                                         ((GConnectorController*) cont)->getManualContourController();
759                         manualConnectorContourView
760                                         * connView =
761                                                         (manualConnectorContourView*) manCont->GetManualViewBaseContour();
762                         connView->Refresh();
763
764                         std::map<int, GObjectController*>::iterator it2;
765
766                         for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2) {
767                                 GObjectController *cont = it2->second;
768                                 if (cont->getView() != NULL) {
769                                         cont->getView()->setState(NOTHING_HAPPENS);
770                                         cont->getModel()->notifyObservers(_idManager);
771                                 }
772                                 cont->SetActive(true);
773                         }
774                 }
775
776         }
777
778 }
779
780 //=========================================================================
781
782 bool wxVtkSceneManager::OnMouseMove() {
783         int X, Y;
784         bool okStatusMessage = false;
785         bool okPortMessage = false;
786         wxVTKRenderWindowInteractor *wxVTKiren;
787         wxVTKiren
788                         = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
789         wxVTKiren->GetEventPosition(X, Y);
790
791         if (_worldState == DRAG_OBJECTS) {
792                 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
793                         int id = _selectedObjects[i];
794                         GObjectController* cont = _controllers[id];
795                         if (_startDragging) {
796                                 cont->getView()->setStartDragging(true);
797                         }
798                         cont->getView()->moveObject(X, Y);
799                         cont->getView()->setState(DRAG);
800                         cont->getModel()->notifyObservers(_idManager);
801                 }
802
803                 std::map<int, GObjectController*>::iterator it;
804
805                 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
806                         GObjectController *desc = it->second;
807                         if (desc->getGObjectType() == GCONNECTOR) {
808                                 vtkGConnectorView* vconn = (vtkGConnectorView*) desc->getView();
809                                 vconn->updateStartEndPoints();
810                         }
811                 }
812
813                 _startDragging = false;
814
815         } else if (_worldState == NOTHING_HAPPENS || _worldState
816                         == INIT_CREATION_CONTOUR) {
817                 std::map<int, GObjectController*>::iterator it;
818                 double px, py, pz;
819                 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
820                         GObjectController *desc = it->second;
821                         int type = desc->getGObjectType();
822                         int state = desc->getView()->getState();
823                         desc->getModel()->getCenter(px, py, pz);
824
825                         // JGRR & CM
826                         if ((state == HIGHLIGHTED) || (state == SELECTED_POSSIBLE_CONNECTION )) {
827                         // EO JGRR & CM    
828                                 okStatusMessage = true;
829                                 updateStatusBar(desc->getStatusText());
830                                 if (type == GBLACKBOX) {
831                                         GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
832                                         _parent->displayBlackBoxInfo(mod->getBBTKPackage(),
833                                                         mod->getBBTKType());
834                                 } // if GBLACKBOX
835                                 if (type == GPORT) {
836                                         // PortText
837                                         okPortMessage = true;
838                                         py = py + 5;
839                                         _textActor->SetInput(desc->getStatusText().c_str());
840                                         _textActor->SetScale(0.1);
841                                         _textActor->SetPosition(px - 25, py + 1, pz + 2);
842
843                                         // FillPortText
844                                         px = px - 33;
845                                         py = py;
846                                         _fillObjectActor->SetScale(1);
847                                         _fillObjectActor->GetProperty()->SetOpacity(0.50);
848                                         _fillObjectActor->SetPosition(px, py, 1);
849                                         _aPolygonMapper->Modified();
850                                 } // if GPORT
851
852                         } // for controllers it
853                 }
854         }
855         if (okStatusMessage == false) {
856                 updateStatusBar("");
857         }
858
859         if (okPortMessage == false) {
860                 _textActor->SetScale(0.0001);
861                 _fillObjectActor->SetScale(0.0001);
862         }
863         return true;
864 }
865
866 //=========================================================================
867
868 bool wxVtkSceneManager::OnLeftButtonDown() {
869
870         if (_worldState == INIT_CREATION_CONTOUR) {
871                 bool isOverPort = false;
872                 std::map<int, GObjectController*>::iterator it;
873                 for (it = _controllers.begin(); it != _controllers.end() && isOverPort
874                                 == false; ++it) {
875                         GObjectController *desc = it->second;
876                         if (desc->getGObjectType() == GPORT) {
877                                 GPortModel *portmod = (GPortModel*) desc->getModel();
878                                 vtkGObjectView *portView = desc->getView();
879                                 if (portmod->getPortType() == GINPUTPORT
880                                                 && portView->getState() == HIGHLIGHTED) {
881                                         isOverPort = true;
882                                  } // if
883                                 // JGRR & CM                    
884                                 if ( portmod->getPortType( ) == GINPUTPORT &&  portView->getState( ) == SELECTED_POSSIBLE_CONNECTION   ) {
885                                     isOverPort = true ;
886                                     portView->setState( HIGHLIGHTED);
887                                 }                    
888                                 // EO JGRR & CM 
889
890                         } // if
891                 } // for
892
893                 if (isOverPort == false) {
894                         CancelConnection();
895                         UnSelectBlackBoxes();
896                 } // isOverPort
897         
898
899         } else { //_worldState
900
901                 _worldState = DRAG_OBJECTS;
902                 _startDragging = true;
903
904                 int shiftkey =
905                                 _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey();
906                 int ctrlkey =
907                                 _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
908                 ctrlkey = ctrlkey + shiftkey;
909
910                 GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
911
912                 if (GetGBlackBoxControlerPointedByMouse() != NULL) {
913                         int state = cont->getView()->getState();
914                         if ((ctrlkey == 0) && (state == HIGHLIGHTED)) {
915                                 UnSelectBlackBoxes();
916                         }
917                 }
918                 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
919                         int id = _selectedObjects[i];
920                         GObjectController* cont = _controllers[id];
921                         cont->getView()->setState(DRAG);
922                         cont->getModel()->notifyObservers(_idManager);
923                 } // for
924                 
925         } // if _selectedObjects.size
926
927
928         return true;
929 }
930
931 //=========================================================================
932
933 bool wxVtkSceneManager::OnLeftButtonUp() {
934         if (_worldState == DRAG_OBJECTS) {
935                 _worldState = NOTHING_HAPPENS;
936
937                 for (int i = 0; i < (int) _selectedObjects.size(); i++) {
938                         int id = _selectedObjects[i];
939                         GObjectController* cont = _controllers[id];
940                         cont->getView()->setState(SELECTED);
941                         cont->getModel()->notifyObservers(_idManager);
942                 }
943         }
944         return true;
945 }
946
947 //=========================================================================
948 void wxVtkSceneManager::CancelConnection() {
949         if (_worldState == INIT_CREATION_CONTOUR) {
950                 _worldState = NOTHING_HAPPENS;
951                 //int lastId = _controllers.size()-1;
952
953                 GConnectorController *connector =
954                                 (GConnectorController*) _controllers[_idConnectionInCreation];
955                 connector->removeFromScene();
956                 unregisterController(connector);
957                 _controllers.erase(_idConnectionInCreation);
958
959                 std::map<int, GObjectController*>::iterator it;
960                 for (it = _controllers.begin(); it != _controllers.end(); ++it) {
961                         GObjectController *desc = it->second;
962                         desc->SetActive(true);
963                         desc->getView()->setState(NOTHING_HAPPENS);
964                         desc->getModel()->notifyObservers(_idManager);
965                 } // for
966         }// if
967 }
968
969 //=========================================================================
970
971 bool wxVtkSceneManager::OnRightButtonUp() {
972         if (_worldState == INIT_CREATION_CONTOUR) {
973                 CancelConnection();
974         }
975         UnSelectBlackBoxes();
976         return true;
977 }
978
979  ///JLGR 21-05-2012
980
981 bool wxVtkSceneManager::OnMiddleButtonDown() {
982
983
984         this->_vtkInteractorStyleBaseView->StartPan();
985
986         return true;
987     }
988
989 bool wxVtkSceneManager::OnMiddleButtonUp() {
990
991
992         this->_vtkInteractorStyleBaseView->EndPan();
993
994
995         return true;
996     }
997
998
999 //=========================================================================
1000
1001 GObjectController *wxVtkSceneManager::GetGBlackBoxControlerPointedByMouse() {
1002         GObjectController *result = NULL;
1003         int X, Y;
1004         wxVTKRenderWindowInteractor *wxVTKiren;
1005         wxVTKiren
1006                         = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
1007         wxVTKiren->GetEventPosition(X, Y);
1008
1009         std::map<int, GObjectController*>::iterator it;
1010
1011         for (it = _controllers.begin(); it != _controllers.end(); ++it) {
1012                 GObjectController *cont = it->second;
1013                 int type = cont->getGObjectType();
1014
1015                 if (cont->getView()->isPointInside(X, Y) == true) {
1016                         if (type == GBLACKBOX) {
1017                                 result = cont;
1018                         } // if type
1019                 } // if isPointInside
1020         } // for it
1021         return result;
1022 }
1023
1024 //=========================================================================
1025 void wxVtkSceneManager::UnSelectBlackBoxes() {
1026         for (int i = 0; i < (int) _selectedObjects.size(); i++) {
1027                 int id = _selectedObjects[i];
1028                 GObjectController* control = _controllers[id];
1029                 control->getView()->setState(NOTHING_HAPPENS);
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->saveTempDiagram();
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