]> Creatis software - bbtkGEditor.git/blobdiff - lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxVtkSceneManager.cxx
This commit was manufactured by cvs2svn to create tag 'CREATOOLS_2-0-3'.
[bbtkGEditor.git] / lib / EditorGraphicBBS / bbsWxGUIEditorGraphic / wxVtkSceneManager.cxx
index de07bcb8ee13796df554b65938d8522d2d52d6b6..3cb95f86f21e22778fb95e3f97f47a42029d7e57 100644 (file)
@@ -58,7 +58,7 @@ namespace bbtk
                {
 //EED02JUIN2010
                        printf ("RaC-EED 21-06-2010 %p wxVtkSceneManager::wxVtkSceneManager If you comment this line, the drag and drop functionnality is not initialized.\n" , this );
-#ifdef _APPLE_
+#ifdef __APPLE__
                        _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget((wxDropTarget*)parent);
 #endif
 
@@ -132,7 +132,6 @@ namespace bbtk
                _fillObjectActor                                                = vtkActor::New();
 
                                                        _pts                            = vtkPoints::New();
-//ups4 EED Borrame
 
                double w=100,h=10,b=h/15,t=3;
                _pts->SetNumberOfPoints(21);
@@ -598,7 +597,6 @@ printf("EED  wxVtkSceneManager::createGComplexBoxOutputPort 900-450\n");
 
        void wxVtkSceneManager::update(int idController,int command)
        {
-printf("EED wxVtkSceneManager::update  1 \n" );
 
                if(command != NO_COMMAND)
                {
@@ -667,20 +665,17 @@ printf("EED wxVtkSceneManager::update  1 \n" );
                                                cont->SetActive(false);
                                        }
                                }
-
                                _selectedObjects.clear();
-
                                _idConnectionInCreation=createGConnector(startOutputPort);
-
                        }
                        else if(command == FIN_CREATION_CONTOUR && _worldState == INIT_CREATION_CONTOUR)
                        {
-                               _worldState = NOTHING_HAPPENS;
+                               _worldState                                             =       NOTHING_HAPPENS;
                                //int id = _controllers.size()-1;
-                               GObjectController* cont = _controllers[_idConnectionInCreation];
-                               GConnectorModel* modelContour = (GConnectorModel*)cont->getModel();
+                               GObjectController       *cont                   = _controllers[_idConnectionInCreation];
+                               GConnectorModel         *modelContour   = (GConnectorModel*)cont->getModel();
+                               GObjectController       *finPort                = _controllers[idController];
 
-                               GObjectController* finPort = _controllers[idController];
                                if(finPort->getGObjectType() == GPORT)
                                {
                                        GPortModel* modelPort = (GPortModel*)finPort->getModel();
@@ -707,8 +702,6 @@ printf("EED wxVtkSceneManager::update  1 \n" );
 
                }
 
-printf("EED wxVtkSceneManager::update  2 \n" );
-
        }
 
        //=========================================================================
@@ -740,6 +733,7 @@ printf("EED wxVtkSceneManager::update  2 \n" );
 
                        std::map<int, GObjectController*>::iterator it;
 
+
                        for(it = _controllers.begin(); it != _controllers.end(); ++it)
                        {
                                GObjectController *desc = it->second;
@@ -781,7 +775,6 @@ printf("EED wxVtkSceneManager::update  2 \n" );
                                                _textActor->SetScale(0.1);
                                                _textActor->SetPosition(  px-25 ,py+1 , pz+2 );
 
-//ups4 EED Borrame
                                                // FillPortText
                                                px=px-33;
                                                py=py;
@@ -804,8 +797,6 @@ printf("EED wxVtkSceneManager::update  2 \n" );
                        _textActor->SetScale(0.0001);
                        _fillObjectActor->SetScale(0.0001);
                }
-
-
                return true;
        }
 
