0031687: Draw Harness, ViewerTest - extend command vrenderparams with option updating...
[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 <DrawTrSurf.hxx>
33 #include <TopAbs_ShapeEnum.hxx>
34 #include <TopoDS.hxx>
35 #include <TopoDS_Edge.hxx>
36 #include <TopoDS_Face.hxx>
37 #include <TopExp_Explorer.hxx>
38 #include <TopExp.hxx>
39 #include <BRepAdaptor_HSurface.hxx>
40 #include <BRepAdaptor_HCurve2d.hxx>
41 #include <BRepAdaptor_HCurve.hxx>
42 #include <BRepAdaptor_Surface.hxx>
43 #include <BRepAdaptor_Curve2d.hxx>
44 #include <BRepAdaptor_Curve.hxx>  
45 #include <BRepTest.hxx>
46 #include <DBRep.hxx>
47 #include <Adaptor3d_HCurveOnSurface.hxx>
48 #include <Adaptor3d_CurveOnSurface.hxx>
49 #include <TColStd_HArray1OfInteger.hxx>
50 #include <BRep_Tool.hxx>
51
52 #include <BRepLib.hxx>
53 #include <BRep_Builder.hxx>
54 #include <GeomPlate_BuildPlateSurface.hxx>
55 #include <GeomPlate_BuildAveragePlane.hxx>
56 #include <GeomPlate_Surface.hxx>
57 #include <GeomPlate_BuildAveragePlane.hxx>
58 #include <GeomPlate_HArray1OfHCurve.hxx>
59
60 #include <GeomPlate_MakeApprox.hxx>
61 #include <GeomPlate_PlateG0Criterion.hxx>
62 #include <GeomPlate_PlateG1Criterion.hxx>
63 #include <BRepFill_CurveConstraint.hxx>
64 #include <GeomPlate_PointConstraint.hxx>
65 #include <GeomAdaptor_HSurface.hxx>
66 #include <Geom_Surface.hxx>
67
68 #include <TopoDS_Wire.hxx>
69 #include <BRepBuilderAPI_MakeEdge.hxx>
70 #include <BRepBuilderAPI_MakeWire.hxx>
71 #include <BRepBuilderAPI_WireError.hxx>
72 #include <BRepBuilderAPI_MakeFace.hxx>
73 #include <TColGeom2d_HArray1OfCurve.hxx>
74
75 #include <AdvApp2Var_ApproxAFunc2Var.hxx>
76 #include <AdvApp2Var_Context.hxx>
77 #include <AdvApprox_PrefCutting.hxx>
78 #include <AdvApprox_Cutting.hxx>
79 #include <AdvApprox_DichoCutting.hxx>
80
81 #include <Geom_BSplineSurface.hxx>
82
83 #include <TColStd_HArray1OfReal.hxx>
84 #include <TColStd_HArray2OfReal.hxx>
85
86 #include <TColgp_SequenceOfXY.hxx>
87 #include <TColgp_SequenceOfXYZ.hxx>
88
89 #include <BRepAdaptor_HCurve.hxx>
90 #include <Adaptor3d_HIsoCurve.hxx>
91
92 #include <Extrema_ExtPS.hxx>
93 #include <Extrema_POnSurf.hxx>
94 #include <Geom_Plane.hxx>
95 #include <BRepOffsetAPI_MakeFilling.hxx>
96 #include <TCollection_AsciiString.hxx>
97 #include <Geom2d_TrimmedCurve.hxx>
98 #include <GeomConvert_ApproxSurface.hxx>
99
100 #include <BRepTest_Objects.hxx>
101
102 #include <stdio.h>
103 #include <gp_Pnt.hxx>
104
105 // pour mes tests
106 #ifdef OCCT_DEBUG
107 #include <OSD_Chronometer.hxx>
108 #include <Geom_Line.hxx>
109 #endif
110
111 const Standard_Integer defDegree = 3;
112 const Standard_Integer defNbPtsOnCur = 10;
113 const Standard_Integer defNbIter = 3;
114 const Standard_Boolean defAnisotropie = Standard_False;
115 const Standard_Real defTol2d = 0.00001;
116 const Standard_Real defTol3d = 0.0001;
117 const Standard_Real defTolAng = 0.01;
118 const Standard_Real defTolCurv = 0.1;
119 const Standard_Integer defMaxDeg = 8;
120 const Standard_Integer defMaxSegments = 9;
121
122 Standard_Integer Degree = defDegree;
123 Standard_Integer NbPtsOnCur = defNbPtsOnCur ;
124 Standard_Integer NbIter = defNbIter;
125 Standard_Boolean Anisotropie = defAnisotropie ;
126 Standard_Real Tol2d = defTol2d;
127 Standard_Real Tol3d = defTol3d;
128 Standard_Real TolAng = defTolAng;
129 Standard_Real TolCurv = defTolCurv;
130 Standard_Integer MaxDeg = defMaxDeg;
131 Standard_Integer MaxSegments = defMaxSegments;
132
133 //////////////////////////////////////////////////////////////////////////////// 
134 //  commande plate : resultat face sur surface plate
135 //////////////////////////////////////////////////////////////////////////////// 
136
137 static Standard_Integer plate (Draw_Interpretor & di,Standard_Integer n,const char** a)
138 {
139   if (n < 8 ) return 1;
140   Standard_Integer NbCurFront=Draw::Atoi(a[3]);
141   Handle(GeomPlate_HArray1OfHCurve) Fronts = new GeomPlate_HArray1OfHCurve(1,NbCurFront);
142   Handle(TColStd_HArray1OfInteger) Tang = new TColStd_HArray1OfInteger(1,NbCurFront);
143   Handle(TColStd_HArray1OfInteger) NbPtsCur = new TColStd_HArray1OfInteger(1,NbCurFront);
144   BRep_Builder B;
145   
146   GeomPlate_BuildPlateSurface Henri(3,15,2);
147
148   Standard_Integer i;
149   for (i=1; i<=NbCurFront ; i++) { 
150     TopoDS_Shape aLocalEdge(DBRep::Get(a[3*i+1],TopAbs_EDGE));
151     TopoDS_Edge E = TopoDS::Edge(aLocalEdge);
152 //    TopoDS_Edge E = TopoDS::Edge(DBRep::Get(a[3*i+1],TopAbs_EDGE));
153     if(E.IsNull()) return 1;
154     TopoDS_Shape aLocalFace(DBRep::Get(a[3*i+2],TopAbs_FACE));
155     TopoDS_Face F = TopoDS::Face(aLocalFace);
156 //    TopoDS_Face F = TopoDS::Face(DBRep::Get(a[3*i+2],TopAbs_FACE));
157     if(F.IsNull()) return 1;
158     Standard_Integer T = Draw::Atoi(a[3*i+3]);
159     Tang->SetValue(i,T);
160     NbPtsCur->SetValue(i,Draw::Atoi(a[2]));
161     Handle(BRepAdaptor_HSurface) S = new BRepAdaptor_HSurface();
162     S->ChangeSurface().Initialize(F);
163     Handle(BRepAdaptor_HCurve2d) C = new BRepAdaptor_HCurve2d();
164     C->ChangeCurve2d().Initialize(E,F);
165     Adaptor3d_CurveOnSurface ConS(C,S);
166     Handle (Adaptor3d_HCurveOnSurface) HConS = new Adaptor3d_HCurveOnSurface(ConS);
167     Fronts->SetValue(i,HConS);
168     Handle(GeomPlate_CurveConstraint) Cont
169       = new BRepFill_CurveConstraint(HConS,
170                                      Tang->Value(i),
171                                      NbPtsCur->Value(i));
172     Henri.Add(Cont);
173   }
174   
175   Henri.Perform();
176
177   Standard_Real ErrG0 = 1.1*Henri.G0Error();
178   //std::cout<<" dist. max = "<<Henri.G0Error()<<" ; angle max = "<<Henri.G1Error()<<std::endl;
179   di<<" dist. max = "<<Henri.G0Error()<<" ; angle max = "<<Henri.G1Error()<<"\n";
180
181   BRepBuilderAPI_MakeWire MW;
182   for (i=1 ; i<=NbCurFront ; i++) {
183     Standard_Integer iInOrder=Henri.Order()->Value(i);
184     TopoDS_Edge E;
185     if (Henri.Sense()->Value(iInOrder)==1) { 
186       BRepBuilderAPI_MakeEdge ME(Henri.Curves2d()->Value(iInOrder),
187                           Henri.Surface(),
188                           Fronts->Value(iInOrder)->LastParameter(),
189                           Fronts->Value(iInOrder)->FirstParameter());
190       E = ME.Edge();
191       
192     }
193     else {
194       BRepBuilderAPI_MakeEdge ME(Henri.Curves2d()->Value(iInOrder),
195                           Henri.Surface(),
196                           Fronts->Value(iInOrder)->FirstParameter(),
197                           Fronts->Value(iInOrder)->LastParameter());
198       E = ME.Edge();
199     }
200     B.UpdateVertex(TopExp::FirstVertex(E), ErrG0);
201     B.UpdateVertex(TopExp::LastVertex(E), ErrG0);
202     BRepLib::BuildCurve3d(E);
203     char name[100];
204     Sprintf(name,"Edge_%d", i);
205     DBRep::Set(name, E);
206     MW.Add(E);
207     if (MW.IsDone()==Standard_False) {
208       throw Standard_Failure("mkWire is over ");
209     }
210       
211   }
212   TopoDS_Wire W;
213   W=MW.Wire();
214   if (!(W.Closed())) throw Standard_Failure("Wire is not closed");
215   BRepBuilderAPI_MakeFace MF(Henri.Surface(),W,Standard_True);
216   DBRep::Set(a[1],MF.Face());
217   return 0;
218 }
219
220 //////////////////////////////////////////////////////////////////////////////// 
221 //  commande gplate : resultat face egale a la surface approchee
222 //////////////////////////////////////////////////////////////////////////////// 
223  
224 static Standard_Integer gplate (Draw_Interpretor & ,Standard_Integer n,const char** a)
225 {
226   if (n < 6 ) return 1; 
227   Standard_Integer NbCurFront=Draw::Atoi(a[2]),
228   NbPointConstraint=Draw::Atoi(a[3]);
229   
230   GeomPlate_BuildPlateSurface Henri(3,15,2);
231   
232   Standard_Integer i;
233   Standard_Integer Conti;
234   Standard_Integer Indice=4;
235 //Surface d'init  
236   TopoDS_Shape aLocalFace(DBRep::Get(a[Indice++],TopAbs_FACE));
237   TopoDS_Face SI = TopoDS::Face(aLocalFace);
238 //  TopoDS_Face SI = TopoDS::Face(DBRep::Get(a[Indice++],TopAbs_FACE));
239   if(SI.IsNull()) 
240     Indice--;
241   else
242     { Handle(BRepAdaptor_HSurface) HSI = new BRepAdaptor_HSurface();
243       HSI->ChangeSurface().Initialize(SI);
244       Henri.LoadInitSurface( BRep_Tool::Surface(HSI->ChangeSurface().Face()));
245     }
246   for (i=1; i<=NbCurFront ; i++) { 
247     TopoDS_Shape aLocalShape(DBRep::Get(a[Indice++],TopAbs_EDGE));
248     TopoDS_Edge E = TopoDS::Edge(aLocalShape);
249 //    TopoDS_Edge E = TopoDS::Edge(DBRep::Get(a[Indice++],TopAbs_EDGE));
250     if(E.IsNull()) return 1;
251     Conti=Draw::Atoi(a[Indice++]);
252     if ((Conti==0)||(Conti==-1))
253       { Handle(BRepAdaptor_HCurve) C = new BRepAdaptor_HCurve();
254         C->ChangeCurve().Initialize(E);
255         const Handle(Adaptor3d_HCurve)& aC = C; // to avoid ambiguity
256         Handle(GeomPlate_CurveConstraint) Cont= new BRepFill_CurveConstraint(aC,Conti);
257         Henri.Add(Cont);
258      }
259     else 
260       { 
261         aLocalFace = DBRep::Get(a[Indice++],TopAbs_FACE);
262         TopoDS_Face F = TopoDS::Face(aLocalFace);
263 //      TopoDS_Face F = TopoDS::Face(DBRep::Get(a[Indice++],TopAbs_FACE));
264         if(F.IsNull()) 
265           return 1;
266         Handle(BRepAdaptor_HSurface) S = new BRepAdaptor_HSurface();
267         S->ChangeSurface().Initialize(F);
268         Handle(BRepAdaptor_HCurve2d) C = new BRepAdaptor_HCurve2d();
269         C->ChangeCurve2d().Initialize(E,F);
270         Adaptor3d_CurveOnSurface ConS(C,S);
271         Handle (Adaptor3d_HCurveOnSurface) HConS = new Adaptor3d_HCurveOnSurface(ConS);
272         Handle(GeomPlate_CurveConstraint) Cont= new BRepFill_CurveConstraint(HConS,Conti);
273         Henri.Add(Cont);
274       }
275   }
276   
277   for (i=1; i<=NbPointConstraint ; i++) 
278     { 
279 //      gp_Pnt P1,P2,P3;
280       gp_Pnt P1;
281 //      gp_Vec V1,V2,V3,V4,V5;
282
283       if (DrawTrSurf::GetPoint(a[Indice], P1) ) 
284         { Conti=0;
285           Handle(GeomPlate_PointConstraint) PCont= new GeomPlate_PointConstraint(P1,0);
286           Henri.Add(PCont);
287           Indice++;
288         }
289       else
290         { Standard_Real u=Draw::Atof(a[Indice++]), 
291                         v=Draw::Atof(a[Indice++]);
292
293           Conti=Draw::Atoi(a[Indice++]);
294           aLocalFace = DBRep::Get(a[Indice++],TopAbs_FACE);
295           TopoDS_Face F = TopoDS::Face(aLocalFace);
296 //        TopoDS_Face F = TopoDS::Face(DBRep::Get(a[Indice++],TopAbs_FACE));
297           if(F.IsNull()) 
298             return 1;   
299           Handle(BRepAdaptor_HSurface) HF = new BRepAdaptor_HSurface();
300           HF->ChangeSurface().Initialize(F);
301           Handle(GeomPlate_PointConstraint) PCont= new GeomPlate_PointConstraint(u,v,BRep_Tool::Surface(HF->ChangeSurface().Face()),Conti,0.001,0.001,0.001);
302           Henri.Add(PCont);
303         }
304     }    
305   Henri.Perform();
306   Standard_Integer nbcarreau=9;
307   Standard_Integer degmax=8;
308   Standard_Real seuil;
309
310   Handle(GeomPlate_Surface) gpPlate = Henri.Surface();
311   TColgp_SequenceOfXY S2d;
312   TColgp_SequenceOfXYZ S3d;
313   S2d.Clear();
314   S3d.Clear();
315   Henri.Disc2dContour(4,S2d);
316   Henri.Disc3dContour(4,0,S3d);
317   seuil = Max(0.0001,10*Henri.G0Error());
318   GeomPlate_PlateG0Criterion critere (S2d,S3d,seuil);
319   GeomPlate_MakeApprox Mapp(gpPlate,critere,0.0001,nbcarreau,degmax);
320   Handle (Geom_Surface) Surf (Mapp.Surface());
321
322   Standard_Real Umin, Umax, Vmin, Vmax;
323   
324   Henri.Surface()->Bounds( Umin, Umax, Vmin, Vmax);
325   
326   BRepBuilderAPI_MakeFace MF(Surf, Umin, Umax, Vmin, Vmax, Precision::Confusion());
327   
328   DBRep::Set(a[1],MF.Face());
329   return 0;
330 }
331
332
333 //////////////////////////////////////////////////////////////////////////////// 
334 //  commande approxplate : resultat face sur surface approchee
335 //////////////////////////////////////////////////////////////////////////////// 
336
337 static Standard_Integer approxplate (Draw_Interpretor & di,Standard_Integer n,const char** a)
338 {
339   if (n < 9 ) return 1;
340   Standard_Integer NbMedium=Draw::Atoi(a[2]);
341   Standard_Integer NbCurFront=Draw::Atoi(a[3]);
342   Handle(GeomPlate_HArray1OfHCurve) Fronts = new GeomPlate_HArray1OfHCurve(1,NbCurFront);
343   Handle(TColStd_HArray1OfInteger) Tang = new TColStd_HArray1OfInteger(1,NbCurFront);
344   Handle(TColStd_HArray1OfInteger) NbPtsCur = new TColStd_HArray1OfInteger(1,NbCurFront);
345   
346   GeomPlate_BuildPlateSurface Henri(3,15,2);
347
348   Standard_Integer i;
349   for (i=1; i<=NbCurFront ; i++) { 
350     TopoDS_Shape aLocalShape(DBRep::Get(a[3*i+1],TopAbs_EDGE));
351     TopoDS_Edge E = TopoDS::Edge(aLocalShape);
352 //    TopoDS_Edge E = TopoDS::Edge(DBRep::Get(a[3*i+1],TopAbs_EDGE));
353     if(E.IsNull()) return 1;
354     TopoDS_Shape aLocalFace(DBRep::Get(a[3*i+2],TopAbs_FACE));
355     TopoDS_Face F = TopoDS::Face(aLocalFace);
356 //    TopoDS_Face F = TopoDS::Face(DBRep::Get(a[3*i+2],TopAbs_FACE));
357     if(F.IsNull()) return 1;
358     Standard_Integer T = Draw::Atoi(a[3*i+3]);
359     Tang->SetValue(i,T);
360     NbPtsCur->SetValue(i,NbMedium);
361     Handle(BRepAdaptor_HSurface) S = new BRepAdaptor_HSurface();
362     S->ChangeSurface().Initialize(F);
363     Handle(BRepAdaptor_HCurve2d) C = new BRepAdaptor_HCurve2d();
364     C->ChangeCurve2d().Initialize(E,F);
365     Adaptor3d_CurveOnSurface ConS(C,S);
366     Handle (Adaptor3d_HCurveOnSurface) HConS = new Adaptor3d_HCurveOnSurface(ConS);
367     Fronts->SetValue(i,HConS);
368     Handle(GeomPlate_CurveConstraint) Cont
369       = new BRepFill_CurveConstraint(HConS,
370                                      Tang->Value(i),
371                                      NbPtsCur->Value(i));
372     Henri.Add(Cont);
373   }
374   
375   Henri.Perform();
376
377   Standard_Real dmax = Henri.G0Error(),
378                 anmax = Henri.G1Error();
379   //std::cout<<" dist. max = "<<dmax<<" ; angle max = "<<anmax<<std::endl;
380   di<<" dist. max = "<<dmax<<" ; angle max = "<<anmax<<"\n";
381
382   Tol3d = Draw::Atof(a[3*NbCurFront+4]);
383   Standard_Integer Nbmax = Draw::Atoi(a[3*NbCurFront+5]);
384   Standard_Integer degmax = Draw::Atoi(a[3*NbCurFront+6]);
385   Standard_Integer CritOrder = Draw::Atoi(a[3*NbCurFront+7]);
386   Handle(GeomPlate_Surface) surf = Henri.Surface();
387   Handle(Geom_BSplineSurface) support;
388
389   if (CritOrder==-1) {
390     GeomPlate_MakeApprox MApp(surf,Tol3d,Nbmax,degmax,dmax,-1);
391     support = MApp.Surface();
392   }
393   else if (CritOrder>=0) {
394     TColgp_SequenceOfXY S2d;
395     TColgp_SequenceOfXYZ S3d;
396     S2d.Clear();
397     S3d.Clear();
398     Standard_Real seuil;
399     if (CritOrder==0) {
400       Henri.Disc2dContour(4,S2d);
401       Henri.Disc3dContour(4,0,S3d);
402       seuil = Max(Tol3d,dmax*10);
403       GeomPlate_PlateG0Criterion Crit0(S2d,S3d,seuil);
404       GeomPlate_MakeApprox MApp(surf,Crit0,Tol3d,Nbmax,degmax);
405       support = MApp.Surface();
406     }
407     else if (CritOrder==1) {
408       Henri.Disc2dContour(4,S2d);
409       Henri.Disc3dContour(4,1,S3d);
410       seuil = Max(Tol3d,anmax*10);
411       GeomPlate_PlateG1Criterion Crit1(S2d,S3d,seuil);
412       GeomPlate_MakeApprox MApp(surf,Crit1,Tol3d,Nbmax,degmax);
413       support = MApp.Surface();
414     }
415   }
416
417   BRepBuilderAPI_MakeWire MW;
418   BRep_Builder B;
419   for (i=1 ; i<=NbCurFront ; i++) {
420     Standard_Integer iInOrder=Henri.Order()->Value(i);
421     TopoDS_Edge E;
422     if (Henri.Sense()->Value(iInOrder)==1) { 
423       BRepBuilderAPI_MakeEdge ME(Henri.Curves2d()->Value(iInOrder),
424                           support,
425                           Fronts->Value(iInOrder)->LastParameter(),
426                           Fronts->Value(iInOrder)->FirstParameter());
427       E = ME.Edge();
428     }
429     else {
430       BRepBuilderAPI_MakeEdge ME(Henri.Curves2d()->Value(iInOrder),
431                           support,
432                           Fronts->Value(iInOrder)->FirstParameter(),
433                           Fronts->Value(iInOrder)->LastParameter());
434       E = ME.Edge();
435     }
436     B.UpdateVertex(TopExp::FirstVertex(E), dmax);
437     B.UpdateVertex(TopExp::LastVertex(E), dmax);
438     BRepLib::BuildCurve3d(E);
439     MW.Add(E);
440     if (MW.IsDone()==Standard_False) {
441       throw Standard_Failure("mkWire is over ");
442     }
443   }
444   TopoDS_Wire W;
445   W=MW.Wire();
446   if (!(W.Closed())) throw Standard_Failure("Wire is not closed");
447   BRepBuilderAPI_MakeFace MF(support,W,Standard_True);
448   DBRep::Set(a[1],MF.Face());
449
450   return 0;
451 }
452
453 static Standard_Integer filling( Draw_Interpretor & di, Standard_Integer n, const char** a )
454 {
455 #ifdef OCCT_DEBUG
456   // Chronometrage
457   OSD_Chronometer Chrono;
458   Chrono.Reset();
459   Chrono.Start();
460 #endif
461
462   if (n < 7)
463   {
464     di.PrintHelp(a[0]);
465     return 1;
466   }
467   
468   Standard_Integer NbBounds = Draw::Atoi( a[2] );
469   Standard_Integer NbConstraints = Draw::Atoi( a[3] );
470   Standard_Integer NbPoints = Draw::Atoi( a[4] );
471
472   BRepOffsetAPI_MakeFilling MakeFilling( Degree,
473                                    NbPtsOnCur,
474                                    NbIter,
475                                    Anisotropie,
476                                    Tol2d,
477                                    Tol3d,
478                                    TolAng,
479                                    TolCurv,
480                                    MaxDeg,
481                                    MaxSegments );
482   TopoDS_Face InitFace = TopoDS::Face( DBRep::Get(a[5], TopAbs_FACE) );
483   if (! InitFace.IsNull())
484     MakeFilling.LoadInitSurface( InitFace );
485   
486   Standard_Integer i = (InitFace.IsNull())? 5 : 6, k;
487   TopoDS_Edge E;
488   TopoDS_Face F;
489   gp_Pnt Point;
490   Standard_Integer Order;
491   TopTools_ListOfShape ListForHistory;
492   for (k = 1; k <= NbBounds; k++)
493   { 
494     E.Nullify();
495     F.Nullify();
496     E = TopoDS::Edge( DBRep::Get(a[i], TopAbs_EDGE) );
497     if (! E.IsNull())
498       i++;
499     F = TopoDS::Face( DBRep::Get(a[i], TopAbs_FACE) );
500     if (! F.IsNull())
501       i++;
502     
503     Order = Draw::Atoi( a[i++] );
504     
505     if (! E.IsNull() && ! F.IsNull())
506       MakeFilling.Add( E, F, (GeomAbs_Shape)Order );
507     else if (E.IsNull())
508     {
509       if (F.IsNull())
510       {
511         di<<"\nWrong parameters\n\n";
512         return 1;
513       }
514       else
515         MakeFilling.Add( F, (GeomAbs_Shape)Order );
516     }
517     else
518       MakeFilling.Add( E, (GeomAbs_Shape)Order );
519
520     //History 
521     if (!E.IsNull())
522       ListForHistory.Append(E);
523   }
524   for (k = 1; k <= NbConstraints; k++)
525   { 
526     E.Nullify();
527     F.Nullify();
528     E = TopoDS::Edge( DBRep::Get(a[i++], TopAbs_EDGE) );
529     if (E.IsNull())
530     {
531       di<<"Wrong parameters\n";
532       return 1;
533     }
534     F = TopoDS::Face( DBRep::Get(a[i], TopAbs_FACE) );
535     if (! F.IsNull())
536       i++;
537     
538     Order = Draw::Atoi( a[i++] );
539     
540     if (F.IsNull())
541       MakeFilling.Add( E, (GeomAbs_Shape)Order, Standard_False );
542     else
543       MakeFilling.Add( E, F, (GeomAbs_Shape)Order, Standard_False );
544   }
545   for (k = 1; k <= NbPoints; k++)
546   {
547     if (DrawTrSurf::GetPoint( a[i], Point )) 
548     {
549       MakeFilling.Add( Point );
550       i++;
551     }
552     else
553     {
554       Standard_Real U = Draw::Atof( a[i++] ), V = Draw::Atof( a[i++] );
555       F = TopoDS::Face( DBRep::Get(a[i++], TopAbs_FACE));
556       if (F.IsNull()) 
557       {
558         di<<"Wrong parameters\n";
559         return 1;
560       }
561       Order = Draw::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     di<<"filling failed\n";
571     return 0;
572   }
573   
574   Standard_Real dmax = MakeFilling.G0Error(),
575     angmax = MakeFilling.G1Error(),
576     curvmax = MakeFilling.G2Error();
577   di<<" dist. max = "<<dmax<<" ; angle max = "<<angmax<<" ; diffcurv max = "<<curvmax<<"\n";
578   
579   TopoDS_Face ResFace= TopoDS::Face( MakeFilling.Shape() );
580   DBRep::Set( a[1], ResFace );
581
582 #ifdef OCCT_DEBUG
583   Chrono.Stop();
584   Standard_Real Tps;
585   Chrono.Show(Tps);
586   di<<"*** FIN DE FILLING ***\n";
587   di<<"Temps de calcul  : "<<Tps<<"\n";
588 #endif
589
590   //History 
591   if (BRepTest_Objects::IsHistoryNeeded())
592     BRepTest_Objects::SetHistory(ListForHistory, MakeFilling);
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     //std::cout << "fillingparam : options are"  <<std::endl;
602     //std::cout << "-l : to list current values" << std::endl;
603     //std::cout << "-i : to set default values"   << std::endl;
604     //std::cout << "-r deg nbPonC nbIt anis : to set filling options" <<std::endl;
605     //std::cout << "-c t2d t3d tang tcur : to set tolerances" << std::endl;
606     //std::cout << "-a maxdeg maxseg : Approximation option" << std::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           //std::cout<<std::endl;
622           //std::cout<<"Degree = "<<Degree<<std::endl;
623           //std::cout<<"NbPtsOnCur = "<<NbPtsOnCur<<std::endl;
624           //std::cout<<"NbIter = "<<NbIter<<std::endl;
625           //std::cout<<"Anisotropie = "<<Anisotropie<<std::endl<<std::endl;
626           //
627           //std::cout<<"Tol2d = "<<Tol2d<<std::endl;
628           //std::cout<<"Tol3d = "<<Tol3d<<std::endl;
629           //std::cout<<"TolAng = "<<TolAng<<std::endl;
630           //std::cout<<"TolCurv = "<<TolCurv<<std::endl<<std::endl;
631           //
632           //std::cout<<"MaxDeg = "<<MaxDeg<<std::endl;
633           //std::cout<<"MaxSegments = "<<MaxSegments<<std::endl<<std::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      = Draw::Atoi( a[2] );
666           NbPtsOnCur  = Draw::Atoi( a[3] );
667           NbIter      = Draw::Atoi( a[4] );
668           Anisotropie = Draw::Atoi( a[5] ) != 0;
669         }
670       else if (strcmp( flag, "-c" ) == 0 && n == 6)
671         {
672           Tol2d   = Draw::Atof( a[2] ); 
673           Tol3d   = Draw::Atof( a[3] );
674           TolAng  = Draw::Atof( a[4] );
675           TolCurv = Draw::Atof( a[5] );
676         }
677       else if (strcmp( flag, "-a" ) == 0 && n == 4)
678         {
679           MaxDeg      = Draw::Atoi( a[2] );
680           MaxSegments = Draw::Atoi( a[3] );
681         }
682       else
683         {
684           //std::cout<<"Wrong parameters"<<std::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 }