1 // Created on: 1998-01-07
2 // Created by: Philippe MANGIN
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and / or modify it
9 // under the terms of the GNU Lesser General Public version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
19 #include <BRepFill_Sweep.ixx>
21 #include <BRepFill_SectionLaw.hxx>
22 //#include <BRepFill_TrimCorner.hxx>
23 #include <BRepFill_CurveConstraint.hxx>
25 #include <GeomFill_SectionLaw.hxx>
26 #include <GeomFill_LocationLaw.hxx>
27 #include <GeomFill_Sweep.hxx>
29 // modified by NIZHNY-MKK Wed Oct 22 12:25:45 2003
30 #include <BRepFill_TrimShellCorner.hxx>
32 //#include <GeomPlate_BuildPlateSurface.hxx>
33 //#include <GeomPlate_Surface.hxx>
34 //#include <GeomPlate_PointConstraint.hxx>
36 #include <gp_Pnt2d.hxx>
37 #include <gp_Vec2d.hxx>
38 #include <Bnd_Box.hxx>
40 #include <Geom_Surface.hxx>
41 #include <Geom_SurfaceOfRevolution.hxx>
42 #include <Geom_RectangularTrimmedSurface.hxx>
43 #include <Geom_Plane.hxx>
44 #include <Geom_Curve.hxx>
45 #include <Geom_BezierCurve.hxx>
46 #include <Geom_BSplineCurve.hxx>
47 #include <Geom2d_Line.hxx>
48 #include <Geom2d_Curve.hxx>
49 #include <Geom2d_TrimmedCurve.hxx>
50 #include <GeomLib.hxx>
51 #include <GeomLib_IsPlanarSurface.hxx>
52 #include <BRepLib_FindSurface.hxx>
53 #include <GeomConvert_ApproxSurface.hxx>
55 #include <BRepAdaptor_HCurve.hxx>
56 #include <BRepAdaptor_HCurve2d.hxx>
57 #include <BRepAdaptor_HSurface.hxx>
58 #include <Adaptor3d_HCurveOnSurface.hxx>
59 #include <GeomAdaptor_HSurface.hxx>
60 #include <GeomAdaptor_HCurve.hxx>
61 #include <Geom2dAdaptor_HCurve.hxx>
62 #include <Approx_CurveOnSurface.hxx>
63 #include <Approx_SameParameter.hxx>
64 #include <GCPnts_AbscissaPoint.hxx>
66 #include <BRep_Builder.hxx>
67 #include <BRep_Tool.hxx>
68 #include <BRep_ListIteratorOfListOfCurveRepresentation.hxx>
69 #include <BRep_TEdge.hxx>
70 #include <BRep_TVertex.hxx>
71 #include <BRep_CurveRepresentation.hxx>
72 #include <BRep_GCurve.hxx>
74 #include <BRepLib.hxx>
75 #include <BRepLib_MakeEdge.hxx>
76 #include <BRepLib_MakeFace.hxx>
77 #include <BRepLib_FaceError.hxx>
80 #include <TopoDS_Edge.hxx>
81 #include <TopoDS_Face.hxx>
82 #include <TopoDS_Compound.hxx>
83 #include <TopoDS_Shell.hxx>
85 #include <TopExp_Explorer.hxx>
86 #include <TopAbs_Orientation.hxx>
88 #include <TColStd_HArray1OfInteger.hxx>
89 #include <TColStd_Array2OfInteger.hxx>
90 #include <TColStd_Array1OfReal.hxx>
91 #include <TColStd_Array2OfReal.hxx>
92 #include <TColGeom_Array2OfSurface.hxx>
93 #include <TColgp_Array1OfPnt.hxx>
94 #include <TColStd_Array1OfBoolean.hxx>
96 #include <TopTools_Array1OfShape.hxx>
97 #include <TopTools_Array2OfShape.hxx>
98 #include <TopTools_HArray2OfShape.hxx>
99 #include <TopTools_HArray1OfShape.hxx>
100 #include <TopTools_ListIteratorOfListOfShape.hxx>
101 #include <TopTools_ListOfShape.hxx>
102 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
103 #include <TopTools_SequenceOfShape.hxx>
104 #include <BRepTools_WireExplorer.hxx>
106 #include <Standard_ConstructionError.hxx>
107 #include <Precision.hxx>
108 #include <BRepBuilderAPI_MakeWire.hxx>
110 #include <BRepTools_Substitution.hxx>
111 #include <TopTools_DataMapIteratorOfDataMapOfShapeShape.hxx>
112 #include <TopoDS_Iterator.hxx>
115 #include <BRepCheck_Edge.hxx>
119 #include <DrawTrSurf.hxx>
121 static Standard_Boolean Affich = 0;
124 //=======================================================================
125 //function : NumberOfPoles
127 //=======================================================================
128 static Standard_Integer NumberOfPoles(const TopoDS_Wire& W)
130 Standard_Integer NbPoints = 0;
132 TopoDS_Iterator iter(W);
133 for (; iter.More(); iter.Next())
135 BRepAdaptor_Curve c(TopoDS::Edge(iter.Value()));
137 Standard_Real dfUf = c.FirstParameter();
138 Standard_Real dfUl = c.LastParameter();
139 if (IsEqual(dfUf,dfUl))
145 case GeomAbs_BezierCurve:
147 // Put all poles for bezier
148 Handle(Geom_BezierCurve) GC = c.Bezier();
149 Standard_Integer iNbPol = GC->NbPoles();
154 case GeomAbs_BSplineCurve:
156 // Put all poles for bspline
157 Handle(Geom_BSplineCurve) GC = c.BSpline();
158 Standard_Integer iNbPol = GC->NbPoles();
169 case GeomAbs_Ellipse:
170 case GeomAbs_Hyperbola:
171 case GeomAbs_Parabola:
177 NbPoints += 15 + c.NbIntervals(GeomAbs_C3);
178 } // switch (c.GetType()) ...
179 } // for (; iter.More(); iter.Next())
184 //=======================================================================
185 //function : HasPCurves
187 //=======================================================================
188 static Standard_Boolean HasPCurves(const TopoDS_Edge& E)
190 Standard_Boolean haspcurves = Standard_False;
192 BRep_ListIteratorOfListOfCurveRepresentation itcr
193 ((*((Handle(BRep_TEdge)*)&E.TShape()))->Curves());
194 for (; itcr.More(); itcr.Next())
196 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
197 if (cr->IsCurveOnSurface())
199 haspcurves = Standard_True;
206 //=======================================================================
207 //function : Translate
208 //purpose : Copy a column from one table to another.
209 //=======================================================================
210 static void Translate(const Handle(TopTools_HArray2OfShape)& ArrayIn,
211 const Standard_Integer In,
212 Handle(TopTools_HArray2OfShape)& ArrayOut,
213 const Standard_Integer Out)
215 Standard_Integer ii, Nb;
216 Nb = ArrayOut->ColLength();
217 for (ii=1; ii<=Nb; ii++) {
218 ArrayOut->SetValue(ii, Out, ArrayIn->Value(ii, In));
223 //=======================================================================
225 //purpose : Bounding box of a section.
226 //=======================================================================
227 static void Box(Handle(GeomFill_SectionLaw)& Sec,
228 const Standard_Real U,
232 Standard_Integer NbPoles, bid;
234 Sec->SectionShape(NbPoles, bid, bid);
235 TColgp_Array1OfPnt Poles(1, NbPoles);
236 TColStd_Array1OfReal W(1, NbPoles);
237 Sec->D0(U, Poles, W);
238 for (Standard_Integer ii=1; ii<=NbPoles; ii++) {
243 //=======================================================================
245 //purpose : Check if E is an edge of sewing on S
246 // and make the representation HadHoc
247 //=======================================================================
248 static Handle(Geom2d_Curve) Couture(const TopoDS_Edge& E,
249 const Handle(Geom_Surface)& S,
250 const TopLoc_Location& L)
252 TopLoc_Location l = L.Predivided(E.Location());
253 Standard_Boolean Eisreversed = (E.Orientation() == TopAbs_REVERSED);
255 // find the representation
256 BRep_ListIteratorOfListOfCurveRepresentation itcr
257 ((*((Handle(BRep_TEdge)*)&E.TShape()))->ChangeCurves());
259 while (itcr.More()) {
260 Handle(BRep_CurveRepresentation)& cr = itcr.Value();
261 if (cr->IsCurveOnSurface(S,l)) {
262 Handle(BRep_GCurve)& GC = *((Handle(BRep_GCurve)*)&cr);
263 if (GC->IsCurveOnClosedSurface() && Eisreversed)
264 return GC->PCurve2();
270 Handle(Geom2d_Curve) pc;
275 //=======================================================================
276 //function : CheckSameParameter
277 //purpose : Check a posteriori that sameparameter has worked correctly
278 //=======================================================================
280 static Standard_Boolean CheckSameParameter
281 (const Handle(Adaptor3d_HCurve)& C3d,
282 const Handle(Geom2d_Curve)& Pcurv,
283 const Handle(Adaptor3d_HSurface)& S,
284 const Standard_Real tol3d,
285 Standard_Real& tolreached)
288 Standard_Real f = C3d->FirstParameter();
289 Standard_Real l = C3d->LastParameter();
290 Standard_Integer nbp = 45;
291 Standard_Real step = 1./(nbp -1);
292 for(Standard_Integer i = 0; i < nbp; i++){
295 t = (1-t) * f + t * l;
296 Pcurv->Value(t).Coord(u,v);
297 gp_Pnt pS = S->Value(u,v);
298 gp_Pnt pC = C3d->Value(t);
299 Standard_Real d2 = pS.SquareDistance(pC);
300 tolreached = Max(tolreached,d2);
302 tolreached = sqrt(tolreached);
303 if(tolreached > tol3d){
305 return Standard_False;
308 tolreached = Max(tolreached,Precision::Confusion());
309 return Standard_True;
312 //=======================================================================
313 //function : SameParameter
314 //purpose : Encapsulation of Sameparameter
315 // Boolean informs if the pcurve was computed or not...
316 // The tolerance is always OK.
317 //=======================================================================
319 static Standard_Boolean SameParameter(TopoDS_Edge& E,
320 Handle(Geom2d_Curve)& Pcurv,
321 const Handle(Geom_Surface)& Surf,
322 const Standard_Real tol3d,
323 Standard_Real& tolreached)
325 //Handle(BRepAdaptor_HCurve) C3d = new (BRepAdaptor_HCurve)(E);
327 Handle(Geom_Curve) C3d = BRep_Tool::Curve( E, f, l );
328 GeomAdaptor_Curve GAC3d( C3d, f, l );
329 Handle(GeomAdaptor_HCurve) HC3d = new GeomAdaptor_HCurve( GAC3d );
331 Handle(GeomAdaptor_HSurface) S = new (GeomAdaptor_HSurface)(Surf);
332 Standard_Real ResTol;
334 if(CheckSameParameter( HC3d, Pcurv, S, tol3d, tolreached ))
335 return Standard_True;
339 Handle(Geom2dAdaptor_HCurve) HC2d = new Geom2dAdaptor_HCurve( Pcurv );
340 Approx_CurveOnSurface AppCurve(HC2d, S, HC2d->FirstParameter(), HC2d->LastParameter(),
341 Precision::Confusion(), GeomAbs_C1, 10, 10, Standard_True);
342 if (AppCurve.IsDone() && AppCurve.HasResult())
344 C3d = AppCurve.Curve3d();
345 tolreached = AppCurve.MaxError3d();
347 B.UpdateEdge( E, C3d, tolreached );
348 return Standard_True;
352 Approx_SameParameter sp( HC3d, Pcurv, S, tol3d );
353 if(sp.IsDone() && !sp.IsSameParameter()) Pcurv = sp.Curve2d();
354 else if(!sp.IsDone() && !sp.IsSameParameter()){
356 cout<<"echec SameParameter"<<endl;
358 return Standard_False;
361 ResTol = sp.TolReached();
362 if(ResTol > tolreached ){
364 cout<<"SameParameter : Tolerance not reached!"<<endl;
365 cout<<"tol visee : "<<tol3d<<" tol obtained : "<<ResTol<<endl;
367 return Standard_False;
370 tolreached = 1.1*ResTol;
371 if(sp.IsDone() && !sp.IsSameParameter()) Pcurv = sp.Curve2d();
373 return Standard_True;
376 //=======================================================================
377 //Objet : Orientate an edge of natural restriction
379 //=======================================================================
380 static void Oriente(const Handle(Geom_Surface)& S,
384 gp_Vec2d D, URef(1, 0), VRef(0, 1);
385 Standard_Boolean isuiso, isfirst, isopposite;
386 Standard_Real UFirst, ULast, VFirst, VLast, f, l;
387 S->Bounds(UFirst, ULast, VFirst, VLast);
388 Handle(Geom2d_Curve) C;
391 C = BRep_Tool::CurveOnSurface(E, S, bid, f, l);
392 C->D1((f+l)/2, P, D);
394 isuiso = D.IsParallel(VRef, 0.1);
397 isfirst = (Abs (P.X()-UFirst) < Precision::Confusion());
398 isopposite = D.IsOpposite(VRef, 0.1);
399 E.Orientation(TopAbs_REVERSED);
402 isfirst = (Abs (P.Y()-VFirst) < Precision::Confusion());
403 isopposite = D.IsOpposite(URef, 0.1);
404 E.Orientation(TopAbs_FORWARD);
407 if (!isfirst) E.Reverse();
408 if (isopposite) E.Reverse();
411 static void UpdateEdgeOnPlane(const TopoDS_Face& F, const TopoDS_Edge& E,
412 const BRep_Builder& BB)
415 Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(E,F,f,l);
416 Handle(Geom_Surface) S = BRep_Tool::Surface(F);
418 Standard_Real Tol = BRep_Tool::Tolerance(E);
419 BB.UpdateEdge(E, C2d, S, Loc, Tol);
420 BRepCheck_Edge Check(E);
421 Tol = Max(Tol,Check.Tolerance());
422 BB.UpdateEdge(E, Tol);
425 V = TopExp::FirstVertex(E);
426 if(BRep_Tool::Tolerance(V) < Tol) BB.UpdateVertex(V, Tol);
427 V = TopExp::LastVertex(E);
428 if(BRep_Tool::Tolerance(V) < Tol) BB.UpdateVertex(V, Tol);
431 //=======================================================================
432 //Function : BuildFace
433 //Objet : Construct a Face via a surface and 4 Edges (natural borders)
434 // : Only one Hypothesis : isos u and v are switched :
435 // Edge1/3 are iso u (recp v)
436 // Edge2/4 are iso v (recp u)
437 //=======================================================================
438 static void BuildFace(const Handle(Geom_Surface)& S,
439 const TopoDS_Edge& E1,
440 const TopoDS_Edge& E2,
441 const TopoDS_Edge& E3,
442 const TopoDS_Edge& E4,
443 TopTools_DataMapOfShapeShape& EEmap,
444 const Standard_Boolean ExchUV,
445 const Standard_Boolean UReverse,
449 // Class BRep_Tool without fields and without Constructor :
451 TopoDS_Edge e1, e2, E;
454 BRepBuilderAPI_MakeWire B;
455 TopoDS_Iterator Iter;
458 //Is the surface planar ?
459 Standard_Real Tol1, Tol2, Tol3, Tol4;
460 Tol1 = BRep_Tool::Tolerance( E1 );
461 Tol2 = BRep_Tool::Tolerance( E2 );
462 Tol3 = BRep_Tool::Tolerance( E3 );
463 Tol4 = BRep_Tool::Tolerance( E4 );
464 // Tol = Min( BT.Tolerance(E1), BT.Tolerance(E2));
465 Tol = Min( Tol1, Tol2 );
466 // Tol = Min(Tol, Min(BT.Tolerance(E3),BT.Tolerance(E4)));
467 Tol = Min( Tol, Min( Tol3, Tol4 ) );
468 Standard_Boolean IsPlan = Standard_False;
469 Handle(Geom_Plane) thePlane;
471 if (!E1.IsSame(E3) && !E2.IsSame(E4)) //exclude cases with seam edges: they are not planar
473 GeomLib_IsPlanarSurface IsP(S, Tol);
476 IsPlan = Standard_True;
477 thePlane = new Geom_Plane( IsP.Plan() );
481 Handle(BRep_TEdge)& TE1 = *((Handle(BRep_TEdge)*)&E1.TShape());
482 Handle(BRep_TEdge)& TE2 = *((Handle(BRep_TEdge)*)&E2.TShape());
483 Handle(BRep_TEdge)& TE3 = *((Handle(BRep_TEdge)*)&E3.TShape());
484 Handle(BRep_TEdge)& TE4 = *((Handle(BRep_TEdge)*)&E4.TShape());
485 TE1->Tolerance( Precision::Confusion() );
486 TE2->Tolerance( Precision::Confusion() );
487 TE3->Tolerance( Precision::Confusion() );
488 TE4->Tolerance( Precision::Confusion() );
490 TopoDS_Wire theWire = BRepLib_MakeWire( E1, E2, E3, E4 );
491 Standard_Integer NbPoints = NumberOfPoles( theWire );
492 if (NbPoints <= 100) //limitation for CPU
494 BRepLib_FindSurface FS( theWire, -1, Standard_True );
497 IsPlan = Standard_True;
498 thePlane = Handle(Geom_Plane)::DownCast(FS.Surface());
501 BB.UpdateEdge( E1, Tol1 );
502 BB.UpdateEdge( E2, Tol2 );
503 BB.UpdateEdge( E3, Tol3 );
504 BB.UpdateEdge( E4, Tol4 );
508 // Construction of the wire
512 // if (!IsPlan || !BT.Degenerated(e1))
513 if (!IsPlan || !BRep_Tool::Degenerated(e1))
518 // if (!IsPlan || !BT.Degenerated(e2))
519 if (!IsPlan || !BRep_Tool::Degenerated(e2))
522 if (!BRep_Tool::Degenerated(e2))
525 TopoDS_Shape NewEdge;
526 //take the last edge added to WW
527 for (Iter.Initialize( WW ); Iter.More(); Iter.Next())
528 NewEdge = Iter.Value();
529 if (! e2.IsSame(NewEdge))
530 EEmap.Bind( e2, NewEdge );
542 // if (!IsPlan || !BT.Degenerated(E))
543 if (!IsPlan || !BRep_Tool::Degenerated(E))
546 if (!BRep_Tool::Degenerated(E))
549 TopoDS_Shape NewEdge;
550 //take the last edge added to WW
551 for (Iter.Initialize( WW ); Iter.More(); Iter.Next())
552 NewEdge = Iter.Value();
553 if (! E.IsSame(NewEdge))
554 EEmap.Bind( E, NewEdge );
566 // if (!IsPlan || !BT.Degenerated(E))
567 if (!IsPlan || !BRep_Tool::Degenerated(E))
570 if (!BRep_Tool::Degenerated(E))
573 TopoDS_Shape NewEdge;
574 //take the last edge added to WW
575 for (Iter.Initialize( WW ); Iter.More(); Iter.Next())
576 NewEdge = Iter.Value();
577 if (! E.IsSame(NewEdge))
578 EEmap.Bind( E, NewEdge );
585 DBRep::Set("wire-on-face", WW);
588 // Construction of the face.
589 if (IsPlan) { // Suspend representation 2d
590 // and construct face Plane
592 //BRepLib_MakeFace MkF(IsP.Plan(), WW);
594 gp_Vec DU, DV, NS, NP;
595 Standard_Real Ufirst, Ulast, Vfirst, Vlast;
596 S->Bounds( Ufirst, Ulast, Vfirst, Vlast );
597 S->D1( (Ufirst+Ulast)/2., (Vfirst+Vlast)/2., aPnt, DU, DV );
599 NP = thePlane->Pln().Axis().Direction();
601 thePlane->UReverse();
602 BRepLib_MakeFace MkF( thePlane, WW );
603 if (MkF.Error() != BRepLib_FaceDone) {
605 BRepLib_FaceError Err = MkF.Error();
606 cout << "Planar Face Error :" << Err << endl;
610 Handle(Geom2d_Curve) NullC2d;
612 BB.UpdateEdge( E1, NullC2d, S, Loc, Tol1 );
613 BB.UpdateEdge( E2, NullC2d, S, Loc, Tol2 );
614 BB.UpdateEdge( E3, NullC2d, S, Loc, Tol3 );
615 BB.UpdateEdge( E4, NullC2d, S, Loc, Tol4 );
618 UpdateEdgeOnPlane(F,E1,BB);
619 UpdateEdgeOnPlane(F,E2,BB);
620 UpdateEdgeOnPlane(F,E3,BB);
621 UpdateEdgeOnPlane(F,E4,BB);
624 Handle(Geom2d_Curve) NC;
626 // B.UpdateEdge(E1, NC, S, Loc, BT.Tolerance(E1));
627 BB.UpdateEdge(E1, NC, S, Loc, BRep_Tool::Tolerance(E1));
628 // B.UpdateEdge(E2, NC, S, Loc, BT.Tolerance(E2));
629 BB.UpdateEdge(E2, NC, S, Loc, BRep_Tool::Tolerance(E2));
630 // B.UpdateEdge(E3, NC, S, Loc, BT.Tolerance(E3));
631 BB.UpdateEdge(E3, NC, S, Loc, BRep_Tool::Tolerance(E3));
632 // B.UpdateEdge(E4, NC, S, Loc, BT.Tolerance(E4));
633 BB.UpdateEdge(E4, NC, S, Loc, BRep_Tool::Tolerance(E4));
638 if (!IsPlan) {// Cas Standard : Ajout
639 BB.MakeFace(F, S, Precision::Confusion());
644 if (ExchUV) F.Reverse();
645 if (UReverse) F.Reverse();
649 //=======================================================================
650 //Fonction : BuildEdge
651 //Objet : Construct non-closed Edge
652 //=======================================================================
653 static TopoDS_Edge BuildEdge(Handle(Geom_Curve)& C3d,
654 Handle(Geom2d_Curve)& C2d,
655 Handle(Geom_Surface)& S,
656 const TopoDS_Vertex& VF,
657 const TopoDS_Vertex& VL,
658 const Standard_Real f,
659 const Standard_Real l,
660 const Standard_Real Tol3d)
663 Standard_Real Tol1, Tol2, Tol, d;
664 // Class BRep_Tool without fields and without Constructor :
670 P1 = BRep_Tool::Pnt(VF);
671 // Tol1 = BT.Tolerance(VF);
672 Tol1 = BRep_Tool::Tolerance(VF);
674 P2 = BRep_Tool::Pnt(VL);
675 // Tol2 = BT.Tolerance(VF);
676 Tol2 = BRep_Tool::Tolerance(VF);
677 Tol = Max(Tol1, Tol2);
680 (P1.Distance(P2) < Tol ) ) {
684 S->D0(P2d.X(), P2d.Y(), P);
686 if (d > Tol) Tol = d;
688 S->D0(P2d.X(), P2d.Y(), P);
690 if (d > Tol) Tol = d;
692 B.UpdateVertex(VF, Tol);
693 B.UpdateVertex(VL, Tol);
696 B.UpdateEdge(E,C2d,S,TopLoc_Location(), Tol);
700 B.Degenerated(E, Standard_True);
708 B.UpdateVertex(VF, d);
711 P1 = BRep_Tool::Pnt(VL);
715 B.UpdateVertex(VL, d);
717 BRepLib_MakeEdge MkE (C3d, VF, VL, f, l);
718 if (!MkE.IsDone()) { // Error of construction !!
721 sprintf(name,"firstvertex_error");
722 DBRep::Set(name, VF);
723 sprintf(name,"lastvertex_error");
724 DBRep::Set(name, VL);
725 sprintf(name,"curve3d_error");
727 DrawTrSurf::Set(Temp, C3d);
728 // DrawTrSurf::Set(name, C3d);
729 Standard_ConstructionError::Raise("BRepFill_Sweep::BuildEdge");
735 B.UpdateEdge(E, C2d, S, Loc, Tol3d);
741 //=======================================================================
743 //Objet : Construct the faces of filling
744 //=======================================================================
745 static Standard_Boolean Filling(const TopoDS_Shape& EF,
746 const TopoDS_Shape& F1,
747 const TopoDS_Shape& EL,
748 const TopoDS_Shape& F2,
749 TopTools_DataMapOfShapeShape& EEmap,
750 const Standard_Real Tol,
752 const gp_Vec& TangentOnPart1,
758 // Class BRep_Tool without fields and without Constructor :
760 // Standard_Integer NbInt =0;
761 // Standard_Real Tol3d = Tol;
762 Standard_Boolean WithE3, WithE4;
764 // Return constraints
765 TopoDS_Vertex V1, V2, Vf, Vl;
766 TopoDS_Edge E1, E2, E3, E4;
767 E1 = TopoDS::Edge(EF);
768 E2 = TopoDS::Edge(EL);
770 TopExp::Vertices(E1, Vf, Vl);
771 Vf.Orientation(TopAbs_FORWARD);
772 Vl.Orientation(TopAbs_FORWARD);
774 TopExp::Vertices(E2, V1, V2);
775 V1.Orientation(TopAbs_REVERSED);
776 V2.Orientation(TopAbs_REVERSED);
781 WithE3 = WithE4 = Standard_False;
783 if ((!Aux1.IsNull()) && (!Vf.IsSame(V1))) {
785 // E3 = TopoDS::Edge(Aux1);
786 WithE3 = Standard_True;
794 else if (!Aux2.IsNull() && (!Vl.IsSame(V2))) {
796 // E4 = TopoDS::Edge(Aux2);
797 WithE4 = Standard_True;
802 DBRep::Set("Fill_Edge1", E1);
803 DBRep::Set("Fill_Edge2", E2);
805 DBRep::Set("Fill_Edge3", E3);
807 DBRep::Set("Fill_Edge4", E4);
811 // Construction of a surface of revolution
812 Handle(Geom_Curve) Prof1, Prof2;
813 //Standard_Integer ii, jj;//, Nb;
814 Standard_Real f1, f2, l1, l2,/*d1, d2,*/ Angle;//, Eps = 1.e-9;
815 // Prof1 = BT.Curve(E1, f1, l1);
816 Prof1 = BRep_Tool::Curve(E1, f1, l1);
817 // Prof2 = BT.Curve(E2, f2, l2);
818 Prof2 = BRep_Tool::Curve(E2, f2, l2);
822 Tf.SetTransformation(Axe);
824 // Choose the angle of opening
825 P1 = Prof1->Value((f1+l1)/2);
826 P2 = Prof2->Value((f2+l2)/2);
829 p1.SetCoord(P1.Z(), P1.X());
830 p2.SetCoord(P2.Z(), P2.X());
831 gp_Vec2d v1(gp::Origin2d(), p1);
832 gp_Vec2d v2(gp::Origin2d(), p2);
833 if (v1.Magnitude() <= gp::Resolution() ||
834 v2.Magnitude() <= gp::Resolution())
835 return Standard_False;
836 Angle = v1.Angle(v2);
838 gp_Ax1 axe(Axe.Location(), Axe.YDirection());
845 Handle(Geom_SurfaceOfRevolution) Rev =
846 new (Geom_SurfaceOfRevolution) (Prof1, axe);
848 Handle(Geom_Surface) Surf =
849 new (Geom_RectangularTrimmedSurface) (Rev, 0, Angle, f1, l1);
851 // Control the direction of the rotation
852 Standard_Boolean ToReverseResult = Standard_False;
854 d1u = Surf->DN(0, (f1+l1)/2, 1, 0);
855 if (d1u.Angle(TangentOnPart1) > M_PI/2) { //Invert everything
856 ToReverseResult = Standard_True;
859 Angle = 2*M_PI - Angle;
860 Rev = new (Geom_SurfaceOfRevolution) (Prof1, axe);
861 Surf = new (Geom_RectangularTrimmedSurface)
862 (Rev, 0, Angle, f1, l1);
868 char* Temp = "Surf_Init" ;
869 DrawTrSurf::Set(Temp, Surf);
873 Handle(Geom2d_Curve) C1, C2, C3, C4;
875 // Deform the surface of revolution.
876 GeomPlate_BuildPlateSurface BPS;
878 Handle(BRepAdaptor_HSurface) AS;
879 Handle(BRepAdaptor_HCurve2d) AC2d;
880 Handle(Adaptor3d_HCurveOnSurface) HConS;
882 Handle(Geom2d_Line) L;
885 L = new (Geom2d_Line) (P2d, gp::DY2d());
886 C1 = new (Geom2d_TrimmedCurve) (L, f1, l1);
888 P2d.SetCoord(Angle,0.);
889 L = new (Geom2d_Line) (P2d, gp::DY2d());
890 C2 = new (Geom2d_TrimmedCurve) (L, f1, l1);
892 // It is required to control the direction and the range.
894 Surf->D0(P2d.X(), P2d.Y(), P1);
896 Surf->D0(P2d.X(), P2d.Y(), P2);
898 P = BRep_Tool::Pnt(V1);
899 if (P.Distance(P2)+Tol < P.Distance(P1)) {
900 // E2 is parsed in the direction opposite to E1
907 GeomLib::SameRange(Precision::PConfusion(), C2,
908 C2->FirstParameter(),
914 P1 = BRep_Tool::Pnt(Vf);
916 P2 = BRep_Tool::Pnt(V1);
917 // pointu_f = Vf.IsSame(V1) || (P1.Distance(P2) < BT.Tolerance(Vf));
919 P1 = BRep_Tool::Pnt(Vl);
921 P2 = BRep_Tool::Pnt(V2);
922 // pointu_l = Vl.IsSame(V2) || (P1.Distance(P2) < BT.Tolerance(Vl));
925 L = new (Geom2d_Line) (P2d, gp::DX2d());
926 C3 = new (Geom2d_TrimmedCurve) (L, 0, Angle);
930 L = new (Geom2d_Line) (P2d, gp::DX2d());
931 C4 = new (Geom2d_TrimmedCurve) (L, 0, Angle);
933 // Determine the constraints and
934 // their parametric localisation.
936 AS = new BRepAdaptor_HSurface(TopoDS::Face(F1));
937 AC2d = new BRepAdaptor_HCurve2d();
938 AC2d->ChangeCurve2d().Initialize(E1,TopoDS::Face(F1));
939 HConS = new (Adaptor3d_HCurveOnSurface)();
940 HConS->ChangeCurve().Load(AC2d);
941 HConS->ChangeCurve().Load(AS);
943 Handle(BRepFill_CurveConstraint) Cont
944 = new BRepFill_CurveConstraint(HConS, 1, 15);
945 Cont->SetCurve2dOnSurf(C1);
948 NbInt = HConS->NbIntervals(GeomAbs_CN);
952 AS = new BRepAdaptor_HSurface(TopoDS::Face(F2));
953 AC2d = new BRepAdaptor_HCurve2d();
954 AC2d->ChangeCurve2d().Initialize(E2,TopoDS::Face(F2));
955 HConS = new (Adaptor3d_HCurveOnSurface);
957 HConS->ChangeCurve().Load(AC2d);
958 HConS->ChangeCurve().Load(AS);
960 Handle(BRepFill_CurveConstraint) Cont
961 = new BRepFill_CurveConstraint(HConS, 1, 15);
962 Cont->SetCurve2dOnSurf(C2);
967 Handle(BRepAdaptor_HCurve) AC = new (BRepAdaptor_HCurve) (E3);
968 Handle(BRepFill_CurveConstraint) Cont
969 = new BRepFill_CurveConstraint(AC, 0);
970 Cont->SetCurve2dOnSurf(C3);
974 Standard_Real delta = Angle / 11;
976 P = BRep_Tool::Pnt(Vf);
977 Handle(GeomPlate_PointConstraint) PC;
978 for (ii=1; ii<=10; ii++) {
979 C3->D0(ii*delta, P2d);
980 PC = new (GeomPlate_PointConstraint) (P, 0);
981 PC->SetPnt2dOnSurf(P2d);
988 Handle(BRepAdaptor_HCurve) AC = new (BRepAdaptor_HCurve) (E4);
989 Handle(BRepFill_CurveConstraint) Cont
990 = new BRepFill_CurveConstraint(AC, 0);
991 Cont->SetCurve2dOnSurf(C4);
995 Standard_Real delta = Angle / 11;
997 P = BRep_Tool::Pnt(Vl);
998 Handle(GeomPlate_PointConstraint) PC;
999 for (ii=1; ii<=10; ii++) {
1000 C4->D0(ii*delta, P2d);
1001 PC = new (GeomPlate_PointConstraint) (P, 0);
1002 PC->SetPnt2dOnSurf(P2d);
1007 BPS.LoadInitSurface(Surf);
1010 // Controle s'il y a une deformation effective
1011 Handle(GeomPlate_Surface) plate;
1012 plate = BPS.Surface();
1013 plate->SetBounds(0, Angle, f1, l1);
1014 Standard_Boolean Ok=Standard_True;
1018 for (ii=0; ii<=5 && Ok; ii++) {
1020 for (jj=0; jj<=5 && Ok; jj++) {
1022 plate->D0(u, v, P1);
1024 Ok = (P2.IsEqual(P1, Tol));
1030 // Approx de la plate surface
1031 // Bords naturelles => pas besoin de criteres.
1032 GeomConvert_ApproxSurface App(BPS.Surface(),
1034 GeomAbs_C1, GeomAbs_C1,
1036 if (!App.HasResult()) {
1038 cout << "Filling_Approx : Pas de resultat" << endl;
1040 return Standard_False;
1043 cout << "Filling_Approx Error 3d = " <<
1044 App.MaxError() << endl;
1046 Surf = App.Surface();
1047 Tol3d = App.MaxError();
1052 TopLoc_Location Loc;
1053 Handle(Geom_Curve) C3d;
1054 B.UpdateEdge(E1, C1, Surf, Loc, /*Tol3d*/Precision::Confusion());
1055 B.UpdateEdge(E2, C2, Surf, Loc, /*Tol3d*/Precision::Confusion());
1057 if (E3.IsSame(E4)) {
1060 C3d = Surf->VIso(f1);
1061 E3 = BuildEdge(C3d, C3, Surf, Vf, V1, 0, Angle, /*Tol3d*/Precision::Confusion());
1065 BRepAdaptor_Curve aCurve(E3);
1066 Standard_Real AngleOld = aCurve.LastParameter();
1067 if (Angle > AngleOld)
1069 B.Range( E3, 0, Angle );
1070 TopoDS_Vertex V (TopExp::LastVertex(E3));
1071 Handle(BRep_TVertex)& TVlast = *((Handle(BRep_TVertex)*) &V.TShape());
1072 TVlast->Tolerance( Precision::Confusion() );
1076 B.UpdateEdge(E3, C3, C4, Surf, Loc, /*Tol3d*/Precision::Confusion());
1083 C3d = Surf->VIso(f1);
1084 E3 = BuildEdge(C3d, C3, Surf, Vf, V1, 0, Angle, /*Tol3d*/Precision::Confusion());
1088 BRepAdaptor_Curve aCurve(E3);
1089 Standard_Real AngleOld = aCurve.LastParameter();
1090 if (Angle > AngleOld)
1092 B.Range( E3, 0, Angle );
1093 TopoDS_Vertex V(TopExp::LastVertex(E3));
1094 Handle(BRep_TVertex)& TVlast = *((Handle(BRep_TVertex)*) &V.TShape());
1095 TVlast->Tolerance( Precision::Confusion() );
1098 B.UpdateEdge(E3, C3, Surf, Loc, /*Tol3d*/Precision::Confusion());
1103 C3d = Surf->VIso(l1);
1104 E4 = BuildEdge(C3d, C4, Surf, Vl, V2, 0, Angle, /*Tol3d*/Precision::Confusion());
1108 BRepAdaptor_Curve aCurve(E4);
1109 Standard_Real AngleOld = aCurve.LastParameter();
1110 if (Angle > AngleOld)
1112 B.Range( E4, 0, Angle );
1113 TopoDS_Vertex V (TopExp::LastVertex(E4));
1114 Handle(BRep_TVertex)& TVlast = *((Handle(BRep_TVertex)*)&V.TShape());
1115 TVlast->Tolerance( Precision::Confusion() );
1118 B.UpdateEdge(E4, C4, Surf, Loc, /*Tol3d*/Precision::Confusion());
1123 BuildFace(Surf,E1, E3, E2, E4, EEmap,
1124 Standard_False, Standard_False,
1127 // Set the continuities.
1128 B.Continuity(E1, TopoDS::Face(F1), Result, GeomAbs_G1);
1129 B.Continuity(E2, TopoDS::Face(F2), Result, GeomAbs_G1);
1131 // Render the calculated borders.
1132 // if (!BT.Degenerated(E3))
1133 if (!BRep_Tool::Degenerated(E3))
1136 B.MakeEdge(Aux1); //Nullify
1138 // if (!BT.Degenerated(E4))
1139 if (!BRep_Tool::Degenerated(E4))
1144 // Set the orientation
1145 gp_Vec D1U, D1V, N1, N2;
1146 C1->D0( (f1+l1)/2, P2d);
1147 Surf->D1(P2d.X(), P2d.Y(), P, D1U, D1V);
1150 // C1 = BT.CurveOnSurface(E1, TopoDS::Face(F1), f2, l2);
1151 C1 = BRep_Tool::CurveOnSurface(E1, TopoDS::Face(F1), f2, l2);
1152 C1->D0( (f1+l1)/2, P2d);
1153 Handle(BRepAdaptor_HSurface) AS = new BRepAdaptor_HSurface(TopoDS::Face(F1));
1154 AS->D1(P2d.X(), P2d.Y(), P, D1U, D1V);
1157 if ( (F1.Orientation() == TopAbs_REVERSED) ^ (N1.Angle(N2)>M_PI/2) )
1158 Result.Orientation(TopAbs_REVERSED);
1159 else Result.Orientation(TopAbs_FORWARD);
1161 if (ToReverseResult)
1165 if (Affich) DBRep::Set("BoucheTrou", Result);
1168 return Standard_True;
1171 //=======================================================================
1172 //function : Substitute
1174 //=======================================================================
1175 static void Substitute(BRepTools_Substitution& aSubstitute,
1176 const TopoDS_Edge& Old,
1177 const TopoDS_Edge& New)
1179 TopTools_ListOfShape listShape;
1181 TopoDS_Vertex OldV1, OldV2, NewV1, NewV2;
1182 TopExp::Vertices( Old, OldV1, OldV2 );
1183 TopExp::Vertices( New, NewV1, NewV2 );
1185 if (!aSubstitute.IsCopied( OldV1 ))
1187 listShape.Append( NewV1.Oriented(TopAbs_FORWARD) );
1188 aSubstitute.Substitute( OldV1, listShape );
1191 if (!aSubstitute.IsCopied( OldV2 ))
1193 listShape.Append( NewV2.Oriented(TopAbs_FORWARD) );
1194 aSubstitute.Substitute( OldV2, listShape );
1197 if (!aSubstitute.IsCopied( Old ))
1199 listShape.Append( New.Oriented(TopAbs_FORWARD) );
1200 aSubstitute.Substitute( Old, listShape );
1204 //=======================================================================
1205 //Function : SetCommonEdgeInFace
1206 //Purpose : Replace an edge of the face by the corresponding edge from
1208 //=======================================================================
1210 static void SetCommonEdgeInFace(BRepTools_Substitution& aSubstitute,
1211 const TopoDS_Shape& Face,
1212 const TopoDS_Shape& Edge)
1217 Standard_Boolean done = Standard_False;
1218 // Class BRep_Tool without fields and without Constructor :
1221 TopExp_Explorer Exp(Face, TopAbs_EDGE);
1222 Handle(Geom_Curve) Cref, C;
1223 TopLoc_Location Lref, L;
1224 // Cref = BT.Curve(TopoDS::Edge(Edge), Lref, f, l);
1225 const TopoDS_Edge& NewEdge = TopoDS::Edge(Edge);
1226 Cref = BRep_Tool::Curve( NewEdge, Lref, f, l );
1228 for ( ; Exp.More() && !done; Exp.Next()) {
1229 // C = BT.Curve(TopoDS::Edge(Exp.Current()), L, f, l);
1230 const TopoDS_Edge& OldEdge = TopoDS::Edge(Exp.Current());
1231 C = BRep_Tool::Curve(OldEdge, L, f, l);
1232 if ((Cref==C) && (Lref == L)) {
1233 done = Standard_True;
1234 Substitute( aSubstitute, OldEdge, NewEdge );
1238 if (!done) cout << "Substitution of Edge failed" << endl;
1243 //=======================================================================
1244 //Fonction : KeepEdge
1245 //Objet : Find edges of the face supported by the same Curve.
1246 //=======================================================================
1247 static void KeepEdge(const TopoDS_Shape& Face,
1248 const TopoDS_Shape& Edge,
1249 TopTools_ListOfShape& List)
1252 // Class BRep_Tool without fields and without Constructor :
1255 TopExp_Explorer Exp(Face, TopAbs_EDGE);
1256 Handle(Geom_Curve) Cref, C;
1257 TopLoc_Location Lref, L;
1258 // Cref = BT.Curve(TopoDS::Edge(Edge), Lref, f, l);
1259 Cref = BRep_Tool::Curve(TopoDS::Edge(Edge), Lref, f, l);
1261 for ( ; Exp.More(); Exp.Next()) {
1262 // C = BT.Curve(TopoDS::Edge(Exp.Current()), L, f, l);
1263 C = BRep_Tool::Curve(TopoDS::Edge(Exp.Current()), L, f, l);
1264 if ((Cref==C) && (Lref == L)) {
1265 List.Append(Exp.Current());
1270 //=======================================================================
1272 //Objet : Construct a vertex via an iso
1273 //=======================================================================
1274 static void BuildVertex(const Handle(Geom_Curve)& Iso,
1275 const Standard_Boolean isfirst,
1276 const Standard_Real First,
1277 const Standard_Real Last,
1278 TopoDS_Shape& Vertex)
1283 if (isfirst) val = First;
1285 B.MakeVertex(TopoDS::Vertex(Vertex),
1287 Precision::Confusion());
1290 //=======================================================================
1292 //Objet : Construct an empty edge
1293 //=======================================================================
1294 static TopoDS_Edge NullEdge(TopoDS_Shape& Vertex)
1299 Vertex.Orientation(TopAbs_FORWARD);
1301 B.Add(E, Vertex.Reversed());
1302 B.Degenerated(E, Standard_True);
1307 //=======================================================================
1309 //Objet : Construct an edge via an iso
1310 //=======================================================================
1311 static TopoDS_Edge BuildEdge(const Handle(Geom_Surface)& S,
1312 const Standard_Boolean isUiso,
1313 const Standard_Real ValIso,
1314 const TopoDS_Shape& VFirst,
1315 const TopoDS_Shape& VLast,
1316 const Standard_Real Tol)
1320 Handle(Geom_Curve) Iso;
1321 Standard_Boolean sing = Standard_False;
1323 Iso = S->UIso(ValIso);
1326 Iso = S->VIso(ValIso);
1329 if (VFirst.IsSame(VLast)) { // Singular case ?
1331 // Class BRep_Tool without fields and without Constructor :
1333 const TopoDS_Vertex& V = TopoDS::Vertex(VFirst);
1334 // Standard_Real tol = BT.Tolerance(V);
1335 Standard_Real tol = BRep_Tool::Tolerance(V);
1336 if (Tol > tol) tol = Tol;
1337 Iso->D0((Iso->FirstParameter()+Iso->LastParameter())/2, P);
1338 // if (P.Distance(BT.Pnt(V)) < tol) {
1339 if (P.Distance(BRep_Tool::Pnt(V)) < tol) {
1340 GeomAdaptor_Curve AC(Iso);
1341 sing = GCPnts_AbscissaPoint::Length(AC, tol/4) < tol;
1346 if (sing) { // Singular case
1351 // B.UpdateEdge(E, Iso, Precision::Confusion());
1352 B.Degenerated(E, Standard_True);
1356 // Construction Via 3d
1358 // Iso = S->UIso(ValIso);
1360 Standard_Real p1, p2, p11, p12, p21, p22;
1361 Standard_Boolean fwd = Standard_False;
1362 p1 = Iso->FirstParameter();
1363 p2 = Iso->LastParameter();
1364 P1 = Iso->Value(p1);
1365 P2 = Iso->Value(p2);
1367 Standard_Real t1 = BRep_Tool::Tolerance(TopoDS::Vertex(VFirst));
1368 Standard_Real t2 = BRep_Tool::Tolerance(TopoDS::Vertex(VLast));
1372 p11 = P1.Distance(BRep_Tool::Pnt(TopoDS::Vertex(VFirst)));
1373 p22 = P2.Distance(BRep_Tool::Pnt(TopoDS::Vertex(VLast)));
1374 p12 = P1.Distance(BRep_Tool::Pnt(TopoDS::Vertex(VLast)));
1375 p21 = P2.Distance(BRep_Tool::Pnt(TopoDS::Vertex(VFirst)));
1377 if(p11 < p12 && p22 < p21) fwd = Standard_True;
1379 if(fwd) { //OCC500(apo)
1380 if (p11 >= t1) BB.UpdateVertex(TopoDS::Vertex(VFirst), 1.01*p11);
1381 if (p22 >= t2) BB.UpdateVertex(TopoDS::Vertex(VLast), 1.01*p22);
1384 // Iso = S->VIso(ValIso);
1385 if (p12 >= t2) BB.UpdateVertex(TopoDS::Vertex(VLast), 1.01*p12);
1386 if (p21 >= t1) BB.UpdateVertex(TopoDS::Vertex(VFirst), 1.01*p21);
1389 BRepLib_MakeEdge MkE;
1392 // TopoDS::Vertex(VFirst),
1393 // TopoDS::Vertex(VLast),
1394 // Iso->FirstParameter(),
1395 // Iso->LastParameter());
1398 TopoDS::Vertex(VFirst),
1399 TopoDS::Vertex(VLast),
1400 Iso->FirstParameter(),
1401 Iso->LastParameter());
1404 TopoDS::Vertex(VLast),
1405 TopoDS::Vertex(VFirst),
1406 Iso->FirstParameter(),
1407 Iso->LastParameter());
1409 // if (!MkE.IsDone()) { // Il faut peut etre permuter les Vertex
1411 // TopoDS::Vertex(VLast),
1412 // TopoDS::Vertex(VFirst),
1413 // Iso->FirstParameter(),
1414 // Iso->LastParameter());
1417 if (!MkE.IsDone()) { // Erreur de construction !!
1420 sprintf(name,"firstvertex_error");
1421 DBRep::Set(name, VFirst);
1422 sprintf(name,"lastvertex_error");
1423 DBRep::Set(name, VLast);
1424 sprintf(name,"curve3d_error");
1426 DrawTrSurf::Set(Temp,Iso);
1427 // DrawTrSurf::Set(name,Iso);
1429 Standard_ConstructionError::Raise("BRepFill_Sweep::BuildEdge");
1436 Handle(Geom2d_Line) L;
1437 TopLoc_Location Loc;
1439 gp_Pnt2d P(ValIso, 0);
1441 L = new (Geom2d_Line) (P, V);
1444 gp_Pnt2d P(0., ValIso);
1446 L = new (Geom2d_Line) (P, V);
1449 B.UpdateEdge(E, L, S, Loc, Precision::Confusion());
1450 if (sing) B.Range(E, S, Loc,
1451 Iso->FirstParameter(),
1452 Iso->LastParameter());
1454 Standard_Real MaxTol = 1.e-4;
1455 Standard_Real theTol;
1456 GeomAdaptor_Curve GAiso(Iso);
1457 Handle(GeomAdaptor_HCurve) GAHiso = new GeomAdaptor_HCurve(GAiso);
1458 GeomAdaptor_Surface GAsurf(S);
1459 Handle(GeomAdaptor_HSurface) GAHsurf = new GeomAdaptor_HSurface(GAsurf);
1460 CheckSameParameter( GAHiso, L, GAHsurf, MaxTol, theTol);
1461 B.UpdateEdge(E, theTol);
1466 //=======================================================================
1468 //Objet : Complete an edge via an iso
1469 //=======================================================================
1470 static void UpdateEdge(TopoDS_Edge& E,
1471 const Handle(Geom_Surface)& S,
1472 const Standard_Boolean isUiso,
1473 const Standard_Real ValIso)
1476 Handle(Geom2d_Line) L;
1477 Handle(Geom2d_Curve) PCurve, CL;
1478 TopLoc_Location Loc;
1479 Standard_Real UFirst, ULast, VFirst, VLast, F2d, L2d;
1480 S->Bounds( UFirst, ULast, VFirst, VLast);
1482 Standard_Boolean sing = Standard_False;
1483 Handle(Geom_Curve) Iso;
1485 Iso = S->UIso(ValIso);
1488 Iso = S->VIso(ValIso);
1491 TopoDS_Vertex Vf, Vl;
1492 TopExp::Vertices(E, Vf, Vl);
1493 if (Vf.IsSame(Vl)) { // Singular case ?
1495 Standard_Real tol = BRep_Tool::Tolerance(Vf);
1496 Iso->D0((Iso->FirstParameter()+Iso->LastParameter())/2, Pmid);
1497 if (Pmid.Distance(BRep_Tool::Pnt(Vf)) < tol) {
1498 GeomAdaptor_Curve AC(Iso);
1499 sing = GCPnts_AbscissaPoint::Length(AC, tol/4) < tol;
1504 gp_Pnt2d P(ValIso, 0);
1506 L = new (Geom2d_Line) (P, V);
1511 gp_Pnt2d P(0., ValIso);
1513 L = new (Geom2d_Line) (P, V);
1517 CL = new (Geom2d_TrimmedCurve) (L, F2d, L2d);
1519 // Control direction & Range
1520 Standard_Real R, First, Last, Tol=1.e-4;
1521 Standard_Boolean reverse = Standard_False;;
1524 // Class BRep_Tool without fields and without Constructor :
1528 // BT.Range(E, First, Last);
1529 BRep_Tool::Range(E, First, Last);
1531 if (!Vf.IsSame(Vl)) {
1532 // Test distances between "FirstPoint" and "Vertex"
1533 P2d = CL->Value(F2d);
1534 POnS = S->Value(P2d.X(), P2d.Y());
1535 // reverse = POnS.Distance(BT.Pnt(Vl)) < POnS.Distance(BT.Pnt(Vf));
1536 reverse = POnS.Distance(BRep_Tool::Pnt(Vl)) < POnS.Distance(BRep_Tool::Pnt(Vf));
1539 // Test angle between "First Tangente"
1541 gp_Vec V3d, du, dv, dC3d;
1542 BRepAdaptor_Curve C3d(E);
1544 C3d.D1(First, POnS, dC3d);
1545 CL->D1(F2d, P2d, V2d);
1546 S->D1(P2d.X(), P2d.Y(), POnS, du, dv);
1547 V3d.SetLinearForm(V2d.X(), du, V2d.Y(), dv);
1548 reverse = ( dC3d.Angle(V3d) > Tol);
1550 if (reverse ) { // Return curve 2d
1551 CL = new (Geom2d_TrimmedCurve)(L, F2d, L2d);
1553 F2d = CL->FirstParameter();
1554 L2d = CL->LastParameter();
1559 Handle(Geom_Curve) NullCurve;
1560 B.UpdateEdge(E, NullCurve, 0.);
1561 B.Degenerated(E, Standard_True);
1562 B.Range(E, F2d, L2d);
1567 if (First != F2d || Last != L2d) {
1568 Handle(Geom2d_Curve) C2d;
1569 GeomLib::SameRange(Precision::PConfusion(), CL,
1570 F2d, L2d, First, Last,
1572 CL = new (Geom2d_TrimmedCurve)(C2d, First, Last);
1575 // Update des Vertex
1579 P2d = CL->Value(First);
1580 POnS = S->Value(P2d.X(), P2d.Y());
1581 V = TopExp::FirstVertex(E);
1582 // R = POnS.Distance(BT.Pnt(V));
1583 R = POnS.Distance(BRep_Tool::Pnt(V));
1584 B.UpdateVertex(V, R);
1586 P2d = CL->Value(Last);
1587 POnS = S->Value(P2d.X(), P2d.Y());
1588 V = TopExp::LastVertex(E);
1589 // R = POnS.Distance(BT.Pnt(V));
1590 R = POnS.Distance(BRep_Tool::Pnt(V));
1591 B.UpdateVertex(V, R);
1594 if (!sing && SameParameter(E, CL, S, Tol, R)) {
1598 PCurve = Couture(E, S, Loc);
1599 if (PCurve.IsNull())
1600 B.UpdateEdge(E, CL, S, Loc, Precision::Confusion());
1601 else { // Sewing edge
1604 if (e.Orientation() == TopAbs_REVERSED)
1605 B.UpdateEdge(E, CL, PCurve, S, Loc, Precision::Confusion());
1607 B.UpdateEdge(E, PCurve, CL, S, Loc, Precision::Confusion());
1610 // Attention to case not SameRange on its shapes (PRO13551)
1611 // if (!BT.SameRange(E)) B.Range(E, S, Loc, First, Last);
1612 if (!BRep_Tool::SameRange(E)) B.Range(E, S, Loc, First, Last);
1615 //=======================================================================
1616 // Object : Check if a surface is degenerated
1617 //=======================================================================
1618 static Standard_Boolean IsDegen(const Handle(Geom_Surface)& S,
1619 const Standard_Real Tol)
1621 Standard_Integer Nb = 5;
1622 Standard_Boolean B = Standard_True;
1623 Standard_Real Umax, Umin, Vmax, Vmin, t, dt, l;
1624 Standard_Integer ii;
1625 Handle(Geom_Curve) Iso;
1627 GCPnts_AbscissaPoint GC;
1629 S->Bounds(Umin, Umax, Vmin, Vmax);
1631 // Check the length of Iso-U
1632 t = (Umin + Umax)/2;
1634 S->D0(t, (Vmin+Vmax)/2, P2);
1636 B = ((P1.Distance(P2) + P2.Distance(P3)) < Tol);
1638 for (ii=1, dt = (Umax-Umin)/(Nb+1); B && (ii<=Nb); ii++) {
1641 GeomAdaptor_Curve AC(Iso);
1642 l = GC.Length(AC, Tol/4);
1646 if (B) return Standard_True;
1648 // Check the length of Iso-V
1649 t = (Vmin + Vmax)/2;
1651 S->D0((Umin+Umax)/2, t, P2);
1653 B = ((P1.Distance(P2) + P2.Distance(P3)) < Tol);
1656 for (ii=1, dt = (Vmax-Vmin)/(Nb+1); B && (ii<=Nb); ii++) {
1659 GeomAdaptor_Curve AC(Iso);
1660 l = GC.Length(AC, Tol/4);
1667 //=======================================================================
1668 //function : Constructeur
1670 //======================================================================
1671 BRepFill_Sweep::BRepFill_Sweep(const Handle(BRepFill_SectionLaw)& Section,
1672 const Handle(BRepFill_LocationLaw)& Location,
1673 const Standard_Boolean WithKPart) :
1674 isDone(Standard_False),
1682 SetTolerance(1.e-4);
1683 SetAngularControl();
1686 myApproxStyle = GeomFill_Location;
1687 myContinuity = GeomAbs_C2;
1690 myForceApproxC1 = Standard_False;
1693 //=======================================================================
1694 //function : SetBounds
1695 //purpose : Define start and end shapes
1696 //======================================================================
1697 void BRepFill_Sweep::SetBounds(const TopoDS_Wire& First,
1698 const TopoDS_Wire& Last)
1703 // It is necessary to check the SameRange on its (PRO13551)
1705 Standard_Boolean issame = Standard_True;
1708 BRepTools_WireExplorer wexp;
1709 if (!FirstShape.IsNull()) {
1710 for (wexp.Init(FirstShape); wexp.More(); wexp.Next()) {
1711 if (!BRepLib::CheckSameRange(wexp.Current())) {
1712 B.SameRange(wexp.Current(), Standard_False);
1713 B.SameParameter(wexp.Current(), Standard_False);
1715 issame = Standard_False;
1721 if (!LastShape.IsNull()) {
1722 for (wexp.Init(LastShape); wexp.More(); wexp.Next()) {
1723 if (!BRepLib::CheckSameRange(wexp.Current())) {
1724 B.SameRange(wexp.Current(), Standard_False);
1725 B.SameParameter(wexp.Current(), Standard_False);
1727 issame = Standard_False;
1735 cout<<"Sweep Warning : Edge not SameRange in the limits"<<endl;
1739 //=======================================================================
1740 //function : SetTolerance
1742 //======================================================================
1743 void BRepFill_Sweep::SetTolerance(const Standard_Real Tol3d,
1744 const Standard_Real BoundTol,
1745 const Standard_Real Tol2d,
1746 const Standard_Real TolAngular)
1749 myBoundTol = BoundTol;
1751 myTolAngular = TolAngular;
1753 //=======================================================================
1754 //function : SetAngularControl
1756 //======================================================================
1757 void BRepFill_Sweep::SetAngularControl(const Standard_Real MinAngle,
1758 const Standard_Real MaxAngle)
1760 myAngMin = Max (MinAngle, Precision::Angular());
1761 myAngMax = Min (MaxAngle, 6.28);
1764 //=======================================================================
1765 //function : SetForceApproxC1
1766 //purpose : Set the flag that indicates attempt to approximate
1767 // a C1-continuous surface if a swept surface proved
1769 //=======================================================================
1770 void BRepFill_Sweep::SetForceApproxC1(const Standard_Boolean ForceApproxC1)
1772 myForceApproxC1 = ForceApproxC1;
1775 ///=======================================================================
1776 //function : CorrectApproxParameters
1778 //=======================================================================
1779 Standard_Boolean BRepFill_Sweep::CorrectApproxParameters()
1781 TopoDS_Wire thePath = myLoc->Wire();
1782 GeomAbs_Shape NewCont = myContinuity;
1783 Standard_Integer NewSegmax = mySegmax;
1785 TopoDS_Iterator iter(thePath);
1786 for (; iter.More(); iter.Next())
1788 TopoDS_Edge anEdge = TopoDS::Edge(iter.Value());
1789 BRepAdaptor_Curve aBAcurve(anEdge);
1790 GeomAbs_Shape aContinuity = aBAcurve.Continuity();
1791 Standard_Integer aNbInterv = aBAcurve.NbIntervals(GeomAbs_CN);
1792 if (aContinuity < NewCont)
1793 NewCont = aContinuity;
1794 if (aNbInterv > NewSegmax)
1795 NewSegmax = aNbInterv;
1798 Standard_Boolean Corrected = Standard_False;
1799 if (NewCont != myContinuity || NewSegmax != mySegmax)
1800 Corrected = Standard_True;
1801 myContinuity = NewCont;
1802 mySegmax = NewSegmax;
1806 //=======================================================================
1807 //function : BuildWire
1808 //purpose : Construit a wire by sweeping
1809 //======================================================================
1810 Standard_Boolean BRepFill_Sweep::
1811 BuildWire(const BRepFill_TransitionStyle /*Transition*/)
1813 Standard_Integer ipath, isec = 1;
1817 // Class BRep_Tool without fields and without Constructor :
1819 Standard_Integer NbPath = myLoc->NbLaw();
1820 Standard_Boolean vclose;
1821 vclose = (myLoc->IsClosed() && (myLoc->IsG1(0, myTol3d)>= 0));
1823 Handle(Geom_Surface) S;
1824 Handle(Geom_Curve) Iso;
1825 Standard_Real val, bid, First, Last, Tol;
1831 // (1) Construction of all curves
1833 // (1.1) Construction of Tables
1834 myFaces = new (TopTools_HArray2OfShape) (1, 1, 1, NbPath);
1835 myUEdges = new (TopTools_HArray2OfShape) (1, 2, 1, NbPath);
1836 myVEdges = new (TopTools_HArray2OfShape) (1, 1, 1, NbPath+1);
1838 // (1.2) Calculate curves / vertex / edge
1839 for (ipath=1; ipath <=NbPath; ipath++) {
1840 // Curve by iso value
1841 GeomFill_Sweep Sweep(myLoc->Law(ipath), KPart);
1842 Sweep.SetTolerance(myTol3d, myBoundTol, myTol2d, myTolAngular);
1843 Sweep.SetForceApproxC1(myForceApproxC1);
1844 Sweep.Build(mySec->Law(isec), myApproxStyle, myContinuity, myDegmax, mySegmax);
1845 if (!Sweep.IsDone())
1846 return Standard_False;
1847 S = Sweep.Surface();
1848 if (Sweep.ExchangeUV()) {
1849 if (Sweep.UReversed()) S->Bounds(First, Last, bid, val);
1850 else S->Bounds(First, Last, val, bid);
1854 if (Sweep.UReversed()) S->Bounds(bid, val, First, Last);
1855 else S->Bounds(val, bid, First, Last);
1858 // Vertex by position
1860 BuildVertex(Iso, Standard_False, First, Last,
1861 myVEdges->ChangeValue(1, ipath+1));
1864 TopoDS_Vertex& V = TopoDS::Vertex(myVEdges->ChangeValue(1, 1));
1865 myVEdges->SetValue(1, ipath+1, V);
1867 // Tol = P1.Distance(BT.Pnt(V));
1868 Tol = P1.Distance(BRep_Tool::Pnt(V));
1869 B.UpdateVertex(V, Tol);
1872 if (!LastShape.IsNull()) myVEdges->SetValue(1, NbPath, FirstShape);
1873 else BuildVertex(Iso, Standard_False, First, Last,
1874 myVEdges->ChangeValue(1, NbPath+1));
1880 TopoDS_Vertex& V = TopoDS::Vertex(myVEdges->ChangeValue(1, ipath));
1881 // Tol = P1.Distance(BT.Pnt(V));
1882 Tol = P1.Distance(BRep_Tool::Pnt(V));
1883 B.UpdateVertex(V, Tol);
1886 if (!FirstShape.IsNull()) myVEdges->SetValue(1,1, FirstShape);
1887 else BuildVertex(Iso, Standard_True, First, Last,
1888 myVEdges->ChangeValue(1, 1));
1891 // Construction of the edge
1892 BRepLib_MakeEdge MkE;
1894 TopoDS::Vertex(myVEdges->Value(1, ipath)),
1895 TopoDS::Vertex(myVEdges->Value(1, ipath+1)),
1896 Iso->FirstParameter(),
1897 Iso->LastParameter());
1898 if (!MkE.IsDone()) { // Error of construction !!
1901 sprintf(name,"firstvertex_error");
1902 DBRep::Set(name, myVEdges->Value(1, ipath));
1903 sprintf(name,"lastvertex_error");
1904 DBRep::Set(name, myVEdges->Value(1, ipath+1));
1905 sprintf(name,"curve3d_error");
1907 DrawTrSurf::Set(Temp,Iso);
1908 // DrawTrSurf::Set(name,Iso);
1909 Standard_ConstructionError::Raise("BRepFill_Sweep::BuildEdge");
1911 return Standard_False;
1916 sprintf(name,"Surf_%d", ipath);
1918 DrawTrSurf::Set(Temp, S);
1919 // DrawTrSurf::Set(name, S);
1920 sprintf(name,"Edge_%d", ipath);
1921 DBRep::Set(name, E);
1924 B.UpdateEdge(E, Sweep.ErrorOnSurface());
1926 myFaces->SetValue(1, ipath, E);
1929 return Standard_True;
1932 //=======================================================================
1933 //function : BuildShell
1934 //purpose : Construct a Shell by sweeping
1935 //======================================================================
1936 Standard_Boolean BRepFill_Sweep::
1937 BuildShell(const BRepFill_TransitionStyle /*Transition*/,
1938 const Standard_Integer IFirst,
1939 const Standard_Integer ILast,
1940 TopTools_MapOfShape& ReversedEdges,
1941 BRepFill_DataMapOfShapeHArray2OfShape& Tapes,
1942 const Standard_Real ExtendFirst,
1943 const Standard_Real ExtendLast)
1945 Standard_Integer ipath, isec, IPath;
1950 Standard_Integer NbPath = ILast - IFirst;
1951 Standard_Integer NbLaw = mySec->NbLaw();
1952 Standard_Boolean uclose, vclose, constSection, hasdegen = Standard_False;
1953 constSection = mySec->IsConstant();
1954 uclose = mySec->IsUClosed();
1955 vclose = (mySec->IsVClosed() && myLoc->IsClosed()) &&
1956 (NbPath == myLoc->NbLaw()) && (myLoc->IsG1(0, myTol3d)>= 0);
1959 // (1) Construction of all surfaces
1961 // (1.1) Construction of Tables
1963 TColStd_Array2OfInteger ExchUV(1, NbLaw, 1, NbPath);
1964 TColStd_Array2OfInteger UReverse(1, NbLaw, 1, NbPath);
1965 TColStd_Array2OfInteger Degenerated(1, NbLaw, 1, NbPath);
1966 Degenerated.Init(0);
1967 // No VReverse for the moment...
1968 TColStd_Array2OfReal TabErr(1, NbLaw , 1, NbPath);
1969 TColGeom_Array2OfSurface TabS(1, NbLaw , 1, NbPath);
1971 TopTools_Array2OfShape UEdge(1, NbLaw+1, 1, NbPath);
1972 TopTools_Array2OfShape VEdge(1, NbLaw , 1, NbPath+1);
1973 TopTools_Array2OfShape Vertex(1,NbLaw+1, 1, NbPath+1);
1975 TopoDS_Vertex VNULL;
1979 TopTools_Array1OfShape SecVertex(1, NbLaw+1);
1980 TColStd_Array1OfReal VError(1, NbLaw+1);
1981 TColStd_Array1OfReal Vi(1, NbPath+1);
1983 //Initialization of management of parametric intervals
1984 //(Case of evolutionary sections)
1985 Standard_Real Length, SecDom, SecDeb;
1986 myLoc->CurvilinearBounds(myLoc->NbLaw(), SecDom, Length);
1987 mySec->Law(1)->GetDomain(SecDeb, SecDom);
1990 Standard_Real Lf, Ll;
1991 myLoc->CurvilinearBounds(IFirst-1, Lf, Ll);
1992 Vi(1) = SecDeb + (Ll/Length)*SecDom;
1997 // Error a priori on vertices
1999 for (isec=1; isec<=NbLaw+1; isec++) {
2000 VError(isec) = mySec->VertexTol(isec-1, 0.);
2001 SecVertex(isec) = mySec->Vertex(isec, 0.);
2006 // (1.2) Calculate surfaces
2007 for (ipath=1, IPath=IFirst; ipath <=NbPath; ipath++, IPath++) {
2009 GeomFill_Sweep Sweep(myLoc->Law(IPath), KPart);
2010 Sweep.SetTolerance(myTol3d, myBoundTol, myTol2d, myTolAngular);
2011 Sweep.SetForceApproxC1(myForceApproxC1);
2013 // Case of evolutionary section, definition of parametric correspondence
2014 if (!constSection) {
2015 Standard_Real lf, ll, Lf, Ll;
2016 myLoc->Law(IPath)->GetDomain(lf, ll);
2017 myLoc->CurvilinearBounds(IPath, Lf, Ll);
2018 Vi(ipath+1) = SecDeb + (Ll/Length)*SecDom;
2019 Sweep.SetDomain(lf, ll, Vi(ipath), Vi(ipath+1));
2021 else //section is constant
2023 Standard_Real lf, ll, Lf, Ll;
2024 myLoc->Law(IPath)->GetDomain(lf, ll);
2025 myLoc->CurvilinearBounds(IPath, Lf, Ll);
2026 Vi(ipath+1) = SecDeb + (Ll/Length)*SecDom;
2029 for(isec=1; isec<=NbLaw; isec++) {
2030 Sweep.Build(mySec->Law(isec), myApproxStyle, myContinuity, myDegmax, mySegmax);
2031 if (!Sweep.IsDone())
2032 return Standard_False;
2033 TabS(isec,ipath) = Sweep.Surface();
2034 TabErr(isec,ipath) = Sweep.ErrorOnSurface();
2035 ExchUV(isec, ipath) = Sweep.ExchangeUV();
2036 UReverse(isec, ipath) = Sweep.UReversed();
2037 if (Sweep.ErrorOnSurface()>Error) Error = Sweep.ErrorOnSurface();
2039 if ((ipath==1)&&(ExtendFirst>0)) {
2040 Handle(Geom_BoundedSurface) BndS;
2041 BndS = Handle(Geom_BoundedSurface)::DownCast(TabS(isec,ipath));
2042 GeomLib::ExtendSurfByLength(BndS, ExtendFirst, 1,
2043 Sweep.ExchangeUV(), Standard_False);
2044 TabS(isec,ipath) = BndS;
2046 if ((ipath==NbPath)&&(ExtendLast>0)){
2047 Handle(Geom_BoundedSurface) BndS;
2048 BndS = Handle(Geom_BoundedSurface)::DownCast(TabS(isec,ipath));
2049 GeomLib::ExtendSurfByLength(BndS, ExtendLast, 1,
2050 Sweep.ExchangeUV(), Standard_True);
2051 TabS(isec,ipath) = BndS;
2056 sprintf(name,"Surf_%d_%d", isec, IPath);
2058 DrawTrSurf::Set(Temp, TabS(isec,ipath));
2064 // (2) Construction of Edges
2065 Standard_Real UFirst, ULast, VFirst, VLast;
2066 Standard_Boolean exuv, singu, singv;
2067 Handle(Geom_Surface) S;
2069 // (2.0) return preexisting Edges and vertices
2071 TColStd_Array1OfBoolean IsBuilt(1, NbLaw);
2072 IsBuilt.Init(Standard_False);
2073 TopTools_Array1OfShape StartEdges(1, NbLaw);
2074 if (! FirstShape.IsNull() && (IFirst==1)) {
2075 mySec->Init(FirstShape);
2076 for (isec=1; isec<=NbLaw; isec++) {
2077 E = mySec->CurrentEdge();
2079 if (E.Orientation() == TopAbs_REVERSED)
2080 Vertex(isec+1, 1) = TopExp::FirstVertex(E);
2082 Vertex(isec+1, 1) = TopExp::LastVertex(E);
2083 UpdateVertex(IFirst-1, isec+1,
2084 TabErr(isec, 1), Vi(1), Vertex(isec+1, 1));
2086 StartEdges(isec) = E;
2087 if (Tapes.IsBound(E))
2089 IsBuilt(isec) = Standard_True;
2091 //Initialize VEdge, UEdge, Vertex and myFaces
2093 for (j = 1; j <= NbPath+1; j++)
2095 VEdge(isec, j) = Tapes(E)->Value(1, j);
2096 VEdge(isec, j).Reverse(); //direction of round is reversed
2098 Standard_Integer ifirst = isec+1, ilast = isec; //direction of round is reversed
2099 for (j = 1; j <= NbPath; j++)
2100 UEdge(ifirst, j) = Tapes(E)->Value(2, j);
2101 for (j = 1; j <= NbPath; j++)
2102 UEdge(ilast, j) = Tapes(E)->Value(3, j);
2103 for (j = 1; j <= NbPath+1; j++)
2104 Vertex(ifirst, j) = Tapes(E)->Value(4, j);
2105 for (j = 1; j <= NbPath+1; j++)
2106 Vertex(ilast, j) = Tapes(E)->Value(5, j);
2107 for (j = 1; j <= NbPath; j++)
2108 myFaces->SetValue(isec, j, Tapes(E)->Value(6, j));
2110 if (uclose && isec == 1)
2112 for (j = 1; j <= NbPath; j++)
2113 UEdge(NbLaw+1, j) = UEdge(1, j);
2114 for (j = 1; j <= NbPath+1; j++)
2115 Vertex(NbLaw+1, j) = Vertex(1, j);
2117 if (uclose && isec == NbLaw)
2119 for (j = 1; j <= NbPath; j++)
2120 UEdge(1, j) = UEdge(NbLaw+1, j);
2121 for (j = 1; j <= NbPath+1; j++)
2122 Vertex(1, j) = Vertex(NbLaw+1, j);
2127 Handle(TopTools_HArray2OfShape) EmptyArray = new TopTools_HArray2OfShape(1, 6, 1, NbPath+1);
2128 Tapes.Bind(E, EmptyArray);
2132 if (VEdge(1, 1).Orientation() == TopAbs_REVERSED)
2133 Vertex(1, 1) = TopExp::LastVertex(TopoDS::Edge(VEdge(1, 1)));
2135 Vertex(1, 1) = TopExp::FirstVertex(TopoDS::Edge(VEdge(1, 1)));
2136 UpdateVertex(IFirst-1, 1,
2137 TabErr(1, 1), Vi(1), Vertex(1, 1));
2140 Standard_Real u, v, aux;
2141 Standard_Boolean ureverse;
2142 for (isec=1; isec<=NbLaw+1; isec++) {
2146 ureverse = UReverse(NbLaw, 1);
2147 exuv = ExchUV(NbLaw, 1);
2151 ureverse = UReverse(isec, 1);
2152 exuv = ExchUV(isec, 1);
2154 S->Bounds(UFirst, ULast, VFirst, VLast);
2156 // Choice of parameters
2159 aux = VFirst; VFirst = VLast; VLast = aux;
2162 aux = UFirst; UFirst = ULast; ULast = aux;
2165 if (isec!= NbLaw+1) {
2180 // construction of vertices
2181 if (Vertex(isec, 1).IsNull())
2182 B.MakeVertex(TopoDS::Vertex(Vertex(isec, 1)),
2184 mySec->VertexTol(isec-1,Vi(1)));
2187 TopLoc_Location Identity;
2188 Vertex(isec, 1).Location(Identity);
2189 B.UpdateVertex(TopoDS::Vertex(Vertex(isec, 1)),
2191 mySec->VertexTol(isec-1,Vi(1)));
2193 } //end of for (isec=1; isec<=NbLaw+1; isec++)
2195 if (! LastShape.IsNull() && (ILast==myLoc->NbLaw()+1) ) {
2196 mySec->Init(LastShape);
2197 for (isec=1; isec<=NbLaw; isec++) {
2198 E = mySec->CurrentEdge();
2199 if (VEdge(isec, NbPath+1).IsNull())
2200 VEdge(isec, NbPath+1) = E;
2202 if (Vertex(isec+1, NbPath+1).IsNull())
2204 if (VEdge(isec, NbPath+1).Orientation() == TopAbs_REVERSED)
2205 Vertex(isec+1, NbPath+1) = TopExp::FirstVertex(TopoDS::Edge(VEdge(isec, NbPath+1)));
2207 Vertex(isec+1, NbPath+1) = TopExp::LastVertex(TopoDS::Edge(VEdge(isec, NbPath+1)));
2209 UpdateVertex(ILast-1, isec+1, TabErr(isec, NbPath),
2210 Vi(NbPath+1), Vertex(isec+1, NbPath+1));
2213 if (Vertex(1, NbPath+1).IsNull())
2215 if (VEdge(1, NbPath+1).Orientation() == TopAbs_REVERSED)
2216 Vertex(1, NbPath+1) = TopExp::LastVertex(TopoDS::Edge(VEdge(1, NbPath+1)));
2218 Vertex(1, NbPath+1) = TopExp::FirstVertex(TopoDS::Edge(VEdge(1, NbPath+1)));
2220 UpdateVertex(ILast-1, 1,
2221 TabErr(1, NbPath), Vi(NbPath+1), Vertex(1, NbPath+1 ));
2224 for (isec=1; isec<=NbLaw+1; isec++) {
2227 S = TabS(NbLaw, NbPath);
2228 ureverse = UReverse(NbLaw, NbPath);
2229 exuv = ExchUV(NbLaw, NbPath);
2232 S = TabS(isec, NbPath);
2233 ureverse = UReverse(isec, NbPath);
2234 exuv = ExchUV(isec, NbPath);
2236 S->Bounds(UFirst, ULast, VFirst, VLast);
2238 // Choice of parametres
2241 aux = VFirst; VFirst = VLast; VLast = aux;
2244 aux = UFirst; UFirst = ULast; ULast = aux;
2247 if (isec == NbLaw+1) {
2262 // construction of vertex
2263 if (Vertex(isec, NbPath+1).IsNull())
2264 B.MakeVertex(TopoDS::Vertex(Vertex(isec, NbPath+1)),
2266 mySec->VertexTol(isec-1, Vi(NbPath+1)));
2269 TopLoc_Location Identity;
2270 Vertex(isec, NbPath+1).Location(Identity);
2271 B.UpdateVertex(TopoDS::Vertex(Vertex(isec, NbPath+1)),
2273 mySec->VertexTol(isec-1, Vi(NbPath+1)));
2275 } //end of for (isec=1; isec<=NbLaw+1; isec++)
2278 // ---------- Creation of Vertex and edge ------------
2279 ReversedEdges.Clear();
2280 for (ipath=1, IPath=IFirst; ipath<=NbPath;
2282 for (isec=1; isec <=NbLaw; isec++) {
2286 S = TabS(isec, ipath);
2287 exuv = ExchUV(isec, ipath);
2288 S->Bounds(UFirst, ULast, VFirst, VLast);
2289 if (UReverse(isec, ipath)) {
2292 aux = VFirst; VFirst = VLast; VLast = aux;
2295 aux = UFirst; UFirst = ULast; ULast = aux;
2299 // (2.1) Construction of new vertices
2301 if (ipath == 1 && Vertex(1, 1).IsNull()) {
2304 myLoc->PerformVertex(IPath-1,
2305 TopoDS::Vertex(SecVertex(1)),
2307 TopoDS::Vertex(Vertex(1, 1)));
2309 myLoc->PerformVertex(IPath-1,
2310 mySec->Vertex(1,Vi(1)),
2311 mySec->VertexTol(0,Vi(1)),
2312 TopoDS::Vertex(Vertex(1, 1)));
2314 // the first and the next column
2315 if (vclose &&(ipath == NbPath) ) {
2316 Vertex(1, ipath+1) = Vertex(1, 1);
2318 else if (Vertex(1, ipath+1).IsNull()) {
2320 myLoc->PerformVertex(IPath,
2321 TopoDS::Vertex(SecVertex(1)),
2322 TabErr(1,ipath)+VError(1),
2323 TopoDS::Vertex(Vertex(1, ipath+1)) );
2325 myLoc->PerformVertex(IPath,
2326 mySec->Vertex(1,Vi(ipath+1)),
2328 mySec->VertexTol(0,Vi(ipath+1)),
2329 TopoDS::Vertex(Vertex(1, ipath+1)));
2331 if (MergeVertex(Vertex(1,ipath), Vertex(1,ipath+1))) {
2332 UEdge(1, ipath) = NullEdge(Vertex(1,ipath));
2338 if (uclose && (isec == NbLaw)) {
2339 Vertex(isec+1, 1) = Vertex(1, 1);
2341 else if (Vertex(isec+1, 1).IsNull()) {
2343 myLoc->PerformVertex(IPath-1,
2344 TopoDS::Vertex(SecVertex(isec+1)),
2345 TabErr(isec,1)+VError(isec+1),
2346 TopoDS::Vertex(Vertex(isec+1, 1)) );
2348 myLoc->PerformVertex(IPath-1,
2349 mySec->Vertex(isec+1,Vi(1)),
2351 mySec->VertexTol(isec,Vi(1)),
2352 TopoDS::Vertex(Vertex(isec+1, 1)) );
2354 if (MergeVertex(Vertex(isec,1), Vertex(isec+1,1))) {
2355 VEdge(isec, 1) = NullEdge(Vertex(isec, 1));
2360 if (uclose && (isec == NbLaw)) {
2361 Vertex(isec+1, ipath+1) = Vertex(1, ipath+1);
2363 else if (vclose && (ipath == NbPath)) {
2364 Vertex(isec+1, ipath+1) = Vertex(isec+1, 1);
2366 else if (Vertex(isec+1, ipath+1).IsNull()) {
2368 myLoc->PerformVertex(IPath,
2369 TopoDS::Vertex(SecVertex(isec+1)),
2370 TabErr(isec, ipath)+ VError(isec+1),
2371 TopoDS::Vertex(Vertex(isec+1, ipath+1)) );
2373 myLoc->PerformVertex(IPath,
2374 mySec->Vertex(isec+1,Vi(ipath+1)),
2375 TabErr(isec, ipath) +
2376 mySec->VertexTol(isec, Vi(ipath+1)),
2377 TopoDS::Vertex(Vertex(isec+1, ipath+1)) );
2381 singv = MergeVertex(Vertex(isec,ipath+1), Vertex(isec+1,ipath+1));
2382 singu = MergeVertex(Vertex(isec+1,ipath), Vertex(isec+1,ipath+1));
2386 if (singu || singv) {
2387 Degenerated(isec, ipath) = IsDegen(TabS(isec,ipath),
2388 Max(myTol3d, TabErr(isec,ipath)));
2390 if (Degenerated(isec, ipath)) {
2392 cout << "Sweep : Degenerated case" << endl;
2394 hasdegen = Standard_True;
2395 // Particular construction of edges
2396 if (UEdge(isec+1, ipath).IsNull()) {
2399 UEdge(isec+1, ipath) = NullEdge(Vertex(isec+1,ipath));
2401 else { // Copy the previous edge
2402 UEdge(isec+1, ipath) = UEdge(isec, ipath);
2405 if (VEdge(isec, ipath+1).IsNull()) {
2408 VEdge(isec, ipath+1) = NullEdge(Vertex(isec,ipath+1));
2410 else { // Copy the previous edge
2411 VEdge(isec, ipath+1) = VEdge(isec, ipath);
2415 else { // Construction of edges by isos
2418 UV = UFirst; UFirst = VFirst; VFirst = UV;
2419 UV = ULast ; ULast = VLast ; VLast = UV;
2423 if (isec == 1 && UEdge(1, ipath).IsNull()) {
2424 if (!Vertex(1,ipath).IsSame(Vertex(1,ipath+1))) {
2425 gp_Pnt P1 = BRep_Tool::Pnt(TopoDS::Vertex(Vertex(1,ipath)));
2426 gp_Pnt P2 = BRep_Tool::Pnt(TopoDS::Vertex(Vertex(1,ipath+1)));
2427 if (P1.Distance(P2) <= myTol3d)
2428 Vertex(1,ipath+1) = Vertex(1,ipath);
2430 UEdge(1, ipath) = BuildEdge(S, !exuv, UFirst,
2435 else UpdateEdge(TopoDS::Edge(UEdge(isec, ipath)),
2438 if (uclose && (isec==NbLaw)) {
2439 UpdateEdge(TopoDS::Edge(UEdge(1, ipath)),
2441 UEdge(isec+1, ipath) = UEdge(1, ipath);
2444 if (UEdge(isec+1, ipath).IsNull())
2445 UEdge(isec+1, ipath) = BuildEdge(S, !exuv, ULast,
2446 Vertex(isec+1, ipath),
2447 Vertex(isec+1, ipath+1),
2450 UpdateEdge(TopoDS::Edge(UEdge(isec+1, ipath)), S, !exuv, ULast);
2456 TopoDS_Edge aNewFirstEdge = BuildEdge(S, exuv, VFirst,
2460 if (VEdge(isec, ipath).IsNull())
2461 VEdge(isec, ipath) = aNewFirstEdge;
2462 else //rebuild first edge
2463 RebuildTopOrBottomEdge(aNewFirstEdge,
2464 TopoDS::Edge(VEdge(isec, ipath)),
2468 else UpdateEdge(TopoDS::Edge(VEdge(isec, ipath)),
2471 if (vclose && (ipath == NbPath)) {
2472 UpdateEdge(TopoDS::Edge(VEdge(isec, 1)),
2474 VEdge(isec, ipath+1) = VEdge(isec, 1);
2476 else if (VEdge(isec, ipath+1).IsNull())
2477 VEdge(isec, ipath+1) = BuildEdge(S, exuv, VLast,
2478 Vertex(isec , ipath+1),
2479 Vertex(isec+1, ipath+1),
2483 if (ipath != NbPath || vclose)
2484 UpdateEdge(TopoDS::Edge(VEdge(isec, ipath+1)),
2486 else //ipath == NbPath && !vclose => rebuild last edge
2488 TopoDS_Edge aNewLastEdge = BuildEdge(S, exuv, VLast,
2489 Vertex(isec , ipath+1),
2490 Vertex(isec+1, ipath+1),
2492 RebuildTopOrBottomEdge(aNewLastEdge,
2493 TopoDS::Edge(VEdge(isec, ipath+1)),
2498 }// End of construction of edges
2501 // (3) Construction of Faces
2506 for (ipath=1, IPath=IFirst; ipath<=NbPath; ipath++, IPath++) {
2507 for (isec=1; isec <=NbLaw+1; isec++){
2508 sprintf(name,"uedge_%d_%d", isec, IPath);
2509 DBRep::Set(name,UEdge(isec, ipath));
2513 for (ipath=1, IPath=IFirst; ipath<=NbPath+1; ipath++, IPath++) {
2514 for (isec=1; isec <=NbLaw; isec++){
2515 sprintf(name,"vedge_%d_%d", isec, IPath);
2516 DBRep::Set(name,VEdge(isec, ipath));
2519 for (isec=1; isec <=NbLaw+1; isec++){
2520 sprintf(name,"vertex_%d_%d", isec, IPath);
2521 DBRep::Set(name,Vertex(isec, ipath));
2527 for (ipath=1, IPath=IFirst; ipath<=NbPath; ipath++, IPath++) {
2528 for (isec=1; isec <=NbLaw; isec++) {
2529 if (Degenerated(isec, ipath)) {
2530 if (UEdge(isec, ipath).IsSame(UEdge(isec+1, ipath)))
2531 myFaces->SetValue(isec, IPath, UEdge(isec, ipath));
2533 myFaces->SetValue(isec, IPath, VEdge(isec, ipath));
2535 else if (myFaces->Value(isec, IPath).IsNull()) {
2536 BuildFace(TabS(isec,ipath),
2537 TopoDS::Edge(UEdge(isec, ipath)),
2538 TopoDS::Edge(VEdge(isec, ipath)),
2539 TopoDS::Edge(UEdge(isec+1, ipath)),
2540 TopoDS::Edge(VEdge(isec, ipath+1)),
2542 ExchUV(isec, ipath),
2543 UReverse(isec, ipath),
2545 myFaces->SetValue(isec, IPath, face);
2550 // (3.1) Reverse the faces that have been built ealier
2551 for (ipath = 1; ipath <= NbPath; ipath++)
2552 for (isec = 1; isec <= NbLaw; isec++)
2554 myFaces->ChangeValue(isec, ipath).Reverse();
2557 // (4) History and Continuity
2560 //(4.1) // Degenerated case => Sledgehammer
2561 TopoDS_Compound Comp;
2562 B.MakeCompound(Comp);
2563 for (isec=1; isec <= NbLaw+1; isec++)
2564 for (ipath=1, IPath=IFirst; ipath<= NbPath+1; ipath++, IPath++) {
2565 if (ipath <= NbPath) myUEdges->SetValue(isec, IPath, UEdge(isec, ipath));
2566 if (isec <= NbLaw) myVEdges->SetValue(isec, IPath, VEdge(isec, ipath));
2567 if ((ipath <= NbPath) && (isec <= NbLaw) &&
2568 (myFaces->Value(isec, IPath).ShapeType() == TopAbs_FACE))
2569 B.Add(Comp, myFaces->Value(isec, IPath));
2571 BRepLib::EncodeRegularity(Comp, myTolAngular);
2574 //(4.2) // General case => Tweezers
2575 Standard_Boolean isG1;
2579 for (isec=1; isec <= NbLaw+1; isec++) {
2581 (mySec->Continuity(isec-1, myTolAngular) >= GeomAbs_G1);
2582 else isG1 = Standard_False;
2583 for (ipath=1, IPath=IFirst; ipath<= NbPath; ipath++, IPath++) {
2584 myUEdges->SetValue(isec, IPath, UEdge(isec, ipath));
2586 if (isec == NbLaw+1) FF = TopoDS::Face(myFaces->Value(1, IPath));
2587 else FF = TopoDS::Face(myFaces->Value(isec, IPath));
2588 B.Continuity(TopoDS::Edge(myUEdges->Value(isec, IPath)),
2589 TopoDS::Face(myFaces->Value(isec-1, IPath)),
2595 Standard_Integer nbpath = NbPath;
2596 if (vclose) nbpath++; //Another test G1
2597 for (ipath=1, IPath=IFirst; ipath<= NbPath+1; ipath++, IPath++) {
2598 if ((ipath > 1) && (ipath <=nbpath))
2599 isG1 = (myLoc->IsG1(IPath-1, myTol3d, myTolAngular) >= 0);
2600 else isG1 = Standard_False;
2601 for (isec=1; isec <= NbLaw; isec++) {
2602 myVEdges->SetValue(isec, IPath, VEdge(isec, ipath));
2604 if (ipath==NbPath+1) FF = TopoDS::Face(myFaces->Value(isec, 1));
2605 else FF = TopoDS::Face(myFaces->Value(isec, IPath));
2606 E = TopoDS::Edge(myVEdges->Value(isec, IPath));
2607 BRepLib::EncodeRegularity(E, FF,
2608 TopoDS::Face(myFaces->Value(isec, IPath-1)),
2617 if (IFirst == 1 && !Tapes.IsEmpty()) //works only in case of single shell
2619 for (isec = 1; isec <= NbLaw; isec++)
2621 for (j = 1; j <= NbPath+1; j++)
2622 Tapes(StartEdges(isec))->SetValue(1, j, myVEdges->Value(isec, j));
2623 for (j = 1; j <= NbPath; j++)
2624 Tapes(StartEdges(isec))->SetValue(2, j, myUEdges->Value(isec, j));
2625 for (j = 1; j <= NbPath; j++)
2626 Tapes(StartEdges(isec))->SetValue(3, j, myUEdges->Value(isec+1, j));
2627 for (j = 1; j <= NbPath+1; j++)
2628 Tapes(StartEdges(isec))->SetValue(4, j, Vertex(isec, j));
2629 for (j = 1; j <= NbPath+1; j++)
2630 Tapes(StartEdges(isec))->SetValue(5, j, Vertex(isec+1, j));
2631 for (j = 1; j <= NbPath; j++)
2632 Tapes(StartEdges(isec))->SetValue(6, j, myFaces->Value(isec, j));
2636 return Standard_True;
2639 //=======================================================================
2641 //purpose : Construt the result of sweeping
2642 //======================================================================
2643 void BRepFill_Sweep::Build(TopTools_MapOfShape& ReversedEdges,
2644 BRepFill_DataMapOfShapeHArray2OfShape& Tapes,
2645 const BRepFill_TransitionStyle Transition,
2646 const GeomAbs_Shape Continuity,
2647 const GeomFill_ApproxStyle Approx,
2648 const Standard_Integer Degmax,
2649 const Standard_Integer Segmax)
2651 myContinuity = Continuity;
2652 myApproxStyle = Approx;
2656 CorrectApproxParameters();
2659 if (mySec->IsVertex()) isDone = BuildWire(Transition);
2662 Standard_Integer NbTrous = myLoc->NbHoles(myTol3d),
2663 NbPath = myLoc->NbLaw(),
2664 NbLaw = mySec->NbLaw(), ii, jj, NbPart=1;
2665 Standard_Integer ipath, isec;
2667 myUEdges = new (TopTools_HArray2OfShape) (1, NbLaw+1, 1, NbPath);
2668 myVEdges = new (TopTools_HArray2OfShape) (1, NbLaw, 1, NbPath+1);
2669 myFaces = new (TopTools_HArray2OfShape) (1, NbLaw, 1, NbPath);
2670 Handle (TopTools_HArray2OfShape) Bounds =
2671 new (TopTools_HArray2OfShape) (1, NbLaw, 1, 2);
2673 Handle(TColStd_HArray1OfInteger) Trous;
2675 if (NbTrous>0) { // How many sub-parts ?
2676 Trous = new (TColStd_HArray1OfInteger) (1, NbTrous);
2677 myLoc->Holes(Trous->ChangeArray1());
2679 if (Trous->Value(NbTrous) == NbPath+1) NbPart--;
2681 if (NbPart == 1) { // This is done at once
2682 Standard_Real Extend = 0.0;
2683 if (NbTrous==1) Extend = EvalExtrapol(1, Transition);
2684 isDone = BuildShell(Transition,
2690 else { // This is done piece by piece
2691 Standard_Integer IFirst = 1, ILast;
2692 for (ii=1, isDone=Standard_True;
2693 ii<=NbPart && isDone; ii++) {
2694 if (ii > NbTrous) ILast = NbPath+1;
2695 else ILast = Trous->Value(ii);
2696 isDone = BuildShell(Transition,
2700 EvalExtrapol(IFirst, Transition),
2701 EvalExtrapol(ILast, Transition));
2703 Translate(myVEdges, IFirst, Bounds, 2);
2704 PerformCorner(IFirst,
2705 Transition, Bounds);
2708 Translate(myVEdges, IFirst, Bounds, 1);
2711 // Management of looping ends
2712 if ( (NbTrous>0) && (myLoc->IsClosed()) &&
2713 (Trous->Value(NbTrous) == NbPath+1) ) {
2714 Translate(myVEdges, NbPath+1, Bounds, 1);
2715 Translate(myVEdges, 1, Bounds, 2);
2716 PerformCorner(1, Transition, Bounds);
2719 // Construction of the shell
2722 for (ipath=1; ipath<=NbPath; ipath++)
2723 for (isec=1; isec <=NbLaw; isec++) {
2724 const TopoDS_Shape& face = myFaces->Value(isec, ipath);
2725 if (!face.IsNull() &&
2726 (face.ShapeType() == TopAbs_FACE) ) B.Add(shell, face);
2729 TopTools_ListIteratorOfListOfShape It(myAuxShape);
2730 for (; It.More(); It.Next()) {
2731 const TopoDS_Shape& face = It.Value();
2732 if (!face.IsNull() &&
2733 (face.ShapeType() == TopAbs_FACE) ) B.Add(shell, face);
2735 //Set common Uedges to faces
2736 BRepTools_Substitution aSubstitute;
2738 for (ii = 1; ii <= NbLaw; ii++)
2739 for (jj = 1; jj <= NbPath; jj++)
2741 SetCommonEdgeInFace(aSubstitute,
2742 myFaces->Value(ii, jj),
2743 myUEdges->Value(ii, jj));
2744 SetCommonEdgeInFace(aSubstitute,
2745 myFaces->Value(ii, jj),
2746 myUEdges->Value(ii+1, jj));
2748 if (mySec->IsUClosed())
2749 for (jj = 1; jj <= NbPath; jj++)
2750 SetCommonEdgeInFace(aSubstitute,
2751 myFaces->Value( 1, jj ),
2752 myUEdges->Value( NbLaw+1, jj));
2754 TopTools_DataMapIteratorOfDataMapOfShapeShape mapit( myVEdgesModified );
2755 for (; mapit.More(); mapit.Next())
2757 const TopoDS_Edge& OldEdge = TopoDS::Edge(mapit.Key());
2758 const TopoDS_Edge& NewEdge = TopoDS::Edge(mapit.Value());
2759 Substitute( aSubstitute, OldEdge, NewEdge );
2761 aSubstitute.Build( shell );
2762 if (aSubstitute.IsCopied( shell )) {
2763 const TopTools_ListOfShape& listSh = aSubstitute.Copy( shell );
2764 shell = TopoDS::Shell( listSh.First() );
2767 for (ii = myFaces->LowerRow(); ii <= myFaces->UpperRow(); ii++) {
2768 for (jj = myFaces->LowerCol(); jj <= myFaces->UpperCol(); jj++) {
2769 const TopoDS_Shape& aLocalShape = myFaces->Value(ii, jj);
2771 if(!aLocalShape.IsNull() && aSubstitute.IsCopied(aLocalShape)) {
2772 const TopTools_ListOfShape& aList = aSubstitute.Copy(aLocalShape);
2774 if(!aList.IsEmpty())
2775 myFaces->ChangeValue(ii, jj) = aList.First();
2780 for (ii = myVEdges->LowerRow(); ii <= myVEdges->UpperRow(); ii++) {
2781 for (jj = myVEdges->LowerCol(); jj <= myVEdges->UpperCol(); jj++) {
2782 const TopoDS_Shape& aLocalShape = myVEdges->Value(ii, jj);
2784 if(!aLocalShape.IsNull() && aSubstitute.IsCopied(aLocalShape)) {
2785 const TopTools_ListOfShape& aList = aSubstitute.Copy(aLocalShape);
2787 if(!aList.IsEmpty())
2788 myVEdges->ChangeValue(ii, jj) = aList.First();
2793 for (ii = myUEdges->LowerRow(); ii <= myUEdges->UpperRow(); ii++) {
2794 for (jj = myUEdges->LowerCol(); jj <= myUEdges->UpperCol(); jj++) {
2795 const TopoDS_Shape& aLocalShape = myUEdges->Value(ii, jj);
2797 if(!aLocalShape.IsNull() && aSubstitute.IsCopied(aLocalShape)) {
2798 const TopTools_ListOfShape& aList = aSubstitute.Copy(aLocalShape);
2800 if(!aList.IsEmpty())
2801 myUEdges->ChangeValue(ii, jj) = aList.First();
2807 if (myLoc->IsClosed() && mySec->IsUClosed()) {
2809 Standard_Boolean closed = Standard_True;
2810 Standard_Integer iedge;
2811 TopTools_IndexedDataMapOfShapeListOfShape EFmap;
2812 TopExp::MapShapesAndAncestors(shell, TopAbs_EDGE,
2813 TopAbs_FACE, EFmap);
2815 for (iedge = 1; iedge <=EFmap.Extent() && closed; iedge++) {
2816 const TopoDS_Edge& theEdge = TopoDS::Edge(EFmap.FindKey(iedge));
2817 if (BRep_Tool::Degenerated(theEdge)) continue;
2818 closed = ( EFmap(iedge).Extent() > 1);
2820 shell.Closed(closed);
2827 //=======================================================================
2830 //=======================================================================
2831 Standard_Boolean BRepFill_Sweep::IsDone() const
2836 //=======================================================================
2839 //=======================================================================
2840 TopoDS_Shape BRepFill_Sweep::Shape() const
2845 //=======================================================================
2846 //function : ErrorOnSurface
2848 //=======================================================================
2849 Standard_Real BRepFill_Sweep::ErrorOnSurface() const
2854 //=======================================================================
2855 //function : SubShape
2856 //purpose : Faces obtained by sweeping
2857 //=======================================================================
2858 Handle(TopTools_HArray2OfShape) BRepFill_Sweep::SubShape() const
2863 //=======================================================================
2864 //function : InterFaces
2865 //purpose : Edges obtained by sweeping
2866 //=======================================================================
2867 Handle(TopTools_HArray2OfShape) BRepFill_Sweep::InterFaces() const
2872 //=======================================================================
2873 //function : Sections
2874 //purpose : Edges or Face (or compound of 2) Transition between 2 sweepings
2875 //=======================================================================
2876 Handle(TopTools_HArray2OfShape) BRepFill_Sweep::Sections() const
2881 //=======================================================================
2882 //function : PerformCorner
2883 //purpose : Trim and/or loop a corner
2884 //======================================================================
2885 void BRepFill_Sweep::PerformCorner(const Standard_Integer Index,
2886 const BRepFill_TransitionStyle Transition,
2887 const Handle(TopTools_HArray2OfShape)& Bounds)
2890 if (Transition == BRepFill_Modified) return; // Do nothing.
2892 BRepFill_TransitionStyle TheTransition = Transition;
2893 Standard_Boolean isTangent=Standard_False;
2895 Standard_Integer I1, I2, ii; //, jj;
2897 gp_Vec T1, T2, Tang, Sortant;
2899 //Handle(TopTools_HArray1OfShape) TheShape =
2900 //new TopTools_HArray1OfShape( 1, mySec->NbLaw() );
2901 // TopTools_ListIteratorOfListOfShape Iterator;
2908 I1 = myLoc->NbLaw();
2912 // Construct an axis supported by the bissectrice
2913 myLoc->Law(I1)->GetDomain(F, L);
2914 myLoc->Law(I1)->GetCurve()->D1(L, P1, T1);
2917 myLoc->Law(I2)->GetDomain(F, L);
2918 myLoc->Law(I2)->GetCurve()->D1(F, P2, T2);
2921 if (T1.Angle(T2) < myAngMin) {
2922 isTangent = Standard_True;
2925 myLoc->Law(I1)->GetDomain(F, L);
2926 myLoc->Law(I1)->D0(L, M, V);
2928 myLoc->Law(I2)->GetDomain(F, L);
2929 myLoc->Law(I2)->D0(L, M, V);
2932 if (t1.Angle(t2) < myAngMin) {
2934 cout << "BRepFill_Sweep::PerformCorner : This is not a corner !" << endl;
2941 if ((TheTransition == BRepFill_Right)
2942 && (T1.Angle(T2) > myAngMax) ) {
2943 TheTransition = BRepFill_Round;
2946 Tang = T1 + T2; //Average direction
2947 gp_Dir NormalOfBisPlane = Tang;
2950 Sortant -= Tang.Dot(Tang)*Tang;
2953 Sortant = T2-T1; //Direction input
2954 Sortant *= -1; // " " output
2955 Tang -= (Tang.Dot(T2))*T2;
2958 P1.BaryCenter(0.5, P2, 0.5);
2962 gp_Ax2 Axe (P1, N, Dx);
2963 gp_Ax2 AxeOfBisPlane( P1, NormalOfBisPlane );
2965 // Construct 2 intersecting Shells
2966 Handle (TopTools_HArray2OfShape) UEdges =
2967 new TopTools_HArray2OfShape( 1, mySec->NbLaw()+1, 1, myLoc->NbLaw() );
2968 UEdges->ChangeArray2() = myUEdges->Array2();
2970 // modified by NIZHNY-MKK Wed Oct 29 18:31:47 2003.BEGIN
2971 Handle (TopTools_HArray2OfShape) aFaces =
2972 new TopTools_HArray2OfShape(myFaces->LowerRow(), myFaces->UpperRow(), 1, 2);
2973 Translate(myFaces, I1, aFaces, 1);
2974 Translate(myFaces, I2, aFaces, 2);
2976 Handle (TopTools_HArray2OfShape) aUEdges =
2977 new TopTools_HArray2OfShape(myUEdges->LowerRow(), myUEdges->UpperRow(), 1, 2);
2978 Translate(myUEdges, I1, aUEdges, 1);
2979 Translate(myUEdges, I2, aUEdges, 2);
2981 gp_Vec aNormal = T2 + T1;
2982 TopoDS_Face aPlaneF;
2984 if(aNormal.Magnitude() > gp::Resolution()) {
2985 gp_Pln pl(P1, gp_Dir(aNormal));
2986 BRepLib_MakeFace aFMaker(pl);
2988 if(aFMaker.Error() == BRepLib_FaceDone) {
2989 aPlaneF = aFMaker.Face();
2991 aBB.UpdateFace(aPlaneF, Precision::Confusion() * 10.);
2995 BRepFill_TrimShellCorner aTrim(aFaces, AxeOfBisPlane, aPlaneF);
2996 aTrim.AddBounds(Bounds);
2997 aTrim.AddUEdges(aUEdges);
3000 if (aTrim.IsDone()) {
3001 TopTools_ListOfShape listmodif;
3002 Standard_Integer iit = 0;
3004 for(iit = 0; iit < 2; iit++) {
3005 Standard_Integer II = (iit == 0) ? I1 : I2;
3007 for (ii = 1; ii <= mySec->NbLaw(); ii++) {
3008 aTrim.Modified(myFaces->Value(ii, II), listmodif);
3010 if(!listmodif.IsEmpty()) {
3011 myFaces->SetValue(ii, II, listmodif.First());
3015 for (ii = myUEdges->LowerRow(); ii <= myUEdges->UpperRow(); ii++) {
3016 aTrim.Modified(myUEdges->Value(ii, II), listmodif);
3018 if(!listmodif.IsEmpty()) {
3019 myUEdges->SetValue(ii, II, listmodif.First());
3024 else if ((TheTransition == BRepFill_Right) ||
3025 aTrim.HasSection() ) {
3027 cout << "Fail of TrimCorner" << endl;
3029 return; // Nothing is touched
3032 if (mySec->IsUClosed())
3034 myUEdges->SetValue( 1, I1, myUEdges->Value(mySec->NbLaw()+1, I1) );
3035 myUEdges->SetValue( 1, I2, myUEdges->Value(mySec->NbLaw()+1, I2) );
3038 if (TheTransition == BRepFill_Round) {
3040 TopTools_ListOfShape list1, list2;
3041 TopoDS_Edge Bord1, Bord2, BordFirst;
3042 BordFirst.Nullify();
3045 Standard_Boolean HasFilling = Standard_False;
3047 for (ii=1; ii<=mySec->NbLaw(); ii++) {
3048 KeepEdge(myFaces->Value(ii, I1), Bounds->Value(ii, 1), list1);
3049 KeepEdge(myFaces->Value(ii, I2), Bounds->Value(ii, 2), list2);
3050 if (list1.Extent() == list2.Extent()) {
3051 TopTools_ListIteratorOfListOfShape It1(list1);
3052 TopTools_ListIteratorOfListOfShape It2(list2);
3054 for (; It1.More(); It1.Next(), It2.Next()) {
3055 if (HasFilling) { // Transversal choice of constraints
3056 TopoDS_Vertex VF, VL, VC;
3057 TopoDS_Edge E = TopoDS::Edge(It1.Value());
3061 TopExp::Vertices(E, VF, VL);
3062 if (!Bord1.IsNull() &&
3063 TopExp::CommonVertex(E, Bord1, VC)) {
3064 if (VC.IsSame(VF)) E1 = Bord1;
3067 if (!Bord2.IsNull() &&
3068 TopExp::CommonVertex(E, Bord2, VC)) {
3069 if (VC.IsSame(VF)) E1 = Bord2;
3072 if (!BordFirst.IsNull() &&
3073 TopExp::CommonVertex(E, BordFirst, VC)) {
3074 if (VC.IsSame(VF)) E1 = BordFirst;
3075 else E2 = BordFirst;
3082 B = Filling(It1.Value(), myFaces->Value(ii, I1),
3083 It2.Value(), myFaces->Value(ii, I2),
3084 myVEdgesModified, myTol3d, Axe, T1, Bord1, Bord2, FF);
3087 myAuxShape.Append(FF);
3088 myVEdges->ChangeValue(ii, I2) = FF;
3089 HasFilling = Standard_True;
3091 if (ii==1) BordFirst = Bord1;
3095 else cout << "PerformCorner : Unsymmetry of free border" << endl;
3103 Standard_Integer jj;
3105 DBRep::Set("TrimmedShell", TheShape);
3106 for (jj=1; jj <=myFaces->ColLength(); jj++){
3107 sprintf(name,"Tfaces_%d_%d", jj, I1);
3108 DBRep::Set(name, myFaces->Value(jj, I1));
3109 sprintf(name,"Tfaces_%d_%d", jj, I2);
3110 DBRep::Set(name, myFaces->Value(jj, I2));
3117 //=======================================================================
3118 //function : EvalExtrapol
3120 //======================================================================
3121 Standard_Real BRepFill_Sweep::
3122 EvalExtrapol(const Standard_Integer Index,
3123 const BRepFill_TransitionStyle Transition) const
3125 Standard_Real Extrap = 0.0;
3126 if (Transition == BRepFill_Right) {
3127 Standard_Integer I1, I2;
3128 if ((Index == 1) || (Index ==myLoc->NbLaw()+1) ) {
3129 if (!myLoc->IsClosed() || !mySec->IsVClosed()) return Extrap;
3130 I1 = myLoc->NbLaw();
3138 gp_Vec V1, V2, T1, T2;
3140 Standard_Real Xmin, Ymin, Zmin, Xmax, Ymax, Zmax, R, f, l;
3142 myLoc->Law(I1)->GetDomain(f, l);
3143 myLoc->Law(I1)->D0(l, M1, V1);
3144 T1.SetXYZ(M1.Column(3));
3145 myLoc->Law(I2)->GetDomain(f, l);
3146 myLoc->Law(I2)->D0(f, M2, V2);
3147 T2.SetXYZ(M2.Column(3));
3149 Standard_Real alpha = T1.Angle(T2);
3150 if ((alpha > myAngMax) || (alpha < myAngMin)) {
3151 //Angle too great => No "straight" connection
3152 //Angle too small => No connection
3153 return Extrap; // = 0.0
3156 Handle(GeomFill_SectionLaw) Sec;
3157 Sec = mySec->ConcatenedLaw();
3159 //Calculating parameter U
3160 Standard_Real U, Length, SecFirst, SecLen, Lf, Ll;
3161 myLoc->CurvilinearBounds( myLoc->NbLaw(), Lf, Length );
3162 mySec->Law(1)->GetDomain( SecFirst, SecLen );
3164 myLoc->CurvilinearBounds( I1, Lf, Ll );
3165 U = SecFirst + (Ll/Length)*SecLen;
3168 //Box(Sec, 0., box);
3170 box.Get(Xmin, Ymin, Zmin, Xmax, Ymax, Zmax);
3172 R = Max(Max(Abs(Xmin), Abs(Xmax)),Max(Abs(Ymin), Abs(Ymax)));
3174 // modified by NIZHNY-MKK Fri Oct 31 18:57:51 2003
3175 // Standard_Real coef = 1.2;
3176 Standard_Real coef = 2.;
3178 Extrap = Max(Abs(Zmin), Abs(Zmax)) + 100*myTol3d;
3179 Extrap += R*Tan(alpha/2);
3184 //=======================================================================
3185 //function : MergeVertex
3186 //purpose : Make V2 = V1 if V2 is too close to V1
3187 //======================================================================
3188 Standard_Boolean BRepFill_Sweep::MergeVertex(const TopoDS_Shape& V1,
3189 TopoDS_Shape& V2) const
3191 // Class BRep_Tool without fields and without Constructor :
3193 const TopoDS_Vertex& v1 = TopoDS::Vertex(V1);
3194 const TopoDS_Vertex& v2 = TopoDS::Vertex(V2);
3196 // tol = Max(BT.Tolerance(v1), BT.Tolerance(v2));
3197 tol = Max(BRep_Tool::Tolerance(v1), BRep_Tool::Tolerance(v2));
3198 if (tol < myTol3d) tol = myTol3d;
3199 // if (BT.Pnt(v1).Distance(BT.Pnt(v2)) <= tol ){
3200 if (BRep_Tool::Pnt(v1).Distance(BRep_Tool::Pnt(v2)) <= tol ){
3202 return Standard_True;
3204 return Standard_False;
3208 //=======================================================================
3209 //function : UpdateVertex
3210 //purpose : Update the Tolerance of Vertices depending on Laws.
3211 //======================================================================
3212 void BRepFill_Sweep::UpdateVertex(const Standard_Integer ipath,
3213 const Standard_Integer isec,
3214 const Standard_Real ErrApp,
3215 const Standard_Real Param,
3216 TopoDS_Shape& V) const
3218 TopoDS_Vertex vv, TheV;
3219 TheV = TopoDS::Vertex(V);
3220 myLoc->PerformVertex(ipath,
3221 mySec->Vertex(isec, Param),
3222 ErrApp+mySec->VertexTol(isec-1, Param),
3224 // Class BRep_Tool without fields and without Constructor :
3228 P1 = BRep_Tool::Pnt(vv);
3229 // P2 = BT.Pnt(TheV);
3230 P2 = BRep_Tool::Pnt(TheV);
3232 // Standard_Real Tol = BT.Tolerance(vv);
3233 Standard_Real Tol = BRep_Tool::Tolerance(vv);
3234 Tol += P1.Distance(P2);
3236 // if (Tol > BT.Tolerance(TheV)) {
3237 if (Tol > BRep_Tool::Tolerance(TheV)) {
3239 B.UpdateVertex(TheV, Tol);
3243 //=======================================================================
3244 //function : RebuildTopOrBottomEdge
3245 //purpose : Rebuild v-iso edge of top or bottom section
3246 // inserting new 3d and 2d curves taken from swept surfaces
3247 //======================================================================
3248 void BRepFill_Sweep::RebuildTopOrBottomEdge(const TopoDS_Edge& aNewEdge,
3249 TopoDS_Edge& anEdge,
3250 TopTools_MapOfShape& ReversedEdges) const
3252 Standard_Real fpar, lpar;
3253 Handle(Geom_Curve) aNewCurve = BRep_Tool::Curve(aNewEdge, fpar, lpar);
3254 TopLoc_Location Identity;
3256 Standard_Boolean ToReverse = Standard_False;
3257 Standard_Boolean IsDegen = BRep_Tool::Degenerated(aNewEdge);
3259 BRep_Tool::Range(aNewEdge, fpar, lpar);
3262 TopoDS_Vertex V1, V2, NewV1, NewV2;
3263 TopExp::Vertices(anEdge, V1, V2);
3266 TopExp::Vertices(aNewEdge, NewV1, NewV2);
3267 V1.Location(Identity);
3268 if (!V1.IsSame(NewV1))
3270 if (V1.IsSame(NewV2))
3271 ToReverse = Standard_True;
3274 gp_Pnt Pnt1 = BRep_Tool::Pnt(V1);
3275 gp_Pnt NewPnt1 = BRep_Tool::Pnt(NewV1);
3276 Standard_Real TolSum = BRep_Tool::Tolerance(V1) + BRep_Tool::Tolerance(NewV1);
3277 if (!Pnt1.IsEqual(NewPnt1, TolSum))
3278 ToReverse = Standard_True;
3284 Standard_Real OldFirst, OldLast;
3285 Handle(Geom_Curve) OldCurve = BRep_Tool::Curve(anEdge, OldFirst, OldLast);
3286 gp_Vec OldD1, NewD1;
3288 OldCurve->D1(0.5*(OldFirst + OldLast), MidPnt, OldD1);
3289 aNewCurve->D1(0.5*(fpar + lpar), MidPnt, NewD1);
3290 if (OldD1 * NewD1 < 0.)
3291 ToReverse = Standard_True;
3295 anEdge.Location(Identity);
3296 const Handle(BRep_TEdge)& TEdge = *((Handle(BRep_TEdge)*) &anEdge.TShape());
3297 TEdge->Tolerance(BRep_Tool::Tolerance(aNewEdge));
3299 BB.Range(anEdge, fpar, lpar);
3300 BB.UpdateEdge(anEdge, aNewCurve, Precision::Confusion());
3301 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &aNewEdge.TShape());
3302 const BRep_ListOfCurveRepresentation& lcr = TE->Curves();
3303 BRep_ListIteratorOfListOfCurveRepresentation itrep(lcr);
3304 for (; itrep.More(); itrep.Next())
3306 const Handle(BRep_CurveRepresentation)& CurveRep = itrep.Value();
3307 if (CurveRep->IsCurveOnSurface())
3309 const Handle(BRep_GCurve)& GC = *((Handle(BRep_GCurve)*)&CurveRep);
3310 Handle(Geom2d_Curve) aPCurve = GC->PCurve();
3311 Handle(Geom_Surface) aSurf = GC->Surface();
3312 TopLoc_Location aLoc = aNewEdge.Location() * GC->Location();
3313 BB.UpdateEdge(anEdge, aPCurve, aSurf, aLoc, Precision::Confusion());
3317 anEdge.Free(Standard_True);
3318 TopoDS_Vertex V1, V2;
3319 TopExp::Vertices(anEdge, V1, V2);
3321 TopoDS_Shape anEdgeFORWARD = anEdge.Oriented(TopAbs_FORWARD);
3323 BB.Remove(anEdgeFORWARD, V1);
3324 BB.Remove(anEdgeFORWARD, V2);
3326 V1.Location(Identity);
3327 V2.Location(Identity);
3330 V2.Orientation(TopAbs_FORWARD);
3331 V1.Orientation(TopAbs_REVERSED);
3333 BB.Add(anEdgeFORWARD, V1);
3334 BB.Add(anEdgeFORWARD, V2);
3339 ReversedEdges.Add(anEdge);
3342 BB.Degenerated(anEdge, IsDegen);