]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
Fix for Bug NPAL16771 (EDF 556 SMESH : Can't select some groups of nodes in the VTK... MERGE_MULTIPR_EVOLUTION
authormzn <mzn@opencascade.com>
Mon, 17 Sep 2007 10:05:22 +0000 (10:05 +0000)
committermzn <mzn@opencascade.com>
Mon, 17 Sep 2007 10:05:22 +0000 (10:05 +0000)
src/SVTK/SVTK_InteractorStyle.cxx
src/SVTK/SVTK_InteractorStyle.h
src/SVTK/SVTK_Renderer.cxx
src/SVTK/SVTK_Renderer.h
src/SVTK/SVTK_Selector.cxx
src/SVTK/SVTK_Selector.h
src/SVTK/SVTK_SelectorDef.h
src/SVTK/SVTK_View.cxx
src/SVTK/SVTK_View.h
src/SVTK/SVTK_ViewWindow.cxx
src/SVTK/SVTK_ViewWindow.h

index 2746a24e6426b53d51b0ec8e4a87b0874e474f62..37756f98d28de487c0c9f6138fe4ae3ec28203ff 100644 (file)
@@ -48,7 +48,6 @@
 #include <vtkCommand.h>
 #include <vtkCamera.h>
 #include <vtkRenderer.h>
-#include <vtkPicker.h>
 #include <vtkPointPicker.h>
 #include <vtkRenderWindow.h>
 #include <vtkRenderWindowInteractor.h>
@@ -82,38 +81,18 @@ namespace
     theInteractor->GetEventPosition(theX,theY);
     theY = theInteractor->GetSize()[1] - theY - 1;
   }
-
-  //==================================================================
-  // function : GetFirstSALOMEActor
-  // purpose  :
-  //==================================================================
-  struct THaveIO
-  {
-    bool
-    operator()(SALOME_Actor* theActor)
-    {
-      return theActor->hasIO();
-    }
-  };
-
-  inline
-  SALOME_Actor* 
-  GetFirstSALOMEActor(vtkPicker *thePicker)
-  {
-    return VTK::Find<SALOME_Actor>(thePicker->GetActors(),THaveIO());
-  }
 }
 
 
 vtkStandardNewMacro(SVTK_InteractorStyle);
 
+
 /*!
   Constructor
 */
 SVTK_InteractorStyle
 ::SVTK_InteractorStyle():
   mySelectionEvent(new SVTK_SelectionEvent()),
-  myPicker(vtkPicker::New()),
   myPointPicker(vtkPointPicker::New()),
   myLastHighlitedActor(NULL),
   myLastPreHighlitedActor(NULL),
