1 // File: BRepOffset_Tool.cxx
2 // Created: Mon Oct 23 14:25:07 1995
3 // Author: Yves FRICAUD
8 #include <BRepOffset_Tool.ixx>
10 #include <BRepAlgo_Tool.hxx>
12 #include <BRepAdaptor_Curve.hxx>
13 #include <BRepAdaptor_Surface.hxx>
14 #include <BRepAdaptor_HCurve.hxx>
15 #include <BRepAdaptor_HSurface.hxx>
17 #include <BRepBndLib.hxx>
19 #include <Bnd_Box2d.hxx>
20 #include <BndLib_Add3dCurve.hxx>
21 #include <BRep_Tool.hxx>
22 #include <BRepLib.hxx>
23 #include <BRepLib_MakeEdge.hxx>
24 #include <BRepLib_MakeVertex.hxx>
25 #include <BRepLib_MakePolygon.hxx>
26 #include <BRepLib_MakeFace.hxx>
27 #include <BRepLib_MakeWire.hxx>
28 #include <BRepTools.hxx>
29 #include <BRepTools_WireExplorer.hxx>
31 #include <BRepTools_Modifier.hxx>
32 #include <BRepTools_TrsfModification.hxx>
33 #include <BRepTopAdaptor_FClass2d.hxx>
34 #include <BRepAdaptor_Curve.hxx>
35 #include <BRepAdaptor_Curve2d.hxx>
37 #include <IntRes2d_IntersectionPoint.hxx>
38 #include <IntRes2d_IntersectionSegment.hxx>
39 #include <Extrema_ExtPC.hxx>
42 #include <TopExp_Explorer.hxx>
44 #include <Standard_ConstructionError.hxx>
46 #include <TopOpeBRepBuild_Builder.hxx>
47 #include <TopOpeBRepDS_HDataStructure.hxx>
48 #include <TopOpeBRepDS_CurveExplorer.hxx>
49 #include <TopOpeBRep_DSFiller.hxx>
50 #include <TopOpeBRepTool_GeomTool.hxx>
51 #include <TopOpeBRep_ShapeIntersector.hxx>
52 #include <TopOpeBRep_FacesFiller.hxx>
53 #include <TopOpeBRep_GeomTool.hxx>
55 #include <TopoDS_Iterator.hxx>
56 #include <TopTools_ListIteratorOfListOfShape.hxx>
57 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
59 #include <Geom_Surface.hxx>
60 #include <Geom_RectangularTrimmedSurface.hxx>
61 #include <Geom_OffsetSurface.hxx>
62 #include <Geom_BezierSurface.hxx>
63 #include <Geom_BSplineSurface.hxx>
64 #include <Geom_ConicalSurface.hxx>
65 #include <Geom_Curve.hxx>
66 #include <Geom_Line.hxx>
67 #include <Geom_Conic.hxx>
68 #include <Geom_TrimmedCurve.hxx>
69 #include <GCPnts_QuasiUniformDeflection.hxx>
71 #include <GeomLib.hxx>
72 #include <GeomAPI.hxx>
73 #include <GeomAPI_ProjectPointOnCurve.hxx>
74 #include <Geom2d_TrimmedCurve.hxx>
75 #include <Geom2d_Line.hxx>
76 #include <Geom2d_Curve.hxx>
77 #include <Geom2d_Circle.hxx>
78 #include <Geom2d_Ellipse.hxx>
79 #include <Geom2d_Parabola.hxx>
80 #include <Geom2d_Hyperbola.hxx>
81 #include <Geom2d_BezierCurve.hxx>
82 #include <Geom2d_BSplineCurve.hxx>
84 #include <Geom2dAdaptor_Curve.hxx>
85 #include <Geom2dInt_GInter.hxx>
87 #include <GeomAdaptor_Surface.hxx>
88 #include <GeomProjLib.hxx>
89 #include <GeomInt_IntSS.hxx>
90 #include <ProjLib_ProjectedCurve.hxx>
91 #include <ProjLib_HProjectedCurve.hxx>
101 #include <Precision.hxx>
102 #include <Standard_ConstructionError.hxx>
104 #include <BRep_TEdge.hxx>
105 #include <Extrema_ExtPC2d.hxx>
107 #include <Geom_SurfaceOfLinearExtrusion.hxx>
108 #include <Geom_SurfaceOfRevolution.hxx>
109 #include <GCPnts_AbscissaPoint.hxx>
111 //tma: for new boolean operation
112 #include <TopTools_SequenceOfShape.hxx>
113 #include <BOPTools_DSFiller.hxx>
114 #include <Geom_BSplineCurve.hxx>
115 #include <GeomConvert_CompCurveToBSplineCurve.hxx>
116 #include <Geom2dConvert_CompCurveToBSplineCurve.hxx>
117 #include <GeomConvert_ApproxCurve.hxx>
118 #include <Geom2dConvert_ApproxCurve.hxx>
119 //#include <BRepAlgoAPI_Section.hxx>
120 #include <BooleanOperations_ShapesDataStructure.hxx>
121 #include <BOPTools_InterferencePool.hxx>
122 #include <BOPTools_SSInterference.hxx>
123 #include <BOPTools_SequenceOfCurves.hxx>
124 #include <BOPTools_Curve.hxx>
125 #include <BOPTools_ListOfPaveBlock.hxx>
126 #include <BOPTools_ListIteratorOfListOfPaveBlock.hxx>
127 #include <BOPTools_PaveBlock.hxx>
128 #include <BRepAlgoAPI_Section.hxx>
129 #include <BOPTools_SSIntersectionAttribute.hxx>
130 #include <BOPTools_PaveFiller.hxx>
131 #include <BOPTools_Tools2D.hxx>
132 #include <BOPTools_ListIteratorOfListOfPave.hxx>
133 #include <TopoDS_Compound.hxx>
134 #include <GCPnts_UniformAbscissa.hxx>
135 #include <BRep_ListIteratorOfListOfCurveRepresentation.hxx>
136 #include <BRep_CurveRepresentation.hxx>
138 #include <BRepOffset_ListOfInterval.hxx>
139 #include <BRepOffset_Interval.hxx>
140 #include <TColgp_Array1OfPnt2d.hxx>
141 #include <ShapeCustom_Curve2d.hxx>
142 #include <GeomAPI_ExtremaCurveCurve.hxx>
150 Standard_Boolean AffichInter = Standard_False;
151 static Standard_Boolean AffichExtent = Standard_False;
152 static Standard_Integer NbNewEdges = 1;
153 static Standard_Integer NbFaces = 1;
154 static Standard_Integer NbFOB = 1;
155 static Standard_Integer NbFTE = 1;
156 static Standard_Integer NbExtE = 1;
158 //char* name = new char[100];
162 //=======================================================================
163 //function : EdgeVertices
165 //=======================================================================
167 void BRepOffset_Tool::EdgeVertices (const TopoDS_Edge& E,
171 if (E.Orientation() == TopAbs_REVERSED) {
172 TopExp::Vertices(E,V2,V1);
175 TopExp::Vertices(E,V1,V2);
179 //=======================================================================
180 //function : OriEdgeInFace
182 //=======================================================================
184 TopAbs_Orientation BRepOffset_Tool::OriEdgeInFace (const TopoDS_Edge& E,
185 const TopoDS_Face& F )
189 TopAbs_Orientation O =
193 Exp.Init(F.Oriented(TopAbs_FORWARD),TopAbs_EDGE);
195 for (; Exp.More() ;Exp.Next()) {
196 if (Exp.Current().IsSame(E)) {
197 return Exp.Current().Orientation();
200 Standard_ConstructionError::Raise("BRepOffset_Tool::OriEdgeInFace");
201 return E.Orientation();
205 //=======================================================================
206 //function : FindPeriod
208 //=======================================================================
210 static void FindPeriod (const TopoDS_Face& F,
219 for (exp.Init(F,TopAbs_EDGE); exp.More(); exp.Next()) {
220 const TopoDS_Edge& E = TopoDS::Edge(exp.Current());
223 const Handle(Geom2d_Curve) C = BRep_Tool::CurveOnSurface(E,F,pf,pl);
224 if (C.IsNull()) return;
225 Geom2dAdaptor_Curve PC(C,pf,pl);
226 Standard_Real i, nbp = 20;
227 if (PC.GetType() == GeomAbs_Line) nbp = 2;
228 Standard_Real step = (pl - pf) / nbp;
232 for (i = 2; i < nbp; i++) {
239 B.Get(umin,vmin,umax,vmax);
243 //=======================================================================
244 //function : PutInBounds
245 //purpose : Recadre la courbe 2d dans les bounds de la face
246 //=======================================================================
248 static void PutInBounds (const TopoDS_Face& F,
249 const TopoDS_Edge& E,
250 Handle(Geom2d_Curve)& C2d)
252 Standard_Real umin,umax,vmin,vmax;
254 BRep_Tool::Range(E,f,l);
256 TopLoc_Location L; // Recup S avec la location pour eviter la copie.
257 Handle (Geom_Surface) S = BRep_Tool::Surface(F,L);
259 if (S->IsInstance(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
260 S = (*(Handle_Geom_RectangularTrimmedSurface*)&S)->BasisSurface();
265 if (!S->IsUPeriodic() && !S->IsVPeriodic()) return;
267 FindPeriod (F,umin,umax,vmin,vmax);
269 if (S->IsUPeriodic()) {
270 Standard_Real period = S->UPeriod();
271 Standard_Real eps = period*1.e-6;
272 gp_Pnt2d Pf = C2d->Value(f);
273 gp_Pnt2d Pl = C2d->Value(l);
274 gp_Pnt2d Pm = C2d->Value(0.34*f + 0.66*l);
275 Standard_Real minC = Min(Pf.X(),Pl.X()); minC = Min(minC,Pm.X());
276 Standard_Real maxC = Max(Pf.X(),Pl.X()); maxC = Max(maxC,Pm.X());
277 Standard_Real du = 0.;
278 if (minC< umin - eps) {
279 du = (int((umin - minC)/period) + 1)*period;
281 if (minC > umax + eps) {
282 du = -(int((minC - umax)/period) + 1)*period;
287 minC += du; maxC += du;
289 // Ajuste au mieux la courbe dans le domaine.
290 if (maxC > umax +100*eps) {
291 Standard_Real d1 = maxC - umax;
292 Standard_Real d2 = umin - minC + period;
293 if (d2 < d1) du =-period;
303 if (S->IsVPeriodic()) {
304 Standard_Real period = S->VPeriod();
305 Standard_Real eps = period*1.e-6;
306 gp_Pnt2d Pf = C2d->Value(f);
307 gp_Pnt2d Pl = C2d->Value(l);
308 gp_Pnt2d Pm = C2d->Value(0.34*f + 0.66*l);
309 Standard_Real minC = Min(Pf.Y(),Pl.Y()); minC = Min(minC,Pm.Y());
310 Standard_Real maxC = Max(Pf.Y(),Pl.Y()); maxC = Max(maxC,Pm.Y());
311 Standard_Real dv = 0.;
312 if (minC< vmin - eps) {
313 dv = (int((vmin - minC)/period) + 1)*period;
315 if (minC > vmax + eps) {
316 dv = -(int((minC - vmax)/period) + 1)*period;
321 minC += dv; maxC += dv;
323 // Ajuste au mieux la courbe dans le domaine.
324 if (maxC > vmax +100*eps) {
325 Standard_Real d1 = maxC - vmax;
326 Standard_Real d2 = vmin - minC + period;
327 if (d2 < d1) dv =-period;
336 //=======================================================================
339 //=======================================================================
341 Standard_Real BRepOffset_Tool::Gabarit(const Handle(Geom_Curve)& aCurve)
343 GeomAdaptor_Curve GC( aCurve );
345 BndLib_Add3dCurve::Add( GC, Precision::Confusion(), aBox );
346 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax, dist;
347 aBox.Get( aXmin, aYmin, aZmin, aXmax, aYmax, aZmax );
348 dist = Max( (aXmax-aXmin), (aYmax-aYmin) );
349 dist = Max( dist, (aZmax-aZmin) );
353 //=======================================================================
354 //function : BuildPCurves
356 //=======================================================================
358 static void BuildPCurves (const TopoDS_Edge& E,
359 const TopoDS_Face& F)
362 Handle (Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface (E,F,ff,ll);
363 if (!C2d.IsNull()) return;
365 //Standard_Real Tolerance = Max(Precision::Confusion(),BRep_Tool::Tolerance(E));
366 Standard_Real Tolerance = Precision::Confusion();
368 BRepAdaptor_Surface AS(F,0);
369 BRepAdaptor_Curve AC(E);
371 //Try to find pcurve on a bound of BSpline or Bezier surface
372 Handle( Geom_Surface ) theSurf = BRep_Tool::Surface( F );
373 Handle( Standard_Type ) typS = theSurf->DynamicType();
374 if (typS == STANDARD_TYPE(Geom_OffsetSurface))
375 typS = (*((Handle(Geom_OffsetSurface)*)&theSurf))->BasisSurface()->DynamicType();
376 if (typS == STANDARD_TYPE(Geom_BezierSurface) || typS == STANDARD_TYPE(Geom_BSplineSurface))
378 gp_Pnt fpoint = AC.Value( AC.FirstParameter() );
379 gp_Pnt lpoint = AC.Value( AC.LastParameter() );
380 TopoDS_Face theFace = BRepLib_MakeFace( theSurf, Precision::Confusion() );
381 Standard_Real U1 = 0., U2 = 0., TolProj = 1.e-4; //1.e-5;
383 TopExp_Explorer Explo;
384 Explo.Init( theFace, TopAbs_EDGE );
385 for (; Explo.More(); Explo.Next())
387 TopoDS_Edge anEdge = TopoDS::Edge( Explo.Current() );
388 BRepAdaptor_Curve aCurve( anEdge );
389 Extrema_ExtPC fextr( fpoint, aCurve );
390 if (!fextr.IsDone() || fextr.NbExt() < 1)
392 Standard_Real dist2, dist2min = RealLast();
394 for (i = 1; i <= fextr.NbExt(); i++)
396 dist2 = fextr.SquareDistance(i);
397 if (dist2 < dist2min)
400 U1 = fextr.Point(i).Parameter();
403 if (dist2min > TolProj * TolProj)
405 Extrema_ExtPC lextr( lpoint, aCurve );
406 if (!lextr.IsDone() || lextr.NbExt() <1)
408 dist2min = RealLast();
409 for (i = 1; i <= lextr.NbExt(); i++)
411 dist2 = lextr.SquareDistance(i);
412 if (dist2 < dist2min)
415 U2 = lextr.Point(i).Parameter();
418 if (dist2min <= TolProj * TolProj)
423 } // for (; Explo.More(); Explo.Current())
425 if (! theEdge.IsNull())
427 //Construction of pcurve
430 Standard_Real temp = U1;
435 C2d = BRep_Tool::CurveOnSurface( theEdge, theFace, f, l );
436 C2d = new Geom2d_TrimmedCurve( C2d, U1, U2 );
438 if (theSurf->IsUPeriodic() || theSurf->IsVPeriodic())
439 PutInBounds( F, E, C2d );
442 B.UpdateEdge( E, C2d, F, BRep_Tool::Tolerance(E) );
443 BRepLib::SameRange( E );
449 Handle(BRepAdaptor_HSurface) HS = new BRepAdaptor_HSurface(AS);
450 Handle(BRepAdaptor_HCurve) HC = new BRepAdaptor_HCurve(AC);
452 ProjLib_ProjectedCurve Proj(HS,HC,Tolerance);
454 switch ( Proj.GetType()) {
457 C2d = new Geom2d_Line(Proj.Line());
461 C2d = new Geom2d_Circle(Proj.Circle());
464 case GeomAbs_Ellipse:
465 C2d = new Geom2d_Ellipse(Proj.Ellipse());
468 case GeomAbs_Parabola:
469 C2d = new Geom2d_Parabola(Proj.Parabola());
472 case GeomAbs_Hyperbola:
473 C2d = new Geom2d_Hyperbola(Proj.Hyperbola());
476 case GeomAbs_BezierCurve:
480 case GeomAbs_BSplineCurve:
481 C2d = Proj.BSpline();
489 if (AS.IsUPeriodic() || AS.IsVPeriodic()) {
490 PutInBounds(F,E,C2d);
494 B.UpdateEdge (E,C2d,F,BRep_Tool::Tolerance(E));
497 Standard_ConstructionError::Raise("BRepOffset_Tool::BuildPCurves");
498 cout <<"Echec ProjLib"<<endl;
502 //=======================================================================
505 //=======================================================================
507 void BRepOffset_Tool::OrientSection (const TopoDS_Edge& E,
508 const TopoDS_Face& F1,
509 const TopoDS_Face& F2,
510 TopAbs_Orientation& O1,
511 TopAbs_Orientation& O2)
516 Handle (Geom_Surface) S1 = BRep_Tool::Surface(F1);
517 Handle (Geom_Surface) S2 = BRep_Tool::Surface(F2);
518 Handle (Geom2d_Curve) C1 = BRep_Tool::CurveOnSurface(E,F1,f,l);
519 Handle (Geom2d_Curve) C2 = BRep_Tool::CurveOnSurface(E,F2,f,l);
520 Handle (Geom_Curve) C = BRep_Tool::Curve(E,L,f,l);
522 BRepAdaptor_Curve BAcurve( E );
523 GCPnts_UniformAbscissa Distribution( BAcurve, 3 );
524 Standard_Real ParOnC = Distribution.Parameter(2); //0.5*(f+l);
526 gp_Vec T1 = C->DN(ParOnC,1).Transformed(L.Transformation());
527 if (T1.SquareMagnitude() > gp::Resolution()) {
531 gp_Pnt2d P = C1->Value(ParOnC);
535 S1->D1(P.X(),P.Y(),P3,D1U,D1V);
537 if (F1.Orientation() == TopAbs_REVERSED) DN1.Reverse();
539 P = C2->Value(ParOnC);
540 S2->D1(P.X(),P.Y(),P3,D1U,D1V);
542 if (F2.Orientation() == TopAbs_REVERSED) DN2.Reverse();
544 gp_Vec ProVec = DN2^T1;
545 Standard_Real Prod = DN1.Dot(ProVec);
550 O1 = TopAbs_REVERSED;
553 Prod = DN2.Dot(ProVec);
558 O2 = TopAbs_REVERSED;
560 if (F1.Orientation() == TopAbs_REVERSED) O1 = TopAbs::Reverse(O1);
561 if (F2.Orientation() == TopAbs_REVERSED) O2 = TopAbs::Reverse(O2);
564 //=======================================================================
565 //function : HasCommonShape
567 //=======================================================================
569 Standard_Boolean BRepOffset_Tool::HasCommonShapes (const TopoDS_Face& F1,
570 const TopoDS_Face& F2,
571 TopTools_ListOfShape& LE,
572 TopTools_ListOfShape& LV)
574 Standard_Boolean Common = Standard_False;
575 LE.Clear(); LV.Clear();
577 TopExp_Explorer exp1;
578 exp1.Init(F1,TopAbs_EDGE);
580 for (; exp1.More(); exp1.Next()) {
581 TopExp_Explorer exp2;
582 exp2.Init(F2,TopAbs_EDGE);
583 for (; exp2.More(); exp2.Next()) {
584 if (exp1.Current().IsSame(exp2.Current())) {
585 Common = Standard_True;
586 LE.Append(exp1.Current());
590 for (exp1.Init(F1,TopAbs_VERTEX); exp1.More(); exp1.Next()) {
591 TopExp_Explorer exp2;
592 exp2.Init(F2,TopAbs_EDGE);
593 for (exp2.Init(F2,TopAbs_VERTEX); exp2.More(); exp2.Next()) {
594 if (exp1.Current().IsSame(exp2.Current())) {
595 Common = Standard_True;
596 LV.Append(exp1.Current());
603 //=======================================================================
606 //=======================================================================
608 static Standard_Boolean ToSmall (const Handle(Geom_Curve)& C)
610 Standard_Real Tol = 10*Precision::Confusion();
611 Standard_Real m = (C->FirstParameter()*0.668 + C->LastParameter()*0.332);
612 gp_Pnt P1 = C->Value(C->FirstParameter());
613 gp_Pnt P2 = C->Value(C->LastParameter());
614 gp_Pnt P3 = C->Value(m);
615 if (P1.Distance(P2) > Tol) return Standard_False;
616 if (P2.Distance(P3) > Tol) return Standard_False;
617 return Standard_True;
621 //=======================================================================
622 //function : IsOnSurface
624 //=======================================================================
626 static Standard_Boolean IsOnSurface(const Handle(Geom_Curve)& C,
627 const Handle(Geom_Surface)& S,
628 Standard_Real TolConf,
629 Standard_Real& TolReached)
631 Standard_Real f = C->FirstParameter();
632 Standard_Real l = C->LastParameter();
633 Standard_Integer n = 5;
634 Standard_Real du = (f-l)/(n-1);
640 GeomAdaptor_Surface AS(S);
642 switch ( AS.GetType()) {
645 gp_Ax3 Ax = AS.Plane().Position();
646 for ( Standard_Integer i = 0; i < n; i++) {
647 P = C->Value(f+i*du);
648 ElSLib::PlaneParameters(Ax,P,U,V);
649 TolReached = P.Distance(ElSLib::PlaneValue(U,V,Ax));
650 if ( TolReached > TolConf)
651 return Standard_False;
655 case GeomAbs_Cylinder:
657 gp_Ax3 Ax = AS.Cylinder().Position();
658 Standard_Real Rad = AS.Cylinder().Radius();
659 for ( Standard_Integer i = 0; i < n; i++) {
660 P = C->Value(f+i*du);
661 ElSLib::CylinderParameters(Ax,Rad,P,U,V);
662 TolReached = P.Distance(ElSLib::CylinderValue(U,V,Ax,Rad));
663 if ( TolReached > TolConf)
664 return Standard_False;
670 gp_Ax3 Ax = AS.Cone().Position();
671 Standard_Real Rad = AS.Cone().RefRadius();
672 Standard_Real Alp = AS.Cone().SemiAngle();
673 for ( Standard_Integer i = 0; i < n; i++) {
674 P = C->Value(f+i*du);
675 ElSLib::ConeParameters(Ax,Rad,Alp,P,U,V);
676 TolReached = P.Distance(ElSLib::ConeValue(U,V,Ax,Rad,Alp));
677 if ( TolReached > TolConf)
678 return Standard_False;
684 gp_Ax3 Ax = AS.Sphere().Position();
685 Standard_Real Rad = AS.Sphere().Radius();
686 for ( Standard_Integer i = 0; i < n; i++) {
687 P = C->Value(f+i*du);
688 ElSLib::SphereParameters(Ax,Rad,P,U,V);
689 TolReached = P.Distance(ElSLib::SphereValue(U,V,Ax,Rad));
690 if ( TolReached > TolConf)
691 return Standard_False;
697 gp_Ax3 Ax = AS.Torus().Position();
698 Standard_Real R1 = AS.Torus().MajorRadius();
699 Standard_Real R2 = AS.Torus().MinorRadius();
700 for ( Standard_Integer i = 0; i < n; i++) {
701 P = C->Value(f+i*du);
702 ElSLib::TorusParameters(Ax,R1,R2,P,U,V);
703 TolReached = P.Distance(ElSLib::TorusValue(U,V,Ax,R1,R2));
704 if ( TolReached > TolConf)
705 return Standard_False;
712 return Standard_False;
716 return Standard_True;
720 //=======================================================================
721 //function : PipeInter
723 //=======================================================================
725 void BRepOffset_Tool::PipeInter(const TopoDS_Face& F1,
726 const TopoDS_Face& F2,
727 TopTools_ListOfShape& L1,
728 TopTools_ListOfShape& L2,
729 const TopAbs_State Side)
734 char* name = new char[100];
735 sprintf(name,"FF_%d",NbFaces++);
737 sprintf(name,"FF_%d",NbFaces++);
742 Handle (Geom_Curve) CI;
744 TopAbs_Orientation O1,O2;
745 L1.Clear(); L2.Clear();
747 Handle (Geom_Surface) S1 = BRep_Tool::Surface(F1);
748 Handle (Geom_Surface) S2 = BRep_Tool::Surface(F2);
750 GeomInt_IntSS Inter (S1,S2, Precision::Confusion(),1,1,1);
752 if (Inter.IsDone()) {
753 for (Standard_Integer i = 1; i <= Inter.NbLines(); i++) {
755 if (ToSmall(CI)) continue;
756 TopoDS_Edge E = BRepLib_MakeEdge(CI);
757 if (Inter.HasLineOnS1(i)) {
758 Handle(Geom2d_Curve) C2 = Inter.LineOnS1(i);
759 PutInBounds (F1,E,C2);
760 B.UpdateEdge (E,C2,F1,BRep_Tool::Tolerance(E));
765 if (Inter.HasLineOnS2(i)) {
766 Handle(Geom2d_Curve) C2 = Inter.LineOnS2(i);
767 PutInBounds (F2,E,C2);
768 B.UpdateEdge (E,C2,F2,BRep_Tool::Tolerance(E));
773 OrientSection (E,F1,F2,O1,O2);
774 if (Side == TopAbs_OUT) {
775 O1 = TopAbs::Reverse(O1);
776 O2 = TopAbs::Reverse(O2);
778 L1.Append (E.Oriented(O1));
779 L2.Append (E.Oriented(O2));
783 char* name = new char[100];
784 sprintf(name,"EI_%d",NbNewEdges++);
785 DBRep::Set(name,E.Oriented(O1));
793 //=======================================================================
794 //function : IsAutonomVertex
795 //purpose : Checks wether a vertex is "autonom" or not
796 //=======================================================================
798 static Standard_Boolean IsAutonomVertex(const TopoDS_Shape& aVertex,
799 const TopoDS_Shape& F1,
800 const TopoDS_Shape& F2,
801 const BooleanOperations_ShapesDataStructure& theDS,
802 const BOPTools_PaveFiller& thePaveFiller)
804 Standard_Integer i, index = theDS.ShapeIndex( aVertex, 1 );
807 index = theDS.ShapeIndex( aVertex, 2 );
810 for (i = theDS.NumberOfSourceShapes()+1; i <= theDS.NumberOfInsertedShapes(); i++)
812 const TopoDS_Shape& aShape = theDS.GetShape(i);
813 if (aVertex.IsSame(aShape))
822 Standard_Integer indF1 = theDS.ShapeIndex( F1, 1 );
823 Standard_Integer indF2 = theDS.ShapeIndex( F2, 2 );
825 BooleanOperations_KindOfInterference theTypeInterf;
826 const BOPTools_PavePool& thePavePool = thePaveFiller.PavePool();
827 BOPTools_ListIteratorOfListOfPave itpave;
828 for (i = 1; i <= thePavePool.Length(); i++)
830 const BOPTools_ListOfPave& aPaveList = thePavePool(i).Set();
831 for (itpave.Initialize( aPaveList ); itpave.More(); itpave.Next())
833 BOPTools_Pave aPave = itpave.Value();
834 if (aPave.Index() == index)
836 theTypeInterf = aPave.Type();
837 if (theTypeInterf != BooleanOperations_SurfaceSurface &&
838 theTypeInterf != BooleanOperations_UnknownInterference)
839 return Standard_False;
844 BOPTools_PaveFiller * pPF = (BOPTools_PaveFiller*) &thePaveFiller;
845 BOPTools_PaveFiller& thePF = *pPF;
846 BOPTools_CArray1OfSSInterference& aFFs = thePF.InterfPool()->SSInterferences();
847 Standard_Integer aNbFFs=aFFs.Extent();
848 for (i = 1; i <= aNbFFs; i++)
850 BOPTools_SSInterference& aFFi = aFFs(i);
852 if (aFFi.Index1() == indF1 && aFFi.Index2() == indF2)
854 const BOPTools_ListOfPave& aPaveList = aFFi.NewPaveSet().Set();
855 for (itpave.Initialize( aPaveList ); itpave.More(); itpave.Next())
857 BOPTools_Pave aPave = itpave.Value();
858 if (aPave.Index() == index)
860 theTypeInterf = aPave.Type();
861 if (theTypeInterf != BooleanOperations_SurfaceSurface &&
862 theTypeInterf != BooleanOperations_UnknownInterference)
863 return Standard_False;
869 return Standard_True;
873 //=======================================================================
874 //function : AreConnex
875 //purpose : define if two shapes are connex by a vertex (vertices)
876 //=======================================================================
878 static Standard_Boolean AreConnex(const TopoDS_Wire& W1,
879 const TopoDS_Wire& W2,
880 const TopoDS_Shape& F1,
881 const TopoDS_Shape& F2,
882 const BOPTools_DSFiller* pDF)
884 TopoDS_Vertex V11, V12, V21, V22;
885 TopExp::Vertices( W1, V11, V12 );
886 TopExp::Vertices( W2, V21, V22 );
888 if (V11.IsSame(V21) || V11.IsSame(V22) ||
889 V12.IsSame(V21) || V12.IsSame(V22))
891 Standard_Boolean isCV1 = V11.IsSame(V21) || V11.IsSame(V22);
892 Standard_Boolean isCV2 = V12.IsSame(V21) || V12.IsSame(V22);
893 if (isCV1 && !IsAutonomVertex(V11, F1, F2, pDF->DS(), pDF->PaveFiller()))
896 return Standard_False;
897 if (!IsAutonomVertex(V12, F1, F2, pDF->DS(), pDF->PaveFiller()))
898 return Standard_False;
900 if (!isCV1 && !IsAutonomVertex(V12, F1, F2, pDF->DS(), pDF->PaveFiller()))
901 return Standard_False;
903 TopoDS_Vertex CV = (V11.IsSame(V21) || V11.IsSame(V22))? V11 : V12;
905 TopoDS_Iterator itw( W1 );
906 for (; itw.More(); itw.Next())
908 E1 = TopoDS::Edge(itw.Value());
909 TopoDS_Vertex V1, V2;
910 TopExp::Vertices( E1, V1, V2 );
911 if (V1.IsSame(CV) || V2.IsSame(CV))
914 itw.Initialize( W2 );
915 E2 = TopoDS::Edge(itw.Value());
918 Handle(Geom_Curve) C1 = BRep_Tool::Curve( E1, f, l );
919 if (C1->IsInstance(STANDARD_TYPE(Geom_TrimmedCurve)))
920 C1 = (*((Handle(Geom_TrimmedCurve)*)&C1))->BasisCurve();
922 Handle(Geom_Curve) C2 = BRep_Tool::Curve( E2, f, l );
923 if (C2->IsInstance(STANDARD_TYPE(Geom_TrimmedCurve)))
924 C2 = (*((Handle(Geom_TrimmedCurve)*)&C2))->BasisCurve();
926 if (C1->IsInstance(STANDARD_TYPE(Geom_Line)) &&
927 C2->IsInstance(STANDARD_TYPE(Geom_Line)))
929 Handle(Geom_Line) L1 = *((Handle(Geom_Line)*) &C1);
930 gp_Ax1 Axis1 = L1->Position();
931 Handle(Geom_Line) L2 = *((Handle(Geom_Line)*) &C2);
932 gp_Ax1 Axis2 = L2->Position();
933 if (! Axis1.IsParallel( Axis2, Precision::Angular() ))
934 return Standard_False;
937 return Standard_True;
940 return Standard_False;
943 //=======================================================================
944 //function : AreClosed
945 //purpose : define if two edges are connex by two vertices
946 //=======================================================================
948 static Standard_Boolean AreClosed(const TopoDS_Edge& E1,
949 const TopoDS_Edge& E2)
951 TopoDS_Vertex V11, V12, V21, V22;
952 TopExp::Vertices( E1, V11, V12 );
953 TopExp::Vertices( E2, V21, V22 );
955 if (V11.IsSame(V21) && V12.IsSame(V22) ||
956 V11.IsSame(V22) && V12.IsSame(V21))
957 return Standard_True;
959 return Standard_False;
962 //=======================================================================
963 //function : BSplineEdges
965 //=======================================================================
967 static Standard_Boolean BSplineEdges(const TopoDS_Edge& E1,
968 const TopoDS_Edge& E2,
969 const Standard_Integer par1,
970 const Standard_Integer par2,
971 Standard_Real& angle)
973 Standard_Real first1, last1, first2, last2, Param1, Param2;
975 Handle(Geom_Curve) C1 = BRep_Tool::Curve( E1, first1, last1 );
976 if (C1->IsInstance(STANDARD_TYPE(Geom_TrimmedCurve)))
977 C1 = (*((Handle(Geom_TrimmedCurve)*)&C1))->BasisCurve();
979 Handle(Geom_Curve) C2 = BRep_Tool::Curve( E2, first2, last2 );
980 if (C2->IsInstance(STANDARD_TYPE(Geom_TrimmedCurve)))
981 C2 = (*((Handle(Geom_TrimmedCurve)*)&C2))->BasisCurve();
983 if (!C1->IsInstance(STANDARD_TYPE(Geom_BSplineCurve)) ||
984 !C2->IsInstance(STANDARD_TYPE(Geom_BSplineCurve)))
985 return Standard_False;
987 Param1 = (par1 == 0)? first1 : last1;
988 Param2 = (par2 == 0)? first2 : last2;
992 C1->D1( Param1, Pnt1, Der1 );
993 C2->D1( Param2, Pnt2, Der2 );
995 if (Der1.Magnitude() <= gp::Resolution() ||
996 Der2.Magnitude() <= gp::Resolution())
999 angle = Der1.Angle(Der2);
1001 return Standard_True;
1004 //=======================================================================
1005 //function : AngleWireEdge
1007 //=======================================================================
1009 static Standard_Real AngleWireEdge(const TopoDS_Wire& aWire,
1010 const TopoDS_Edge& anEdge)
1012 TopoDS_Vertex V11, V12, V21, V22, CV;
1013 TopExp::Vertices( aWire, V11, V12 );
1014 TopExp::Vertices( anEdge, V21, V22 );
1015 CV = (V11.IsSame(V21) || V11.IsSame(V22))? V11 : V12;
1016 TopoDS_Edge FirstEdge;
1017 TopoDS_Iterator itw(aWire);
1018 for (; itw.More(); itw.Next())
1020 FirstEdge = TopoDS::Edge(itw.Value());
1021 TopoDS_Vertex v1, v2;
1022 TopExp::Vertices( FirstEdge, v1, v2 );
1023 if (v1.IsSame(CV) || v2.IsSame(CV))
1030 Standard_Real Angle;
1031 if (V11.IsSame(CV) && V21.IsSame(CV))
1033 BSplineEdges( FirstEdge, anEdge, 0, 0, Angle );
1036 else if (V11.IsSame(CV) && V22.IsSame(CV))
1037 BSplineEdges( FirstEdge, anEdge, 0, 1, Angle );
1038 else if (V12.IsSame(CV) && V21.IsSame(CV))
1039 BSplineEdges( FirstEdge, anEdge, 1, 0, Angle );
1042 BSplineEdges( FirstEdge, anEdge, 1, 1, Angle );
1049 //=======================================================================
1050 //function : ReconstructPCurves
1052 //=======================================================================
1054 static void ReconstructPCurves(const TopoDS_Edge& anEdge)
1057 Handle(Geom_Curve) C3d = BRep_Tool::Curve(anEdge, f, l);
1059 BRep_ListIteratorOfListOfCurveRepresentation
1060 itcr( (Handle(BRep_TEdge)::DownCast(anEdge.TShape()))->ChangeCurves() );
1061 for (; itcr.More(); itcr.Next())
1063 Handle( BRep_CurveRepresentation ) CurveRep = itcr.Value();
1064 if (CurveRep->IsCurveOnSurface())
1066 Handle(Geom_Surface) theSurf = CurveRep->Surface();
1067 TopLoc_Location theLoc = CurveRep->Location();
1068 theLoc = anEdge.Location() * theLoc;
1069 theSurf = Handle(Geom_Surface)::DownCast
1070 (theSurf->Transformed(theLoc.Transformation()));
1071 Handle(Geom2d_Curve) ProjPCurve =
1072 GeomProjLib::Curve2d( C3d, f, l, theSurf );
1073 CurveRep->PCurve( ProjPCurve );
1078 //=======================================================================
1079 //function : ConcatPCurves
1081 //=======================================================================
1083 static Handle(Geom2d_Curve) ConcatPCurves(const TopoDS_Edge& E1,
1084 const TopoDS_Edge& E2,
1085 const TopoDS_Face& F,
1086 const Standard_Boolean After,
1087 Standard_Real& newFirst,
1088 Standard_Real& newLast)
1090 Standard_Real Tol = 1.e-7;
1091 GeomAbs_Shape Continuity = GeomAbs_C1;
1092 Standard_Integer MaxDeg = 14;
1093 Standard_Integer MaxSeg = 16;
1095 Standard_Real first1, last1, first2, last2;
1096 Handle(Geom2d_Curve) PCurve1, PCurve2, newPCurve;
1098 PCurve1 = BRep_Tool::CurveOnSurface( E1, F, first1, last1 );
1099 if (PCurve1->IsInstance(STANDARD_TYPE(Geom2d_TrimmedCurve)))
1100 PCurve1 = (*((Handle(Geom2d_TrimmedCurve)*)&PCurve1))->BasisCurve();
1102 PCurve2 = BRep_Tool::CurveOnSurface( E2, F, first2, last2 );
1103 if (PCurve2->IsInstance(STANDARD_TYPE(Geom2d_TrimmedCurve)))
1104 PCurve2 = (*((Handle(Geom2d_TrimmedCurve)*)&PCurve2))->BasisCurve();
1106 if (PCurve1 == PCurve2)
1108 newPCurve = PCurve1;
1109 newFirst = Min( first1, first2 );
1110 newLast = Max( last1, last2 );
1112 else if (PCurve1->DynamicType() == PCurve2->DynamicType() &&
1113 (PCurve1->IsInstance(STANDARD_TYPE(Geom2d_Line)) ||
1114 PCurve1->IsKind(STANDARD_TYPE(Geom2d_Conic))))
1116 newPCurve = PCurve1;
1118 P1 = PCurve2->Value( first2 );
1119 P2 = PCurve2->Value( last2 );
1120 if (PCurve1->IsInstance(STANDARD_TYPE(Geom2d_Line)))
1122 Handle(Geom2d_Line) Lin1 = *((Handle(Geom2d_Line)*) &PCurve1);
1123 gp_Lin2d theLin = Lin1->Lin2d();
1124 first2 = ElCLib::Parameter( theLin, P1 );
1125 last2 = ElCLib::Parameter( theLin, P2 );
1127 else if (PCurve1->IsInstance(STANDARD_TYPE(Geom2d_Circle)))
1129 Handle(Geom2d_Circle) Circ1 = *((Handle(Geom2d_Circle)*) &PCurve1);
1130 gp_Circ2d theCirc = Circ1->Circ2d();
1131 first2 = ElCLib::Parameter( theCirc, P1 );
1132 last2 = ElCLib::Parameter( theCirc, P2 );
1134 else if (PCurve1->IsInstance(STANDARD_TYPE(Geom2d_Ellipse)))
1136 Handle(Geom2d_Ellipse) Ell1 = *((Handle(Geom2d_Ellipse)*) &PCurve1);
1137 gp_Elips2d theElips = Ell1->Elips2d();
1138 first2 = ElCLib::Parameter( theElips, P1 );
1139 last2 = ElCLib::Parameter( theElips, P2 );
1141 else if (PCurve1->IsInstance(STANDARD_TYPE(Geom2d_Parabola)))
1143 Handle(Geom2d_Parabola) Parab1 = *((Handle(Geom2d_Parabola)*) &PCurve1);
1144 gp_Parab2d theParab = Parab1->Parab2d();
1145 first2 = ElCLib::Parameter( theParab, P1 );
1146 last2 = ElCLib::Parameter( theParab, P2 );
1148 else if (PCurve1->IsInstance(STANDARD_TYPE(Geom2d_Hyperbola)))
1150 Handle(Geom2d_Hyperbola) Hypr1 = *((Handle(Geom2d_Hyperbola)*) &PCurve1);
1151 gp_Hypr2d theHypr = Hypr1->Hypr2d();
1152 first2 = ElCLib::Parameter( theHypr, P1 );
1153 last2 = ElCLib::Parameter( theHypr, P2 );
1155 newFirst = Min( first1, first2 );
1156 newLast = Max( last1, last2 );
1160 Handle(Geom2d_TrimmedCurve) TC1 = new Geom2d_TrimmedCurve( PCurve1, first1, last1 );
1161 Handle(Geom2d_TrimmedCurve) TC2 = new Geom2d_TrimmedCurve( PCurve2, first2, last2 );
1162 Geom2dConvert_CompCurveToBSplineCurve Concat2d( TC1 );
1163 Concat2d.Add( TC2, Precision::Confusion(), After );
1164 newPCurve = Concat2d.BSplineCurve();
1165 if (newPCurve->Continuity() < GeomAbs_C1)
1167 Geom2dConvert_ApproxCurve Approx2d( newPCurve, Tol, Continuity, MaxSeg, MaxDeg );
1168 if (Approx2d.HasResult())
1169 newPCurve = Approx2d.Curve();
1171 newFirst = newPCurve->FirstParameter();
1172 newLast = newPCurve->LastParameter();
1178 //=======================================================================
1180 //purpose : glue two edges.
1181 //=======================================================================
1183 static TopoDS_Edge Glue(const TopoDS_Edge& E1,
1184 const TopoDS_Edge& E2,
1185 const TopoDS_Vertex& Vfirst,
1186 const TopoDS_Vertex& Vlast,
1187 const Standard_Boolean After,
1188 const TopoDS_Face& F1,
1189 const Standard_Boolean addPCurve1,
1190 const TopoDS_Face& F2,
1191 const Standard_Boolean addPCurve2)
1193 Standard_Real Tol = 1.e-7;
1194 GeomAbs_Shape Continuity = GeomAbs_C1;
1195 Standard_Integer MaxDeg = 14;
1196 Standard_Integer MaxSeg = 16;
1198 Handle(Geom_Curve) C1, C2, newCurve;
1199 Handle(Geom2d_Curve) PCurve1, PCurve2, newPCurve;
1200 Standard_Real first1, last1, first2, last2, fparam=0., lparam=0.;
1201 Standard_Boolean IsCanonic = Standard_False;
1203 C1 = BRep_Tool::Curve( E1, first1, last1 );
1204 if (C1->IsInstance(STANDARD_TYPE(Geom_TrimmedCurve)))
1205 C1 = (*((Handle(Geom_TrimmedCurve)*)&C1))->BasisCurve();
1207 C2 = BRep_Tool::Curve( E2, first2, last2 );
1208 if (C2->IsInstance(STANDARD_TYPE(Geom_TrimmedCurve)))
1209 C2 = (*((Handle(Geom_TrimmedCurve)*)&C2))->BasisCurve();
1214 fparam = Min( first1, first2 );
1215 lparam = Max( last1, last2 );
1217 else if (C1->DynamicType() == C2->DynamicType() &&
1218 (C1->IsInstance(STANDARD_TYPE(Geom_Line)) ||
1219 C1->IsKind(STANDARD_TYPE(Geom_Conic))))
1221 IsCanonic = Standard_True;
1226 Handle(Geom_TrimmedCurve) TC1 = new Geom_TrimmedCurve( C1, first1, last1 );
1227 Handle(Geom_TrimmedCurve) TC2 = new Geom_TrimmedCurve( C2, first2, last2 );
1228 GeomConvert_CompCurveToBSplineCurve Concat( TC1 );
1229 Concat.Add( TC2, Precision::Confusion(), After );
1230 newCurve = Concat.BSplineCurve();
1231 if (newCurve->Continuity() < GeomAbs_C1)
1233 GeomConvert_ApproxCurve Approx3d( newCurve, Tol, Continuity, MaxSeg, MaxDeg );
1234 if (Approx3d.HasResult())
1235 newCurve = Approx3d.Curve();
1237 fparam = newCurve->FirstParameter();
1238 lparam = newCurve->LastParameter();
1241 TopoDS_Edge newEdge;
1245 newEdge = BRepLib_MakeEdge( newCurve, Vfirst, Vlast );
1247 newEdge = BRepLib_MakeEdge( newCurve, Vfirst, Vlast, fparam, lparam );
1249 Standard_Real newFirst, newLast;
1252 newPCurve = ConcatPCurves( E1, E2, F1, After, newFirst, newLast );
1253 BB.UpdateEdge( newEdge, newPCurve, F1, 0. );
1254 BB.Range( newEdge, F1, newFirst, newLast );
1258 newPCurve = ConcatPCurves( E1, E2, F2, After, newFirst, newLast );
1259 BB.UpdateEdge( newEdge, newPCurve, F2, 0. );
1260 BB.Range( newEdge, F2, newFirst, newLast );
1267 //=======================================================================
1268 //function : FindNewVerticesOnBoundsOfFace
1270 //=======================================================================
1272 static void FindNewVerticesOnBoundsOfFace(const BOPTools_DSFiller& pDF,
1273 const TopoDS_Face& aFace,
1274 const Standard_Integer iFace,
1275 TopTools_DataMapOfShapeShape& VEmap)
1277 TopTools_IndexedMapOfShape OldVertices;
1278 TopExp::MapShapes( aFace, TopAbs_VERTEX, OldVertices );
1280 const BOPTools_SplitShapesPool& aPool = pDF.SplitShapesPool();
1282 TopExp_Explorer Explo( aFace, TopAbs_EDGE );
1283 for (; Explo.More(); Explo.Next())
1285 TopoDS_Shape anEdge = Explo.Current();
1286 Standard_Integer eind = pDF.DS().ShapeIndex(anEdge,iFace);
1287 const BOPTools_ListOfPaveBlock& aSplitEdges = aPool( pDF.DS().RefEdge(eind) );
1288 BOPTools_ListIteratorOfListOfPaveBlock itpb( aSplitEdges );
1289 for (; itpb.More(); itpb.Next())
1291 BOPTools_PaveBlock& aPaveBlock = itpb.Value();
1292 TopoDS_Shape aSplit = pDF.DS().GetShape( aPaveBlock.Edge() );
1293 TopoDS_Edge aNewEdge = TopoDS::Edge(aSplit);
1294 TopoDS_Vertex V1, V2;
1295 TopExp::Vertices( aNewEdge, V1, V2 );
1296 if (!OldVertices.Contains( V1 ))
1297 VEmap.Bind( V1, anEdge );
1298 if (!OldVertices.Contains( V2 ))
1299 VEmap.Bind( V2, anEdge );
1304 //=======================================================================
1305 //function : CheckIntersFF
1307 //=======================================================================
1309 static Standard_Boolean CheckIntersFF(const BOPTools_DSFiller& pDF,
1310 const TopoDS_Edge& RefEdge,
1311 const TopoDS_Face& F1,
1312 const TopoDS_Face& F2,
1313 TopTools_IndexedMapOfShape& TrueEdges)
1315 Standard_Boolean isEl1 = Standard_False, isEl2 = Standard_False;
1316 Standard_Boolean isPlane1 = Standard_False, isPlane2 = Standard_False;
1318 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(F1);
1319 if (aSurf->IsInstance(STANDARD_TYPE(Geom_RectangularTrimmedSurface)))
1320 aSurf = (*((Handle(Geom_RectangularTrimmedSurface)*)&aSurf))->BasisSurface();
1321 if (aSurf->IsInstance(STANDARD_TYPE(Geom_Plane)))
1322 isPlane1 = Standard_True;
1323 else if (aSurf->IsKind(STANDARD_TYPE(Geom_ElementarySurface)))
1324 isEl1 = Standard_True;
1326 aSurf = BRep_Tool::Surface(F2);
1327 if (aSurf->IsInstance(STANDARD_TYPE(Geom_RectangularTrimmedSurface)))
1328 aSurf = (*((Handle(Geom_RectangularTrimmedSurface)*)&aSurf))->BasisSurface();
1329 if (aSurf->IsInstance(STANDARD_TYPE(Geom_Plane)))
1330 isPlane2 = Standard_True;
1331 else if (aSurf->IsKind(STANDARD_TYPE(Geom_ElementarySurface)))
1332 isEl2 = Standard_True;
1334 if (isPlane1 || isPlane2)
1335 return Standard_True;
1338 return Standard_True;
1340 const BooleanOperations_ShapesDataStructure& aDS = pDF.DS();
1341 BOPTools_InterferencePool* anIntrPool = (BOPTools_InterferencePool*)&pDF.InterfPool();
1342 BOPTools_CArray1OfSSInterference& aFFs = anIntrPool->SSInterferences();
1343 Standard_Integer aNb = aFFs.Extent();
1344 Standard_Integer i, j, nbe = 0;
1346 TopTools_SequenceOfShape Edges;
1348 for (i = 1; i <= aNb; i++)
1350 BOPTools_SSInterference& aFFi = aFFs(i);
1351 BOPTools_SequenceOfCurves& aBCurves = aFFi.Curves();
1352 Standard_Integer aNbCurves = aBCurves.Length();
1354 for (j = 1; j <= aNbCurves; j++)
1356 BOPTools_Curve& aBC = aBCurves(j);
1357 const BOPTools_ListOfPaveBlock& aSectEdges = aBC.NewPaveBlocks();
1359 BOPTools_ListIteratorOfListOfPaveBlock aPBIt(aSectEdges);
1361 for (; aPBIt.More(); aPBIt.Next())
1363 BOPTools_PaveBlock& aPB=aPBIt.Value();
1364 Standard_Integer nSect = aPB.Edge();
1365 TopoDS_Edge anEdge = TopoDS::Edge(aDS.Shape(nSect));
1366 Edges.Append( anEdge );
1373 return Standard_True;
1375 //define tangents of RefEdge on start and on end
1376 BRepAdaptor_Curve cref(RefEdge);
1377 gp_Vec RefTangFirst = cref.DN(cref.FirstParameter(), 1);
1378 gp_Vec RefTangLast = cref.DN(cref.LastParameter(), 1);
1380 //find the start edge and take it from Edges
1381 TopoDS_Edge StartEdge; //, StartEonF1, StartEonF2, EndEonF1, EndEonF2;
1383 TopTools_DataMapOfShapeShape VEmapF1, VEmapF2;
1384 FindNewVerticesOnBoundsOfFace( pDF, F1, 1, VEmapF1 );
1385 FindNewVerticesOnBoundsOfFace( pDF, F2, 2, VEmapF2 );
1387 Standard_Real AngTol = 0.1;
1388 Standard_Boolean V1onBound = Standard_False;
1389 Standard_Boolean V2onBound = Standard_False;
1390 TopoDS_Vertex V1, V2, Vcur;
1391 gp_Vec TangFirst, TangLast, TangCur;
1392 for (i = 1; i <= Edges.Length(); i++)
1394 StartEdge = TopoDS::Edge(Edges(i));
1395 TopExp::Vertices( StartEdge, V1, V2 );
1396 V1onBound = VEmapF1.IsBound(V1) || VEmapF2.IsBound(V1); // && ?
1397 V2onBound = VEmapF1.IsBound(V2) || VEmapF2.IsBound(V2); // && ?
1398 if (V1onBound || V2onBound)
1400 BRepAdaptor_Curve CE(StartEdge);
1401 TangFirst = CE.DN( CE.FirstParameter(), 1 );
1402 TangLast = CE.DN( CE.LastParameter(), 1 );
1405 if (TangFirst.IsParallel( RefTangFirst, AngTol ) ||
1406 TangFirst.IsParallel( RefTangLast, AngTol ))
1407 break; //start edged found
1411 if (TangLast.IsParallel( RefTangLast, AngTol ) ||
1412 TangLast.IsParallel( RefTangFirst, AngTol ))
1413 break; //start edged found
1418 if (i > Edges.Length()) //start edged not found
1419 return Standard_False;
1421 if (V1onBound && V2onBound)
1423 if (TangFirst.IsParallel(RefTangFirst,AngTol) && TangLast.IsParallel(RefTangLast,AngTol) ||
1424 TangFirst.IsParallel(RefTangLast,AngTol) && TangLast.IsParallel(RefTangFirst,AngTol))
1426 TrueEdges.Add( Edges(i) );
1427 return Standard_True;
1430 return Standard_False;
1433 //StartEonF1 = (V1onBound)? VEmapF1( V1 ) : VEmapF1( V2 );
1434 //StartEonF2 = (V1onBound)? VEmapF2( V1 ) : VEmapF2( V2 );
1436 TrueEdges.Add( Edges(i) );
1438 Vcur = (V1onBound)? V2 : V1;
1439 TangCur = (V1onBound)? TangLast : TangFirst;
1443 //build the chain from StartEdge till the opposite bound of face
1446 TColStd_SequenceOfInteger Candidates;
1447 for (i = 1; i <= Edges.Length(); i++)
1449 TopoDS_Edge anEdge = TopoDS::Edge(Edges(i));
1450 TopExp::Vertices( anEdge, V1, V2 );
1451 if (V1.IsSame(Vcur) || V2.IsSame(Vcur))
1452 Candidates.Append(i);
1454 if (Candidates.IsEmpty())
1457 return Standard_False;
1460 Standard_Integer minind = 1;
1461 if (Candidates.Length() > 1)
1463 Standard_Real MinAngle = RealLast();
1464 for (i = 1; i <= Candidates.Length(); i++)
1466 TopoDS_Edge anEdge = TopoDS::Edge(Edges(Candidates(i)));
1467 TopExp::Vertices( anEdge, V1, V2 );
1468 Standard_Boolean ConnectByFirst = (Vcur.IsSame(V1))? Standard_True : Standard_False;
1469 BRepAdaptor_Curve CE(anEdge);
1470 gp_Vec aTang = (ConnectByFirst)?
1471 CE.DN( CE.FirstParameter(), 1 ) : CE.DN( CE.LastParameter(), 1 );
1472 if (!ConnectByFirst)
1474 Standard_Real anAngle = TangCur.Angle(aTang);
1475 if (anAngle < MinAngle)
1482 TopoDS_Edge CurEdge = TopoDS::Edge(Edges(Candidates(minind)));
1483 TrueEdges.Add( CurEdge );
1484 Edges.Remove(Candidates(minind));
1485 TopExp::Vertices( CurEdge, V1, V2 );
1486 Standard_Boolean ConnectByFirst = (Vcur.IsSame(V1))? Standard_True : Standard_False;
1487 Vcur = (ConnectByFirst)? V2 : V1;
1488 BRepAdaptor_Curve CE(CurEdge);
1489 TangCur = (ConnectByFirst)? CE.DN( CE.LastParameter(), 1 ) : CE.DN( CE.FirstParameter(), 1 );
1490 if (!ConnectByFirst)
1492 //check if Vcur is on bounds of faces
1493 if (VEmapF1.IsBound(Vcur) || VEmapF2.IsBound(Vcur))
1497 if (TangCur.IsParallel( RefTangFirst, AngTol ) ||
1498 TangCur.IsParallel( RefTangLast, AngTol ))
1499 return Standard_True;
1502 return Standard_False;
1505 //=======================================================================
1506 //function : AssembleEdge
1508 //=======================================================================
1510 static TopoDS_Edge AssembleEdge(const BOPTools_DSFiller* pDF,
1511 const TopoDS_Face& F1,
1512 const TopoDS_Face& F2,
1513 const Standard_Boolean addPCurve1,
1514 const Standard_Boolean addPCurve2,
1515 const TopTools_SequenceOfShape& EdgesForConcat)
1517 TopoDS_Edge CurEdge = TopoDS::Edge( EdgesForConcat(1) );
1518 for (Standard_Integer j = 2; j <= EdgesForConcat.Length(); j++)
1520 TopoDS_Edge anEdge = TopoDS::Edge( EdgesForConcat(j) );
1521 Standard_Boolean After = Standard_False;
1522 TopoDS_Vertex Vfirst, Vlast;
1523 if (AreClosed( CurEdge, anEdge ))
1525 TopoDS_Vertex V1, V2;
1526 TopExp::Vertices( CurEdge, V1, V2 );
1527 if (IsAutonomVertex( V1, F1, F2, pDF->DS(), pDF->PaveFiller() ))
1529 After = Standard_False;
1530 Vfirst = Vlast = V2;
1534 After = Standard_True;
1535 Vfirst = Vlast = V1;
1540 TopoDS_Vertex CV, V11, V12, V21, V22;
1541 TopExp::CommonVertex( CurEdge, anEdge, CV );
1542 TopExp::Vertices( CurEdge, V11, V12 );
1543 TopExp::Vertices( anEdge, V21, V22 );
1544 if (V11.IsSame(CV) && V21.IsSame(CV))
1549 else if (V11.IsSame(CV) && V22.IsSame(CV))
1554 else if (V12.IsSame(CV) && V21.IsSame(CV))
1564 } //end of else (open wire)
1566 TopoDS_Edge NewEdge = Glue(CurEdge, anEdge,
1567 Vfirst, Vlast, After,
1568 F1, addPCurve1, F2, addPCurve2);
1570 } //end of for (Standard_Integer j = 2; j <= EdgesForConcat.Length(); j++)
1575 //=======================================================================
1576 //function : Inter3D
1578 //=======================================================================
1580 void BRepOffset_Tool::Inter3D(const TopoDS_Face& F1,
1581 const TopoDS_Face& F2,
1582 TopTools_ListOfShape& L1,
1583 TopTools_ListOfShape& L2,
1584 const TopAbs_State Side,
1585 const TopoDS_Edge& RefEdge,
1586 const Standard_Boolean IsRefEdgeDefined)
1591 char* name = new char[100];
1592 sprintf(name,"FF_%d",NbFaces++);
1593 DBRep::Set(name,F1);
1594 sprintf(name,"FF_%d",NbFaces++);
1595 DBRep::Set(name,F2);
1599 TopoDS_Face cpF1=F1;
1600 TopoDS_Face cpF2=F2;
1601 // create 3D curves on faces
1602 BRepLib::BuildCurves3d(cpF1);
1603 BRepLib::BuildCurves3d(cpF2);
1605 BOPTools_DSFiller pDF1, pDF2;
1606 pDF1.SetShapes(cpF1, cpF2);
1610 BOPTools_DSFiller * pDF = &pDF1;
1611 TopTools_IndexedMapOfShape TrueEdges;
1612 if (IsRefEdgeDefined && !CheckIntersFF( pDF1, RefEdge, cpF1, cpF2, TrueEdges ))
1616 pDF2.SetShapes(cpF1, cpF2);
1618 CheckIntersFF( pDF2, RefEdge, cpF1, cpF2, TrueEdges );
1622 Standard_Boolean addPCurve1 = pDF->PaveFiller().SectionAttribute().PCurveOnS1();
1623 Standard_Boolean addPCurve2 = pDF->PaveFiller().SectionAttribute().PCurveOnS2();
1625 const BooleanOperations_ShapesDataStructure& aDS = pDF->DS();
1626 BOPTools_InterferencePool* anIntrPool = (BOPTools_InterferencePool*)& pDF->InterfPool();
1627 BOPTools_CArray1OfSSInterference& aFFs = anIntrPool->SSInterferences();
1628 Standard_Integer aNb = aFFs.Extent();
1629 Standard_Integer i = 0, j = 0, k;
1631 L1.Clear(); L2.Clear();
1632 TopAbs_Orientation O1,O2;
1634 for (i = 1; i <= aNb; i++) {
1635 BOPTools_SSInterference& aFFi = aFFs(i);
1636 BOPTools_SequenceOfCurves& aBCurves = aFFi.Curves();
1637 Standard_Integer aNbCurves = aBCurves.Length();
1639 for (j = 1; j <= aNbCurves; j++) {
1640 BOPTools_Curve& aBC = aBCurves(j);
1641 const BOPTools_ListOfPaveBlock& aSectEdges = aBC.NewPaveBlocks();
1643 BOPTools_ListIteratorOfListOfPaveBlock aPBIt(aSectEdges);
1645 for (; aPBIt.More(); aPBIt.Next()) {
1646 BOPTools_PaveBlock& aPB=aPBIt.Value();
1647 Standard_Integer nSect = aPB.Edge();
1648 TopoDS_Edge anEdge = TopoDS::Edge(aDS.Shape(nSect));
1649 if (!TrueEdges.IsEmpty() && !TrueEdges.Contains(anEdge))
1653 const Handle(Geom_Curve)& aC3DE = BRep_Tool::Curve(anEdge, f, l);
1654 Handle(Geom_TrimmedCurve) aC3DETrim;
1657 aC3DETrim = new Geom_TrimmedCurve(aC3DE, f, l);
1660 Standard_Real aTolEdge = BRep_Tool::Tolerance(anEdge);
1662 if (!BOPTools_Tools2D::HasCurveOnSurface(anEdge, cpF1)) {
1663 Handle(Geom2d_Curve) aC2d = aBC.Curve().FirstCurve2d();
1664 if(!aC3DETrim.IsNull()) {
1665 Handle(Geom2d_Curve) aC2dNew;
1667 if(aC3DE->IsPeriodic()) {
1668 BOPTools_Tools2D::AdjustPCurveOnFace(cpF1, f, l, aC2d, aC2dNew);
1671 BOPTools_Tools2D::AdjustPCurveOnFace(cpF1, aC3DETrim, aC2d, aC2dNew);
1675 aBB.UpdateEdge(anEdge, aC2d, cpF1, aTolEdge);
1678 if (!BOPTools_Tools2D::HasCurveOnSurface(anEdge, cpF2)) {
1679 Handle(Geom2d_Curve) aC2d = aBC.Curve().SecondCurve2d();
1680 if(!aC3DETrim.IsNull()) {
1681 Handle(Geom2d_Curve) aC2dNew;
1683 if(aC3DE->IsPeriodic()) {
1684 BOPTools_Tools2D::AdjustPCurveOnFace(cpF2, f, l, aC2d, aC2dNew);
1687 BOPTools_Tools2D::AdjustPCurveOnFace(cpF2, aC3DETrim, aC2d, aC2dNew);
1691 aBB.UpdateEdge(anEdge, aC2d, cpF2, aTolEdge);
1694 OrientSection (anEdge, F1, F2, O1, O2);
1695 if (Side == TopAbs_OUT) {
1696 O1 = TopAbs::Reverse(O1);
1697 O2 = TopAbs::Reverse(O2);
1700 L1.Append (anEdge.Oriented(O1));
1701 L2.Append (anEdge.Oriented(O2));
1705 char* name = new char[100];
1706 sprintf(name,"EI_%d",NbNewEdges++);
1707 DBRep::Set(name,anEdge.Oriented(O1));
1715 Standard_Real aSameParTol = Precision::Confusion();
1716 Standard_Boolean isEl1 = Standard_False, isEl2 = Standard_False;
1718 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(cpF1);
1719 if (aSurf->IsInstance(STANDARD_TYPE(Geom_RectangularTrimmedSurface)))
1720 aSurf = (*((Handle(Geom_RectangularTrimmedSurface)*)&aSurf))->BasisSurface();
1721 if (aSurf->IsInstance(STANDARD_TYPE(Geom_Plane)))
1722 addPCurve1 = Standard_False;
1723 else if (aSurf->IsKind(STANDARD_TYPE(Geom_ElementarySurface)))
1724 isEl1 = Standard_True;
1726 aSurf = BRep_Tool::Surface(cpF2);
1727 if (aSurf->IsInstance(STANDARD_TYPE(Geom_RectangularTrimmedSurface)))
1728 aSurf = (*((Handle(Geom_RectangularTrimmedSurface)*)&aSurf))->BasisSurface();
1729 if (aSurf->IsInstance(STANDARD_TYPE(Geom_Plane)))
1730 addPCurve2 = Standard_False;
1731 else if (aSurf->IsKind(STANDARD_TYPE(Geom_ElementarySurface)))
1732 isEl2 = Standard_True;
1734 if (L1.Extent() > 1 && (!isEl1 || !isEl2)) {
1735 TopTools_SequenceOfShape eseq;
1736 TopTools_SequenceOfShape EdgesForConcat;
1738 if (!TrueEdges.IsEmpty())
1740 for (i = TrueEdges.Extent(); i >= 1; i--)
1741 EdgesForConcat.Append( TrueEdges(i) );
1742 TopoDS_Edge theEdge =
1743 AssembleEdge( pDF, cpF1, cpF2, addPCurve1, addPCurve2, EdgesForConcat );
1744 eseq.Append(theEdge);
1748 const BOPTools_PaveFiller& thePaveFiller = pDF->PaveFiller();
1750 TopTools_SequenceOfShape wseq;
1751 TopTools_SequenceOfShape edges;
1752 TopTools_ListIteratorOfListOfShape itl(L1);
1753 for (; itl.More(); itl.Next())
1754 edges.Append( itl.Value() );
1755 while (!edges.IsEmpty())
1757 TopoDS_Edge anEdge = TopoDS::Edge( edges.First() );
1758 TopoDS_Wire aWire = BRepLib_MakeWire( anEdge ), resWire;
1759 TColStd_SequenceOfInteger Candidates;
1760 for (k = 1; k <= wseq.Length(); k++)
1762 resWire = TopoDS::Wire(wseq(k));
1763 if (AreConnex( resWire, aWire, cpF1, cpF2, pDF ))
1765 Candidates.Append( 1 );
1769 if (Candidates.IsEmpty())
1771 wseq.Append( aWire );
1776 for (j = 2; j <= edges.Length(); j++)
1778 anEdge = TopoDS::Edge( edges(j) );
1779 //if (anEdge.IsSame(edges(Candidates.First())))
1781 aWire = BRepLib_MakeWire( anEdge );
1782 if (AreConnex( resWire, aWire, cpF1, cpF2, pDF ))
1783 Candidates.Append( j );
1785 Standard_Integer minind = 1;
1786 if (Candidates.Length() > 1)
1788 Standard_Real MinAngle = RealLast();
1789 for (j = 1; j <= Candidates.Length(); j++)
1791 anEdge = TopoDS::Edge( edges(Candidates(j)) );
1792 Standard_Real anAngle = AngleWireEdge( resWire, anEdge );
1793 if (anAngle < MinAngle)
1800 TopoDS_Wire NewWire = BRepLib_MakeWire( resWire, TopoDS::Edge(edges(Candidates(minind))) );
1802 edges.Remove(Candidates(minind));
1804 } //end of while (!edges.IsEmpty())
1806 for (i = 1; i <= wseq.Length(); i++)
1808 TopoDS_Wire aWire = TopoDS::Wire(wseq(i));
1809 TopTools_SequenceOfShape EdgesForConcat;
1812 TopoDS_Vertex StartVertex;
1813 TopoDS_Edge StartEdge;
1814 Standard_Boolean StartFound = Standard_False;
1815 TopTools_ListOfShape Elist;
1817 TopoDS_Iterator itw(aWire);
1818 for (; itw.More(); itw.Next())
1820 TopoDS_Edge anEdge = TopoDS::Edge(itw.Value());
1822 Elist.Append(anEdge);
1825 TopoDS_Vertex V1, V2;
1826 TopExp::Vertices( anEdge, V1, V2 );
1827 if (!IsAutonomVertex( V1, cpF1, cpF2, aDS, thePaveFiller ))
1831 StartFound = Standard_True;
1833 else if (!IsAutonomVertex( V2, cpF1, cpF2, aDS, thePaveFiller ))
1837 StartFound = Standard_True;
1840 Elist.Append(anEdge);
1842 } //end of for (; itw.More(); itw.Next())
1845 itl.Initialize(Elist);
1846 StartEdge = TopoDS::Edge(itl.Value());
1848 TopoDS_Vertex V1, V2;
1849 TopExp::Vertices( StartEdge, V1, V2 );
1852 EdgesForConcat.Append( StartEdge );
1853 while (!Elist.IsEmpty())
1855 for (itl.Initialize(Elist); itl.More(); itl.Next())
1857 TopoDS_Edge anEdge = TopoDS::Edge(itl.Value());
1858 TopoDS_Vertex V1, V2;
1859 TopExp::Vertices( anEdge, V1, V2 );
1860 if (V1.IsSame(StartVertex))
1863 EdgesForConcat.Append( anEdge );
1867 else if (V2.IsSame(StartVertex))
1870 EdgesForConcat.Append( anEdge );
1875 } //end of while (!Elist.IsEmpty())
1876 } //end of if (aWire.Closed())
1879 BRepTools_WireExplorer Wexp( aWire );
1880 for (; Wexp.More(); Wexp.Next())
1881 EdgesForConcat.Append( Wexp.Current() );
1884 TopoDS_Edge theEdge =
1885 AssembleEdge( pDF, cpF1, cpF2, addPCurve1, addPCurve2, EdgesForConcat );
1886 eseq.Append( theEdge );
1888 } //end of else (when TrueEdges is empty)
1890 if (eseq.Length() < L1.Extent())
1894 for (i = 1; i <= eseq.Length(); i++)
1896 TopoDS_Edge anEdge = TopoDS::Edge(eseq(i));
1897 BRepLib::SameParameter(anEdge, aSameParTol, Standard_True);
1898 Standard_Real EdgeTol = BRep_Tool::Tolerance(anEdge);
1900 cout<<"Tolerance of glued E = "<<EdgeTol<<endl;
1902 if (EdgeTol > 1.e-2)
1905 if (EdgeTol >= 1.e-4)
1907 ReconstructPCurves(anEdge);
1908 BRepLib::SameParameter(anEdge, aSameParTol, Standard_True);
1910 cout<<"After projection tol of E = "<<BRep_Tool::Tolerance(anEdge)<<endl;
1914 OrientSection( anEdge, F1, F2, O1, O2 );
1915 if (Side == TopAbs_OUT)
1917 O1 = TopAbs::Reverse(O1);
1918 O2 = TopAbs::Reverse(O2);
1921 L1.Append( anEdge.Oriented(O1) );
1922 L2.Append( anEdge.Oriented(O2) );
1925 } //end of if (L1.Extent() > 1)
1929 TopTools_ListIteratorOfListOfShape itl(L1);
1930 for (; itl.More(); itl.Next())
1932 const TopoDS_Edge& anEdge = TopoDS::Edge( itl.Value() );
1933 BRepLib::SameParameter(anEdge, aSameParTol, Standard_True);
1938 //=======================================================================
1939 //function : TryProject
1941 //=======================================================================
1943 Standard_Boolean BRepOffset_Tool::TryProject
1944 (const TopoDS_Face& F1,
1945 const TopoDS_Face& F2,
1946 const TopTools_ListOfShape& Edges,
1947 TopTools_ListOfShape& LInt1,
1948 TopTools_ListOfShape& LInt2,
1949 const TopAbs_State Side,
1950 const Standard_Real TolConf)
1955 char* name = new char[100];
1956 sprintf(name,"FF_%d",NbFaces++);
1957 DBRep::Set(name,F1);
1958 sprintf(name,"FF_%d",NbFaces++);
1959 DBRep::Set(name,F2);
1963 // try to find if the edges <Edges> are laying on the face F1.
1964 LInt1.Clear(); LInt2.Clear();
1965 TopTools_ListIteratorOfListOfShape it(Edges);
1966 Standard_Boolean isOk = Standard_True;
1967 Standard_Boolean Ok = Standard_True;
1968 TopAbs_Orientation O1,O2;
1969 Handle(Geom_Surface) Bouchon = BRep_Tool::Surface(F1);
1972 for ( ; it.More(); it.Next()) {
1975 TopoDS_Edge CurE = TopoDS::Edge(it.Value());
1976 Handle(Geom_Curve) C = BRep_Tool::Curve(CurE,L,f,l);
1978 BRepLib::BuildCurve3d(CurE,BRep_Tool::Tolerance(CurE));
1979 C = BRep_Tool::Curve(CurE,L,f,l);
1981 C = new Geom_TrimmedCurve(C,f,l);
1982 if ( !L.IsIdentity()) C->Transform(L);
1983 Standard_Real TolReached;
1984 isOk = IsOnSurface(C,Bouchon,TolConf,TolReached);
1987 B.UpdateEdge(CurE,TolReached);
1988 BuildPCurves(CurE,F1);
1989 OrientSection (CurE,F1,F2,O1,O2);
1990 if (Side == TopAbs_OUT) {
1991 O1 = TopAbs::Reverse(O1);
1992 O2 = TopAbs::Reverse(O2);
1994 LInt1.Append (CurE.Oriented(O1));
1995 LInt2.Append (CurE.Oriented(O2));
1999 char* name = new char[100];
2000 sprintf(name,"EI_%d",NbNewEdges++);
2001 DBRep::Set(name,CurE.Oriented(O1));
2006 Ok = Standard_False;
2012 //=======================================================================
2013 //function : InterOrExtent
2015 //=======================================================================
2017 void BRepOffset_Tool::InterOrExtent(const TopoDS_Face& F1,
2018 const TopoDS_Face& F2,
2019 TopTools_ListOfShape& L1,
2020 TopTools_ListOfShape& L2,
2021 const TopAbs_State Side)
2026 char* name = new char[100];
2027 sprintf(name,"FF_%d",NbFaces++);
2028 DBRep::Set(name,F1);
2029 sprintf(name,"FF_%d",NbFaces++);
2030 DBRep::Set(name,F2);
2034 Handle (Geom_Curve) CI;
2036 TopAbs_Orientation O1,O2;
2037 L1.Clear(); L2.Clear();
2038 Handle (Geom_Surface) S1 = BRep_Tool::Surface(F1);
2039 Handle (Geom_Surface) S2 = BRep_Tool::Surface(F2);
2041 if (S1->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
2042 Handle(Geom_RectangularTrimmedSurface) RTS ;
2043 RTS = *((Handle(Geom_RectangularTrimmedSurface)*) &S1);
2044 if (RTS->BasisSurface()->DynamicType() == STANDARD_TYPE(Geom_Plane)) {
2045 S1 = RTS->BasisSurface();
2048 if (S2->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
2049 Handle(Geom_RectangularTrimmedSurface) RTS ;
2050 RTS = *((Handle(Geom_RectangularTrimmedSurface)*) &S2);
2051 if (RTS->BasisSurface()->DynamicType() == STANDARD_TYPE(Geom_Plane)) {
2052 S2 = RTS->BasisSurface();
2056 GeomInt_IntSS Inter (S1,S2, Precision::Confusion());
2058 if (Inter.IsDone()) {
2059 for (Standard_Integer i = 1; i <= Inter.NbLines(); i++) {
2062 if (ToSmall(CI)) continue;
2063 TopoDS_Edge E = BRepLib_MakeEdge(CI);
2064 BuildPCurves (E,F1);
2065 BuildPCurves (E,F2);
2066 OrientSection (E,F1,F2,O1,O2);
2067 if (Side == TopAbs_OUT) {
2068 O1 = TopAbs::Reverse(O1);
2069 O2 = TopAbs::Reverse(O2);
2071 L1.Append (E.Oriented(O1));
2072 L2.Append (E.Oriented(O2));
2076 char* name = new char[100];
2077 sprintf(name,"EI_%d",NbNewEdges++);
2078 DBRep::Set(name,E.Oriented(O1));
2085 //=======================================================================
2086 //function : ExtentEdge
2088 //=======================================================================
2090 static void ExtentEdge(const TopoDS_Face& F,
2091 const TopoDS_Face& EF,
2092 const TopoDS_Edge& E,
2095 BRepAdaptor_Curve CE(E);
2096 GeomAbs_CurveType Type = CE.GetType();
2097 TopoDS_Shape aLocalEdge = E.EmptyCopied();
2098 NE = TopoDS::Edge(aLocalEdge);
2099 // NE = TopoDS::Edge(E.EmptyCopied());
2101 if (Type == GeomAbs_Line || Type == GeomAbs_Circle || Type == GeomAbs_Ellipse ||
2102 Type == GeomAbs_Hyperbola || Type == GeomAbs_Parabola) {
2105 // Extension en tangence jusqu'au bord de la surface.
2106 Standard_Real PMax = 1.e2;
2108 Handle(Geom_Surface) S = BRep_Tool::Surface(F,L);
2109 Standard_Real umin,umax,vmin,vmax;
2111 S->Bounds(umin,umax,vmin,vmax);
2112 umin = Max(umin,-PMax);vmin = Max(vmin,-PMax);
2113 umax = Min(umax, PMax);vmax = Min(vmax, PMax);
2117 Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(E,F,f,l);
2119 //calcul point cible . ie point d'intersection du prolongement tangent et des bords.
2122 C2d->D1(CE.FirstParameter(),P,Tang);
2123 Standard_Real tx,ty,tmin;
2124 tx = ty = Precision::Infinite();
2125 if (Abs(Tang.X()) > Precision::Confusion())
2126 tx = Min (Abs((umax - P.X())/Tang.X()), Abs((umin - P.X())/Tang.X()));
2127 if (Abs(Tang.Y()) > Precision::Confusion())
2128 ty = Min (Abs((vmax - P.Y())/Tang.Y()), Abs((vmin - P.Y())/Tang.Y()));
2131 gp_Pnt2d PF2d (P.X() - Tang.X(),P.Y() - Tang.Y());
2133 C2d->D1(CE.LastParameter(),P,Tang);
2134 tx = ty = Precision::Infinite();
2135 if (Abs(Tang.X()) > Precision::Confusion())
2136 tx = Min (Abs((umax - P.X())/Tang.X()), Abs((umin - P.X())/Tang.X()));
2137 if (Abs(Tang.Y()) > Precision::Confusion())
2138 ty = Min (Abs((vmax - P.Y())/Tang.Y()), Abs((vmin - P.Y())/Tang.Y()));
2141 gp_Pnt2d PL2d (P.X() + Tang.X(),P.Y() + Tang.Y());
2143 Handle(Geom_Curve) CC = GeomAPI::To3d(C2d,gp_Pln(gp::XOY()));
2144 gp_Pnt PF(PF2d.X(),PF2d.Y(),0.);
2145 gp_Pnt PL(PL2d.X(),PL2d.Y(),0.);
2147 Handle(Geom_BoundedCurve) ExtC = Handle(Geom_BoundedCurve)::DownCast(CC);
2148 if (ExtC.IsNull()) return;
2150 GeomLib::ExtendCurveToPoint(ExtC,PF,1,0);
2151 GeomLib::ExtendCurveToPoint(ExtC,PL,1,1);
2153 Handle(Geom2d_Curve) CNE2d = GeomAPI::To2d(ExtC,gp_Pln(gp::XOY()));
2155 //Construction de la nouvelle arrete;
2158 // B.UpdateEdge (NE,CNE2d,F,BRep_Tool::Tolerance(E));
2159 B.UpdateEdge (NE,CNE2d,EF,BRep_Tool::Tolerance(E));
2160 B.Range (NE,CNE2d->FirstParameter(), CNE2d->LastParameter());
2161 NE.Orientation(E.Orientation());
2164 char* name = new char[100];
2165 sprintf (name,"F_%d",NbExtE);
2166 DBRep::Set(name,EF);
2167 sprintf (name,"OE_%d",NbExtE);
2168 DBRep::Set (name,E);
2169 sprintf (name,"ExtE_%d",NbExtE++);
2170 DBRep::Set(name,NE);
2175 //=======================================================================
2176 //function : ProjectVertexOnEdge
2178 //=======================================================================
2180 static Standard_Boolean ProjectVertexOnEdge(TopoDS_Vertex& V,
2181 const TopoDS_Edge& E,
2182 Standard_Real TolConf)
2193 Standard_Real U = 0.;
2198 Standard_Boolean found = Standard_False;
2200 gp_Pnt P = BRep_Tool::Pnt (V);
2201 BRepAdaptor_Curve C = BRepAdaptor_Curve(E);
2202 f = C.FirstParameter(); l = C.LastParameter();
2204 if (V.Orientation() == TopAbs_FORWARD) {
2205 if (Abs(f) < Precision::Infinite()) {
2206 gp_Pnt PF = C.Value (f);
2207 if (PF.IsEqual(P,TolConf)) {
2209 found = Standard_True;
2213 if (V.Orientation() == TopAbs_REVERSED) {
2214 if (!found && Abs(l) < Precision::Infinite()) {
2215 gp_Pnt PL = C.Value (l);
2216 if (PL.IsEqual(P,TolConf)) {
2218 found = Standard_True;
2223 Extrema_ExtPC Proj(P,C);
2224 if (Proj.IsDone() && Proj.NbExt() > 0) {
2225 Standard_Real Dist2,Dist2Min = Proj.SquareDistance(1);
2226 U = Proj.Point(1).Parameter();
2227 for (Standard_Integer i = 2; i <= Proj.NbExt(); i++) {
2228 Dist2 = Proj.SquareDistance(i);
2229 if (Dist2 < Dist2Min) {
2231 U = Proj.Point(i).Parameter();
2234 found = Standard_True;
2240 Standard_Real Dist = P.Distance(C.Value(U));
2241 if (Dist > TolConf) {
2242 cout << " ProjectVertexOnEdge :distance vertex edge :"<<Dist<<endl;
2244 if (U < f - Precision::Confusion() ||
2245 U > l + Precision::Confusion()) {
2246 cout << " ProjectVertexOnEdge : hors borne :"<<endl;
2247 cout << " f = "<<f<<" l ="<<l<< " U ="<<U<<endl;
2251 cout <<"BRepOffset_Tool::ProjectVertexOnEdge Parameter no found"<<endl;
2252 if (Abs(f) < Precision::Infinite() &&
2253 Abs(l) < Precision::Infinite()) {
2261 TopoDS_Shape aLocalShape = E.Oriented(TopAbs_FORWARD);
2262 TopoDS_Edge EE = TopoDS::Edge(aLocalShape);
2263 aLocalShape = V.Oriented(TopAbs_INTERNAL);
2264 // TopoDS_Edge EE = TopoDS::Edge(E.Oriented(TopAbs_FORWARD));
2265 B.UpdateVertex(TopoDS::Vertex(aLocalShape),
2266 U,EE,BRep_Tool::Tolerance(E));
2272 //=======================================================================
2273 //function : Inter2d
2275 //=======================================================================
2277 void BRepOffset_Tool::Inter2d (const TopoDS_Face& F,
2278 const TopoDS_Edge& E1,
2279 const TopoDS_Edge& E2,
2280 TopTools_ListOfShape& LV,
2281 const Standard_Real TolConf)
2285 DBRep::Set("E1",E1);
2286 DBRep::Set("E2",E2);
2291 Standard_Real fl1[2],fl2[2];
2294 // Si l edge a ete etendu les pcurves ne sont pas forcement
2300 // Construction des curves 3d si elles n existent pas
2301 // utile pour coder correctement les parametres des vertex
2302 // d intersection sur les edges.
2303 //TopLoc_Location L;
2304 //Standard_Real f,l;
2305 //Handle(Geom_Curve) C3d1 = BRep_Tool::Curve(E1,L,f,l);
2306 //if (C3d1.IsNull()) {
2307 // BRepLib::BuildCurve3d(E1,BRep_Tool::Tolerance(E1));
2309 //Handle(Geom_Curve) C3d2 = BRep_Tool::Curve(E2,L,f,l);
2310 //if (C3d2.IsNull()) {
2311 // BRepLib::BuildCurve3d(E2,BRep_Tool::Tolerance(E2));
2314 Standard_Integer NbPC1 = 1, NbPC2 = 1;
2315 if (BRep_Tool::IsClosed(E1,F)) NbPC1++;
2316 if (BRep_Tool::IsClosed(E2,F)) NbPC2++;
2318 Handle(Geom_Surface) S = BRep_Tool::Surface(F);
2319 Handle(Geom2d_Curve) C1, C2;
2320 Standard_Boolean YaSol = Standard_False;
2321 Standard_Integer itry = 0;
2323 while (!YaSol && itry < 2) {
2324 for ( Standard_Integer i = 1; i <= NbPC1 ; i++) {
2325 TopoDS_Shape aLocalEdge = E1.Reversed();
2326 if (i == 1) C1 = BRep_Tool::CurveOnSurface(E1,F,fl1[0],fl1[1]);
2327 else C1 = BRep_Tool::CurveOnSurface(TopoDS::Edge(aLocalEdge),
2329 // if (i == 1) C1 = BRep_Tool::CurveOnSurface(E1,F,fl1[0],fl1[1]);
2330 // else C1 = BRep_Tool::CurveOnSurface(TopoDS::Edge(E1.Reversed()),
2331 // F,fl1[0],fl1[1]);
2332 for ( Standard_Integer j = 1; j <= NbPC2; j++ ) {
2333 TopoDS_Shape aLocalEdge = E2.Reversed();
2334 if (j == 1) C2 = BRep_Tool::CurveOnSurface(E2,F,fl2[0],fl2[1]);
2335 else C2 = BRep_Tool::CurveOnSurface(TopoDS::Edge(aLocalEdge),
2337 // if (j == 1) C2 = BRep_Tool::CurveOnSurface(E2,F,fl2[0],fl2[1]);
2338 // else C2 = BRep_Tool::CurveOnSurface(TopoDS::Edge(E2.Reversed()),
2339 // F,fl2[0],fl2[1]);
2341 if (C1.IsNull() || C2.IsNull()) {
2342 cout <<"Inter2d : Pas de pcurve"<<endl;
2344 DBRep::Set("E1",E1);
2345 DBRep::Set("E2",E2);
2352 Standard_Real U1 = 0.,U2 = 0.;
2354 Standard_Real U1,U2;
2358 fl1[0] = C1->FirstParameter(); fl1[1] = C1->LastParameter();
2359 fl2[0] = C2->FirstParameter(); fl2[1] = C2->LastParameter();
2361 Geom2dAdaptor_Curve AC1(C1,fl1[0],fl1[1]);
2362 Geom2dAdaptor_Curve AC2(C2,fl2[0],fl2[1]);
2365 gp_Pnt2d P1[2],P2[2];
2366 P1[0] = C1->Value(fl1[0]); P1[1] = C1->Value(fl1[1]);
2367 P2[0] = C2->Value(fl2[0]); P2[1] = C2->Value(fl2[1]);
2369 Standard_Integer i1 ;
2370 for ( i1 = 0; i1 < 2; i1++) {
2371 for (Standard_Integer i2 = 0; i2 < 2; i2++) {
2372 if (Abs(fl1[i1]) < Precision::Infinite() &&
2373 Abs(fl2[i2]) < Precision::Infinite() ) {
2374 if (P1[i1].IsEqual(P2[i2],TolConf)) {
2375 YaSol = Standard_True;
2376 U1 = fl1[i1]; U2 = fl2[i2];
2377 P2d = C1->Value(U1);
2383 for (i1 = 0; i1 < 2; i1++)
2385 Extrema_ExtPC2d extr( P1[i1], AC2 );
2386 if (extr.IsDone() && extr.NbExt() > 0)
2388 Standard_Real Dist2, Dist2Min = extr.SquareDistance(1);
2389 Standard_Integer IndexMin = 1;
2390 for (Standard_Integer ind = 2; ind <= extr.NbExt(); ind++)
2392 Dist2 = extr.SquareDistance(ind);
2393 if (Dist2 < Dist2Min)
2399 if (Dist2Min <= Precision::Confusion() * Precision::Confusion())
2401 YaSol = Standard_True;
2404 U2 = (extr.Point(IndexMin)).Parameter();
2410 for (Standard_Integer i2 = 0; i2 < 2; i2++)
2412 Extrema_ExtPC2d extr( P2[i2], AC1 );
2413 if (extr.IsDone() && extr.NbExt() > 0)
2415 Standard_Real Dist2, Dist2Min = extr.SquareDistance(1);
2416 Standard_Integer IndexMin = 1;
2417 for (Standard_Integer ind = 2; ind <= extr.NbExt(); ind++)
2419 Dist2 = extr.SquareDistance(ind);
2420 if (Dist2 < Dist2Min)
2426 if (Dist2Min <= Precision::Confusion() * Precision::Confusion())
2428 YaSol = Standard_True;
2431 U1 = (extr.Point(IndexMin)).Parameter();
2439 Geom2dInt_GInter Inter (AC1,AC2,TolConf,TolConf);
2441 if (!Inter.IsEmpty() && Inter.NbPoints() > 0) {
2442 YaSol = Standard_True;
2443 U1 = Inter.Point(1).ParamOnFirst();
2444 U2 = Inter.Point(1).ParamOnSecond();
2445 P2d = Inter.Point(1).Value();
2447 else if (!Inter.IsEmpty() && Inter.NbSegments() > 0) {
2448 YaSol = Standard_True;
2449 IntRes2d_IntersectionSegment Seg = Inter.Segment(1);
2450 IntRes2d_IntersectionPoint IntP1 = Seg.FirstPoint();
2451 IntRes2d_IntersectionPoint IntP2 = Seg.LastPoint();
2452 Standard_Real U1on1 = IntP1.ParamOnFirst();
2453 Standard_Real U1on2 = IntP2.ParamOnFirst();
2454 Standard_Real U2on1 = IntP1.ParamOnSecond();
2455 Standard_Real U2on2 = IntP2.ParamOnSecond();
2457 cout << " BRepOffset_Tool::Inter2d SEGMENT d intersection" << endl;
2458 cout << " ===> Parametres sur Curve1 : ";
2459 cout << U1on1 << " " << U1on2 << endl;
2460 cout << " ===> Parametres sur Curve2 : ";
2461 cout << U2on1 << " " << U2on2 << endl;
2463 U1 = (U1on1 + U1on2)/2.;
2464 U2 = (U2on1 + U2on2)/2.;
2465 gp_Pnt2d P2d1 = C1->Value(U1);
2466 gp_Pnt2d P2d2 = C2->Value(U2);
2467 P2d.SetX( (P2d1.X() + P2d2.X()) / 2.);
2468 P2d.SetY( (P2d1.Y() + P2d2.Y()) / 2.);
2472 gp_Pnt P = S->Value(P2d.X(),P2d.Y());
2473 TopoDS_Vertex V = BRepLib_MakeVertex(P);
2474 V.Orientation(TopAbs_INTERNAL);
2475 TopoDS_Shape aLocalEdge = E1.Oriented(TopAbs_FORWARD);
2476 B.UpdateVertex(V,U1,TopoDS::Edge(aLocalEdge),TolConf);
2477 aLocalEdge = E2.Oriented(TopAbs_FORWARD);
2478 B.UpdateVertex(V,U2,TopoDS::Edge(aLocalEdge),TolConf);
2479 // B.UpdateVertex(V,U1,TopoDS::Edge(E1.Oriented(TopAbs_FORWARD)),TolConf);
2480 // B.UpdateVertex(V,U2,TopoDS::Edge(E2.Oriented(TopAbs_FORWARD)),TolConf);
2488 if (LV.Extent() > 1) {
2489 //------------------------------------------------
2490 // garde seulement les vertex les plus proches du
2491 //debut et de la fin.
2492 //------------------------------------------------
2493 TopTools_ListIteratorOfListOfShape it(LV);
2494 TopoDS_Vertex VF,VL;
2495 Standard_Real UMin = Precision::Infinite();
2496 Standard_Real UMax = -Precision::Infinite();
2499 for ( ; it.More(); it.Next()) {
2500 TopoDS_Vertex CV = TopoDS::Vertex(it.Value());
2501 TopoDS_Shape aLocalEdge = E1.Oriented(TopAbs_FORWARD);
2502 U = BRep_Tool::Parameter(CV,TopoDS::Edge(aLocalEdge));
2503 // U = BRep_Tool::Parameter(CV,TopoDS::Edge(E1.Oriented(TopAbs_FORWARD)));
2511 LV.Clear();LV.Append(VF); LV.Append(VL);
2516 cout <<"Inter2d : Pas de solution"<<endl;
2518 DBRep::Set("E1",E1);
2519 DBRep::Set("E2",E2);
2526 //=======================================================================
2527 //function : SelectEdge
2529 //=======================================================================
2531 static void SelectEdge (const TopoDS_Face& F,
2532 const TopoDS_Face& EF,
2533 const TopoDS_Edge& E,
2534 TopTools_ListOfShape& LInt)
2536 //------------------------------------------------------------
2537 // detrompeur sur les intersections sur les faces periodiques
2538 //------------------------------------------------------------
2539 TopTools_ListIteratorOfListOfShape it(LInt);
2540 Standard_Real dU = 1.0e100;
2543 Standard_Real Fst, Lst, tmp;
2544 BRep_Tool::Range(E, Fst, Lst);
2545 BRepAdaptor_Curve Ad1(E);
2547 gp_Pnt PFirst = Ad1.Value( Fst );
2548 gp_Pnt PLast = Ad1.Value( Lst );
2550 //----------------------------------------------------------------------
2551 // Selection de l edge qui couvre le plus le domaine de l edge initiale.
2552 //----------------------------------------------------------------------
2553 for (; it.More(); it.Next()) {
2554 const TopoDS_Edge& EI = TopoDS::Edge(it.Value());
2556 BRep_Tool::Range(EI, Fst, Lst);
2557 BRepAdaptor_Curve Ad2(EI);
2558 gp_Pnt P1 = Ad2.Value(Fst);
2559 gp_Pnt P2 = Ad2.Value(Lst);
2561 tmp = P1.Distance(PFirst) + P2.Distance(PLast);
2573 //=======================================================================
2576 //=======================================================================
2578 static void MakeFace(const Handle(Geom_Surface)& S,
2579 const Standard_Real Um,
2580 const Standard_Real UM,
2581 const Standard_Real Vm,
2582 const Standard_Real VM,
2583 const Standard_Boolean isVminDegen,
2584 const Standard_Boolean isVmaxDegen,
2587 Standard_Real UMin = Um;
2588 Standard_Real UMax = UM;
2589 Standard_Real VMin = Vm;
2590 Standard_Real VMax = VM;
2591 Standard_Real epsilon = Precision::Confusion();
2593 Standard_Real umin,umax,vmin,vmax;
2594 S->Bounds(umin,umax,vmin,vmax);
2597 // compute infinite flags
2598 Standard_Boolean umininf = Precision::IsNegativeInfinite(UMin);
2599 Standard_Boolean umaxinf = Precision::IsPositiveInfinite(UMax);
2600 Standard_Boolean vmininf = Precision::IsNegativeInfinite(VMin);
2601 Standard_Boolean vmaxinf = Precision::IsPositiveInfinite(VMax);
2604 Standard_Boolean IsSuclosed = S->IsUClosed(), IsSvclosed = S->IsVClosed();
2605 if (S->DynamicType() == STANDARD_TYPE(Geom_OffsetSurface))
2607 Handle(Geom_Surface) BasisSurf = (*((Handle(Geom_OffsetSurface)*)&S))->BasisSurface();
2608 IsSuclosed = BasisSurf->IsUClosed();
2609 IsSvclosed = BasisSurf->IsVClosed();
2612 Standard_Boolean uclosed =
2614 Abs(UMin - umin) < epsilon &&
2615 Abs(UMax - umax) < epsilon;
2617 Standard_Boolean vclosed =
2619 Abs(VMin - vmin) < epsilon &&
2620 Abs(VMax - vmax) < epsilon;
2622 // degenerated flags (for cones)
2623 Standard_Boolean vmindegen = isVminDegen, vmaxdegen = isVmaxDegen;
2624 Handle(Geom_Surface) theSurf = S;
2625 if (S->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface))
2626 theSurf = (*(Handle_Geom_RectangularTrimmedSurface*)&S)->BasisSurface();
2627 if (theSurf->DynamicType() == STANDARD_TYPE(Geom_ConicalSurface))
2629 Handle(Geom_ConicalSurface) ConicalS = *((Handle(Geom_ConicalSurface)*) &theSurf);
2630 gp_Cone theCone = ConicalS->Cone();
2631 gp_Pnt theApex = theCone.Apex();
2632 Standard_Real Uapex, Vapex;
2633 ElSLib::Parameters( theCone, theApex, Uapex, Vapex );
2634 if (Abs(VMin - Vapex) <= Precision::Confusion())
2635 vmindegen = Standard_True;
2636 if (Abs(VMax - Vapex) <= Precision::Confusion())
2637 vmaxdegen = Standard_True;
2642 Standard_Real tol = Precision::Confusion();
2644 TopoDS_Vertex V00,V10,V11,V01;
2647 if (!vmininf) B.MakeVertex(V00,S->Value(UMin,VMin),tol);
2648 if (!vmaxinf) B.MakeVertex(V01,S->Value(UMin,VMax),tol);
2651 if (!vmininf) B.MakeVertex(V10,S->Value(UMax,VMin),tol);
2652 if (!vmaxinf) B.MakeVertex(V11,S->Value(UMax,VMax),tol);
2671 Handle(Geom2d_Line) Lumin,Lumax,Lvmin,Lvmax;
2673 Lumin = new Geom2d_Line(gp_Pnt2d(UMin,0),gp_Dir2d(0,1));
2675 Lumax = new Geom2d_Line(gp_Pnt2d(UMax,0),gp_Dir2d(0,1));
2677 Lvmin = new Geom2d_Line(gp_Pnt2d(0,VMin),gp_Dir2d(1,0));
2679 Lvmax = new Geom2d_Line(gp_Pnt2d(0,VMax),gp_Dir2d(1,0));
2681 Handle(Geom_Curve) Cumin,Cumax,Cvmin,Cvmax;
2682 Standard_Real TolApex = 1.e-5;
2683 //Standard_Boolean hasiso = ! S->IsKind(STANDARD_TYPE(Geom_OffsetSurface));
2684 Standard_Boolean hasiso = S->IsKind(STANDARD_TYPE(Geom_ElementarySurface));
2687 Cumin = S->UIso(UMin);
2689 Cumax = S->UIso(UMax);
2692 Cvmin = S->VIso(VMin);
2693 if (BRepOffset_Tool::Gabarit( Cvmin ) <= TolApex)
2694 vmindegen = Standard_True;
2698 Cvmax = S->VIso(VMax);
2699 if (BRepOffset_Tool::Gabarit( Cvmax ) <= TolApex)
2700 vmaxdegen = Standard_True;
2705 B.MakeFace(F,S,tol);
2708 TopoDS_Edge eumin,eumax,evmin,evmax;
2712 B.MakeEdge(eumin,Cumin,tol);
2716 B.UpdateEdge(eumin,Lumax,Lumin,F,tol);
2718 B.UpdateEdge(eumin,Lumin,F,tol);
2720 V00.Orientation(TopAbs_FORWARD);
2724 V01.Orientation(TopAbs_REVERSED);
2727 B.Range(eumin,VMin,VMax);
2735 B.MakeEdge(eumax,Cumax,tol);
2738 B.UpdateEdge(eumax,Lumax,F,tol);
2740 V10.Orientation(TopAbs_FORWARD);
2744 V11.Orientation(TopAbs_REVERSED);
2747 B.Range(eumax,VMin,VMax);
2752 if (hasiso && !vmindegen)
2753 B.MakeEdge(evmin,Cvmin,tol);
2757 B.UpdateEdge(evmin,Lvmin,Lvmax,F,tol);
2759 B.UpdateEdge(evmin,Lvmin,F,tol);
2761 V00.Orientation(TopAbs_FORWARD);
2765 V10.Orientation(TopAbs_REVERSED);
2768 B.Range(evmin,UMin,UMax);
2770 B.Degenerated(evmin, Standard_True);
2777 if (hasiso && !vmaxdegen)
2778 B.MakeEdge(evmax,Cvmax,tol);
2781 B.UpdateEdge(evmax,Lvmax,F,tol);
2783 V01.Orientation(TopAbs_FORWARD);
2787 V11.Orientation(TopAbs_REVERSED);
2790 B.Range(evmax,UMin,UMax);
2792 B.Degenerated(evmax, Standard_True);
2796 // make the wires and add them to the face
2797 eumin.Orientation(TopAbs_REVERSED);
2798 evmax.Orientation(TopAbs_REVERSED);
2802 if (!umininf && !umaxinf && vmininf && vmaxinf) {
2813 else if (umininf && umaxinf && !vmininf && !vmaxinf) {
2824 else if (!umininf || !umaxinf || !vmininf || !vmaxinf) {
2827 if (!umininf) B.Add(W,eumin);
2828 if (!vmininf) B.Add(W,evmin);
2829 if (!umaxinf) B.Add(W,eumax);
2830 if (!vmaxinf) B.Add(W,evmax);
2832 W.Closed(!umininf && !umaxinf && !vmininf && !vmaxinf);
2833 F.Closed(uclosed && vclosed);
2837 //=======================================================================
2838 //function : EnLargeGeometry
2840 //=======================================================================
2842 static Standard_Boolean EnlargeGeometry(Handle(Geom_Surface)& S,
2847 Standard_Boolean& IsV1degen,
2848 Standard_Boolean& IsV2degen,
2849 const Standard_Real uf1,
2850 const Standard_Real uf2,
2851 const Standard_Real vf1,
2852 const Standard_Real vf2,
2853 const Standard_Boolean GlobalEnlargeU,
2854 const Standard_Boolean GlobalEnlargeVfirst,
2855 const Standard_Boolean GlobalEnlargeVlast)
2857 const Standard_Real coeff = 4.;
2858 const Standard_Real TolApex = 1.e-5;
2860 Standard_Boolean SurfaceChange = Standard_False;
2861 if ( S->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
2862 Handle(Geom_Surface) BS = (*((Handle(Geom_RectangularTrimmedSurface)*)&S))->BasisSurface();
2863 EnlargeGeometry(BS,U1,U2,V1,V2,IsV1degen,IsV2degen,
2864 uf1,uf2,vf1,vf2,GlobalEnlargeU,GlobalEnlargeVfirst,GlobalEnlargeVlast);
2865 if (!GlobalEnlargeVfirst)
2867 if (!GlobalEnlargeVlast)
2869 if (!GlobalEnlargeVfirst || !GlobalEnlargeVlast)
2870 //(*((Handle(Geom_RectangularTrimmedSurface)*)&S))->SetTrim( U1, U2, V1, V2 );
2871 S = new Geom_RectangularTrimmedSurface( BS, U1, U2, V1, V2 );
2874 SurfaceChange = Standard_True;
2876 else if (S->DynamicType() == STANDARD_TYPE(Geom_OffsetSurface)) {
2877 Handle(Geom_Surface) Surf = (*((Handle(Geom_OffsetSurface)*)&S))->BasisSurface();
2878 SurfaceChange = EnlargeGeometry(Surf,U1,U2,V1,V2,IsV1degen,IsV2degen,
2879 uf1,uf2,vf1,vf2,GlobalEnlargeU,GlobalEnlargeVfirst,GlobalEnlargeVlast);
2880 Handle(Geom_OffsetSurface)::DownCast(S)->SetBasisSurface(Surf);
2882 else if (S->DynamicType() == STANDARD_TYPE(Geom_SurfaceOfLinearExtrusion) ||
2883 S->DynamicType() == STANDARD_TYPE(Geom_SurfaceOfRevolution))
2885 Standard_Real du=0., dv=0.;
2886 Handle( Geom_Curve ) uiso, viso, uiso1, uiso2, viso1, viso2;
2887 Standard_Real u1, u2, v1, v2;
2888 Standard_Boolean enlargeU = GlobalEnlargeU, enlargeV = Standard_True;
2889 Standard_Boolean enlargeUfirst = enlargeU, enlargeUlast = enlargeU;
2890 Standard_Boolean enlargeVfirst = GlobalEnlargeVfirst, enlargeVlast = GlobalEnlargeVlast;
2891 S->Bounds( u1, u2, v1, v2 );
2892 if (Precision::IsInfinite(u1) || Precision::IsInfinite(u2))
2897 enlargeU = Standard_False;
2899 else if (S->IsUClosed())
2900 enlargeU = Standard_False;
2903 viso = S->VIso( vf1 );
2904 GeomAdaptor_Curve gac( viso );
2905 du = GCPnts_AbscissaPoint::Length( gac ) / coeff;
2906 uiso1 = S->UIso( uf1 );
2907 uiso2 = S->UIso( uf2 );
2908 if (BRepOffset_Tool::Gabarit( uiso1 ) <= TolApex)
2909 enlargeUfirst = Standard_False;
2910 if (BRepOffset_Tool::Gabarit( uiso2 ) <= TolApex)
2911 enlargeUlast = Standard_False;
2913 if (Precision::IsInfinite(v1) || Precision::IsInfinite(v2))
2918 enlargeV = Standard_False;
2920 else if (S->IsVClosed())
2921 enlargeV = Standard_False;
2924 uiso = S->UIso( uf1 );
2925 GeomAdaptor_Curve gac( uiso );
2926 dv = GCPnts_AbscissaPoint::Length( gac ) / coeff;
2927 viso1 = S->VIso( vf1 );
2928 viso2 = S->VIso( vf2 );
2929 if (BRepOffset_Tool::Gabarit( viso1 ) <= TolApex)
2931 enlargeVfirst = Standard_False;
2932 IsV1degen = Standard_True;
2934 if (BRepOffset_Tool::Gabarit( viso2 ) <= TolApex)
2936 enlargeVlast = Standard_False;
2937 IsV2degen = Standard_True;
2940 S = new Geom_RectangularTrimmedSurface( S, u1, u2, v1, v2 );
2944 GeomLib::ExtendSurfByLength( *((Handle(Geom_BoundedSurface)*)&S), du, 1, Standard_True, Standard_False );
2946 GeomLib::ExtendSurfByLength( *((Handle(Geom_BoundedSurface)*)&S), du, 1, Standard_True, Standard_True );
2951 GeomLib::ExtendSurfByLength( *((Handle(Geom_BoundedSurface)*)&S), dv, 1, Standard_False, Standard_False );
2953 GeomLib::ExtendSurfByLength( *((Handle(Geom_BoundedSurface)*)&S), dv, 1, Standard_False, Standard_True );
2955 S->Bounds( U1, U2, V1, V2 );
2956 SurfaceChange = Standard_True;
2958 else if (S->DynamicType() == STANDARD_TYPE(Geom_BezierSurface) ||
2959 S->DynamicType() == STANDARD_TYPE(Geom_BSplineSurface))
2961 Standard_Boolean enlargeU = GlobalEnlargeU, enlargeV = Standard_True;
2962 Standard_Boolean enlargeUfirst = enlargeU, enlargeUlast = enlargeU;
2963 Standard_Boolean enlargeVfirst = GlobalEnlargeVfirst, enlargeVlast = GlobalEnlargeVlast;
2965 enlargeU = Standard_False;
2967 enlargeV = Standard_False;
2969 Standard_Real duf = uf2-uf1, dvf = vf2-vf1;
2970 Standard_Real u1, u2, v1, v2;
2971 S->Bounds( u1, u2, v1, v2 );
2973 Standard_Real du=0., dv=0.;
2974 Handle( Geom_Curve ) uiso, viso, uiso1, uiso2, viso1, viso2;
2975 GeomAdaptor_Curve gac;
2978 viso = S->VIso( v1 );
2980 du = GCPnts_AbscissaPoint::Length( gac ) / coeff;
2981 uiso1 = S->UIso( u1 );
2982 uiso2 = S->UIso( u2 );
2983 if (BRepOffset_Tool::Gabarit( uiso1 ) <= TolApex)
2984 enlargeUfirst = Standard_False;
2985 if (BRepOffset_Tool::Gabarit( uiso2 ) <= TolApex)
2986 enlargeUlast = Standard_False;
2990 uiso = S->UIso( u1 );
2992 dv = GCPnts_AbscissaPoint::Length( gac ) / coeff;
2993 viso1 = S->VIso( v1 );
2994 viso2 = S->VIso( v2 );
2995 if (BRepOffset_Tool::Gabarit( viso1 ) <= TolApex)
2997 enlargeVfirst = Standard_False;
2998 IsV1degen = Standard_True;
3000 if (BRepOffset_Tool::Gabarit( viso2 ) <= TolApex)
3002 enlargeVlast = Standard_False;
3003 IsV2degen = Standard_True;
3009 if (enlargeUfirst && uf1-u1 < duf)
3010 GeomLib::ExtendSurfByLength( *((Handle(Geom_BoundedSurface)*)&S), du, 1, Standard_True, Standard_False );
3011 if (enlargeUlast && u2-uf2 < duf)
3012 GeomLib::ExtendSurfByLength( *((Handle(Geom_BoundedSurface)*)&S), du, 1, Standard_True, Standard_True );
3016 if (enlargeVfirst && vf1-v1 < dvf)
3017 GeomLib::ExtendSurfByLength( *((Handle(Geom_BoundedSurface)*)&S), dv, 1, Standard_False, Standard_False );
3018 if (enlargeVlast && v2-vf2 < dvf)
3019 GeomLib::ExtendSurfByLength( *((Handle(Geom_BoundedSurface)*)&S), dv, 1, Standard_False, Standard_True );
3022 S->Bounds( U1, U2, V1, V2 );
3023 SurfaceChange = Standard_True;
3025 // else if (S->DynamicType() == STANDARD_TYPE(Geom_BezierSurface) ||
3026 // S->DynamicType() == STANDARD_TYPE(Geom_BSplineSurface)) {
3027 // S->Bounds(U1,U2,V1,V2);
3030 Standard_Real UU1,UU2,VV1,VV2;
3031 S->Bounds(UU1,UU2,VV1,VV2);
3032 // Pas d extension au dela des bornes de la surface.
3038 return SurfaceChange;
3041 //=======================================================================
3042 //function : UpDatePCurve
3043 //purpose : Mise a jour des pcurves de F sur la surface de de BF.
3044 // F and BF has to be FORWARD,
3045 //=======================================================================
3047 static void UpdatePCurves (const TopoDS_Face& F,
3053 TopTools_IndexedMapOfShape Emap;
3054 Handle(Geom2d_Curve) NullPCurve;
3056 TopExp::MapShapes( F, TopAbs_EDGE, Emap );
3058 for (i = 1; i <= Emap.Extent(); i++)
3060 TopoDS_Edge CE = TopoDS::Edge( Emap(i) );
3061 CE.Orientation( TopAbs_FORWARD );
3062 Handle(Geom2d_Curve) C2 = BRep_Tool::CurveOnSurface( CE, F, f, l );
3065 if (BRep_Tool::IsClosed( CE, F ))
3068 Handle(Geom2d_Curve) C2R = BRep_Tool::CurveOnSurface( CE, F, f, l );
3069 B.UpdateEdge( CE, NullPCurve, NullPCurve, F, BRep_Tool::Tolerance(CE) );
3070 B.UpdateEdge( CE, C2, C2R, BF, BRep_Tool::Tolerance(CE) );
3074 B.UpdateEdge( CE, NullPCurve, F, BRep_Tool::Tolerance(CE) );
3075 B.UpdateEdge( CE, C2, BF, BRep_Tool::Tolerance(CE) );
3083 //=======================================================================
3084 //function :CompactUVBounds
3086 //=======================================================================
3088 static void CompactUVBounds (const TopoDS_Face& F,
3089 Standard_Real& UMin,
3090 Standard_Real& UMax,
3091 Standard_Real& VMin,
3092 Standard_Real& VMax)
3094 // Calcul serre pour que les bornes ne couvrent pas plus d une periode
3095 Standard_Real U1,U2;
3096 Standard_Real N = 33;
3099 TopExp_Explorer exp;
3100 for (exp.Init(F, TopAbs_EDGE); exp.More(); exp.Next()) {
3101 const TopoDS_Edge& E = TopoDS::Edge(exp.Current());
3102 BRepAdaptor_Curve2d C(E,F);
3103 BRep_Tool::Range(E,U1,U2);
3105 Standard_Real U = U1;
3106 Standard_Real DU = (U2-U1)/(N-1);
3107 for (Standard_Integer j=1;j<N;j++) {
3115 B.Get(UMin,VMin,UMax,VMax);
3118 //=======================================================================
3119 //function : CheckBounds
3121 //=======================================================================
3123 void BRepOffset_Tool::CheckBounds(const TopoDS_Face& F,
3124 const BRepOffset_Analyse& Analyse,
3125 Standard_Boolean& enlargeU,
3126 Standard_Boolean& enlargeVfirst,
3127 Standard_Boolean& enlargeVlast)
3129 enlargeU = Standard_True;
3130 enlargeVfirst = Standard_True; enlargeVlast = Standard_True;
3132 Standard_Integer Ubound = 0, Vbound = 0;
3133 Standard_Real Ufirst = RealLast(), Ulast = RealFirst();
3134 Standard_Real Vfirst = RealLast(), Vlast = RealFirst();
3136 Standard_Real UF1,UF2,VF1,VF2;
3137 CompactUVBounds(F,UF1,UF2,VF1,VF2);
3139 Handle(Geom_Surface) theSurf = BRep_Tool::Surface(F);
3140 if (theSurf->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface))
3141 theSurf = (*((Handle(Geom_RectangularTrimmedSurface)*)&theSurf))->BasisSurface();
3143 if (theSurf->DynamicType() == STANDARD_TYPE(Geom_SurfaceOfLinearExtrusion) ||
3144 theSurf->DynamicType() == STANDARD_TYPE(Geom_SurfaceOfRevolution) ||
3145 theSurf->DynamicType() == STANDARD_TYPE(Geom_BezierSurface) ||
3146 theSurf->DynamicType() == STANDARD_TYPE(Geom_BSplineSurface))
3148 TopExp_Explorer Explo(F, TopAbs_EDGE);
3149 for (; Explo.More(); Explo.Next())
3151 const TopoDS_Edge& anEdge = TopoDS::Edge(Explo.Current());
3152 const BRepOffset_ListOfInterval& L = Analyse.Type(anEdge);
3153 if (!L.IsEmpty() || BRep_Tool::Degenerated(anEdge))
3155 BRepOffset_Type OT = L.First().Type();
3156 if (OT == BRepOffset_Tangent || BRep_Tool::Degenerated(anEdge))
3158 Standard_Real fpar, lpar;
3159 Handle(Geom2d_Curve) aCurve = BRep_Tool::CurveOnSurface(anEdge, F, fpar, lpar);
3160 if (aCurve->DynamicType() == STANDARD_TYPE(Geom2d_TrimmedCurve))
3161 aCurve = (*((Handle(Geom2d_TrimmedCurve)*)&aCurve))->BasisCurve();
3163 Handle(Geom2d_Line) theLine;
3164 if (aCurve->DynamicType() == STANDARD_TYPE(Geom2d_Line))
3165 theLine = *((Handle(Geom2d_Line)*)&aCurve);
3166 else if (aCurve->DynamicType() == STANDARD_TYPE(Geom2d_BezierCurve) ||
3167 aCurve->DynamicType() == STANDARD_TYPE(Geom2d_BSplineCurve))
3169 Standard_Real newFpar, newLpar, deviation;
3170 theLine = ShapeCustom_Curve2d::ConvertToLine2d(aCurve, fpar, lpar, Precision::Confusion(),
3171 newFpar, newLpar, deviation);
3174 if (!theLine.IsNull())
3176 gp_Dir2d theDir = theLine->Direction();
3177 if (theDir.IsParallel( gp::DX2d(), Precision::Angular() ))
3180 if (BRep_Tool::Degenerated(anEdge))
3182 if (Abs(theLine->Location().Y() - VF1) <= Precision::Confusion())
3183 enlargeVfirst = Standard_False;
3184 else //theLine->Location().Y() is near VF2
3185 enlargeVlast = Standard_False;
3189 if (theLine->Location().Y() < Vfirst)
3190 Vfirst = theLine->Location().Y();
3191 if (theLine->Location().Y() > Vlast)
3192 Vlast = theLine->Location().Y();
3195 else if (theDir.IsParallel( gp::DY2d(), Precision::Angular() ))
3198 if (theLine->Location().X() < Ufirst)
3199 Ufirst = theLine->Location().X();
3200 if (theLine->Location().X() > Ulast)
3201 Ulast = theLine->Location().X();
3209 if (Ubound >= 2 || Vbound >= 2)
3212 Abs(UF1-Ufirst) <= Precision::Confusion() &&
3213 Abs(UF2-Ulast) <= Precision::Confusion())
3214 enlargeU = Standard_False;
3216 Abs(VF1-Vfirst) <= Precision::Confusion() &&
3217 Abs(VF2-Vlast) <= Precision::Confusion())
3219 enlargeVfirst = Standard_False;
3220 enlargeVlast = Standard_False;
3225 //=======================================================================
3226 //function : EnLargeFace
3228 //=======================================================================
3230 Standard_Boolean BRepOffset_Tool::EnLargeFace
3231 (const TopoDS_Face& F,
3233 const Standard_Boolean CanExtentSurface,
3234 const Standard_Boolean UpdatePCurve,
3235 const Standard_Boolean enlargeU,
3236 const Standard_Boolean enlargeVfirst,
3237 const Standard_Boolean enlargeVlast)
3239 //---------------------------
3240 // extension de la geometrie.
3241 //---------------------------
3243 Handle (Geom_Surface) S = BRep_Tool::Surface(F,L);
3244 Standard_Real UU1,VV1,UU2,VV2;
3245 Standard_Boolean isVV1degen = Standard_False, isVV2degen = Standard_False;
3246 Standard_Real US1,VS1,US2,VS2;
3247 Standard_Real UF1,VF1,UF2,VF2;
3248 Standard_Real infini = 1.e8;
3249 Standard_Boolean SurfaceChange = Standard_False;
3251 if (S->IsUPeriodic() || S->IsVPeriodic()) {
3252 // Calcul serre pour que les bornes ne couvre pas plus d une periode
3253 CompactUVBounds(F,UF1,UF2,VF1,VF2);
3256 BRepTools::UVBounds(F,UF1,UF2,VF1,VF2);
3259 S->Bounds (US1,US2,VS1,VS2);
3260 UU1 = VV1 = - infini;
3263 if (CanExtentSurface) {
3264 SurfaceChange = EnlargeGeometry( S, UU1, UU2, VV1, VV2, isVV1degen, isVV2degen, UF1, UF2, VF1, VF2,
3265 enlargeU, enlargeVfirst, enlargeVlast );
3268 UU1 = Max(US1,UU1); UU2 = Min(UU2,US2);
3269 VV1 = Max(VS1,VV1); VV2 = Min(VS2,VV2);
3272 if (S->IsUPeriodic()) {
3273 Standard_Real Period = S->UPeriod();
3274 Standard_Real Delta = Period - (UF2 - UF1);
3275 Standard_Real alpha = 0.1;
3276 UU1 = UF1 - alpha*Delta; UU2 = UF2 + alpha*Delta;
3277 if ((UU2 - UU1) > Period) {
3281 if (S->IsVPeriodic()) {
3282 Standard_Real Period = S->VPeriod();
3283 Standard_Real Delta = Period - (VF2 - VF1);
3284 Standard_Real alpha = 0.1;
3285 VV1 = VF1 - alpha*Delta; VV2 = VF2 + alpha*Delta;
3286 if ((VV2 - VV1) > Period) {
3291 //Special treatment for conical surfaces
3292 Handle(Geom_Surface) theSurf = S;
3293 if (S->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface))
3294 theSurf = (*(Handle_Geom_RectangularTrimmedSurface*)&S)->BasisSurface();
3295 if (theSurf->DynamicType() == STANDARD_TYPE(Geom_ConicalSurface))
3297 Handle(Geom_ConicalSurface) ConicalS = *((Handle(Geom_ConicalSurface)*) &theSurf);
3298 gp_Cone theCone = ConicalS->Cone();
3299 gp_Pnt theApex = theCone.Apex();
3300 Standard_Real Uapex, Vapex;
3301 ElSLib::Parameters( theCone, theApex, Uapex, Vapex );
3302 if (VV1 < Vapex && Vapex < VV2)
3304 //consider that VF1 and VF2 are on the same side from apex
3305 Standard_Real TolApex = 1.e-5;
3306 if (Vapex - VF1 >= TolApex ||
3307 Vapex - VF2 >= TolApex) //if (VF1 < Vapex || VF2 < Vapex)
3316 UU1 = UF1; UU2 = UF2;
3323 MakeFace(S,UU1,UU2,VV1,VV2,isVV1degen,isVV2degen,BF);
3326 if (S->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
3328 //----------------------------------------------------------------
3329 // utile pour les bouchons on ne doit pas changer leur geometrie.
3330 // (Ce que fait BRepLib_MakeFace si S est restreinte).
3331 // On remet S et on update les pcurves.
3332 //----------------------------------------------------------------
3333 TopExp_Explorer exp;
3334 exp.Init(BF,TopAbs_EDGE);
3335 Standard_Real f=0.,l=0.;
3336 for (; exp.More(); exp.Next()) {
3337 TopoDS_Edge CE = TopoDS::Edge(exp.Current());
3338 Handle(Geom2d_Curve) C2 = BRep_Tool::CurveOnSurface(CE,BF,f,l);
3339 B.UpdateEdge (CE,C2,S,L,BRep_Tool::Tolerance(CE));
3341 B.UpdateFace(BF,S,L,BRep_Tool::Tolerance(F));
3344 if (SurfaceChange && UpdatePCurve) {
3345 TopoDS_Shape aLocalFace = F.Oriented(TopAbs_FORWARD);
3346 UpdatePCurves(TopoDS::Face(aLocalFace),BF);
3347 //UpdatePCurves(TopoDS::Face(F.Oriented(TopAbs_FORWARD)),BF);
3349 BB.UpdateFace( F, S, L, BRep_Tool::Tolerance(F) );
3352 BF.Orientation(F.Orientation());
3353 return SurfaceChange;
3356 //=======================================================================
3357 //function : TryParameter
3359 //=======================================================================
3361 static Standard_Boolean TryParameter (const TopoDS_Edge& OE,
3363 const TopoDS_Edge& NE,
3364 Standard_Real TolConf)
3366 BRepAdaptor_Curve OC(OE);
3367 BRepAdaptor_Curve NC(NE);
3368 Standard_Real Of = OC.FirstParameter(); Standard_Real Ol = OC.LastParameter();
3369 Standard_Real Nf = NC.FirstParameter(); Standard_Real Nl = NC.LastParameter();
3371 Standard_Real U = 0.;
3375 gp_Pnt P = BRep_Tool::Pnt(V);
3376 Standard_Boolean OK = Standard_False;
3378 if (P.Distance(OC.Value(Of)) < TolConf) {
3379 if (Of > Nf && Of < Nl && P.Distance(NC.Value(Of)) < TolConf) {
3384 if (P.Distance(OC.Value(Ol)) < TolConf) {
3385 if (Ol > Nf && Ol < Nl && P.Distance(NC.Value(Ol)) < TolConf) {
3392 TopoDS_Shape aLocalShape = NE.Oriented(TopAbs_FORWARD);
3393 TopoDS_Edge EE = TopoDS::Edge(aLocalShape);
3394 // TopoDS_Edge EE = TopoDS::Edge(NE.Oriented(TopAbs_FORWARD));
3395 aLocalShape = V.Oriented(TopAbs_INTERNAL);
3396 B.UpdateVertex(TopoDS::Vertex(aLocalShape),
3397 U,NE,BRep_Tool::Tolerance(NE));
3398 // B.UpdateVertex(TopoDS::Vertex(V.Oriented(TopAbs_INTERNAL)),
3399 // U,NE,BRep_Tool::Tolerance(NE));
3404 //=======================================================================
3407 //=======================================================================
3409 void BRepOffset_Tool::MapVertexEdges (const TopoDS_Shape& S,
3410 TopTools_DataMapOfShapeListOfShape& MEV)
3412 TopExp_Explorer exp;
3413 exp.Init(S.Oriented(TopAbs_FORWARD),TopAbs_EDGE);
3414 TopTools_MapOfShape DejaVu;
3415 for ( ; exp.More(); exp.Next()) {
3416 const TopoDS_Edge& E = TopoDS::Edge(exp.Current());
3417 if (DejaVu.Add(E)) {
3418 TopoDS_Vertex V1,V2;
3419 TopExp::Vertices (E,V1,V2);
3420 if (!MEV.IsBound(V1)) {
3421 TopTools_ListOfShape empty;
3425 if (!V1.IsSame(V2)) {
3426 if (!MEV.IsBound(V2)) {
3427 TopTools_ListOfShape empty;
3436 //=======================================================================
3439 //=======================================================================
3441 void BRepOffset_Tool::BuildNeighbour (const TopoDS_Wire& W,
3442 const TopoDS_Face& F,
3443 TopTools_DataMapOfShapeShape& NOnV1,
3444 TopTools_DataMapOfShapeShape& NOnV2)
3446 TopoDS_Vertex V1,V2,VP1,VP2,FV1,FV2;
3447 TopoDS_Edge CurE,FirstE,PrecE;
3448 BRepTools_WireExplorer wexp;
3450 TopoDS_Shape aLocalFace = F.Oriented(TopAbs_FORWARD);
3451 TopoDS_Shape aLocalWire = W.Oriented(TopAbs_FORWARD);
3452 wexp.Init(TopoDS::Wire(aLocalWire),TopoDS::Face(aLocalFace));
3453 // wexp.Init(TopoDS::Wire(W.Oriented(TopAbs_FORWARD)),
3454 // TopoDS::Face(F.Oriented(TopAbs_FORWARD)));
3455 CurE = FirstE = PrecE = wexp.Current();
3456 TopExp::Vertices(CurE,V1,V2);
3457 FV1 = VP1 = V1; FV2 = VP2 = V2;
3459 while (wexp.More()) {
3460 CurE = wexp.Current();
3461 TopExp::Vertices(CurE,V1,V2);
3462 if (V1.IsSame(VP1)) { NOnV1.Bind(PrecE,CurE); NOnV1.Bind(CurE,PrecE);}
3463 if (V1.IsSame(VP2)) { NOnV2.Bind(PrecE,CurE); NOnV1.Bind(CurE,PrecE);}
3464 if (V2.IsSame(VP1)) { NOnV1.Bind(PrecE,CurE); NOnV2.Bind(CurE,PrecE);}
3465 if (V2.IsSame(VP2)) { NOnV2.Bind(PrecE,CurE); NOnV2.Bind(CurE,PrecE);}
3470 if (V1.IsSame(FV1)) { NOnV1.Bind(FirstE,CurE); NOnV1.Bind(CurE,FirstE);}
3471 if (V1.IsSame(FV2)) { NOnV2.Bind(FirstE,CurE); NOnV1.Bind(CurE,FirstE);}
3472 if (V2.IsSame(FV1)) { NOnV1.Bind(FirstE,CurE); NOnV2.Bind(CurE,FirstE);}
3473 if (V2.IsSame(FV2)) { NOnV2.Bind(FirstE,CurE); NOnV2.Bind(CurE,FirstE);}
3476 //=======================================================================
3477 //function : ExtentFace
3479 //=======================================================================
3481 void BRepOffset_Tool::ExtentFace (const TopoDS_Face& F,
3482 TopTools_DataMapOfShapeShape& ConstShapes,
3483 TopTools_DataMapOfShapeShape& ToBuild,
3484 const TopAbs_State Side,
3485 const Standard_Real TolConf,
3491 char* name = new char[100];
3492 sprintf(name,"FTE_%d",NbFTE++);
3497 TopExp_Explorer exp,exp2;
3498 TopTools_DataMapOfShapeShape Build;
3499 TopTools_DataMapOfShapeShape Extent;
3500 TopoDS_Edge FirstE,PrecE,CurE,NE;
3504 // Construction de la boite englobante de la face a etendre et des bouchons pour
3505 // limiter les extensions.
3506 //Bnd_Box ContextBox;
3507 //BRepBndLib::Add(F,B);
3508 //TopTools_DataMapIteratorOfDataMapOfShape itTB(ToBuild);
3509 //for (; itTB.More(); itTB.Next()) {
3510 //BRepBndLib::Add(TopBuild.Value(), ContextBox);
3514 Standard_Boolean SurfaceChange;
3515 SurfaceChange = EnLargeFace (F,EF,Standard_True);
3517 TopoDS_Shape aLocalShape = EF.EmptyCopied();
3518 NF = TopoDS::Face(aLocalShape);
3519 // NF = TopoDS::Face(EF.EmptyCopied());
3520 NF.Orientation(TopAbs_FORWARD);
3522 if (SurfaceChange) {
3523 //------------------------------------------------
3524 // Mise a jour des pcurves sur la surface de base.
3525 //------------------------------------------------
3526 TopoDS_Face Fforward = F;
3527 Fforward.Orientation(TopAbs_FORWARD);
3528 TopTools_IndexedMapOfShape Emap;
3529 TopExp::MapShapes( Fforward, TopAbs_EDGE, Emap );
3531 for (Standard_Integer i = 1; i <= Emap.Extent(); i++) {
3532 TopoDS_Edge CE = TopoDS::Edge( Emap(i) );
3533 CE.Orientation(TopAbs_FORWARD);
3534 TopoDS_Edge Ecs; //patch
3535 Handle(Geom2d_Curve) C2 = BRep_Tool::CurveOnSurface(CE,Fforward,f,l);
3537 if (ConstShapes.IsBound(CE)) {
3538 Ecs = TopoDS::Edge(ConstShapes(CE));
3539 BRep_Tool::Range(Ecs,f,l);
3541 if (BRep_Tool::IsClosed(CE,Fforward)) {
3542 TopoDS_Shape aLocalShape = CE.Reversed();
3543 Handle(Geom2d_Curve) C2R =
3544 BRep_Tool::CurveOnSurface(TopoDS::Edge(aLocalShape),Fforward,f,l);
3545 // Handle(Geom2d_Curve) C2R =
3546 // BRep_Tool::CurveOnSurface(TopoDS::Edge(CE.Reversed()),F,f,l);
3547 B.UpdateEdge (CE,C2,C2R,EF,BRep_Tool::Tolerance(CE));
3549 B.UpdateEdge (Ecs,C2,C2R,EF,BRep_Tool::Tolerance(CE));
3552 B.UpdateEdge (CE,C2,EF,BRep_Tool::Tolerance(CE));
3554 B.UpdateEdge (Ecs,C2,EF,BRep_Tool::Tolerance(CE));
3563 for (exp.Init(F.Oriented(TopAbs_FORWARD),TopAbs_WIRE);
3566 const TopoDS_Wire& W = TopoDS::Wire(exp.Current());
3567 TopTools_DataMapOfShapeListOfShape MVE; // Vertex -> Edges incidentes.
3568 TopTools_DataMapOfShapeShape NOnV1;
3569 TopTools_DataMapOfShapeShape NOnV2;
3571 MapVertexEdges (W,MVE);
3572 BuildNeighbour (W,F,NOnV1,NOnV2);
3574 TopTools_ListOfShape LInt1,LInt2;
3575 TopoDS_Face StopFace;
3576 //------------------------------------------------
3577 // Construction edges
3578 //------------------------------------------------
3579 for (exp2.Init(W.Oriented(TopAbs_FORWARD),TopAbs_EDGE);
3580 exp2.More(); exp2.Next()) {
3581 const TopoDS_Edge& E = TopoDS::Edge(exp2.Current());
3582 if (ConstShapes.IsBound(E)) ToBuild.UnBind(E);
3583 if (ToBuild.IsBound(E)) {
3584 TopTools_ListOfShape LOE;
3586 BRepOffset_Tool::TryProject (TopoDS::Face(ToBuild(E)),
3587 EF,LOE,LInt2,LInt1,Side,TolConf);
3588 if (!LInt1.IsEmpty())
3593 for (exp2.Init(W.Oriented(TopAbs_FORWARD),TopAbs_EDGE);
3594 exp2.More(); exp2.Next()) {
3595 const TopoDS_Edge& E = TopoDS::Edge(exp2.Current());
3596 if (ConstShapes.IsBound(E)) ToBuild.UnBind(E);
3597 if (ToBuild.IsBound(E)) {
3598 EnLargeFace(TopoDS::Face(ToBuild(E)),StopFace,Standard_False);
3599 BRepOffset_Tool::Inter3D (EF,StopFace,LInt1,LInt2,Side,E,Standard_True);
3600 if (LInt1.Extent() > 1) {
3601 // l intersection est en plusieurs edges (franchissement de couture)
3602 SelectEdge (F,EF,E,LInt1);
3604 NE = TopoDS::Edge(LInt1.First());
3605 Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &NE.TShape());
3606 TE->Tolerance( TE->Tolerance()*10. ); //????
3607 if (NE.Orientation() == E.Orientation()) {
3608 Build.Bind(E,NE.Oriented(TopAbs_FORWARD));
3611 Build.Bind(E,NE.Oriented(TopAbs_REVERSED));
3613 const TopoDS_Edge& EOnV1 = TopoDS::Edge(NOnV1(E));
3614 if (!ToBuild .IsBound(EOnV1) &&
3615 !ConstShapes.IsBound(EOnV1) &&
3616 !Build .IsBound(EOnV1)) {
3617 ExtentEdge (F,EF,EOnV1,NE);
3618 Build.Bind (EOnV1,NE.Oriented(TopAbs_FORWARD));
3620 const TopoDS_Edge& EOnV2 = TopoDS::Edge(NOnV2(E));
3621 if (!ToBuild .IsBound(EOnV2) &&
3622 !ConstShapes.IsBound(EOnV2) &&
3623 !Build .IsBound(EOnV2)) {
3624 ExtentEdge (F,EF,EOnV2,NE);
3625 Build.Bind (EOnV2,NE.Oriented (TopAbs_FORWARD));
3630 //------------------------------------------------
3631 // Construction Vertex.
3632 //------------------------------------------------
3633 TopTools_ListOfShape LV;
3636 TopoDS_Vertex V1,V2;
3638 for (exp2.Init(W.Oriented(TopAbs_FORWARD),TopAbs_EDGE);
3639 exp2.More(); exp2.Next()) {
3640 const TopoDS_Edge& E = TopoDS::Edge(exp2.Current());
3641 TopExp::Vertices (E,V1,V2);
3642 BRep_Tool::Range (E,f,l);
3644 if (Build.IsBound(E)) {
3645 const TopoDS_Edge& NEOnV1 = TopoDS::Edge(NOnV1(E));
3646 if (Build.IsBound(NEOnV1) &&
3647 (ToBuild.IsBound(E) || ToBuild.IsBound(NEOnV1))) {
3648 if (E.IsSame(NEOnV1))
3649 V = TopExp::FirstVertex(TopoDS::Edge(Build(E)));
3654 if (!Build.IsBound(V1)) {
3655 Inter2d (EF,TopoDS::Edge(Build(E)),
3656 TopoDS::Edge(Build(NEOnV1)),LV,/*TolConf*/Precision::Confusion());
3657 if (Build(E).Orientation() == TopAbs_FORWARD) {
3658 V = TopoDS::Vertex(LV.First());
3661 V = TopoDS::Vertex(LV.Last());
3665 V = TopoDS::Vertex(Build(V1));
3666 if (MVE (V1).Extent() > 2) {
3667 V.Orientation(TopAbs_FORWARD);
3668 if (Build(E).Orientation() == TopAbs_REVERSED)
3669 V.Orientation(TopAbs_REVERSED);
3670 ProjectVertexOnEdge(V,TopoDS::Edge(Build(E)),TolConf);
3680 if (ConstShapes.IsBound(V1)) V = TopoDS::Vertex(ConstShapes(V1));
3681 V.Orientation(TopAbs_FORWARD);
3682 if (Build(E).Orientation() == TopAbs_REVERSED)
3683 V.Orientation(TopAbs_REVERSED);
3684 if (!TryParameter (E,V,TopoDS::Edge(Build(E)),TolConf))
3685 ProjectVertexOnEdge(V,TopoDS::Edge(Build(E)),TolConf);
3687 ConstShapes.Bind(V1,V);
3689 const TopoDS_Edge& NEOnV2 = TopoDS::Edge(NOnV2(E));
3690 if (Build.IsBound(NEOnV2) &&
3691 (ToBuild.IsBound(E) || ToBuild.IsBound(NEOnV2))) {
3692 if (E.IsSame(NEOnV2))
3693 V = TopExp::LastVertex(TopoDS::Edge(Build(E)));
3698 if (!Build.IsBound(V2)) {
3699 Inter2d (EF,TopoDS::Edge(Build(E)),
3700 TopoDS::Edge(Build(NEOnV2)),LV,/*TolConf*/Precision::Confusion());
3701 if (Build(E).Orientation() == TopAbs_FORWARD) {
3702 V = TopoDS::Vertex(LV.Last());
3705 V = TopoDS::Vertex(LV.First());
3709 V = TopoDS::Vertex(Build(V2));
3710 if (MVE (V2).Extent() > 2) {
3711 V.Orientation(TopAbs_REVERSED);
3712 if (Build(E).Orientation() == TopAbs_REVERSED)
3713 V.Orientation(TopAbs_FORWARD);
3714 ProjectVertexOnEdge(V,TopoDS::Edge(Build(E)),TolConf);
3724 if (ConstShapes.IsBound(V2)) V = TopoDS::Vertex(ConstShapes(V2));
3725 V.Orientation(TopAbs_REVERSED);
3726 if (Build(E).Orientation() == TopAbs_REVERSED)
3727 V.Orientation(TopAbs_FORWARD);
3728 if (!TryParameter (E,V,TopoDS::Edge(Build(E)),TolConf))
3729 ProjectVertexOnEdge(V,TopoDS::Edge(Build(E)),TolConf);
3731 ConstShapes.Bind(V2,V);
3737 TopoDS_Vertex NV1,NV2;
3738 TopAbs_Orientation Or;
3739 Standard_Real U1,U2;
3740 Standard_Real eps = Precision::Confusion();
3750 for (exp2.Init(W.Oriented(TopAbs_FORWARD),TopAbs_EDGE);
3751 exp2.More(); exp2.Next()) {
3752 const TopoDS_Edge& E = TopoDS::Edge(exp2.Current());
3753 TopExp::Vertices (E,V1,V2);
3754 if (Build.IsBound(E)) {
3755 NE = TopoDS::Edge(Build(E));
3756 BRep_Tool::Range(NE,f,l);
3757 Or = NE.Orientation();
3758 //-----------------------------------------------------
3759 // Copy pour virer les vertex deja sur la nouvelle edge.
3760 //-----------------------------------------------------
3761 NV1 = TopoDS::Vertex(ConstShapes(V1));
3762 NV2 = TopoDS::Vertex(ConstShapes(V2));
3764 TopoDS_Shape aLocalVertex = NV1.Oriented(TopAbs_INTERNAL);
3765 TopoDS_Shape aLocalEdge = NE.Oriented(TopAbs_INTERNAL);
3767 U1 = BRep_Tool::Parameter(TopoDS::Vertex(aLocalVertex),
3768 TopoDS::Edge (aLocalEdge));
3769 aLocalVertex = NV2.Oriented(TopAbs_INTERNAL);
3770 aLocalEdge = NE.Oriented(TopAbs_FORWARD);
3771 U2 = BRep_Tool::Parameter
3772 (TopoDS::Vertex(aLocalVertex),TopoDS::Edge (aLocalEdge));
3773 // U1 = BRep_Tool::Parameter
3774 // (TopoDS::Vertex(NV1.Oriented(TopAbs_INTERNAL)),
3775 // TopoDS::Edge (NE .Oriented(TopAbs_FORWARD)));
3776 // U2 = BRep_Tool::Parameter
3777 // (TopoDS::Vertex(NV2.Oriented(TopAbs_INTERNAL)),
3778 // TopoDS::Edge (NE.Oriented(TopAbs_FORWARD)));
3779 aLocalEdge = NE.EmptyCopied();
3780 NE = TopoDS::Edge(aLocalEdge);
3781 NE.Orientation(TopAbs_FORWARD);
3782 if (NV1.IsSame(NV2))
3787 if (Or == TopAbs_FORWARD) {U1 = f; U2 = l;}
3788 else {U1 = l; U2 = f;}
3789 if (Or == TopAbs_FORWARD)
3793 if (Abs(U1-l) < eps) U1 = f;
3794 if (Abs(U2-f) < eps) U2 = l;
3796 TopoDS_Shape aLocalVertex = NV1.Oriented(TopAbs_FORWARD );
3797 B.Add (NE,TopoDS::Vertex(aLocalVertex));
3798 aLocalVertex = NV2.Oriented(TopAbs_REVERSED);
3799 B.Add (NE,TopoDS::Vertex(aLocalVertex));
3800 // B.Add (NE,TopoDS::Vertex(NV1.Oriented(TopAbs_FORWARD )));
3801 // B.Add (NE,TopoDS::Vertex(NV2.Oriented(TopAbs_REVERSED)));
3803 ConstShapes.Bind(E,NE);
3804 NE.Orientation(E.Orientation());
3810 if (Abs(U2-l) < eps) U2 = f;
3811 if (Abs(U1-f) < eps) U1 = l;
3813 TopoDS_Shape aLocalVertex = NV2.Oriented(TopAbs_FORWARD );
3814 B.Add (NE,TopoDS::Vertex(aLocalVertex));
3815 aLocalVertex = NV1.Oriented(TopAbs_REVERSED);
3816 B.Add (NE,TopoDS::Vertex(aLocalVertex));
3817 // B.Add (NE,TopoDS::Vertex(NV2.Oriented(TopAbs_FORWARD )));
3818 // B.Add (NE,TopoDS::Vertex(NV1.Oriented(TopAbs_REVERSED)));
3820 ConstShapes.Bind(E,NE.Oriented(TopAbs_REVERSED));
3821 NE.Orientation(TopAbs::Reverse(E.Orientation()));
3826 //-------------------
3827 // edge is not ferme.
3828 //-------------------
3829 if (Or == TopAbs_FORWARD) {
3831 TopoDS_Shape aLocalVertex = NV2.Oriented(TopAbs_FORWARD );
3832 B.Add (NE,TopoDS::Vertex(aLocalVertex));
3833 aLocalVertex = NV1.Oriented(TopAbs_REVERSED);
3834 B.Add (NE,TopoDS::Vertex(aLocalVertex));
3835 // B.Add (NE,TopoDS::Vertex(NV2.Oriented(TopAbs_FORWARD )));
3836 // B.Add (NE,TopoDS::Vertex(NV1.Oriented(TopAbs_REVERSED)));
3841 TopoDS_Shape aLocalVertex = NV1.Oriented(TopAbs_FORWARD );
3842 B.Add (NE,TopoDS::Vertex(aLocalVertex));
3843 aLocalVertex = NV2.Oriented(TopAbs_REVERSED);
3844 B.Add (NE,TopoDS::Vertex(aLocalVertex));
3845 // B.Add (NE,TopoDS::Vertex(NV1.Oriented(TopAbs_FORWARD )));
3846 // B.Add (NE,TopoDS::Vertex(NV2.Oriented(TopAbs_REVERSED)));
3849 ConstShapes.Bind(E,NE);
3850 NE.Orientation(E.Orientation());
3854 TopoDS_Shape aLocalVertex = NV1.Oriented(TopAbs_FORWARD );
3855 B.Add (NE,TopoDS::Vertex(aLocalVertex));
3856 aLocalVertex = NV2.Oriented(TopAbs_REVERSED);
3857 B.Add (NE,TopoDS::Vertex(aLocalVertex));
3858 // B.Add (NE,TopoDS::Vertex(NV1.Oriented(TopAbs_FORWARD )));
3859 // B.Add (NE,TopoDS::Vertex(NV2.Oriented(TopAbs_REVERSED)));
3861 ConstShapes.Bind(E,NE);
3862 NE.Orientation(E.Orientation());
3866 TopoDS_Shape aLocalVertex = NV2.Oriented(TopAbs_FORWARD );
3867 B.Add (NE,TopoDS::Vertex(aLocalVertex));
3868 aLocalVertex = NV1.Oriented(TopAbs_REVERSED);
3869 B.Add (NE,TopoDS::Vertex(aLocalVertex));
3870 // B.Add (NE,TopoDS::Vertex(NV2.Oriented(TopAbs_FORWARD )));
3871 // B.Add (NE,TopoDS::Vertex(NV1.Oriented(TopAbs_REVERSED)));
3873 ConstShapes.Bind(E,NE.Oriented(TopAbs_REVERSED));
3874 NE.Orientation(TopAbs::Reverse(E.Orientation()));
3879 } // Build.IsBound(E)
3880 else if (ConstShapes.IsBound(E)) { // !Build.IsBound(E)
3881 NE = TopoDS::Edge(ConstShapes(E));
3882 BuildPCurves(NE,NF);
3883 Or = NE.Orientation();
3884 if (Or == TopAbs_REVERSED) {
3885 NE.Orientation(TopAbs::Reverse(E.Orientation()));
3888 NE.Orientation(E.Orientation());
3893 ConstShapes.Bind(E,NE.Oriented(TopAbs_FORWARD));
3897 B.Add(NF,NW.Oriented(W.Orientation()));
3899 NF.Orientation(F.Orientation());
3900 BRepTools::Update(NF); // Maj des UVPoints
3905 char* name = new char[100];
3906 sprintf(name,"FOB_%d",NbFOB++);
3907 DBRep::Set(name,NF);
3913 //=======================================================================
3914 //function : Deboucle3D
3916 //=======================================================================
3918 TopoDS_Shape BRepOffset_Tool::Deboucle3D(const TopoDS_Shape& S,
3919 const TopTools_MapOfShape& Boundary)
3921 return BRepAlgo_Tool::Deboucle3D(S,Boundary);
3924 //=======================================================================
3925 //function : IsInOut
3927 //=======================================================================
3929 static Standard_Boolean IsInOut (BRepTopAdaptor_FClass2d& FC,
3930 Geom2dAdaptor_Curve AC,
3931 const TopAbs_State& S )
3933 Standard_Real Def = 100*Precision::Confusion();
3934 GCPnts_QuasiUniformDeflection QU(AC,Def);
3936 for (Standard_Integer i = 1; i <= QU.NbPoints(); i++) {
3937 gp_Pnt2d P = AC.Value(QU.Parameter(i));
3938 if (FC.Perform(P) != S) {
3939 return Standard_False;
3943 return Standard_True;
3946 //=======================================================================
3947 //function : CorrectOrientation
3949 //=======================================================================
3951 void BRepOffset_Tool::CorrectOrientation(const TopoDS_Shape& SI,
3952 const TopTools_MapOfShape& NewEdges,
3953 Handle(BRepAlgo_AsDes)& AsDes,
3954 BRepAlgo_Image& InitOffset,
3955 const Standard_Real Offset)
3958 TopExp_Explorer exp;
3959 exp.Init(SI,TopAbs_FACE);
3960 Standard_Real f=0.,l=0.;
3962 for (; exp.More(); exp.Next()) {
3964 const TopoDS_Face& FI = TopoDS::Face(exp.Current());
3965 const TopTools_ListOfShape& LOF = InitOffset.Image(FI);
3966 TopTools_ListIteratorOfListOfShape it(LOF);
3967 for (; it.More(); it.Next()) {
3968 const TopoDS_Face& OF = TopoDS::Face(it.Value());
3969 TopTools_ListOfShape& LOE = AsDes->ChangeDescendant(OF);
3970 TopTools_ListIteratorOfListOfShape itE(LOE);
3972 Standard_Boolean YaInt = Standard_False;
3973 for (; itE.More(); itE.Next()) {
3974 const TopoDS_Edge& OE = TopoDS::Edge(itE.Value());
3975 if (NewEdges.Contains(OE)) {YaInt = Standard_True; break;}
3978 TopoDS_Shape aLocalFace = FI.Oriented(TopAbs_FORWARD);
3979 BRepTopAdaptor_FClass2d FC (TopoDS::Face(aLocalFace),
3980 Precision::Confusion());
3981 // BRepTopAdaptor_FClass2d FC (TopoDS::Face(FI.Oriented(TopAbs_FORWARD)),
3982 // Precision::Confusion());
3983 for (itE.Initialize(LOE); itE.More(); itE.Next()) {
3984 TopoDS_Shape& OE = itE.Value();
3985 if (NewEdges.Contains(OE)) {
3986 Handle(Geom2d_Curve) CO2d =
3987 BRep_Tool::CurveOnSurface(TopoDS::Edge(OE),OF,f,l);
3988 Geom2dAdaptor_Curve AC(CO2d,f,l);
3991 if (IsInOut(FC,AC,TopAbs_OUT)) OE.Reverse();
3994 // if (IsInOut(FC,AC,TopAbs_IN)) OE.Reverse();