]> Creatis software - bbtkGEditor.git/blobdiff - lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxVtkSceneManager.cxx
#3252Select mechanism of boxes
[bbtkGEditor.git] / lib / EditorGraphicBBS / bbsWxGUIEditorGraphic / wxVtkSceneManager.cxx
index e839044db26271bb09997f39b5f2cf223433e148..1d8dc2957e68a4d5a5dbbbba61394369b4d00623 100644 (file)
@@ -110,6 +110,11 @@ wxVtkSceneManager::wxVtkSceneManager(wxGEditorTabPanel *parent, wxVtk3DBaseView
        }
        _idConnectionInCreation = -1;
        _contLastId                             = 0;
+    
+    selectRegionX1          = -1;
+    selectRegionY1          = -1;
+    selectRegionX2          = -1;
+    selectRegionY2          = -1;
 }
 
 //=========================================================================
@@ -251,29 +256,28 @@ std::string wxVtkSceneManager::generateANewNameForABox() {
 
 //=========================================================================
 
-std::string wxVtkSceneManager::findANewNameForABox() {
+std::string wxVtkSceneManager::findANewNameForABox()
+{
        std::string boxname = generateANewNameForABox();
-
-       while (boxExist(boxname) == true) {
+       while (boxExist(boxname) == true)
+    {
                boxname = generateANewNameForABox();
        } // while
-
        return boxname;
 }
 
 //=========================================================================
 void wxVtkSceneManager::configGBlackBox(int idBox, double xIn, double yIn,
                double zIn, std::string name, bool boxExecutable, double xEn,
-               double yEn, double zEn) {
+               double yEn, double zEn)
+{
        GObjectController *cont = _controllers[idBox];
        GBlackBoxModel *bbmod = (GBlackBoxModel*) cont->getModel();
        bbmod->setBBTKName(name);
        bbmod->setInicPoint(xIn, yIn, zIn);
        bbmod->setFinalPoint(xEn, yEn, zEn);
        bbmod->setExecutable(boxExecutable);
-
        bbmod->notifyObservers(_idManager);
-
 }
 
 //=========================================================================
@@ -831,16 +835,19 @@ bool wxVtkSceneManager::OnMouseMove()
 {
        int X, Y;
        bool okStatusMessage    = false;
-       bool okPortMessage      = false;
+       bool okPortMessage          = false;
        crea::wxVTKRenderWindowInteractor *wxVTKiren;
        wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
        wxVTKiren->GetEventPosition(X, Y);
 
-       if (_worldState == DRAG_OBJECTS) {
-               for (int i = 0; i < (int) _selectedObjects.size(); i++) {
+       if (_worldState == DRAG_OBJECTS)
+    {
+               for (int i = 0; i < (int) _selectedObjects.size(); i++)
+        {
                        int id = _selectedObjects[i];
                        GObjectController* cont = _controllers[id];
-                       if (_startDragging) {
+                       if (_startDragging)
+            {
                                cont->getView()->setStartDragging(true);
                        }
                        cont->getView()->moveObject(X, Y);
@@ -850,20 +857,23 @@ bool wxVtkSceneManager::OnMouseMove()
 
                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;
-                       if (desc->getGObjectType() == GCONNECTOR) {
+                       if (desc->getGObjectType() == GCONNECTOR)
+            {
                                vtkGConnectorView* vconn = (vtkGConnectorView*) desc->getView();
                                vconn->updateStartEndPoints();
-                       }
-               }
+                       } // if
+               } // for
 
                _startDragging = false;
 
        } else if (_worldState == NOTHING_HAPPENS || _worldState == INIT_CREATION_CONTOUR) {
                std::map<int, GObjectController*>::iterator it;
                double px, py, pz;
-               for (it = _controllers.begin(); it != _controllers.end(); ++it) {
+               for (it = _controllers.begin(); it != _controllers.end(); ++it)
+        {
                        GObjectController *desc = it->second;
                        int type        = desc->getGObjectType();
                        int state       = desc->getView()->getState();
@@ -912,12 +922,55 @@ bool wxVtkSceneManager::OnMouseMove()
                                                _bugTextActor_status= 2;
                                        } //  _bugTextActor_tex
                                        _bugTextActor_text                  = desc->getStatusText();
-
                                } // if GPORT
-                       }  //if state
+            } // if  state
                } // for controllers it
-       }
-       if (okStatusMessage == false) 
+    } else if (_worldState == SELECTING_BOXES ) {
+
+
+        int sX1,sX2,sY1,sY2;
+        if (X<selectRegionX1)
+        {
+            sX1=X; sX2=selectRegionX1;
+        } else {
+            sX1=selectRegionX1; sX2=X;
+        }
+
+        if (Y<selectRegionY1)
+        {
+            sY1=Y; sY2=selectRegionY1;
+        } else {
+            sY1=selectRegionY1; sY2=Y;
+        }
+
+        UnSelectBlackBoxes();
+        
+        std::map<int, GObjectController*>::iterator it;
+        GObjectController                           *desc;
+        int                                         type;
+        int                                         state;
+        int                                         id;
+        for (it = _controllers.begin(); it != _controllers.end(); ++it)
+        {
+            desc    = it->second;
+            type    = desc->getGObjectType();
+            state   = desc->getView()->getState();
+            
+            if ( (type==GBLACKBOX) || (type==GCOMPLEXINPUTPORT) || (type==GCOMPLEXOUTPUTPORT) )
+            {
+                if ( desc->getView()->isBoxInsideRectangle( sX1 , sY1,sX2 , sY2 ) )
+                {
+                    desc->getView()->setState(SELECTED);
+                    id = desc->getModel()->getObjectId();
+                    desc->getModel()->notifyObservers( id , ADD_TO_SELECTED );
+                }
+            } // if type == 1
+        } // for
+        
+        
+    } //  if _worldState
+    
+       if (okStatusMessage == false)
        {
                updateStatusBar("");
        }
@@ -961,42 +1014,49 @@ bool wxVtkSceneManager::OnLeftButtonDown()
 
                        } // if
                } // for
