]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsKernelEditorGraphic/wxVtkSceneManager.cxx
c4efe5605d986f87da642f9bbcd499ea122c47e3
[bbtkGEditor.git] / lib / EditorGraphicBBS / bbsKernelEditorGraphic / 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                 _idLastController=0;
51                 _startDragging=false;
52
53                 if( _baseView!=NULL )
54                 {
55                         _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget((wxDropTarget*)parent);                      
56                         configureBaseView();
57                         _worldState=NOTHING_HAPPENS;
58                         registerController(this);
59                         
60                 }
61
62         }
63
64         //=========================================================================
65
66         void wxVtkSceneManager::disconnectDrop()
67         {
68                 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget(NULL);
69         }
70
71         //=========================================================================
72
73         wxVtkSceneManager::~wxVtkSceneManager()
74         {
75         }
76
77         //=========================================================================
78
79         void wxVtkSceneManager::configureBaseView()
80         {
81                 vtkInteractorStyleBaseView2D *interactorstylebaseview = vtkInteractorStyleBaseView2D::New();
82
83                 _baseView->SetInteractorStyleBaseView(interactorstylebaseview);
84
85                 // Important to activate the 2D interaction system
86                 wxVTKRenderWindowInteractor *iren = _baseView->GetWxVTKRenderWindowInteractor();
87                 interactorstylebaseview->SetInteractor ( iren );
88                 iren->SetInteractorStyle(interactorstylebaseview);
89                 interactorstylebaseview->SetwxVtkBaseView(_baseView);
90                 
91                 _baseView->GetRenderer()->GetActiveCamera()->ParallelProjectionOn();
92                 _baseView->GetRenderer()->ResetCamera(-100,100,-100,100,900,1000);
93                 
94                 _baseView->GetRenderer()->SetBackground(0.9,0.9,0.9);
95                 _baseView->GetRenderer()->GradientBackgroundOff();
96                 _baseView->Refresh();
97         }
98
99         //=========================================================================
100
101         void wxVtkSceneManager::createGBlackBox(int x, int y, std::string packageName, std::string boxType)
102         {
103
104                 int windowWidth=_baseView->GetRenWin()->GetSize()[0];
105                 int windowHeight=_baseView->GetRenWin()->GetSize()[1];
106
107                 int type = GBLACKBOX;
108
109                 //Create the MVC Objects
110                 
111                 GBlackBoxModel *model = (GBlackBoxModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
112                 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
113                 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
114                 
115                 BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxType);
116                 
117                 //Prepares the initial model
118                 //The coordinates obtained are the following. Top-Left:x=0,y=0 Bottom-Right:x=width,y=height  
119
120                 double xx = x;
121                 double yy = windowHeight-y;
122                 
123                 //z value is not important yet, because it is only used a parallel projection
124                 double zz = 900;
125
126                 _baseView->TransCoordScreenToWorld(xx,yy,zz);
127                 model->setInicPoint(xx,yy,zz);
128                 
129                 _numBoxes++;
130                 std::stringstream stream;
131                 
132                 if(_numBoxes<10)
133                 {
134                         stream << "Box0" << _numBoxes;
135                 }
136                 else
137                 {
138                         stream << "Box" << _numBoxes;
139                 }
140                 std::string arraystring = stream.str();
141
142                 model->setBBTKName(arraystring);
143                 model->setBBTKType(boxType);
144                 model->setBBTKPackage(packageName);
145                                 
146                 model->addObserver(view);
147                 model->addObserver(this);
148
149                 //Iterate and create the input ports
150                 std::map<std::string, BlackBoxInputDescriptor*> descriptorInMap = descriptor->GetInputDescriptorMap();
151                 std::map<std::string, BlackBoxInputDescriptor*>::iterator itInput;
152
153                 int i=0;
154                 for(itInput = descriptorInMap.begin(); itInput != descriptorInMap.end(); ++itInput)
155                 {
156                         BlackBoxInputDescriptor *desc = itInput->second;
157                         createGInputPort(GINPUTPORT,i,model,desc);
158                         i++;
159                 }
160
161                 //Iterate and create the output ports
162                 std::map<std::string, BlackBoxOutputDescriptor*> descriptorOutMap = descriptor->GetOutputDescriptorMap();
163                 std::map<std::string, BlackBoxOutputDescriptor*>::iterator itOutput;
164
165                 i=0;
166                 for(itOutput = descriptorOutMap.begin();itOutput != descriptorOutMap.end(); ++itOutput)
167                 {
168                         BlackBoxOutputDescriptor *desc = itOutput->second;
169                         createGOutputPort(GOUTPUTPORT,i,model,desc);
170                         i++;
171                 }
172
173
174                 //Associates the view with the correspondent renderer and the  model.
175                 //(NOTE: Refresh is only made by the view)
176                 view->setModel(model);
177                 view->setBaseView(_baseView);
178                 view->initVtkObjects();
179                 
180                 //Associates the controller with the correspondent model and view
181                 controller->setModelAndView(model,view);
182
183                 //Resgiter change to the observers of the actual model
184                 model->notifyObservers(_idManager);
185                 
186                 //Register the controller of the new object
187                 registerController((InteractorStyleMaracas*) controller);
188
189                 //Add the object to the objects list 
190                 int newId = _controllers.size();
191                 controller->setId(newId);
192                 _controllers[newId] = controller;
193
194         }
195
196         //=========================================================================
197
198         void wxVtkSceneManager::createGInputPort(int portType, int posinBox,GBlackBoxModel *blackBox, BlackBoxInputDescriptor *desc)
199         {
200                 createGPort(portType,desc->GetName(),desc->GetTypeName(),posinBox,blackBox);
201         }
202
203         //=========================================================================
204
205         void wxVtkSceneManager::createGOutputPort(int portType, int posinBox,GBlackBoxModel *blackBox, BlackBoxOutputDescriptor *desc)
206         {
207                 createGPort(portType,desc->GetName(),desc->GetTypeName(),posinBox,blackBox);
208         }
209
210         //=========================================================================
211
212         void wxVtkSceneManager::createGPort(int portType,std::string bbtkName, std::string bbtkType, int posInBox,GBlackBoxModel *blackBox)
213         {
214                 int type = GPORT;
215
216                 //Create the MVC Objects
217                 GPortModel *model = (GPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
218                 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
219                 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
220
221                 model->registerInBox(blackBox,portType, posInBox);
222                 blackBox->addOutputPort(model);
223                 
224                 model->setBBTKType(bbtkType);
225                 model->setBBTKName(bbtkName);
226
227                 model->addObserver(view);
228                 model->addObserver(this);
229
230                 //Associates the view with the correspondent renderer and the  model.
231                 //(NOTE: Refresh is only made by the view)
232                 view->setModel(model);
233                 view->setBaseView(_baseView);
234                 view->initVtkObjects();
235                 
236                 //Associates the controller with the correspondent model and view
237                 controller->setModelAndView(model,view);
238
239                 model->notifyObservers(_idManager);
240
241                 //Register the controller of the new object
242                 registerController((InteractorStyleMaracas*) controller);
243                 
244                 int newId = _controllers.size();
245                 controller->setId(newId);
246                 _controllers[newId] = controller;
247         }
248
249         //=========================================================================
250
251         void wxVtkSceneManager::createGConnector(GPortModel* startPort)
252         {
253                 int type = GCONNECTOR;
254
255                 manualConnectorContourController* manContourControl     = new manualConnectorContourController();
256                 manualConnectorContourView* manContourView      = new manualConnectorContourView();
257                 manualContourModel* manContourModel     = new manualContourModel();
258
259                 GConnectorController* connectorcontroller = new GConnectorController();                         
260                 GConnectorModel* connectorModel = new GConnectorModel();
261                 GConnectorView* connectorView = new GConnectorView();
262                 connectorModel->setGObjectType(type);
263
264                 manContourModel->SetCloseContour(false);
265                 connectorModel->setStartPort(startPort);
266
267                 manContourView->SetModel( manContourModel );
268                 manContourView->SetWxVtkBaseView( _baseView );
269                 manContourView->SetRange( 0.5 );
270                 manContourView->SetZ( 900 );
271
272                 manContourView->SetColorNormalContour(0, 0, 1);
273                 manContourView->SetColorEditContour(0.5, 0.5, 0.5);
274                 manContourView->SetColorSelectContour(1, 0.8, 0);
275                 manContourView->SetWidthLine(1);
276
277                 manContourControl->SetModelView( manContourModel , manContourView );
278                 
279                 manContourControl->CreateNewManualContour();
280
281                 manContourView->RefreshContour();
282
283
284                 double x,y,z;
285                 connectorModel->getInicPoint(x,y,z);
286
287                 manContourControl->SetState(1);
288                 manContourModel->SetCloseContour(false);
289                 
290                 manContourModel->AddPoint(x,y,z);
291                 manContourView->AddPoint();
292
293                 manContourModel->AddPoint(x,y,z);
294                 manContourView->AddPoint();
295
296                 int bak= manContourControl->GetNumberOfPointsManualContour() - 1;
297                 manContourControl->_bakIdPoint=bak;
298                 manContourView->Refresh();
299
300                 manContourControl->SetMoving( false );
301
302                 registerController((InteractorStyleMaracas*) connectorcontroller);
303
304                 connectorcontroller->setManualContourController(manContourControl);             
305                 connectorModel->setManualContourModel(manContourModel);
306                 connectorView->setManualContourView(manContourView);
307                 connectorView->setModel(connectorModel);
308                 connectorcontroller->setModelAndView(connectorModel,connectorView);
309
310                 int newId = _controllers.size();
311                 connectorcontroller->setId(newId);
312                 _controllers[newId] = connectorcontroller;
313
314         }
315
316         //=========================================================================
317
318         void wxVtkSceneManager::registerController(InteractorStyleMaracas *param)
319         {
320                 vtkInteractorStyleBaseView* baseViewControlManager = (vtkInteractorStyleBaseView*)_baseView->GetInteractorStyleBaseView();
321                 baseViewControlManager->AddInteractorStyleMaracas( param );
322         }
323
324         //=========================================================================
325
326         void wxVtkSceneManager::unregisterController(InteractorStyleMaracas *param)
327         {
328                 vtkInteractorStyleBaseView* baseViewControlManager = (vtkInteractorStyleBaseView*)_baseView->GetInteractorStyleBaseView();
329                 baseViewControlManager->RemoveInteractorStyleMaracas( param );
330         }
331
332         //=========================================================================
333
334         vtkRenderer* wxVtkSceneManager::getRenderer()
335         {
336                 return _baseView->GetRenderer();
337         }
338
339         //=========================================================================
340
341         vtkRenderWindow* wxVtkSceneManager::getRenderWindow()
342         {
343                 return _baseView->GetRenWin();
344         }
345         //=========================================================================
346
347                 
348         void wxVtkSceneManager::update(int idController,int command)
349         {
350                 if(command != NO_COMMAND)
351                 {
352                         if(command == ADD_TO_SELECTED)
353                         {
354                                 GObjectController* cont = _controllers[idController];
355
356                                 bool foundID=false;
357                                 for (int i=0; i<_selectedObjects.size() && foundID==false; i++)
358                                 {
359                                         int id = _selectedObjects[i];
360                                         if(id==idController)
361                                         {
362                                                 foundID = true;
363                                         }
364                                 }
365                                 if(!foundID)
366                                 {
367                                         int id = idController;
368                                         _selectedObjects.push_back(id);
369                                 }
370
371                         }
372                         else if(command == INIT_CREATION_CONTOUR)
373                         {       
374                                 _worldState = INIT_CREATION_CONTOUR;
375                                 GObjectController* cont = _controllers[idController];
376                                 GPortModel* startOutputPort = (GPortModel*)cont->getModel();
377                                 
378
379                                 // The last one is the controller of the connector
380                                 for(int i=0;i<_controllers.size();i++)
381                                 {
382                                         GObjectController* cont = _controllers[i];
383                                         if(cont->getGObjectType() == GPORT )
384                                         {
385                                                 GPortModel* port = (GPortModel*)cont->getModel();
386                                                 if(port->getPortType()==GINPUTPORT)
387                                                 {
388                                                         cont->SetActive(true);
389                                                 }
390                                                 else
391                                                 {
392                                                         cont->getView()->setState(NOTHING_HAPPENS);
393                                                         cont->getModel()->notifyObservers(_idManager);
394                                                         cont->SetActive(false);
395                                                 }
396                                         }
397                                         else
398                                         {
399                                                 cont->getView()->setState(NOTHING_HAPPENS);
400                                                 cont->getModel()->notifyObservers(_idManager);
401                                                 cont->SetActive(false);
402                                         }                               
403                                 }
404
405                                 _selectedObjects.clear();
406
407                                 createGConnector(startOutputPort);
408
409                         }
410                         else if(command == FIN_CREATION_CONTOUR && _worldState == INIT_CREATION_CONTOUR)
411                         {                               
412                                 _worldState = NOTHING_HAPPENS;
413                                 int id = _controllers.size()-1;
414                                 GObjectController* cont = _controllers[id];                     
415                                 GConnectorModel* modelContour = (GConnectorModel*)cont->getModel();
416
417                                 GObjectController* finPort = _controllers[idController];
418                                 if(finPort->getGObjectType() == GPORT)
419                                 {
420                                         GPortModel* modelPort = (GPortModel*)finPort->getModel();
421                                         modelContour->setEndPort(modelPort);
422                                 }                       
423
424                                 manualConnectorContourController* manCont = ((GConnectorController*)cont)->getManualContourController();                        
425                                 manualConnectorContourView* connView = (manualConnectorContourView*)manCont->GetManualViewBaseContour();
426                                 connView->Refresh();
427
428                                 for(int i=0;i<_controllers.size();i++)
429                                 {
430                                         GObjectController* cont = _controllers[i];
431                                         if(cont->getView()!=NULL)
432                                         {
433                                                 cont->getView()->setState(NOTHING_HAPPENS);
434                                                 cont->getModel()->notifyObservers(_idManager);
435                                         }
436                                         cont->SetActive(true);                                                          
437                                 }
438                         }
439                 }
440         }
441
442         //=========================================================================
443
444         bool wxVtkSceneManager::OnMouseMove()
445         {
446                 int X,Y;
447                 wxVTKRenderWindowInteractor *wxVTKiren;
448                 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
449                 wxVTKiren->GetEventPosition(X,Y);
450         
451                 
452                 if(_worldState == DRAG_OBJECTS)
453                 {                       
454                         for (int i=0; i<_selectedObjects.size(); i++)
455                         {
456                                 int id = _selectedObjects[i];
457                                 GObjectController* cont = _controllers[id];
458                                 if(_startDragging)
459                                 {
460                                         cont->getView()->setStartDragging(true);
461                                 }
462                                 cont->getView()->moveObject(X,Y);
463                                 cont->getView()->setState(DRAG);
464                                 cont->getModel()->notifyObservers(_idManager);
465                         }
466
467                         std::map<int, GObjectController*>::iterator it;
468
469                         for(it = _controllers.begin(); it != _controllers.end(); ++it)
470                         {
471                                 GObjectController *desc = it->second;
472                                 if(desc->getGObjectType()==GCONNECTOR)
473                                 {
474                                         GConnectorView* vconn = (GConnectorView*)desc->getView();
475                                         vconn->updateStartEndPoints();
476                                 }
477                         }
478                         
479                         _startDragging=false;
480
481                 }
482                 else if(_worldState == NOTHING_HAPPENS || _worldState == INIT_CREATION_CONTOUR)
483                 {
484                         std::map<int, GObjectController*>::iterator it;
485
486                         for(it = _controllers.begin(); it != _controllers.end(); ++it)
487                         {
488                                 GObjectController *desc = it->second;
489                                 int type = desc->getGObjectType();
490                                 int state = desc->getView()->getState();
491                                 
492                                 if(state == HIGHLIGHTED){
493
494                                         updateStatusBar(desc->getStatusText());
495                                         if(type==GBLACKBOX)
496                                         {
497                                                 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
498                                                 _parent->displayBlackBoxInfo(mod->getBBTKPackage(),mod->getBBTKType());
499                                         }
500                                 }
501                         }
502                 }
503                 
504                 
505
506
507                 return true;
508         }
509
510         //=========================================================================
511         
512         bool wxVtkSceneManager::OnLeftButtonDown()
513         {
514                 
515                 if(_selectedObjects.size()!=0)
516                 {
517                         _worldState = DRAG_OBJECTS;
518                         _startDragging = true;
519
520                         for (int i = 0; i < _selectedObjects.size(); i++)
521                         {
522                                 int id = _selectedObjects[i];
523                                 GObjectController* cont = _controllers[id];
524                                 cont->getView()->setState(DRAG);
525                                 cont->getModel()->notifyObservers(_idManager);
526                         }
527                 }
528                 
529                 
530                 
531                 return true;
532         }
533
534         //=========================================================================
535         
536         bool wxVtkSceneManager::OnLeftButtonUp()
537         {
538                 if(_worldState == DRAG_OBJECTS)
539                 {
540                         _worldState = NOTHING_HAPPENS;
541
542                         for (int i = 0; i < _selectedObjects.size(); i++)
543                         {
544                                 int id = _selectedObjects[i];
545                                 GObjectController* cont = _controllers[id];
546                                 cont->getView()->setState(SELECTED);
547                                 cont->getModel()->notifyObservers(_idManager);
548                         }
549                 }
550                 return true;
551         }
552
553         //=========================================================================
554
555         bool wxVtkSceneManager::OnRightButtonUp()
556         {
557                 for (int i = 0; i < _selectedObjects.size(); i++)
558                 {
559                         int id = _selectedObjects[i];
560                         GObjectController* cont = _controllers[id];
561                         cont->SetActive(true);
562                         cont->getView()->setState(NOTHING_HAPPENS);
563                         cont->getModel()->notifyObservers(_idManager);
564                 }
565
566                 _selectedObjects.clear();
567
568                 return true;
569         }
570
571         //=========================================================================
572
573         bool wxVtkSceneManager::OnChar()
574         {       
575                 char keyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
576                 
577                 // KeyCode 127 : Delete Key
578                 // KeyCode 8 : Backspace Key
579                 if(keyCode == 8 || keyCode == 127)
580                 {
581                         if(_selectedObjects.size()>0)
582                         {
583                                 for(int i=0;i<_selectedObjects.size();i++)
584                                 {
585                                         int id = _selectedObjects[i];
586                                         removeObject(id);
587                                 }
588                                 _selectedObjects.clear();
589                         }
590                 }
591
592                 return true;
593         }
594
595         //=========================================================================
596
597         void wxVtkSceneManager::removeObject(int id)
598         {
599                 GObjectController *control = _controllers[id];
600                 std::vector<int> controllersToRemove;
601
602                 if(control->getGObjectType()==GBLACKBOX)
603                 {
604                         GBlackBoxModel *bbmod = (GBlackBoxModel*)control->getModel();
605                         std::vector<GPortModel*>inputs = bbmod->getInputPorts();
606                         
607                         for(int i = 0;i<inputs.size();i++)
608                         {
609                                 controllersToRemove.push_back(inputs[i]->getObjectId());
610                         }
611
612                         std::vector<GPortModel*>outputs = bbmod->getOutputPorts();
613
614                         for(int i = 0;i<outputs.size();i++)
615                         {
616                                 controllersToRemove.push_back(outputs[i]->getObjectId());
617                         }
618
619                         controllersToRemove.push_back(control->getId());
620                 }
621
622                 for(int i = 0;i<controllersToRemove.size();i++)
623                 {
624                         int id = controllersToRemove[i];
625                         GObjectController *cont = _controllers[id];
626                         cont->removeFromScene();
627                         unregisterController((InteractorStyleMaracas*)cont);
628                         _controllers.erase(id);
629                 }
630
631
632         }
633
634         //=========================================================================
635
636         void wxVtkSceneManager::displayBlackBoxInfo(std::string packageName, std::string boxName)
637         {
638                 _parent->displayBlackBoxInfo(packageName,boxName);
639         }
640
641         //=========================================================================
642
643         void wxVtkSceneManager::updateStatusBar(std::string textStatus)
644         {
645                 _parent->updateStatusBar(textStatus);
646         }
647
648         //=========================================================================
649
650         std::string wxVtkSceneManager::getDiagramScript()
651         {
652                 bool existsExec=false;
653
654                 std::vector<std::string> packages;
655                 std::vector<int> boxes;
656                 std::vector<int> connections;
657                 std::vector<int> execBoxes;
658
659                 std::map<int, GObjectController*>::iterator it;
660
661                 for(it = _controllers.begin(); it != _controllers.end(); ++it)
662                 {
663                         GObjectController *desc = it->second;
664                         int type = desc->getGObjectType();
665
666                         if(type==GBLACKBOX)
667                         {
668                                 GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
669                                 
670                                 std::string pkg = mod->getBBTKPackage();
671                                 bool existsPkg = false;
672                                 for(int t = 0;t<packages.size() && existsPkg == false;t++)
673                                 {
674                                         if(packages[t]==pkg)
675                                         {
676                                                 existsPkg=true;
677                                         }
678                                 }
679                                 if(!existsPkg)
680                                 {
681                                         packages.push_back(pkg);
682                                 }
683
684
685                                 boxes.push_back(it->first);
686                                 if(mod->isExecutable())
687                                 {
688                                         execBoxes.push_back(it->first);
689                                         existsExec=true;
690                                 }
691                         }
692                         else if(type==GCONNECTOR)
693                         {
694                                 connections.push_back(it->first);
695                         }
696                 }
697
698                 std::string script = "";
699                 script+="# BBTK GEditor Script\n";
700                 script+="# ----------------------\n";
701                 if(existsExec)
702                 {
703                         int i;
704                         for(i = 0; i<packages.size();i++)
705                         {
706                                 script+="load ";
707                                 script+=packages[i];
708                                 script+="\n";
709                         }
710
711                         for(i = 0; i<boxes.size();i++)
712                         {
713                                 script+="new ";
714                                 int id = boxes[i];
715                                 GObjectController *control = _controllers[id];
716                                 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
717
718                                 script+=model->getBBTKType();
719                                 script+=" ";
720                                 script+=model->getBBTKName();
721                                 script+="\n";
722                         }
723
724                         for(i = 0; i<connections.size();i++)
725                         {
726                                 script+="connect ";
727                                 int id = connections[i];
728                                 GObjectController *control = _controllers[id];
729                                 GConnectorModel *model = (GConnectorModel*)control->getModel();
730
731                                 //Start Connection info
732                                 GPortModel *start = model->getStartPort();
733                                 script+=start->getParentBox()->getBBTKName();
734                                 script+=".";
735                                 script+=start->getBBTKName();
736
737                                 script+=" ";
738
739                                 //End Connection info
740                                 GPortModel *end = model->getEndPort();
741                                 script+=end->getParentBox()->getBBTKName();
742                                 script+=".";
743                                 script+=end->getBBTKName();
744
745                                 script+="\n";
746                         }
747
748                         for(i = 0; i<execBoxes.size();i++)
749                         {
750                                 script+="exec ";
751                                 int id = execBoxes[i];
752                                 GObjectController *control = _controllers[id];
753                                 GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
754
755                                 script+=model->getBBTKName();
756                                 script+="\n";
757                         }
758
759                 }
760
761                 return script;
762         }
763
764         //=========================================================================
765
766 }  // EO namespace bbtk
767
768 // EOF
769