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 const 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());
1461 Standard_Real MaxTol = 1.e-4;
1462 Standard_Real theTol;
1463 GeomAdaptor_Curve GAiso(Iso);
1464 Handle(GeomAdaptor_HCurve) GAHiso = new GeomAdaptor_HCurve(GAiso);
1465 GeomAdaptor_Surface GAsurf(S);
1466 Handle(GeomAdaptor_HSurface) GAHsurf = new GeomAdaptor_HSurface(GAsurf);
1467 CheckSameParameter( GAHiso, L, GAHsurf, MaxTol, theTol);
1468 B.UpdateEdge(E, theTol);
1473 //=======================================================================
1475 //Objet : Complete an edge via an iso
1476 //=======================================================================
1477 static void UpdateEdge(TopoDS_Edge& E,
1478 const Handle(Geom_Surface)& S,
1479 const Standard_Boolean isUiso,
1480 const Standard_Real ValIso)
1483 Handle(Geom2d_Line) L;
1484 Handle(Geom2d_Curve) PCurve, CL;
1485 TopLoc_Location Loc;
1486 Standard_Real UFirst, ULast, VFirst, VLast, F2d, L2d;
1487 S->Bounds( UFirst, ULast, VFirst, VLast);
1489 Standard_Boolean sing = Standard_False;
1490 Handle(Geom_Curve) Iso;
1492 Iso = S->UIso(ValIso);
1495 Iso = S->VIso(ValIso);
1498 TopoDS_Vertex Vf, Vl;
1499 TopExp::Vertices(E, Vf, Vl);
1500 if (Vf.IsSame(Vl)) { // Singular case ?
1502 Standard_Real tol = BRep_Tool::Tolerance(Vf);
1503 Iso->D0((Iso->FirstParameter()+Iso->LastParameter())/2, Pmid);
1504 if (Pmid.Distance(BRep_Tool::Pnt(Vf)) < tol) {
1505 GeomAdaptor_Curve AC(Iso);
1506 sing = GCPnts_AbscissaPoint::Length(AC, tol/4) < tol;
1511 gp_Pnt2d P(ValIso, 0);
1513 L = new (Geom2d_Line) (P, V);
1518 gp_Pnt2d P(0., ValIso);
1520 L = new (Geom2d_Line) (P, V);
1524 CL = new (Geom2d_TrimmedCurve) (L, F2d, L2d);
1526 // Control direction & Range
1527 Standard_Real R, First, Last, Tol=1.e-4;
1528 Standard_Boolean reverse = Standard_False;;
1531 // Class BRep_Tool without fields and without Constructor :
1535 // BT.Range(E, First, Last);
1536 BRep_Tool::Range(E, First, Last);
1538 if (!Vf.IsSame(Vl)) {
1539 // Test distances between "FirstPoint" and "Vertex"
1540 P2d = CL->Value(F2d);
1541 POnS = S->Value(P2d.X(), P2d.Y());
1542 // reverse = POnS.Distance(BT.Pnt(Vl)) < POnS.Distance(BT.Pnt(Vf));
1543 reverse = POnS.Distance(BRep_Tool::Pnt(Vl)) < POnS.Distance(BRep_Tool::Pnt(Vf));
1546 // Test angle between "First Tangente"
1548 gp_Vec V3d, du, dv, dC3d;
1549 BRepAdaptor_Curve C3d(E);
1551 C3d.D1(First, POnS, dC3d);
1552 CL->D1(F2d, P2d, V2d);
1553 S->D1(P2d.X(), P2d.Y(), POnS, du, dv);
1554 V3d.SetLinearForm(V2d.X(), du, V2d.Y(), dv);
1555 reverse = ( dC3d.Angle(V3d) > Tol);
1557 if (reverse ) { // Return curve 2d
1558 CL = new (Geom2d_TrimmedCurve)(L, F2d, L2d);
1560 F2d = CL->FirstParameter();
1561 L2d = CL->LastParameter();
1566 Handle(Geom_Curve) NullCurve;
1567 B.UpdateEdge(E, NullCurve, 0.);
1568 B.Degenerated(E, Standard_True);
1569 B.Range(E, F2d, L2d);
1574 if (First != F2d || Last != L2d) {
1575 Handle(Geom2d_Curve) C2d;
1576 GeomLib::SameRange(Precision::PConfusion(), CL,
1577 F2d, L2d, First, Last,
1579 CL = new (Geom2d_TrimmedCurve)(C2d, First, Last);
1582 // Update des Vertex
1586 P2d = CL->Value(First);
1587 POnS = S->Value(P2d.X(), P2d.Y());
1588 V = TopExp::FirstVertex(E);
1589 // R = POnS.Distance(BT.Pnt(V));
1590 R = POnS.Distance(BRep_Tool::Pnt(V));
1591 B.UpdateVertex(V, R);
1593 P2d = CL->Value(Last);
1594 POnS = S->Value(P2d.X(), P2d.Y());
1595 V = TopExp::LastVertex(E);
1596 // R = POnS.Distance(BT.Pnt(V));
1597 R = POnS.Distance(BRep_Tool::Pnt(V));
1598 B.UpdateVertex(V, R);
1601 if (!sing && SameParameter(E, CL, S, Tol, R)) {
1605 PCurve = Couture(E, S, Loc);
1606 if (PCurve.IsNull())
1607 B.UpdateEdge(E, CL, S, Loc, Precision::Confusion());
1608 else { // Sewing edge
1611 if (e.Orientation() == TopAbs_REVERSED)
1612 B.UpdateEdge(E, CL, PCurve, S, Loc, Precision::Confusion());
1614 B.UpdateEdge(E, PCurve, CL, S, Loc, Precision::Confusion());
1617 // Attention to case not SameRange on its shapes (PRO13551)
1618 // if (!BT.SameRange(E)) B.Range(E, S, Loc, First, Last);
1619 if (!BRep_Tool::SameRange(E)) B.Range(E, S, Loc, First, Last);
1622 //=======================================================================
1623 // Object : Check if a surface is degenerated
1624 //=======================================================================
1625 static Standard_Boolean IsDegen(const Handle(Geom_Surface)& S,
1626 const Standard_Real Tol)
1628 Standard_Integer Nb = 5;
1629 Standard_Boolean B = Standard_True;
1630 Standard_Real Umax, Umin, Vmax, Vmin, t, dt, l;
1631 Standard_Integer ii;
1632 Handle(Geom_Curve) Iso;
1634 GCPnts_AbscissaPoint GC;
1636 S->Bounds(Umin, Umax, Vmin, Vmax);
1638 // Check the length of Iso-U
1639 t = (Umin + Umax)/2;
1641 S->D0(t, (Vmin+Vmax)/2, P2);
1643 B = ((P1.Distance(P2) + P2.Distance(P3)) < Tol);
1645 for (ii=1, dt = (Umax-Umin)/(Nb+1); B && (ii<=Nb); ii++) {
1648 GeomAdaptor_Curve AC(Iso);
1649 l = GC.Length(AC, Tol/4);
1653 if (B) return Standard_True;
1655 // Check the length of Iso-V
1656 t = (Vmin + Vmax)/2;
1658 S->D0((Umin+Umax)/2, t, P2);
1660 B = ((P1.Distance(P2) + P2.Distance(P3)) < Tol);
1663 for (ii=1, dt = (Vmax-Vmin)/(Nb+1); B && (ii<=Nb); ii++) {
1666 GeomAdaptor_Curve AC(Iso);
1667 l = GC.Length(AC, Tol/4);
1674 //=======================================================================
1675 //function : Constructeur
1677 //======================================================================
1678 BRepFill_Sweep::BRepFill_Sweep(const Handle(BRepFill_SectionLaw)& Section,
1679 const Handle(BRepFill_LocationLaw)& Location,
1680 const Standard_Boolean WithKPart) :
1681 isDone(Standard_False),
1689 SetTolerance(1.e-4);
1690 SetAngularControl();
1693 myApproxStyle = GeomFill_Location;
1694 myContinuity = GeomAbs_C2;
1697 myForceApproxC1 = Standard_False;
1700 //=======================================================================
1701 //function : SetBounds
1702 //purpose : Define start and end shapes
1703 //======================================================================
1704 void BRepFill_Sweep::SetBounds(const TopoDS_Wire& First,
1705 const TopoDS_Wire& Last)
1710 // It is necessary to check the SameRange on its (PRO13551)
1711 Standard_Boolean issame = Standard_True;
1713 BRepTools_WireExplorer wexp;
1714 if (!FirstShape.IsNull()) {
1715 for (wexp.Init(FirstShape); wexp.More(); wexp.Next()) {
1716 if (!BRepLib::CheckSameRange(wexp.Current())) {
1717 B.SameRange(wexp.Current(), Standard_False);
1718 B.SameParameter(wexp.Current(), Standard_False);
1719 issame = Standard_False;
1724 if (!LastShape.IsNull()) {
1725 for (wexp.Init(LastShape); wexp.More(); wexp.Next()) {
1726 if (!BRepLib::CheckSameRange(wexp.Current())) {
1727 B.SameRange(wexp.Current(), Standard_False);
1728 B.SameParameter(wexp.Current(), Standard_False);
1729 issame = Standard_False;
1736 cout<<"Sweep Warning : Edge not SameRange in the limits"<<endl;
1740 //=======================================================================
1741 //function : SetTolerance
1743 //======================================================================
1744 void BRepFill_Sweep::SetTolerance(const Standard_Real Tol3d,
1745 const Standard_Real BoundTol,
1746 const Standard_Real Tol2d,
1747 const Standard_Real TolAngular)
1750 myBoundTol = BoundTol;
1752 myTolAngular = TolAngular;
1754 //=======================================================================
1755 //function : SetAngularControl
1757 //======================================================================
1758 void BRepFill_Sweep::SetAngularControl(const Standard_Real MinAngle,
1759 const Standard_Real MaxAngle)
1761 myAngMin = Max (MinAngle, Precision::Angular());
1762 myAngMax = Min (MaxAngle, 6.28);
1765 //=======================================================================
1766 //function : SetForceApproxC1
1767 //purpose : Set the flag that indicates attempt to approximate
1768 // a C1-continuous surface if a swept surface proved
1770 //=======================================================================
1771 void BRepFill_Sweep::SetForceApproxC1(const Standard_Boolean ForceApproxC1)
1773 myForceApproxC1 = ForceApproxC1;
1776 ///=======================================================================
1777 //function : CorrectApproxParameters
1779 //=======================================================================
1780 Standard_Boolean BRepFill_Sweep::CorrectApproxParameters()
1782 TopoDS_Wire thePath = myLoc->Wire();
1783 GeomAbs_Shape NewCont = myContinuity;
1784 Standard_Integer NewSegmax = mySegmax;
1786 TopoDS_Iterator iter(thePath);
1787 for (; iter.More(); iter.Next())
1789 TopoDS_Edge anEdge = TopoDS::Edge(iter.Value());
1790 BRepAdaptor_Curve aBAcurve(anEdge);
1791 GeomAbs_Shape aContinuity = aBAcurve.Continuity();
1792 Standard_Integer aNbInterv = aBAcurve.NbIntervals(GeomAbs_CN);
1793 if (aContinuity < NewCont)
1794 NewCont = aContinuity;
1795 if (aNbInterv > NewSegmax)
1796 NewSegmax = aNbInterv;
1799 Standard_Boolean Corrected = Standard_False;
1800 if (NewCont != myContinuity || NewSegmax != mySegmax)
1801 Corrected = Standard_True;
1802 myContinuity = NewCont;
1803 mySegmax = NewSegmax;
1807 //=======================================================================
1808 //function : BuildWire
1809 //purpose : Construit a wire by sweeping
1810 //======================================================================
1811 Standard_Boolean BRepFill_Sweep::
1812 BuildWire(const BRepFill_TransitionStyle /*Transition*/)
1814 Standard_Integer ipath, isec = 1;
1818 // Class BRep_Tool without fields and without Constructor :
1820 Standard_Integer NbPath = myLoc->NbLaw();
1821 Standard_Boolean vclose;
1822 vclose = (myLoc->IsClosed() && (myLoc->IsG1(0, myTol3d)>= 0));
1824 Handle(Geom_Surface) S;
1825 Handle(Geom_Curve) Iso;
1826 Standard_Real val, bid, First, Last, Tol;
1832 // (1) Construction of all curves
1834 // (1.1) Construction of Tables
1835 myFaces = new (TopTools_HArray2OfShape) (1, 1, 1, NbPath);
1836 myUEdges = new (TopTools_HArray2OfShape) (1, 2, 1, NbPath);
1837 myVEdges = new (TopTools_HArray2OfShape) (1, 1, 1, NbPath+1);
1839 // (1.2) Calculate curves / vertex / edge
1840 for (ipath=1; ipath <=NbPath; ipath++) {
1841 // Curve by iso value
1842 GeomFill_Sweep Sweep(myLoc->Law(ipath), KPart);
1843 Sweep.SetTolerance(myTol3d, myBoundTol, myTol2d, myTolAngular);
1844 Sweep.SetForceApproxC1(myForceApproxC1);
1845 Sweep.Build(mySec->Law(isec), myApproxStyle, myContinuity, myDegmax, mySegmax);
1846 if (!Sweep.IsDone())
1847 return Standard_False;
1848 S = Sweep.Surface();
1849 if (Sweep.ExchangeUV()) {
1850 if (Sweep.UReversed()) S->Bounds(First, Last, bid, val);
1851 else S->Bounds(First, Last, val, bid);
1855 if (Sweep.UReversed()) S->Bounds(bid, val, First, Last);
1856 else S->Bounds(val, bid, First, Last);
1859 // Vertex by position
1861 BuildVertex(Iso, Standard_False, First, Last,
1862 myVEdges->ChangeValue(1, ipath+1));
1865 TopoDS_Vertex& V = TopoDS::Vertex(myVEdges->ChangeValue(1, 1));
1866 myVEdges->SetValue(1, ipath+1, V);
1868 // Tol = P1.Distance(BT.Pnt(V));
1869 Tol = P1.Distance(BRep_Tool::Pnt(V));
1870 B.UpdateVertex(V, Tol);
1873 if (!LastShape.IsNull()) myVEdges->SetValue(1, NbPath, FirstShape);
1874 else BuildVertex(Iso, Standard_False, First, Last,
1875 myVEdges->ChangeValue(1, NbPath+1));
1881 TopoDS_Vertex& V = TopoDS::Vertex(myVEdges->ChangeValue(1, ipath));
1882 // Tol = P1.Distance(BT.Pnt(V));
1883 Tol = P1.Distance(BRep_Tool::Pnt(V));
1884 B.UpdateVertex(V, Tol);
1887 if (!FirstShape.IsNull()) myVEdges->SetValue(1,1, FirstShape);
1888 else BuildVertex(Iso, Standard_True, First, Last,
1889 myVEdges->ChangeValue(1, 1));
1892 // Construction of the edge
1893 BRepLib_MakeEdge MkE;
1895 TopoDS::Vertex(myVEdges->Value(1, ipath)),
1896 TopoDS::Vertex(myVEdges->Value(1, ipath+1)),
1897 Iso->FirstParameter(),
1898 Iso->LastParameter());
1899 if (!MkE.IsDone()) { // Error of construction !!
1902 sprintf(name,"firstvertex_error");
1903 DBRep::Set(name, myVEdges->Value(1, ipath));
1904 sprintf(name,"lastvertex_error");
1905 DBRep::Set(name, myVEdges->Value(1, ipath+1));
1906 sprintf(name,"curve3d_error");
1908 DrawTrSurf::Set(Temp,Iso);
1909 // DrawTrSurf::Set(name,Iso);
1910 Standard_ConstructionError::Raise("BRepFill_Sweep::BuildEdge");
1912 return Standard_False;
1917 sprintf(name,"Surf_%d", ipath);
1919 DrawTrSurf::Set(Temp, S);
1920 // DrawTrSurf::Set(name, S);
1921 sprintf(name,"Edge_%d", ipath);
1922 DBRep::Set(name, E);
1925 B.UpdateEdge(E, Sweep.ErrorOnSurface());
1927 myFaces->SetValue(1, ipath, E);
1930 return Standard_True;
1933 //=======================================================================
1934 //function : BuildShell
1935 //purpose : Construct a Shell by sweeping
1936 //======================================================================
1937 Standard_Boolean BRepFill_Sweep::
1938 BuildShell(const BRepFill_TransitionStyle /*Transition*/,
1939 const Standard_Integer IFirst,
1940 const Standard_Integer ILast,
1941 const Standard_Real ExtendFirst,
1942 const Standard_Real ExtendLast)
1944 Standard_Integer ipath, isec, IPath;
1949 Standard_Integer NbPath = ILast - IFirst;
1950 Standard_Integer NbLaw = mySec->NbLaw();
1951 Standard_Boolean uclose, vclose, constSection, hasdegen = Standard_False;
1952 constSection = mySec->IsConstant();
1953 uclose = mySec->IsUClosed();
1954 vclose = (mySec->IsVClosed() && myLoc->IsClosed()) &&
1955 (NbPath == myLoc->NbLaw()) && (myLoc->IsG1(0, myTol3d)>= 0);
1958 // (1) Construction of all surfaces
1960 // (1.1) Construction of Tables
1962 TColStd_Array2OfInteger ExchUV(1, NbLaw, 1, NbPath);
1963 TColStd_Array2OfInteger UReverse(1, NbLaw, 1, NbPath);
1964 TColStd_Array2OfInteger Degenerated(1, NbLaw, 1, NbPath);
1965 Degenerated.Init(0);
1966 // No VReverse for the moment...
1967 TColStd_Array2OfReal TabErr(1, NbLaw , 1, NbPath);
1968 TColGeom_Array2OfSurface TabS(1, NbLaw , 1, NbPath);
1970 TopTools_Array2OfShape UEdge(1, NbLaw+1, 1, NbPath);
1971 TopTools_Array2OfShape VEdge(1, NbLaw , 1, NbPath+1);
1972 TopTools_Array2OfShape Vertex(1,NbLaw+1, 1, NbPath+1);
1974 TopoDS_Vertex VNULL;
1978 TopTools_Array1OfShape SecVertex(1, NbLaw+1);
1979 TColStd_Array1OfReal VError(1, NbLaw+1);
1980 TColStd_Array1OfReal Vi(1, NbPath+1);
1982 //Initialization of management of parametric intervals
1983 //(Case of evolutionary sections)
1984 Standard_Real Length, SecDom, SecDeb;
1985 myLoc->CurvilinearBounds(myLoc->NbLaw(), SecDom, Length);
1986 mySec->Law(1)->GetDomain(SecDeb, SecDom);
1989 Standard_Real Lf, Ll;
1990 myLoc->CurvilinearBounds(IFirst-1, Lf, Ll);
1991 Vi(1) = SecDeb + (Ll/Length)*SecDom;
1996 // Error a priori on vertices
1998 for (isec=1; isec<=NbLaw+1; isec++) {
1999 VError(isec) = mySec->VertexTol(isec-1, 0.);
2000 SecVertex(isec) = mySec->Vertex(isec, 0.);
2005 // (1.2) Calculate surfaces
2006 for (ipath=1, IPath=IFirst; ipath <=NbPath; ipath++, IPath++) {
2008 GeomFill_Sweep Sweep(myLoc->Law(IPath), KPart);
2009 Sweep.SetTolerance(myTol3d, myBoundTol, myTol2d, myTolAngular);
2010 Sweep.SetForceApproxC1(myForceApproxC1);
2012 // Case of evolutionary section, definition of parametric correspondence
2013 if (!constSection) {
2014 Standard_Real lf, ll, Lf, Ll;
2015 myLoc->Law(IPath)->GetDomain(lf, ll);
2016 myLoc->CurvilinearBounds(IPath, Lf, Ll);
2017 Vi(ipath+1) = SecDeb + (Ll/Length)*SecDom;
2018 Sweep.SetDomain(lf, ll, Vi(ipath), Vi(ipath+1));
2020 else //section is constant
2022 Standard_Real lf, ll, Lf, Ll;
2023 myLoc->Law(IPath)->GetDomain(lf, ll);
2024 myLoc->CurvilinearBounds(IPath, Lf, Ll);
2025 Vi(ipath+1) = SecDeb + (Ll/Length)*SecDom;
2028 for(isec=1; isec<=NbLaw; isec++) {
2029 Sweep.Build(mySec->Law(isec), myApproxStyle, myContinuity, myDegmax, mySegmax);
2030 if (!Sweep.IsDone())
2031 return Standard_False;
2032 TabS(isec,ipath) = Sweep.Surface();
2033 TabErr(isec,ipath) = Sweep.ErrorOnSurface();
2034 ExchUV(isec, ipath) = Sweep.ExchangeUV();
2035 UReverse(isec, ipath) = Sweep.UReversed();
2036 if (Sweep.ErrorOnSurface()>Error) Error = Sweep.ErrorOnSurface();
2038 if ((ipath==1)&&(ExtendFirst>0)) {
2039 Handle(Geom_BoundedSurface) BndS;
2040 BndS = Handle(Geom_BoundedSurface)::DownCast(TabS(isec,ipath));
2041 GeomLib::ExtendSurfByLength(BndS, ExtendFirst, 1,
2042 Sweep.ExchangeUV(), Standard_False);
2043 TabS(isec,ipath) = BndS;
2045 if ((ipath==NbPath)&&(ExtendLast>0)){
2046 Handle(Geom_BoundedSurface) BndS;
2047 BndS = Handle(Geom_BoundedSurface)::DownCast(TabS(isec,ipath));
2048 GeomLib::ExtendSurfByLength(BndS, ExtendLast, 1,
2049 Sweep.ExchangeUV(), Standard_True);
2050 TabS(isec,ipath) = BndS;
2055 sprintf(name,"Surf_%d_%d", isec, IPath);
2057 DrawTrSurf::Set(Temp, TabS(isec,ipath));
2063 // (2) Construction of Edges
2064 Standard_Real UFirst, ULast, VFirst, VLast;
2065 Standard_Boolean exuv, singu, singv;
2066 Handle(Geom_Surface) S;
2068 // (2.0) return preexisting Edges and vertices
2070 if (! FirstShape.IsNull() && (IFirst==1)) {
2071 mySec->Init(FirstShape);
2072 for (isec=1; isec<=NbLaw; isec++) {
2073 E = mySec->CurrentEdge();
2075 if (E.Orientation() == TopAbs_REVERSED)
2076 Vertex(isec+1, 1) = TopExp::FirstVertex(E);
2078 Vertex(isec+1, 1) = TopExp::LastVertex(E);
2079 UpdateVertex(IFirst-1, isec+1,
2080 TabErr(isec, 1), Vi(1), Vertex(isec+1, 1));
2082 if (VEdge(1, 1).Orientation() == TopAbs_REVERSED)
2083 Vertex(1, 1) = TopExp::LastVertex(TopoDS::Edge(VEdge(1, 1)));
2085 Vertex(1, 1) = TopExp::FirstVertex(TopoDS::Edge(VEdge(1, 1)));
2086 UpdateVertex(IFirst-1, 1,
2087 TabErr(1, 1), Vi(1), Vertex(1, 1));
2089 else { // Otherwise construct vertices
2090 Standard_Real u, v, aux;
2091 Standard_Boolean ureverse;
2092 for (isec=1; isec<=NbLaw+1; isec++) {
2096 ureverse = UReverse(NbLaw, 1);
2097 exuv = ExchUV(NbLaw, 1);
2101 ureverse = UReverse(isec, 1);
2102 exuv = ExchUV(isec, 1);
2104 S->Bounds(UFirst, ULast, VFirst, VLast);
2106 // Choice of parameters
2109 aux = VFirst; VFirst = VLast; VLast = aux;
2112 aux = UFirst; UFirst = ULast; ULast = aux;
2115 if (isec!= NbLaw+1) {
2130 // construction of vertices
2131 B.MakeVertex(TopoDS::Vertex(Vertex(isec, 1)),
2133 mySec->VertexTol(isec-1,Vi(1)));
2137 if (! LastShape.IsNull() && (ILast==myLoc->NbLaw()+1) ) {
2138 mySec->Init(LastShape);
2139 for (isec=1; isec<=NbLaw; isec++) {
2140 E = mySec->CurrentEdge();
2141 VEdge(isec, NbPath+1) = E;
2142 if (E.Orientation() == TopAbs_REVERSED)
2143 Vertex(isec+1, NbPath+1) = TopExp::FirstVertex(E);
2145 Vertex(isec+1, NbPath+1) = TopExp::LastVertex(E);
2146 UpdateVertex(ILast-1, isec+1, TabErr(isec, NbPath),
2147 Vi(NbPath+1), Vertex(isec+1, NbPath+1));
2149 if (VEdge(1, NbPath+1).Orientation() == TopAbs_REVERSED)
2150 Vertex(1, NbPath+1) =
2151 TopExp::LastVertex(TopoDS::Edge(VEdge(1, NbPath+1)));
2153 Vertex(1, NbPath+1) =
2154 TopExp::FirstVertex(TopoDS::Edge(VEdge(1, NbPath+1)));
2155 UpdateVertex(ILast-1, 1,
2156 TabErr(1, NbPath), Vi(NbPath+1), Vertex(1, NbPath+1 ));
2159 Standard_Real u, v, aux;
2160 Standard_Boolean ureverse;
2161 for (isec=1; isec<=NbLaw+1; isec++) {
2164 S = TabS(NbLaw, NbPath);
2165 ureverse = UReverse(NbLaw, NbPath);
2166 exuv = ExchUV(NbLaw, NbPath);
2169 S = TabS(isec, NbPath);
2170 ureverse = UReverse(isec, NbPath);
2171 exuv = ExchUV(isec, NbPath);
2173 S->Bounds(UFirst, ULast, VFirst, VLast);
2175 // Choice of parametres
2178 aux = VFirst; VFirst = VLast; VLast = aux;
2181 aux = UFirst; UFirst = ULast; ULast = aux;
2184 if (isec == NbLaw+1) {
2199 // construction of vertex
2200 B.MakeVertex(TopoDS::Vertex(Vertex(isec, NbPath+1)),
2202 mySec->VertexTol(isec-1, Vi(NbPath+1)));
2207 // ---------- Creation of Vertex and edge ------------
2208 for (ipath=1, IPath=IFirst; ipath<=NbPath;
2210 for (isec=1; isec <=NbLaw; isec++) {
2211 S = TabS(isec, ipath);
2212 exuv = ExchUV(isec, ipath);
2213 S->Bounds(UFirst, ULast, VFirst, VLast);
2214 if (UReverse(isec, ipath)) {
2217 aux = VFirst; VFirst = VLast; VLast = aux;
2220 aux = UFirst; UFirst = ULast; ULast = aux;
2224 // (2.1) Construction of new vertices
2226 if (ipath == 1 && Vertex(1, 1).IsNull()) {
2229 myLoc->PerformVertex(IPath-1,
2230 TopoDS::Vertex(SecVertex(1)),
2232 TopoDS::Vertex(Vertex(1, 1)));
2234 myLoc->PerformVertex(IPath-1,
2235 mySec->Vertex(1,Vi(1)),
2236 mySec->VertexTol(0,Vi(1)),
2237 TopoDS::Vertex(Vertex(1, 1)));
2239 // the first and the next column
2240 if (vclose &&(ipath == NbPath) ) {
2241 Vertex(1, ipath+1) = Vertex(1, 1);
2243 else if (Vertex(1, ipath+1).IsNull()) {
2245 myLoc->PerformVertex(IPath,
2246 TopoDS::Vertex(SecVertex(1)),
2247 TabErr(1,ipath)+VError(1),
2248 TopoDS::Vertex(Vertex(1, ipath+1)) );
2250 myLoc->PerformVertex(IPath,
2251 mySec->Vertex(1,Vi(ipath+1)),
2253 mySec->VertexTol(0,Vi(ipath+1)),
2254 TopoDS::Vertex(Vertex(1, ipath+1)));
2256 if (MergeVertex(Vertex(1,ipath), Vertex(1,ipath+1))) {
2257 UEdge(1, ipath) = NullEdge(Vertex(1,ipath));
2263 if (uclose && (isec == NbLaw)) {
2264 Vertex(isec+1, 1) = Vertex(1, 1);
2266 else if (Vertex(isec+1, 1).IsNull()) {
2268 myLoc->PerformVertex(IPath-1,
2269 TopoDS::Vertex(SecVertex(isec+1)),
2270 TabErr(isec,1)+VError(isec+1),
2271 TopoDS::Vertex(Vertex(isec+1, 1)) );
2273 myLoc->PerformVertex(IPath-1,
2274 mySec->Vertex(isec+1,Vi(1)),
2276 mySec->VertexTol(isec,Vi(1)),
2277 TopoDS::Vertex(Vertex(isec+1, 1)) );
2278 if (MergeVertex(Vertex(isec,1), Vertex(isec+1,1))) {
2279 VEdge(isec, 1) = NullEdge(Vertex(isec, 1));
2284 if (uclose && (isec == NbLaw)) {
2285 Vertex(isec+1, ipath+1) = Vertex(1, ipath+1);
2287 else if (vclose && (ipath == NbPath)) {
2288 Vertex(isec+1, ipath+1) = Vertex(isec+1, 1);
2290 else if (Vertex(isec+1, ipath+1).IsNull()) {
2292 myLoc->PerformVertex(IPath,
2293 TopoDS::Vertex(SecVertex(isec+1)),
2294 TabErr(isec, ipath)+ VError(isec+1),
2295 TopoDS::Vertex(Vertex(isec+1, ipath+1)) );
2297 myLoc->PerformVertex(IPath,
2298 mySec->Vertex(isec+1,Vi(ipath+1)),
2299 TabErr(isec, ipath) +
2300 mySec->VertexTol(isec, Vi(ipath+1)),
2301 TopoDS::Vertex(Vertex(isec+1, ipath+1)) );
2305 singv = MergeVertex(Vertex(isec,ipath+1), Vertex(isec+1,ipath+1));
2306 singu = MergeVertex(Vertex(isec+1,ipath), Vertex(isec+1,ipath+1));
2310 if (singu || singv) {
2311 Degenerated(isec, ipath) = IsDegen(TabS(isec,ipath),
2312 Max(myTol3d, TabErr(isec,ipath)));
2314 if (Degenerated(isec, ipath)) {
2316 cout << "Sweep : Degenerated case" << endl;
2318 hasdegen = Standard_True;
2319 // Particular construction of edges
2320 if (UEdge(isec+1, ipath).IsNull()) {
2323 UEdge(isec+1, ipath) = NullEdge(Vertex(isec+1,ipath));
2325 else { // Copy the previous edge
2326 UEdge(isec+1, ipath) = UEdge(isec, ipath);
2329 if (VEdge(isec, ipath+1).IsNull()) {
2332 VEdge(isec, ipath+1) = NullEdge(Vertex(isec,ipath+1));
2334 else { // Copy the previous edge
2335 VEdge(isec, ipath+1) = VEdge(isec, ipath);
2339 else { // Construction of edges by isos
2342 UV = UFirst; UFirst = VFirst; VFirst = UV;
2343 UV = ULast ; ULast = VLast ; VLast = UV;
2348 if (!Vertex(1,ipath).IsSame(Vertex(1,ipath+1))) {
2349 gp_Pnt P1 = BRep_Tool::Pnt(TopoDS::Vertex(Vertex(1,ipath)));
2350 gp_Pnt P2 = BRep_Tool::Pnt(TopoDS::Vertex(Vertex(1,ipath+1)));
2351 if (P1.Distance(P2) <= myTol3d)
2352 Vertex(1,ipath+1) = Vertex(1,ipath);
2354 UEdge(1, ipath) = BuildEdge(S, !exuv, UFirst,
2359 else UpdateEdge(TopoDS::Edge(UEdge(isec, ipath)),
2362 if (uclose && (isec==NbLaw)) {
2363 UpdateEdge(TopoDS::Edge(UEdge(1, ipath)),
2365 UEdge(isec+1, ipath) = UEdge(1, ipath);
2368 UEdge(isec+1, ipath) = BuildEdge(S, !exuv, ULast,
2369 Vertex(isec+1, ipath),
2370 Vertex(isec+1, ipath+1),
2375 if (ipath == 1 && VEdge(isec, ipath).IsNull())
2376 VEdge(isec, ipath) = BuildEdge(S, exuv, VFirst,
2381 else UpdateEdge(TopoDS::Edge(VEdge(isec, ipath)),
2384 if (vclose && (ipath == NbPath)) {
2385 UpdateEdge(TopoDS::Edge(VEdge(isec, 1)),
2387 VEdge(isec, ipath+1) = VEdge(isec, 1);
2389 else if (VEdge(isec, ipath+1).IsNull())
2390 VEdge(isec, ipath+1) = BuildEdge(S, exuv, VLast,
2391 Vertex(isec , ipath+1),
2392 Vertex(isec+1, ipath+1),
2394 else UpdateEdge(TopoDS::Edge(VEdge(isec, ipath+1)),
2398 }// End of construction of edges
2401 // (3) Construction of Faces
2406 for (ipath=1, IPath=IFirst; ipath<=NbPath; ipath++, IPath++) {
2407 for (isec=1; isec <=NbLaw+1; isec++){
2408 sprintf(name,"uedge_%d_%d", isec, IPath);
2409 DBRep::Set(name,UEdge(isec, ipath));
2413 for (ipath=1, IPath=IFirst; ipath<=NbPath+1; ipath++, IPath++) {
2414 for (isec=1; isec <=NbLaw; isec++){
2415 sprintf(name,"vedge_%d_%d", isec, IPath);
2416 DBRep::Set(name,VEdge(isec, ipath));
2419 for (isec=1; isec <=NbLaw+1; isec++){
2420 sprintf(name,"vertex_%d_%d", isec, IPath);
2421 DBRep::Set(name,Vertex(isec, ipath));
2427 for (ipath=1, IPath=IFirst; ipath<=NbPath; ipath++, IPath++) {
2428 for (isec=1; isec <=NbLaw; isec++) {
2429 if (Degenerated(isec, ipath)) {
2430 if (UEdge(isec, ipath).IsSame(UEdge(isec+1, ipath)))
2431 myFaces->SetValue(isec, IPath, UEdge(isec, ipath));
2433 myFaces->SetValue(isec, IPath, VEdge(isec, ipath));
2436 BuildFace(TabS(isec,ipath),
2437 TopoDS::Edge(UEdge(isec, ipath)),
2438 TopoDS::Edge(VEdge(isec, ipath)),
2439 TopoDS::Edge(UEdge(isec+1, ipath)),
2440 TopoDS::Edge(VEdge(isec, ipath+1)),
2442 ExchUV(isec, ipath),
2443 UReverse(isec, ipath),
2445 myFaces->SetValue(isec, IPath, face);
2451 // (4) History and Continuity
2454 //(4.1) // Degenerated case => Sledgehammer
2455 TopoDS_Compound Comp;
2456 B.MakeCompound(Comp);
2457 for (isec=1; isec <= NbLaw+1; isec++)
2458 for (ipath=1, IPath=IFirst; ipath<= NbPath+1; ipath++, IPath++) {
2459 if (ipath <= NbPath) myUEdges->SetValue(isec, IPath, UEdge(isec, ipath));
2460 if (isec <= NbLaw) myVEdges->SetValue(isec, IPath, VEdge(isec, ipath));
2461 if ((ipath <= NbPath) && (isec <= NbLaw) &&
2462 (myFaces->Value(isec, IPath).ShapeType() == TopAbs_FACE))
2463 B.Add(Comp, myFaces->Value(isec, IPath));
2465 BRepLib::EncodeRegularity(Comp, myTolAngular);
2468 //(4.2) // General case => Tweezers
2469 Standard_Boolean isG1;
2473 for (isec=1; isec <= NbLaw+1; isec++) {
2475 (mySec->Continuity(isec-1, myTolAngular) >= GeomAbs_G1);
2476 else isG1 = Standard_False;
2477 for (ipath=1, IPath=IFirst; ipath<= NbPath; ipath++, IPath++) {
2478 myUEdges->SetValue(isec, IPath, UEdge(isec, ipath));
2480 if (isec == NbLaw+1) FF = TopoDS::Face(myFaces->Value(1, IPath));
2481 else FF = TopoDS::Face(myFaces->Value(isec, IPath));
2482 B.Continuity(TopoDS::Edge(myUEdges->Value(isec, IPath)),
2483 TopoDS::Face(myFaces->Value(isec-1, IPath)),
2489 Standard_Integer nbpath = NbPath;
2490 if (vclose) nbpath++; //Another test G1
2491 for (ipath=1, IPath=IFirst; ipath<= NbPath+1; ipath++, IPath++) {
2492 if ((ipath > 1) && (ipath <=nbpath))
2493 isG1 = (myLoc->IsG1(IPath-1, myTol3d, myTolAngular) >= 0);
2494 else isG1 = Standard_False;
2495 for (isec=1; isec <= NbLaw; isec++) {
2496 myVEdges->SetValue(isec, IPath, VEdge(isec, ipath));
2498 if (ipath==NbPath+1) FF = TopoDS::Face(myFaces->Value(isec, 1));
2499 else FF = TopoDS::Face(myFaces->Value(isec, IPath));
2500 E = TopoDS::Edge(myVEdges->Value(isec, IPath));
2501 BRepLib::EncodeRegularity(E, FF,
2502 TopoDS::Face(myFaces->Value(isec, IPath-1)),
2508 return Standard_True;
2511 //=======================================================================
2513 //purpose : Construt the result of sweeping
2514 //======================================================================
2515 void BRepFill_Sweep::Build(const BRepFill_TransitionStyle Transition,
2516 const GeomAbs_Shape Continuity,
2517 const GeomFill_ApproxStyle Approx,
2518 const Standard_Integer Degmax,
2519 const Standard_Integer Segmax)
2521 myContinuity = Continuity;
2522 myApproxStyle = Approx;
2526 CorrectApproxParameters();
2529 if (mySec->IsVertex()) isDone = BuildWire(Transition);
2532 Standard_Integer NbTrous = myLoc->NbHoles(myTol3d),
2533 NbPath = myLoc->NbLaw(),
2534 NbLaw = mySec->NbLaw(), ii, jj, NbPart=1;
2535 Standard_Integer ipath, isec;
2537 myUEdges = new (TopTools_HArray2OfShape) (1, NbLaw+1, 1, NbPath);
2538 myVEdges = new (TopTools_HArray2OfShape) (1, NbLaw, 1, NbPath+1);
2539 myFaces = new (TopTools_HArray2OfShape) (1, NbLaw, 1, NbPath);
2540 Handle (TopTools_HArray2OfShape) Bounds =
2541 new (TopTools_HArray2OfShape) (1, NbLaw, 1, 2);
2543 Handle(TColStd_HArray1OfInteger) Trous;
2545 if (NbTrous>0) { // How many sub-parts ?
2546 Trous = new (TColStd_HArray1OfInteger) (1, NbTrous);
2547 myLoc->Holes(Trous->ChangeArray1());
2549 if (Trous->Value(NbTrous) == NbPath+1) NbPart--;
2551 if (NbPart == 1) { // This is done at once
2552 Standard_Real Extend = 0.0;
2553 if (NbTrous==1) Extend = EvalExtrapol(1, Transition);
2554 isDone = BuildShell(Transition,
2558 else { // This is done piece by piece
2559 Standard_Integer IFirst = 1, ILast;
2560 for (ii=1, isDone=Standard_True;
2561 ii<=NbPart && isDone; ii++) {
2562 if (ii > NbTrous) ILast = NbPath+1;
2563 else ILast = Trous->Value(ii);
2564 isDone = BuildShell(Transition,
2566 EvalExtrapol(IFirst, Transition),
2567 EvalExtrapol(ILast, Transition));
2569 Translate(myVEdges, IFirst, Bounds, 2);
2570 PerformCorner(IFirst,
2571 Transition, Bounds);
2574 Translate(myVEdges, IFirst, Bounds, 1);
2577 // Management of looping ends
2578 if ( (NbTrous>0) && (myLoc->IsClosed()) &&
2579 (Trous->Value(NbTrous) == NbPath+1) ) {
2580 Translate(myVEdges, NbPath+1, Bounds, 1);
2581 Translate(myVEdges, 1, Bounds, 2);
2582 PerformCorner(1, Transition, Bounds);
2585 // Construction of the shell
2588 for (ipath=1; ipath<=NbPath; ipath++)
2589 for (isec=1; isec <=NbLaw; isec++) {
2590 const TopoDS_Shape& face = myFaces->Value(isec, ipath);
2591 if (!face.IsNull() &&
2592 (face.ShapeType() == TopAbs_FACE) ) B.Add(shell, face);
2595 TopTools_ListIteratorOfListOfShape It(myAuxShape);
2596 for (; It.More(); It.Next()) {
2597 const TopoDS_Shape& face = It.Value();
2598 if (!face.IsNull() &&
2599 (face.ShapeType() == TopAbs_FACE) ) B.Add(shell, face);
2601 //Set common Uedges to faces
2602 BRepTools_Substitution aSubstitute;
2604 for (ii = 1; ii <= NbLaw; ii++)
2605 for (jj = 1; jj <= NbPath; jj++)
2607 SetCommonEdgeInFace(aSubstitute,
2608 myFaces->Value(ii, jj),
2609 myUEdges->Value(ii, jj));
2610 SetCommonEdgeInFace(aSubstitute,
2611 myFaces->Value(ii, jj),
2612 myUEdges->Value(ii+1, jj));
2614 if (mySec->IsUClosed())
2615 for (jj = 1; jj <= NbPath; jj++)
2616 SetCommonEdgeInFace(aSubstitute,
2617 myFaces->Value( 1, jj ),
2618 myUEdges->Value( NbLaw+1, jj));
2620 TopTools_DataMapIteratorOfDataMapOfShapeShape mapit( myVEdgesModified );
2621 for (; mapit.More(); mapit.Next())
2623 const TopoDS_Edge& OldEdge = TopoDS::Edge(mapit.Key());
2624 const TopoDS_Edge& NewEdge = TopoDS::Edge(mapit.Value());
2625 Substitute( aSubstitute, OldEdge, NewEdge );
2627 aSubstitute.Build( shell );
2628 if (aSubstitute.IsCopied( shell )) {
2629 const TopTools_ListOfShape& listSh = aSubstitute.Copy( shell );
2630 shell = TopoDS::Shell( listSh.First() );
2633 for (ii = myFaces->LowerRow(); ii <= myFaces->UpperRow(); ii++) {
2634 for (jj = myFaces->LowerCol(); jj <= myFaces->UpperCol(); jj++) {
2635 const TopoDS_Shape& aLocalShape = myFaces->Value(ii, jj);
2637 if(!aLocalShape.IsNull() && aSubstitute.IsCopied(aLocalShape)) {
2638 const TopTools_ListOfShape& aList = aSubstitute.Copy(aLocalShape);
2640 if(!aList.IsEmpty())
2641 myFaces->ChangeValue(ii, jj) = aList.First();
2646 for (ii = myVEdges->LowerRow(); ii <= myVEdges->UpperRow(); ii++) {
2647 for (jj = myVEdges->LowerCol(); jj <= myVEdges->UpperCol(); jj++) {
2648 const TopoDS_Shape& aLocalShape = myVEdges->Value(ii, jj);
2650 if(!aLocalShape.IsNull() && aSubstitute.IsCopied(aLocalShape)) {
2651 const TopTools_ListOfShape& aList = aSubstitute.Copy(aLocalShape);
2653 if(!aList.IsEmpty())
2654 myVEdges->ChangeValue(ii, jj) = aList.First();
2659 for (ii = myUEdges->LowerRow(); ii <= myUEdges->UpperRow(); ii++) {
2660 for (jj = myUEdges->LowerCol(); jj <= myUEdges->UpperCol(); jj++) {
2661 const TopoDS_Shape& aLocalShape = myUEdges->Value(ii, jj);
2663 if(!aLocalShape.IsNull() && aSubstitute.IsCopied(aLocalShape)) {
2664 const TopTools_ListOfShape& aList = aSubstitute.Copy(aLocalShape);
2666 if(!aList.IsEmpty())
2667 myUEdges->ChangeValue(ii, jj) = aList.First();
2673 if (myLoc->IsClosed() && mySec->IsUClosed()) {
2675 Standard_Boolean closed = Standard_True;
2676 Standard_Integer iedge;
2677 TopTools_IndexedDataMapOfShapeListOfShape EFmap;
2678 TopExp::MapShapesAndAncestors(shell, TopAbs_EDGE,
2679 TopAbs_FACE, EFmap);
2681 for (iedge = 1; iedge <=EFmap.Extent() && closed; iedge++) {
2682 const TopoDS_Edge& theEdge = TopoDS::Edge(EFmap.FindKey(iedge));
2683 if (BRep_Tool::Degenerated(theEdge)) continue;
2684 closed = ( EFmap(iedge).Extent() > 1);
2686 shell.Closed(closed);
2693 //=======================================================================
2696 //=======================================================================
2697 Standard_Boolean BRepFill_Sweep::IsDone() const
2702 //=======================================================================
2705 //=======================================================================
2706 TopoDS_Shape BRepFill_Sweep::Shape() const
2711 //=======================================================================
2712 //function : ErrorOnSurface
2714 //=======================================================================
2715 Standard_Real BRepFill_Sweep::ErrorOnSurface() const
2720 //=======================================================================
2721 //function : SubShape
2722 //purpose : Faces obtained by sweeping
2723 //=======================================================================
2724 Handle(TopTools_HArray2OfShape) BRepFill_Sweep::SubShape() const
2729 //=======================================================================
2730 //function : InterFaces
2731 //purpose : Edges obtained by sweeping
2732 //=======================================================================
2733 Handle(TopTools_HArray2OfShape) BRepFill_Sweep::InterFaces() const
2738 //=======================================================================
2739 //function : Sections
2740 //purpose : Edges or Face (or compound of 2) Transition between 2 sweepings
2741 //=======================================================================
2742 Handle(TopTools_HArray2OfShape) BRepFill_Sweep::Sections() const
2747 //=======================================================================
2748 //function : PerformCorner
2749 //purpose : Trim and/or loop a corner
2750 //======================================================================
2751 void BRepFill_Sweep::PerformCorner(const Standard_Integer Index,
2752 const BRepFill_TransitionStyle Transition,
2753 const Handle(TopTools_HArray2OfShape)& Bounds)
2756 if (Transition == BRepFill_Modified) return; // Do nothing.
2758 BRepFill_TransitionStyle TheTransition = Transition;
2759 Standard_Boolean isTangent=Standard_False;
2761 Standard_Integer I1, I2, ii; //, jj;
2763 gp_Vec T1, T2, Tang, Sortant;
2765 //Handle(TopTools_HArray1OfShape) TheShape =
2766 //new TopTools_HArray1OfShape( 1, mySec->NbLaw() );
2767 // TopTools_ListIteratorOfListOfShape Iterator;
2774 I1 = myLoc->NbLaw();
2778 // Construct an axis supported by the bissectrice
2779 myLoc->Law(I1)->GetDomain(F, L);
2780 myLoc->Law(I1)->GetCurve()->D1(L, P1, T1);
2783 myLoc->Law(I2)->GetDomain(F, L);
2784 myLoc->Law(I2)->GetCurve()->D1(F, P2, T2);
2787 if (T1.Angle(T2) < myAngMin) {
2788 isTangent = Standard_True;
2791 myLoc->Law(I1)->GetDomain(F, L);
2792 myLoc->Law(I1)->D0(L, M, V);
2794 myLoc->Law(I2)->GetDomain(F, L);
2795 myLoc->Law(I2)->D0(L, M, V);
2798 if (t1.Angle(t2) < myAngMin) {
2800 cout << "BRepFill_Sweep::PerformCorner : This is not a corner !" << endl;
2807 if ((TheTransition == BRepFill_Right)
2808 && (T1.Angle(T2) > myAngMax) ) {
2809 TheTransition = BRepFill_Round;
2812 Tang = T1 + T2; //Average direction
2813 gp_Dir NormalOfBisPlane = Tang;
2816 Sortant -= Tang.Dot(Tang)*Tang;
2819 Sortant = T2-T1; //Direction input
2820 Sortant *= -1; // " " output
2821 Tang -= (Tang.Dot(T2))*T2;
2824 P1.BaryCenter(0.5, P2, 0.5);
2828 gp_Ax2 Axe (P1, N, Dx);
2829 gp_Ax2 AxeOfBisPlane( P1, NormalOfBisPlane );
2831 // Construct 2 intersecting Shells
2832 Handle (TopTools_HArray2OfShape) UEdges =
2833 new TopTools_HArray2OfShape( 1, mySec->NbLaw()+1, 1, myLoc->NbLaw() );
2834 UEdges->ChangeArray2() = myUEdges->Array2();
2836 // modified by NIZHNY-MKK Wed Oct 29 18:31:47 2003.BEGIN
2837 Handle (TopTools_HArray2OfShape) aFaces =
2838 new TopTools_HArray2OfShape(myFaces->LowerRow(), myFaces->UpperRow(), 1, 2);
2839 Translate(myFaces, I1, aFaces, 1);
2840 Translate(myFaces, I2, aFaces, 2);
2842 Handle (TopTools_HArray2OfShape) aUEdges =
2843 new TopTools_HArray2OfShape(myUEdges->LowerRow(), myUEdges->UpperRow(), 1, 2);
2844 Translate(myUEdges, I1, aUEdges, 1);
2845 Translate(myUEdges, I2, aUEdges, 2);
2847 gp_Vec aNormal = T2 + T1;
2848 TopoDS_Face aPlaneF;
2850 if(aNormal.Magnitude() > gp::Resolution()) {
2851 gp_Pln pl(P1, gp_Dir(aNormal));
2852 BRepLib_MakeFace aFMaker(pl);
2854 if(aFMaker.Error() == BRepLib_FaceDone) {
2855 aPlaneF = aFMaker.Face();
2857 aBB.UpdateFace(aPlaneF, Precision::Confusion() * 10.);
2861 BRepFill_TrimShellCorner aTrim(aFaces, AxeOfBisPlane, aPlaneF);
2862 aTrim.AddBounds(Bounds);
2863 aTrim.AddUEdges(aUEdges);
2866 if (aTrim.IsDone()) {
2867 TopTools_ListOfShape listmodif;
2868 Standard_Integer iit = 0;
2870 for(iit = 0; iit < 2; iit++) {
2871 Standard_Integer II = (iit == 0) ? I1 : I2;
2873 for (ii = 1; ii <= mySec->NbLaw(); ii++) {
2874 aTrim.Modified(myFaces->Value(ii, II), listmodif);
2876 if(!listmodif.IsEmpty()) {
2877 myFaces->SetValue(ii, II, listmodif.First());
2881 for (ii = myUEdges->LowerRow(); ii <= myUEdges->UpperRow(); ii++) {
2882 aTrim.Modified(myUEdges->Value(ii, II), listmodif);
2884 if(!listmodif.IsEmpty()) {
2885 myUEdges->SetValue(ii, II, listmodif.First());
2890 else if ((TheTransition == BRepFill_Right) ||
2891 aTrim.HasSection() ) {
2893 cout << "Fail of TrimCorner" << endl;
2895 return; // Nothing is touched
2898 if (mySec->IsUClosed())
2900 myUEdges->SetValue( 1, I1, myUEdges->Value(mySec->NbLaw()+1, I1) );
2901 myUEdges->SetValue( 1, I2, myUEdges->Value(mySec->NbLaw()+1, I2) );
2904 if (TheTransition == BRepFill_Round) {
2906 TopTools_ListOfShape list1, list2;
2907 TopoDS_Edge Bord1, Bord2, BordFirst;
2908 BordFirst.Nullify();
2911 Standard_Boolean HasFilling = Standard_False;
2913 for (ii=1; ii<=mySec->NbLaw(); ii++) {
2914 KeepEdge(myFaces->Value(ii, I1), Bounds->Value(ii, 1), list1);
2915 KeepEdge(myFaces->Value(ii, I2), Bounds->Value(ii, 2), list2);
2916 if (list1.Extent() == list2.Extent()) {
2917 TopTools_ListIteratorOfListOfShape It1(list1);
2918 TopTools_ListIteratorOfListOfShape It2(list2);
2920 for (; It1.More(); It1.Next(), It2.Next()) {
2921 if (HasFilling) { // Transversal choice of constraints
2922 TopoDS_Vertex VF, VL, VC;
2923 TopoDS_Edge E = TopoDS::Edge(It1.Value());
2927 TopExp::Vertices(E, VF, VL);
2928 if (!Bord1.IsNull() &&
2929 TopExp::CommonVertex(E, Bord1, VC)) {
2930 if (VC.IsSame(VF)) E1 = Bord1;
2933 if (!Bord2.IsNull() &&
2934 TopExp::CommonVertex(E, Bord2, VC)) {
2935 if (VC.IsSame(VF)) E1 = Bord2;
2938 if (!BordFirst.IsNull() &&
2939 TopExp::CommonVertex(E, BordFirst, VC)) {
2940 if (VC.IsSame(VF)) E1 = BordFirst;
2941 else E2 = BordFirst;
2948 B = Filling(It1.Value(), myFaces->Value(ii, I1),
2949 It2.Value(), myFaces->Value(ii, I2),
2950 myVEdgesModified, myTol3d, Axe, T1, Bord1, Bord2, FF);
2953 myAuxShape.Append(FF);
2954 myVEdges->ChangeValue(ii, I2) = FF;
2955 HasFilling = Standard_True;
2957 if (ii==1) BordFirst = Bord1;
2961 else cout << "PerformCorner : Unsymmetry of free border" << endl;
2969 Standard_Integer jj;
2971 DBRep::Set("TrimmedShell", TheShape);
2972 for (jj=1; jj <=myFaces->ColLength(); jj++){
2973 sprintf(name,"Tfaces_%d_%d", jj, I1);
2974 DBRep::Set(name, myFaces->Value(jj, I1));
2975 sprintf(name,"Tfaces_%d_%d", jj, I2);
2976 DBRep::Set(name, myFaces->Value(jj, I2));
2983 //=======================================================================
2984 //function : EvalExtrapol
2986 //======================================================================
2987 Standard_Real BRepFill_Sweep::
2988 EvalExtrapol(const Standard_Integer Index,
2989 const BRepFill_TransitionStyle Transition) const
2991 Standard_Real Extrap = 0.0;
2992 if (Transition == BRepFill_Right) {
2993 Standard_Integer I1, I2;
2994 if ((Index == 1) || (Index ==myLoc->NbLaw()+1) ) {
2995 if (!myLoc->IsClosed() || !mySec->IsVClosed()) return Extrap;
2996 I1 = myLoc->NbLaw();
3004 gp_Vec V1, V2, T1, T2;
3006 Standard_Real Xmin, Ymin, Zmin, Xmax, Ymax, Zmax, R, f, l;
3008 myLoc->Law(I1)->GetDomain(f, l);
3009 myLoc->Law(I1)->D0(l, M1, V1);
3010 T1.SetXYZ(M1.Column(3));
3011 myLoc->Law(I2)->GetDomain(f, l);
3012 myLoc->Law(I2)->D0(f, M2, V2);
3013 T2.SetXYZ(M2.Column(3));
3015 Standard_Real alpha = T1.Angle(T2);
3016 if ((alpha > myAngMax) || (alpha < myAngMin)) {
3017 //Angle too great => No "straight" connection
3018 //Angle too small => No connection
3019 return Extrap; // = 0.0
3022 Handle(GeomFill_SectionLaw) Sec;
3023 Sec = mySec->ConcatenedLaw();
3025 //Calculating parameter U
3026 Standard_Real U, Length, SecFirst, SecLen, Lf, Ll;
3027 myLoc->CurvilinearBounds( myLoc->NbLaw(), Lf, Length );
3028 mySec->Law(1)->GetDomain( SecFirst, SecLen );
3030 myLoc->CurvilinearBounds( I1, Lf, Ll );
3031 U = SecFirst + (Ll/Length)*SecLen;
3034 //Box(Sec, 0., box);
3036 box.Get(Xmin, Ymin, Zmin, Xmax, Ymax, Zmax);
3038 R = Max(Max(Abs(Xmin), Abs(Xmax)),Max(Abs(Ymin), Abs(Ymax)));
3040 // modified by NIZHNY-MKK Fri Oct 31 18:57:51 2003
3041 // Standard_Real coef = 1.2;
3042 Standard_Real coef = 2.;
3044 Extrap = Max(Abs(Zmin), Abs(Zmax)) + 100*myTol3d;
3045 Extrap += R*Tan(alpha/2);
3050 //=======================================================================
3051 //function : MergeVertex
3052 //purpose : Make V2 = V1 if V2 is too close to V1
3053 //======================================================================
3054 Standard_Boolean BRepFill_Sweep::MergeVertex(const TopoDS_Shape& V1,
3055 TopoDS_Shape& V2) const
3057 // Class BRep_Tool without fields and without Constructor :
3059 const TopoDS_Vertex& v1 = TopoDS::Vertex(V1);
3060 const TopoDS_Vertex& v2 = TopoDS::Vertex(V2);
3062 // tol = Max(BT.Tolerance(v1), BT.Tolerance(v2));
3063 tol = Max(BRep_Tool::Tolerance(v1), BRep_Tool::Tolerance(v2));
3064 if (tol < myTol3d) tol = myTol3d;
3065 // if (BT.Pnt(v1).Distance(BT.Pnt(v2)) <= tol ){
3066 if (BRep_Tool::Pnt(v1).Distance(BRep_Tool::Pnt(v2)) <= tol ){
3068 return Standard_True;
3070 return Standard_False;
3074 //=======================================================================
3075 //function : UpdateVertex
3076 //purpose : Update the Tolerance of Vertices depending on Laws.
3077 //======================================================================
3078 void BRepFill_Sweep::UpdateVertex(const Standard_Integer ipath,
3079 const Standard_Integer isec,
3080 const Standard_Real ErrApp,
3081 const Standard_Real Param,
3082 TopoDS_Shape& V) const
3084 TopoDS_Vertex vv, TheV;
3085 TheV = TopoDS::Vertex(V);
3086 myLoc->PerformVertex(ipath,
3087 mySec->Vertex(isec, Param),
3088 ErrApp+mySec->VertexTol(isec-1, Param),
3090 // Class BRep_Tool without fields and without Constructor :
3094 P1 = BRep_Tool::Pnt(vv);
3095 // P2 = BT.Pnt(TheV);
3096 P2 = BRep_Tool::Pnt(TheV);
3098 // Standard_Real Tol = BT.Tolerance(vv);
3099 Standard_Real Tol = BRep_Tool::Tolerance(vv);
3100 Tol += P1.Distance(P2);
3102 // if (Tol > BT.Tolerance(TheV)) {
3103 if (Tol > BRep_Tool::Tolerance(TheV)) {
3105 B.UpdateVertex(TheV, Tol);