0032337: Visualization - rename Overlaps() method in selection to more self-describab...
[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 <Select3D_PointData.hxx>
18 #include <Select3D_SensitiveSet.hxx>
19 #include <Select3D_TypeOfSensitivity.hxx>
20 #include <TColStd_HArray1OfInteger.hxx>
21 #include <TColgp_HArray1OfPnt.hxx>
22
23 class Standard_ConstructionError;
24 class Standard_OutOfRange;
25
26 //! Sensitive Entity to make a face selectable.
27 //! In some cases this class can raise Standard_ConstructionError and
28 //! Standard_OutOfRange exceptions from its member Select3D_PointData
29 //! myPolyg.
30 class Select3D_SensitivePoly : public Select3D_SensitiveSet
31 {
32   DEFINE_STANDARD_RTTIEXT(Select3D_SensitivePoly, Select3D_SensitiveSet)
33 public:
34
35   //! Constructs a sensitive face object defined by the
36   //! owner OwnerId, the array of points ThePoints, and
37   //! the sensitivity type Sensitivity.
38   //! The array of points is the outer polygon of the geometric face.
39   Standard_EXPORT Select3D_SensitivePoly (const Handle(SelectMgr_EntityOwner)& theOwnerId,
40                                           const TColgp_Array1OfPnt& thePoints,
41                                           const Standard_Boolean theIsBVHEnabled);
42
43   //! Constructs a sensitive face object defined by the
44   //! owner OwnerId, the array of points ThePoints, and
45   //! the sensitivity type Sensitivity.
46   //! The array of points is the outer polygon of the geometric face.
47   Standard_EXPORT Select3D_SensitivePoly (const Handle(SelectMgr_EntityOwner)& theOwnerId,
48                                           const Handle(TColgp_HArray1OfPnt)& thePoints,
49                                           const Standard_Boolean theIsBVHEnabled);
50
51   //! Constructs the sensitive circle object defined by the
52   //! owner OwnerId, the circle Circle, the Boolean
53   //! FilledCircle and the number of points NbOfPoints.
54   Standard_EXPORT Select3D_SensitivePoly (const Handle(SelectMgr_EntityOwner)& theOwnerId,
55                                           const Standard_Boolean theIsBVHEnabled,
56                                           const Standard_Integer theNbPnts = 6);
57
58   //! Returns the amount of segments in poly
59   Standard_EXPORT virtual Standard_Integer NbSubElements() const Standard_OVERRIDE;
60
61   //! Returns the 3D points of the array used at construction time.
62   void Points3D (Handle(TColgp_HArray1OfPnt)& theHArrayOfPnt)
63   {
64     Standard_Integer aSize = myPolyg.Size();
65     theHArrayOfPnt = new TColgp_HArray1OfPnt (1,aSize);
66     for(Standard_Integer anIndex = 1; anIndex <= aSize; anIndex++)
67     {
68       theHArrayOfPnt->SetValue (anIndex, myPolyg.Pnt (anIndex-1));
69     }
70   }
71
72   //! Return array bounds.
73   void ArrayBounds (Standard_Integer& theLow,
74                     Standard_Integer& theUp) const
75   {
76     theLow = 0;
77     theUp = myPolyg.Size() - 1;
78   }
79
80   //! Return point.
81   gp_Pnt GetPoint3d (const Standard_Integer thePntIdx) const
82   {
83     return (thePntIdx >= 0 && thePntIdx < myPolyg.Size())
84          ? myPolyg.Pnt (thePntIdx)
85          : gp_Pnt();
86   }
87
88   //! Returns bounding box of a polygon. If location
89   //! transformation is set, it will be applied
90   Standard_EXPORT virtual Select3D_BndBox3d BoundingBox() Standard_OVERRIDE;
91
92   //! Returns center of the point set. If location transformation
93   //! is set, it will be applied
94   Standard_EXPORT virtual gp_Pnt CenterOfGeometry() const Standard_OVERRIDE;
95
96   //! Returns the amount of segments of the poly
97   Standard_EXPORT virtual Standard_Integer Size() const Standard_OVERRIDE;
98
99   //! Returns bounding box of segment with index theIdx
100   Standard_EXPORT virtual Select3D_BndBox3d Box (const Standard_Integer theIdx) const Standard_OVERRIDE;
101
102   //! Returns geometry center of sensitive entity index theIdx in the vector along
103   //! the given axis theAxis
104   Standard_EXPORT virtual Standard_Real Center (const Standard_Integer theIdx,
105                                                 const Standard_Integer theAxis) const Standard_OVERRIDE;
106
107   //! Swaps items with indexes theIdx1 and theIdx2 in the vector
108   Standard_EXPORT virtual void Swap (const Standard_Integer theIdx1,
109                                      const Standard_Integer theIdx2) Standard_OVERRIDE;
110
111   //! Dumps the content of me into the stream
112   Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const Standard_OVERRIDE;
113
114 protected:
115
116   //! Checks whether the segment with index theIdx overlaps the current selecting volume
117   Standard_EXPORT virtual Standard_Boolean overlapsElement (SelectBasics_PickResult& thePickResult,
118                                                             SelectBasics_SelectingVolumeManager& theMgr,
119                                                             Standard_Integer theElemIdx,
120                                                             Standard_Boolean theIsFullInside) Standard_OVERRIDE;
121
122   //! Checks whether the entity with index theIdx is inside the current selecting volume
123   Standard_EXPORT virtual Standard_Boolean elementIsInside (SelectBasics_SelectingVolumeManager& theMgr,
124                                                             Standard_Integer theElemIdx,
125                                                             Standard_Boolean theIsFullInside) Standard_OVERRIDE;
126
127   //! Calculates distance from the 3d projection of used-picked screen point
128   //! to center of the geometry
129   Standard_EXPORT virtual Standard_Real distanceToCOG (SelectBasics_SelectingVolumeManager& theMgr) Standard_OVERRIDE;
130
131 protected:
132
133   Select3D_PointData              myPolyg;              //!< Points of the poly
134   mutable gp_Pnt                  myCOG;                //!< Center of the poly
135   Handle(TColStd_HArray1OfInteger) mySegmentIndexes;     //!< Segment indexes for BVH tree build
136   Select3D_BndBox3d               myBndBox;             //!< Bounding box of the poly
137   mutable Standard_Boolean        myIsComputed;         //!< Is true if all the points and data structures of polygon are initialized
138 };
139
140 DEFINE_STANDARD_HANDLE(Select3D_SensitivePoly, Select3D_SensitiveSet)
141
142 #endif // _Select3D_SensitivePoly_HeaderFile