]> Creatis software - bbtkGEditor.git/blobdiff - lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxVtkSceneManager.cxx
some memory leaks
[bbtkGEditor.git] / lib / EditorGraphicBBS / bbsWxGUIEditorGraphic / wxVtkSceneManager.cxx
index de07bcb8ee13796df554b65938d8522d2d52d6b6..3740f982be9afc20d9c3e585f6913dc7afae0a2f 100644 (file)
@@ -39,7 +39,6 @@ Version:   $Revision$
  #include <vtkPolygon.h>
  #include <vtkUnstructuredGrid.h>
 
-
 namespace bbtk
 {
 
@@ -47,6 +46,12 @@ namespace bbtk
        //=========================================================================
        wxVtkSceneManager::wxVtkSceneManager(wxGEditorTabPanel *parent, wxVtk3DBaseView *baseView,int idManager)
        {
+        _cbName         = "ComplexBoxName";
+        _cbPackageName  = "PackageName";
+        _Author       = "Author ??";
+        _Category     = "<VOID>";
+        _Description  = "Description ??";
+
                _parent                 = parent;
                _numBoxes               = 0;
                _idManager              = idManager;
@@ -58,7 +63,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
 
@@ -85,14 +90,17 @@ namespace bbtk
 
        wxVtkSceneManager::~wxVtkSceneManager()
        {
+               //FCY memory leaks
                printf ("EED %p ~wxVtkSceneManager()\n" , this );
                disconnectDrop();
+               delete _baseView;
        }
 
        //=========================================================================
 
        void wxVtkSceneManager::configureBaseView()
        {
+printf("EED wxVtkSceneManager::configureBaseView 0\n");
                vtkInteractorStyleBaseView2D *interactorstylebaseview = vtkInteractorStyleBaseView2D::New();
 
                _baseView->SetInteractorStyleBaseView(interactorstylebaseview);
@@ -132,7 +140,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);
@@ -180,6 +187,7 @@ namespace bbtk
                _aPolygonMapper->Modified();
 
                _baseView->GetRenderer()->AddActor( _fillObjectActor );
+printf("EED wxVtkSceneManager::configureBaseView 1\n");
        }
 
        //=========================================================================
@@ -598,7 +606,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 +674,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 +711,6 @@ printf("EED wxVtkSceneManager::update  1 \n" );
 
                }
 
-printf("EED wxVtkSceneManager::update  2 \n" );
-
        }
 
        //=========================================================================
@@ -740,6 +742,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 +784,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 +806,6 @@ printf("EED wxVtkSceneManager::update  2 \n" );
                        _textActor->SetScale(0.0001);
                        _fillObjectActor->SetScale(0.0001);
                }
-
-
                return true;
        }
 
@@ -813,6 +813,7 @@ printf("EED wxVtkSceneManager::update  2 \n" );
 
        bool wxVtkSceneManager::OnLeftButtonDown()
        {
+
                if(_worldState==INIT_CREATION_CONTOUR)
                {
                        bool isOverPort=false;
@@ -822,8 +823,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,54 +834,40 @@ 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;
+               } else {  //_worldState
 
+                       _worldState                             = DRAG_OBJECTS;
+                       _startDragging                  = true;
 
-printf("EED wxVtkSceneManager::OnLeftButtonDown  1 \n" );
+                       int shiftkey            = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey();
+                       int ctrlkey             = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
+                       ctrlkey = ctrlkey + shiftkey;
 
+                       GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
 
-        int ctrlkey             = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
-        GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
-
-        if (GetGBlackBoxControlerPointedByMouse()!=NULL)
-        {
-            int state=cont->getView()->getState() ;
-                       if(  (ctrlkey==0) && (state==HIGHLIGHTED) )
-            {
-                UnSelectBlackBoxes();
-            }
-        }
 
+                       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
 
-        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
+               } // if _selectedObjects.size
 
-printf("EED wxVtkSceneManager::OnLeftButtonDown  2 \n" );
 
                return true;
        }
@@ -905,8 +892,7 @@ printf("EED wxVtkSceneManager::OnLeftButtonDown  2 \n" );
        }
 
        //=========================================================================
