0024814: Avoid using explicit names of Handle classes
[occt.git] / src / GeometryTest / GeometryTest_ConstraintCommands.cxx
1 // Created on: 1993-08-12
2 // Created by: Bruno DUMORTIER
3 // Copyright (c) 1993-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 // JPI : Commande smooth transferee dans GeomliteTest
18 // PMN : Ajout de la commande smooth
19 // JCT : Correction d'un trap dans la commande gcarc
20
21 #include <Standard_Stream.hxx>
22
23 #include <GeometryTest.hxx>
24 #include <DrawTrSurf.hxx>
25 #include <Draw.hxx>
26 #include <Draw_Appli.hxx>
27 #include <Draw_Interpretor.hxx>
28 #include <Geom2dGcc_Circ2d2TanRad.hxx>
29 #include <Geom2dGcc_Circ2d3Tan.hxx>
30 #include <Geom2dGcc_Circ2d2TanOn.hxx>
31 #include <Geom2dGcc_Circ2dTanOnRad.hxx>
32 #include <Geom2dGcc_Circ2dTanCen.hxx>
33 #include <Geom2dGcc_Lin2d2Tan.hxx>
34 #include <Geom2dGcc_Lin2dTanObl.hxx>
35 #include <Geom2dGcc.hxx>
36 #include <Geom2dGcc_QualifiedCurve.hxx>
37 #include <Geom2d_CartesianPoint.hxx>
38 #include <Geom2d_Circle.hxx>
39 #include <Geom2d_Line.hxx>
40 #include <Precision.hxx>
41 #include <GeomAPI_Interpolate.hxx>
42 #include <Draw_Marker3D.hxx>
43 #include <Geom2dAPI_Interpolate.hxx>
44 #include <Draw_Marker2D.hxx>
45 #include <TColgp_HArray1OfPnt.hxx>
46 #include <Geom_BSplineCurve.hxx>
47 #include <TColgp_HArray1OfPnt2d.hxx>
48 #include <Geom2d_BSplineCurve.hxx>
49 #include <DrawTrSurf_BSplineCurve.hxx>
50 #include <DrawTrSurf_BSplineCurve2d.hxx>
51 #include <TColgp_HArray1OfPnt.hxx>
52 #include <TColgp_Array1OfPnt.hxx>
53 #include <TColgp_Array1OfPnt2d.hxx>
54 #include <TColgp_HArray1OfVec.hxx>
55 #include <TColgp_Array1OfVec.hxx>
56 #include <TColStd_Array1OfReal.hxx>
57 #include <TColStd_HArray1OfReal.hxx>
58 #include <TColStd_HArray1OfBoolean.hxx>
59 #include <AppParCurves_MultiBSpCurve.hxx>
60 #include <AppDef_MultiLine.hxx>
61 #include <AppParCurves_HArray1OfConstraintCouple.hxx>
62 #include <AppParCurves_ConstraintCouple.hxx>
63 #include <GC_MakeSegment.hxx>
64 #include <GC_MakeArcOfCircle.hxx>
65
66 //#ifdef WNT
67 #include <stdio.h>
68 #ifdef WNT
69 Standard_IMPORT Draw_Viewer dout;
70 #endif
71 Standard_IMPORT Draw_Color DrawTrSurf_CurveColor(const Draw_Color);
72
73
74 static Standard_Integer solutions(Draw_Interpretor& di,
75                                   Geom2dGcc_Circ2d2TanRad& ct3, const char* name) 
76 {
77   char solname[200];
78
79   Draw_Color col = DrawTrSurf_CurveColor(Draw_Color(Draw_vert));
80   DrawTrSurf_CurveColor(col);
81
82   if (ct3.IsDone()) {
83     for (Standard_Integer i = 1 ; i <= ct3.NbSolutions() ; i++) {
84       Handle(Geom2d_Circle) C = new Geom2d_Circle(ct3.ThisSolution(i));
85       Sprintf(solname,"%s_%d",name,i);
86       char* temp = solname; // pour portage WNT
87       DrawTrSurf::Set(temp,C);
88       di << solname << " ";
89     }
90     return 0;
91   }
92   else {
93     di << "Circ2d2TanRad Not done";
94     return 1;
95   }
96 }
97
98 static Standard_Integer solutions(Draw_Interpretor& di,
99                                   Geom2dGcc_Circ2d3Tan& ct3, const char* name) 
100 {
101   char solname[200];
102
103   Draw_Color col = DrawTrSurf_CurveColor(Draw_Color(Draw_vert));
104   DrawTrSurf_CurveColor(col);
105
106   if (ct3.IsDone()) {
107     for (Standard_Integer i = 1 ; i <= ct3.NbSolutions() ; i++) {
108       Handle(Geom2d_Circle) C = new Geom2d_Circle(ct3.ThisSolution(i));
109       Sprintf(solname,"%s_%d",name,i);
110       char* temp = solname; // pour portage WNT
111       DrawTrSurf::Set(temp,C);
112       di << solname << " ";
113     }
114     return 0;
115   }
116   else {
117     di << "Circ2d3Tan Not done";
118     return 1;
119   }
120 }
121
122 //=======================================================================
123 //function : cirtang
124 //purpose  : 
125 //=======================================================================
126
127 static Standard_Integer cirtang (Draw_Interpretor& di,Standard_Integer n, const char** a)
128 {
129   if (n < 5) return 1;
130
131   Handle(Geom2d_Curve) C1 = DrawTrSurf::GetCurve2d(a[2]);
132   Handle(Geom2d_Curve) C2 = DrawTrSurf::GetCurve2d(a[3]);
133   Handle(Geom2d_Curve) C3 = DrawTrSurf::GetCurve2d(a[4]);
134   gp_Pnt2d P1,P2,P3;
135   Standard_Boolean ip1 = DrawTrSurf::GetPoint2d(a[2],P1);
136   Standard_Boolean ip2 = DrawTrSurf::GetPoint2d(a[3],P2);
137   Standard_Boolean ip3 = DrawTrSurf::GetPoint2d(a[4],P3);
138
139   Standard_Real tol = Precision::Confusion();
140   if (n > 5) tol = Draw::Atof(a[5]);
141
142
143   if (!C1.IsNull()) {
144     // C-...
145     if (!C2.IsNull()) {
146       // C-C-...
147       if (!C3.IsNull()) {
148         // C-C-C
149         Geom2dGcc_Circ2d3Tan ct3(Geom2dGcc::Unqualified(C1),
150           Geom2dGcc::Unqualified(C2),
151           Geom2dGcc::Unqualified(C3),
152           tol,0,0,0);
153         return solutions(di,ct3,a[1]);
154       }
155
156       else if (ip3) {
157         // C-C-P
158         Geom2dGcc_Circ2d3Tan ct3(Geom2dGcc::Unqualified(C1),
159           Geom2dGcc::Unqualified(C2),
160           new Geom2d_CartesianPoint(P3),
161           tol,0,0);
162         return solutions(di,ct3,a[1]);
163       }
164
165       else {
166         // C-C-R
167         Geom2dGcc_Circ2d2TanRad ct3(Geom2dGcc::Unqualified(C1),
168           Geom2dGcc::Unqualified(C2),
169           Draw::Atof(a[4]),tol);
170         return solutions(di,ct3,a[1]);
171       }
172     }
173     else if (ip2) {
174       // C-P-..
175       if (!C3.IsNull()) {
176         // C-P-C
177         Geom2dGcc_Circ2d3Tan ct3(Geom2dGcc::Unqualified(C1),
178           Geom2dGcc::Unqualified(C3),
179           new Geom2d_CartesianPoint(P2),
180           tol,0,0);
181         return solutions(di,ct3,a[1]);
182       }
183
184       else if (ip3) {
185         // C-P-P
186         Geom2dGcc_Circ2d3Tan ct3(Geom2dGcc::Unqualified(C1),
187           new Geom2d_CartesianPoint(P2),
188           new Geom2d_CartesianPoint(P3),
189           tol,0);
190         return solutions(di,ct3,a[1]);
191       }
192
193       else {
194         // C-P-R
195         Geom2dGcc_Circ2d2TanRad ct3(Geom2dGcc::Unqualified(C1),
196           new Geom2d_CartesianPoint(P2),
197           Draw::Atof(a[4]),tol);
198         return solutions(di,ct3,a[1]);
199       }
200     }
201
202     else {
203       // C-R-..
204       if (!C3.IsNull()) {
205         // C-R-C
206         Geom2dGcc_Circ2d2TanRad ct3(Geom2dGcc::Unqualified(C1),
207           Geom2dGcc::Unqualified(C3),
208           Draw::Atof(a[3]),
209           tol);
210         return solutions(di,ct3,a[1]);
211       }
212
213       else if (ip3) {
214         // C-R-P
215         Geom2dGcc_Circ2d2TanRad ct3(Geom2dGcc::Unqualified(C1),
216           new Geom2d_CartesianPoint(P3),
217           Draw::Atof(a[3]),
218           tol);
219         return solutions(di,ct3,a[1]);
220       }
221
222       else {
223         // C-R-R
224         di << "Curve, radius, radius ???"<<"\n";
225         return 1;
226       }
227     }
228   }
229
230   else if (ip1) {
231     // P-...
232     if (!C2.IsNull()) {
233       // P-C-...
234       if (!C3.IsNull()) {
235         // P-C-C
236         Geom2dGcc_Circ2d3Tan ct3(Geom2dGcc::Unqualified(C2),
237           Geom2dGcc::Unqualified(C3),
238           new Geom2d_CartesianPoint(P1),
239           tol,0,0);
240         return solutions(di,ct3,a[1]);
241       }
242
243       else if (ip3) {
244         // P-C-P
245         Geom2dGcc_Circ2d3Tan ct3(Geom2dGcc::Unqualified(C2),
246           new Geom2d_CartesianPoint(P1),
247           new Geom2d_CartesianPoint(P3),
248           tol,0);
249         return solutions(di,ct3,a[1]);
250       }
251
252       else {
253         // P-C-R
254         Geom2dGcc_Circ2d2TanRad ct3(Geom2dGcc::Unqualified(C2),
255           new Geom2d_CartesianPoint(P1),
256           Draw::Atof(a[4]),tol);
257         return solutions(di,ct3,a[1]);
258       }
259     }
260     else if (ip2) {
261       // P-P-..
262       if (!C3.IsNull()) {
263         // P-P-C
264         Geom2dGcc_Circ2d3Tan ct3(Geom2dGcc::Unqualified(C3),
265           new Geom2d_CartesianPoint(P1),
266           new Geom2d_CartesianPoint(P2),
267           tol,0);
268         return solutions(di,ct3,a[1]);
269       }
270
271       else if (ip3) {
272         // P-P-P
273         Geom2dGcc_Circ2d3Tan ct3(new Geom2d_CartesianPoint(P1),
274           new Geom2d_CartesianPoint(P2),
275           new Geom2d_CartesianPoint(P3),
276           tol);
277         return solutions(di,ct3,a[1]);
278       }
279
280       else {
281         // P-P-R
282         Geom2dGcc_Circ2d2TanRad ct3(new Geom2d_CartesianPoint(P1),
283           new Geom2d_CartesianPoint(P2),
284           Draw::Atof(a[4]),tol);
285         return solutions(di,ct3,a[1]);
286       }
287     }
288
289     else {
290       // P-R-..
291       if (!C3.IsNull()) {
292         // P-R-C
293         Geom2dGcc_Circ2d2TanRad ct3(Geom2dGcc::Unqualified(C3),
294           new Geom2d_CartesianPoint(P1),
295           Draw::Atof(a[3]),
296           tol);
297         return solutions(di,ct3,a[1]);
298       }
299
300       else if (ip3) {
301         // P-R-P
302         Geom2dGcc_Circ2d2TanRad ct3(new Geom2d_CartesianPoint(P1),
303           new Geom2d_CartesianPoint(P3),
304           Draw::Atof(a[3]),
305           tol);
306         return solutions(di,ct3,a[1]);
307       }
308
309       else {
310         // P-R-R
311         di << "Point, radius, radius ???"<<"\n";
312         return 1;
313       }
314     }
315   }
316
317   else {
318     // R-...
319     if (!C2.IsNull()) {
320       // R-C-...
321       if (!C3.IsNull()) {
322         // R-C-C
323         Geom2dGcc_Circ2d2TanRad ct3(Geom2dGcc::Unqualified(C2),
324           Geom2dGcc::Unqualified(C3),
325           Draw::Atof(a[2]),
326           tol);
327         return solutions(di,ct3,a[1]);
328       }
329
330       else if (ip3) {
331         // R-C-P
332         Geom2dGcc_Circ2d2TanRad ct3(Geom2dGcc::Unqualified(C2),
333           new Geom2d_CartesianPoint(P3),
334           Draw::Atof(a[2]),
335           tol);
336         return solutions(di,ct3,a[1]);
337       }
338
339       else {
340         // R-C-R
341         di << "Radius - Curve - Radius ??"<<"\n";
342         return 1;
343       }
344     }
345     else if (ip2) {
346       // R-P-..
347       if (!C3.IsNull()) {
348         // R-P-C
349         Geom2dGcc_Circ2d2TanRad ct3(Geom2dGcc::Unqualified(C3),
350           new Geom2d_CartesianPoint(P2),
351           Draw::Atof(a[2]),
352           tol);
353         return solutions(di,ct3,a[1]);
354       }
355
356       else if (ip3) 
357       {
358         // R-P-P
359         Geom2dGcc_Circ2d2TanRad ct3(new Geom2d_CartesianPoint(P2),
360           new Geom2d_CartesianPoint(P3),
361           Draw::Atof(a[2]),
362           tol);
363         return solutions(di,ct3,a[1]);
364       }      
365       else {
366         // R-P-R
367         di << "Radius - Point - Radius ??"<<"\n";
368         return 1;
369       }
370     }
371     else {
372       // R-R-..
373       di << "radius, radius ???"<<"\n";
374       return 1;
375     }
376   }
377 }
378
379
380 //=======================================================================
381 //function : lintang
382 //purpose  : 
383 //=======================================================================
384
385 static Standard_Integer lintang (Draw_Interpretor& di,Standard_Integer n, const char** a)
386 {
387   if (n < 4) return 1;
388
389   Handle(Geom2d_Curve) C1 = DrawTrSurf::GetCurve2d(a[2]);
390   Handle(Geom2d_Curve) C2 = DrawTrSurf::GetCurve2d(a[3]);
391
392   char solname[200];
393
394   if (C1.IsNull() || C2.IsNull())
395     return 1;
396
397   Draw_Color col = DrawTrSurf_CurveColor(Draw_Color(Draw_vert));
398
399   if (n >= 5) {
400     Handle(Geom2d_Line) L = Handle(Geom2d_Line)::DownCast(C2);
401     if (L.IsNull()) {
402       di << "Second argument must be a line";
403       return 1;
404     }
405     Standard_Real ang = Draw::Atof(a[4]) * (M_PI / 180.0);
406     Geom2dGcc_Lin2dTanObl ct3(Geom2dGcc::Unqualified(C1),
407       L->Lin2d(),
408       Precision::Angular(),
409       (C1->FirstParameter()+C1->LastParameter())/2.,
410       ang);
411     if (ct3.IsDone()) {
412       for (Standard_Integer i = 1 ; i <= ct3.NbSolutions() ; i++) {
413         Handle(Geom2d_Line) LS = new Geom2d_Line(ct3.ThisSolution(i));
414         Sprintf(solname,"%s_%d",a[1],i);
415         char* temp = solname; // pour portage WNT
416         DrawTrSurf::Set(temp,LS);
417         di << solname << " ";
418       }
419     }
420     else
421       di << "Lin2dTanObl Not done" << "\n";
422   }
423   else {
424     Geom2dGcc_Lin2d2Tan ct3(Geom2dGcc::Unqualified(C1),
425       Geom2dGcc::Unqualified(C2),
426       Precision::Angular(),
427       (C1->FirstParameter()+C1->LastParameter())/2.,
428       (C2->FirstParameter()+C2->LastParameter())/2.);
429     if (ct3.IsDone()) {
430       for (Standard_Integer i = 1 ; i <= ct3.NbSolutions() ; i++) {
431         Handle(Geom2d_Line) LS = new Geom2d_Line(ct3.ThisSolution(i));
432         Sprintf(solname,"%s_%d",a[1],i);
433         char* temp = solname; // pour portage WNT
434         DrawTrSurf::Set(temp,LS);
435         di << solname << " ";
436       }
437     }
438     else
439       di << "Lin2d2Tan Not done" << "\n";
440   }
441
442   DrawTrSurf_CurveColor(col);
443
444   return 0;
445 }
446
447 //==================================================================================
448 static Standard_Integer interpol (Draw_Interpretor& di,Standard_Integer n, const char** a)
449 //==================================================================================
450 {
451   if (n == 1) {
452     di <<"give a name to your curve !" << "\n";
453     return 0;
454   }
455   if (n == 2) {
456     Standard_Integer id,XX,YY,b, i, j;
457     di << "Pick points "<< "\n";
458     dout.Select(id, XX, YY, b);
459     Standard_Real zoom = dout.Zoom(id);
460     if (b != 1) return 0;
461     if (id < 0) return 0;
462     gp_Pnt P;
463     gp_Pnt2d P2d;
464     Standard_Boolean newcurve;
465
466     if (dout.Is3D(id)) {
467       Handle(Draw_Marker3D) mark;
468       Handle(TColgp_HArray1OfPnt) Points = new TColgp_HArray1OfPnt(1, 1);
469       P.SetCoord((Standard_Real)XX/zoom,(Standard_Real)YY/zoom, 0.0);
470       Points->SetValue(1 , P);
471       Handle(TColgp_HArray1OfPnt) ThePoints = new TColgp_HArray1OfPnt(1, 2);
472       ThePoints->SetValue(1 , P);
473       mark = new Draw_Marker3D(Points->Value(1), Draw_X, Draw_vert);
474       dout << mark;
475       dout.Flush();
476       Handle(Geom_BSplineCurve) C;
477       i = 1;
478
479       while (b != 3) {
480         dout.Select(id,XX,YY,b, Standard_False);
481         P.SetCoord((Standard_Real)XX/zoom,(Standard_Real)YY/zoom, 0.0);
482         ThePoints->SetValue(i+1, P);
483         newcurve = Standard_False;
484         if (!(ThePoints->Value(i)).IsEqual(ThePoints->Value(i+1), 1.e-06)) {
485           if (b == 1) { 
486             i++;
487             mark = new Draw_Marker3D(ThePoints->Value(i), Draw_X, Draw_vert);
488             dout << mark;
489             dout.Flush();
490             Points = 
491               new TColgp_HArray1OfPnt(ThePoints->Lower(),ThePoints->Upper());
492             Points->ChangeArray1() = ThePoints->Array1();
493             newcurve = Standard_True;
494           }
495           GeomAPI_Interpolate anInterpolator(ThePoints,
496             Standard_False,
497             1.0e-5);
498           anInterpolator.Perform() ;
499           if (anInterpolator.IsDone()) {
500             C = anInterpolator.Curve() ;
501             Handle(DrawTrSurf_BSplineCurve) 
502               DC = new DrawTrSurf_BSplineCurve(C);
503             DC->ClearPoles();
504             DC->ClearKnots();
505             Draw::Set(a[1], DC);
506             dout.RepaintView(id);
507           }
508           if (newcurve) {
509             ThePoints = new TColgp_HArray1OfPnt(1, i+1);
510             for (j = 1; j <= i; j++) ThePoints->SetValue(j, Points->Value(j));
511           }
512         }
513       }
514       GeomAPI_Interpolate anInterpolator(ThePoints,
515         Standard_False,
516         1.0e-5);
517       anInterpolator.Perform() ;
518       if (anInterpolator.IsDone()) {
519         C = anInterpolator.Curve() ;
520         DrawTrSurf::Set(a[1], C);
521         dout.RepaintView(id);
522       }      
523     }
524     else {
525       Handle(Draw_Marker2D) mark;
526       Handle(TColgp_HArray1OfPnt2d) Points = new TColgp_HArray1OfPnt2d(1, 1);
527       P2d.SetCoord((Standard_Real)XX/zoom,(Standard_Real)YY/zoom);
528       Points->SetValue(1 , P2d);
529       Handle(TColgp_HArray1OfPnt2d) ThePoints = new TColgp_HArray1OfPnt2d(1, 2);
530       ThePoints->SetValue(1, P2d);
531       mark = new Draw_Marker2D(P2d, Draw_X, Draw_vert);
532       dout << mark;
533       dout.Flush();
534       Handle(Geom2d_BSplineCurve) C;
535       i = 1;
536
537       while (b != 3) {
538         dout.Select(id,XX,YY,b, Standard_False);
539         P2d.SetCoord((Standard_Real)XX/zoom,(Standard_Real)YY/zoom);
540         ThePoints->SetValue(i+1, P2d);
541         newcurve = Standard_False;
542         if (!(ThePoints->Value(i)).IsEqual(ThePoints->Value(i+1), 1.e-06)) {
543           if (b == 1) { 
544             i++;
545             mark = new Draw_Marker2D(P2d, Draw_X, Draw_vert);
546             dout << mark;
547             dout.Flush();
548             Points = 
549               new TColgp_HArray1OfPnt2d(ThePoints->Lower(),ThePoints->Upper());
550             Points->ChangeArray1() = ThePoints->Array1();
551             newcurve = Standard_True;
552           }
553           Geom2dAPI_Interpolate    a2dInterpolator(ThePoints,
554             Standard_False,
555             1.0e-5) ;
556           a2dInterpolator.Perform() ;
557           if (a2dInterpolator.IsDone()) { 
558             C = a2dInterpolator.Curve() ;
559
560             Handle(DrawTrSurf_BSplineCurve2d) 
561               DC = new DrawTrSurf_BSplineCurve2d(C);
562             DC->ClearPoles();
563             DC->ClearKnots();
564             Draw::Set(a[1], DC);
565             dout.RepaintView(id);
566           }
567
568           if (newcurve) {
569             ThePoints = new TColgp_HArray1OfPnt2d(1, i+1);
570             for (j = 1; j <= i; j++) ThePoints->SetValue(j, Points->Value(j));
571           }
572         }
573       }
574       Geom2dAPI_Interpolate    a2dInterpolator(Points,
575         Standard_False,
576         1.0e-5) ;
577       a2dInterpolator.Perform() ;
578       if (a2dInterpolator.IsDone()) { 
579         C = a2dInterpolator.Curve() ;
580
581         DrawTrSurf::Set(a[1], C);
582         dout.RepaintView(id); 
583       }
584
585     }
586   }
587   else if (n == 3) {
588     // lecture du fichier.
589     // nbpoints, 2d ou 3d, puis valeurs.
590     const char* nomfic = a[2];
591     ifstream iFile(nomfic, ios::in);
592     if (!iFile) return 1;
593     Standard_Integer nbp, i;
594     Standard_Real x, y, z;
595     iFile >> nbp;
596     char dimen[3];
597     iFile >> dimen;
598     if (!strcmp(dimen,"3d")) {
599       Handle(TColgp_HArray1OfPnt) Point =
600         new TColgp_HArray1OfPnt(1, nbp);
601       for (i = 1; i <= nbp; i++) {
602         iFile >> x >> y >> z;
603         Point->SetValue(i, gp_Pnt(x, y, z));
604       }
605       GeomAPI_Interpolate  anInterpolator(Point,
606         Standard_False,
607         1.0e-5) ;
608       anInterpolator.Perform() ;
609       if (anInterpolator.IsDone()) { 
610         Handle(Geom_BSplineCurve) C = 
611           anInterpolator.Curve();
612         DrawTrSurf::Set(a[1], C);
613       }
614     }
615     else if (!strcmp(dimen,"2d")) {
616       Handle(TColgp_HArray1OfPnt2d)  PointPtr = 
617         new TColgp_HArray1OfPnt2d(1, nbp);
618       for (i = 1; i <= nbp; i++) {
619         iFile >> x >> y;
620         PointPtr->SetValue(i, gp_Pnt2d(x, y));
621       }
622       Geom2dAPI_Interpolate   a2dInterpolator(PointPtr,
623         Standard_False,
624         1.0e-5);
625       a2dInterpolator.Perform() ;
626       if (a2dInterpolator.IsDone()) {
627         Handle(Geom2d_BSplineCurve) C = a2dInterpolator.Curve() ;
628         DrawTrSurf::Set(a[1], C);
629       }
630     }
631   }
632   return 0;
633 }
634
635 static Standard_Integer tanginterpol (Draw_Interpretor& di,
636                                       Standard_Integer n, 
637                                       const char** a)
638 {
639
640
641   if (n < 4)
642     return 1;
643
644   Standard_Integer 
645     ii,
646     jj,
647     //    num_knots,
648     //    degree,
649     num_tangents,
650     num_read,
651     num_start,
652     num_parameters ;
653
654
655   Standard_Real 
656     //    delta,
657     tolerance;
658   //    parameter ;
659
660   Standard_Boolean periodic_flag = Standard_False ;
661   gp_Pnt a_point ;
662   gp_Vec a_vector ;
663   tolerance = 1.0e-5 ;
664
665
666
667
668   Handle(Geom_BSplineCurve) NewCurvePtr ;
669
670
671
672
673   num_read = 2 ;
674   if (strcmp(a[num_read],"p") == 0) {
675     periodic_flag = Standard_True ;
676     num_read += 1 ;
677   }
678   num_parameters = Draw::Atoi(a[num_read]) ;
679
680   if (num_parameters < 2) {
681     num_parameters = 2 ;
682   }
683   if ( n <  num_parameters * 3 + num_read) {
684     return 1 ;
685   }
686   Handle(TColgp_HArray1OfPnt)   PointsArrayPtr=
687     new TColgp_HArray1OfPnt(1,num_parameters) ;
688
689   num_tangents = ((n - num_read) / 3)  - num_parameters ;
690   num_tangents = Max (0,num_tangents) ; 
691   num_tangents = Min (num_parameters, num_tangents) ;
692   ii = 1 ;
693   num_start = num_read ;
694   num_read += 1 ;
695   while (num_read <= num_parameters * 3 + num_start ) {
696     for (jj = 1 ; jj <= 3 ; jj++) {
697       a_point.SetCoord(jj,Draw::Atof(a[num_read])) ;
698       num_read += 1 ;
699     }
700     PointsArrayPtr->SetValue(ii,a_point) ;
701     ii += 1 ;
702   }
703   GeomAPI_Interpolate anInterpolator(PointsArrayPtr,
704     periodic_flag,
705     tolerance) ; 
706
707   if (num_tangents > 0) {
708     TColgp_Array1OfVec TangentsArray(1,num_parameters) ;
709     Handle(TColStd_HArray1OfBoolean) 
710       TangentFlagsPtr =
711       new TColStd_HArray1OfBoolean(1,num_parameters) ;
712
713     for (ii = 1 ; ii <= num_tangents ; ii++) {
714       TangentFlagsPtr->SetValue(ii,Standard_True) ;
715     }
716     for (ii = num_tangents + 1 ; ii <= num_parameters ; ii++) {
717       TangentFlagsPtr->SetValue(ii,Standard_False) ;
718     }
719     ii = 1 ;
720     while (ii <= num_tangents) {
721       for (jj = 1 ; jj <= 3 ; jj++) {
722         a_vector.SetCoord(jj,Draw::Atof(a[num_read])) ;
723         num_read += 1 ;
724       }
725       TangentsArray.SetValue(ii,a_vector) ;
726       ii += 1 ;
727     }
728
729
730     anInterpolator.Load(TangentsArray,
731       TangentFlagsPtr) ;
732   }
733   anInterpolator.Perform() ;
734   if (anInterpolator.IsDone()) {
735     NewCurvePtr =
736       anInterpolator.Curve() ;
737
738     DrawTrSurf::Set(a[1],
739       NewCurvePtr) ;
740     di << a[2] << " " ;
741
742   }
743   return 0 ;
744 }
745
746 //==================================================================================
747 static Standard_Integer gcarc (Draw_Interpretor& di,Standard_Integer n, const char** a)
748 //==================================================================================
749 {
750   if (n >= 5) {
751     gp_Pnt P1,P2,P3,P4;
752     if (!strcmp(a[2], "seg")) {
753       if (DrawTrSurf::GetPoint(a[3], P1)) {
754         if (DrawTrSurf::GetPoint(a[4], P2)) {
755           Handle(Geom_Curve) theline = GC_MakeSegment(P1,P2).Value();
756           DrawTrSurf::Set(a[1], theline);
757           return 1;
758         }
759       }
760     }
761     else if (!strcmp(a[2], "cir")) {
762       if (DrawTrSurf::GetPoint(a[3], P1)) {
763         if (DrawTrSurf::GetPoint(a[4], P2)) {
764           if (DrawTrSurf::GetPoint(a[5], P3)) {
765             //      if (DrawTrSurf::GetPoint(a[6], P4)) {
766             if (n>6) {
767               DrawTrSurf::GetPoint(a[6], P4);
768               gp_Vec V1 = gp_Vec(P2,P3);                                                    
769               Handle(Geom_Curve)thearc = GC_MakeArcOfCircle(P1,V1,P4).Value();
770               DrawTrSurf::Set(a[1], thearc);
771               return 1;
772             }
773             else {
774               Handle(Geom_Curve)thearc = GC_MakeArcOfCircle(P1,P2,P3).Value();
775               DrawTrSurf::Set(a[1], thearc);
776               return 1;
777             }
778           }
779         }
780       }
781     }
782   }
783   di <<"give a name for arc and the type seg or cir then" << "\n";
784   di <<"give passing points p1 p2 for seg    p1 p2 p3 or p1 p2 p3 p4 for cir (p2 p3 is a tgtvec)!" << "\n";
785   return 0;
786 }
787
788 //=======================================================================
789 //function : ConstraintCommands
790 //purpose  : 
791 //=======================================================================
792
793
794 void  GeometryTest::ConstraintCommands(Draw_Interpretor& theCommands)
795 {
796
797   static Standard_Boolean loaded = Standard_False;
798   if (loaded) return;
799   loaded = Standard_True;
800
801   DrawTrSurf::BasicCommands(theCommands);
802
803   const char* g;
804   // constrained constructs
805   g = "GEOMETRY Constraints";
806
807   theCommands.Add("cirtang",
808     "cirtang cname curve/point/radius curve/point/radius curve/point/radius",
809     __FILE__,
810     cirtang,g);
811
812   theCommands.Add("lintan",
813     "lintan lname curve1 curve2 [angle]",
814     __FILE__,
815     lintang,g);
816
817
818   theCommands.Add("interpol",
819     "interpol cname [fic]", 
820     __FILE__,
821     interpol, g);
822   theCommands.Add("tanginterpol",
823     "tanginterpol curve [p] num_points points [tangents] modifier  p = periodic",
824     __FILE__,
825     tanginterpol,g);
826
827   theCommands.Add("gcarc",
828     "gcarc name seg/cir p1 p2 p3 p4",
829     __FILE__,
830     gcarc,g);
831 }