//=========================================================================
- std::string wxVtkSceneManager::getDiagramScript()
+ std::string wxVtkSceneManager::getDiagramBBS()
{
bool existsExec=false;
//=========================================================================
+ std::string wxVtkSceneManager::saveComplexBoxBBS(std::string cbName,std::string cbAuthor,std::string cbCategory,std::string cbDescription)
+ {
+
+ std::vector<std::string> packages;
+ std::vector<int> boxes;
+ std::vector<int> connections;
+ std::vector<int> execBoxes;
+
+ std::map<int, GObjectController*>::iterator it;
+
+ for(it = _controllers.begin(); it != _controllers.end(); ++it)
+ {
+ GObjectController *desc = it->second;
+ int type = desc->getGObjectType();
+
+ if(type==GBLACKBOX)
+ {
+ GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
+
+ std::string pkg = mod->getBBTKPackage();
+ bool existsPkg = false;
+ for(int t = 0;t<packages.size() && existsPkg == false;t++)
+ {
+ if(packages[t]==pkg)
+ {
+ existsPkg=true;
+ }
+ }
+ if(!existsPkg)
+ {
+ packages.push_back(pkg);
+ }
+
+
+ boxes.push_back(it->first);
+ if(mod->isExecutable())
+ {
+ execBoxes.push_back(it->first);
+ }
+ }
+ else if(type==GCONNECTOR)
+ {
+ connections.push_back(it->first);
+ }
+ }
+
+ std::string script = "";
+ int i;
+ for(i = 0; i<packages.size();i++)
+ {
+ script+="include ";
+ script+=packages[i];
+ script+="\n";
+ }
+
+ script+="include std\n";
+
+ // Definition of a complex box
+ script+="define ";
+ script+=cbName;
+ script+="\n";
+
+ script+="author \" ";
+ script+=cbAuthor;
+ script+="\"\n";
+
+ script+="description \" ";
+ script+=cbDescription;
+ script+="\"\n";
+
+ // Create boxes
+ for(i = 0; i<boxes.size();i++)
+ {
+ script+="new ";
+ int id = boxes[i];
+ GObjectController *control = _controllers[id];
+ GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
+
+ script+=model->getBBTKType();
+ script+=" ";
+ script+=model->getBBTKName();
+ script+="\n";
+
+ std::vector<GPortModel*> inputs = model->getInputPorts();
+ for(int j = 0; j<inputs.size();j++)
+ {
+ GPortModel* inputPort = inputs[j];
+ if(inputPort->isValueSet())
+ {
+ script+="set ";
+ script+=model->getBBTKName();
+ script+=".";
+ script+=inputPort->getBBTKName();
+ script+=" ";
+ script+=inputPort->getValue();
+ script+="\n";
+ }
+ }
+
+ }
+
+ // Create connections in the script. If the connection is made with a complex port, it is created the input or output
+
+ std::string complexInputs="";
+ std::string complexOutputs="";
+
+ for(i = 0; i<connections.size();i++)
+ {
+ int id = connections[i];
+ GObjectController *control = _controllers[id];
+ GConnectorModel *model = (GConnectorModel*)control->getModel();
+
+ //Connection info
+ GPortModel *start = model->getStartPort();
+ GBoxModel *startBox =start->getParentBox();
+
+ GPortModel *end = model->getEndPort();
+ 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 if(endBox->getGObjectType()==GCOMPLEXOUTPUTPORT)
+ {
+ complexOutputs+="output ";
+ complexOutputs+=endBox->getBBTKName();
+
+ complexOutputs+=" ";
+ complexOutputs+=startBox->getBBTKName();
+ complexOutputs+=".";
+ complexOutputs+=start->getBBTKName();
+
+ complexOutputs+=" ";
+ complexOutputs+="\" \"";
+
+ complexOutputs+="\n";
+ }
+ else
+ {
+ script+="connect ";
+ script+=startBox->getBBTKName();
+ script+=".";
+ script+=start->getBBTKName();
+
+ script+=" ";
+
+ //End Connection info
+ script+=endBox->getBBTKName();
+ script+=".";
+ script+=end->getBBTKName();
+
+ script+="\n";
+ }
+ }
+
+ for(i = 0; i<execBoxes.size();i++)
+ {
+ script+="exec ";
+ int id = execBoxes[i];
+ GObjectController *control = _controllers[id];
+ GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
+
+ script+=model->getBBTKName();
+ 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";
+
+ return script;
+ }
+
+ //=========================================================================
+
void wxVtkSceneManager::deleteAllBoxes()
{
std::map<int, GObjectController*>::iterator it;