-
-       bool wxVtkSceneManager::OnRightButtonUp()
+       void wxVtkSceneManager::CancelConnection()
        {
                if(_worldState==INIT_CREATION_CONTOUR)
                {
@@ -925,21 +911,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 +957,7 @@ printf("EED wxVtkSceneManager::OnLeftButtonDown  2 \n" );
     }
 
        //=========================================================================
-       bool wxVtkSceneManager::UnSelectBlackBoxes()
+       void wxVtkSceneManager::UnSelectBlackBoxes()
        {
         for (int i=0; i< (int)_selectedObjects.size(); i++)
                {
@@ -1277,6 +1262,28 @@ printf("EED wxVtkSceneManager::OnLeftButtonDown  2 \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++)
@@ -1363,9 +1370,8 @@ printf("EED wxVtkSceneManager::OnLeftButtonDown  2 \n" );
 
        //=========================================================================
 
-       std::string wxVtkSceneManager::saveComplexBoxBBS(std::string cbName,std::string cbAuthor,std::string cbCategory,std::string cbDescription)
+       std::string wxVtkSceneManager::saveComplexBoxBBS()
        {
-
                std::vector<std::string> packages;
                std::vector<int> boxes;
                std::vector<int> connections;
@@ -1422,21 +1428,28 @@ printf("EED wxVtkSceneManager::OnLeftButtonDown  2 \n" );
                }
                script+="\n";
 
+
                // Definition of a complex box
                script+="define ";
-               script+=cbName;
+               script+=_cbName+" "+_cbPackageName;
                script+="\n";
                script+="\n";
 
-               script+="author \" ";
-               script+=cbAuthor;
+               script+="author \"";
+               script+=_Author;
                script+="\"\n";
 
-               script+="description \" ";
-               script+=cbDescription;
+               script+="description \"";
+               script+=_Description;
                script+="\"\n";
                script+="\n";
 
+               script+="category \"";
+               script+=_Category;
+               script+="\"\n";
+               script+="\n";
+
+
                // Create boxes
                for(i = 0; i<(int)boxes.size();i++)
                {
@@ -1613,11 +1626,32 @@ printf("EED wxVtkSceneManager::OnLeftButtonDown  2 \n" );
        {
                char buffer [50];
 
+        content+="CATEGORY:";
+        content+=GetCategory();
+        content+="\n";
+
+        content+="DESCRIPTION:";
+        content+=GetDescription();
+        content+="\n";
+
+        content+="AUTHOR:";
+        content+=GetAuthor();
+        content+="\n";
+
+
                //Print info IF COMPLEX BOX
                content+="COMPLEXBOX:";
                if(_isComplexBox)
                {
                        content+="TRUE\n";
+//ups1
+                       content+="COMPLEXBOXNAME:";
+            content+=GetCbName();
+                       content+="\n";
+
+                       content+="PACKAGENAME:";
+            content+=GetCbPackageName();
+                       content+="\n";
 
                        //Print info complex input ports
                        std::vector<int> inputs = getComplexInputPorts();
@@ -1691,6 +1725,7 @@ printf("EED wxVtkSceneManager::OnLeftButtonDown  2 \n" );
        void wxVtkSceneManager::loadDiagram(ifstream &inputStream)
        {
 
+               std::string version="<void>";
                std::string line="";
                char delims[] = ":";
                char *result = NULL;
@@ -1702,6 +1737,18 @@ 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);
+                               }
+                               if (line=="# - BBTKGEditor v 1.1 BBG BlackBox Diagram file")
+                               {
+                                       version=line.substr(18,3);
+                               }
+                               if (line=="# - BBTKGEditor v 1.2 BBG BlackBox Diagram file")
+                               {
+                                       version=line.substr(18,3);
+                               }
                        }
                        else if(line=="APP_START")
                        {
@@ -1710,14 +1757,40 @@ printf("EED wxVtkSceneManager::OnLeftButtonDown  2 \n" );
                        }
                }
 
+        printf("EED wxVtkSceneManager::loadDiagram  version=%s\n",version.c_str());
+
                if(start)
                {
 
+            if ((version!="1.0") && (version!="1.1"))
+            {
+                               getline(inputStream,line);//CATEGORY:<category of the box>
+                char categoryTmp[30];
+                strcpy( categoryTmp, line.c_str() );
+                result = strtok( categoryTmp, delims );
+                result = strtok( NULL, delims );
+                SetCategory(result);
+
+                               getline(inputStream,line);//DESCRIPTION:<description of the box>
+                char descriptionTmp[1024];
+                strcpy( descriptionTmp, line.c_str() );
+                result = strtok( descriptionTmp, delims );
+                result = strtok( NULL, delims );
+                SetDescription(result);
+
+                               getline(inputStream,line);//AUTHOR:<author>
+                char authorTmp[255];
+                strcpy( authorTmp, line.c_str() );
+                result = strtok( authorTmp, delims );
+                result = strtok( NULL, delims );
+                SetAuthor(result);
+            }
+
                        //----------
                        getline(inputStream,line);//COMPLEX_BOX:TRUE|FALSE
-                       char complex[30];
-                       strcpy( complex, line.c_str() );
-                       result = strtok( complex, delims );
+                       char complexTmp[30];
+                       strcpy( complexTmp, line.c_str() );
+                       result = strtok( complexTmp, delims );
                        result = strtok( NULL, delims );
                        std::string isComplexBox(result);
 
@@ -1725,6 +1798,24 @@ printf("EED wxVtkSceneManager::OnLeftButtonDown  2 \n" );
                        {
                                _isComplexBox=true;
 
+                if ((version!="1.0") && (version!="1.1"))
+                {
+                    getline(inputStream,line);//COMPLEXNAME:<name of the complex box>
+                    char complexboxnameTmp[255];
+                    strcpy( complexboxnameTmp, line.c_str() );
+                    result = strtok( complexboxnameTmp, delims );
+                    result = strtok( NULL, delims );
+                    SetCbName(result);
+
+                    getline(inputStream,line);//PACKAGENAME:<name of the package of the box>
+                    char packagenameTmp[255];
+                    strcpy( packagenameTmp, line.c_str() );
+                    result = strtok( packagenameTmp, delims );
+                    result = strtok( NULL, delims );
+                    SetCbPackageName(result);
+                }
+
+
                                //-----------------------
                                //- COMPLEX INPUT PORTS
                                //-----------------------
@@ -1953,11 +2044,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 +2162,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 +2182,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 +2192,7 @@ printf("EED wxVtkSceneManager::OnLeftButtonDown  2 \n" );
                tempp->endContourCreation();
                conMod->setEndPort(endP);
                conView->updateStartEndPoints();
+               return idCon;
        }
 
        //=========================================================================
@@ -2402,7 +2534,94 @@ printf("EED wxVtkSceneManager::OnLeftButtonDown  2 \n" );
 
        }
 
+
+       //=========================================================================
+    void wxVtkSceneManager::SetCbName(std::string cbName)
+    {
+        _cbName=cbName;
+        if (_cbName=="")
+        {
+            _cbName="<complex box name>";
+        }
+    }
+
+       //=========================================================================
+    std::string wxVtkSceneManager::GetCbName()
+    {
+        return _cbName;
+    }
+
+       //=========================================================================
+    void wxVtkSceneManager::SetCbPackageName(std::string packagename)
+    {
+        _cbPackageName=packagename;
+        if (_cbPackageName=="")
+        {
+            _cbPackageName="<package name of the complex box>";
+        }
+    }
+
+       //=========================================================================
+    std::string wxVtkSceneManager::GetCbPackageName()
+    {
+        return _cbPackageName;
+    }
+
        //=========================================================================
+    void wxVtkSceneManager::SetAuthor(std::string author)
+    {
+        _Author=author;
+        if (_Author=="")
+        {
+            _Author="<author of the box>";
+        }
+    }
+
+       //=========================================================================
+    std::string wxVtkSceneManager::GetAuthor()
+    {
+        return _Author;
+    }
+
+       //=========================================================================
+    void wxVtkSceneManager::SetCategory(std::string category)
+    {
+        _Category=category;
+        if (_Category=="")
+        {
+            _Category="<category of the box>";
+        }
+    }
+
+       //=========================================================================
+    std::string wxVtkSceneManager::GetCategory()
+    {
+        return _Category;
+    }
+
+       //=========================================================================
+    void wxVtkSceneManager::SetDescription(std::string description)
+    {
+        _Description=description;
+        if (_Description=="")
+        {
+            _Description="<description of the box>";
+        }
+    }
+
+       //=========================================================================
+    std::string wxVtkSceneManager::GetDescription()
+    {
+        return _Description;
+    }
+
+       //=========================================================================
+
+
+
+
+
+
 
 }  // EO namespace bbtk