0031939: Coding - correction of spelling errors in comments [part 6]
[occt.git] / src / DrawTrSurf / DrawTrSurf.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
18 #include <Draw.hxx>
19 #include <Draw_Appli.hxx>
20 #include <Draw_Color.hxx>
21 #include <DrawTrSurf.hxx>
22 #include <DrawTrSurf_BezierCurve.hxx>
23 #include <DrawTrSurf_BezierCurve2d.hxx>
24 #include <DrawTrSurf_BezierSurface.hxx>
25 #include <DrawTrSurf_BSplineCurve.hxx>
26 #include <DrawTrSurf_BSplineCurve2d.hxx>
27 #include <DrawTrSurf_BSplineSurface.hxx>
28 #include <DrawTrSurf_Curve.hxx>
29 #include <DrawTrSurf_Curve2d.hxx>
30 #include <DrawTrSurf_Drawable.hxx>
31 #include <DrawTrSurf_Point.hxx>
32 #include <DrawTrSurf_Polygon2D.hxx>
33 #include <DrawTrSurf_Polygon3D.hxx>
34 #include <DrawTrSurf_Surface.hxx>
35 #include <DrawTrSurf_Triangulation.hxx>
36 #include <Geom2d_BezierCurve.hxx>
37 #include <Geom2d_BSplineCurve.hxx>
38 #include <Geom2d_Curve.hxx>
39 #include <Geom_BezierCurve.hxx>
40 #include <Geom_BezierSurface.hxx>
41 #include <Geom_BSplineCurve.hxx>
42 #include <Geom_BSplineSurface.hxx>
43 #include <Geom_Curve.hxx>
44 #include <Geom_Geometry.hxx>
45 #include <Geom_Surface.hxx>
46 #include <GeomTools_Curve2dSet.hxx>
47 #include <GeomTools_CurveSet.hxx>
48 #include <GeomTools_SurfaceSet.hxx>
49 #include <gp_Ax2.hxx>
50 #include <gp_Ax2d.hxx>
51 #include <gp_Pln.hxx>
52 #include <gp_Pnt.hxx>
53 #include <gp_Pnt2d.hxx>
54 #include <gp_Trsf2d.hxx>
55 #include <Poly.hxx>
56 #include <Poly_Polygon2D.hxx>
57 #include <Poly_Polygon3D.hxx>
58 #include <Poly_Triangulation.hxx>
59 #include <Standard_Stream.hxx>
60 #include <TCollection_AsciiString.hxx>
61
62 static Draw_Color       PntColor(Draw_rouge);
63 static Draw_Color       CurvColor(Draw_jaune);
64 static Draw_Color       BoundsColor(Draw_vert);
65 static Draw_Color       IsosColor(Draw_bleu);
66 static Draw_Color       PolesColor(Draw_rouge);
67 static Draw_Color       KnotsColor(Draw_violet);
68
69 static Draw_MarkerShape PntShape   = Draw_Plus;
70 static Draw_MarkerShape KnotsShape = Draw_Losange;
71 static Standard_Boolean ShowPoles  = Standard_True;
72 static Standard_Boolean ShowKnots  = Standard_True;
73 static Standard_Boolean knotsIsos  =Standard_True;
74 static Standard_Real    Deflection = 0.01;
75 static Standard_Integer KnotsSize  = 5;
76 static Standard_Integer Discret    = 30;
77 static Standard_Integer DrawMode   = 0;
78 static Standard_Integer NbUIsos    = 10;
79 static Standard_Integer NbVIsos    = 10;
80
81 static TCollection_AsciiString ColorsHint(
82 "The possible colors are: \n\
83   white, red, green, blue, cyan,\n\
84   golden, magenta, brown, orange, pink,\n\
85   salmon, violet, yellow, darkgreen, coral");
86
87 static TCollection_AsciiString MarkersHint(
88 "The possible markers are: \n\
89   square, diamond, x, plus, circle, circle_zoom");
90
91 //=======================================================================
92 //function : DrawTrSurf_CurveColor
93 //purpose  : Sets new color for rendering of curves. Returns the
94 //           previous one to keep possibility to restore the initial
95 //           state
96 //=======================================================================
97
98 Standard_EXPORT Draw_Color DrawTrSurf_CurveColor(const Draw_Color col)
99 {
100   Draw_Color c = CurvColor;
101   CurvColor = col;
102   return c;
103 }
104
105 //=======================================================================
106 //function : DrawTrSurf_PointColor
107 //purpose  : Sets new color for rendering of points. Returns the
108 //           previous one to keep possibility to restore the initial
109 //           state
110 //=======================================================================
111
112 Standard_EXPORT Draw_Color DrawTrSurf_PointColor(const Draw_Color col)
113 {
114   Draw_Color c = PntColor;
115   PntColor = col;
116   return c;
117 }
118
119 //=======================================================================
120 //function : DrawTrSurf_PointMarker
121 //purpose  : Sets new marker for rendering of points. Returns the
122 //           previous one to keep possibility to restore the initial
123 //           state
124 //=======================================================================
125
126 Standard_EXPORT Draw_MarkerShape DrawTrSurf_PointMarker(const Draw_MarkerShape marker)
127 {
128   Draw_MarkerShape prev = PntShape;
129   PntShape = marker;
130   return prev;
131 }
132
133 //=======================================================================
134 //function : GetDrawable
135 //purpose  : 
136 //=======================================================================
137 static Handle(DrawTrSurf_Drawable) GetDrawable(Standard_CString& Name)
138 {
139   Handle(Draw_Drawable3D) D = Draw::Get(Name);
140   Handle(DrawTrSurf_Drawable) Dr;
141   if (!D.IsNull()) 
142     Dr = Handle(DrawTrSurf_Drawable)::DownCast(D);
143   return Dr;
144 }
145
146 //=======================================================================
147 //function : GetSurface
148 //purpose  : 
149 //=======================================================================
150 static Handle(DrawTrSurf_Surface) GetSurface(Standard_CString& Name)
151 {
152   Handle(Draw_Drawable3D) D = Draw::Get(Name);
153   Handle(DrawTrSurf_Surface) Dr;
154   if (!D.IsNull()) 
155     Dr = Handle(DrawTrSurf_Surface)::DownCast(D);
156   return Dr;
157 }
158
159 //=======================================================================
160 //function : GetBezierSurface
161 //purpose  : 
162 //=======================================================================
163 static Handle(DrawTrSurf_BezierSurface) GetBezierSurface(Standard_CString& Name)
164 {
165   Handle(Draw_Drawable3D) D = Draw::Get(Name);
166   Handle(DrawTrSurf_BezierSurface) Dr;
167   if (!D.IsNull()) 
168     Dr = Handle(DrawTrSurf_BezierSurface)::DownCast(D);
169   return Dr;
170 }
171
172 //=======================================================================
173 //function : GetBSplineSurface
174 //purpose  : 
175 //=======================================================================
176 static Handle(DrawTrSurf_BSplineSurface) GetBSplineSurface(Standard_CString& Name)
177 {
178   Handle(Draw_Drawable3D) D = Draw::Get(Name);
179   Handle(DrawTrSurf_BSplineSurface) Dr;
180   if (!D.IsNull()) 
181     Dr = Handle(DrawTrSurf_BSplineSurface)::DownCast(D);
182   return Dr;
183 }
184
185 //=======================================================================
186 //function : GetBezierCurve
187 //purpose  : 
188 //=======================================================================
189 static Handle(DrawTrSurf_BezierCurve) GetBezierCurve(Standard_CString& Name)
190 {
191   Handle(Draw_Drawable3D) D = Draw::Get(Name);
192   Handle(DrawTrSurf_BezierCurve) Dr;
193   if (!D.IsNull()) 
194     Dr = Handle(DrawTrSurf_BezierCurve)::DownCast(D);
195   return Dr;
196 }
197
198 //=======================================================================
199 //function : GetBSplineCurve
200 //purpose  : 
201 //=======================================================================
202 static Handle(DrawTrSurf_BSplineCurve) GetBSplineCurve(Standard_CString& Name)
203 {
204   Handle(Draw_Drawable3D) D = Draw::Get(Name);
205   Handle(DrawTrSurf_BSplineCurve) Dr;
206   if (!D.IsNull()) 
207     Dr = Handle(DrawTrSurf_BSplineCurve)::DownCast(D);
208   return Dr;
209 }
210
211 //=======================================================================
212 //function : GetBezierCurve2d
213 //purpose  : 
214 //=======================================================================
215 static Handle(DrawTrSurf_BezierCurve2d) GetBezierCurve2d(Standard_CString& Name)
216 {
217   Handle(Draw_Drawable3D) D = Draw::Get(Name);
218   Handle(DrawTrSurf_BezierCurve2d) Dr;
219   if (!D.IsNull()) 
220     Dr = Handle(DrawTrSurf_BezierCurve2d)::DownCast(D);
221   return Dr;
222 }
223
224 //=======================================================================
225 //function : GetBSplineCurve2d
226 //purpose  : 
227 //=======================================================================
228 static Handle(DrawTrSurf_BSplineCurve2d) GetBSplineCurve2d(Standard_CString& Name)
229 {
230   Handle(Draw_Drawable3D) D = Draw::Get(Name);
231   Handle(DrawTrSurf_BSplineCurve2d) Dr;
232   if (!D.IsNull()) 
233     Dr = Handle(DrawTrSurf_BSplineCurve2d)::DownCast(D);
234   return Dr;
235 }
236
237
238 //=======================================================================
239 //function : nbiso
240 //purpose  : 
241 //=======================================================================
242 static Standard_Integer nbiso (Draw_Interpretor& di, Standard_Integer n, const char** a)
243 {
244   if (n < 4) {
245     if (n == 3) {
246       NbUIsos = Draw::Atoi(a[1]);
247       NbVIsos = Draw::Atoi(a[2]);
248     }
249     di << NbUIsos << " " << NbVIsos;
250   }
251   else {
252     for (Standard_Integer i = 1; i < n - 2; i++) {
253       Handle(DrawTrSurf_Surface) DS = GetSurface(a[i]);
254       if (!DS.IsNull()) {
255         DS->ShowIsos(Draw::Atoi(a[n-2]),Draw::Atoi(a[n-1]));
256         Draw::Repaint();
257       }
258     }
259   }
260   return 0;
261 }
262
263 //=======================================================================
264 //function : drawpoles
265 //purpose  : 
266 //=======================================================================
267
268 static Standard_Integer drawpoles(Draw_Interpretor&, 
269                                   Standard_Integer n,
270                                   const char** a)
271 {
272   if ( n == 1) {
273     if ( !strcmp(a[0],"shpoles")) {
274       ShowPoles = Standard_True;
275     }
276     else if ( !strcmp(a[0],"clpoles")) {
277       ShowPoles = Standard_False;
278     }
279     else if ( !strcmp(a[0],"shknots")) {
280       ShowKnots = Standard_True;
281     }
282     else if ( !strcmp(a[0],"clknots")) {
283       ShowKnots = Standard_False;
284     }
285   }
286
287   if ( n<2) return 0;
288
289   Handle(DrawTrSurf_BezierSurface) BZS;
290   BZS = GetBezierSurface(a[1]);
291   if ( !BZS.IsNull()) {
292     if ( !strcmp(a[0],"shpoles")) {
293       BZS->ShowPoles();
294     }
295     else if ( !strcmp(a[0],"clpoles")) {
296       BZS->ClearPoles();
297     }
298     else {
299       return 1;
300     }
301   }
302   else {
303     Handle(DrawTrSurf_BSplineSurface) BSS = GetBSplineSurface(a[1]);
304     if ( !BSS.IsNull()) {
305       if ( !strcmp(a[0],"shpoles")) {
306         BSS->ShowPoles();
307       }
308       else if ( !strcmp(a[0],"clpoles")) {
309         BSS->ClearPoles();
310       }
311       else if ( !strcmp(a[0],"shknots")) {
312         BSS->ShowKnots();
313       }
314       else if ( !strcmp(a[0],"clknots")) {
315         BSS->ClearKnots();
316       }
317     }
318     else {
319       Handle(DrawTrSurf_BezierCurve) BZC = GetBezierCurve(a[1]);
320       if ( !BZC.IsNull()) {
321         if ( !strcmp(a[0],"shpoles")) {
322           BZC->ShowPoles();
323         }
324         else if ( !strcmp(a[0],"clpoles")) {
325           BZC->ClearPoles();
326         }
327         else {
328           return 1;
329         }
330       }
331       else {
332         Handle(DrawTrSurf_BSplineCurve) BSC = GetBSplineCurve(a[1]);
333         if ( !BSC.IsNull()) {
334           if ( !strcmp(a[0],"shpoles")) {
335             BSC->ShowPoles();
336           }
337           else if ( !strcmp(a[0],"clpoles")) {
338             BSC->ClearPoles();
339           }
340           else if ( !strcmp(a[0],"shknots")) {
341             BSC->ShowKnots();
342           }
343           else if ( !strcmp(a[0],"clknots")) {
344             BSC->ClearKnots();
345           }
346         }
347         else {
348           Handle(DrawTrSurf_BezierCurve2d) BZ2 = GetBezierCurve2d(a[1]);
349           if ( !BZ2.IsNull()) {
350             if ( !strcmp(a[0],"shpoles")) {
351               BZ2->ShowPoles();
352             }
353             else if ( !strcmp(a[0],"clpoles")) {
354               BZ2->ClearPoles();
355             }
356             else {
357               return 1;
358             }
359           }
360           else {
361             Handle(DrawTrSurf_BSplineCurve2d) BS2 = GetBSplineCurve2d(a[1]);
362             if ( !BS2.IsNull()) {
363               if ( !strcmp(a[0],"shpoles")) {
364                 BS2->ShowPoles();
365               }
366               else if ( !strcmp(a[0],"clpoles")) {
367                 BS2->ClearPoles();
368               }
369               else if ( !strcmp(a[0],"shknots")) {
370                 BS2->ShowKnots();
371               }
372               else if ( !strcmp(a[0],"clknots")) {
373                 BS2->ClearKnots();
374               }
375             }
376             else {
377               return 1;
378             }
379           }
380         }
381       }
382     }
383   }
384   Draw::Repaint();
385   return 0;
386 }
387
388 //=======================================================================
389 //function : draw
390 //purpose  : 
391 //=======================================================================
392
393 static Standard_Integer draw (Draw_Interpretor& di, Standard_Integer n, const char** a)
394 {
395   if (n <= 2) {
396         if (!strcmp(a[0],"dmode")) {
397           if (n == 2) {
398             DrawMode = 1;
399           }
400           if (DrawMode)
401             di << "u";
402           else
403             di << "d";
404         }
405         
406         else if (!strcmp(a[0],"discr")) {
407           if (n == 2)
408             Discret = Draw::Atoi(a[n-1]);
409           di << Discret;
410         }
411         
412         else if (!strcmp(a[0],"defle")) {
413           if (n == 2)
414             Deflection = Draw::Atof(a[n-1]);
415           di << Deflection;
416         }
417   }
418   else {
419     for (Standard_Integer i = 1; i < n - 1; i++) {
420       Handle(DrawTrSurf_Drawable) D = GetDrawable(a[1]);
421       if (!D.IsNull()) {
422         if (!strcmp(a[0],"dmode")) {
423           Standard_Integer mod = 0;
424           if ((*a[n-1] == 'U')||(*a[n-1] == 'u')) mod = 1;
425           D->SetDrawMode(mod);
426         }
427         
428         else if (!strcmp(a[0],"discr")) {
429           D->SetDiscretisation(Draw::Atoi(a[n-1]));
430         }
431         
432         else if (!strcmp(a[0],"defle")) {
433           D->SetDeflection(Draw::Atof(a[n-1]));
434         }
435         
436         Draw::Repaint();
437       }
438     }
439   }
440   return 0;
441 }
442
443 //=======================================================================
444 //function : transform
445 //purpose  : 
446 //=======================================================================
447
448 static Standard_Integer transform (Draw_Interpretor& di, Standard_Integer n, const char** a)
449 {
450   if (n < 5) return 1;
451   gp_Trsf T;
452   Standard_Integer i,last = n-1;
453   if (!strcmp(a[0],"pscale")) {
454     Standard_Real s = Draw::Atof(a[last]);
455     last--;
456     if (last < 4) return 1;
457     gp_Pnt P(Draw::Atof(a[last-2]),Draw::Atof(a[last-1]),Draw::Atof(a[last]));
458     T.SetScale(P,s);
459   }
460   else if (!strcmp(a[0]+1,"mirror")) {
461     if (last < 4) return 1;
462     gp_Pnt P(Draw::Atof(a[last-2]),Draw::Atof(a[last-1]),Draw::Atof(a[last]));
463     if (*a[0] == 'p') {
464       T.SetMirror(P);
465     }
466     else {
467       last -= 3;
468       if (last < 4) return 1;
469       gp_Pnt O(Draw::Atof(a[last-2]),Draw::Atof(a[last-1]),Draw::Atof(a[last]));
470       last -= 3;
471       gp_Dir D(P.X(),P.Y(),P.Z());
472       if (*a[0] == 'l') {
473         T.SetMirror(gp_Ax1(O,D));
474       }
475       else if (*a[0] == 's') {
476         gp_Pln Pl(O,D);
477         T.SetMirror(Pl.Position().Ax2());
478       }
479     }
480   }
481
482   else if (!strcmp(a[0],"translate")) {
483     if (last < 4) return 1;
484     gp_Vec V(Draw::Atof(a[last-2]),Draw::Atof(a[last-1]),Draw::Atof(a[last]));
485     last -= 3;
486     T.SetTranslation(V);
487   }
488
489   else if (!strcmp(a[0],"rotate")) {
490     if (last < 8) return 1;
491     Standard_Real ang = Draw::Atof(a[last]) * (M_PI / 180.0);
492     last --;
493     gp_Dir D(Draw::Atof(a[last-2]),Draw::Atof(a[last-1]),Draw::Atof(a[last]));
494     last -= 3;
495     gp_Pnt P(Draw::Atof(a[last-2]),Draw::Atof(a[last-1]),Draw::Atof(a[last]));
496     last -= 3;
497     T.SetRotation(gp_Ax1(P,D),ang);
498   }
499
500   for (i = 1; i <= last; i++) {
501     Handle(Geom_Geometry) G = DrawTrSurf::Get(a[i]);
502     if (!G.IsNull()) {
503       G->Transform(T);
504       Draw::Repaint();
505     }
506     else {
507       gp_Pnt P;
508       if (DrawTrSurf::GetPoint(a[i],P)) {
509         P.Transform(T);
510         DrawTrSurf::Set(a[i],P);
511       }
512     }
513     di << a[i] << " ";
514   }
515   return 0;
516 }
517
518 //=======================================================================
519 //function : d2transform
520 //purpose  : 
521 //=======================================================================
522
523 static Standard_Integer d2transform (Draw_Interpretor& di, Standard_Integer n, const char** a)
524 {
525   if (n < 4) return 1;
526   gp_Trsf2d T;
527   Standard_Integer i,last = n-1;
528   if (!strcmp(a[0],"2dpscale")) {
529     Standard_Real s = Draw::Atof(a[last]);
530     last--;
531     if (last < 3) return 1;
532     gp_Pnt2d P(Draw::Atof(a[last-1]),Draw::Atof(a[last]));
533     T.SetScale(P,s);
534   }
535   else if ( (!strcmp(a[0],"2dpmirror")) || 
536             (!strcmp(a[0],"2dlmirror"))   ) {
537     if (last < 3) return 1;
538     gp_Pnt2d P(Draw::Atof(a[last-1]),Draw::Atof(a[last]));
539     if (!strcmp(a[0],"2dpmirror")) {
540       T.SetMirror(P);
541     }
542     else {
543       last -= 2;
544       if (last < 3) return 1;
545       gp_Pnt2d O(Draw::Atof(a[last-1]),Draw::Atof(a[last]));
546       last -= 2;
547       gp_Dir2d D(P.X(),P.Y());
548       T.SetMirror(gp_Ax2d(O,D));
549     }
550   }
551
552   else if (!strcmp(a[0],"2dtranslate")) {
553     if (last < 3) return 1;
554     gp_Vec2d V(Draw::Atof(a[last-1]),Draw::Atof(a[last]));
555     last -= 2;
556     T.SetTranslation(V);
557   }
558
559   else if (!strcmp(a[0],"2drotate")) {
560     if (last < 4) return 1;
561     Standard_Real ang = Draw::Atof(a[last]) * (M_PI / 180.0);
562     last --;
563     gp_Pnt2d P(Draw::Atof(a[last-1]),Draw::Atof(a[last]));
564     last -= 2;
565     T.SetRotation(P,ang);
566   }
567
568   for (i = 1; i <= last; i++) {
569     Handle(Geom2d_Curve) G = DrawTrSurf::GetCurve2d(a[i]);
570     if (!G.IsNull()) {
571       G->Transform(T);
572       Draw::Repaint();
573     }
574     else {
575       gp_Pnt2d P;
576       if (DrawTrSurf::GetPoint2d(a[i],P)) {
577         P.Transform(T);
578         DrawTrSurf::Set(a[i],P);
579       }
580     }
581     di << a[i] << " ";
582   }
583   return 0;
584 }
585
586 //=======================================================================
587 //function : Set
588 //purpose  : point
589 //=======================================================================
590 void  DrawTrSurf::Set(const Standard_CString Name, 
591                       const gp_Pnt& P)
592 {
593   Handle(DrawTrSurf_Point) DP = new DrawTrSurf_Point(P,PntShape,PntColor);
594  Draw::Set(Name,DP);
595 }
596
597 //=======================================================================
598 //function : Set
599 //purpose  : point
600 //=======================================================================
601 void  DrawTrSurf::Set(const Standard_CString Name, 
602                       const gp_Pnt2d& P)
603 {
604   Handle(DrawTrSurf_Point) DP = new DrawTrSurf_Point(P,PntShape,PntColor);
605  Draw::Set(Name,DP);
606 }
607
608 //=======================================================================
609 //function : Set
610 //purpose  : Geometry from Geom
611 //=======================================================================
612 void  DrawTrSurf::Set(const Standard_CString Name, 
613                       const Handle(Geom_Geometry)& G,
614                       const Standard_Boolean isSenseMarker)
615 {
616   Handle(DrawTrSurf_Drawable) D;
617   if (!G.IsNull()) {
618
619     Handle(Geom_Curve) C = Handle(Geom_Curve)::DownCast(G);
620     if (!C.IsNull()) {
621       
622       Handle(Geom_BezierCurve) Bez = 
623         Handle(Geom_BezierCurve)::DownCast(C);
624       if (!Bez.IsNull()) {
625         Handle(DrawTrSurf_BezierCurve) DBez = 
626           new DrawTrSurf_BezierCurve(Bez,CurvColor,PolesColor,ShowPoles,
627                                      Discret,Deflection,DrawMode);
628         D = DBez;
629       }
630
631
632       Handle(Geom_BSplineCurve) BS = 
633         Handle(Geom_BSplineCurve)::DownCast(C);
634       if (!BS.IsNull()) {
635         Handle(DrawTrSurf_BSplineCurve) DBS = 
636           new DrawTrSurf_BSplineCurve(BS,
637                                       CurvColor,PolesColor,
638                                       KnotsColor,
639                                       KnotsShape,KnotsSize,
640                                       ShowPoles,ShowKnots,
641                                       Discret,Deflection,DrawMode);
642         D = DBS;
643       }
644
645       if (Bez.IsNull() && BS.IsNull()) {
646         Handle(DrawTrSurf_Curve) DC =
647           new DrawTrSurf_Curve(C,CurvColor,Discret,Deflection,DrawMode,isSenseMarker);
648         D = DC;
649       }
650     }
651
652
653     Handle(Geom_Surface) S = Handle(Geom_Surface)::DownCast(G);
654     if (!S.IsNull()) {
655       
656       Handle(Geom_BezierSurface) Bez = 
657         Handle(Geom_BezierSurface)::DownCast(S);
658       if (!Bez.IsNull()) {
659         Handle(DrawTrSurf_BezierSurface) DBez = 
660           new DrawTrSurf_BezierSurface(Bez,NbUIsos,NbVIsos,
661                                        BoundsColor,IsosColor,PolesColor,
662                                        ShowPoles,
663                                        Discret,Deflection,DrawMode);
664         D = DBez;
665       }
666
667
668       Handle(Geom_BSplineSurface) BS = 
669         Handle(Geom_BSplineSurface)::DownCast(S);
670       if (!BS.IsNull()) {
671         Handle(DrawTrSurf_BSplineSurface) DBS ;
672         if (!knotsIsos) 
673           DBS = new DrawTrSurf_BSplineSurface(BS,
674                                               NbUIsos,NbVIsos,
675                                               BoundsColor,IsosColor,
676                                               PolesColor,KnotsColor,
677                                               KnotsShape,KnotsSize,
678                                               ShowPoles,ShowKnots,
679                                               Discret,Deflection,DrawMode);
680         else
681           DBS = new DrawTrSurf_BSplineSurface(BS,
682                                               BoundsColor,IsosColor,
683                                               PolesColor,KnotsColor,
684                                               KnotsShape,KnotsSize,
685                                               ShowPoles,ShowKnots,
686                                               Discret,Deflection,DrawMode);
687         
688         D = DBS;
689       }
690
691       if (Bez.IsNull() && BS.IsNull()) {
692         Handle(DrawTrSurf_Surface) DS =
693           new DrawTrSurf_Surface(S,
694                                  NbUIsos,NbVIsos,
695                                  BoundsColor,IsosColor,
696                                  Discret,Deflection,DrawMode);
697         D = DS;
698       }
699     }
700
701   }
702   Draw::Set(Name,D);
703 }
704
705
706 //=======================================================================
707 //function : Set
708 //purpose  : Curve from Geom2d
709 //=======================================================================
710 void  DrawTrSurf::Set(const Standard_CString Name, 
711                       const Handle(Geom2d_Curve)& C,
712                       const Standard_Boolean isSenseMarker)
713 {
714   Handle(DrawTrSurf_Drawable) D;
715   if (!C.IsNull()) {
716
717       Handle(Geom2d_BezierCurve) Bez = 
718         Handle(Geom2d_BezierCurve)::DownCast(C);
719       if (!Bez.IsNull()) {
720         Handle(DrawTrSurf_BezierCurve2d) DBez = 
721           new DrawTrSurf_BezierCurve2d(Bez,CurvColor,PolesColor,ShowPoles,
722                                        Discret);
723         D = DBez;
724       }
725
726
727       Handle(Geom2d_BSplineCurve) BS = 
728         Handle(Geom2d_BSplineCurve)::DownCast(C);
729       if (!BS.IsNull()) {
730         Handle(DrawTrSurf_BSplineCurve2d) DBS = 
731           new DrawTrSurf_BSplineCurve2d(BS,
732                                         CurvColor,PolesColor,
733                                         KnotsColor,
734                                         KnotsShape,KnotsSize,
735                                         ShowPoles,ShowKnots,
736                                         Discret);
737         D = DBS;
738       }
739       
740       if (Bez.IsNull() && BS.IsNull()) {
741         Handle(DrawTrSurf_Curve2d) DC =
742           new DrawTrSurf_Curve2d(C,CurvColor,Discret,isSenseMarker);
743         D = DC;
744       }
745     }
746
747   Draw::Set(Name,D);
748 }
749
750 //=======================================================================
751 //function : Set
752 //purpose  : 
753 //=======================================================================
754 void DrawTrSurf::Set(const Standard_CString Name, 
755                      const Handle(Poly_Triangulation)& T)
756 {
757   Handle(DrawTrSurf_Triangulation) D = new DrawTrSurf_Triangulation(T);
758   Draw::Set(Name,D);
759 }
760 //=======================================================================
761 //function : Set
762 //purpose  : 
763 //=======================================================================
764 void DrawTrSurf::Set(const Standard_CString Name, 
765                      const Handle(Poly_Polygon3D)& P)
766 {
767   Handle(DrawTrSurf_Polygon3D) D = new DrawTrSurf_Polygon3D(P);
768   Draw::Set(Name,D);
769 }
770
771 //=======================================================================
772 //function : Set
773 //purpose  : 
774 //=======================================================================
775 void DrawTrSurf::Set(const Standard_CString Name, 
776                      const Handle(Poly_Polygon2D)& P)
777 {
778   Handle(DrawTrSurf_Polygon2D) D = new DrawTrSurf_Polygon2D(P);
779   Draw::Set(Name,D);
780 }
781
782 //=======================================================================
783 //function : Get
784 //purpose  : 
785 //=======================================================================
786 Handle(Geom_Geometry)  DrawTrSurf::Get(Standard_CString& Name)
787 {
788   Handle(Draw_Drawable3D) D = Draw::Get(Name);
789
790   Handle(DrawTrSurf_Curve) DC = 
791     Handle(DrawTrSurf_Curve)::DownCast(D);
792   if (!DC.IsNull())
793     return DC->GetCurve();
794
795   Handle(DrawTrSurf_Surface) DS = 
796     Handle(DrawTrSurf_Surface)::DownCast(D);
797   if (!DS.IsNull())
798     return DS->GetSurface();
799
800   return Handle(Geom_Geometry) ();
801 }
802
803
804 //=======================================================================
805 //function : GetPoint
806 //purpose  : 
807 //=======================================================================
808 Standard_Boolean DrawTrSurf::GetPoint(Standard_CString& Name,
809                                       gp_Pnt& P)
810 {
811   Handle(DrawTrSurf_Point) D = 
812     Handle(DrawTrSurf_Point)::DownCast(Draw::Get(Name));
813   if (D.IsNull())
814     return Standard_False;
815   else if (!D->Is3D())
816     return Standard_False;
817   else {
818     P = D->Point();
819     return Standard_True;
820   }
821 }
822
823 //=======================================================================
824 //function : GetPoint2d
825 //purpose  : 
826 //=======================================================================
827 Standard_Boolean DrawTrSurf::GetPoint2d(Standard_CString& Name,
828                                         gp_Pnt2d& P)
829 {
830   Handle(DrawTrSurf_Point) D = 
831     Handle(DrawTrSurf_Point)::DownCast(Draw::Get(Name));
832   if (D.IsNull())
833     return Standard_False;
834   else if (D->Is3D()) 
835     return Standard_False;
836   else {
837     P = D->Point2d();
838     return Standard_True;
839   }
840 }
841
842 //=======================================================================
843 //function : GetCurve
844 //purpose  : 
845 //=======================================================================
846 Handle(Geom_Curve)  DrawTrSurf::GetCurve(Standard_CString& Name)
847 {
848   Handle(DrawTrSurf_Curve) D = 
849     Handle(DrawTrSurf_Curve)::DownCast(Draw::Get(Name));
850   if (D.IsNull())
851     return Handle(Geom_Curve)();
852   else
853     return D->GetCurve();
854 }
855
856
857 //=======================================================================
858 //function : GetBezierCurve
859 //purpose  : 
860 //=======================================================================
861 Handle(Geom_BezierCurve)  DrawTrSurf::GetBezierCurve(Standard_CString& Name)
862 {
863   Handle(DrawTrSurf_BezierCurve) D = 
864     Handle(DrawTrSurf_BezierCurve)::DownCast(Draw::Get(Name));
865   if (D.IsNull())
866     return Handle(Geom_BezierCurve)();
867   else
868     return Handle(Geom_BezierCurve)::DownCast(D->GetCurve());
869 }
870
871
872 //=======================================================================
873 //function : GetBSplineCurve
874 //purpose  : 
875 //=======================================================================
876 Handle(Geom_BSplineCurve)  DrawTrSurf::GetBSplineCurve(Standard_CString& Name)
877 {
878   Handle(DrawTrSurf_BSplineCurve) D = 
879     Handle(DrawTrSurf_BSplineCurve)::DownCast(Draw::Get(Name));
880   if (D.IsNull())
881     return Handle(Geom_BSplineCurve)();
882   else
883     return Handle(Geom_BSplineCurve)::DownCast(D->GetCurve());
884 }
885 //=======================================================================
886 //function : GetCurve2d
887 //purpose  : 
888 //=======================================================================
889 Handle(Geom2d_Curve)  DrawTrSurf::GetCurve2d(Standard_CString& Name)
890 {
891   Handle(DrawTrSurf_Curve2d) D = 
892     Handle(DrawTrSurf_Curve2d)::DownCast(Draw::Get(Name));
893   if (D.IsNull())
894     return Handle(Geom2d_Curve)();
895   else
896     return D->GetCurve();
897 }
898 //=======================================================================
899 //function : GetBezierCurve2d
900 //purpose  : 
901 //=======================================================================
902 Handle(Geom2d_BezierCurve)  DrawTrSurf::GetBezierCurve2d(Standard_CString& Name)
903 {
904   Handle(DrawTrSurf_Curve2d) D = 
905     Handle(DrawTrSurf_Curve2d)::DownCast(Draw::Get(Name));
906   if (D.IsNull())
907     return Handle(Geom2d_BezierCurve)();
908   else
909     return Handle(Geom2d_BezierCurve)::DownCast(D->GetCurve());
910 }
911 //=======================================================================
912 //function : GetBSplineCurve2d
913 //purpose  : 
914 //=======================================================================
915 Handle(Geom2d_BSplineCurve)  DrawTrSurf::GetBSplineCurve2d
916        (Standard_CString& Name)
917 {
918   Handle(DrawTrSurf_Curve2d) D = 
919     Handle(DrawTrSurf_Curve2d)::DownCast(Draw::Get(Name));
920   if (D.IsNull())
921     return Handle(Geom2d_BSplineCurve)();
922   else
923     return Handle(Geom2d_BSplineCurve)::DownCast(D->GetCurve());
924 }
925 //=======================================================================
926 //function : GetSurface
927 //purpose  : 
928 //=======================================================================
929 Handle(Geom_Surface)  DrawTrSurf::GetSurface
930        (Standard_CString& Name)
931 {
932   Handle(DrawTrSurf_Surface) D = 
933     Handle(DrawTrSurf_Surface)::DownCast(Draw::Get(Name));
934   if (D.IsNull())
935     return Handle(Geom_Surface)();
936   else
937     return D->GetSurface();
938 }
939 //=======================================================================
940 //function : GetBezierSurface
941 //purpose  : 
942 //=======================================================================
943 Handle(Geom_BezierSurface)  DrawTrSurf::GetBezierSurface
944        (Standard_CString& Name)
945 {
946   Handle(DrawTrSurf_BezierSurface) D = 
947     Handle(DrawTrSurf_BezierSurface)::DownCast(Draw::Get(Name));
948   if (D.IsNull())
949     return Handle(Geom_BezierSurface)();
950   else
951     return Handle(Geom_BezierSurface)::DownCast(D->GetSurface());
952 }
953 //=======================================================================
954 //function : GetBSplineSurface
955 //purpose  : 
956 //=======================================================================
957 Handle(Geom_BSplineSurface) DrawTrSurf::GetBSplineSurface
958        (Standard_CString& Name)
959 {
960   Handle(DrawTrSurf_BSplineSurface) D = 
961     Handle(DrawTrSurf_BSplineSurface)::DownCast(Draw::Get(Name));
962   if (D.IsNull())
963     return Handle(Geom_BSplineSurface)();
964   else
965     return Handle(Geom_BSplineSurface)::DownCast(D->GetSurface());
966 }
967 //=======================================================================
968 //function : GetTriangulation
969 //purpose  : 
970 //=======================================================================
971 Handle(Poly_Triangulation) DrawTrSurf::GetTriangulation(Standard_CString& Name)
972 {
973   Handle(DrawTrSurf_Triangulation) D =
974     Handle(DrawTrSurf_Triangulation)::DownCast(Draw::Get(Name));
975   if (D.IsNull())
976     return Handle(Poly_Triangulation)();
977   else
978     return D->Triangulation();
979 }
980 //=======================================================================
981 //function : GetPolygon3D
982 //purpose  : 
983 //=======================================================================
984 Handle(Poly_Polygon3D) DrawTrSurf::GetPolygon3D(Standard_CString& Name)
985 {
986   Handle(DrawTrSurf_Polygon3D) D =
987     Handle(DrawTrSurf_Polygon3D)::DownCast(Draw::Get(Name));
988   if (D.IsNull())
989     return Handle(Poly_Polygon3D)();
990   else
991     return D->Polygon3D();
992 }
993 //=======================================================================
994 //function : GetPolygon2D
995 //purpose  : 
996 //=======================================================================
997 Handle(Poly_Polygon2D) DrawTrSurf::GetPolygon2D(Standard_CString& Name)
998 {
999   Handle(DrawTrSurf_Polygon2D) D =
1000     Handle(DrawTrSurf_Polygon2D)::DownCast(Draw::Get(Name));
1001   if (D.IsNull())
1002     return Handle(Poly_Polygon2D)();
1003   else
1004     return D->Polygon2D();
1005 }
1006
1007 //=======================================================================
1008 //function : printColor
1009 //purpose  : 
1010 //=======================================================================
1011
1012 static void printColor(Draw_Interpretor& di, const Draw_Color& theColor)
1013 {
1014   switch ( theColor.ID() )
1015   {
1016     case Draw_blanc:   di << "white "            << "\n"; break;
1017     case Draw_rouge:   di << "red "              << "\n"; break;
1018     case Draw_vert:    di << "green "            << "\n"; break;
1019     case Draw_bleu:    di << "blue "             << "\n"; break;
1020     case Draw_cyan:    di << "cyan "             << "\n"; break;
1021     case Draw_or:      di << "golden "           << "\n"; break;
1022     case Draw_magenta: di << "magenta "          << "\n"; break;
1023     case Draw_marron:  di << "brown "            << "\n"; break;
1024     case Draw_orange:  di << "orange "           << "\n"; break;
1025     case Draw_rose:    di << "pink "             << "\n"; break;
1026     case Draw_saumon:  di << "salmon "           << "\n"; break;
1027     case Draw_violet:  di << "violet "           << "\n"; break;
1028     case Draw_jaune:   di << "yellow "           << "\n"; break;
1029     case Draw_kaki:    di << "dark-olive green \n"; break;
1030     case Draw_corail:  di << "coral "            << "\n"; break;
1031   }
1032 }
1033
1034 //=======================================================================
1035 //function : recognizeColor
1036 //purpose  : 
1037 //=======================================================================
1038
1039 static Draw_Color recognizeColor(const char* theColorStr,
1040                                  const Draw_Color& theDefaultColor)
1041 {
1042   Draw_Color aResult = theDefaultColor;
1043
1044   if ( !strcasecmp(theColorStr,"white") )
1045     aResult = Draw_blanc;
1046   if ( !strcasecmp(theColorStr, "red") )
1047     aResult = Draw_rouge;
1048   if ( !strcasecmp(theColorStr, "green") )
1049     aResult = Draw_vert;
1050   if ( !strcasecmp(theColorStr, "blue") )
1051     aResult = Draw_bleu;
1052   if ( !strcasecmp(theColorStr, "cyan") )
1053     aResult = Draw_cyan;
1054   if ( !strcasecmp(theColorStr, "golden") )
1055     aResult = Draw_or;
1056   if ( !strcasecmp(theColorStr, "magenta") )
1057     aResult = Draw_magenta;
1058   if ( !strcasecmp(theColorStr, "brown") )
1059     aResult = Draw_marron;
1060   if ( !strcasecmp(theColorStr, "orange") )
1061     aResult = Draw_orange;
1062   if ( !strcasecmp(theColorStr, "pink") )
1063     aResult = Draw_rose;
1064   if ( !strcasecmp(theColorStr, "salmon") )
1065     aResult = Draw_saumon;
1066   if ( !strcasecmp(theColorStr, "violet") )
1067     aResult = Draw_violet;
1068   if ( !strcasecmp(theColorStr, "yellow") )
1069     aResult = Draw_jaune;
1070   if ( !strcasecmp(theColorStr, "darkgreen") )
1071     aResult = Draw_kaki;
1072   if ( !strcasecmp(theColorStr, "coral") )
1073     aResult = Draw_corail;
1074
1075   return aResult;
1076 }
1077
1078 //=======================================================================
1079 //function : setcurvcolor
1080 //purpose  : 
1081 //=======================================================================
1082
1083 static Standard_Integer setcurvcolor(Draw_Interpretor& di,
1084                                      Standard_Integer n, const char** a)
1085 {
1086   Draw_Color col, savecol;
1087
1088   savecol = DrawTrSurf_CurveColor(Draw_Color(Draw_jaune));
1089   DrawTrSurf_CurveColor(savecol);
1090
1091   if (n < 2)
1092   {
1093     printColor(di, savecol);
1094   }
1095   else {
1096     col = recognizeColor(a[1], savecol);
1097     DrawTrSurf_CurveColor(col);
1098   }
1099   return 0;
1100 }
1101
1102 //=======================================================================
1103 //function : changecurvcolor
1104 //purpose  : 
1105 //=======================================================================
1106
1107 static Standard_Integer changecurvcolor(Draw_Interpretor&,
1108                                         Standard_Integer n, const char** a)
1109 {
1110   Draw_Color col, savecol;
1111
1112   savecol = DrawTrSurf_CurveColor(Draw_Color(Draw_jaune));
1113   DrawTrSurf_CurveColor(savecol);
1114
1115   if ( n < 3 )
1116     return 1;
1117
1118   col = recognizeColor(a[1], savecol);
1119     
1120   Handle(DrawTrSurf_Curve) D = Handle(DrawTrSurf_Curve)::DownCast( Draw::Get(a[2]) );
1121   if ( !D.IsNull() )
1122   {
1123     D->SetColor(col);
1124     Draw::Repaint();
1125   }
1126
1127   return 0;
1128 }
1129
1130 //=======================================================================
1131 //function : setpointcolor
1132 //purpose  : 
1133 //=======================================================================
1134
1135 static Standard_Integer setpointcolor(Draw_Interpretor& di,
1136                                       Standard_Integer n, const char** a)
1137 {
1138   Draw_Color col, savecol;
1139
1140   savecol = DrawTrSurf_PointColor(Draw_Color(Draw_jaune));
1141   DrawTrSurf_PointColor(savecol);
1142
1143   if (n < 2)
1144   {
1145     printColor(di, savecol);
1146   }
1147   else {
1148     col = recognizeColor(a[1], savecol);
1149     DrawTrSurf_PointColor(col);
1150   }
1151   return 0;
1152 }
1153
1154 //=======================================================================
1155 //function : changepointcolor
1156 //purpose  : 
1157 //=======================================================================
1158
1159 static Standard_Integer changepointcolor(Draw_Interpretor&,
1160                                          Standard_Integer n, const char** a)
1161 {
1162   Draw_Color col, savecol;
1163
1164   savecol = DrawTrSurf_PointColor(Draw_Color(Draw_jaune));
1165   DrawTrSurf_PointColor(savecol);
1166
1167   if ( n < 3 )
1168     return 1;
1169
1170   col = recognizeColor(a[1], savecol);
1171     
1172   Handle(DrawTrSurf_Point) D = Handle(DrawTrSurf_Point)::DownCast( Draw::Get(a[2]) );
1173   if ( !D.IsNull() )
1174   {
1175     D->Color(col);
1176     Draw::Repaint();
1177   }
1178
1179   return 0;
1180 }
1181
1182 //=======================================================================
1183 //function : printMarker
1184 //purpose  : 
1185 //=======================================================================
1186
1187 static void printMarker(Draw_Interpretor& di, const Draw_MarkerShape& theMarker)
1188 {
1189   switch ( theMarker )
1190   {
1191     case Draw_Square:     di << "square "      << "\n"; break;
1192     case Draw_Losange:    di << "diamond "     << "\n"; break;
1193     case Draw_X:          di << "x "           << "\n"; break;
1194     case Draw_Plus:       di << "plus "        << "\n"; break;
1195     case Draw_Circle:     di << "circle "      << "\n"; break;
1196     case Draw_CircleZoom: di << "circle_zoom \n"; break;
1197   }
1198 }
1199
1200 //=======================================================================
1201 //function : recognizeMarker
1202 //purpose  : 
1203 //=======================================================================
1204
1205 static Draw_MarkerShape recognizeMarker(const char* theMarkerStr,
1206                                         const Draw_MarkerShape& theDefaultMarker)
1207 {
1208   Draw_MarkerShape aResult = theDefaultMarker;
1209
1210   if ( !strcasecmp(theMarkerStr, "square") )
1211     aResult = Draw_Square;
1212   if ( !strcasecmp(theMarkerStr, "diamond") )
1213     aResult = Draw_Losange;
1214   if ( !strcasecmp(theMarkerStr, "x") )
1215     aResult = Draw_X;
1216   if ( !strcasecmp(theMarkerStr, "plus") )
1217     aResult = Draw_Plus;
1218   if ( !strcasecmp(theMarkerStr, "circle") )
1219     aResult = Draw_Circle;
1220   if ( !strcasecmp(theMarkerStr, "circle_zoom") )
1221     aResult = Draw_CircleZoom;
1222
1223   return aResult;
1224 }
1225
1226 //=======================================================================
1227 //function : setpointmarker
1228 //purpose  : 
1229 //=======================================================================
1230
1231 static Standard_Integer setpointmarker(Draw_Interpretor& di,
1232                                        Standard_Integer n, const char** a)
1233 {
1234   Draw_MarkerShape mark, savemark;
1235
1236   savemark = DrawTrSurf_PointMarker(Draw_MarkerShape(Draw_Plus));
1237   DrawTrSurf_PointMarker(savemark);
1238
1239   if ( n < 2 )
1240   {
1241     printMarker(di, savemark);
1242   }
1243   else {
1244     mark = recognizeMarker(a[1], savemark);
1245     DrawTrSurf_PointMarker(mark);
1246   }
1247   return 0;
1248 }
1249
1250 //=======================================================================
1251 //function : changepointmarker
1252 //purpose  : 
1253 //=======================================================================
1254
1255 static Standard_Integer changepointmarker(Draw_Interpretor&,
1256                                           Standard_Integer n, const char** a)
1257 {
1258   Draw_MarkerShape mark, savemark;
1259
1260   savemark = DrawTrSurf_PointMarker(Draw_MarkerShape(Draw_Plus));
1261   DrawTrSurf_PointMarker(savemark);
1262
1263   if ( n < 3 )
1264     return 1;
1265
1266   mark = recognizeMarker(a[1], savemark);
1267     
1268   Handle(DrawTrSurf_Point) D = Handle(DrawTrSurf_Point)::DownCast( Draw::Get(a[2]) );
1269   if ( !D.IsNull() )
1270   {
1271     D->Shape(mark);
1272     Draw::Repaint();
1273   }
1274
1275   return 0;
1276 }
1277
1278 //=======================================================================
1279 //function : BasicCommands
1280 //purpose  : 
1281 //=======================================================================
1282
1283 static Standard_Boolean done = Standard_False;
1284 void  DrawTrSurf::BasicCommands(Draw_Interpretor& theCommands)
1285 {
1286   if (done) return;
1287   done = Standard_True;
1288
1289   const char* g;
1290   g = "geometric display commands";
1291   
1292   theCommands.Add("nbiso",
1293                   "nbiso name [names...] nuiso nviso",
1294                   __FILE__,
1295                   nbiso,g);
1296   
1297   theCommands.Add("clpoles",
1298                   "clpoles [name], no args : modal ",
1299                   __FILE__,
1300                   drawpoles,g);
1301   
1302   theCommands.Add("shpoles",
1303                   "shpoles [name], no args : modal ",
1304                   __FILE__,
1305                   drawpoles,g);
1306   
1307   theCommands.Add("clknots",
1308                   "clknots [name], no args : modal ",
1309                   __FILE__,
1310                   drawpoles,g);
1311   
1312   theCommands.Add("shknots",
1313                   "shknots [name], no args : modal ",
1314                   __FILE__,
1315                   drawpoles,g);
1316   
1317   theCommands.Add("dmode",
1318                   "dmode [names...] Uniform/Discret",
1319                   __FILE__,
1320                   draw,g);
1321
1322   theCommands.Add("discr",
1323                   "discr [names...] nbintervals",
1324                   __FILE__,
1325                   draw,g);
1326
1327   theCommands.Add("defle",
1328                   "defle [names...] defle",
1329                   __FILE__,
1330                   draw,g);
1331
1332   theCommands.Add("setcurvcolor",
1333                   TCollection_AsciiString("setcurvcolor [color] : set curve color\
1334  by default, or print the current curve color if no argument (this does not modify\
1335  the color of the curve)\n\n").Cat(ColorsHint).ToCString(),
1336                   __FILE__,setcurvcolor,g);
1337
1338   theCommands.Add("changecurvcolor",
1339                   TCollection_AsciiString("changecurvcolor color curve: change\
1340  color of the curve\n\n").Cat(ColorsHint).ToCString(),
1341                   __FILE__,changecurvcolor,g);
1342
1343   theCommands.Add("setpointcolor",
1344                   TCollection_AsciiString("setpointcolor [color] : set point color\
1345  by default, or print the current point color if no argument (this does not modify\
1346  the color of the point)\n\n").Cat(ColorsHint).ToCString(),
1347                   __FILE__,setpointcolor,g);
1348
1349   theCommands.Add("changepointcolor",
1350                   TCollection_AsciiString("changepointcolor color point: change\
1351  color of the point\n\n").Cat(ColorsHint).ToCString(),
1352                   __FILE__,changepointcolor,g);
1353   
1354   theCommands.Add("setpointmarker",
1355                   TCollection_AsciiString("setpointmarker [marker] : set point marker\
1356  by default, or print the current point marker if no argument (this does not modify\
1357  the marker of the point)\n\n").Cat(MarkersHint).ToCString(),
1358                   __FILE__,setpointmarker,g);
1359
1360   theCommands.Add("changepointmarker",
1361                   TCollection_AsciiString("changepointmarker marker point: change\
1362  marker of the point\n\n").Cat(MarkersHint).ToCString(),
1363                   __FILE__,changepointmarker,g);
1364
1365   g = "Geometric transformations";
1366   
1367   theCommands.Add("translate",
1368                   "translate name [names...] dx dy dz",
1369                   __FILE__,
1370                   transform,g);
1371
1372   theCommands.Add("rotate",
1373                   "rotate name [names...] x y z dx dy dz angle",
1374                   __FILE__,
1375                   transform,g);
1376
1377   theCommands.Add("pmirror",
1378                   "pmirror name [names...] x y z",
1379                   __FILE__,
1380                   transform,g);
1381
1382   theCommands.Add("lmirror",
1383                   "lmirror name [names...] x y z dx dy dz",
1384                   __FILE__,
1385                   transform,g);
1386
1387   theCommands.Add("smirror",
1388                   "smirror name [names...] x y z dx dy dz",
1389                   __FILE__,
1390                   transform,g);
1391
1392   theCommands.Add("pscale",
1393                   "pscale name [names...] x y z s",
1394                   __FILE__,
1395                   transform,g);
1396
1397   theCommands.Add("2dtranslate",
1398                   "translate name [names...] dx dy",
1399                   __FILE__,
1400                   d2transform,g);
1401
1402   theCommands.Add("2drotate",
1403                   "rotate name [names...] x y dx dy  angle",
1404                   __FILE__,
1405                   d2transform,g);
1406
1407   theCommands.Add("2dpmirror",
1408                   "pmirror name [names...] x y",
1409                   __FILE__,
1410                   d2transform,g);
1411
1412   theCommands.Add("2dlmirror",
1413                   "lmirror name [names...] x y dx dy",
1414                   __FILE__,
1415                   d2transform,g);
1416
1417   theCommands.Add("2dpscale",
1418                   "pscale name [names...] x y s",
1419                   __FILE__,
1420                   d2transform,g);
1421 }
1422
1423
1424 //=================================================================
1425 // save and restore curves
1426 //=================================================================
1427
1428 static Standard_Boolean ctest(const Handle(Draw_Drawable3D)& d) 
1429 {
1430   return d->IsInstance(STANDARD_TYPE(DrawTrSurf_Curve));
1431 }
1432
1433 static void csave(const Handle(Draw_Drawable3D)&d, std::ostream& OS)
1434 {
1435   Handle(DrawTrSurf_Curve) N = Handle(DrawTrSurf_Curve)::DownCast(d);
1436   GeomTools_CurveSet::PrintCurve(N->GetCurve(),OS,Standard_True);
1437 }
1438
1439 static Handle(Draw_Drawable3D) crestore (std::istream& is)
1440 {
1441   Handle(Geom_Curve) G = GeomTools_CurveSet::ReadCurve(is);
1442   Handle(DrawTrSurf_Curve) N = 
1443     new DrawTrSurf_Curve(G,CurvColor,Discret,Deflection,DrawMode);
1444   return N;
1445 }
1446
1447
1448 static Draw_SaveAndRestore csr("DrawTrSurf_Curve",
1449                                ctest,csave,crestore);
1450
1451
1452
1453
1454 //=================================================================
1455 // save and restore bezier curves
1456 //=================================================================
1457
1458 static Standard_Boolean bzctest(const Handle(Draw_Drawable3D)& d) 
1459 {
1460   return d->IsInstance(STANDARD_TYPE(DrawTrSurf_BezierCurve));
1461 }
1462
1463 static void bzcsave(const Handle(Draw_Drawable3D)&d, std::ostream& OS)
1464 {
1465   Handle(DrawTrSurf_BezierCurve) 
1466     N = Handle(DrawTrSurf_BezierCurve)::DownCast(d);
1467   GeomTools_CurveSet::PrintCurve(N->GetCurve(),OS,Standard_True);
1468 }
1469
1470 static Handle(Draw_Drawable3D) bzcrestore (std::istream& is)
1471 {
1472   Handle(Geom_BezierCurve) G = 
1473     Handle(Geom_BezierCurve)::DownCast (GeomTools_CurveSet::ReadCurve(is));
1474   Handle(DrawTrSurf_BezierCurve) N = 
1475     new DrawTrSurf_BezierCurve(G,CurvColor,PolesColor,ShowPoles,
1476                                Discret,Deflection,DrawMode);
1477   return N;
1478 }
1479
1480
1481 static Draw_SaveAndRestore bzcsr("DrawTrSurf_BezierCurve",
1482                                bzctest,bzcsave,bzcrestore);
1483
1484
1485
1486
1487 //=================================================================
1488 // save and restore bspline curves
1489 //=================================================================
1490
1491 static Standard_Boolean bsctest(const Handle(Draw_Drawable3D)& d) 
1492 {
1493   return d->IsInstance(STANDARD_TYPE(DrawTrSurf_BSplineCurve));
1494 }
1495
1496 static void bscsave(const Handle(Draw_Drawable3D)&d, std::ostream& OS)
1497 {
1498   Handle(DrawTrSurf_BSplineCurve) 
1499     N = Handle(DrawTrSurf_BSplineCurve)::DownCast(d);
1500   GeomTools_CurveSet::PrintCurve(N->GetCurve(),OS,Standard_True);
1501 }
1502
1503 static Handle(Draw_Drawable3D) bscrestore (std::istream& is)
1504 {
1505   Handle(Geom_BSplineCurve) G =
1506     Handle(Geom_BSplineCurve)::DownCast (GeomTools_CurveSet::ReadCurve(is));
1507   Handle(DrawTrSurf_BSplineCurve) N = 
1508     new DrawTrSurf_BSplineCurve(G, CurvColor,PolesColor,
1509                                 KnotsColor,
1510                                 KnotsShape,KnotsSize,
1511                                 ShowPoles,ShowKnots,
1512                                 Discret,Deflection,DrawMode);
1513   return N;
1514 }
1515
1516
1517 static Draw_SaveAndRestore bscsr("DrawTrSurf_BSplineCurve",
1518                                bsctest,bscsave,bscrestore);
1519
1520
1521 //=================================================================
1522 // save and restore curves 2d
1523 //=================================================================
1524
1525 static Standard_Boolean c2dtest(const Handle(Draw_Drawable3D)& d) 
1526 {
1527   return d->IsInstance(STANDARD_TYPE(DrawTrSurf_Curve2d));
1528 }
1529
1530 static void c2dsave(const Handle(Draw_Drawable3D)&d, std::ostream& OS)
1531 {
1532   Handle(DrawTrSurf_Curve2d) N = Handle(DrawTrSurf_Curve2d)::DownCast(d);
1533   GeomTools_Curve2dSet::PrintCurve2d(N->GetCurve(),OS,Standard_True);
1534 }
1535
1536 static Handle(Draw_Drawable3D) c2drestore (std::istream& is)
1537 {
1538   Handle(Geom2d_Curve) G = GeomTools_Curve2dSet::ReadCurve2d(is);
1539   Handle(DrawTrSurf_Curve2d) N = 
1540     new DrawTrSurf_Curve2d(G,CurvColor,Discret);
1541   return N;
1542 }
1543
1544
1545 static Draw_SaveAndRestore c2dsr("DrawTrSurf_Curve2d",
1546                                c2dtest,c2dsave,c2drestore);
1547
1548
1549
1550
1551 //=================================================================
1552 // save and restore bezier curves 2d
1553 //=================================================================
1554
1555 static Standard_Boolean bzc2dtest(const Handle(Draw_Drawable3D)& d) 
1556 {
1557   return d->IsInstance(STANDARD_TYPE(DrawTrSurf_BezierCurve2d));
1558 }
1559
1560 static void bzc2dsave(const Handle(Draw_Drawable3D)&d, std::ostream& OS)
1561 {
1562   Handle(DrawTrSurf_BezierCurve2d) 
1563     N = Handle(DrawTrSurf_BezierCurve2d)::DownCast(d);
1564   GeomTools_Curve2dSet::PrintCurve2d(N->GetCurve(),OS,Standard_True);
1565 }
1566
1567 static Handle(Draw_Drawable3D) bzc2drestore (std::istream& is)
1568 {
1569   Handle(Geom2d_BezierCurve) G =
1570     Handle(Geom2d_BezierCurve)::DownCast (GeomTools_Curve2dSet::ReadCurve2d(is));
1571   Handle(DrawTrSurf_BezierCurve2d) N = 
1572     new DrawTrSurf_BezierCurve2d(G,CurvColor,PolesColor,ShowPoles,
1573                                Discret);
1574   return N;
1575 }
1576
1577
1578 static Draw_SaveAndRestore bzc2dsr("DrawTrSurf_BezierCurve2d",
1579                                bzc2dtest,bzc2dsave,bzc2drestore);
1580
1581
1582
1583
1584 //=================================================================
1585 // save and restore bspline curves 2d
1586 //=================================================================
1587
1588 static Standard_Boolean bsc2dtest(const Handle(Draw_Drawable3D)& d) 
1589 {
1590   return d->IsInstance(STANDARD_TYPE(DrawTrSurf_BSplineCurve2d));
1591 }
1592
1593 static void bsc2dsave(const Handle(Draw_Drawable3D)&d, std::ostream& OS)
1594 {
1595   Handle(DrawTrSurf_BSplineCurve2d) 
1596     N = Handle(DrawTrSurf_BSplineCurve2d)::DownCast(d);
1597   GeomTools_Curve2dSet::PrintCurve2d(N->GetCurve(),OS,Standard_True);
1598 }
1599
1600 static Handle(Draw_Drawable3D) bsc2drestore (std::istream& is)
1601 {
1602   Handle(Geom2d_BSplineCurve) G =
1603     Handle(Geom2d_BSplineCurve)::DownCast (GeomTools_Curve2dSet::ReadCurve2d(is));
1604   Handle(DrawTrSurf_BSplineCurve2d) N = 
1605     new DrawTrSurf_BSplineCurve2d(G, CurvColor,PolesColor,
1606                                 KnotsColor,
1607                                 KnotsShape,KnotsSize,
1608                                 ShowPoles,ShowKnots,
1609                                 Discret);
1610   return N;
1611 }
1612
1613
1614 static Draw_SaveAndRestore bsc2dsr("DrawTrSurf_BSplineCurve2d",
1615                                bsc2dtest,bsc2dsave,bsc2drestore);
1616
1617
1618 //=================================================================
1619 // save and restore surfaces
1620 //=================================================================
1621
1622 static Standard_Boolean stest(const Handle(Draw_Drawable3D)& d) 
1623 {
1624   return d->IsInstance(STANDARD_TYPE(DrawTrSurf_Surface));
1625 }
1626
1627 static void ssave(const Handle(Draw_Drawable3D)&d, std::ostream& OS)
1628 {
1629   Handle(DrawTrSurf_Surface) N = Handle(DrawTrSurf_Surface)::DownCast(d);
1630   GeomTools_SurfaceSet::PrintSurface(N->GetSurface(),OS,Standard_True);
1631 }
1632
1633 static Handle(Draw_Drawable3D) srestore (std::istream& is)
1634 {
1635   Handle(Geom_Surface) G = GeomTools_SurfaceSet::ReadSurface(is);
1636   Handle(DrawTrSurf_Surface) N = 
1637     new DrawTrSurf_Surface(G,
1638                            NbUIsos,NbVIsos,
1639                            BoundsColor,IsosColor,
1640                            Discret,Deflection,DrawMode);
1641   return N;
1642 }
1643
1644
1645 static Draw_SaveAndRestore ssr("DrawTrSurf_Surface",
1646                                stest,ssave,srestore);
1647
1648
1649
1650
1651 //=================================================================
1652 // save and restore bezier surfaces
1653 //=================================================================
1654
1655 static Standard_Boolean bzstest(const Handle(Draw_Drawable3D)& d) 
1656 {
1657   return d->IsInstance(STANDARD_TYPE(DrawTrSurf_BezierSurface));
1658 }
1659
1660 static void bzssave(const Handle(Draw_Drawable3D)&d, std::ostream& OS)
1661 {
1662   Handle(DrawTrSurf_BezierSurface) 
1663     N = Handle(DrawTrSurf_BezierSurface)::DownCast(d);
1664   GeomTools_SurfaceSet::PrintSurface(N->GetSurface(),OS,Standard_True);
1665 }
1666
1667 static Handle(Draw_Drawable3D) bzsrestore (std::istream& is)
1668 {
1669   Handle(Geom_BezierSurface) G =
1670     Handle(Geom_BezierSurface)::DownCast (GeomTools_SurfaceSet::ReadSurface(is));
1671   Handle(DrawTrSurf_BezierSurface) N = 
1672     new DrawTrSurf_BezierSurface(G,NbUIsos,NbVIsos,
1673                                  BoundsColor,IsosColor,PolesColor,
1674                                  ShowPoles,
1675                                  Discret,Deflection,DrawMode);
1676   return N;
1677 }
1678
1679
1680 static Draw_SaveAndRestore bzssr("DrawTrSurf_BezierSurface",
1681                                bzstest,bzssave,bzsrestore);
1682
1683
1684
1685
1686 //=================================================================
1687 // save and restore bspline surfaces
1688 //=================================================================
1689
1690 static Standard_Boolean bsstest(const Handle(Draw_Drawable3D)& d) 
1691 {
1692   return d->IsInstance(STANDARD_TYPE(DrawTrSurf_BSplineSurface));
1693 }
1694
1695 static void bsssave(const Handle(Draw_Drawable3D)&d, std::ostream& OS)
1696 {
1697   Handle(DrawTrSurf_BSplineSurface) 
1698     N = Handle(DrawTrSurf_BSplineSurface)::DownCast(d);
1699   GeomTools_SurfaceSet::PrintSurface(N->GetSurface(),OS,Standard_True);
1700 }
1701
1702 static Handle(Draw_Drawable3D) bssrestore (std::istream& is)
1703 {
1704   Handle(Geom_BSplineSurface) G =
1705     Handle(Geom_BSplineSurface)::DownCast (GeomTools_SurfaceSet::ReadSurface(is));
1706   Handle(DrawTrSurf_BSplineSurface) N;
1707   if (!knotsIsos) 
1708     N   = new DrawTrSurf_BSplineSurface(G,
1709                                         NbUIsos,NbVIsos,
1710                                         BoundsColor,IsosColor,
1711                                         PolesColor,KnotsColor,
1712                                         KnotsShape,KnotsSize,
1713                                         ShowPoles,ShowKnots,
1714                                               Discret,Deflection,DrawMode);
1715   else
1716     N   = new DrawTrSurf_BSplineSurface(G,
1717                                         BoundsColor,IsosColor,
1718                                         PolesColor,KnotsColor,
1719                                         KnotsShape,KnotsSize,
1720                                         ShowPoles,ShowKnots,
1721                                         Discret,Deflection,DrawMode);
1722         
1723   return N;
1724 }
1725
1726
1727 static Draw_SaveAndRestore bsssr("DrawTrSurf_BSplineSurface",
1728                                bsstest,bsssave,bssrestore);
1729
1730
1731 //=================================================================
1732 // save and restore points
1733 //=================================================================
1734
1735 static Standard_Boolean pnttest(const Handle(Draw_Drawable3D)& d) 
1736 {
1737   return d->IsInstance(STANDARD_TYPE(DrawTrSurf_Point));
1738 }
1739
1740 static void pntsave(const Handle(Draw_Drawable3D)&d, std::ostream& OS)
1741 {
1742   Handle(DrawTrSurf_Point) 
1743     N = Handle(DrawTrSurf_Point)::DownCast(d);
1744 #if !defined(_MSC_VER) && !defined(__sgi) && !defined(IRIX)
1745   std::ios::fmtflags F = OS.flags();
1746   OS.setf(std::ios::scientific,std::ios::floatfield);
1747   OS.precision(15);
1748 #else
1749   long form = OS.setf(std::ios::scientific);
1750   std::streamsize prec = OS.precision(15);
1751 #endif
1752   gp_Pnt P = N->Point();
1753   if (N->Is3D()) {
1754     OS << "1 ";
1755     OS << P.X() << " " << P.Y() << " " << P.Z() << "\n";
1756   }
1757   else {
1758     OS << "0 ";
1759     OS << P.X() << " " << P.Y() << "\n";
1760   }
1761 #if !defined(_MSC_VER) && !defined(__sgi) && !defined(IRIX)
1762   OS.setf(F);
1763 #else
1764   OS.setf(form);
1765   OS.precision(prec);
1766 #endif
1767 }
1768
1769 static Handle(Draw_Drawable3D) pntrestore (std::istream& is)
1770 {
1771   Standard_Integer is3d;
1772   is >> is3d;
1773   Standard_Real x,y,z = 0.;
1774   if (is3d)
1775     is >> x >> y >> z;
1776   else
1777     is >> x >> y;
1778   Handle(DrawTrSurf_Point) N;
1779   if (is3d)
1780     N = new DrawTrSurf_Point(gp_Pnt(x,y,z),PntShape,PntColor);
1781   else
1782     N = new DrawTrSurf_Point(gp_Pnt2d(x,y),PntShape,PntColor);
1783     
1784   return N;
1785 }
1786
1787
1788 static Draw_SaveAndRestore pntsr("DrawTrSurf_Point",
1789                                pnttest,pntsave,pntrestore);
1790
1791
1792
1793 //=================================================================
1794 // save and restore triangulation
1795 //=================================================================
1796
1797 static Standard_Boolean triatest(const Handle(Draw_Drawable3D)& d) 
1798 {
1799   return d->IsInstance(STANDARD_TYPE(DrawTrSurf_Triangulation));
1800 }
1801
1802 static void triasave(const Handle(Draw_Drawable3D)&d, std::ostream& OS)
1803 {
1804   Handle(DrawTrSurf_Triangulation) 
1805     T = Handle(DrawTrSurf_Triangulation)::DownCast(d);
1806 #if !defined(_MSC_VER) && !defined(__sgi) && !defined(IRIX)
1807   std::ios::fmtflags F = OS.flags();
1808   OS.setf(std::ios::scientific,std::ios::floatfield);
1809   OS.precision(15);
1810 #else
1811   long form = OS.setf(std::ios::scientific);
1812   std::streamsize prec = OS.precision(15);
1813 #endif
1814   Poly::Write(T->Triangulation(),OS);
1815 #if !defined(_MSC_VER) && !defined(__sgi) && !defined(IRIX)
1816   OS.setf(F);
1817 #else
1818   OS.setf(form);
1819   OS.precision(prec);
1820 #endif
1821 }
1822
1823 static Handle(Draw_Drawable3D) triarestore (std::istream& is)
1824 {
1825   return new DrawTrSurf_Triangulation(Poly::ReadTriangulation(is));
1826 }
1827
1828
1829 static Draw_SaveAndRestore triasr("DrawTrSurf_Triangulation",
1830                                triatest,triasave,triarestore);
1831
1832
1833
1834 //=================================================================
1835 // save and restore polygon3d
1836 //=================================================================
1837
1838 static Standard_Boolean poly3dtest(const Handle(Draw_Drawable3D)& d) 
1839 {
1840   return d->IsInstance(STANDARD_TYPE(DrawTrSurf_Polygon3D));
1841 }
1842
1843 static void poly3dsave(const Handle(Draw_Drawable3D)&d, std::ostream& OS)
1844 {
1845   Handle(DrawTrSurf_Polygon3D) 
1846     T = Handle(DrawTrSurf_Polygon3D)::DownCast(d);
1847 #if !defined(_MSC_VER) && !defined(__sgi) && !defined(IRIX)
1848   std::ios::fmtflags F = OS.flags();
1849   OS.setf(std::ios::scientific,std::ios::floatfield);
1850   OS.precision(15);
1851 #else
1852   long form = OS.setf(std::ios::scientific);
1853   std::streamsize prec = OS.precision(15);
1854 #endif
1855   Poly::Write(T->Polygon3D(),OS);
1856 #if !defined(_MSC_VER) && !defined(__sgi) && !defined(IRIX)
1857   OS.setf(F);
1858 #else
1859   OS.setf(form);
1860   OS.precision(prec);
1861 #endif
1862 }
1863
1864 static Handle(Draw_Drawable3D) poly3drestore (std::istream& is)
1865 {
1866   return new DrawTrSurf_Polygon3D(Poly::ReadPolygon3D(is));
1867 }
1868
1869
1870 static Draw_SaveAndRestore poly3dsr("DrawTrSurf_Polygon3D",
1871                                poly3dtest,poly3dsave,poly3drestore);
1872
1873
1874 //=================================================================
1875 // save and restore polygon2d
1876 //=================================================================
1877
1878 static Standard_Boolean poly2dtest(const Handle(Draw_Drawable3D)& d) 
1879 {
1880   return d->IsInstance(STANDARD_TYPE(DrawTrSurf_Polygon2D));
1881 }
1882
1883 static void poly2dsave(const Handle(Draw_Drawable3D)&d, std::ostream& OS)
1884 {
1885   Handle(DrawTrSurf_Polygon2D) 
1886     T = Handle(DrawTrSurf_Polygon2D)::DownCast(d);
1887 #if !defined(_MSC_VER) && !defined(__sgi) && !defined(IRIX)
1888   std::ios::fmtflags F = OS.flags();
1889   OS.setf(std::ios::scientific, std::ios::floatfield);
1890   OS.precision(15);
1891 #else
1892   long form = OS.setf(std::ios::scientific);
1893   std::streamsize prec = OS.precision(15);
1894 #endif
1895   Poly::Write(T->Polygon2D(),OS);
1896 #if !defined(_MSC_VER) && !defined(__sgi) && !defined(IRIX)
1897   OS.setf(F);
1898 #else
1899   OS.setf(form);
1900   OS.precision(prec);
1901 #endif
1902 }
1903
1904 static Handle(Draw_Drawable3D) poly2drestore (std::istream& is)
1905 {
1906   return new DrawTrSurf_Polygon2D(Poly::ReadPolygon2D(is));
1907 }
1908
1909
1910 static Draw_SaveAndRestore poly2dsr("DrawTrSurf_Polygon2D",
1911                                poly2dtest,poly2dsave,poly2drestore);
1912