- std::vector<int> controllersToRemove;
-
- if(control->getGObjectType()==GBLACKBOX || control->getGObjectType()==GCOMPLEXINPUTPORT || control->getGObjectType()==GCOMPLEXOUTPUTPORT)
- {
- GBoxModel *bbmod = (GBoxModel*)control->getModel();
- std::vector<GPortModel*> inputs = bbmod->getInputPorts();
-
- bool boxConnected = false;
-
- // Add box input controllers to be removed
- for(int i = 0;i< (int)inputs.size();i++)
- {
- AddControlerToBeRemove( &controllersToRemove, inputs[i]->getObjectId() );
- if(inputs[i]->isConnected())
- {
- boxConnected = true;
- }
- }
-
- std::vector<GPortModel*> outputs = bbmod->getOutputPorts();
-
- // Add box output controllers to be removed
- for(int i = 0;i<(int)outputs.size();i++)
- {
- AddControlerToBeRemove( &controllersToRemove, outputs[i]->getObjectId() );
- if(outputs[i]->isConnected())
- {
- boxConnected = true;
- }
- }
-
- // Add connection controllers to be removed
- std::map<int, GObjectController*>::iterator it;
- for(it = _controllers.begin(); it != _controllers.end(); ++it)
- {
- GObjectController *cont = it->second;
- int type = cont->getGObjectType();
- if(type==GCONNECTOR)
- {
- GConnectorModel *conMod = (GConnectorModel*)cont->getModel();
- if(conMod->getStartPort()!=NULL && conMod->getStartPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
- {
- AddControlerToBeRemove( &controllersToRemove, conMod->getObjectId() );
- }
- if(conMod->getEndPort()!=NULL && conMod->getEndPort()->getParentBox()->getObjectId() == bbmod->getObjectId())
- {
- AddControlerToBeRemove( &controllersToRemove, conMod->getObjectId() );
- }
- }
- }
-
- // Add box controller to be removed
- AddControlerToBeRemove( &controllersToRemove, bbmod->getObjectId() );
- }
- else if(control->getGObjectType()==GCONNECTOR)
- {
- GConnectorModel *conMod = (GConnectorModel*)control->getModel();
- AddControlerToBeRemove( &controllersToRemove, conMod->getObjectId() );
- }
-
-
- std::map<int,GObjectController*>::iterator it;
-
- for(int i = 0;i<(int)controllersToRemove.size();i++)
- {
- int key = controllersToRemove[i];
- it = _controllers.find( key );
- GObjectController *cont = _controllers[ key ];
- if(cont!=NULL)
- {
- cont->removeFromScene();
- unregisterController((InteractorStyleMaracas*)cont);
- _controllers.erase(it);
- }//if
- }// for
- }
-
- //=========================================================================
-
- void wxVtkSceneManager::displayBlackBoxInfo(std::string packageName, std::string boxName)
- {
- _parent->displayBlackBoxInfo(packageName,boxName);
- }
-
- //=========================================================================
-
- void wxVtkSceneManager::updateStatusBar(std::string textStatus)
- {
- _parent->updateStatusBar(textStatus);
- }
-
-
- //=========================================================================
- std::string wxVtkSceneManager::LineNumber(bool withLineNumber, int &value)
- {
- std::string result="";
- if (withLineNumber==true)
- {
- value++;
- stringstream StrStream;
- StrStream << value;
- std::string strValue=StrStream.str();
- if (value<10)
- {
- result+=" ";
- }else if (value<100)
- {
- result+=" ";
- }
-
- result+=strValue+": ";
- }
- return result;
- }
- //=========================================================================
-
- 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";
-
- // 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";
- }