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