0022312: Translation of french commentaries in OCCT files
[occt.git] / src / BRepFill / BRepFill_Generator.cxx
1 // File:        BRepFill_Generator.cxx
2 // Created:     Mon Mar  7 10:01:42 1994
3 // Author:      Bruno DUMORTIER
4 //              <dub@fuegox>
5
6 #include <BRepFill_Generator.ixx>
7
8 #include <TopoDS_Face.hxx>
9 #include <TopoDS_Wire.hxx>
10 #include <TopoDS_Edge.hxx>
11 #include <TopoDS_Vertex.hxx>
12 #include <BRep_Builder.hxx>
13 #include <TopLoc_Location.hxx>
14 #include <TopExp_Explorer.hxx>
15 #include <gp_Pnt2d.hxx>
16 #include <gp_Dir2d.hxx>
17 #include <gp_Ax1.hxx>
18 #include <gp_Ax3.hxx>
19 #include <gp_Circ.hxx>
20 #include <gp_Lin.hxx>
21 #include <GeomAbs_Shape.hxx>
22 #include <GeomAdaptor_Curve.hxx>
23 #include <Geom_Circle.hxx>
24 #include <Geom_Line.hxx>
25 #include <Geom_Curve.hxx>
26 #include <Geom_BezierCurve.hxx>
27 #include <Geom_TrimmedCurve.hxx>
28 #include <Geom_Surface.hxx>
29 #include <Geom_Plane.hxx>
30 #include <Geom_CylindricalSurface.hxx>
31 #include <Geom_ConicalSurface.hxx>
32 #include <Geom_RectangularTrimmedSurface.hxx>
33 #include <Geom2d_Line.hxx>
34 #include <Geom2d_BezierCurve.hxx>
35 #include <GeomFill_Generator.hxx>
36
37 #include <TopTools_DataMapOfShapeShape.hxx>
38 #include <GeomFill.hxx>
39 #include <BRep_Tool.hxx>
40 #include <TopoDS.hxx>
41 #include <TopExp.hxx>
42 #include <Precision.hxx>
43 #include <BRepLib.hxx>
44
45 #include <TColgp_Array1OfPnt.hxx> 
46 #include <TColgp_Array1OfPnt2d.hxx> 
47 #include <Geom_BSplineCurve.hxx> 
48 #include <gp_Vec.hxx>
49 #include <GeomConvert.hxx>
50
51 #include <BRepTools_WireExplorer.hxx>
52 #include <BRepTools.hxx>
53
54
55
56 //=======================================================================
57 //function : DetectKPart
58 //purpose  : 
59 //=======================================================================
60
61 Standard_Integer DetectKPart(const TopoDS_Edge& Edge1,
62                              const TopoDS_Edge& Edge2)
63 {
64   // initializations
65   Standard_Integer IType = 0;
66
67   // characteristics of the first edge
68   Standard_Real first1, last1, first2, last2, ff, ll;
69   TopLoc_Location loc;
70   TopoDS_Vertex V1, V2;
71   Handle(Geom_Curve) curv1, curv;
72   GeomAdaptor_Curve AdC1;
73   Standard_Boolean degen1 = BRep_Tool::Degenerated(Edge1);
74
75   // find the particular case
76   gp_Pnt pos1, pos;
77   Standard_Real  dist;
78 #ifndef DEB
79   Standard_Real dist1 =0.;
80 #else
81   Standard_Real dist1;
82 #endif
83   gp_Ax1 axe1, axe;
84
85   if (degen1) {
86     IType = -2;
87     TopExp::Vertices(Edge1,V1,V2);
88     pos1 = BRep_Tool::Pnt(V1);
89   }
90   else {
91     curv1 = BRep_Tool::Curve(Edge1, loc, first1, last1);
92     curv1 = 
93       Handle(Geom_Curve)::DownCast(curv1->Transformed(loc.Transformation()));
94     ff = first1;
95     ll = last1;
96     if (Edge1.Orientation() == TopAbs_REVERSED) {
97       curv1->Reverse();
98       first1 = curv1->ReversedParameter(ll);
99       last1 = curv1->ReversedParameter(ff);
100     }
101     AdC1.Load(curv1);
102     if (AdC1.GetType() == GeomAbs_Circle) {
103       // first circular section 
104       IType = 1;
105       pos1 = AdC1.Circle().Location();
106       dist1 = AdC1.Circle().Radius();
107       axe1 = AdC1.Circle().Axis();
108     }
109     else if (AdC1.GetType() == GeomAbs_Line) {
110       // first straight line section 
111       IType = 4;
112       pos1 = AdC1.Line().Location();
113       dist1 = AdC1.Value(first1).Distance(AdC1.Value(last1));
114       gp_Vec vec(AdC1.Value(first1),AdC1.Value(last1));
115       gp_Dir dir(vec);
116       axe1 = gp_Ax1(AdC1.Value(first1),dir);
117     }
118     else {
119       // first section of any type
120       IType = 0;
121     }
122   }
123
124   if (IType!=0) {
125
126     Standard_Boolean degen2 = BRep_Tool::Degenerated(Edge2);
127     if (degen2) {
128       TopExp::Vertices(Edge2,V1,V2);
129       pos = BRep_Tool::Pnt(V1);
130       if (IType==1) {
131         // the only particular case with degenerated edge at end : the cone
132         if (pos.IsEqual(pos1,Precision::Confusion())) {
133           // the top is mixed with the center of the circle
134           IType = 0;
135         }
136         else {
137           gp_Vec vec(pos1,pos);
138           gp_Dir dir(vec);
139           axe = gp_Ax1(pos1,dir);
140           if (axe.IsParallel(axe1,Precision::Angular())) {
141             // the top is on the axis of the circle
142             IType = 2;
143           }
144           else {
145             // incorrect top --> no particular case
146             IType = 0;
147           }
148         }
149       }
150       else if (IType != 4) { //not a plane
151         // no particular case
152         IType = 0;
153       }
154     }
155     else {
156       curv = BRep_Tool::Curve(Edge2, loc, first2, last2);
157       curv = 
158         Handle(Geom_Curve)::DownCast(curv->Transformed(loc.Transformation()));
159       ff = first2;
160       ll = last2;
161       if (Edge2.Orientation() == TopAbs_REVERSED) {
162         curv->Reverse();
163         first2 = curv->ReversedParameter(ll);
164         last2 = curv->ReversedParameter(ff);
165       }
166       GeomAdaptor_Curve AdC(curv);
167     
168       if (IType>0 && IType<4) {
169         if (AdC.GetType() != GeomAbs_Circle) {
170           // section not circular --> no particular case
171           IType = 0;
172         }
173         else {
174           if (AdC.Circle().Axis()
175               .IsCoaxial(axe1,Precision::Angular(),Precision::Confusion())) {
176             // same axis
177             if (Abs(AdC.Circle().Radius()-dist1)< Precision::Confusion()) {
178               // possibility of cylinder or a piece of cylinder
179               Standard_Real h1 = Abs(last1-first1), h2 = Abs(last2-first2);
180               Standard_Boolean Same, 
181                SameParametricLength = ( Abs(h1-h2) < Precision::PConfusion() );
182               Standard_Real m1=(first1+last1)/2., m2=(first2+last2)/2.;
183               gp_Pnt P1,P2;
184               gp_Vec DU;
185               AdC1.D1(m1,P1,DU);
186               AdC.D0(m2,P2);
187               Same = SameParametricLength 
188                 && ( gp_Vec(P1,P2).IsNormal(DU,Precision::Angular()) ) ;
189               if (Same) {
190                 // cylinder or piece of cylinder
191                 IType = 1;
192               }
193               else {
194                 // the interval of definition is not correct
195                 IType = 0;
196               }
197             }
198             else {
199               // possibility of cone truncation
200               Standard_Real h1 = Abs(last1-first1), h2 = Abs(last2-first2);
201               Standard_Boolean Same, 
202                SameParametricLength = ( Abs(h1-h2) < Precision::PConfusion() );
203               Standard_Real m1=(first1+last1)/2., m2=(first2+last2)/2.;
204               gp_Pnt P1,P2;
205               gp_Vec DU;
206               AdC1.D1(m1,P1,DU);
207               AdC.D0(m2,P2);
208               Same = SameParametricLength 
209                 && ( gp_Vec(P1,P2).IsNormal(DU,Precision::Angular()) ) ;
210               if (Same) {
211                 // truncation of cone
212                 IType = 2;
213               }
214               else {
215                 // the interval of definition is not correct
216                 IType = 0;
217               }
218             }
219             if (AdC.Circle().Location().IsEqual(pos1,Precision::Confusion())) {
220               // the centers are mixed
221               IType = 0;
222             }
223           }
224           else {
225             // different axis
226             if (AdC.Circle().Radius()==dist1) {
227               // torus ?
228               IType = 3;
229             }
230             else {
231               // different radius --> no particular case
232               IType = 0;
233             }
234           }
235         }
236       }
237       else if (IType>=4) {
238         if (AdC.GetType() != GeomAbs_Line) {
239           // not a straight line section --> no particular case
240           IType = 0;
241         }
242         else {
243           pos = AdC.Line().Location();
244           dist = AdC.Value(first2).Distance(AdC.Value(last2));
245           gp_Vec vec(AdC.Value(first2),AdC.Value(last2));
246           gp_Dir dir(vec);
247           axe = gp_Ax1(AdC.Value(first2),dir);
248           if (axe.IsParallel(axe1,Precision::Angular())) {
249             // parallel straight line
250             if (Abs(dist-dist1)<Precision::Confusion()) {
251               gp_Dir dir(gp_Vec(AdC1.Value(first1),AdC.Value(first2)));
252               if (dir.IsNormal(gp_Dir(vec),Precision::Angular())) {
253                 // plane
254                 IType = 4;
255               }
256               else {
257                 // extrusion ?
258                 IType = 5;
259               }
260             }
261             else {
262               // different length --> no particular case
263               IType = 0;
264             }
265           }
266           else {
267             // not parallel straight line --> no particular case
268             IType = 0;
269           }
270         }
271       }
272       else if (IType==-2) {
273         if (AdC.GetType() == GeomAbs_Line)
274           IType = 4; //plane
275         else if (AdC.GetType() == GeomAbs_Circle)
276           {
277             // the only particular case with degenerated edge at the beginning the cone
278             pos = AdC.Circle().Location();
279             axe = AdC.Circle().Axis();
280             if (pos1.IsEqual(pos,Precision::Confusion())) {
281               // the top is mixed with the center of the circle
282               IType = 0;
283             }
284             else {
285               gp_Vec vec(pos1,pos);
286               gp_Dir dir(vec);
287               axe1 = gp_Ax1(pos1,dir);
288               if (axe.IsParallel(axe1,Precision::Angular())) {
289                 // the top is on the axis of the circle
290                 IType = -2;
291               }
292               else {
293                 // incorrect top --> no particular case
294                 IType = 0;
295               }
296             }
297           }
298         else
299           IType = 0;
300       }
301     }
302     
303   }
304   // torus and extrusion are not particular cases.
305   if (IType == 3 || IType == 5) IType = 0;
306   return IType;
307 }
308
309
310 //=======================================================================
311 //function : CreateKPart
312 //purpose  : 
313 //=======================================================================
314
315 void CreateKPart(const TopoDS_Edge& Edge1,const TopoDS_Edge& Edge2,
316                  const Standard_Integer IType, 
317                  Handle(Geom_Surface)& Surf)
318 {
319   // find the dimension
320   TopoDS_Vertex V1, V2;
321
322   TopLoc_Location loc;
323   Standard_Real a1, b1, aa =0., bb =0.;
324   TopoDS_Vertex v1f,v1l,v2f,v2l;
325
326   // find characteristics of the first edge
327   Handle(Geom_Curve) C1;
328   Standard_Boolean degen1 = BRep_Tool::Degenerated(Edge1);
329   if(degen1) {
330     // cone with degenerated edge at the top
331     TopExp::Vertices(Edge1,v1f,v1l);
332   }
333   else {
334     C1 = BRep_Tool::Curve(Edge1, loc, a1, b1);
335     C1 = Handle(Geom_Curve)::DownCast(C1->Transformed(loc.Transformation()));
336     aa = a1;
337     bb = b1;
338     if (Edge1.Orientation() == TopAbs_REVERSED) {
339       C1->Reverse();
340       aa = C1->ReversedParameter(b1);
341       bb = C1->ReversedParameter(a1);
342       TopExp::Vertices(Edge1,v1l,v1f);
343     }
344     else {
345       TopExp::Vertices(Edge1,v1f,v1l);
346     }
347   }
348
349   // find characteristics of the second edge
350   Handle(Geom_Curve) C2;
351   Standard_Boolean degen2 = BRep_Tool::Degenerated(Edge2);
352   if(degen2) {
353     // cone with degenerated edge at the top
354     TopExp::Vertices(Edge2,v2f,v2l);
355   }
356   else {
357     C2 = BRep_Tool::Curve(Edge2, loc, a1, b1);
358     C2 = Handle(Geom_Curve)::DownCast(C2->Transformed(loc.Transformation()));
359     if (Edge2.Orientation() == TopAbs_REVERSED) {
360       C2->Reverse();
361       if (degen1) {
362         aa = a1;
363         bb = b1;
364       }
365       TopExp::Vertices(Edge2,v2l,v2f);
366     }
367     else {
368       if (degen1) {
369         aa = a1; //C2->ReversedParameter(b1);
370         bb = b1; //C2->ReversedParameter(a1);
371       }
372       TopExp::Vertices(Edge2,v2f,v2l);
373     }
374   }
375
376   // create the new surface
377   TopoDS_Shell shell;
378   TopoDS_Face face;
379   TopoDS_Wire W;
380   TopoDS_Edge edge1, edge2, edge3, edge4, couture;
381
382   BRep_Builder B;
383   B.MakeShell(shell);
384
385   TopoDS_Wire newW1, newW2;
386   BRep_Builder BW1, BW2;
387   BW1.MakeWire(newW1);
388   BW2.MakeWire(newW2);
389
390
391   // calculate the surface
392   Handle(Geom_Surface) surface;
393   Standard_Real V, Rad;
394   if (IType==1) {
395     // cylindrical surface
396     gp_Circ c1 = (Handle(Geom_Circle)::DownCast(C1))->Circ();
397     gp_Circ c2 = (Handle(Geom_Circle)::DownCast(C2))->Circ();
398     gp_Ax3 Ac1 = c1.Position();
399     V = gp_Vec( c1.Location(),c2.Location()).Dot(gp_Vec(Ac1.Direction()));
400     if ( V < 0.) {
401       Ac1.ZReverse();
402       V = -V;
403     }
404     Handle(Geom_CylindricalSurface) Cyl = 
405       new Geom_CylindricalSurface( Ac1, c1.Radius());
406     surface = new Geom_RectangularTrimmedSurface
407       ( Cyl, aa, bb, Min(0.,V), Max(0.,V) );
408   }
409   else if (IType==2) {
410     // conical surface
411     gp_Circ k1 = (Handle(Geom_Circle)::DownCast(C1))->Circ();
412     gp_Ax3 Ak1 = k1.Position();
413     if (degen2) {
414       V = gp_Vec( k1.Location(),BRep_Tool::Pnt(v2f))
415         .Dot(gp_Vec(Ak1.Direction()));
416       Rad = - k1.Radius();
417     }
418     else {
419       gp_Circ k2 = (Handle(Geom_Circle)::DownCast(C2))->Circ();
420       V = gp_Vec( k1.Location(),k2.Location()).Dot(gp_Vec(Ak1.Direction()));
421       Rad = k2.Radius() - k1.Radius();
422     }
423       
424     if ( V < 0.) {
425       Ak1.ZReverse();
426       V = -V;
427     }
428     Standard_Real Ang = ATan( Rad / V);
429     Handle(Geom_ConicalSurface) Cone = 
430       new Geom_ConicalSurface( Ak1, Ang, k1.Radius());
431     V /= Cos(Ang);
432     surface = new Geom_RectangularTrimmedSurface
433       ( Cone, aa, bb, Min(0.,V), Max(0.,V) );
434   }
435   else if (IType==-2) {
436     // conical surface with the top at the beginning (degen1 is true)
437     gp_Circ k2 = (Handle(Geom_Circle)::DownCast(C2))->Circ();
438     gp_Ax3 Ak2 = k2.Position();
439     Ak2.SetLocation(BRep_Tool::Pnt(v1f));
440     V = gp_Vec(BRep_Tool::Pnt(v1f),k2.Location())
441                                 .Dot(gp_Vec(Ak2.Direction()));
442     Rad = k2.Radius(); // - k2.Radius();      
443     if ( V < 0.) {
444       Ak2.ZReverse();
445       V = -V;
446     }
447     Standard_Real Ang = ATan( Rad / V);
448     Handle(Geom_ConicalSurface) Cone = 
449       new Geom_ConicalSurface( Ak2, Ang, 0.);
450     V /= Cos(Ang);
451     surface = new Geom_RectangularTrimmedSurface
452       ( Cone, aa, bb, Min(0.,V), Max(0.,V) );
453   }
454   else if (IType==3) {
455     // torus surface ?
456   }
457   else if (IType==4) {
458     // surface plane
459     gp_Lin L1, L2, aLine;
460     if (!degen1)
461       {
462         L1 = (Handle(Geom_Line)::DownCast(C1))->Lin();
463         aLine = L1;
464       }
465     if (!degen2)
466       {
467         L2 = (Handle(Geom_Line)::DownCast(C2))->Lin();
468         aLine = L2;
469       }
470
471     gp_Pnt P1 = (degen1)? BRep_Tool::Pnt(v1f) : L1.Location();
472     gp_Pnt P2 = (degen2)? BRep_Tool::Pnt(v2f) : L2.Location();
473
474     gp_Vec P1P2( P1, P2 ); 
475     gp_Dir D1 = aLine.Direction();
476     gp_Ax3 Ax( aLine.Location(), gp_Dir(D1.Crossed(P1P2)), D1 );
477     Handle(Geom_Plane) Plan = new Geom_Plane(Ax);
478     V = P1P2.Dot( Ax.YDirection());
479     surface = Plan;
480     //surface = new Geom_RectangularTrimmedSurface
481       //( Plan, aa, bb, Min(0.,V), Max(0.,V) );
482   }
483   else if (IType==5) {
484     // surface of extrusion ?
485   }
486   else {
487     // IType incorrect
488   }
489   Surf = surface;
490 }
491
492
493 //=======================================================================
494 //function : BRepFill_Generator
495 //purpose  : 
496 //=======================================================================
497
498 BRepFill_Generator::BRepFill_Generator()
499 {
500 }
501
502
503 //=======================================================================
504 //function : AddWire
505 //purpose  : 
506 //=======================================================================
507
508 void BRepFill_Generator::AddWire(const TopoDS_Wire& Wire)
509 {
510   myWires.Append( Wire);
511 }
512
513
514 //=======================================================================
515 //function : Perform
516 //purpose  : 
517 //=======================================================================
518
519 void BRepFill_Generator::Perform()
520 {
521   TopoDS_Shell Shell;
522   TopoDS_Face  Face;
523   TopoDS_Shape S1, S2;
524   TopoDS_Edge  Edge1, Edge2, Edge3, Edge4, Couture;
525
526   BRep_Builder B;
527   B.MakeShell(myShell);
528
529   Standard_Integer Nb = myWires.Length();
530
531   BRepTools_WireExplorer ex1,ex2;
532
533   Standard_Boolean wPoint1, wPoint2, uClosed, DegenFirst, DegenLast;
534   
535   for ( Standard_Integer i = 1; i <= Nb-1; i++) {
536
537     TopoDS_Wire Wire1 = TopoDS::Wire(myWires( i ));
538     TopoDS_Wire Wire2 = TopoDS::Wire(myWires(i+1));
539
540     wPoint1 = Standard_False;
541     if (i==1) {
542       wPoint1 = Standard_True;
543       for(ex1.Init(Wire1); ex1.More(); ex1.Next()) {
544         wPoint1 = wPoint1 && (BRep_Tool::Degenerated(ex1.Current()));
545       }
546       DegenFirst = wPoint1;
547
548       TopoDS_Vertex V1, V2;
549       TopExp::Vertices(Wire1, V1, V2);
550       uClosed = V1.IsSame(V2);
551     }
552
553     wPoint2 = Standard_False;
554     if (i==Nb-1) {
555       wPoint2 = Standard_True;
556       for(ex2.Init(Wire2); ex2.More(); ex2.Next()) {
557         wPoint2 = wPoint2 && (BRep_Tool::Degenerated(ex2.Current()));
558       }
559       DegenLast = wPoint2;
560     }
561
562     ex1.Init(Wire1);
563     ex2.Init(Wire2);
564
565     TopTools_DataMapOfShapeShape Map;
566     
567     Standard_Boolean tantque = ex1.More() && ex2.More();
568
569     while ( tantque ) { 
570
571       TopoDS_Vertex V1f,V1l,V2f,V2l, Vf_toMap, Vl_toMap;
572
573       Standard_Boolean degen1 
574         = BRep_Tool::Degenerated(TopoDS::Edge(ex1.Current()));
575       Standard_Boolean degen2
576         = BRep_Tool::Degenerated(TopoDS::Edge(ex2.Current()));
577
578       if ( degen1 ) {
579         TopoDS_Shape aLocalShape = ex1.Current().EmptyCopied();
580         Edge1 = TopoDS::Edge(aLocalShape);
581 //      Edge1 = TopoDS::Edge(ex1.Current().EmptyCopied());
582 //      aLocalShape = ex1.Current();
583 //      TopExp::Vertices(TopoDS::Edge(aLocalShape),V1f,V1l);
584         TopExp::Vertices(TopoDS::Edge(ex1.Current()),V1f,V1l);
585         V1f.Orientation(TopAbs_FORWARD);
586         B.Add(Edge1,V1f);
587         V1l.Orientation(TopAbs_REVERSED);
588         B.Add(Edge1,V1l);
589         B.Range(Edge1,0,1);
590       }
591       else {
592         TopoDS_Shape aLocalShape = ex1.Current();
593         Edge1 = TopoDS::Edge(aLocalShape);
594 //      Edge1 = TopoDS::Edge(ex1.Current());
595       }
596
597       if ( degen2 ) {
598         TopoDS_Shape aLocalShape = ex2.Current().EmptyCopied();
599         Edge2 = TopoDS::Edge(aLocalShape);
600 //      Edge2 = TopoDS::Edge(ex2.Current().EmptyCopied());
601         TopExp::Vertices(TopoDS::Edge(ex2.Current()),V2f,V2l);
602         V2f.Orientation(TopAbs_FORWARD);
603         B.Add(Edge2,V2f);
604         V2l.Orientation(TopAbs_REVERSED);
605         B.Add(Edge2,V2l);
606         B.Range(Edge2,0,1);
607       }
608       else {
609         Edge2 = TopoDS::Edge(ex2.Current());
610       }
611
612       Standard_Boolean Periodic
613         = (Edge1.Closed() || degen1) && (Edge2.Closed() || degen2);
614       // ATTENTION : a non-punctual wire should not 
615       //             contain a punctual edge
616       if (!wPoint1) ex1.Next();
617       if (!wPoint2) ex2.Next();
618
619       // initialization of vertices
620       Handle(Geom_Surface) Surf;
621       Standard_Real f1=0, l1=1, f2=0, l2=1;
622       if (Edge1.Orientation() == TopAbs_REVERSED)
623         TopExp::Vertices(Edge1,V1l,V1f);
624       else
625         TopExp::Vertices(Edge1,V1f,V1l);
626       if (Edge2.Orientation() == TopAbs_REVERSED)
627         TopExp::Vertices(Edge2,V2l,V2f);
628       else
629         TopExp::Vertices(Edge2,V2f,V2l);
630       if (degen1)
631         {
632           Vf_toMap = V2f;
633           Vl_toMap = V2l;
634         }
635       else
636         {
637           Vf_toMap = V1f;
638           Vl_toMap = V1l;
639         }
640       
641       if(Periodic) {
642         Standard_Boolean E1IsReallyClosed = BRepTools::Compare(V1f,V1l);
643         Standard_Boolean E2IsReallyClosed = BRepTools::Compare(V2f,V2l);
644         Periodic 
645           = (E1IsReallyClosed || degen1) && (E2IsReallyClosed || degen2);
646       }
647       // processing of KPart
648       Standard_Integer IType = DetectKPart(Edge1,Edge2);
649       if (IType==0) {
650         // no part cases
651         TopLoc_Location L,L1,L2;
652
653         Handle(Geom_Curve) C1, C2;
654         TColgp_Array1OfPnt Extremities(1,2);
655       
656         if (degen1) {
657           Extremities(1) = BRep_Tool::Pnt(V1f);
658           Extremities(2) = BRep_Tool::Pnt(V1l);
659           C1 = new Geom_BezierCurve(Extremities);
660         }
661         else {
662           C1 = BRep_Tool::Curve(Edge1,L1,f1,l1);
663         }
664         if (degen2) {
665           Extremities(1) = BRep_Tool::Pnt(V2l);
666           Extremities(2) = BRep_Tool::Pnt(V2f);
667           C2 = new Geom_BezierCurve(Extremities);
668         }
669         else {
670           C2 = BRep_Tool::Curve(Edge2,L2,f2,l2);
671         }
672         
673         // compute the location
674         Standard_Boolean SameLoc = Standard_False;
675         
676         // transform and trim the curves
677       
678         if (Abs(f1 - C1->FirstParameter()) > Precision::PConfusion() ||
679             Abs(l1 - C1->LastParameter())  > Precision::PConfusion()   ) {
680           C1 = new Geom_TrimmedCurve(C1,f1,l1);
681         }
682         else {
683           C1 = Handle(Geom_Curve)::DownCast(C1->Copy());
684         }
685         if (!SameLoc) C1->Transform(L1.Transformation());
686         if (Edge1.Orientation() == TopAbs_REVERSED) {
687           C1->Reverse();
688         }
689         
690         if (Abs(f2 - C2->FirstParameter()) > Precision::PConfusion() ||
691             Abs(l2 - C2->LastParameter())  > Precision::PConfusion()   ) {
692           C2 = new Geom_TrimmedCurve(C2,f2,l2);
693         }
694         else {
695           C2 = Handle(Geom_Curve)::DownCast(C2->Copy());
696         }
697         if (!SameLoc) C2->Transform(L2.Transformation());
698         if (Edge2.Orientation() == TopAbs_REVERSED) {
699           C2->Reverse();
700         }
701         
702         GeomFill_Generator Generator;
703         Generator.AddCurve( C1);
704         Generator.AddCurve( C2);
705         Generator.Perform( Precision::PConfusion());
706         
707         Surf = Generator.Surface();
708         B.MakeFace(Face,Surf,Precision::Confusion());
709       }
710       else {
711         // particular case
712         CreateKPart(Edge1,Edge2,IType,Surf);
713         B.MakeFace(Face,Surf,Precision::Confusion());
714       }
715       
716       // make the missing edges
717       Standard_Real first,last;
718       Surf->Bounds(f1,l1,f2,l2);
719
720       if ( Map.IsBound(Vf_toMap)) {
721         TopoDS_Shape aLocalShape = Map(Vf_toMap).Reversed();
722         Edge3 = TopoDS::Edge(aLocalShape);
723 //      Edge3 = TopoDS::Edge(Map(V1f).Reversed());
724       }
725       else {
726         Handle(Geom_Curve) CC;
727         TColgp_Array1OfPnt Extremities(1,2);
728         if (IType==0) {
729           // general case : Edge3 corresponds to iso U=f1
730           CC = Surf->UIso(f1);
731           first=f2;
732           last=l2;
733         }
734         else {
735           // particular case : it is required to calculate the curve 3d
736           Extremities(1) = BRep_Tool::Pnt(V1f);
737           Extremities(2) = BRep_Tool::Pnt(V2f);
738           CC = new Geom_BezierCurve(Extremities);
739           first=0.;
740           last=1.;
741         }
742         B.MakeEdge(Edge3,CC,Precision::Confusion());
743         V1f.Orientation(TopAbs_FORWARD);
744         B.Add(Edge3,V1f);
745         V2f.Orientation(TopAbs_REVERSED);
746         B.Add(Edge3,V2f);
747         B.Range(Edge3,first,last);
748         Edge3.Reverse();
749         Map.Bind(Vf_toMap, Edge3);
750       }
751
752       Standard_Boolean CommonEdge = Standard_False;
753       if ( Map.IsBound(Vl_toMap)  ) {
754         TopoDS_Shape aLocalShape = Map(Vl_toMap).Reversed();
755         const TopoDS_Edge CommonE = TopoDS::Edge(aLocalShape);
756 //      const TopoDS_Edge CommonE = TopoDS::Edge(Map(V1l).Reversed());
757         TopoDS_Vertex V1, V2;
758         TopExp::Vertices(CommonE,V1,V2);
759         CommonEdge = V1.IsSame(V1l) && V2.IsSame(V2l);
760       }
761       if ( CommonEdge ) {
762         TopoDS_Shape aLocalShape = Map(Vl_toMap).Reversed();
763         Edge4 = TopoDS::Edge(aLocalShape);
764 //      Edge4 = TopoDS::Edge(Map(V1l).Reversed());
765       }
766       else {
767         Handle(Geom_Curve) CC;
768         TColgp_Array1OfPnt Extremities(1,2);
769         if (IType==0) {
770           // general case : Edge4 corresponds to iso U=l1
771           CC = Surf->UIso(l1);
772           first=f2;
773           last=l2;
774         }
775         else {
776           // particular case : it is required to calculate the curve 3d
777           Extremities(1) = BRep_Tool::Pnt(V1l);
778           Extremities(2) = BRep_Tool::Pnt(V2l);
779           CC = new Geom_BezierCurve(Extremities);
780           first=0.;
781           last=1.;
782         }
783         B.MakeEdge(Edge4,CC,Precision::Confusion());
784         V1l.Orientation(TopAbs_FORWARD);
785         B.Add(Edge4,V1l);
786         V2l.Orientation(TopAbs_REVERSED);
787         B.Add(Edge4,V2l);
788         B.Range(Edge4,first,last);
789         Map.Bind(Vl_toMap, Edge4);
790       }
791
792       // make the wire
793       
794       TopoDS_Wire W;
795       B.MakeWire(W);
796       
797       if (! (degen1 && IType == 4))
798         B.Add(W,Edge1);
799       B.Add(W,Edge4);
800       if (! (degen2 && IType == 4))
801         B.Add(W,Edge2.Reversed());
802       B.Add(W,Edge3);
803       
804       B.Add(Face,W);
805       
806       B.Add(myShell,Face);
807
808     // complete myMap for edge1
809       if (! (degen1 && IType == 4))
810         {
811           TopTools_ListOfShape Empty;
812           if (!myMap.IsBound(Edge1)) myMap.Bind(Edge1,Empty);
813           myMap(Edge1).Append(Face);
814         }
815       
816       // set the pcurves
817       
818       Standard_Real T = Precision::Confusion();
819
820       if (IType != 4) //not plane
821         {
822           if ( Edge1.Orientation() == TopAbs_REVERSED ) {
823             B.UpdateEdge(Edge1,
824                          new Geom2d_Line(gp_Pnt2d(0,f2),gp_Dir2d(-1,0)),
825                          Face,T);
826             B.Range(Edge1,Face,-l1,-f1);
827           }
828           else {
829             B.UpdateEdge(Edge1,
830                          new Geom2d_Line(gp_Pnt2d(0,f2),gp_Dir2d(1,0)),
831                          Face,T);
832             B.Range(Edge1,Face,f1,l1);
833           }
834           
835           if ( Edge2.Orientation() == TopAbs_REVERSED ) {
836             B.UpdateEdge(Edge2,
837                          new Geom2d_Line(gp_Pnt2d(0,l2),gp_Dir2d(-1,0)),
838                          Face,T);
839             B.Range(Edge2,Face,-l1,-f1);
840           }
841           else {
842             B.UpdateEdge(Edge2,
843                          new Geom2d_Line(gp_Pnt2d(0,l2),gp_Dir2d(1,0)),
844                          Face,T);
845             B.Range(Edge2,Face,f1,l1);
846           }
847         }
848
849       if (IType==0) {
850         if ( Periodic) {
851           B.UpdateEdge(Edge3,
852                        new Geom2d_Line(gp_Pnt2d(l1,0),gp_Dir2d(0,1)),
853                        new Geom2d_Line(gp_Pnt2d(f1,0),gp_Dir2d(0,1)),
854                        Face,T);
855         }
856         else {
857           B.UpdateEdge(Edge3,
858                        new Geom2d_Line(gp_Pnt2d(f1,0),gp_Dir2d(0,1)),
859                        Face,T);
860           B.UpdateEdge(Edge4,
861                        new Geom2d_Line(gp_Pnt2d(l1,0),gp_Dir2d(0,1)),
862                        Face,T);
863         }
864       }
865       else {
866         // KPart
867         if ( Periodic) {
868           TColgp_Array1OfPnt2d Extrem1(1,2);
869           Extrem1(1).SetCoord(l1,f2);
870           Extrem1(2).SetCoord(l1,l2);
871           TColgp_Array1OfPnt2d Extrem2(1,2);
872           Extrem2(1).SetCoord(f1,f2);
873           Extrem2(2).SetCoord(f1,l2);
874           B.UpdateEdge(Edge3,
875                        new Geom2d_BezierCurve(Extrem1),
876                        new Geom2d_BezierCurve(Extrem2),
877                        Face,T);
878         }
879         else if (IType != 4) { //not plane
880           TColgp_Array1OfPnt2d Extrem2(1,2);
881           Extrem2(1).SetCoord(f1,f2);
882           Extrem2(2).SetCoord(f1,l2);
883           B.UpdateEdge(Edge3,
884                        new Geom2d_BezierCurve(Extrem2),
885                        Face,T);
886           TColgp_Array1OfPnt2d Extrem1(1,2);
887           Extrem1(1).SetCoord(l1,f2);
888           Extrem1(2).SetCoord(l1,l2);
889           B.UpdateEdge(Edge4,
890                        new Geom2d_BezierCurve(Extrem1),
891                        Face,T);
892         }
893       }
894       // Set the non parameter flag;
895       B.SameParameter(Edge1,Standard_False);
896       B.SameParameter(Edge2,Standard_False);
897       B.SameParameter(Edge3,Standard_False);
898       B.SameParameter(Edge4,Standard_False);
899       B.SameRange(Edge1,Standard_False);
900       B.SameRange(Edge2,Standard_False);
901       B.SameRange(Edge3,Standard_False);
902       B.SameRange(Edge4,Standard_False);
903
904       tantque = ex1.More() && ex2.More();
905       if (wPoint1) tantque = ex2.More();
906       if (wPoint2) tantque = ex1.More();
907     }
908   }
909   BRepLib::SameParameter(myShell);
910
911   if (uClosed && DegenFirst && DegenLast)
912     myShell.Closed(Standard_True);
913 }
914
915
916 //=======================================================================
917 //function : GeneratedShapes
918 //purpose  : 
919 //=======================================================================
920
921 const TopTools_ListOfShape& 
922  BRepFill_Generator::GeneratedShapes (const TopoDS_Shape& SSection) const 
923 {
924   if (myMap.IsBound(SSection)) {
925     return myMap(SSection);
926   }
927   else {
928     static TopTools_ListOfShape Empty;
929     return Empty;
930   }
931 }
932
933 //=======================================================================
934 //function : Generated
935 //purpose  : 
936 //=================================================================== ====
937
938 const TopTools_DataMapOfShapeListOfShape& BRepFill_Generator::Generated() const
939 {
940   return myMap;
941 }
942
943