From: mzn Date: Fri, 14 Sep 2007 13:43:59 +0000 (+0000) Subject: Fix for Bug NPAL16771 (EDF 556 SMESH : Can't select some groups of nodes in the VTK... X-Git-Tag: T_24092007~2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=8c37eaba62526b421a1eb71eeb25facf1f50d62c;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 08f0f2134..381f07c46 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,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(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 ); diff --git a/src/SVTK/SVTK_InteractorStyle.h b/src/SVTK/SVTK_InteractorStyle.h index e03f1ca73..643dc8cdd 100644 --- a/src/SVTK/SVTK_InteractorStyle.h +++ b/src/SVTK/SVTK_InteractorStyle.h @@ -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 myPicker; - unsigned long myCurrRotationPointType; unsigned long myPrevRotationPointType; diff --git a/src/SVTK/SVTK_Renderer.cxx b/src/SVTK/SVTK_Renderer.cxx index d3020f1c1..155e419ca 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 6683cf384..7c10b4bb2 100644 --- a/src/SVTK/SVTK_Renderer.h +++ b/src/SVTK/SVTK_Renderer.h @@ -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 diff --git a/src/SVTK/SVTK_Selector.cxx b/src/SVTK/SVTK_Selector.cxx index 78c94989d..a3b0b526d 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(); } /*! @@ -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); +} diff --git a/src/SVTK/SVTK_Selector.h b/src/SVTK/SVTK_Selector.h index 44c1d9690..522f5f58c 100644 --- a/src/SVTK/SVTK_Selector.h +++ b/src/SVTK/SVTK_Selector.h @@ -41,6 +41,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 @@ -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; }; 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 e0c21ddd7..598265048 100755 --- a/src/SVTK/SVTK_ViewWindow.cxx +++ b/src/SVTK/SVTK_ViewWindow.cxx @@ -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 ) diff --git a/src/SVTK/SVTK_ViewWindow.h b/src/SVTK/SVTK_ViewWindow.h index 3031624b8..c636fad3c 100755 --- a/src/SVTK/SVTK_ViewWindow.h +++ b/src/SVTK/SVTK_ViewWindow.h @@ -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