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