]> Creatis software - bbtkGEditor.git/blobdiff - lib/EditorGraphicBBS/bbsKernelEditorGraphic/wxVtkSceneManager.cxx
It is possible to execute the simplest diagram :) Perfect !!!
[bbtkGEditor.git] / lib / EditorGraphicBBS / bbsKernelEditorGraphic / wxVtkSceneManager.cxx
index 78ece891bb13c29bcdf5cd1ba7c2fc752074978e..0420aa3356d8901b591cfa0e8f30e933055cb348 100644 (file)
@@ -66,7 +66,7 @@ namespace bbtk
        void wxVtkSceneManager::disconnectDrop()
        {
                _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget(NULL);
-       }
+       }
 
        //=========================================================================
 
@@ -98,7 +98,7 @@ namespace bbtk
 
        //=========================================================================
 
-       void wxVtkSceneManager::createGBlackBox(int x, int y, std::string packageName, std::string boxName)
+       void wxVtkSceneManager::createGBlackBox(int x, int y, std::string packageName, std::string boxType)
        {
 
                int windowWidth=_baseView->GetRenWin()->GetSize()[0];
@@ -112,7 +112,7 @@ namespace bbtk
                vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
                GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
                
-               BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxName);
+               BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxType);
                
                //Prepares the initial model
                //The coordinates obtained are the following. Top-Left:x=0,y=0 Bottom-Right:x=width,y=height  
@@ -140,7 +140,7 @@ namespace bbtk
                std::string arraystring = stream.str();
 
                model->setBBTKName(arraystring);
-               model->setBBTKType(boxName);
+               model->setBBTKType(boxType);
                model->setBBTKPackage(packageName);
                                
                model->addObserver(view);
@@ -197,19 +197,19 @@ namespace bbtk
 
        void wxVtkSceneManager::createGInputPort(int portType, int posinBox,GBlackBoxModel *blackBox, BlackBoxInputDescriptor *desc)
        {
-               createGPort(portType,posinBox,blackBox);
+               createGPort(portType,desc->GetName(),desc->GetTypeName(),posinBox,blackBox);
        }
 
        //=========================================================================
 
        void wxVtkSceneManager::createGOutputPort(int portType, int posinBox,GBlackBoxModel *blackBox, BlackBoxOutputDescriptor *desc)
        {
-               createGPort(portType,posinBox,blackBox);
+               createGPort(portType,desc->GetName(),desc->GetTypeName(),posinBox,blackBox);
        }
 
        //=========================================================================
 
-       void wxVtkSceneManager::createGPort(int portType, int posInBox,GBlackBoxModel *blackBox)
+       void wxVtkSceneManager::createGPort(int portType,std::string bbtkName, std::string bbtkType, int posInBox,GBlackBoxModel *blackBox)
        {
                int type = GPORT;
 
@@ -221,6 +221,9 @@ namespace bbtk
                model->registerInBox(blackBox,portType, posInBox);
                blackBox->addOutputPort(model);
                
+               model->setBBTKType(bbtkType);
+               model->setBBTKName(bbtkName);
+
                model->addObserver(view);
                model->addObserver(this);
 
@@ -333,65 +336,7 @@ namespace bbtk
        }
        //=========================================================================
 
