]> Creatis software - bbtkGEditor.git/blobdiff - lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxVtkSceneManager.cxx
Bug #1682 Crash deleting the actual connection creation
[bbtkGEditor.git] / lib / EditorGraphicBBS / bbsWxGUIEditorGraphic / wxVtkSceneManager.cxx
index 6c8acf0eae3dcbfb045f94839df4cdaa88e42c09..3a411d84aae13f951de908eb7ca225c46b5dfe04 100644 (file)
@@ -507,7 +507,11 @@ GPortController* wxVtkSceneManager::createGPort(int portType,
 
 //=========================================================================
 
-int wxVtkSceneManager::createGConnector(GPortModel* startPort) {
+int wxVtkSceneManager::createGConnector(GPortModel* startPort) 
+{
+       
+               
+
        int type = GCONNECTOR;
 
        manualConnectorContourController        *manContourControl              = new manualConnectorContourController();
@@ -530,6 +534,8 @@ int wxVtkSceneManager::createGConnector(GPortModel* startPort) {
        manContourView->SetColorEditContour(0.5, 0.5, 0.5);
        manContourView->SetColorSelectContour(1, 0.8, 0);
         
+       
+
         /**
          * JGRR AND CM
          * Width increased from 2 to 3, it simplifies line handling and spline control :P
@@ -677,6 +683,7 @@ void wxVtkSceneManager::update(int idController, int command) {
                        // The last one is the controller of the connector
                        std::map<int, GObjectController*>::iterator it2;
 
+
                        for (it2 = _controllers.begin(); it2 != _controllers.end(); ++it2) {
                                GObjectController *cont = it2->second;
                                if (cont->getGObjectType() == GPORT) {
@@ -755,7 +762,8 @@ void wxVtkSceneManager::update(int idController, int command) {
 
 //=========================================================================
 
-bool wxVtkSceneManager::OnMouseMove() {
+bool wxVtkSceneManager::OnMouseMove() 
+{
        int X, Y;
        bool okStatusMessage    = false;
        bool okPortMessage              = false;
@@ -797,16 +805,18 @@ bool wxVtkSceneManager::OnMouseMove() {
                        desc->getModel()->getCenter(px, py, pz);
 
                         // JGRR & CM
-                       if ((state == HIGHLIGHTED) || (state == SELECTED_POSSIBLE_CONNECTION )) {
+                       if ((state == HIGHLIGHTED) || (state == SELECTED_POSSIBLE_CONNECTION )) 
+                       {
                         // EO JGRR & CM    
                                okStatusMessage = true;
                                updateStatusBar(desc->getStatusText());
-                               if (type == GBLACKBOX) {
+                               if (type == GBLACKBOX) 
+                               {
                                        GBlackBoxModel *mod = (GBlackBoxModel*) desc->getModel();
-                                       _parent->displayBlackBoxInfo(mod->getBBTKPackage(),
-                                                       mod->getBBTKType());
+                                       _parent->displayBlackBoxInfo(mod->getBBTKPackage(),mod->getBBTKType());
                                } // if GBLACKBOX
-                               if (type == GPORT) {
+                               if (type == GPORT) 
+                               {
                                        // PortText
                                        okPortMessage = true;
                                        py = py + 5;
@@ -816,7 +826,7 @@ bool wxVtkSceneManager::OnMouseMove() {
 
                                        // FillPortText
                                        px = px - 33;
-                                       py = py;
+                                       //py = py;
                                        _fillObjectActor->SetScale(1);
                                        _fillObjectActor->GetProperty()->SetOpacity(0.50);
                                        _fillObjectActor->SetPosition(px, py, 1);
@@ -826,11 +836,13 @@ bool wxVtkSceneManager::OnMouseMove() {
                        } // for controllers it
                }
        }
-       if (okStatusMessage == false) {
+       if (okStatusMessage == false) 
+       {
                updateStatusBar("");
        }
 
-       if (okPortMessage == false) {
+       if (okPortMessage == false) 
+       {
                _textActor->SetScale(0.0001);
                _fillObjectActor->SetScale(0.0001);
        }
@@ -839,32 +851,35 @@ bool wxVtkSceneManager::OnMouseMove() {
 
 //=========================================================================
 
-bool wxVtkSceneManager::OnLeftButtonDown() {
-
-       if (_worldState == INIT_CREATION_CONTOUR) {
+bool wxVtkSceneManager::OnLeftButtonDown() 
+{
+       if (_worldState == INIT_CREATION_CONTOUR) 
+       {
                bool isOverPort = false;
                std::map<int, GObjectController*>::iterator it;
-               for (it = _controllers.begin(); it != _controllers.end() && isOverPort
-                               == false; ++it) {
+               for (it = _controllers.begin(); it != _controllers.end() && isOverPort== false; ++it) 
+               {
                        GObjectController *desc = it->second;
-                       if (desc->getGObjectType() == GPORT) {
+                       if (desc->getGObjectType() == GPORT) 
+                       {
                                GPortModel *portmod = (GPortModel*) desc->getModel();
                                vtkGObjectView *portView = desc->getView();
-                               if (portmod->getPortType() == GINPUTPORT
-                                               && portView->getState() == HIGHLIGHTED) {
+                               if (portmod->getPortType() == GINPUTPORT && portView->getState() == HIGHLIGHTED) 
+                               {
                                        isOverPort = true;
-                                 } // if
-                                // JGRR & CM                    
-                                if ( portmod->getPortType( ) == GINPUTPORT &&  portView->getState( ) == SELECTED_POSSIBLE_CONNECTION   ) {
-                                    isOverPort = true ;
-                                    portView->setState( HIGHLIGHTED);
-                                }                    
-                                // EO JGRR & CM 
-
-                        } // if
+                               } // if
+                               // JGRR & CM                    
+                               if ( portmod->getPortType( ) == GINPUTPORT &&  portView->getState( ) == SELECTED_POSSIBLE_CONNECTION   ) {
+                                       isOverPort = true ;
+                                       portView->setState( HIGHLIGHTED);
+                               }                    
+                               // EO JGRR & CM 
+
+                       } // if
                } // for
 
-               if (isOverPort == false) {
+               if (isOverPort == false) 
+               {
                        CancelConnection();
                        UnSelectBlackBoxes();
                } // isOverPort
@@ -881,19 +896,20 @@ bool wxVtkSceneManager::OnLeftButtonDown() {
 
                GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
 
-               if (GetGBlackBoxControlerPointedByMouse() != NULL) {
+               if (cont != NULL) {
                        int state = cont->getView()->getState();
                        if ((ctrlkey == 0) && (state == HIGHLIGHTED)) {
                                UnSelectBlackBoxes();
                        }
+               } else {
+                       UnSelectBlackBoxes();  // EED 12/07/2012
                }
                for (int i = 0; i < (int) _selectedObjects.size(); i++) {
                        int id = _selectedObjects[i];
-                       GObjectControllercont = _controllers[id];
+                       GObjectController *cont = _controllers[id];
                        cont->getView()->setState(DRAG);
                        cont->getModel()->notifyObservers(_idManager);
                } // for
-               
        } // if _selectedObjects.size
 
 
@@ -902,7 +918,8 @@ bool wxVtkSceneManager::OnLeftButtonDown() {
 
 //=========================================================================
 
-bool wxVtkSceneManager::OnLeftButtonUp() {
+bool wxVtkSceneManager::OnLeftButtonUp() 
+{
        if (_worldState == DRAG_OBJECTS) {
                _worldState = NOTHING_HAPPENS;
 
@@ -917,8 +934,10 @@ bool wxVtkSceneManager::OnLeftButtonUp() {
 }
 
 //=========================================================================
-void wxVtkSceneManager::CancelConnection() {
-       if (_worldState == INIT_CREATION_CONTOUR) {
+void wxVtkSceneManager::CancelConnection() 
+{
+       if (_worldState == INIT_CREATION_CONTOUR) 
+       {
                _worldState = NOTHING_HAPPENS;
                //int lastId = _controllers.size()-1;
 
@@ -929,7 +948,8 @@ void wxVtkSceneManager::CancelConnection() {
                _controllers.erase(_idConnectionInCreation);
 
                std::map<int, GObjectController*>::iterator it;
-               for (it = _controllers.begin(); it != _controllers.end(); ++it) {
+               for (it = _controllers.begin(); it != _controllers.end(); ++it) 
+               {
                        GObjectController *desc = it->second;
                        desc->SetActive(true);
                        desc->getView()->setState(NOTHING_HAPPENS);
@@ -940,8 +960,10 @@ void wxVtkSceneManager::CancelConnection() {
 
 //=========================================================================
 
-bool wxVtkSceneManager::OnRightButtonUp() {
-       if (_worldState == INIT_CREATION_CONTOUR) {
+bool wxVtkSceneManager::OnRightButtonUp() 
+{
+       if (_worldState == INIT_CREATION_CONTOUR) 
+       {
                CancelConnection();
        }
        UnSelectBlackBoxes();
@@ -1066,8 +1088,21 @@ bool wxVtkSceneManager::OnChar()
         
        // KeyCode 127 : Delete Key
        // KeyCode 8 : Backspace Key
+
+
+       if (keyCode == 8 || keyCode == 127 || keyCode == 27) 
+       {
+               if (_worldState == INIT_CREATION_CONTOUR) 
+               {
+                       CancelConnection();
+                       UnSelectBlackBoxes();
+               }
+       }
+
+
        if (keyCode == 8 || keyCode == 127) 
        {
+
                        for (int i = 0; i < (int) _selectedObjects.size(); i++) 
                        {
                                int id = _selectedObjects[i];
@@ -1092,7 +1127,8 @@ bool wxVtkSceneManager::OnChar()
 #endif
                if(_selectedObjects.size()){
                        std::cout<<"objects to copy :";
-                       for(int i=0;i<_selectedObjects.size();i++){
+                       for(int i=0;i<_selectedObjects.size();i++)
+                       {
                                std::cout<<_selectedObjects.at(i)<<" ";
                        }
                        DuplicateObjects(getSelectedObjects());   
@@ -1740,14 +1776,16 @@ void wxVtkSceneManager::getCleanLine(stringstream &inputStream, std::string &lin
 {
        getline(inputStream, line,'\n');
        int size = line.length();
-       if ( line[ size-1 ]==13  )
+    if (size>0)
        {
-               line.erase(size-1,1);
-       }
+               if ( line[ size-1 ]==13  )
+               {
+                       line.erase(size-1,1);
+               } // if line
+       } // if size
 }
        
 //=========================================================================
-
 void wxVtkSceneManager::loadDiagram(stringstream &inputStream) 
 {
        int size;
@@ -2689,6 +2727,7 @@ std::string wxVtkSceneManager::GetCategory() {
 //=========================================================================
 void wxVtkSceneManager::SetDescription(std::string description) {
        _Description = description;
+       std::cout<<"Description:"<<_Description<<std::endl;
        if (_Description == "") {
                _Description = "<description of the box>";
        }