From: mzn Date: Mon, 17 Sep 2007 10:05:22 +0000 (+0000) Subject: Fix for Bug NPAL16771 (EDF 556 SMESH : Can't select some groups of nodes in the VTK... X-Git-Tag: V4_1_0a1~8 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=34c1342b259a6a3a938643a0c7f45a184148739c;p=modules%2Fgui.git Fix for Bug NPAL16771 (EDF 556 SMESH : Can't select some groups of nodes in the VTK view). --- diff --git a/src/SVTK/SVTK_InteractorStyle.cxx b/src/SVTK/SVTK_InteractorStyle.cxx index 2746a24e6..37756f98d 100644 --- a/src/SVTK/SVTK_InteractorStyle.cxx +++ b/src/SVTK/SVTK_InteractorStyle.cxx @@ -48,7 +48,6 @@ #include #include #include -#include #include #include #include @@ -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(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 ); diff --git a/src/SVTK/SVTK_InteractorStyle.h b/src/SVTK/SVTK_InteractorStyle.h index dec8c0a0d..3ce8ba2f4 100644 --- a/src/SVTK/SVTK_InteractorStyle.h +++ b/src/SVTK/SVTK_InteractorStyle.h @@ -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 myPicker; - unsigned long myCurrRotationPointType; unsigned long myPrevRotationPointType; diff --git a/src/SVTK/SVTK_Renderer.cxx b/src/SVTK/SVTK_Renderer.cxx index 9dd784fb1..cab5ca695 100644 --- a/src/SVTK/SVTK_Renderer.cxx +++ b/src/SVTK/SVTK_Renderer.cxx @@ -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 ); } diff --git a/src/SVTK/SVTK_Renderer.h b/src/SVTK/SVTK_Renderer.h index 3e44d5fe4..5c24cefa1 100644 --- a/src/SVTK/SVTK_Renderer.h +++ b/src/SVTK/SVTK_Renderer.h @@ -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 diff --git a/src/SVTK/SVTK_Selector.cxx b/src/SVTK/SVTK_Selector.cxx index d93bd4b44..db6474a2a 100644 --- a/src/SVTK/SVTK_Selector.cxx +++ b/src/SVTK/SVTK_Selector.cxx @@ -35,6 +35,27 @@ #include #include +#include +#include + + +/*! + 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(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); +} diff --git a/src/SVTK/SVTK_Selector.h b/src/SVTK/SVTK_Selector.h index 380e28b31..f72ba8adc 100644 --- a/src/SVTK/SVTK_Selector.h +++ b/src/SVTK/SVTK_Selector.h @@ -42,6 +42,11 @@ 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; }; diff --git a/src/SVTK/SVTK_SelectorDef.h b/src/SVTK/SVTK_SelectorDef.h index e20d764ec..634d7297b 100644 --- a/src/SVTK/SVTK_SelectorDef.h +++ b/src/SVTK/SVTK_SelectorDef.h @@ -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 TFilters; TFilters myFilters; + + vtkSmartPointer myPicker; + vtkSmartPointer myCellPicker; }; #endif diff --git a/src/SVTK/SVTK_View.cxx b/src/SVTK/SVTK_View.cxx index 882728b3a..34ea47300 100644 --- a/src/SVTK/SVTK_View.cxx +++ b/src/SVTK/SVTK_View.cxx @@ -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); } /*! diff --git a/src/SVTK/SVTK_View.h b/src/SVTK/SVTK_View.h index 4c25de9bc..c7cc984b9 100644 --- a/src/SVTK/SVTK_View.h +++ b/src/SVTK/SVTK_View.h @@ -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; diff --git a/src/SVTK/SVTK_ViewWindow.cxx b/src/SVTK/SVTK_ViewWindow.cxx index 667f406c3..af9841baa 100755 --- a/src/SVTK/SVTK_ViewWindow.cxx +++ b/src/SVTK/SVTK_ViewWindow.cxx @@ -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); } /*! diff --git a/src/SVTK/SVTK_ViewWindow.h b/src/SVTK/SVTK_ViewWindow.h index 809168505..14b79945b 100755 --- a/src/SVTK/SVTK_ViewWindow.h +++ b/src/SVTK/SVTK_ViewWindow.h @@ -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