1 // Created on: 1998-01-07
2 // Created by: Philippe MANGIN
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <Adaptor3d_CurveOnSurface.hxx>
19 #include <Approx_CurveOnSurface.hxx>
20 #include <Approx_SameParameter.hxx>
21 #include <Bnd_Box.hxx>
22 #include <BOPTools_AlgoTools.hxx>
23 #include <BRep_Builder.hxx>
24 #include <BRep_CurveRepresentation.hxx>
25 #include <BRep_GCurve.hxx>
26 #include <BRep_ListIteratorOfListOfCurveRepresentation.hxx>
27 #include <BRep_TEdge.hxx>
28 #include <BRep_Tool.hxx>
29 #include <BRep_TVertex.hxx>
30 #include <BRepAdaptor_Curve.hxx>
31 #include <BRepAdaptor_Curve2d.hxx>
32 #include <BRepAdaptor_Surface.hxx>
33 #include <BRepBuilderAPI_MakeWire.hxx>
34 #include <BRepCheck_Edge.hxx>
35 #include <BRepFill_CurveConstraint.hxx>
36 #include <BRepFill_LocationLaw.hxx>
37 #include <BRepFill_SectionLaw.hxx>
38 #include <BRepFill_Sweep.hxx>
39 #include <BRepFill_TrimShellCorner.hxx>
40 #include <BRepLib.hxx>
41 #include <BRepLib_FaceError.hxx>
42 #include <BRepLib_FindSurface.hxx>
43 #include <BRepLib_MakeEdge.hxx>
44 #include <BRepLib_MakeFace.hxx>
45 #include <BRepTools_Substitution.hxx>
46 #include <BRepTools_WireExplorer.hxx>
47 #include <GCPnts_AbscissaPoint.hxx>
48 #include <Geom2d_BSplineCurve.hxx>
49 #include <Geom2d_Line.hxx>
50 #include <Geom2d_TrimmedCurve.hxx>
51 #include <Geom2dAdaptor_Curve.hxx>
52 #include <Geom_BezierCurve.hxx>
53 #include <Geom_BSplineCurve.hxx>
54 #include <Geom_Curve.hxx>
55 #include <Geom_Plane.hxx>
56 #include <Geom_RectangularTrimmedSurface.hxx>
57 #include <Geom_Surface.hxx>
58 #include <Geom_SurfaceOfRevolution.hxx>
59 #include <GeomAdaptor_Curve.hxx>
60 #include <GeomAdaptor_Surface.hxx>
61 #include <GeomConvert_ApproxSurface.hxx>
62 #include <GeomFill_LocationLaw.hxx>
63 #include <GeomFill_SectionLaw.hxx>
64 #include <GeomFill_Sweep.hxx>
65 #include <GeomLib.hxx>
66 #include <GeomLib_IsPlanarSurface.hxx>
67 #include <gp_Pnt2d.hxx>
68 #include <gp_Vec2d.hxx>
69 #include <Precision.hxx>
70 #include <Standard_ConstructionError.hxx>
71 #include <Standard_OutOfRange.hxx>
72 #include <StdFail_NotDone.hxx>
73 #include <TColGeom_Array2OfSurface.hxx>
74 #include <TColgp_Array1OfPnt.hxx>
75 #include <TColStd_Array1OfBoolean.hxx>
76 #include <TColStd_Array1OfReal.hxx>
77 #include <TColStd_Array2OfBoolean.hxx>
78 #include <TColStd_Array2OfInteger.hxx>
79 #include <TColStd_Array2OfReal.hxx>
80 #include <TColStd_HArray1OfInteger.hxx>
81 #include <TopAbs_Orientation.hxx>
83 #include <TopExp_Explorer.hxx>
85 #include <TopoDS_Compound.hxx>
86 #include <TopoDS_Edge.hxx>
87 #include <TopoDS_Face.hxx>
88 #include <TopoDS_Iterator.hxx>
89 #include <TopoDS_Shape.hxx>
90 #include <TopoDS_Shell.hxx>
91 #include <TopoDS_Wire.hxx>
92 #include <TopTools_Array1OfShape.hxx>
93 #include <TopTools_Array2OfShape.hxx>
94 #include <TopTools_DataMapIteratorOfDataMapOfShapeShape.hxx>
95 #include <TopTools_HArray1OfShape.hxx>
96 #include <TopTools_HArray2OfShape.hxx>
97 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
98 #include <TopTools_ListIteratorOfListOfShape.hxx>
99 #include <TopTools_ListOfShape.hxx>
100 #include <TopTools_SequenceOfShape.hxx>
103 //#include <BRepFill_TrimCorner.hxx>
104 // modified by NIZHNY-MKK Wed Oct 22 12:25:45 2003
105 //#include <GeomPlate_BuildPlateSurface.hxx>
106 //#include <GeomPlate_Surface.hxx>
107 //#include <GeomPlate_PointConstraint.hxx>
111 #include <DrawTrSurf.hxx>
113 #include <Geom_BoundedSurface.hxx>
114 static Standard_Boolean Affich = 0;
117 //=======================================================================
118 //function : NumberOfPoles
120 //=======================================================================
121 static Standard_Integer NumberOfPoles(const TopoDS_Wire& W)
123 Standard_Integer NbPoints = 0;
125 TopoDS_Iterator iter(W);
126 for (; iter.More(); iter.Next())
128 BRepAdaptor_Curve c(TopoDS::Edge(iter.Value()));
130 Standard_Real dfUf = c.FirstParameter();
131 Standard_Real dfUl = c.LastParameter();
132 if (IsEqual(dfUf,dfUl))
138 case GeomAbs_BezierCurve:
140 // Put all poles for bezier
141 Handle(Geom_BezierCurve) GC = c.Bezier();
142 Standard_Integer iNbPol = GC->NbPoles();
147 case GeomAbs_BSplineCurve:
149 // Put all poles for bspline
150 Handle(Geom_BSplineCurve) GC = c.BSpline();
151 Standard_Integer iNbPol = GC->NbPoles();
162 case GeomAbs_Ellipse:
163 case GeomAbs_Hyperbola:
164 case GeomAbs_Parabola:
170 NbPoints += 15 + c.NbIntervals(GeomAbs_C3);
171 } // switch (c.GetType()) ...
172 } // for (; iter.More(); iter.Next())
177 //=======================================================================
178 //function : HasPCurves
180 //=======================================================================
181 static Standard_Boolean HasPCurves(const TopoDS_Edge& E)
183 Standard_Boolean haspcurves = Standard_False;
185 BRep_ListIteratorOfListOfCurveRepresentation itcr
186 ((*((Handle(BRep_TEdge)*)&E.TShape()))->Curves());
187 for (; itcr.More(); itcr.Next())
189 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
190 if (cr->IsCurveOnSurface())
192 haspcurves = Standard_True;
199 //=======================================================================
200 //function : Translate
201 //purpose : Copy a column from one table to another.
202 //=======================================================================
203 static void Translate(const Handle(TopTools_HArray2OfShape)& ArrayIn,
204 const Standard_Integer In,
205 Handle(TopTools_HArray2OfShape)& ArrayOut,
206 const Standard_Integer Out)
208 Standard_Integer ii, Nb;
209 Nb = ArrayOut->ColLength();
210 for (ii=1; ii<=Nb; ii++) {
211 ArrayOut->SetValue(ii, Out, ArrayIn->Value(ii, In));
216 //=======================================================================
218 //purpose : Bounding box of a section.
219 //=======================================================================
220 static void Box(Handle(GeomFill_SectionLaw)& Sec,
221 const Standard_Real U,
225 Standard_Integer NbPoles, bid;
227 Sec->SectionShape(NbPoles, bid, bid);
228 TColgp_Array1OfPnt Poles(1, NbPoles);
229 TColStd_Array1OfReal W(1, NbPoles);
230 Sec->D0(U, Poles, W);
231 for (Standard_Integer ii=1; ii<=NbPoles; ii++) {
236 //=======================================================================
238 //purpose : Check if E is an edge of sewing on S
239 // and make the representation HadHoc
240 //=======================================================================
241 static Handle(Geom2d_Curve) Couture(const TopoDS_Edge& E,
242 const Handle(Geom_Surface)& S,
243 const TopLoc_Location& L)
245 TopLoc_Location l = L.Predivided(E.Location());
246 Standard_Boolean Eisreversed = (E.Orientation() == TopAbs_REVERSED);
248 // find the representation
249 BRep_ListIteratorOfListOfCurveRepresentation itcr
250 ((*((Handle(BRep_TEdge)*)&E.TShape()))->ChangeCurves());
252 while (itcr.More()) {
253 Handle(BRep_CurveRepresentation)& cr = itcr.Value();
254 if (cr->IsCurveOnSurface(S,l)) {
255 Handle(BRep_GCurve) GC (Handle(BRep_GCurve)::DownCast (cr));
256 if (GC->IsCurveOnClosedSurface() && Eisreversed)
257 return GC->PCurve2();
263 Handle(Geom2d_Curve) pc;
268 //=======================================================================
269 //function : CheckSameParameter
270 //purpose : Check a posteriori that sameparameter has worked correctly
271 //=======================================================================
273 static Standard_Boolean CheckSameParameter
274 (const Handle(Adaptor3d_Curve)& C3d,
275 const Handle(Geom2d_Curve)& Pcurv,
276 const Handle(Adaptor3d_Surface)& S,
277 const Standard_Real tol3d,
278 Standard_Real& tolreached)
281 Standard_Real f = C3d->FirstParameter();
282 Standard_Real l = C3d->LastParameter();
283 Standard_Integer nbp = 45;
284 Standard_Real step = 1./(nbp -1);
285 for(Standard_Integer i = 0; i < nbp; i++){
288 t = (1-t) * f + t * l;
289 Pcurv->Value(t).Coord(u,v);
290 gp_Pnt pS = S->Value(u,v);
291 gp_Pnt pC = C3d->Value(t);
292 Standard_Real d2 = pS.SquareDistance(pC);
293 tolreached = Max(tolreached,d2);
295 tolreached = sqrt(tolreached);
296 if(tolreached > tol3d){
298 return Standard_False;
301 tolreached = Max(tolreached,Precision::Confusion());
302 return Standard_True;
305 //=======================================================================
306 //function : SameParameter
307 //purpose : Encapsulation of Sameparameter
308 // Boolean informs if the pcurve was computed or not...
309 // The tolerance is always OK.
310 //=======================================================================
312 static Standard_Boolean SameParameter(TopoDS_Edge& E,
313 Handle(Geom2d_Curve)& Pcurv,
314 const Handle(Geom_Surface)& Surf,
315 const Standard_Real tol3d,
316 Standard_Real& tolreached)
318 //Handle(BRepAdaptor_Curve) C3d = new (BRepAdaptor_Curve)(E);
320 Handle(Geom_Curve) C3d = BRep_Tool::Curve( E, f, l );
321 GeomAdaptor_Curve GAC3d( C3d, f, l );
322 Handle(GeomAdaptor_Curve) HC3d = new GeomAdaptor_Curve( GAC3d );
324 Handle(GeomAdaptor_Surface) S = new (GeomAdaptor_Surface)(Surf);
325 Standard_Real ResTol;
327 if(CheckSameParameter( HC3d, Pcurv, S, tol3d, tolreached ))
328 return Standard_True;
332 Handle(Geom2dAdaptor_Curve) HC2d = new Geom2dAdaptor_Curve( Pcurv );
333 Approx_CurveOnSurface AppCurve(HC2d, S, HC2d->FirstParameter(), HC2d->LastParameter(),
334 Precision::Confusion());
335 AppCurve.Perform(10, 10, GeomAbs_C1, Standard_True);
336 if (AppCurve.IsDone() && AppCurve.HasResult())
338 C3d = AppCurve.Curve3d();
339 tolreached = AppCurve.MaxError3d();
341 B.UpdateEdge( E, C3d, tolreached );
342 return Standard_True;
346 const Handle(Adaptor3d_Curve)& aHCurve = HC3d; // to avoid ambiguity
347 Approx_SameParameter sp (aHCurve, Pcurv, S, tol3d );
348 if(sp.IsDone() && !sp.IsSameParameter()) Pcurv = sp.Curve2d();
349 else if(!sp.IsDone() && !sp.IsSameParameter()){
351 std::cout<<"echec SameParameter"<<std::endl;
353 return Standard_False;
356 ResTol = sp.TolReached();
357 if(ResTol > tolreached ){
359 std::cout<<"SameParameter : Tolerance not reached!"<<std::endl;
360 std::cout<<"tol visee : "<<tol3d<<" tol obtained : "<<ResTol<<std::endl;
362 return Standard_False;
365 tolreached = 1.1*ResTol;
366 if(sp.IsDone() && !sp.IsSameParameter()) Pcurv = sp.Curve2d();
368 return Standard_True;
371 static void CorrectSameParameter(TopoDS_Edge& theEdge,
372 const TopoDS_Face& theFace1,
373 const TopoDS_Face& theFace2)
375 if (BRep_Tool::Degenerated(theEdge))
378 Standard_Real fpar, lpar;
379 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(theEdge, fpar, lpar);
381 Standard_Boolean PCurveExists [2] = {Standard_False, Standard_False};
382 BRepAdaptor_Curve BAcurve [2];
384 if (!theFace1.IsNull())
386 PCurveExists[0] = Standard_True;
387 BAcurve[0].Initialize(theEdge, theFace1);
389 if (!theFace1.IsNull() &&
390 theFace1.IsSame(theFace2))
392 if (!theFace2.IsNull())
394 PCurveExists[1] = Standard_True;
395 BAcurve[1].Initialize(theEdge, theFace2);
398 Standard_Real MaxSqDist = 0.;
399 const Standard_Integer NCONTROL = 23;
400 Standard_Real delta = (lpar - fpar)/NCONTROL;
402 for (Standard_Integer i = 0; i <= NCONTROL; i++)
404 Standard_Real aParam = fpar + i*delta;
405 gp_Pnt aPnt = aCurve->Value(aParam);
406 for (Standard_Integer j = 0; j < 2; j++)
409 gp_Pnt aPntFromFace = BAcurve[j].Value(aParam);
410 Standard_Real aSqDist = aPnt.SquareDistance(aPntFromFace);
411 if (aSqDist > MaxSqDist)
416 Standard_Real aTol = sqrt(MaxSqDist);
418 BB.UpdateEdge(theEdge, aTol);
421 //=======================================================================
422 //Objet : Orientate an edge of natural restriction
424 //=======================================================================
425 static void Oriente(const Handle(Geom_Surface)& S,
429 gp_Vec2d D, URef(1, 0), VRef(0, 1);
430 Standard_Boolean isuiso, isfirst, isopposite;
431 Standard_Real UFirst, ULast, VFirst, VLast, f, l;
432 S->Bounds(UFirst, ULast, VFirst, VLast);
433 Handle(Geom2d_Curve) C;
436 C = BRep_Tool::CurveOnSurface(E, S, bid, f, l);
437 C->D1((f+l)/2, P, D);
439 isuiso = D.IsParallel(VRef, 0.1);
442 isfirst = (Abs (P.X()-UFirst) < Precision::Confusion());
443 isopposite = D.IsOpposite(VRef, 0.1);
444 E.Orientation(TopAbs_REVERSED);
447 isfirst = (Abs (P.Y()-VFirst) < Precision::Confusion());
448 isopposite = D.IsOpposite(URef, 0.1);
449 E.Orientation(TopAbs_FORWARD);
452 if (!isfirst) E.Reverse();
453 if (isopposite) E.Reverse();
456 static void UpdateEdgeOnPlane(const TopoDS_Face& F, const TopoDS_Edge& E,
457 const BRep_Builder& BB)
460 Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(E,F,f,l);
461 Handle(Geom_Surface) S = BRep_Tool::Surface(F);
463 Standard_Real Tol = BRep_Tool::Tolerance(E);
464 BB.UpdateEdge(E, C2d, S, Loc, Tol);
465 BRepCheck_Edge Check(E);
466 Tol = Max(Tol,Check.Tolerance());
467 BB.UpdateEdge(E, Tol);
470 V = TopExp::FirstVertex(E);
471 if(BRep_Tool::Tolerance(V) < Tol) BB.UpdateVertex(V, Tol);
472 V = TopExp::LastVertex(E);
473 if(BRep_Tool::Tolerance(V) < Tol) BB.UpdateVertex(V, Tol);
476 //=======================================================================
477 //Function : BuildFace
478 //Objet : Construct a Face via a surface and 4 Edges (natural borders)
479 // : Only one Hypothesis : isos u and v are switched :
480 // Edge1/3 are iso u (recp v)
481 // Edge2/4 are iso v (recp u)
482 //=======================================================================
483 static void BuildFace(const Handle(Geom_Surface)& S,
484 const TopoDS_Edge& E1,
485 const TopoDS_Edge& E2,
486 const TopoDS_Edge& E3,
487 const TopoDS_Edge& E4,
488 TopTools_DataMapOfShapeShape& EEmap,
489 const Standard_Boolean ExchUV,
490 const Standard_Boolean UReverse,
494 // Class BRep_Tool without fields and without Constructor :
496 TopoDS_Edge e1, e2, E;
499 BRepBuilderAPI_MakeWire B;
500 TopoDS_Iterator Iter;
503 //Is the surface planar ?
504 Standard_Real Tol1, Tol2, Tol3, Tol4;
505 Tol1 = BRep_Tool::Tolerance( E1 );
506 Tol2 = BRep_Tool::Tolerance( E2 );
507 Tol3 = BRep_Tool::Tolerance( E3 );
508 Tol4 = BRep_Tool::Tolerance( E4 );
509 // Tol = Min( BT.Tolerance(E1), BT.Tolerance(E2));
510 Tol = Min( Tol1, Tol2 );
511 // Tol = Min(Tol, Min(BT.Tolerance(E3),BT.Tolerance(E4)));
512 Tol = Min( Tol, Min( Tol3, Tol4 ) );
513 Standard_Boolean IsPlan = Standard_False;
514 Handle(Geom_Plane) thePlane;
516 if (!E1.IsSame(E3) && !E2.IsSame(E4)) //exclude cases with seam edges: they are not planar
518 GeomLib_IsPlanarSurface IsP(S, Tol);
521 IsPlan = Standard_True;
522 thePlane = new Geom_Plane( IsP.Plan() );
526 Handle(BRep_TEdge)& TE1 = *((Handle(BRep_TEdge)*)&E1.TShape());
527 Handle(BRep_TEdge)& TE2 = *((Handle(BRep_TEdge)*)&E2.TShape());
528 Handle(BRep_TEdge)& TE3 = *((Handle(BRep_TEdge)*)&E3.TShape());
529 Handle(BRep_TEdge)& TE4 = *((Handle(BRep_TEdge)*)&E4.TShape());
530 TE1->Tolerance( Precision::Confusion() );
531 TE2->Tolerance( Precision::Confusion() );
532 TE3->Tolerance( Precision::Confusion() );
533 TE4->Tolerance( Precision::Confusion() );
535 TopoDS_Wire theWire = BRepLib_MakeWire( E1, E2, E3, E4 );
536 Standard_Integer NbPoints = NumberOfPoles( theWire );
537 if (NbPoints <= 100) //limitation for CPU
539 BRepLib_FindSurface FS( theWire, -1, Standard_True );
542 IsPlan = Standard_True;
543 thePlane = Handle(Geom_Plane)::DownCast(FS.Surface());
546 BB.UpdateEdge( E1, Tol1 );
547 BB.UpdateEdge( E2, Tol2 );
548 BB.UpdateEdge( E3, Tol3 );
549 BB.UpdateEdge( E4, Tol4 );
553 // Construction of the wire
557 // if (!IsPlan || !BT.Degenerated(e1))
558 if (!IsPlan || !BRep_Tool::Degenerated(e1))
563 // if (!IsPlan || !BT.Degenerated(e2))
564 if (!IsPlan || !BRep_Tool::Degenerated(e2))
567 if (!BRep_Tool::Degenerated(e2))
570 TopoDS_Shape NewEdge;
571 //take the last edge added to WW
572 for (Iter.Initialize( WW ); Iter.More(); Iter.Next())
573 NewEdge = Iter.Value();
574 if (! e2.IsSame(NewEdge))
575 EEmap.Bind( e2, NewEdge );
587 // if (!IsPlan || !BT.Degenerated(E))
588 if (!IsPlan || !BRep_Tool::Degenerated(E))
591 if (!BRep_Tool::Degenerated(E))
594 TopoDS_Shape NewEdge;
595 //take the last edge added to WW
596 for (Iter.Initialize( WW ); Iter.More(); Iter.Next())
597 NewEdge = Iter.Value();
598 if (! E.IsSame(NewEdge))
599 EEmap.Bind( E, NewEdge );
611 // if (!IsPlan || !BT.Degenerated(E))
612 if (!IsPlan || !BRep_Tool::Degenerated(E))
615 if (!BRep_Tool::Degenerated(E))
618 TopoDS_Shape NewEdge;
619 //take the last edge added to WW
620 for (Iter.Initialize( WW ); Iter.More(); Iter.Next())
621 NewEdge = Iter.Value();
622 if (! E.IsSame(NewEdge))
623 EEmap.Bind( E, NewEdge );
630 DBRep::Set("wire-on-face", WW);
633 // Construction of the face.
634 if (IsPlan) { // Suspend representation 2d
635 // and construct face Plane
637 //BRepLib_MakeFace MkF(IsP.Plan(), WW);
639 gp_Vec DU, DV, NS, NP;
640 Standard_Real Ufirst, Ulast, Vfirst, Vlast;
641 S->Bounds( Ufirst, Ulast, Vfirst, Vlast );
642 S->D1( (Ufirst+Ulast)/2., (Vfirst+Vlast)/2., aPnt, DU, DV );
644 NP = thePlane->Pln().Axis().Direction();
646 thePlane->UReverse();
647 BRepLib_MakeFace MkF( thePlane, WW );
648 if (MkF.Error() != BRepLib_FaceDone) {
650 BRepLib_FaceError Err = MkF.Error();
651 std::cout << "Planar Face Error :" << Err << std::endl;
655 Handle(Geom2d_Curve) NullC2d;
657 BB.UpdateEdge( E1, NullC2d, S, Loc, Tol1 );
658 BB.UpdateEdge( E2, NullC2d, S, Loc, Tol2 );
659 BB.UpdateEdge( E3, NullC2d, S, Loc, Tol3 );
660 BB.UpdateEdge( E4, NullC2d, S, Loc, Tol4 );
663 UpdateEdgeOnPlane(F,E1,BB);
664 UpdateEdgeOnPlane(F,E2,BB);
665 UpdateEdgeOnPlane(F,E3,BB);
666 UpdateEdgeOnPlane(F,E4,BB);
669 Handle(Geom2d_Curve) NC;
671 // B.UpdateEdge(E1, NC, S, Loc, BT.Tolerance(E1));
672 BB.UpdateEdge(E1, NC, S, Loc, BRep_Tool::Tolerance(E1));
673 // B.UpdateEdge(E2, NC, S, Loc, BT.Tolerance(E2));
674 BB.UpdateEdge(E2, NC, S, Loc, BRep_Tool::Tolerance(E2));
675 // B.UpdateEdge(E3, NC, S, Loc, BT.Tolerance(E3));
676 BB.UpdateEdge(E3, NC, S, Loc, BRep_Tool::Tolerance(E3));
677 // B.UpdateEdge(E4, NC, S, Loc, BT.Tolerance(E4));
678 BB.UpdateEdge(E4, NC, S, Loc, BRep_Tool::Tolerance(E4));
683 if (!IsPlan) {// Cas Standard : Ajout
684 BB.MakeFace(F, S, Precision::Confusion());
689 if (ExchUV) F.Reverse();
690 if (UReverse) F.Reverse();
694 //=======================================================================
695 //Fonction : BuildEdge
696 //Objet : Construct non-closed Edge
697 //=======================================================================
698 static TopoDS_Edge BuildEdge(Handle(Geom_Curve)& C3d,
699 Handle(Geom2d_Curve)& C2d,
700 Handle(Geom_Surface)& S,
701 const TopoDS_Vertex& VF,
702 const TopoDS_Vertex& VL,
703 const Standard_Real f,
704 const Standard_Real l,
705 const Standard_Real Tol3d)
708 Standard_Real Tol1, Tol2, Tol, d;
709 // Class BRep_Tool without fields and without Constructor :
715 const gp_Pnt P1 = BRep_Tool::Pnt(VF);
716 // Tol1 = BT.Tolerance(VF);
717 Tol1 = BRep_Tool::Tolerance(VF);
719 const gp_Pnt P2 = BRep_Tool::Pnt(VL);
720 // Tol2 = BT.Tolerance(VF);
721 Tol2 = BRep_Tool::Tolerance(VL);
722 Tol = Max(Tol1, Tol2);
725 (P1.Distance(P2) < Tol ) ) {
729 S->D0(P2d.X(), P2d.Y(), P);
731 if (d > Tol) Tol = d;
733 S->D0(P2d.X(), P2d.Y(), P);
735 if (d > Tol) Tol = d;
737 B.UpdateVertex(VF, Tol);
738 B.UpdateVertex(VL, Tol);
741 B.UpdateEdge(E,C2d,S,TopLoc_Location(), Tol);
745 B.Degenerated(E, Standard_True);
753 B.UpdateVertex(VF, d);
758 B.UpdateVertex(VL, d);
760 BRepLib_MakeEdge MkE (C3d, VF, VL, f, l);
761 if (!MkE.IsDone()) { // Error of construction !!
764 sprintf(name,"firstvertex_error");
765 DBRep::Set(name, VF);
766 sprintf(name,"lastvertex_error");
767 DBRep::Set(name, VL);
768 sprintf(name,"curve3d_error");
770 DrawTrSurf::Set(Temp, C3d);
771 // DrawTrSurf::Set(name, C3d);
772 throw Standard_ConstructionError("BRepFill_Sweep::BuildEdge");
778 B.UpdateEdge(E, C2d, S, Loc, Tol3d);
780 const Handle(IntTools_Context) aNullCtx;
781 if (BOPTools_AlgoTools::IsMicroEdge(E, aNullCtx))
783 TopoDS_Vertex aV = VF;
784 B.UpdateVertex(aV, P1.Distance(P2));
786 B.UpdateEdge(E, C2d, S, TopLoc_Location(), Tol);
787 B.Add(E, TopoDS::Vertex(aV.Oriented(TopAbs_FORWARD)));
788 B.Add(E, TopoDS::Vertex(aV.Oriented(TopAbs_REVERSED)));
790 B.Degenerated(E, Standard_True);
797 //=======================================================================
799 //Objet : Construct the faces of filling
800 //=======================================================================
801 static Standard_Boolean Filling(const TopoDS_Shape& EF,
802 const TopoDS_Shape& F1,
803 const TopoDS_Shape& EL,
804 const TopoDS_Shape& F2,
805 TopTools_DataMapOfShapeShape& EEmap,
806 const Standard_Real Tol,
808 const gp_Vec& TangentOnPart1,
814 // Class BRep_Tool without fields and without Constructor :
816 // Standard_Integer NbInt =0;
817 // Standard_Real Tol3d = Tol;
818 Standard_Boolean WithE3, WithE4;
820 // Return constraints
821 TopoDS_Vertex V1, V2, Vf, Vl;
822 TopoDS_Edge E1, E2, E3, E4;
823 E1 = TopoDS::Edge(EF);
824 E2 = TopoDS::Edge(EL);
826 TopExp::Vertices(E1, Vf, Vl);
827 Vf.Orientation(TopAbs_FORWARD);
828 Vl.Orientation(TopAbs_FORWARD);
830 TopExp::Vertices(E2, V1, V2);
831 V1.Orientation(TopAbs_REVERSED);
832 V2.Orientation(TopAbs_REVERSED);
837 WithE3 = WithE4 = Standard_False;
839 if ((!Aux1.IsNull()) && (!Vf.IsSame(V1))) {
841 // E3 = TopoDS::Edge(Aux1);
842 WithE3 = Standard_True;
850 else if (!Aux2.IsNull() && (!Vl.IsSame(V2))) {
852 // E4 = TopoDS::Edge(Aux2);
853 WithE4 = Standard_True;
858 DBRep::Set("Fill_Edge1", E1);
859 DBRep::Set("Fill_Edge2", E2);
861 DBRep::Set("Fill_Edge3", E3);
863 DBRep::Set("Fill_Edge4", E4);
867 // Construction of a surface of revolution
868 Handle(Geom_Curve) Prof1, Prof2;
869 //Standard_Integer ii, jj;//, Nb;
870 Standard_Real f1, f2, l1, l2,/*d1, d2,*/ Angle;//, Eps = 1.e-9;
871 // Prof1 = BT.Curve(E1, f1, l1);
872 Prof1 = BRep_Tool::Curve(E1, f1, l1);
873 // Prof2 = BT.Curve(E2, f2, l2);
874 Prof2 = BRep_Tool::Curve(E2, f2, l2);
876 // Indeed, both Prof1 and Prof2 are the same curves but in different positions
880 // Choose the angle of opening
882 aTf.SetTransformation(Axe);
884 // Choose the furthest point from the "center of revolution"
885 // to provide correct angle measurement.
886 const Standard_Real aPrm[] = {f1, 0.5*(f1 + l1), l1};
887 const gp_Pnt aP1[] = {Prof1->Value(aPrm[0]).Transformed(aTf),
888 Prof1->Value(aPrm[1]).Transformed(aTf),
889 Prof1->Value(aPrm[2]).Transformed(aTf)};
891 Standard_Integer aMaxIdx = -1;
892 Standard_Real aMaxDist = RealFirst();
893 for (Standard_Integer i = 0; i < 3; i++)
895 const Standard_Real aDist = aP1[i].X()*aP1[i].X() + aP1[i].Z()*aP1[i].Z();
896 if (aDist > aMaxDist)
903 const gp_Pnt aP2 = Prof2->Value(aPrm[aMaxIdx]).Transformed(aTf);
904 const gp_Vec2d aV1(aP1[aMaxIdx].Z(), aP1[aMaxIdx].X());
905 const gp_Vec2d aV2(aP2.Z(), aP2.X());
906 if (aV1.SquareMagnitude() <= gp::Resolution() ||
907 aV2.SquareMagnitude() <= gp::Resolution())
909 return Standard_False;
912 Angle = aV1.Angle(aV2);
914 gp_Ax1 axe(Axe.Location(), Axe.YDirection());
921 Handle(Geom_SurfaceOfRevolution) Rev =
922 new (Geom_SurfaceOfRevolution) (Prof1, axe);
924 Handle(Geom_Surface) Surf =
925 new (Geom_RectangularTrimmedSurface) (Rev, 0, Angle, f1, l1);
927 // Control the direction of the rotation
928 Standard_Boolean ToReverseResult = Standard_False;
930 d1u = Surf->DN(0, aPrm[aMaxIdx], 1, 0);
931 if (d1u.Angle(TangentOnPart1) > M_PI/2) { //Invert everything
932 ToReverseResult = Standard_True;
935 Angle = 2*M_PI - Angle;
936 Rev = new (Geom_SurfaceOfRevolution) (Prof1, axe);
937 Surf = new (Geom_RectangularTrimmedSurface)
938 (Rev, 0, Angle, f1, l1);
944 char* Temp = "Surf_Init" ;
945 DrawTrSurf::Set(Temp, Surf);
949 Handle(Geom2d_Curve) C1, C2, C3, C4;
951 // Deform the surface of revolution.
952 GeomPlate_BuildPlateSurface BPS;
954 Handle(BRepAdaptor_Surface) AS;
955 Handle(BRepAdaptor_Curve2d) AC2d;
956 Handle(Adaptor3d_CurveOnSurface) HConS;
958 Handle(Geom2d_Line) L;
961 L = new (Geom2d_Line) (P2d, gp::DY2d());
962 C1 = new (Geom2d_TrimmedCurve) (L, f1, l1);
964 P2d.SetCoord(Angle,0.);
965 L = new (Geom2d_Line) (P2d, gp::DY2d());
966 C2 = new (Geom2d_TrimmedCurve) (L, f1, l1);
968 // It is required to control the direction and the range.
970 Surf->D0(P2d.X(), P2d.Y(), P1);
972 Surf->D0(P2d.X(), P2d.Y(), P2);
974 P = BRep_Tool::Pnt(V1);
975 if (P.Distance(P2)+Tol < P.Distance(P1)) {
976 // E2 is parsed in the direction opposite to E1
983 GeomLib::SameRange(Precision::PConfusion(), C2,
984 C2->FirstParameter(),
990 P1 = BRep_Tool::Pnt(Vf);
992 P2 = BRep_Tool::Pnt(V1);
993 // pointu_f = Vf.IsSame(V1) || (P1.Distance(P2) < BT.Tolerance(Vf));
995 P1 = BRep_Tool::Pnt(Vl);
997 P2 = BRep_Tool::Pnt(V2);
998 // pointu_l = Vl.IsSame(V2) || (P1.Distance(P2) < BT.Tolerance(Vl));
1000 P2d.SetCoord(0.,f1);
1001 L = new (Geom2d_Line) (P2d, gp::DX2d());
1002 C3 = new (Geom2d_TrimmedCurve) (L, 0, Angle);
1005 P2d.SetCoord(0.,l1);
1006 L = new (Geom2d_Line) (P2d, gp::DX2d());
1007 C4 = new (Geom2d_TrimmedCurve) (L, 0, Angle);
1009 // Determine the constraints and
1010 // their parametric localisation.
1012 AS = new BRepAdaptor_Surface(TopoDS::Face(F1));
1013 AC2d = new BRepAdaptor_Curve2d();
1014 AC2d->ChangeCurve2d().Initialize(E1,TopoDS::Face(F1));
1015 HConS = new (Adaptor3d_CurveOnSurface)();
1016 HConS->ChangeCurve().Load(AC2d);
1017 HConS->ChangeCurve().Load(AS);
1019 Handle(BRepFill_CurveConstraint) Cont
1020 = new BRepFill_CurveConstraint(HConS, 1, 15);
1021 Cont->SetCurve2dOnSurf(C1);
1024 NbInt = HConS->NbIntervals(GeomAbs_CN);
1028 AS = new BRepAdaptor_Surface(TopoDS::Face(F2));
1029 AC2d = new BRepAdaptor_Curve2d();
1030 AC2d->ChangeCurve2d().Initialize(E2,TopoDS::Face(F2));
1031 HConS = new (Adaptor3d_CurveOnSurface);
1033 HConS->ChangeCurve().Load(AC2d);
1034 HConS->ChangeCurve().Load(AS);
1036 Handle(BRepFill_CurveConstraint) Cont
1037 = new BRepFill_CurveConstraint(HConS, 1, 15);
1038 Cont->SetCurve2dOnSurf(C2);
1043 Handle(BRepAdaptor_Curve) AC = new (BRepAdaptor_Curve) (E3);
1044 Handle(BRepFill_CurveConstraint) Cont
1045 = new BRepFill_CurveConstraint(AC, 0);
1046 Cont->SetCurve2dOnSurf(C3);
1049 else if (pointu_f) {
1050 Standard_Real delta = Angle / 11;
1052 P = BRep_Tool::Pnt(Vf);
1053 Handle(GeomPlate_PointConstraint) PC;
1054 for (ii=1; ii<=10; ii++) {
1055 C3->D0(ii*delta, P2d);
1056 PC = new (GeomPlate_PointConstraint) (P, 0);
1057 PC->SetPnt2dOnSurf(P2d);
1064 Handle(BRepAdaptor_Curve) AC = new (BRepAdaptor_Curve) (E4);
1065 Handle(BRepFill_CurveConstraint) Cont
1066 = new BRepFill_CurveConstraint(AC, 0);
1067 Cont->SetCurve2dOnSurf(C4);
1070 else if (pointu_l) {
1071 Standard_Real delta = Angle / 11;
1073 P = BRep_Tool::Pnt(Vl);
1074 Handle(GeomPlate_PointConstraint) PC;
1075 for (ii=1; ii<=10; ii++) {
1076 C4->D0(ii*delta, P2d);
1077 PC = new (GeomPlate_PointConstraint) (P, 0);
1078 PC->SetPnt2dOnSurf(P2d);
1083 BPS.LoadInitSurface(Surf);
1086 // Controle s'il y a une deformation effective
1087 Handle(GeomPlate_Surface) plate;
1088 plate = BPS.Surface();
1089 plate->SetBounds(0, Angle, f1, l1);
1090 Standard_Boolean Ok=Standard_True;
1094 for (ii=0; ii<=5 && Ok; ii++) {
1096 for (jj=0; jj<=5 && Ok; jj++) {
1098 plate->D0(u, v, P1);
1100 Ok = (P2.IsEqual(P1, Tol));
1106 // Approx de la plate surface
1107 // Bords naturelles => pas besoin de criteres.
1108 GeomConvert_ApproxSurface App(BPS.Surface(),
1110 GeomAbs_C1, GeomAbs_C1,
1112 if (!App.HasResult()) {
1114 std::cout << "Filling_Approx : Pas de resultat" << std::endl;
1116 return Standard_False;
1119 std::cout << "Filling_Approx Error 3d = " <<
1120 App.MaxError() << std::endl;
1122 Surf = App.Surface();
1123 Tol3d = App.MaxError();
1128 TopLoc_Location Loc;
1129 Handle(Geom_Curve) C3d;
1130 B.UpdateEdge(E1, C1, Surf, Loc, /*Tol3d*/Precision::Confusion());
1131 B.UpdateEdge(E2, C2, Surf, Loc, /*Tol3d*/Precision::Confusion());
1133 if (E3.IsSame(E4)) {
1136 C3d = Surf->VIso(f1);
1137 E3 = BuildEdge(C3d, C3, Surf, Vf, V1, 0, Angle, /*Tol3d*/Precision::Confusion());
1141 BRepAdaptor_Curve aCurve(E3);
1142 Standard_Real AngleOld = aCurve.LastParameter();
1143 if (Angle > AngleOld)
1145 B.Range( E3, 0, Angle );
1146 TopoDS_Vertex V (TopExp::LastVertex(E3));
1147 Handle(BRep_TVertex)& TVlast = *((Handle(BRep_TVertex)*) &V.TShape());
1148 TVlast->Tolerance( Precision::Confusion() );
1152 B.UpdateEdge(E3, C3, C4, Surf, Loc, /*Tol3d*/Precision::Confusion());
1159 C3d = Surf->VIso(f1);
1160 E3 = BuildEdge(C3d, C3, Surf, Vf, V1, 0, Angle, /*Tol3d*/Precision::Confusion());
1164 BRepAdaptor_Curve aCurve(E3);
1165 Standard_Real AngleOld = aCurve.LastParameter();
1166 if (Angle > AngleOld)
1168 B.Range( E3, 0, Angle );
1169 TopoDS_Vertex V(TopExp::LastVertex(E3));
1170 Handle(BRep_TVertex)& TVlast = *((Handle(BRep_TVertex)*) &V.TShape());
1171 TVlast->Tolerance( Precision::Confusion() );
1174 B.UpdateEdge(E3, C3, Surf, Loc, /*Tol3d*/Precision::Confusion());
1179 C3d = Surf->VIso(l1);
1180 E4 = BuildEdge(C3d, C4, Surf, Vl, V2, 0, Angle, /*Tol3d*/Precision::Confusion());
1184 BRepAdaptor_Curve aCurve(E4);
1185 Standard_Real AngleOld = aCurve.LastParameter();
1186 if (Angle > AngleOld)
1188 B.Range( E4, 0, Angle );
1189 TopoDS_Vertex V (TopExp::LastVertex(E4));
1190 Handle(BRep_TVertex)& TVlast = *((Handle(BRep_TVertex)*)&V.TShape());
1191 TVlast->Tolerance( Precision::Confusion() );
1194 B.UpdateEdge(E4, C4, Surf, Loc, /*Tol3d*/Precision::Confusion());
1199 BuildFace(Surf,E1, E3, E2, E4, EEmap,
1200 Standard_False, Standard_False,
1203 // Set the continuities.
1204 B.Continuity(E1, TopoDS::Face(F1), Result, GeomAbs_G1);
1205 B.Continuity(E2, TopoDS::Face(F2), Result, GeomAbs_G1);
1207 // Render the calculated borders.
1208 // if (!BT.Degenerated(E3))
1209 if (!BRep_Tool::Degenerated(E3))
1212 B.MakeEdge(Aux1); //Nullify
1214 // if (!BT.Degenerated(E4))
1215 if (!BRep_Tool::Degenerated(E4))
1220 // Set the orientation
1222 // Provide correct normals computation
1223 // (the normal will be computed not in
1224 // singularity point definitely).
1225 Angle = RealFirst();
1226 for (Standard_Integer i = 0; i < 3; i++)
1228 gp_Vec D1U, D1V, N1, N2;
1229 C1->D0(aPrm[i], P2d);
1230 Surf->D1(P2d.X(), P2d.Y(), P, D1U, D1V);
1233 if (N1.SquareMagnitude() < Precision::SquareConfusion())
1236 // C1 = BT.CurveOnSurface(E1, TopoDS::Face(F1), f2, l2);
1237 C1 = BRep_Tool::CurveOnSurface(E1, TopoDS::Face(F1), f2, l2);
1238 C1->D0(aPrm[i], P2d);
1239 Handle(BRepAdaptor_Surface) AS = new BRepAdaptor_Surface(TopoDS::Face(F1));
1240 AS->D1(P2d.X(), P2d.Y(), P, D1U, D1V);
1243 if (N2.SquareMagnitude() < Precision::SquareConfusion())
1246 Angle = N1.Angle(N2);
1251 if (Angle == RealFirst())
1252 return Standard_False;
1254 if ( (F1.Orientation() == TopAbs_REVERSED) ^ (Angle>M_PI/2))
1255 Result.Orientation(TopAbs_REVERSED);
1256 else Result.Orientation(TopAbs_FORWARD);
1258 if (ToReverseResult)
1262 if (Affich) DBRep::Set("BoucheTrou", Result);
1265 return Standard_True;
1268 //=======================================================================
1269 //function : Substitute
1271 //=======================================================================
1272 static void Substitute(BRepTools_Substitution& aSubstitute,
1273 const TopoDS_Edge& Old,
1274 const TopoDS_Edge& New)
1276 TopTools_ListOfShape listShape;
1278 TopoDS_Vertex OldV1, OldV2, NewV1, NewV2;
1279 TopExp::Vertices( Old, OldV1, OldV2 );
1280 TopExp::Vertices( New, NewV1, NewV2 );
1282 if (!aSubstitute.IsCopied( OldV1 ))
1284 listShape.Append( NewV1.Oriented(TopAbs_FORWARD) );
1285 aSubstitute.Substitute( OldV1, listShape );
1288 if (!aSubstitute.IsCopied( OldV2 ))
1290 listShape.Append( NewV2.Oriented(TopAbs_FORWARD) );
1291 aSubstitute.Substitute( OldV2, listShape );
1294 if (!aSubstitute.IsCopied( Old ))
1296 listShape.Append( New.Oriented(TopAbs_FORWARD) );
1297 aSubstitute.Substitute( Old, listShape );
1301 //=======================================================================
1302 //Function : SetCommonEdgeInFace
1303 //Purpose : Replace an edge of the face by the corresponding edge from
1305 //=======================================================================
1307 static void SetCommonEdgeInFace(BRepTools_Substitution& aSubstitute,
1308 const TopoDS_Shape& Face,
1309 const TopoDS_Shape& Edge)
1314 Standard_Boolean done = Standard_False;
1315 // Class BRep_Tool without fields and without Constructor :
1318 TopExp_Explorer Exp(Face, TopAbs_EDGE);
1319 Handle(Geom_Curve) Cref, C;
1320 TopLoc_Location Lref, L;
1321 // Cref = BT.Curve(TopoDS::Edge(Edge), Lref, f, l);
1322 const TopoDS_Edge& NewEdge = TopoDS::Edge(Edge);
1323 Cref = BRep_Tool::Curve( NewEdge, Lref, f, l );
1325 for ( ; Exp.More() && !done; Exp.Next()) {
1326 // C = BT.Curve(TopoDS::Edge(Exp.Current()), L, f, l);
1327 const TopoDS_Edge& OldEdge = TopoDS::Edge(Exp.Current());
1328 C = BRep_Tool::Curve(OldEdge, L, f, l);
1329 if ((Cref==C) && (Lref == L)) {
1330 done = Standard_True;
1331 Substitute( aSubstitute, OldEdge, NewEdge );
1335 if (!done) std::cout << "Substitution of Edge failed" << std::endl;
1340 //=======================================================================
1341 //Fonction : KeepEdge
1342 //Objet : Find edges of the face supported by the same Curve.
1343 //=======================================================================
1344 static void KeepEdge(const TopoDS_Shape& Face,
1345 const TopoDS_Shape& Edge,
1346 TopTools_ListOfShape& List)
1349 // Class BRep_Tool without fields and without Constructor :
1352 TopExp_Explorer Exp(Face, TopAbs_EDGE);
1353 Handle(Geom_Curve) Cref, C;
1354 TopLoc_Location Lref, L;
1355 // Cref = BT.Curve(TopoDS::Edge(Edge), Lref, f, l);
1356 Cref = BRep_Tool::Curve(TopoDS::Edge(Edge), Lref, f, l);
1358 for ( ; Exp.More(); Exp.Next()) {
1359 // C = BT.Curve(TopoDS::Edge(Exp.Current()), L, f, l);
1360 C = BRep_Tool::Curve(TopoDS::Edge(Exp.Current()), L, f, l);
1361 if ((Cref==C) && (Lref == L)) {
1362 List.Append(Exp.Current());
1367 //=======================================================================
1369 //Objet : Construct a vertex via an iso
1370 //=======================================================================
1371 static void BuildVertex(const Handle(Geom_Curve)& Iso,
1372 const Standard_Boolean isfirst,
1373 const Standard_Real First,
1374 const Standard_Real Last,
1375 TopoDS_Shape& Vertex)
1380 if (isfirst) val = First;
1382 B.MakeVertex(TopoDS::Vertex(Vertex),
1384 Precision::Confusion());
1387 //=======================================================================
1389 //Objet : Construct an empty edge
1390 //=======================================================================
1391 static TopoDS_Edge NullEdge(TopoDS_Shape& Vertex)
1396 Vertex.Orientation(TopAbs_FORWARD);
1398 B.Add(E, Vertex.Reversed());
1399 B.Degenerated(E, Standard_True);
1404 //=======================================================================
1406 //Objet : Construct an edge via an iso
1407 //=======================================================================
1408 static TopoDS_Edge BuildEdge(const Handle(Geom_Surface)& S,
1409 const Standard_Boolean isUiso,
1410 const Standard_Real ValIso,
1411 const TopoDS_Shape& VFirst,
1412 const TopoDS_Shape& VLast,
1413 const Standard_Real Tol)
1417 Handle(Geom_Curve) Iso;
1418 Standard_Boolean sing = Standard_False;
1420 Iso = S->UIso(ValIso);
1423 Iso = S->VIso(ValIso);
1426 if (VFirst.IsSame(VLast)) { // Singular case ?
1428 // Class BRep_Tool without fields and without Constructor :
1430 const TopoDS_Vertex& V = TopoDS::Vertex(VFirst);
1431 // Standard_Real tol = BT.Tolerance(V);
1432 Standard_Real tol = BRep_Tool::Tolerance(V);
1433 if (Tol > tol) tol = Tol;
1434 Iso->D0((Iso->FirstParameter()+Iso->LastParameter())/2, P);
1435 // if (P.Distance(BT.Pnt(V)) < tol) {
1436 if (P.Distance(BRep_Tool::Pnt(V)) < tol) {
1437 GeomAdaptor_Curve AC(Iso);
1438 sing = GCPnts_AbscissaPoint::Length(AC, tol/4) < tol;
1443 if (sing) { // Singular case
1448 // B.UpdateEdge(E, Iso, Precision::Confusion());
1449 B.Degenerated(E, Standard_True);
1453 // Construction Via 3d
1455 // Iso = S->UIso(ValIso);
1457 Standard_Real p1, p2, p11, p12, p21, p22;
1458 Standard_Boolean fwd = Standard_False;
1459 p1 = Iso->FirstParameter();
1460 p2 = Iso->LastParameter();
1461 P1 = Iso->Value(p1);
1462 P2 = Iso->Value(p2);
1464 Standard_Real t1 = BRep_Tool::Tolerance(TopoDS::Vertex(VFirst));
1465 Standard_Real t2 = BRep_Tool::Tolerance(TopoDS::Vertex(VLast));
1469 p11 = P1.Distance(BRep_Tool::Pnt(TopoDS::Vertex(VFirst)));
1470 p22 = P2.Distance(BRep_Tool::Pnt(TopoDS::Vertex(VLast)));
1471 p12 = P1.Distance(BRep_Tool::Pnt(TopoDS::Vertex(VLast)));
1472 p21 = P2.Distance(BRep_Tool::Pnt(TopoDS::Vertex(VFirst)));
1474 if(p11 < p12 && p22 < p21) fwd = Standard_True;
1476 if(fwd) { //OCC500(apo)
1477 if (p11 >= t1) BB.UpdateVertex(TopoDS::Vertex(VFirst), 1.01*p11);
1478 if (p22 >= t2) BB.UpdateVertex(TopoDS::Vertex(VLast), 1.01*p22);
1481 // Iso = S->VIso(ValIso);
1482 if (p12 >= t2) BB.UpdateVertex(TopoDS::Vertex(VLast), 1.01*p12);
1483 if (p21 >= t1) BB.UpdateVertex(TopoDS::Vertex(VFirst), 1.01*p21);
1486 BRepLib_MakeEdge MkE;
1489 // TopoDS::Vertex(VFirst),
1490 // TopoDS::Vertex(VLast),
1491 // Iso->FirstParameter(),
1492 // Iso->LastParameter());
1495 TopoDS::Vertex(VFirst),
1496 TopoDS::Vertex(VLast),
1497 Iso->FirstParameter(),
1498 Iso->LastParameter());
1501 TopoDS::Vertex(VLast),
1502 TopoDS::Vertex(VFirst),
1503 Iso->FirstParameter(),
1504 Iso->LastParameter());
1506 // if (!MkE.IsDone()) { // Il faut peut etre permuter les Vertex
1508 // TopoDS::Vertex(VLast),
1509 // TopoDS::Vertex(VFirst),
1510 // Iso->FirstParameter(),
1511 // Iso->LastParameter());
1514 if (!MkE.IsDone()) { // Erreur de construction !!
1517 sprintf(name,"firstvertex_error");
1518 DBRep::Set(name, VFirst);
1519 sprintf(name,"lastvertex_error");
1520 DBRep::Set(name, VLast);
1521 sprintf(name,"curve3d_error");
1523 DrawTrSurf::Set(Temp,Iso);
1524 // DrawTrSurf::Set(name,Iso);
1526 throw Standard_ConstructionError("BRepFill_Sweep::BuildEdge");
1533 Handle(Geom2d_Line) L;
1534 TopLoc_Location Loc;
1535 Standard_Real Umin, Umax, Vmin, Vmax;
1536 S->Bounds(Umin, Umax, Vmin, Vmax);
1538 //gp_Pnt2d P(ValIso, 0);
1539 gp_Pnt2d P( ValIso, Vmin - Iso->FirstParameter() );
1541 L = new (Geom2d_Line) (P, V);
1544 //gp_Pnt2d P(0., ValIso);
1545 gp_Pnt2d P( Umin -Iso->FirstParameter() , ValIso );
1547 L = new (Geom2d_Line) (P, V);
1550 B.UpdateEdge(E, L, S, Loc, Precision::Confusion());
1551 if (sing) B.Range(E, S, Loc,
1552 Iso->FirstParameter(),
1553 Iso->LastParameter());
1555 Standard_Real MaxTol = 1.e-4;
1556 Standard_Real theTol;
1557 GeomAdaptor_Curve GAiso(Iso);
1558 Handle(GeomAdaptor_Curve) GAHiso = new GeomAdaptor_Curve(GAiso);
1559 GeomAdaptor_Surface GAsurf(S);
1560 Handle(GeomAdaptor_Surface) GAHsurf = new GeomAdaptor_Surface(GAsurf);
1561 CheckSameParameter( GAHiso, L, GAHsurf, MaxTol, theTol);
1562 B.UpdateEdge(E, theTol);
1567 //=======================================================================
1569 //Objet : Complete an edge via an iso
1570 //=======================================================================
1571 static void UpdateEdge(TopoDS_Edge& E,
1572 const Handle(Geom_Surface)& S,
1573 const Standard_Boolean isUiso,
1574 const Standard_Real ValIso)
1577 Handle(Geom2d_Line) L;
1578 Handle(Geom2d_Curve) PCurve, CL;
1579 TopLoc_Location Loc;
1580 Standard_Real UFirst, ULast, VFirst, VLast, F2d, L2d;
1581 S->Bounds( UFirst, ULast, VFirst, VLast);
1583 Standard_Boolean sing = Standard_False;
1584 Handle(Geom_Curve) Iso;
1586 Iso = S->UIso(ValIso);
1589 Iso = S->VIso(ValIso);
1592 TopoDS_Vertex Vf, Vl;
1593 TopExp::Vertices(E, Vf, Vl);
1594 if (Vf.IsSame(Vl)) { // Singular case ?
1596 Standard_Real tol = BRep_Tool::Tolerance(Vf);
1597 Iso->D0((Iso->FirstParameter()+Iso->LastParameter())/2, Pmid);
1598 if (Pmid.Distance(BRep_Tool::Pnt(Vf)) < tol) {
1599 GeomAdaptor_Curve AC(Iso);
1600 sing = GCPnts_AbscissaPoint::Length(AC, tol/4) < tol;
1605 gp_Pnt2d P(ValIso, 0);
1607 L = new (Geom2d_Line) (P, V);
1612 gp_Pnt2d P(0., ValIso);
1614 L = new (Geom2d_Line) (P, V);
1618 CL = new (Geom2d_TrimmedCurve) (L, F2d, L2d);
1620 // Control direction & Range
1621 Standard_Real R, First, Last, Tol=1.e-4;
1622 Standard_Boolean reverse = Standard_False;
1625 // Class BRep_Tool without fields and without Constructor :
1629 // BT.Range(E, First, Last);
1630 BRep_Tool::Range(E, First, Last);
1632 if (!Vf.IsSame(Vl)) {
1633 // Test distances between "FirstPoint" and "Vertex"
1634 P2d = CL->Value(F2d);
1635 POnS = S->Value(P2d.X(), P2d.Y());
1636 // reverse = POnS.Distance(BT.Pnt(Vl)) < POnS.Distance(BT.Pnt(Vf));
1637 reverse = POnS.Distance(BRep_Tool::Pnt(Vl)) < POnS.Distance(BRep_Tool::Pnt(Vf));
1640 // Test angle between "First Tangente"
1642 gp_Vec V3d, du, dv, dC3d;
1643 BRepAdaptor_Curve C3d(E);
1645 C3d.D1(First, POnS, dC3d);
1646 CL->D1(F2d, P2d, V2d);
1647 S->D1(P2d.X(), P2d.Y(), POnS, du, dv);
1648 V3d.SetLinearForm(V2d.X(), du, V2d.Y(), dv);
1649 reverse = ( dC3d.Angle(V3d) > Tol);
1651 if (reverse ) { // Return curve 2d
1652 CL = new (Geom2d_TrimmedCurve)(L, F2d, L2d);
1654 F2d = CL->FirstParameter();
1655 L2d = CL->LastParameter();
1660 Handle(Geom_Curve) NullCurve;
1661 B.UpdateEdge(E, NullCurve, 0.);
1662 B.Degenerated(E, Standard_True);
1663 B.Range(E, F2d, L2d);
1668 if (First != F2d || Last != L2d) {
1669 Handle(Geom2d_Curve) C2d;
1670 GeomLib::SameRange(Precision::PConfusion(), CL,
1671 F2d, L2d, First, Last,
1673 CL = new (Geom2d_TrimmedCurve)(C2d, First, Last);
1676 // Update des Vertex
1680 P2d = CL->Value(First);
1681 POnS = S->Value(P2d.X(), P2d.Y());
1682 V = TopExp::FirstVertex(E);
1683 // R = POnS.Distance(BT.Pnt(V));
1684 R = POnS.Distance(BRep_Tool::Pnt(V));
1685 B.UpdateVertex(V, R);
1687 P2d = CL->Value(Last);
1688 POnS = S->Value(P2d.X(), P2d.Y());
1689 V = TopExp::LastVertex(E);
1690 // R = POnS.Distance(BT.Pnt(V));
1691 R = POnS.Distance(BRep_Tool::Pnt(V));
1692 B.UpdateVertex(V, R);
1695 if (!sing && SameParameter(E, CL, S, Tol, R)) {
1699 PCurve = Couture(E, S, Loc);
1700 if (PCurve.IsNull())
1701 B.UpdateEdge(E, CL, S, Loc, Precision::Confusion());
1702 else { // Sewing edge
1705 if (e.Orientation() == TopAbs_REVERSED)
1706 B.UpdateEdge(E, CL, PCurve, S, Loc, Precision::Confusion());
1708 B.UpdateEdge(E, PCurve, CL, S, Loc, Precision::Confusion());
1711 // Attention to case not SameRange on its shapes (PRO13551)
1712 // if (!BT.SameRange(E)) B.Range(E, S, Loc, First, Last);
1713 if (!BRep_Tool::SameRange(E)) B.Range(E, S, Loc, First, Last);
1716 //=======================================================================
1717 // Object : Check if a surface is degenerated
1718 //=======================================================================
1719 static Standard_Boolean IsDegen(const Handle(Geom_Surface)& S,
1720 const Standard_Real Tol)
1722 Standard_Integer Nb = 5;
1723 Standard_Boolean B = Standard_True;
1724 Standard_Real Umax, Umin, Vmax, Vmin, t, dt, l;
1725 Standard_Integer ii;
1726 Handle(Geom_Curve) Iso;
1728 GCPnts_AbscissaPoint GC;
1730 S->Bounds(Umin, Umax, Vmin, Vmax);
1732 // Check the length of Iso-U
1733 t = (Umin + Umax)/2;
1735 S->D0(t, (Vmin+Vmax)/2, P2);
1737 B = ((P1.Distance(P2) + P2.Distance(P3)) < Tol);
1739 for (ii=1, dt = (Umax-Umin)/(Nb+1); B && (ii<=Nb); ii++) {
1742 GeomAdaptor_Curve AC(Iso);
1743 l = GC.Length(AC, Tol/4);
1747 if (B) return Standard_True;
1749 // Check the length of Iso-V
1750 t = (Vmin + Vmax)/2;
1752 S->D0((Umin+Umax)/2, t, P2);
1754 B = ((P1.Distance(P2) + P2.Distance(P3)) < Tol);
1757 for (ii=1, dt = (Vmax-Vmin)/(Nb+1); B && (ii<=Nb); ii++) {
1760 GeomAdaptor_Curve AC(Iso);
1761 l = GC.Length(AC, Tol/4);
1768 static void ReverseEdgeInFirstOrLastWire(TopoDS_Shape& theWire,
1769 const TopoDS_Shape& theEdge)
1771 TopoDS_Shape EdgeToReverse;
1772 TopoDS_Iterator itw(theWire);
1774 for (; itw.More(); itw.Next())
1776 const TopoDS_Shape& anEdge = itw.Value();
1777 if (anEdge.IsSame(theEdge))
1779 EdgeToReverse = anEdge;
1784 if (!EdgeToReverse.IsNull())
1787 theWire.Free(Standard_True);
1788 BB.Remove(theWire, EdgeToReverse);
1789 EdgeToReverse.Reverse();
1790 BB.Add(theWire, EdgeToReverse);
1794 static void ReverseModifiedEdges(TopoDS_Wire& theWire,
1795 const TopTools_MapOfShape& theEmap)
1797 if (theEmap.IsEmpty())
1800 TopoDS_Iterator itw(theWire);
1803 TopTools_ListOfShape Ledges;
1804 for (; itw.More(); itw.Next())
1805 Ledges.Append(itw.Value());
1807 theWire.Free(Standard_True);
1808 TopTools_ListIteratorOfListOfShape itl(Ledges);
1809 for (; itl.More(); itl.Next())
1810 BB.Remove(theWire, itl.Value());
1812 for (itl.Initialize(Ledges); itl.More(); itl.Next())
1814 TopoDS_Shape anEdge = itl.Value();
1815 if (theEmap.Contains(anEdge))
1817 BB.Add(theWire, anEdge);
1822 //=======================================================================
1823 //function : Constructeur
1825 //======================================================================
1826 BRepFill_Sweep::BRepFill_Sweep(const Handle(BRepFill_SectionLaw)& Section,
1827 const Handle(BRepFill_LocationLaw)& Location,
1828 const Standard_Boolean WithKPart) :
1829 isDone(Standard_False),
1835 SetTolerance(1.e-4);
1836 SetAngularControl();
1839 myApproxStyle = GeomFill_Location;
1840 myContinuity = GeomAbs_C2;
1843 myForceApproxC1 = Standard_False;
1846 //=======================================================================
1847 //function : SetBounds
1848 //purpose : Define start and end shapes
1849 //======================================================================
1850 void BRepFill_Sweep::SetBounds(const TopoDS_Wire& First,
1851 const TopoDS_Wire& Last)
1856 // It is necessary to check the SameRange on its (PRO13551)
1858 Standard_Boolean issame = Standard_True;
1861 BRepTools_WireExplorer wexp;
1862 if (!FirstShape.IsNull()) {
1863 for (wexp.Init(FirstShape); wexp.More(); wexp.Next()) {
1864 if (!BRepLib::CheckSameRange(wexp.Current())) {
1865 B.SameRange(wexp.Current(), Standard_False);
1866 B.SameParameter(wexp.Current(), Standard_False);
1868 issame = Standard_False;
1874 if (!LastShape.IsNull()) {
1875 for (wexp.Init(LastShape); wexp.More(); wexp.Next()) {
1876 if (!BRepLib::CheckSameRange(wexp.Current())) {
1877 B.SameRange(wexp.Current(), Standard_False);
1878 B.SameParameter(wexp.Current(), Standard_False);
1880 issame = Standard_False;
1888 std::cout<<"Sweep Warning : Edge not SameRange in the limits"<<std::endl;
1892 //=======================================================================
1893 //function : SetTolerance
1895 //======================================================================
1896 void BRepFill_Sweep::SetTolerance(const Standard_Real Tol3d,
1897 const Standard_Real BoundTol,
1898 const Standard_Real Tol2d,
1899 const Standard_Real TolAngular)
1902 myBoundTol = BoundTol;
1904 myTolAngular = TolAngular;
1906 //=======================================================================
1907 //function : SetAngularControl
1909 //======================================================================
1910 void BRepFill_Sweep::SetAngularControl(const Standard_Real MinAngle,
1911 const Standard_Real MaxAngle)
1913 myAngMin = Max (MinAngle, Precision::Angular());
1914 myAngMax = Min (MaxAngle, 6.28);
1917 //=======================================================================
1918 //function : SetForceApproxC1
1919 //purpose : Set the flag that indicates attempt to approximate
1920 // a C1-continuous surface if a swept surface proved
1922 //=======================================================================
1923 void BRepFill_Sweep::SetForceApproxC1(const Standard_Boolean ForceApproxC1)
1925 myForceApproxC1 = ForceApproxC1;
1928 ///=======================================================================
1929 //function : CorrectApproxParameters
1931 //=======================================================================
1932 Standard_Boolean BRepFill_Sweep::CorrectApproxParameters()
1934 TopoDS_Wire thePath = myLoc->Wire();
1935 GeomAbs_Shape NewCont = myContinuity;
1936 Standard_Integer NewSegmax = mySegmax;
1938 TopoDS_Iterator iter(thePath);
1939 for (; iter.More(); iter.Next())
1941 TopoDS_Edge anEdge = TopoDS::Edge(iter.Value());
1942 BRepAdaptor_Curve aBAcurve(anEdge);
1943 GeomAbs_Shape aContinuity = aBAcurve.Continuity();
1944 Standard_Integer aNbInterv = aBAcurve.NbIntervals(GeomAbs_CN);
1945 if (aContinuity < NewCont)
1946 NewCont = aContinuity;
1947 if (aNbInterv > NewSegmax)
1948 NewSegmax = aNbInterv;
1951 Standard_Boolean Corrected = Standard_False;
1952 if (NewCont != myContinuity || NewSegmax != mySegmax)
1953 Corrected = Standard_True;
1954 myContinuity = NewCont;
1955 mySegmax = NewSegmax;
1959 //=======================================================================
1960 //function : BuildWire
1961 //purpose : Construit a wire by sweeping
1962 //======================================================================
1963 Standard_Boolean BRepFill_Sweep::
1964 BuildWire(const BRepFill_TransitionStyle /*Transition*/)
1966 Standard_Integer ipath, isec = 1;
1970 // Class BRep_Tool without fields and without Constructor :
1972 Standard_Integer NbPath = myLoc->NbLaw();
1973 Standard_Boolean vclose;
1974 vclose = (myLoc->IsClosed() && (myLoc->IsG1(0, myTol3d)>= 0));
1976 Handle(Geom_Surface) S;
1977 Handle(Geom_Curve) Iso;
1978 Standard_Real val, bid, First, Last, Tol;
1984 // (1) Construction of all curves
1986 // (1.1) Construction of Tables
1987 myFaces = new (TopTools_HArray2OfShape) (1, 1, 1, NbPath);
1988 myUEdges = new (TopTools_HArray2OfShape) (1, 2, 1, NbPath);
1989 myVEdges = new (TopTools_HArray2OfShape) (1, 1, 1, NbPath+1);
1991 // (1.2) Calculate curves / vertex / edge
1992 for (ipath=1; ipath <=NbPath; ipath++) {
1993 // Curve by iso value
1994 GeomFill_Sweep Sweep(myLoc->Law(ipath), KPart);
1995 Sweep.SetTolerance(myTol3d, myBoundTol, myTol2d, myTolAngular);
1996 Sweep.SetForceApproxC1(myForceApproxC1);
1997 Sweep.Build(mySec->Law(isec), myApproxStyle, myContinuity, myDegmax, mySegmax);
1998 if (!Sweep.IsDone())
1999 return Standard_False;
2000 S = Sweep.Surface();
2001 if (Sweep.ExchangeUV()) {
2002 if (Sweep.UReversed()) S->Bounds(First, Last, bid, val);
2003 else S->Bounds(First, Last, val, bid);
2007 if (Sweep.UReversed()) S->Bounds(bid, val, First, Last);
2008 else S->Bounds(val, bid, First, Last);
2011 // Vertex by position
2013 BuildVertex(Iso, Standard_False, First, Last,
2014 myVEdges->ChangeValue(1, ipath+1));
2017 TopoDS_Vertex& V = TopoDS::Vertex(myVEdges->ChangeValue(1, 1));
2018 myVEdges->SetValue(1, ipath+1, V);
2020 // Tol = P1.Distance(BT.Pnt(V));
2021 Tol = P1.Distance(BRep_Tool::Pnt(V));
2022 B.UpdateVertex(V, Tol);
2025 if (!LastShape.IsNull()) myVEdges->SetValue(1, NbPath, FirstShape);
2026 else BuildVertex(Iso, Standard_False, First, Last,
2027 myVEdges->ChangeValue(1, NbPath+1));
2033 TopoDS_Vertex& V = TopoDS::Vertex(myVEdges->ChangeValue(1, ipath));
2034 // Tol = P1.Distance(BT.Pnt(V));
2035 Tol = P1.Distance(BRep_Tool::Pnt(V));
2036 B.UpdateVertex(V, Tol);
2039 if (!FirstShape.IsNull()) myVEdges->SetValue(1,1, FirstShape);
2040 else BuildVertex(Iso, Standard_True, First, Last,
2041 myVEdges->ChangeValue(1, 1));
2044 // Construction of the edge
2045 BRepLib_MakeEdge MkE;
2047 TopoDS::Vertex(myVEdges->Value(1, ipath)),
2048 TopoDS::Vertex(myVEdges->Value(1, ipath+1)),
2049 Iso->FirstParameter(),
2050 Iso->LastParameter());
2051 if (!MkE.IsDone()) { // Error of construction !!
2054 sprintf(name,"firstvertex_error");
2055 DBRep::Set(name, myVEdges->Value(1, ipath));
2056 sprintf(name,"lastvertex_error");
2057 DBRep::Set(name, myVEdges->Value(1, ipath+1));
2058 sprintf(name,"curve3d_error");
2060 DrawTrSurf::Set(Temp,Iso);
2061 // DrawTrSurf::Set(name,Iso);
2062 throw Standard_ConstructionError("BRepFill_Sweep::BuildEdge");
2064 return Standard_False;
2069 sprintf(name,"Surf_%d", ipath);
2071 DrawTrSurf::Set(Temp, S);
2072 // DrawTrSurf::Set(name, S);
2073 sprintf(name,"Edge_%d", ipath);
2074 DBRep::Set(name, E);
2077 B.UpdateEdge(E, Sweep.ErrorOnSurface());
2079 myFaces->SetValue(1, ipath, E);
2082 return Standard_True;
2085 //=======================================================================
2086 //function : BuildShell
2087 //purpose : Construct a Shell by sweeping
2088 //======================================================================
2089 Standard_Boolean BRepFill_Sweep::
2090 BuildShell(const BRepFill_TransitionStyle /*Transition*/,
2091 const Standard_Integer IFirst,
2092 const Standard_Integer ILast,
2093 TopTools_MapOfShape& ReversedEdges,
2094 BRepFill_DataMapOfShapeHArray2OfShape& Tapes,
2095 BRepFill_DataMapOfShapeHArray2OfShape& Rails,
2096 const Standard_Real ExtendFirst,
2097 const Standard_Real ExtendLast)
2099 Standard_Integer ipath, isec, IPath;
2104 Standard_Integer NbPath = ILast - IFirst;
2105 Standard_Integer NbLaw = mySec->NbLaw();
2106 Standard_Boolean uclose, vclose, global_vclose, constSection, hasdegen = Standard_False;
2107 constSection = mySec->IsConstant();
2108 uclose = mySec->IsUClosed();
2109 global_vclose = (myLoc->IsClosed()) && (myLoc->IsG1(0, myTol3d)>= 0);
2110 vclose = global_vclose && (mySec->IsVClosed()) && (NbPath == myLoc->NbLaw());
2113 // (1) Construction of all surfaces
2115 // (1.1) Construction of Tables
2117 TColStd_Array2OfBoolean ExchUV (1, NbLaw, 1, NbPath);
2118 TColStd_Array2OfBoolean UReverse (1, NbLaw, 1, NbPath);
2119 TColStd_Array2OfBoolean Degenerated(1, NbLaw, 1, NbPath);
2120 Degenerated.Init (false);
2121 // No VReverse for the moment...
2122 TColStd_Array2OfReal TabErr(1, NbLaw , 1, NbPath);
2123 TColGeom_Array2OfSurface TabS(1, NbLaw , 1, NbPath);
2125 TopTools_Array2OfShape UEdge(1, NbLaw+1, 1, NbPath);
2126 TopTools_Array2OfShape VEdge(1, NbLaw , 1, NbPath+1);
2127 TopTools_Array2OfShape Vertex(1,NbLaw+1, 1, NbPath+1);
2129 TopoDS_Vertex VNULL;
2133 TopTools_Array1OfShape SecVertex(1, NbLaw+1);
2134 TColStd_Array1OfReal VError(1, NbLaw+1);
2135 TColStd_Array1OfReal Vi(1, NbPath+1);
2137 //Initialization of management of parametric intervals
2138 //(Case of evolutionary sections)
2139 Standard_Real Length, SecDom, SecDeb;
2140 myLoc->CurvilinearBounds(myLoc->NbLaw(), SecDom, Length);
2141 mySec->Law(1)->GetDomain(SecDeb, SecDom);
2144 Standard_Real Lf, Ll;
2145 myLoc->CurvilinearBounds(IFirst-1, Lf, Ll);
2146 Vi(1) = SecDeb + (Ll/Length)*SecDom;
2151 // Error a priori on vertices
2153 for (isec=1; isec<=NbLaw+1; isec++) {
2154 VError(isec) = mySec->VertexTol(isec-1, 0.);
2155 SecVertex(isec) = mySec->Vertex(isec, 0.);
2160 // (1.2) Calculate surfaces
2161 for (ipath=1, IPath=IFirst; ipath <=NbPath; ipath++, IPath++) {
2163 GeomFill_Sweep Sweep(myLoc->Law(IPath), KPart);
2164 Sweep.SetTolerance(myTol3d, myBoundTol, myTol2d, myTolAngular);
2165 Sweep.SetForceApproxC1(myForceApproxC1);
2167 // Case of evolutionary section, definition of parametric correspondence
2168 if (!constSection) {
2169 Standard_Real lf, ll, Lf, Ll;
2170 myLoc->Law(IPath)->GetDomain(lf, ll);
2171 myLoc->CurvilinearBounds(IPath, Lf, Ll);
2172 Vi(ipath+1) = SecDeb + (Ll/Length)*SecDom;
2173 Sweep.SetDomain(lf, ll, Vi(ipath), Vi(ipath+1));
2175 else //section is constant
2177 Standard_Real lf, ll, Lf, Ll;
2178 myLoc->Law(IPath)->GetDomain(lf, ll);
2179 myLoc->CurvilinearBounds(IPath, Lf, Ll);
2180 Vi(ipath+1) = SecDeb + (Ll/Length)*SecDom;
2183 for(isec=1; isec<=NbLaw; isec++) {
2184 Sweep.Build(mySec->Law(isec), myApproxStyle, myContinuity, myDegmax, mySegmax);
2185 if (!Sweep.IsDone())
2186 return Standard_False;
2187 TabS(isec,ipath) = Sweep.Surface();
2188 TabErr(isec,ipath) = Sweep.ErrorOnSurface();
2189 ExchUV(isec, ipath) = Sweep.ExchangeUV();
2190 UReverse(isec, ipath) = Sweep.UReversed();
2191 if (Sweep.ErrorOnSurface()>Error) Error = Sweep.ErrorOnSurface();
2193 if ((ipath==1)&&(ExtendFirst>0)) {
2194 Handle(Geom_BoundedSurface) BndS;
2195 BndS = Handle(Geom_BoundedSurface)::DownCast(TabS(isec,ipath));
2196 GeomLib::ExtendSurfByLength(BndS, ExtendFirst, 1,
2197 Sweep.ExchangeUV(), Standard_False);
2198 TabS(isec,ipath) = BndS;
2200 if ((ipath==NbPath)&&(ExtendLast>0)){
2201 Handle(Geom_BoundedSurface) BndS;
2202 BndS = Handle(Geom_BoundedSurface)::DownCast(TabS(isec,ipath));
2203 GeomLib::ExtendSurfByLength(BndS, ExtendLast, 1,
2204 Sweep.ExchangeUV(), Standard_True);
2205 TabS(isec,ipath) = BndS;
2210 sprintf(name,"Surf_%d_%d", isec, IPath);
2212 DrawTrSurf::Set(Temp, TabS(isec,ipath));
2218 // (2) Construction of Edges
2219 Standard_Real UFirst, ULast, VFirst, VLast;
2220 Standard_Boolean exuv, singu, singv;
2221 Handle(Geom_Surface) S;
2223 //Correct <FirstShape> and <LastShape>: reverse modified edges
2224 ReverseModifiedEdges(FirstShape, ReversedEdges);
2225 ReverseModifiedEdges(LastShape, ReversedEdges);
2227 // (2.0) return preexisting Edges and vertices
2229 TColStd_Array1OfBoolean IsBuilt(1, NbLaw);
2230 IsBuilt.Init(Standard_False);
2231 TopTools_Array1OfShape StartEdges(1, NbLaw);
2232 if (! FirstShape.IsNull() && (IFirst==1)) {
2233 mySec->Init(FirstShape);
2234 for (isec=1; isec<=NbLaw; isec++) {
2235 E = mySec->CurrentEdge();
2236 TopoDS_Vertex Vfirst, Vlast;
2237 TopExp::Vertices(E, Vfirst, Vlast);
2239 if (E.Orientation() == TopAbs_REVERSED)
2240 Vertex(isec+1, 1) = Vfirst; //TopExp::FirstVertex(E);
2242 Vertex(isec+1, 1) = Vlast; //TopExp::LastVertex(E);
2243 UpdateVertex(IFirst-1, isec+1,
2244 TabErr(isec, 1), Vi(1), Vertex(isec+1, 1));
2246 StartEdges(isec) = E;
2247 if (Tapes.IsBound(E))
2249 IsBuilt(isec) = Standard_True;
2251 //Initialize VEdge, UEdge, Vertex and myFaces
2253 for (j = 1; j <= NbPath+1; j++)
2255 VEdge(isec, j) = Tapes(E)->Value(1, j);
2256 VEdge(isec, j).Reverse(); //direction of round is reversed
2258 Standard_Integer ifirst = isec+1, ilast = isec; //direction of round is reversed
2259 for (j = 1; j <= NbPath; j++)
2260 UEdge(ifirst, j) = Tapes(E)->Value(2, j);
2261 for (j = 1; j <= NbPath; j++)
2262 UEdge(ilast, j) = Tapes(E)->Value(3, j);
2263 for (j = 1; j <= NbPath+1; j++)
2264 Vertex(ifirst, j) = Tapes(E)->Value(4, j);
2265 for (j = 1; j <= NbPath+1; j++)
2266 Vertex(ilast, j) = Tapes(E)->Value(5, j);
2267 for (j = 1; j <= NbPath; j++)
2268 myFaces->SetValue(isec, j, Tapes(E)->Value(6, j));
2270 if (uclose && isec == 1)
2272 for (j = 1; j <= NbPath; j++)
2273 UEdge(NbLaw+1, j) = UEdge(1, j);
2274 for (j = 1; j <= NbPath+1; j++)
2275 Vertex(NbLaw+1, j) = Vertex(1, j);
2277 if (uclose && isec == NbLaw)
2279 for (j = 1; j <= NbPath; j++)
2280 UEdge(1, j) = UEdge(NbLaw+1, j);
2281 for (j = 1; j <= NbPath+1; j++)
2282 Vertex(1, j) = Vertex(NbLaw+1, j);
2287 Handle(TopTools_HArray2OfShape) EmptyArray = new TopTools_HArray2OfShape(1, 6, 1, NbPath+1);
2288 Tapes.Bind(E, EmptyArray);
2290 if (Rails.IsBound(Vfirst))
2292 Standard_Integer ind = (E.Orientation() == TopAbs_REVERSED)? isec+1 : isec;
2293 for (j = 1; j <= NbPath; j++)
2294 UEdge(ind, j) = Rails(Vfirst)->Value(1, j);
2295 for (j = 1; j <= NbPath+1; j++)
2296 Vertex(ind, j) = Rails(Vfirst)->Value(2, j);
2298 if (Rails.IsBound(Vlast))
2300 Standard_Integer ind = (E.Orientation() == TopAbs_FORWARD)? isec+1 : isec;
2301 for (j = 1; j <= NbPath; j++)
2302 UEdge(ind, j) = Rails(Vlast)->Value(1, j);
2303 for (j = 1; j <= NbPath+1; j++)
2304 Vertex(ind, j) = Rails(Vlast)->Value(2, j);
2309 if (VEdge(1, 1).Orientation() == TopAbs_REVERSED)
2310 Vertex(1, 1) = TopExp::LastVertex(TopoDS::Edge(VEdge(1, 1)));
2312 Vertex(1, 1) = TopExp::FirstVertex(TopoDS::Edge(VEdge(1, 1)));
2313 UpdateVertex(IFirst-1, 1,
2314 TabErr(1, 1), Vi(1), Vertex(1, 1));
2317 Standard_Real u, v, aux;
2318 Standard_Boolean ureverse;
2319 for (isec=1; isec<=NbLaw+1; isec++) {
2323 ureverse = UReverse(NbLaw, 1);
2324 exuv = ExchUV(NbLaw, 1);
2328 ureverse = UReverse(isec, 1);
2329 exuv = ExchUV(isec, 1);
2331 S->Bounds(UFirst, ULast, VFirst, VLast);
2333 // Choice of parameters
2336 aux = VFirst; VFirst = VLast; VLast = aux;
2339 aux = UFirst; UFirst = ULast; ULast = aux;
2342 if (isec!= NbLaw+1) {
2357 // construction of vertices
2358 if (Vertex(isec, 1).IsNull())
2359 B.MakeVertex(TopoDS::Vertex(Vertex(isec, 1)),
2361 mySec->VertexTol(isec-1,Vi(1)));
2364 TopLoc_Location Identity;
2365 Vertex(isec, 1).Location(Identity);
2366 B.UpdateVertex(TopoDS::Vertex(Vertex(isec, 1)),
2368 mySec->VertexTol(isec-1,Vi(1)));
2370 } //end of for (isec=1; isec<=NbLaw+1; isec++)
2372 if (! LastShape.IsNull() && (ILast==myLoc->NbLaw()+1) ) {
2373 mySec->Init(LastShape);
2374 for (isec=1; isec<=NbLaw; isec++) {
2375 E = mySec->CurrentEdge();
2376 if (VEdge(isec, NbPath+1).IsNull())
2377 VEdge(isec, NbPath+1) = E;
2379 if (Vertex(isec+1, NbPath+1).IsNull())
2381 if (VEdge(isec, NbPath+1).Orientation() == TopAbs_REVERSED)
2382 Vertex(isec+1, NbPath+1) = TopExp::FirstVertex(TopoDS::Edge(VEdge(isec, NbPath+1)));
2384 Vertex(isec+1, NbPath+1) = TopExp::LastVertex(TopoDS::Edge(VEdge(isec, NbPath+1)));
2386 UpdateVertex(ILast-1, isec+1, TabErr(isec, NbPath),
2387 Vi(NbPath+1), Vertex(isec+1, NbPath+1));
2390 if (Vertex(1, NbPath+1).IsNull())
2392 if (VEdge(1, NbPath+1).Orientation() == TopAbs_REVERSED)
2393 Vertex(1, NbPath+1) = TopExp::LastVertex(TopoDS::Edge(VEdge(1, NbPath+1)));
2395 Vertex(1, NbPath+1) = TopExp::FirstVertex(TopoDS::Edge(VEdge(1, NbPath+1)));
2397 UpdateVertex(ILast-1, 1,
2398 TabErr(1, NbPath), Vi(NbPath+1), Vertex(1, NbPath+1 ));
2401 for (isec=1; isec<=NbLaw+1; isec++) {
2404 S = TabS(NbLaw, NbPath);
2405 ureverse = UReverse(NbLaw, NbPath);
2406 exuv = ExchUV(NbLaw, NbPath);
2409 S = TabS(isec, NbPath);
2410 ureverse = UReverse(isec, NbPath);
2411 exuv = ExchUV(isec, NbPath);
2413 S->Bounds(UFirst, ULast, VFirst, VLast);
2415 // Choice of parametres
2418 aux = VFirst; VFirst = VLast; VLast = aux;
2421 aux = UFirst; UFirst = ULast; ULast = aux;
2424 if (isec == NbLaw+1) {
2439 // construction of vertex
2440 if (Vertex(isec, NbPath+1).IsNull())
2441 B.MakeVertex(TopoDS::Vertex(Vertex(isec, NbPath+1)),
2443 mySec->VertexTol(isec-1, Vi(NbPath+1)));
2446 TopLoc_Location Identity;
2447 Vertex(isec, NbPath+1).Location(Identity);
2448 B.UpdateVertex(TopoDS::Vertex(Vertex(isec, NbPath+1)),
2450 mySec->VertexTol(isec-1, Vi(NbPath+1)));
2452 } //end of for (isec=1; isec<=NbLaw+1; isec++)
2455 // ---------- Creation of Vertex and edge ------------
2456 for (ipath=1, IPath=IFirst; ipath<=NbPath;
2458 for (isec=1; isec <=NbLaw; isec++) {
2462 S = TabS(isec, ipath);
2463 exuv = ExchUV(isec, ipath);
2464 S->Bounds(UFirst, ULast, VFirst, VLast);
2465 if (UReverse(isec, ipath)) {
2468 aux2 = VFirst; VFirst = VLast; VLast = aux2;
2471 aux2 = UFirst; UFirst = ULast; ULast = aux2;
2475 // (2.1) Construction of new vertices
2477 if (ipath == 1 && Vertex(1, 1).IsNull()) {
2480 myLoc->PerformVertex(IPath-1,
2481 TopoDS::Vertex(SecVertex(1)),
2483 TopoDS::Vertex(Vertex(1, 1)));
2485 myLoc->PerformVertex(IPath-1,
2486 mySec->Vertex(1,Vi(1)),
2487 mySec->VertexTol(0,Vi(1)),
2488 TopoDS::Vertex(Vertex(1, 1)));
2490 // the first and the next column
2491 if (vclose &&(ipath == NbPath) ) {
2492 Vertex(1, ipath+1) = Vertex(1, 1);
2494 else if (Vertex(1, ipath+1).IsNull()) {
2496 myLoc->PerformVertex(IPath,
2497 TopoDS::Vertex(SecVertex(1)),
2498 TabErr(1,ipath)+VError(1),
2499 TopoDS::Vertex(Vertex(1, ipath+1)) );
2501 myLoc->PerformVertex(IPath,
2502 mySec->Vertex(1,Vi(ipath+1)),
2504 mySec->VertexTol(0,Vi(ipath+1)),
2505 TopoDS::Vertex(Vertex(1, ipath+1)));
2507 if (MergeVertex(Vertex(1,ipath), Vertex(1,ipath+1))) {
2508 UEdge(1, ipath) = NullEdge(Vertex(1,ipath));
2514 if (uclose && (isec == NbLaw)) {
2515 Vertex(isec+1, 1) = Vertex(1, 1);
2517 else if (Vertex(isec+1, 1).IsNull()) {
2519 myLoc->PerformVertex(IPath-1,
2520 TopoDS::Vertex(SecVertex(isec+1)),
2521 TabErr(isec,1)+VError(isec+1),
2522 TopoDS::Vertex(Vertex(isec+1, 1)) );
2524 myLoc->PerformVertex(IPath-1,
2525 mySec->Vertex(isec+1,Vi(1)),
2527 mySec->VertexTol(isec,Vi(1)),
2528 TopoDS::Vertex(Vertex(isec+1, 1)) );
2530 if (MergeVertex(Vertex(isec,1), Vertex(isec+1,1))) {
2531 VEdge(isec, 1) = NullEdge(Vertex(isec, 1));
2536 if (uclose && (isec == NbLaw)) {
2537 Vertex(isec+1, ipath+1) = Vertex(1, ipath+1);
2539 else if (vclose && (ipath == NbPath)) {
2540 Vertex(isec+1, ipath+1) = Vertex(isec+1, 1);
2542 else if (Vertex(isec+1, ipath+1).IsNull()) {
2544 myLoc->PerformVertex(IPath,
2545 TopoDS::Vertex(SecVertex(isec+1)),
2546 TabErr(isec, ipath)+ VError(isec+1),
2547 TopoDS::Vertex(Vertex(isec+1, ipath+1)) );
2549 myLoc->PerformVertex(IPath,
2550 mySec->Vertex(isec+1,Vi(ipath+1)),
2551 TabErr(isec, ipath) +
2552 mySec->VertexTol(isec, Vi(ipath+1)),
2553 TopoDS::Vertex(Vertex(isec+1, ipath+1)) );
2557 singv = MergeVertex(Vertex(isec,ipath+1), Vertex(isec+1,ipath+1));
2558 singu = MergeVertex(Vertex(isec+1,ipath), Vertex(isec+1,ipath+1));
2562 if (singu || singv) {
2563 Degenerated(isec, ipath) = IsDegen(TabS(isec,ipath),
2564 Max(myTol3d, TabErr(isec,ipath)));
2566 if (Degenerated(isec, ipath)) {
2568 std::cout << "Sweep : Degenerated case" << std::endl;
2570 hasdegen = Standard_True;
2571 // Particular construction of edges
2572 if (UEdge(isec+1, ipath).IsNull()) {
2575 UEdge(isec+1, ipath) = NullEdge(Vertex(isec+1,ipath));
2577 else { // Copy the previous edge
2578 UEdge(isec+1, ipath) = UEdge(isec, ipath);
2581 if (VEdge(isec, ipath+1).IsNull()) {
2584 VEdge(isec, ipath+1) = NullEdge(Vertex(isec,ipath+1));
2586 else { // Copy the previous edge
2587 VEdge(isec, ipath+1) = VEdge(isec, ipath);
2591 else { // Construction of edges by isos
2594 UV = UFirst; UFirst = VFirst; VFirst = UV;
2595 UV = ULast ; ULast = VLast ; VLast = UV;
2599 if (isec == 1 && UEdge(1, ipath).IsNull()) {
2600 if (!Vertex(1,ipath).IsSame(Vertex(1,ipath+1))) {
2601 gp_Pnt P1 = BRep_Tool::Pnt(TopoDS::Vertex(Vertex(1,ipath)));
2602 gp_Pnt P2 = BRep_Tool::Pnt(TopoDS::Vertex(Vertex(1,ipath+1)));
2603 if (P1.Distance(P2) <= myTol3d)
2604 Vertex(1,ipath+1) = Vertex(1,ipath);
2606 UEdge(1, ipath) = BuildEdge(S, !exuv, UFirst,
2613 if (UEdge(isec, ipath).IsNull()) //sweep failed
2614 return Standard_False;
2615 UpdateEdge(TopoDS::Edge(UEdge(isec, ipath)),
2619 if (uclose && (isec==NbLaw)) {
2620 if (UEdge(1, ipath).IsNull()) //degenerated case
2622 UEdge(isec+1, ipath) = BuildEdge(S, !exuv, ULast,
2623 Vertex(isec+1, ipath),
2624 Vertex(isec+1, ipath+1),
2628 UpdateEdge(TopoDS::Edge(UEdge(1, ipath)),
2630 UEdge(isec+1, ipath) = UEdge(1, ipath);
2634 if (UEdge(isec+1, ipath).IsNull())
2635 UEdge(isec+1, ipath) = BuildEdge(S, !exuv, ULast,
2636 Vertex(isec+1, ipath),
2637 Vertex(isec+1, ipath+1),
2640 UpdateEdge(TopoDS::Edge(UEdge(isec+1, ipath)), S, !exuv, ULast);
2646 TopoDS_Edge aNewFirstEdge = BuildEdge(S, exuv, VFirst,
2650 if (VEdge(isec, ipath).IsNull())
2651 VEdge(isec, ipath) = aNewFirstEdge;
2652 else //rebuild first edge
2654 RebuildTopOrBottomEdge(aNewFirstEdge,
2655 TopoDS::Edge(VEdge(isec, ipath)),
2657 if (ReversedEdges.Contains(VEdge(isec, ipath)))
2659 ReverseEdgeInFirstOrLastWire(FirstShape, VEdge(isec, ipath));
2660 StartEdges(isec).Reverse();
2665 else UpdateEdge(TopoDS::Edge(VEdge(isec, ipath)),
2668 if (vclose && (ipath == NbPath)) {
2669 if (VEdge(isec, 1).IsNull()) //degenerated case
2671 VEdge(isec, ipath+1) = BuildEdge(S, exuv, VLast,
2672 Vertex(isec , ipath+1),
2673 Vertex(isec+1, ipath+1),
2677 UpdateEdge(TopoDS::Edge(VEdge(isec, 1)),
2679 VEdge(isec, ipath+1) = VEdge(isec, 1);
2682 else if (VEdge(isec, ipath+1).IsNull())
2683 VEdge(isec, ipath+1) = BuildEdge(S, exuv, VLast,
2684 Vertex(isec , ipath+1),
2685 Vertex(isec+1, ipath+1),
2689 if (ipath != NbPath ||
2691 (global_vclose && ILast == myLoc->NbLaw()+1))
2693 UpdateEdge(TopoDS::Edge(VEdge(isec, ipath+1)),
2695 else //ipath == NbPath && !vclose => rebuild last edge
2697 TopoDS_Edge aNewLastEdge = BuildEdge(S, exuv, VLast,
2698 Vertex(isec , ipath+1),
2699 Vertex(isec+1, ipath+1),
2701 RebuildTopOrBottomEdge(aNewLastEdge,
2702 TopoDS::Edge(VEdge(isec, ipath+1)),
2704 if (ReversedEdges.Contains(VEdge(isec, ipath+1)))
2705 ReverseEdgeInFirstOrLastWire(LastShape, VEdge(isec, ipath+1));
2709 }// End of construction of edges
2712 // (3) Construction of Faces
2717 for (ipath=1, IPath=IFirst; ipath<=NbPath; ipath++, IPath++) {
2718 for (isec=1; isec <=NbLaw+1; isec++){
2719 sprintf(name,"uedge_%d_%d", isec, IPath);
2720 DBRep::Set(name,UEdge(isec, ipath));
2724 for (ipath=1, IPath=IFirst; ipath<=NbPath+1; ipath++, IPath++) {
2725 for (isec=1; isec <=NbLaw; isec++){
2726 sprintf(name,"vedge_%d_%d", isec, IPath);
2727 DBRep::Set(name,VEdge(isec, ipath));
2730 for (isec=1; isec <=NbLaw+1; isec++){
2731 sprintf(name,"vertex_%d_%d", isec, IPath);
2732 DBRep::Set(name,Vertex(isec, ipath));
2738 for (ipath=1, IPath=IFirst; ipath<=NbPath; ipath++, IPath++) {
2739 for (isec=1; isec <=NbLaw; isec++) {
2740 if (Degenerated(isec, ipath)) {
2741 if (UEdge(isec, ipath).IsSame(UEdge(isec+1, ipath)))
2742 myFaces->SetValue(isec, IPath, UEdge(isec, ipath));
2744 myFaces->SetValue(isec, IPath, VEdge(isec, ipath));
2746 else if (myFaces->Value(isec, IPath).IsNull()) {
2747 BuildFace(TabS(isec,ipath),
2748 TopoDS::Edge(UEdge(isec, ipath)),
2749 TopoDS::Edge(VEdge(isec, ipath)),
2750 TopoDS::Edge(UEdge(isec+1, ipath)),
2751 TopoDS::Edge(VEdge(isec, ipath+1)),
2753 ExchUV(isec, ipath),
2754 UReverse(isec, ipath),
2756 myFaces->SetValue(isec, IPath, face);
2761 // (3.1) Reverse the faces that have been built earlier
2762 for (ipath = 1; ipath <= NbPath; ipath++)
2763 for (isec = 1; isec <= NbLaw; isec++)
2765 myFaces->ChangeValue(isec, ipath).Reverse();
2768 // (4) History and Continuity
2771 //(4.1) // Degenerated case => Sledgehammer
2772 TopoDS_Compound Comp;
2773 B.MakeCompound(Comp);
2774 for (isec=1; isec <= NbLaw+1; isec++)
2775 for (ipath=1, IPath=IFirst; ipath<= NbPath+1; ipath++, IPath++) {
2776 if (ipath <= NbPath) myUEdges->SetValue(isec, IPath, UEdge(isec, ipath));
2777 if (isec <= NbLaw) myVEdges->SetValue(isec, IPath, VEdge(isec, ipath));
2778 if ((ipath <= NbPath) && (isec <= NbLaw) &&
2779 !myFaces->Value(isec, IPath).IsNull() &&
2780 myFaces->Value(isec, IPath).ShapeType() == TopAbs_FACE)
2781 B.Add(Comp, myFaces->Value(isec, IPath));
2783 BRepLib::EncodeRegularity(Comp, myTolAngular);
2786 //(4.2) // General case => Tweezers
2787 Standard_Boolean isG1;
2791 for (isec=1; isec <= NbLaw+1; isec++) {
2793 (mySec->Continuity(isec-1, myTolAngular) >= GeomAbs_G1);
2794 else isG1 = Standard_False;
2795 for (ipath=1, IPath=IFirst; ipath<= NbPath; ipath++, IPath++) {
2796 myUEdges->SetValue(isec, IPath, UEdge(isec, ipath));
2798 if (isec == NbLaw+1) FF = TopoDS::Face(myFaces->Value(1, IPath));
2799 else FF = TopoDS::Face(myFaces->Value(isec, IPath));
2800 B.Continuity(TopoDS::Edge(myUEdges->Value(isec, IPath)),
2801 TopoDS::Face(myFaces->Value(isec-1, IPath)),
2807 Standard_Integer nbpath = NbPath;
2808 if (vclose) nbpath++; //Another test G1
2809 for (ipath=1, IPath=IFirst; ipath<= NbPath+1; ipath++, IPath++) {
2810 if ((ipath > 1) && (ipath <=nbpath))
2811 isG1 = (myLoc->IsG1(IPath-1, myTol3d, myTolAngular) >= 0);
2812 else isG1 = Standard_False;
2813 for (isec=1; isec <= NbLaw; isec++) {
2814 myVEdges->SetValue(isec, IPath, VEdge(isec, ipath));
2816 if (ipath==NbPath+1) FF = TopoDS::Face(myFaces->Value(isec, 1));
2817 else FF = TopoDS::Face(myFaces->Value(isec, IPath));
2818 anEdge = TopoDS::Edge(myVEdges->Value(isec, IPath));
2819 BRepLib::EncodeRegularity(anEdge, FF,
2820 TopoDS::Face(myFaces->Value(isec, IPath-1)),
2827 // (5) Update Tapes and Rails
2829 if (IFirst == 1 && !Tapes.IsEmpty()) //works only in case of single shell
2831 for (isec = 1; isec <= NbLaw; isec++)
2833 for (j = 1; j <= NbPath+1; j++)
2834 Tapes(StartEdges(isec))->SetValue(1, j, myVEdges->Value(isec, j));
2835 for (j = 1; j <= NbPath; j++)
2836 Tapes(StartEdges(isec))->SetValue(2, j, myUEdges->Value(isec, j));
2837 for (j = 1; j <= NbPath; j++)
2838 Tapes(StartEdges(isec))->SetValue(3, j, myUEdges->Value(isec+1, j));
2839 for (j = 1; j <= NbPath+1; j++)
2840 Tapes(StartEdges(isec))->SetValue(4, j, Vertex(isec, j));
2841 for (j = 1; j <= NbPath+1; j++)
2842 Tapes(StartEdges(isec))->SetValue(5, j, Vertex(isec+1, j));
2843 for (j = 1; j <= NbPath; j++)
2844 Tapes(StartEdges(isec))->SetValue(6, j, myFaces->Value(isec, j));
2845 TopoDS_Vertex Vfirst, Vlast;
2846 TopExp::Vertices(TopoDS::Edge(StartEdges(isec)), Vfirst, Vlast, Standard_True); //with orientation
2847 if (!Rails.IsBound(Vfirst))
2849 Handle(TopTools_HArray2OfShape) anArray = new TopTools_HArray2OfShape(1, 2, 1, NbPath+1);
2850 for (j = 1; j <= NbPath; j++)
2851 anArray->SetValue(1, j, myUEdges->Value(isec, j));
2852 for (j = 1; j <= NbPath+1; j++)
2853 anArray->SetValue(2, j, Vertex(isec, j));
2854 Rails.Bind(Vfirst, anArray);
2856 if (!Rails.IsBound(Vlast))
2858 Handle(TopTools_HArray2OfShape) anArray = new TopTools_HArray2OfShape(1, 2, 1, NbPath+1);
2859 for (j = 1; j <= NbPath; j++)
2860 anArray->SetValue(1, j, myUEdges->Value(isec+1, j));
2861 for (j = 1; j <= NbPath+1; j++)
2862 anArray->SetValue(2, j, Vertex(isec+1, j));
2863 Rails.Bind(Vlast, anArray);
2868 return Standard_True;
2871 //=======================================================================
2873 //purpose : Construt the result of sweeping
2874 //======================================================================
2875 void BRepFill_Sweep::Build(TopTools_MapOfShape& ReversedEdges,
2876 BRepFill_DataMapOfShapeHArray2OfShape& Tapes,
2877 BRepFill_DataMapOfShapeHArray2OfShape& Rails,
2878 const BRepFill_TransitionStyle Transition,
2879 const GeomAbs_Shape Continuity,
2880 const GeomFill_ApproxStyle Approx,
2881 const Standard_Integer Degmax,
2882 const Standard_Integer Segmax)
2884 myContinuity = Continuity;
2885 myApproxStyle = Approx;
2889 CorrectApproxParameters();
2892 if (mySec->IsVertex()) isDone = BuildWire(Transition);
2895 Standard_Integer NbTrous = myLoc->NbHoles(myTol3d),
2896 NbPath = myLoc->NbLaw(),
2897 NbLaw = mySec->NbLaw(), ii, jj, NbPart=1;
2898 Standard_Integer ipath, isec;
2900 myUEdges = new (TopTools_HArray2OfShape) (1, NbLaw+1, 1, NbPath);
2901 myVEdges = new (TopTools_HArray2OfShape) (1, NbLaw, 1, NbPath+1);
2902 myFaces = new (TopTools_HArray2OfShape) (1, NbLaw, 1, NbPath);
2903 myTapes = new (TopTools_HArray1OfShape) (1, NbLaw);
2905 for (Standard_Integer i = 1; i <= NbLaw; i++)
2907 TopoDS_Shell aShell;
2908 BB.MakeShell(aShell);
2909 myTapes->ChangeValue(i) = aShell;
2911 Handle (TopTools_HArray2OfShape) Bounds =
2912 new (TopTools_HArray2OfShape) (1, NbLaw, 1, 2);
2914 Handle(TColStd_HArray1OfInteger) Trous;
2916 if (NbTrous>0) { // How many sub-parts ?
2917 Trous = new (TColStd_HArray1OfInteger) (1, NbTrous);
2918 myLoc->Holes(Trous->ChangeArray1());
2920 if (Trous->Value(NbTrous) == NbPath+1) NbPart--;
2922 if (NbPart == 1) { // This is done at once
2923 Standard_Real Extend = 0.0;
2924 if (NbTrous==1) Extend = EvalExtrapol(1, Transition);
2925 isDone = BuildShell(Transition,
2931 else { // This is done piece by piece
2932 Standard_Integer IFirst = 1, ILast;
2933 for (ii=1, isDone=Standard_True;
2934 ii<=NbPart && isDone; ii++) {
2935 if (ii > NbTrous) ILast = NbPath+1;
2936 else ILast = Trous->Value(ii);
2937 isDone = BuildShell(Transition,
2941 EvalExtrapol(IFirst, Transition),
2942 EvalExtrapol(ILast, Transition));
2944 Translate(myVEdges, IFirst, Bounds, 2);
2945 if (!PerformCorner(IFirst,
2946 Transition, Bounds))
2948 isDone = Standard_False;
2953 Translate(myVEdges, IFirst, Bounds, 1);
2956 // Management of looping ends
2957 if ( (NbTrous>0) && (myLoc->IsClosed()) &&
2958 (Trous->Value(NbTrous) == NbPath+1) ) {
2959 Translate(myVEdges, NbPath+1, Bounds, 1);
2960 Translate(myVEdges, 1, Bounds, 2);
2961 if (!PerformCorner(1, Transition, Bounds))
2963 isDone = Standard_False;
2966 Translate(myVEdges, 1, myVEdges, NbPath+1);
2969 // Construction of the shell
2972 Standard_Integer aNbFaces = 0;
2973 for (ipath=1; ipath<=NbPath; ipath++)
2974 for (isec=1; isec <=NbLaw; isec++)
2976 const TopoDS_Shape& face = myFaces->Value(isec, ipath);
2977 if (!face.IsNull() &&
2978 (face.ShapeType() == TopAbs_FACE) )
2987 isDone = Standard_False;
2991 TopTools_ListIteratorOfListOfShape It(myAuxShape);
2992 for (; It.More(); It.Next()) {
2993 const TopoDS_Shape& face = It.Value();
2994 if (!face.IsNull() &&
2995 (face.ShapeType() == TopAbs_FACE) ) B.Add(shell, face);
2997 //Set common Uedges to faces
2998 BRepTools_Substitution aSubstitute;
3000 for (ii = 1; ii <= NbLaw; ii++)
3001 for (jj = 1; jj <= NbPath; jj++)
3003 SetCommonEdgeInFace(aSubstitute,
3004 myFaces->Value(ii, jj),
3005 myUEdges->Value(ii, jj));
3006 SetCommonEdgeInFace(aSubstitute,
3007 myFaces->Value(ii, jj),
3008 myUEdges->Value(ii+1, jj));
3010 if (mySec->IsUClosed())
3011 for (jj = 1; jj <= NbPath; jj++)
3012 SetCommonEdgeInFace(aSubstitute,
3013 myFaces->Value( 1, jj ),
3014 myUEdges->Value( NbLaw+1, jj));
3016 TopTools_DataMapIteratorOfDataMapOfShapeShape mapit( myVEdgesModified );
3017 for (; mapit.More(); mapit.Next())
3019 const TopoDS_Edge& OldEdge = TopoDS::Edge(mapit.Key());
3020 const TopoDS_Edge& NewEdge = TopoDS::Edge(mapit.Value());
3021 Substitute( aSubstitute, OldEdge, NewEdge );
3023 aSubstitute.Build( shell );
3024 if (aSubstitute.IsCopied( shell )) {
3025 const TopTools_ListOfShape& listSh = aSubstitute.Copy( shell );
3026 shell = TopoDS::Shell( listSh.First() );
3029 for (ii = myFaces->LowerRow(); ii <= myFaces->UpperRow(); ii++) {
3030 for (jj = myFaces->LowerCol(); jj <= myFaces->UpperCol(); jj++) {
3031 const TopoDS_Shape& aLocalShape = myFaces->Value(ii, jj);
3033 if(!aLocalShape.IsNull() && aSubstitute.IsCopied(aLocalShape)) {
3034 const TopTools_ListOfShape& aList = aSubstitute.Copy(aLocalShape);
3036 if(!aList.IsEmpty())
3037 myFaces->ChangeValue(ii, jj) = aList.First();
3042 for (ii = myVEdges->LowerRow(); ii <= myVEdges->UpperRow(); ii++) {
3043 for (jj = myVEdges->LowerCol(); jj <= myVEdges->UpperCol(); jj++) {
3044 const TopoDS_Shape& aLocalShape = myVEdges->Value(ii, jj);
3046 if(!aLocalShape.IsNull() && aSubstitute.IsCopied(aLocalShape)) {
3047 const TopTools_ListOfShape& aList = aSubstitute.Copy(aLocalShape);
3049 if(!aList.IsEmpty())
3050 myVEdges->ChangeValue(ii, jj) = aList.First();
3055 for (ii = myUEdges->LowerRow(); ii <= myUEdges->UpperRow(); ii++) {
3056 for (jj = myUEdges->LowerCol(); jj <= myUEdges->UpperCol(); jj++) {
3057 const TopoDS_Shape& aLocalShape = myUEdges->Value(ii, jj);
3059 if(!aLocalShape.IsNull() && aSubstitute.IsCopied(aLocalShape)) {
3060 const TopTools_ListOfShape& aList = aSubstitute.Copy(aLocalShape);
3062 if(!aList.IsEmpty())
3063 myUEdges->ChangeValue(ii, jj) = aList.First();
3068 //Ensure Same Parameter on U-edges
3069 for (ii = myUEdges->LowerRow(); ii <= myUEdges->UpperRow(); ii++)
3071 if (mySec->IsUClosed() && ii == myUEdges->UpperRow())
3073 for (jj = myUEdges->LowerCol(); jj <= myUEdges->UpperCol(); jj++)
3075 TopoDS_Edge anEdge = TopoDS::Edge(myUEdges->Value(ii, jj));
3076 if (anEdge.IsNull() ||
3077 BRep_Tool::Degenerated(anEdge))
3079 TopoDS_Face Face1, Face2;
3080 Standard_Integer i1 = ii-1, i2 = ii;
3081 if (i1 == 0 && mySec->IsUClosed())
3082 i1 = myFaces->UpperRow();
3083 if (i2 > myFaces->UpperRow())
3087 const TopoDS_Shape& aShape1 = myFaces->Value(i1, jj);
3088 if (aShape1.ShapeType() == TopAbs_FACE)
3089 Face1 = TopoDS::Face(aShape1);
3093 const TopoDS_Shape& aShape2 = myFaces->Value(i2, jj);
3094 if (aShape2.ShapeType() == TopAbs_FACE)
3095 Face2 = TopoDS::Face(aShape2);
3097 if (!Face1.IsNull() && !Face2.IsNull())
3098 CorrectSameParameter(anEdge, Face1, Face2);
3102 for (ii = 1; ii <= NbLaw; ii++)
3103 for (jj = 1; jj <= NbPath; jj++)
3105 const TopoDS_Shape& aFace = myFaces->Value(ii,jj);
3106 if (!aFace.IsNull() && aFace.ShapeType() == TopAbs_FACE)
3107 BB.Add(myTapes->ChangeValue(ii), aFace);
3111 if (myLoc->IsClosed() && mySec->IsUClosed()) {
3113 Standard_Boolean closed = Standard_True;
3114 Standard_Integer iedge;
3115 TopTools_IndexedDataMapOfShapeListOfShape EFmap;
3116 TopExp::MapShapesAndAncestors(shell, TopAbs_EDGE,
3117 TopAbs_FACE, EFmap);
3119 for (iedge = 1; iedge <=EFmap.Extent() && closed; iedge++) {
3120 const TopoDS_Edge& theEdge = TopoDS::Edge(EFmap.FindKey(iedge));
3121 if (BRep_Tool::Degenerated(theEdge)) continue;
3122 closed = ( EFmap(iedge).Extent() > 1);
3124 shell.Closed(closed);
3131 //=======================================================================
3134 //=======================================================================
3135 Standard_Boolean BRepFill_Sweep::IsDone() const
3140 //=======================================================================
3143 //=======================================================================
3144 TopoDS_Shape BRepFill_Sweep::Shape() const
3149 //=======================================================================
3150 //function : ErrorOnSurface
3152 //=======================================================================
3153 Standard_Real BRepFill_Sweep::ErrorOnSurface() const
3158 //=======================================================================
3159 //function : SubShape
3160 //purpose : Faces obtained by sweeping
3161 //=======================================================================
3162 Handle(TopTools_HArray2OfShape) BRepFill_Sweep::SubShape() const
3167 //=======================================================================
3168 //function : InterFaces
3169 //purpose : Edges obtained by sweeping
3170 //=======================================================================
3171 Handle(TopTools_HArray2OfShape) BRepFill_Sweep::InterFaces() const
3176 //=======================================================================
3177 //function : Sections
3178 //purpose : Edges or Face (or compound of 2) Transition between 2 sweepings
3179 //=======================================================================
3180 Handle(TopTools_HArray2OfShape) BRepFill_Sweep::Sections() const
3185 //=======================================================================
3187 //purpose : returns the Tape corresponding to Index-th edge of section
3188 //=======================================================================
3189 TopoDS_Shape BRepFill_Sweep::Tape(const Standard_Integer Index) const
3191 return myTapes->Value(Index);
3194 //=======================================================================
3195 //function : PerformCorner
3196 //purpose : Trim and/or loop a corner
3197 //======================================================================
3198 Standard_Boolean BRepFill_Sweep::PerformCorner(const Standard_Integer Index,
3199 const BRepFill_TransitionStyle Transition,
3200 const Handle(TopTools_HArray2OfShape)& Bounds)
3203 if (Transition == BRepFill_Modified) return Standard_True; // Do nothing.
3205 const Standard_Real anAngularTol = 0.025;
3207 BRepFill_TransitionStyle TheTransition = Transition;
3208 Standard_Boolean isTangent=Standard_False;
3210 Standard_Integer I1, I2, ii; //, jj;
3212 gp_Vec T1, T2, Tang, Sortant;
3214 //Handle(TopTools_HArray1OfShape) TheShape =
3215 //new TopTools_HArray1OfShape( 1, mySec->NbLaw() );
3216 // TopTools_ListIteratorOfListOfShape Iterator;
3223 I1 = myLoc->NbLaw();
3227 // Construct an axis supported by the bissectrice
3228 myLoc->Law(I1)->GetDomain(F, L);
3229 myLoc->Law(I1)->GetCurve()->D1(L, P1, T1);
3232 myLoc->Law(I2)->GetDomain(F, L);
3233 myLoc->Law(I2)->GetCurve()->D1(F, P2, T2);
3236 if (T1.Angle(T2) < myAngMin) {
3237 isTangent = Standard_True;
3240 myLoc->Law(I1)->GetDomain(F, L);
3241 myLoc->Law(I1)->D0(L, M, V);
3243 myLoc->Law(I2)->GetDomain(F, L);
3244 myLoc->Law(I2)->D0(L, M, V);
3247 if (t1.Angle(t2) < myAngMin) {
3249 std::cout << "BRepFill_Sweep::PerformCorner : This is not a corner !" << std::endl;
3251 return Standard_True;
3256 if (T1.Angle(T2) >= M_PI - anAngularTol)
3258 return Standard_False;
3260 if ((TheTransition == BRepFill_Right)
3261 && (T1.Angle(T2) > myAngMax) ) {
3262 TheTransition = BRepFill_Round;
3265 Tang = T1 + T2; //Average direction
3266 gp_Dir NormalOfBisPlane = Tang;
3269 Sortant -= Tang.Dot(Tang)*Tang;
3272 Sortant = T2-T1; //Direction input
3273 Sortant *= -1; // " " output
3274 Tang -= (Tang.Dot(T2))*T2;
3277 P1.BaryCenter(0.5, P2, 0.5);
3281 gp_Ax2 Axe (P1, N, Dx);
3282 gp_Ax2 AxeOfBisPlane( P1, NormalOfBisPlane );
3284 // Construct 2 intersecting Shells
3285 Handle (TopTools_HArray2OfShape) UEdges =
3286 new TopTools_HArray2OfShape( 1, mySec->NbLaw()+1, 1, myLoc->NbLaw() );
3287 UEdges->ChangeArray2() = myUEdges->Array2();
3289 // modified by NIZHNY-MKK Wed Oct 29 18:31:47 2003.BEGIN
3290 Handle (TopTools_HArray2OfShape) aFaces =
3291 new TopTools_HArray2OfShape(myFaces->LowerRow(), myFaces->UpperRow(), 1, 2);
3292 Translate(myFaces, I1, aFaces, 1);
3293 Translate(myFaces, I2, aFaces, 2);
3295 Handle (TopTools_HArray2OfShape) aUEdges =
3296 new TopTools_HArray2OfShape(myUEdges->LowerRow(), myUEdges->UpperRow(), 1, 2);
3297 Translate(myUEdges, I1, aUEdges, 1);
3298 Translate(myUEdges, I2, aUEdges, 2);
3300 gp_Vec aNormal = T2 + T1;
3301 TopoDS_Face aPlaneF;
3303 if(aNormal.Magnitude() > gp::Resolution()) {
3304 gp_Pln pl(P1, gp_Dir(aNormal));
3305 BRepLib_MakeFace aFMaker(pl);
3307 if(aFMaker.Error() == BRepLib_FaceDone) {
3308 aPlaneF = aFMaker.Face();
3310 aBB.UpdateFace(aPlaneF, Precision::Confusion() * 10.);
3314 BRepFill_TrimShellCorner aTrim(aFaces, Transition, AxeOfBisPlane);
3315 aTrim.AddBounds(Bounds);
3316 aTrim.AddUEdges(aUEdges);
3317 aTrim.AddVEdges(myVEdges, Index);
3320 if (aTrim.IsDone()) {
3322 TopTools_ListOfShape listmodif;
3323 for (ii = 1; ii <= mySec->NbLaw(); ii++)
3326 aTrim.Modified(myVEdges->Value(ii, Index), listmodif);
3328 if (listmodif.IsEmpty())
3330 TopoDS_Edge NullEdge;
3331 myVEdges->SetValue(ii, Index, NullEdge);
3334 myVEdges->SetValue(ii, Index, listmodif.First());
3338 Standard_Integer iit = 0;
3340 for(iit = 0; iit < 2; iit++) {
3341 Standard_Integer II = (iit == 0) ? I1 : I2;
3343 for (ii = 1; ii <= mySec->NbLaw(); ii++) {
3344 aTrim.Modified(myFaces->Value(ii, II), listmodif);
3346 if(!listmodif.IsEmpty()) {
3347 myFaces->SetValue(ii, II, listmodif.First());
3351 for (ii = myUEdges->LowerRow(); ii <= myUEdges->UpperRow(); ii++) {
3352 aTrim.Modified(myUEdges->Value(ii, II), listmodif);
3354 if(!listmodif.IsEmpty()) {
3355 myUEdges->SetValue(ii, II, listmodif.First());
3360 else if ((TheTransition == BRepFill_Right) ||
3361 aTrim.HasSection() ) {
3363 std::cout << "Fail of TrimCorner" << std::endl;
3365 return Standard_True; // Nothing is touched
3368 if (mySec->IsUClosed())
3370 myUEdges->SetValue( 1, I1, myUEdges->Value(mySec->NbLaw()+1, I1) );
3371 myUEdges->SetValue( 1, I2, myUEdges->Value(mySec->NbLaw()+1, I2) );
3374 if (TheTransition == BRepFill_Round) {
3376 TopTools_ListOfShape list1, list2;
3377 TopoDS_Edge Bord1, Bord2, BordFirst;
3378 BordFirst.Nullify();
3381 Standard_Boolean HasFilling = Standard_False;
3383 for (ii=1; ii<=mySec->NbLaw(); ii++) {
3384 KeepEdge(myFaces->Value(ii, I1), Bounds->Value(ii, 1), list1);
3385 KeepEdge(myFaces->Value(ii, I2), Bounds->Value(ii, 2), list2);
3386 if (list1.Extent() == list2.Extent()) {
3387 TopTools_ListIteratorOfListOfShape It1(list1);
3388 TopTools_ListIteratorOfListOfShape It2(list2);
3390 for (; It1.More(); It1.Next(), It2.Next()) {
3391 if (HasFilling) { // Transversal choice of constraints
3392 TopoDS_Vertex VF, VL, VC;
3393 TopoDS_Edge E = TopoDS::Edge(It1.Value());
3397 TopExp::Vertices(E, VF, VL);
3398 if (!Bord1.IsNull() &&
3399 TopExp::CommonVertex(E, Bord1, VC)) {
3400 if (VC.IsSame(VF)) E1 = Bord1;
3403 if (!Bord2.IsNull() &&
3404 TopExp::CommonVertex(E, Bord2, VC)) {
3405 if (VC.IsSame(VF)) E1 = Bord2;
3408 if (!BordFirst.IsNull() &&
3409 TopExp::CommonVertex(E, BordFirst, VC)) {
3410 if (VC.IsSame(VF)) E1 = BordFirst;
3411 else E2 = BordFirst;
3418 B = Filling(It1.Value(), myFaces->Value(ii, I1),
3419 It2.Value(), myFaces->Value(ii, I2),
3420 myVEdgesModified, myTol3d, Axe, T1,
3424 myAuxShape.Append(FF);
3426 TopoDS_Shape aVshape = myVEdges->Value(ii, I2);
3427 TopoDS_Compound aCompound;
3428 BB.MakeCompound(aCompound);
3429 if (!aVshape.IsNull())
3430 BB.Add(aCompound, aVshape);
3431 BB.Add(aCompound, FF);
3432 myVEdges->ChangeValue(ii, I2) = aCompound;
3434 BB.Add(myTapes->ChangeValue(ii), FF);
3435 HasFilling = Standard_True;
3437 if (ii==1) BordFirst = Bord1;
3441 else std::cout << "PerformCorner : Unsymmetry of free border" << std::endl;
3445 return Standard_True;
3449 Standard_Integer jj;
3451 DBRep::Set("TrimmedShell", TheShape);
3452 for (jj=1; jj <=myFaces->ColLength(); jj++){
3453 sprintf(name,"Tfaces_%d_%d", jj, I1);
3454 DBRep::Set(name, myFaces->Value(jj, I1));
3455 sprintf(name,"Tfaces_%d_%d", jj, I2);
3456 DBRep::Set(name, myFaces->Value(jj, I2));
3463 //=======================================================================
3464 //function : EvalExtrapol
3466 //======================================================================
3467 Standard_Real BRepFill_Sweep::
3468 EvalExtrapol(const Standard_Integer Index,
3469 const BRepFill_TransitionStyle Transition) const
3471 Standard_Real Extrap = 0.0;
3472 if (Transition == BRepFill_Right) {
3473 Standard_Integer I1, I2;
3474 if ((Index == 1) || (Index ==myLoc->NbLaw()+1) ) {
3475 if (!myLoc->IsClosed() || !mySec->IsVClosed()) return Extrap;
3476 I1 = myLoc->NbLaw();
3484 gp_Vec V1, V2, T1, T2;
3486 Standard_Real Xmin, Ymin, Zmin, Xmax, Ymax, Zmax, R, f, l;
3488 myLoc->Law(I1)->GetDomain(f, l);
3489 myLoc->Law(I1)->D0(l, M1, V1);
3490 T1.SetXYZ(M1.Column(3));
3491 myLoc->Law(I2)->GetDomain(f, l);
3492 myLoc->Law(I2)->D0(f, M2, V2);
3493 T2.SetXYZ(M2.Column(3));
3495 Standard_Real alpha = T1.Angle(T2);
3496 if ((alpha > myAngMax) || (alpha < myAngMin)) {
3497 //Angle too great => No "straight" connection
3498 //Angle too small => No connection
3499 return Extrap; // = 0.0
3502 Handle(GeomFill_SectionLaw) Sec;
3503 Sec = mySec->ConcatenedLaw();
3505 //Calculating parameter U
3506 Standard_Real U, Length, SecFirst, SecLen, Lf, Ll;
3507 myLoc->CurvilinearBounds( myLoc->NbLaw(), Lf, Length );
3508 mySec->Law(1)->GetDomain( SecFirst, SecLen );
3510 myLoc->CurvilinearBounds( I1, Lf, Ll );
3511 U = SecFirst + (Ll/Length)*SecLen;
3514 //Box(Sec, 0., box);
3516 box.Get(Xmin, Ymin, Zmin, Xmax, Ymax, Zmax);
3518 R = Max(Max(Abs(Xmin), Abs(Xmax)),Max(Abs(Ymin), Abs(Ymax)));
3520 // modified by NIZHNY-MKK Fri Oct 31 18:57:51 2003
3521 // Standard_Real coef = 1.2;
3522 Standard_Real coef = 2.;
3524 Extrap = Max(Abs(Zmin), Abs(Zmax)) + 100*myTol3d;
3525 Extrap += R*Tan(alpha/2);
3530 //=======================================================================
3531 //function : MergeVertex
3532 //purpose : Make V2 = V1 if V2 is too close to V1
3533 //======================================================================
3534 Standard_Boolean BRepFill_Sweep::MergeVertex(const TopoDS_Shape& V1,
3535 TopoDS_Shape& V2) const
3537 // Class BRep_Tool without fields and without Constructor :
3539 const TopoDS_Vertex& v1 = TopoDS::Vertex(V1);
3540 const TopoDS_Vertex& v2 = TopoDS::Vertex(V2);
3542 // tol = Max(BT.Tolerance(v1), BT.Tolerance(v2));
3543 tol = Max(BRep_Tool::Tolerance(v1), BRep_Tool::Tolerance(v2));
3544 if (tol < myTol3d) tol = myTol3d;
3545 // if (BT.Pnt(v1).Distance(BT.Pnt(v2)) <= tol ){
3546 if (BRep_Tool::Pnt(v1).Distance(BRep_Tool::Pnt(v2)) <= tol ){
3548 return Standard_True;
3550 return Standard_False;
3554 //=======================================================================
3555 //function : UpdateVertex
3556 //purpose : Update the Tolerance of Vertices depending on Laws.
3557 //======================================================================
3558 void BRepFill_Sweep::UpdateVertex(const Standard_Integer ipath,
3559 const Standard_Integer isec,
3560 const Standard_Real ErrApp,
3561 const Standard_Real Param,
3562 TopoDS_Shape& V) const
3564 TopoDS_Vertex vv, TheV;
3565 TheV = TopoDS::Vertex(V);
3566 myLoc->PerformVertex(ipath,
3567 mySec->Vertex(isec, Param),
3568 ErrApp+mySec->VertexTol(isec-1, Param),
3570 // Class BRep_Tool without fields and without Constructor :
3574 P1 = BRep_Tool::Pnt(vv);
3575 // P2 = BT.Pnt(TheV);
3576 P2 = BRep_Tool::Pnt(TheV);
3578 // Standard_Real Tol = BT.Tolerance(vv);
3579 Standard_Real Tol = BRep_Tool::Tolerance(vv);
3580 Tol += P1.Distance(P2);
3582 // if (Tol > BT.Tolerance(TheV)) {
3583 if (Tol > BRep_Tool::Tolerance(TheV)) {
3585 B.UpdateVertex(TheV, Tol);
3589 //=======================================================================
3590 //function : RebuildTopOrBottomEdge
3591 //purpose : Rebuild v-iso edge of top or bottom section
3592 // inserting new 3d and 2d curves taken from swept surfaces
3593 //======================================================================
3594 void BRepFill_Sweep::RebuildTopOrBottomEdge(const TopoDS_Edge& aNewEdge,
3595 TopoDS_Edge& anEdge,
3596 TopTools_MapOfShape& ReversedEdges) const
3598 Standard_Real fpar, lpar;
3599 Handle(Geom_Curve) aNewCurve = BRep_Tool::Curve(aNewEdge, fpar, lpar);
3600 TopLoc_Location Identity;
3602 Standard_Boolean ToReverse = Standard_False;
3603 Standard_Boolean IsDegen = BRep_Tool::Degenerated(aNewEdge);
3605 BRep_Tool::Range(aNewEdge, fpar, lpar);
3608 TopoDS_Vertex V1, V2, NewV1, NewV2;
3609 TopExp::Vertices(anEdge, V1, V2);
3612 TopExp::Vertices(aNewEdge, NewV1, NewV2);
3613 V1.Location(Identity);
3614 if (!V1.IsSame(NewV1))
3616 if (V1.IsSame(NewV2))
3617 ToReverse = Standard_True;
3620 gp_Pnt Pnt1 = BRep_Tool::Pnt(V1);
3621 gp_Pnt NewPnt1 = BRep_Tool::Pnt(NewV1);
3622 Standard_Real TolSum = BRep_Tool::Tolerance(V1) + BRep_Tool::Tolerance(NewV1);
3623 if (!Pnt1.IsEqual(NewPnt1, TolSum))
3624 ToReverse = Standard_True;
3630 Standard_Real OldFirst, OldLast;
3631 Handle(Geom_Curve) OldCurve = BRep_Tool::Curve(anEdge, OldFirst, OldLast);
3632 gp_Vec OldD1, NewD1;
3634 OldCurve->D1(0.5*(OldFirst + OldLast), MidPnt, OldD1);
3635 aNewCurve->D1(0.5*(fpar + lpar), MidPnt, NewD1);
3636 if (OldD1 * NewD1 < 0.)
3637 ToReverse = Standard_True;
3641 anEdge.Location(Identity);
3642 const Handle(BRep_TEdge)& TEdge = *((Handle(BRep_TEdge)*) &anEdge.TShape());
3643 TEdge->Tolerance(BRep_Tool::Tolerance(aNewEdge));
3645 BB.Range(anEdge, fpar, lpar);
3646 BB.UpdateEdge(anEdge, aNewCurve, Precision::Confusion());
3647 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &aNewEdge.TShape());
3648 const BRep_ListOfCurveRepresentation& lcr = TE->Curves();
3649 BRep_ListIteratorOfListOfCurveRepresentation itrep(lcr);
3650 for (; itrep.More(); itrep.Next())
3652 const Handle(BRep_CurveRepresentation)& CurveRep = itrep.Value();
3653 if (CurveRep->IsCurveOnSurface())
3655 Handle(BRep_GCurve) GC (Handle(BRep_GCurve)::DownCast (CurveRep));
3656 Handle(Geom2d_Curve) aPCurve = GC->PCurve();
3657 Handle(Geom_Surface) aSurf = GC->Surface();
3658 TopLoc_Location aLoc = aNewEdge.Location() * GC->Location();
3659 BB.UpdateEdge(anEdge, aPCurve, aSurf, aLoc, Precision::Confusion());
3663 anEdge.Free(Standard_True);
3664 TopoDS_Vertex V1, V2;
3665 TopExp::Vertices(anEdge, V1, V2);
3667 TopoDS_Shape anEdgeFORWARD = anEdge.Oriented(TopAbs_FORWARD);
3669 BB.Remove(anEdgeFORWARD, V1);
3670 BB.Remove(anEdgeFORWARD, V2);
3672 V1.Location(Identity);
3673 V2.Location(Identity);
3676 V2.Orientation(TopAbs_FORWARD);
3677 V1.Orientation(TopAbs_REVERSED);
3679 BB.Add(anEdgeFORWARD, V1);
3680 BB.Add(anEdgeFORWARD, V2);
3685 ReversedEdges.Add(anEdge);
3688 BB.Degenerated(anEdge, IsDegen);