- std::map<int, GObjectController*>::iterator it;
-
- for(it = _controllers.begin(); it != _controllers.end() ; ++it)
- {
- GObjectController *cont = it->second;
- int type = cont->getGObjectType();
-
- if( cont->getView()->isPointInside(X,Y)==true )
- {
- if(type==GBLACKBOX)
- {
- result=cont;
- } // if type
- } // if isPointInside
- } // for it
- return result;
- }
-
- //=========================================================================
- void wxVtkSceneManager::UnSelectBlackBoxes()
- {
- for (int i=0; i< (int)_selectedObjects.size(); i++)
- {
- int id = _selectedObjects[i];
- GObjectController* control = _controllers[id];
- control->getView()->setState(NOTHING_HAPPENS);
- }// for _selectedObjects
- _selectedObjects.clear();
- }
-
- //=========================================================================
- bool wxVtkSceneManager::OnLeftDClick()
- {
- GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
- if (cont!=NULL)
- {
- UnSelectBlackBoxes();
- _parent->editBlackBox( (GBlackBoxModel*)cont->getModel() );
- }
-
-/*EED Borrame
-
- int X,Y;
- wxVTKRenderWindowInteractor *wxVTKiren;
- wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
- wxVTKiren->GetEventPosition(X,Y);
-
- std::map<int, GObjectController*>::iterator it;
-
- bool clickOnObject = false;
-
- for(it = _controllers.begin(); it != _controllers.end() && clickOnObject==false; ++it)
- {
- GObjectController *cont = it->second;
- int type = cont->getGObjectType();
-
- if(cont->getView()->isPointInside(X,Y))
- {
- if(type==GBLACKBOX)
- {
- for (int i=0; i< (int)_selectedObjects.size(); i++)
- {
- int id = _selectedObjects[i];
- GObjectController* control = _controllers[id];
- control->getView()->setState(NOTHING_HAPPENS);
- }
- _selectedObjects.clear();
-
- GBlackBoxModel *bbmodel = (GBlackBoxModel*)cont->getModel();
- _parent->editBlackBox(bbmodel);
- }
- clickOnObject = true;
- }
- }
-
- if(clickOnObject==false)
- {
- //_parent->editDiagramParameters(this);
- }
-*/
- return true;
- }
-
- //=========================================================================
-
- bool wxVtkSceneManager::OnChar()
- {
- char keyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
-
- // KeyCode 127 : Delete Key
- // KeyCode 8 : Backspace Key
- if(keyCode == 8 || keyCode == 127)
- {
- if(_selectedObjects.size()>0)
- {
- for(int i=0;i<(int)_selectedObjects.size();i++)
- {
- int id = _selectedObjects[i];
- std::map<int,GObjectController*>::iterator it;
- it = _controllers.find(id);
- if (it!=_controllers.end())
- {
- deleteObject(id);
- }
- }
- _selectedObjects.clear();
- }
- }
-
- return true;
- }
-
- //=========================================================================
-
- void wxVtkSceneManager::AddControlerToBeRemove(std::vector<int> *controllersToRemove, int id)
- {
-
- int i;
- bool ok=true;
- for(i=0 ; i < (int)controllersToRemove->size() ; i++ )
- {
- if (id == (*controllersToRemove)[i] )
- {
- ok=false;
- }
- }
-
- if (ok==true)
- {
- controllersToRemove->push_back( id );
- }
-
- }
-
- //=========================================================================
-
- void wxVtkSceneManager::deleteObject(int id)
- {
- GObjectController *control = _controllers[id];
- 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";
-
-
-//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;