]> 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...
authormzn <mzn@opencascade.com>
Fri, 14 Sep 2007 13:43:59 +0000 (13:43 +0000)
committermzn <mzn@opencascade.com>
Fri, 14 Sep 2007 13:43:59 +0000 (13:43 +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 08f0f213465d76ece71647f7b6fee60e9080d87a..381f07c4606dcc78e27758cfea7a2d6541004a5e 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,26 +81,6 @@ 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());
-  }
 }
 
 
@@ -114,7 +93,6 @@ vtkStandardNewMacro(SVTK_InteractorStyle);
 SVTK_InteractorStyle
 ::SVTK_InteractorStyle():
   mySelectionEvent(new SVTK_SelectionEvent()),
-  myPicker(vtkPicker::New()),
   myPointPicker(vtkPointPicker::New()),
   myLastHighlitedActor(NULL),
   myLastPreHighlitedActor(NULL),
@@ -122,7 +100,6 @@ SVTK_InteractorStyle
   myControllerOnKeyDown(SVTK_ControllerOnKeyDown::New()),
   myHighlightRotationPointActor(SVTK_Actor::New())
 {
-  myPicker->Delete();
   myPointPicker->Delete();
 
   myPointPicker->SetTolerance(0.025);
@@ -516,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 +1073,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)
@@ -1234,13 +1206,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 e03f1ca73dcc7de2b4375dece2fa25ae018eb332..643dc8cddb00f7d16bdea9ed578412b93c4acb7b 100644 (file)
@@ -99,7 +99,6 @@ class SVTK_ControllerOnKeyDown : public vtkObject{
 };
 
 class vtkCell;
-class vtkPicker;
 class vtkPointPicker;
 
 class SALOME_Actor;
@@ -324,8 +323,6 @@ class SVTK_EXPORT SVTK_InteractorStyle: public vtkInteractorStyle
 
   PSelectionEvent mySelectionEvent;
 
-  vtkSmartPointer<vtkPicker> myPicker;
-
   unsigned long                   myCurrRotationPointType;
   unsigned long                   myPrevRotationPointType;
 
index d3020f1c1a03657e55164e121ef585ca51c91b3b..155e419ca4688c2df6c6d5090967f7ae5196da10 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 6683cf384181aeb0ea618394609b279b31f5846d..7c10b4bb26d44b3b35468185b58f519bc7ef2887 100644 (file)
@@ -119,7 +119,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 78c94989d531f51a6a8eb21682456e7e94d828cd..a3b0b526d03be451c4e5f7e64876587cc8737ca6 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();
 }
 
 /*!
@@ -518,3 +544,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 44c1d9690bdac408d5cdad304f59d2d73b75214c..522f5f58c0ab5e0a1b0574c8eb0b49e3aed9d6b9 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
@@ -204,6 +209,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 e0c21ddd7ef9c86357b40902d5791f0c9d9fc6df..598265048a09fb63522c6418c86d98ce6f3ffae1 100755 (executable)
@@ -733,9 +733,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);
 }
 
 int convertAction( const int accelAction )
index 3031624b8077f14b747c1aa78afb1ee09e87654b..c636fad3c875a656471fcf58356337536ba00f08 100755 (executable)
@@ -243,7 +243,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