1 // Created on: 1995-06-27
2 // Created by: Jacques GOUSSARD
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.
18 #include <BRep_Builder.hxx>
19 #include <BRep_Tool.hxx>
20 #include <BRepAdaptor_Surface.hxx>
21 #include <BRepClass_FaceExplorer.hxx>
22 #include <BRepLib_MakeFace.hxx>
23 #include <BRepLib_MakeWire.hxx>
24 #include <BRepTools.hxx>
25 #include <BRepTools_WireExplorer.hxx>
26 #include <BRepTopAdaptor_FClass2d.hxx>
27 #include <Geom2d_Curve.hxx>
28 #include <gp_Dir2d.hxx>
29 #include <gp_Pnt2d.hxx>
30 #include <gp_Vec2d.hxx>
32 #include <LocOpe_SplitShape.hxx>
33 #include <Precision.hxx>
34 #include <Standard_ConstructionError.hxx>
35 #include <Standard_ErrorHandler.hxx>
36 #include <Standard_NoSuchObject.hxx>
37 #include <StdFail_NotDone.hxx>
39 #include <TopExp_Explorer.hxx>
41 #include <TopoDS_Edge.hxx>
42 #include <TopoDS_Face.hxx>
43 #include <TopoDS_Iterator.hxx>
44 #include <TopoDS_Shape.hxx>
45 #include <TopoDS_Vertex.hxx>
46 #include <TopoDS_Wire.hxx>
47 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
48 #include <TopTools_DataMapIteratorOfDataMapOfShapeShape.hxx>
49 #include <TopTools_DataMapOfShapeInteger.hxx>
50 #include <TopTools_DataMapOfShapeListOfShape.hxx>
51 #include <TopTools_DataMapOfShapeShape.hxx>
52 #include <TopTools_IndexedMapOfShape.hxx>
53 #include <TopTools_ListIteratorOfListOfShape.hxx>
54 #include <TopTools_ListOfShape.hxx>
55 #include <TopTools_MapIteratorOfMapOfOrientedShape.hxx>
56 #include <TopTools_MapIteratorOfMapOfShape.hxx>
57 #include <TopTools_MapOfOrientedShape.hxx>
58 #include <TopTools_MapOfShape.hxx>
59 #include <ShapeAnalysis_Edge.hxx>
60 #include <Geom2dAPI_ProjectPointOnCurve.hxx>
62 #include <Geom_Surface.hxx>
64 static Standard_Boolean IsInside(const TopoDS_Face&,
68 static Standard_Boolean IsInside(const TopoDS_Face&,
71 static void GetDirection(const TopoDS_Edge&,
75 Standard_Boolean isFirstEnd);
77 static Standard_Boolean ChoixUV(const TopoDS_Edge&,
79 const TopTools_IndexedMapOfShape&,
84 static TopoDS_Shape ChooseDirection(const TopoDS_Shape&,
87 const TopTools_ListOfShape&);
89 inline Standard_Boolean SameUV(const gp_Pnt2d& P1, const gp_Pnt2d& P2,
90 const BRepAdaptor_Surface& theBAS)//const Standard_Real tol)
92 Standard_Boolean isSame = Standard_True;
93 if(theBAS.IsUPeriodic())
94 isSame = (fabs(P1.X() - P2.X()) < theBAS.UPeriod() *0.5);
95 if(theBAS.IsVPeriodic())
96 isSame = (isSame && (fabs(P1.Y() - P2.Y()) < theBAS.VPeriod() *0.5));
98 //return P1.SquareDistance(P2) < tol * tol; //IFV
103 //=======================================================================
106 //=======================================================================
108 void LocOpe_SplitShape::Init(const TopoDS_Shape& S)
110 myDone = Standard_False;
118 //=======================================================================
119 //function : CanSplit
121 //=======================================================================
123 Standard_Boolean LocOpe_SplitShape::CanSplit(const TopoDS_Edge& E) const
126 return Standard_False;
128 if (myMap.IsEmpty()) {
129 return Standard_False;
132 if (!myMap.IsBound(E)) {
133 return Standard_False;
136 // On verifie que l`edge n`appartient pas a un wire deja reconstruit
138 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itm(myMap);
139 for (; itm.More(); itm.Next()) {
140 if (itm.Key().ShapeType() == TopAbs_WIRE && !itm.Value().IsEmpty()) {
141 for (exp.Init(itm.Key(),TopAbs_EDGE); exp.More(); exp.Next()) {
142 if (exp.Current().IsSame(E)) {
143 return Standard_False;
148 return Standard_True;
152 //=======================================================================
155 //=======================================================================
157 void LocOpe_SplitShape::Add(const TopoDS_Vertex& V,
158 const Standard_Real P,
159 const TopoDS_Edge& E)
166 TopTools_ListOfShape& le = myMap(E);
170 TopTools_ListIteratorOfListOfShape itl(le);
172 TopTools_ListOfShape aNewList;
173 for (; itl.More(); itl.Next()) {
174 const TopoDS_Edge& edg = TopoDS::Edge(itl.Value());
175 BRep_Tool::Range(edg,f,l);
176 if (P > f + Precision::PConfusion() && P < l - Precision::PConfusion()) {
180 aNewList.Append(edg);
185 TopoDS_Edge edg = TopoDS::Edge(itl.Value());
187 if (V.Orientation() == TopAbs_FORWARD ||
188 V.Orientation() == TopAbs_REVERSED) {
190 edg.Orientation(TopAbs_FORWARD);
191 TopoDS_Vertex aCurV1, aCurV2;
192 TopExp::Vertices(edg, aCurV1, aCurV2);
193 Standard_Real aPar1 = BRep_Tool::Parameter(aCurV1,edg);
195 Standard_Real aPar2 = BRep_Tool::Parameter(aCurV2,edg);
197 TopoDS_Shape aLocalShape = edg.EmptyCopied();
198 TopoDS_Edge E1 = TopoDS::Edge(aLocalShape);
199 aLocalShape = edg.EmptyCopied();
200 TopoDS_Edge E2 = TopoDS::Edge(aLocalShape);
201 // TopoDS_Edge E1 = TopoDS::Edge(edg.EmptyCopied());
202 // TopoDS_Edge E2 = TopoDS::Edge(edg.EmptyCopied());
203 E1.Orientation(TopAbs_FORWARD);
204 E2.Orientation(TopAbs_FORWARD);
205 TopoDS_Vertex newVtx = V;
206 Standard_Real aTolSplitV = BRep_Tool::Tolerance(V);
208 aCurV1.Orientation(TopAbs_FORWARD);
211 //for degenerated edges tolerance of vertices should be set to maximal value
212 //from tolerance of the vertex of the edge and tolerance of splitting vertex
213 Standard_Real aTolV1 = ( BRep_Tool::Degenerated(edg) ?
214 Max(BRep_Tool::Tolerance(aCurV1), aTolSplitV) : BRep_Tool::Tolerance(aCurV1));
216 B.UpdateVertex(aCurV1,aPar1,E1, aTolV1);
217 newVtx.Orientation(TopAbs_REVERSED);
219 B.UpdateVertex(newVtx,P,E1,BRep_Tool::Tolerance(V));
220 newVtx.Orientation(TopAbs_FORWARD);
222 B.UpdateVertex(newVtx,P,E2,BRep_Tool::Tolerance(V));
224 aCurV2.Orientation(TopAbs_REVERSED);
227 //for degenerated edges tolerance of vertices should be set to maximal value
228 //from tolerance of the vertex of the edge and tolerance of splitting vertex
229 Standard_Real aTolV2 = ( BRep_Tool::Degenerated(edg) ? aTolV1 : BRep_Tool::Tolerance(aCurV2));
230 B.UpdateVertex(aCurV2,aPar2,E2,aTolV2);
234 for (; itl.More(); itl.Next())
236 const TopoDS_Edge& edg1 = TopoDS::Edge(itl.Value());
237 aNewList.Append(edg1);
240 myMap.Bind(E, aNewList);
244 TopoDS_Shape aLocalShape = edg.EmptyCopied();
245 TopoDS_Edge E1 = TopoDS::Edge(aLocalShape);
248 for (exp.Init(edg,TopAbs_VERTEX); exp.More(); exp.Next()) {
250 const TopoDS_Vertex& vtx = TopoDS::Vertex(exp.Current());
251 f = BRep_Tool::Parameter(vtx,edg);
253 B.UpdateVertex(vtx,f,E1,BRep_Tool::Tolerance(vtx));
256 B.UpdateVertex(V,P,E1,BRep_Tool::Tolerance(V));
261 //=======================================================================
263 //purpose : adds the list of wires on the face <F>
264 //=======================================================================
266 Standard_Boolean LocOpe_SplitShape::Add(const TopTools_ListOfShape& Lwires,
267 const TopoDS_Face& F)
271 return Standard_False;
274 TopTools_ListOfShape& lf = myMap(F);
279 // On cherche la face descendante de F qui continent le wire
281 TopTools_ListIteratorOfListOfShape itl(lf);
282 TopoDS_Vertex Vfirst,Vlast;
284 BRepTools::Update(F);
286 TopTools_ListOfShape aLInside;
287 for (; itl.More(); itl.Next())
289 const TopoDS_Face& fac = TopoDS::Face(itl.Value());
290 TopTools_ListIteratorOfListOfShape itwires(Lwires);
291 for (; itwires.More(); itwires.Next())
293 const TopoDS_Wire& aWire = TopoDS::Wire(itwires.Value());
294 if (IsInside(fac, aWire))
296 aLInside.Append(aWire);
300 if(aLInside.Extent())
303 if (!aLInside.Extent() || !itl.More()) {
304 return Standard_False;
307 TopoDS_Face FaceRef = TopoDS::Face(itl.Value());
308 FaceRef.Orientation(TopAbs_FORWARD);
311 TopTools_ListOfShape NewWires;
313 TopTools_DataMapOfShapeInteger SectionsTimes;
314 for (itl.Initialize(aLInside); itl.More(); itl.Next())
315 SectionsTimes.Bind(itl.Value(), 2);
317 TopTools_ListOfShape BreakVertices;
318 TopTools_ListOfShape BreakOnWires;
320 TopTools_DataMapOfShapeShape VerWireMap;
322 TopExp_Explorer ExploF, ExploW;
323 for (itl.Initialize(aLInside); itl.More(); itl.Next())
325 const TopoDS_Wire& aSection = TopoDS::Wire(itl.Value());
326 TopoDS_Vertex Ver [2];
327 TopExp::Vertices(aSection, Ver[0], Ver[1]);
328 for (i = 0; i < 2; i++)
330 if (VerWireMap.IsBound(Ver[i]))
332 for (ExploF.Init(FaceRef, TopAbs_WIRE); ExploF.More(); ExploF.Next())
334 const TopoDS_Shape& aWire = ExploF.Current();
336 for (ExploW.Init(aWire, TopAbs_VERTEX); ExploW.More(); ExploW.Next())
338 aVer = ExploW.Current();
339 if (aVer.IsSame(Ver[i]))
342 if (aVer.IsSame(Ver[i]))
344 VerWireMap.Bind(aVer, aWire);
351 TopTools_DataMapOfShapeListOfShape VerSecMap;
352 for (itl.Initialize(aLInside); itl.More(); itl.Next())
354 const TopoDS_Wire& aWire = TopoDS::Wire(itl.Value());
355 TopoDS_Vertex V1, V2;
356 TopExp::Vertices(aWire, V1, V2);
357 TopTools_ListOfShape LW1, LW2;
358 if (!VerSecMap.IsBound(V1))
359 VerSecMap.Bind(V1, LW1);
360 VerSecMap(V1).Append(aWire);
361 if (!VerSecMap.IsBound(V2))
362 VerSecMap.Bind(V2, LW2);
363 VerSecMap(V2).Append(aWire);
366 //TopTools_IndexedDataMapOfShapeShape InnerTouchingWiresOnVertex;
368 TopoDS_Wire outerW = BRepTools::OuterWire(FaceRef);
369 TopoDS_Wire CurWire = outerW;
370 BRepLib_MakeWire *MW;
371 MW = new BRepLib_MakeWire();
372 BRepTools_WireExplorer wexp(CurWire, FaceRef);
375 TopoDS_Vertex theStartVertex = wexp.CurrentVertex(), CurVertex;
376 TopoDS_Edge CurEdge = wexp.Current();
377 TopoDS_Edge LastEdge = CurEdge;
379 TopoDS_Wire aSectionWire;
380 TopoDS_Vertex aBreakVertex;
383 wexp.Init(CurWire, FaceRef);
386 if (MW->Wire().Closed())
388 CurVertex = wexp.CurrentVertex();
389 if (VerSecMap.IsBound(CurVertex))
391 TopoDS_Shape aLocalWire = ChooseDirection(LastEdge, CurVertex, FaceRef, VerSecMap(CurVertex));
392 aSectionWire = TopoDS::Wire(aLocalWire);
395 CurEdge = wexp.Current();
400 wexp.Init(CurWire, FaceRef);
402 if (MW->Wire().Closed())
404 NewWires.Append(MW->Wire());
405 theStartVertex = TopoDS::Vertex(BreakVertices.First());
406 BreakVertices.RemoveFirst();
407 CurWire = TopoDS::Wire(BreakOnWires.First());
408 BreakOnWires.RemoveFirst();
409 wexp.Init(CurWire, FaceRef);
410 while (!wexp.CurrentVertex().IsSame(theStartVertex))
412 MW = new BRepLib_MakeWire();
415 aBreakVertex = CurVertex;
416 BreakVertices.Append(aBreakVertex);
417 BreakOnWires.Append(CurWire);
420 MW->Add(aSectionWire);
421 (SectionsTimes(aSectionWire))--;
422 if (SectionsTimes(aSectionWire) == 0)
423 SectionsTimes.UnBind(aSectionWire);
424 if (MW->Wire().Closed())
426 NewWires.Append(MW->Wire());
427 if (SectionsTimes.IsEmpty())
429 theStartVertex = TopoDS::Vertex(BreakVertices.First());
430 BreakVertices.RemoveFirst();
431 CurWire = TopoDS::Wire(BreakOnWires.First());
432 BreakOnWires.RemoveFirst();
433 wexp.Init(CurWire, FaceRef);
434 while (!wexp.CurrentVertex().IsSame(theStartVertex))
436 MW = new BRepLib_MakeWire();
441 TopoDS_Vertex V1, V2, aStartVertex;
442 TopExp::Vertices(aSectionWire, V1, V2);
443 aStartVertex = (V1.IsSame(aBreakVertex))? V2 : V1;
444 CurWire = TopoDS::Wire(VerWireMap(aStartVertex));
446 wexp.Init(CurWire, FaceRef);
447 while (!wexp.CurrentVertex().IsSame(aStartVertex))
450 const TopTools_ListOfShape& Lsections = VerSecMap(aStartVertex);
451 if (Lsections.Extent() == 1)
454 //else: choose the way
455 TopoDS_Wire NextSectionWire =
456 TopoDS::Wire((aSectionWire.IsSame(Lsections.First()))? Lsections.Last() : Lsections.First());
458 Standard_Integer Times = 0;
459 TopTools_DataMapIteratorOfDataMapOfShapeShape itVW(VerWireMap);
460 for (; itVW.More(); itVW.Next())
461 if (itVW.Value().IsSame(CurWire))
463 if (Times == 1) //it is inner touching wire
465 //InnerTouchingWiresOnVertex.Bind(aWire, aStartVertex);
469 //we have to choose the direction
470 TopoDS_Edge aStartEdge = wexp.Current();
471 TopTools_ListOfShape Ldirs;
472 Ldirs.Append(aStartEdge);
473 Ldirs.Append(NextSectionWire);
474 TopoDS_Shape theDirection = ChooseDirection(aSectionWire, aStartVertex, FaceRef, Ldirs);
475 if (theDirection.IsSame(aStartEdge))
478 aSectionWire = NextSectionWire;
479 aBreakVertex = aStartVertex;
480 } //end of else (MW is not closed)
481 } //end of for (;;) (loop on section wires)
482 if (SectionsTimes.IsEmpty())
484 } //end of global for (;;)
486 TopTools_ListOfShape NewFaces;
488 for (itl.Initialize(NewWires); itl.More(); itl.Next())
490 TopoDS_Shape aLocalFace = FaceRef.EmptyCopied();
491 TopoDS_Face aNewFace = TopoDS::Face(aLocalFace);
492 aNewFace.Orientation(TopAbs_FORWARD);
493 BB.Add(aNewFace, itl.Value());
494 NewFaces.Append(aNewFace);
498 TopTools_ListOfShape Holes;
499 for (ExploF.Init(FaceRef, TopAbs_WIRE); ExploF.More(); ExploF.Next())
501 const TopoDS_Shape& aWire = ExploF.Current();
502 ExploW.Init(aWire, TopAbs_EDGE);
503 TopoDS_Shape anEdge = ExploW.Current();
504 Standard_Boolean found = Standard_False;
505 for (itl.Initialize(NewWires); itl.More(); itl.Next())
507 const TopoDS_Shape& aNewWire = itl.Value();
508 for (ExploW.Init(aNewWire, TopAbs_EDGE); ExploW.More(); ExploW.Next())
510 if (anEdge.IsSame(ExploW.Current()))
512 found = Standard_True;
522 TopTools_ListIteratorOfListOfShape itlNewF;
523 for (itl.Initialize(Holes); itl.More(); itl.Next())
525 const TopoDS_Wire& aHole = TopoDS::Wire(itl.Value());
526 for (itlNewF.Initialize(NewFaces); itlNewF.More(); itlNewF.Next())
528 TopoDS_Face& aNewFace = TopoDS::Face(itlNewF.Value());
529 if (IsInside(aNewFace, aHole))
531 BB.Add(aNewFace, aHole);
540 //Update of descendants of wires
541 for (ExploF.Init(F, TopAbs_WIRE); ExploF.More(); ExploF.Next())
543 TopTools_ListOfShape& ls = myMap(ExploF.Current());
548 // JAG 10.11.95 Codage des regularites
549 for (itl.Initialize(aLInside); itl.More(); itl.Next())
550 for (ExploW.Init(itl.Value(), TopAbs_EDGE); ExploW.More(); ExploW.Next())
552 const TopoDS_Edge& edg = TopoDS::Edge(ExploW.Current());
553 if (!BRep_Tool::HasContinuity(edg,F,F)) {
554 BB.Continuity(edg,F,F,GeomAbs_CN);
557 return Standard_True;
561 //=======================================================================
564 //=======================================================================
566 Standard_Boolean LocOpe_SplitShape::Add(const TopoDS_Wire& W,
567 const TopoDS_Face& F)
571 return Standard_False;
576 TopTools_ListOfShape& lf = myMap(F);
582 if (!LocOpe::Closed(W,F)) {
583 if(!AddOpenWire(W,F))
584 return Standard_False;
587 if(!AddClosedWire(W,F))
588 return Standard_False;
590 } catch (Standard_Failure ) {
592 cout << "Warning: SpliShape internal problem detected, some faces may be lost. Check input edges/wires" <<endl;
594 return Standard_False;
596 // JAG 10.11.95 Codage des regularites
598 for (exp.Init(W,TopAbs_EDGE); exp.More(); exp.Next()) {
599 const TopoDS_Edge& edg = TopoDS::Edge(exp.Current());
600 if (!BRep_Tool::HasContinuity(edg,F,F)) {
601 B.Continuity(edg,F,F,GeomAbs_CN);
604 return Standard_True;
609 //=======================================================================
610 //function : AddClosedWire
612 //=======================================================================
614 Standard_Boolean LocOpe_SplitShape::AddClosedWire(const TopoDS_Wire& W,
615 const TopoDS_Face& F)
619 // On cherche la face descendante de F qui continent le wire
620 TopTools_ListOfShape& lf = myMap(F);
621 TopTools_ListIteratorOfListOfShape itl(lf);
623 for (; itl.More(); itl.Next()) {
624 const TopoDS_Face& fac = TopoDS::Face(itl.Value());
626 if (IsInside(fac,W)) {
632 return Standard_False;
637 TopAbs_Orientation orWire = W.Orientation();
638 TopoDS_Shape aLocalFace = F.EmptyCopied();
639 TopoDS_Face newFace = TopoDS::Face(aLocalFace);
640 // TopoDS_Face newFace = TopoDS::Face(F.EmptyCopied());
641 newFace.Orientation(TopAbs_FORWARD);
644 // BRepGProp::SurfaceProperties (newFace,GP);
645 // if (GP.Mass() < 0) {
646 BRepTopAdaptor_FClass2d classif(newFace,Precision::PConfusion());
647 if (classif.PerformInfinitePoint() == TopAbs_IN) {
648 //le wire donne defini un trou
649 aLocalFace = F.EmptyCopied();
650 newFace = TopoDS::Face(aLocalFace);
651 // newFace = TopoDS::Face(F.EmptyCopied());
652 newFace.Orientation(TopAbs_FORWARD);
653 orWire = TopAbs::Reverse(orWire);
654 B.Add(newFace,W.Oriented(orWire));
657 TopoDS_Face FaceRef = TopoDS::Face(itl.Value());
658 FaceRef.Orientation(TopAbs_FORWARD);
661 aLocalFace = FaceRef.EmptyCopied();
662 TopoDS_Face newRef = TopoDS::Face(aLocalFace);
663 // TopoDS_Face newRef = TopoDS::Face(FaceRef.EmptyCopied());
664 newRef.Orientation(TopAbs_FORWARD);
666 // On suppose que les edges du wire ont des courbes 2d.
667 // Comme on ne change pas de surface de base, pas besoin d`UpdateEdge.
669 for (exp.Init(FaceRef.Oriented(TopAbs_FORWARD),TopAbs_WIRE);
670 exp.More(); exp.Next()) {
671 const TopoDS_Wire& wir = TopoDS::Wire(exp.Current());
672 if (IsInside(F,wir,W)) {
679 B.Add(newRef,W.Oriented(TopAbs::Reverse(orWire)));
682 return Standard_True;
685 //=======================================================================
686 //function : checkOverlapping
688 //=======================================================================
690 static Standard_Boolean checkOverlapping(const TopoDS_Edge& theEdge1, const TopoDS_Edge& theEdge2,
691 const TopoDS_Face& theFace)
694 BRepAdaptor_Surface anAdS(theFace,Standard_False );
696 Standard_Real MaxTol = (BRep_Tool::Tolerance(theEdge1) + BRep_Tool::Tolerance(theEdge2));
698 Standard_Real aMaxTol2d = Max(anAdS.UResolution(MaxTol),anAdS.VResolution(MaxTol));
699 Standard_Real aTolAng = M_PI/180.;
700 Geom2dAPI_ProjectPointOnCurve proj;
701 Standard_Real aF1, aL1,aF2, aL2;
703 Handle(Geom2d_Curve) aCrv1 = BRep_Tool::CurveOnSurface(theEdge1, theFace, aF1, aL1);
704 Handle(Geom2d_Curve) aCrv2 = BRep_Tool::CurveOnSurface(theEdge2, theFace, aF2, aL2);
705 Standard_Integer j =1, nbP = 4;
706 Standard_Real aStep = ( aL2 - aF2)/nbP;
709 Standard_Real par2 = aF2 + aStep * j;
712 aCrv2->D1(par2, aP2d, aV2);
714 proj.Init(aP2d,aCrv1, aF1, aL1);
715 //check intermediate points
716 if(!proj.NbPoints() || proj.LowerDistance() > aMaxTol2d)
717 return Standard_False;
718 Standard_Real par1 = proj.LowerDistanceParameter();
721 aCrv1->D1(par1, aP2d1, aV1);
723 if( !aV1.IsParallel(aV2, aTolAng))
724 return Standard_False;
726 return Standard_True;
730 //=======================================================================
731 //function : AddOpenWire
733 //=======================================================================
735 Standard_Boolean LocOpe_SplitShape::AddOpenWire(const TopoDS_Wire& W,
736 const TopoDS_Face& F)
738 // On cherche la face descendante de F qui continent le wire
739 TopTools_ListOfShape& lf = myMap(F);
740 TopTools_ListIteratorOfListOfShape itl(lf);
741 TopoDS_Vertex Vfirst,Vlast;
743 BRepTools::Update(F);
745 Standard_Real tolf, toll, tol1;
747 TopoDS_Shape aLocalShape = W.Oriented(TopAbs_FORWARD);
748 TopExp::Vertices(TopoDS::Wire(aLocalShape),Vfirst,Vlast);
750 tolf = BRep_Tool::Tolerance(Vfirst);
751 toll = BRep_Tool::Tolerance(Vlast);
752 tol1 = Max(tolf, toll);
755 TopExp_Explorer exp,exp2;
757 TopoDS_Wire wfirst,wlast;
758 for (; itl.More(); itl.Next()) {
759 TopoDS_Face fac = TopoDS::Face(itl.Value());
760 if (!IsInside(fac,W)) {
764 fac.Orientation(TopAbs_FORWARD);
765 Standard_Boolean ffound = Standard_False;
766 Standard_Boolean lfound = Standard_False;
767 for (exp.Init(fac,TopAbs_WIRE); exp.More(); exp.Next()) {
768 const TopoDS_Wire& wir = TopoDS::Wire(exp.Current());
769 for (exp2.Init(wir,TopAbs_VERTEX); exp2.More(); exp2.Next()) {
770 if (!ffound && exp2.Current().IsSame(Vfirst)) {
771 ffound = Standard_True;
774 else if (!lfound && exp2.Current().IsSame(Vlast)) {
775 lfound = Standard_True;
778 if (ffound && lfound) {
791 return Standard_False;
794 TopoDS_Face FaceRef = TopoDS::Face(itl.Value());
795 FaceRef.Orientation(TopAbs_FORWARD);
799 BRepAdaptor_Surface BAS(FaceRef, Standard_False);
801 Standard_Boolean IsPeriodic = BAS.IsUPeriodic() || BAS.IsVPeriodic();
803 tol1 = Max(BAS.UResolution(tol1), BAS.VResolution(tol1));
805 if (wfirst.IsSame(wlast)) {
806 // on cree 2 faces en remplacement de itl.Value()
808 TopTools_ListOfShape WiresFirst;
809 for (exp.Init(wfirst,TopAbs_EDGE); exp.More(); exp.Next()) {
810 if (BRep_Tool::IsClosed(TopoDS::Edge(exp.Current()),FaceRef)) {
811 myDblE.Add(exp.Current());
813 WiresFirst.Append(exp.Current());
816 TopAbs_Orientation orient;
817 TopoDS_Wire newW1,newW2;
819 newW1.Orientation(TopAbs_FORWARD);
821 newW2.Orientation(TopAbs_FORWARD);
823 Standard_Integer nbE = 0;
824 for (exp.Init(W.Oriented(TopAbs_FORWARD),TopAbs_EDGE);
825 exp.More(); exp.Next()) {
827 const TopoDS_Edge& edg = TopoDS::Edge(exp.Current());
828 orient = edg.Orientation();
829 WiresFirst.Append(edg);
830 WiresFirst.Append(edg.Oriented(TopAbs::Reverse(orient)));
834 TopTools_IndexedMapOfShape PossE;
835 TopTools_MapOfOrientedShape MapE;
836 TopoDS_Vertex vdeb,vfin;
837 Standard_Integer nbPoss;
839 // On recherche l`edge contenant Vlast
840 TopoDS_Edge LastEdge;
841 gp_Pnt2d pfirst,plast;
843 Handle(Geom2d_Curve) C2d;
846 for (exp.Init(W.Oriented(TopAbs_FORWARD),TopAbs_EDGE);
847 exp.More(); exp.Next()) {
848 const TopoDS_Edge& edg = TopoDS::Edge(exp.Current());
849 for (exp2.Init(edg,TopAbs_VERTEX); exp2.More(); exp2.Next()) {
850 if (exp2.Current().IsSame(Vfirst)) {
856 LastEdge.Orientation(edg.Orientation());
861 TopoDS_Shape aLocalFace = FaceRef.Oriented(wfirst.Orientation());
862 C2d = BRep_Tool::CurveOnSurface(LastEdge, TopoDS::Face(aLocalFace), f, l);
864 if (LastEdge.Orientation() == TopAbs_FORWARD) {
865 pfirst = C2d->Value(f);
868 pfirst = C2d->Value(l);
871 for (exp.Init(W.Oriented(TopAbs_FORWARD),TopAbs_EDGE);
872 exp.More(); exp.Next()) {
873 const TopoDS_Edge& edg = TopoDS::Edge(exp.Current());
874 if( nbE>1 && edg.IsSame(LastEdge) )
876 for (exp2.Init(edg,TopAbs_VERTEX); exp2.More(); exp2.Next()) {
877 if (exp2.Current().IsSame(Vlast)) {
883 LastEdge.Orientation(edg.Orientation());
887 aLocalFace = FaceRef.Oriented(wfirst.Orientation());
888 GetDirection(LastEdge, TopoDS::Face(aLocalFace),plast , dlast, Standard_False);
890 Standard_Boolean cond;
894 cond = !(Vfirst.IsSame(Vlast) && SameUV(pfirst,plast,BAS));
897 cond = !(Vfirst.IsSame(Vlast));
903 // On enchaine par la fin
904 TopTools_ListIteratorOfListOfShape lexp(WiresFirst);
905 for (; lexp.More(); lexp.Next()) {
906 const TopoDS_Edge& edg = TopoDS::Edge(lexp.Value());
908 orient = edg.Orientation();
909 TopExp::Vertices(edg,vdeb,vfin);
911 if ((orient == TopAbs_FORWARD && Vlast.IsSame(vdeb)) ||
912 (orient == TopAbs_REVERSED && Vlast.IsSame(vfin)))
915 nbPoss = PossE.Extent();
921 TopoDS_Edge aNextEdge;
923 aNextEdge = TopoDS::Edge (PossE.FindKey (1));
924 TopoDS_Shape aLocalFaceTemp = FaceRef.Oriented(wfirst.Orientation());
925 GetDirection(aNextEdge, TopoDS::Face(aLocalFaceTemp),plast , dlast, Standard_False);
928 else if (nbPoss > 1) {
929 // Faire choix en U,V...
930 TopoDS_Shape aLocalFaceTemp = FaceRef.Oriented(wfirst.Orientation());
932 if(!ChoixUV(LastEdge, TopoDS::Face(aLocalFaceTemp), PossE,
933 aNextEdge, plast, dlast))
934 return Standard_False;
939 if (aNextEdge.IsNull())
941 // loop is not closed. Split is not possible
942 return Standard_False;
945 if (MapE.Contains(aNextEdge))
947 B.Add(newW1, aNextEdge);
949 LastEdge = aNextEdge;
951 if (LastEdge.Orientation() == TopAbs_FORWARD) {
952 Vlast = TopExp::LastVertex(LastEdge);
955 Vlast = TopExp::FirstVertex(LastEdge);
958 toll = BRep_Tool::Tolerance(Vlast);
959 tol1 = Max(tolf, toll);
962 //MODIFICATION PIERRE SMEYERS : si pas de possibilite, on sort avec erreur
964 cout<<"erreur Spliter : pas de chainage du wire"<<endl;
965 return Standard_False;
969 tol1 = Max(BAS.UResolution(tol1), BAS.VResolution(tol1));
973 Standard_Integer nbAddBound =0;
974 TopTools_ListIteratorOfListOfShape lexp(WiresFirst);
975 TopoDS_Shape anE1, anE2;
976 for (; lexp.More(); lexp.Next()) {
977 const TopoDS_Edge& edg = TopoDS::Edge(lexp.Value());
978 if (!MapE.Contains(edg)) {
989 //check overlapping edges for second face
991 return Standard_False;
992 if(nbAddBound ==2 && !anE1.IsNull() && !anE2.IsNull())
994 if(checkOverlapping(TopoDS::Edge(anE1), TopoDS::Edge(anE2),FaceRef ))
995 return Standard_False;
1001 TopoDS_Shape anE11, anE12;
1002 TopoDS_Iterator anItE(newW1, Standard_False);
1003 for( ; anItE.More(); anItE.Next())
1005 if( anItE.Value().ShapeType() != TopAbs_EDGE)
1009 anE11 = anItE.Value();
1011 anE12 = anItE.Value();
1014 //check overlapping edges for first face
1016 return Standard_False;
1017 if(nbAddBound ==2 && !anE11.IsNull() && !anE12.IsNull())
1019 if(checkOverlapping(TopoDS::Edge(anE11), TopoDS::Edge(anE12), FaceRef))
1020 return Standard_False;
1024 TopoDS_Face newF1,newF2;
1025 aLocalFace = FaceRef.EmptyCopied();
1026 newF1 = TopoDS::Face(aLocalFace);
1027 newF1.Orientation(TopAbs_FORWARD);
1028 aLocalFace = FaceRef.EmptyCopied();
1029 newF2 = TopoDS::Face(aLocalFace);
1030 newF2.Orientation(TopAbs_FORWARD);
1032 // modifs JAG 97.05.28
1036 for (exp.Init(FaceRef.Oriented(TopAbs_FORWARD),TopAbs_WIRE); exp.More(); exp.Next()) {
1037 const TopoDS_Wire& wir = TopoDS::Wire(exp.Current());
1038 if (!wir.IsSame(wfirst)) {
1039 if (IsInside(newF1, wir)) {
1042 else if (IsInside(newF2, wir)) {
1046 // Ce wire est ni dans newF2 ni dans newF1
1047 // Peut etre faut il construire une troisieme face
1048 cout << "WARNING: LocOpe_SPlitShape : Ce wire est ni dans newF2 ni dans newF1" << endl;
1055 // Mise a jour des descendants des wires
1056 for (exp.Init(F,TopAbs_WIRE); exp.More(); exp.Next()) {
1057 TopTools_ListOfShape& ls = myMap(exp.Current());
1059 for (; itl.More(); itl.Next()) {
1060 if (itl.Value().IsSame(wfirst)) {
1064 if (itl.More()) { // on a trouve le wire
1072 // on ne cree qu`une seule face
1073 TopoDS_Wire outerW = BRepTools::OuterWire(FaceRef);
1074 TopoDS_Wire newWire;
1075 TopoDS_Face newFace;
1076 B.MakeWire(newWire);
1077 newWire.Orientation(TopAbs_FORWARD);
1078 TopAbs_Orientation orient,orRelat;
1080 if (wfirst.Orientation() == wlast.Orientation()) {
1081 orRelat = TopAbs_FORWARD;
1084 orRelat = TopAbs_REVERSED;
1087 if (wlast.IsSame(outerW)) {
1093 for (exp.Init(wfirst.Oriented(TopAbs_FORWARD),TopAbs_EDGE);
1094 exp.More(); exp.Next()) {
1095 B.Add(newWire,TopoDS::Edge(exp.Current()));
1099 for (exp.Init(wlast.Oriented(TopAbs_FORWARD),TopAbs_EDGE);
1100 exp.More(); exp.Next()) {
1101 const TopoDS_Edge& edg = TopoDS::Edge(exp.Current());
1102 orient = TopAbs::Compose(edg.Orientation(),orRelat);
1103 B.Add(newWire,edg.Oriented(orient));
1107 // Edges du wire ajoute, et dans les 2 sens
1108 for (exp.Init(W.Oriented(TopAbs_FORWARD),TopAbs_EDGE);
1109 exp.More(); exp.Next()) {
1110 const TopoDS_Edge& edg = TopoDS::Edge(exp.Current());
1111 orient = edg.Orientation();
1112 B.Add(newWire,edg.Oriented(orient));
1113 B.Add(newWire,edg.Oriented(TopAbs::Reverse(orient)));
1114 myDblE.Add(edg.Oriented(orient));
1117 // on refait une face
1119 TopoDS_Shape aLocalFace = FaceRef.EmptyCopied();
1120 newFace = TopoDS::Face(aLocalFace);
1121 // newFace = TopoDS::Face(FaceRef.EmptyCopied());
1122 FaceRef.Orientation(TopAbs_FORWARD);
1123 for (exp.Init(FaceRef.Oriented(TopAbs_FORWARD),TopAbs_WIRE);
1124 exp.More(); exp.Next()) {
1125 const TopoDS_Wire& wir = TopoDS::Wire(exp.Current());
1126 if (wir.IsSame(wfirst)) {
1127 B.Add(newFace,newWire.Oriented(wir.Orientation()));
1129 else if (!wir.IsSame(wlast)) {
1135 // Mise a jour des descendants des wires
1136 for (exp.Init(F,TopAbs_WIRE); exp.More(); exp.Next()) {
1137 TopTools_ListOfShape& ls = myMap(exp.Current());
1139 Standard_Boolean touch = Standard_False;
1140 while (itl.More()) {
1141 if (itl.Value().IsSame(wfirst) || itl.Value().IsSame(wlast)) {
1143 touch = Standard_True;
1155 return Standard_True;
1159 //=======================================================================
1162 //=======================================================================
1164 const TopTools_ListOfShape& LocOpe_SplitShape::LeftOf(const TopoDS_Wire& W,
1165 const TopoDS_Face& F)
1167 if (myShape.IsNull()) {
1168 Standard_NoSuchObject::Raise();
1171 TopExp_Explorer exp,expw,expf;
1172 exp.Init(myShape,TopAbs_FACE);
1173 for (; exp.More(); exp.Next()) {
1174 if (exp.Current().IsSame(F)) {
1179 Standard_NoSuchObject::Raise();
1183 const TopoDS_Face& theFace = TopoDS::Face(exp.Current());
1184 TopAbs_Orientation orFace = theFace.Orientation();
1185 TopTools_ListIteratorOfListOfShape itl,itl2;
1187 for (expw.Init(W,TopAbs_EDGE); expw.More(); expw.Next()) {
1188 const TopoDS_Edge& edg = TopoDS::Edge(expw.Current());
1189 for (itl.Initialize(myMap(theFace)); itl.More(); itl.Next()) {
1190 TopoDS_Face fac = TopoDS::Face(itl.Value());
1191 fac.Orientation(orFace);
1192 for (expf.Init(fac,TopAbs_EDGE); expf.More(); expf.Next()) {
1193 const TopoDS_Edge& edgbis = TopoDS::Edge(expf.Current());
1194 if (edgbis.IsSame(edg) &&
1195 edgbis.Orientation() == edg.Orientation()) {
1196 for (itl2.Initialize(myLeft); itl2.More(); itl2.Next()) {
1197 if (itl2.Value().IsSame(fac)) {
1201 if (!itl2.More()) { // la face n`est pas deja presente
1207 if (expf.More()) { // face found
1216 //=======================================================================
1217 //function : DescendantShapes
1219 //=======================================================================
1221 const TopTools_ListOfShape& LocOpe_SplitShape::DescendantShapes
1222 (const TopoDS_Shape& S)
1226 myDone = Standard_True;
1229 if (!myDblE.IsEmpty()) {
1230 cout << "Le shape comporte des faces invalides" << endl;
1238 //=======================================================================
1241 //=======================================================================
1243 void LocOpe_SplitShape::Put(const TopoDS_Shape& S)
1245 if (!myMap.IsBound(S)) {
1246 TopTools_ListOfShape thelist;
1247 myMap.Bind(S, thelist);
1248 if (S.ShapeType() != TopAbs_VERTEX) {
1249 for(TopoDS_Iterator theIterator(S);theIterator.More();
1250 theIterator.Next()) {
1251 Put(theIterator.Value());
1260 static void updateToleraces(const TopoDS_Face& theFace, const TopTools_DataMapOfShapeListOfShape& theMap)
1262 TopExp_Explorer aExpE(theFace, TopAbs_EDGE);
1263 for (; aExpE.More(); aExpE.Next())
1265 if (!theMap.IsBound(aExpE.Current()))
1267 const TopTools_ListOfShape& lEdges = theMap(aExpE.Current());
1268 if (lEdges.Extent() <= 1)
1271 TopTools_ListIteratorOfListOfShape itrE(lEdges);
1272 ShapeAnalysis_Edge aSae;
1274 for (; itrE.More(); itrE.Next())
1276 TopoDS_Edge aCurE = TopoDS::Edge(itrE.Value());
1277 Standard_Real amaxdev = 0.;
1278 if (aSae.CheckSameParameter(aCurE, theFace, amaxdev))
1281 aB.UpdateEdge(aCurE, amaxdev);
1287 //=======================================================================
1288 //function : Rebuild
1290 //=======================================================================
1292 Standard_Boolean LocOpe_SplitShape::Rebuild(const TopoDS_Shape& S)
1295 if (S.ShapeType() == TopAbs_FACE)
1296 updateToleraces(TopoDS::Face(S), myMap);
1297 TopTools_ListIteratorOfListOfShape itr(myMap(S));
1299 if (itr.Value().IsSame(S)) {
1300 return Standard_False;
1302 return Standard_True;
1304 Standard_Boolean rebuild = Standard_False;
1306 for(it.Initialize(S); it.More(); it.Next()) {
1307 rebuild = Rebuild(it.Value()) || rebuild;
1312 TopoDS_Shape result = S.EmptyCopied();
1313 TopAbs_Orientation orient;
1314 for(it.Initialize(S); it.More(); it.Next()) {
1315 orient = it.Value().Orientation();
1316 for (itr.Initialize(myMap(it.Value())); itr.More(); itr.Next()) {
1317 B.Add(result,itr.Value().Oriented(orient));
1320 // Assign "Closed" flag for Wires and Shells only
1321 if (result.ShapeType() == TopAbs_WIRE || result.ShapeType() == TopAbs_SHELL)
1322 result.Closed (BRep_Tool::IsClosed(result));
1323 myMap(S).Append(result);
1333 //=======================================================================
1334 //function : IsInside
1336 //=======================================================================
1338 static Standard_Boolean IsInside(const TopoDS_Face& F,
1339 const TopoDS_Wire& W1,
1340 const TopoDS_Wire& W2)
1342 // Attention, c`est tres boeuf !!!!
1344 TopoDS_Shape aLocalShape = F.EmptyCopied();
1345 TopoDS_Face newFace = TopoDS::Face(aLocalShape);
1346 // TopoDS_Face newFace = TopoDS::Face(F.EmptyCopied());
1348 //TopAbs_Orientation orWire = W2.Orientation();
1350 newFace.Orientation(TopAbs_FORWARD);
1353 // BRepGProp::SurfaceProperties(newFace,GP);
1354 // if (GP.Mass() < 0) {
1355 BRepTopAdaptor_FClass2d classif(newFace,Precision::PConfusion());
1356 Standard_Boolean Reversed = Standard_False;
1357 if (classif.PerformInfinitePoint() == TopAbs_IN) {
1358 //le wire donne defini un trou
1359 // newFace = TopoDS::Face(F.EmptyCopied());
1360 // newFace.Orientation(TopAbs_FORWARD);
1361 // orWire = TopAbs::Reverse(orWire);
1362 // B.Add(newFace,W2.Oriented(orWire));
1363 Reversed = Standard_True;
1366 // Standard_Real U,V;
1367 TopExp_Explorer exp(W1,TopAbs_EDGE);
1368 const TopoDS_Edge& edg = TopoDS::Edge(exp.Current());
1369 TopExp_Explorer exp2(edg,TopAbs_VERTEX);
1370 const TopoDS_Vertex& vtx = TopoDS::Vertex(exp2.Current());
1371 Standard_Real prm = BRep_Tool::Parameter(vtx,edg);
1373 Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(edg,F,f,l);
1376 cout << "Edge is not on surface" <<endl;
1378 return Standard_False;
1380 gp_Pnt2d pt2d(C2d->Value(prm));
1381 // BRepClass_FaceClassifier classif(newFace,pt2d,Precision::PConfusion());
1382 // return (classif.State() == TopAbs_IN);
1384 return (classif.Perform(pt2d) == TopAbs_IN);
1387 return (classif.Perform(pt2d) == TopAbs_OUT);
1392 //=======================================================================
1393 //function : IsInside
1395 //=======================================================================
1397 static Standard_Boolean IsInside(const TopoDS_Face& F,
1398 const TopoDS_Wire& W)
1400 // Attention, c`est tres boeuf !!!!
1401 TopExp_Explorer exp(W,TopAbs_EDGE);
1402 for( ; exp.More(); exp.Next()) {
1403 const TopoDS_Edge& edg = TopoDS::Edge(exp.Current());
1404 // TopExp_Explorer exp2(edg,TopAbs_VERTEX);
1405 // const TopoDS_Vertex& vtx = TopoDS::Vertex(exp2.Current());
1406 // Standard_Real prm = BRep_Tool::Parameter(vtx,edg);
1407 Standard_Real f,l,prm;
1408 Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(edg,F,f,l);
1409 if (!Precision::IsNegativeInfinite(f) &&
1410 !Precision::IsPositiveInfinite(l)) {
1414 if (Precision::IsNegativeInfinite(f) &&
1415 Precision::IsPositiveInfinite(l)){
1418 else if (Precision::IsNegativeInfinite(f)) {
1426 gp_Pnt2d pt2d(C2d->Value(prm));
1427 // BRepClass_FaceClassifier classif(F,pt2d,Precision::PConfusion());
1428 // return (classif.State() != TopAbs_OUT);
1429 BRepTopAdaptor_FClass2d classif(F,Precision::PConfusion());
1430 TopAbs_State stat = classif.Perform(pt2d);
1431 // return (classif.Perform(pt2d) != TopAbs_OUT);
1432 if(stat == TopAbs_OUT) return Standard_False;
1434 if(stat == TopAbs_ON) {
1435 Standard_Integer nbPnt =10;
1436 Standard_Integer nbOut =0,nbIn =0,nbOn=0;
1437 Standard_Integer j =1;
1438 for( ; j<= nbPnt ; j++)
1440 //check neighbouring point
1441 //prm = .66 * prm + .34 * l;
1442 prm = f + (l-f)/nbPnt*(j-1);
1443 pt2d = C2d->Value(prm);
1444 stat = classif.Perform(pt2d);
1445 if(stat == TopAbs_OUT )
1447 else if(stat == TopAbs_IN)
1452 if(nbOut > nbIn + nbOn)
1453 return Standard_False;
1456 return Standard_True;
1459 //=======================================================================
1460 //function : GetDirection
1462 //=======================================================================
1463 static void GetDirection(const TopoDS_Edge& theEdge,
1464 const TopoDS_Face& theFace,
1467 Standard_Boolean isFirstEnd)
1469 Standard_Real aFirst, aLast;
1470 Handle(Geom2d_Curve) aC2d = BRep_Tool::CurveOnSurface (theEdge, theFace, aFirst, aLast);
1472 TopAbs_Orientation anOr = theEdge.Orientation();
1474 Standard_Boolean takeFirst = ((anOr == TopAbs_FORWARD && isFirstEnd) ||
1475 (anOr == TopAbs_REVERSED && !isFirstEnd));
1477 Standard_Real dpar = (aLast - aFirst)*0.01;
1481 aC2d->D0 (aFirst, thePnt);
1482 gp_Pnt2d aNextPnt = aC2d->Value(aFirst + dpar);
1483 theDir = gp_Vec2d(thePnt, aNextPnt);
1488 aC2d->D0 (aLast, thePnt);
1489 gp_Pnt2d aPrevPnt = aC2d->Value(aLast - dpar);
1490 theDir = gp_Vec2d( aPrevPnt, thePnt );
1492 if(anOr == TopAbs_REVERSED)
1496 //=======================================================================
1497 //function : ChoixUV
1499 //=======================================================================
1501 Standard_Boolean ChoixUV(const TopoDS_Edge& Last,
1502 const TopoDS_Face& F,
1503 const TopTools_IndexedMapOfShape& Poss,
1504 TopoDS_Edge& theResEdge,
1510 gp_Pnt aPCur, aPlst;
1512 BRepAdaptor_Surface surf(F,Standard_False); // no restriction
1513 surf.D0 (plst.X(), plst.Y(), aPlst);
1515 gp_Dir2d ref2d(dlst);
1517 Handle(Geom2d_Curve) C2d;
1520 Standard_Integer index = 0, imin=0;
1521 Standard_Real angmax = -M_PI, ang;
1523 for (index = 1; index <= Poss.Extent(); index++) {
1524 TopoDS_Edge anEdge = TopoDS::Edge (Poss.FindKey (index));
1526 GetDirection(anEdge, F, p2d, v2d, Standard_True);
1528 surf.D0 (p2d.X(), p2d.Y(), aPCur);
1530 if (!Last.IsSame(anEdge)) {
1531 ang = ref2d.Angle(gp_Dir2d(v2d));
1537 if ( (ang > angmax)) {
1545 theResEdge = TopoDS::Edge (Poss.FindKey (imin));
1546 GetDirection(theResEdge, F, plst, dlst, Standard_False);
1552 //=======================================================================
1553 //function : ChooseDirection
1555 //=======================================================================
1557 static TopoDS_Shape ChooseDirection(const TopoDS_Shape& RefDir,
1558 const TopoDS_Vertex& RefVertex,
1559 const TopoDS_Face& theFace,
1560 const TopTools_ListOfShape& Ldirs)
1562 TopExp_Explorer Explo(RefDir, TopAbs_EDGE);
1563 TopoDS_Edge RefEdge;
1564 TopoDS_Vertex V1, V2;
1565 TopAbs_Orientation anOr = TopAbs_FORWARD;
1566 for (; Explo.More(); Explo.Next())
1568 RefEdge = TopoDS::Edge(Explo.Current());
1569 TopExp::Vertices(RefEdge, V1, V2);
1570 if (V1.IsSame(RefVertex))
1572 anOr = TopAbs_REVERSED;
1575 else if (V2.IsSame(RefVertex))
1577 anOr = TopAbs_FORWARD;
1582 Standard_Real RefFirst, RefLast;
1583 Handle(Geom2d_Curve) RefCurve = BRep_Tool::CurveOnSurface(RefEdge, theFace, RefFirst, RefLast);
1587 //Standard_Real RefPar = (RefEdge.Orientation() == TopAbs_FORWARD)? RefLast : RefFirst;
1588 Standard_Real RefPar = (anOr == TopAbs_FORWARD)? RefLast : RefFirst;
1589 RefCurve->D1(RefPar, RefPnt, RefVec);
1590 if (anOr == TopAbs_FORWARD)
1593 Handle(Geom2d_Curve) aCurve;
1594 Standard_Real aFirst, aLast, aPar;
1596 Standard_Real MinAngle = RealLast(), anAngle;
1597 TopoDS_Shape TargetDir;
1598 TopTools_ListIteratorOfListOfShape itl(Ldirs);
1599 for (; itl.More(); itl.Next())
1601 const TopoDS_Shape& aShape = itl.Value();
1603 for (Explo.Init(aShape, TopAbs_EDGE); Explo.More(); Explo.Next())
1605 anEdge = TopoDS::Edge(Explo.Current());
1606 TopExp::Vertices(anEdge, V1, V2);
1607 if (V1.IsSame(RefVertex))
1609 anOr = TopAbs_FORWARD;
1612 else if (V2.IsSame(RefVertex))
1614 anOr = TopAbs_REVERSED;
1618 aCurve = BRep_Tool::CurveOnSurface(anEdge, theFace, aFirst, aLast);
1619 aPar = (anOr == TopAbs_FORWARD)? aFirst : aLast;
1620 aCurve->D1(aPar, RefPnt, aVec);
1621 if (anOr == TopAbs_REVERSED)
1623 anAngle = aVec.Angle(RefVec);
1627 if (anAngle < MinAngle)