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