]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxVtkSceneManager.cxx
no message
[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
37 #include "wxVtkSceneManager.h"
38
39 namespace bbtk
40 {
41
42
43         //=========================================================================
44         wxVtkSceneManager::wxVtkSceneManager(wxGEditorTabPanel *parent, wxVtk3DBaseView *baseView,int idManager)
45         {
46                 _parent = parent;
47                 _numBoxes=0;
48                 _idManager=idManager;
49                 _baseView=baseView;
50                 _startDragging=false;
51                 _isComplexBox=false;
52
53                 if( _baseView!=NULL )
54                 {
55 //EED02JUIN2010 
56                         printf ("RaC-EED 21-06-2010 %p wxVtkSceneManager::wxVtkSceneManager If you comment this line, the drag and drop functionnality is not initialized.\n" , this );
57                         _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget((wxDropTarget*)parent);                      
58
59                         configureBaseView();
60                         _worldState=NOTHING_HAPPENS;
61                         registerController(this);
62                         
63                 }
64                 _idConnectionInCreation=-1;
65                 _contLastId=0;
66
67         }
68
69         //=========================================================================
70
71         void wxVtkSceneManager::disconnectDrop()
72         {
73                 printf ("EED %p ~wxVtkSceneManager::disconnectDrop()\n" , this );
74 //EED02JUIN2010         _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget(NULL);
75 //      _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget( new tmpClasswxTextDropTarget() );
76         }
77
78         //=========================================================================
79
80         wxVtkSceneManager::~wxVtkSceneManager()
81         {
82                 printf ("EED %p ~wxVtkSceneManager()\n" , this );
83                 disconnectDrop();
84         }
85  
86         //=========================================================================
87
88         void wxVtkSceneManager::configureBaseView()
89         {
90                 vtkInteractorStyleBaseView2D *interactorstylebaseview = vtkInteractorStyleBaseView2D::New();
91
92                 _baseView->SetInteractorStyleBaseView(interactorstylebaseview);
93
94                 // Important to activate the 2D interaction system
95                 wxVTKRenderWindowInteractor *iren = _baseView->GetWxVTKRenderWindowInteractor();
96                 interactorstylebaseview->SetInteractor ( iren );
97                 iren->SetInteractorStyle(interactorstylebaseview);
98                 interactorstylebaseview->SetwxVtkBaseView(_baseView);
99                 
100                 _baseView->GetRenderer()->GetActiveCamera()->ParallelProjectionOn();
101                 _baseView->GetRenderer()->ResetCamera(-100,100,-100,100,900,1000);
102                 
103                 _baseView->GetRenderer()->SetBackground(0.9,0.9,0.9);
104                 _baseView->GetRenderer()->GradientBackgroundOff();
105                 _baseView->Refresh();
106         }
107
108         //=========================================================================
109
110         int wxVtkSceneManager::createGBlackBox(int x, int y, std::string packageName, std::string boxType)
111         {
112                 _worldState = NOTHING_HAPPENS;
113                 int windowWidth=_baseView->GetRenWin()->GetSize()[0];
114                 int windowHeight=_baseView->GetRenWin()->GetSize()[1];
115
116                 int type = GBLACKBOX;
117
118                 //Create the MVC Objects
119                 
120                 GBlackBoxModel *model = (GBlackBoxModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
121                 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
122                 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
123                 
124                 BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxType);
125                 
126                 //Prepares the initial model
127                 //The coordinates obtained are the following. Top-Left:x=0,y=0 Bottom-Right:x=width,y=height  
128
129                 double xx = x;
130                 double yy = windowHeight-y;
131                 
132                 //z value is not important yet, because it is only used a parallel projection
133                 double zz = 900;
134
135                 _baseView->TransCoordScreenToWorld(xx,yy,zz);
136                 model->setInicPoint(xx,yy,zz);
137                 
138                 _numBoxes++;
139                 std::stringstream stream;
140                 
141                 if(_numBoxes<10)
142                 {
143                         stream << "Box0" << _numBoxes;
144                 }
145                 else
146                 {
147                         stream << "Box" << _numBoxes;
148                 }
149                 std::string arraystring = stream.str();
150
151                 model->setBBTKName(arraystring);
152                 model->setBBTKType(boxType);
153                 model->setBBTKPackage(packageName);
154                                 
155                 model->addObserver(view);
156                 model->addObserver(this);
157
158                 //Iterate and create the input ports
159                 std::map<std::string, BlackBoxInputDescriptor*> descriptorInMap = descriptor->GetInputDescriptorMap();
160                 std::map<std::string, BlackBoxInputDescriptor*>::iterator itInput;
161
162                 int i=0;
163                 for(itInput = descriptorInMap.begin(); itInput != descriptorInMap.end(); ++itInput)
164                 {
165                         BlackBoxInputDescriptor *desc = itInput->second;
166                         createGInputPort(GINPUTPORT,i,model,desc);
167                         i++;
168                 }
169
170                 //Iterate and create the output ports
171                 std::map<std::string, BlackBoxOutputDescriptor*> descriptorOutMap = descriptor->GetOutputDescriptorMap();
172                 std::map<std::string, BlackBoxOutputDescriptor*>::iterator itOutput;
173
174                 i=0;
175                 for(itOutput = descriptorOutMap.begin();itOutput != descriptorOutMap.end(); ++itOutput)
176                 {
177                         BlackBoxOutputDescriptor *desc = itOutput->second;
178                         createGOutputPort(GOUTPUTPORT,i,model,desc);
179                         i++;
180                 }
181
182
183                 //Associates the view with the correspondent renderer and the  model.
184                 //(NOTE: Refresh is only made by the view)
185                 view->setModel(model);
186                 view->setBaseView(_baseView);
187                 view->initVtkObjects();
188                 
189                 //Associates the controller with the correspondent model and view
190                 controller->setModelAndView(model,view);
191
192                 //Resgiter change to the observers of the actual model
193                 model->notifyObservers(_idManager);
194                 
195                 int newId = addObjectController(controller);
196
197                 return newId;
198
199         }
200
201         //=========================================================================
202
203         int wxVtkSceneManager::createGComplexBoxInputPort(std::string inputName)
204         {
205                 int windowWidth=_baseView->GetRenWin()->GetSize()[0];
206                 int windowHeight=_baseView->GetRenWin()->GetSize()[1];
207                 
208                 int type = GCOMPLEXINPUTPORT;
209
210                 //Create the MVC Objects
211                 
212                 GComplexBoxPortModel *model = (GComplexBoxPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
213                 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
214                 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
215                                 
216                 //Prepares the initial model 
217
218                 double xx = 5;
219                 double yy = windowHeight-5;
220                 
221                 //z value is not important yet, because it is only used a parallel projection
222                 double zz = 900;
223
224                 _baseView->TransCoordScreenToWorld(xx,yy,zz);
225                 model->setInicPoint(xx,yy,zz);
226                                 
227                 model->setBBTKName(inputName);
228                 model->setBBTKType("ComplexInputPort");
229                 model->setComplexPortType(type);
230                                 
231                 model->addObserver(view);
232                 model->addObserver(this);
233                 
234                 //create the output port                
235                 GPortController* portController = createGPort(GOUTPUTPORT,inputName,"ComplexInputPort",0,model);
236                 model->addOutputPort((GPortModel*)portController->getModel());
237                 
238                 //Associates the view with the correspondent renderer and the  model.
239                 //(NOTE: Refresh is only made by the view)
240                 view->setModel(model);
241                 view->setBaseView(_baseView);
242                 view->initVtkObjects();
243                 
244                 //Associates the controller with the correspondent model and view
245                 controller->setModelAndView(model,view);
246
247                 //Resgiter change to the observers of the actual model
248                 model->notifyObservers(_idManager);
249                 
250                 int newId = addObjectController(controller);
251                 return newId;
252         }
253
254         //=========================================================================
255         
256         int wxVtkSceneManager::createGComplexBoxOutputPort(std::string outputName)
257         {
258                 int windowWidth=_baseView->GetRenWin()->GetSize()[0];
259                 int windowHeight=_baseView->GetRenWin()->GetSize()[1];
260
261                 int type = GCOMPLEXOUTPUTPORT;
262
263                 //Create the MVC Objects
264                 
265                 GComplexBoxPortModel *model = (GComplexBoxPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
266                 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
267                 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
268                                 
269                 //Prepares the initial model 
270
271                 double xx = 5;
272                 double yy = windowHeight-5;
273                 
274                 //z value is not important yet, because it is only used a parallel projection
275                 double zz = 900;
276
277                 _baseView->TransCoordScreenToWorld(xx,yy,zz);
278                 model->setInicPoint(xx,yy,zz);
279                                 
280                 model->setBBTKName(outputName);
281                 model->setBBTKType("ComplexOutputPort");
282                 model->setComplexPortType(type);
283                                 
284                 model->addObserver(view);
285                 model->addObserver(this);
286                 
287                 //create the output port                
288                 GPortController* portController = createGPort(GINPUTPORT,outputName,"ComplexInputPort",0,model);
289                 model->addInputPort((GPortModel*)portController->getModel());
290                 
291                 //Associates the view with the correspondent renderer and the  model.
292                 //(NOTE: Refresh is only made by the view)
293                 view->setModel(model);
294                 view->setBaseView(_baseView);
295                 view->initVtkObjects();
296                 
297                 //Associates the controller with the correspondent model and view
298                 controller->setModelAndView(model,view);
299
300                 //Resgiter change to the observers of the actual model
301                 model->notifyObservers(_idManager);
302                 
303                 int newId = addObjectController(controller);
304                 return newId;
305         }
306
307         //=========================================================================
308
309         int wxVtkSceneManager::createGInputPort(int portType, int posinBox,GBoxModel *blackBox, BlackBoxInputDescriptor *desc)
310         {
311                 GPortController* portController = createGPort(portType,desc->GetName(),desc->GetTypeName(),posinBox,blackBox);
312                 blackBox->addInputPort((GPortModel*)portController->getModel());
313                 return portController->getId();
314         }
315
316         //=========================================================================
317
318         int wxVtkSceneManager::createGOutputPort(int portType, int posinBox,GBoxModel *blackBox, BlackBoxOutputDescriptor *desc)
319         {
320                 GPortController* portController = createGPort(portType,desc->GetName(),desc->GetTypeName(),posinBox,blackBox);
321                 blackBox->addOutputPort((GPortModel*)portController->getModel());
322                 return portController->getId();
323         }
324
325         //=========================================================================
326
327         GPortController* wxVtkSceneManager::createGPort(int portType,std::string bbtkName, std::string bbtkType, int posInBox,GBoxModel *blackBox)
328         {
329                 int type = GPORT;
330
331                 //Create the MVC Objects
332                 GPortModel *model = (GPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
333                 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
334                 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
335
336                 model->registerInBox(blackBox,portType, posInBox);
337                 
338                 model->setBBTKType(bbtkType);
339                 model->setBBTKName(bbtkName);
340
341                 model->addObserver(view);
342                 model->addObserver(this);
343
344                 //Associates the view with the correspondent renderer and the  model.
345                 //(NOTE: Refresh is only made by the view)
346                 view->setModel(model);
347                 view->setBaseView(_baseView);
348                 view->initVtkObjects();
349                 
350                 //Associates the controller with the correspondent model and view
351                 controller->setModelAndView(model,view);
352
353                 model->notifyObservers(_idManager);
354
355                 int newId = addObjectController(controller);
356
357                 return (GPortController*)controller;
358         }
359
360         //=========================================================================
361
362         int wxVtkSceneManager::createGConnector(GPortModel* startPort)
363         {
364                 int type = GCONNECTOR;
365
366                 manualConnectorContourController* manContourControl     = new manualConnectorContourController();
367                 manualConnectorContourView* manContourView      = new manualConnectorContourView();
368                 manualContourModel* manContourModel     = new manualContourModel();
369
370                 GConnectorController* connectorcontroller = new GConnectorController();                         
371                 GConnectorModel* connectorModel = new GConnectorModel();
372                 vtkGConnectorView* connectorView = new vtkGConnectorView();
373                 connectorModel->setGObjectType(type);
374
375                 manContourModel->SetCloseContour(false);
376                 connectorModel->setStartPort(startPort);
377
378                 manContourView->SetModel( manContourModel );
379                 manContourView->SetWxVtkBaseView( _baseView );
380                 manContourView->SetRange( 0.5 );
381                 manContourView->SetZ( 900 );
382
383                 manContourView->SetColorNormalContour(0, 0, 1);
384                 manContourView->SetColorEditContour(0.5, 0.5, 0.5);
385                 manContourView->SetColorSelectContour(1, 0.8, 0);
386                 manContourView->SetWidthLine(1);
387                 manContourView->SetShowText(false);
388
389                 manContourControl->SetModelView( manContourModel , manContourView );
390                 
391                 manContourControl->CreateNewManualContour();
392
393                 manContourView->RefreshContour();
394
395
396                 double x,y,z;
397                 connectorModel->getInicPoint(x,y,z);
398
399                 manContourControl->SetState(1);
400                 manContourModel->SetCloseContour(false);
401                 
402                 manContourModel->AddPoint(x,y,z);
403                 manContourView->AddPoint();
404
405                 manContourModel->AddPoint(x,y,z);
406                 manContourView->AddPoint();
407
408                 int bak= manContourControl->GetNumberOfPointsManualContour() - 1;
409                 manContourControl->_bakIdPoint=bak;
410                 manContourView->Refresh();
411
412                 manContourControl->SetMoving( false );
413
414                 connectorcontroller->setModelAndView(connectorModel,connectorView);
415
416                 int newId = addObjectController(connectorcontroller);
417
418                 connectorcontroller->setManualContourController(manContourControl);             
419                 connectorModel->setManualContourModel(manContourModel);
420                 connectorView->setManualContourView(manContourView);
421                 connectorView->setModel(connectorModel);
422                 connectorView->setBaseView(_baseView);
423                 
424
425                 connectorModel->addObserver(connectorView);
426                 connectorModel->addObserver(this);
427
428                 return newId;
429         }
430
431         //=========================================================================
432
433         void wxVtkSceneManager::registerController(InteractorStyleMaracas *param)
434         {
435                 vtkInteractorStyleBaseView* baseViewControlManager = (vtkInteractorStyleBaseView*)_baseView->GetInteractorStyleBaseView();
436                 baseViewControlManager->AddInteractorStyleMaracas( param );
437         }
438
439         //=========================================================================
440
441         void wxVtkSceneManager::unregisterController(InteractorStyleMaracas *param)
442         {
443                 vtkInteractorStyleBaseView* baseViewControlManager = (vtkInteractorStyleBaseView*)_baseView->GetInteractorStyleBaseView();
444                 baseViewControlManager->RemoveInteractorStyleMaracas( param );
445         }
446
447         //=========================================================================
448
449         vtkRenderer* wxVtkSceneManager::getRenderer()
450         {
451                 return _baseView->GetRenderer();
452         }
453
454         //=========================================================================
455
456         vtkRenderWindow* wxVtkSceneManager::getRenderWindow()
457         {
458                 return _baseView->GetRenWin();
459         }
460         //=========================================================================
461
462                 
463         void wxVtkSceneManager::update(int idController,int command)
464         {
465                 if(command != NO_COMMAND)
466                 {
467                         if(command == ADD_TO_SELECTED)
468                         {
469                                 GObjectController* cont = _controllers[idController];
470
471                                 bool foundID=false;
472                                 for (int i=0; i<_selectedObjects.size() && foundID==false; i++)
473                                 {
474                                         int id = _selectedObjects[i];
475                                         if(id==idController)
476                                         {
477                                                 foundID = true;
478                                         }
479                                 }
480                                 if(!foundID)
481                                 {
482                                         int id = idController;
483                                         _selectedObjects.push_back(id);
484                                 }
485
486                         }
487                         else if(command == INIT_CREATION_CONTOUR)
488                         {       
489                                 _worldState = INIT_CREATION_CONTOUR;
490                                 GObjectController* cont = _controllers[idController];
491                                 GPortModel* startOutputPort = (GPortModel*)cont->getModel();
492                                 
493
494                                 // The last one is the controller of the connector
495                                 std::map<int, GObjectController*>::iterator it2;
496
497                                 for(it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
498                                 {
499                                         GObjectController *cont = it2->second;
500                                         if(cont->getGObjectType() == GPORT )
501                                         {
502                                                 GPortModel* port = (GPortModel*)cont->getModel();
503                                                 if(port->getPortType()==GINPUTPORT)
504                                                 {
505                                                         cont->SetActive(true);
506                                                 }
507                                                 else
508                                                 {
509                                                         cont->getView()->setState(NOTHING_HAPPENS);
510                                                         cont->getModel()->notifyObservers(_idManager);
511                                                         cont->SetActive(false);
512                                                 }
513                                         }
514                                         else
515                                         {
516                                                 cont->getView()->setState(NOTHING_HAPPENS);
517                                                 cont->getModel()->notifyObservers(_idManager);
518                                                 cont->SetActive(false);
519                                         }                               
520                                 }
521
522                                 _selectedObjects.clear();
523
524                                 _idConnectionInCreation=createGConnector(startOutputPort);
525
526                         }
527                         else if(command == FIN_CREATION_CONTOUR && _worldState == INIT_CREATION_CONTOUR)
528                         {                               
529                                 _worldState = NOTHING_HAPPENS;
530                                 //int id = _controllers.size()-1;
531                                 GObjectController* cont = _controllers[_idConnectionInCreation];                        
532                                 GConnectorModel* modelContour = (GConnectorModel*)cont->getModel();
533
534                                 GObjectController* finPort = _controllers[idController];
535                                 if(finPort->getGObjectType() == GPORT)
536                                 {
537                                         GPortModel* modelPort = (GPortModel*)finPort->getModel();
538                                         modelContour->setEndPort(modelPort);
539                                 }                       
540
541                                 manualConnectorContourController* manCont = ((GConnectorController*)cont)->getManualContourController();                        
542                                 manualConnectorContourView* connView = (manualConnectorContourView*)manCont->GetManualViewBaseContour();
543                                 connView->Refresh();
544
545                                 std::map<int, GObjectController*>::iterator it2;
546
547                                 for(it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
548                                 {
549                                         GObjectController *cont = it2->second;
550                                         if(cont->getView()!=NULL)
551                                         {
552                                                 cont->getView()->setState(NOTHING_HAPPENS);
553                                                 cont->getModel()->notifyObservers(_idManager);
554                                         }
555                                         cont->SetActive(true);                                                          
556                                 }
557                         }
558                         
559                 }
560         }
561
562         //=========================================================================
563
564         bool wxVtkSceneManager::OnMouseMove()
565         {
566                 int X,Y;
567                 wxVTKRenderWindowInteractor *wxVTKiren;
568                 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
569                 wxVTKiren->GetEventPosition(X,Y);
570         
571                 
572                 if(_worldState == DRAG_OBJECTS)
573                 {                       
574                         for (int i=0; i<_selectedObjects.size(); i++)
575                         {
576                                 int id = _selectedObjects[i];
577                                 GObjectController* cont = _controllers[id];
578                                 if(_startDragging)
579                                 {
580                                         cont->getView()->setStartDragging(true);
581                                 }
582                                 cont->getView()->moveObject(X,Y);
583                                 cont->getView()->setState(DRAG);
584                                 cont->getModel()->notifyObservers(_idManager);
585                         }
586
587                         std::map<int, GObjectController*>::iterator it;
588
589                         for(it = _controllers.begin(); it != _controllers.end(); ++it)
590                         {
591                                 GObjectController *desc = it->second;
592                                 if(desc->getGObjectType()==GCONNECTOR)
593                                 {
594                                         vtkGConnectorView* vconn = (vtkGConnectorView*)desc->getView();
595                                         vconn->updateStartEndPoints();
596                                 }
597                         }
598                         
599                         _startDragging=false;
600
601                 }
602                 else if(_worldState == NOTHING_HAPPENS || _worldState == INIT_CREATION_CONTOUR)
603                 {
604                         std::map<int, GObjectController*>::iterator it;
605
606                         for(it = _controllers.begin(); it != _controllers.end(); ++it)
607                         {
608                                 GObjectController *desc = it->second;
609                                 int type = desc->getGObjectType();
610                                 int state = desc->getView()->getState();
611                                 
612                                 if(state == HIGHLIGHTED){
613
614                                         updateStatusBar(desc->getStatusText());
615                                         if(type==GBLACKBOX)
616                                         {
617                                                 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
618                                                 _parent->displayBlackBoxInfo(mod->getBBTKPackage(),mod->getBBTKType());
619                                         }
620                                 }
621                         }
622                 }
623                 
624                 return true;
625         }
626
627         //=========================================================================
628         
629         bool wxVtkSceneManager::OnLeftButtonDown()
630         {
631                 if(_worldState==INIT_CREATION_CONTOUR)
632                 {
633                         bool isOverPort=false;
634                         std::map<int, GObjectController*>::iterator it;
635                         for(it = _controllers.begin(); it != _controllers.end() && isOverPort==false; ++it)
636                         {
637                                 GObjectController *desc = it->second;
638                                 if(desc->getGObjectType()==GPORT)
639                                 {
640                                         GPortModel* portmod=(GPortModel*)desc->getModel();
641                                         vtkGObjectView* portView=desc->getView();
642                                         if(portmod->getPortType()==GINPUTPORT && portView->getState()==HIGHLIGHTED)
643                                         {
644                                                 isOverPort=true;
645                                         }
646                                 }
647                         }
648                         
649                         if(isOverPort==false)
650                         {
651                                 _worldState=NOTHING_HAPPENS;
652                                 //int lastId = _controllers.size()-1;
653                                 GConnectorController *connector = (GConnectorController*)_controllers[_controllers.size()-1];
654                                 connector->removeFromScene();
655                                 unregisterController(connector);
656                                 _controllers.erase(_controllers.size()-1);                      
657
658                                 for(it = _controllers.begin(); it != _controllers.end(); ++it)
659                                 {
660                                         GObjectController *desc = it->second;
661                                         desc->SetActive(true);
662                                         desc->getView()->setState(NOTHING_HAPPENS);
663                                         desc->getModel()->notifyObservers(_idManager);
664                                 }
665                         }
666                 }
667                 
668                 if(_selectedObjects.size()!=0)
669                 {
670                         _worldState = DRAG_OBJECTS;
671                         _startDragging = true;
672
673                         for (int i = 0; i < _selectedObjects.size(); i++)
674                         {
675                                 int id = _selectedObjects[i];
676                                 GObjectController* cont = _controllers[id];
677                                 cont->getView()->setState(DRAG);
678                                 cont->getModel()->notifyObservers(_idManager);
679                         }
680                 }
681                 
682                 
683                 
684                 return true;
685         }
686
687         //=========================================================================
688         
689         bool wxVtkSceneManager::OnLeftButtonUp()
690         {
691                 if(_worldState == DRAG_OBJECTS)
692                 {
693                         _worldState = NOTHING_HAPPENS;
694
695                         for (int i = 0; i < _selectedObjects.size(); i++)
696                         {
697                                 int id = _selectedObjects[i];
698                                 GObjectController* cont = _controllers[id];
699                                 cont->getView()->setState(SELECTED);
700                                 cont->getModel()->notifyObservers(_idManager);
701                         }
702                 }
703                 return true;
704         }
705
706         //=========================================================================
707
708         bool wxVtkSceneManager::OnRightButtonUp()
709         {
710                 if(_worldState==INIT_CREATION_CONTOUR)
711                 {
712                         _worldState=NOTHING_HAPPENS;
713                         //int lastId = _controllers.size()-1;
714                         GConnectorController *connector = (GConnectorController*)_controllers[_idConnectionInCreation];
715                         connector->removeFromScene();
716                         unregisterController(connector);
717                         _controllers.erase(_idConnectionInCreation);                    
718
719                         std::map<int, GObjectController*>::iterator it;
720                         for(it = _controllers.begin(); it != _controllers.end(); ++it)
721                         {
722                                 GObjectController *desc = it->second;
723                                 desc->SetActive(true);
724                                 desc->getView()->setState(NOTHING_HAPPENS);
725                                 desc->getModel()->notifyObservers(_idManager);
726                         }
727                 }
728
729                         
730                 for (int i = 0; i < _selectedObjects.size(); i++)
731                 {
732                         int id = _selectedObjects[i];
733                         GObjectController* cont = _controllers[id];
734                         cont->SetActive(true);
735                         cont->getView()->setState(NOTHING_HAPPENS);
736                         cont->getModel()->notifyObservers(_idManager);
737                 }
738
739                 _selectedObjects.clear();
740
741                 return true;
742         }
743
744         //=========================================================================
745
746         bool wxVtkSceneManager::OnLeftDClick()
747         {
748                 int X,Y;
749                 wxVTKRenderWindowInteractor *wxVTKiren;
750                 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
751                 wxVTKiren->GetEventPosition(X,Y);
752
753                 std::map<int, GObjectController*>::iterator it;
754
755                 bool clickOnObject = false;
756
757                 for(it = _controllers.begin(); it != _controllers.end() && clickOnObject==false; ++it)
758                 {
759                         GObjectController *cont = it->second;
760                         int type = cont->getGObjectType();
761                         
762                         if(cont->getView()->isPointInside(X,Y))
763                         {
764                                 if(type==GBLACKBOX)
765                                 {
766                                         for (int i=0; i<_selectedObjects.size(); i++)
767                                         {
768                                                 int id = _selectedObjects[i];
769                                                 GObjectController* control = _controllers[id];
770                                                 control->getView()->setState(NOTHING_HAPPENS);
771                                         }
772                                         _selectedObjects.clear();
773
774                                         GBlackBoxModel *bbmodel = (GBlackBoxModel*)cont->getModel();
775                                         _parent->editBlackBox(bbmodel);
776                                 }
777                                 clickOnObject = true;                   
778                         }
779                 }
780
781                 if(clickOnObject==false)
782                 {
783                         //_parent->editDiagramParameters(this);
784                 }
785
786                 return true;
787         }
788         
789         //=========================================================================
790
791         bool wxVtkSceneManager::OnChar()
792         {       
793                 char keyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
794                 
795                 // KeyCode 127 : Delete Key
796                 // KeyCode 8 : Backspace Key
797                 if(keyCode == 8 || keyCode == 127)
798                 {
799                         if(_selectedObjects.size()>0)
800                         {
801                                 for(int i=0;i<(int)_selectedObjects.size();i++)
802                                 {
803                                         int id = _selectedObjects[i];                                   
804                                         std::map<int,GObjectController*>::iterator it;
805                     it = _controllers.find(id);
806                                         if (it!=_controllers.end())
807                                         {
808                                                 deleteObject(id);
809                                         }
810                                 }
811                                 _selectedObjects.clear();
812                         }
813                 }
814
815                 return true;
816         }
817
818         //=========================================================================
819
820         void wxVtkSceneManager::AddControlerToBeRemove(std::vector<int> *controllersToRemove, int id)
821         {
822                 
823                 int i;
824                 bool ok=true;
825                 for(i=0 ; i < (int)controllersToRemove->size() ; i++ )
826                 {
827                         if (id == (*controllersToRemove)[i] )
828                         {
829                                 ok=false;
830                         }
831                 }
832                 
833                 if (ok==true)
834                 {
835                    controllersToRemove->push_back( id );
836                 }
837                 
838         }
839         
840         //=========================================================================
841         
842         void wxVtkSceneManager::deleteObject(int id)
843         {
844                 GObjectController *control = _controllers[id];
845                 std::vector<int> controllersToRemove;
846
847                 if(control->getGObjectType()==GBLACKBOX || control->getGObjectType()==GCOMPLEXINPUTPORT || control->getGObjectType()==GCOMPLEXOUTPUTPORT)
848                 {
849                         GBoxModel *bbmod = (GBoxModel*)control->getModel();
850                         std::vector<GPortModel*> inputs = bbmod->getInputPorts();
851                         
852                         bool boxConnected = false;
853
854                         // Add box input controllers to be removed
855                         for(int i = 0;i< (int)inputs.size();i++)
856                         {
857                                 AddControlerToBeRemove( &controllersToRemove, inputs[i]->getObjectId() );
858                                 if(inputs[i]->isConnected())
859                                 {
860                                         boxConnected = true;
861                                 }
862                         }
863
864                         std::vector<GPortModel*> outputs = bbmod->getOutputPorts();
865
866                         // Add box output controllers to be removed
867                         for(int i = 0;i<(int)outputs.size();i++)
868                         {
869                                 AddControlerToBeRemove( &controllersToRemove, outputs[i]->getObjectId() );
870                                 if(outputs[i]->isConnected())
871                                 {
872                                         boxConnected = true;
873                                 }
874                         }
875
876                         // Add connection controllers to be removed
877                         std::map<int, GObjectController*>::iterator it;
878                         for(it = _controllers.begin(); it != _controllers.end(); ++it)
879                         {
880                                 GObjectController *cont = it->second;
881                                 int type = cont->getGObjectType();
882                                 if(type==GCONNECTOR)
883                                 {
884                                         GConnectorModel *conMod = (GConnectorModel*)cont->getModel();
885                                         if(conMod->getStartPort()!=NULL && conMod->getStartPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
886                                         {
887                                                 AddControlerToBeRemove( &controllersToRemove, conMod->getObjectId() );
888                                         }
889                                         if(conMod->getEndPort()!=NULL && conMod->getEndPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
890                                         {
891                                                 AddControlerToBeRemove( &controllersToRemove, conMod->getObjectId() );
892                                         }
893                                 }
894                         }
895
896                         // Add box controller to be removed
897                         AddControlerToBeRemove( &controllersToRemove, bbmod->getObjectId() );
898                 }
899                 else if(control->getGObjectType()==GCONNECTOR)
900                 {                       
901                         GConnectorModel *conMod = (GConnectorModel*)control->getModel();
902                         AddControlerToBeRemove( &controllersToRemove, conMod->getObjectId() );
903                 }
904
905                 
906                 std::map<int,GObjectController*>::iterator it;
907
908                 for(int i = 0;i<(int)controllersToRemove.size();i++)
909                 {
910                         int key = controllersToRemove[i];
911                         it = _controllers.find( key );
912                         GObjectController *cont = _controllers[ key ];
913                         if(cont!=NULL)
914                         {
915                                 cont->removeFromScene();
916                                 unregisterController((InteractorStyleMaracas*)cont);                    
917                                 _controllers.erase(it);
918                         }//if
919                 }// for
920         }
921
922         //=========================================================================
923
924         void wxVtkSceneManager::displayBlackBoxInfo(std::string packageName, std::string boxName)
925         {
926                 _parent->displayBlackBoxInfo(packageName,boxName);
927         }
928
929         //=========================================================================
930
931         void wxVtkSceneManager::updateStatusBar(std::string textStatus)
932         {
933                 _parent->updateStatusBar(textStatus);
934         }
935
936         //=========================================================================
937
938         std::string wxVtkSceneManager::getDiagramBBS()
939         {
940                 bool existsExec=false;
941
942                 std::vector<std::string> packages;
943                 std::vector<int> boxes;
944                 std::vector<int> connections;
945                 std::vector<int> execBoxes;
946
947                 std::map<int, GObjectController*>::iterator it;
948
949                 for(it = _controllers.begin(); it != _controllers.end(); ++it)
950                 {
951                         GObjectController *desc = it->second;
952                         int type = desc->getGObjectType();
953
954                         if(type==GBLACKBOX)
955                         {
956                                 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
957                                 
958                                 std::string pkg = mod->getBBTKPackage();
959                                 bool existsPkg = false;
960                                 for(int t = 0;t<packages.size() && existsPkg == false;t++)
961                                 {
962                                         if(packages[t]==pkg)
963                                         {
964                                                 existsPkg=true;
965                                         }
966                                 }
967                                 if(!existsPkg)
968                                 {
969                                         packages.push_back(pkg);
970                                 }
971
972
973                                 boxes.push_back(it->first);
974                                 if(mod->isExecutable())
975                                 {
976                                         execBoxes.push_back(it->first);
977                                         existsExec=true;
978                                 }
979                         }
980                         else if(type==GCONNECTOR)
981                         {
982                                 connections.push_back(it->first);
983                         }
984                 }
985
986                 std::string script = "";
987                 script+="# BBTK GEditor Script\n";
988                 script+="# ----------------------\n";
989                 if(existsExec)
990                 {
991                         script+="include std\n"; // EED
992                         script+="include itkvtk\n"; // EED
993                         int i;
994                         for(i = 0; i<packages.size();i++)
995                         {
996                                 script+="include ";
997                                 script+=packages[i];
998                                 script+="\n";
999                         }
1000
1001                         // script+="include std\n"; // JPR
1002
1003                         for(i = 0; i<boxes.size();i++)
1004                         {
1005                                 script+="new ";
1006                                 int id = boxes[i];
1007                                 GObjectController *control = _controllers[id];
1008                                 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1009
1010                                 script+=model->getBBTKType();
1011                                 script+=" ";
1012                                 script+=model->getBBTKName();
1013                                 script+="\n";
1014
1015                                 std::vector<GPortModel*> inputs = model->getInputPorts();
1016                                 for(int j = 0; j<inputs.size();j++)
1017                                 {
1018                                         GPortModel* inputPort = inputs[j];
1019                                         if(inputPort->isValueSet())
1020                                         {
1021                                                 script+="set ";
1022                                                 script+=model->getBBTKName();
1023                                                 script+=".";
1024                                                 script+=inputPort->getBBTKName();
1025                                                 script+=" ";
1026                                                 script+=inputPort->getValue();
1027                                                 script+="\n";
1028                                         }
1029                                 }
1030
1031                         }
1032
1033                         for(i = 0; i<connections.size();i++)
1034                         {
1035                                 script+="connect ";
1036                                 int id = connections[i];
1037                                 GObjectController *control = _controllers[id];
1038                                 GConnectorModel *model = (GConnectorModel*)control->getModel();
1039
1040                                 //Start Connection info
1041                                 GPortModel *start = model->getStartPort();
1042                                 script+=start->getParentBox()->getBBTKName();
1043                                 script+=".";
1044                                 script+=start->getBBTKName();
1045
1046                                 script+=" ";
1047
1048                                 //End Connection info
1049                                 GPortModel *end = model->getEndPort();
1050                                 script+=end->getParentBox()->getBBTKName();
1051                                 script+=".";
1052                                 script+=end->getBBTKName();
1053
1054                                 script+="\n";
1055                         }
1056
1057                         for(i = 0; i<execBoxes.size();i++)
1058                         {
1059                                 script+="exec ";
1060                                 int id = execBoxes[i];
1061                                 GObjectController *control = _controllers[id];
1062                                 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1063
1064                                 script+=model->getBBTKName();
1065                                 script+="\n";
1066                         }
1067
1068                 }
1069
1070                 return script;
1071         }
1072
1073         //=========================================================================
1074
1075         std::string wxVtkSceneManager::saveComplexBoxBBS(std::string cbName,std::string cbAuthor,std::string cbCategory,std::string cbDescription)
1076         {
1077
1078                 std::vector<std::string> packages;
1079                 std::vector<int> boxes;
1080                 std::vector<int> connections;
1081                 std::vector<int> execBoxes;
1082
1083                 std::map<int, GObjectController*>::iterator it;
1084
1085                 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1086                 {
1087                         GObjectController *desc = it->second;
1088                         int type = desc->getGObjectType();
1089
1090                         if(type==GBLACKBOX)
1091                         {
1092                                 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
1093                                 
1094                                 std::string pkg = mod->getBBTKPackage();
1095                                 bool existsPkg = false;
1096                                 for(int t = 0;t<packages.size() && existsPkg == false;t++)
1097                                 {
1098                                         if(packages[t]==pkg)
1099                                         {
1100                                                 existsPkg=true;
1101                                         }
1102                                 }
1103                                 if(!existsPkg)
1104                                 {
1105                                         packages.push_back(pkg);
1106                                 }
1107
1108
1109                                 boxes.push_back(it->first);
1110                                 if(mod->isExecutable())
1111                                 {
1112                                         execBoxes.push_back(it->first);
1113                                 }
1114                         }
1115                         else if(type==GCONNECTOR)
1116                         {
1117                                 connections.push_back(it->first);
1118                         }
1119                 }
1120
1121                 std::string script = "";
1122
1123                 script+="include std\n";    // EED
1124                 script+="include itkvtk\n"; // EED
1125                 int i;
1126                 for(i = 0; i<packages.size();i++)
1127                 {
1128                         script+="include ";
1129                         script+=packages[i];
1130                         script+="\n";
1131                 }
1132
1133                 // Definition of a complex box
1134                 script+="define ";
1135                 script+=cbName;
1136                 script+="\n";
1137
1138                 script+="author \" ";
1139                 script+=cbAuthor;
1140                 script+="\"\n";
1141
1142                 script+="description \" ";
1143                 script+=cbDescription;
1144                 script+="\"\n";
1145
1146                 // Create boxes
1147                 for(i = 0; i<boxes.size();i++)
1148                 {
1149                         script+="new ";
1150                         int id = boxes[i];
1151                         GObjectController *control = _controllers[id];
1152                         GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1153
1154                         script+=model->getBBTKType();
1155                         script+=" ";
1156                         script+=model->getBBTKName();
1157                         script+="\n";
1158
1159                                 std::vector<GPortModel*> inputs = model->getInputPorts();
1160                                 for(int j = 0; j<inputs.size();j++)
1161                                 {
1162                                         GPortModel* inputPort = inputs[j];
1163                                         if(inputPort->isValueSet())
1164                                         {
1165                                                 script+="set ";
1166                                                 script+=model->getBBTKName();
1167                                                 script+=".";
1168                                                 script+=inputPort->getBBTKName();
1169                                                 script+=" ";
1170                                                 script+=inputPort->getValue();
1171                                                 script+="\n";
1172                                         }
1173                                 }
1174
1175                         }
1176
1177                         // Create connections in the script. If the connection is made with a complex port, it is created the input or output
1178
1179                         std::string complexInputs="";
1180                         std::string complexOutputs="";
1181
1182                         for(i = 0; i<connections.size();i++)
1183                         {
1184                                 int id = connections[i];
1185                                 GObjectController *control = _controllers[id];
1186                                 GConnectorModel *model = (GConnectorModel*)control->getModel();
1187
1188                                 //Connection info
1189                                 GPortModel *start = model->getStartPort();
1190                                 GBoxModel *startBox =start->getParentBox();
1191
1192                                 GPortModel *end = model->getEndPort();
1193                                 GBoxModel *endBox =end->getParentBox();
1194
1195                                 if(startBox->getGObjectType()==GCOMPLEXINPUTPORT)
1196                                 {
1197                                         complexInputs+="input ";
1198                                         complexInputs+=startBox->getBBTKName();
1199
1200                                         complexInputs+=" ";
1201                                         complexInputs+=endBox->getBBTKName();
1202                                         complexInputs+=".";
1203                                         complexInputs+=end->getBBTKName();
1204
1205                                         complexInputs+=" ";
1206                                         complexInputs+="\" \"";
1207
1208                                         complexInputs+="\n";
1209                                 }
1210                                 else if(endBox->getGObjectType()==GCOMPLEXOUTPUTPORT)
1211                                 {
1212                                         complexOutputs+="output ";
1213                                         complexOutputs+=endBox->getBBTKName();
1214
1215                                         complexOutputs+=" ";
1216                                         complexOutputs+=startBox->getBBTKName();
1217                                         complexOutputs+=".";
1218                                         complexOutputs+=start->getBBTKName();
1219
1220                                         complexOutputs+=" ";
1221                                         complexOutputs+="\" \"";
1222
1223                                         complexOutputs+="\n";
1224                                 }
1225                                 else
1226                                 {
1227                                         script+="connect ";
1228                                         script+=startBox->getBBTKName();
1229                                         script+=".";
1230                                         script+=start->getBBTKName();
1231
1232                                         script+=" ";
1233
1234                                         //End Connection info
1235                                         script+=endBox->getBBTKName();
1236                                         script+=".";
1237                                         script+=end->getBBTKName();
1238
1239                                         script+="\n";
1240                                 }
1241                         }
1242
1243                         for(i = 0; i<execBoxes.size();i++)
1244                         {
1245                                 script+="exec ";
1246                                 int id = execBoxes[i];
1247                                 GObjectController *control = _controllers[id];
1248                                 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
1249
1250                                 script+=model->getBBTKName();
1251                                 script+="\n";
1252                         }
1253
1254                         script+="\n";
1255                         script+="# Complex input ports\n";
1256                         script+=complexInputs;
1257
1258                         script+="\n";
1259                         script+="# Complex output ports\n";
1260                         script+=complexOutputs;
1261
1262                         script+="\n";
1263                         script+="endefine";
1264                         script+="\n";           
1265
1266                 return script;
1267         }
1268
1269         //=========================================================================
1270
1271         void wxVtkSceneManager::deleteAllBoxes()
1272         {               
1273                 std::map<int, GObjectController*>::iterator it;
1274                 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1275                 {
1276                         GObjectController *cont = it->second;           
1277                         cont->removeFromScene();
1278                         unregisterController((InteractorStyleMaracas*)cont);
1279                 }
1280                 _selectedObjects.clear();
1281                 _controllers.clear();   
1282                 refreshScene();
1283         }
1284
1285         //=========================================================================
1286
1287         void wxVtkSceneManager::refreshScene()
1288         {
1289                 _baseView->RefreshView();
1290         }
1291
1292         //=========================================================================
1293         
1294         void wxVtkSceneManager::centerView()
1295         {
1296                 double temp[3];
1297                 _baseView->GetRenderer()->GetActiveCamera()->GetFocalPoint(temp);
1298                 _baseView->GetRenderer()->GetActiveCamera()->SetFocalPoint(0,0,temp[2]);
1299                 _baseView->GetRenderer()->GetActiveCamera()->GetPosition(temp);
1300                 _baseView->GetRenderer()->GetActiveCamera()->SetPosition(0,0,temp[2]);
1301                 _baseView->RefreshView();
1302
1303         }
1304
1305         //=========================================================================
1306
1307         void wxVtkSceneManager::saveDiagram(std::string &content)
1308         {
1309                 char buffer [50];
1310
1311                 //Print info IF COMPLEX BOX
1312                 content+="COMPLEXBOX:";
1313                 if(_isComplexBox)
1314                 {
1315                         content+="TRUE\n";
1316
1317                         //Print info complex input ports
1318                         std::vector<int> inputs = getComplexInputPorts();
1319                         int insize = inputs.size();
1320                         content+="COMPLEXINPUTS:";
1321                         sprintf (buffer, "%d", insize);
1322                         content+=buffer;
1323                         content+="\n";
1324                         
1325                         for(int i = 0;i<insize;i++)
1326                         {
1327                                 int id = inputs[i];
1328                                 GObjectController *cont = _controllers[id];
1329                                 cont->getModel()->save(content);
1330                         }
1331
1332                         //Print info complex output ports
1333                         std::vector<int> outputs = getComplexOutputPorts();
1334                         int outsize = outputs.size();
1335                         content+="COMPLEXOUTPUTS:";
1336                         sprintf (buffer, "%d", outsize);
1337                         content+=buffer;
1338                         content+="\n";
1339                         
1340                         for(int i = 0;i<outsize;i++)
1341                         {
1342                                 int id = outputs[i];
1343                                 GObjectController *cont = _controllers[id];
1344                                 cont->getModel()->save(content);
1345                         }
1346                 } // _isComplexBox
1347                 else
1348                 {
1349                         content+="FALSE\n";
1350                 }
1351
1352                 //Print boxes
1353                 std::vector<int> boxes = getBlackBoxes();
1354                 int bsize = boxes.size();
1355                 content+="BOXES:";
1356                 sprintf (buffer, "%d", bsize);
1357                 content+=buffer;
1358                 content+="\n";
1359                 
1360                 for(int i = 0;i<bsize;i++)
1361                 {
1362                         int id = boxes[i];
1363                         GObjectController *cont = _controllers[id];
1364                         cont->getModel()->save(content);
1365                 }
1366
1367                 //Print connections
1368                 std::vector<int> connections = getConnections();
1369                 int csize = connections.size();
1370                 content+="CONNECTIONS:";
1371                 sprintf (buffer, "%d", csize);
1372                 content+=buffer;
1373                 content+="\n";
1374                 
1375                 for(int i = 0;i<csize;i++)
1376                 {
1377                         int id = connections[i];
1378                         GObjectController *cont = _controllers[id];
1379                         cont->getModel()->save(content);
1380                 }
1381
1382         }
1383
1384         //=========================================================================
1385
1386         void wxVtkSceneManager::loadDiagram(ifstream &inputStream)
1387         {
1388
1389                 std::string line="";    
1390                 char delims[] = ":";
1391                 char *result = NULL;
1392         getline(inputStream,line);
1393
1394                 bool start = false;
1395                 while ( !inputStream.eof() ) 
1396                 {
1397                         if(line=="" || line[0]=='#')
1398                         {
1399                                 getline(inputStream,line);
1400                         }
1401                         else if(line=="APP_START")
1402                         {
1403                                 start = true;
1404                                 break;
1405                         }
1406                 }
1407
1408                 if(start)
1409                 {
1410
1411                         //----------
1412                         getline(inputStream,line);//COMPLEX_BOX:TRUE|FALSE
1413                         char complex[30];
1414                         strcpy( complex, line.c_str() );
1415                         result = strtok( complex, delims );
1416                         result = strtok( NULL, delims );
1417                         std::string isComplexBox(result);
1418
1419                         if(isComplexBox=="TRUE")
1420                         {
1421                                 _isComplexBox=true;
1422
1423                                 //-----------------------
1424                                 //- COMPLEX INPUT PORTS
1425                                 //-----------------------
1426                                 getline(inputStream,line);//COMPLEXINPUTS:num
1427                                 char inputs[30];
1428                                 strcpy( inputs, line.c_str() );
1429                                 result = strtok( inputs, delims );
1430                                 result = strtok( NULL, delims );
1431                                                 
1432                                 int numInputs;
1433                                 std::istringstream inps(result);
1434                                 inps >> numInputs;
1435                                 
1436                                 for(int i = 0;i<numInputs;i++)
1437                                 {
1438                                         //----------
1439                                         getline(inputStream,line);//COMPLEX_PORT
1440                                         getline(inputStream,line);//name
1441                                         std::string inputPortName(line);
1442
1443                                         //----------
1444                                         getline(inputStream,line);//xInic:yInic:zInic
1445                                         char coord[80];
1446                                         strcpy( coord, line.c_str() );
1447                                         result = strtok( coord, delims );//xInic
1448                                         std::string xInic(result);
1449                                         result = strtok( NULL, delims );//yInic
1450                                         std::string yInic(result);
1451                                         result = strtok( NULL, delims );//zInic
1452                                         std::string zInic(result);
1453
1454                                         double xIn, yIn, zIn;
1455                                         std::istringstream xSt(xInic);
1456                                         xSt >> xIn;
1457                                         std::istringstream ySt(yInic);
1458                                         ySt >> yIn;
1459                                         std::istringstream zSt(zInic);
1460                                         zSt >> zIn;
1461
1462                                         getline(inputStream,line);//FIN_COMPLEX_PORT
1463
1464                                         int idInputPort = createGComplexBoxInputPort(inputPortName);
1465                                         GObjectController *cont = _controllers[idInputPort];
1466                                         GBoxModel *cbmod = (GBoxModel*)cont->getModel();
1467                                         cbmod->setInicPoint(xIn,yIn,zIn);
1468                                         cbmod->notifyObservers(_idManager);
1469                                 } // for input complex box
1470
1471
1472                                 //-----------------------
1473                                 //- COMPLEX OUTPUT PORTS
1474                                 //-----------------------
1475
1476                                 getline(inputStream,line);//COMPLEXOUTPUTS:num
1477                                 char outputs[30];
1478                                 strcpy( outputs, line.c_str() );
1479                                 result = strtok( outputs, delims );
1480                                 result = strtok( NULL, delims );
1481                                                 
1482                                 int numOutputs;
1483                                 std::istringstream outps(result);
1484                                 outps >> numOutputs;
1485                                 
1486                                 for(int i = 0;i<numOutputs;i++)
1487                                 {
1488                                         //----------
1489                                         getline(inputStream,line);//COMPLEX_PORT
1490                                         getline(inputStream,line);//name
1491                                         std::string outputPortName(line);
1492
1493                                         //----------
1494                                         getline(inputStream,line);//xInic:yInic:zInic
1495                                         char coord[80];
1496                                         strcpy( coord, line.c_str() );
1497                                         result = strtok( coord, delims );//xInic
1498                                         std::string xInic(result);
1499                                         result = strtok( NULL, delims );//yInic
1500                                         std::string yInic(result);
1501                                         result = strtok( NULL, delims );//zInic
1502                                         std::string zInic(result);
1503
1504                                         double xIn, yIn, zIn;
1505                                         std::istringstream xSt(xInic);
1506                                         xSt >> xIn;
1507                                         std::istringstream ySt(yInic);
1508                                         ySt >> yIn;
1509                                         std::istringstream zSt(zInic);
1510                                         zSt >> zIn;
1511
1512                                         getline(inputStream,line);//FIN_COMPLEX_PORT
1513
1514                                         int idOutputPort = createGComplexBoxOutputPort(outputPortName);
1515                                         GObjectController *cont = _controllers[idOutputPort];
1516                                         GBoxModel *cbmod = (GBoxModel*)cont->getModel();
1517                                         cbmod->setInicPoint(xIn,yIn,zIn);
1518                                         cbmod->notifyObservers(_idManager);
1519                                 } // for output complex box
1520
1521                         } // complex box
1522
1523                         //----------
1524                         getline(inputStream,line);//BOXES:num
1525                         char boxes[9];
1526                         strcpy( boxes, line.c_str() );
1527                         result = strtok( boxes, delims );
1528                         result = strtok( NULL, delims );
1529                                         
1530                         int numBoxes;
1531                         std::istringstream is(result);
1532                         is >> numBoxes;
1533                         
1534                         for(int i = 0;i<numBoxes;i++)
1535                         {
1536                                 //----------
1537                                 getline(inputStream,line);//BOX
1538                                 getline(inputStream,line);//package:type:name
1539                                 char box[150];
1540                                 strcpy( box, line.c_str() );
1541                                 result = strtok( box, delims );//package
1542                                 std::string package(result);
1543                                 result = strtok( NULL, delims );//type
1544                                 std::string type(result);
1545                                 result = strtok( NULL, delims );//name
1546                                 std::string name(result);
1547
1548                                 getline(inputStream,line);//ISEXEC:TRUE|FALSE
1549                                 char exec[15];
1550                                 strcpy( exec, line.c_str() );
1551                                 result = strtok( exec, delims );//ISEXEC                                
1552                                 result = strtok( NULL, delims );//TRUE|FALSE
1553                                 std::string isExec(result);
1554
1555                                 //----------
1556                                 getline(inputStream,line);//xInic:yInic:zInic
1557                                 char coord[80];
1558                                 strcpy( coord, line.c_str() );
1559                                 result = strtok( coord, delims );//xInic
1560                                 std::string xInic(result);
1561                                 result = strtok( NULL, delims );//yInic
1562                                 std::string yInic(result);
1563                                 result = strtok( NULL, delims );//zInic
1564                                 std::string zInic(result);
1565
1566                                 double xIn, yIn, zIn;
1567                                 std::istringstream xSt(xInic);
1568                                 xSt >> xIn;
1569                                 std::istringstream ySt(yInic);
1570                                 ySt >> yIn;
1571                                 std::istringstream zSt(zInic);
1572                                 zSt >> zIn;
1573                                                 
1574                                 //----------
1575                                 getline(inputStream,line);//xEnd:yEnd:zEnd
1576                                 strcpy( coord, line.c_str() );
1577                                 result = strtok( coord, delims );//xEnd
1578                                 std::string xEnd(result);
1579                                 result = strtok( NULL, delims );//yEnd
1580                                 std::string yEnd(result);
1581                                 result = strtok( NULL, delims );//zEnd
1582                                 std::string zEnd(result);
1583
1584                                 double xEn, yEn, zEn;
1585                                 std::istringstream xEt(xEnd);
1586                                 xEt >> xEn;
1587                                 std::istringstream yEt(yEnd);
1588                                 yEt >> yEn;
1589                                 std::istringstream zEt(zEnd);
1590                                 zEt >> zEn;
1591
1592                                 int idBox = createGBlackBox(0,0,package,type);
1593                                 GObjectController *cont = _controllers[idBox];
1594                                 GBlackBoxModel *bbmod = (GBlackBoxModel*)cont->getModel();
1595                                 bbmod->setBBTKName(name);
1596                                 bbmod->setInicPoint(xIn,yIn,zIn);
1597                                 bbmod->setFinalPoint(xEn,yEn,zEn);
1598                                 if(isExec=="TRUE")
1599                                 {
1600                                         bbmod->setExecutable(true);
1601                                 }
1602                                 else if(isExec=="FALSE")
1603                                 {
1604                                         bbmod->setExecutable(false);
1605                                 }
1606                                                         
1607                                 //----------
1608                                 getline(inputStream,line);//PORT o FIN_BOX
1609                                 std::string port=line.substr(0,4);
1610                                 while(port=="PORT")
1611                                 {
1612                                         getline(inputStream,line);//name:value
1613                                         char poort[150];
1614                                         strcpy( poort, line.c_str() );
1615                                         result = strtok( poort, delims );//name
1616                                         std::string name(result);
1617                                         result = strtok( NULL, delims );//value
1618                                         std::string value(result);
1619
1620                                         bbmod->setValueToInput(name,value);                                     
1621
1622                                         getline(inputStream,line);//PORT o FIN_BOX
1623                                         port=line.substr(0,4);
1624                                 } // while              
1625
1626                                 bbmod->notifyObservers(_idManager);
1627                         } // boxes
1628
1629                         /// CONNECTIONS
1630                         //----------
1631                         getline(inputStream,line);//CONNECTIONS:num
1632                         char conns[30];
1633                         strcpy( conns, line.c_str() );
1634                         result = strtok( conns, delims );
1635                         result = strtok( NULL, delims );
1636                                         
1637                         int numConns;
1638                         std::istringstream isCons(result);
1639                         isCons >> numConns;
1640                                         
1641                         for(int i = 0;i<numConns;i++)
1642                         {
1643                                 //----------
1644                                 getline(inputStream,line);//CONNECTION
1645                                 getline(inputStream,line);//Startbox.PortName:EndBox.PortName
1646
1647                                 char connec[200];
1648                                 strcpy( connec, line.c_str() );
1649                                 result = strtok( connec, delims );
1650                                 std::string nameStartBox(result);
1651                                 result = strtok( NULL, delims );
1652                                 std::string nameStartPort(result);
1653                                 result = strtok( NULL, delims );
1654                                 std::string nameEndBox(result);
1655                                 result = strtok( NULL, delims );
1656                                 std::string nameEndPort(result);
1657
1658                                 std::vector<int> lstB = getBlackBoxes();
1659                                 
1660                                 GPortModel *startP=NULL;
1661                                 GPortModel *endP=NULL;                          
1662                                 for(int j = 0;j<lstB.size();j++)
1663                                 {
1664                                         int idB = lstB[j];
1665                                         GBlackBoxModel *bbMod = (GBlackBoxModel*)_controllers[idB]->getModel();
1666                                         if(_controllers[idB]->getModel()->getBBTKName()==nameStartBox)
1667                                         {                                               
1668                                                 startP = bbMod->getOutputPort(nameStartPort);
1669                                         }
1670                                         else if(_controllers[idB]->getModel()->getBBTKName()==nameEndBox)
1671                                         {
1672                                                 endP = bbMod->getInputPort(nameEndPort);
1673                                         }
1674                                 } // for
1675
1676                                 if(_isComplexBox)
1677                                 {
1678                                         if(startP==NULL)
1679                                         {
1680                                                 std::vector<int> lstInputs = getComplexInputPorts();
1681                                                 for(int j = 0;j<lstInputs.size();j++)
1682                                                 {
1683                                                         int idB = lstInputs[j];
1684                                                         GBoxModel *cbMod = (GBoxModel*)_controllers[idB]->getModel();
1685                                                         if(_controllers[idB]->getModel()->getBBTKName()==nameStartBox)
1686                                                         {                                               
1687                                                                 startP = cbMod->getOutputPort(nameStartPort);
1688                                                         }
1689                                                 }
1690                                         }
1691
1692                                         if(endP==NULL)
1693                                         {
1694                                                 std::vector<int> lstOutputs = getComplexOutputPorts();
1695                                                 for(int j = 0;j<lstOutputs.size();j++)
1696                                                 {
1697                                                         int idB = lstOutputs[j];
1698                                                         GBoxModel *cbMod = (GBoxModel*)_controllers[idB]->getModel();
1699                                                         if(_controllers[idB]->getModel()->getBBTKName()==nameEndBox)
1700                                                         {                                               
1701                                                                 endP = cbMod->getInputPort(nameEndPort);
1702                                                         }
1703                                                 }
1704                                         }
1705                                 } // complex box
1706                                                                 
1707                                 int idCon = createGConnector(startP);
1708                                 _worldState = NOTHING_HAPPENS;
1709                                 GConnectorController *tempp = (GConnectorController*)_controllers[idCon]; 
1710
1711                                 GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
1712                                 vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
1713                                 tempp->endContourCreation();
1714                                 conMod->setEndPort(endP);                                       
1715                                 conView->updateStartEndPoints();
1716
1717                         } // for numConns
1718         } // start
1719
1720         }
1721
1722         //=========================================================================
1723
1724         std::vector<int> wxVtkSceneManager::getBlackBoxes()
1725         {
1726                 std::vector<int> vect;
1727                 std::map<int, GObjectController*>::iterator it;
1728                 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1729                 {
1730                         GObjectController *cont = it->second;           
1731                         if(cont->getGObjectType()==GBLACKBOX)
1732                         {
1733                                 vect.push_back(cont->getId());
1734                         }
1735                 }
1736                 return vect;
1737         }
1738
1739         //=========================================================================
1740
1741         std::vector<int> wxVtkSceneManager::getComplexInputPorts()
1742         {
1743                 std::vector<int> vect;
1744                 std::map<int, GObjectController*>::iterator it;
1745                 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1746                 {
1747                         GObjectController *cont = it->second;           
1748                         if(cont->getGObjectType()==GCOMPLEXINPUTPORT)
1749                         {
1750                                 vect.push_back(cont->getId());
1751                         }
1752                 }
1753                 return vect;
1754         }
1755
1756         //=========================================================================
1757
1758         std::vector<int> wxVtkSceneManager::getComplexOutputPorts()
1759         {
1760                 std::vector<int> vect;
1761                 std::map<int, GObjectController*>::iterator it;
1762                 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1763                 {
1764                         GObjectController *cont = it->second;           
1765                         if(cont->getGObjectType()==GCOMPLEXOUTPUTPORT)
1766                         {
1767                                 vect.push_back(cont->getId());
1768                         }
1769                 }
1770                 return vect;
1771         }
1772
1773         //=========================================================================
1774
1775         std::vector<int> wxVtkSceneManager::getConnections()
1776         {
1777                 std::vector<int> vect;
1778                 std::map<int, GObjectController*>::iterator it;
1779                 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1780                 {
1781                         GObjectController *cont = it->second;           
1782                         if(cont->getGObjectType()==GCONNECTOR)
1783                         {
1784                                 vect.push_back(cont->getId());
1785                         }
1786                 }
1787                 return vect;
1788         }
1789
1790         //=========================================================================
1791         
1792         bool wxVtkSceneManager::isComplexBox()
1793         {
1794                 return _isComplexBox;
1795         }
1796
1797         //=========================================================================
1798
1799         void wxVtkSceneManager::setComplexBox(bool val)
1800         {
1801                 _isComplexBox=val;
1802         }
1803  
1804         //=========================================================================
1805
1806         int wxVtkSceneManager::addObjectController(GObjectController* objController)
1807         {
1808                 //Register the controller of the new object
1809                 registerController((InteractorStyleMaracas*) objController);
1810
1811                 //Add the object to the objects list 
1812                 int newId = _contLastId;//_controllers.size();
1813                 objController->setId(newId);
1814                 _controllers[newId] = objController;
1815                 _contLastId++;
1816                 return newId;
1817         }
1818
1819         //=========================================================================
1820
1821         int wxVtkSceneManager::getNumSelectedObjects()
1822         {
1823                 return _selectedObjects.size();
1824         }
1825
1826         //=========================================================================
1827
1828         std::map<int,GObjectController*> wxVtkSceneManager::getSelectedObjects()
1829         {
1830                 std::map<int,GObjectController*> mapSelected;
1831
1832                 std::map<int, GObjectController*>::iterator it;
1833                 for(it = _controllers.begin(); it != _controllers.end(); ++it)
1834                 {
1835                         GObjectController *cont = it->second;           
1836                         if(cont->getGObjectType()==GBLACKBOX && cont->getView()->getState()==SELECTED)
1837                         {
1838                                 mapSelected[cont->getId()]=cont;
1839                         }
1840                 }
1841
1842                 std::map<int, GObjectController*>::iterator it2;
1843                 for(it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
1844                 {
1845                         GObjectController *cont = it2->second;          
1846                         if(cont->getGObjectType()==GCONNECTOR)
1847                         {
1848                                 GConnectorModel* cmod = (GConnectorModel*)cont->getModel();
1849                                 GBoxModel* endPortParentBox = cmod->getEndPort()->getParentBox();
1850                                 GBoxModel* startPortParentBox = cmod->getStartPort()->getParentBox();
1851
1852                                 std::map<int, GObjectController*>::iterator iterOBJ1 = mapSelected.find(startPortParentBox->getObjectId());
1853                                 std::map<int, GObjectController*>::iterator iterOBJ2 = mapSelected.find(endPortParentBox->getObjectId());
1854                                 
1855                                 if(iterOBJ1 != mapSelected.end() && iterOBJ2 != mapSelected.end())
1856                                 {                                       
1857                                         int ID = cont->getId();
1858                                         mapSelected[ID]=cont;
1859                                 }
1860                                 
1861                         }
1862                 }
1863                 return mapSelected;
1864         }
1865
1866         //=========================================================================
1867
1868         void wxVtkSceneManager::addObjects(std::map<int,GObjectController*> objectsMap)
1869         {
1870                 
1871                 std::map<int,int> oldIdNewIdBoxes;
1872                 std::vector<int> connections;
1873
1874                 std::map<int, GObjectController*>::iterator it;         
1875                 for(it = objectsMap.begin(); it != objectsMap.end(); ++it)
1876                 {
1877                         GObjectController *cont = it->second;
1878                         int type = cont->getGObjectType();
1879
1880                         if(type==GBLACKBOX)
1881                         {
1882                                 // Copy black box
1883                                 double xInic, yInic,zInic;
1884                                 GBlackBoxModel* copyBox = (GBlackBoxModel*)cont->getModel();
1885                                 copyBox->getInicPoint(xInic,yInic,zInic);
1886                                 int idBox = createGBlackBox(0,0,copyBox->getBBTKPackage(),copyBox->getBBTKType());
1887
1888                                 int idcB = copyBox->getObjectId();
1889                                 oldIdNewIdBoxes[idcB]=idBox;
1890                                 cont = _controllers[idBox];                                                             
1891                                 GBlackBoxModel* newbox  = (GBlackBoxModel*)cont->getModel();
1892                                 newbox->setInicPoint(xInic,yInic,zInic);                                                        
1893                                 int num = newbox->getNumInputPorts();
1894                                 for(int j=0;j<num;j++)
1895                                 {
1896                                         newbox->setValueToInputPort(j,copyBox->getValueInputPort(j));
1897                                 }
1898                                 newbox->notifyObservers(_idManager);
1899                         }
1900                         else if(type==GCONNECTOR)
1901                         {
1902                                 int idCon = cont->getId();
1903                                 connections.push_back(idCon);
1904                         }
1905                         
1906                 }
1907                 
1908                 for(int i = 0 ;i<connections.size();i++)
1909                 {
1910                         int objId = connections[i];
1911                         GObjectController *cont = objectsMap[objId];                    
1912                         GConnectorModel* connectModel = (GConnectorModel*)cont->getModel();
1913                         
1914                         GPortModel* startPort = connectModel->getStartPort();
1915                         int startPortIndex = startPort->getPosInBox();
1916                         GPortModel* endPort = connectModel->getEndPort();
1917                         int endPortIndex = endPort->getPosInBox();                      
1918
1919                         GBlackBoxModel* startPortParentBox = (GBlackBoxModel*)startPort->getParentBox();
1920                         GBlackBoxModel* endPortParentBox = (GBlackBoxModel*)endPort->getParentBox();
1921                         
1922                         int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
1923                         int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
1924
1925                         GBlackBoxModel* newStartBox = (GBlackBoxModel*)_controllers[idNewStartBox]->getModel();
1926                         GBlackBoxModel* newEndBox = (GBlackBoxModel*)_controllers[idNewEndBox]->getModel();
1927
1928                         GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
1929                         GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
1930
1931                         // Creates connection 
1932                         int idCon = createGConnector(newStartPort);
1933                         GConnectorController *tempp = (GConnectorController*)_controllers[idCon]; 
1934                         GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
1935                         vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
1936                         tempp->endContourCreation();
1937                         conMod->setEndPort(newEndPort);                                 
1938                         conView->updateStartEndPoints();
1939                 }
1940
1941                 std::map<int, int>::iterator itIds;             
1942                 for(itIds = oldIdNewIdBoxes.begin(); itIds != oldIdNewIdBoxes.end(); ++itIds)
1943                 {
1944                         int idOld = itIds->first;
1945                         int idNew = itIds->second;
1946
1947                         GBlackBoxModel* oldBox = (GBlackBoxModel*)objectsMap[idOld]->getModel();
1948                         GBlackBoxModel* newBox = (GBlackBoxModel*)_controllers[idNew]->getModel();
1949
1950                         std::vector<int> oldInputConnections = oldBox->getConnectedInputs();
1951                         std::vector<int> oldOutputConnections = oldBox->getConnectedOutputs();
1952                         std::vector<int> newInputConnections = newBox->getConnectedInputs();
1953                         std::vector<int> newOutputConnections = newBox->getConnectedOutputs();
1954
1955                         for(int k = 0; k<oldInputConnections.size();k++)
1956                         {
1957                                 bool exist=false;
1958                                 int toCreate=-1;
1959                                 for(int l = 0; l<newInputConnections.size() && !exist;l++)
1960                                 {
1961                                         if(oldInputConnections[k]==newInputConnections[l])
1962                                         {
1963                                                 exist=true;
1964                                         }
1965                                 }
1966
1967                                 if(exist==false)
1968                                 {
1969                                         //Create complex input 
1970                                         int posInBox = oldInputConnections[k];
1971                                         GPortModel* inputPort = oldBox->getInputPort(posInBox);
1972                                         std::string inputPortName = inputPort->getBBTKName();
1973                                         int idInputPort = createGComplexBoxInputPort(inputPortName);
1974                                         GObjectController *cont = _controllers[idInputPort];
1975                                         GBoxModel *cbmod = (GBoxModel*)cont->getModel();
1976                                         double xIn,yIn,zIn;
1977                                         inputPort->getInicPoint(xIn,yIn,zIn);
1978                                         yIn+=20;
1979                                         cbmod->setInicPoint(xIn,yIn,zIn);
1980                                         cbmod->notifyObservers(_idManager);
1981                                                                                                                 
1982                                         GPortModel* inputPortEnd = newBox->getInputPort(posInBox);
1983
1984                                         // Creates connection 
1985                                         int idCon = createGConnector(cbmod->getOutputPort(0));
1986                                         GConnectorController *tempp = (GConnectorController*)_controllers[idCon]; 
1987                                         GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
1988                                         vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
1989                                         tempp->endContourCreation();
1990                                         conMod->setEndPort(inputPortEnd);                                       
1991                                         conView->updateStartEndPoints();
1992
1993                                 }
1994                                         
1995                         }
1996                         
1997
1998                         for(int k = 0; k<oldOutputConnections.size();k++)
1999                         {
2000                                 bool exist=false;
2001                                 int toCreate=-1;
2002                                 for(int l = 0; l<newOutputConnections.size() && !exist;l++)
2003                                 {
2004                                         if(oldOutputConnections[k]==newOutputConnections[l])
2005                                         {
2006                                                 exist=true;
2007                                         }
2008                                 }
2009
2010                                 if(exist==false)
2011                                 {
2012                                         //Create complex output 
2013                                         int posInBox = oldOutputConnections[k];
2014                                         GPortModel* outputPort = oldBox->getOutputPort(posInBox);
2015                                         std::string outputPortName = outputPort->getBBTKName();
2016                                         int idOutputPort = createGComplexBoxOutputPort(outputPortName);
2017                                         GObjectController *cont = _controllers[idOutputPort];
2018                                         GBoxModel *cbmod = (GBoxModel*)cont->getModel();
2019                                         double xIn,yIn,zIn;
2020                                         outputPort->getInicPoint(xIn,yIn,zIn);
2021                                         yIn-=20;
2022                                         cbmod->setInicPoint(xIn,yIn,zIn);
2023                                         cbmod->notifyObservers(_idManager);
2024                                                                                                                 
2025                                         GPortModel* outputPortEnd = newBox->getOutputPort(posInBox);
2026
2027                                         // Creates connection 
2028                                         int idCon = createGConnector(outputPortEnd);
2029                                         GConnectorController *tempp = (GConnectorController*)_controllers[idCon]; 
2030                                         GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
2031                                         vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
2032                                         tempp->endContourCreation();
2033                                         conMod->setEndPort(cbmod->getInputPort(0));                                     
2034                                         conView->updateStartEndPoints();
2035
2036                                 }
2037                                         
2038                         }
2039
2040                 }
2041
2042
2043         }
2044
2045         //=========================================================================     
2046
2047 }  // EO namespace bbtk
2048
2049 // EOF
2050