]> Creatis software - bbtkGEditor.git/blobdiff - lib/EditorGraphicBBS/bbsKernelEditorGraphic/wxVtkSceneManager.cxx
The app saves and opens diagrams !!!! Allll fiiiinnn se logro !!
[bbtkGEditor.git] / lib / EditorGraphicBBS / bbsKernelEditorGraphic / wxVtkSceneManager.cxx
index 2227c9003b5245407b07340d5be07c8808aaadb7..4fcb0434e0c6ca4fa0125b12fafc068850fe9235 100644 (file)
@@ -97,7 +97,7 @@ namespace bbtk
 
        //=========================================================================
 
-       void wxVtkSceneManager::createGBlackBox(int x, int y, std::string packageName, std::string boxType)
+       int wxVtkSceneManager::createGBlackBox(int x, int y, std::string packageName, std::string boxType)
        {
 
                int windowWidth=_baseView->GetRenWin()->GetSize()[0];
@@ -189,23 +189,26 @@ namespace bbtk
                int newId = _controllers.size();
                controller->setId(newId);
                _controllers[newId] = controller;
+               return newId;
 
        }
 
        //=========================================================================
 
-       void wxVtkSceneManager::createGInputPort(int portType, int posinBox,GBlackBoxModel *blackBox, BlackBoxInputDescriptor *desc)
+       int wxVtkSceneManager::createGInputPort(int portType, int posinBox,GBlackBoxModel *blackBox, BlackBoxInputDescriptor *desc)
        {
                GPortController* portController = createGPort(portType,desc->GetName(),desc->GetTypeName(),posinBox,blackBox);
                blackBox->addInputPort((GPortModel*)portController->getModel());
+               return portController->getId();
        }
 
        //=========================================================================
 
-       void wxVtkSceneManager::createGOutputPort(int portType, int posinBox,GBlackBoxModel *blackBox, BlackBoxOutputDescriptor *desc)
+       int wxVtkSceneManager::createGOutputPort(int portType, int posinBox,GBlackBoxModel *blackBox, BlackBoxOutputDescriptor *desc)
        {
                GPortController* portController = createGPort(portType,desc->GetName(),desc->GetTypeName(),posinBox,blackBox);
                blackBox->addOutputPort((GPortModel*)portController->getModel());
+               return portController->getId();
        }
 
        //=========================================================================
@@ -250,7 +253,7 @@ namespace bbtk
 
        //=========================================================================
 
-       void wxVtkSceneManager::createGConnector(GPortModel* startPort)
+       int wxVtkSceneManager::createGConnector(GPortModel* startPort)
        {
                int type = GCONNECTOR;
 
@@ -318,6 +321,7 @@ namespace bbtk
                connectorcontroller->setId(newId);
                _controllers[newId] = connectorcontroller;
 
+               return newId;
        }
 
        //=========================================================================
@@ -373,7 +377,6 @@ namespace bbtk
                                {
                                        int id = idController;
                                        _selectedObjects.push_back(id);
-                                       cout<<"RaC wxVtkSceneManager::update _selectedObjects.push_back id:"<<id<<endl;
                                }
 
                        }
@@ -973,7 +976,7 @@ namespace bbtk
                char buffer [50];
                std::vector<int> boxes = getBoxes();
                int bsize = boxes.size();
-               content+="BOXES ";
+               content+="BOXES:";
                sprintf (buffer, "%d", bsize);
                content+=buffer;
                content+="\n";
@@ -985,12 +988,10 @@ namespace bbtk
                        cont->getModel()->save(content);
                }
 
-               content+="\n";
-
                //Print connections
                std::vector<int> connections = getConnections();
                int csize = connections.size();
-               content+="CONNECTIONS ";
+               content+="CONNECTIONS:";
                sprintf (buffer, "%d", csize);
                content+=buffer;
                content+="\n";
@@ -1006,6 +1007,185 @@ namespace bbtk
 
        //=========================================================================
 
