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>
25 class vtkActorCollection;
27 //! @class IVtkTools_ShapePicker
28 //! @brief VTK picker for OCC shapes with OCC selection algorithm.
29 class IVtkTools_EXPORT IVtkTools_ShapePicker : public vtkAbstractPropPicker
32 vtkTypeMacro(IVtkTools_ShapePicker, vtkAbstractPropPicker);
33 static IVtkTools_ShapePicker* New();
35 //! Pick entities in the given point or area.
36 //! @return Number of detected entities.
37 int pick (double* thePos, vtkRenderer *theRenderer, const int theNbPoints = -1);
39 //! Pick entities in the given point.
40 //! @return Number of detected entities.
41 int Pick (double theX, double theY, double theZ, vtkRenderer *theRenderer = NULL);
43 //! Pick entities in the given rectangle area.
44 //! @return Number of detected entities.
45 int Pick(double theX0, double theY0, double theX1, double theY1, vtkRenderer *theRenderer = NULL);
47 //! Pick entities in the given polygonal area.
48 //! @return Number of detected entities.
49 int Pick(double poly[][3], const int theNbPoints, vtkRenderer *theRenderer = NULL);
51 //! Setter for tolerance of picking.
52 void SetTolerance (float theTolerance);
53 //! Getter for tolerance of picking.
54 float GetTolerance () const;
56 //! Sets the renderer to be used by OCCT selection algorithm
57 void SetRenderer (vtkRenderer* theRenderer);
58 //! Sets area selection on/off
59 //! @param [in] theIsOn true if area selection is turned on, false otherwise.
60 void SetAreaSelection (bool theIsOn);
62 //! Get activated selection modes for a shape.
63 //! @param [in] theShape a shape with activated selection mode(s)
64 //! @return list of active selection modes
65 IVtk_SelectionModeList GetSelectionModes (const IVtk_IShape::Handle& theShape) const;
67 //! Get activated selection modes for a shape actor.
68 //! @param [in] theShapeActor an actor with activated selection mode(s)
69 //! @return list of active selection modes
70 IVtk_SelectionModeList GetSelectionModes (vtkActor* theShapeActor) const;
72 //! Turn on/off a selection mode for a shape actor.
73 //! @param [in] theShape a shape to set a selection mode for
74 //! @param [in] theMode selection mode to be activated
75 //! @param [in] theIsTurnOn Flag to turn on/off the selection mode
76 void SetSelectionMode (const IVtk_IShape::Handle& theShape,
77 const IVtk_SelectionMode theMode,
78 const bool theIsTurnOn = true) const;
80 //! Turn on/off a selection mode for a shape actor.
81 //! @param [in] shapeActor shape presentation actor to set a selection mode for
82 //! @param [in] mode selection mode to be activated
83 //! @param [in] turnOn Flag to turn on/off the selection mode
84 void SetSelectionMode (vtkActor* theShapeActor,
85 const IVtk_SelectionMode theMode,
86 const bool theIsTurnOn = true) const;
88 //! Sets the current selection mode for all visible shape objects.
89 //! @param [in] theMode selection mode to be activated
90 //! @param [in] theIsTurnOn Flag to turn on/off the selection mode
91 void SetSelectionMode (const IVtk_SelectionMode theMode,
92 const bool theIsTurnOn = true) const;
96 //! Access to the list of top-level shapes picked.
97 //! If all argument is true, the picker returns the list of
98 //! all OccShape objects found by the picking algorithm. e.g. all
99 //! shapes under the mouse cursor. Otherwise, ID of the shape closest to the eye
101 //! @param [in] all Controls if all selected shapes or just the only
102 //! top one is returned, has no effect during area selection.
103 //! @return List of top-level shape IDs
104 IVtk_ShapeIdList GetPickedShapesIds (bool theIsAll = false) const;
106 //! Access to the list of sub-shapes ids picked.
107 //! @param [in] id top-level shape ID
108 //! @param [in] all Controls if all selected sub-shapes or just the
109 //! only top one is returned, has no effect during area selection.
110 //! @return List of sub-shapes IDs
111 IVtk_ShapeIdList GetPickedSubShapesIds (const IVtk_IdType theId, bool theIsAll = false) const;
113 //! Access to the list of actors picked.
114 //! @param [in] all Controls if all selected actors or just the only
115 //! top one is returned, has no effect during area selection.
116 //! @return List of actors IDs
117 vtkActorCollection* GetPickedActors (bool theIsAll = false) const;
120 //! Constructs the picker with empty renderer and ready for point selection.
121 IVtkTools_ShapePicker();
123 ~IVtkTools_ShapePicker();
125 //! Convert display coordinates to world coordinates
126 static bool convertDisplayToWorld (vtkRenderer *theRenderer,
127 vtkFloatingPointType theDisplayCoord[3],
128 vtkFloatingPointType theWorldCoord[3] );
130 private: // not copyable
131 IVtkTools_ShapePicker (const IVtkTools_ShapePicker&);
132 IVtkTools_ShapePicker& operator= (const IVtkTools_ShapePicker&);
134 //! Implementation of picking algorithm.
135 //! The coordinates accepted by this method are display (pixel) coordinates.
136 //! @param [in] pos contains the pick point (3 coordinates) or pick rectangle (6 coordinates)
137 //! or polyline (array of 2d coordinates)
138 //! @param [in] renderer vtkRenderer object to be used (normally set in advance with setRenderer())
139 //! @param [in] nbPoints number of points for polyline case
140 //! @see IVtkTools_ShapePicker::setRenderer
141 virtual void doPickImpl (double*, vtkRenderer* theRenderer, const int theNbPoints = -1);
144 IVtkOCC_ShapePickerAlgo::Handle myOccPickerAlgo; //!< Picking algorithm implementation
145 vtkRenderer* myRenderer; //!< VTK renderer
146 bool myIsRectSelection;//!< Rectangle selection mode flag
147 bool myIsPolySelection;//!< Polyline selection mode flag
148 float myTolerance; //!< Selectoin tolerance
151 #endif // __IVTKTOOLS_SHAPEPICKER_H__