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