2 // Created by: Roman KOZLOV
3 // Copyright (c) 2011-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef __IVTKTOOLS_SHAPEPICKER_H__
17 #define __IVTKTOOLS_SHAPEPICKER_H__
19 #include <IVtkTools.hxx>
20 #include <IVtk_Types.hxx>
21 #include <IVtkOCC_ShapePickerAlgo.hxx>
22 #include <vtkAbstractPropPicker.h>
23 #include <vtkSmartPointer.h>
26 class vtkActorCollection;
28 //! @class IVtkTools_ShapePicker
29 //! @brief VTK picker for OCC shapes with OCC selection algorithm.
30 class IVtkTools_EXPORT IVtkTools_ShapePicker : public vtkAbstractPropPicker
33 vtkTypeMacro(IVtkTools_ShapePicker, vtkAbstractPropPicker)
35 static IVtkTools_ShapePicker* New();
37 //! Pick entities in the given point or area.
38 //! @return Number of detected entities.
39 int pick (double* thePos, vtkRenderer *theRenderer, const int theNbPoints = -1);
41 //! Pick entities in the given point.
42 //! @return Number of detected entities.
43 int Pick (double theX, double theY, double theZ, vtkRenderer *theRenderer = NULL);
45 //! Pick entities in the given rectangle area.
46 //! @return Number of detected entities.
47 int Pick(double theX0, double theY0, double theX1, double theY1, vtkRenderer *theRenderer = NULL);
49 //! Pick entities in the given polygonal area.
50 //! @return Number of detected entities.
51 int Pick(double poly[][3], const int theNbPoints, vtkRenderer *theRenderer = NULL);
53 //! Setter for tolerance of picking.
54 void SetTolerance (float theTolerance);
55 //! Getter for tolerance of picking.
56 float GetTolerance () const;
58 //! Sets the renderer to be used by OCCT selection algorithm
59 void SetRenderer (vtkRenderer* theRenderer);
60 //! Sets area selection on/off
61 //! @param [in] theIsOn true if area selection is turned on, false otherwise.
62 void SetAreaSelection (bool theIsOn);
64 //! Get activated selection modes for a shape.
65 //! @param [in] theShape a shape with activated selection mode(s)
66 //! @return list of active selection modes
67 IVtk_SelectionModeList GetSelectionModes (const IVtk_IShape::Handle& theShape) const;
69 //! Get activated selection modes for a shape actor.
70 //! @param [in] theShapeActor an actor with activated selection mode(s)
71 //! @return list of active selection modes
72 IVtk_SelectionModeList GetSelectionModes (vtkActor* theShapeActor) const;
74 //! Turn on/off a selection mode for a shape actor.
75 //! @param [in] theShape a shape to set a selection mode for
76 //! @param [in] theMode selection mode to be activated
77 //! @param [in] theIsTurnOn Flag to turn on/off the selection mode
78 void SetSelectionMode (const IVtk_IShape::Handle& theShape,
79 const IVtk_SelectionMode theMode,
80 const bool theIsTurnOn = true) const;
82 //! Turn on/off a selection mode for a shape actor.
83 //! @param [in] theShapeActor shape presentation actor to set a selection mode for
84 //! @param [in] theMode selection mode to be activated
85 //! @param [in] theIsTurnOn Flag to turn on/off the selection mode
86 void SetSelectionMode (vtkActor* theShapeActor,
87 const IVtk_SelectionMode theMode,
88 const bool theIsTurnOn = true) const;
90 //! Sets the current selection mode for all visible shape objects.
91 //! @param [in] theMode selection mode to be activated
92 //! @param [in] theIsTurnOn Flag to turn on/off the selection mode
93 void SetSelectionMode (const IVtk_SelectionMode theMode,
94 const bool theIsTurnOn = true) const;
98 //! Access to the list of top-level shapes picked.
99 //! If all argument is true, the picker returns the list of
100 //! all OccShape objects found by the picking algorithm. e.g. all
101 //! shapes under the mouse cursor. Otherwise, ID of the shape closest to the eye
103 //! @param [in] theIsAll Get all selected shapes or just the only
104 //! top one is returned, has no effect during area selection.
105 //! @return List of top-level shape IDs
106 IVtk_ShapeIdList GetPickedShapesIds (bool theIsAll = false) const;
108 //! Access to the list of sub-shapes ids picked.
109 //! @param [in] theId top-level shape ID
110 //! @param [in] theIsAll Get all selected sub-shapes or just the
111 //! only top one is returned, has no effect during area selection.
112 //! @return List of sub-shapes IDs
113 IVtk_ShapeIdList GetPickedSubShapesIds (const IVtk_IdType theId, bool theIsAll = false) const;
115 //! Access to the list of actors picked.
116 //! @param [in] theIsAll Get all selected actors or just the only
117 //! top one is returned, has no effect during area selection.
118 //! @return List of actors IDs
119 vtkSmartPointer<vtkActorCollection> GetPickedActors (bool theIsAll = false) const;
121 //! Remove selectable object from the picker (from internal maps).
122 //! @param [in] theShape the selectable shape
123 void RemoveSelectableObject(const IVtk_IShape::Handle& theShape);
125 //! Remove selectable object from the picker (from internal maps).
126 //! @param [in] theShapeActor the shape presentation actor to be removed from the picker
127 void RemoveSelectableActor(vtkActor* theShapeActor);
130 //! Constructs the picker with empty renderer and ready for point selection.
131 IVtkTools_ShapePicker();
133 virtual ~IVtkTools_ShapePicker();
135 //! Convert display coordinates to world coordinates
136 static bool convertDisplayToWorld (vtkRenderer *theRenderer,
137 double theDisplayCoord[3],
138 double theWorldCoord[3] );
140 private: // not copyable
141 IVtkTools_ShapePicker (const IVtkTools_ShapePicker&);
142 IVtkTools_ShapePicker& operator= (const IVtkTools_ShapePicker&);
144 //! Implementation of picking algorithm.
145 //! The coordinates accepted by this method are display (pixel) coordinates.
146 //! @param [in] pos contains the pick point (3 coordinates) or pick rectangle (6 coordinates)
147 //! or polyline (array of 2d coordinates)
148 //! @param [in] renderer vtkRenderer object to be used (normally set in advance with setRenderer())
149 //! @param [in] nbPoints number of points for polyline case
150 //! @see IVtkTools_ShapePicker::setRenderer
151 virtual void doPickImpl (double*, vtkRenderer* theRenderer, const int theNbPoints = -1);
154 IVtkOCC_ShapePickerAlgo::Handle myOccPickerAlgo; //!< Picking algorithm implementation
155 vtkSmartPointer<vtkRenderer> myRenderer; //!< VTK renderer
156 bool myIsRectSelection;//!< Rectangle selection mode flag
157 bool myIsPolySelection;//!< Polyline selection mode flag
158 float myTolerance; //!< Selectoin tolerance
161 #endif // __IVTKTOOLS_SHAPEPICKER_H__