0031642: Visualization - crash in Graphic3d_Structure::SetVisual() on redisplaying...
[occt.git] / src / Select3D / Select3D_SensitiveFace.cxx
1 // Created on: 1995-03-27
2 // Created by: Robert COUBLANC
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #include <Select3D_SensitiveFace.hxx>
18
19 #include <Select3D_SensitivePoly.hxx>
20 #include <Select3D_InteriorSensitivePointSet.hxx>
21
22 IMPLEMENT_STANDARD_RTTIEXT(Select3D_SensitiveFace,Select3D_SensitiveEntity)
23
24 //==================================================
25 // Function: Hide this constructor to the next version...
26 // Purpose : simply avoid interfering with the version update
27 //==================================================
28 Select3D_SensitiveFace::Select3D_SensitiveFace (const Handle(SelectMgr_EntityOwner)& theOwnerId,
29                                                 const TColgp_Array1OfPnt& thePoints,
30                                                 const Select3D_TypeOfSensitivity theType)
31 : Select3D_SensitiveEntity (theOwnerId),
32   mySensType (theType)
33 {
34   if (mySensType == Select3D_TOS_INTERIOR)
35   {
36     myFacePoints = new Select3D_InteriorSensitivePointSet (theOwnerId, thePoints);
37   }
38   else
39   {
40     myFacePoints = new Select3D_SensitivePoly (theOwnerId, thePoints, Standard_True);
41   }
42 }
43
44 //==================================================
45 // Function: Creation
46 // Purpose :
47 //==================================================
48 Select3D_SensitiveFace::Select3D_SensitiveFace (const Handle(SelectMgr_EntityOwner)& theOwnerId,
49                                                 const Handle(TColgp_HArray1OfPnt)& thePoints,
50                                                 const Select3D_TypeOfSensitivity theType)
51 : Select3D_SensitiveEntity (theOwnerId),
52   mySensType (theType)
53 {
54   if (mySensType == Select3D_TOS_INTERIOR)
55   {
56     myFacePoints = new Select3D_InteriorSensitivePointSet (theOwnerId, thePoints->Array1());
57   }
58   else
59   {
60     myFacePoints = new Select3D_SensitivePoly (theOwnerId, thePoints->Array1(), Standard_True);
61   }
62 }
63
64 //=======================================================================
65 // function : GetPoints
66 // purpose  : Initializes the given array theHArrayOfPnt by 3d
67 //            coordinates of vertices of the face
68 //=======================================================================
69 void Select3D_SensitiveFace::GetPoints (Handle(TColgp_HArray1OfPnt)& theHArrayOfPnt)
70 {
71   if (myFacePoints->IsKind(STANDARD_TYPE(Select3D_SensitivePoly)))
72   {
73     Handle(Select3D_SensitivePoly)::DownCast (myFacePoints)->Points3D (theHArrayOfPnt);
74   }
75   else
76   {
77     Handle(Select3D_InteriorSensitivePointSet)::DownCast (myFacePoints)->GetPoints (theHArrayOfPnt);
78   }
79
80 }
81
82 //=======================================================================
83 // function : BVH
84 // purpose  : Builds BVH tree for the face
85 //=======================================================================
86 void Select3D_SensitiveFace::BVH()
87 {
88   myFacePoints->BVH();
89 }
90
91 //=======================================================================
92 // function : Matches
93 // purpose  : Checks whether the face overlaps current selecting volume
94 //=======================================================================
95 Standard_Boolean Select3D_SensitiveFace::Matches (SelectBasics_SelectingVolumeManager& theMgr,
96                                                   SelectBasics_PickResult& thePickResult)
97 {
98   return myFacePoints->Matches (theMgr, thePickResult);
99 }
100
101 //=======================================================================
102 //function : GetConnected
103 //purpose  :
104 //=======================================================================
105 Handle(Select3D_SensitiveEntity) Select3D_SensitiveFace::GetConnected()
106 {
107   // Create a copy of this
108   Handle(TColgp_HArray1OfPnt) aPoints;
109   GetPoints (aPoints);
110
111   Handle(Select3D_SensitiveEntity) aNewEntity =
112     new Select3D_SensitiveFace (myOwnerId, aPoints, mySensType);
113
114   return aNewEntity;
115 }
116
117 //=======================================================================
118 // function : BoundingBox
119 // purpose  : Returns bounding box of the face. If location transformation
120 //            is set, it will be applied
121 //=======================================================================
122 Select3D_BndBox3d Select3D_SensitiveFace::BoundingBox()
123 {
124   return myFacePoints->BoundingBox();
125 }
126
127 //=======================================================================
128 // function : CenterOfGeometry
129 // purpose  : Returns center of the face. If location transformation
130 //            is set, it will be applied
131 //=======================================================================
132 gp_Pnt Select3D_SensitiveFace::CenterOfGeometry() const
133 {
134   return myFacePoints->CenterOfGeometry();
135 }
136
137 //=======================================================================
138 // function : NbSubElements
139 // purpose  : Returns the amount of sub-entities (points or planar convex
140 //            polygons)
141 //=======================================================================
142 Standard_Integer Select3D_SensitiveFace::NbSubElements() const
143 {
144   return myFacePoints->NbSubElements();
145 }
146
147 //=======================================================================
148 //function : DumpJson
149 //purpose  :
150 //=======================================================================
151 void Select3D_SensitiveFace::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
152 {
153   OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
154   OCCT_DUMP_BASE_CLASS (theOStream, theDepth, Select3D_SensitiveEntity)
155
156   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, mySensType)
157   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myFacePoints.get())
158 }