-
                if (isOverPort == false) 
                {
                        CancelConnection();
                        UnSelectBlackBoxes();
                } // isOverPort
-       
-
        } else { //_worldState
-
-               _worldState             = DRAG_OBJECTS;
-               _startDragging  = true;
-
-               int shiftkey    = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey();
-               int ctrlkey             = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
-               ctrlkey                 = ctrlkey + shiftkey;
-
-               GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
-
-               if (cont != NULL) {
+               _startDragging          = true;
+               int shiftkey            = _vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey();
+               int ctrlkey                     = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
+               ctrlkey                         = ctrlkey + shiftkey;
+               GObjectController *cont = GetGBoxControlerPointedByMouse();
+               if (cont != NULL)
+        {
+            _worldState        = DRAG_OBJECTS;
                        int state = cont->getView()->getState();
-                       if ((ctrlkey == 0) && (state == HIGHLIGHTED)) {
+                       if ((ctrlkey == 0) && (state == HIGHLIGHTED))
+            {
                                UnSelectBlackBoxes();
-                       }
+                       } // if ctrlkey state
                } else {
                        UnSelectBlackBoxes();  // EED 12/07/2012
-               }
-               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
-
+            _worldState        = SELECTING_BOXES;
+               } // if cont
+        
+        if (_worldState==SELECTING_BOXES)
+        {
+            crea::wxVTKRenderWindowInteractor *wxVTKiren;
+            wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
+            wxVTKiren->GetEventPosition(selectRegionX1, selectRegionY1);
+        } // if _worldState SELECTING_BOXES
+        
+        if (_worldState==DRAG_OBJECTS)
+        {
+            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  _worldState DRAG_OBJECTS
 
+       } // if _selectedObjects.size
        return true;
 }
 
