0031687: Draw Harness, ViewerTest - extend command vrenderparams with option updating...
[occt.git] / src / IVtkTools / IVtkTools_ShapePicker.hxx
CommitLineData
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>
a9660929 22
23// prevent disabling some MSVC warning messages by VTK headers
24#ifdef _MSC_VER
25#pragma warning(push)
26#endif
913a4c4a 27#include <vtkAbstractPropPicker.h>
a2f76b15 28#include <vtkSmartPointer.h>
a9660929 29#ifdef _MSC_VER
30#pragma warning(pop)
31#endif
913a4c4a 32
33class vtkRenderer;
34class vtkActorCollection;
35
896faa72 36#ifdef _MSC_VER
37#pragma warning(push)
38#pragma warning(disable: 4251) // avoid warning C4251: "class needs to have dll-interface..."
39#endif
40
913a4c4a 41//! @class IVtkTools_ShapePicker
42//! @brief VTK picker for OCC shapes with OCC selection algorithm.
68df8478 43class Standard_EXPORT IVtkTools_ShapePicker : public vtkAbstractPropPicker
913a4c4a 44{
45public:
68858c7d 46 vtkTypeMacro(IVtkTools_ShapePicker, vtkAbstractPropPicker)
47
913a4c4a 48 static IVtkTools_ShapePicker* New();
49
50 //! Pick entities in the given point or area.
51 //! @return Number of detected entities.
52 int pick (double* thePos, vtkRenderer *theRenderer, const int theNbPoints = -1);
53
54 //! Pick entities in the given point.
55 //! @return Number of detected entities.
56 int Pick (double theX, double theY, double theZ, vtkRenderer *theRenderer = NULL);
57
58 //! Pick entities in the given rectangle area.
59 //! @return Number of detected entities.
60 int Pick(double theX0, double theY0, double theX1, double theY1, vtkRenderer *theRenderer = NULL);
61
62 //! Pick entities in the given polygonal area.
63 //! @return Number of detected entities.
64 int Pick(double poly[][3], const int theNbPoints, vtkRenderer *theRenderer = NULL);
65
66 //! Setter for tolerance of picking.
67 void SetTolerance (float theTolerance);
68 //! Getter for tolerance of picking.
69 float GetTolerance () const;
70
71 //! Sets the renderer to be used by OCCT selection algorithm
72 void SetRenderer (vtkRenderer* theRenderer);
73 //! Sets area selection on/off
74 //! @param [in] theIsOn true if area selection is turned on, false otherwise.
75 void SetAreaSelection (bool theIsOn);
76
77 //! Get activated selection modes for a shape.
78 //! @param [in] theShape a shape with activated selection mode(s)
79 //! @return list of active selection modes
80 IVtk_SelectionModeList GetSelectionModes (const IVtk_IShape::Handle& theShape) const;
81
82 //! Get activated selection modes for a shape actor.
83 //! @param [in] theShapeActor an actor with activated selection mode(s)
84 //! @return list of active selection modes
85 IVtk_SelectionModeList GetSelectionModes (vtkActor* theShapeActor) const;
86
87 //! Turn on/off a selection mode for a shape actor.
88 //! @param [in] theShape a shape to set a selection mode for
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_IShape::Handle& theShape,
92 const IVtk_SelectionMode theMode,
93 const bool theIsTurnOn = true) const;
94
95 //! Turn on/off a selection mode for a shape actor.
a2f76b15 96 //! @param [in] theShapeActor shape presentation actor to set a selection mode for
97 //! @param [in] theMode selection mode to be activated
98 //! @param [in] theIsTurnOn Flag to turn on/off the selection mode
913a4c4a 99 void SetSelectionMode (vtkActor* theShapeActor,
100 const IVtk_SelectionMode theMode,
101 const bool theIsTurnOn = true) const;
102
103 //! Sets the current selection mode for all visible shape objects.
104 //! @param [in] theMode selection mode to be activated
105 //! @param [in] theIsTurnOn Flag to turn on/off the selection mode
106 void SetSelectionMode (const IVtk_SelectionMode theMode,
107 const bool theIsTurnOn = true) const;
108
109 // Picking results
110
111 //! Access to the list of top-level shapes picked.
112 //! If all argument is true, the picker returns the list of
113 //! all OccShape objects found by the picking algorithm. e.g. all
114 //! shapes under the mouse cursor. Otherwise, ID of the shape closest to the eye
115 //! is returned.
a2f76b15 116 //! @param [in] theIsAll Get all selected shapes or just the only
913a4c4a 117 //! top one is returned, has no effect during area selection.
118 //! @return List of top-level shape IDs
119 IVtk_ShapeIdList GetPickedShapesIds (bool theIsAll = false) const;
120
121 //! Access to the list of sub-shapes ids picked.
a2f76b15 122 //! @param [in] theId top-level shape ID
123 //! @param [in] theIsAll Get all selected sub-shapes or just the
913a4c4a 124 //! only top one is returned, has no effect during area selection.
125 //! @return List of sub-shapes IDs
126 IVtk_ShapeIdList GetPickedSubShapesIds (const IVtk_IdType theId, bool theIsAll = false) const;
127
128 //! Access to the list of actors picked.
a2f76b15 129 //! @param [in] theIsAll Get all selected actors or just the only
913a4c4a 130 //! top one is returned, has no effect during area selection.
131 //! @return List of actors IDs
a2f76b15 132 vtkSmartPointer<vtkActorCollection> GetPickedActors (bool theIsAll = false) const;
133
134 //! Remove selectable object from the picker (from internal maps).
135 //! @param [in] theShape the selectable shape
136 void RemoveSelectableObject(const IVtk_IShape::Handle& theShape);
137
138 //! Remove selectable object from the picker (from internal maps).
139 //! @param [in] theShapeActor the shape presentation actor to be removed from the picker
140 void RemoveSelectableActor(vtkActor* theShapeActor);
913a4c4a 141
142protected:
143 //! Constructs the picker with empty renderer and ready for point selection.
144 IVtkTools_ShapePicker();
145 //! Destructor
a2f76b15 146 virtual ~IVtkTools_ShapePicker();
913a4c4a 147
148 //! Convert display coordinates to world coordinates
149 static bool convertDisplayToWorld (vtkRenderer *theRenderer,
5ca413ce 150 double theDisplayCoord[3],
151 double theWorldCoord[3] );
913a4c4a 152
153private: // not copyable
154 IVtkTools_ShapePicker (const IVtkTools_ShapePicker&);
155 IVtkTools_ShapePicker& operator= (const IVtkTools_ShapePicker&);
156
157 //! Implementation of picking algorithm.
158 //! The coordinates accepted by this method are display (pixel) coordinates.
159 //! @param [in] pos contains the pick point (3 coordinates) or pick rectangle (6 coordinates)
160 //! or polyline (array of 2d coordinates)
161 //! @param [in] renderer vtkRenderer object to be used (normally set in advance with setRenderer())
162 //! @param [in] nbPoints number of points for polyline case
163 //! @see IVtkTools_ShapePicker::setRenderer
164 virtual void doPickImpl (double*, vtkRenderer* theRenderer, const int theNbPoints = -1);
165
166private:
167 IVtkOCC_ShapePickerAlgo::Handle myOccPickerAlgo; //!< Picking algorithm implementation
a2f76b15 168 vtkSmartPointer<vtkRenderer> myRenderer; //!< VTK renderer
913a4c4a 169 bool myIsRectSelection;//!< Rectangle selection mode flag
170 bool myIsPolySelection;//!< Polyline selection mode flag
171 float myTolerance; //!< Selectoin tolerance
172};
173
896faa72 174#ifdef _MSC_VER
175#pragma warning(pop)
176#endif
177
913a4c4a 178#endif // __IVTKTOOLS_SHAPEPICKER_H__