+       void wxVtkSceneManager::loadDiagram(ifstream &inputStream)
+       {
+
+               std::string line="";    
+               char delims[] = ":";
+               char *result = NULL;
+        getline(inputStream,line);
+
+               bool start = false;
+               while ( !inputStream.eof() ) 
+               {
+                       if(line=="" || line[0]=='#')
+                       {
+                               getline(inputStream,line);
+                       }
+                       else if(line=="APP_START")
+                       {
+                               start = true;
+                               break;
+                       }
+               }
+
+               if(start)
+               {
+                       //----------
+                       getline(inputStream,line);//BOXES:num
+                       char boxes[9];
+                       strcpy( boxes, line.c_str() );
+                       result = strtok( boxes, delims );
+                       result = strtok( NULL, delims );
+                                       
+                       int numBoxes;
+                       std::istringstream is(result);
+                       is >> numBoxes;
+                       
+                       for(int i = 0;i<numBoxes;i++)
+                       {
+                               //----------
+                               getline(inputStream,line);//BOX
+                               getline(inputStream,line);//package:type:name
+                               char box[100];
+                               strcpy( box, line.c_str() );
+                               result = strtok( box, delims );//package
+                               std::string package(result);
+                               result = strtok( NULL, delims );//type
+                               std::string type(result);
+                               result = strtok( NULL, delims );//name
+                               std::string name(result);
+
+                               //----------
+                               getline(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;
+                                               
+                               //----------
+                               getline(inputStream,line);//xEnd:yEnd:zEnd
+                               strcpy( coord, line.c_str() );
+                               result = strtok( coord, delims );//xEnd
+                               std::string xEnd(result);
+                               result = strtok( NULL, delims );//yEnd
+                               std::string yEnd(result);
+                               result = strtok( NULL, delims );//zEnd
+                               std::string zEnd(result);
+
+                               double xEn, yEn, zEn;
+                               std::istringstream xEt(xEnd);
+                               xEt >> xEn;
+                               std::istringstream yEt(yEnd);
+                               yEt >> yEn;
+                               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);
+                                                       
+                               //----------
+                               getline(inputStream,line);//PORT o #FIN_BOX
+                               std::string port=line.substr(0,4);
+                               while(port=="PORT")
+                               {
+                                       getline(inputStream,line);//name:value
+                                       char poort[20];
+                                       strcpy( poort, line.c_str() );
+                                       result = strtok( poort, delims );//name
+                                       std::string name(result);
+                                       result = strtok( NULL, delims );//value
+                                       std::string value(result);
+
+                                       bbmod->setValueToInput(name,value);                                     
+
+                                       getline(inputStream,line);//PORT o FIN_BOX
+                                       port=line.substr(0,4);
+                               }               
+
+                               bbmod->notifyObservers(_idManager);
+                       }
+
+                       /// CONNECTIONS
+                       //----------
+                       getline(inputStream,line);//CONNECTIONS:num
+                       char conns[15];
+                       strcpy( conns, line.c_str() );
+                       result = strtok( conns, delims );
+                       result = strtok( NULL, delims );
+                                       
+                       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
+
+                               char connec[100];
+                               strcpy( connec, line.c_str() );
+                               result = strtok( connec, delims );
+                               std::string nameStartBox(result);
+                               result = strtok( NULL, delims );
+                               std::string nameStartPort(result);
+                               result = strtok( NULL, delims );
+                               std::string nameEndBox(result);
+                               result = strtok( NULL, delims );
+                               std::string nameEndPort(result);
+
+                               std::vector<int> lstB = getBoxes();
+                               
+                               GPortModel *startP=NULL;
+                               GPortModel *endP=NULL;                          
+                               for(int j = 0;j<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);
+                                       }
+                               }
+                               
+                               int idCon = createGConnector(startP);
+                               _worldState = NOTHING_HAPPENS;
+                               GConnectorController *tempp = (GConnectorController*)_controllers[idCon]; 
+
+                               GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
+                               GConnectorView *conView = (GConnectorView*)tempp->getView();
+                               tempp->endContourCreation();
+                               conMod->setEndPort(endP);                                       
+                               conView->updateStartEndPoints();
+
+                       }
+        }
+
+       }
+
+       //=========================================================================
+
        std::vector<int> wxVtkSceneManager::getBoxes()
        {
                std::vector<int> vect;