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