From: apo Date: Mon, 17 Oct 2005 06:15:06 +0000 (+0000) Subject: To improve selection management - X-Git-Tag: TG-D5-38-2003_D2005-29-12~64 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=1d3ec6cd979552fc08af45de3ab158b618b62d28;p=modules%2Fgui.git To improve selection management - All SALOME_Actor share the same instances of pickers and highlight/prehighlight properties that is stored into SVTK_Renderer --- diff --git a/src/SVTK/SVTK_Renderer.cxx b/src/SVTK/SVTK_Renderer.cxx index 864ce5967..6e811822a 100644 --- a/src/SVTK/SVTK_Renderer.cxx +++ b/src/SVTK/SVTK_Renderer.cxx @@ -30,6 +30,7 @@ #include "SVTK_Trihedron.h" #include "SVTK_CubeAxesActor2D.h" +#include "VTKViewer_CellRectPicker.h" #include "SALOME_Actor.h" #include "VTKViewer_Actor.h" @@ -42,6 +43,12 @@ #include #include +#include +#include +#include + +#include + // 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() - "<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(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(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(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. diff --git a/src/SVTK/SVTK_Renderer.h b/src/SVTK/SVTK_Renderer.h index 18186da7c..0093081dc 100644 --- a/src/SVTK/SVTK_Renderer.h +++ b/src/SVTK/SVTK_Renderer.h @@ -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 myDevice; vtkRenderWindowInteractor* myInteractor; + //---------------------------------------------------------------------------- vtkSmartPointer myTransform; + + //---------------------------------------------------------------------------- + // Highlight/ Prehighlight devices + vtkSmartPointer myPointPicker; + vtkSmartPointer myCellPicker; + vtkSmartPointer myCellRectPicker; + + vtkSmartPointer myPreHighlightProperty; + vtkSmartPointer myHighlightProperty; + + //---------------------------------------------------------------------------- vtkSmartPointer myCubeAxes; vtkSmartPointer myTrihedron; int myTrihedronSize;