@@ -1004,10 +1064,11 @@ bool wxVtkSceneManager::OnLeftButtonDown()
 
 bool wxVtkSceneManager::OnLeftButtonUp() 
 {
-       if (_worldState == DRAG_OBJECTS) {
+       if ( (_worldState == DRAG_OBJECTS) || (_worldState == SELECTING_BOXES) )
+    {
                _worldState = NOTHING_HAPPENS;
-
-               for (int i = 0; i < (int) _selectedObjects.size(); i++) {
+               for (int i = 0; i < (int) _selectedObjects.size(); i++)
+        {
                        int id = _selectedObjects[i];
                        GObjectController* cont = _controllers[id];
                        cont->getView()->setState(SELECTED);
@@ -1043,7 +1104,6 @@ void wxVtkSceneManager::CancelConnection()
 }
 
 //=========================================================================
-
 bool wxVtkSceneManager::OnRightButtonUp() 
 {
        if (_worldState == INIT_CREATION_CONTOUR) 
@@ -1055,43 +1115,37 @@ bool wxVtkSceneManager::OnRightButtonUp()
 }
 
  ///JLGR 21-05-2012
-
-bool wxVtkSceneManager::OnMiddleButtonDown() {
-
-
+//=========================================================================
+bool wxVtkSceneManager::OnMiddleButtonDown()
+{
         this->_vtkInteractorStyleBaseView->StartPan();
-
         return true;
-    }
-
-bool wxVtkSceneManager::OnMiddleButtonUp() {
-
+}
 
+//=========================================================================
+bool wxVtkSceneManager::OnMiddleButtonUp()
+{
         this->_vtkInteractorStyleBaseView->EndPan();
-
-
         return true;
-    }
-
+}
 
 //=========================================================================
-
-GObjectController *wxVtkSceneManager::GetGBlackBoxControlerPointedByMouse() {
+GObjectController *wxVtkSceneManager::GetGBoxControlerPointedByMouse()
+{
        GObjectController *result = NULL;
        int X, Y;
        crea::wxVTKRenderWindowInteractor *wxVTKiren;
-       wxVTKiren
-                       = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
+       wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
        wxVTKiren->GetEventPosition(X, Y);
-
        std::map<int, GObjectController*>::iterator it;
-
-       for (it = _controllers.begin(); it != _controllers.end(); ++it) {
+       for (it = _controllers.begin(); it != _controllers.end(); ++it)
+    {
                GObjectController *cont = it->second;
                int type = cont->getGObjectType();
-
-               if (cont->getView()->isPointInside(X, Y) == true) {
-                       if (type == GBLACKBOX) {
+               if (cont->getView()->isPointInside(X, Y) == true)
+        {
+                       if ( (type == GBLACKBOX) ||  (type == GCOMPLEXINPUTPORT) || (type == GCOMPLEXOUTPUTPORT))
+            {
                                result = cont;
                        } // if type
                } // if isPointInside
@@ -1100,8 +1154,10 @@ GObjectController *wxVtkSceneManager::GetGBlackBoxControlerPointedByMouse() {
 }
 
 //=========================================================================
-void wxVtkSceneManager::UnSelectBlackBoxes() {
-       for (int i = 0; i < (int) _selectedObjects.size(); i++) {
+void wxVtkSceneManager::UnSelectBlackBoxes()
+{
+       for (int i = 0; i < (int) _selectedObjects.size(); i++)
+    {
                int id = _selectedObjects[i];
                GObjectController* control = _controllers[id];
                control->getView()->setState(NOTHING_HAPPENS);
@@ -1111,41 +1167,40 @@ void wxVtkSceneManager::UnSelectBlackBoxes() {
 }
 
 //=========================================================================
-bool wxVtkSceneManager::OnLeftDClick() {
-       GObjectController *cont = GetGBlackBoxControlerPointedByMouse();
-       if (cont != NULL) {
-               UnSelectBlackBoxes();
-               _parent->editBlackBox((GBlackBoxModel*) cont->getModel());
-       }
+bool wxVtkSceneManager::OnLeftDClick()
+{
+       GObjectController *cont = GetGBoxControlerPointedByMouse();
+       if (cont != NULL)
+    {
+        int type    = cont->getGObjectType();
+        if (type==GBLACKBOX)
+        {
+            UnSelectBlackBoxes();
+            _parent->editBlackBox((GBlackBoxModel*) cont->getModel());
+        } // if type
+       } // if cont
        return true;
 }
 
 //=========================================================================
-
 bool wxVtkSceneManager::OnChar() 
 {
        bool ok=false;
        bool oktmp;
        char keyCode    = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
-       int ctrlkey             = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
-        
+       int  ctrlkey            = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
        // KeyCode 127 : Delete Key
        // KeyCode 8 : Backspace Key
-
-
        if (keyCode == 8 || keyCode == 127 || keyCode == 27) 
        {
                if (_worldState == INIT_CREATION_CONTOUR) 
                {
                        CancelConnection();
-                       UnSelectBlackBoxes();
-               }
+            UnSelectBlackBoxes();
+               } // if _worldState
        }
-
-
        if (keyCode == 8 || keyCode == 127) 
        {
-
                        for (int i = 0; i < (int) _selectedObjects.size(); i++) 
                        {
                                int id = _selectedObjects[i];
@@ -1160,7 +1215,6 @@ bool wxVtkSceneManager::OnChar()
                        if (ok) _selectedObjects.clear();
                        _parent->saveTempandUpdate("delete object");
        }// if keyCode
-       
        // Duplicate
        ctrlkey+=keyCode;
        if(ctrlkey==5){                
@@ -1174,28 +1228,26 @@ bool wxVtkSceneManager::OnChar()
                }else{
                        std::cout<<"No objects to copy\n";
                } // _selectedObjects.size
-       } // ctrlkey 5  
-
+       } // ctrlkey 5
        return true;
 }
 
 //=========================================================================
-
-void wxVtkSceneManager::AddControlerToBeRemove(
-               std::vector<int> *controllersToRemove, int id) {
-
+void wxVtkSceneManager::AddControlerToBeRemove( std::vector<int> *controllersToRemove, int id)
+{
        int i;
        bool ok = true;
-       for (i = 0; i < (int) controllersToRemove->size(); i++) {
-               if (id == (*controllersToRemove)[i]) {
+       for (i = 0; i < (int) controllersToRemove->size(); i++)
+    {
+               if (id == (*controllersToRemove)[i])
+        {
                        ok = false;
-               }
-       }
-
-       if (ok == true) {
+               } // if  id
+       } //  for i
+       if (ok == true)
+    {
                controllersToRemove->push_back(id);
-       }
-
+       } //if ok
 }
 
 //=========================================================================