]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
To improve selection management -
authorapo <apo@opencascade.com>
Mon, 17 Oct 2005 06:15:06 +0000 (06:15 +0000)
committerapo <apo@opencascade.com>
Mon, 17 Oct 2005 06:15:06 +0000 (06:15 +0000)
All SALOME_Actor share the same instances of pickers and highlight/prehighlight properties that is stored into SVTK_Renderer

src/SVTK/SVTK_Renderer.cxx
src/SVTK/SVTK_Renderer.h

index 864ce5967e6b9b8406c266117e0249b918992099..6e811822a1af42b26b1e3fd80cfbc2735741035c 100644 (file)
@@ -30,6 +30,7 @@
 
 #include "SVTK_Trihedron.h"
 #include "SVTK_CubeAxesActor2D.h"
+#include "VTKViewer_CellRectPicker.h"
 
 #include "SALOME_Actor.h"
 #include "VTKViewer_Actor.h"
 #include <vtkObjectFactory.h>
 #include <vtkCallbackCommand.h>
 
+#include <vtkPicker.h>
+#include <vtkPointPicker.h>
+#include <vtkCellPicker.h>
+
+#include <vtkProperty.h>
+
 // undefining min and max because CASCADE's defines them and
 // it clashes with std::min(), std::max() included in utilities.h
 #undef min
@@ -64,17 +71,42 @@ SVTK_Renderer
 ::SVTK_Renderer():
   myDevice(vtkRenderer::New()),
   myInteractor(NULL),
+  myPriority(0.0),
+  myEventCallbackCommand(vtkCallbackCommand::New()),
+  myPointPicker(vtkPointPicker::New()),
+  myCellPicker(vtkCellPicker::New()),
+  myCellRectPicker(VTKViewer_CellRectPicker::New()),
+  myPreHighlightProperty(vtkProperty::New()),
+  myHighlightProperty(vtkProperty::New()),
   myTransform(VTKViewer_Transform::New()),
   myCubeAxes(SVTK_CubeAxesActor2D::New()),
   myTrihedron(SVTK_Trihedron::New()),
-  myTrihedronSize(105),
-  myPriority(0.0),
-  myEventCallbackCommand(vtkCallbackCommand::New())
+  myTrihedronSize(105)
 {
   if(MYDEBUG) INFOS("SVTK_Renderer() - "<<this);
 
   myDevice->Delete();
   myTransform->Delete();
+
+  SetSelectionTolerance();
+  myPointPicker->Delete();
+  myCellPicker->Delete();
+  myCellRectPicker->Delete();
+
+  //SetPreselectionProp();
+  myPreHighlightProperty->Delete();
+  myPreHighlightProperty->SetColor(0,1,1);
+  myPreHighlightProperty->SetPointSize(SALOME_POINT_SIZE);
+  myPreHighlightProperty->SetLineWidth(SALOME_LINE_WIDTH);
+  myPreHighlightProperty->SetRepresentationToPoints();
+
+  //SetSelectionProp();
+  myHighlightProperty->Delete();
+  myHighlightProperty->SetColor(1,1,0);
+  myHighlightProperty->SetPointSize(SALOME_POINT_SIZE);
+  myHighlightProperty->SetLineWidth(SALOME_LINE_WIDTH);
+  myHighlightProperty->SetRepresentationToPoints();
+
   myTrihedron->Delete();
   myCubeAxes->Delete();
   myEventCallbackCommand->Delete();
@@ -129,11 +161,7 @@ SVTK_Renderer
   anActors->InitTraversal();
   while(vtkActor* anAct = anActors->GetNextActor()){
     if(SALOME_Actor* anActor = dynamic_cast<SALOME_Actor*>(anAct)){
-      // Order of the calls are important because VTKViewer_Actor::RemoveFromRender
-      //   can leads do destruction of the actor
-      anActor->SetTransform(NULL);
-      anActor->SetInteractor(NULL);
-      anActor->RemoveFromRender(GetDevice());
+      RemoveActor(anActor);
     }
   }
 }
