1 // Created on: 1998-01-07
2 // Created by: Philippe MANGIN
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
24 #include <BRepFill_Sweep.ixx>
26 #include <BRepFill_SectionLaw.hxx>
27 //#include <BRepFill_TrimCorner.hxx>
28 #include <BRepFill_CurveConstraint.hxx>
30 #include <GeomFill_SectionLaw.hxx>
31 #include <GeomFill_LocationLaw.hxx>
32 #include <GeomFill_Sweep.hxx>
34 // modified by NIZHNY-MKK Wed Oct 22 12:25:45 2003
35 #include <BRepFill_TrimShellCorner.hxx>
37 //#include <GeomPlate_BuildPlateSurface.hxx>
38 //#include <GeomPlate_Surface.hxx>
39 //#include <GeomPlate_PointConstraint.hxx>
41 #include <gp_Pnt2d.hxx>
42 #include <gp_Vec2d.hxx>
43 #include <Bnd_Box.hxx>
45 #include <Geom_Surface.hxx>
46 #include <Geom_SurfaceOfRevolution.hxx>
47 #include <Geom_RectangularTrimmedSurface.hxx>
48 #include <Geom_Plane.hxx>
49 #include <Geom_Curve.hxx>
50 #include <Geom_BezierCurve.hxx>
51 #include <Geom_BSplineCurve.hxx>
52 #include <Geom2d_Line.hxx>
53 #include <Geom2d_Curve.hxx>
54 #include <Geom2d_TrimmedCurve.hxx>
55 #include <GeomLib.hxx>
56 #include <GeomLib_IsPlanarSurface.hxx>
57 #include <BRepLib_FindSurface.hxx>
58 #include <GeomConvert_ApproxSurface.hxx>
60 #include <BRepAdaptor_HCurve.hxx>
61 #include <BRepAdaptor_HCurve2d.hxx>
62 #include <BRepAdaptor_HSurface.hxx>
63 #include <Adaptor3d_HCurveOnSurface.hxx>
64 #include <GeomAdaptor_HSurface.hxx>
65 #include <GeomAdaptor_HCurve.hxx>
66 #include <Geom2dAdaptor_HCurve.hxx>
67 #include <Approx_CurveOnSurface.hxx>
68 #include <Approx_SameParameter.hxx>
69 #include <GCPnts_AbscissaPoint.hxx>
71 #include <BRep_Builder.hxx>
72 #include <BRep_Tool.hxx>
73 #include <BRep_ListIteratorOfListOfCurveRepresentation.hxx>
74 #include <BRep_TEdge.hxx>
75 #include <BRep_TVertex.hxx>
76 #include <BRep_CurveRepresentation.hxx>
77 #include <BRep_GCurve.hxx>
79 #include <BRepLib.hxx>
80 #include <BRepLib_MakeEdge.hxx>
81 #include <BRepLib_MakeFace.hxx>
82 #include <BRepLib_FaceError.hxx>
85 #include <TopoDS_Edge.hxx>
86 #include <TopoDS_Face.hxx>
87 #include <TopoDS_Compound.hxx>
88 #include <TopoDS_Shell.hxx>
90 #include <TopExp_Explorer.hxx>
91 #include <TopAbs_Orientation.hxx>
93 #include <TColStd_HArray1OfInteger.hxx>
94 #include <TColStd_Array2OfInteger.hxx>
95 #include <TColStd_Array1OfReal.hxx>
96 #include <TColStd_Array2OfReal.hxx>
97 #include <TColGeom_Array2OfSurface.hxx>
98 #include <TColgp_Array1OfPnt.hxx>
100 #include <TopTools_Array1OfShape.hxx>
101 #include <TopTools_Array2OfShape.hxx>
102 #include <TopTools_HArray2OfShape.hxx>
103 #include <TopTools_HArray1OfShape.hxx>
104 #include <TopTools_ListIteratorOfListOfShape.hxx>
105 #include <TopTools_ListOfShape.hxx>
106 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
107 #include <BRepTools_WireExplorer.hxx>
109 #include <Standard_ConstructionError.hxx>
110 #include <Precision.hxx>
111 #include <BRepBuilderAPI_MakeWire.hxx>
113 #include <BRepTools_Substitution.hxx>
114 #include <TopTools_DataMapIteratorOfDataMapOfShapeShape.hxx>
115 #include <TopoDS_Iterator.hxx>
118 #include <BRepCheck_Edge.hxx>
122 #include <DrawTrSurf.hxx>
124 static Standard_Boolean Affich = 0;
127 //=======================================================================
128 //function : NumberOfPoles
130 //=======================================================================
131 static Standard_Integer NumberOfPoles(const TopoDS_Wire& W)
133 Standard_Integer NbPoints = 0;
135 TopoDS_Iterator iter(W);
136 for (; iter.More(); iter.Next())
138 BRepAdaptor_Curve c(TopoDS::Edge(iter.Value()));
140 Standard_Real dfUf = c.FirstParameter();
141 Standard_Real dfUl = c.LastParameter();
142 if (IsEqual(dfUf,dfUl))
148 case GeomAbs_BezierCurve:
150 // Put all poles for bezier
151 Handle(Geom_BezierCurve) GC = c.Bezier();
152 Standard_Integer iNbPol = GC->NbPoles();
157 case GeomAbs_BSplineCurve:
159 // Put all poles for bspline
160 Handle(Geom_BSplineCurve) GC = c.BSpline();
161 Standard_Integer iNbPol = GC->NbPoles();
172 case GeomAbs_Ellipse:
173 case GeomAbs_Hyperbola:
174 case GeomAbs_Parabola:
180 NbPoints += 15 + c.NbIntervals(GeomAbs_C3);
181 } // switch (c.GetType()) ...
182 } // for (; iter.More(); iter.Next())
187 //=======================================================================
188 //function : HasPCurves
190 //=======================================================================
191 static Standard_Boolean HasPCurves(const TopoDS_Edge& E)
193 Standard_Boolean haspcurves = Standard_False;
195 BRep_ListIteratorOfListOfCurveRepresentation itcr
196 ((*((Handle(BRep_TEdge)*)&E.TShape()))->Curves());
197 for (; itcr.More(); itcr.Next())
199 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
200 if (cr->IsCurveOnSurface())
202 haspcurves = Standard_True;
209 //=======================================================================
210 //function : Translate
211 //purpose : Copy a column from one table to another.
212 //=======================================================================
213 static void Translate(const Handle(TopTools_HArray2OfShape)& ArrayIn,
214 const Standard_Integer In,
215 Handle(TopTools_HArray2OfShape)& ArrayOut,
216 const Standard_Integer Out)
218 Standard_Integer ii, Nb;
219 Nb = ArrayOut->ColLength();
220 for (ii=1; ii<=Nb; ii++) {
221 ArrayOut->SetValue(ii, Out, ArrayIn->Value(ii, In));
226 //=======================================================================
228 //purpose : Bounding box of a section.
229 //=======================================================================
230 static void Box(Handle(GeomFill_SectionLaw)& Sec,
231 const Standard_Real U,
235 Standard_Integer NbPoles, bid;
237 Sec->SectionShape(NbPoles, bid, bid);
238 TColgp_Array1OfPnt Poles(1, NbPoles);
239 TColStd_Array1OfReal W(1, NbPoles);
240 Sec->D0(U, Poles, W);
241 for (Standard_Integer ii=1; ii<=NbPoles; ii++) {
246 //=======================================================================
248 //purpose : Check if E is an edge of sewing on S
249 // and make the representation HadHoc
250 //=======================================================================
251 static Handle(Geom2d_Curve) Couture(const TopoDS_Edge& E,
252 const Handle(Geom_Surface)& S,
253 const TopLoc_Location& L)
255 TopLoc_Location l = L.Predivided(E.Location());
256 Standard_Boolean Eisreversed = (E.Orientation() == TopAbs_REVERSED);
258 // find the representation
259 BRep_ListIteratorOfListOfCurveRepresentation itcr
260 ((*((Handle(BRep_TEdge)*)&E.TShape()))->ChangeCurves());
262 while (itcr.More()) {
263 Handle(BRep_CurveRepresentation)& cr = itcr.Value();
264 if (cr->IsCurveOnSurface(S,l)) {
265 Handle(BRep_GCurve)& GC = *((Handle(BRep_GCurve)*)&cr);
266 if (GC->IsCurveOnClosedSurface() && Eisreversed)
267 return GC->PCurve2();
273 Handle(Geom2d_Curve) pc;
278 //=======================================================================
279 //function : CheckSameParameter
280 //purpose : Check a posteriori that sameparameter has worked correctly
281 //=======================================================================
283 static Standard_Boolean CheckSameParameter
284 (const Handle(Adaptor3d_HCurve)& C3d,
285 Handle(Geom2d_Curve)& Pcurv,
286 const Handle(Adaptor3d_HSurface)& S,
287 const Standard_Real tol3d,
288 Standard_Real& tolreached)
291 Standard_Real f = C3d->FirstParameter();
292 Standard_Real l = C3d->LastParameter();
293 Standard_Integer nbp = 45;
294 Standard_Real step = 1./(nbp -1);
295 for(Standard_Integer i = 0; i < nbp; i++){
298 t = (1-t) * f + t * l;
299 Pcurv->Value(t).Coord(u,v);
300 gp_Pnt pS = S->Value(u,v);
301 gp_Pnt pC = C3d->Value(t);
302 Standard_Real d2 = pS.SquareDistance(pC);
303 tolreached = Max(tolreached,d2);
305 tolreached = sqrt(tolreached);
306 if(tolreached > tol3d){
308 return Standard_False;
311 tolreached = Max(tolreached,Precision::Confusion());
312 return Standard_True;
315 //=======================================================================
316 //function : SameParameter
317 //purpose : Encapsulation of Sameparameter
318 // Boolean informs if the pcurve was computed or not...
319 // The tolerance is always OK.
320 //=======================================================================
322 static Standard_Boolean SameParameter(TopoDS_Edge& E,
323 Handle(Geom2d_Curve)& Pcurv,
324 const Handle(Geom_Surface)& Surf,
325 const Standard_Real tol3d,
326 Standard_Real& tolreached)
328 //Handle(BRepAdaptor_HCurve) C3d = new (BRepAdaptor_HCurve)(E);
330 Handle(Geom_Curve) C3d = BRep_Tool::Curve( E, f, l );
331 GeomAdaptor_Curve GAC3d( C3d, f, l );
332 Handle(GeomAdaptor_HCurve) HC3d = new GeomAdaptor_HCurve( GAC3d );
334 Handle(GeomAdaptor_HSurface) S = new (GeomAdaptor_HSurface)(Surf);
335 Standard_Real ResTol;
337 if(CheckSameParameter( HC3d, Pcurv, S, tol3d, tolreached ))
338 return Standard_True;
342 Handle(Geom2dAdaptor_HCurve) HC2d = new Geom2dAdaptor_HCurve( Pcurv );
343 Approx_CurveOnSurface AppCurve(HC2d, S, HC2d->FirstParameter(), HC2d->LastParameter(),
344 Precision::Confusion(), GeomAbs_C1, 10, 10, Standard_True);
345 if (AppCurve.IsDone() && AppCurve.HasResult())
347 C3d = AppCurve.Curve3d();
348 tolreached = AppCurve.MaxError3d();
350 B.UpdateEdge( E, C3d, tolreached );
351 return Standard_True;
355 Approx_SameParameter sp( HC3d, Pcurv, S, tol3d );
356 if(sp.IsDone() && !sp.IsSameParameter()) Pcurv = sp.Curve2d();
357 else if(!sp.IsDone() && !sp.IsSameParameter()){
359 cout<<"echec SameParameter"<<endl;
361 return Standard_False;
364 ResTol = sp.TolReached();
365 if(ResTol > tolreached ){
367 cout<<"SameParameter : Tolerance not reached!"<<endl;
368 cout<<"tol visee : "<<tol3d<<" tol obtained : "<<ResTol<<endl;
370 return Standard_False;
373 tolreached = 1.1*ResTol;
374 if(sp.IsDone() && !sp.IsSameParameter()) Pcurv = sp.Curve2d();
376 return Standard_True;
379 //=======================================================================
380 //Objet : Orientate an edge of natural restriction
382 //=======================================================================
383 static void Oriente(const Handle(Geom_Surface)& S,
387 gp_Vec2d D, URef(1, 0), VRef(0, 1);
388 Standard_Boolean isuiso, isfirst, isopposite;
389 Standard_Real UFirst, ULast, VFirst, VLast, f, l;
390 S->Bounds(UFirst, ULast, VFirst, VLast);
391 Handle(Geom2d_Curve) C;
394 C = BRep_Tool::CurveOnSurface(E, S, bid, f, l);
395 C->D1((f+l)/2, P, D);
397 isuiso = D.IsParallel(VRef, 0.1);
400 isfirst = (Abs (P.X()-UFirst) < Precision::Confusion());
401 isopposite = D.IsOpposite(VRef, 0.1);
402 E.Orientation(TopAbs_REVERSED);
405 isfirst = (Abs (P.Y()-VFirst) < Precision::Confusion());
406 isopposite = D.IsOpposite(URef, 0.1);
407 E.Orientation(TopAbs_FORWARD);
410 if (!isfirst) E.Reverse();
411 if (isopposite) E.Reverse();
414 static void UpdateEdgeOnPlane(const TopoDS_Face& F, const TopoDS_Edge& E,
415 const BRep_Builder& BB)
418 Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(E,F,f,l);
419 Handle(Geom_Surface) S = BRep_Tool::Surface(F);
421 Standard_Real Tol = BRep_Tool::Tolerance(E);
422 BB.UpdateEdge(E, C2d, S, Loc, Tol);
423 BRepCheck_Edge Check(E);
424 Tol = Max(Tol,Check.Tolerance());
425 BB.UpdateEdge(E, Tol);
428 V = TopExp::FirstVertex(E);
429 if(BRep_Tool::Tolerance(V) < Tol) BB.UpdateVertex(V, Tol);
430 V = TopExp::LastVertex(E);
431 if(BRep_Tool::Tolerance(V) < Tol) BB.UpdateVertex(V, Tol);
434 //=======================================================================
435 //Function : BuildFace
436 //Objet : Construct a Face via a surface and 4 Edges (natural borders)
437 // : Only one Hypothesis : isos u and v are switched :
438 // Edge1/3 are iso u (recp v)
439 // Edge2/4 are iso v (recp u)
440 //=======================================================================
441 static void BuildFace(const Handle(Geom_Surface)& S,
442 const TopoDS_Edge& E1,
443 const TopoDS_Edge& E2,
444 const TopoDS_Edge& E3,
445 const TopoDS_Edge& E4,
446 TopTools_DataMapOfShapeShape& EEmap,
447 const Standard_Boolean ExchUV,
448 const Standard_Boolean UReverse,
452 // Class BRep_Tool without fields and without Constructor :
454 TopoDS_Edge e1, e2, E;
457 BRepBuilderAPI_MakeWire B;
458 TopoDS_Iterator Iter;
461 //Is the surface planar ?
462 Standard_Real Tol1, Tol2, Tol3, Tol4;
463 Tol1 = BRep_Tool::Tolerance( E1 );
464 Tol2 = BRep_Tool::Tolerance( E2 );
465 Tol3 = BRep_Tool::Tolerance( E3 );
466 Tol4 = BRep_Tool::Tolerance( E4 );
467 // Tol = Min( BT.Tolerance(E1), BT.Tolerance(E2));
468 Tol = Min( Tol1, Tol2 );
469 // Tol = Min(Tol, Min(BT.Tolerance(E3),BT.Tolerance(E4)));
470 Tol = Min( Tol, Min( Tol3, Tol4 ) );
471 Standard_Boolean IsPlan = Standard_False;
472 Handle(Geom_Plane) thePlane;
474 if (!E1.IsSame(E3) && !E2.IsSame(E4)) //exclude cases with seam edges: they are not planar
476 GeomLib_IsPlanarSurface IsP(S, Tol);
479 IsPlan = Standard_True;
480 thePlane = new Geom_Plane( IsP.Plan() );
484 Handle(BRep_TEdge)& TE1 = *((Handle(BRep_TEdge)*)&E1.TShape());
485 Handle(BRep_TEdge)& TE2 = *((Handle(BRep_TEdge)*)&E2.TShape());
486 Handle(BRep_TEdge)& TE3 = *((Handle(BRep_TEdge)*)&E3.TShape());
487 Handle(BRep_TEdge)& TE4 = *((Handle(BRep_TEdge)*)&E4.TShape());
488 TE1->Tolerance( Precision::Confusion() );
489 TE2->Tolerance( Precision::Confusion() );
490 TE3->Tolerance( Precision::Confusion() );
491 TE4->Tolerance( Precision::Confusion() );
493 TopoDS_Wire theWire = BRepLib_MakeWire( E1, E2, E3, E4 );
494 Standard_Integer NbPoints = NumberOfPoles( theWire );
495 if (NbPoints <= 100) //limitation for CPU
497 BRepLib_FindSurface FS( theWire, -1, Standard_True );
500 IsPlan = Standard_True;
501 thePlane = Handle(Geom_Plane)::DownCast(FS.Surface());
504 BB.UpdateEdge( E1, Tol1 );
505 BB.UpdateEdge( E2, Tol2 );
506 BB.UpdateEdge( E3, Tol3 );
507 BB.UpdateEdge( E4, Tol4 );
511 // Construction of the wire
515 // if (!IsPlan || !BT.Degenerated(e1))
516 if (!IsPlan || !BRep_Tool::Degenerated(e1))
521 // if (!IsPlan || !BT.Degenerated(e2))
522 if (!IsPlan || !BRep_Tool::Degenerated(e2))
525 if (!BRep_Tool::Degenerated(e2))
528 TopoDS_Shape NewEdge;
529 //take the last edge added to WW
530 for (Iter.Initialize( WW ); Iter.More(); Iter.Next())
531 NewEdge = Iter.Value();
532 if (! e2.IsSame(NewEdge))
533 EEmap.Bind( e2, NewEdge );
545 // if (!IsPlan || !BT.Degenerated(E))
546 if (!IsPlan || !BRep_Tool::Degenerated(E))
549 if (!BRep_Tool::Degenerated(E))
552 TopoDS_Shape NewEdge;
553 //take the last edge added to WW
554 for (Iter.Initialize( WW ); Iter.More(); Iter.Next())
555 NewEdge = Iter.Value();
556 if (! E.IsSame(NewEdge))
557 EEmap.Bind( E, NewEdge );
569 // if (!IsPlan || !BT.Degenerated(E))
570 if (!IsPlan || !BRep_Tool::Degenerated(E))
573 if (!BRep_Tool::Degenerated(E))
576 TopoDS_Shape NewEdge;
577 //take the last edge added to WW
578 for (Iter.Initialize( WW ); Iter.More(); Iter.Next())
579 NewEdge = Iter.Value();
580 if (! E.IsSame(NewEdge))
581 EEmap.Bind( E, NewEdge );
588 DBRep::Set("wire-on-face", WW);
591 // Construction of the face.
592 if (IsPlan) { // Suspend representation 2d
593 // and construct face Plane
595 //BRepLib_MakeFace MkF(IsP.Plan(), WW);
597 gp_Vec DU, DV, NS, NP;
598 Standard_Real Ufirst, Ulast, Vfirst, Vlast;
599 S->Bounds( Ufirst, Ulast, Vfirst, Vlast );
600 S->D1( (Ufirst+Ulast)/2., (Vfirst+Vlast)/2., aPnt, DU, DV );
602 NP = thePlane->Pln().Axis().Direction();
604 thePlane->UReverse();
605 BRepLib_MakeFace MkF( thePlane, WW );
606 if (MkF.Error() != BRepLib_FaceDone) {
608 BRepLib_FaceError Err = MkF.Error();
609 cout << "Planar Face Error :" << Err << endl;
613 Handle(Geom2d_Curve) NullC2d;
615 BB.UpdateEdge( E1, NullC2d, S, Loc, Tol1 );
616 BB.UpdateEdge( E2, NullC2d, S, Loc, Tol2 );
617 BB.UpdateEdge( E3, NullC2d, S, Loc, Tol3 );
618 BB.UpdateEdge( E4, NullC2d, S, Loc, Tol4 );
621 UpdateEdgeOnPlane(F,E1,BB);
622 UpdateEdgeOnPlane(F,E2,BB);
623 UpdateEdgeOnPlane(F,E3,BB);
624 UpdateEdgeOnPlane(F,E4,BB);
627 Handle(Geom2d_Curve) NC;
629 // B.UpdateEdge(E1, NC, S, Loc, BT.Tolerance(E1));
630 BB.UpdateEdge(E1, NC, S, Loc, BRep_Tool::Tolerance(E1));
631 // B.UpdateEdge(E2, NC, S, Loc, BT.Tolerance(E2));
632 BB.UpdateEdge(E2, NC, S, Loc, BRep_Tool::Tolerance(E2));
633 // B.UpdateEdge(E3, NC, S, Loc, BT.Tolerance(E3));
634 BB.UpdateEdge(E3, NC, S, Loc, BRep_Tool::Tolerance(E3));
635 // B.UpdateEdge(E4, NC, S, Loc, BT.Tolerance(E4));
636 BB.UpdateEdge(E4, NC, S, Loc, BRep_Tool::Tolerance(E4));
641 if (!IsPlan) {// Cas Standard : Ajout
642 BB.MakeFace(F, S, Precision::Confusion());
647 if (ExchUV) F.Reverse();
648 if (UReverse) F.Reverse();
652 //=======================================================================
653 //Fonction : BuildEdge
654 //Objet : Construct non-closed Edge
655 //=======================================================================
656 static TopoDS_Edge BuildEdge(Handle(Geom_Curve)& C3d,
657 Handle(Geom2d_Curve)& C2d,
658 Handle(Geom_Surface)& S,
659 const TopoDS_Vertex& VF,
660 const TopoDS_Vertex& VL,
661 const Standard_Real f,
662 const Standard_Real l,
663 const Standard_Real Tol3d)
666 Standard_Real Tol1, Tol2, Tol, d;
667 // Class BRep_Tool without fields and without Constructor :
673 P1 = BRep_Tool::Pnt(VF);
674 // Tol1 = BT.Tolerance(VF);
675 Tol1 = BRep_Tool::Tolerance(VF);
677 P2 = BRep_Tool::Pnt(VL);
678 // Tol2 = BT.Tolerance(VF);
679 Tol2 = BRep_Tool::Tolerance(VF);
680 Tol = Max(Tol1, Tol2);
683 (P1.Distance(P2) < Tol ) ) {
687 S->D0(P2d.X(), P2d.Y(), P);
689 if (d > Tol) Tol = d;
691 S->D0(P2d.X(), P2d.Y(), P);
693 if (d > Tol) Tol = d;
695 B.UpdateVertex(VF, Tol);
696 B.UpdateVertex(VL, Tol);
699 B.UpdateEdge(E,C2d,S,TopLoc_Location(), Tol);
703 B.Degenerated(E, Standard_True);
711 B.UpdateVertex(VF, d);
714 P1 = BRep_Tool::Pnt(VL);
718 B.UpdateVertex(VL, d);
720 BRepLib_MakeEdge MkE (C3d, VF, VL, f, l);
721 if (!MkE.IsDone()) { // Error of construction !!
724 sprintf(name,"firstvertex_error");
725 DBRep::Set(name, VF);
726 sprintf(name,"lastvertex_error");
727 DBRep::Set(name, VL);
728 sprintf(name,"curve3d_error");
730 DrawTrSurf::Set(Temp, C3d);
731 // DrawTrSurf::Set(name, C3d);
732 Standard_ConstructionError::Raise("BRepFill_Sweep::BuildEdge");
738 B.UpdateEdge(E, C2d, S, Loc, Tol3d);
744 //=======================================================================
746 //Objet : Construct the faces of filling
747 //=======================================================================
748 static Standard_Boolean Filling(const TopoDS_Shape& EF,
749 const TopoDS_Shape& F1,
750 const TopoDS_Shape& EL,
751 const TopoDS_Shape& F2,
752 TopTools_DataMapOfShapeShape& EEmap,
753 const Standard_Real Tol,
755 const gp_Vec& TangentOnPart1,
761 // Class BRep_Tool without fields and without Constructor :
763 // Standard_Integer NbInt =0;
764 // Standard_Real Tol3d = Tol;
765 Standard_Boolean WithE3, WithE4;
767 // Return constraints
768 TopoDS_Vertex V1, V2, Vf, Vl;
769 TopoDS_Edge E1, E2, E3, E4;
770 E1 = TopoDS::Edge(EF);
771 E2 = TopoDS::Edge(EL);
773 TopExp::Vertices(E1, Vf, Vl);
774 Vf.Orientation(TopAbs_FORWARD);
775 Vl.Orientation(TopAbs_FORWARD);
777 TopExp::Vertices(E2, V1, V2);
778 V1.Orientation(TopAbs_REVERSED);
779 V2.Orientation(TopAbs_REVERSED);
784 WithE3 = WithE4 = Standard_False;
786 if ((!Aux1.IsNull()) && (!Vf.IsSame(V1))) {
788 // E3 = TopoDS::Edge(Aux1);
789 WithE3 = Standard_True;
797 else if (!Aux2.IsNull() && (!Vl.IsSame(V2))) {
799 // E4 = TopoDS::Edge(Aux2);
800 WithE4 = Standard_True;
805 DBRep::Set("Fill_Edge1", E1);
806 DBRep::Set("Fill_Edge2", E2);
808 DBRep::Set("Fill_Edge3", E3);
810 DBRep::Set("Fill_Edge4", E4);
814 // Construction of a surface of revolution
815 Handle(Geom_Curve) Prof1, Prof2;
816 //Standard_Integer ii, jj;//, Nb;
817 Standard_Real f1, f2, l1, l2,/*d1, d2,*/ Angle;//, Eps = 1.e-9;
818 // Prof1 = BT.Curve(E1, f1, l1);
819 Prof1 = BRep_Tool::Curve(E1, f1, l1);
820 // Prof2 = BT.Curve(E2, f2, l2);
821 Prof2 = BRep_Tool::Curve(E2, f2, l2);
825 Tf.SetTransformation(Axe);
827 // Choose the angle of opening
828 P1 = Prof1->Value((f1+l1)/2);
829 P2 = Prof2->Value((f2+l2)/2);
832 p1.SetCoord(P1.Z(), P1.X());
833 p2.SetCoord(P2.Z(), P2.X());
834 gp_Vec2d v1(gp::Origin2d(), p1);
835 gp_Vec2d v2(gp::Origin2d(), p2);
836 if (v1.Magnitude() <= gp::Resolution() ||
837 v2.Magnitude() <= gp::Resolution())
838 return Standard_False;
839 Angle = v1.Angle(v2);
841 gp_Ax1 axe(Axe.Location(), Axe.YDirection());
848 Handle(Geom_SurfaceOfRevolution) Rev =
849 new (Geom_SurfaceOfRevolution) (Prof1, axe);
851 Handle(Geom_Surface) Surf =
852 new (Geom_RectangularTrimmedSurface) (Rev, 0, Angle, f1, l1);
854 // Control the direction of the rotation
855 Standard_Boolean ToReverseResult = Standard_False;
857 d1u = Surf->DN(0, (f1+l1)/2, 1, 0);
858 if (d1u.Angle(TangentOnPart1) > M_PI/2) { //Invert everything
859 ToReverseResult = Standard_True;
862 Angle = 2*M_PI - Angle;
863 Rev = new (Geom_SurfaceOfRevolution) (Prof1, axe);
864 Surf = new (Geom_RectangularTrimmedSurface)
865 (Rev, 0, Angle, f1, l1);
871 char* Temp = "Surf_Init" ;
872 DrawTrSurf::Set(Temp, Surf);
876 Handle(Geom2d_Curve) C1, C2, C3, C4;
878 // Deform the surface of revolution.
879 GeomPlate_BuildPlateSurface BPS;
881 Handle(BRepAdaptor_HSurface) AS;
882 Handle(BRepAdaptor_HCurve2d) AC2d;
883 Handle(Adaptor3d_HCurveOnSurface) HConS;
885 Handle(Geom2d_Line) L;
888 L = new (Geom2d_Line) (P2d, gp::DY2d());
889 C1 = new (Geom2d_TrimmedCurve) (L, f1, l1);
891 P2d.SetCoord(Angle,0.);
892 L = new (Geom2d_Line) (P2d, gp::DY2d());
893 C2 = new (Geom2d_TrimmedCurve) (L, f1, l1);
895 // It is required to control the direction and the range.
897 Surf->D0(P2d.X(), P2d.Y(), P1);
899 Surf->D0(P2d.X(), P2d.Y(), P2);
901 P = BRep_Tool::Pnt(V1);
902 if (P.Distance(P2)+Tol < P.Distance(P1)) {
903 // E2 is parsed in the direction opposite to E1
910 GeomLib::SameRange(Precision::PConfusion(), C2,
911 C2->FirstParameter(),
916 Standard_Boolean pointu_f, pointu_l;
918 P1 = BRep_Tool::Pnt(Vf);
920 P2 = BRep_Tool::Pnt(V1);
921 // pointu_f = Vf.IsSame(V1) || (P1.Distance(P2) < BT.Tolerance(Vf));
922 pointu_f = Vf.IsSame(V1) || (P1.Distance(P2) < BRep_Tool::Tolerance(Vf));
924 P1 = BRep_Tool::Pnt(Vl);
926 P2 = BRep_Tool::Pnt(V2);
927 // pointu_l = Vl.IsSame(V2) || (P1.Distance(P2) < BT.Tolerance(Vl));
928 pointu_l = Vl.IsSame(V2) || (P1.Distance(P2) < BRep_Tool::Tolerance(Vl));
932 L = new (Geom2d_Line) (P2d, gp::DX2d());
933 C3 = new (Geom2d_TrimmedCurve) (L, 0, Angle);
937 L = new (Geom2d_Line) (P2d, gp::DX2d());
938 C4 = new (Geom2d_TrimmedCurve) (L, 0, Angle);
940 // Determine the constraints and
941 // their parametric localisation.
943 AS = new BRepAdaptor_HSurface(TopoDS::Face(F1));
944 AC2d = new BRepAdaptor_HCurve2d();
945 AC2d->ChangeCurve2d().Initialize(E1,TopoDS::Face(F1));
946 HConS = new (Adaptor3d_HCurveOnSurface)();
947 HConS->ChangeCurve().Load(AC2d);
948 HConS->ChangeCurve().Load(AS);
950 Handle(BRepFill_CurveConstraint) Cont
951 = new BRepFill_CurveConstraint(HConS, 1, 15);
952 Cont->SetCurve2dOnSurf(C1);
955 NbInt = HConS->NbIntervals(GeomAbs_CN);
959 AS = new BRepAdaptor_HSurface(TopoDS::Face(F2));
960 AC2d = new BRepAdaptor_HCurve2d();
961 AC2d->ChangeCurve2d().Initialize(E2,TopoDS::Face(F2));
962 HConS = new (Adaptor3d_HCurveOnSurface);
964 HConS->ChangeCurve().Load(AC2d);
965 HConS->ChangeCurve().Load(AS);
967 Handle(BRepFill_CurveConstraint) Cont
968 = new BRepFill_CurveConstraint(HConS, 1, 15);
969 Cont->SetCurve2dOnSurf(C2);
974 Handle(BRepAdaptor_HCurve) AC = new (BRepAdaptor_HCurve) (E3);
975 Handle(BRepFill_CurveConstraint) Cont
976 = new BRepFill_CurveConstraint(AC, 0);
977 Cont->SetCurve2dOnSurf(C3);
981 Standard_Real delta = Angle / 11;
983 P = BRep_Tool::Pnt(Vf);
984 Handle(GeomPlate_PointConstraint) PC;
985 for (ii=1; ii<=10; ii++) {
986 C3->D0(ii*delta, P2d);
987 PC = new (GeomPlate_PointConstraint) (P, 0);
988 PC->SetPnt2dOnSurf(P2d);
995 Handle(BRepAdaptor_HCurve) AC = new (BRepAdaptor_HCurve) (E4);
996 Handle(BRepFill_CurveConstraint) Cont
997 = new BRepFill_CurveConstraint(AC, 0);
998 Cont->SetCurve2dOnSurf(C4);
1001 else if (pointu_l) {
1002 Standard_Real delta = Angle / 11;
1004 P = BRep_Tool::Pnt(Vl);
1005 Handle(GeomPlate_PointConstraint) PC;
1006 for (ii=1; ii<=10; ii++) {
1007 C4->D0(ii*delta, P2d);
1008 PC = new (GeomPlate_PointConstraint) (P, 0);
1009 PC->SetPnt2dOnSurf(P2d);
1014 BPS.LoadInitSurface(Surf);
1017 // Controle s'il y a une deformation effective
1018 Handle(GeomPlate_Surface) plate;
1019 plate = BPS.Surface();
1020 plate->SetBounds(0, Angle, f1, l1);
1021 Standard_Boolean Ok=Standard_True;
1025 for (ii=0; ii<=5 && Ok; ii++) {
1027 for (jj=0; jj<=5 && Ok; jj++) {
1029 plate->D0(u, v, P1);
1031 Ok = (P2.IsEqual(P1, Tol));
1037 // Approx de la plate surface
1038 // Bords naturelles => pas besoin de criteres.
1039 GeomConvert_ApproxSurface App(BPS.Surface(),
1041 GeomAbs_C1, GeomAbs_C1,
1043 if (!App.HasResult()) {
1045 cout << "Filling_Approx : Pas de resultat" << endl;
1047 return Standard_False;
1050 cout << "Filling_Approx Error 3d = " <<
1051 App.MaxError() << endl;
1053 Surf = App.Surface();
1054 Tol3d = App.MaxError();
1059 TopLoc_Location Loc;
1060 Handle(Geom_Curve) C3d;
1061 B.UpdateEdge(E1, C1, Surf, Loc, /*Tol3d*/Precision::Confusion());
1062 B.UpdateEdge(E2, C2, Surf, Loc, /*Tol3d*/Precision::Confusion());
1064 if (E3.IsSame(E4)) {
1067 C3d = Surf->VIso(f1);
1068 E3 = BuildEdge(C3d, C3, Surf, Vf, V1, 0, Angle, /*Tol3d*/Precision::Confusion());
1072 BRepAdaptor_Curve aCurve(E3);
1073 Standard_Real AngleOld = aCurve.LastParameter();
1074 if (Angle > AngleOld)
1076 B.Range( E3, 0, Angle );
1077 TopoDS_Vertex V (TopExp::LastVertex(E3));
1078 Handle(BRep_TVertex)& TVlast = *((Handle(BRep_TVertex)*) &V.TShape());
1079 TVlast->Tolerance( Precision::Confusion() );
1083 B.UpdateEdge(E3, C3, C4, Surf, Loc, /*Tol3d*/Precision::Confusion());
1090 C3d = Surf->VIso(f1);
1091 E3 = BuildEdge(C3d, C3, Surf, Vf, V1, 0, Angle, /*Tol3d*/Precision::Confusion());
1095 BRepAdaptor_Curve aCurve(E3);
1096 Standard_Real AngleOld = aCurve.LastParameter();
1097 if (Angle > AngleOld)
1099 B.Range( E3, 0, Angle );
1100 TopoDS_Vertex V(TopExp::LastVertex(E3));
1101 Handle(BRep_TVertex)& TVlast = *((Handle(BRep_TVertex)*) &V.TShape());
1102 TVlast->Tolerance( Precision::Confusion() );
1105 B.UpdateEdge(E3, C3, Surf, Loc, /*Tol3d*/Precision::Confusion());
1110 C3d = Surf->VIso(l1);
1111 E4 = BuildEdge(C3d, C4, Surf, Vl, V2, 0, Angle, /*Tol3d*/Precision::Confusion());
1115 BRepAdaptor_Curve aCurve(E4);
1116 Standard_Real AngleOld = aCurve.LastParameter();
1117 if (Angle > AngleOld)
1119 B.Range( E4, 0, Angle );
1120 TopoDS_Vertex V (TopExp::LastVertex(E4));
1121 Handle(BRep_TVertex)& TVlast = *((Handle(BRep_TVertex)*)&V.TShape());
1122 TVlast->Tolerance( Precision::Confusion() );
1125 B.UpdateEdge(E4, C4, Surf, Loc, /*Tol3d*/Precision::Confusion());
1130 BuildFace(Surf,E1, E3, E2, E4, EEmap,
1131 Standard_False, Standard_False,
1134 // Set the continuities.
1135 B.Continuity(E1, TopoDS::Face(F1), Result, GeomAbs_G1);
1136 B.Continuity(E2, TopoDS::Face(F2), Result, GeomAbs_G1);
1138 // Render the calculated borders.
1139 // if (!BT.Degenerated(E3))
1140 if (!BRep_Tool::Degenerated(E3))
1143 B.MakeEdge(Aux1); //Nullify
1145 // if (!BT.Degenerated(E4))
1146 if (!BRep_Tool::Degenerated(E4))
1151 // Set the orientation
1152 gp_Vec D1U, D1V, N1, N2;
1153 C1->D0( (f1+l1)/2, P2d);
1154 Surf->D1(P2d.X(), P2d.Y(), P, D1U, D1V);
1157 // C1 = BT.CurveOnSurface(E1, TopoDS::Face(F1), f2, l2);
1158 C1 = BRep_Tool::CurveOnSurface(E1, TopoDS::Face(F1), f2, l2);
1159 C1->D0( (f1+l1)/2, P2d);
1160 Handle(BRepAdaptor_HSurface) AS = new BRepAdaptor_HSurface(TopoDS::Face(F1));
1161 AS->D1(P2d.X(), P2d.Y(), P, D1U, D1V);
1164 if ( (F1.Orientation() == TopAbs_REVERSED) ^ (N1.Angle(N2)>M_PI/2) )
1165 Result.Orientation(TopAbs_REVERSED);
1166 else Result.Orientation(TopAbs_FORWARD);
1168 if (ToReverseResult)
1172 if (Affich) DBRep::Set("BoucheTrou", Result);
1175 return Standard_True;
1178 //=======================================================================
1179 //function : Substitute
1181 //=======================================================================
1182 static void Substitute(BRepTools_Substitution& aSubstitute,
1183 const TopoDS_Edge& Old,
1184 const TopoDS_Edge& New)
1186 TopTools_ListOfShape listShape;
1188 TopoDS_Vertex OldV1, OldV2, NewV1, NewV2;
1189 TopExp::Vertices( Old, OldV1, OldV2 );
1190 TopExp::Vertices( New, NewV1, NewV2 );
1192 if (!aSubstitute.IsCopied( OldV1 ))
1194 listShape.Append( NewV1.Oriented(TopAbs_FORWARD) );
1195 aSubstitute.Substitute( OldV1, listShape );
1198 if (!aSubstitute.IsCopied( OldV2 ))
1200 listShape.Append( NewV2.Oriented(TopAbs_FORWARD) );
1201 aSubstitute.Substitute( OldV2, listShape );
1204 if (!aSubstitute.IsCopied( Old ))
1206 listShape.Append( New.Oriented(TopAbs_FORWARD) );
1207 aSubstitute.Substitute( Old, listShape );
1211 //=======================================================================
1212 //Function : SetCommonEdgeInFace
1213 //Purpose : Replace an edge of the face by the corresponding edge from
1215 //=======================================================================
1217 static void SetCommonEdgeInFace(BRepTools_Substitution& aSubstitute,
1218 const TopoDS_Shape& Face,
1219 const TopoDS_Shape& Edge)
1224 Standard_Boolean done = Standard_False;
1225 // Class BRep_Tool without fields and without Constructor :
1228 TopExp_Explorer Exp(Face, TopAbs_EDGE);
1229 Handle(Geom_Curve) Cref, C;
1230 TopLoc_Location Lref, L;
1231 // Cref = BT.Curve(TopoDS::Edge(Edge), Lref, f, l);
1232 const TopoDS_Edge& NewEdge = TopoDS::Edge(Edge);
1233 Cref = BRep_Tool::Curve( NewEdge, Lref, f, l );
1235 for ( ; Exp.More() && !done; Exp.Next()) {
1236 // C = BT.Curve(TopoDS::Edge(Exp.Current()), L, f, l);
1237 const TopoDS_Edge& OldEdge = TopoDS::Edge(Exp.Current());
1238 C = BRep_Tool::Curve(OldEdge, L, f, l);
1239 if ((Cref==C) && (Lref == L)) {
1240 done = Standard_True;
1241 Substitute( aSubstitute, OldEdge, NewEdge );
1245 if (!done) cout << "Substitution of Edge failed" << endl;
1250 //=======================================================================
1251 //Fonction : KeepEdge
1252 //Objet : Find edges of the face supported by the same Curve.
1253 //=======================================================================
1254 static void KeepEdge(const TopoDS_Shape& Face,
1255 const TopoDS_Shape& Edge,
1256 TopTools_ListOfShape& List)
1259 // Class BRep_Tool without fields and without Constructor :
1262 TopExp_Explorer Exp(Face, TopAbs_EDGE);
1263 Handle(Geom_Curve) Cref, C;
1264 TopLoc_Location Lref, L;
1265 // Cref = BT.Curve(TopoDS::Edge(Edge), Lref, f, l);
1266 Cref = BRep_Tool::Curve(TopoDS::Edge(Edge), Lref, f, l);
1268 for ( ; Exp.More(); Exp.Next()) {
1269 // C = BT.Curve(TopoDS::Edge(Exp.Current()), L, f, l);
1270 C = BRep_Tool::Curve(TopoDS::Edge(Exp.Current()), L, f, l);
1271 if ((Cref==C) && (Lref == L)) {
1272 List.Append(Exp.Current());
1277 //=======================================================================
1279 //Objet : Construct a vertex via an iso
1280 //=======================================================================
1281 static void BuildVertex(const Handle(Geom_Curve)& Iso,
1282 const Standard_Boolean isfirst,
1283 const Standard_Real First,
1284 const Standard_Real Last,
1285 TopoDS_Shape& Vertex)
1290 if (isfirst) val = First;
1292 B.MakeVertex(TopoDS::Vertex(Vertex),
1294 Precision::Confusion());
1297 //=======================================================================
1299 //Objet : Construct an empty edge
1300 //=======================================================================
1301 static TopoDS_Edge NullEdge(TopoDS_Shape& Vertex)
1306 Vertex.Orientation(TopAbs_FORWARD);
1308 B.Add(E, Vertex.Reversed());
1309 B.Degenerated(E, Standard_True);
1314 //=======================================================================
1316 //Objet : Construct an edge via an iso
1317 //=======================================================================
1318 static TopoDS_Edge BuildEdge(const Handle(Geom_Surface)& S,
1319 const Standard_Boolean isUiso,
1320 const Standard_Real ValIso,
1321 const TopoDS_Shape& VFirst,
1322 const TopoDS_Shape& VLast,
1323 const Standard_Real Tol)
1327 Handle(Geom_Curve) Iso;
1328 Standard_Boolean sing = Standard_False;
1330 Iso = S->UIso(ValIso);
1333 Iso = S->VIso(ValIso);
1336 if (VFirst.IsSame(VLast)) { // Singular case ?
1338 // Class BRep_Tool without fields and without Constructor :
1340 const TopoDS_Vertex& V = TopoDS::Vertex(VFirst);
1341 // Standard_Real tol = BT.Tolerance(V);
1342 Standard_Real tol = BRep_Tool::Tolerance(V);
1343 if (Tol > tol) tol = Tol;
1344 Iso->D0((Iso->FirstParameter()+Iso->LastParameter())/2, P);
1345 // if (P.Distance(BT.Pnt(V)) < tol) {
1346 if (P.Distance(BRep_Tool::Pnt(V)) < tol) {
1347 GeomAdaptor_Curve AC(Iso);
1348 sing = GCPnts_AbscissaPoint::Length(AC, tol/4) < tol;
1353 if (sing) { // Singular case
1358 // B.UpdateEdge(E, Iso, Precision::Confusion());
1359 B.Degenerated(E, Standard_True);
1363 // Construction Via 3d
1365 // Iso = S->UIso(ValIso);
1367 Standard_Real p1, p2, p11, p12, p21, p22;
1368 Standard_Boolean fwd = Standard_False;
1369 p1 = Iso->FirstParameter();
1370 p2 = Iso->LastParameter();
1371 P1 = Iso->Value(p1);
1372 P2 = Iso->Value(p2);
1374 Standard_Real t1 = BRep_Tool::Tolerance(TopoDS::Vertex(VFirst));
1375 Standard_Real t2 = BRep_Tool::Tolerance(TopoDS::Vertex(VLast));
1379 p11 = P1.Distance(BRep_Tool::Pnt(TopoDS::Vertex(VFirst)));
1380 p22 = P2.Distance(BRep_Tool::Pnt(TopoDS::Vertex(VLast)));
1381 p12 = P1.Distance(BRep_Tool::Pnt(TopoDS::Vertex(VLast)));
1382 p21 = P2.Distance(BRep_Tool::Pnt(TopoDS::Vertex(VFirst)));
1384 if(p11 < p12 && p22 < p21) fwd = Standard_True;
1386 if(fwd) { //OCC500(apo)
1387 if (p11 >= t1) BB.UpdateVertex(TopoDS::Vertex(VFirst), 1.01*p11);
1388 if (p22 >= t2) BB.UpdateVertex(TopoDS::Vertex(VLast), 1.01*p22);
1391 // Iso = S->VIso(ValIso);
1392 if (p12 >= t2) BB.UpdateVertex(TopoDS::Vertex(VLast), 1.01*p12);
1393 if (p21 >= t1) BB.UpdateVertex(TopoDS::Vertex(VFirst), 1.01*p21);
1396 BRepLib_MakeEdge MkE;
1399 // TopoDS::Vertex(VFirst),
1400 // TopoDS::Vertex(VLast),
1401 // Iso->FirstParameter(),
1402 // Iso->LastParameter());
1405 TopoDS::Vertex(VFirst),
1406 TopoDS::Vertex(VLast),
1407 Iso->FirstParameter(),
1408 Iso->LastParameter());
1411 TopoDS::Vertex(VLast),
1412 TopoDS::Vertex(VFirst),
1413 Iso->FirstParameter(),
1414 Iso->LastParameter());
1416 // if (!MkE.IsDone()) { // Il faut peut etre permuter les Vertex
1418 // TopoDS::Vertex(VLast),
1419 // TopoDS::Vertex(VFirst),
1420 // Iso->FirstParameter(),
1421 // Iso->LastParameter());
1424 if (!MkE.IsDone()) { // Erreur de construction !!
1427 sprintf(name,"firstvertex_error");
1428 DBRep::Set(name, VFirst);
1429 sprintf(name,"lastvertex_error");
1430 DBRep::Set(name, VLast);
1431 sprintf(name,"curve3d_error");
1433 DrawTrSurf::Set(Temp,Iso);
1434 // DrawTrSurf::Set(name,Iso);
1436 Standard_ConstructionError::Raise("BRepFill_Sweep::BuildEdge");
1443 Handle(Geom2d_Line) L;
1444 TopLoc_Location Loc;
1446 gp_Pnt2d P(ValIso, 0);
1448 L = new (Geom2d_Line) (P, V);
1451 gp_Pnt2d P(0., ValIso);
1453 L = new (Geom2d_Line) (P, V);
1456 B.UpdateEdge(E, L, S, Loc, Precision::Confusion());
1457 if (sing) B.Range(E, S, Loc,
1458 Iso->FirstParameter(),
1459 Iso->LastParameter());
1464 //=======================================================================
1466 //Objet : Complete an edge via an iso
1467 //=======================================================================
1468 static void UpdateEdge(TopoDS_Edge& E,
1469 const Handle(Geom_Surface)& S,
1470 const Standard_Boolean isUiso,
1471 const Standard_Real ValIso)
1474 Handle(Geom2d_Line) L;
1475 Handle(Geom2d_Curve) PCurve, CL;
1476 TopLoc_Location Loc;
1477 Standard_Real UFirst, ULast, VFirst, VLast, F2d, L2d;
1478 S->Bounds( UFirst, ULast, VFirst, VLast);
1480 Standard_Boolean sing = Standard_False;
1481 Handle(Geom_Curve) Iso;
1483 Iso = S->UIso(ValIso);
1486 Iso = S->VIso(ValIso);
1489 TopoDS_Vertex Vf, Vl;
1490 TopExp::Vertices(E, Vf, Vl);
1491 if (Vf.IsSame(Vl)) { // Singular case ?
1493 Standard_Real tol = BRep_Tool::Tolerance(Vf);
1494 Iso->D0((Iso->FirstParameter()+Iso->LastParameter())/2, Pmid);
1495 if (Pmid.Distance(BRep_Tool::Pnt(Vf)) < tol) {
1496 GeomAdaptor_Curve AC(Iso);
1497 sing = GCPnts_AbscissaPoint::Length(AC, tol/4) < tol;
1502 gp_Pnt2d P(ValIso, 0);
1504 L = new (Geom2d_Line) (P, V);
1509 gp_Pnt2d P(0., ValIso);
1511 L = new (Geom2d_Line) (P, V);
1515 CL = new (Geom2d_TrimmedCurve) (L, F2d, L2d);
1517 // Control direction & Range
1518 Standard_Real R, First, Last, Tol=1.e-4;
1519 Standard_Boolean reverse = Standard_False;;
1522 // Class BRep_Tool without fields and without Constructor :
1526 // BT.Range(E, First, Last);
1527 BRep_Tool::Range(E, First, Last);
1529 if (!Vf.IsSame(Vl)) {
1530 // Test distances between "FirstPoint" and "Vertex"
1531 P2d = CL->Value(F2d);
1532 POnS = S->Value(P2d.X(), P2d.Y());
1533 // reverse = POnS.Distance(BT.Pnt(Vl)) < POnS.Distance(BT.Pnt(Vf));
1534 reverse = POnS.Distance(BRep_Tool::Pnt(Vl)) < POnS.Distance(BRep_Tool::Pnt(Vf));
1537 // Test angle between "First Tangente"
1539 gp_Vec V3d, du, dv, dC3d;
1540 BRepAdaptor_Curve C3d(E);
1542 C3d.D1(First, POnS, dC3d);
1543 CL->D1(F2d, P2d, V2d);
1544 S->D1(P2d.X(), P2d.Y(), POnS, du, dv);
1545 V3d.SetLinearForm(V2d.X(), du, V2d.Y(), dv);
1546 reverse = ( dC3d.Angle(V3d) > Tol);
1548 if (reverse ) { // Return curve 2d
1549 CL = new (Geom2d_TrimmedCurve)(L, F2d, L2d);
1551 F2d = CL->FirstParameter();
1552 L2d = CL->LastParameter();
1557 Handle(Geom_Curve) NullCurve;
1558 B.UpdateEdge(E, NullCurve, 0.);
1559 B.Degenerated(E, Standard_True);
1560 B.Range(E, F2d, L2d);
1565 if (First != F2d || Last != L2d) {
1566 Handle(Geom2d_Curve) C2d;
1567 GeomLib::SameRange(Precision::PConfusion(), CL,
1568 F2d, L2d, First, Last,
1570 CL = new (Geom2d_TrimmedCurve)(C2d, First, Last);
1573 // Update des Vertex
1577 P2d = CL->Value(First);
1578 POnS = S->Value(P2d.X(), P2d.Y());
1579 V = TopExp::FirstVertex(E);
1580 // R = POnS.Distance(BT.Pnt(V));
1581 R = POnS.Distance(BRep_Tool::Pnt(V));
1582 B.UpdateVertex(V, R);
1584 P2d = CL->Value(Last);
1585 POnS = S->Value(P2d.X(), P2d.Y());
1586 V = TopExp::LastVertex(E);
1587 // R = POnS.Distance(BT.Pnt(V));
1588 R = POnS.Distance(BRep_Tool::Pnt(V));
1589 B.UpdateVertex(V, R);
1592 if (!sing && SameParameter(E, CL, S, Tol, R)) {
1596 PCurve = Couture(E, S, Loc);
1597 if (PCurve.IsNull())
1598 B.UpdateEdge(E, CL, S, Loc, Precision::Confusion());
1599 else { // Sewing edge
1602 if (e.Orientation() == TopAbs_REVERSED)
1603 B.UpdateEdge(E, CL, PCurve, S, Loc, Precision::Confusion());
1605 B.UpdateEdge(E, PCurve, CL, S, Loc, Precision::Confusion());
1608 // Attention to case not SameRange on its shapes (PRO13551)
1609 // if (!BT.SameRange(E)) B.Range(E, S, Loc, First, Last);
1610 if (!BRep_Tool::SameRange(E)) B.Range(E, S, Loc, First, Last);
1613 //=======================================================================
1614 // Object : Check if a surface is degenerated
1615 //=======================================================================
1616 static Standard_Boolean IsDegen(const Handle(Geom_Surface)& S,
1617 const Standard_Real Tol)
1619 Standard_Integer Nb = 5;
1620 Standard_Boolean B = Standard_True;
1621 Standard_Real Umax, Umin, Vmax, Vmin, t, dt, l;
1622 Standard_Integer ii;
1623 Handle(Geom_Curve) Iso;
1625 GCPnts_AbscissaPoint GC;
1627 S->Bounds(Umin, Umax, Vmin, Vmax);
1629 // Check the length of Iso-U
1630 t = (Umin + Umax)/2;
1632 S->D0(t, (Vmin+Vmax)/2, P2);
1634 B = ((P1.Distance(P2) + P2.Distance(P3)) < Tol);
1636 for (ii=1, dt = (Umax-Umin)/(Nb+1); B && (ii<=Nb); ii++) {
1639 GeomAdaptor_Curve AC(Iso);
1640 l = GC.Length(AC, Tol/4);
1644 if (B) return Standard_True;
1646 // Check the length of Iso-V
1647 t = (Vmin + Vmax)/2;
1649 S->D0((Umin+Umax)/2, t, P2);
1651 B = ((P1.Distance(P2) + P2.Distance(P3)) < Tol);
1654 for (ii=1, dt = (Vmax-Vmin)/(Nb+1); B && (ii<=Nb); ii++) {
1657 GeomAdaptor_Curve AC(Iso);
1658 l = GC.Length(AC, Tol/4);
1665 //=======================================================================
1666 //function : Constructeur
1668 //======================================================================
1669 BRepFill_Sweep::BRepFill_Sweep(const Handle(BRepFill_SectionLaw)& Section,
1670 const Handle(BRepFill_LocationLaw)& Location,
1671 const Standard_Boolean WithKPart) :
1672 isDone(Standard_False),
1680 SetTolerance(1.e-4);
1681 SetAngularControl();
1684 myApproxStyle = GeomFill_Location;
1685 myContinuity = GeomAbs_C2;
1688 myForceApproxC1 = Standard_False;
1691 //=======================================================================
1692 //function : SetBounds
1693 //purpose : Define start and end shapes
1694 //======================================================================
1695 void BRepFill_Sweep::SetBounds(const TopoDS_Wire& First,
1696 const TopoDS_Wire& Last)
1701 // It is necessary to check the SameRange on its (PRO13551)
1702 Standard_Boolean issame = Standard_True;
1704 BRepTools_WireExplorer wexp;
1705 if (!FirstShape.IsNull()) {
1706 for (wexp.Init(FirstShape); wexp.More(); wexp.Next()) {
1707 if (!BRepLib::CheckSameRange(wexp.Current())) {
1708 B.SameRange(wexp.Current(), Standard_False);
1709 B.SameParameter(wexp.Current(), Standard_False);
1710 issame = Standard_False;
1715 if (!LastShape.IsNull()) {
1716 for (wexp.Init(LastShape); wexp.More(); wexp.Next()) {
1717 if (!BRepLib::CheckSameRange(wexp.Current())) {
1718 B.SameRange(wexp.Current(), Standard_False);
1719 B.SameParameter(wexp.Current(), Standard_False);
1720 issame = Standard_False;
1727 cout<<"Sweep Warning : Edge not SameRange in the limits"<<endl;
1731 //=======================================================================
1732 //function : SetTolerance
1734 //======================================================================
1735 void BRepFill_Sweep::SetTolerance(const Standard_Real Tol3d,
1736 const Standard_Real BoundTol,
1737 const Standard_Real Tol2d,
1738 const Standard_Real TolAngular)
1741 myBoundTol = BoundTol;
1743 myTolAngular = TolAngular;
1745 //=======================================================================
1746 //function : SetAngularControl
1748 //======================================================================
1749 void BRepFill_Sweep::SetAngularControl(const Standard_Real MinAngle,
1750 const Standard_Real MaxAngle)
1752 myAngMin = Max (MinAngle, Precision::Angular());
1753 myAngMax = Min (MaxAngle, 6.28);
1756 //=======================================================================
1757 //function : SetForceApproxC1
1758 //purpose : Set the flag that indicates attempt to approximate
1759 // a C1-continuous surface if a swept surface proved
1761 //=======================================================================
1762 void BRepFill_Sweep::SetForceApproxC1(const Standard_Boolean ForceApproxC1)
1764 myForceApproxC1 = ForceApproxC1;
1767 ///=======================================================================
1768 //function : CorrectApproxParameters
1770 //=======================================================================
1771 Standard_Boolean BRepFill_Sweep::CorrectApproxParameters()
1773 TopoDS_Wire thePath = myLoc->Wire();
1774 GeomAbs_Shape NewCont = myContinuity;
1775 Standard_Integer NewSegmax = mySegmax;
1777 TopoDS_Iterator iter(thePath);
1778 for (; iter.More(); iter.Next())
1780 TopoDS_Edge anEdge = TopoDS::Edge(iter.Value());
1781 BRepAdaptor_Curve aBAcurve(anEdge);
1782 GeomAbs_Shape aContinuity = aBAcurve.Continuity();
1783 Standard_Integer aNbInterv = aBAcurve.NbIntervals(GeomAbs_CN);
1784 if (aContinuity < NewCont)
1785 NewCont = aContinuity;
1786 if (aNbInterv > NewSegmax)
1787 NewSegmax = aNbInterv;
1790 Standard_Boolean Corrected = Standard_False;
1791 if (NewCont != myContinuity || NewSegmax != mySegmax)
1792 Corrected = Standard_True;
1793 myContinuity = NewCont;
1794 mySegmax = NewSegmax;
1798 //=======================================================================
1799 //function : BuildWire
1800 //purpose : Construit a wire by sweeping
1801 //======================================================================
1802 Standard_Boolean BRepFill_Sweep::
1803 BuildWire(const BRepFill_TransitionStyle /*Transition*/)
1805 Standard_Integer ipath, isec = 1;
1809 // Class BRep_Tool without fields and without Constructor :
1811 Standard_Integer NbPath = myLoc->NbLaw();
1812 Standard_Boolean vclose;
1813 vclose = (myLoc->IsClosed() && (myLoc->IsG1(0, myTol3d)>= 0));
1815 Handle(Geom_Surface) S;
1816 Handle(Geom_Curve) Iso;
1817 Standard_Real val, bid, First, Last, Tol;
1823 // (1) Construction of all curves
1825 // (1.1) Construction of Tables
1826 myFaces = new (TopTools_HArray2OfShape) (1, 1, 1, NbPath);
1827 myUEdges = new (TopTools_HArray2OfShape) (1, 2, 1, NbPath);
1828 myVEdges = new (TopTools_HArray2OfShape) (1, 1, 1, NbPath+1);
1830 // (1.2) Calculate curves / vertex / edge
1831 for (ipath=1; ipath <=NbPath; ipath++) {
1832 // Curve by iso value
1833 GeomFill_Sweep Sweep(myLoc->Law(ipath), KPart);
1834 Sweep.SetTolerance(myTol3d, myBoundTol, myTol2d, myTolAngular);
1835 Sweep.SetForceApproxC1(myForceApproxC1);
1836 Sweep.Build(mySec->Law(isec), myApproxStyle, myContinuity, myDegmax, mySegmax);
1837 if (!Sweep.IsDone())
1838 return Standard_False;
1839 S = Sweep.Surface();
1840 if (Sweep.ExchangeUV()) {
1841 if (Sweep.UReversed()) S->Bounds(First, Last, bid, val);
1842 else S->Bounds(First, Last, val, bid);
1846 if (Sweep.UReversed()) S->Bounds(bid, val, First, Last);
1847 else S->Bounds(val, bid, First, Last);
1850 // Vertex by position
1852 BuildVertex(Iso, Standard_False, First, Last,
1853 myVEdges->ChangeValue(1, ipath+1));
1856 TopoDS_Vertex& V = TopoDS::Vertex(myVEdges->ChangeValue(1, 1));
1857 myVEdges->SetValue(1, ipath+1, V);
1859 // Tol = P1.Distance(BT.Pnt(V));
1860 Tol = P1.Distance(BRep_Tool::Pnt(V));
1861 B.UpdateVertex(V, Tol);
1864 if (!LastShape.IsNull()) myVEdges->SetValue(1, NbPath, FirstShape);
1865 else BuildVertex(Iso, Standard_False, First, Last,
1866 myVEdges->ChangeValue(1, NbPath+1));
1872 TopoDS_Vertex& V = TopoDS::Vertex(myVEdges->ChangeValue(1, ipath));
1873 // Tol = P1.Distance(BT.Pnt(V));
1874 Tol = P1.Distance(BRep_Tool::Pnt(V));
1875 B.UpdateVertex(V, Tol);
1878 if (!FirstShape.IsNull()) myVEdges->SetValue(1,1, FirstShape);
1879 else BuildVertex(Iso, Standard_True, First, Last,
1880 myVEdges->ChangeValue(1, 1));
1883 // Construction of the edge
1884 BRepLib_MakeEdge MkE;
1886 TopoDS::Vertex(myVEdges->Value(1, ipath)),
1887 TopoDS::Vertex(myVEdges->Value(1, ipath+1)),
1888 Iso->FirstParameter(),
1889 Iso->LastParameter());
1890 if (!MkE.IsDone()) { // Error of construction !!
1893 sprintf(name,"firstvertex_error");
1894 DBRep::Set(name, myVEdges->Value(1, ipath));
1895 sprintf(name,"lastvertex_error");
1896 DBRep::Set(name, myVEdges->Value(1, ipath+1));
1897 sprintf(name,"curve3d_error");
1899 DrawTrSurf::Set(Temp,Iso);
1900 // DrawTrSurf::Set(name,Iso);
1901 Standard_ConstructionError::Raise("BRepFill_Sweep::BuildEdge");
1903 return Standard_False;
1908 sprintf(name,"Surf_%d", ipath);
1910 DrawTrSurf::Set(Temp, S);
1911 // DrawTrSurf::Set(name, S);
1912 sprintf(name,"Edge_%d", ipath);
1913 DBRep::Set(name, E);
1916 B.UpdateEdge(E, Sweep.ErrorOnSurface());
1918 myFaces->SetValue(1, ipath, E);
1921 return Standard_True;
1924 //=======================================================================
1925 //function : BuildShell
1926 //purpose : Construct a Shell by sweeping
1927 //======================================================================
1928 Standard_Boolean BRepFill_Sweep::
1929 BuildShell(const BRepFill_TransitionStyle /*Transition*/,
1930 const Standard_Integer IFirst,
1931 const Standard_Integer ILast,
1932 const Standard_Real ExtendFirst,
1933 const Standard_Real ExtendLast)
1935 Standard_Integer ipath, isec, IPath;
1940 Standard_Integer NbPath = ILast - IFirst;
1941 Standard_Integer NbLaw = mySec->NbLaw();
1942 Standard_Boolean uclose, vclose, constSection, hasdegen = Standard_False;
1943 constSection = mySec->IsConstant();
1944 uclose = mySec->IsUClosed();
1945 vclose = (mySec->IsVClosed() && myLoc->IsClosed()) &&
1946 (NbPath == myLoc->NbLaw()) && (myLoc->IsG1(0, myTol3d)>= 0);
1949 // (1) Construction of all surfaces
1951 // (1.1) Construction of Tables
1953 TColStd_Array2OfInteger ExchUV(1, NbLaw, 1, NbPath);
1954 TColStd_Array2OfInteger UReverse(1, NbLaw, 1, NbPath);
1955 TColStd_Array2OfInteger Degenerated(1, NbLaw, 1, NbPath);
1956 Degenerated.Init(0);
1957 // No VReverse for the moment...
1958 TColStd_Array2OfReal TabErr(1, NbLaw , 1, NbPath);
1959 TColGeom_Array2OfSurface TabS(1, NbLaw , 1, NbPath);
1961 TopTools_Array2OfShape UEdge(1, NbLaw+1, 1, NbPath);
1962 TopTools_Array2OfShape VEdge(1, NbLaw , 1, NbPath+1);
1963 TopTools_Array2OfShape Vertex(1,NbLaw+1, 1, NbPath+1);
1965 TopoDS_Vertex VNULL;
1969 TopTools_Array1OfShape SecVertex(1, NbLaw+1);
1970 TColStd_Array1OfReal VError(1, NbLaw+1);
1971 TColStd_Array1OfReal Vi(1, NbPath+1);
1973 //Initialization of management of parametric intervals
1974 //(Case of evolutionary sections)
1975 Standard_Real Length, SecDom, SecDeb;
1976 myLoc->CurvilinearBounds(myLoc->NbLaw(), SecDom, Length);
1977 mySec->Law(1)->GetDomain(SecDeb, SecDom);
1980 Standard_Real Lf, Ll;
1981 myLoc->CurvilinearBounds(IFirst-1, Lf, Ll);
1982 Vi(1) = SecDeb + (Ll/Length)*SecDom;
1987 // Error a priori on vertices
1989 for (isec=1; isec<=NbLaw+1; isec++) {
1990 VError(isec) = mySec->VertexTol(isec-1, 0.);
1991 SecVertex(isec) = mySec->Vertex(isec, 0.);
1996 // (1.2) Calculate surfaces
1997 for (ipath=1, IPath=IFirst; ipath <=NbPath; ipath++, IPath++) {
1999 GeomFill_Sweep Sweep(myLoc->Law(IPath), KPart);
2000 Sweep.SetTolerance(myTol3d, myBoundTol, myTol2d, myTolAngular);
2001 Sweep.SetForceApproxC1(myForceApproxC1);
2003 // Case of evolutionary section, definition of parametric correspondence
2004 if (!constSection) {
2005 Standard_Real lf, ll, Lf, Ll;
2006 myLoc->Law(IPath)->GetDomain(lf, ll);
2007 myLoc->CurvilinearBounds(IPath, Lf, Ll);
2008 Vi(ipath+1) = SecDeb + (Ll/Length)*SecDom;
2009 Sweep.SetDomain(lf, ll, Vi(ipath), Vi(ipath+1));
2011 else //section is constant
2013 Standard_Real lf, ll, Lf, Ll;
2014 myLoc->Law(IPath)->GetDomain(lf, ll);
2015 myLoc->CurvilinearBounds(IPath, Lf, Ll);
2016 Vi(ipath+1) = SecDeb + (Ll/Length)*SecDom;
2019 for(isec=1; isec<=NbLaw; isec++) {
2020 Sweep.Build(mySec->Law(isec), myApproxStyle, myContinuity, myDegmax, mySegmax);
2021 if (!Sweep.IsDone())
2022 return Standard_False;
2023 TabS(isec,ipath) = Sweep.Surface();
2024 TabErr(isec,ipath) = Sweep.ErrorOnSurface();
2025 ExchUV(isec, ipath) = Sweep.ExchangeUV();
2026 UReverse(isec, ipath) = Sweep.UReversed();
2027 if (Sweep.ErrorOnSurface()>Error) Error = Sweep.ErrorOnSurface();
2029 if ((ipath==1)&&(ExtendFirst>0)) {
2030 Handle(Geom_BoundedSurface) BndS;
2031 BndS = Handle(Geom_BoundedSurface)::DownCast(TabS(isec,ipath));
2032 GeomLib::ExtendSurfByLength(BndS, ExtendFirst, 1,
2033 Sweep.ExchangeUV(), Standard_False);
2034 TabS(isec,ipath) = BndS;
2036 if ((ipath==NbPath)&&(ExtendLast>0)){
2037 Handle(Geom_BoundedSurface) BndS;
2038 BndS = Handle(Geom_BoundedSurface)::DownCast(TabS(isec,ipath));
2039 GeomLib::ExtendSurfByLength(BndS, ExtendLast, 1,
2040 Sweep.ExchangeUV(), Standard_True);
2041 TabS(isec,ipath) = BndS;
2046 sprintf(name,"Surf_%d_%d", isec, IPath);
2048 DrawTrSurf::Set(Temp, TabS(isec,ipath));
2054 // (2) Construction of Edges
2055 Standard_Real UFirst, ULast, VFirst, VLast;
2056 Standard_Boolean exuv, singu, singv;
2057 Handle(Geom_Surface) S;
2060 // (2.0) return preexisting Edges and vertices
2062 if (! FirstShape.IsNull() && (IFirst==1)) {
2063 mySec->Init(FirstShape);
2064 for (isec=1; isec<=NbLaw; isec++) {
2065 E = mySec->CurrentEdge();
2067 if (E.Orientation() == TopAbs_REVERSED)
2068 Vertex(isec+1, 1) = TopExp::FirstVertex(E);
2070 Vertex(isec+1, 1) = TopExp::LastVertex(E);
2071 UpdateVertex(IFirst-1, isec+1,
2072 TabErr(isec, 1), Vi(1), Vertex(isec+1, 1));
2074 if (VEdge(1, 1).Orientation() == TopAbs_REVERSED)
2075 Vertex(1, 1) = TopExp::LastVertex(TopoDS::Edge(VEdge(1, 1)));
2077 Vertex(1, 1) = TopExp::FirstVertex(TopoDS::Edge(VEdge(1, 1)));
2078 UpdateVertex(IFirst-1, 1,
2079 TabErr(1, 1), Vi(1), Vertex(1, 1));
2081 else { // Otherwise construct vertices
2082 Standard_Real u, v, aux;
2083 Standard_Boolean ureverse;
2084 for (isec=1; isec<=NbLaw+1; isec++) {
2088 ureverse = UReverse(NbLaw, 1);
2089 exuv = ExchUV(NbLaw, 1);
2093 ureverse = UReverse(isec, 1);
2094 exuv = ExchUV(isec, 1);
2096 S->Bounds(UFirst, ULast, VFirst, VLast);
2098 // Choice of parameters
2101 aux = VFirst; VFirst = VLast; VLast = aux;
2104 aux = UFirst; UFirst = ULast; ULast = aux;
2107 if (isec!= NbLaw+1) {
2122 // construction of vertices
2123 B.MakeVertex(TopoDS::Vertex(Vertex(isec, 1)),
2125 mySec->VertexTol(isec-1,Vi(1)));
2129 if (! LastShape.IsNull() && (ILast==myLoc->NbLaw()+1) ) {
2130 mySec->Init(LastShape);
2131 for (isec=1; isec<=NbLaw; isec++) {
2132 E = mySec->CurrentEdge();
2133 VEdge(isec, NbPath+1) = E;
2134 if (E.Orientation() == TopAbs_REVERSED)
2135 Vertex(isec+1, NbPath+1) = TopExp::FirstVertex(E);
2137 Vertex(isec+1, NbPath+1) = TopExp::LastVertex(E);
2138 UpdateVertex(ILast-1, isec+1, TabErr(isec, NbPath),
2139 Vi(NbPath+1), Vertex(isec+1, NbPath+1));
2141 if (VEdge(1, NbPath+1).Orientation() == TopAbs_REVERSED)
2142 Vertex(1, NbPath+1) =
2143 TopExp::LastVertex(TopoDS::Edge(VEdge(1, NbPath+1)));
2145 Vertex(1, NbPath+1) =
2146 TopExp::FirstVertex(TopoDS::Edge(VEdge(1, NbPath+1)));
2147 UpdateVertex(ILast-1, 1,
2148 TabErr(1, NbPath), Vi(NbPath+1), Vertex(1, NbPath+1 ));
2151 Standard_Real u, v, aux;
2152 Standard_Boolean ureverse;
2153 for (isec=1; isec<=NbLaw+1; isec++) {
2156 S = TabS(NbLaw, NbPath);
2157 ureverse = UReverse(NbLaw, NbPath);
2158 exuv = ExchUV(NbLaw, NbPath);
2161 S = TabS(isec, NbPath);
2162 ureverse = UReverse(isec, NbPath);
2163 exuv = ExchUV(isec, NbPath);
2165 S->Bounds(UFirst, ULast, VFirst, VLast);
2167 // Choice of parametres
2170 aux = VFirst; VFirst = VLast; VLast = aux;
2173 aux = UFirst; UFirst = ULast; ULast = aux;
2176 if (isec == NbLaw+1) {
2191 // construction of vertex
2192 B.MakeVertex(TopoDS::Vertex(Vertex(isec, NbPath+1)),
2194 mySec->VertexTol(isec-1, Vi(NbPath+1)));
2200 // ---------- Creation of Vertex and edge ------------
2201 for (ipath=1, IPath=IFirst; ipath<=NbPath;
2203 for (isec=1; isec <=NbLaw; isec++) {
2204 S = TabS(isec, ipath);
2205 exuv = ExchUV(isec, ipath);
2206 S->Bounds(UFirst, ULast, VFirst, VLast);
2207 if (UReverse(isec, ipath)) {
2210 aux = VFirst; VFirst = VLast; VLast = aux;
2213 aux = UFirst; UFirst = ULast; ULast = aux;
2217 // (2.1) Construction of new vertices
2219 if (ipath == 1 && Vertex(1, 1).IsNull()) {
2222 myLoc->PerformVertex(IPath-1,
2223 TopoDS::Vertex(SecVertex(1)),
2225 TopoDS::Vertex(Vertex(1, 1)));
2227 myLoc->PerformVertex(IPath-1,
2228 mySec->Vertex(1,Vi(1)),
2229 mySec->VertexTol(0,Vi(1)),
2230 TopoDS::Vertex(Vertex(1, 1)));
2232 // the first and the next column
2233 if (vclose &&(ipath == NbPath) ) {
2234 Vertex(1, ipath+1) = Vertex(1, 1);
2236 else if (Vertex(1, ipath+1).IsNull()) {
2238 myLoc->PerformVertex(IPath,
2239 TopoDS::Vertex(SecVertex(1)),
2240 TabErr(1,ipath)+VError(1),
2241 TopoDS::Vertex(Vertex(1, ipath+1)) );
2243 myLoc->PerformVertex(IPath,
2244 mySec->Vertex(1,Vi(ipath+1)),
2246 mySec->VertexTol(0,Vi(ipath+1)),
2247 TopoDS::Vertex(Vertex(1, ipath+1)));
2249 if (MergeVertex(Vertex(1,ipath), Vertex(1,ipath+1))) {
2250 UEdge(1, ipath) = NullEdge(Vertex(1,ipath));
2256 if (uclose && (isec == NbLaw)) {
2257 Vertex(isec+1, 1) = Vertex(1, 1);
2259 else if (Vertex(isec+1, 1).IsNull()) {
2261 myLoc->PerformVertex(IPath-1,
2262 TopoDS::Vertex(SecVertex(isec+1)),
2263 TabErr(isec,1)+VError(isec+1),
2264 TopoDS::Vertex(Vertex(isec+1, 1)) );
2266 myLoc->PerformVertex(IPath-1,
2267 mySec->Vertex(isec+1,Vi(1)),
2269 mySec->VertexTol(isec,Vi(1)),
2270 TopoDS::Vertex(Vertex(isec+1, 1)) );
2271 if (MergeVertex(Vertex(isec,1), Vertex(isec+1,1))) {
2272 VEdge(isec, 1) = NullEdge(Vertex(isec, 1));
2276 if (uclose && (isec == NbLaw)) {
2277 Vertex(isec+1, ipath+1) = Vertex(1, ipath+1);
2279 else if (vclose && (ipath == NbPath)) {
2280 Vertex(isec+1, ipath+1) = Vertex(isec+1, 1);
2282 else if (Vertex(isec+1, ipath+1).IsNull()) {
2284 myLoc->PerformVertex(IPath,
2285 TopoDS::Vertex(SecVertex(isec+1)),
2286 TabErr(isec, ipath)+ VError(isec+1),
2287 TopoDS::Vertex(Vertex(isec+1, ipath+1)) );
2289 myLoc->PerformVertex(IPath,
2290 mySec->Vertex(isec+1,Vi(ipath+1)),
2291 TabErr(isec, ipath) +
2292 mySec->VertexTol(isec, Vi(ipath+1)),
2293 TopoDS::Vertex(Vertex(isec+1, ipath+1)) );
2297 singv = MergeVertex(Vertex(isec,ipath+1), Vertex(isec+1,ipath+1));
2298 singu = MergeVertex(Vertex(isec+1,ipath), Vertex(isec+1,ipath+1));
2302 if (singu || singv) {
2303 Degenerated(isec, ipath) = IsDegen(TabS(isec,ipath),
2304 Max(myTol3d, TabErr(isec,ipath)));
2306 if (Degenerated(isec, ipath)) {
2308 cout << "Sweep : Degenerated case" << endl;
2310 hasdegen = Standard_True;
2311 // Particular construction of edges
2312 if (UEdge(isec+1, ipath).IsNull()) {
2315 UEdge(isec+1, ipath) = NullEdge(Vertex(isec+1,ipath));
2317 else { // Copy the previous edge
2318 UEdge(isec+1, ipath) = UEdge(isec, ipath);
2321 if (VEdge(isec, ipath+1).IsNull()) {
2324 VEdge(isec, ipath+1) = NullEdge(Vertex(isec,ipath+1));
2326 else { // Copy the previous edge
2327 VEdge(isec, ipath+1) = VEdge(isec, ipath);
2331 else { // Construction of edges by isos
2334 UV = UFirst; UFirst = VFirst; VFirst = UV;
2335 UV = ULast ; ULast = VLast ; VLast = UV;
2340 if (!Vertex(1,ipath).IsSame(Vertex(1,ipath+1))) {
2341 gp_Pnt P1 = BRep_Tool::Pnt(TopoDS::Vertex(Vertex(1,ipath)));
2342 gp_Pnt P2 = BRep_Tool::Pnt(TopoDS::Vertex(Vertex(1,ipath+1)));
2343 if (P1.Distance(P2) <= myTol3d)
2344 Vertex(1,ipath+1) = Vertex(1,ipath);
2346 UEdge(1, ipath) = BuildEdge(S, !exuv, UFirst,
2351 else UpdateEdge(TopoDS::Edge(UEdge(isec, ipath)),
2354 if (uclose && (isec==NbLaw)) {
2355 UpdateEdge(TopoDS::Edge(UEdge(1, ipath)),
2357 UEdge(isec+1, ipath) = UEdge(1, ipath);
2360 UEdge(isec+1, ipath) = BuildEdge(S, !exuv, ULast,
2361 Vertex(isec+1, ipath),
2362 Vertex(isec+1, ipath+1),
2367 if (ipath == 1 && VEdge(isec, ipath).IsNull())
2368 VEdge(isec, ipath) = BuildEdge(S, exuv, VFirst,
2373 else UpdateEdge(TopoDS::Edge(VEdge(isec, ipath)),
2376 if (vclose && (ipath == NbPath)) {
2377 UpdateEdge(TopoDS::Edge(VEdge(isec, 1)),
2379 VEdge(isec, ipath+1) = VEdge(isec, 1);
2381 else if (VEdge(isec, ipath+1).IsNull())
2382 VEdge(isec, ipath+1) = BuildEdge(S, exuv, VLast,
2383 Vertex(isec , ipath+1),
2384 Vertex(isec+1, ipath+1),
2386 else UpdateEdge(TopoDS::Edge(VEdge(isec, ipath+1)),
2390 }// End of construction of edges
2393 // (3) Construction of Faces
2398 for (ipath=1, IPath=IFirst; ipath<=NbPath; ipath++, IPath++) {
2399 for (isec=1; isec <=NbLaw+1; isec++){
2400 sprintf(name,"uedge_%d_%d", isec, IPath);
2401 DBRep::Set(name,UEdge(isec, ipath));
2405 for (ipath=1, IPath=IFirst; ipath<=NbPath+1; ipath++, IPath++) {
2406 for (isec=1; isec <=NbLaw; isec++){
2407 sprintf(name,"vedge_%d_%d", isec, IPath);
2408 DBRep::Set(name,VEdge(isec, ipath));
2411 for (isec=1; isec <=NbLaw+1; isec++){
2412 sprintf(name,"vertex_%d_%d", isec, IPath);
2413 DBRep::Set(name,Vertex(isec, ipath));
2419 for (ipath=1, IPath=IFirst; ipath<=NbPath; ipath++, IPath++) {
2420 for (isec=1; isec <=NbLaw; isec++) {
2421 if (Degenerated(isec, ipath)) {
2422 if (UEdge(isec, ipath).IsSame(UEdge(isec+1, ipath)))
2423 myFaces->SetValue(isec, IPath, UEdge(isec, ipath));
2425 myFaces->SetValue(isec, IPath, VEdge(isec, ipath));
2428 BuildFace(TabS(isec,ipath),
2429 TopoDS::Edge(UEdge(isec, ipath)),
2430 TopoDS::Edge(VEdge(isec, ipath)),
2431 TopoDS::Edge(UEdge(isec+1, ipath)),
2432 TopoDS::Edge(VEdge(isec, ipath+1)),
2434 ExchUV(isec, ipath),
2435 UReverse(isec, ipath),
2437 myFaces->SetValue(isec, IPath, face);
2443 // (4) History and Continuity
2446 //(4.1) // Degenerated case => Sledgehammer
2447 TopoDS_Compound Comp;
2448 B.MakeCompound(Comp);
2449 for (isec=1; isec <= NbLaw+1; isec++)
2450 for (ipath=1, IPath=IFirst; ipath<= NbPath+1; ipath++, IPath++) {
2451 if (ipath <= NbPath) myUEdges->SetValue(isec, IPath, UEdge(isec, ipath));
2452 if (isec <= NbLaw) myVEdges->SetValue(isec, IPath, VEdge(isec, ipath));
2453 if ((ipath <= NbPath) && (isec <= NbLaw) &&
2454 (myFaces->Value(isec, IPath).ShapeType() == TopAbs_FACE))
2455 B.Add(Comp, myFaces->Value(isec, IPath));
2457 BRepLib::EncodeRegularity(Comp, myTolAngular);
2460 //(4.2) // General case => Tweezers
2461 Standard_Boolean isG1;
2465 for (isec=1; isec <= NbLaw+1; isec++) {
2467 (mySec->Continuity(isec-1, myTolAngular) >= GeomAbs_G1);
2468 else isG1 = Standard_False;
2469 for (ipath=1, IPath=IFirst; ipath<= NbPath; ipath++, IPath++) {
2470 myUEdges->SetValue(isec, IPath, UEdge(isec, ipath));
2472 if (isec == NbLaw+1) FF = TopoDS::Face(myFaces->Value(1, IPath));
2473 else FF = TopoDS::Face(myFaces->Value(isec, IPath));
2474 B.Continuity(TopoDS::Edge(myUEdges->Value(isec, IPath)),
2475 TopoDS::Face(myFaces->Value(isec-1, IPath)),
2481 Standard_Integer nbpath = NbPath;
2482 if (vclose) nbpath++; //Another test G1
2483 for (ipath=1, IPath=IFirst; ipath<= NbPath+1; ipath++, IPath++) {
2484 if ((ipath > 1) && (ipath <=nbpath))
2485 isG1 = (myLoc->IsG1(IPath-1, myTol3d, myTolAngular) >= 0);
2486 else isG1 = Standard_False;
2487 for (isec=1; isec <= NbLaw; isec++) {
2488 myVEdges->SetValue(isec, IPath, VEdge(isec, ipath));
2490 if (ipath==NbPath+1) FF = TopoDS::Face(myFaces->Value(isec, 1));
2491 else FF = TopoDS::Face(myFaces->Value(isec, IPath));
2492 E = TopoDS::Edge(myVEdges->Value(isec, IPath));
2493 BRepLib::EncodeRegularity(E, FF,
2494 TopoDS::Face(myFaces->Value(isec, IPath-1)),
2500 return Standard_True;
2503 //=======================================================================
2505 //purpose : Construt the result of sweeping
2506 //======================================================================
2507 void BRepFill_Sweep::Build(const BRepFill_TransitionStyle Transition,
2508 const GeomAbs_Shape Continuity,
2509 const GeomFill_ApproxStyle Approx,
2510 const Standard_Integer Degmax,
2511 const Standard_Integer Segmax)
2513 myContinuity = Continuity;
2514 myApproxStyle = Approx;
2518 CorrectApproxParameters();
2521 if (mySec->IsVertex()) isDone = BuildWire(Transition);
2524 Standard_Integer NbTrous = myLoc->NbHoles(myTol3d),
2525 NbPath = myLoc->NbLaw(),
2526 NbLaw = mySec->NbLaw(), ii, jj, NbPart=1;
2527 Standard_Integer ipath, isec;
2529 myUEdges = new (TopTools_HArray2OfShape) (1, NbLaw+1, 1, NbPath);
2530 myVEdges = new (TopTools_HArray2OfShape) (1, NbLaw, 1, NbPath+1);
2531 myFaces = new (TopTools_HArray2OfShape) (1, NbLaw, 1, NbPath);
2532 Handle (TopTools_HArray2OfShape) Bounds =
2533 new (TopTools_HArray2OfShape) (1, NbLaw, 1, 2);
2535 Handle(TColStd_HArray1OfInteger) Trous;
2537 if (NbTrous>0) { // How many sub-parts ?
2538 Trous = new (TColStd_HArray1OfInteger) (1, NbTrous);
2539 myLoc->Holes(Trous->ChangeArray1());
2541 if (Trous->Value(NbTrous) == NbPath+1) NbPart--;
2543 if (NbPart == 1) { // This is done at once
2544 Standard_Real Extend = 0.0;
2545 if (NbTrous==1) Extend = EvalExtrapol(1, Transition);
2546 isDone = BuildShell(Transition,
2550 else { // This is done piece by piece
2551 Standard_Integer IFirst = 1, ILast;
2552 for (ii=1, isDone=Standard_True;
2553 ii<=NbPart && isDone; ii++) {
2554 if (ii > NbTrous) ILast = NbPath+1;
2555 else ILast = Trous->Value(ii);
2556 isDone = BuildShell(Transition,
2558 EvalExtrapol(IFirst, Transition),
2559 EvalExtrapol(ILast, Transition));
2561 Translate(myVEdges, IFirst, Bounds, 2);
2562 PerformCorner(IFirst,
2563 Transition, Bounds);
2566 Translate(myVEdges, IFirst, Bounds, 1);
2569 // Management of looping ends
2570 if ( (NbTrous>0) && (myLoc->IsClosed()) &&
2571 (Trous->Value(NbTrous) == NbPath+1) ) {
2572 Translate(myVEdges, NbPath+1, Bounds, 1);
2573 Translate(myVEdges, 1, Bounds, 2);
2574 PerformCorner(1, Transition, Bounds);
2577 // Construction of the shell
2580 for (ipath=1; ipath<=NbPath; ipath++)
2581 for (isec=1; isec <=NbLaw; isec++) {
2582 const TopoDS_Shape& face = myFaces->Value(isec, ipath);
2583 if (!face.IsNull() &&
2584 (face.ShapeType() == TopAbs_FACE) ) B.Add(shell, face);
2587 TopTools_ListIteratorOfListOfShape It(myAuxShape);
2588 for (; It.More(); It.Next()) {
2589 const TopoDS_Shape& face = It.Value();
2590 if (!face.IsNull() &&
2591 (face.ShapeType() == TopAbs_FACE) ) B.Add(shell, face);
2593 //Set common Uedges to faces
2594 BRepTools_Substitution aSubstitute;
2596 for (ii = 1; ii <= NbLaw; ii++)
2597 for (jj = 1; jj <= NbPath; jj++)
2599 SetCommonEdgeInFace(aSubstitute,
2600 myFaces->Value(ii, jj),
2601 myUEdges->Value(ii, jj));
2602 SetCommonEdgeInFace(aSubstitute,
2603 myFaces->Value(ii, jj),
2604 myUEdges->Value(ii+1, jj));
2606 if (mySec->IsUClosed())
2607 for (jj = 1; jj <= NbPath; jj++)
2608 SetCommonEdgeInFace(aSubstitute,
2609 myFaces->Value( 1, jj ),
2610 myUEdges->Value( NbLaw+1, jj));
2612 TopTools_DataMapIteratorOfDataMapOfShapeShape mapit( myVEdgesModified );
2613 for (; mapit.More(); mapit.Next())
2615 const TopoDS_Edge& OldEdge = TopoDS::Edge(mapit.Key());
2616 const TopoDS_Edge& NewEdge = TopoDS::Edge(mapit.Value());
2617 Substitute( aSubstitute, OldEdge, NewEdge );
2619 aSubstitute.Build( shell );
2620 if (aSubstitute.IsCopied( shell )) {
2621 const TopTools_ListOfShape& listSh = aSubstitute.Copy( shell );
2622 shell = TopoDS::Shell( listSh.First() );
2625 for (ii = myFaces->LowerRow(); ii <= myFaces->UpperRow(); ii++) {
2626 for (jj = myFaces->LowerCol(); jj <= myFaces->UpperCol(); jj++) {
2627 const TopoDS_Shape& aLocalShape = myFaces->Value(ii, jj);
2629 if(!aLocalShape.IsNull() && aSubstitute.IsCopied(aLocalShape)) {
2630 const TopTools_ListOfShape& aList = aSubstitute.Copy(aLocalShape);
2632 if(!aList.IsEmpty())
2633 myFaces->ChangeValue(ii, jj) = aList.First();
2638 for (ii = myVEdges->LowerRow(); ii <= myVEdges->UpperRow(); ii++) {
2639 for (jj = myVEdges->LowerCol(); jj <= myVEdges->UpperCol(); jj++) {
2640 const TopoDS_Shape& aLocalShape = myVEdges->Value(ii, jj);
2642 if(!aLocalShape.IsNull() && aSubstitute.IsCopied(aLocalShape)) {
2643 const TopTools_ListOfShape& aList = aSubstitute.Copy(aLocalShape);
2645 if(!aList.IsEmpty())
2646 myVEdges->ChangeValue(ii, jj) = aList.First();
2651 for (ii = myUEdges->LowerRow(); ii <= myUEdges->UpperRow(); ii++) {
2652 for (jj = myUEdges->LowerCol(); jj <= myUEdges->UpperCol(); jj++) {
2653 const TopoDS_Shape& aLocalShape = myUEdges->Value(ii, jj);
2655 if(!aLocalShape.IsNull() && aSubstitute.IsCopied(aLocalShape)) {
2656 const TopTools_ListOfShape& aList = aSubstitute.Copy(aLocalShape);
2658 if(!aList.IsEmpty())
2659 myUEdges->ChangeValue(ii, jj) = aList.First();
2665 if (myLoc->IsClosed() && mySec->IsUClosed()) {
2667 Standard_Boolean closed = Standard_True;
2668 Standard_Integer iedge;
2669 TopTools_IndexedDataMapOfShapeListOfShape EFmap;
2670 TopExp::MapShapesAndAncestors(shell, TopAbs_EDGE,
2671 TopAbs_FACE, EFmap);
2673 for (iedge = 1; iedge <=EFmap.Extent() && closed; iedge++) {
2674 const TopoDS_Edge& theEdge = TopoDS::Edge(EFmap.FindKey(iedge));
2675 if (BRep_Tool::Degenerated(theEdge)) continue;
2676 closed = ( EFmap(iedge).Extent() > 1);
2678 shell.Closed(closed);
2685 //=======================================================================
2688 //=======================================================================
2689 Standard_Boolean BRepFill_Sweep::IsDone() const
2694 //=======================================================================
2697 //=======================================================================
2698 TopoDS_Shape BRepFill_Sweep::Shape() const
2703 //=======================================================================
2704 //function : ErrorOnSurface
2706 //=======================================================================
2707 Standard_Real BRepFill_Sweep::ErrorOnSurface() const
2712 //=======================================================================
2713 //function : SubShape
2714 //purpose : Faces obtained by sweeping
2715 //=======================================================================
2716 Handle(TopTools_HArray2OfShape) BRepFill_Sweep::SubShape() const
2721 //=======================================================================
2722 //function : InterFaces
2723 //purpose : Edges obtained by sweeping
2724 //=======================================================================
2725 Handle(TopTools_HArray2OfShape) BRepFill_Sweep::InterFaces() const
2730 //=======================================================================
2731 //function : Sections
2732 //purpose : Edges or Face (or compound of 2) Transition between 2 sweepings
2733 //=======================================================================
2734 Handle(TopTools_HArray2OfShape) BRepFill_Sweep::Sections() const
2739 //=======================================================================
2740 //function : PerformCorner
2741 //purpose : Trim and/or loop a corner
2742 //======================================================================
2743 void BRepFill_Sweep::PerformCorner(const Standard_Integer Index,
2744 const BRepFill_TransitionStyle Transition,
2745 const Handle(TopTools_HArray2OfShape)& Bounds)
2748 if (Transition == BRepFill_Modified) return; // Do nothing.
2750 BRepFill_TransitionStyle TheTransition = Transition;
2751 Standard_Boolean isTangent=Standard_False;
2753 Standard_Integer I1, I2, ii; //, jj;
2755 gp_Vec T1, T2, Tang, Sortant;
2757 //Handle(TopTools_HArray1OfShape) TheShape =
2758 //new TopTools_HArray1OfShape( 1, mySec->NbLaw() );
2759 // TopTools_ListIteratorOfListOfShape Iterator;
2766 I1 = myLoc->NbLaw();
2770 // Construct an axis supported by the bissectrice
2771 myLoc->Law(I1)->GetDomain(F, L);
2772 myLoc->Law(I1)->GetCurve()->D1(L, P1, T1);
2775 myLoc->Law(I2)->GetDomain(F, L);
2776 myLoc->Law(I2)->GetCurve()->D1(F, P2, T2);
2779 if (T1.Angle(T2) < myAngMin) {
2780 isTangent = Standard_True;
2783 myLoc->Law(I1)->GetDomain(F, L);
2784 myLoc->Law(I1)->D0(L, M, V);
2786 myLoc->Law(I2)->GetDomain(F, L);
2787 myLoc->Law(I2)->D0(L, M, V);
2790 if (t1.Angle(t2) < myAngMin) {
2792 cout << "BRepFill_Sweep::PerformCorner : This is not a corner !" << endl;
2799 if ((TheTransition == BRepFill_Right)
2800 && (T1.Angle(T2) > myAngMax) ) {
2801 TheTransition = BRepFill_Round;
2804 Tang = T1 + T2; //Average direction
2805 gp_Dir NormalOfBisPlane = Tang;
2808 Sortant -= Tang.Dot(Tang)*Tang;
2811 Sortant = T2-T1; //Direction input
2812 Sortant *= -1; // " " output
2813 Tang -= (Tang.Dot(T2))*T2;
2816 P1.BaryCenter(0.5, P2, 0.5);
2820 gp_Ax2 Axe (P1, N, Dx);
2821 gp_Ax2 AxeOfBisPlane( P1, NormalOfBisPlane );
2823 // Construct 2 intersecting Shells
2824 Handle (TopTools_HArray2OfShape) UEdges =
2825 new TopTools_HArray2OfShape( 1, mySec->NbLaw()+1, 1, myLoc->NbLaw() );
2826 UEdges->ChangeArray2() = myUEdges->Array2();
2828 // modified by NIZHNY-MKK Wed Oct 29 18:31:47 2003.BEGIN
2829 Handle (TopTools_HArray2OfShape) aFaces =
2830 new TopTools_HArray2OfShape(myFaces->LowerRow(), myFaces->UpperRow(), 1, 2);
2831 Translate(myFaces, I1, aFaces, 1);
2832 Translate(myFaces, I2, aFaces, 2);
2834 Handle (TopTools_HArray2OfShape) aUEdges =
2835 new TopTools_HArray2OfShape(myUEdges->LowerRow(), myUEdges->UpperRow(), 1, 2);
2836 Translate(myUEdges, I1, aUEdges, 1);
2837 Translate(myUEdges, I2, aUEdges, 2);
2839 gp_Vec aNormal = T2 + T1;
2840 TopoDS_Face aPlaneF;
2842 if(aNormal.Magnitude() > gp::Resolution()) {
2843 gp_Pln pl(P1, gp_Dir(aNormal));
2844 BRepLib_MakeFace aFMaker(pl);
2846 if(aFMaker.Error() == BRepLib_FaceDone) {
2847 aPlaneF = aFMaker.Face();
2849 aBB.UpdateFace(aPlaneF, Precision::Confusion() * 10.);
2853 BRepFill_TrimShellCorner aTrim(aFaces, AxeOfBisPlane, aPlaneF);
2854 aTrim.AddBounds(Bounds);
2855 aTrim.AddUEdges(aUEdges);
2858 if (aTrim.IsDone()) {
2859 TopTools_ListOfShape listmodif;
2860 Standard_Integer iit = 0;
2862 for(iit = 0; iit < 2; iit++) {
2863 Standard_Integer II = (iit == 0) ? I1 : I2;
2865 for (ii = 1; ii <= mySec->NbLaw(); ii++) {
2866 aTrim.Modified(myFaces->Value(ii, II), listmodif);
2868 if(!listmodif.IsEmpty()) {
2869 myFaces->SetValue(ii, II, listmodif.First());
2873 for (ii = myUEdges->LowerRow(); ii <= myUEdges->UpperRow(); ii++) {
2874 aTrim.Modified(myUEdges->Value(ii, II), listmodif);
2876 if(!listmodif.IsEmpty()) {
2877 myUEdges->SetValue(ii, II, listmodif.First());
2882 else if ((TheTransition == BRepFill_Right) ||
2883 aTrim.HasSection() ) {
2885 cout << "Fail of TrimCorner" << endl;
2887 return; // Nothing is touched
2890 if (mySec->IsUClosed())
2892 myUEdges->SetValue( 1, I1, myUEdges->Value(mySec->NbLaw()+1, I1) );
2893 myUEdges->SetValue( 1, I2, myUEdges->Value(mySec->NbLaw()+1, I2) );
2896 if (TheTransition == BRepFill_Round) {
2898 TopTools_ListOfShape list1, list2;
2899 TopoDS_Edge Bord1, Bord2, BordFirst;
2900 BordFirst.Nullify();
2903 Standard_Boolean HasFilling = Standard_False;
2905 for (ii=1; ii<=mySec->NbLaw(); ii++) {
2906 KeepEdge(myFaces->Value(ii, I1), Bounds->Value(ii, 1), list1);
2907 KeepEdge(myFaces->Value(ii, I2), Bounds->Value(ii, 2), list2);
2908 if (list1.Extent() == list2.Extent()) {
2909 TopTools_ListIteratorOfListOfShape It1(list1);
2910 TopTools_ListIteratorOfListOfShape It2(list2);
2912 for (; It1.More(); It1.Next(), It2.Next()) {
2913 if (HasFilling) { // Transversal choice of constraints
2914 TopoDS_Vertex VF, VL, VC;
2915 TopoDS_Edge E = TopoDS::Edge(It1.Value());
2919 TopExp::Vertices(E, VF, VL);
2920 if (!Bord1.IsNull() &&
2921 TopExp::CommonVertex(E, Bord1, VC)) {
2922 if (VC.IsSame(VF)) E1 = Bord1;
2925 if (!Bord2.IsNull() &&
2926 TopExp::CommonVertex(E, Bord2, VC)) {
2927 if (VC.IsSame(VF)) E1 = Bord2;
2930 if (!BordFirst.IsNull() &&
2931 TopExp::CommonVertex(E, BordFirst, VC)) {
2932 if (VC.IsSame(VF)) E1 = BordFirst;
2933 else E2 = BordFirst;
2940 B = Filling(It1.Value(), myFaces->Value(ii, I1),
2941 It2.Value(), myFaces->Value(ii, I2),
2942 myVEdgesModified, myTol3d, Axe, T1, Bord1, Bord2, FF);
2945 myAuxShape.Append(FF);
2946 myVEdges->ChangeValue(ii, I2) = FF;
2947 HasFilling = Standard_True;
2949 if (ii==1) BordFirst = Bord1;
2953 else cout << "PerformCorner : Unsymmetry of free border" << endl;
2961 Standard_Integer jj;
2963 DBRep::Set("TrimmedShell", TheShape);
2964 for (jj=1; jj <=myFaces->ColLength(); jj++){
2965 sprintf(name,"Tfaces_%d_%d", jj, I1);
2966 DBRep::Set(name, myFaces->Value(jj, I1));
2967 sprintf(name,"Tfaces_%d_%d", jj, I2);
2968 DBRep::Set(name, myFaces->Value(jj, I2));
2975 //=======================================================================
2976 //function : EvalExtrapol
2978 //======================================================================
2979 Standard_Real BRepFill_Sweep::
2980 EvalExtrapol(const Standard_Integer Index,
2981 const BRepFill_TransitionStyle Transition) const
2983 Standard_Real Extrap = 0.0;
2984 if (Transition == BRepFill_Right) {
2985 Standard_Integer I1, I2;
2986 if ((Index == 1) || (Index ==myLoc->NbLaw()+1) ) {
2987 if (!myLoc->IsClosed() || !mySec->IsVClosed()) return Extrap;
2988 I1 = myLoc->NbLaw();
2996 gp_Vec V1, V2, T1, T2;
2998 Standard_Real Xmin, Ymin, Zmin, Xmax, Ymax, Zmax, R, f, l;
3000 myLoc->Law(I1)->GetDomain(f, l);
3001 myLoc->Law(I1)->D0(l, M1, V1);
3002 T1.SetXYZ(M1.Column(3));
3003 myLoc->Law(I2)->GetDomain(f, l);
3004 myLoc->Law(I2)->D0(f, M2, V2);
3005 T2.SetXYZ(M2.Column(3));
3007 Standard_Real alpha = T1.Angle(T2);
3008 if ((alpha > myAngMax) || (alpha < myAngMin)) {
3009 //Angle too great => No "straight" connection
3010 //Angle too small => No connection
3011 return Extrap; // = 0.0
3014 Handle(GeomFill_SectionLaw) Sec;
3015 Sec = mySec->ConcatenedLaw();
3017 //Calculating parameter U
3018 Standard_Real U, Length, SecFirst, SecLen, Lf, Ll;
3019 myLoc->CurvilinearBounds( myLoc->NbLaw(), Lf, Length );
3020 mySec->Law(1)->GetDomain( SecFirst, SecLen );
3022 myLoc->CurvilinearBounds( I1, Lf, Ll );
3023 U = SecFirst + (Ll/Length)*SecLen;
3026 //Box(Sec, 0., box);
3028 box.Get(Xmin, Ymin, Zmin, Xmax, Ymax, Zmax);
3030 R = Max(Max(Abs(Xmin), Abs(Xmax)),Max(Abs(Ymin), Abs(Ymax)));
3032 // modified by NIZHNY-MKK Fri Oct 31 18:57:51 2003
3033 // Standard_Real coef = 1.2;
3034 Standard_Real coef = 2.;
3036 Extrap = Max(Abs(Zmin), Abs(Zmax)) + 100*myTol3d;
3037 Extrap += R*Tan(alpha/2);
3042 //=======================================================================
3043 //function : MergeVertex
3044 //purpose : Make V2 = V1 if V2 is too close to V1
3045 //======================================================================
3046 Standard_Boolean BRepFill_Sweep::MergeVertex(const TopoDS_Shape& V1,
3047 TopoDS_Shape& V2) const
3049 // Class BRep_Tool without fields and without Constructor :
3051 const TopoDS_Vertex& v1 = TopoDS::Vertex(V1);
3052 const TopoDS_Vertex& v2 = TopoDS::Vertex(V2);
3054 // tol = Max(BT.Tolerance(v1), BT.Tolerance(v2));
3055 tol = Max(BRep_Tool::Tolerance(v1), BRep_Tool::Tolerance(v2));
3056 if (tol < myTol3d) tol = myTol3d;
3057 // if (BT.Pnt(v1).Distance(BT.Pnt(v2)) <= tol ){
3058 if (BRep_Tool::Pnt(v1).Distance(BRep_Tool::Pnt(v2)) <= tol ){
3060 return Standard_True;
3062 return Standard_False;
3066 //=======================================================================
3067 //function : UpdateVertex
3068 //purpose : Update the Tolerance of Vertices depending on Laws.
3069 //======================================================================
3070 void BRepFill_Sweep::UpdateVertex(const Standard_Integer ipath,
3071 const Standard_Integer isec,
3072 const Standard_Real ErrApp,
3073 const Standard_Real Param,
3074 TopoDS_Shape& V) const
3076 TopoDS_Vertex vv, TheV;
3077 TheV = TopoDS::Vertex(V);
3078 myLoc->PerformVertex(ipath,
3079 mySec->Vertex(isec, Param),
3080 ErrApp+mySec->VertexTol(isec-1, Param),
3082 // Class BRep_Tool without fields and without Constructor :
3086 P1 = BRep_Tool::Pnt(vv);
3087 // P2 = BT.Pnt(TheV);
3088 P2 = BRep_Tool::Pnt(TheV);
3090 // Standard_Real Tol = BT.Tolerance(vv);
3091 Standard_Real Tol = BRep_Tool::Tolerance(vv);
3092 Tol += P1.Distance(P2);
3094 // if (Tol > BT.Tolerance(TheV)) {
3095 if (Tol > BRep_Tool::Tolerance(TheV)) {
3097 B.UpdateVertex(TheV, Tol);