f6c368abd1addf78a36829a1652bb7eef090210a
[occt.git] / src / Select3D / Select3D_SensitivePoly.hxx
1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14 #ifndef _Select3D_SensitivePoly_HeaderFile
15 #define _Select3D_SensitivePoly_HeaderFile
16
17 #include <NCollection_Handle.hxx>
18
19 #include <Standard.hxx>
20 #include <Standard_Type.hxx>
21 #include <Standard_Type.hxx>
22
23 #include <TColStd_HArray1OfInteger.hxx>
24 #include <TColgp_HArray1OfPnt.hxx>
25
26 #include <Select3D_PointData.hxx>
27 #include <Select3D_Pnt.hxx>
28 #include <Select3D_SensitiveSet.hxx>
29 #include <Select3D_TypeOfSensitivity.hxx>
30
31
32 class Standard_ConstructionError;
33 class Standard_OutOfRange;
34 class SelectBasics_EntityOwner;
35
36 //! Sensitive Entity to make a face selectable.
37 //! In some cases this class can raise Standard_ConstructionError and
38 //! Standard_OutOfRange exceptions from its member Select3D_PointData
39 //! myPolyg.
40 class Select3D_SensitivePoly : public Select3D_SensitiveSet
41 {
42 public:
43
44   //! Constructs a sensitive face object defined by the
45   //! owner OwnerId, the array of points ThePoints, and
46   //! the sensitivity type Sensitivity.
47   //! The array of points is the outer polygon of the geometric face.
48   Standard_EXPORT Select3D_SensitivePoly (const Handle(SelectBasics_EntityOwner)& theOwnerId,
49                                           const TColgp_Array1OfPnt& thePoints,
50                                           const Standard_Boolean theIsBVHEnabled);
51
52   //! Constructs a sensitive face object defined by the
53   //! owner OwnerId, the array of points ThePoints, and
54   //! the sensitivity type Sensitivity.
55   //! The array of points is the outer polygon of the geometric face.
56   Standard_EXPORT Select3D_SensitivePoly (const Handle(SelectBasics_EntityOwner)& theOwnerId,
57                                           const Handle(TColgp_HArray1OfPnt)& thePoints,
58                                           const Standard_Boolean theIsBVHEnabled);
59
60   //! Constructs the sensitive circle object defined by the
61   //! owner OwnerId, the circle Circle, the Boolean
62   //! FilledCircle and the number of points NbOfPoints.
63   Standard_EXPORT Select3D_SensitivePoly (const Handle(SelectBasics_EntityOwner)& theOwnerId,
64                                           const Standard_Boolean theIsBVHEnabled,
65                                           const Standard_Integer theNbPnts = 6);
66
67   //! Returns the amount of segments in poly
68   Standard_EXPORT virtual Standard_Integer NbSubElements() Standard_OVERRIDE;
69
70   //! Returns the 3D points of the array used at construction time.
71   Standard_EXPORT void Points3D (Handle(TColgp_HArray1OfPnt)& theHArrayOfPnt);
72
73   //! Returns bounding box of a polygon. If location
74   //! transformation is set, it will be applied
75   Standard_EXPORT virtual Select3D_BndBox3d BoundingBox() Standard_OVERRIDE;
76
77   //! Returns center of the point set. If location transformation
78   //! is set, it will be applied
79   Standard_EXPORT virtual gp_Pnt CenterOfGeometry() const Standard_OVERRIDE;
80
81   //! Returns the amount of segments of the poly
82   Standard_EXPORT virtual Standard_Integer Size() const Standard_OVERRIDE;
83
84   //! Returns bounding box of segment with index theIdx
85   Standard_EXPORT virtual Select3D_BndBox3d Box (const Standard_Integer theIdx) const Standard_OVERRIDE;
86
87   //! Returns geometry center of sensitive entity index theIdx in the vector along
88   //! the given axis theAxis
89   Standard_EXPORT virtual Standard_Real Center (const Standard_Integer theIdx,
90                                                 const Standard_Integer theAxis) const Standard_OVERRIDE;
91
92   //! Swaps items with indexes theIdx1 and theIdx2 in the vector
93   Standard_EXPORT virtual void Swap (const Standard_Integer theIdx1,
94                                      const Standard_Integer theIdx2) Standard_OVERRIDE;
95
96   DEFINE_STANDARD_RTTIEXT(Select3D_SensitivePoly,Select3D_SensitiveSet)
97
98 private:
99
100   //! Checks whether the segment with index theIdx overlaps the current selecting volume
101   virtual Standard_Boolean overlapsElement (SelectBasics_SelectingVolumeManager& theMgr,
102                                             Standard_Integer theElemIdx,
103                                             Standard_Real& theMatchDepth) Standard_OVERRIDE;
104
105   //! Checks whether the entity with index theIdx is inside the current selecting volume
106   virtual Standard_Boolean elementIsInside (SelectBasics_SelectingVolumeManager& theMgr,
107                                             const Standard_Integer               theElemIdx) Standard_OVERRIDE;
108
109   //! Calculates distance from the 3d projection of used-picked screen point
110   //! to center of the geometry
111   virtual Standard_Real distanceToCOG (SelectBasics_SelectingVolumeManager& theMgr) Standard_OVERRIDE;
112
113 protected:
114
115   Select3D_PointData              myPolyg;              //!< Points of the poly
116   mutable gp_Pnt                  myCOG;                //!< Center of the poly
117   Handle(TColStd_HArray1OfInteger) mySegmentIndexes;     //!< Segment indexes for BVH tree build
118   Select3D_BndBox3d               myBndBox;             //!< Bounding box of the poly
119   mutable Standard_Boolean        myIsComputed;         //!< Is true if all the points and data structures of polygon are initialized
120 };
121
122 DEFINE_STANDARD_HANDLE(Select3D_SensitivePoly, Select3D_SensitiveSet)
123
124 #include <Select3D_SensitivePoly.lxx>
125
126 #endif // _Select3D_SensitivePoly_HeaderFile