1 // File: BRepFill_Sweep.cxx
2 // Created: Wed Jan 7 13:39:37 1998
3 // Author: Philippe MANGIN
8 #include <BRepFill_Sweep.ixx>
10 #include <BRepFill_SectionLaw.hxx>
11 //#include <BRepFill_TrimCorner.hxx>
12 #include <BRepFill_CurveConstraint.hxx>
14 #include <GeomFill_SectionLaw.hxx>
15 #include <GeomFill_LocationLaw.hxx>
16 #include <GeomFill_Sweep.hxx>
18 // modified by NIZHNY-MKK Wed Oct 22 12:25:45 2003
19 #include <BRepFill_TrimShellCorner.hxx>
21 //#include <GeomPlate_BuildPlateSurface.hxx>
22 //#include <GeomPlate_Surface.hxx>
23 //#include <GeomPlate_PointConstraint.hxx>
25 #include <gp_Pnt2d.hxx>
26 #include <gp_Vec2d.hxx>
27 #include <Bnd_Box.hxx>
29 #include <Geom_Surface.hxx>
30 #include <Geom_SurfaceOfRevolution.hxx>
31 #include <Geom_RectangularTrimmedSurface.hxx>
32 #include <Geom_Plane.hxx>
33 #include <Geom_Curve.hxx>
34 #include <Geom_BezierCurve.hxx>
35 #include <Geom_BSplineCurve.hxx>
36 #include <Geom2d_Line.hxx>
37 #include <Geom2d_Curve.hxx>
38 #include <Geom2d_TrimmedCurve.hxx>
39 #include <GeomLib.hxx>
40 #include <GeomLib_IsPlanarSurface.hxx>
41 #include <BRepLib_FindSurface.hxx>
42 #include <GeomConvert_ApproxSurface.hxx>
44 #include <BRepAdaptor_HCurve.hxx>
45 #include <BRepAdaptor_HCurve2d.hxx>
46 #include <BRepAdaptor_HSurface.hxx>
47 #include <Adaptor3d_HCurveOnSurface.hxx>
48 #include <GeomAdaptor_HSurface.hxx>
49 #include <GeomAdaptor_HCurve.hxx>
50 #include <Geom2dAdaptor_HCurve.hxx>
51 #include <Approx_CurveOnSurface.hxx>
52 #include <Approx_SameParameter.hxx>
53 #include <GCPnts_AbscissaPoint.hxx>
55 #include <BRep_Builder.hxx>
56 #include <BRep_Tool.hxx>
57 #include <BRep_ListIteratorOfListOfCurveRepresentation.hxx>
58 #include <BRep_TEdge.hxx>
59 #include <BRep_TVertex.hxx>
60 #include <BRep_CurveRepresentation.hxx>
61 #include <BRep_GCurve.hxx>
63 #include <BRepLib.hxx>
64 #include <BRepLib_MakeEdge.hxx>
65 #include <BRepLib_MakeFace.hxx>
66 #include <BRepLib_FaceError.hxx>
69 #include <TopoDS_Edge.hxx>
70 #include <TopoDS_Face.hxx>
71 #include <TopoDS_Compound.hxx>
72 #include <TopoDS_Shell.hxx>
74 #include <TopExp_Explorer.hxx>
75 #include <TopAbs_Orientation.hxx>
77 #include <TColStd_HArray1OfInteger.hxx>
78 #include <TColStd_Array2OfInteger.hxx>
79 #include <TColStd_Array1OfReal.hxx>
80 #include <TColStd_Array2OfReal.hxx>
81 #include <TColGeom_Array2OfSurface.hxx>
82 #include <TColgp_Array1OfPnt.hxx>
84 #include <TopTools_Array1OfShape.hxx>
85 #include <TopTools_Array2OfShape.hxx>
86 #include <TopTools_HArray2OfShape.hxx>
87 #include <TopTools_HArray1OfShape.hxx>
88 #include <TopTools_ListIteratorOfListOfShape.hxx>
89 #include <TopTools_ListOfShape.hxx>
90 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
91 #include <BRepTools_WireExplorer.hxx>
93 #include <Standard_ConstructionError.hxx>
94 #include <Precision.hxx>
95 #include <BRepBuilderAPI_MakeWire.hxx>
97 #include <BRepTools_Substitution.hxx>
98 #include <TopTools_DataMapIteratorOfDataMapOfShapeShape.hxx>
99 #include <TopoDS_Iterator.hxx>
102 #include <BRepCheck_Edge.hxx>
106 #include <DrawTrSurf.hxx>
108 static Standard_Boolean Affich = 0;
111 //=======================================================================
112 //function : NumberOfPoles
114 //=======================================================================
115 static Standard_Integer NumberOfPoles(const TopoDS_Wire& W)
117 Standard_Integer NbPoints = 0;
119 TopoDS_Iterator iter(W);
120 for (; iter.More(); iter.Next())
122 BRepAdaptor_Curve c(TopoDS::Edge(iter.Value()));
124 Standard_Real dfUf = c.FirstParameter();
125 Standard_Real dfUl = c.LastParameter();
126 if (IsEqual(dfUf,dfUl))
132 case GeomAbs_BezierCurve:
134 // Put all poles for bezier
135 Handle(Geom_BezierCurve) GC = c.Bezier();
136 Standard_Integer iNbPol = GC->NbPoles();
141 case GeomAbs_BSplineCurve:
143 // Put all poles for bspline
144 Handle(Geom_BSplineCurve) GC = c.BSpline();
145 Standard_Integer iNbPol = GC->NbPoles();
156 case GeomAbs_Ellipse:
157 case GeomAbs_Hyperbola:
158 case GeomAbs_Parabola:
164 NbPoints += 15 + c.NbIntervals(GeomAbs_C3);
165 } // switch (c.GetType()) ...
166 } // for (; iter.More(); iter.Next())
171 //=======================================================================
172 //function : HasPCurves
174 //=======================================================================
175 static Standard_Boolean HasPCurves(const TopoDS_Edge& E)
177 Standard_Boolean haspcurves = Standard_False;
179 BRep_ListIteratorOfListOfCurveRepresentation itcr
180 ((*((Handle(BRep_TEdge)*)&E.TShape()))->Curves());
181 for (; itcr.More(); itcr.Next())
183 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
184 if (cr->IsCurveOnSurface())
186 haspcurves = Standard_True;
193 //=======================================================================
194 //function : Translate
195 //purpose : Copy a column from one table to another.
196 //=======================================================================
197 static void Translate(const Handle(TopTools_HArray2OfShape)& ArrayIn,
198 const Standard_Integer In,
199 Handle(TopTools_HArray2OfShape)& ArrayOut,
200 const Standard_Integer Out)
202 Standard_Integer ii, Nb;
203 Nb = ArrayOut->ColLength();
204 for (ii=1; ii<=Nb; ii++) {
205 ArrayOut->SetValue(ii, Out, ArrayIn->Value(ii, In));
210 //=======================================================================
212 //purpose : Bounding box of a section.
213 //=======================================================================
214 static void Box(Handle(GeomFill_SectionLaw)& Sec,
215 const Standard_Real U,
219 Standard_Integer NbPoles, bid;
221 Sec->SectionShape(NbPoles, bid, bid);
222 TColgp_Array1OfPnt Poles(1, NbPoles);
223 TColStd_Array1OfReal W(1, NbPoles);
224 Sec->D0(U, Poles, W);
225 for (Standard_Integer ii=1; ii<=NbPoles; ii++) {
230 //=======================================================================
232 //purpose : Check if E is an edge of sewing on S
233 // and make the representation HadHoc
234 //=======================================================================
235 static Handle(Geom2d_Curve) Couture(const TopoDS_Edge& E,
236 const Handle(Geom_Surface)& S,
237 const TopLoc_Location& L)
239 TopLoc_Location l = L.Predivided(E.Location());
240 Standard_Boolean Eisreversed = (E.Orientation() == TopAbs_REVERSED);
242 // find the representation
243 BRep_ListIteratorOfListOfCurveRepresentation itcr
244 ((*((Handle(BRep_TEdge)*)&E.TShape()))->ChangeCurves());
246 while (itcr.More()) {
247 Handle(BRep_CurveRepresentation)& cr = itcr.Value();
248 if (cr->IsCurveOnSurface(S,l)) {
249 Handle(BRep_GCurve)& GC = *((Handle(BRep_GCurve)*)&cr);
250 if (GC->IsCurveOnClosedSurface() && Eisreversed)
251 return GC->PCurve2();
257 Handle(Geom2d_Curve) pc;
262 //=======================================================================
263 //function : CheckSameParameter
264 //purpose : Check a posteriori that sameparameter has worked correctly
265 //=======================================================================
267 static Standard_Boolean CheckSameParameter
268 (const Handle(Adaptor3d_HCurve)& C3d,
269 Handle(Geom2d_Curve)& Pcurv,
270 const Handle(Adaptor3d_HSurface)& S,
271 const Standard_Real tol3d,
272 Standard_Real& tolreached)
275 Standard_Real f = C3d->FirstParameter();
276 Standard_Real l = C3d->LastParameter();
277 Standard_Integer nbp = 45;
278 Standard_Real step = 1./(nbp -1);
279 for(Standard_Integer i = 0; i < nbp; i++){
282 t = (1-t) * f + t * l;
283 Pcurv->Value(t).Coord(u,v);
284 gp_Pnt pS = S->Value(u,v);
285 gp_Pnt pC = C3d->Value(t);
286 Standard_Real d2 = pS.SquareDistance(pC);
287 tolreached = Max(tolreached,d2);
289 tolreached = sqrt(tolreached);
290 if(tolreached > tol3d){
292 return Standard_False;
295 tolreached = Max(tolreached,Precision::Confusion());
296 return Standard_True;
299 //=======================================================================
300 //function : SameParameter
301 //purpose : Encapsulation of Sameparameter
302 // Boolean informs if the pcurve was computed or not...
303 // The tolerance is always OK.
304 //=======================================================================
306 static Standard_Boolean SameParameter(TopoDS_Edge& E,
307 Handle(Geom2d_Curve)& Pcurv,
308 const Handle(Geom_Surface)& Surf,
309 const Standard_Real tol3d,
310 Standard_Real& tolreached)
312 //Handle(BRepAdaptor_HCurve) C3d = new (BRepAdaptor_HCurve)(E);
314 Handle(Geom_Curve) C3d = BRep_Tool::Curve( E, f, l );
315 GeomAdaptor_Curve GAC3d( C3d, f, l );
316 Handle(GeomAdaptor_HCurve) HC3d = new GeomAdaptor_HCurve( GAC3d );
318 Handle(GeomAdaptor_HSurface) S = new (GeomAdaptor_HSurface)(Surf);
319 Standard_Real ResTol;
321 if(CheckSameParameter( HC3d, Pcurv, S, tol3d, tolreached ))
322 return Standard_True;
326 Handle(Geom2dAdaptor_HCurve) HC2d = new Geom2dAdaptor_HCurve( Pcurv );
327 Approx_CurveOnSurface AppCurve(HC2d, S, HC2d->FirstParameter(), HC2d->LastParameter(),
328 Precision::Confusion(), GeomAbs_C1, 10, 10, Standard_True);
329 if (AppCurve.IsDone() && AppCurve.HasResult())
331 C3d = AppCurve.Curve3d();
332 tolreached = AppCurve.MaxError3d();
334 B.UpdateEdge( E, C3d, tolreached );
335 return Standard_True;
339 Approx_SameParameter sp( HC3d, Pcurv, S, tol3d );
340 if(sp.IsDone() && !sp.IsSameParameter()) Pcurv = sp.Curve2d();
341 else if(!sp.IsDone() && !sp.IsSameParameter()){
343 cout<<"echec SameParameter"<<endl;
345 return Standard_False;
348 ResTol = sp.TolReached();
349 if(ResTol > tolreached ){
351 cout<<"SameParameter : Tolerance not reached!"<<endl;
352 cout<<"tol visee : "<<tol3d<<" tol obtained : "<<ResTol<<endl;
354 return Standard_False;
357 tolreached = 1.1*ResTol;
358 if(sp.IsDone() && !sp.IsSameParameter()) Pcurv = sp.Curve2d();
360 return Standard_True;
363 //=======================================================================
364 //Objet : Orientate an edge of natural restriction
366 //=======================================================================
367 static void Oriente(const Handle(Geom_Surface)& S,
371 gp_Vec2d D, URef(1, 0), VRef(0, 1);
372 Standard_Boolean isuiso, isfirst, isopposite;
373 Standard_Real UFirst, ULast, VFirst, VLast, f, l;
374 S->Bounds(UFirst, ULast, VFirst, VLast);
375 Handle(Geom2d_Curve) C;
378 C = BRep_Tool::CurveOnSurface(E, S, bid, f, l);
379 C->D1((f+l)/2, P, D);
381 isuiso = D.IsParallel(VRef, 0.1);
384 isfirst = (Abs (P.X()-UFirst) < Precision::Confusion());
385 isopposite = D.IsOpposite(VRef, 0.1);
386 E.Orientation(TopAbs_REVERSED);
389 isfirst = (Abs (P.Y()-VFirst) < Precision::Confusion());
390 isopposite = D.IsOpposite(URef, 0.1);
391 E.Orientation(TopAbs_FORWARD);
394 if (!isfirst) E.Reverse();
395 if (isopposite) E.Reverse();
398 static void UpdateEdgeOnPlane(const TopoDS_Face& F, const TopoDS_Edge& E,
399 const BRep_Builder& BB)
402 Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(E,F,f,l);
403 Handle(Geom_Surface) S = BRep_Tool::Surface(F);
405 Standard_Real Tol = BRep_Tool::Tolerance(E);
406 BB.UpdateEdge(E, C2d, S, Loc, Tol);
407 BRepCheck_Edge Check(E);
408 Tol = Max(Tol,Check.Tolerance());
409 BB.UpdateEdge(E, Tol);
412 V = TopExp::FirstVertex(E);
413 if(BRep_Tool::Tolerance(V) < Tol) BB.UpdateVertex(V, Tol);
414 V = TopExp::LastVertex(E);
415 if(BRep_Tool::Tolerance(V) < Tol) BB.UpdateVertex(V, Tol);
418 //=======================================================================
419 //Function : BuildFace
420 //Objet : Construct a Face via a surface and 4 Edges (natural borders)
421 // : Only one Hypothesis : isos u and v are switched :
422 // Edge1/3 are iso u (recp v)
423 // Edge2/4 are iso v (recp u)
424 //=======================================================================
425 static void BuildFace(const Handle(Geom_Surface)& S,
426 const TopoDS_Edge& E1,
427 const TopoDS_Edge& E2,
428 const TopoDS_Edge& E3,
429 const TopoDS_Edge& E4,
430 TopTools_DataMapOfShapeShape& EEmap,
431 const Standard_Boolean ExchUV,
432 const Standard_Boolean UReverse,
436 // Class BRep_Tool without fields and without Constructor :
438 TopoDS_Edge e1, e2, E;
441 BRepBuilderAPI_MakeWire B;
442 TopoDS_Iterator Iter;
445 //Is the surface planar ?
446 Standard_Real Tol1, Tol2, Tol3, Tol4;
447 Tol1 = BRep_Tool::Tolerance( E1 );
448 Tol2 = BRep_Tool::Tolerance( E2 );
449 Tol3 = BRep_Tool::Tolerance( E3 );
450 Tol4 = BRep_Tool::Tolerance( E4 );
451 // Tol = Min( BT.Tolerance(E1), BT.Tolerance(E2));
452 Tol = Min( Tol1, Tol2 );
453 // Tol = Min(Tol, Min(BT.Tolerance(E3),BT.Tolerance(E4)));
454 Tol = Min( Tol, Min( Tol3, Tol4 ) );
455 Standard_Boolean IsPlan = Standard_False;
456 Handle(Geom_Plane) thePlane;
458 if (!E1.IsSame(E3) && !E2.IsSame(E4)) //exclude cases with seam edges: they are not planar
460 GeomLib_IsPlanarSurface IsP(S, Tol);
463 IsPlan = Standard_True;
464 thePlane = new Geom_Plane( IsP.Plan() );
468 Handle(BRep_TEdge)& TE1 = *((Handle(BRep_TEdge)*)&E1.TShape());
469 Handle(BRep_TEdge)& TE2 = *((Handle(BRep_TEdge)*)&E2.TShape());
470 Handle(BRep_TEdge)& TE3 = *((Handle(BRep_TEdge)*)&E3.TShape());
471 Handle(BRep_TEdge)& TE4 = *((Handle(BRep_TEdge)*)&E4.TShape());
472 TE1->Tolerance( Precision::Confusion() );
473 TE2->Tolerance( Precision::Confusion() );
474 TE3->Tolerance( Precision::Confusion() );
475 TE4->Tolerance( Precision::Confusion() );
477 TopoDS_Wire theWire = BRepLib_MakeWire( E1, E2, E3, E4 );
478 Standard_Integer NbPoints = NumberOfPoles( theWire );
479 if (NbPoints <= 100) //limitation for CPU
481 BRepLib_FindSurface FS( theWire, -1, Standard_True );
484 IsPlan = Standard_True;
485 thePlane = Handle(Geom_Plane)::DownCast(FS.Surface());
488 BB.UpdateEdge( E1, Tol1 );
489 BB.UpdateEdge( E2, Tol2 );
490 BB.UpdateEdge( E3, Tol3 );
491 BB.UpdateEdge( E4, Tol4 );
495 // Construction of the wire
499 // if (!IsPlan || !BT.Degenerated(e1))
500 if (!IsPlan || !BRep_Tool::Degenerated(e1))
505 // if (!IsPlan || !BT.Degenerated(e2))
506 if (!IsPlan || !BRep_Tool::Degenerated(e2))
509 if (!BRep_Tool::Degenerated(e2))
512 TopoDS_Shape NewEdge;
513 //take the last edge added to WW
514 for (Iter.Initialize( WW ); Iter.More(); Iter.Next())
515 NewEdge = Iter.Value();
516 if (! e2.IsSame(NewEdge))
517 EEmap.Bind( e2, NewEdge );
529 // if (!IsPlan || !BT.Degenerated(E))
530 if (!IsPlan || !BRep_Tool::Degenerated(E))
533 if (!BRep_Tool::Degenerated(E))
536 TopoDS_Shape NewEdge;
537 //take the last edge added to WW
538 for (Iter.Initialize( WW ); Iter.More(); Iter.Next())
539 NewEdge = Iter.Value();
540 if (! E.IsSame(NewEdge))
541 EEmap.Bind( E, NewEdge );
553 // if (!IsPlan || !BT.Degenerated(E))
554 if (!IsPlan || !BRep_Tool::Degenerated(E))
557 if (!BRep_Tool::Degenerated(E))
560 TopoDS_Shape NewEdge;
561 //take the last edge added to WW
562 for (Iter.Initialize( WW ); Iter.More(); Iter.Next())
563 NewEdge = Iter.Value();
564 if (! E.IsSame(NewEdge))
565 EEmap.Bind( E, NewEdge );
573 sprintf(name,"wire-on-face");
574 DBRep::Set(name, WW);
578 // Construction of the face.
579 if (IsPlan) { // Suspend representation 2d
580 // and construct face Plane
582 //BRepLib_MakeFace MkF(IsP.Plan(), WW);
584 gp_Vec DU, DV, NS, NP;
585 Standard_Real Ufirst, Ulast, Vfirst, Vlast;
586 S->Bounds( Ufirst, Ulast, Vfirst, Vlast );
587 S->D1( (Ufirst+Ulast)/2., (Vfirst+Vlast)/2., aPnt, DU, DV );
589 NP = thePlane->Pln().Axis().Direction();
591 thePlane->UReverse();
592 BRepLib_MakeFace MkF( thePlane, WW );
593 if (MkF.Error() != BRepLib_FaceDone) {
595 BRepLib_FaceError Err = MkF.Error();
596 cout << "Planar Face Error :" << Err << endl;
600 Handle(Geom2d_Curve) NullC2d;
602 BB.UpdateEdge( E1, NullC2d, S, Loc, Tol1 );
603 BB.UpdateEdge( E2, NullC2d, S, Loc, Tol2 );
604 BB.UpdateEdge( E3, NullC2d, S, Loc, Tol3 );
605 BB.UpdateEdge( E4, NullC2d, S, Loc, Tol4 );
608 UpdateEdgeOnPlane(F,E1,BB);
609 UpdateEdgeOnPlane(F,E2,BB);
610 UpdateEdgeOnPlane(F,E3,BB);
611 UpdateEdgeOnPlane(F,E4,BB);
614 Handle(Geom2d_Curve) NC;
616 // B.UpdateEdge(E1, NC, S, Loc, BT.Tolerance(E1));
617 BB.UpdateEdge(E1, NC, S, Loc, BRep_Tool::Tolerance(E1));
618 // B.UpdateEdge(E2, NC, S, Loc, BT.Tolerance(E2));
619 BB.UpdateEdge(E2, NC, S, Loc, BRep_Tool::Tolerance(E2));
620 // B.UpdateEdge(E3, NC, S, Loc, BT.Tolerance(E3));
621 BB.UpdateEdge(E3, NC, S, Loc, BRep_Tool::Tolerance(E3));
622 // B.UpdateEdge(E4, NC, S, Loc, BT.Tolerance(E4));
623 BB.UpdateEdge(E4, NC, S, Loc, BRep_Tool::Tolerance(E4));
628 if (!IsPlan) {// Cas Standard : Ajout
629 BB.MakeFace(F, S, Precision::Confusion());
634 if (ExchUV) F.Reverse();
635 if (UReverse) F.Reverse();
639 //=======================================================================
640 //Fonction : BuildEdge
641 //Objet : Construct non-closed Edge
642 //=======================================================================
643 static TopoDS_Edge BuildEdge(Handle(Geom_Curve)& C3d,
644 Handle(Geom2d_Curve)& C2d,
645 Handle(Geom_Surface)& S,
646 const TopoDS_Vertex& VF,
647 const TopoDS_Vertex& VL,
648 const Standard_Real f,
649 const Standard_Real l,
650 const Standard_Real Tol3d)
653 Standard_Real Tol1, Tol2, Tol, d;
654 // Class BRep_Tool without fields and without Constructor :
660 P1 = BRep_Tool::Pnt(VF);
661 // Tol1 = BT.Tolerance(VF);
662 Tol1 = BRep_Tool::Tolerance(VF);
664 P2 = BRep_Tool::Pnt(VL);
665 // Tol2 = BT.Tolerance(VF);
666 Tol2 = BRep_Tool::Tolerance(VF);
667 Tol = Max(Tol1, Tol2);
670 (P1.Distance(P2) < Tol ) ) {
674 S->D0(P2d.X(), P2d.Y(), P);
676 if (d > Tol) Tol = d;
678 S->D0(P2d.X(), P2d.Y(), P);
680 if (d > Tol) Tol = d;
682 B.UpdateVertex(VF, Tol);
683 B.UpdateVertex(VL, Tol);
686 B.UpdateEdge(E,C2d,S,TopLoc_Location(), Tol);
690 B.Degenerated(E, Standard_True);
698 B.UpdateVertex(VF, d);
701 P1 = BRep_Tool::Pnt(VL);
705 B.UpdateVertex(VL, d);
707 BRepLib_MakeEdge MkE (C3d, VF, VL, f, l);
708 if (!MkE.IsDone()) { // Error of construction !!
711 sprintf(name,"firstvertex_error");
712 DBRep::Set(name, VF);
713 sprintf(name,"lastvertex_error");
714 DBRep::Set(name, VL);
715 sprintf(name,"curve3d_error");
717 DrawTrSurf::Set(Temp, C3d);
718 // DrawTrSurf::Set(name, C3d);
719 Standard_ConstructionError::Raise("BRepFill_Sweep::BuildEdge");
725 B.UpdateEdge(E, C2d, S, Loc, Tol3d);
731 //=======================================================================
733 //Objet : Construct the faces of filling
734 //=======================================================================
735 static Standard_Boolean Filling(const TopoDS_Shape& EF,
736 const TopoDS_Shape& F1,
737 const TopoDS_Shape& EL,
738 const TopoDS_Shape& F2,
739 TopTools_DataMapOfShapeShape& EEmap,
740 const Standard_Real Tol,
742 const gp_Vec& TangentOnPart1,
748 // Class BRep_Tool without fields and without Constructor :
750 // Standard_Integer NbInt =0;
751 // Standard_Real Tol3d = Tol;
752 Standard_Boolean WithE3, WithE4;
754 // Return constraints
755 TopoDS_Vertex V1, V2, Vf, Vl;
756 TopoDS_Edge E1, E2, E3, E4;
757 E1 = TopoDS::Edge(EF);
758 E2 = TopoDS::Edge(EL);
760 TopExp::Vertices(E1, Vf, Vl);
761 Vf.Orientation(TopAbs_FORWARD);
762 Vl.Orientation(TopAbs_FORWARD);
764 TopExp::Vertices(E2, V1, V2);
765 V1.Orientation(TopAbs_REVERSED);
766 V2.Orientation(TopAbs_REVERSED);
771 WithE3 = WithE4 = Standard_False;
773 if ((!Aux1.IsNull()) && (!Vf.IsSame(V1))) {
775 // E3 = TopoDS::Edge(Aux1);
776 WithE3 = Standard_True;
784 else if (!Aux2.IsNull() && (!Vl.IsSame(V2))) {
786 // E4 = TopoDS::Edge(Aux2);
787 WithE4 = Standard_True;
792 DBRep::Set("Fill_Edge1", E1);
793 DBRep::Set("Fill_Edge2", E2);
795 DBRep::Set("Fill_Edge3", E3);
797 DBRep::Set("Fill_Edge4", E4);
801 // Construction of a surface of revolution
802 Handle(Geom_Curve) Prof1, Prof2;
803 //Standard_Integer ii, jj;//, Nb;
804 Standard_Real f1, f2, l1, l2,/*d1, d2,*/ Angle;//, Eps = 1.e-9;
805 // Prof1 = BT.Curve(E1, f1, l1);
806 Prof1 = BRep_Tool::Curve(E1, f1, l1);
807 // Prof2 = BT.Curve(E2, f2, l2);
808 Prof2 = BRep_Tool::Curve(E2, f2, l2);
812 Tf.SetTransformation(Axe);
814 // Choose the angle of opening
815 P1 = Prof1->Value((f1+l1)/2);
816 P2 = Prof2->Value((f2+l2)/2);
819 p1.SetCoord(P1.Z(), P1.X());
820 p2.SetCoord(P2.Z(), P2.X());
821 gp_Vec2d v1(gp::Origin2d(), p1);
822 gp_Vec2d v2(gp::Origin2d(), p2);
823 if (v1.Magnitude() <= gp::Resolution() ||
824 v2.Magnitude() <= gp::Resolution())
825 return Standard_False;
826 Angle = v1.Angle(v2);
828 gp_Ax1 axe(Axe.Location(), Axe.YDirection());
835 Handle(Geom_SurfaceOfRevolution) Rev =
836 new (Geom_SurfaceOfRevolution) (Prof1, axe);
838 Handle(Geom_Surface) Surf =
839 new (Geom_RectangularTrimmedSurface) (Rev, 0, Angle, f1, l1);
841 // Control the direction of the rotation
842 Standard_Boolean ToReverseResult = Standard_False;
844 d1u = Surf->DN(0, (f1+l1)/2, 1, 0);
845 if (d1u.Angle(TangentOnPart1) > PI/2) { //Invert everything
846 ToReverseResult = Standard_True;
849 Angle = 2*PI - Angle;
850 Rev = new (Geom_SurfaceOfRevolution) (Prof1, axe);
851 Surf = new (Geom_RectangularTrimmedSurface)
852 (Rev, 0, Angle, f1, l1);
858 char* Temp = "Surf_Init" ;
859 DrawTrSurf::Set(Temp, Surf);
863 Handle(Geom2d_Curve) C1, C2, C3, C4;
865 // Deform the surface of revolution.
866 GeomPlate_BuildPlateSurface BPS;
868 Handle(BRepAdaptor_HSurface) AS;
869 Handle(BRepAdaptor_HCurve2d) AC2d;
870 Handle(Adaptor3d_HCurveOnSurface) HConS;
872 Handle(Geom2d_Line) L;
875 L = new (Geom2d_Line) (P2d, gp::DY2d());
876 C1 = new (Geom2d_TrimmedCurve) (L, f1, l1);
878 P2d.SetCoord(Angle,0.);
879 L = new (Geom2d_Line) (P2d, gp::DY2d());
880 C2 = new (Geom2d_TrimmedCurve) (L, f1, l1);
882 // It is required to control the direction and the range.
884 Surf->D0(P2d.X(), P2d.Y(), P1);
886 Surf->D0(P2d.X(), P2d.Y(), P2);
888 P = BRep_Tool::Pnt(V1);
889 if (P.Distance(P2)+Tol < P.Distance(P1)) {
890 // E2 is parsed in the direction opposite to E1
897 GeomLib::SameRange(Precision::PConfusion(), C2,
898 C2->FirstParameter(),
903 Standard_Boolean pointu_f, pointu_l;
905 P1 = BRep_Tool::Pnt(Vf);
907 P2 = BRep_Tool::Pnt(V1);
908 // pointu_f = Vf.IsSame(V1) || (P1.Distance(P2) < BT.Tolerance(Vf));
909 pointu_f = Vf.IsSame(V1) || (P1.Distance(P2) < BRep_Tool::Tolerance(Vf));
911 P1 = BRep_Tool::Pnt(Vl);
913 P2 = BRep_Tool::Pnt(V2);
914 // pointu_l = Vl.IsSame(V2) || (P1.Distance(P2) < BT.Tolerance(Vl));
915 pointu_l = Vl.IsSame(V2) || (P1.Distance(P2) < BRep_Tool::Tolerance(Vl));
919 L = new (Geom2d_Line) (P2d, gp::DX2d());
920 C3 = new (Geom2d_TrimmedCurve) (L, 0, Angle);
924 L = new (Geom2d_Line) (P2d, gp::DX2d());
925 C4 = new (Geom2d_TrimmedCurve) (L, 0, Angle);
927 // Determine the constraints and
928 // their parametric localisation.
930 AS = new BRepAdaptor_HSurface(TopoDS::Face(F1));
931 AC2d = new BRepAdaptor_HCurve2d();
932 AC2d->ChangeCurve2d().Initialize(E1,TopoDS::Face(F1));
933 HConS = new (Adaptor3d_HCurveOnSurface)();
934 HConS->ChangeCurve().Load(AC2d);
935 HConS->ChangeCurve().Load(AS);
937 Handle(BRepFill_CurveConstraint) Cont
938 = new BRepFill_CurveConstraint(HConS, 1, 15);
939 Cont->SetCurve2dOnSurf(C1);
942 NbInt = HConS->NbIntervals(GeomAbs_CN);
946 AS = new BRepAdaptor_HSurface(TopoDS::Face(F2));
947 AC2d = new BRepAdaptor_HCurve2d();
948 AC2d->ChangeCurve2d().Initialize(E2,TopoDS::Face(F2));
949 HConS = new (Adaptor3d_HCurveOnSurface);
951 HConS->ChangeCurve().Load(AC2d);
952 HConS->ChangeCurve().Load(AS);
954 Handle(BRepFill_CurveConstraint) Cont
955 = new BRepFill_CurveConstraint(HConS, 1, 15);
956 Cont->SetCurve2dOnSurf(C2);
961 Handle(BRepAdaptor_HCurve) AC = new (BRepAdaptor_HCurve) (E3);
962 Handle(BRepFill_CurveConstraint) Cont
963 = new BRepFill_CurveConstraint(AC, 0);
964 Cont->SetCurve2dOnSurf(C3);
968 Standard_Real delta = Angle / 11;
970 P = BRep_Tool::Pnt(Vf);
971 Handle(GeomPlate_PointConstraint) PC;
972 for (ii=1; ii<=10; ii++) {
973 C3->D0(ii*delta, P2d);
974 PC = new (GeomPlate_PointConstraint) (P, 0);
975 PC->SetPnt2dOnSurf(P2d);
982 Handle(BRepAdaptor_HCurve) AC = new (BRepAdaptor_HCurve) (E4);
983 Handle(BRepFill_CurveConstraint) Cont
984 = new BRepFill_CurveConstraint(AC, 0);
985 Cont->SetCurve2dOnSurf(C4);
989 Standard_Real delta = Angle / 11;
991 P = BRep_Tool::Pnt(Vl);
992 Handle(GeomPlate_PointConstraint) PC;
993 for (ii=1; ii<=10; ii++) {
994 C4->D0(ii*delta, P2d);
995 PC = new (GeomPlate_PointConstraint) (P, 0);
996 PC->SetPnt2dOnSurf(P2d);
1001 BPS.LoadInitSurface(Surf);
1004 // Controle s'il y a une deformation effective
1005 Handle(GeomPlate_Surface) plate;
1006 plate = BPS.Surface();
1007 plate->SetBounds(0, Angle, f1, l1);
1008 Standard_Boolean Ok=Standard_True;
1012 for (ii=0; ii<=5 && Ok; ii++) {
1014 for (jj=0; jj<=5 && Ok; jj++) {
1016 plate->D0(u, v, P1);
1018 Ok = (P2.IsEqual(P1, Tol));
1024 // Approx de la plate surface
1025 // Bords naturelles => pas besoin de criteres.
1026 GeomConvert_ApproxSurface App(BPS.Surface(),
1028 GeomAbs_C1, GeomAbs_C1,
1030 if (!App.HasResult()) {
1032 cout << "Filling_Approx : Pas de resultat" << endl;
1034 return Standard_False;
1037 cout << "Filling_Approx Error 3d = " <<
1038 App.MaxError() << endl;
1040 Surf = App.Surface();
1041 Tol3d = App.MaxError();
1046 TopLoc_Location Loc;
1047 Handle(Geom_Curve) C3d;
1048 B.UpdateEdge(E1, C1, Surf, Loc, /*Tol3d*/Precision::Confusion());
1049 B.UpdateEdge(E2, C2, Surf, Loc, /*Tol3d*/Precision::Confusion());
1051 if (E3.IsSame(E4)) {
1054 C3d = Surf->VIso(f1);
1055 E3 = BuildEdge(C3d, C3, Surf, Vf, V1, 0, Angle, /*Tol3d*/Precision::Confusion());
1059 BRepAdaptor_Curve aCurve(E3);
1060 Standard_Real AngleOld = aCurve.LastParameter();
1061 if (Angle > AngleOld)
1063 B.Range( E3, 0, Angle );
1064 TopoDS_Vertex V (TopExp::LastVertex(E3));
1065 Handle(BRep_TVertex)& TVlast = *((Handle(BRep_TVertex)*) &V.TShape());
1066 TVlast->Tolerance( Precision::Confusion() );
1070 B.UpdateEdge(E3, C3, C4, Surf, Loc, /*Tol3d*/Precision::Confusion());
1077 C3d = Surf->VIso(f1);
1078 E3 = BuildEdge(C3d, C3, Surf, Vf, V1, 0, Angle, /*Tol3d*/Precision::Confusion());
1082 BRepAdaptor_Curve aCurve(E3);
1083 Standard_Real AngleOld = aCurve.LastParameter();
1084 if (Angle > AngleOld)
1086 B.Range( E3, 0, Angle );
1087 TopoDS_Vertex V(TopExp::LastVertex(E3));
1088 Handle(BRep_TVertex)& TVlast = *((Handle(BRep_TVertex)*) &V.TShape());
1089 TVlast->Tolerance( Precision::Confusion() );
1092 B.UpdateEdge(E3, C3, Surf, Loc, /*Tol3d*/Precision::Confusion());
1097 C3d = Surf->VIso(l1);
1098 E4 = BuildEdge(C3d, C4, Surf, Vl, V2, 0, Angle, /*Tol3d*/Precision::Confusion());
1102 BRepAdaptor_Curve aCurve(E4);
1103 Standard_Real AngleOld = aCurve.LastParameter();
1104 if (Angle > AngleOld)
1106 B.Range( E4, 0, Angle );
1107 TopoDS_Vertex V (TopExp::LastVertex(E4));
1108 Handle(BRep_TVertex)& TVlast = *((Handle(BRep_TVertex)*)&V.TShape());
1109 TVlast->Tolerance( Precision::Confusion() );
1112 B.UpdateEdge(E4, C4, Surf, Loc, /*Tol3d*/Precision::Confusion());
1117 BuildFace(Surf,E1, E3, E2, E4, EEmap,
1118 Standard_False, Standard_False,
1121 // Set the continuities.
1122 B.Continuity(E1, TopoDS::Face(F1), Result, GeomAbs_G1);
1123 B.Continuity(E2, TopoDS::Face(F2), Result, GeomAbs_G1);
1125 // Render the calculated borders.
1126 // if (!BT.Degenerated(E3))
1127 if (!BRep_Tool::Degenerated(E3))
1130 B.MakeEdge(Aux1); //Nullify
1132 // if (!BT.Degenerated(E4))
1133 if (!BRep_Tool::Degenerated(E4))
1138 // Set the orientation
1139 gp_Vec D1U, D1V, N1, N2;
1140 C1->D0( (f1+l1)/2, P2d);
1141 Surf->D1(P2d.X(), P2d.Y(), P, D1U, D1V);
1144 // C1 = BT.CurveOnSurface(E1, TopoDS::Face(F1), f2, l2);
1145 C1 = BRep_Tool::CurveOnSurface(E1, TopoDS::Face(F1), f2, l2);
1146 C1->D0( (f1+l1)/2, P2d);
1147 Handle(BRepAdaptor_HSurface) AS = new BRepAdaptor_HSurface(TopoDS::Face(F1));
1148 AS->D1(P2d.X(), P2d.Y(), P, D1U, D1V);
1151 if ( (F1.Orientation() == TopAbs_REVERSED) ^ (N1.Angle(N2)>PI/2) )
1152 Result.Orientation(TopAbs_REVERSED);
1153 else Result.Orientation(TopAbs_FORWARD);
1155 if (ToReverseResult)
1159 if (Affich) DBRep::Set("BoucheTrou", Result);
1162 return Standard_True;
1165 //=======================================================================
1166 //function : Substitute
1168 //=======================================================================
1169 static void Substitute(BRepTools_Substitution& aSubstitute,
1170 const TopoDS_Edge& Old,
1171 const TopoDS_Edge& New)
1173 TopTools_ListOfShape listShape;
1175 TopoDS_Vertex OldV1, OldV2, NewV1, NewV2;
1176 TopExp::Vertices( Old, OldV1, OldV2 );
1177 TopExp::Vertices( New, NewV1, NewV2 );
1179 if (!aSubstitute.IsCopied( OldV1 ))
1181 listShape.Append( NewV1.Oriented(TopAbs_FORWARD) );
1182 aSubstitute.Substitute( OldV1, listShape );
1185 if (!aSubstitute.IsCopied( OldV2 ))
1187 listShape.Append( NewV2.Oriented(TopAbs_FORWARD) );
1188 aSubstitute.Substitute( OldV2, listShape );
1191 if (!aSubstitute.IsCopied( Old ))
1193 listShape.Append( New.Oriented(TopAbs_FORWARD) );
1194 aSubstitute.Substitute( Old, listShape );
1198 //=======================================================================
1199 //Function : SetCommonEdgeInFace
1200 //Purpose : Replace an edge of the face by the corresponding edge from
1202 //=======================================================================
1204 static void SetCommonEdgeInFace(BRepTools_Substitution& aSubstitute,
1205 const TopoDS_Shape& Face,
1206 const TopoDS_Shape& Edge)
1211 Standard_Boolean done = Standard_False;
1212 // Class BRep_Tool without fields and without Constructor :
1215 TopExp_Explorer Exp(Face, TopAbs_EDGE);
1216 Handle(Geom_Curve) Cref, C;
1217 TopLoc_Location Lref, L;
1218 // Cref = BT.Curve(TopoDS::Edge(Edge), Lref, f, l);
1219 const TopoDS_Edge& NewEdge = TopoDS::Edge(Edge);
1220 Cref = BRep_Tool::Curve( NewEdge, Lref, f, l );
1222 for ( ; Exp.More() && !done; Exp.Next()) {
1223 // C = BT.Curve(TopoDS::Edge(Exp.Current()), L, f, l);
1224 const TopoDS_Edge& OldEdge = TopoDS::Edge(Exp.Current());
1225 C = BRep_Tool::Curve(OldEdge, L, f, l);
1226 if ((Cref==C) && (Lref == L)) {
1227 done = Standard_True;
1228 Substitute( aSubstitute, OldEdge, NewEdge );
1232 if (!done) cout << "Substitution of Edge failed" << endl;
1237 //=======================================================================
1238 //Fonction : KeepEdge
1239 //Objet : Find edges of the face supported by the same Curve.
1240 //=======================================================================
1241 static void KeepEdge(const TopoDS_Shape& Face,
1242 const TopoDS_Shape& Edge,
1243 TopTools_ListOfShape& List)
1246 // Class BRep_Tool without fields and without Constructor :
1249 TopExp_Explorer Exp(Face, TopAbs_EDGE);
1250 Handle(Geom_Curve) Cref, C;
1251 TopLoc_Location Lref, L;
1252 // Cref = BT.Curve(TopoDS::Edge(Edge), Lref, f, l);
1253 Cref = BRep_Tool::Curve(TopoDS::Edge(Edge), Lref, f, l);
1255 for ( ; Exp.More(); Exp.Next()) {
1256 // C = BT.Curve(TopoDS::Edge(Exp.Current()), L, f, l);
1257 C = BRep_Tool::Curve(TopoDS::Edge(Exp.Current()), L, f, l);
1258 if ((Cref==C) && (Lref == L)) {
1259 List.Append(Exp.Current());
1264 //=======================================================================
1266 //Objet : Construct a vertex via an iso
1267 //=======================================================================
1268 static void BuildVertex(const Handle(Geom_Curve)& Iso,
1269 const Standard_Boolean isfirst,
1270 const Standard_Real First,
1271 const Standard_Real Last,
1272 TopoDS_Shape& Vertex)
1277 if (isfirst) val = First;
1279 B.MakeVertex(TopoDS::Vertex(Vertex),
1281 Precision::Confusion());
1284 //=======================================================================
1286 //Objet : Construct an empty edge
1287 //=======================================================================
1288 static TopoDS_Edge NullEdge(TopoDS_Shape& Vertex)
1293 Vertex.Orientation(TopAbs_FORWARD);
1295 B.Add(E, Vertex.Reversed());
1296 B.Degenerated(E, Standard_True);
1301 //=======================================================================
1303 //Objet : Construct an edge via an iso
1304 //=======================================================================
1305 static TopoDS_Edge BuildEdge(const Handle(Geom_Surface)& S,
1306 const Standard_Boolean isUiso,
1307 const Standard_Real ValIso,
1308 const TopoDS_Shape& VFirst,
1309 const TopoDS_Shape& VLast,
1310 const Standard_Real Tol)
1314 Handle(Geom_Curve) Iso;
1315 Standard_Boolean sing = Standard_False;
1317 Iso = S->UIso(ValIso);
1320 Iso = S->VIso(ValIso);
1323 if (VFirst.IsSame(VLast)) { // Singular case ?
1325 // Class BRep_Tool without fields and without Constructor :
1327 const TopoDS_Vertex& V = TopoDS::Vertex(VFirst);
1328 // Standard_Real tol = BT.Tolerance(V);
1329 Standard_Real tol = BRep_Tool::Tolerance(V);
1330 if (Tol > tol) tol = Tol;
1331 Iso->D0((Iso->FirstParameter()+Iso->LastParameter())/2, P);
1332 // if (P.Distance(BT.Pnt(V)) < tol) {
1333 if (P.Distance(BRep_Tool::Pnt(V)) < tol) {
1334 GeomAdaptor_Curve AC(Iso);
1335 sing = GCPnts_AbscissaPoint::Length(AC, tol/4) < tol;
1340 if (sing) { // Singular case
1345 // B.UpdateEdge(E, Iso, Precision::Confusion());
1346 B.Degenerated(E, Standard_True);
1350 // Construction Via 3d
1352 // Iso = S->UIso(ValIso);
1354 Standard_Real p1, p2, p11, p12, p21, p22;
1355 Standard_Boolean fwd = Standard_False;
1356 p1 = Iso->FirstParameter();
1357 p2 = Iso->LastParameter();
1358 P1 = Iso->Value(p1);
1359 P2 = Iso->Value(p2);
1361 Standard_Real t1 = BRep_Tool::Tolerance(TopoDS::Vertex(VFirst));
1362 Standard_Real t2 = BRep_Tool::Tolerance(TopoDS::Vertex(VLast));
1366 p11 = P1.Distance(BRep_Tool::Pnt(TopoDS::Vertex(VFirst)));
1367 p22 = P2.Distance(BRep_Tool::Pnt(TopoDS::Vertex(VLast)));
1368 p12 = P1.Distance(BRep_Tool::Pnt(TopoDS::Vertex(VLast)));
1369 p21 = P2.Distance(BRep_Tool::Pnt(TopoDS::Vertex(VFirst)));
1371 if(p11 < p12 && p22 < p21) fwd = Standard_True;
1373 if(fwd) { //OCC500(apo)
1374 if (p11 >= t1) BB.UpdateVertex(TopoDS::Vertex(VFirst), 1.01*p11);
1375 if (p22 >= t2) BB.UpdateVertex(TopoDS::Vertex(VLast), 1.01*p22);
1378 // Iso = S->VIso(ValIso);
1379 if (p12 >= t2) BB.UpdateVertex(TopoDS::Vertex(VLast), 1.01*p12);
1380 if (p21 >= t1) BB.UpdateVertex(TopoDS::Vertex(VFirst), 1.01*p21);
1383 BRepLib_MakeEdge MkE;
1386 // TopoDS::Vertex(VFirst),
1387 // TopoDS::Vertex(VLast),
1388 // Iso->FirstParameter(),
1389 // Iso->LastParameter());
1392 TopoDS::Vertex(VFirst),
1393 TopoDS::Vertex(VLast),
1394 Iso->FirstParameter(),
1395 Iso->LastParameter());
1398 TopoDS::Vertex(VLast),
1399 TopoDS::Vertex(VFirst),
1400 Iso->FirstParameter(),
1401 Iso->LastParameter());
1403 // if (!MkE.IsDone()) { // Il faut peut etre permuter les Vertex
1405 // TopoDS::Vertex(VLast),
1406 // TopoDS::Vertex(VFirst),
1407 // Iso->FirstParameter(),
1408 // Iso->LastParameter());
1411 if (!MkE.IsDone()) { // Erreur de construction !!
1414 sprintf(name,"firstvertex_error");
1415 DBRep::Set(name, VFirst);
1416 sprintf(name,"lastvertex_error");
1417 DBRep::Set(name, VLast);
1418 sprintf(name,"curve3d_error");
1420 DrawTrSurf::Set(Temp,Iso);
1421 // DrawTrSurf::Set(name,Iso);
1423 Standard_ConstructionError::Raise("BRepFill_Sweep::BuildEdge");
1430 Handle(Geom2d_Line) L;
1431 TopLoc_Location Loc;
1433 gp_Pnt2d P(ValIso, 0);
1435 L = new (Geom2d_Line) (P, V);
1438 gp_Pnt2d P(0., ValIso);
1440 L = new (Geom2d_Line) (P, V);
1443 B.UpdateEdge(E, L, S, Loc, Precision::Confusion());
1444 if (sing) B.Range(E, S, Loc,
1445 Iso->FirstParameter(),
1446 Iso->LastParameter());
1451 //=======================================================================
1453 //Objet : Complete an edge via an iso
1454 //=======================================================================
1455 static void UpdateEdge(TopoDS_Edge& E,
1456 const Handle(Geom_Surface)& S,
1457 const Standard_Boolean isUiso,
1458 const Standard_Real ValIso)
1461 Handle(Geom2d_Line) L;
1462 Handle(Geom2d_Curve) PCurve, CL;
1463 TopLoc_Location Loc;
1464 Standard_Real UFirst, ULast, VFirst, VLast, F2d, L2d;
1465 S->Bounds( UFirst, ULast, VFirst, VLast);
1467 Standard_Boolean sing = Standard_False;
1468 Handle(Geom_Curve) Iso;
1470 Iso = S->UIso(ValIso);
1473 Iso = S->VIso(ValIso);
1476 TopoDS_Vertex Vf, Vl;
1477 TopExp::Vertices(E, Vf, Vl);
1478 if (Vf.IsSame(Vl)) { // Singular case ?
1480 Standard_Real tol = BRep_Tool::Tolerance(Vf);
1481 Iso->D0((Iso->FirstParameter()+Iso->LastParameter())/2, Pmid);
1482 if (Pmid.Distance(BRep_Tool::Pnt(Vf)) < tol) {
1483 GeomAdaptor_Curve AC(Iso);
1484 sing = GCPnts_AbscissaPoint::Length(AC, tol/4) < tol;
1489 gp_Pnt2d P(ValIso, 0);
1491 L = new (Geom2d_Line) (P, V);
1496 gp_Pnt2d P(0., ValIso);
1498 L = new (Geom2d_Line) (P, V);
1502 CL = new (Geom2d_TrimmedCurve) (L, F2d, L2d);
1504 // Control direction & Range
1505 Standard_Real R, First, Last, Tol=1.e-4;
1506 Standard_Boolean reverse = Standard_False;;
1509 // Class BRep_Tool without fields and without Constructor :
1513 // BT.Range(E, First, Last);
1514 BRep_Tool::Range(E, First, Last);
1516 if (!Vf.IsSame(Vl)) {
1517 // Test distances between "FirstPoint" and "Vertex"
1518 P2d = CL->Value(F2d);
1519 POnS = S->Value(P2d.X(), P2d.Y());
1520 // reverse = POnS.Distance(BT.Pnt(Vl)) < POnS.Distance(BT.Pnt(Vf));
1521 reverse = POnS.Distance(BRep_Tool::Pnt(Vl)) < POnS.Distance(BRep_Tool::Pnt(Vf));
1524 // Test angle between "First Tangente"
1526 gp_Vec V3d, du, dv, dC3d;
1527 BRepAdaptor_Curve C3d(E);
1529 C3d.D1(First, POnS, dC3d);
1530 CL->D1(F2d, P2d, V2d);
1531 S->D1(P2d.X(), P2d.Y(), POnS, du, dv);
1532 V3d.SetLinearForm(V2d.X(), du, V2d.Y(), dv);
1533 reverse = ( dC3d.Angle(V3d) > Tol);
1535 if (reverse ) { // Return curve 2d
1536 CL = new (Geom2d_TrimmedCurve)(L, F2d, L2d);
1538 F2d = CL->FirstParameter();
1539 L2d = CL->LastParameter();
1544 Handle(Geom_Curve) NullCurve;
1545 B.UpdateEdge(E, NullCurve, 0.);
1546 B.Degenerated(E, Standard_True);
1547 B.Range(E, F2d, L2d);
1552 if (First != F2d || Last != L2d) {
1553 Handle(Geom2d_Curve) C2d;
1554 GeomLib::SameRange(Precision::PConfusion(), CL,
1555 F2d, L2d, First, Last,
1557 CL = new (Geom2d_TrimmedCurve)(C2d, First, Last);
1560 // Update des Vertex
1564 P2d = CL->Value(First);
1565 POnS = S->Value(P2d.X(), P2d.Y());
1566 V = TopExp::FirstVertex(E);
1567 // R = POnS.Distance(BT.Pnt(V));
1568 R = POnS.Distance(BRep_Tool::Pnt(V));
1569 B.UpdateVertex(V, R);
1571 P2d = CL->Value(Last);
1572 POnS = S->Value(P2d.X(), P2d.Y());
1573 V = TopExp::LastVertex(E);
1574 // R = POnS.Distance(BT.Pnt(V));
1575 R = POnS.Distance(BRep_Tool::Pnt(V));
1576 B.UpdateVertex(V, R);
1579 if (!sing && SameParameter(E, CL, S, Tol, R)) {
1583 PCurve = Couture(E, S, Loc);
1584 if (PCurve.IsNull())
1585 B.UpdateEdge(E, CL, S, Loc, Precision::Confusion());
1586 else { // Sewing edge
1589 if (e.Orientation() == TopAbs_REVERSED)
1590 B.UpdateEdge(E, CL, PCurve, S, Loc, Precision::Confusion());
1592 B.UpdateEdge(E, PCurve, CL, S, Loc, Precision::Confusion());
1595 // Attention to case not SameRange on its shapes (PRO13551)
1596 // if (!BT.SameRange(E)) B.Range(E, S, Loc, First, Last);
1597 if (!BRep_Tool::SameRange(E)) B.Range(E, S, Loc, First, Last);
1600 //=======================================================================
1601 // Object : Check if a surface is degenerated
1602 //=======================================================================
1603 static Standard_Boolean IsDegen(const Handle(Geom_Surface)& S,
1604 const Standard_Real Tol)
1606 Standard_Integer Nb = 5;
1607 Standard_Boolean B = Standard_True;
1608 Standard_Real Umax, Umin, Vmax, Vmin, t, dt, l;
1609 Standard_Integer ii;
1610 Handle(Geom_Curve) Iso;
1612 GCPnts_AbscissaPoint GC;
1614 S->Bounds(Umin, Umax, Vmin, Vmax);
1616 // Check the length of Iso-U
1617 t = (Umin + Umax)/2;
1619 S->D0(t, (Vmin+Vmax)/2, P2);
1621 B = ((P1.Distance(P2) + P2.Distance(P3)) < Tol);
1623 for (ii=1, dt = (Umax-Umin)/(Nb+1); B && (ii<=Nb); ii++) {
1626 GeomAdaptor_Curve AC(Iso);
1627 l = GC.Length(AC, Tol/4);
1631 if (B) return Standard_True;
1633 // Check the length of Iso-V
1634 t = (Vmin + Vmax)/2;
1636 S->D0((Umin+Umax)/2, t, P2);
1638 B = ((P1.Distance(P2) + P2.Distance(P3)) < Tol);
1641 for (ii=1, dt = (Vmax-Vmin)/(Nb+1); B && (ii<=Nb); ii++) {
1644 GeomAdaptor_Curve AC(Iso);
1645 l = GC.Length(AC, Tol/4);
1652 //=======================================================================
1653 //function : Constructeur
1655 //======================================================================
1656 BRepFill_Sweep::BRepFill_Sweep(const Handle(BRepFill_SectionLaw)& Section,
1657 const Handle(BRepFill_LocationLaw)& Location,
1658 const Standard_Boolean WithKPart) :
1659 isDone(Standard_False),
1667 SetTolerance(1.e-4);
1668 SetAngularControl();
1671 myApproxStyle = GeomFill_Location;
1672 myContinuity = GeomAbs_C2;
1677 //=======================================================================
1678 //function : SetBounds
1679 //purpose : Define start and end shapes
1680 //======================================================================
1681 void BRepFill_Sweep::SetBounds(const TopoDS_Wire& First,
1682 const TopoDS_Wire& Last)
1687 // It is necessary to check the SameRange on its (PRO13551)
1688 Standard_Boolean issame = Standard_True;
1690 BRepTools_WireExplorer wexp;
1691 if (!FirstShape.IsNull()) {
1692 for (wexp.Init(FirstShape); wexp.More(); wexp.Next()) {
1693 if (!BRepLib::CheckSameRange(wexp.Current())) {
1694 B.SameRange(wexp.Current(), Standard_False);
1695 B.SameParameter(wexp.Current(), Standard_False);
1696 issame = Standard_False;
1701 if (!LastShape.IsNull()) {
1702 for (wexp.Init(LastShape); wexp.More(); wexp.Next()) {
1703 if (!BRepLib::CheckSameRange(wexp.Current())) {
1704 B.SameRange(wexp.Current(), Standard_False);
1705 B.SameParameter(wexp.Current(), Standard_False);
1706 issame = Standard_False;
1713 cout<<"Sweep Warning : Edge not SameRange in the limits"<<endl;
1717 //=======================================================================
1718 //function : SetTolerance
1720 //======================================================================
1721 void BRepFill_Sweep::SetTolerance(const Standard_Real Tol3d,
1722 const Standard_Real BoundTol,
1723 const Standard_Real Tol2d,
1724 const Standard_Real TolAngular)
1727 myBoundTol = BoundTol;
1729 myTolAngular = TolAngular;
1731 //=======================================================================
1732 //function : SetAngularControl
1734 //======================================================================
1735 void BRepFill_Sweep::SetAngularControl(const Standard_Real MinAngle,
1736 const Standard_Real MaxAngle)
1738 myAngMin = Max (MinAngle, Precision::Angular());
1739 myAngMax = Min (MaxAngle, 6.28);
1742 ///=======================================================================
1743 //function : CorrectApproxParameters
1745 //=======================================================================
1746 Standard_Boolean BRepFill_Sweep::CorrectApproxParameters()
1748 TopoDS_Wire thePath = myLoc->Wire();
1749 GeomAbs_Shape NewCont = myContinuity;
1750 Standard_Integer NewSegmax = mySegmax;
1752 TopoDS_Iterator iter(thePath);
1753 for (; iter.More(); iter.Next())
1755 TopoDS_Edge anEdge = TopoDS::Edge(iter.Value());
1756 BRepAdaptor_Curve aBAcurve(anEdge);
1757 GeomAbs_Shape aContinuity = aBAcurve.Continuity();
1758 Standard_Integer aNbInterv = aBAcurve.NbIntervals(GeomAbs_CN);
1759 if (aContinuity < NewCont)
1760 NewCont = aContinuity;
1761 if (aNbInterv > NewSegmax)
1762 NewSegmax = aNbInterv;
1765 Standard_Boolean Corrected = Standard_False;
1766 if (NewCont != myContinuity || NewSegmax != mySegmax)
1767 Corrected = Standard_True;
1768 myContinuity = NewCont;
1769 mySegmax = NewSegmax;
1773 //=======================================================================
1774 //function : BuildWire
1775 //purpose : Construit a wire by sweeping
1776 //======================================================================
1777 Standard_Boolean BRepFill_Sweep::
1778 BuildWire(const BRepFill_TransitionStyle /*Transition*/)
1780 Standard_Integer ipath, isec = 1;
1784 // Class BRep_Tool without fields and without Constructor :
1786 Standard_Integer NbPath = myLoc->NbLaw();
1787 Standard_Boolean vclose;
1788 vclose = (myLoc->IsClosed() && (myLoc->IsG1(0, myTol3d)>= 0));
1790 Handle(Geom_Surface) S;
1791 Handle(Geom_Curve) Iso;
1792 Standard_Real val, bid, First, Last, Tol;
1798 // (1) Construction of all curves
1800 // (1.1) Construction of Tables
1801 myFaces = new (TopTools_HArray2OfShape) (1, 1, 1, NbPath);
1802 myUEdges = new (TopTools_HArray2OfShape) (1, 2, 1, NbPath);
1803 myVEdges = new (TopTools_HArray2OfShape) (1, 1, 1, NbPath+1);
1805 // (1.2) Calculate curves / vertex / edge
1806 for (ipath=1; ipath <=NbPath; ipath++) {
1807 // Curve by iso value
1808 GeomFill_Sweep Sweep(myLoc->Law(ipath), KPart);
1809 Sweep.SetTolerance(myTol3d, myBoundTol, myTol2d, myTolAngular);
1810 Sweep.Build(mySec->Law(isec), myApproxStyle, myContinuity, myDegmax, mySegmax);
1811 if (!Sweep.IsDone())
1812 return Standard_False;
1813 S = Sweep.Surface();
1814 if (Sweep.ExchangeUV()) {
1815 if (Sweep.UReversed()) S->Bounds(First, Last, bid, val);
1816 else S->Bounds(First, Last, val, bid);
1820 if (Sweep.UReversed()) S->Bounds(bid, val, First, Last);
1821 else S->Bounds(val, bid, First, Last);
1824 // Vertex by position
1826 BuildVertex(Iso, Standard_False, First, Last,
1827 myVEdges->ChangeValue(1, ipath+1));
1830 TopoDS_Vertex& V = TopoDS::Vertex(myVEdges->ChangeValue(1, 1));
1831 myVEdges->SetValue(1, ipath+1, V);
1833 // Tol = P1.Distance(BT.Pnt(V));
1834 Tol = P1.Distance(BRep_Tool::Pnt(V));
1835 B.UpdateVertex(V, Tol);
1838 if (!LastShape.IsNull()) myVEdges->SetValue(1, NbPath, FirstShape);
1839 else BuildVertex(Iso, Standard_False, First, Last,
1840 myVEdges->ChangeValue(1, NbPath+1));
1846 TopoDS_Vertex& V = TopoDS::Vertex(myVEdges->ChangeValue(1, ipath));
1847 // Tol = P1.Distance(BT.Pnt(V));
1848 Tol = P1.Distance(BRep_Tool::Pnt(V));
1849 B.UpdateVertex(V, Tol);
1852 if (!FirstShape.IsNull()) myVEdges->SetValue(1,1, FirstShape);
1853 else BuildVertex(Iso, Standard_True, First, Last,
1854 myVEdges->ChangeValue(1, 1));
1857 // Construction of the edge
1858 BRepLib_MakeEdge MkE;
1860 TopoDS::Vertex(myVEdges->Value(1, ipath)),
1861 TopoDS::Vertex(myVEdges->Value(1, ipath+1)),
1862 Iso->FirstParameter(),
1863 Iso->LastParameter());
1864 if (!MkE.IsDone()) { // Error of construction !!
1867 sprintf(name,"firstvertex_error");
1868 DBRep::Set(name, myVEdges->Value(1, ipath));
1869 sprintf(name,"lastvertex_error");
1870 DBRep::Set(name, myVEdges->Value(1, ipath+1));
1871 sprintf(name,"curve3d_error");
1873 DrawTrSurf::Set(Temp,Iso);
1874 // DrawTrSurf::Set(name,Iso);
1875 Standard_ConstructionError::Raise("BRepFill_Sweep::BuildEdge");
1877 return Standard_False;
1882 sprintf(name,"Surf_%d", ipath);
1884 DrawTrSurf::Set(Temp, S);
1885 // DrawTrSurf::Set(name, S);
1886 sprintf(name,"Edge_%d", ipath);
1887 DBRep::Set(name, E);
1890 B.UpdateEdge(E, Sweep.ErrorOnSurface());
1892 myFaces->SetValue(1, ipath, E);
1895 return Standard_True;
1898 //=======================================================================
1899 //function : BuildShell
1900 //purpose : Construct a Shell by sweeping
1901 //======================================================================
1902 Standard_Boolean BRepFill_Sweep::
1903 BuildShell(const BRepFill_TransitionStyle /*Transition*/,
1904 const Standard_Integer IFirst,
1905 const Standard_Integer ILast,
1906 const Standard_Real ExtendFirst,
1907 const Standard_Real ExtendLast)
1909 Standard_Integer ipath, isec, IPath;
1914 Standard_Integer NbPath = ILast - IFirst;
1915 Standard_Integer NbLaw = mySec->NbLaw();
1916 Standard_Boolean uclose, vclose, constSection, hasdegen = Standard_False;
1917 constSection = mySec->IsConstant();
1918 uclose = mySec->IsUClosed();
1919 vclose = (mySec->IsVClosed() && myLoc->IsClosed()) &&
1920 (NbPath == myLoc->NbLaw()) && (myLoc->IsG1(0, myTol3d)>= 0);
1923 // (1) Construction of all surfaces
1925 // (1.1) Construction of Tables
1927 TColStd_Array2OfInteger ExchUV(1, NbLaw, 1, NbPath);
1928 TColStd_Array2OfInteger UReverse(1, NbLaw, 1, NbPath);
1929 TColStd_Array2OfInteger Degenerated(1, NbLaw, 1, NbPath);
1930 Degenerated.Init(0);
1931 // No VReverse for the moment...
1932 TColStd_Array2OfReal TabErr(1, NbLaw , 1, NbPath);
1933 TColGeom_Array2OfSurface TabS(1, NbLaw , 1, NbPath);
1935 TopTools_Array2OfShape UEdge(1, NbLaw+1, 1, NbPath);
1936 TopTools_Array2OfShape VEdge(1, NbLaw , 1, NbPath+1);
1937 TopTools_Array2OfShape Vertex(1,NbLaw+1, 1, NbPath+1);
1939 TopoDS_Vertex VNULL;
1943 TopTools_Array1OfShape SecVertex(1, NbLaw+1);
1944 TColStd_Array1OfReal VError(1, NbLaw+1);
1945 TColStd_Array1OfReal Vi(1, NbPath+1);
1947 //Initialization of management of parametric intervals
1948 //(Case of evolutionary sections)
1949 Standard_Real Length, SecDom, SecDeb;
1950 myLoc->CurvilinearBounds(myLoc->NbLaw(), SecDom, Length);
1951 mySec->Law(1)->GetDomain(SecDeb, SecDom);
1954 Standard_Real Lf, Ll;
1955 myLoc->CurvilinearBounds(IFirst-1, Lf, Ll);
1956 Vi(1) = SecDeb + (Ll/Length)*SecDom;
1961 // Error a priori on vertices
1963 for (isec=1; isec<=NbLaw+1; isec++) {
1964 VError(isec) = mySec->VertexTol(isec-1, 0.);
1965 SecVertex(isec) = mySec->Vertex(isec, 0.);
1970 // (1.2) Calculate surfaces
1971 for (ipath=1, IPath=IFirst; ipath <=NbPath; ipath++, IPath++) {
1973 GeomFill_Sweep Sweep(myLoc->Law(IPath), KPart);
1974 Sweep.SetTolerance(myTol3d, myBoundTol, myTol2d, myTolAngular);
1976 // Case of evolutionary section, definition of parametric correspondence
1977 if (!constSection) {
1978 Standard_Real lf, ll, Lf, Ll;
1979 myLoc->Law(IPath)->GetDomain(lf, ll);
1980 myLoc->CurvilinearBounds(IPath, Lf, Ll);
1981 Vi(ipath+1) = SecDeb + (Ll/Length)*SecDom;
1982 Sweep.SetDomain(lf, ll, Vi(ipath), Vi(ipath+1));
1984 else //section is constant
1986 Standard_Real lf, ll, Lf, Ll;
1987 myLoc->Law(IPath)->GetDomain(lf, ll);
1988 myLoc->CurvilinearBounds(IPath, Lf, Ll);
1989 Vi(ipath+1) = SecDeb + (Ll/Length)*SecDom;
1992 for(isec=1; isec<=NbLaw; isec++) {
1993 Sweep.Build(mySec->Law(isec), myApproxStyle, myContinuity, myDegmax, mySegmax);
1994 if (!Sweep.IsDone())
1995 return Standard_False;
1996 TabS(isec,ipath) = Sweep.Surface();
1997 TabErr(isec,ipath) = Sweep.ErrorOnSurface();
1998 ExchUV(isec, ipath) = Sweep.ExchangeUV();
1999 UReverse(isec, ipath) = Sweep.UReversed();
2000 if (Sweep.ErrorOnSurface()>Error) Error = Sweep.ErrorOnSurface();
2002 if ((ipath==1)&&(ExtendFirst>0)) {
2003 Handle(Geom_BoundedSurface) BndS;
2004 BndS = Handle(Geom_BoundedSurface)::DownCast(TabS(isec,ipath));
2005 GeomLib::ExtendSurfByLength(BndS, ExtendFirst, 1,
2006 Sweep.ExchangeUV(), Standard_False);
2007 TabS(isec,ipath) = BndS;
2009 if ((ipath==NbPath)&&(ExtendLast>0)){
2010 Handle(Geom_BoundedSurface) BndS;
2011 BndS = Handle(Geom_BoundedSurface)::DownCast(TabS(isec,ipath));
2012 GeomLib::ExtendSurfByLength(BndS, ExtendLast, 1,
2013 Sweep.ExchangeUV(), Standard_True);
2014 TabS(isec,ipath) = BndS;
2019 sprintf(name,"Surf_%d_%d", isec, IPath);
2021 DrawTrSurf::Set(Temp, TabS(isec,ipath));
2027 // (2) Construction of Edges
2028 Standard_Real UFirst, ULast, VFirst, VLast;
2029 Standard_Boolean exuv, singu, singv;
2030 Handle(Geom_Surface) S;
2033 // (2.0) return preexisting Edges and vertices
2035 if (! FirstShape.IsNull() && (IFirst==1)) {
2036 mySec->Init(FirstShape);
2037 for (isec=1; isec<=NbLaw; isec++) {
2038 E = mySec->CurrentEdge();
2040 if (E.Orientation() == TopAbs_REVERSED)
2041 Vertex(isec+1, 1) = TopExp::FirstVertex(E);
2043 Vertex(isec+1, 1) = TopExp::LastVertex(E);
2044 UpdateVertex(IFirst-1, isec+1,
2045 TabErr(isec, 1), Vi(1), Vertex(isec+1, 1));
2047 if (VEdge(1, 1).Orientation() == TopAbs_REVERSED)
2048 Vertex(1, 1) = TopExp::LastVertex(TopoDS::Edge(VEdge(1, 1)));
2050 Vertex(1, 1) = TopExp::FirstVertex(TopoDS::Edge(VEdge(1, 1)));
2051 UpdateVertex(IFirst-1, 1,
2052 TabErr(1, 1), Vi(1), Vertex(1, 1));
2054 else { // Otherwise construct vertices
2055 Standard_Real u, v, aux;
2056 Standard_Boolean ureverse;
2057 for (isec=1; isec<=NbLaw+1; isec++) {
2061 ureverse = UReverse(NbLaw, 1);
2062 exuv = ExchUV(NbLaw, 1);
2066 ureverse = UReverse(isec, 1);
2067 exuv = ExchUV(isec, 1);
2069 S->Bounds(UFirst, ULast, VFirst, VLast);
2071 // Choice of parameters
2074 aux = VFirst; VFirst = VLast; VLast = aux;
2077 aux = UFirst; UFirst = ULast; ULast = aux;
2080 if (isec!= NbLaw+1) {
2095 // construction of vertices
2096 B.MakeVertex(TopoDS::Vertex(Vertex(isec, 1)),
2098 mySec->VertexTol(isec-1,Vi(1)));
2102 if (! LastShape.IsNull() && (ILast==myLoc->NbLaw()+1) ) {
2103 mySec->Init(LastShape);
2104 for (isec=1; isec<=NbLaw; isec++) {
2105 E = mySec->CurrentEdge();
2106 VEdge(isec, NbPath+1) = E;
2107 if (E.Orientation() == TopAbs_REVERSED)
2108 Vertex(isec+1, NbPath+1) = TopExp::FirstVertex(E);
2110 Vertex(isec+1, NbPath+1) = TopExp::LastVertex(E);
2111 UpdateVertex(ILast-1, isec+1, TabErr(isec, NbPath),
2112 Vi(NbPath+1), Vertex(isec+1, NbPath+1));
2114 if (VEdge(1, NbPath+1).Orientation() == TopAbs_REVERSED)
2115 Vertex(1, NbPath+1) =
2116 TopExp::LastVertex(TopoDS::Edge(VEdge(1, NbPath+1)));
2118 Vertex(1, NbPath+1) =
2119 TopExp::FirstVertex(TopoDS::Edge(VEdge(1, NbPath+1)));
2120 UpdateVertex(ILast-1, 1,
2121 TabErr(1, NbPath), Vi(NbPath+1), Vertex(1, NbPath+1 ));
2124 Standard_Real u, v, aux;
2125 Standard_Boolean ureverse;
2126 for (isec=1; isec<=NbLaw+1; isec++) {
2129 S = TabS(NbLaw, NbPath);
2130 ureverse = UReverse(NbLaw, NbPath);
2131 exuv = ExchUV(NbLaw, NbPath);
2134 S = TabS(isec, NbPath);
2135 ureverse = UReverse(isec, NbPath);
2136 exuv = ExchUV(isec, NbPath);
2138 S->Bounds(UFirst, ULast, VFirst, VLast);
2140 // Choice of parametres
2143 aux = VFirst; VFirst = VLast; VLast = aux;
2146 aux = UFirst; UFirst = ULast; ULast = aux;
2149 if (isec == NbLaw+1) {
2164 // construction of vertex
2165 B.MakeVertex(TopoDS::Vertex(Vertex(isec, NbPath+1)),
2167 mySec->VertexTol(isec-1, Vi(NbPath+1)));
2173 // ---------- Creation of Vertex and edge ------------
2174 for (ipath=1, IPath=IFirst; ipath<=NbPath;
2176 for (isec=1; isec <=NbLaw; isec++) {
2177 S = TabS(isec, ipath);
2178 exuv = ExchUV(isec, ipath);
2179 S->Bounds(UFirst, ULast, VFirst, VLast);
2180 if (UReverse(isec, ipath)) {
2183 aux = VFirst; VFirst = VLast; VLast = aux;
2186 aux = UFirst; UFirst = ULast; ULast = aux;
2190 // (2.1) Construction of new vertices
2192 if (ipath == 1 && Vertex(1, 1).IsNull()) {
2195 myLoc->PerformVertex(IPath-1,
2196 TopoDS::Vertex(SecVertex(1)),
2198 TopoDS::Vertex(Vertex(1, 1)));
2200 myLoc->PerformVertex(IPath-1,
2201 mySec->Vertex(1,Vi(1)),
2202 mySec->VertexTol(0,Vi(1)),
2203 TopoDS::Vertex(Vertex(1, 1)));
2205 // the first and the next column
2206 if (vclose &&(ipath == NbPath) ) {
2207 Vertex(1, ipath+1) = Vertex(1, 1);
2209 else if (Vertex(1, ipath+1).IsNull()) {
2211 myLoc->PerformVertex(IPath,
2212 TopoDS::Vertex(SecVertex(1)),
2213 TabErr(1,ipath)+VError(1),
2214 TopoDS::Vertex(Vertex(1, ipath+1)) );
2216 myLoc->PerformVertex(IPath,
2217 mySec->Vertex(1,Vi(ipath+1)),
2219 mySec->VertexTol(0,Vi(ipath+1)),
2220 TopoDS::Vertex(Vertex(1, ipath+1)));
2222 if (MergeVertex(Vertex(1,ipath), Vertex(1,ipath+1))) {
2223 UEdge(1, ipath) = NullEdge(Vertex(1,ipath));
2229 if (uclose && (isec == NbLaw)) {
2230 Vertex(isec+1, 1) = Vertex(1, 1);
2232 else if (Vertex(isec+1, 1).IsNull()) {
2234 myLoc->PerformVertex(IPath-1,
2235 TopoDS::Vertex(SecVertex(isec+1)),
2236 TabErr(isec,1)+VError(isec+1),
2237 TopoDS::Vertex(Vertex(isec+1, 1)) );
2239 myLoc->PerformVertex(IPath-1,
2240 mySec->Vertex(isec+1,Vi(1)),
2242 mySec->VertexTol(isec,Vi(1)),
2243 TopoDS::Vertex(Vertex(isec+1, 1)) );
2244 if (MergeVertex(Vertex(isec,1), Vertex(isec+1,1))) {
2245 VEdge(isec, 1) = NullEdge(Vertex(isec, 1));
2249 if (uclose && (isec == NbLaw)) {
2250 Vertex(isec+1, ipath+1) = Vertex(1, ipath+1);
2252 else if (vclose && (ipath == NbPath)) {
2253 Vertex(isec+1, ipath+1) = Vertex(isec+1, 1);
2255 else if (Vertex(isec+1, ipath+1).IsNull()) {
2257 myLoc->PerformVertex(IPath,
2258 TopoDS::Vertex(SecVertex(isec+1)),
2259 TabErr(isec, ipath)+ VError(isec+1),
2260 TopoDS::Vertex(Vertex(isec+1, ipath+1)) );
2262 myLoc->PerformVertex(IPath,
2263 mySec->Vertex(isec+1,Vi(ipath+1)),
2264 TabErr(isec, ipath) +
2265 mySec->VertexTol(isec, Vi(ipath+1)),
2266 TopoDS::Vertex(Vertex(isec+1, ipath+1)) );
2270 singv = MergeVertex(Vertex(isec,ipath+1), Vertex(isec+1,ipath+1));
2271 singu = MergeVertex(Vertex(isec+1,ipath), Vertex(isec+1,ipath+1));
2275 if (singu || singv) {
2276 Degenerated(isec, ipath) = IsDegen(TabS(isec,ipath),
2277 Max(myTol3d, TabErr(isec,ipath)));
2279 if (Degenerated(isec, ipath)) {
2281 cout << "Sweep : Degenerated case" << endl;
2283 hasdegen = Standard_True;
2284 // Particular construction of edges
2285 if (UEdge(isec+1, ipath).IsNull()) {
2288 UEdge(isec+1, ipath) = NullEdge(Vertex(isec+1,ipath));
2290 else { // Copy the previous edge
2291 UEdge(isec+1, ipath) = UEdge(isec, ipath);
2294 if (VEdge(isec, ipath+1).IsNull()) {
2297 VEdge(isec, ipath+1) = NullEdge(Vertex(isec,ipath+1));
2299 else { // Copy the previous edge
2300 VEdge(isec, ipath+1) = VEdge(isec, ipath);
2304 else { // Construction of edges by isos
2307 UV = UFirst; UFirst = VFirst; VFirst = UV;
2308 UV = ULast ; ULast = VLast ; VLast = UV;
2313 if (!Vertex(1,ipath).IsSame(Vertex(1,ipath+1))) {
2314 gp_Pnt P1 = BRep_Tool::Pnt(TopoDS::Vertex(Vertex(1,ipath)));
2315 gp_Pnt P2 = BRep_Tool::Pnt(TopoDS::Vertex(Vertex(1,ipath+1)));
2316 if (P1.Distance(P2) <= myTol3d)
2317 Vertex(1,ipath+1) = Vertex(1,ipath);
2319 UEdge(1, ipath) = BuildEdge(S, !exuv, UFirst,
2324 else UpdateEdge(TopoDS::Edge(UEdge(isec, ipath)),
2327 if (uclose && (isec==NbLaw)) {
2328 UpdateEdge(TopoDS::Edge(UEdge(1, ipath)),
2330 UEdge(isec+1, ipath) = UEdge(1, ipath);
2333 UEdge(isec+1, ipath) = BuildEdge(S, !exuv, ULast,
2334 Vertex(isec+1, ipath),
2335 Vertex(isec+1, ipath+1),
2340 if (ipath == 1 && VEdge(isec, ipath).IsNull())
2341 VEdge(isec, ipath) = BuildEdge(S, exuv, VFirst,
2346 else UpdateEdge(TopoDS::Edge(VEdge(isec, ipath)),
2349 if (vclose && (ipath == NbPath)) {
2350 UpdateEdge(TopoDS::Edge(VEdge(isec, 1)),
2352 VEdge(isec, ipath+1) = VEdge(isec, 1);
2354 else if (VEdge(isec, ipath+1).IsNull())
2355 VEdge(isec, ipath+1) = BuildEdge(S, exuv, VLast,
2356 Vertex(isec , ipath+1),
2357 Vertex(isec+1, ipath+1),
2359 else UpdateEdge(TopoDS::Edge(VEdge(isec, ipath+1)),
2363 }// End of construction of edges
2366 // (3) Construction of Faces
2371 for (ipath=1, IPath=IFirst; ipath<=NbPath; ipath++, IPath++) {
2372 for (isec=1; isec <=NbLaw+1; isec++){
2373 sprintf(name,"uedge_%d_%d", isec, IPath);
2374 DBRep::Set(name,UEdge(isec, ipath));
2378 for (ipath=1, IPath=IFirst; ipath<=NbPath+1; ipath++, IPath++) {
2379 for (isec=1; isec <=NbLaw; isec++){
2380 sprintf(name,"vedge_%d_%d", isec, IPath);
2381 DBRep::Set(name,VEdge(isec, ipath));
2384 for (isec=1; isec <=NbLaw+1; isec++){
2385 sprintf(name,"vertex_%d_%d", isec, IPath);
2386 DBRep::Set(name,Vertex(isec, ipath));
2392 for (ipath=1, IPath=IFirst; ipath<=NbPath; ipath++, IPath++) {
2393 for (isec=1; isec <=NbLaw; isec++) {
2394 if (Degenerated(isec, ipath)) {
2395 if (UEdge(isec, ipath).IsSame(UEdge(isec+1, ipath)))
2396 myFaces->SetValue(isec, IPath, UEdge(isec, ipath));
2398 myFaces->SetValue(isec, IPath, VEdge(isec, ipath));
2401 BuildFace(TabS(isec,ipath),
2402 TopoDS::Edge(UEdge(isec, ipath)),
2403 TopoDS::Edge(VEdge(isec, ipath)),
2404 TopoDS::Edge(UEdge(isec+1, ipath)),
2405 TopoDS::Edge(VEdge(isec, ipath+1)),
2407 ExchUV(isec, ipath),
2408 UReverse(isec, ipath),
2410 myFaces->SetValue(isec, IPath, face);
2416 // (4) History and Continuity
2419 //(4.1) // Degenerated case => Sledgehammer
2420 TopoDS_Compound Comp;
2421 B.MakeCompound(Comp);
2422 for (isec=1; isec <= NbLaw+1; isec++)
2423 for (ipath=1, IPath=IFirst; ipath<= NbPath+1; ipath++, IPath++) {
2424 if (ipath <= NbPath) myUEdges->SetValue(isec, IPath, UEdge(isec, ipath));
2425 if (isec <= NbLaw) myVEdges->SetValue(isec, IPath, VEdge(isec, ipath));
2426 if ((ipath <= NbPath) && (isec <= NbLaw) &&
2427 (myFaces->Value(isec, IPath).ShapeType() == TopAbs_FACE))
2428 B.Add(Comp, myFaces->Value(isec, IPath));
2430 BRepLib::EncodeRegularity(Comp, myTolAngular);
2433 //(4.2) // General case => Tweezers
2434 Standard_Boolean isG1;
2438 for (isec=1; isec <= NbLaw+1; isec++) {
2440 (mySec->Continuity(isec-1, myTolAngular) >= GeomAbs_G1);
2441 else isG1 = Standard_False;
2442 for (ipath=1, IPath=IFirst; ipath<= NbPath; ipath++, IPath++) {
2443 myUEdges->SetValue(isec, IPath, UEdge(isec, ipath));
2445 if (isec == NbLaw+1) FF = TopoDS::Face(myFaces->Value(1, IPath));
2446 else FF = TopoDS::Face(myFaces->Value(isec, IPath));
2447 B.Continuity(TopoDS::Edge(myUEdges->Value(isec, IPath)),
2448 TopoDS::Face(myFaces->Value(isec-1, IPath)),
2454 Standard_Integer nbpath = NbPath;
2455 if (vclose) nbpath++; //Another test G1
2456 for (ipath=1, IPath=IFirst; ipath<= NbPath+1; ipath++, IPath++) {
2457 if ((ipath > 1) && (ipath <=nbpath))
2458 isG1 = (myLoc->IsG1(IPath-1, myTol3d, myTolAngular) >= 0);
2459 else isG1 = Standard_False;
2460 for (isec=1; isec <= NbLaw; isec++) {
2461 myVEdges->SetValue(isec, IPath, VEdge(isec, ipath));
2463 if (ipath==NbPath+1) FF = TopoDS::Face(myFaces->Value(isec, 1));
2464 else FF = TopoDS::Face(myFaces->Value(isec, IPath));
2465 E = TopoDS::Edge(myVEdges->Value(isec, IPath));
2466 BRepLib::EncodeRegularity(E, FF,
2467 TopoDS::Face(myFaces->Value(isec, IPath-1)),
2473 return Standard_True;
2476 //=======================================================================
2478 //purpose : Construt the result of sweeping
2479 //======================================================================
2480 void BRepFill_Sweep::Build(const BRepFill_TransitionStyle Transition,
2481 const GeomFill_ApproxStyle Approx,
2482 const GeomAbs_Shape Continuity,
2483 const Standard_Integer Degmax,
2484 const Standard_Integer Segmax)
2486 myApproxStyle = Approx;
2487 myContinuity = Continuity;
2491 CorrectApproxParameters();
2494 if (mySec->IsVertex()) isDone = BuildWire(Transition);
2497 Standard_Integer NbTrous = myLoc->NbHoles(myTol3d),
2498 NbPath = myLoc->NbLaw(),
2499 NbLaw = mySec->NbLaw(), ii, jj, NbPart=1;
2500 Standard_Integer ipath, isec;
2502 myUEdges = new (TopTools_HArray2OfShape) (1, NbLaw+1, 1, NbPath);
2503 myVEdges = new (TopTools_HArray2OfShape) (1, NbLaw, 1, NbPath+1);
2504 myFaces = new (TopTools_HArray2OfShape) (1, NbLaw, 1, NbPath);
2505 Handle (TopTools_HArray2OfShape) Bounds =
2506 new (TopTools_HArray2OfShape) (1, NbLaw, 1, 2);
2508 Handle(TColStd_HArray1OfInteger) Trous;
2510 if (NbTrous>0) { // How many sub-parts ?
2511 Trous = new (TColStd_HArray1OfInteger) (1, NbTrous);
2512 myLoc->Holes(Trous->ChangeArray1());
2514 if (Trous->Value(NbTrous) == NbPath+1) NbPart--;
2516 if (NbPart == 1) { // This is done at once
2517 Standard_Real Extend = 0.0;
2518 if (NbTrous==1) Extend = EvalExtrapol(1, Transition);
2519 isDone = BuildShell(Transition,
2523 else { // This is done piece by piece
2524 Standard_Integer IFirst = 1, ILast;
2525 for (ii=1, isDone=Standard_True;
2526 ii<=NbPart && isDone; ii++) {
2527 if (ii > NbTrous) ILast = NbPath+1;
2528 else ILast = Trous->Value(ii);
2529 isDone = BuildShell(Transition,
2531 EvalExtrapol(IFirst, Transition),
2532 EvalExtrapol(ILast, Transition));
2534 Translate(myVEdges, IFirst, Bounds, 2);
2535 PerformCorner(IFirst,
2536 Transition, Bounds);
2539 Translate(myVEdges, IFirst, Bounds, 1);
2542 // Management of looping ends
2543 if ( (NbTrous>0) && (myLoc->IsClosed()) &&
2544 (Trous->Value(NbTrous) == NbPath+1) ) {
2545 Translate(myVEdges, NbPath+1, Bounds, 1);
2546 Translate(myVEdges, 1, Bounds, 2);
2547 PerformCorner(1, Transition, Bounds);
2550 // Construction of the shell
2553 for (ipath=1; ipath<=NbPath; ipath++)
2554 for (isec=1; isec <=NbLaw; isec++) {
2555 const TopoDS_Shape& face = myFaces->Value(isec, ipath);
2556 if (!face.IsNull() &&
2557 (face.ShapeType() == TopAbs_FACE) ) B.Add(shell, face);
2560 TopTools_ListIteratorOfListOfShape It(myAuxShape);
2561 for (; It.More(); It.Next()) {
2562 const TopoDS_Shape& face = It.Value();
2563 if (!face.IsNull() &&
2564 (face.ShapeType() == TopAbs_FACE) ) B.Add(shell, face);
2566 //Set common Uedges to faces
2567 BRepTools_Substitution aSubstitute;
2569 for (ii = 1; ii <= NbLaw; ii++)
2570 for (jj = 1; jj <= NbPath; jj++)
2572 SetCommonEdgeInFace(aSubstitute,
2573 myFaces->Value(ii, jj),
2574 myUEdges->Value(ii, jj));
2575 SetCommonEdgeInFace(aSubstitute,
2576 myFaces->Value(ii, jj),
2577 myUEdges->Value(ii+1, jj));
2579 if (mySec->IsUClosed())
2580 for (jj = 1; jj <= NbPath; jj++)
2581 SetCommonEdgeInFace(aSubstitute,
2582 myFaces->Value( 1, jj ),
2583 myUEdges->Value( NbLaw+1, jj));
2585 TopTools_DataMapIteratorOfDataMapOfShapeShape mapit( myVEdgesModified );
2586 for (; mapit.More(); mapit.Next())
2588 const TopoDS_Edge& OldEdge = TopoDS::Edge(mapit.Key());
2589 const TopoDS_Edge& NewEdge = TopoDS::Edge(mapit.Value());
2590 Substitute( aSubstitute, OldEdge, NewEdge );
2592 aSubstitute.Build( shell );
2593 if (aSubstitute.IsCopied( shell )) {
2594 const TopTools_ListOfShape& listSh = aSubstitute.Copy( shell );
2595 shell = TopoDS::Shell( listSh.First() );
2598 for (ii = myFaces->LowerRow(); ii <= myFaces->UpperRow(); ii++) {
2599 for (jj = myFaces->LowerCol(); jj <= myFaces->UpperCol(); jj++) {
2600 const TopoDS_Shape& aLocalShape = myFaces->Value(ii, jj);
2602 if(!aLocalShape.IsNull() && aSubstitute.IsCopied(aLocalShape)) {
2603 const TopTools_ListOfShape& aList = aSubstitute.Copy(aLocalShape);
2605 if(!aList.IsEmpty())
2606 myFaces->ChangeValue(ii, jj) = aList.First();
2611 for (ii = myVEdges->LowerRow(); ii <= myVEdges->UpperRow(); ii++) {
2612 for (jj = myVEdges->LowerCol(); jj <= myVEdges->UpperCol(); jj++) {
2613 const TopoDS_Shape& aLocalShape = myVEdges->Value(ii, jj);
2615 if(!aLocalShape.IsNull() && aSubstitute.IsCopied(aLocalShape)) {
2616 const TopTools_ListOfShape& aList = aSubstitute.Copy(aLocalShape);
2618 if(!aList.IsEmpty())
2619 myVEdges->ChangeValue(ii, jj) = aList.First();
2624 for (ii = myUEdges->LowerRow(); ii <= myUEdges->UpperRow(); ii++) {
2625 for (jj = myUEdges->LowerCol(); jj <= myUEdges->UpperCol(); jj++) {
2626 const TopoDS_Shape& aLocalShape = myUEdges->Value(ii, jj);
2628 if(!aLocalShape.IsNull() && aSubstitute.IsCopied(aLocalShape)) {
2629 const TopTools_ListOfShape& aList = aSubstitute.Copy(aLocalShape);
2631 if(!aList.IsEmpty())
2632 myUEdges->ChangeValue(ii, jj) = aList.First();
2638 if (myLoc->IsClosed() && mySec->IsUClosed()) {
2640 Standard_Boolean closed = Standard_True;
2641 Standard_Integer iedge;
2642 TopTools_IndexedDataMapOfShapeListOfShape EFmap;
2643 TopExp::MapShapesAndAncestors(shell, TopAbs_EDGE,
2644 TopAbs_FACE, EFmap);
2646 for (iedge = 1; iedge <=EFmap.Extent() && closed; iedge++) {
2647 const TopoDS_Edge& theEdge = TopoDS::Edge(EFmap.FindKey(iedge));
2648 if (BRep_Tool::Degenerated(theEdge)) continue;
2649 closed = ( EFmap(iedge).Extent() > 1);
2651 shell.Closed(closed);
2658 //=======================================================================
2661 //=======================================================================
2662 Standard_Boolean BRepFill_Sweep::IsDone() const
2667 //=======================================================================
2670 //=======================================================================
2671 TopoDS_Shape BRepFill_Sweep::Shape() const
2676 //=======================================================================
2677 //function : ErrorOnSurface
2679 //=======================================================================
2680 Standard_Real BRepFill_Sweep::ErrorOnSurface() const
2685 //=======================================================================
2686 //function : SubShape
2687 //purpose : Faces obtained by sweeping
2688 //=======================================================================
2689 Handle(TopTools_HArray2OfShape) BRepFill_Sweep::SubShape() const
2694 //=======================================================================
2695 //function : InterFaces
2696 //purpose : Edges obtained by sweeping
2697 //=======================================================================
2698 Handle(TopTools_HArray2OfShape) BRepFill_Sweep::InterFaces() const
2703 //=======================================================================
2704 //function : Sections
2705 //purpose : Edges or Face (or compound of 2) Transition between 2 sweepings
2706 //=======================================================================
2707 Handle(TopTools_HArray2OfShape) BRepFill_Sweep::Sections() const
2712 //=======================================================================
2713 //function : PerformCorner
2714 //purpose : Trim and/or loop a corner
2715 //======================================================================
2716 void BRepFill_Sweep::PerformCorner(const Standard_Integer Index,
2717 const BRepFill_TransitionStyle Transition,
2718 const Handle(TopTools_HArray2OfShape)& Bounds)
2721 if (Transition == BRepFill_Modified) return; // Do nothing.
2723 BRepFill_TransitionStyle TheTransition = Transition;
2724 Standard_Boolean isTangent=Standard_False;
2726 Standard_Integer I1, I2, ii; //, jj;
2728 gp_Vec T1, T2, Tang, Sortant;
2730 //Handle(TopTools_HArray1OfShape) TheShape =
2731 //new TopTools_HArray1OfShape( 1, mySec->NbLaw() );
2732 // TopTools_ListIteratorOfListOfShape Iterator;
2739 I1 = myLoc->NbLaw();
2743 // Construct an axis supported by the bissectrice
2744 myLoc->Law(I1)->GetDomain(F, L);
2745 myLoc->Law(I1)->GetCurve()->D1(L, P1, T1);
2748 myLoc->Law(I2)->GetDomain(F, L);
2749 myLoc->Law(I2)->GetCurve()->D1(F, P2, T2);
2752 if (T1.Angle(T2) < myAngMin) {
2753 isTangent = Standard_True;
2756 myLoc->Law(I1)->GetDomain(F, L);
2757 myLoc->Law(I1)->D0(L, M, V);
2759 myLoc->Law(I2)->GetDomain(F, L);
2760 myLoc->Law(I2)->D0(L, M, V);
2763 if (t1.Angle(t2) < myAngMin) {
2765 cout << "BRepFill_Sweep::PerformCorner : This is not a corner !" << endl;
2772 if ((TheTransition == BRepFill_Right)
2773 && (T1.Angle(T2) > myAngMax) ) {
2774 TheTransition = BRepFill_Round;
2777 Tang = T1 + T2; //Average direction
2778 gp_Dir NormalOfBisPlane = Tang;
2781 Sortant -= Tang.Dot(Tang)*Tang;
2784 Sortant = T2-T1; //Direction input
2785 Sortant *= -1; // " " output
2786 Tang -= (Tang.Dot(T2))*T2;
2789 P1.BaryCenter(0.5, P2, 0.5);
2793 gp_Ax2 Axe (P1, N, Dx);
2794 gp_Ax2 AxeOfBisPlane( P1, NormalOfBisPlane );
2796 // Construct 2 intersecting Shells
2797 Handle (TopTools_HArray2OfShape) UEdges =
2798 new TopTools_HArray2OfShape( 1, mySec->NbLaw()+1, 1, myLoc->NbLaw() );
2799 UEdges->ChangeArray2() = myUEdges->Array2();
2801 // modified by NIZHNY-MKK Wed Oct 29 18:31:47 2003.BEGIN
2802 Handle (TopTools_HArray2OfShape) aFaces =
2803 new TopTools_HArray2OfShape(myFaces->LowerRow(), myFaces->UpperRow(), 1, 2);
2804 Translate(myFaces, I1, aFaces, 1);
2805 Translate(myFaces, I2, aFaces, 2);
2807 Handle (TopTools_HArray2OfShape) aUEdges =
2808 new TopTools_HArray2OfShape(myUEdges->LowerRow(), myUEdges->UpperRow(), 1, 2);
2809 Translate(myUEdges, I1, aUEdges, 1);
2810 Translate(myUEdges, I2, aUEdges, 2);
2812 gp_Vec aNormal = T2 + T1;
2813 TopoDS_Face aPlaneF;
2815 if(aNormal.Magnitude() > gp::Resolution()) {
2816 gp_Pln pl(P1, gp_Dir(aNormal));
2817 BRepLib_MakeFace aFMaker(pl);
2819 if(aFMaker.Error() == BRepLib_FaceDone) {
2820 aPlaneF = aFMaker.Face();
2822 aBB.UpdateFace(aPlaneF, Precision::Confusion() * 10.);
2826 BRepFill_TrimShellCorner aTrim(aFaces, AxeOfBisPlane, aPlaneF);
2827 aTrim.AddBounds(Bounds);
2828 aTrim.AddUEdges(aUEdges);
2831 if (aTrim.IsDone()) {
2832 TopTools_ListOfShape listmodif;
2833 Standard_Integer iit = 0;
2835 for(iit = 0; iit < 2; iit++) {
2836 Standard_Integer II = (iit == 0) ? I1 : I2;
2838 for (ii = 1; ii <= mySec->NbLaw(); ii++) {
2839 aTrim.Modified(myFaces->Value(ii, II), listmodif);
2841 if(!listmodif.IsEmpty()) {
2842 myFaces->SetValue(ii, II, listmodif.First());
2846 for (ii = myUEdges->LowerRow(); ii <= myUEdges->UpperRow(); ii++) {
2847 aTrim.Modified(myUEdges->Value(ii, II), listmodif);
2849 if(!listmodif.IsEmpty()) {
2850 myUEdges->SetValue(ii, II, listmodif.First());
2855 else if ((TheTransition == BRepFill_Right) ||
2856 aTrim.HasSection() ) {
2858 cout << "Fail of TrimCorner" << endl;
2860 return; // Nothing is touched
2863 if (mySec->IsUClosed())
2865 myUEdges->SetValue( 1, I1, myUEdges->Value(mySec->NbLaw()+1, I1) );
2866 myUEdges->SetValue( 1, I2, myUEdges->Value(mySec->NbLaw()+1, I2) );
2869 if (TheTransition == BRepFill_Round) {
2871 TopTools_ListOfShape list1, list2;
2872 TopoDS_Edge Bord1, Bord2, BordFirst;
2873 BordFirst.Nullify();
2876 Standard_Boolean HasFilling = Standard_False;
2878 for (ii=1; ii<=mySec->NbLaw(); ii++) {
2879 KeepEdge(myFaces->Value(ii, I1), Bounds->Value(ii, 1), list1);
2880 KeepEdge(myFaces->Value(ii, I2), Bounds->Value(ii, 2), list2);
2881 if (list1.Extent() == list2.Extent()) {
2882 TopTools_ListIteratorOfListOfShape It1(list1);
2883 TopTools_ListIteratorOfListOfShape It2(list2);
2885 for (; It1.More(); It1.Next(), It2.Next()) {
2886 if (HasFilling) { // Transversal choice of constraints
2887 TopoDS_Vertex VF, VL, VC;
2888 TopoDS_Edge E = TopoDS::Edge(It1.Value());
2892 TopExp::Vertices(E, VF, VL);
2893 if (!Bord1.IsNull() &&
2894 TopExp::CommonVertex(E, Bord1, VC)) {
2895 if (VC.IsSame(VF)) E1 = Bord1;
2898 if (!Bord2.IsNull() &&
2899 TopExp::CommonVertex(E, Bord2, VC)) {
2900 if (VC.IsSame(VF)) E1 = Bord2;
2903 if (!BordFirst.IsNull() &&
2904 TopExp::CommonVertex(E, BordFirst, VC)) {
2905 if (VC.IsSame(VF)) E1 = BordFirst;
2906 else E2 = BordFirst;
2913 B = Filling(It1.Value(), myFaces->Value(ii, I1),
2914 It2.Value(), myFaces->Value(ii, I2),
2915 myVEdgesModified, myTol3d, Axe, T1, Bord1, Bord2, FF);
2918 myAuxShape.Append(FF);
2919 myVEdges->ChangeValue(ii, I2) = FF;
2920 HasFilling = Standard_True;
2922 if (ii==1) BordFirst = Bord1;
2926 else cout << "PerformCorner : Unsymmetry of free border" << endl;
2934 Standard_Integer jj;
2936 DBRep::Set("TrimmedShell", TheShape);
2937 for (jj=1; jj <=myFaces->ColLength(); jj++){
2938 sprintf(name,"Tfaces_%d_%d", jj, I1);
2939 DBRep::Set(name, myFaces->Value(jj, I1));
2940 sprintf(name,"Tfaces_%d_%d", jj, I2);
2941 DBRep::Set(name, myFaces->Value(jj, I2));
2948 //=======================================================================
2949 //function : EvalExtrapol
2951 //======================================================================
2952 Standard_Real BRepFill_Sweep::
2953 EvalExtrapol(const Standard_Integer Index,
2954 const BRepFill_TransitionStyle Transition) const
2956 Standard_Real Extrap = 0.0;
2957 if (Transition == BRepFill_Right) {
2958 Standard_Integer I1, I2;
2959 if ((Index == 1) || (Index ==myLoc->NbLaw()+1) ) {
2960 if (!myLoc->IsClosed() || !mySec->IsVClosed()) return Extrap;
2961 I1 = myLoc->NbLaw();
2969 gp_Vec V1, V2, T1, T2;
2971 Standard_Real Xmin, Ymin, Zmin, Xmax, Ymax, Zmax, R, f, l;
2973 myLoc->Law(I1)->GetDomain(f, l);
2974 myLoc->Law(I1)->D0(l, M1, V1);
2975 T1.SetXYZ(M1.Column(3));
2976 myLoc->Law(I2)->GetDomain(f, l);
2977 myLoc->Law(I2)->D0(f, M2, V2);
2978 T2.SetXYZ(M2.Column(3));
2980 Standard_Real alpha = T1.Angle(T2);
2981 if ((alpha > myAngMax) || (alpha < myAngMin)) {
2982 //Angle too great => No "straight" connection
2983 //Angle too small => No connection
2984 return Extrap; // = 0.0
2987 Handle(GeomFill_SectionLaw) Sec;
2988 Sec = mySec->ConcatenedLaw();
2990 //Calculating parameter U
2991 Standard_Real U, Length, SecFirst, SecLen, Lf, Ll;
2992 myLoc->CurvilinearBounds( myLoc->NbLaw(), Lf, Length );
2993 mySec->Law(1)->GetDomain( SecFirst, SecLen );
2995 myLoc->CurvilinearBounds( I1, Lf, Ll );
2996 U = SecFirst + (Ll/Length)*SecLen;
2999 //Box(Sec, 0., box);
3001 box.Get(Xmin, Ymin, Zmin, Xmax, Ymax, Zmax);
3003 R = Max(Max(Abs(Xmin), Abs(Xmax)),Max(Abs(Ymin), Abs(Ymax)));
3005 // modified by NIZHNY-MKK Fri Oct 31 18:57:51 2003
3006 // Standard_Real coef = 1.2;
3007 Standard_Real coef = 2.;
3009 Extrap = Max(Abs(Zmin), Abs(Zmax)) + 100*myTol3d;
3010 Extrap += R*Tan(alpha/2);
3015 //=======================================================================
3016 //function : MergeVertex
3017 //purpose : Make V2 = V1 if V2 is too close to V1
3018 //======================================================================
3019 Standard_Boolean BRepFill_Sweep::MergeVertex(const TopoDS_Shape& V1,
3020 TopoDS_Shape& V2) const
3022 // Class BRep_Tool without fields and without Constructor :
3024 const TopoDS_Vertex& v1 = TopoDS::Vertex(V1);
3025 const TopoDS_Vertex& v2 = TopoDS::Vertex(V2);
3027 // tol = Max(BT.Tolerance(v1), BT.Tolerance(v2));
3028 tol = Max(BRep_Tool::Tolerance(v1), BRep_Tool::Tolerance(v2));
3029 if (tol < myTol3d) tol = myTol3d;
3030 // if (BT.Pnt(v1).Distance(BT.Pnt(v2)) <= tol ){
3031 if (BRep_Tool::Pnt(v1).Distance(BRep_Tool::Pnt(v2)) <= tol ){
3033 return Standard_True;
3035 return Standard_False;
3039 //=======================================================================
3040 //function : UpdateVertex
3041 //purpose : Update the Tolerance of Vertices depending on Laws.
3042 //======================================================================
3043 void BRepFill_Sweep::UpdateVertex(const Standard_Integer ipath,
3044 const Standard_Integer isec,
3045 const Standard_Real ErrApp,
3046 const Standard_Real Param,
3047 TopoDS_Shape& V) const
3049 TopoDS_Vertex vv, TheV;
3050 TheV = TopoDS::Vertex(V);
3051 myLoc->PerformVertex(ipath,
3052 mySec->Vertex(isec, Param),
3053 ErrApp+mySec->VertexTol(isec-1, Param),
3055 // Class BRep_Tool without fields and without Constructor :
3059 P1 = BRep_Tool::Pnt(vv);
3060 // P2 = BT.Pnt(TheV);
3061 P2 = BRep_Tool::Pnt(TheV);
3063 // Standard_Real Tol = BT.Tolerance(vv);
3064 Standard_Real Tol = BRep_Tool::Tolerance(vv);
3065 Tol += P1.Distance(P2);
3067 // if (Tol > BT.Tolerance(TheV)) {
3068 if (Tol > BRep_Tool::Tolerance(TheV)) {
3070 B.UpdateVertex(TheV, Tol);