0024059: Eliminate compiler warning C4701 in MSVC++ with warning level 4
[occt.git] / src / GeomliteTest / GeomliteTest_ApproxCommands.cxx
1 // Created on: 1993-08-12
2 // Created by: Bruno DUMORTIER
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
5 //
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
10 //
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 //
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
20
21
22 // PMN : Ajout de la commande smooth
23 // PMN : 11/07/97 Passage a GeomliteTest de bsmooth.
24
25 #include <Standard_Stream.hxx>
26
27 #include <GeomliteTest.hxx>
28 #include <DrawTrSurf.hxx>
29 #include <Draw.hxx>
30 #include <Draw_Appli.hxx>
31 #include <Draw_Interpretor.hxx>
32 #include <Precision.hxx>
33 #include <Draw_Marker3D.hxx>
34 #include <Draw_Marker2D.hxx>
35 #include <TColgp_HArray1OfPnt.hxx>
36 #include <TColgp_SequenceOfPnt.hxx>
37 #include <Geom_BSplineCurve.hxx>
38 #include <Geom_BezierCurve.hxx>
39 #include <TColgp_HArray1OfPnt2d.hxx>
40 #include <TColgp_SequenceOfPnt2d.hxx>
41
42 #include <Geom2d_BSplineCurve.hxx>
43 #include <Geom2d_BezierCurve.hxx>
44 #include <DrawTrSurf_BSplineCurve.hxx>
45 #include <DrawTrSurf_BezierCurve.hxx>
46 #include <DrawTrSurf_BSplineCurve2d.hxx>
47 #include <DrawTrSurf_BezierCurve2d.hxx>
48 #include <TColgp_HArray1OfPnt.hxx>
49 #include <TColgp_Array1OfPnt.hxx>
50 #include <TColgp_Array1OfPnt2d.hxx>
51 #include <TColgp_HArray1OfVec.hxx>
52 #include <TColgp_Array1OfVec.hxx>
53 #include <TColStd_Array1OfReal.hxx>
54 #include <TColStd_HArray1OfReal.hxx>
55 #include <TColStd_HArray1OfBoolean.hxx>
56 #include <Handle_TColStd_HArray1OfReal.hxx>
57 #include <Handle_TColStd_HArray1OfBoolean.hxx>
58
59 #include <AppParCurves_MultiBSpCurve.hxx>
60 #include <AppParCurves_MultiCurve.hxx>
61 #include <AppDef_MultiLine.hxx>
62 #include <AppDef_TheVariational.hxx>
63 #include <AppDef_Compute.hxx>
64 #include <AppParCurves_HArray1OfConstraintCouple.hxx>
65 #include <AppParCurves_ConstraintCouple.hxx>
66 #include <AppDef_HArray1OfMultiPointConstraint.hxx>
67 #include <AppDef_Array1OfMultiPointConstraint.hxx>
68 #include <math_Vector.hxx>
69
70 #ifdef WNT
71 #include <stdio.h>
72 Standard_IMPORT Draw_Viewer dout;
73 #endif
74
75 //Draw_Color DrawTrSurf_CurveColor(const Draw_Color);
76
77 //=======================================================================
78 //function :  NbConstraint
79 //=======================================================================
80 static Standard_Integer  NbConstraint(const AppParCurves_Constraint C1,
81                                       const AppParCurves_Constraint C2)
82 {
83    Standard_Integer N =0;
84    switch (C1) {
85    case  AppParCurves_PassPoint : 
86      {
87        N = 1;
88        break;
89      }
90    case  AppParCurves_TangencyPoint : 
91      {
92        N =2;
93        break;
94      }
95    case  AppParCurves_CurvaturePoint : 
96      {
97        N = 3;
98        break;
99      }     
100    default:
101        break;
102    }
103
104    switch (C2) {
105    case  AppParCurves_PassPoint : 
106      {
107        N++;
108        break;
109      }
110    case  AppParCurves_TangencyPoint : 
111      {
112        N += 2;
113        break;
114      }
115    case  AppParCurves_CurvaturePoint : 
116      {
117        N += 3;
118        break;
119      }     
120    default:
121        break;
122    }
123    return N;
124 }
125 //=======================================================================
126 //function : PointsByPick
127 //=======================================================================
128 static Standard_Integer PointsByPick
129        (Handle(AppDef_HArray1OfMultiPointConstraint)& MPC, Draw_Interpretor& di)
130 {
131  Standard_Integer id,XX,YY,b, i;
132  
133  di << "Pick points "<< "\n";
134  dout.Select(id, XX, YY, b);
135  Standard_Real zoom = dout.Zoom(id);
136  if (b != 1) return 0;
137  if (id < 0) return 0;
138  gp_Pnt P;
139  gp_Pnt2d P2d;
140
141  //Standard_Boolean newcurve;
142     
143  if (dout.Is3D(id)) {
144    // Cas du 3D -------
145    Handle(Draw_Marker3D) mark;
146    TColgp_SequenceOfPnt ThePoints;
147    P.SetCoord((Standard_Real)XX/zoom,(Standard_Real)YY/zoom, 0.0);
148    ThePoints.Append (P);
149    mark = new Draw_Marker3D(P, Draw_X, Draw_orange);
150    dout << mark;
151    dout.Flush();
152    i = 1;
153       
154    while (b != 3) {
155      dout.Select(id,XX,YY,b, Standard_False);
156      if (b == 1) { 
157        i++;
158        P.SetCoord( (Standard_Real)XX/zoom,
159                   (Standard_Real)YY/zoom, 0.0);
160        ThePoints.Append(P);
161        mark = new Draw_Marker3D(P, Draw_X, Draw_orange);
162        dout << mark;
163        dout.Flush();
164      }
165    }
166
167    MPC = new (AppDef_HArray1OfMultiPointConstraint)(1, ThePoints.Length());
168    AppDef_MultiPointConstraint mpc(1,0);
169    MPC->ChangeArray1().Init(mpc);
170    for (i=1; i<=ThePoints.Length(); i++) {
171       AppDef_MultiPointConstraint mpc(1,0);
172       mpc.SetPoint(1, ThePoints.Value(i));
173       MPC->SetValue(i, mpc); 
174    }  
175  }
176  
177  else {
178    // Cas du 2D -------
179    Handle(Draw_Marker2D) mark;
180    TColgp_SequenceOfPnt2d ThePoints;
181    P2d.SetCoord((Standard_Real)XX/zoom,(Standard_Real)YY/zoom);
182    ThePoints.Append(P2d);
183    mark = new Draw_Marker2D(P2d, Draw_X, Draw_orange);
184    dout << mark;
185    dout.Flush();
186    i = 1;
187       
188    while (b != 3) {
189      dout.Select(id,XX,YY,b, Standard_False);
190      
191      if (b == 1) { 
192        i++;
193        P2d.SetCoord( (Standard_Real)XX/zoom, (Standard_Real)YY/zoom );
194        ThePoints.Append (P2d);
195        mark = new Draw_Marker2D(P2d, Draw_X, Draw_orange);
196        dout << mark;
197        dout.Flush();
198      }
199    }
200
201    MPC = new (AppDef_HArray1OfMultiPointConstraint)(1, ThePoints.Length());
202    for (i=1; i<=ThePoints.Length(); i++) {
203      AppDef_MultiPointConstraint mpc(0,1);
204      mpc.SetPoint2d(1, ThePoints.Value(i));
205      MPC->SetValue(i,  mpc);
206    }
207  }
208  return id;
209 }
210
211 //=======================================================================
212 //function : PointsByFile
213 //=======================================================================
214 static void PointsByFile(Handle(AppDef_HArray1OfMultiPointConstraint)& MPC,
215                          Handle(AppParCurves_HArray1OfConstraintCouple)& TABofCC,
216                          ifstream& iFile,
217                          Draw_Interpretor& di)
218 {
219   Standard_Integer nbp, i, nbc;
220   char c;
221   Standard_Real x, y, z;
222
223   iFile >> nbp;
224   char dimen[3];
225   iFile >> dimen;
226
227   if (!strcmp(dimen,"3d")) {
228     Handle(Draw_Marker3D) mark;
229     MPC = new (AppDef_HArray1OfMultiPointConstraint)(1, nbp);
230
231     for (i = 1; i <= nbp; i++) {
232       iFile >> x >> y >> z;
233       AppDef_MultiPointConstraint mpc(1,0);
234       mpc.SetPoint(1, gp_Pnt(x, y, z));
235       MPC->SetValue(i,mpc);
236       mark = new Draw_Marker3D(gp_Pnt(x, y, z), Draw_X, Draw_orange);
237       dout << mark;
238     }
239     Standard_Boolean HasConstrainte = Standard_False;
240     if (iFile.get(c)) {
241       if ( IsControl( (Standard_Character)c) ) {   
242         if (iFile.get(c))  HasConstrainte = Standard_True;
243       }
244       else  HasConstrainte = Standard_True;
245     }
246
247     if (HasConstrainte) {
248       Standard_Integer num, ordre;
249       iFile >> nbc;
250       if ((nbc < 1) || (nbc>nbp)) return; // Y a comme un probleme
251       AppParCurves_Constraint  Constraint = AppParCurves_NoConstraint;
252       TABofCC = new AppParCurves_HArray1OfConstraintCouple(1, nbp);
253       for(i=1; i<=nbp; i++){
254         AppParCurves_ConstraintCouple ACC(i,Constraint);
255         TABofCC->SetValue(i,ACC);
256       }
257       for(i=1; i<=nbc; i++) {
258         iFile >> num >> ordre;
259         if ((num<1)||(num>nbp)) {
260           di << "Error on point Index in constrainte" << "\n";
261           return;
262         }
263         Constraint = (AppParCurves_Constraint) (ordre+1);
264         TABofCC->ChangeValue(num).SetConstraint(Constraint);
265         if (Constraint >=  AppParCurves_TangencyPoint) {
266           iFile >> x >> y >> z;
267           MPC->ChangeValue(num).SetTang(1, gp_Vec(x,y,z));
268         }
269         if (Constraint >=  AppParCurves_CurvaturePoint) {
270           iFile >> x >> y >> z;
271           MPC->ChangeValue(num).SetCurv(1, gp_Vec(x,y,z));
272         }
273       }
274     }
275     
276   }
277   else if (!strcmp(dimen,"2d")) {
278     Handle(Draw_Marker2D) mark;
279     MPC = new (AppDef_HArray1OfMultiPointConstraint)(1, nbp);
280
281     for (i = 1; i <= nbp; i++) {
282       iFile >> x >> y;
283       AppDef_MultiPointConstraint mpc(0,1);
284       mpc.SetPoint2d(1, gp_Pnt2d(x, y));
285       MPC->SetValue(i, mpc);
286       mark = new Draw_Marker2D(gp_Pnt2d(x, y), Draw_X, Draw_orange);
287       dout << mark;
288     }
289
290     Standard_Boolean HasConstrainte = Standard_False;
291     if (iFile.get(c)) {
292       if ( IsControl( (Standard_Character)c) )  {
293         if (iFile.get(c))  HasConstrainte = Standard_True;
294       }
295       else  HasConstrainte = Standard_True;
296     }
297
298     if (HasConstrainte) {
299       Standard_Integer num, ordre;
300       iFile >> nbc;
301       if ((nbc < 1) || (nbc>nbp)) return; // Y a comme un probleme
302       AppParCurves_Constraint  Constraint = AppParCurves_NoConstraint;
303       TABofCC = new AppParCurves_HArray1OfConstraintCouple(1, nbp);
304       for(i=1; i<=nbp; i++){
305         AppParCurves_ConstraintCouple ACC(i,Constraint);
306         TABofCC->SetValue(i,ACC);
307       }
308       for(i=1; i<=nbc; i++) {
309         iFile >> num >> ordre;
310         if ((num<1)||(num>nbp)) {
311           di << "Error on point Index in constrainte" << "\n";
312           return;
313         }
314         Constraint = (AppParCurves_Constraint) (ordre+1);
315         TABofCC->ChangeValue(num).SetConstraint(Constraint);
316         if (Constraint >=  AppParCurves_TangencyPoint) {
317           iFile >> x >> y;
318           MPC->ChangeValue(num).SetTang2d(1, gp_Vec2d(x,y));
319         }
320         if (Constraint >=  AppParCurves_CurvaturePoint) {
321           iFile >> x >> y;
322           MPC->ChangeValue(num).SetCurv2d(1, gp_Vec2d(x,y));
323         }
324       }
325     }
326   }  
327 }
328
329
330
331 //==================================================================================
332 static Standard_Integer smoothing (Draw_Interpretor& di,Standard_Integer n, const char** a)
333 //==================================================================================
334 //  Tolerance < 0 lissage "filtre"
335 //  Tolerance > 0 lissage avec respect de l'erreur max
336 //  Tolerance = 0 interpolation.
337 //
338 {
339   Standard_Real Tolerance=0;
340
341   AppParCurves_Constraint  Constraint=AppParCurves_NoConstraint;
342
343   Handle(AppParCurves_HArray1OfConstraintCouple)TABofCC;
344   TABofCC.Nullify();
345   Handle(AppDef_HArray1OfMultiPointConstraint) Points;
346   Standard_Integer id = 0, DegMax = -1;
347
348   if (n == 1) {
349     di <<"give a name to your curve !" << "\n";
350     return 0;
351   }
352   if (n == 2) {
353     di <<"give a tolerance to your curve !" << "\n";
354     return 0;
355   }
356   if (n == 3) {
357     Tolerance = Draw::Atof(a[2]);
358     if (Abs(Tolerance) < Precision::Confusion()*1.e-7)  {
359       Constraint = AppParCurves_PassPoint;
360     }
361     else {
362       Constraint = AppParCurves_NoConstraint;
363     } 
364     // Designation Graphique ------------------------
365     id = PointsByPick(Points, di);
366   }
367   else if (n >= 4) {
368     Standard_Integer ific = 3;
369     Tolerance = Draw::Atof(a[2]);
370     if (Abs(Tolerance) < Precision::Confusion()*1.e-7)  {
371       Constraint = AppParCurves_PassPoint;
372     }
373     else {
374       Constraint = AppParCurves_NoConstraint;
375     }
376
377     if (! strcmp(a[3],"-D")) {
378        DegMax = Draw::Atoi(a[4]);
379        ific = 5;
380     }
381     
382     if (n > ific) {
383       // lecture du fichier.
384     // nbpoints, 2d ou 3d, puis valeurs.
385       const char* nomfic = a[ific];
386       ifstream iFile(nomfic, ios::in);
387       if (!iFile) { 
388         di << a[ific] <<"do not exist !" << "\n";
389         return 1;
390       }
391       PointsByFile(Points, TABofCC, iFile, di);
392     }
393     else {
394     // Designation Graphique
395     id = PointsByPick(Points, di);
396     }
397   }
398
399   AppDef_MultiLine AML(Points->Array1());
400
401   // Compute --------------
402   Standard_Integer i;
403   if (Points->Value(1).NbPoints()==0){
404     // Cas 2d
405     Handle(TColgp_HArray1OfPnt2d) ThePoints;
406     // Calcul du lissage
407     Standard_Integer NbPoints = Points->Length();
408     if (TABofCC.IsNull()) {
409       TABofCC = new AppParCurves_HArray1OfConstraintCouple(1, NbPoints);
410       for(i=1; i<=NbPoints; i++){
411         AppParCurves_ConstraintCouple ACC(i,Constraint);
412         TABofCC->SetValue(i,ACC);
413       }
414     }
415
416     AppDef_TheVariational Variation(AML, 
417                                     1, NbPoints,
418                                     TABofCC);
419     
420     if (DegMax > 0) {
421       if (DegMax < 3) Variation.SetContinuity(GeomAbs_C0);
422       else if (DegMax <5) Variation.SetContinuity(GeomAbs_C1);
423       Variation.SetMaxDegree(DegMax);
424     }
425     Variation.SetTolerance( Abs(Tolerance));
426     if (Tolerance>0) { Variation.SetWithMinMax(Standard_True);}
427     Variation.Approximate();
428
429 #  ifdef DEB
430     //Variation.Dump(cout);
431     Standard_SStream aSStream;
432     Variation.Dump(aSStream);
433     di << aSStream;
434 #   endif
435
436     AppParCurves_MultiBSpCurve AnMuC = Variation.Value();
437
438     TColgp_Array1OfPnt2d ThePoles (1,  AnMuC.NbPoles() ); 
439     AnMuC.Curve(1, ThePoles);    
440     Handle(Geom2d_BSplineCurve) Cvliss = new (Geom2d_BSplineCurve)
441       (ThePoles,
442        AnMuC.Knots(),
443        AnMuC. Multiplicities(),
444        AnMuC.Degree() );
445
446     Handle(DrawTrSurf_BSplineCurve2d) 
447       DC = new DrawTrSurf_BSplineCurve2d(Cvliss);
448     DC->ClearPoles();
449     Draw::Set(a[1], DC);
450     if (id!=0) dout.RepaintView(id); 
451   }
452   else {
453     Standard_Integer NbPoints = Points->Length();
454     if (TABofCC.IsNull()) {
455       TABofCC = new AppParCurves_HArray1OfConstraintCouple(1, NbPoints);
456       for(i=1; i<=NbPoints; i++){
457         AppParCurves_ConstraintCouple ACC(i,Constraint);
458         TABofCC->SetValue(i,ACC);
459       }
460     } 
461
462     AppDef_TheVariational Variation(AML, 
463                                     1,  NbPoints,
464                                     TABofCC);
465
466     if (DegMax > 0) {
467       if (DegMax < 3) Variation.SetContinuity(GeomAbs_C0);
468       else if (DegMax <5) Variation.SetContinuity(GeomAbs_C1);
469       Variation.SetMaxDegree(DegMax);
470     }
471     Variation.SetTolerance( Abs(Tolerance));
472     if (Tolerance>0) { Variation.SetWithMinMax(Standard_True);}
473     Variation.Approximate();
474 #     ifdef DEB
475     //Variation.Dump(cout);
476     Standard_SStream aSStream;
477     Variation.Dump(aSStream);
478     di << aSStream;
479 #     endif
480
481     AppParCurves_MultiBSpCurve AnMuC = Variation.Value();
482
483     TColgp_Array1OfPnt ThePoles (1,  AnMuC.NbPoles() ); 
484     AnMuC.Curve(1, ThePoles);    
485     Handle(Geom_BSplineCurve) Cvliss = new (Geom_BSplineCurve)
486       (ThePoles,
487        AnMuC.Knots(),
488        AnMuC. Multiplicities(),
489        AnMuC.Degree() );
490
491     Handle(DrawTrSurf_BSplineCurve) 
492       DC = new DrawTrSurf_BSplineCurve(Cvliss);
493     DC->ClearPoles();
494     Draw::Set(a[1], DC);
495     if (id!=0) dout.RepaintView(id);
496   }
497   return 0;
498 }
499
500 //=============================================================================
501 static Standard_Integer smoothingbybezier (Draw_Interpretor& di,
502                                            Standard_Integer n, 
503                                            const char** a)
504 //============================================================================
505 {
506   Standard_Real Tolerance=0;
507   AppParCurves_Constraint Constraint = AppParCurves_NoConstraint;
508   Handle(AppParCurves_HArray1OfConstraintCouple)TABofCC;
509   Handle(AppDef_HArray1OfMultiPointConstraint) Points;
510
511   Standard_Integer id = 0;
512   Standard_Integer methode=0;
513   Standard_Integer Degree = 8;
514
515   if (n == 1) {
516     di <<"give a name to your curve !" << "\n";
517     return 0;
518   }
519   if (n == 2) {
520     di <<"give a tolerance to your curve !" << "\n";
521     return 0;
522   }
523  if (n == 3) {
524     di <<"give a max degree!" << "\n";
525     return 0;
526   }
527
528   if (n == 4) {
529     di <<"give an option!" << "\n";
530     return 0;
531   }
532   if (n >= 5) {
533     Tolerance = Draw::Atof(a[2]);
534     Degree = Draw::Atoi(a[3]);
535     if (! strcmp(a[4],"-GR")) {
536       methode = 1;
537     }
538     else if (! strcmp(a[4],"-PR")) {
539       methode = 2;
540     }
541     else { methode = 3;}
542     
543     if (Abs(Tolerance) < Precision::Confusion()*1.e-7)  {
544       Constraint = AppParCurves_PassPoint;
545     }
546     else {
547       Constraint = AppParCurves_NoConstraint;
548     } 
549     if (n==5)
550       // Designation Graphique ------------------------
551      id = PointsByPick(Points, di);
552     else {
553       // lecture du fichier.
554       // nbpoints, 2d ou 3d, puis valeurs.
555       const char* nomfic = a[5];
556       ifstream iFile(nomfic, ios::in);
557       if (!iFile) { 
558         di << a[6] <<"do not exist !" << "\n";
559         return 1;
560       }
561       PointsByFile(Points, TABofCC, iFile, di);
562     }
563   }
564     
565   AppDef_MultiLine AML(Points->Array1());  
566
567   // Compute --------------
568   Standard_Integer i;
569   if (Points->Value(1).NbPoints()==0){
570     // Cas 2d
571     Handle(TColgp_HArray1OfPnt2d) ThePoints;
572     // Calcul du lissage
573     Standard_Integer NbPoints = Points->Length();
574     if (TABofCC.IsNull()) {
575       TABofCC = new AppParCurves_HArray1OfConstraintCouple(1, NbPoints);
576       for(i=1; i<=NbPoints; i++){
577         AppParCurves_ConstraintCouple ACC(i,Constraint);
578         TABofCC->SetValue(i,ACC);
579       }
580
581       AppParCurves_ConstraintCouple AC1(1, AppParCurves_PassPoint);
582       if (TABofCC->Value(1).Constraint()<AppParCurves_PassPoint)
583         TABofCC->SetValue(1, AC1);
584     
585       AppParCurves_ConstraintCouple AC2(NbPoints, AppParCurves_PassPoint);
586       if (TABofCC->Value(NbPoints).Constraint()<AppParCurves_PassPoint)
587         TABofCC->SetValue(NbPoints, AC2);
588     }
589
590     if (methode < 3) {
591       Standard_Boolean mySquare = (methode == 2);
592       Standard_Integer degmin = 4;
593       Standard_Integer NbIteration = 5;
594       
595       if (Degree < 4) degmin = Max(1, Degree -1);
596       degmin = Max(degmin, NbConstraint(TABofCC->Value(1).Constraint(),  
597                                         TABofCC->Value(NbPoints).Constraint()) );
598       
599       AppDef_Compute Appr(degmin, Degree,
600                           Abs(Tolerance),  Abs(Tolerance),
601                           NbIteration, Standard_False, 
602                           Approx_ChordLength, mySquare);
603
604      Appr.SetConstraints(TABofCC->Value(1).Constraint(), 
605                           TABofCC->Value(NbPoints).Constraint());
606    
607       Appr.Perform (AML);
608       
609       if (! Appr.IsAllApproximated()) {
610         di << " No result" << "\n";
611       }
612       AppParCurves_MultiCurve AnMuC = Appr.Value();
613       ThePoints = new (TColgp_HArray1OfPnt2d) (1,  AnMuC.NbPoles() );
614       AnMuC.Curve(1, ThePoints->ChangeArray1());
615       Standard_Real err, err2d;
616       Appr.Error(1, err, err2d);
617       di <<" Error2D is : " << err2d << "\n";
618     }
619     else {
620       AppDef_TheVariational Varia(AML, 
621                                   1,  NbPoints,
622                                   TABofCC,
623                                   Degree, 1);
624       Varia.SetTolerance(Abs(Tolerance));
625       Varia.Approximate();
626
627       if (! Varia.IsDone()) {
628         di << " No result" << "\n";
629       }
630
631       AppParCurves_MultiBSpCurve  AnMuC = Varia.Value();
632       di <<" Error2D is : " << Varia.MaxError() << "\n";
633       ThePoints = new (TColgp_HArray1OfPnt2d) (1,  AnMuC.NbPoles() );
634       AnMuC.Curve(1, ThePoints->ChangeArray1());    
635  }
636     
637     Handle(Geom2d_BezierCurve) Cvliss = 
638       new (Geom2d_BezierCurve)(ThePoints->Array1());
639
640     Handle(DrawTrSurf_BezierCurve2d) DC = 
641       new (DrawTrSurf_BezierCurve2d) (Cvliss);
642     Draw::Set(a[1], DC);
643     if (id!=0) dout.RepaintView(id); 
644   }
645   else {
646     // Cas 3d
647     Handle(TColgp_HArray1OfPnt) ThePoints;
648     Standard_Integer NbPoints = Points->Length();
649     if (TABofCC.IsNull()) {
650       TABofCC = new AppParCurves_HArray1OfConstraintCouple(1, NbPoints);
651       for(i=1; i<=NbPoints; i++){
652         AppParCurves_ConstraintCouple ACC(i,Constraint);
653         TABofCC->SetValue(i,ACC);
654       }
655     
656
657       AppParCurves_ConstraintCouple AC1(1, AppParCurves_PassPoint);
658       if (TABofCC->Value(1).Constraint()<AppParCurves_PassPoint)
659         TABofCC->SetValue(1, AC1);
660     
661       AppParCurves_ConstraintCouple AC2(NbPoints, AppParCurves_PassPoint);
662       if (TABofCC->Value(NbPoints).Constraint()<AppParCurves_PassPoint)
663         TABofCC->SetValue(NbPoints, AC2);
664     }
665
666     if (methode < 3) {
667       Standard_Boolean mySquare = (methode == 2);
668       Standard_Integer degmin = 4;
669       Standard_Integer NbIteration = 5;
670       if (Degree < 4) degmin = Max(1, Degree - 1);
671       degmin = Max(degmin, NbConstraint(TABofCC->Value(1).Constraint(),  
672                                         TABofCC->Value(NbPoints).Constraint()) );
673       
674       AppDef_Compute Appr(degmin, Degree,
675                           Abs(Tolerance),  Abs(Tolerance),
676                           NbIteration, Standard_False, 
677                           Approx_ChordLength, mySquare);
678
679       Appr.SetConstraints(TABofCC->Value(1).Constraint(), 
680                           TABofCC->Value(NbPoints).Constraint());
681    
682       Appr.Perform (AML);
683       
684       if (! Appr.IsAllApproximated()) {
685         di << " No result" << "\n";
686       }
687       AppParCurves_MultiCurve AnMuC = Appr.Value();
688       ThePoints = new (TColgp_HArray1OfPnt) (1,  AnMuC.NbPoles() );
689       AnMuC.Curve(1, ThePoints->ChangeArray1());
690       Standard_Real err, err2d;
691       Appr.Error(1, err, err2d);
692       di <<" Error3D is : " << err << "\n";
693     }
694     else {
695       AppDef_TheVariational Varia(AML, 
696                                   1,  NbPoints,
697                                   TABofCC,
698                                   Degree, 1);
699
700       Varia.SetTolerance(Abs(Tolerance));
701       Varia.Approximate();
702       if (! Varia.IsDone()) {
703         di << " No result" << "\n";
704       }
705
706       AppParCurves_MultiBSpCurve  AnMuC = Varia.Value();
707       di <<" Error3D is : " << Varia.MaxError() << "\n";
708       ThePoints = new (TColgp_HArray1OfPnt) (1,  AnMuC.NbPoles() );
709       AnMuC.Curve(1, ThePoints->ChangeArray1());    
710     }    
711
712     Handle(Geom_BezierCurve) Cvliss = 
713       new (Geom_BezierCurve)(ThePoints->Array1());
714
715     Handle(DrawTrSurf_BezierCurve) 
716       DC = new DrawTrSurf_BezierCurve(Cvliss);
717     Draw::Set(a[1], DC);
718     if (id!=0) dout.RepaintView(id);
719   }
720   return 0;
721 }
722
723 //=======================================================================
724 //function : ConstraintCommands
725 //purpose  : 
726 //=======================================================================
727
728
729 void  GeomliteTest::ApproxCommands(Draw_Interpretor& theCommands)
730 {
731
732   static Standard_Boolean loaded = Standard_False;
733   if (loaded) return;
734   loaded = Standard_True;
735
736   DrawTrSurf::BasicCommands(theCommands);
737
738   const char* g;
739   // constrained constructs
740   g = "GEOMETRY Constraints";
741
742
743   theCommands.Add("bsmooth",
744                   "bsmooth cname tol [-D degree] [fic]", 
745                   __FILE__,
746                   smoothing, g);
747
748   theCommands.Add("bzsmooth",
749                   "bzsmooth cname tol degree option [fic]", 
750                   __FILE__,
751                   smoothingbybezier, g);
752 }
753