//=========================================================================
- 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];
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();
}
//=========================================================================
//=========================================================================
- void wxVtkSceneManager::createGConnector(GPortModel* startPort)
+ int wxVtkSceneManager::createGConnector(GPortModel* startPort)
{
int type = GCONNECTOR;
connectorcontroller->setId(newId);
_controllers[newId] = connectorcontroller;
+ return newId;
}
//=========================================================================
{
int id = idController;
_selectedObjects.push_back(id);
- cout<<"RaC wxVtkSceneManager::update _selectedObjects.push_back id:"<<id<<endl;
}
}
char buffer [50];
std::vector<int> boxes = getBoxes();
int bsize = boxes.size();
- content+="BOXES ";
+ content+="BOXES:";
sprintf (buffer, "%d", bsize);
content+=buffer;
content+="\n";
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";
//=========================================================================
+ 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;