0031668: Visualization - WebGL sample doesn't work on Emscripten 1.39
[occt.git] / src / IVtkOCC / IVtkOCC_ShapePickerAlgo.hxx
CommitLineData
913a4c4a 1// Created on: 2011-10-14
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 __IVTKOCC_SHAPEPICKERALGO_H__
17#define __IVTKOCC_SHAPEPICKERALGO_H__
18
19#include <IVtk_IShapePickerAlgo.hxx>
20#include <IVtkOCC_ViewerSelector.hxx>
21
c04c30b3 22class IVtkOCC_ShapePickerAlgo;
913a4c4a 23DEFINE_STANDARD_HANDLE( IVtkOCC_ShapePickerAlgo, IVtk_IShapePickerAlgo )
24
25//! @class IVtkOCC_ShapePickerAlgo
26//! @brief OCC implementation of 3D shapes picking algorithm.
27class IVtkOCC_ShapePickerAlgo : public IVtk_IShapePickerAlgo
28{
29public:
30 typedef Handle(IVtkOCC_ShapePickerAlgo) Handle;
31
32 //! Constructor
33 Standard_EXPORT IVtkOCC_ShapePickerAlgo();
34
35 //! Destructor
36 Standard_EXPORT virtual ~IVtkOCC_ShapePickerAlgo();
37
38 //! Sets the picker's view interface.
39 //! The picker uses the view to obtain parameters of
40 //! the 3D view projection.
c7854818 41 Standard_EXPORT virtual void SetView (const IVtk_IView::Handle& theView) Standard_OVERRIDE;
913a4c4a 42
913a4c4a 43 //! Get number of picked entities.
c7854818 44 Standard_EXPORT virtual int NbPicked() Standard_OVERRIDE;
913a4c4a 45
46 //! Get activated selection modes for a shape.
47 //! @param [in] theShape a shape with activated selection mode(s)
48 //! @return list of active selection modes
c7854818 49 Standard_EXPORT virtual IVtk_SelectionModeList
50 GetSelectionModes (const IVtk_IShape::Handle& theShape) const Standard_OVERRIDE;
913a4c4a 51
52public: //! @name Set selectable shapes and selection modes
53
54 //! Activates/deactivates the given selection mode for the shape.
55 //! If mode == SM_None, the shape becomes non-selectable and
56 //! is removed from the internal selection data.
57 //! @param [in] theShape Shape for which the selection mode should be activated
58 //! @param [in] theMode Selection mode to be activated
59 //! @param [in] theIsTurnOn Flag to turn on/off the selection mode
60 Standard_EXPORT virtual void SetSelectionMode (const IVtk_IShape::Handle& theShape,
61 const IVtk_SelectionMode theMode,
c7854818 62 const bool theIsTurnOn = true) Standard_OVERRIDE;
913a4c4a 63
64 //! Activates/deactivates the given selection mode for the shape.
65 //! If mode == SM_None, the shape becomes non-selectable and
66 //! is removed from the internal selection data.
67 //! @param [in] theShapes List of shapes for which the selection mode should be activated
68 //! @param [in] theMode Selection mode to be activated
69 //! @param [in] theIsTurnOn Flag to turn on/off the selection mode
70 Standard_EXPORT virtual void SetSelectionMode (const IVtk_ShapePtrList& theShapes,
71 const IVtk_SelectionMode theMode,
c7854818 72 const bool theIsTurnOn = true) Standard_OVERRIDE;
913a4c4a 73
74public: //! @name Picking methods
75
c7854818 76 Standard_EXPORT virtual bool Pick (const double theX, const double theY) Standard_OVERRIDE;
913a4c4a 77
78 Standard_EXPORT virtual bool Pick (const double theXMin,
79 const double theYMin,
80 const double theXMax,
c7854818 81 const double theYMax) Standard_OVERRIDE;
913a4c4a 82
c7854818 83 Standard_EXPORT virtual bool Pick (double** thePolyLine, const int theNbPoints) Standard_OVERRIDE;
913a4c4a 84
85public: //! @name Obtain picking results
86
87 //! @return the list of picked top-level shape IDs,
88 //! in the order of increasing depth (the ID of the shape closest to the eye
89 //! is the first in the list)
c7854818 90 Standard_EXPORT virtual const IVtk_ShapeIdList& ShapesPicked() const Standard_OVERRIDE;
913a4c4a 91
92 //! @param [in] theId Top-level shape ID
93 //! @param [out] theShapeList the list of picked sub-shape IDs for the given top-level shape ID,
94 //! in the order of increasing depth (the ID of the sub-shape closest to the eye
95 //! is the first in the list)
c7854818 96 Standard_EXPORT virtual void
97 SubShapesPicked (const IVtk_IdType theId, IVtk_ShapeIdList& theShapeList) const Standard_OVERRIDE;
913a4c4a 98
a2f76b15 99 //! Remove selectable object from the picker (from internal maps).
100 //! @param [in] theShape the selectable shape
101 Standard_EXPORT virtual void RemoveSelectableObject(const IVtk_IShape::Handle& theShape);
102
1e756cb9 103 //! Return topmost picked 3D point or (Inf, Inf, Inf) if undefined.
104 const gp_Pnt& TopPickedPoint() const { return myTopPickedPoint; }
105
913a4c4a 106public:
107
92efcf78 108 DEFINE_STANDARD_RTTIEXT(IVtkOCC_ShapePickerAlgo,IVtk_IShapePickerAlgo)
913a4c4a 109
110private:
111
112 //! Internal method, resets picked data
113 void clearPicked();
114
115 //! Internal method, extracts picked shapes from ViewerSelector
116 //! and prepares the results in the form of IDs:
117 //! In case of top-level shape(s) selected, only myShapesPicked list is filled.
118 //! Otherwise, mySubShapesPicked map is filled in addition, to provide the information
119 //! about selected sub-shapes grouped by their top-level shapes.
120 //! @return true if some shapes has been picked, and false otherwise
121 //! @see IVtkOCC_ShapePickerAlgo::pick
122 bool processPicked();
123
124 IVtk_IView::Handle myView;
125 IVtk_ShapeIdList myShapesPicked;
126 IVtk_SubShapeMap mySubShapesPicked;
1e756cb9 127 gp_Pnt myTopPickedPoint;
913a4c4a 128 Handle(IVtkOCC_ViewerSelector) myViewerSelector;
129};
130
131#endif // __IVTKOCC_SHAPEPICKERALGO_H__