913a4c4a |
1 | // Created: 2011-10-27 |
2 | // Created by: Roman KOZLOV |
3 | // Copyright (c) 2011-2014 OPEN CASCADE SAS |
4 | // |
5 | // This file is part of Open CASCADE Technology software library. |
6 | // |
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. |
12 | // |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
15 | |
16 | #ifndef __IVTKTOOLS_SHAPEPICKER_H__ |
17 | #define __IVTKTOOLS_SHAPEPICKER_H__ |
18 | |
19 | #include <IVtkTools.hxx> |
20 | #include <IVtk_Types.hxx> |
21 | #include <IVtkOCC_ShapePickerAlgo.hxx> |
22 | #include <vtkAbstractPropPicker.h> |
23 | |
24 | class vtkRenderer; |
25 | class vtkActorCollection; |
26 | |
27 | //! @class IVtkTools_ShapePicker |
28 | //! @brief VTK picker for OCC shapes with OCC selection algorithm. |
29 | class IVtkTools_EXPORT IVtkTools_ShapePicker : public vtkAbstractPropPicker |
30 | { |
31 | public: |
68858c7d |
32 | vtkTypeMacro(IVtkTools_ShapePicker, vtkAbstractPropPicker) |
33 | |
913a4c4a |
34 | static IVtkTools_ShapePicker* New(); |
35 | |
36 | //! Pick entities in the given point or area. |
37 | //! @return Number of detected entities. |
38 | int pick (double* thePos, vtkRenderer *theRenderer, const int theNbPoints = -1); |
39 | |
40 | //! Pick entities in the given point. |
41 | //! @return Number of detected entities. |
42 | int Pick (double theX, double theY, double theZ, vtkRenderer *theRenderer = NULL); |
43 | |
44 | //! Pick entities in the given rectangle area. |
45 | //! @return Number of detected entities. |
46 | int Pick(double theX0, double theY0, double theX1, double theY1, vtkRenderer *theRenderer = NULL); |
47 | |
48 | //! Pick entities in the given polygonal area. |
49 | //! @return Number of detected entities. |
50 | int Pick(double poly[][3], const int theNbPoints, vtkRenderer *theRenderer = NULL); |
51 | |
52 | //! Setter for tolerance of picking. |
53 | void SetTolerance (float theTolerance); |
54 | //! Getter for tolerance of picking. |
55 | float GetTolerance () const; |
56 | |
57 | //! Sets the renderer to be used by OCCT selection algorithm |
58 | void SetRenderer (vtkRenderer* theRenderer); |
59 | //! Sets area selection on/off |
60 | //! @param [in] theIsOn true if area selection is turned on, false otherwise. |
61 | void SetAreaSelection (bool theIsOn); |
62 | |
63 | //! Get activated selection modes for a shape. |
64 | //! @param [in] theShape a shape with activated selection mode(s) |
65 | //! @return list of active selection modes |
66 | IVtk_SelectionModeList GetSelectionModes (const IVtk_IShape::Handle& theShape) const; |
67 | |
68 | //! Get activated selection modes for a shape actor. |
69 | //! @param [in] theShapeActor an actor with activated selection mode(s) |
70 | //! @return list of active selection modes |
71 | IVtk_SelectionModeList GetSelectionModes (vtkActor* theShapeActor) const; |
72 | |
73 | //! Turn on/off a selection mode for a shape actor. |
74 | //! @param [in] theShape a shape to set a selection mode for |
75 | //! @param [in] theMode selection mode to be activated |
76 | //! @param [in] theIsTurnOn Flag to turn on/off the selection mode |
77 | void SetSelectionMode (const IVtk_IShape::Handle& theShape, |
78 | const IVtk_SelectionMode theMode, |
79 | const bool theIsTurnOn = true) const; |
80 | |
81 | //! Turn on/off a selection mode for a shape actor. |
82 | //! @param [in] shapeActor shape presentation actor to set a selection mode for |
83 | //! @param [in] mode selection mode to be activated |
84 | //! @param [in] turnOn Flag to turn on/off the selection mode |
85 | void SetSelectionMode (vtkActor* theShapeActor, |
86 | const IVtk_SelectionMode theMode, |
87 | const bool theIsTurnOn = true) const; |
88 | |
89 | //! Sets the current selection mode for all visible shape objects. |
90 | //! @param [in] theMode selection mode to be activated |
91 | //! @param [in] theIsTurnOn Flag to turn on/off the selection mode |
92 | void SetSelectionMode (const IVtk_SelectionMode theMode, |
93 | const bool theIsTurnOn = true) const; |
94 | |
95 | // Picking results |
96 | |
97 | //! Access to the list of top-level shapes picked. |
98 | //! If all argument is true, the picker returns the list of |
99 | //! all OccShape objects found by the picking algorithm. e.g. all |
100 | //! shapes under the mouse cursor. Otherwise, ID of the shape closest to the eye |
101 | //! is returned. |
102 | //! @param [in] all Controls if all selected shapes or just the only |
103 | //! top one is returned, has no effect during area selection. |
104 | //! @return List of top-level shape IDs |
105 | IVtk_ShapeIdList GetPickedShapesIds (bool theIsAll = false) const; |
106 | |
107 | //! Access to the list of sub-shapes ids picked. |
108 | //! @param [in] id top-level shape ID |
109 | //! @param [in] all Controls if all selected sub-shapes or just the |
110 | //! only top one is returned, has no effect during area selection. |
111 | //! @return List of sub-shapes IDs |
112 | IVtk_ShapeIdList GetPickedSubShapesIds (const IVtk_IdType theId, bool theIsAll = false) const; |
113 | |
114 | //! Access to the list of actors picked. |
115 | //! @param [in] all Controls if all selected actors or just the only |
116 | //! top one is returned, has no effect during area selection. |
117 | //! @return List of actors IDs |
118 | vtkActorCollection* GetPickedActors (bool theIsAll = false) const; |
119 | |
120 | protected: |
121 | //! Constructs the picker with empty renderer and ready for point selection. |
122 | IVtkTools_ShapePicker(); |
123 | //! Destructor |
124 | ~IVtkTools_ShapePicker(); |
125 | |
126 | //! Convert display coordinates to world coordinates |
127 | static bool convertDisplayToWorld (vtkRenderer *theRenderer, |
5ca413ce |
128 | double theDisplayCoord[3], |
129 | double theWorldCoord[3] ); |
913a4c4a |
130 | |
131 | private: // not copyable |
132 | IVtkTools_ShapePicker (const IVtkTools_ShapePicker&); |
133 | IVtkTools_ShapePicker& operator= (const IVtkTools_ShapePicker&); |
134 | |
135 | //! Implementation of picking algorithm. |
136 | //! The coordinates accepted by this method are display (pixel) coordinates. |
137 | //! @param [in] pos contains the pick point (3 coordinates) or pick rectangle (6 coordinates) |
138 | //! or polyline (array of 2d coordinates) |
139 | //! @param [in] renderer vtkRenderer object to be used (normally set in advance with setRenderer()) |
140 | //! @param [in] nbPoints number of points for polyline case |
141 | //! @see IVtkTools_ShapePicker::setRenderer |
142 | virtual void doPickImpl (double*, vtkRenderer* theRenderer, const int theNbPoints = -1); |
143 | |
144 | private: |
145 | IVtkOCC_ShapePickerAlgo::Handle myOccPickerAlgo; //!< Picking algorithm implementation |
146 | vtkRenderer* myRenderer; //!< VTK renderer |
147 | bool myIsRectSelection;//!< Rectangle selection mode flag |
148 | bool myIsPolySelection;//!< Polyline selection mode flag |
149 | float myTolerance; //!< Selectoin tolerance |
150 | }; |
151 | |
152 | #endif // __IVTKTOOLS_SHAPEPICKER_H__ |