1 // Created on: 1995-03-14
2 // Created by: Robert COUBLANC
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <StdSelect_BRepSelectionTool.ixx>
18 #include <GeomAdaptor_Curve.hxx>
19 #include <BRepAdaptor_Curve.hxx>
20 #include <TopTools_IndexedMapOfShape.hxx>
22 #include <TopExp_Explorer.hxx>
23 #include <BRepTools_WireExplorer.hxx>
24 #include <Select3D_SensitivePoint.hxx>
25 #include <StdSelect_BRepOwner.hxx>
27 #include <BRepAdaptor_Curve.hxx>
28 #include <BRepAdaptor_Surface.hxx>
29 #include <GeomAbs_SurfaceType.hxx>
30 #include <BRepBndLib.hxx>
31 #include <Bnd_Box.hxx>
32 #include <BRep_Tool.hxx>
33 #include <Geom_Circle.hxx>
34 #include <Select3D_SensitiveEntity.hxx>
35 #include <Select3D_SensitiveCircle.hxx>
36 #include <Select3D_SensitiveCurve.hxx>
37 #include <Select3D_SensitiveSegment.hxx>
38 #include <Select3D_SensitiveWire.hxx>
39 #include <Select3D_SensitiveFace.hxx>
40 #include <Select3D_SensitiveBox.hxx>
41 #include <Select3D_SensitiveTriangulation.hxx>
42 #include <Select3D_SensitiveTriangle.hxx>
43 #include <Select3D_SensitiveGroup.hxx>
44 #include <SelectMgr_Selection.hxx>
45 #include <TColgp_HArray1OfPnt.hxx>
46 #include <TColgp_SequenceOfPnt.hxx>
47 #include <TColStd_Array1OfReal.hxx>
48 #include <BRep_Tool.hxx>
49 #include <BRepTools.hxx>
50 #include <Select3D_TypeOfSensitivity.hxx>
51 #include <Precision.hxx>
52 #include <gp_Circ.hxx>
53 #include <GCPnts_TangentialDeflection.hxx>
54 #include <TopoDS_Wire.hxx>
55 #include <Poly_Array1OfTriangle.hxx>
56 #include <Poly_Polygon3D.hxx>
57 #include <Poly_PolygonOnTriangulation.hxx>
58 #include <Poly_Triangulation.hxx>
59 #include <BRepMesh_IncrementalMesh.hxx>
60 #include <Standard_NullObject.hxx>
61 #include <Standard_ErrorHandler.hxx>
62 #include <SelectMgr_EntityOwner.hxx>
64 #define BVH_PRIMITIVE_LIMIT 800000
66 //==================================================
67 // function: preBuildBVH
68 // purpose : Pre-builds BVH tree for heavyweight
69 // sensitive entities with sub-elements
70 // amount more than BVH_PRIMITIVE_LIMIT
71 //==================================================
72 void StdSelect_BRepSelectionTool::preBuildBVH (const Handle(SelectMgr_Selection)& theSelection)
74 for (theSelection->Init(); theSelection->More(); theSelection->Next())
76 const Handle(SelectBasics_SensitiveEntity)& aSensitive = theSelection->Sensitive()->BaseSensitive();
77 if (aSensitive->NbSubElements() >= BVH_PRIMITIVE_LIMIT)
82 if (aSensitive->IsInstance ("Select3D_SensitiveGroup"))
84 Handle(Select3D_SensitiveGroup) aGroup (Handle(Select3D_SensitiveGroup)::DownCast (aSensitive));
85 const Select3D_EntitySequence& aSubEntities = aGroup->GetEntities();
86 for (Select3D_EntitySequenceIter aSubEntitiesIter (aSubEntities); aSubEntitiesIter.More(); aSubEntitiesIter.Next())
88 const Handle(Select3D_SensitiveEntity)& aSubEntity = aSubEntitiesIter.Value();
89 if (aSubEntity->NbSubElements() >= BVH_PRIMITIVE_LIMIT)
98 //==================================================
101 //==================================================
102 void StdSelect_BRepSelectionTool
103 ::Load (const Handle(SelectMgr_Selection)& theSelection,
104 const TopoDS_Shape& theShape,
105 const TopAbs_ShapeEnum theType,
106 const Standard_Real theDeflection,
107 const Standard_Real theDeviationAngle,
108 const Standard_Boolean isAutoTriangulation,
109 const Standard_Integer thePriority,
110 const Standard_Integer theNbPOnEdge,
111 const Standard_Real theMaxParam)
113 Standard_Integer aPriority = (thePriority == -1) ? GetStandardPriority (theShape, theType) : thePriority;
115 if( isAutoTriangulation && !BRepTools::Triangulation (theShape, Precision::Infinite()) )
117 BRepMesh_IncrementalMesh aMesher(theShape, theDeflection, Standard_False, theDeviationAngle);
120 Handle(StdSelect_BRepOwner) aBrepOwner;
129 case TopAbs_COMPSOLID:
131 TopTools_IndexedMapOfShape aSubShapes;
132 TopExp::MapShapes (theShape, theType, aSubShapes);
134 Standard_Boolean isComesFromDecomposition = !((aSubShapes.Extent() == 1) && (theShape == aSubShapes (1)));
135 for (Standard_Integer aShIndex = 1; aShIndex <= aSubShapes.Extent(); ++aShIndex)
137 const TopoDS_Shape& aSubShape = aSubShapes (aShIndex);
138 aBrepOwner = new StdSelect_BRepOwner (aSubShape, aPriority, isComesFromDecomposition);
139 ComputeSensitive (aSubShape, aBrepOwner,
145 isAutoTriangulation);
151 aBrepOwner = new StdSelect_BRepOwner (theShape, aPriority);
152 ComputeSensitive (theShape, aBrepOwner,
158 isAutoTriangulation);
163 //==================================================
166 //==================================================
167 void StdSelect_BRepSelectionTool
168 ::Load (const Handle(SelectMgr_Selection)& theSelection,
169 const Handle(SelectMgr_SelectableObject)& theSelectableObj,
170 const TopoDS_Shape& theShape,
171 const TopAbs_ShapeEnum theType,
172 const Standard_Real theDeflection,
173 const Standard_Real theDeviationAngle,
174 const Standard_Boolean isAutoTriangulation,
175 const Standard_Integer thePriority,
176 const Standard_Integer theNbPOnEdge,
177 const Standard_Real theMaxParam)
189 // loading of selectables...
190 for (theSelection->Init(); theSelection->More(); theSelection->Next())
192 Handle(SelectMgr_EntityOwner) anOwner
193 = Handle(SelectMgr_EntityOwner)::DownCast (theSelection->Sensitive()->BaseSensitive()->OwnerId());
194 anOwner->Set (theSelectableObj);
197 preBuildBVH (theSelection);
200 //==================================================
201 // Function: ComputeSensitive
203 //==================================================
204 void StdSelect_BRepSelectionTool
205 ::ComputeSensitive (const TopoDS_Shape& theShape,
206 const Handle(StdSelect_BRepOwner)& theOwner,
207 const Handle(SelectMgr_Selection)& theSelection,
208 const Standard_Real theDeflection,
209 const Standard_Real theDeviationAngle,
210 const Standard_Integer theNbPOnEdge,
211 const Standard_Real theMaxParam,
212 const Standard_Boolean isAutoTriangulation)
214 switch (theShape.ShapeType())
218 theSelection->Add (new Select3D_SensitivePoint
219 (theOwner, BRep_Tool::Pnt (TopoDS::Vertex (theShape))));
224 Handle(Select3D_SensitiveEntity) aSensitive;
225 GetEdgeSensitive (theShape, theOwner, theSelection,
226 theDeflection, theDeviationAngle, theNbPOnEdge, theMaxParam,
228 if (!aSensitive.IsNull())
230 theSelection->Add (aSensitive);
236 BRepTools_WireExplorer aWireExp (TopoDS::Wire (theShape));
237 Handle (Select3D_SensitiveEntity) aSensitive;
238 Handle (Select3D_SensitiveWire) aWireSensitive = new Select3D_SensitiveWire (theOwner);
239 theSelection->Add (aWireSensitive);
240 while (aWireExp.More())
242 GetEdgeSensitive (aWireExp.Current(), theOwner, theSelection,
243 theDeflection, theDeviationAngle, theNbPOnEdge, theMaxParam,
245 if (!aSensitive.IsNull())
247 aWireSensitive->Add (aSensitive);
255 const TopoDS_Face& aFace = TopoDS::Face (theShape);
256 Select3D_EntitySequence aSensitiveList;
257 GetSensitiveForFace (aFace, theOwner,
259 isAutoTriangulation, theNbPOnEdge, theMaxParam);
260 for (Select3D_EntitySequenceIter aSensIter (aSensitiveList);
261 aSensIter.More(); aSensIter.Next())
263 theSelection->Add (aSensIter.Value());
269 case TopAbs_COMPSOLID:
271 TopTools_IndexedMapOfShape aSubfacesMap;
272 TopExp::MapShapes (theShape, TopAbs_FACE, aSubfacesMap);
273 for (Standard_Integer aShIndex = 1; aShIndex <= aSubfacesMap.Extent(); ++aShIndex)
275 ComputeSensitive (aSubfacesMap (aShIndex), theOwner,
277 theDeflection, theDeviationAngle, theNbPOnEdge, theMaxParam, isAutoTriangulation);
281 case TopAbs_COMPOUND:
284 TopExp_Explorer anExp;
286 for (anExp.Init (theShape, TopAbs_VERTEX, TopAbs_EDGE); anExp.More(); anExp.Next())
288 ComputeSensitive (anExp.Current(), theOwner,
290 theDeflection, theDeviationAngle, theNbPOnEdge, theMaxParam, isAutoTriangulation);
293 for (anExp.Init (theShape, TopAbs_EDGE, TopAbs_FACE); anExp.More(); anExp.Next())
295 ComputeSensitive (anExp.Current(), theOwner,
297 theDeflection, theDeviationAngle, theNbPOnEdge, theMaxParam, isAutoTriangulation);
300 for (anExp.Init (theShape, TopAbs_WIRE, TopAbs_FACE); anExp.More(); anExp.Next())
302 ComputeSensitive (anExp.Current(), theOwner,
304 theDeflection, theDeviationAngle, theNbPOnEdge, theMaxParam, isAutoTriangulation);
308 TopTools_IndexedMapOfShape aSubfacesMap;
309 TopExp::MapShapes (theShape, TopAbs_FACE, aSubfacesMap);
310 for (Standard_Integer aShIndex = 1; aShIndex <= aSubfacesMap.Extent(); ++aShIndex)
312 ComputeSensitive (aSubfacesMap (aShIndex), theOwner,
314 theDeflection, theDeviationAngle, theNbPOnEdge, theMaxParam, isAutoTriangulation);
320 //==================================================
321 // Function: GetPointsFromPolygon
323 //==================================================
324 static Handle(TColgp_HArray1OfPnt) GetPointsFromPolygon (const TopoDS_Edge& theEdge,
325 const Standard_Real theDeflection)
327 Handle(TColgp_HArray1OfPnt) aResultPoints;
329 Standard_Real fi, la;
330 Handle(Geom_Curve) CC3d = BRep_Tool::Curve (theEdge, fi, la);
332 TopLoc_Location aLocation;
333 Handle(Poly_Polygon3D) aPolygon = BRep_Tool::Polygon3D (theEdge, aLocation);
334 if (!aPolygon.IsNull())
336 Standard_Boolean isOK = aPolygon->Deflection() <= theDeflection;
337 isOK = isOK || (CC3d.IsNull());
340 const TColgp_Array1OfPnt& aNodes = aPolygon->Nodes();
341 aResultPoints = new TColgp_HArray1OfPnt (1, aNodes.Length());
342 if (aLocation.IsIdentity())
344 for (Standard_Integer aNodeId (aNodes.Lower()), aPntId (1); aNodeId <= aNodes.Upper(); ++aNodeId, ++aPntId)
346 aResultPoints->SetValue (aPntId, aNodes.Value (aNodeId));
351 for (Standard_Integer aNodeId (aNodes.Lower()), aPntId (1); aNodeId <= aNodes.Upper(); ++aNodeId, ++aPntId)
353 aResultPoints->SetValue (aPntId, aNodes.Value (aNodeId).Transformed (aLocation));
356 return aResultPoints;
360 Handle(Poly_Triangulation) aTriangulation;
361 Handle(Poly_PolygonOnTriangulation) anHIndices;
362 BRep_Tool::PolygonOnTriangulation (theEdge, anHIndices, aTriangulation, aLocation);
363 if (!anHIndices.IsNull())
365 Standard_Boolean isOK = anHIndices->Deflection() <= theDeflection;
366 isOK = isOK || (CC3d.IsNull());
369 const TColStd_Array1OfInteger& anIndices = anHIndices->Nodes();
370 const TColgp_Array1OfPnt& aNodes = aTriangulation->Nodes();
372 aResultPoints = new TColgp_HArray1OfPnt (1, anIndices.Length());
374 if (aLocation.IsIdentity())
376 for (Standard_Integer anIndex (anIndices.Lower()), aPntId (1); anIndex <= anIndices.Upper(); ++anIndex, ++aPntId)
378 aResultPoints->SetValue (aPntId, aNodes (anIndices (anIndex)));
383 for (Standard_Integer anIndex (anIndices.Lower()), aPntId (1); anIndex <= anIndices.Upper(); ++anIndex, ++aPntId)
385 aResultPoints->SetValue (aPntId, aNodes (anIndices (anIndex)).Transformed (aLocation));
388 return aResultPoints;
391 return aResultPoints;
394 //==================================================
395 // Function: FindLimits
397 //==================================================
398 static Standard_Boolean FindLimits (const Adaptor3d_Curve& theCurve,
399 const Standard_Real theLimit,
400 Standard_Real& theFirst,
401 Standard_Real& theLast)
403 theFirst = theCurve.FirstParameter();
404 theLast = theCurve.LastParameter();
405 Standard_Boolean isFirstInf = Precision::IsNegativeInfinite (theFirst);
406 Standard_Boolean isLastInf = Precision::IsPositiveInfinite (theLast);
407 if (isFirstInf || isLastInf)
410 Standard_Real aDelta = 1.0;
411 Standard_Integer anIterCount = 0;
412 if (isFirstInf && isLastInf)
415 if (anIterCount++ >= 100000) return Standard_False;
419 theCurve.D0 (theFirst, aPnt1);
420 theCurve.D0 (theLast, aPnt2);
421 } while (aPnt1.Distance (aPnt2) < theLimit);
425 theCurve.D0 (theLast, aPnt2);
427 if (anIterCount++ >= 100000) return Standard_False;
429 theFirst = theLast - aDelta;
430 theCurve.D0 (theFirst, aPnt1);
431 } while (aPnt1.Distance (aPnt2) < theLimit);
435 theCurve.D0 (theFirst, aPnt1);
437 if (anIterCount++ >= 100000) return Standard_False;
439 theLast = theFirst + aDelta;
440 theCurve.D0 (theLast, aPnt2);
441 } while (aPnt1.Distance (aPnt2) < theLimit);
444 return Standard_True;
447 //=====================================================
448 // Function : GetEdgeSensitive
449 // Purpose : create a sensitive edge to add it
450 // in computeselection to "aselection" (case of selection of an edge)
451 // or to "aSensitiveWire" (case of selection of a wire; in this case,
452 // the sensitive wire is added to "aselection" )
453 // odl - for selection by rectangle -
454 //=====================================================
455 void StdSelect_BRepSelectionTool
456 ::GetEdgeSensitive (const TopoDS_Shape& theShape,
457 const Handle(StdSelect_BRepOwner)& theOwner,
458 const Handle(SelectMgr_Selection)& theSelection,
459 const Standard_Real theDeflection,
460 const Standard_Real theDeviationAngle,
461 const Standard_Integer theNbPOnEdge,
462 const Standard_Real theMaxParam,
463 Handle(Select3D_SensitiveEntity)& theSensitive)
465 const TopoDS_Edge& anEdge = TopoDS::Edge (theShape);
466 BRepAdaptor_Curve cu3d;
469 cu3d.Initialize (anEdge);
470 } catch (Standard_NullObject) {
474 // try to get points from existing polygons
475 Handle(TColgp_HArray1OfPnt) aPoints = GetPointsFromPolygon (anEdge, theDeflection);
476 if (!aPoints.IsNull() && aPoints->Length() > 0)
478 theSensitive = new Select3D_SensitiveCurve (theOwner, aPoints);
482 Standard_Real aParamFirst = cu3d.FirstParameter();
483 Standard_Real aParamLast = cu3d.LastParameter();
484 switch (cu3d.GetType())
488 BRep_Tool::Range (anEdge, aParamFirst, aParamLast);
489 theSensitive = new Select3D_SensitiveSegment (theOwner,
490 cu3d.Value (aParamFirst),
491 cu3d.Value (aParamLast));
496 Handle (Geom_Circle) aCircle = new Geom_Circle (cu3d.Circle());
497 if (aCircle->Radius() <= Precision::Confusion())
499 theSelection->Add (new Select3D_SensitivePoint (theOwner, aCircle->Location()));
503 theSensitive = new Select3D_SensitiveCircle (theOwner, aCircle,
504 aParamFirst, aParamLast, Standard_False, 16);
510 // reproduce drawing behaviour
511 // TODO: remove copy-paste from StdPrs_Curve and some others...
512 if (FindLimits (cu3d, theMaxParam, aParamFirst, aParamLast))
514 Standard_Integer aNbIntervals = cu3d.NbIntervals (GeomAbs_C1);
515 TColStd_Array1OfReal anIntervals (1, aNbIntervals + 1);
516 cu3d.Intervals (anIntervals, GeomAbs_C1);
517 Standard_Real aV1, aV2;
518 Standard_Integer aNumberOfPoints;
519 TColgp_SequenceOfPnt aPointsSeq;
520 for (Standard_Integer anIntervalId = 1; anIntervalId <= aNbIntervals; ++anIntervalId)
522 aV1 = anIntervals (anIntervalId);
523 aV2 = anIntervals (anIntervalId + 1);
524 if (aV2 > aParamFirst && aV1 < aParamLast)
526 aV1 = Max (aV1, aParamFirst);
527 aV2 = Min (aV2, aParamLast);
529 GCPnts_TangentialDeflection anAlgo (cu3d, aV1, aV2, theDeviationAngle, theDeflection);
530 aNumberOfPoints = anAlgo.NbPoints();
532 for (Standard_Integer aPntId = 1; aPntId < aNumberOfPoints; ++aPntId)
534 aPointsSeq.Append (anAlgo.Value (aPntId));
536 if (aNumberOfPoints > 0 && anIntervalId == aNbIntervals)
538 aPointsSeq.Append (anAlgo.Value (aNumberOfPoints));
543 aPoints = new TColgp_HArray1OfPnt (1, aPointsSeq.Length());
544 for (Standard_Integer aPntId = 1; aPntId <= aPointsSeq.Length(); ++aPntId)
546 aPoints->SetValue (aPntId, aPointsSeq.Value (aPntId));
548 theSensitive = new Select3D_SensitiveCurve (theOwner, aPoints);
552 // simple subdivisions
553 Standard_Integer nbintervals = 1;
554 if (cu3d.GetType() == GeomAbs_BSplineCurve)
556 nbintervals = cu3d.NbKnots() - 1;
557 nbintervals = Max (1, nbintervals / 3);
560 Standard_Real aParam;
561 Standard_Integer aPntNb = Max (2, theNbPOnEdge * nbintervals);
562 Standard_Real aParamDelta = (aParamLast - aParamFirst) / (aPntNb - 1);
563 Handle(TColgp_HArray1OfPnt) aPointArray = new TColgp_HArray1OfPnt (1, aPntNb);
564 for (Standard_Integer aPntId = 1; aPntId <= aPntNb; ++aPntId)
566 aParam = aParamFirst + aParamDelta * (aPntId - 1);
567 aPointArray->SetValue (aPntId, cu3d.Value (aParam));
569 theSensitive = new Select3D_SensitiveCurve (theOwner, aPointArray);
575 //=====================================================
576 // Function : GetStandardPriority
578 //=====================================================
579 Standard_Integer StdSelect_BRepSelectionTool::GetStandardPriority (const TopoDS_Shape& theShape,
580 const TopAbs_ShapeEnum theType)
584 case TopAbs_VERTEX: return 8;
585 case TopAbs_EDGE: return 7;
586 case TopAbs_WIRE: return 6;
587 case TopAbs_FACE: return 5;
590 switch (theShape.ShapeType())
592 case TopAbs_VERTEX: return 9;
593 case TopAbs_EDGE: return 8;
594 case TopAbs_WIRE: return 7;
595 case TopAbs_FACE: return 6;
596 case TopAbs_SHELL: return 5;
597 case TopAbs_COMPOUND:
598 case TopAbs_COMPSOLID:
607 //=======================================================================
608 //function : GetSensitiveEntityForFace
610 //=======================================================================
611 Standard_Boolean StdSelect_BRepSelectionTool
612 ::GetSensitiveForFace (const TopoDS_Face& theFace,
613 const Handle(StdSelect_BRepOwner)& theOwner,
614 Select3D_EntitySequence& theSensitiveList,
615 const Standard_Boolean /*theAutoTriangulation*/,
616 const Standard_Integer NbPOnEdge,
617 const Standard_Real theMaxParam,
618 const Standard_Boolean theInteriorFlag)
620 // check if there is triangulation of the face...
621 TopLoc_Location aLoc;
622 Handle(Poly_Triangulation) aTriangulation = BRep_Tool::Triangulation (theFace, aLoc);
624 if (!aTriangulation.IsNull())
626 Handle(Select3D_SensitiveTriangulation) STG = new Select3D_SensitiveTriangulation (theOwner, aTriangulation, aLoc, theInteriorFlag);
627 theSensitiveList.Append (STG);
628 return Standard_True;
631 // for faces with triangulation bugs or without autotriangulation ....
632 // very ugly and should not even exist ...
633 BRepAdaptor_Surface BS;
634 BS.Initialize (theFace);
636 Standard_Real FirstU = BS.FirstUParameter() <= -Precision::Infinite() ? -theMaxParam : BS.FirstUParameter();
637 Standard_Real LastU = BS.LastUParameter() >= Precision::Infinite() ? theMaxParam : BS.LastUParameter();
638 Standard_Real FirstV = BS.FirstVParameter() <= -Precision::Infinite() ? -theMaxParam : BS.FirstVParameter();
639 Standard_Real LastV = BS.LastVParameter() >= Precision::Infinite() ? theMaxParam : BS.LastVParameter();
641 if (BS.GetType() == GeomAbs_Plane)
644 Handle(TColgp_HArray1OfPnt) P = new TColgp_HArray1OfPnt (1, 5);
645 BS.D0 (FirstU, FirstV, pcur);
646 P->SetValue (1, pcur);
647 BS.D0 (LastU, FirstV, pcur);
648 P->SetValue (2, pcur);
649 BS.D0 (LastU, LastV, pcur);
650 P->SetValue (3, pcur);
651 BS.D0 (FirstU, LastV, pcur);
652 P->SetValue (4, pcur);
653 P->SetValue (5, P->Value (1));
654 // if the plane is "infinite", it is sensitive only on the border limited by MaxParam
655 if (FirstU == -theMaxParam && LastU == theMaxParam && FirstV == -theMaxParam && LastV == theMaxParam)
657 theSensitiveList.Append (new Select3D_SensitiveFace (theOwner, P, Select3D_TOS_BOUNDARY));
661 Select3D_TypeOfSensitivity TS = theInteriorFlag ? Select3D_TOS_INTERIOR : Select3D_TOS_BOUNDARY;
662 theSensitiveList.Append (new Select3D_SensitiveFace (theOwner, P, TS));
664 return Standard_True;
667 // This is construction of a sevsitive polygon from the exterior contour of the face...
668 // It is not good at all, but...
670 TopExp_Explorer anExpWiresInFace (theFace, TopAbs_WIRE);
671 if (anExpWiresInFace.More())
673 // believing that this is the first... to be seen
674 aWire = TopoDS::Wire (anExpWiresInFace.Current());
678 return Standard_False;
681 TColgp_SequenceOfPnt WirePoints;
682 Standard_Boolean FirstExp = Standard_True;
683 Standard_Real wf, wl;
684 BRepAdaptor_Curve cu3d;
685 for (BRepTools_WireExplorer aWireExplorer (aWire);
686 aWireExplorer.More(); aWireExplorer.Next())
688 cu3d.Initialize (aWireExplorer.Current());
689 BRep_Tool::Range (aWireExplorer.Current(), wf, wl);
690 if (Abs (wf - wl) <= Precision::Confusion())
693 cout<<" StdSelect_BRepSelectionTool : Curve where ufirst = ulast ...."<<endl;
700 if (aWireExplorer.Orientation() == TopAbs_FORWARD)
702 WirePoints.Append (cu3d.Value (wf));
706 WirePoints.Append (cu3d.Value (wl));
708 FirstExp = Standard_False;
711 switch (cu3d.GetType())
715 WirePoints.Append (cu3d.Value ((aWireExplorer.Orientation() == TopAbs_FORWARD) ? wl : wf));
720 if (2 * M_PI - Abs (wl - wf) <= Precision::Confusion())
722 if (BS.GetType() == GeomAbs_Cylinder ||
723 BS.GetType() == GeomAbs_Torus ||
724 BS.GetType() == GeomAbs_Cone ||
725 BS.GetType() == GeomAbs_BSplineSurface) // beuurkk pour l'instant...
727 Standard_Real ff = wf ,ll = wl;
728 Standard_Real dw =(Max (wf, wl) - Min (wf, wl)) / (Standard_Real )Max (2, NbPOnEdge - 1);
729 if (aWireExplorer.Orientation() == TopAbs_FORWARD)
731 for (Standard_Real wc = wf + dw; wc <= wl; wc += dw)
733 WirePoints.Append (cu3d.Value (wc));
736 else if (aWireExplorer.Orientation() == TopAbs_REVERSED)
738 for (Standard_Real wc = ll - dw; wc >= ff; wc -= dw)
740 WirePoints.Append (cu3d.Value (wc));
746 if (cu3d.Circle().Radius() <= Precision::Confusion())
748 theSensitiveList.Append (new Select3D_SensitivePoint (theOwner, cu3d.Circle().Location()));
752 theSensitiveList.Append (new Select3D_SensitiveCircle (theOwner, new Geom_Circle (cu3d.Circle()), theInteriorFlag, 16));
758 Standard_Real ff = wf, ll = wl;
759 Standard_Real dw = (Max (wf, wl) - Min (wf, wl)) / (Standard_Real )Max (2, NbPOnEdge - 1);
760 if (aWireExplorer.Orientation() == TopAbs_FORWARD)
762 for (Standard_Real wc = wf + dw; wc <= wl; wc += dw)
764 WirePoints.Append (cu3d.Value (wc));
767 else if (aWireExplorer.Orientation() == TopAbs_REVERSED)
769 for (Standard_Real wc = ll - dw; wc >= ff; wc -= dw)
771 WirePoints.Append (cu3d.Value (wc));
779 Standard_Real ff = wf, ll = wl;
780 Standard_Real dw = (Max (wf, wl) - Min (wf, wl)) / (Standard_Real )Max (2, NbPOnEdge - 1);
781 if (aWireExplorer.Orientation()==TopAbs_FORWARD)
783 for (Standard_Real wc = wf + dw; wc <= wl; wc += dw)
785 WirePoints.Append (cu3d.Value (wc));
788 else if (aWireExplorer.Orientation() == TopAbs_REVERSED)
790 for (Standard_Real wc = ll - dw; wc >= ff; wc -= dw)
792 WirePoints.Append (cu3d.Value (wc));
799 Standard_Integer ArrayPosition = WirePoints.Length();
801 Handle(TColgp_HArray1OfPnt) facepoints = new TColgp_HArray1OfPnt (1, ArrayPosition);
802 for (Standard_Integer I = 1; I <= ArrayPosition; ++I)
804 facepoints->SetValue (I, WirePoints.Value(I));
807 if ((facepoints->Array1()).Length() > 1)
808 { //1 if only one circular edge
809 Select3D_TypeOfSensitivity TS = theInteriorFlag ? Select3D_TOS_INTERIOR : Select3D_TOS_BOUNDARY;
810 theSensitiveList.Append (new Select3D_SensitiveFace (theOwner, facepoints, TS));
812 return Standard_True;