@@ -121,7 +100,6 @@ SVTK_InteractorStyle
   myControllerOnKeyDown(SVTK_ControllerOnKeyDown::New()),
   myHighlightRotationPointActor(SVTK_Actor::New())
 {
-  myPicker->Delete();
   myPointPicker->Delete();
 
   myPointPicker->SetTolerance(0.025);
@@ -515,11 +493,10 @@ SVTK_InteractorStyle
     else if ( myCurrRotationPointType == SVTK::StartPointSelection )
     {
       SVTK_SelectionEvent* aSelectionEvent = GetSelectionEventFlipY();
-      myPicker->Pick(aSelectionEvent->myX, 
-                    aSelectionEvent->myY, 
-                    0.0, 
-                    GetCurrentRenderer());
-      if ( SALOME_Actor* anActor = GetFirstSALOMEActor(myPicker.GetPointer()) )
+
+      SALOME_Actor* anActor = GetSelector()->Pick(aSelectionEvent, GetCurrentRenderer());
+      
+      if ( anActor )
       {
        myPointPicker->Pick( aSelectionEvent->myX,
                             aSelectionEvent->myY, 
@@ -1097,12 +1074,8 @@ SVTK_InteractorStyle
            this->FindPokedRenderer(aSelectionEvent->myX, aSelectionEvent->myY);
            Interactor->StartPickCallback();
            
-           myPicker->Pick(aSelectionEvent->myX, 
-                          aSelectionEvent->myY, 
-                          0.0, 
-                          GetCurrentRenderer());
-           //
-           SALOME_Actor* anActor = GetFirstSALOMEActor(myPicker.GetPointer());
+           SALOME_Actor* anActor = GetSelector()->Pick(aSelectionEvent, GetCurrentRenderer());
+           
            aSelectionEvent->myIsRectangle = false;
 
            if(!myShiftState)
@@ -1239,13 +1212,8 @@ SVTK_InteractorStyle
 
   bool anIsChanged = false;
 
-  myPicker->Pick(aSelectionEvent->myX, 
-                aSelectionEvent->myY, 
-                0.0, 
-                GetCurrentRenderer());
+  SALOME_Actor *anActor = GetSelector()->Pick(aSelectionEvent, GetCurrentRenderer());
   
-  SALOME_Actor *anActor = GetFirstSALOMEActor(myPicker.GetPointer());
-
   if ( myCurrRotationPointType == SVTK::StartPointSelection )
   {
     myHighlightRotationPointActor->SetVisibility( false );
index dec8c0a0db4e2aad479f2c9302feb33fb858ac8a..3ce8ba2f43e643da3b66a973f20f3e03b892265c 100644 (file)
@@ -104,7 +104,6 @@ class SVTK_EXPORT SVTK_ControllerOnKeyDown : public vtkObject{
 };
 
 class vtkCell;
-class vtkPicker;
 class vtkPointPicker;
 
 class SALOME_Actor;
@@ -329,8 +328,6 @@ class SVTK_EXPORT SVTK_InteractorStyle: public vtkInteractorStyle
 
   PSelectionEvent mySelectionEvent;
 
-  vtkSmartPointer<vtkPicker> myPicker;
-
   unsigned long                   myCurrRotationPointType;
   unsigned long                   myPrevRotationPointType;
 
index 9dd784fb10c1c74c68ee93032bb5168b51e21316..cab5ca695e67649dce67d9cff6276d5d3f4bd29f 100644 (file)
@@ -81,8 +81,6 @@ SVTK_Renderer
   myDevice->Delete();
   myTransform->Delete();
 
-  SetSelectionTolerance();
-
   myPointPicker->Delete();
   myCellPicker->Delete();
 
@@ -225,6 +223,7 @@ SVTK_Renderer
 {
   myInteractor = theInteractor;
   mySelector = theSelector;
+  SetSelectionTolerance();
 }
 
 /*!
@@ -348,13 +347,16 @@ SVTK_Renderer
 void
 SVTK_Renderer
 ::SetSelectionTolerance(const double& theTolNodes, 
-                       const double& theTolCell)
+                       const double& theTolCell,
+                       const double& theTolObjects)
 {
   myPointPicker->SetTolerance( theTolNodes );
   myCellPicker->SetTolerance( theTolCell );
 
   myPointRectPicker->SetTolerance( theTolNodes );
   myCellRectPicker->SetTolerance( theTolCell );
+
+  mySelector->SetTolerance( theTolObjects );
 }
 
 
index 3e44d5fe4d5f779fec6b3b8d6a2da2c5e0c84188..5c24cefa13b315a4a25202a2deaa174d9bd751c5 100644 (file)
@@ -122,7 +122,8 @@ class SVTK_EXPORT SVTK_Renderer : public vtkObject
   //! Setup requested tolerance for the picking
   void
   SetSelectionTolerance(const double& theTolNodes = 0.025, 
-                       const double& theTolCell = 0.001);
+                       const double& theTolCell = 0.001,
+                       const double& theTolObjects = 0.025);
 
   //----------------------------------------------------------------------------
   //! Adjust all intenal actors (trihedron and graduated rules) to the scene
index d93bd4b448f7e24a1786cf20dd21bc01bdb6338f..db6474a2a1fb9f9b612cbee23a1135d075cf1e5c 100644 (file)
 #include <TColStd_IndexedMapOfInteger.hxx>
 
 #include <vtkCallbackCommand.h>
+#include <vtkActorCollection.h>
+#include <vtkCellPicker.h>
+
+
+/*!
+  Find first SALOME_Actor from the end of actors collection
+*/
+inline
+SALOME_Actor* 
+GetFirstSALOMEActor(vtkActorCollection* theCollection)
+{
+  if (theCollection) {
+    for (int i = theCollection->GetNumberOfItems() - 1; i >= 0; i--) {
+      SALOME_Actor* anActor = dynamic_cast<SALOME_Actor*>(theCollection->GetItemAsObject(i));
+      if (anActor)
+       return anActor;
+    }
+  }
+  return NULL;
+}
+
 
 /*!
   \return new SVTK_Selector
@@ -50,9 +71,14 @@ SVTK_Selector
   Default constructor
 */
 SVTK_SelectorDef
-::SVTK_SelectorDef()
+::SVTK_SelectorDef():
+  myPicker(vtkPicker::New()),
+  myCellPicker(vtkCellPicker::New())
 {
   mySelectionMode = ActorSelection;
+
+  myPicker->Delete();
+  myCellPicker->Delete();
 }
 
 /*!
@@ -515,3 +541,34 @@ SVTK_SelectorDef
   return Handle(VTKViewer_Filter)();
 }
 
+SALOME_Actor*
+SVTK_SelectorDef
+::Pick(const SVTK_SelectionEvent* theEvent, vtkRenderer* theRenderer) const
+{
+  myCellPicker->Pick(theEvent->myX,
+                    theEvent->myY, 
+                    0.0,
+                    theRenderer);
+  
+  vtkActorCollection* aListActors = myCellPicker->GetActors();
+  SALOME_Actor* anActor = GetFirstSALOMEActor(aListActors);
+  
+  if (! anActor) {
+    myPicker->Pick(theEvent->myX,
+                  theEvent->myY, 
+                  0.0,
+                  theRenderer);
+    aListActors = myPicker->GetActors();
+    anActor = GetFirstSALOMEActor(aListActors);
+  }
+  
+  return anActor;
+}
+
+void
+SVTK_SelectorDef
+::SetTolerance(const double& theTolerance) 
+{
+  myPicker->SetTolerance(theTolerance);        
+  myCellPicker->SetTolerance(theTolerance);
+}
index 380e28b31ef2e37ccc9a0265d2be8c0499480c6b..f72ba8adc042bf24618eba25dad43bf51d8afb14 100644 (file)
 
 class SALOME_Actor;
 
+class SVTK_SelectionEvent;
+
+class vtkRenderer;
+
+
 //! Define an abstract interface for selection in SVTK package
 /*!
   The class implements selection functionality through storing corresponding
@@ -205,6 +210,15 @@ public:
   virtual
   void 
   EndPickCallback() = 0;
+
+  //----------------------------------------------------------------------------
+  virtual
+  SALOME_Actor*
+  Pick(const SVTK_SelectionEvent* theEvent, vtkRenderer* theRenderer) const =0;
+
+  virtual
+  void
+  SetTolerance(const double& theTolerance) = 0;
 };
 
 
index e20d764ec73c54b1b358f83c8dfd02b5b6a08e6d..634d7297bf2a62b4539877823a9c41317038b920 100644 (file)
@@ -43,6 +43,9 @@ class SALOME_Actor;
 class SVTK_Viewer;
 class SVTK_ViewWindow;
 
+class vtkPicker;
+class vtkCellPicker;
+
 class SVTK_SelectorDef: public SVTK_Selector
 {
 public:
@@ -165,6 +168,15 @@ public:
   void 
   EndPickCallback();
 
+  //----------------------------------------------------------------------------
+  virtual
+  SALOME_Actor*
+  Pick(const SVTK_SelectionEvent* theEvent, vtkRenderer* theRenderer) const;
+
+  virtual
+  void
+  SetTolerance(const double& theTolerance);
+
 private:
   int mySelectionMode;
 
@@ -206,6 +218,9 @@ private:
 
   typedef std::map<TFilterID,Handle(VTKViewer_Filter)> TFilters;
   TFilters myFilters;
+
+  vtkSmartPointer<vtkPicker> myPicker;
+  vtkSmartPointer<vtkCellPicker> myCellPicker;
 };
 
 #endif
index 882728b3ae045ff48e015db26c9a877847ad01cf..34ea473009411a804fdadbc7a1182fefdd093e58 100644 (file)
@@ -259,9 +259,10 @@ SVTK_View
 void
 SVTK_View
 ::SetSelectionTolerance(const double& theTolNodes, 
-                       const double& theTolCell)
+                       const double& theTolCell,
+                       const double& theTolObjects)
 {
-  GetRenderer()->SetSelectionTolerance(theTolNodes,theTolCell);
+  GetRenderer()->SetSelectionTolerance(theTolNodes,theTolCell, theTolObjects);
 }
 
 /*!
index 4c25de9bcead69118b2ec683f2c0e43b6774733a..c7cc984b9aa39ed24b0579882fe1c2ce24b5ef87 100644 (file)
@@ -251,7 +251,8 @@ public:
   //! Redirect the request to #SVTK_Renderer::SetPreselectionProp
   void
   SetSelectionTolerance(const double& theTolNodes = 0.025, 
-                       const double& theTolCell = 0.001);
+                       const double& theTolCell = 0.001,
+                       const double& theTolObjects = 0.025);
 
  protected:  
   int myDisplayMode;
index 667f406c3ab04473b12ad1fd5d5a5f285ef5e465..af9841baac310e18c9aa5ecb3f50837163f71698 100755 (executable)
@@ -758,9 +758,10 @@ SVTK_ViewWindow
 void
 SVTK_ViewWindow
 ::SetSelectionTolerance(const double& theTolNodes, 
-                       const double& theTolItems)
+                       const double& theTolItems,
+                       const double& theTolObjects)
 {
-  myView->SetSelectionTolerance(theTolNodes,theTolItems);
+  myView->SetSelectionTolerance(theTolNodes,theTolItems, theTolObjects);
 }
 
 /*!
index 809168505d1be23beb2d4d12669bb44765f6629f..14b79945bd7afa26e1a8241fff25d856c8c20a3a 100755 (executable)
@@ -249,7 +249,8 @@ class SVTK_EXPORT SVTK_ViewWindow : public SUIT_ViewWindow
   virtual
   void
   SetSelectionTolerance(const double& theTolNodes = 0.025, 
-                       const double& theTolCell = 0.001);
+                       const double& theTolCell = 0.001,
+                       const double& theTolObjects = 0.025);
 
   //! Methods to save/restore visual parameters of a view (pan, zoom, etc.)
   virtual