- //=========================================================================
-
- std::string wxVtkSceneManager::getDiagramBBS(bool wln)
- {
- bool existsExec=false;
-
- 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< (int)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);
- existsExec=true;
- }
- }
- else if(type==GCONNECTOR)
- {
- connections.push_back(it->first);
- }
- }
-
- int lnNmbr=0;
- std::string script = "";
- script+=LineNumber(wln,lnNmbr)+"# BBTK GEditor Script\n";
- script+=LineNumber(wln,lnNmbr)+"# ----------------------\n";
- script+=LineNumber(wln,lnNmbr)+"\n";
- if(existsExec)
- {
- script+=LineNumber(wln,lnNmbr)+"include std\n"; // EED
- script+=LineNumber(wln,lnNmbr)+"include itkvtk\n"; // EED
- int i;
- for(i = 0; i< (int)packages.size();i++)
- {
- script+=LineNumber(wln,lnNmbr);
- script+="include ";
- script+=packages[i];
- script+="\n";
- }
-
- script+=LineNumber(wln,lnNmbr);
- script+="\n";
-
-
-//ups2
-
- script+=LineNumber(wln,lnNmbr);
- script+="author \"";
- script+=_Author;
- script+="\"\n";
-
- script+=LineNumber(wln,lnNmbr);
- script+="description \"";
- script+=_Description;
- script+="\"\n";
-
- script+=LineNumber(wln,lnNmbr);
- script+="category \"";
- script+=_Category;
- script+="\"\n";
-
- script+=LineNumber(wln,lnNmbr);
- script+="\n";
-
-
- // script+="include std\n"; // JPR
-
- for(i = 0; i < (int)boxes.size();i++)
- {
- script+=LineNumber(wln,lnNmbr);
- 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 < (int)inputs.size();j++)
- {
- GPortModel* inputPort = inputs[j];
- if(inputPort->isValueSet())
- {
- script+=LineNumber(wln,lnNmbr);
- script+=" set ";
- script+=model->getBBTKName();
- script+=".";
- script+=inputPort->getBBTKName();
- script+=" ";
- script+=inputPort->getValue();
- script+="\n";
- }
- }
-
- script+=LineNumber(wln,lnNmbr);
- script+="\n";
-
- }
-
- script+=LineNumber(wln,lnNmbr);
- script+="\n";
-
- for(i = 0; i<(int)connections.size();i++)
- {
- 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+=" ";
-
- //End Connection info
- GPortModel *end = model->getEndPort();
- script+=end->getParentBox()->getBBTKName();
- script+=".";
- script+=end->getBBTKName();
-
- script+="\n";
- }
-
- script+=LineNumber(wln,lnNmbr);
- script+="\n";
- for(i = 0; i<(int)execBoxes.size();i++)
- {
- script+=LineNumber(wln,lnNmbr);
- script+="exec ";
- int id = execBoxes[i];
- GObjectController *control = _controllers[id];
- GBlackBoxModel *model = (GBlackBoxModel*)control->getModel();
-
- script+=model->getBBTKName();
- script+="\n";
- }
-
- }
-
- return script;
- }
-
- //=========================================================================
-
- std::string wxVtkSceneManager::saveComplexBoxBBS()
- {
- 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<(int)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 = "";
-
- script+="include std\n"; // EED
- script+="include itkvtk\n"; // EED
- int 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+" "+_cbPackageName;
- script+="\n";
- script+="\n";
-
- script+="author \"";
- script+=_Author;
- script+="\"\n";
-
- script+="description \"";
- script+=_Description;
- script+="\"\n";
- script+="\n";
-
- script+="category \"";
- script+=_Category;
- script+="\"\n";
- script+="\n";
-
-
- // Create boxes
- for(i = 0; i<(int)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<(int)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";
- }
- }
- 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="";
- script+="\n";
-
- for(i = 0; i<(int)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";
- }
- }
-
- script+="\n";
-
- for(i = 0; i<(int)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;
- for(it = _controllers.begin(); it != _controllers.end(); ++it)
- {
- GObjectController *cont = it->second;
- cont->removeFromScene();
- unregisterController((InteractorStyleMaracas*)cont);
- }
- _selectedObjects.clear();
- _controllers.clear();
- refreshScene();
- }
-
- //=========================================================================
-
-
- void wxVtkSceneManager::refresh()
- {
- _baseView->Refresh();
- }
- //=========================================================================
-
- void wxVtkSceneManager::refreshScene()
- {
- _baseView->RefreshView();
- }
-
- //=========================================================================
-
- void wxVtkSceneManager::centerView()
- {
- double temp[3];
- _baseView->GetRenderer()->GetActiveCamera()->GetFocalPoint(temp);
- _baseView->GetRenderer()->GetActiveCamera()->SetFocalPoint(0,0,temp[2]);
- _baseView->GetRenderer()->GetActiveCamera()->GetPosition(temp);
- _baseView->GetRenderer()->GetActiveCamera()->SetPosition(0,0,temp[2]);
- _baseView->RefreshView();
-
- }
-
- //=========================================================================
-
- void wxVtkSceneManager::saveDiagram(std::string &content)
- {
- char buffer [50];
-
- content+="CATEGORY:";
- content+=GetCategory();
- content+="\n";
-
- content+="DESCRIPTION:";
- content+=GetDescription();
- content+="\n";
-
- content+="AUTHOR:";
- content+=GetAuthor();
- content+="\n";
-
-
- //Print info IF COMPLEX BOX
- content+="COMPLEXBOX:";
- if(_isComplexBox)
- {
- content+="TRUE\n";
-//ups1
- content+="COMPLEXBOXNAME:";
- content+=GetCbName();
- content+="\n";
-
- content+="PACKAGENAME:";
- content+=GetCbPackageName();
- content+="\n";
-
- //Print info complex input ports
- 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 info complex output ports
- std::vector<int> outputs = getComplexOutputPorts();
- int outsize = outputs.size();
- content+="COMPLEXOUTPUTS:";
- sprintf (buffer, "%d", outsize);
- content+=buffer;
- content+="\n";
-
- for(int i = 0;i<outsize;i++)
- {
- int id = outputs[i];
- GObjectController *cont = _controllers[id];
- cont->getModel()->save(content);
- }
- } // _isComplexBox
- else
- {
- content+="FALSE\n";
- }
-
- //Print boxes
- std::vector<int> boxes = getBlackBoxes();
- int bsize = boxes.size();
- content+="BOXES:";
- sprintf (buffer, "%d", bsize);
- content+=buffer;
- content+="\n";
-
- for(int i = 0;i<bsize;i++)
- {
- int id = boxes[i];