Commit | Line | Data |
---|---|---|
bbf32d01 K |
1 | // Copyright: Matra-Datavision 1995 |
2 | // File: StdSelect_BRepSelectionTool.cxx | |
3 | // Created: Tue Mar 14 14:09:28 1995 | |
4 | // Author: Robert COUBLANC | |
5 | // <rob> | |
6 | ||
7fd59977 | 7 | #include <StdSelect_BRepSelectionTool.ixx> |
8 | #include <GeomAdaptor_Curve.hxx> | |
9 | #include <BRepAdaptor_Curve.hxx> | |
10 | #include <TopTools_IndexedMapOfShape.hxx> | |
11 | #include <TopExp.hxx> | |
12 | #include <TopExp_Explorer.hxx> | |
13 | #include <BRepTools_WireExplorer.hxx> | |
14 | #include <Select3D_SensitivePoint.hxx> | |
15 | #include <StdSelect_BRepOwner.hxx> | |
16 | #include <TopoDS.hxx> | |
17 | #include <BRepAdaptor_Curve.hxx> | |
18 | #include <BRepAdaptor_Surface.hxx> | |
19 | #include <GeomAbs_SurfaceType.hxx> | |
20 | #include <BRepBndLib.hxx> | |
21 | #include <Bnd_Box.hxx> | |
22 | #include <BRep_Tool.hxx> | |
23 | #include <Geom_Circle.hxx> | |
24 | #include <Select3D_SensitiveCircle.hxx> | |
25 | #include <Select3D_SensitiveCurve.hxx> | |
26 | #include <Select3D_SensitiveSegment.hxx> | |
27 | #include <Select3D_SensitiveWire.hxx> | |
28 | #include <Select3D_SensitiveFace.hxx> | |
29 | #include <Select3D_SensitiveBox.hxx> | |
30 | #include <Select3D_SensitiveTriangulation.hxx> | |
31 | #include <Select3D_SensitiveTriangle.hxx> | |
32 | #include <Select3D_SensitiveGroup.hxx> | |
33 | ||
34 | #include <Select3D_ListIteratorOfListOfSensitive.hxx> | |
35 | #include <Select3D_ListOfSensitiveTriangle.hxx> | |
36 | #include <TColgp_HArray1OfPnt.hxx> | |
37 | #include <TColgp_SequenceOfPnt.hxx> | |
38 | #include <TColStd_Array1OfReal.hxx> | |
39 | #include <BRep_Tool.hxx> | |
40 | #include <BRepTools.hxx> | |
41 | #include <Select3D_TypeOfSensitivity.hxx> | |
42 | #include <Precision.hxx> | |
43 | #include <gp_Circ.hxx> | |
bbf32d01 K |
44 | #include <GCPnts_TangentialDeflection.hxx> |
45 | #include <TopoDS_Wire.hxx> | |
7fd59977 | 46 | #include <Poly_Array1OfTriangle.hxx> |
47 | #include <Poly_Polygon3D.hxx> | |
48 | #include <Poly_PolygonOnTriangulation.hxx> | |
49 | #include <Poly_Triangulation.hxx> | |
50 | #include <BRepMesh_IncrementalMesh.hxx> | |
51 | #include <Standard_NullObject.hxx> | |
52 | #include <Standard_ErrorHandler.hxx> | |
53 | ||
7fd59977 | 54 | //================================================== |
bbf32d01 K |
55 | // Function: Load |
56 | // Purpose : | |
57 | //================================================== | |
7fd59977 | 58 | void StdSelect_BRepSelectionTool |
bbf32d01 K |
59 | ::Load (const Handle(SelectMgr_Selection)& theSelection, |
60 | const TopoDS_Shape& theShape, | |
61 | const TopAbs_ShapeEnum theType, | |
62 | const Standard_Real theDeflection, | |
63 | const Standard_Real theDeviationAngle, | |
64 | const Standard_Boolean isAutoTriangulation, | |
65 | const Standard_Integer thePriority, | |
66 | const Standard_Integer theNbPOnEdge, | |
67 | const Standard_Real theMaxParam) | |
7fd59977 | 68 | { |
bbf32d01 | 69 | Standard_Integer aPriority = (thePriority == -1) ? GetStandardPriority (theShape, theType) : thePriority; |
3c34883c O |
70 | |
71 | if( isAutoTriangulation && !BRepTools::Triangulation (theShape, Precision::Infinite()) ) | |
72 | { | |
73 | BRepMesh_IncrementalMesh(theShape, theDeflection, Standard_False, theDeviationAngle); | |
74 | } | |
75 | ||
bbf32d01 K |
76 | Handle(StdSelect_BRepOwner) aBrepOwner; |
77 | switch (theType) | |
78 | { | |
79 | case TopAbs_VERTEX: | |
80 | case TopAbs_EDGE: | |
81 | case TopAbs_WIRE: | |
82 | case TopAbs_FACE: | |
83 | case TopAbs_SHELL: | |
84 | case TopAbs_SOLID: | |
85 | case TopAbs_COMPSOLID: | |
7fd59977 | 86 | { |
bbf32d01 K |
87 | TopTools_IndexedMapOfShape aSubShapes; |
88 | TopExp::MapShapes (theShape, theType, aSubShapes); | |
89 | ||
90 | Standard_Boolean isComesFromDecomposition = !((aSubShapes.Extent() == 1) && (theShape == aSubShapes (1))); | |
91 | for (Standard_Integer aShIndex = 1; aShIndex <= aSubShapes.Extent(); ++aShIndex) | |
92 | { | |
93 | const TopoDS_Shape& aSubShape = aSubShapes (aShIndex); | |
94 | aBrepOwner = new StdSelect_BRepOwner (aSubShape, aPriority, isComesFromDecomposition); | |
95 | ComputeSensitive (aSubShape, aBrepOwner, | |
96 | theSelection, | |
97 | theDeflection, | |
98 | theDeviationAngle, | |
99 | theNbPOnEdge, | |
100 | theMaxParam, | |
101 | isAutoTriangulation); | |
7fd59977 | 102 | } |
103 | break; | |
104 | } | |
bbf32d01 | 105 | default: |
7fd59977 | 106 | { |
bbf32d01 K |
107 | aBrepOwner = new StdSelect_BRepOwner (theShape, aPriority); |
108 | ComputeSensitive (theShape, aBrepOwner, | |
109 | theSelection, | |
110 | theDeflection, | |
111 | theDeviationAngle, | |
112 | theNbPOnEdge, | |
113 | theMaxParam, | |
114 | isAutoTriangulation); | |
7fd59977 | 115 | } |
7fd59977 | 116 | } |
117 | } | |
118 | ||
bbf32d01 K |
119 | //================================================== |
120 | // Function: Load | |
121 | // Purpose : | |
122 | //================================================== | |
7fd59977 | 123 | void StdSelect_BRepSelectionTool |
bbf32d01 K |
124 | ::Load (const Handle(SelectMgr_Selection)& theSelection, |
125 | const Handle(SelectMgr_SelectableObject)& theSelectableObj, | |
126 | const TopoDS_Shape& theShape, | |
127 | const TopAbs_ShapeEnum theType, | |
128 | const Standard_Real theDeflection, | |
129 | const Standard_Real theDeviationAngle, | |
130 | const Standard_Boolean isAutoTriangulation, | |
131 | const Standard_Integer thePriority, | |
132 | const Standard_Integer theNbPOnEdge, | |
133 | const Standard_Real theMaxParam) | |
7fd59977 | 134 | { |
bbf32d01 K |
135 | Load (theSelection, |
136 | theShape, | |
137 | theType, | |
7fd59977 | 138 | theDeflection, |
139 | theDeviationAngle, | |
bbf32d01 K |
140 | isAutoTriangulation, |
141 | thePriority, | |
142 | theNbPOnEdge, | |
143 | theMaxParam); | |
144 | ||
145 | // loading of selectables... | |
146 | for (theSelection->Init(); theSelection->More(); theSelection->Next()) | |
147 | { | |
148 | Handle(SelectMgr_EntityOwner) anOwner | |
149 | = Handle(SelectMgr_EntityOwner)::DownCast (theSelection->Sensitive()->OwnerId()); | |
150 | anOwner->Set (theSelectableObj); | |
7fd59977 | 151 | } |
152 | } | |
153 | ||
bbf32d01 K |
154 | //================================================== |
155 | // Function: ComputeSensitive | |
156 | // Purpose : | |
157 | //================================================== | |
7fd59977 | 158 | void StdSelect_BRepSelectionTool |
bbf32d01 K |
159 | ::ComputeSensitive (const TopoDS_Shape& theShape, |
160 | const Handle(StdSelect_BRepOwner)& theOwner, | |
161 | const Handle(SelectMgr_Selection)& theSelection, | |
162 | const Standard_Real theDeflection, | |
163 | const Standard_Real theDeviationAngle, | |
164 | const Standard_Integer theNbPOnEdge, | |
165 | const Standard_Real theMaxParam, | |
166 | const Standard_Boolean isAutoTriangulation) | |
7fd59977 | 167 | { |
bbf32d01 K |
168 | switch (theShape.ShapeType()) |
169 | { | |
170 | case TopAbs_VERTEX: | |
171 | { | |
172 | theSelection->Add (new Select3D_SensitivePoint | |
173 | (theOwner, BRep_Tool::Pnt (TopoDS::Vertex (theShape)))); | |
7fd59977 | 174 | break; |
175 | } | |
bbf32d01 K |
176 | case TopAbs_EDGE: |
177 | { | |
178 | Handle(Select3D_SensitiveEntity) aSensitive; | |
179 | GetEdgeSensitive (theShape, theOwner, theSelection, | |
180 | theDeflection, theDeviationAngle, theNbPOnEdge, theMaxParam, | |
181 | aSensitive); | |
182 | if (!aSensitive.IsNull()) | |
183 | { | |
184 | theSelection->Add (aSensitive); | |
185 | } | |
7fd59977 | 186 | break; |
187 | } | |
bbf32d01 | 188 | case TopAbs_WIRE: |
7fd59977 | 189 | { |
bbf32d01 | 190 | BRepTools_WireExplorer aWireExp (TopoDS::Wire (theShape)); |
7fd59977 | 191 | Handle (Select3D_SensitiveEntity) aSensitive; |
bbf32d01 K |
192 | Handle (Select3D_SensitiveWire) aWireSensitive = new Select3D_SensitiveWire (theOwner); |
193 | theSelection->Add (aWireSensitive); | |
194 | while (aWireExp.More()) | |
195 | { | |
196 | GetEdgeSensitive (aWireExp.Current(), theOwner, theSelection, | |
197 | theDeflection, theDeviationAngle, theNbPOnEdge, theMaxParam, | |
198 | aSensitive); | |
199 | if (!aSensitive.IsNull()) | |
200 | { | |
201 | aWireSensitive->Add (aSensitive); | |
202 | } | |
203 | aWireExp.Next(); | |
7fd59977 | 204 | } |
205 | break; | |
206 | } | |
bbf32d01 | 207 | case TopAbs_FACE: |
7fd59977 | 208 | { |
bbf32d01 K |
209 | const TopoDS_Face& aFace = TopoDS::Face (theShape); |
210 | Select3D_ListOfSensitive aSensitiveList; | |
211 | GetSensitiveForFace (aFace, theOwner, | |
212 | aSensitiveList, | |
213 | isAutoTriangulation, theNbPOnEdge, theMaxParam); | |
214 | for (Select3D_ListIteratorOfListOfSensitive aSensIter (aSensitiveList); | |
215 | aSensIter.More(); aSensIter.Next()) | |
216 | { | |
217 | theSelection->Add (aSensIter.Value()); | |
218 | } | |
7fd59977 | 219 | break; |
220 | } | |
bbf32d01 | 221 | case TopAbs_SHELL: |
bbf32d01 K |
222 | case TopAbs_SOLID: |
223 | case TopAbs_COMPSOLID: | |
7fd59977 | 224 | { |
bbf32d01 K |
225 | TopTools_IndexedMapOfShape aSubfacesMap; |
226 | TopExp::MapShapes (theShape, TopAbs_FACE, aSubfacesMap); | |
227 | for (Standard_Integer aShIndex = 1; aShIndex <= aSubfacesMap.Extent(); ++aShIndex) | |
228 | { | |
229 | ComputeSensitive (aSubfacesMap (aShIndex), theOwner, | |
230 | theSelection, | |
231 | theDeflection, theDeviationAngle, theNbPOnEdge, theMaxParam, isAutoTriangulation); | |
232 | } | |
7fd59977 | 233 | break; |
234 | } | |
bbf32d01 K |
235 | case TopAbs_COMPOUND: |
236 | default: | |
7fd59977 | 237 | { |
bbf32d01 K |
238 | TopExp_Explorer anExp; |
239 | // sub-vertices | |
240 | for (anExp.Init (theShape, TopAbs_VERTEX, TopAbs_EDGE); anExp.More(); anExp.Next()) | |
241 | { | |
242 | ComputeSensitive (anExp.Current(), theOwner, | |
243 | theSelection, | |
244 | theDeflection, theDeviationAngle, theNbPOnEdge, theMaxParam, isAutoTriangulation); | |
245 | } | |
246 | // sub-edges | |
247 | for (anExp.Init (theShape, TopAbs_EDGE, TopAbs_FACE); anExp.More(); anExp.Next()) | |
248 | { | |
249 | ComputeSensitive (anExp.Current(), theOwner, | |
250 | theSelection, | |
251 | theDeflection, theDeviationAngle, theNbPOnEdge, theMaxParam, isAutoTriangulation); | |
252 | } | |
253 | // sub-wires | |
254 | for (anExp.Init (theShape, TopAbs_WIRE, TopAbs_FACE); anExp.More(); anExp.Next()) | |
255 | { | |
256 | ComputeSensitive (anExp.Current(), theOwner, | |
257 | theSelection, | |
258 | theDeflection, theDeviationAngle, theNbPOnEdge, theMaxParam, isAutoTriangulation); | |
259 | } | |
7fd59977 | 260 | |
bbf32d01 K |
261 | // sub-faces |
262 | TopTools_IndexedMapOfShape aSubfacesMap; | |
263 | TopExp::MapShapes (theShape, TopAbs_FACE, aSubfacesMap); | |
264 | for (Standard_Integer aShIndex = 1; aShIndex <= aSubfacesMap.Extent(); ++aShIndex) | |
265 | { | |
266 | ComputeSensitive (aSubfacesMap (aShIndex), theOwner, | |
267 | theSelection, | |
268 | theDeflection, theDeviationAngle, theNbPOnEdge, theMaxParam, isAutoTriangulation); | |
269 | } | |
270 | } | |
271 | } | |
7fd59977 | 272 | } |
273 | ||
bbf32d01 K |
274 | //================================================== |
275 | // Function: GetPointsFromPolygon | |
276 | // Purpose : | |
277 | //================================================== | |
7fd59977 | 278 | static Handle(TColgp_HArray1OfPnt) GetPointsFromPolygon (const TopoDS_Edge& theEdge, |
279 | const Standard_Real theDeflection) | |
280 | { | |
281 | Handle(TColgp_HArray1OfPnt) aResultPoints; | |
282 | ||
283 | Standard_Real fi, la; | |
284 | Handle(Geom_Curve) CC3d = BRep_Tool::Curve (theEdge, fi, la); | |
285 | ||
286 | TopLoc_Location aLocation; | |
287 | Handle(Poly_Polygon3D) aPolygon = BRep_Tool::Polygon3D (theEdge, aLocation); | |
288 | if (!aPolygon.IsNull()) | |
289 | { | |
290 | Standard_Boolean isOK = aPolygon->Deflection() <= theDeflection; | |
291 | isOK = isOK || (CC3d.IsNull()); | |
292 | if (isOK) | |
293 | { | |
294 | const TColgp_Array1OfPnt& aNodes = aPolygon->Nodes(); | |
295 | aResultPoints = new TColgp_HArray1OfPnt (1, aNodes.Length()); | |
296 | if (aLocation.IsIdentity()) | |
297 | { | |
298 | for (Standard_Integer aNodeId (aNodes.Lower()), aPntId (1); aNodeId <= aNodes.Upper(); ++aNodeId, ++aPntId) | |
299 | { | |
300 | aResultPoints->SetValue (aPntId, aNodes.Value (aNodeId)); | |
301 | } | |
302 | } | |
303 | else | |
304 | { | |
305 | for (Standard_Integer aNodeId (aNodes.Lower()), aPntId (1); aNodeId <= aNodes.Upper(); ++aNodeId, ++aPntId) | |
306 | { | |
307 | aResultPoints->SetValue (aPntId, aNodes.Value (aNodeId).Transformed (aLocation)); | |
308 | } | |
309 | } | |
310 | return aResultPoints; | |
311 | } | |
312 | } | |
313 | ||
314 | Handle(Poly_Triangulation) aTriangulation; | |
315 | Handle(Poly_PolygonOnTriangulation) anHIndices; | |
316 | BRep_Tool::PolygonOnTriangulation (theEdge, anHIndices, aTriangulation, aLocation); | |
317 | if (!anHIndices.IsNull()) | |
318 | { | |
319 | Standard_Boolean isOK = anHIndices->Deflection() <= theDeflection; | |
320 | isOK = isOK || (CC3d.IsNull()); | |
321 | if (isOK) | |
322 | { | |
323 | const TColStd_Array1OfInteger& anIndices = anHIndices->Nodes(); | |
324 | const TColgp_Array1OfPnt& aNodes = aTriangulation->Nodes(); | |
325 | ||
326 | aResultPoints = new TColgp_HArray1OfPnt (1, anIndices.Length()); | |
327 | ||
328 | if (aLocation.IsIdentity()) | |
329 | { | |
330 | for (Standard_Integer anIndex (anIndices.Lower()), aPntId (1); anIndex <= anIndices.Upper(); ++anIndex, ++aPntId) | |
331 | { | |
332 | aResultPoints->SetValue (aPntId, aNodes (anIndices (anIndex))); | |
333 | } | |
334 | } | |
335 | else | |
336 | { | |
337 | for (Standard_Integer anIndex (anIndices.Lower()), aPntId (1); anIndex <= anIndices.Upper(); ++anIndex, ++aPntId) | |
338 | { | |
339 | aResultPoints->SetValue (aPntId, aNodes (anIndices (anIndex)).Transformed (aLocation)); | |
340 | } | |
341 | } | |
342 | return aResultPoints; | |
343 | } | |
344 | } | |
345 | return aResultPoints; | |
346 | } | |
347 | ||
bbf32d01 K |
348 | //================================================== |
349 | // Function: FindLimits | |
350 | // Purpose : | |
351 | //================================================== | |
352 | static Standard_Boolean FindLimits (const Adaptor3d_Curve& theCurve, | |
353 | const Standard_Real theLimit, | |
354 | Standard_Real& theFirst, | |
355 | Standard_Real& theLast) | |
7fd59977 | 356 | { |
bbf32d01 K |
357 | theFirst = theCurve.FirstParameter(); |
358 | theLast = theCurve.LastParameter(); | |
359 | Standard_Boolean isFirstInf = Precision::IsNegativeInfinite (theFirst); | |
360 | Standard_Boolean isLastInf = Precision::IsPositiveInfinite (theLast); | |
361 | if (isFirstInf || isLastInf) | |
362 | { | |
363 | gp_Pnt aPnt1, aPnt2; | |
364 | Standard_Real aDelta = 1.0; | |
365 | Standard_Integer anIterCount = 0; | |
366 | if (isFirstInf && isLastInf) | |
367 | { | |
7fd59977 | 368 | do { |
bbf32d01 K |
369 | if (anIterCount++ >= 100000) return Standard_False; |
370 | aDelta *= 2.0; | |
371 | theFirst = - aDelta; | |
372 | theLast = aDelta; | |
373 | theCurve.D0 (theFirst, aPnt1); | |
374 | theCurve.D0 (theLast, aPnt2); | |
375 | } while (aPnt1.Distance (aPnt2) < theLimit); | |
7fd59977 | 376 | } |
bbf32d01 K |
377 | else if (isFirstInf) |
378 | { | |
379 | theCurve.D0 (theLast, aPnt2); | |
7fd59977 | 380 | do { |
bbf32d01 K |
381 | if (anIterCount++ >= 100000) return Standard_False; |
382 | aDelta *= 2.0; | |
383 | theFirst = theLast - aDelta; | |
384 | theCurve.D0 (theFirst, aPnt1); | |
385 | } while (aPnt1.Distance (aPnt2) < theLimit); | |
7fd59977 | 386 | } |
bbf32d01 K |
387 | else if (isLastInf) |
388 | { | |
389 | theCurve.D0 (theFirst, aPnt1); | |
7fd59977 | 390 | do { |
bbf32d01 K |
391 | if (anIterCount++ >= 100000) return Standard_False; |
392 | aDelta *= 2.0; | |
393 | theLast = theFirst + aDelta; | |
394 | theCurve.D0 (theLast, aPnt2); | |
395 | } while (aPnt1.Distance (aPnt2) < theLimit); | |
7fd59977 | 396 | } |
bbf32d01 | 397 | } |
7fd59977 | 398 | return Standard_True; |
399 | } | |
400 | ||
401 | //===================================================== | |
402 | // Function : GetEdgeSensitive | |
bbf32d01 | 403 | // Purpose : create a sensitive edge to add it |
81bba717 | 404 | // in computeselection to "aselection" (case of selection of an edge) |
405 | // or to "aSensitiveWire" (case of selection of a wire; in this case, | |
406 | // the sensitive wire is added to "aselection" ) | |
407 | // odl - for selection by rectangle - | |
bbf32d01 | 408 | //===================================================== |
7fd59977 | 409 | void StdSelect_BRepSelectionTool |
bbf32d01 K |
410 | ::GetEdgeSensitive (const TopoDS_Shape& theShape, |
411 | const Handle(StdSelect_BRepOwner)& theOwner, | |
412 | const Handle(SelectMgr_Selection)& theSelection, | |
7fd59977 | 413 | const Standard_Real theDeflection, |
414 | const Standard_Real theDeviationAngle, | |
bbf32d01 K |
415 | const Standard_Integer theNbPOnEdge, |
416 | const Standard_Real theMaxParam, | |
417 | Handle(Select3D_SensitiveEntity)& theSensitive) | |
7fd59977 | 418 | { |
bbf32d01 K |
419 | const TopoDS_Edge& anEdge = TopoDS::Edge (theShape); |
420 | BRepAdaptor_Curve cu3d; | |
421 | try { | |
422 | OCC_CATCH_SIGNALS | |
423 | cu3d.Initialize (anEdge); | |
424 | } catch (Standard_NullObject) { | |
425 | return; | |
426 | } | |
7fd59977 | 427 | |
428 | // try to get points from existing polygons | |
bbf32d01 | 429 | Handle(TColgp_HArray1OfPnt) aPoints = GetPointsFromPolygon (anEdge, theDeflection); |
7fd59977 | 430 | if (!aPoints.IsNull() && aPoints->Length() > 0) |
431 | { | |
bbf32d01 | 432 | theSensitive = new Select3D_SensitiveCurve (theOwner, aPoints); |
7fd59977 | 433 | return; |
434 | } | |
435 | ||
bbf32d01 K |
436 | Standard_Real aParamFirst = cu3d.FirstParameter(); |
437 | Standard_Real aParamLast = cu3d.LastParameter(); | |
438 | switch (cu3d.GetType()) | |
439 | { | |
440 | case GeomAbs_Line: | |
7fd59977 | 441 | { |
bbf32d01 K |
442 | BRep_Tool::Range (anEdge, aParamFirst, aParamLast); |
443 | theSensitive = new Select3D_SensitiveSegment (theOwner, | |
444 | cu3d.Value (aParamFirst), | |
445 | cu3d.Value (aParamLast)); | |
7fd59977 | 446 | break; |
447 | } | |
bbf32d01 | 448 | case GeomAbs_Circle: |
7fd59977 | 449 | { |
bbf32d01 K |
450 | Handle (Geom_Circle) aCircle = new Geom_Circle (cu3d.Circle()); |
451 | if (aCircle->Radius() <= Precision::Confusion()) | |
452 | { | |
453 | theSelection->Add (new Select3D_SensitivePoint (theOwner, aCircle->Location())); | |
454 | } | |
7fd59977 | 455 | else |
bbf32d01 K |
456 | { |
457 | theSensitive = new Select3D_SensitiveCircle (theOwner, aCircle, | |
458 | aParamFirst, aParamLast, Standard_False, 16); | |
459 | } | |
7fd59977 | 460 | break; |
461 | } | |
bbf32d01 | 462 | default: |
7fd59977 | 463 | { |
bbf32d01 K |
464 | // reproduce drawing behaviour |
465 | // TODO: remove copy-paste from StdPrs_Curve and some others... | |
466 | if (FindLimits (cu3d, theMaxParam, aParamFirst, aParamLast)) | |
7fd59977 | 467 | { |
468 | Standard_Integer aNbIntervals = cu3d.NbIntervals (GeomAbs_C1); | |
469 | TColStd_Array1OfReal anIntervals (1, aNbIntervals + 1); | |
470 | cu3d.Intervals (anIntervals, GeomAbs_C1); | |
471 | Standard_Real aV1, aV2; | |
472 | Standard_Integer aNumberOfPoints; | |
473 | TColgp_SequenceOfPnt aPointsSeq; | |
7fd59977 | 474 | for (Standard_Integer anIntervalId = 1; anIntervalId <= aNbIntervals; ++anIntervalId) |
475 | { | |
bbf32d01 K |
476 | aV1 = anIntervals (anIntervalId); |
477 | aV2 = anIntervals (anIntervalId + 1); | |
478 | if (aV2 > aParamFirst && aV1 < aParamLast) | |
7fd59977 | 479 | { |
bbf32d01 K |
480 | aV1 = Max (aV1, aParamFirst); |
481 | aV2 = Min (aV2, aParamLast); | |
7fd59977 | 482 | |
483 | GCPnts_TangentialDeflection anAlgo (cu3d, aV1, aV2, theDeviationAngle, theDeflection); | |
484 | aNumberOfPoints = anAlgo.NbPoints(); | |
485 | ||
bbf32d01 | 486 | for (Standard_Integer aPntId = 1; aPntId < aNumberOfPoints; ++aPntId) |
7fd59977 | 487 | { |
bbf32d01 K |
488 | aPointsSeq.Append (anAlgo.Value (aPntId)); |
489 | } | |
490 | if (aNumberOfPoints > 0 && anIntervalId == aNbIntervals) | |
491 | { | |
492 | aPointsSeq.Append (anAlgo.Value (aNumberOfPoints)); | |
7fd59977 | 493 | } |
494 | } | |
495 | } | |
496 | ||
497 | aPoints = new TColgp_HArray1OfPnt (1, aPointsSeq.Length()); | |
498 | for (Standard_Integer aPntId = 1; aPntId <= aPointsSeq.Length(); ++aPntId) | |
499 | { | |
500 | aPoints->SetValue (aPntId, aPointsSeq.Value (aPntId)); | |
501 | } | |
bbf32d01 | 502 | theSensitive = new Select3D_SensitiveCurve (theOwner, aPoints); |
7fd59977 | 503 | break; |
504 | } | |
505 | ||
506 | // simple subdivisions | |
507 | Standard_Integer nbintervals = 1; | |
bbf32d01 K |
508 | if (cu3d.GetType() == GeomAbs_BSplineCurve) |
509 | { | |
510 | nbintervals = cu3d.NbKnots() - 1; | |
511 | nbintervals = Max (1, nbintervals / 3); | |
7fd59977 | 512 | } |
bbf32d01 K |
513 | |
514 | Standard_Real aParam; | |
515 | Standard_Integer aPntNb = Max (2, theNbPOnEdge * nbintervals); | |
516 | Standard_Real aParamDelta = (aParamLast - aParamFirst) / (aPntNb - 1); | |
517 | Handle(TColgp_HArray1OfPnt) aPointArray = new TColgp_HArray1OfPnt (1, aPntNb); | |
518 | for (Standard_Integer aPntId = 1; aPntId <= aPntNb; ++aPntId) | |
519 | { | |
520 | aParam = aParamFirst + aParamDelta * (aPntId - 1); | |
521 | aPointArray->SetValue (aPntId, cu3d.Value (aParam)); | |
7fd59977 | 522 | } |
bbf32d01 | 523 | theSensitive = new Select3D_SensitiveCurve (theOwner, aPointArray); |
7fd59977 | 524 | } |
525 | break; | |
526 | } | |
527 | } | |
528 | ||
bbf32d01 K |
529 | //===================================================== |
530 | // Function : GetStandardPriority | |
531 | // Purpose : | |
532 | //===================================================== | |
533 | Standard_Integer StdSelect_BRepSelectionTool::GetStandardPriority (const TopoDS_Shape& theShape, | |
534 | const TopAbs_ShapeEnum theType) | |
7fd59977 | 535 | { |
bbf32d01 K |
536 | switch (theType) |
537 | { | |
538 | case TopAbs_VERTEX: return 8; | |
539 | case TopAbs_EDGE: return 7; | |
540 | case TopAbs_WIRE: return 6; | |
541 | case TopAbs_FACE: return 5; | |
7fd59977 | 542 | case TopAbs_SHAPE: |
543 | default: | |
bbf32d01 K |
544 | switch (theShape.ShapeType()) |
545 | { | |
546 | case TopAbs_VERTEX: return 9; | |
547 | case TopAbs_EDGE: return 8; | |
548 | case TopAbs_WIRE: return 7; | |
549 | case TopAbs_FACE: return 6; | |
550 | case TopAbs_SHELL: return 5; | |
551 | case TopAbs_COMPOUND: | |
552 | case TopAbs_COMPSOLID: | |
553 | case TopAbs_SOLID: | |
554 | case TopAbs_SHAPE: | |
555 | default: | |
556 | return 4; | |
557 | } | |
7fd59977 | 558 | } |
7fd59977 | 559 | } |
560 | ||
561 | //======================================================================= | |
562 | //function : GetSensitiveEntityForFace | |
bbf32d01 | 563 | //purpose : |
7fd59977 | 564 | //======================================================================= |
bbf32d01 K |
565 | Standard_Boolean StdSelect_BRepSelectionTool |
566 | ::GetSensitiveForFace (const TopoDS_Face& theFace, | |
567 | const Handle(StdSelect_BRepOwner)& theOwner, | |
568 | Select3D_ListOfSensitive& theSensitiveList, | |
569 | const Standard_Boolean theAutoTriangulation, | |
570 | const Standard_Integer NbPOnEdge, | |
571 | const Standard_Real theMaxParam, | |
572 | const Standard_Boolean theInteriorFlag) | |
7fd59977 | 573 | { |
81bba717 | 574 | // check if there is triangulation of the face... |
bbf32d01 K |
575 | TopLoc_Location aLoc; |
576 | Handle(Poly_Triangulation) aTriangulation = BRep_Tool::Triangulation (theFace, aLoc); | |
3c34883c | 577 | |
bbf32d01 K |
578 | if (!aTriangulation.IsNull()) |
579 | { | |
580 | Handle(Select3D_SensitiveTriangulation) STG = new Select3D_SensitiveTriangulation (theOwner, aTriangulation, aLoc, theInteriorFlag); | |
581 | theSensitiveList.Append (STG); | |
7fd59977 | 582 | return Standard_True; |
583 | } | |
584 | ||
81bba717 | 585 | // for faces with triangulation bugs or without autotriangulation .... |
586 | // very ugly and should not even exist ... | |
bbf32d01 K |
587 | BRepAdaptor_Surface BS; |
588 | BS.Initialize (theFace); | |
7fd59977 | 589 | |
bbf32d01 K |
590 | Standard_Real FirstU = BS.FirstUParameter() <= -Precision::Infinite() ? -theMaxParam : BS.FirstUParameter(); |
591 | Standard_Real LastU = BS.LastUParameter() >= Precision::Infinite() ? theMaxParam : BS.LastUParameter(); | |
592 | Standard_Real FirstV = BS.FirstVParameter() <= -Precision::Infinite() ? -theMaxParam : BS.FirstVParameter(); | |
593 | Standard_Real LastV = BS.LastVParameter() >= Precision::Infinite() ? theMaxParam : BS.LastVParameter(); | |
7fd59977 | 594 | |
bbf32d01 K |
595 | if (BS.GetType() == GeomAbs_Plane) |
596 | { | |
7fd59977 | 597 | gp_Pnt pcur; |
bbf32d01 K |
598 | Handle(TColgp_HArray1OfPnt) P = new TColgp_HArray1OfPnt (1, 5); |
599 | BS.D0 (FirstU, FirstV, pcur); | |
600 | P->SetValue (1, pcur); | |
601 | BS.D0 (LastU, FirstV, pcur); | |
602 | P->SetValue (2, pcur); | |
603 | BS.D0 (LastU, LastV, pcur); | |
604 | P->SetValue (3, pcur); | |
605 | BS.D0 (FirstU, LastV, pcur); | |
606 | P->SetValue (4, pcur); | |
607 | P->SetValue (5, P->Value (1)); | |
81bba717 | 608 | // if the plane is "infinite", it is sensitive only on the border limited by MaxParam |
bbf32d01 K |
609 | if (FirstU == -theMaxParam && LastU == theMaxParam && FirstV == -theMaxParam && LastV == theMaxParam) |
610 | { | |
611 | theSensitiveList.Append (new Select3D_SensitiveFace (theOwner, P, Select3D_TOS_BOUNDARY)); | |
612 | } | |
613 | else | |
614 | { | |
615 | Select3D_TypeOfSensitivity TS = theInteriorFlag ? Select3D_TOS_INTERIOR : Select3D_TOS_BOUNDARY; | |
616 | theSensitiveList.Append (new Select3D_SensitiveFace (theOwner, P, TS)); | |
7fd59977 | 617 | } |
618 | return Standard_True; | |
619 | } | |
bbf32d01 | 620 | |
81bba717 | 621 | // This is construction of a sevsitive polygon from the exterior contour of the face... |
622 | // It is not good at all, but... | |
7fd59977 | 623 | TopoDS_Wire aWire; |
bbf32d01 K |
624 | TopExp_Explorer anExpWiresInFace (theFace, TopAbs_WIRE); |
625 | if (anExpWiresInFace.More()) | |
626 | { | |
627 | // believing that this is the first... to be seen | |
628 | aWire = TopoDS::Wire (anExpWiresInFace.Current()); | |
629 | } | |
630 | if (aWire.IsNull()) | |
631 | { | |
632 | return Standard_False; | |
633 | } | |
7fd59977 | 634 | |
7fd59977 | 635 | TColgp_SequenceOfPnt WirePoints; |
636 | Standard_Boolean FirstExp = Standard_True; | |
bbf32d01 K |
637 | Standard_Real wf, wl; |
638 | BRepAdaptor_Curve cu3d; | |
639 | for (BRepTools_WireExplorer aWireExplorer (aWire); | |
640 | aWireExplorer.More(); aWireExplorer.Next()) | |
641 | { | |
642 | cu3d.Initialize (aWireExplorer.Current()); | |
643 | BRep_Tool::Range (aWireExplorer.Current(), wf, wl); | |
644 | if (Abs (wf - wl) <= Precision::Confusion()) | |
645 | { | |
646 | #ifdef DEB | |
7fd59977 | 647 | cout<<" StdSelect_BRepSelectionTool : Curve where ufirst = ulast ...."<<endl; |
bbf32d01 | 648 | #endif |
7fd59977 | 649 | } |
bbf32d01 K |
650 | else |
651 | { | |
652 | if (FirstExp) | |
653 | { | |
654 | if (aWireExplorer.Orientation() == TopAbs_FORWARD) | |
655 | { | |
656 | WirePoints.Append (cu3d.Value (wf)); | |
657 | } | |
658 | else | |
659 | { | |
660 | WirePoints.Append (cu3d.Value (wl)); | |
661 | } | |
662 | FirstExp = Standard_False; | |
7fd59977 | 663 | } |
bbf32d01 K |
664 | |
665 | switch (cu3d.GetType()) | |
666 | { | |
667 | case GeomAbs_Line: | |
668 | { | |
669 | WirePoints.Append (cu3d.Value ((aWireExplorer.Orientation() == TopAbs_FORWARD) ? wl : wf)); | |
670 | break; | |
671 | } | |
672 | case GeomAbs_Circle: | |
673 | { | |
c6541a0c | 674 | if (2 * M_PI - Abs (wl - wf) <= Precision::Confusion()) |
bbf32d01 K |
675 | { |
676 | if (BS.GetType() == GeomAbs_Cylinder || | |
677 | BS.GetType() == GeomAbs_Torus || | |
678 | BS.GetType() == GeomAbs_Cone || | |
679 | BS.GetType() == GeomAbs_BSplineSurface) // beuurkk pour l'instant... | |
680 | { | |
681 | Standard_Real ff = wf ,ll = wl; | |
682 | Standard_Real dw =(Max (wf, wl) - Min (wf, wl)) / (Standard_Real )Max (2, NbPOnEdge - 1); | |
683 | if (aWireExplorer.Orientation() == TopAbs_FORWARD) | |
684 | { | |
685 | for (Standard_Real wc = wf + dw; wc <= wl; wc += dw) | |
686 | { | |
687 | WirePoints.Append (cu3d.Value (wc)); | |
688 | } | |
689 | } | |
690 | else if (aWireExplorer.Orientation() == TopAbs_REVERSED) | |
691 | { | |
692 | for (Standard_Real wc = ll - dw; wc >= ff; wc -= dw) | |
693 | { | |
694 | WirePoints.Append (cu3d.Value (wc)); | |
695 | } | |
696 | } | |
697 | } | |
698 | else | |
699 | { | |
700 | if (cu3d.Circle().Radius() <= Precision::Confusion()) | |
701 | { | |
702 | theSensitiveList.Append (new Select3D_SensitivePoint (theOwner, cu3d.Circle().Location())); | |
703 | } | |
704 | else | |
705 | { | |
706 | theSensitiveList.Append (new Select3D_SensitiveCircle (theOwner, new Geom_Circle (cu3d.Circle()), theInteriorFlag, 16)); | |
707 | } | |
708 | } | |
709 | } | |
710 | else | |
711 | { | |
712 | Standard_Real ff = wf, ll = wl; | |
713 | Standard_Real dw = (Max (wf, wl) - Min (wf, wl)) / (Standard_Real )Max (2, NbPOnEdge - 1); | |
714 | if (aWireExplorer.Orientation() == TopAbs_FORWARD) | |
715 | { | |
716 | for (Standard_Real wc = wf + dw; wc <= wl; wc += dw) | |
717 | { | |
718 | WirePoints.Append (cu3d.Value (wc)); | |
719 | } | |
720 | } | |
721 | else if (aWireExplorer.Orientation() == TopAbs_REVERSED) | |
722 | { | |
723 | for (Standard_Real wc = ll - dw; wc >= ff; wc -= dw) | |
724 | { | |
725 | WirePoints.Append (cu3d.Value (wc)); | |
726 | } | |
727 | } | |
728 | } | |
729 | break; | |
730 | } | |
731 | default: | |
732 | { | |
733 | Standard_Real ff = wf, ll = wl; | |
734 | Standard_Real dw = (Max (wf, wl) - Min (wf, wl)) / (Standard_Real )Max (2, NbPOnEdge - 1); | |
735 | if (aWireExplorer.Orientation()==TopAbs_FORWARD) | |
736 | { | |
737 | for (Standard_Real wc = wf + dw; wc <= wl; wc += dw) | |
738 | { | |
739 | WirePoints.Append (cu3d.Value (wc)); | |
740 | } | |
741 | } | |
742 | else if (aWireExplorer.Orientation() == TopAbs_REVERSED) | |
743 | { | |
744 | for (Standard_Real wc = ll - dw; wc >= ff; wc -= dw) | |
745 | { | |
746 | WirePoints.Append (cu3d.Value (wc)); | |
747 | } | |
748 | } | |
749 | } | |
7fd59977 | 750 | } |
751 | } | |
752 | } | |
753 | Standard_Integer ArrayPosition = WirePoints.Length(); | |
bbf32d01 K |
754 | |
755 | Handle(TColgp_HArray1OfPnt) facepoints = new TColgp_HArray1OfPnt (1, ArrayPosition); | |
756 | for (Standard_Integer I = 1; I <= ArrayPosition; ++I) | |
757 | { | |
758 | facepoints->SetValue (I, WirePoints.Value(I)); | |
759 | } | |
760 | ||
761 | if ((facepoints->Array1()).Length() > 1) | |
762 | { //1 if only one circular edge | |
763 | Select3D_TypeOfSensitivity TS = theInteriorFlag ? Select3D_TOS_INTERIOR : Select3D_TOS_BOUNDARY; | |
764 | theSensitiveList.Append (new Select3D_SensitiveFace (theOwner, facepoints, TS)); | |
7fd59977 | 765 | } |
766 | return Standard_True; | |
767 | } |