-       bool wxVtkSceneManager::OnMouseMove()
-       {
-               int X,Y;
-               wxVTKRenderWindowInteractor *wxVTKiren;
-               wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
-               wxVTKiren->GetEventPosition(X,Y);
-       
                
-               if(_worldState == DRAG_OBJECTS)
-               {                       
-                       for (int i=0; i<_selectedObjects.size(); i++)
-                       {
-                               int id = _selectedObjects[i];
-                               GObjectController* cont = _controllers[id];
-                               if(_startDragging)
-                               {
-                                       cont->getView()->setStartDragging(true);
-                               }
-                               cont->getView()->moveObject(X,Y);
-                               cont->getView()->setState(DRAG);
-                               cont->getModel()->notifyObservers(_idManager);
-                       }
-
-                       std::map<int, GObjectController*>::iterator it;
-
-                       for(it = _controllers.begin(); it != _controllers.end(); ++it)
-                       {
-                               GObjectController *desc = it->second;
-                               if(desc->getGObjectType()==GCONNECTOR)
-                               {
-                                       GConnectorView* vconn = (GConnectorView*)desc->getView();
-                                       vconn->updateStartEndPoints();
-                               }
-                       }
-                       
-                       _startDragging=false;
-
-               }
-               else if(_worldState == NOTHING_HAPPENS)
-               {
-                       std::map<int, GObjectController*>::iterator it;
-
-                       for(it = _controllers.begin(); it != _controllers.end(); ++it)
-                       {
-                               GObjectController *desc = it->second;
-                               if(desc->getGObjectType()==GBLACKBOX && desc->getView()->getState() == HIGHLIGHTED)
-                               {
-                                       GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
-                                       _parent->displayBlackBoxInfo(mod->getBBTKPackage(),mod->getBBTKType());
-                               }
-                       }
-               }
-
-
-               return true;
-       }
-
-       //=========================================================================
-       
        void wxVtkSceneManager::update(int idController,int command)
        {
                if(command != NO_COMMAND)
@@ -488,6 +433,73 @@ namespace bbtk
 
        //=========================================================================
 
+       bool wxVtkSceneManager::OnMouseMove()
+       {
+               int X,Y;
+               wxVTKRenderWindowInteractor *wxVTKiren;
+               wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
+               wxVTKiren->GetEventPosition(X,Y);
+       
+               
+               if(_worldState == DRAG_OBJECTS)
+               {                       
+                       for (int i=0; i<_selectedObjects.size(); i++)
+                       {
+                               int id = _selectedObjects[i];
+                               GObjectController* cont = _controllers[id];
+                               if(_startDragging)
+                               {
+                                       cont->getView()->setStartDragging(true);
+                               }
+                               cont->getView()->moveObject(X,Y);
+                               cont->getView()->setState(DRAG);
+                               cont->getModel()->notifyObservers(_idManager);
+                       }
+
+                       std::map<int, GObjectController*>::iterator it;
+
+                       for(it = _controllers.begin(); it != _controllers.end(); ++it)
+                       {
+                               GObjectController *desc = it->second;
+                               if(desc->getGObjectType()==GCONNECTOR)
+                               {
+                                       GConnectorView* vconn = (GConnectorView*)desc->getView();
+                                       vconn->updateStartEndPoints();
+                               }
+                       }
+                       
+                       _startDragging=false;
+
+               }
+               else if(_worldState == NOTHING_HAPPENS || _worldState == INIT_CREATION_CONTOUR)
+               {
+                       std::map<int, GObjectController*>::iterator it;
+
+                       for(it = _controllers.begin(); it != _controllers.end(); ++it)
+                       {
+                               GObjectController *desc = it->second;
+                               int type = desc->getGObjectType();
+                               int state = desc->getView()->getState();
+                               
+                               if(state == HIGHLIGHTED){
+
+                                       updateStatusBar(desc->getStatusText());
+                                       if(type==GBLACKBOX)
+                                       {
+                                               GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
+                                               _parent->displayBlackBoxInfo(mod->getBBTKPackage(),mod->getBBTKType());
+                                       }
+                               }
+                       }
+               }
+               
+               
+
+
+               return true;
+       }
+
+       //=========================================================================
        
        bool wxVtkSceneManager::OnLeftButtonDown()
        {
@@ -555,6 +567,131 @@ namespace bbtk
                _parent->displayBlackBoxInfo(packageName,boxName);
        }
 
+       //=========================================================================
+
+       void wxVtkSceneManager::updateStatusBar(std::string textStatus)
+       {
+               _parent->updateStatusBar(textStatus);
+       }
+
+       //=========================================================================
+
+       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