1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 #ifndef _Select3D_SensitivePoly_HeaderFile
15 #define _Select3D_SensitivePoly_HeaderFile
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>
23 class Standard_ConstructionError;
24 class Standard_OutOfRange;
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
30 class Select3D_SensitivePoly : public Select3D_SensitiveSet
32 DEFINE_STANDARD_RTTIEXT(Select3D_SensitivePoly, Select3D_SensitiveSet)
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);
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);
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);
58 //! Returns the amount of segments in poly
59 Standard_EXPORT virtual Standard_Integer NbSubElements() const Standard_OVERRIDE;
61 //! Returns the 3D points of the array used at construction time.
62 void Points3D (Handle(TColgp_HArray1OfPnt)& theHArrayOfPnt)
64 Standard_Integer aSize = myPolyg.Size();
65 theHArrayOfPnt = new TColgp_HArray1OfPnt (1,aSize);
66 for(Standard_Integer anIndex = 1; anIndex <= aSize; anIndex++)
68 theHArrayOfPnt->SetValue (anIndex, myPolyg.Pnt (anIndex-1));
72 //! Return array bounds.
73 void ArrayBounds (Standard_Integer& theLow,
74 Standard_Integer& theUp) const
77 theUp = myPolyg.Size() - 1;
81 gp_Pnt GetPoint3d (const Standard_Integer thePntIdx) const
83 return (thePntIdx >= 0 && thePntIdx < myPolyg.Size())
84 ? myPolyg.Pnt (thePntIdx)
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;
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;
96 //! Returns the amount of segments of the poly
97 Standard_EXPORT virtual Standard_Integer Size() const Standard_OVERRIDE;
99 //! Returns bounding box of segment with index theIdx
100 Standard_EXPORT virtual Select3D_BndBox3d Box (const Standard_Integer theIdx) const Standard_OVERRIDE;
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;
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;
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;
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;
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;
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;
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
140 DEFINE_STANDARD_HANDLE(Select3D_SensitivePoly, Select3D_SensitiveSet)
142 #endif // _Select3D_SensitivePoly_HeaderFile