]> Creatis software - bbtkGEditor.git/blobdiff - lib/EditorGraphicBBS/bbsKernelEditorGraphic/wxVtkSceneManager.cxx
Implemented deleting of boxes from the scene....
[bbtkGEditor.git] / lib / EditorGraphicBBS / bbsKernelEditorGraphic / wxVtkSceneManager.cxx
index 22d89775f66482ed7e0434caa6e5351cb1ef2649..c4efe5605d986f87da642f9bbcd499ea122c47e3 100644 (file)
@@ -118,7 +118,7 @@ namespace bbtk
                //The coordinates obtained are the following. Top-Left:x=0,y=0 Bottom-Right:x=width,y=height  
 
                double xx = x;
-               double yy =  windowHeight-y;
+               double yy = windowHeight-y;
                
                //z value is not important yet, because it is only used a parallel projection
                double zz = 900;
@@ -323,6 +323,14 @@ namespace bbtk
 
        //=========================================================================
 
+       void wxVtkSceneManager::unregisterController(InteractorStyleMaracas *param)
+       {
+               vtkInteractorStyleBaseView* baseViewControlManager = (vtkInteractorStyleBaseView*)_baseView->GetInteractorStyleBaseView();
+               baseViewControlManager->RemoveInteractorStyleMaracas( param );
+       }
+
+       //=========================================================================
+
        vtkRenderer* wxVtkSceneManager::getRenderer()
        {
                return _baseView->GetRenderer();
@@ -562,6 +570,69 @@ namespace bbtk
 
        //=========================================================================
 
+       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<_selectedObjects.size();i++)
+                               {
+                                       int id = _selectedObjects[i];
+                                       removeObject(id);
+                               }
+                               _selectedObjects.clear();
+                       }
+               }
+
+               return true;
+       }
+
+       //=========================================================================
+
+       void wxVtkSceneManager::removeObject(int id)
+       {
+               GObjectController *control = _controllers[id];
+               std::vector<int> controllersToRemove;
+
+               if(control->getGObjectType()==GBLACKBOX)
+               {
+                       GBlackBoxModel *bbmod = (GBlackBoxModel*)control->getModel();
+                       std::vector<GPortModel*>inputs = bbmod->getInputPorts();
+                       
+                       for(int i = 0;i<inputs.size();i++)
+                       {
+                               controllersToRemove.push_back(inputs[i]->getObjectId());
+                       }
+
+                       std::vector<GPortModel*>outputs = bbmod->getOutputPorts();
+
+                       for(int i = 0;i<outputs.size();i++)
+                       {
+                               controllersToRemove.push_back(outputs[i]->getObjectId());
+                       }
+
+                       controllersToRemove.push_back(control->getId());
+               }
+
+               for(int i = 0;i<controllersToRemove.size();i++)
+               {
+                       int id = controllersToRemove[i];
+                       GObjectController *cont = _controllers[id];
+                       cont->removeFromScene();
+                       unregisterController((InteractorStyleMaracas*)cont);
+                       _controllers.erase(id);
+               }
+
+
+       }
+
+       //=========================================================================
+
        void wxVtkSceneManager::displayBlackBoxInfo(std::string packageName, std::string boxName)
        {
                _parent->displayBlackBoxInfo(packageName,boxName);
@@ -576,6 +647,122 @@ namespace bbtk
 
        //=========================================================================
 
+       std::string wxVtkSceneManager::getDiagramScript()
+       {
+               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<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);
+                       }
+               }
+
+               std::string script = "";
+               script+="# BBTK GEditor Script\n";
+               script+="# ----------------------\n";
+               if(existsExec)
+               {
+                       int i;
+                       for(i = 0; i<packages.size();i++)
+                       {
+                               script+="load ";
+                               script+=packages[i];
+                               script+="\n";
+                       }
+
+                       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";
+                       }
+
+                       for(i = 0; i<connections.size();i++)
+                       {
+                               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";
+                       }
+
+                       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";
+                       }
+
+               }
+
+               return script;
+       }
+
+       //=========================================================================
+
 }  // EO namespace bbtk
 
 // EOF