Integration of OCCT 6.5.0 from SVN
[occt.git] / src / BRepTest / BRepTest_FillingCommands.cxx
1 // File:        BRepTest_FillingCommands.cxx
2 // Created:     Wed Jul 10 13:23:02 1996
3 // Author:      Xavier BENVENISTE
4 //              <xab@mentox.paris1.matra-dtv.fr>
5 // Modified:    Wed Mar  5 09:45:42 1997
6 //    by:       Joelle CHAUVET
7 //              G1134 : new command "approxplate"
8 // Modified:    Thu Jun 12 16:51:36 1997
9 //    by:       Jerome LEMONIER
10 //              Mise a jour suite a la modification des methodes Curves2d 
11 //              et Sense GeomPlate_BuildPlateSurface.
12 // Modified:    Mon Nov  3 10:24:07 1997
13 // Author:      Joelle CHAUVET
14 //              utilisation de BRepFill_CurveConstraint
15  
16
17
18 #include <GeometryTest.hxx>
19 #include <Draw_Interpretor.hxx>
20 #include <Draw_Appli.hxx>
21 #include <DrawTrSurf.hxx>
22 #include <TopAbs_ShapeEnum.hxx>
23 #include <TopoDS.hxx>
24 #include <TopoDS_Edge.hxx>
25 #include <TopoDS_Face.hxx>
26 #include <TopExp_Explorer.hxx>
27 #include <TopExp.hxx>
28 #include <BRepAdaptor_HSurface.hxx>
29 #include <BRepAdaptor_HCurve2d.hxx>
30 #include <BRepAdaptor_HCurve.hxx>
31 #include <BRepAdaptor_Surface.hxx>
32 #include <BRepAdaptor_Curve2d.hxx>
33 #include <BRepAdaptor_Curve.hxx>  
34 #include <BRepTest.hxx>
35 #include <DBRep.hxx>
36 #include <Adaptor3d_HCurveOnSurface.hxx>
37 #include <Adaptor3d_CurveOnSurface.hxx>
38 #include <TColStd_HArray1OfInteger.hxx>
39 #include <BRep_Tool.hxx>
40
41 #include <BRepLib.hxx>
42 #include <BRep_Builder.hxx>
43 #include <GeomPlate_BuildPlateSurface.hxx>
44 #include <GeomPlate_BuildAveragePlane.hxx>
45 #include <GeomPlate_Surface.hxx>
46 #include <GeomPlate_BuildAveragePlane.hxx>
47 #include <GeomPlate_HArray1OfHCurveOnSurface.hxx>
48
49 #include <GeomPlate_MakeApprox.hxx>
50 #include <GeomPlate_PlateG0Criterion.hxx>
51 #include <GeomPlate_PlateG1Criterion.hxx>
52 #include <BRepFill_CurveConstraint.hxx>
53 #include <GeomPlate_PointConstraint.hxx>
54 #include <GeomAdaptor_HSurface.hxx>
55 #include <Geom_Surface.hxx>
56
57 #include <TopoDS_Wire.hxx>
58 #include <BRepBuilderAPI_MakeEdge.hxx>
59 #include <BRepBuilderAPI_MakeWire.hxx>
60 #include <BRepBuilderAPI_WireError.hxx>
61 #include <BRepBuilderAPI_MakeFace.hxx>
62 #include <TColGeom2d_HArray1OfCurve.hxx>
63
64 #include <AdvApp2Var_ApproxAFunc2Var.hxx>
65 #include <AdvApp2Var_Context.hxx>
66 #include <AdvApprox_PrefCutting.hxx>
67 #include <AdvApprox_Cutting.hxx>
68 #include <AdvApprox_DichoCutting.hxx>
69
70 #include <Geom_BSplineSurface.hxx>
71
72 #include <TColStd_HArray1OfReal.hxx>
73 #include <TColStd_HArray2OfReal.hxx>
74
75 #include <TColgp_SequenceOfXY.hxx>
76 #include <TColgp_SequenceOfXYZ.hxx>
77
78 #include <BRepAdaptor_HCurve.hxx>
79 #include <Adaptor3d_HIsoCurve.hxx>
80
81 #include <Extrema_ExtPS.hxx>
82 #include <Extrema_POnSurf.hxx>
83 #include <Geom_Plane.hxx>
84 #include <BRepOffsetAPI_MakeFilling.hxx>
85 #include <TCollection_AsciiString.hxx>
86 #include <Geom2d_TrimmedCurve.hxx>
87 #include <GeomConvert_ApproxSurface.hxx>
88
89
90 #include <stdio.h>
91 #include <gp_Pnt.hxx>
92
93 // pour mes tests
94 #ifdef DEB
95 #include <OSD_Chronometer.hxx>
96 #include <Geom_Line.hxx>
97 #endif
98
99 const Standard_Integer defDegree = 3;
100 const Standard_Integer defNbPtsOnCur = 10;
101 const Standard_Integer defNbIter = 3;
102 const Standard_Boolean defAnisotropie = Standard_False;
103 const Standard_Real defTol2d = 0.00001;
104 const Standard_Real defTol3d = 0.0001;
105 const Standard_Real defTolAng = 0.01;
106 const Standard_Real defTolCurv = 0.1;
107 const Standard_Integer defMaxDeg = 8;
108 const Standard_Integer defMaxSegments = 9;
109
110 Standard_Integer Degree = defDegree;
111 Standard_Integer NbPtsOnCur = defNbPtsOnCur ;
112 Standard_Integer NbIter = defNbIter;
113 Standard_Boolean Anisotropie = defAnisotropie ;
114 Standard_Real Tol2d = defTol2d;
115 Standard_Real Tol3d = defTol3d;
116 Standard_Real TolAng = defTolAng;
117 Standard_Real TolCurv = defTolCurv;
118 Standard_Integer MaxDeg = defMaxDeg;
119 Standard_Integer MaxSegments = defMaxSegments;
120
121 //////////////////////////////////////////////////////////////////////////////// 
122 //  commande plate : resultat face sur surface plate
123 //////////////////////////////////////////////////////////////////////////////// 
124
125 static Standard_Integer plate (Draw_Interpretor & di,Standard_Integer n,const char** a)
126 {
127   if (n < 8 ) return 1;
128   Standard_Integer NbCurFront=atoi(a[3]);
129   Handle(GeomPlate_HArray1OfHCurveOnSurface) Fronts = new GeomPlate_HArray1OfHCurveOnSurface(1,NbCurFront);
130   Handle(TColStd_HArray1OfInteger) Tang = new TColStd_HArray1OfInteger(1,NbCurFront);
131   Handle(TColStd_HArray1OfInteger) NbPtsCur = new TColStd_HArray1OfInteger(1,NbCurFront);
132   BRep_Builder B;
133   
134   GeomPlate_BuildPlateSurface Henri(3,15,2);
135
136   Standard_Integer i;
137   for (i=1; i<=NbCurFront ; i++) { 
138     TopoDS_Shape aLocalEdge(DBRep::Get(a[3*i+1],TopAbs_EDGE));
139     TopoDS_Edge E = TopoDS::Edge(aLocalEdge);
140 //    TopoDS_Edge E = TopoDS::Edge(DBRep::Get(a[3*i+1],TopAbs_EDGE));
141     if(E.IsNull()) return 1;
142     TopoDS_Shape aLocalFace(DBRep::Get(a[3*i+2],TopAbs_FACE));
143     TopoDS_Face F = TopoDS::Face(aLocalFace);
144 //    TopoDS_Face F = TopoDS::Face(DBRep::Get(a[3*i+2],TopAbs_FACE));
145     if(F.IsNull()) return 1;
146     Standard_Integer T = atoi(a[3*i+3]);
147     Tang->SetValue(i,T);
148     NbPtsCur->SetValue(i,atoi(a[2]));
149     Handle(BRepAdaptor_HSurface) S = new BRepAdaptor_HSurface();
150     S->ChangeSurface().Initialize(F);
151     Handle(BRepAdaptor_HCurve2d) C = new BRepAdaptor_HCurve2d();
152     C->ChangeCurve2d().Initialize(E,F);
153     Adaptor3d_CurveOnSurface ConS(C,S);
154     Handle (Adaptor3d_HCurveOnSurface) HConS = new Adaptor3d_HCurveOnSurface(ConS);
155     Fronts->SetValue(i,HConS);
156     Handle(BRepFill_CurveConstraint) Cont
157       = new BRepFill_CurveConstraint(HConS,
158                                      Tang->Value(i),
159                                      NbPtsCur->Value(i));
160     Henri.Add(Cont);
161   }
162   
163   Henri.Perform();
164
165   Standard_Real ErrG0 = 1.1*Henri.G0Error();
166   //cout<<" dist. max = "<<Henri.G0Error()<<" ; angle max = "<<Henri.G1Error()<<endl;
167   di<<" dist. max = "<<Henri.G0Error()<<" ; angle max = "<<Henri.G1Error()<<"\n";
168
169   BRepBuilderAPI_MakeWire MW;
170   for (i=1 ; i<=NbCurFront ; i++) {
171     Standard_Integer iInOrder=Henri.Order()->Value(i);
172     TopoDS_Edge E;
173     if (Henri.Sense()->Value(iInOrder)==1) { 
174       BRepBuilderAPI_MakeEdge ME(Henri.Curves2d()->Value(iInOrder),
175                           Henri.Surface(),
176                           Fronts->Value(iInOrder)->LastParameter(),
177                           Fronts->Value(iInOrder)->FirstParameter());
178       E = ME.Edge();
179       
180     }
181     else {
182       BRepBuilderAPI_MakeEdge ME(Henri.Curves2d()->Value(iInOrder),
183                           Henri.Surface(),
184                           Fronts->Value(iInOrder)->FirstParameter(),
185                           Fronts->Value(iInOrder)->LastParameter());
186       E = ME.Edge();
187     }
188     B.UpdateVertex(TopExp::FirstVertex(E), ErrG0);
189     B.UpdateVertex(TopExp::LastVertex(E), ErrG0);
190     BRepLib::BuildCurve3d(E);
191     char name[100];
192     sprintf(name,"Edge_%d", i);
193     DBRep::Set(name, E);
194     MW.Add(E);
195     if (MW.IsDone()==Standard_False) {
196 #if DEB
197       BRepBuilderAPI_WireError err =
198 #endif
199                                      MW.Error();
200       Standard_Failure::Raise("mkWire is over ");
201     }
202       
203   }
204   TopoDS_Wire W;
205   W=MW.Wire();
206   if (!(W.Closed())) Standard_Failure::Raise("Wire is not closed");
207   BRepBuilderAPI_MakeFace MF(Henri.Surface(),W,Standard_True);
208   DBRep::Set(a[1],MF.Face());
209   return 0;
210 }
211
212 //////////////////////////////////////////////////////////////////////////////// 
213 //  commande gplate : resultat face egale a la surface approchee
214 //////////////////////////////////////////////////////////////////////////////// 
215  
216 static Standard_Integer gplate (Draw_Interpretor & ,Standard_Integer n,const char** a)
217 {
218   if (n < 6 ) return 1; 
219   Standard_Integer NbCurFront=atoi(a[2]),
220   NbPointConstraint=atoi(a[3]);
221   
222   GeomPlate_BuildPlateSurface Henri(3,15,2);
223   
224   Standard_Integer i;
225   Standard_Integer Conti;
226   Standard_Integer Indice=4;
227 //Surface d'init  
228   TopoDS_Shape aLocalFace(DBRep::Get(a[Indice++],TopAbs_FACE));
229   TopoDS_Face SI = TopoDS::Face(aLocalFace);
230 //  TopoDS_Face SI = TopoDS::Face(DBRep::Get(a[Indice++],TopAbs_FACE));
231   if(SI.IsNull()) 
232     Indice--;
233   else
234     { Handle(BRepAdaptor_HSurface) HSI = new BRepAdaptor_HSurface();
235       HSI->ChangeSurface().Initialize(SI);
236       Henri.LoadInitSurface( BRep_Tool::Surface(HSI->ChangeSurface().Face()));
237     }
238   for (i=1; i<=NbCurFront ; i++) { 
239     TopoDS_Shape aLocalShape(DBRep::Get(a[Indice++],TopAbs_EDGE));
240     TopoDS_Edge E = TopoDS::Edge(aLocalShape);
241 //    TopoDS_Edge E = TopoDS::Edge(DBRep::Get(a[Indice++],TopAbs_EDGE));
242     if(E.IsNull()) return 1;
243     Conti=atoi(a[Indice++]);
244     if ((Conti==0)||(Conti==-1))
245       { Handle(BRepAdaptor_HCurve) C = new BRepAdaptor_HCurve();
246         C->ChangeCurve().Initialize(E);
247         Handle(BRepFill_CurveConstraint) Cont= new BRepFill_CurveConstraint(C,Conti);
248         Henri.Add(Cont);
249      }
250     else 
251       { 
252         aLocalFace = DBRep::Get(a[Indice++],TopAbs_FACE);
253         TopoDS_Face F = TopoDS::Face(aLocalFace);
254 //      TopoDS_Face F = TopoDS::Face(DBRep::Get(a[Indice++],TopAbs_FACE));
255         if(F.IsNull()) 
256           return 1;
257         Handle(BRepAdaptor_HSurface) S = new BRepAdaptor_HSurface();
258         S->ChangeSurface().Initialize(F);
259         Handle(BRepAdaptor_HCurve2d) C = new BRepAdaptor_HCurve2d();
260         C->ChangeCurve2d().Initialize(E,F);
261         Adaptor3d_CurveOnSurface ConS(C,S);
262         Handle (Adaptor3d_HCurveOnSurface) HConS = new Adaptor3d_HCurveOnSurface(ConS);
263         Handle(BRepFill_CurveConstraint) Cont= new BRepFill_CurveConstraint(HConS,Conti);
264         Henri.Add(Cont);
265       }
266   }
267   
268   for (i=1; i<=NbPointConstraint ; i++) 
269     { 
270 //      gp_Pnt P1,P2,P3;
271       gp_Pnt P1;
272 //      gp_Vec V1,V2,V3,V4,V5;
273
274       if (DrawTrSurf::GetPoint(a[Indice], P1) ) 
275         { Conti=0;
276           Handle(GeomPlate_PointConstraint) PCont= new GeomPlate_PointConstraint(P1,0);
277           Henri.Add(PCont);
278           Indice++;
279         }
280       else
281         { Standard_Real u=atof(a[Indice++]), 
282                         v=atof(a[Indice++]);
283
284           Conti=atoi(a[Indice++]);
285           aLocalFace = DBRep::Get(a[Indice++],TopAbs_FACE);
286           TopoDS_Face F = TopoDS::Face(aLocalFace);
287 //        TopoDS_Face F = TopoDS::Face(DBRep::Get(a[Indice++],TopAbs_FACE));
288           if(F.IsNull()) 
289             return 1;   
290           Handle(BRepAdaptor_HSurface) HF = new BRepAdaptor_HSurface();
291           HF->ChangeSurface().Initialize(F);
292           Handle(GeomPlate_PointConstraint) PCont= new GeomPlate_PointConstraint(u,v,BRep_Tool::Surface(HF->ChangeSurface().Face()),Conti,0.001,0.001,0.001);
293           Henri.Add(PCont);
294         }
295     }    
296   Henri.Perform();
297   Standard_Integer nbcarreau=9;
298   Standard_Integer degmax=8;
299   Standard_Real seuil;
300
301   Handle(GeomPlate_Surface) gpPlate = Henri.Surface();
302   TColgp_SequenceOfXY S2d;
303   TColgp_SequenceOfXYZ S3d;
304   S2d.Clear();
305   S3d.Clear();
306   Henri.Disc2dContour(4,S2d);
307   Henri.Disc3dContour(4,0,S3d);
308   seuil = Max(0.0001,10*Henri.G0Error());
309   GeomPlate_PlateG0Criterion critere (S2d,S3d,seuil);
310   GeomPlate_MakeApprox Mapp(gpPlate,critere,0.0001,nbcarreau,degmax);
311   Handle (Geom_Surface) Surf (Mapp.Surface());
312
313   Standard_Real Umin, Umax, Vmin, Vmax;
314   
315   Henri.Surface()->Bounds( Umin, Umax, Vmin, Vmax);
316   
317   BRepBuilderAPI_MakeFace MF(Surf,Umin, Umax, Vmin, Vmax);
318   
319   DBRep::Set(a[1],MF.Face());
320   return 0;
321 }
322
323
324 //////////////////////////////////////////////////////////////////////////////// 
325 //  commande approxplate : resultat face sur surface approchee
326 //////////////////////////////////////////////////////////////////////////////// 
327
328 static Standard_Integer approxplate (Draw_Interpretor & di,Standard_Integer n,const char** a)
329 {
330   if (n < 9 ) return 1;
331   Standard_Integer NbMedium=atoi(a[2]);
332   Standard_Integer NbCurFront=atoi(a[3]);
333   Handle(GeomPlate_HArray1OfHCurveOnSurface) Fronts = new GeomPlate_HArray1OfHCurveOnSurface(1,NbCurFront);
334   Handle(TColStd_HArray1OfInteger) Tang = new TColStd_HArray1OfInteger(1,NbCurFront);
335   Handle(TColStd_HArray1OfInteger) NbPtsCur = new TColStd_HArray1OfInteger(1,NbCurFront);
336   
337   GeomPlate_BuildPlateSurface Henri(3,15,2);
338
339   Standard_Integer i;
340   for (i=1; i<=NbCurFront ; i++) { 
341     TopoDS_Shape aLocalShape(DBRep::Get(a[3*i+1],TopAbs_EDGE));
342     TopoDS_Edge E = TopoDS::Edge(aLocalShape);
343 //    TopoDS_Edge E = TopoDS::Edge(DBRep::Get(a[3*i+1],TopAbs_EDGE));
344     if(E.IsNull()) return 1;
345     TopoDS_Shape aLocalFace(DBRep::Get(a[3*i+2],TopAbs_FACE));
346     TopoDS_Face F = TopoDS::Face(aLocalFace);
347 //    TopoDS_Face F = TopoDS::Face(DBRep::Get(a[3*i+2],TopAbs_FACE));
348     if(F.IsNull()) return 1;
349     Standard_Integer T = atoi(a[3*i+3]);
350     Tang->SetValue(i,T);
351     NbPtsCur->SetValue(i,NbMedium);
352     Handle(BRepAdaptor_HSurface) S = new BRepAdaptor_HSurface();
353     S->ChangeSurface().Initialize(F);
354     Handle(BRepAdaptor_HCurve2d) C = new BRepAdaptor_HCurve2d();
355     C->ChangeCurve2d().Initialize(E,F);
356     Adaptor3d_CurveOnSurface ConS(C,S);
357     Handle (Adaptor3d_HCurveOnSurface) HConS = new Adaptor3d_HCurveOnSurface(ConS);
358     Fronts->SetValue(i,HConS);
359     Handle(BRepFill_CurveConstraint) Cont
360       = new BRepFill_CurveConstraint(HConS,
361                                      Tang->Value(i),
362                                      NbPtsCur->Value(i));
363     Henri.Add(Cont);
364   }
365   
366   Henri.Perform();
367
368   Standard_Real dmax = Henri.G0Error(),
369                 anmax = Henri.G1Error();
370   //cout<<" dist. max = "<<dmax<<" ; angle max = "<<anmax<<endl;
371   di<<" dist. max = "<<dmax<<" ; angle max = "<<anmax<<"\n";
372
373   Tol3d = atof(a[3*NbCurFront+4]);
374   Standard_Integer Nbmax = atoi(a[3*NbCurFront+5]);
375   Standard_Integer degmax = atoi(a[3*NbCurFront+6]);
376   Standard_Integer CritOrder = atoi(a[3*NbCurFront+7]);
377   Handle(GeomPlate_Surface) surf = Henri.Surface();
378   Handle(Geom_BSplineSurface) support;
379
380   if (CritOrder==-1) {
381     GeomPlate_MakeApprox MApp(surf,Tol3d,Nbmax,degmax,dmax,-1);
382     support = MApp.Surface();
383   }
384   else if (CritOrder>=0) {
385     TColgp_SequenceOfXY S2d;
386     TColgp_SequenceOfXYZ S3d;
387     S2d.Clear();
388     S3d.Clear();
389     Standard_Real seuil;
390     if (CritOrder==0) {
391       Henri.Disc2dContour(4,S2d);
392       Henri.Disc3dContour(4,0,S3d);
393       seuil = Max(Tol3d,dmax*10);
394       GeomPlate_PlateG0Criterion Crit0(S2d,S3d,seuil);
395       GeomPlate_MakeApprox MApp(surf,Crit0,Tol3d,Nbmax,degmax);
396       support = MApp.Surface();
397     }
398     else if (CritOrder==1) {
399       Henri.Disc2dContour(4,S2d);
400       Henri.Disc3dContour(4,1,S3d);
401       seuil = Max(Tol3d,anmax*10);
402       GeomPlate_PlateG1Criterion Crit1(S2d,S3d,seuil);
403       GeomPlate_MakeApprox MApp(surf,Crit1,Tol3d,Nbmax,degmax);
404       support = MApp.Surface();
405     }
406   }
407
408   BRepBuilderAPI_MakeWire MW;
409   BRep_Builder B;
410   for (i=1 ; i<=NbCurFront ; i++) {
411     Standard_Integer iInOrder=Henri.Order()->Value(i);
412     TopoDS_Edge E;
413     if (Henri.Sense()->Value(iInOrder)==1) { 
414       BRepBuilderAPI_MakeEdge ME(Henri.Curves2d()->Value(iInOrder),
415                           support,
416                           Fronts->Value(iInOrder)->LastParameter(),
417                           Fronts->Value(iInOrder)->FirstParameter());
418       E = ME.Edge();
419     }
420     else {
421       BRepBuilderAPI_MakeEdge ME(Henri.Curves2d()->Value(iInOrder),
422                           support,
423                           Fronts->Value(iInOrder)->FirstParameter(),
424                           Fronts->Value(iInOrder)->LastParameter());
425       E = ME.Edge();
426     }
427     B.UpdateVertex(TopExp::FirstVertex(E), dmax);
428     B.UpdateVertex(TopExp::LastVertex(E), dmax);
429     BRepLib::BuildCurve3d(E);
430     MW.Add(E);
431     if (MW.IsDone()==Standard_False) {
432 #ifdef DEB
433       BRepBuilderAPI_WireError err =
434 #endif
435                                      MW.Error();
436       Standard_Failure::Raise("mkWire is over ");
437     }
438   }
439   TopoDS_Wire W;
440   W=MW.Wire();
441   if (!(W.Closed())) Standard_Failure::Raise("Wire is not closed");
442   BRepBuilderAPI_MakeFace MF(support,W,Standard_True);
443   DBRep::Set(a[1],MF.Face());
444
445   return 0;
446 }
447
448 static Standard_Integer filling( Draw_Interpretor & di, Standard_Integer n, const char** a )
449 {
450 #ifdef DEB
451   // Chronmetrage
452   OSD_Chronometer Chrono;
453   Chrono.Reset();
454   Chrono.Start();
455 #endif
456
457   if (n < 7) return 1;
458   Standard_Integer NbBounds = atoi( a[2] );
459   Standard_Integer NbConstraints = atoi( a[3] );
460   Standard_Integer NbPoints = atoi( a[4] );
461
462   BRepOffsetAPI_MakeFilling MakeFilling( Degree,
463                                    NbPtsOnCur,
464                                    NbIter,
465                                    Anisotropie,
466                                    Tol2d,
467                                    Tol3d,
468                                    TolAng,
469                                    TolCurv,
470                                    MaxDeg,
471                                    MaxSegments );
472     TopoDS_Shape aLocalFace(DBRep::Get( a[5], TopAbs_FACE ) );
473     TopoDS_Face InitFace = TopoDS::Face( aLocalFace);
474 //  TopoDS_Face InitFace = TopoDS::Face( DBRep::Get( a[5], TopAbs_FACE ) );
475   if (! InitFace.IsNull())
476     MakeFilling.LoadInitSurface( InitFace );
477   
478   Standard_Integer i = (InitFace.IsNull())? 5 : 6, k;
479   TopoDS_Edge E;
480   TopoDS_Face F;
481   gp_Pnt Point;
482   Standard_Integer Order;
483   for (k = 1; k <= NbBounds; k++)
484     { 
485       E.Nullify();
486       F.Nullify();
487       TopoDS_Shape aLocalEdge(DBRep::Get( a[i], TopAbs_EDGE ));
488       E = TopoDS::Edge(aLocalEdge);
489 //      E = TopoDS::Edge( DBRep::Get( a[i], TopAbs_EDGE ) );
490       if (! E.IsNull())
491         i++;
492       aLocalFace =  DBRep::Get( a[i], TopAbs_FACE ) ;
493       F = TopoDS::Face(aLocalFace);
494 //      F = TopoDS::Face( DBRep::Get( a[i], TopAbs_FACE ) );
495       if (! F.IsNull())
496         i++;
497
498       Order = atoi( a[i++] );
499       
500       if (! E.IsNull() && ! F.IsNull())
501         MakeFilling.Add( E, F, (GeomAbs_Shape)Order );
502       else if (E.IsNull())
503         {
504           if (F.IsNull())
505             {
506               //cout<<endl<<"Wrong parameters"<<endl<<endl;
507               di<<"\n"<<"Wrong parameters"<<"\n"<<"\n";
508               return 1;
509             }
510           else
511             MakeFilling.Add( F, (GeomAbs_Shape)Order );
512         }
513       else
514         MakeFilling.Add( E, (GeomAbs_Shape)Order );
515     }
516   for (k = 1; k <= NbConstraints; k++)
517     { 
518       E.Nullify();
519       F.Nullify();
520       TopoDS_Shape aLocalEdge(DBRep::Get( a[i++], TopAbs_EDGE ));
521       E = TopoDS::Edge( aLocalEdge);
522 //      E = TopoDS::Edge( DBRep::Get( a[i++], TopAbs_EDGE ) );
523       if (E.IsNull())
524         {
525           //cout<<"Wrong parameters"<<endl;
526           di<<"Wrong parameters"<<"\n";
527           return 1;
528         }
529       TopoDS_Shape alocalFace(DBRep::Get( a[i], TopAbs_FACE ) );
530       F = TopoDS::Face( aLocalFace);
531 //      F = TopoDS::Face( DBRep::Get( a[i], TopAbs_FACE ) );
532       if (! F.IsNull())
533         i++;
534       
535       Order = atoi( a[i++] );
536       
537       if (F.IsNull())
538         MakeFilling.Add( E, (GeomAbs_Shape)Order, Standard_False );
539       else
540         MakeFilling.Add( E, F, (GeomAbs_Shape)Order, Standard_False );
541     }
542   for (k = 1; k <= NbPoints; k++)
543     {
544       if (DrawTrSurf::GetPoint( a[i], Point )) 
545         {
546           MakeFilling.Add( Point );
547           i++;
548         }
549       else
550         {
551           Standard_Real U = atof( a[i++] ), V = atof( a[i++] );
552           aLocalFace = DBRep::Get( a[i++], TopAbs_FACE );
553           F = TopoDS::Face( aLocalFace);
554 //        F = TopoDS::Face( DBRep::Get( a[i++], TopAbs_FACE ));
555           if (F.IsNull()) 
556             {
557               //cout<<"Wrong parameters"<<endl;
558               di<<"Wrong parameters"<<"\n";
559               return 1;
560             }
561           Order = atoi( a[i++] );
562
563           MakeFilling.Add( U, V, F, (GeomAbs_Shape)Order );
564         }
565     }
566
567   MakeFilling.Build();
568   if (! MakeFilling.IsDone())
569     {
570       //cout<<"filling failed"<<endl;
571       di<<"filling failed"<<"\n";
572       return 0;
573     }
574
575   Standard_Real dmax = MakeFilling.G0Error(),
576                 angmax = MakeFilling.G1Error(),
577                 curvmax = MakeFilling.G2Error();
578   //cout<<" dist. max = "<<dmax<<" ; angle max = "<<angmax<<" ; diffcurv max = "<<curvmax<<endl;
579   di<<" dist. max = "<<dmax<<" ; angle max = "<<angmax<<" ; diffcurv max = "<<curvmax<<"\n";
580
581   TopoDS_Face ResFace= TopoDS::Face( MakeFilling.Shape() );
582   DBRep::Set( a[1], ResFace );
583
584 #ifdef DEB  
585   Chrono.Stop();
586   Standard_Real Tps;
587   Chrono.Show(Tps);
588   //cout<<"*** FIN DE FILLING ***"<<endl;
589   //cout<<"Temps de calcul  : "<<Tps<<endl;
590   di<<"*** FIN DE FILLING ***"<<"\n";
591   di<<"Temps de calcul  : "<<Tps<<"\n";
592 #endif
593
594   return 0;
595 }
596
597 static Standard_Integer fillingparam( Draw_Interpretor & di, Standard_Integer n, const char** a )
598 {
599   if ( n == 1) {
600
601     //cout << "fillingparam : options are"  <<endl;
602     //cout << "-l : to list current values" << endl;
603     //cout << "-i : to set default values"   << endl;
604     //cout << "-r deg nbPonC nbIt anis : to set filling options" <<endl;
605     //cout << "-c t2d t3d tang tcur : to set tolerances" << endl;
606     //cout << "-a maxdeg maxseg : Approximation option" << endl;
607     di << "fillingparam : options are"  <<"\n";
608     di << "-l : to list current values" << "\n";
609     di << "-i : to set default values"   << "\n";
610     di << "-r deg nbPonC nbIt anis : to set filling options" <<"\n";
611     di << "-c t2d t3d tang tcur : to set tolerances" << "\n";
612     di << "-a maxdeg maxseg : Approximation option" << "\n";
613   }
614   else if (n > 1)
615     {
616       TCollection_AsciiString AS( a[1] );
617       AS.LowerCase();
618       const char* flag = AS.ToCString();
619       if (strcmp( flag, "-l" ) == 0 && n == 2)
620         {
621           //cout<<endl;
622           //cout<<"Degree = "<<Degree<<endl;
623           //cout<<"NbPtsOnCur = "<<NbPtsOnCur<<endl;
624           //cout<<"NbIter = "<<NbIter<<endl;
625           //cout<<"Anisotropie = "<<Anisotropie<<endl<<endl;
626           //
627           //cout<<"Tol2d = "<<Tol2d<<endl;
628           //cout<<"Tol3d = "<<Tol3d<<endl;
629           //cout<<"TolAng = "<<TolAng<<endl;
630           //cout<<"TolCurv = "<<TolCurv<<endl<<endl;
631           //
632           //cout<<"MaxDeg = "<<MaxDeg<<endl;
633           //cout<<"MaxSegments = "<<MaxSegments<<endl<<endl;
634           di<<"\n";
635           di<<"Degree = "<<Degree<<"\n";
636           di<<"NbPtsOnCur = "<<NbPtsOnCur<<"\n";
637           di<<"NbIter = "<<NbIter<<"\n";
638           di<<"Anisotropie = "<< (Standard_Integer) Anisotropie<<"\n"<<"\n";
639           
640           di<<"Tol2d = "<<Tol2d<<"\n";
641           di<<"Tol3d = "<<Tol3d<<"\n";
642           di<<"TolAng = "<<TolAng<<"\n";
643           di<<"TolCurv = "<<TolCurv<<"\n"<<"\n";
644           
645           di<<"MaxDeg = "<<MaxDeg<<"\n";
646           di<<"MaxSegments = "<<MaxSegments<<"\n"<<"\n";
647         }
648       else if (strcmp( flag, "-i" ) == 0 && n == 2)
649         {
650           Degree = defDegree;
651           NbPtsOnCur = defNbPtsOnCur;
652           NbIter = defNbIter;
653           Anisotropie = defAnisotropie;
654           
655           Tol2d = defTol2d;
656           Tol3d = defTol3d;
657           TolAng = defTolAng;
658           TolCurv = defTolCurv;
659           
660           MaxDeg = defMaxDeg;
661           MaxSegments = defMaxSegments;
662         }
663       else if (strcmp( flag, "-r" ) == 0 && n == 6)
664         {
665           Degree      = atoi( a[2] );
666           NbPtsOnCur  = atoi( a[3] );
667           NbIter      = atoi( a[4] );
668           Anisotropie = atoi( a[5] );
669         }
670       else if (strcmp( flag, "-c" ) == 0 && n == 6)
671         {
672           Tol2d   = atof( a[2] ); 
673           Tol3d   = atof( a[3] );
674           TolAng  = atof( a[4] );
675           TolCurv = atof( a[5] );
676         }
677       else if (strcmp( flag, "-a" ) == 0 && n == 4)
678         {
679           MaxDeg      = atoi( a[2] );
680           MaxSegments = atoi( a[3] );
681         }
682       else
683         {
684           //cout<<"Wrong parameters"<<endl;
685           di<<"Wrong parameters"<<"\n";
686           return 1;
687         }
688     }
689   return 0;
690 }
691
692
693
694
695 void  BRepTest::FillingCommands(Draw_Interpretor& theCommands)
696 {
697   static Standard_Boolean done = Standard_False;
698   if (done) return;
699   done = Standard_True;
700
701   DBRep::BasicCommands(theCommands);
702   GeometryTest::SurfaceCommands(theCommands);
703
704   const char* g = "Surface filling topology commands";
705   theCommands.Add("plate",
706                   "plate result nbrpntoncurve nbrcurfront edge face tang (0:vif;1:tang) ...",
707                   __FILE__,
708                   plate,
709                   g) ;
710
711   theCommands.Add("gplate",
712                   "gplate result nbrcurfront nbrpntconst [SurfInit] [edge 0] [edge tang (1:G1;2:G2) surf]... [point] [u v tang (1:G1;2:G2) surf] ...",
713                   __FILE__,
714                   gplate,
715                   g) ;
716
717   theCommands.Add("approxplate",
718                   "approxplate result nbrpntoncurve nbrcurfront edge face tang (0:vif;1:tang) ... tol nmax degmax crit",
719                   __FILE__,
720                   approxplate,
721                   g) ;
722
723
724
725   theCommands.Add("filling",
726                   "filling result nbB nbC nbP [SurfInit] [edge][face]order... edge[face]order... point/u v face order...",
727                   __FILE__,
728                   filling,
729                   g) ;
730
731   theCommands.Add("fillingparam",
732                   "fillingparam : no arg give help",
733                   __FILE__,
734                   fillingparam,
735                   g) ;
736
737 }