@@ -813,6 +804,7 @@ printf("EED wxVtkSceneManager::update  2 \n" );
 
        bool wxVtkSceneManager::OnLeftButtonDown()
        {
+
                if(_worldState==INIT_CREATION_CONTOUR)
                {
                        bool isOverPort=false;
@@ -822,8 +814,8 @@ printf("EED wxVtkSceneManager::update  2 \n" );
                                GObjectController *desc = it->second;
                                if(desc->getGObjectType()==GPORT)
                                {
-                                       GPortModel* portmod=(GPortModel*)desc->getModel();
-                                       vtkGObjectView* portView=desc->getView();
+                                       GPortModel              *portmod        = (GPortModel*)desc->getModel();
+                                       vtkGObjectView  *portView       = desc->getView();
                                        if(portmod->getPortType()==GINPUTPORT && portView->getState()==HIGHLIGHTED)
                                        {
                                                isOverPort=true;
@@ -833,55 +825,41 @@ printf("EED wxVtkSceneManager::update  2 \n" );
 
                        if(isOverPort==false)
                        {
-                               _worldState=NOTHING_HAPPENS;
-                               //int lastId = _controllers.size()-1;
-//EED2Oct2010                          GConnectorController *connector = (GConnectorController*)_controllers[_controllers.size()-1];
-                               GConnectorController *connector = (GConnectorController*)_controllers[_idConnectionInCreation];
-
-                               connector->removeFromScene();
-                               unregisterController(connector);
-                               _controllers.erase(_controllers.size()-1);
-
-                               for(it = _controllers.begin(); it != _controllers.end(); ++it)
-                               {
-                                       GObjectController *desc = it->second;
-                                       desc->SetActive(true);
-                                       desc->getView()->setState(NOTHING_HAPPENS);
-                                       desc->getModel()->notifyObservers(_idManager);
-                               } // for
+                               CancelConnection();
+                               UnSelectBlackBoxes();
                        } // isOverPort
-               } // _worldState
-
-        _worldState            = DRAG_OBJECTS;
-        _startDragging = true;
-
-
-printf("EED wxVtkSceneManager::OnLeftButtonDown  1 \n" );
-
 
-        int ctrlkey             = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
-        GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
-
-        if (GetGBlackBoxControlerPointedByMouse()!=NULL)
-        {
-            int state=cont->getView()->getState() ;
-                       if(  (ctrlkey==0) && (state==HIGHLIGHTED) )
-            {
-                UnSelectBlackBoxes();
-            }
-        }
-
-
-        for (int i = 0; i < (int)_selectedObjects.size(); i++)
-        {
-            int id = _selectedObjects[i];
-            GObjectController* cont = _controllers[id];
-            cont->getView()->setState(DRAG);
-            cont->getModel()->notifyObservers(_idManager);
-        } // for
+               } else {  //_worldState
+                       
+                       _worldState                             = DRAG_OBJECTS;
+                       _startDragging                  = true;
+                       
+                       int shiftkey            = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey();
+                       int ctrlkey             = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
+                       ctrlkey = ctrlkey + shiftkey;
+                       
+                       GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
+
+                       
+                       if (GetGBlackBoxControlerPointedByMouse()!=NULL)
+                       {
+                               int state=cont->getView()->getState() ;
+                               if(  (ctrlkey==0) && (state==HIGHLIGHTED) )
+                               {
+                                       UnSelectBlackBoxes();
+                               }
+                       }
+                       for (int i = 0; i < (int)_selectedObjects.size(); i++)
+                       {
+                               int id = _selectedObjects[i];
+                               GObjectController* cont = _controllers[id];
+                               cont->getView()->setState(DRAG);
+                               cont->getModel()->notifyObservers(_idManager);
+                       } // for
 
-printf("EED wxVtkSceneManager::OnLeftButtonDown  2 \n" );
+               } // if _selectedObjects.size
 
+               
                return true;
        }
 
@@ -905,19 +883,18 @@ printf("EED wxVtkSceneManager::OnLeftButtonDown  2 \n" );
        }
 
        //=========================================================================
-
-       bool wxVtkSceneManager::OnRightButtonUp()
+       void wxVtkSceneManager::CancelConnection()
        {
                if(_worldState==INIT_CREATION_CONTOUR)
                {
                        _worldState=NOTHING_HAPPENS;
                        //int lastId = _controllers.size()-1;
-
+                       
                        GConnectorController *connector = (GConnectorController*)_controllers[_idConnectionInCreation];
                        connector->removeFromScene();
                        unregisterController(connector);
                        _controllers.erase(_idConnectionInCreation);
-
+                       
                        std::map<int, GObjectController*>::iterator it;
                        for(it = _controllers.begin(); it != _controllers.end(); ++it)
                        {
@@ -925,21 +902,20 @@ printf("EED wxVtkSceneManager::OnLeftButtonDown  2 \n" );
                                desc->SetActive(true);
                                desc->getView()->setState(NOTHING_HAPPENS);
                                desc->getModel()->notifyObservers(_idManager);
-                       }
-               }
-
+                       } // for
+               }// if          
+       }
+       
+       
+       //=========================================================================
 
-               for (int i = 0; i < (int)_selectedObjects.size(); i++)
+       bool wxVtkSceneManager::OnRightButtonUp()
+       {
+               if(_worldState==INIT_CREATION_CONTOUR)
                {
-                       int id = _selectedObjects[i];
-                       GObjectController* cont = _controllers[id];
-                       cont->SetActive(true);
-                       cont->getView()->setState(NOTHING_HAPPENS);
-                       cont->getModel()->notifyObservers(_idManager);
+                       CancelConnection();
                }
-
-               _selectedObjects.clear();
-
+               UnSelectBlackBoxes();
                return true;
        }
 
