Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 1996-10-17 |
2 | // Created by: Odile OLIVIER | |
3 | // Copyright (c) 1996-1999 Matra Datavision | |
973c2be1 | 4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e | 5 | // |
973c2be1 | 6 | // This file is part of Open CASCADE Technology software library. |
b311480e | 7 | // |
d5f74e42 | 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 | |
973c2be1 | 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. | |
b311480e | 13 | // |
973c2be1 | 14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. | |
7fd59977 | 16 | |
f751596e | 17 | #include <Select3D_SensitiveWire.hxx> |
7fd59977 | 18 | #include <Select3D_SensitiveEntity.hxx> |
7fd59977 | 19 | #include <Precision.hxx> |
f751596e | 20 | #include <TopLoc_Location.hxx> |
7fd59977 | 21 | |
f751596e | 22 | #include <Select3D_SensitiveSegment.hxx> |
7fd59977 | 23 | |
7fd59977 | 24 | |
92efcf78 | 25 | IMPLEMENT_STANDARD_RTTIEXT(Select3D_SensitiveWire,Select3D_SensitiveSet) |
26 | ||
7fd59977 | 27 | //===================================================== |
f751596e | 28 | // Function : Select3D_SensitiveWire |
29 | // Purpose : | |
7fd59977 | 30 | //===================================================== |
f751596e | 31 | Select3D_SensitiveWire::Select3D_SensitiveWire (const Handle(SelectBasics_EntityOwner)& theOwnerId) |
32 | : Select3D_SensitiveSet (theOwnerId), | |
33 | myCenter (0.0, 0.0, 0.0) | |
7fd59977 | 34 | {} |
35 | ||
36 | //===================================================== | |
37 | // Function : Add | |
38 | // Purpose : | |
39 | //===================================================== | |
f751596e | 40 | void Select3D_SensitiveWire::Add (const Handle(Select3D_SensitiveEntity)& theSensitive) |
7fd59977 | 41 | { |
f751596e | 42 | if (!theSensitive.IsNull()) |
43 | myEntities.Append (theSensitive); | |
44 | ||
45 | Select3D_BndBox3d aBndBox = theSensitive->BoundingBox(); | |
46 | myBndBox.Combine (aBndBox); | |
47 | myCenter.ChangeCoord() += theSensitive->CenterOfGeometry().XYZ(); | |
48 | if (myEntities.Length() != 1) | |
49 | myCenter.ChangeCoord().Divide (2.0); | |
50 | myEntityIndexes.Append (myEntities.Length() - 1); | |
7fd59977 | 51 | } |
52 | ||
53 | //======================================================================= | |
f751596e | 54 | // function : NbSubElements |
55 | // purpose : Returns the amount of sub-entities | |
7fd59977 | 56 | //======================================================================= |
f751596e | 57 | Standard_Integer Select3D_SensitiveWire::NbSubElements() |
7fd59977 | 58 | { |
f751596e | 59 | return myEntities.Length(); |
7fd59977 | 60 | } |
ac04d101 | 61 | |
7fd59977 | 62 | //======================================================================= |
f751596e | 63 | // function : Size |
64 | // purpose : Returns the length of vector of sensitive entities | |
7fd59977 | 65 | //======================================================================= |
f751596e | 66 | Standard_Integer Select3D_SensitiveWire::Size() const |
7fd59977 | 67 | { |
f751596e | 68 | return myEntities.Length(); |
7fd59977 | 69 | } |
ac04d101 | 70 | |
f751596e | 71 | //======================================================================= |
72 | // function : Box | |
73 | // purpose : Returns bounding box of sensitive entity with index theIdx | |
74 | //======================================================================= | |
75 | Select3D_BndBox3d Select3D_SensitiveWire::Box (const Standard_Integer theIdx) const | |
7fd59977 | 76 | { |
f751596e | 77 | const Standard_Integer aSensitiveIdx = myEntityIndexes.Value (theIdx); |
78 | return myEntities.Value (aSensitiveIdx)->BoundingBox(); | |
7fd59977 | 79 | } |
80 | ||
f751596e | 81 | //======================================================================= |
82 | // function : Center | |
83 | // purpose : Returns geometry center of sensitive entity with index | |
84 | // theIdx in the vector along the given axis theAxis | |
85 | //======================================================================= | |
86 | Standard_Real Select3D_SensitiveWire::Center (const Standard_Integer theIdx, | |
87 | const Standard_Integer theAxis) const | |
7fd59977 | 88 | { |
f751596e | 89 | const Standard_Integer aSensitiveIdx = myEntityIndexes.Value (theIdx); |
90 | const gp_Pnt& aCenter = myEntities.Value (aSensitiveIdx)->CenterOfGeometry(); | |
91 | Standard_Real aCenterCoord = 0.0; | |
92 | aCenterCoord = theAxis == 0 ? aCenter.X() : (theAxis == 1 ? aCenter.Y() : aCenter.Z()); | |
4952a30a | 93 | |
f751596e | 94 | return aCenterCoord; |
7fd59977 | 95 | } |
96 | ||
f751596e | 97 | //======================================================================= |
98 | // function : Swap | |
99 | // purpose : Swaps items with indexes theIdx1 and theIdx2 in the vector | |
100 | //======================================================================= | |
101 | void Select3D_SensitiveWire::Swap (const Standard_Integer theIdx1, | |
102 | const Standard_Integer theIdx2) | |
7fd59977 | 103 | { |
f751596e | 104 | const Standard_Integer aSensitiveIdx1 = myEntityIndexes.Value (theIdx1); |
105 | const Standard_Integer aSensitiveIdx2 = myEntityIndexes.Value (theIdx2); | |
106 | myEntityIndexes.ChangeValue (theIdx1) = aSensitiveIdx2; | |
107 | myEntityIndexes.ChangeValue (theIdx2) = aSensitiveIdx1; | |
7fd59977 | 108 | } |
109 | ||
f751596e | 110 | // ======================================================================= |
111 | // function : overlapsElement | |
112 | // purpose : Checks whether the entity with index theIdx overlaps the | |
113 | // current selecting volume | |
114 | // ======================================================================= | |
115 | Standard_Boolean Select3D_SensitiveWire::overlapsElement (SelectBasics_SelectingVolumeManager& theMgr, | |
116 | Standard_Integer theElemIdx, | |
117 | Standard_Real& theMatchDepth) | |
7fd59977 | 118 | { |
f751596e | 119 | const Standard_Integer aSensitiveIdx = myEntityIndexes.Value (theElemIdx); |
120 | const Handle(SelectBasics_SensitiveEntity)& aSeg = myEntities.Value (aSensitiveIdx); | |
121 | SelectBasics_PickResult aMatchResult; | |
122 | if (aSeg->Matches (theMgr, aMatchResult)) | |
ac04d101 | 123 | { |
f751596e | 124 | theMatchDepth = aMatchResult.Depth(); |
125 | return Standard_True; | |
7fd59977 | 126 | } |
7fd59977 | 127 | |
f751596e | 128 | return Standard_False; |
7fd59977 | 129 | } |
130 | ||
2157d6ac | 131 | // ======================================================================= |
132 | // function : elementIsInside | |
133 | // purpose : | |
134 | // ======================================================================= | |
135 | Standard_Boolean Select3D_SensitiveWire::elementIsInside (SelectBasics_SelectingVolumeManager& theMgr, | |
136 | const Standard_Integer theElemIdx) | |
137 | { | |
138 | SelectBasics_PickResult aMatchResult; | |
139 | return myEntities.Value (myEntityIndexes.Value (theElemIdx))->Matches (theMgr, aMatchResult); | |
140 | } | |
141 | ||
f751596e | 142 | // ======================================================================= |
143 | // function : distanceToCOG | |
144 | // purpose : Calculates distance from the 3d projection of used-picked | |
145 | // screen point to center of the geometry | |
146 | // ======================================================================= | |
147 | Standard_Real Select3D_SensitiveWire::distanceToCOG (SelectBasics_SelectingVolumeManager& theMgr) | |
7fd59977 | 148 | { |
f751596e | 149 | return theMgr.DistToGeometryCenter (myCenter); |
7fd59977 | 150 | } |
151 | ||
152 | //======================================================================= | |
153 | //function : GetConnected | |
4952a30a | 154 | //purpose : |
7fd59977 | 155 | //======================================================================= |
ac04d101 | 156 | |
f751596e | 157 | Handle(Select3D_SensitiveEntity) Select3D_SensitiveWire::GetConnected() |
7fd59977 | 158 | { |
f751596e | 159 | Handle(Select3D_SensitiveWire) aNewEntity = new Select3D_SensitiveWire (myOwnerId); |
160 | for (Standard_Integer anEntityIdx = 0; anEntityIdx < myEntities.Length(); anEntityIdx++) | |
161 | aNewEntity->Add (myEntities(anEntityIdx)->GetConnected()); | |
7fd59977 | 162 | |
f751596e | 163 | return aNewEntity; |
7fd59977 | 164 | } |
165 | ||
7fd59977 | 166 | //======================================================================= |
167 | //function : GetEdges | |
4952a30a | 168 | //purpose : returns the sensitive edges stored in this wire |
7fd59977 | 169 | //======================================================================= |
f751596e | 170 | const NCollection_Vector<Handle(Select3D_SensitiveEntity)>& Select3D_SensitiveWire::GetEdges() |
7fd59977 | 171 | { |
f751596e | 172 | return myEntities; |
7fd59977 | 173 | } |
174 | ||
175 | //============================================================================= | |
176 | // Function : GetLastDetected | |
4952a30a | 177 | // Purpose : |
7fd59977 | 178 | //============================================================================= |
179 | Handle(Select3D_SensitiveEntity) Select3D_SensitiveWire::GetLastDetected() const | |
180 | { | |
181 | Handle(Select3D_SensitiveEntity) aRes; | |
182 | ||
f751596e | 183 | if (myDetectedIdx >= 0 && myDetectedIdx < myEntities.Length()) |
184 | { | |
185 | const Standard_Integer aSensitiveIdx = myEntityIndexes.Value (myDetectedIdx); | |
186 | aRes = myEntities.Value (aSensitiveIdx); | |
187 | } | |
7fd59977 | 188 | |
189 | return aRes; | |
190 | } | |
ac04d101 SA |
191 | |
192 | //======================================================================= | |
193 | //function : Set | |
194 | //purpose : | |
195 | //======================================================================= | |
f751596e | 196 | void Select3D_SensitiveWire::Set (const Handle(SelectBasics_EntityOwner)& theOwnerId) |
ac04d101 | 197 | { |
f751596e | 198 | Select3D_SensitiveEntity::Set (theOwnerId); |
ac04d101 SA |
199 | |
200 | // Set TheOwnerId for each element of sensitive wire | |
f751596e | 201 | for (Standard_Integer anEntityIdx = 0; anEntityIdx < myEntities.Length(); ++anEntityIdx) |
ac04d101 | 202 | { |
f751596e | 203 | myEntities.Value (anEntityIdx)->Set (theOwnerId); |
ac04d101 SA |
204 | } |
205 | } | |
f751596e | 206 | |
207 | //======================================================================= | |
208 | // function : BoundingBox | |
209 | // purpose : Returns bounding box of the wire. If location | |
210 | // transformation is set, it will be applied | |
211 | //======================================================================= | |
212 | Select3D_BndBox3d Select3D_SensitiveWire::BoundingBox() | |
213 | { | |
214 | if (myBndBox.IsValid()) | |
215 | return myBndBox; | |
216 | ||
217 | for (Standard_Integer aSensitiveIdx = 0; aSensitiveIdx < myEntities.Length(); ++aSensitiveIdx) | |
218 | { | |
219 | myBndBox.Combine (myEntities.Value (aSensitiveIdx)->BoundingBox()); | |
220 | } | |
221 | ||
222 | return myBndBox; | |
223 | } | |
224 | ||
225 | //======================================================================= | |
226 | // function : CenterOfGeometry | |
227 | // purpose : Returns center of the wire. If location transformation | |
228 | // is set, it will be applied | |
229 | //======================================================================= | |
230 | gp_Pnt Select3D_SensitiveWire::CenterOfGeometry() const | |
231 | { | |
232 | return myCenter; | |
233 | } |