@@ -183,7 +211,16 @@ SVTK_Renderer
 {
   if(SALOME_Actor* anActor = dynamic_cast<SALOME_Actor*>(theActor)){
     anActor->SetInteractor(myInteractor);
+
     anActor->SetTransform(GetTransform());
+
+    anActor->SetPointPicker(myPointPicker.GetPointer());
+    anActor->SetCellPicker(myCellPicker.GetPointer());
+    anActor->SetCellRectPicker(myCellRectPicker.GetPointer());
+
+    anActor->SetPreHighlightProperty(myPreHighlightProperty.GetPointer());
+    anActor->SetHighlightProperty(myHighlightProperty.GetPointer());
+
     anActor->AddToRender(GetDevice());
     AdjustActors();
   }
@@ -194,8 +231,18 @@ SVTK_Renderer
 ::RemoveActor(VTKViewer_Actor* theActor)
 {
   if(SALOME_Actor* anActor = dynamic_cast<SALOME_Actor*>(theActor)){
+    // Order of the calls are important because VTKViewer_Actor::RemoveFromRender
+    //   can leads do destruction of the actor
     anActor->SetInteractor(NULL);
     anActor->SetTransform(NULL);
+
+    anActor->SetPointPicker(NULL);
+    anActor->SetCellPicker(NULL);
+    anActor->SetCellRectPicker(NULL);
+
+    anActor->SetPreHighlightProperty(NULL);
+    anActor->SetHighlightProperty(NULL);
+
     anActor->RemoveFromRender(GetDevice());
     AdjustActors();
   }
@@ -224,6 +271,42 @@ SVTK_Renderer
 }
 
 
+//----------------------------------------------------------------------------
+void
+SVTK_Renderer
+::SetSelectionProp(const double& theRed, 
+                  const double& theGreen, 
+                  const double& theBlue, 
+                  const int& theWidth) 
+{
+  myHighlightProperty->SetColor( theRed, theGreen, theBlue );
+  myHighlightProperty->SetLineWidth( theWidth );
+}
+
+//----------------------------------------------------------------------------
+void
+SVTK_Renderer
+::SetPreselectionProp(const double& theRed, 
+                     const double& theGreen, 
+                     const double& theBlue, 
+                     const int& theWidth) 
+{
+  myPreHighlightProperty->SetColor( theRed, theGreen, theBlue );
+  myPreHighlightProperty->SetLineWidth( theWidth );
+}
+
+//----------------------------------------------------------------------------
+void
+SVTK_Renderer
+::SetSelectionTolerance(const double& theTolNodes, 
+                       const double& theTolCell)
+{
+  myPointPicker->SetTolerance( theTolNodes );
+  myCellPicker->SetTolerance( theTolCell );
+  myCellRectPicker->SetTolerance( theTolCell );
+}
+
+
 //----------------------------------------------------------------------------
 /*! If parameter theIsForcedUpdate is true, recalculate parameters for
  *  trihedron and cube axes, even if trihedron and cube axes is invisible.
index 18186da7c1499bfb3a7f0b6224f16b2ee699f873..0093081dcbc2f68f3fc4f8b894bbfbb3dfb739ed 100644 (file)
@@ -38,6 +38,13 @@ class vtkRenderer;
 class vtkCallbackCommand;
 class vtkRenderWindowInteractor;
 
+class vtkPicker;
+class vtkPointPicker;
+class vtkCellPicker;
+class vtkProperty;
+
+class VTKViewer_CellRectPicker;
+
 class VTKViewer_Trihedron;
 class VTKViewer_Transform;
 class SVTK_CubeAxesActor2D;
@@ -76,6 +83,23 @@ class SVTK_EXPORT SVTK_Renderer : public vtkObject
   void
   GetScale( double theScale[3] );
 
+  //----------------------------------------------------------------------------
+  void
+  SetSelectionProp(const double& theRed = 1, 
+                  const double& theGreen = 1,
+                  const double& theBlue = 0, 
+                  const int& theWidth = 5);
+
+  void
+  SetPreselectionProp(const double& theRed = 0, 
+                     const double& theGreen = 1,
+                     const double& theBlue = 1, 
+                     const int& theWidth = 5);
+
+  void
+  SetSelectionTolerance(const double& theTolNodes = 0.025, 
+                       const double& theTolCell = 0.001);
+
   //----------------------------------------------------------------------------
   void
   AdjustActors();
@@ -132,6 +156,7 @@ class SVTK_EXPORT SVTK_Renderer : public vtkObject
   bool
   OnAdjustActors();
 
+  //----------------------------------------------------------------------------
   // Priority at which events are processed
   float myPriority;
 
@@ -148,7 +173,19 @@ class SVTK_EXPORT SVTK_Renderer : public vtkObject
   vtkSmartPointer<vtkRenderer> myDevice;
   vtkRenderWindowInteractor* myInteractor;
 
+  //----------------------------------------------------------------------------
   vtkSmartPointer<VTKViewer_Transform> myTransform;
+
+  //----------------------------------------------------------------------------
+  // Highlight/ Prehighlight devices
+  vtkSmartPointer<vtkPointPicker> myPointPicker;
+  vtkSmartPointer<vtkCellPicker> myCellPicker;
+  vtkSmartPointer<VTKViewer_CellRectPicker> myCellRectPicker;
+
+  vtkSmartPointer<vtkProperty> myPreHighlightProperty;
+  vtkSmartPointer<vtkProperty> myHighlightProperty;
+
+  //----------------------------------------------------------------------------
   vtkSmartPointer<SVTK_CubeAxesActor2D> myCubeAxes;
   vtkSmartPointer<VTKViewer_Trihedron> myTrihedron;  
   int myTrihedronSize;