]> Creatis software - bbtkGEditor.git/blobdiff - lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxVtkSceneManager.cxx
Feature #1674 . RaC
[bbtkGEditor.git] / lib / EditorGraphicBBS / bbsWxGUIEditorGraphic / wxVtkSceneManager.cxx
index b88f527cad467418da510f634b114e5d0e33699f..62ecce36189b7f9a345cafd7db5e67e2cd59bbbc 100644 (file)
@@ -507,7 +507,11 @@ GPortController* wxVtkSceneManager::createGPort(int portType,
 
 //=========================================================================
 
-int wxVtkSceneManager::createGConnector(GPortModel* startPort) {
+int wxVtkSceneManager::createGConnector(GPortModel* startPort) 
+{
+       
+               
+
        int type = GCONNECTOR;
 
        manualConnectorContourController        *manContourControl              = new manualConnectorContourController();
@@ -530,6 +534,8 @@ int wxVtkSceneManager::createGConnector(GPortModel* startPort) {
        manContourView->SetColorEditContour(0.5, 0.5, 0.5);
        manContourView->SetColorSelectContour(1, 0.8, 0);
         
+       
+
         /**
          * JGRR AND CM
          * Width increased from 2 to 3, it simplifies line handling and spline control :P
@@ -677,6 +683,7 @@ void wxVtkSceneManager::update(int idController, int command) {
                        // The last one is the controller of the connector
                        std::map<int, GObjectController*>::iterator it2;
 
+
                        for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2) {
                                GObjectController *cont = it2->second;
                                if (cont->getGObjectType() == GPORT) {
@@ -755,7 +762,8 @@ void wxVtkSceneManager::update(int idController, int command) {
 
 //=========================================================================
 
-bool wxVtkSceneManager::OnMouseMove() {
+bool wxVtkSceneManager::OnMouseMove() 
+{
        int X, Y;
        bool okStatusMessage    = false;
        bool okPortMessage              = false;
@@ -797,16 +805,18 @@ bool wxVtkSceneManager::OnMouseMove() {
                        desc->getModel()->getCenter(px, py, pz);
 
                         // JGRR & CM
-                       if ((state == HIGHLIGHTED) || (state == SELECTED_POSSIBLE_CONNECTION )) {
+                       if ((state == HIGHLIGHTED) || (state == SELECTED_POSSIBLE_CONNECTION )) 
+                       {
                         // EO JGRR & CM    
                                okStatusMessage = true;
                                updateStatusBar(desc->getStatusText());
-                               if (type == GBLACKBOX) {
+                               if (type == GBLACKBOX) 
+                               {
                                        GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
-                                       _parent->displayBlackBoxInfo(mod->getBBTKPackage(),
-                                                       mod->getBBTKType());
+                                       _parent->displayBlackBoxInfo(mod->getBBTKPackage(),mod->getBBTKType());
                                } // if GBLACKBOX
-                               if (type == GPORT) {
+                               if (type == GPORT) 
+                               {
                                        // PortText
                                        okPortMessage = true;
                                        py = py + 5;
@@ -816,7 +826,7 @@ bool wxVtkSceneManager::OnMouseMove() {
 
                                        // FillPortText
                                        px = px - 33;
-                                       py = py;
+                                       //py = py;
                                        _fillObjectActor->SetScale(1);
                                        _fillObjectActor->GetProperty()->SetOpacity(0.50);
                                        _fillObjectActor->SetPosition(px, py, 1);
@@ -826,11 +836,13 @@ bool wxVtkSceneManager::OnMouseMove() {
                        } // for controllers it
                }
        }
-       if (okStatusMessage == false) {
+       if (okStatusMessage == false) 
+       {
                updateStatusBar("");
        }
 
-       if (okPortMessage == false) {
+       if (okPortMessage == false) 
+       {
                _textActor->SetScale(0.0001);
                _fillObjectActor->SetScale(0.0001);
        }
@@ -839,32 +851,35 @@ bool wxVtkSceneManager::OnMouseMove() {
 
 //=========================================================================
 
-bool wxVtkSceneManager::OnLeftButtonDown() {
-
-       if (_worldState == INIT_CREATION_CONTOUR) {
+bool wxVtkSceneManager::OnLeftButtonDown() 
+{
+       if (_worldState == INIT_CREATION_CONTOUR) 
+       {
                bool isOverPort = false;
                std::map<int, GObjectController*>::iterator it;
-               for (it = _controllers.begin(); it != _controllers.end() && isOverPort
-                               == false; ++it) {
+               for (it = _controllers.begin(); it != _controllers.end() && isOverPort== false; ++it) 
+               {
                        GObjectController *desc = it->second;
-                       if (desc->getGObjectType() == GPORT) {
+                       if (desc->getGObjectType() == GPORT) 
+                       {
                                GPortModel *portmod = (GPortModel*) desc->getModel();
                                vtkGObjectView *portView = desc->getView();
-                               if (portmod->getPortType() == GINPUTPORT
-                                               && portView->getState() == HIGHLIGHTED) {
+                               if (portmod->getPortType() == GINPUTPORT && portView->getState() == HIGHLIGHTED) 
+                               {
                                        isOverPort = true;
-                                 } // if
-                                // JGRR & CM                    
-                                if ( portmod->getPortType( ) == GINPUTPORT &&  portView->getState( ) == SELECTED_POSSIBLE_CONNECTION   ) {
-                                    isOverPort = true ;
-                                    portView->setState( HIGHLIGHTED);
-                                }                    
-                                // EO JGRR & CM 
-
-                        } // if
+                               } // if
+                               // JGRR & CM                    
+                               if ( portmod->getPortType( ) == GINPUTPORT &&  portView->getState( ) == SELECTED_POSSIBLE_CONNECTION   ) {
+                                       isOverPort = true ;
+                                       portView->setState( HIGHLIGHTED);
+                               }                    
+                               // EO JGRR & CM 
+
+                       } // if
                } // for
 
-               if (isOverPort == false) {
+               if (isOverPort == false) 
+               {
                        CancelConnection();
                        UnSelectBlackBoxes();
                } // isOverPort
@@ -881,19 +896,20 @@ bool wxVtkSceneManager::OnLeftButtonDown() {
 
                GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
 
-               if (GetGBlackBoxControlerPointedByMouse() != NULL) {
+               if (cont != NULL) {
                        int state = cont->getView()->getState();
                        if ((ctrlkey == 0) && (state == HIGHLIGHTED)) {
                                UnSelectBlackBoxes();
                        }
+               } else {
+                       UnSelectBlackBoxes();  // EED 12/07/2012
                }
                for (int i = 0; i < (int) _selectedObjects.size(); i++) {
                        int id = _selectedObjects[i];
-                       GObjectControllercont = _controllers[id];
+                       GObjectController *cont = _controllers[id];
                        cont->getView()->setState(DRAG);
                        cont->getModel()->notifyObservers(_idManager);
                } // for
-               
        } // if _selectedObjects.size
 
 
@@ -902,7 +918,8 @@ bool wxVtkSceneManager::OnLeftButtonDown() {
 
 //=========================================================================
 
-bool wxVtkSceneManager::OnLeftButtonUp() {
+bool wxVtkSceneManager::OnLeftButtonUp() 
+{
        if (_worldState == DRAG_OBJECTS) {
                _worldState = NOTHING_HAPPENS;
 
@@ -917,8 +934,10 @@ bool wxVtkSceneManager::OnLeftButtonUp() {
 }
 
 //=========================================================================
-void wxVtkSceneManager::CancelConnection() {
-       if (_worldState == INIT_CREATION_CONTOUR) {
+void wxVtkSceneManager::CancelConnection() 
+{
+       if (_worldState == INIT_CREATION_CONTOUR) 
+       {
                _worldState = NOTHING_HAPPENS;
                //int lastId = _controllers.size()-1;
 
@@ -929,7 +948,8 @@ void wxVtkSceneManager::CancelConnection() {
                _controllers.erase(_idConnectionInCreation);
 
                std::map<int, GObjectController*>::iterator it;
-               for (it = _controllers.begin(); it != _controllers.end(); ++it) {
+               for (it = _controllers.begin(); it != _controllers.end(); ++it) 
+               {
                        GObjectController *desc = it->second;
                        desc->SetActive(true);
                        desc->getView()->setState(NOTHING_HAPPENS);
@@ -940,8 +960,10 @@ void wxVtkSceneManager::CancelConnection() {
 
 //=========================================================================
 
-bool wxVtkSceneManager::OnRightButtonUp() {
-       if (_worldState == INIT_CREATION_CONTOUR) {
+bool wxVtkSceneManager::OnRightButtonUp() 
+{
+       if (_worldState == INIT_CREATION_CONTOUR) 
+       {
                CancelConnection();
        }
        UnSelectBlackBoxes();
@@ -1066,8 +1088,21 @@ bool wxVtkSceneManager::OnChar()
         
        // KeyCode 127 : Delete Key
        // KeyCode 8 : Backspace Key
+
+
+       if (keyCode == 8 || keyCode == 127 || keyCode == 27) 
+       {
+               if (_worldState == INIT_CREATION_CONTOUR) 
+               {
+                       CancelConnection();
+                       UnSelectBlackBoxes();
+               }
+       }
+
+
        if (keyCode == 8 || keyCode == 127) 
        {
+
                        for (int i = 0; i < (int) _selectedObjects.size(); i++) 
                        {
                                int id = _selectedObjects[i];
@@ -1092,7 +1127,8 @@ bool wxVtkSceneManager::OnChar()
 #endif
                if(_selectedObjects.size()){
                        std::cout<<"objects to copy :";
-                       for(int i=0;i<_selectedObjects.size();i++){
+                       for(int i=0;i<_selectedObjects.size();i++)
+                       {
                                std::cout<<_selectedObjects.at(i)<<" ";
                        }
                        DuplicateObjects(getSelectedObjects());   
@@ -1380,32 +1416,66 @@ std::string wxVtkSceneManager::getDiagramBBS(bool wln) {
                script += LineNumber(wln, lnNmbr);
                script += "\n";
 
+
+               std::string complexInputs="";
+
                for (i = 0; i < (int) connections.size(); i++) {
-                       script += LineNumber(wln, lnNmbr);
-                       script += "connect ";
+                       //script += LineNumber(wln, lnNmbr);
+                       //script += "connect ";
                        int id = connections[i];
                        GObjectController *control = _controllers[id];
                        GConnectorModel *model = (GConnectorModel*) control->getModel();
 
-                       //Start Connection info
-                       GPortModel *start = model->getStartPort();
-                       script += start->getParentBox()->getBBTKName();
-                       script += ".";
-                       script += start->getBBTKName();
 
-                       script += " ";
+                       //Connection info
+                       GPortModel *start = model->getStartPort();
+                       GBoxModel *startBox = start->getParentBox();
 
-                       //End Connection info
                        GPortModel *end = model->getEndPort();
-                       script += end->getParentBox()->getBBTKName();
-                       script += ".";
-                       script += end->getBBTKName();
+                       GBoxModel *endBox = end->getParentBox();
+
+                       if (startBox->getGObjectType() == GCOMPLEXINPUTPORT)
+                       {
+                                       complexInputs += "input ";
+                                       complexInputs += startBox->getBBTKName();
+
+                                       complexInputs += " ";
+                                       complexInputs += endBox->getBBTKName();
+                                       complexInputs += ".";
+                                       complexInputs += end->getBBTKName();
+
+                                       complexInputs += " ";
+                                       complexInputs += "\" \"";
+
+                                       complexInputs += "\n";
+                       }
+                       else
+                       {
+                                       script += "connect ";
+                                       script += startBox->getBBTKName();
+                                       script += ".";
+                                       script += start->getBBTKName();
+
+                                       script += " ";
+
+                                       //End Connection info
+                                       script += endBox->getBBTKName();
+                                       script += ".";
+                                       script += end->getBBTKName();
+
+                                       script += "\n";
+                       }
 
                        script += "\n";
                }
 
                script += LineNumber(wln, lnNmbr);
                script += "\n";
+
+               script += "\n";
+               script += "# Complex input ports\n";
+               script += complexInputs;
+
                for (i = 0; i < (int) execBoxes.size(); i++) {
                        script += LineNumber(wln, lnNmbr);
                        script += "exec ";
@@ -1581,6 +1651,14 @@ std::string wxVtkSceneManager::saveComplexBoxBBS() {
                }
        }
 
+       script += "\n";
+       script += "# Complex input ports\n";
+       script += complexInputs;
+
+       script += "\n";
+       script += "# Complex output ports\n";
+       script += complexOutputs;
+
        script += "\n";
 
        for (i = 0; i < (int) execBoxes.size(); i++) {
@@ -1593,14 +1671,6 @@ std::string wxVtkSceneManager::saveComplexBoxBBS() {
                script += "\n";
        }
 
-       script += "\n";
-       script += "# Complex input ports\n";
-       script += complexInputs;
-
-       script += "\n";
-       script += "# Complex output ports\n";
-       script += complexOutputs;
-
        script += "\n";
        script += "endefine";
        script += "\n";
@@ -1673,6 +1743,8 @@ void wxVtkSceneManager::saveDiagram(std::string &content) {
                content += GetCbPackageName();
                content += "\n";
 
+               /* CHANGE TO THE VERSION 1.4 RaC2012 2nd HackFest
+                * External inputs are possible for applications and complex boxes
                //Print info complex input ports
                std::vector<int> inputs = getComplexInputPorts();
                int insize = inputs.size();
@@ -1686,6 +1758,7 @@ void wxVtkSceneManager::saveDiagram(std::string &content) {
                        GObjectController *cont = _controllers[id];
                        cont->getModel()->save(content);
                }
+               */
 
                //Print info complex output ports
                std::vector<int> outputs = getComplexOutputPorts();
@@ -1705,6 +1778,21 @@ void wxVtkSceneManager::saveDiagram(std::string &content) {
                content += "FALSE\n";
        }
 
+       // CHANGE TO THE VERSION 1.4 RaC2012 2nd HackFest
+       // External inputs are possible for applications and complex boxes
+       std::vector<int> inputs = getComplexInputPorts();
+       int insize = inputs.size();
+       content += "COMPLEXINPUTS:";
+       sprintf(buffer, "%d", insize);
+       content += buffer;
+       content += "\n";
+
+       for (int i = 0; i < insize; i++) {
+               int id = inputs[i];
+               GObjectController *cont = _controllers[id];
+               cont->getModel()->save(content);
+       }
+
        //Print boxes
        std::vector<int> boxes = getBlackBoxes();
        int bsize = boxes.size();
@@ -1736,20 +1824,36 @@ void wxVtkSceneManager::saveDiagram(std::string &content) {
 }
 
 //=========================================================================
-
-void wxVtkSceneManager::loadDiagram(stringstream &inputStream) {
-
+void wxVtkSceneManager::getCleanLine(stringstream &inputStream, std::string &line)
+{
+       getline(inputStream, line,'\n');
+       int size = line.length();
+    if (size>0)
+       {
+               if ( line[ size-1 ]==13  )
+               {
+                       line.erase(size-1,1);
+               } // if line
+       } // if size
+}
+       
+//=========================================================================
+void wxVtkSceneManager::loadDiagram(stringstream &inputStream) 
+{
+       int size;
        std::string version = "<void>";
        std::string line = "";
        char delims[] = ":";
        char *result = NULL;
 
-       getline(inputStream, line);
+       getCleanLine(inputStream, line);
 
        bool start = false;
        while (!inputStream.eof()) {
                if (line == "" || line[0] == '#') {
-                       getline(inputStream, line);
+                       line="";
+                       getCleanLine(inputStream, line);
+                       
                        if (line == "# - BBTKGEditor v 1.0 BBG BlackBox Diagram file") {
                                version = line.substr(18, 3);
                        }
@@ -1762,32 +1866,34 @@ void wxVtkSceneManager::loadDiagram(stringstream &inputStream) {
                        if (line == "# - BBTKGEditor v 1.3 BBG BlackBox Diagram file") {
                                version = line.substr(18, 3);
                        }
+                       if (line == "# - BBTKGEditor v 1.4 BBG BlackBox Diagram file") {
+                               version = line.substr(18, 3);
+                       }
                } else if (line == "APP_START") {
                        start = true;
                        break;
                }
        }
 
-       printf("EED wxVtkSceneManager::loadDiagram  version=%s\n", version.c_str());
 
        if (start) {
 
                if ((version != "1.0") && (version != "1.1")) {
-                       getline(inputStream, line);//CATEGORY:<category of the box>
+                       getCleanLine(inputStream, line);//CATEGORY:<category of the box>
                        char categoryTmp[30];
                        strcpy(categoryTmp, line.c_str());
                        result = strtok(categoryTmp, delims);
                        result = strtok(NULL, delims);
                        SetCategory(result);
 
-                       getline(inputStream, line);//DESCRIPTION:<description of the box>
+                       getCleanLine(inputStream, line);//DESCRIPTION:<description of the box>
                        char descriptionTmp[1024];
                        strcpy(descriptionTmp, line.c_str());
                        result = strtok(descriptionTmp, delims);
                        result = strtok(NULL, delims);
                        SetDescription(result);
 
-                       getline(inputStream, line);//AUTHOR:<author>
+                       getCleanLine(inputStream, line);//AUTHOR:<author>
                        char authorTmp[255];
                        strcpy(authorTmp, line.c_str());
                        result = strtok(authorTmp, delims);
@@ -1796,7 +1902,7 @@ void wxVtkSceneManager::loadDiagram(stringstream &inputStream) {
                }
 
                //----------
-               getline(inputStream, line);//COMPLEX_BOX:TRUE|FALSE
+               getCleanLine(inputStream, line);//COMPLEX_BOX:TRUE|FALSE
                char complexTmp[30];
                strcpy(complexTmp, line.c_str());
                result = strtok(complexTmp, delims);
@@ -1807,14 +1913,14 @@ void wxVtkSceneManager::loadDiagram(stringstream &inputStream) {
                        _isComplexBox = true;
 
                        if ((version != "1.0") && (version != "1.1")) {
-                               getline(inputStream, line);//COMPLEXNAME:<name of the complex box>
+                               getCleanLine(inputStream, line);//COMPLEXNAME:<name of the complex box>
                                char complexboxnameTmp[255];
                                strcpy(complexboxnameTmp, line.c_str());
                                result = strtok(complexboxnameTmp, delims);
                                result = strtok(NULL, delims);
                                SetCbName(result);
 
-                               getline(inputStream, line);//PACKAGENAME:<name of the package of the box>
+                               getCleanLine(inputStream, line);//PACKAGENAME:<name of the package of the box>
                                char packagenameTmp[255];
                                strcpy(packagenameTmp, line.c_str());
                                result = strtok(packagenameTmp, delims);
@@ -1822,27 +1928,81 @@ void wxVtkSceneManager::loadDiagram(stringstream &inputStream) {
                                SetCbPackageName(result);
                        }
 
+                       if(version < "1.4")
+                       {
+                               //-----------------------
+                               //- COMPLEX INPUT PORTS
+                               //-----------------------
+                               getCleanLine(inputStream, line);//COMPLEXINPUTS:num
+                               char inputs[30];
+                               strcpy(inputs, line.c_str());
+                               result = strtok(inputs, delims);
+                               result = strtok(NULL, delims);
+
+                               int numInputs;
+                               std::istringstream inps(result);
+                               inps >> numInputs;
+
+                               for (int i = 0; i < numInputs; i++) {
+                                       //----------
+                                       getCleanLine(inputStream, line);//COMPLEX_PORT
+                                       getCleanLine(inputStream, line);//name
+                                       std::string inputPortName(line);
+
+                                       //----------
+                                       getCleanLine(inputStream, line);//xInic:yInic:zInic
+                                       char coord[80];
+                                       strcpy(coord, line.c_str());
+                                       result = strtok(coord, delims);//xInic
+                                       std::string xInic(result);
+                                       result = strtok(NULL, delims);//yInic
+                                       std::string yInic(result);
+                                       result = strtok(NULL, delims);//zInic
+                                       std::string zInic(result);
+
+                                       double xIn, yIn, zIn;
+                                       std::istringstream xSt(xInic);
+                                       xSt >> xIn;
+                                       std::istringstream ySt(yInic);
+                                       ySt >> yIn;
+                                       std::istringstream zSt(zInic);
+                                       zSt >> zIn;
+
+                                       if (version<="1.2")
+                                       {
+                                               if (zIn==900) zIn=GPOSITION_Z;
+                                       }
+
+                                       getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
+
+                                       configGComBoxInputOutputPort(true, inputPortName, xIn, yIn, zIn);
+
+                               } // for input complex box
+                       }
+
+
                        //-----------------------
-                       //- COMPLEX INPUT PORTS
+                       //- COMPLEX OUTPUT PORTS
                        //-----------------------
-                       getline(inputStream, line);//COMPLEXINPUTS:num
-                       char inputs[30];
-                       strcpy(inputs, line.c_str());
-                       result = strtok(inputs, delims);
+
+                       getCleanLine(inputStream, line);//COMPLEXOUTPUTS:num
+                       char outputs[30];
+                       strcpy(outputs, line.c_str());
+                       result = strtok(outputs, delims);
                        result = strtok(NULL, delims);
 
-                       int numInputs;
-                       std::istringstream inps(result);
-                       inps >> numInputs;
+                       int numOutputs;
+                       std::istringstream outps(result);
+                       outps >> numOutputs;
 
-                       for (int i = 0; i < numInputs; i++) {
+                       for (int i = 0; i < numOutputs; i++) {
                                //----------
-                               getline(inputStream, line);//COMPLEX_PORT
-                               getline(inputStream, line);//name
-                               std::string inputPortName(line);
+                               getCleanLine(inputStream, line);//COMPLEX_PORT
+                               getCleanLine(inputStream, line);//name
+                               std::string outputPortName(line);
 
                                //----------
-                               getline(inputStream, line);//xInic:yInic:zInic
+                               getCleanLine(inputStream, line);//xInic:yInic:zInic
                                char coord[80];
                                strcpy(coord, line.c_str());
                                result = strtok(coord, delims);//xInic
@@ -1865,35 +2025,38 @@ void wxVtkSceneManager::loadDiagram(stringstream &inputStream) {
                                        if (zIn==900) zIn=GPOSITION_Z;
                                }
                                
-                               getline(inputStream, line);//FIN_COMPLEX_PORT
+                               getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
 
-                               configGComBoxInputOutputPort(true, inputPortName, xIn, yIn, zIn);
+                               configGComBoxInputOutputPort(false, outputPortName, xIn, yIn, zIn);
 
-                       } // for input complex box
+                       } // for output complex box
 
+               } // complex box
 
+               // RaC2012 2nd Hackfest
+               if(version >= "1.4")
+               {
                        //-----------------------
-                       //- COMPLEX OUTPUT PORTS
+                       //- EXTERNAL INPUT PORTS
                        //-----------------------
-
-                       getline(inputStream, line);//COMPLEXOUTPUTS:num
-                       char outputs[30];
-                       strcpy(outputs, line.c_str());
-                       result = strtok(outputs, delims);
+                       getCleanLine(inputStream, line);//COMPLEXINPUTS:num
+                       char inputs[30];
+                       strcpy(inputs, line.c_str());
+                       result = strtok(inputs, delims);
                        result = strtok(NULL, delims);
 
-                       int numOutputs;
-                       std::istringstream outps(result);
-                       outps >> numOutputs;
+                       int numInputs;
+                       std::istringstream inps(result);
+                       inps >> numInputs;
 
-                       for (int i = 0; i < numOutputs; i++) {
+                       for (int i = 0; i < numInputs; i++) {
                                //----------
-                               getline(inputStream, line);//COMPLEX_PORT
-                               getline(inputStream, line);//name
-                               std::string outputPortName(line);
+                               getCleanLine(inputStream, line);//COMPLEX_PORT
+                               getCleanLine(inputStream, line);//name
+                               std::string inputPortName(line);
 
                                //----------
-                               getline(inputStream, line);//xInic:yInic:zInic
+                               getCleanLine(inputStream, line);//xInic:yInic:zInic
                                char coord[80];
                                strcpy(coord, line.c_str());
                                result = strtok(coord, delims);//xInic
@@ -1916,16 +2079,15 @@ void wxVtkSceneManager::loadDiagram(stringstream &inputStream) {
                                        if (zIn==900) zIn=GPOSITION_Z;
                                }
                                
-                               getline(inputStream, line);//FIN_COMPLEX_PORT
-
-                               configGComBoxInputOutputPort(false, outputPortName, xIn, yIn, zIn);
+                               getCleanLine(inputStream, line);//FIN_COMPLEX_PORT
+                               configGComBoxInputOutputPort(true, inputPortName, xIn, yIn, zIn);
 
-                       } // for output complex box
+                       } // for external input
+               }
 
-               } // complex box
 
                //----------
-               getline(inputStream, line);//BOXES:num
+               getCleanLine(inputStream, line);//BOXES:num
                char boxes[9];
                strcpy(boxes, line.c_str());
                result = strtok(boxes, delims);
@@ -1937,8 +2099,8 @@ void wxVtkSceneManager::loadDiagram(stringstream &inputStream) {
 
                for (int i = 0; i < numBoxes; i++) {
                        //----------
-                       getline(inputStream, line);//BOX
-                       getline(inputStream, line);//package:type:name
+                       getCleanLine(inputStream, line);//BOX
+                       getCleanLine(inputStream, line);//package:type:name
                        char box[150];
                        strcpy(box, line.c_str());
                        result = strtok(box, delims);//package
@@ -1948,7 +2110,7 @@ void wxVtkSceneManager::loadDiagram(stringstream &inputStream) {
                        result = strtok(NULL, delims);//name
                        std::string name(result);
 
-                       getline(inputStream, line);//ISEXEC:TRUE|FALSE
+                       getCleanLine(inputStream, line);//ISEXEC:TRUE|FALSE
                        char exec[15];
                        strcpy(exec, line.c_str());
                        result = strtok(exec, delims);//ISEXEC
@@ -1956,7 +2118,7 @@ void wxVtkSceneManager::loadDiagram(stringstream &inputStream) {
                        std::string isExec(result);
 
                        //----------
-                       getline(inputStream, line);//xInic:yInic:zInic
+                       getCleanLine(inputStream, line);//xInic:yInic:zInic
                        char coord[80];
                        strcpy(coord, line.c_str());
                        result = strtok(coord, delims);//xInic
@@ -1982,7 +2144,7 @@ void wxVtkSceneManager::loadDiagram(stringstream &inputStream) {
                        
                        
                        //----------
-                       getline(inputStream, line);//xEnd:yEnd:zEnd
+                       getCleanLine(inputStream, line);//xEnd:yEnd:zEnd
                        strcpy(coord, line.c_str());
                        result = strtok(coord, delims);//xEnd
                        std::string xEnd(result);
@@ -2017,10 +2179,10 @@ void wxVtkSceneManager::loadDiagram(stringstream &inputStream) {
                        GBlackBoxModel *bbmod = (GBlackBoxModel*) cont->getModel();
 
                        //----------
-                       getline(inputStream, line);//PORT o FIN_BOX
+                       getCleanLine(inputStream, line);//PORT o FIN_BOX
                        std::string port = line.substr(0, 4);
                        while (port == "PORT") {
-                               getline(inputStream, line);//name:value
+                               getCleanLine(inputStream, line);//name:value
                                char poort[150];
                                strcpy(poort, line.c_str());
                                result = strtok(poort, delims);//name
@@ -2030,7 +2192,7 @@ void wxVtkSceneManager::loadDiagram(stringstream &inputStream) {
 
                                bbmod->setValueToInput(name, value);
 
-                               getline(inputStream, line);//PORT o FIN_BOX
+                               getCleanLine(inputStream, line);//PORT o FIN_BOX
                                port = line.substr(0, 4);
                        } // while
 
@@ -2039,7 +2201,7 @@ void wxVtkSceneManager::loadDiagram(stringstream &inputStream) {
 
                /// CONNECTIONS
                //----------
-               getline(inputStream, line);//CONNECTIONS:num
+               getCleanLine(inputStream, line);//CONNECTIONS:num
                char conns[30];
                strcpy(conns, line.c_str());
                result = strtok(conns, delims);
@@ -2048,11 +2210,12 @@ void wxVtkSceneManager::loadDiagram(stringstream &inputStream) {
                int numConns;
                std::istringstream isCons(result);
                isCons >> numConns;
-
+               
+               
                for (int i = 0; i < numConns; i++) {
                        //----------
-                       getline(inputStream, line);//CONNECTION
-                       getline(inputStream, line);//Startbox.PortName:EndBox.PortName
+                       getCleanLine(inputStream, line);//CONNECTION
+                       getCleanLine(inputStream, line);//Startbox.PortName:EndBox.PortName
 
                        char connec[200];
                        strcpy(connec, line.c_str());
@@ -2072,7 +2235,7 @@ void wxVtkSceneManager::loadDiagram(stringstream &inputStream) {
                                GConnectorController *tempp             = (GConnectorController*) _controllers[idCon];
                                GConnectorModel *conMod                 = (GConnectorModel*) tempp->getModel();
                                vtkGConnectorView *conView              = (vtkGConnectorView*) tempp->getView();
-                               getline(inputStream, line); //NumberOfControlPoints:##
+                               getCleanLine(inputStream, line); //NumberOfControlPoints:##
                                strcpy(conns, line.c_str());
                                result = strtok(conns, delims);
                                result = strtok(NULL, delims);
@@ -2082,7 +2245,7 @@ void wxVtkSceneManager::loadDiagram(stringstream &inputStream) {
                                isCons >> numberOfControlPoints;
 
                                for (int ii = 0; ii < numberOfControlPoints; ii++) {
-                                       getline(inputStream, line); //XX:YY:ZZ
+                                       getCleanLine(inputStream, line); //XX:YY:ZZ
                                        char connec[200];
                                        strcpy(connec, line.c_str());
 
@@ -2147,7 +2310,9 @@ GBoxModel* wxVtkSceneManager::findGBox(std::string boxname) {
                }
        } // for
 
-       if ((_isComplexBox) && (boxModel == NULL)) {
+
+
+       if (boxModel == NULL) {
                std::vector<int> lstInputs = getComplexInputPorts();
                for (j = 0; j < (int) lstInputs.size(); j++) {
                        idB = lstInputs[j];
@@ -2157,6 +2322,8 @@ GBoxModel* wxVtkSceneManager::findGBox(std::string boxname) {
                        }
                } // for
 
+               if(_isComplexBox)
+               {
                std::vector<int> lstOutputs = getComplexOutputPorts();
                for (j = 0; j < (int) lstOutputs.size(); j++) {
                        int idB = lstOutputs[j];
@@ -2165,8 +2332,9 @@ GBoxModel* wxVtkSceneManager::findGBox(std::string boxname) {
                                boxModel = bMod;
                        }
                } // for
+               }
 
-       } // complex box
+       } // inputs/outputs
 
        return boxModel;
 }
@@ -2183,6 +2351,10 @@ int wxVtkSceneManager::configGConnetion(std::string nameStartBox,
        GPortModel *endP = NULL;
 
        boxModel = findGBox(nameStartBox);
+       if(boxModel == NULL)
+       {
+               printf("RaC: ERROR in wxVtkSceneManager::configGConnetion A box to connect start port %s is null. Box name is probably wrong.\n", nameStartPort.c_str());
+       }
        if (boxModel != NULL) {
                startP = boxModel->getOutputPort(nameStartPort);
                if(startP == NULL){
@@ -2191,6 +2363,10 @@ int wxVtkSceneManager::configGConnetion(std::string nameStartBox,
        }
 
        boxModel = findGBox(nameEndBox);
+       if(boxModel == NULL)
+       {
+                printf("RaC: ERROR in wxVtkSceneManager::configGConnetion A box to connect start port %s is null. Box name is probably wrong.\n", nameStartPort.c_str());
+       }
        if (boxModel != NULL) {
                endP = boxModel->getInputPort(nameEndPort);
                if(endP == NULL){
@@ -2200,6 +2376,7 @@ int wxVtkSceneManager::configGConnetion(std::string nameStartBox,
 
        //ups2
        int idCon = createGConnector(startP);
+
        _worldState = NOTHING_HAPPENS;
        GConnectorController *tempp = (GConnectorController*) _controllers[idCon];
 
@@ -2687,6 +2864,25 @@ std::string wxVtkSceneManager::GetDescription() {
 
 //=========================================================================
 
+std::vector< std::string> wxVtkSceneManager::GetExternalInputsNames()
+{
+
+       std::vector< std::string> extInputs;
+       std::map<int, GObjectController*>::iterator it;
+       for (it = _controllers.begin(); it != _controllers.end(); ++it)
+       {
+               GObjectController *cont = it->second;
+               if (cont->getGObjectType() == GCOMPLEXINPUTPORT)
+               {
+                       extInputs.push_back(cont->getModel()->getBBTKName());
+               }
+       }
+       return extInputs;
+}
+
+//=========================================================================
+
+
 
 void wxVtkSceneManager::printAll(int com , int sta ){