@@ -972,7 +948,7 @@ printf("EED wxVtkSceneManager::OnLeftButtonDown  2 \n" );
     }
 
        //=========================================================================
-       bool wxVtkSceneManager::UnSelectBlackBoxes()
+       void wxVtkSceneManager::UnSelectBlackBoxes()
        {
         for (int i=0; i< (int)_selectedObjects.size(); i++)
                {
@@ -1691,6 +1667,7 @@ printf("EED wxVtkSceneManager::OnLeftButtonDown  2 \n" );
        void wxVtkSceneManager::loadDiagram(ifstream &inputStream)
        {
 
+               std::string version;
                std::string line="";
                char delims[] = ":";
                char *result = NULL;
@@ -1702,6 +1679,12 @@ printf("EED wxVtkSceneManager::OnLeftButtonDown  2 \n" );
                        if(line=="" || line[0]=='#')
                        {
                                getline(inputStream,line);
+                               if (line=="# - BBTKGEditor v 1.0 BBG BlackBox Diagram file")
+                               {
+                                       version=line.substr(18,3);
+                                       printf("EED wxVtkSceneManager::loadDiagram  version=%s\n",version.c_str());
+                               }
+
                        }
                        else if(line=="APP_START")
                        {
@@ -1953,11 +1936,51 @@ printf("EED wxVtkSceneManager::OnLeftButtonDown  2 \n" );
                                result = strtok( NULL, delims );
                                std::string nameEndPort(result);
 
-                               configGConnetion(nameStartBox, nameStartPort, nameEndBox, nameEndPort);
+                               int idCon = configGConnetion(nameStartBox, nameStartPort, nameEndBox, nameEndPort);
+                               
+                               if (version!="1.0")
+                               {
+                                       //Readding control points of the manualContour 
+                                       //ups1
+                                       GConnectorController    *tempp  = (GConnectorController*)_controllers[idCon];                           
+                                       GConnectorModel                 *conMod = (GConnectorModel*)tempp->getModel();
+                                       vtkGConnectorView               *conView= (vtkGConnectorView*)tempp->getView();
+                                       getline(inputStream,line); //NumberOfControlPoints:##
+                                       strcpy( conns, line.c_str() );
+                                       result = strtok( conns, delims );
+                                       result = strtok( NULL, delims );
+                               
+                                       int numberOfControlPoints;
+                                       std::istringstream isCons(result);
+                                       isCons >> numberOfControlPoints;
+                               
+                                       for (int ii=0;ii<numberOfControlPoints;ii++)
+                                       {
+                                               getline(inputStream,line); //XX:YY:ZZ
+                                               char connec[200];
+                                               strcpy( connec, line.c_str() );
+                                       
+                                               double px,py,pz;
+                                               result = strtok( connec, delims );
+                                               std::istringstream isPointX(result);
+                                               isPointX >> px;
+                                               result = strtok( NULL, delims );
+                                               std::istringstream isPointY(result);
+                                               isPointY >> py;
+                                               result = strtok( NULL, delims );
+                                               std::istringstream isPointZ(result);
+                                               isPointZ >> pz;
+                                       
+                                               conMod->getManualContourModel()->InsertPoint_id(ii+1,px,py,pz);
+                                               conView->getManualContourView()->AddPoint();
+                                       }
+                               }// version !=1.0
+                               
                        } // for numConns
 
         } // start
-
+               
+               refresh();
        }
        //=========================================================================
 
@@ -2031,7 +2054,7 @@ printf("EED wxVtkSceneManager::OnLeftButtonDown  2 \n" );
        //=========================================================================
 
 
-       void wxVtkSceneManager::configGConnetion(std::string nameStartBox, std::string  nameStartPort, std::string
+       int wxVtkSceneManager::configGConnetion(std::string nameStartBox, std::string  nameStartPort, std::string
                                                                                         nameEndBox, std::string  nameEndPort)
        {
 
@@ -2051,7 +2074,7 @@ printf("EED wxVtkSceneManager::OnLeftButtonDown  2 \n" );
                        endP            = boxModel->getInputPort(nameEndPort);
                }
 
-
+//ups2
                int idCon                                       = createGConnector(startP);
                _worldState                                     = NOTHING_HAPPENS;
                GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
@@ -2061,6 +2084,7 @@ printf("EED wxVtkSceneManager::OnLeftButtonDown  2 \n" );
                tempp->endContourCreation();
                conMod->setEndPort(endP);
                conView->updateStartEndPoints();
+               return idCon;
        }
 
        //=========================================================================