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