Salome HOME
0021883 [CEA 674] Deactivate pre-selection in OCC and VTK viewer
[modules/gui.git] / src / SVTK / SVTK_ViewModel.cxx
index ce76997151e736c6136bf83b5f7db5fa1b2f6106..4a13dd7ee74f1e95c14e3fff05cf0a308952d6e0 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 #include <vtkActorCollection.h>
 
 //#include "SUIT_Session.h"
-#include "SVTK_Selection.h"
 #include "SVTK_ViewModel.h"
 #include "SVTK_ViewWindow.h"
 #include "SVTK_View.h"
+#include "SVTK_Renderer.h"
 //#include "SVTK_MainWindow.h"
 #include "SVTK_Prs.h"
 
@@ -86,7 +86,8 @@ SVTK_Viewer::SVTK_Viewer()
   myProjMode = 0;
   myStyle = 0;
   myZoomingStyle = 0;
-  myDynamicPreSelection = false;
+  mySelectionEnabled = true;
+  myPreSelectionMode = Standard_Preselection;
   mySpaceBtn[0] = 1;
   mySpaceBtn[1] = 2;
   mySpaceBtn[2] = 9;
@@ -178,7 +179,8 @@ SUIT_ViewWindow* SVTK_Viewer::createView( SUIT_Desktop* theDesktop )
   aViewWindow->SetProjectionMode( projectionMode() );
   aViewWindow->SetInteractionStyle( interactionStyle() );
   aViewWindow->SetZoomingStyle( zoomingStyle() );
-  aViewWindow->SetDynamicPreSelection( dynamicPreSelection() );
+  aViewWindow->SetPreSelectionMode( preSelectionMode() );
+  aViewWindow->SetSelectionEnabled( isSelectionEnabled() );
   aViewWindow->SetIncrementalSpeed( incrementalSpeed(), incrementalSpeedMode() );
   aViewWindow->SetSpacemouseButtons( spacemouseBtn(1), spacemouseBtn(2), spacemouseBtn(3) );
 
@@ -334,27 +336,27 @@ void SVTK_Viewer::setZoomingStyle( const int theStyle )
 }
 
 /*!
-  \return dynamic preselection
+  \return current preselection mode
 */
-bool SVTK_Viewer::dynamicPreSelection() const
+Preselection_Mode SVTK_Viewer::preSelectionMode() const
 {
-  return myDynamicPreSelection;
+  return myPreSelectionMode;
 }
 
 /*!
-  Sets dynamic preselection
-  \param theMode - new dynamic preselection mode
+  Sets preselection mode
+  \param theMode - new preselection mode
 */
-void SVTK_Viewer::setDynamicPreSelection( const bool theMode )
+void SVTK_Viewer::setPreSelectionMode( Preselection_Mode theMode )
 {
-  myDynamicPreSelection = theMode;
+  myPreSelectionMode = theMode;
   
   if (SUIT_ViewManager* aViewManager = getViewManager()) {
     QVector<SUIT_ViewWindow*> aViews = aViewManager->getViews();
     for ( uint i = 0; i < aViews.count(); i++ )
     {
       if ( TViewWindow* aView = dynamic_cast<TViewWindow*>(aViews.at( i )) )
-        aView->SetDynamicPreSelection( theMode );
+        aView->SetPreSelectionMode( theMode );
     }
   }
 }
@@ -493,6 +495,15 @@ void SVTK_Viewer::enableSelection(bool isEnabled)
 {
   mySelectionEnabled = isEnabled;
   //!! To be done for view windows
+   
+  if (SUIT_ViewManager* aViewManager = getViewManager()) {
+    QVector<SUIT_ViewWindow*> aViews = aViewManager->getViews();
+    for ( uint i = 0; i < aViews.count(); i++ )
+    {
+      if ( TViewWindow* aView = dynamic_cast<TViewWindow*>(aViews.at( i )) )
+        aView->SetSelectionEnabled( isEnabled );
+    }
+  }
 }
 
 /*!
@@ -665,9 +676,10 @@ void SVTK_Viewer::EraseAll( const bool forced )
             //Handle(SALOME_InteractiveObject) anObj = anAct->getIO();
             //if(!anObj.IsNull() && anObj->hasEntry() && aStudy)
             //  ToolsGUI::SetVisibility(aStudy,anObj->getEntry(),false,this);
-            if(forced)
-              aRenderer->RemoveActor(anAct);
-            else{
+            if(forced){
+              if(SVTK_Renderer* aRnd = aView->GetRenderer())
+                aRnd->RemoveActor(anAct);
+            }else{
               // just erase actor
               anAct->SetVisibility( false );
               // erase dependent actors