#include <vtkCommand.h>
#include <vtkCamera.h>
#include <vtkRenderer.h>
-#include <vtkPicker.h>
#include <vtkPointPicker.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
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());
- }
}
vtkStandardNewMacro(SVTK_InteractorStyle);
+
/*!
Constructor
*/
SVTK_InteractorStyle
::SVTK_InteractorStyle():
mySelectionEvent(new SVTK_SelectionEvent()),
- myPicker(vtkPicker::New()),
myPointPicker(vtkPointPicker::New()),
myLastHighlitedActor(NULL),
myLastPreHighlitedActor(NULL),
myControllerOnKeyDown(SVTK_ControllerOnKeyDown::New()),
myHighlightRotationPointActor(SVTK_Actor::New())
{
- myPicker->Delete();
myPointPicker->Delete();
myPointPicker->SetTolerance(0.025);
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,
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)
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 );
};
class vtkCell;
-class vtkPicker;
class vtkPointPicker;
class SALOME_Actor;
PSelectionEvent mySelectionEvent;
- vtkSmartPointer<vtkPicker> myPicker;
-
unsigned long myCurrRotationPointType;
unsigned long myPrevRotationPointType;
myDevice->Delete();
myTransform->Delete();
- SetSelectionTolerance();
-
myPointPicker->Delete();
myCellPicker->Delete();
{
myInteractor = theInteractor;
mySelector = theSelector;
+ SetSelectionTolerance();
}
/*!
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 );
}
//! 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
#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
Default constructor
*/
SVTK_SelectorDef
-::SVTK_SelectorDef()
+::SVTK_SelectorDef():
+ myPicker(vtkPicker::New()),
+ myCellPicker(vtkCellPicker::New())
{
mySelectionMode = ActorSelection;
+
+ myPicker->Delete();
+ myCellPicker->Delete();
}
/*!
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);
+}
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
virtual
void
EndPickCallback() = 0;
+
+ //----------------------------------------------------------------------------
+ virtual
+ SALOME_Actor*
+ Pick(const SVTK_SelectionEvent* theEvent, vtkRenderer* theRenderer) const =0;
+
+ virtual
+ void
+ SetTolerance(const double& theTolerance) = 0;
};
class SVTK_Viewer;
class SVTK_ViewWindow;
+class vtkPicker;
+class vtkCellPicker;
+
class SVTK_SelectorDef: public SVTK_Selector
{
public:
void
EndPickCallback();
+ //----------------------------------------------------------------------------
+ virtual
+ SALOME_Actor*
+ Pick(const SVTK_SelectionEvent* theEvent, vtkRenderer* theRenderer) const;
+
+ virtual
+ void
+ SetTolerance(const double& theTolerance);
+
private:
int mySelectionMode;
typedef std::map<TFilterID,Handle(VTKViewer_Filter)> TFilters;
TFilters myFilters;
+
+ vtkSmartPointer<vtkPicker> myPicker;
+ vtkSmartPointer<vtkCellPicker> myCellPicker;
};
#endif
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);
}
/*!
//! 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;
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);
}
/*!
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