]> Creatis software - bbtkGEditor.git/blobdiff - lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxVtkSceneManager.cxx
no message
[bbtkGEditor.git] / lib / EditorGraphicBBS / bbsWxGUIEditorGraphic / wxVtkSceneManager.cxx
index e6b41ad69b3c5c33412548d2548841e16bea89aa..3c8825175f33f32c5ba19337e7bcf54b4a42cf02 100644 (file)
@@ -106,22 +106,67 @@ namespace bbtk
        }
 
        //=========================================================================
+  
+       std::string wxVtkSceneManager::generateANewNameForABox()
+       {
+               std::stringstream boxname;
+               if(_numBoxes<10)
+               {
+                       boxname << "Box0" << _numBoxes;
+               }else{
+                       boxname << "Box" << _numBoxes;
+               }
+               _numBoxes++;
+               return boxname.str();
+       }
 
-       int wxVtkSceneManager::createGBlackBox(int x, int y, std::string packageName, std::string boxType)
+       //=========================================================================
+  
+       std::string wxVtkSceneManager::findANewNameForABox()
        {
-               _worldState = NOTHING_HAPPENS;
-               int windowWidth=_baseView->GetRenWin()->GetSize()[0];
-               int windowHeight=_baseView->GetRenWin()->GetSize()[1];
+               std::string boxname=generateANewNameForABox();
 
-               int type = GBLACKBOX;
+               while (boxExist(boxname)==true)
+               {
+                       boxname=generateANewNameForABox();
+               } // while
+
+               return boxname;
+       }
+
+       //=========================================================================
+//ups1 eed
+       void wxVtkSceneManager::configGBlackBox(int idBox, double xIn, double yIn, double zIn, std::string name, bool boxExecutable,double xEn,double yEn,double zEn)
+       {
+               GObjectController *cont = _controllers[idBox];
+               GBlackBoxModel *bbmod   = (GBlackBoxModel*)cont->getModel();
+               bbmod->setBBTKName(name);
+               bbmod->setInicPoint(xIn,yIn,zIn);
+               bbmod->setFinalPoint(xEn,yEn,zEn);
+               bbmod->setExecutable(boxExecutable);                            
+               
+               bbmod->notifyObservers(_idManager);
+
+       } 
+       
+       
+       //=========================================================================
+
+       int wxVtkSceneManager::createGBlackBox(int x, int y,  std::string packageName, std::string boxType)
+       {
+               _worldState                                                             = NOTHING_HAPPENS;
+//EED          int windowWidth                                                 = _baseView->GetRenWin()->GetSize()[0];
+               int windowHeight                                                = _baseView->GetRenWin()->GetSize()[1];
+
+               int type                                                                = GBLACKBOX;
 
                //Create the MVC Objects
                
-               GBlackBoxModel *model = (GBlackBoxModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
-               vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
-               GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
+               GBlackBoxModel *model                                   = (GBlackBoxModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
+               vtkGObjectView *view                                    = GObjectsMVCFactory::getInstance()->createGObjectView(type);
+               GObjectController* controller                   = GObjectsMVCFactory::getInstance()->createGObjectController(type);
                
-               BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxType);
+               BlackBoxDescriptor::Pointer descriptor  = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxType);
                
                //Prepares the initial model
                //The coordinates obtained are the following. Top-Left:x=0,y=0 Bottom-Right:x=width,y=height  
@@ -135,17 +180,14 @@ namespace bbtk
                _baseView->TransCoordScreenToWorld(xx,yy,zz);
                model->setInicPoint(xx,yy,zz);
                
-               _numBoxes++;
                std::stringstream stream;
                
-               if(_numBoxes<10)
-               {
-                       stream << "Box0" << _numBoxes;
-               }
-               else
-               {
-                       stream << "Box" << _numBoxes;
-               }
+               std::string newBoxName;
+               newBoxName = findANewNameForABox();
+                       
+               
+               stream << newBoxName;
+               
                std::string arraystring = stream.str();
 
                model->setBBTKName(arraystring);
@@ -202,24 +244,24 @@ namespace bbtk
 
        int wxVtkSceneManager::createGComplexBoxInputPort(std::string inputName)
        {
-               int windowWidth=_baseView->GetRenWin()->GetSize()[0];
+//EED          int windowWidth=_baseView->GetRenWin()->GetSize()[0];
                int windowHeight=_baseView->GetRenWin()->GetSize()[1];
                
-               int type = GCOMPLEXINPUTPORT;
+               int type                                                = GCOMPLEXINPUTPORT;
 
                //Create the MVC Objects
                
-               GComplexBoxPortModel *model = (GComplexBoxPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
-               vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
-               GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
+               GComplexBoxPortModel *model             = (GComplexBoxPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
+               vtkGObjectView *view                    = GObjectsMVCFactory::getInstance()->createGObjectView(type);
+               GObjectController* controller   = GObjectsMVCFactory::getInstance()->createGObjectController(type);
                                
                //Prepares the initial model 
 
-               double xx = 5;
-               double yy = windowHeight-5;
+               double xx                                               = 5;
+               double yy                                               = windowHeight-5;
                
                //z value is not important yet, because it is only used a parallel projection
-               double zz = 900;
+               double zz                                               = 900;
 
                _baseView->TransCoordScreenToWorld(xx,yy,zz);
                model->setInicPoint(xx,yy,zz);
@@ -255,24 +297,24 @@ namespace bbtk
        
        int wxVtkSceneManager::createGComplexBoxOutputPort(std::string outputName)
        {
-               int windowWidth=_baseView->GetRenWin()->GetSize()[0];
+//EED          int windowWidth=_baseView->GetRenWin()->GetSize()[0];
                int windowHeight=_baseView->GetRenWin()->GetSize()[1];
 
-               int type = GCOMPLEXOUTPUTPORT;
+               int type                                                = GCOMPLEXOUTPUTPORT;
 
                //Create the MVC Objects
                
-               GComplexBoxPortModel *model = (GComplexBoxPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
-               vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
-               GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
+               GComplexBoxPortModel *model             = (GComplexBoxPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
+               vtkGObjectView *view                    = GObjectsMVCFactory::getInstance()->createGObjectView(type);
+               GObjectController* controller   = GObjectsMVCFactory::getInstance()->createGObjectController(type);
                                
                //Prepares the initial model 
 
-               double xx = 5;
-               double yy = windowHeight-5;
+               double xx                                               = 5;
+               double yy                                               = windowHeight-5;
                
                //z value is not important yet, because it is only used a parallel projection
-               double zz = 900;
+               double zz                                               = 900;
 
                _baseView->TransCoordScreenToWorld(xx,yy,zz);
                model->setInicPoint(xx,yy,zz);
@@ -329,9 +371,9 @@ namespace bbtk
                int type = GPORT;
 
                //Create the MVC Objects
-               GPortModel *model = (GPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
-               vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
-               GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
+               GPortModel *model                               = (GPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
+               vtkGObjectView *view                    = GObjectsMVCFactory::getInstance()->createGObjectView(type);
+               GObjectController* controller   = GObjectsMVCFactory::getInstance()->createGObjectController(type);
 
                model->registerInBox(blackBox,portType, posInBox);
                
@@ -364,12 +406,12 @@ namespace bbtk
                int type = GCONNECTOR;
 
                manualConnectorContourController* manContourControl     = new manualConnectorContourController();
-               manualConnectorContourView* manContourView      = new manualConnectorContourView();
-               manualContourModel* manContourModel     = new manualContourModel();
+               manualConnectorContourView* manContourView                      = new manualConnectorContourView();
+               manualContourModel* manContourModel                                     = new manualContourModel();
 
-               GConnectorController* connectorcontroller = new GConnectorController();                         
-               GConnectorModel* connectorModel = new GConnectorModel();
-               vtkGConnectorView* connectorView = new vtkGConnectorView();
+               GConnectorController* connectorcontroller                       = new GConnectorController();                           
+               GConnectorModel* connectorModel                                         = new GConnectorModel();
+               vtkGConnectorView* connectorView                                        = new vtkGConnectorView();
                connectorModel->setGObjectType(type);
 
                manContourModel->SetCloseContour(false);
@@ -466,10 +508,10 @@ namespace bbtk
                {
                        if(command == ADD_TO_SELECTED)
                        {
-                               GObjectController* cont = _controllers[idController];
+//EED                          GObjectController* cont = _controllers[idController];
 
                                bool foundID=false;
-                               for (int i=0; i<_selectedObjects.size() && foundID==false; i++)
+                               for (int i=0; i<(int)_selectedObjects.size() && foundID==false; i++)
                                {
                                        int id = _selectedObjects[i];
                                        if(id==idController)
@@ -571,7 +613,7 @@ namespace bbtk
                
                if(_worldState == DRAG_OBJECTS)
                {                       
-                       for (int i=0; i<_selectedObjects.size(); i++)
+                       for (int i=0; i<(int)_selectedObjects.size(); i++)
                        {
                                int id = _selectedObjects[i];
                                GObjectController* cont = _controllers[id];
@@ -670,7 +712,7 @@ namespace bbtk
                        _worldState = DRAG_OBJECTS;
                        _startDragging = true;
 
-                       for (int i = 0; i < _selectedObjects.size(); i++)
+                       for (int i = 0; i < (int)_selectedObjects.size(); i++)
                        {
                                int id = _selectedObjects[i];
                                GObjectController* cont = _controllers[id];
@@ -692,7 +734,7 @@ namespace bbtk
                {
                        _worldState = NOTHING_HAPPENS;
 
-                       for (int i = 0; i < _selectedObjects.size(); i++)
+                       for (int i = 0; i < (int)_selectedObjects.size(); i++)
                        {
                                int id = _selectedObjects[i];
                                GObjectController* cont = _controllers[id];
@@ -727,7 +769,7 @@ namespace bbtk
                }
 
                        
-               for (int i = 0; i < _selectedObjects.size(); i++)
+               for (int i = 0; i < (int)_selectedObjects.size(); i++)
                {
                        int id = _selectedObjects[i];
                        GObjectController* cont = _controllers[id];
@@ -763,7 +805,7 @@ namespace bbtk
                        {
                                if(type==GBLACKBOX)
                                {
-                                       for (int i=0; i<_selectedObjects.size(); i++)
+                                       for (int i=0; i< (int)_selectedObjects.size(); i++)
                                        {
                                                int id = _selectedObjects[i];
                                                GObjectController* control = _controllers[id];
@@ -798,10 +840,15 @@ namespace bbtk
                {
                        if(_selectedObjects.size()>0)
                        {
-                               for(int i=0;i<_selectedObjects.size();i++)
+                               for(int i=0;i<(int)_selectedObjects.size();i++)
                                {
-                                       int id = _selectedObjects[i];
-                                       deleteObject(id);
+                                       int id = _selectedObjects[i];                                   
+                                       std::map<int,GObjectController*>::iterator it;
+                    it = _controllers.find(id);
+                                       if (it!=_controllers.end())
+                                       {
+                                               deleteObject(id);
+                                       }
                                }
                                _selectedObjects.clear();
                        }
@@ -812,6 +859,28 @@ namespace bbtk
 
        //=========================================================================
 
+       void wxVtkSceneManager::AddControlerToBeRemove(std::vector<int> *controllersToRemove, int id)
+       {
+               
+               int i;
+               bool ok=true;
+               for(i=0 ; i < (int)controllersToRemove->size() ; i++ )
+               {
+                       if (id == (*controllersToRemove)[i] )
+                       {
+                               ok=false;
+                       }
+               }
+               
+               if (ok==true)
+               {
+                  controllersToRemove->push_back( id );
+               }
+               
+       }
+       
+       //=========================================================================
+       
        void wxVtkSceneManager::deleteObject(int id)
        {
                GObjectController *control = _controllers[id];
@@ -825,9 +894,9 @@ namespace bbtk
                        bool boxConnected = false;
 
                        // Add box input controllers to be removed
-                       for(int i = 0;i<inputs.size();i++)
+                       for(int i = 0;i< (int)inputs.size();i++)
                        {
-                               controllersToRemove.push_back(inputs[i]->getObjectId());
+                               AddControlerToBeRemove( &controllersToRemove, inputs[i]->getObjectId() );
                                if(inputs[i]->isConnected())
                                {
                                        boxConnected = true;
@@ -837,9 +906,9 @@ namespace bbtk
                        std::vector<GPortModel*> outputs = bbmod->getOutputPorts();
 
                        // Add box output controllers to be removed
-                       for(int i = 0;i<outputs.size();i++)
+                       for(int i = 0;i<(int)outputs.size();i++)
                        {
-                               controllersToRemove.push_back(outputs[i]->getObjectId());
+                               AddControlerToBeRemove( &controllersToRemove, outputs[i]->getObjectId() );
                                if(outputs[i]->isConnected())
                                {
                                        boxConnected = true;
@@ -857,37 +926,39 @@ namespace bbtk
                                        GConnectorModel *conMod = (GConnectorModel*)cont->getModel();
                                        if(conMod->getStartPort()!=NULL && conMod->getStartPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
                                        {
-                                               controllersToRemove.push_back(conMod->getObjectId());
+                                               AddControlerToBeRemove( &controllersToRemove, conMod->getObjectId() );
                                        }
                                        if(conMod->getEndPort()!=NULL && conMod->getEndPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
                                        {
-                                               controllersToRemove.push_back(conMod->getObjectId());
+                                               AddControlerToBeRemove( &controllersToRemove, conMod->getObjectId() );
                                        }
                                }
                        }
 
                        // Add box controller to be removed
-                       controllersToRemove.push_back(bbmod->getObjectId());
+                       AddControlerToBeRemove( &controllersToRemove, bbmod->getObjectId() );
                }
                else if(control->getGObjectType()==GCONNECTOR)
                {                       
                        GConnectorModel *conMod = (GConnectorModel*)control->getModel();
-                       controllersToRemove.push_back(conMod->getObjectId());
+                       AddControlerToBeRemove( &controllersToRemove, conMod->getObjectId() );
                }
 
-               for(int i = 0;i<controllersToRemove.size();i++)
+               
+               std::map<int,GObjectController*>::iterator it;
+
+               for(int i = 0;i<(int)controllersToRemove.size();i++)
                {
-                       int id = controllersToRemove[i];
-                       GObjectController *cont = _controllers[id];
+                       int key = controllersToRemove[i];
+                       it = _controllers.find( key );
+                       GObjectController *cont = _controllers[ key ];
                        if(cont!=NULL)
                        {
                                cont->removeFromScene();
                                unregisterController((InteractorStyleMaracas*)cont);                    
-                               _controllers.erase(id);
-                       }
-               }
-
-
+                               _controllers.erase(it);
+                       }//if
+               }// for
        }
 
        //=========================================================================
@@ -928,7 +999,7 @@ namespace bbtk
                                
                                std::string pkg = mod->getBBTKPackage();
                                bool existsPkg = false;
-                               for(int t = 0;t<packages.size() && existsPkg == false;t++)
+                               for(int t = 0;t< (int)packages.size() && existsPkg == false;t++)
                                {
                                        if(packages[t]==pkg)
                                        {
@@ -962,7 +1033,7 @@ namespace bbtk
                        script+="include std\n"; // EED
                        script+="include itkvtk\n"; // EED
                        int i;
-                       for(i = 0; i<packages.size();i++)
+                       for(i = 0; i< (int)packages.size();i++)
                        {
                                script+="include ";
                                script+=packages[i];
@@ -971,7 +1042,7 @@ namespace bbtk
 
                        // script+="include std\n"; // JPR
 
-                       for(i = 0; i<boxes.size();i++)
+                       for(i = 0; i < (int)boxes.size();i++)
                        {
                                script+="new ";
                                int id = boxes[i];
@@ -984,7 +1055,7 @@ namespace bbtk
                                script+="\n";
 
                                std::vector<GPortModel*> inputs = model->getInputPorts();
-                               for(int j = 0; j<inputs.size();j++)
+                               for(int j = 0; j < (int)inputs.size();j++)
                                {
                                        GPortModel* inputPort = inputs[j];
                                        if(inputPort->isValueSet())
@@ -1001,7 +1072,7 @@ namespace bbtk
 
                        }
 
-                       for(i = 0; i<connections.size();i++)
+                       for(i = 0; i<(int)connections.size();i++)
                        {
                                script+="connect ";
                                int id = connections[i];
@@ -1025,7 +1096,7 @@ namespace bbtk
                                script+="\n";
                        }
 
-                       for(i = 0; i<execBoxes.size();i++)
+                       for(i = 0; i<(int)execBoxes.size();i++)
                        {
                                script+="exec ";
                                int id = execBoxes[i];
@@ -1064,7 +1135,7 @@ namespace bbtk
                                
                                std::string pkg = mod->getBBTKPackage();
                                bool existsPkg = false;
-                               for(int t = 0;t<packages.size() && existsPkg == false;t++)
+                               for(int t = 0;t<(int)packages.size() && existsPkg == false;t++)
                                {
                                        if(packages[t]==pkg)
                                        {
@@ -1094,17 +1165,19 @@ namespace bbtk
                script+="include std\n";    // EED
                script+="include itkvtk\n"; // EED
                int i;
-               for(i = 0; i<packages.size();i++)
+               for(i = 0; i<(int)packages.size();i++)
                {
                        script+="include ";
                        script+=packages[i];
                        script+="\n";
                }
+               script+="\n";
 
                // Definition of a complex box
                script+="define ";
                script+=cbName;
                script+="\n";
+               script+="\n";
 
                script+="author \" ";
                script+=cbAuthor;
@@ -1113,9 +1186,10 @@ namespace bbtk
                script+="description \" ";
                script+=cbDescription;
                script+="\"\n";
+               script+="\n";
 
                // Create boxes
-               for(i = 0; i<boxes.size();i++)
+               for(i = 0; i<(int)boxes.size();i++)
                {
                        script+="new ";
                        int id = boxes[i];
@@ -1128,12 +1202,12 @@ namespace bbtk
                        script+="\n";
 
                                std::vector<GPortModel*> inputs = model->getInputPorts();
-                               for(int j = 0; j<inputs.size();j++)
+                               for(int j = 0; j<(int)inputs.size();j++)
                                {
                                        GPortModel* inputPort = inputs[j];
                                        if(inputPort->isValueSet())
                                        {
-                                               script+="set ";
+                                               script+="  set ";
                                                script+=model->getBBTKName();
                                                script+=".";
                                                script+=inputPort->getBBTKName();
@@ -1142,6 +1216,7 @@ namespace bbtk
                                                script+="\n";
                                        }
                                }
+                               script+="\n";
 
                        }
 
@@ -1149,8 +1224,9 @@ namespace bbtk
 
                        std::string complexInputs="";
                        std::string complexOutputs="";
+                       script+="\n";
 
-                       for(i = 0; i<connections.size();i++)
+                       for(i = 0; i<(int)connections.size();i++)
                        {
                                int id = connections[i];
                                GObjectController *control = _controllers[id];
@@ -1211,7 +1287,9 @@ namespace bbtk
                                }
                        }
 
-                       for(i = 0; i<execBoxes.size();i++)
+                   script+="\n";
+               
+                       for(i = 0; i<(int)execBoxes.size();i++)
                        {
                                script+="exec ";
                                int id = execBoxes[i];
@@ -1482,6 +1560,7 @@ namespace bbtk
 
                                        getline(inputStream,line);//FIN_COMPLEX_PORT
 
+                                       
                                        int idOutputPort = createGComplexBoxOutputPort(outputPortName);
                                        GObjectController *cont = _controllers[idOutputPort];
                                        GBoxModel *cbmod = (GBoxModel*)cont->getModel();
@@ -1560,20 +1639,27 @@ namespace bbtk
                                std::istringstream zEt(zEnd);
                                zEt >> zEn;
 
-                               int idBox = createGBlackBox(0,0,package,type);
-                               GObjectController *cont = _controllers[idBox];
-                               GBlackBoxModel *bbmod = (GBlackBoxModel*)cont->getModel();
-                               bbmod->setBBTKName(name);
-                               bbmod->setInicPoint(xIn,yIn,zIn);
-                               bbmod->setFinalPoint(xEn,yEn,zEn);
+                               bool boxExecutable=false;
                                if(isExec=="TRUE")
                                {
-                                       bbmod->setExecutable(true);
-                               }
-                               else if(isExec=="FALSE")
-                               {
-                                       bbmod->setExecutable(false);
+                                       boxExecutable= true;
                                }
+                               
+                               int idBox                               = createGBlackBox(xIn,yIn,package,type);
+                               configGBlackBox(idBox, xIn,yIn,zIn,name, boxExecutable,xEn,yEn,zEn);
+                               
+                               GObjectController *cont = _controllers[idBox];
+                               GBlackBoxModel *bbmod   = (GBlackBoxModel*)cont->getModel();
+                               
+                               
+//ups2 eed                             
+//                             GObjectController *cont = _controllers[idBox];
+//                             GBlackBoxModel *bbmod   = (GBlackBoxModel*)cont->getModel();
+//                             bbmod->setBBTKName(name);
+//                             bbmod->setInicPoint(xIn,yIn,zIn);
+//                             bbmod->setFinalPoint(xEn,yEn,zEn);
+//                             bbmod->setExecutable(boxExecutable);
+
                                                        
                                //----------
                                getline(inputStream,line);//PORT o FIN_BOX
@@ -1594,7 +1680,7 @@ namespace bbtk
                                        port=line.substr(0,4);
                                } // while              
 
-                               bbmod->notifyObservers(_idManager);
+//EED                          bbmod->notifyObservers(_idManager);
                        } // boxes
 
                        /// CONNECTIONS
@@ -1626,11 +1712,14 @@ namespace bbtk
                                result = strtok( NULL, delims );
                                std::string nameEndPort(result);
 
-                               std::vector<int> lstB = getBlackBoxes();
-                               
-                               GPortModel *startP=NULL;
-                               GPortModel *endP=NULL;                          
-                               for(int j = 0;j<lstB.size();j++)
+                               configGConnetion(_isComplexBox, nameStartBox, nameStartPort, nameEndBox, nameEndPort);
+//ups 3 EED Borrame
+/*                             
+                               std::vector<int> lstB   = getBlackBoxes();                              
+                               GPortModel *startP              = NULL;
+                               GPortModel *endP                = NULL;
+                               int j;
+                               for(j = 0;j<lstB.size();j++)
                                {
                                        int idB = lstB[j];
                                        GBlackBoxModel *bbMod = (GBlackBoxModel*)_controllers[idB]->getModel();
@@ -1649,30 +1738,30 @@ namespace bbtk
                                        if(startP==NULL)
                                        {
                                                std::vector<int> lstInputs = getComplexInputPorts();
-                                               for(int j = 0;j<lstInputs.size();j++)
+                                               for(j = 0;j<lstInputs.size();j++)
                                                {
                                                        int idB = lstInputs[j];
                                                        GBoxModel *cbMod = (GBoxModel*)_controllers[idB]->getModel();
                                                        if(_controllers[idB]->getModel()->getBBTKName()==nameStartBox)
                                                        {                                               
                                                                startP = cbMod->getOutputPort(nameStartPort);
-                                                       }
-                                               }
-                                       }
+                                                       } // if 
+                                               } // for
+                                       } // if 
 
                                        if(endP==NULL)
                                        {
                                                std::vector<int> lstOutputs = getComplexOutputPorts();
-                                               for(int j = 0;j<lstOutputs.size();j++)
+                                               for(j = 0;j<lstOutputs.size();j++)
                                                {
                                                        int idB = lstOutputs[j];
                                                        GBoxModel *cbMod = (GBoxModel*)_controllers[idB]->getModel();
                                                        if(_controllers[idB]->getModel()->getBBTKName()==nameEndBox)
                                                        {                                               
                                                                endP = cbMod->getInputPort(nameEndPort);
-                                                       }
-                                               }
-                                       }
+                                                       } // if
+                                               } // for
+                                       } // if endP
                                } // complex box
                                                                
                                int idCon = createGConnector(startP);
@@ -1684,12 +1773,121 @@ namespace bbtk
                                tempp->endContourCreation();
                                conMod->setEndPort(endP);                                       
                                conView->updateStartEndPoints();
-
+ */
                        } // for numConns
+                       
         } // start
 
        }
 
+       //=========================================================================
+       
+       GBlackBoxModel* wxVtkSceneManager::findGBox(std::string boxname)
+       {       
+               GBlackBoxModel *boxModel        = NULL;
+               GBlackBoxModel *bbMod;
+               std::vector<int> lstB           = getBlackBoxes();                              
+               int idB;
+               int j;
+               for(j = 0;j<(int)lstB.size();j++)
+               {
+                       idB = lstB[j];
+                       bbMod = (GBlackBoxModel*)_controllers[idB]->getModel();
+                       if(_controllers[idB]->getModel()->getBBTKName()==boxname)
+                       {                                               
+                               boxModel = bbMod;
+                       }
+               } // for
+               return boxModel;
+       }
+       
+       //=========================================================================
+
+
+       void wxVtkSceneManager::configGConnetion(bool _isComplexBox, 
+                                                                                        std::string nameStartBox, std::string  nameStartPort, std::string  
+                                                                                        nameEndBox, std::string  nameEndPort)
+       {
+               GPortModel *startP              = findGBox(nameStartBox)->getOutputPort(nameStartPort);
+               GPortModel *endP                = findGBox(nameEndBox)->getInputPort(nameEndPort);
+
+/*ups5 EED Borrame
+               std::vector<int> lstB   = getBlackBoxes();                              
+               int j;
+               for(j = 0;j<(int)lstB.size();j++)
+               {
+                       int idB = lstB[j];
+                       GBlackBoxModel *bbMod = (GBlackBoxModel*)_controllers[idB]->getModel();
+                       if(_controllers[idB]->getModel()->getBBTKName()==nameStartBox)
+                       {                                               
+                               startP = bbMod->getOutputPort(nameStartPort);
+                       }
+                       else if(_controllers[idB]->getModel()->getBBTKName()==nameEndBox)
+                       {
+                               endP = bbMod->getInputPort(nameEndPort);
+                       }
+               } // for
+*/             
+               int j;
+               if(_isComplexBox)
+               {
+                       if(startP==NULL)
+                       {
+                               std::vector<int> lstInputs = getComplexInputPorts();
+                               for(j = 0;j<(int)lstInputs.size();j++)
+                               {
+                                       int idB = lstInputs[j];
+                                       GBoxModel *cbMod = (GBoxModel*)_controllers[idB]->getModel();
+                                       if(_controllers[idB]->getModel()->getBBTKName()==nameStartBox)
+                                       {                                               
+                                               startP = cbMod->getOutputPort(nameStartPort);
+                                       } // if 
+                               } // for
+                       } // if 
+                       
+                       if(endP==NULL)
+                       {
+                               std::vector<int> lstOutputs = getComplexOutputPorts();
+                               for(j = 0;j<(int)lstOutputs.size();j++)
+                               {
+                                       int idB = lstOutputs[j];
+                                       GBoxModel *cbMod = (GBoxModel*)_controllers[idB]->getModel();
+                                       if(_controllers[idB]->getModel()->getBBTKName()==nameEndBox)
+                                       {                                               
+                                               endP = cbMod->getInputPort(nameEndPort);
+                                       } // if
+                               } // for
+                       } // if endP
+               } // complex box
+               
+               int idCon = createGConnector(startP);
+               _worldState = NOTHING_HAPPENS;
+               GConnectorController *tempp = (GConnectorController*)_controllers[idCon]; 
+               
+               GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
+               vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
+               tempp->endContourCreation();
+               conMod->setEndPort(endP);                                       
+               conView->updateStartEndPoints();                
+       }
+
+       //=========================================================================
+
+       bool wxVtkSceneManager::boxExist(std::string boxname)
+       {
+               bool ok=false;
+               std::map<int, GObjectController*>::iterator it;
+               for(it = _controllers.begin(); it != _controllers.end(); ++it)
+               {
+                       GObjectController *cont = it->second;           
+                       if(cont->getModel()->getBBTKName()==boxname)
+                       {
+                               ok=true;
+                       }
+               }
+               return ok;
+       }
+
        //=========================================================================
 
        std::vector<int> wxVtkSceneManager::getBlackBoxes()
@@ -1923,11 +2121,11 @@ namespace bbtk
                        std::vector<int> newInputConnections = newBox->getConnectedInputs();
                        std::vector<int> newOutputConnections = newBox->getConnectedOutputs();
 
-                       for(int k = 0; k<oldInputConnections.size();k++)
+                       for(int k = 0; k<(int)oldInputConnections.size();k++)
                        {
                                bool exist=false;
-                               int toCreate=-1;
-                               for(int l = 0; l<newInputConnections.size() && !exist;l++)
+//EED                          int toCreate=-1;
+                               for(int l = 0; l<(int)newInputConnections.size() && !exist;l++)
                                {
                                        if(oldInputConnections[k]==newInputConnections[l])
                                        {
@@ -1966,11 +2164,11 @@ namespace bbtk
                        }
                        
 
-                       for(int k = 0; k<oldOutputConnections.size();k++)
+                       for(int k = 0; k<(int)oldOutputConnections.size();k++)
                        {
                                bool exist=false;
-                               int toCreate=-1;
-                               for(int l = 0; l<newOutputConnections.size() && !exist;l++)
+//EED                          int toCreate=-1;
+                               for(int l = 0; l<(int)newOutputConnections.size() && !exist;l++)
                                {
                                        if(oldOutputConnections[k]==newOutputConnections[l])
                                        {