0024510: Remove unused local variables
[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             DrawMode = 1;
396           }
397           if (DrawMode)
398             di << "u";
399           else
400             di << "d";
401         }
402         
403         else if (!strcmp(a[0],"discr")) {
404           if (n == 2)
405             Discret = Draw::Atoi(a[n-1]);
406           di << Discret;
407         }
408         
409         else if (!strcmp(a[0],"defle")) {
410           if (n == 2)
411             Deflection = Draw::Atof(a[n-1]);
412           di << Deflection;
413         }
414   }
415   else {
416     for (Standard_Integer i = 1; i < n - 1; i++) {
417       Handle(DrawTrSurf_Drawable) D = GetDrawable(a[1]);
418       if (!D.IsNull()) {
419         if (!strcmp(a[0],"dmode")) {
420           Standard_Integer mod = 0;
421           if ((*a[n-1] == 'U')||(*a[n-1] == 'u')) mod = 1;
422           D->SetDrawMode(mod);
423         }
424         
425         else if (!strcmp(a[0],"discr")) {
426           D->SetDiscretisation(Draw::Atoi(a[n-1]));
427         }
428         
429         else if (!strcmp(a[0],"defle")) {
430           D->SetDeflection(Draw::Atof(a[n-1]));
431         }
432         
433         Draw::Repaint();
434       }
435     }
436   }
437   return 0;
438 }
439
440 //=======================================================================
441 //function : transform
442 //purpose  : 
443 //=======================================================================
444
445 static Standard_Integer transform (Draw_Interpretor& di, Standard_Integer n, const char** a)
446 {
447   if (n < 5) return 1;
448   gp_Trsf T;
449   Standard_Integer i,last = n-1;
450   if (!strcmp(a[0],"pscale")) {
451     Standard_Real s = Draw::Atof(a[last]);
452     last--;
453     if (last < 4) return 1;
454     gp_Pnt P(Draw::Atof(a[last-2]),Draw::Atof(a[last-1]),Draw::Atof(a[last]));
455     T.SetScale(P,s);
456   }
457   else if (!strcmp(a[0]+1,"mirror")) {
458     if (last < 4) return 1;
459     gp_Pnt P(Draw::Atof(a[last-2]),Draw::Atof(a[last-1]),Draw::Atof(a[last]));
460     if (*a[0] == 'p') {
461       T.SetMirror(P);
462     }
463     else {
464       last -= 3;
465       if (last < 4) return 1;
466       gp_Pnt O(Draw::Atof(a[last-2]),Draw::Atof(a[last-1]),Draw::Atof(a[last]));
467       last -= 3;
468       gp_Dir D(P.X(),P.Y(),P.Z());
469       if (*a[0] == 'l') {
470         T.SetMirror(gp_Ax1(O,D));
471       }
472       else if (*a[0] == 's') {
473         gp_Pln Pl(O,D);
474         T.SetMirror(Pl.Position().Ax2());
475       }
476     }
477   }
478
479   else if (!strcmp(a[0],"translate")) {
480     if (last < 4) return 1;
481     gp_Vec V(Draw::Atof(a[last-2]),Draw::Atof(a[last-1]),Draw::Atof(a[last]));
482     last -= 3;
483     T.SetTranslation(V);
484   }
485
486   else if (!strcmp(a[0],"rotate")) {
487     if (last < 8) return 1;
488     Standard_Real ang = Draw::Atof(a[last]) * (M_PI / 180.0);
489     last --;
490     gp_Dir D(Draw::Atof(a[last-2]),Draw::Atof(a[last-1]),Draw::Atof(a[last]));
491     last -= 3;
492     gp_Pnt P(Draw::Atof(a[last-2]),Draw::Atof(a[last-1]),Draw::Atof(a[last]));
493     last -= 3;
494     T.SetRotation(gp_Ax1(P,D),ang);
495   }
496
497   for (i = 1; i <= last; i++) {
498     Handle(Geom_Geometry) G = DrawTrSurf::Get(a[i]);
499     if (!G.IsNull()) {
500       G->Transform(T);
501       Draw::Repaint();
502     }
503     else {
504       gp_Pnt P;
505       if (DrawTrSurf::GetPoint(a[i],P)) {
506         P.Transform(T);
507         DrawTrSurf::Set(a[i],P);
508       }
509     }
510     di << a[i] << " ";
511   }
512   return 0;
513 }
514
515 //=======================================================================
516 //function : d2transform
517 //purpose  : 
518 //=======================================================================
519
520 static Standard_Integer d2transform (Draw_Interpretor& di, Standard_Integer n, const char** a)
521 {
522   if (n < 4) return 1;
523   gp_Trsf2d T;
524   Standard_Integer i,last = n-1;
525   if (!strcmp(a[0],"2dpscale")) {
526     Standard_Real s = Draw::Atof(a[last]);
527     last--;
528     if (last < 3) return 1;
529     gp_Pnt2d P(Draw::Atof(a[last-1]),Draw::Atof(a[last]));
530     T.SetScale(P,s);
531   }
532   else if ( (!strcmp(a[0],"2dpmirror")) || 
533             (!strcmp(a[0],"2dlmirror"))   ) {
534     if (last < 3) return 1;
535     gp_Pnt2d P(Draw::Atof(a[last-1]),Draw::Atof(a[last]));
536     if (!strcmp(a[0],"2dpmirror")) {
537       T.SetMirror(P);
538     }
539     else {
540       last -= 2;
541       if (last < 3) return 1;
542       gp_Pnt2d O(Draw::Atof(a[last-1]),Draw::Atof(a[last]));
543       last -= 2;
544       gp_Dir2d D(P.X(),P.Y());
545       T.SetMirror(gp_Ax2d(O,D));
546     }
547   }
548
549   else if (!strcmp(a[0],"2dtranslate")) {
550     if (last < 3) return 1;
551     gp_Vec2d V(Draw::Atof(a[last-1]),Draw::Atof(a[last]));
552     last -= 2;
553     T.SetTranslation(V);
554   }
555
556   else if (!strcmp(a[0],"2drotate")) {
557     if (last < 4) return 1;
558     Standard_Real ang = Draw::Atof(a[last]) * (M_PI / 180.0);
559     last --;
560     gp_Pnt2d P(Draw::Atof(a[last-1]),Draw::Atof(a[last]));
561     last -= 2;
562     T.SetRotation(P,ang);
563   }
564
565   for (i = 1; i <= last; i++) {
566     Handle(Geom2d_Curve) G = DrawTrSurf::GetCurve2d(a[i]);
567     if (!G.IsNull()) {
568       G->Transform(T);
569       Draw::Repaint();
570     }
571     else {
572       gp_Pnt2d P;
573       if (DrawTrSurf::GetPoint2d(a[i],P)) {
574         P.Transform(T);
575         DrawTrSurf::Set(a[i],P);
576       }
577     }
578     di << a[i] << " ";
579   }
580   return 0;
581 }
582
583 //=======================================================================
584 //function : Set
585 //purpose  : point
586 //=======================================================================
587 void  DrawTrSurf::Set(const Standard_CString Name, 
588                       const gp_Pnt& P)
589 {
590   Handle(DrawTrSurf_Point) DP = new DrawTrSurf_Point(P,PntShape,PntColor);
591  Draw::Set(Name,DP);
592 }
593
594 //=======================================================================
595 //function : Set
596 //purpose  : point
597 //=======================================================================
598 void  DrawTrSurf::Set(const Standard_CString Name, 
599                       const gp_Pnt2d& P)
600 {
601   Handle(DrawTrSurf_Point) DP = new DrawTrSurf_Point(P,PntShape,PntColor);
602  Draw::Set(Name,DP);
603 }
604
605 //=======================================================================
606 //function : Set
607 //purpose  : Geometry from Geom
608 //=======================================================================
609 void  DrawTrSurf::Set(const Standard_CString Name, 
610                       const Handle(Geom_Geometry)& G,
611                       const Standard_Boolean isSenseMarker)
612 {
613   Handle(DrawTrSurf_Drawable) D;
614   if (!G.IsNull()) {
615
616     Handle(Geom_Curve) C = Handle(Geom_Curve)::DownCast(G);
617     if (!C.IsNull()) {
618       
619       Handle(Geom_BezierCurve) Bez = 
620         Handle(Geom_BezierCurve)::DownCast(C);
621       if (!Bez.IsNull()) {
622         Handle(DrawTrSurf_BezierCurve) DBez = 
623           new DrawTrSurf_BezierCurve(Bez,CurvColor,PolesColor,ShowPoles,
624                                      Discret,Deflection,DrawMode);
625         D = DBez;
626       }
627
628
629       Handle(Geom_BSplineCurve) BS = 
630         Handle(Geom_BSplineCurve)::DownCast(C);
631       if (!BS.IsNull()) {
632         Handle(DrawTrSurf_BSplineCurve) DBS = 
633           new DrawTrSurf_BSplineCurve(BS,
634                                       CurvColor,PolesColor,
635                                       KnotsColor,
636                                       KnotsShape,KnotsSize,
637                                       ShowPoles,ShowKnots,
638                                       Discret,Deflection,DrawMode);
639         D = DBS;
640       }
641
642       if (Bez.IsNull() && BS.IsNull()) {
643         Handle(DrawTrSurf_Curve) DC =
644           new DrawTrSurf_Curve(C,CurvColor,Discret,Deflection,DrawMode,isSenseMarker);
645         D = DC;
646       }
647     }
648
649
650     Handle(Geom_Surface) S = Handle(Geom_Surface)::DownCast(G);
651     if (!S.IsNull()) {
652       
653       Handle(Geom_BezierSurface) Bez = 
654         Handle(Geom_BezierSurface)::DownCast(S);
655       if (!Bez.IsNull()) {
656         Handle(DrawTrSurf_BezierSurface) DBez = 
657           new DrawTrSurf_BezierSurface(Bez,NbUIsos,NbVIsos,
658                                        BoundsColor,IsosColor,PolesColor,
659                                        ShowPoles,
660                                        Discret,Deflection,DrawMode);
661         D = DBez;
662       }
663
664
665       Handle(Geom_BSplineSurface) BS = 
666         Handle(Geom_BSplineSurface)::DownCast(S);
667       if (!BS.IsNull()) {
668         Handle(DrawTrSurf_BSplineSurface) DBS ;
669         if (!knotsIsos) 
670           DBS = new DrawTrSurf_BSplineSurface(BS,
671                                               NbUIsos,NbVIsos,
672                                               BoundsColor,IsosColor,
673                                               PolesColor,KnotsColor,
674                                               KnotsShape,KnotsSize,
675                                               ShowPoles,ShowKnots,
676                                               Discret,Deflection,DrawMode);
677         else
678           DBS = new DrawTrSurf_BSplineSurface(BS,
679                                               BoundsColor,IsosColor,
680                                               PolesColor,KnotsColor,
681                                               KnotsShape,KnotsSize,
682                                               ShowPoles,ShowKnots,
683                                               Discret,Deflection,DrawMode);
684         
685         D = DBS;
686       }
687
688       if (Bez.IsNull() && BS.IsNull()) {
689         Handle(DrawTrSurf_Surface) DS =
690           new DrawTrSurf_Surface(S,
691                                  NbUIsos,NbVIsos,
692                                  BoundsColor,IsosColor,
693                                  Discret,Deflection,DrawMode);
694         D = DS;
695       }
696     }
697
698   }
699   Draw::Set(Name,D);
700 }
701
702
703 //=======================================================================
704 //function : Set
705 //purpose  : Curve from Geom2d
706 //=======================================================================
707 void  DrawTrSurf::Set(const Standard_CString Name, 
708                       const Handle(Geom2d_Curve)& C,
709                       const Standard_Boolean isSenseMarker)
710 {
711   Handle(DrawTrSurf_Drawable) D;
712   if (!C.IsNull()) {
713
714       Handle(Geom2d_BezierCurve) Bez = 
715         Handle(Geom2d_BezierCurve)::DownCast(C);
716       if (!Bez.IsNull()) {
717         Handle(DrawTrSurf_BezierCurve2d) DBez = 
718           new DrawTrSurf_BezierCurve2d(Bez,CurvColor,PolesColor,ShowPoles,
719                                        Discret);
720         D = DBez;
721       }
722
723
724       Handle(Geom2d_BSplineCurve) BS = 
725         Handle(Geom2d_BSplineCurve)::DownCast(C);
726       if (!BS.IsNull()) {
727         Handle(DrawTrSurf_BSplineCurve2d) DBS = 
728           new DrawTrSurf_BSplineCurve2d(BS,
729                                         CurvColor,PolesColor,
730                                         KnotsColor,
731                                         KnotsShape,KnotsSize,
732                                         ShowPoles,ShowKnots,
733                                         Discret);
734         D = DBS;
735       }
736       
737       if (Bez.IsNull() && BS.IsNull()) {
738         Handle(DrawTrSurf_Curve2d) DC =
739           new DrawTrSurf_Curve2d(C,CurvColor,Discret,isSenseMarker);
740         D = DC;
741       }
742     }
743
744   Draw::Set(Name,D);
745 }
746
747 //=======================================================================
748 //function : Set
749 //purpose  : 
750 //=======================================================================
751 void DrawTrSurf::Set(const Standard_CString Name, 
752                      const Handle(Poly_Triangulation)& T)
753 {
754   Handle(DrawTrSurf_Triangulation) D = new DrawTrSurf_Triangulation(T);
755   Draw::Set(Name,D);
756 }
757 //=======================================================================
758 //function : Set
759 //purpose  : 
760 //=======================================================================
761 void DrawTrSurf::Set(const Standard_CString Name, 
762                      const Handle(Poly_Polygon3D)& P)
763 {
764   Handle(DrawTrSurf_Polygon3D) D = new DrawTrSurf_Polygon3D(P);
765   Draw::Set(Name,D);
766 }
767
768 //=======================================================================
769 //function : Set
770 //purpose  : 
771 //=======================================================================
772 void DrawTrSurf::Set(const Standard_CString Name, 
773                      const Handle(Poly_Polygon2D)& P)
774 {
775   Handle(DrawTrSurf_Polygon2D) D = new DrawTrSurf_Polygon2D(P);
776   Draw::Set(Name,D);
777 }
778
779 //=======================================================================
780 //function : Get
781 //purpose  : 
782 //=======================================================================
783 Handle(Geom_Geometry)  DrawTrSurf::Get(Standard_CString& Name)
784 {
785   Handle(Draw_Drawable3D) D = Draw::Get(Name);
786
787   Handle(DrawTrSurf_Curve) DC = 
788     Handle(DrawTrSurf_Curve)::DownCast(D);
789   if (!DC.IsNull())
790     return DC->GetCurve();
791
792   Handle(DrawTrSurf_Surface) DS = 
793     Handle(DrawTrSurf_Surface)::DownCast(D);
794   if (!DS.IsNull())
795     return DS->GetSurface();
796
797   return Handle(Geom_Geometry) ();
798 }
799
800
801 //=======================================================================
802 //function : GetPoint
803 //purpose  : 
804 //=======================================================================
805 Standard_Boolean DrawTrSurf::GetPoint(Standard_CString& Name,
806                                       gp_Pnt& P)
807 {
808   Handle(DrawTrSurf_Point) D = 
809     Handle(DrawTrSurf_Point)::DownCast(Draw::Get(Name));
810   if (D.IsNull())
811     return Standard_False;
812   else if (!D->Is3D())
813     return Standard_False;
814   else {
815     P = D->Point();
816     return Standard_True;
817   }
818 }
819
820 //=======================================================================
821 //function : GetPoint2d
822 //purpose  : 
823 //=======================================================================
824 Standard_Boolean DrawTrSurf::GetPoint2d(Standard_CString& Name,
825                                         gp_Pnt2d& P)
826 {
827   Handle(DrawTrSurf_Point) D = 
828     Handle(DrawTrSurf_Point)::DownCast(Draw::Get(Name));
829   if (D.IsNull())
830     return Standard_False;
831   else if (D->Is3D()) 
832     return Standard_False;
833   else {
834     P = D->Point2d();
835     return Standard_True;
836   }
837 }
838
839 //=======================================================================
840 //function : GetCurve
841 //purpose  : 
842 //=======================================================================
843 Handle(Geom_Curve)  DrawTrSurf::GetCurve(Standard_CString& Name)
844 {
845   Handle(DrawTrSurf_Curve) D = 
846     Handle(DrawTrSurf_Curve)::DownCast(Draw::Get(Name));
847   if (D.IsNull())
848     return Handle(Geom_Curve)();
849   else
850     return D->GetCurve();
851 }
852
853
854 //=======================================================================
855 //function : GetBezierCurve
856 //purpose  : 
857 //=======================================================================
858 Handle(Geom_BezierCurve)  DrawTrSurf::GetBezierCurve(Standard_CString& Name)
859 {
860   Handle(DrawTrSurf_BezierCurve) D = 
861     Handle(DrawTrSurf_BezierCurve)::DownCast(Draw::Get(Name));
862   if (D.IsNull())
863     return Handle(Geom_BezierCurve)();
864   else
865     return Handle(Geom_BezierCurve)::DownCast(D->GetCurve());
866 }
867
868
869 //=======================================================================
870 //function : GetBSplineCurve
871 //purpose  : 
872 //=======================================================================
873 Handle(Geom_BSplineCurve)  DrawTrSurf::GetBSplineCurve(Standard_CString& Name)
874 {
875   Handle(DrawTrSurf_BSplineCurve) D = 
876     Handle(DrawTrSurf_BSplineCurve)::DownCast(Draw::Get(Name));
877   if (D.IsNull())
878     return Handle(Geom_BSplineCurve)();
879   else
880     return Handle(Geom_BSplineCurve)::DownCast(D->GetCurve());
881 }
882 //=======================================================================
883 //function : GetCurve2d
884 //purpose  : 
885 //=======================================================================
886 Handle(Geom2d_Curve)  DrawTrSurf::GetCurve2d(Standard_CString& Name)
887 {
888   Handle(DrawTrSurf_Curve2d) D = 
889     Handle(DrawTrSurf_Curve2d)::DownCast(Draw::Get(Name));
890   if (D.IsNull())
891     return Handle(Geom2d_Curve)();
892   else
893     return D->GetCurve();
894 }
895 //=======================================================================
896 //function : GetBezierCurve2d
897 //purpose  : 
898 //=======================================================================
899 Handle(Geom2d_BezierCurve)  DrawTrSurf::GetBezierCurve2d(Standard_CString& Name)
900 {
901   Handle(DrawTrSurf_Curve2d) D = 
902     Handle(DrawTrSurf_Curve2d)::DownCast(Draw::Get(Name));
903   if (D.IsNull())
904     return Handle(Geom2d_BezierCurve)();
905   else
906     return Handle(Geom2d_BezierCurve)::DownCast(D->GetCurve());
907 }
908 //=======================================================================
909 //function : GetBSplineCurve2d
910 //purpose  : 
911 //=======================================================================
912 Handle(Geom2d_BSplineCurve)  DrawTrSurf::GetBSplineCurve2d
913        (Standard_CString& Name)
914 {
915   Handle(DrawTrSurf_Curve2d) D = 
916     Handle(DrawTrSurf_Curve2d)::DownCast(Draw::Get(Name));
917   if (D.IsNull())
918     return Handle(Geom2d_BSplineCurve)();
919   else
920     return Handle(Geom2d_BSplineCurve)::DownCast(D->GetCurve());
921 }
922 //=======================================================================
923 //function : GetSurface
924 //purpose  : 
925 //=======================================================================
926 Handle(Geom_Surface)  DrawTrSurf::GetSurface
927        (Standard_CString& Name)
928 {
929   Handle(DrawTrSurf_Surface) D = 
930     Handle(DrawTrSurf_Surface)::DownCast(Draw::Get(Name));
931   if (D.IsNull())
932     return Handle(Geom_Surface)();
933   else
934     return D->GetSurface();
935 }
936 //=======================================================================
937 //function : GetBezierSurface
938 //purpose  : 
939 //=======================================================================
940 Handle(Geom_BezierSurface)  DrawTrSurf::GetBezierSurface
941        (Standard_CString& Name)
942 {
943   Handle(DrawTrSurf_BezierSurface) D = 
944     Handle(DrawTrSurf_BezierSurface)::DownCast(Draw::Get(Name));
945   if (D.IsNull())
946     return Handle(Geom_BezierSurface)();
947   else
948     return Handle(Geom_BezierSurface)::DownCast(D->GetSurface());
949 }
950 //=======================================================================
951 //function : GetBSplineSurface
952 //purpose  : 
953 //=======================================================================
954 Handle(Geom_BSplineSurface) DrawTrSurf::GetBSplineSurface
955        (Standard_CString& Name)
956 {
957   Handle(DrawTrSurf_BSplineSurface) D = 
958     Handle(DrawTrSurf_BSplineSurface)::DownCast(Draw::Get(Name));
959   if (D.IsNull())
960     return Handle(Geom_BSplineSurface)();
961   else
962     return Handle(Geom_BSplineSurface)::DownCast(D->GetSurface());
963 }
964 //=======================================================================
965 //function : GetTriangulation
966 //purpose  : 
967 //=======================================================================
968 Handle(Poly_Triangulation) DrawTrSurf::GetTriangulation(Standard_CString& Name)
969 {
970   Handle(DrawTrSurf_Triangulation) D =
971     Handle(DrawTrSurf_Triangulation)::DownCast(Draw::Get(Name));
972   if (D.IsNull())
973     return Handle(Poly_Triangulation)();
974   else
975     return D->Triangulation();
976 }
977 //=======================================================================
978 //function : GetPolygon3D
979 //purpose  : 
980 //=======================================================================
981 Handle(Poly_Polygon3D) DrawTrSurf::GetPolygon3D(Standard_CString& Name)
982 {
983   Handle(DrawTrSurf_Polygon3D) D =
984     Handle(DrawTrSurf_Polygon3D)::DownCast(Draw::Get(Name));
985   if (D.IsNull())
986     return Handle(Poly_Polygon3D)();
987   else
988     return D->Polygon3D();
989 }
990 //=======================================================================
991 //function : GetPolygon2D
992 //purpose  : 
993 //=======================================================================
994 Handle(Poly_Polygon2D) DrawTrSurf::GetPolygon2D(Standard_CString& Name)
995 {
996   Handle(DrawTrSurf_Polygon2D) D =
997     Handle(DrawTrSurf_Polygon2D)::DownCast(Draw::Get(Name));
998   if (D.IsNull())
999     return Handle(Poly_Polygon2D)();
1000   else
1001     return D->Polygon2D();
1002 }
1003
1004 //=======================================================================
1005 //function : printColor
1006 //purpose  : 
1007 //=======================================================================
1008
1009 static void printColor(Draw_Interpretor& di, const Draw_Color& theColor)
1010 {
1011   switch ( theColor.ID() )
1012   {
1013     case Draw_blanc:   di << "white "            << "\n"; break;
1014     case Draw_rouge:   di << "red "              << "\n"; break;
1015     case Draw_vert:    di << "green "            << "\n"; break;
1016     case Draw_bleu:    di << "blue "             << "\n"; break;
1017     case Draw_cyan:    di << "cyan "             << "\n"; break;
1018     case Draw_or:      di << "golden "           << "\n"; break;
1019     case Draw_magenta: di << "magenta "          << "\n"; break;
1020     case Draw_marron:  di << "brown "            << "\n"; break;
1021     case Draw_orange:  di << "orange "           << "\n"; break;
1022     case Draw_rose:    di << "pink "             << "\n"; break;
1023     case Draw_saumon:  di << "salmon "           << "\n"; break;
1024     case Draw_violet:  di << "violet "           << "\n"; break;
1025     case Draw_jaune:   di << "yellow "           << "\n"; break;
1026     case Draw_kaki:    di << "dark-olive green " << "\n"; break;
1027     case Draw_corail:  di << "coral "            << "\n"; break;
1028   }
1029 }
1030
1031 //=======================================================================
1032 //function : recognizeColor
1033 //purpose  : 
1034 //=======================================================================
1035
1036 static Draw_Color recognizeColor(const char* theColorStr,
1037                                  const Draw_Color& theDefaultColor)
1038 {
1039   Draw_Color aResult = theDefaultColor;
1040
1041   if ( !strcasecmp(theColorStr,"white") )
1042     aResult = Draw_blanc;
1043   if ( !strcasecmp(theColorStr, "red") )
1044     aResult = Draw_rouge;
1045   if ( !strcasecmp(theColorStr, "green") )
1046     aResult = Draw_vert;
1047   if ( !strcasecmp(theColorStr, "blue") )
1048     aResult = Draw_bleu;
1049   if ( !strcasecmp(theColorStr, "cyan") )
1050     aResult = Draw_cyan;
1051   if ( !strcasecmp(theColorStr, "golden") )
1052     aResult = Draw_or;
1053   if ( !strcasecmp(theColorStr, "magenta") )
1054     aResult = Draw_magenta;
1055   if ( !strcasecmp(theColorStr, "brown") )
1056     aResult = Draw_marron;
1057   if ( !strcasecmp(theColorStr, "orange") )
1058     aResult = Draw_orange;
1059   if ( !strcasecmp(theColorStr, "pink") )
1060     aResult = Draw_rose;
1061   if ( !strcasecmp(theColorStr, "salmon") )
1062     aResult = Draw_saumon;
1063   if ( !strcasecmp(theColorStr, "violet") )
1064     aResult = Draw_violet;
1065   if ( !strcasecmp(theColorStr, "yellow") )
1066     aResult = Draw_jaune;
1067   if ( !strcasecmp(theColorStr, "darkgreen") )
1068     aResult = Draw_kaki;
1069   if ( !strcasecmp(theColorStr, "coral") )
1070     aResult = Draw_corail;
1071
1072   return aResult;
1073 }
1074
1075 //=======================================================================
1076 //function : setcurvcolor
1077 //purpose  : 
1078 //=======================================================================
1079
1080 static Standard_Integer setcurvcolor(Draw_Interpretor& di,
1081                                      Standard_Integer n, const char** a)
1082 {
1083   Draw_Color col, savecol;
1084
1085   savecol = DrawTrSurf_CurveColor(Draw_Color(Draw_jaune));
1086   DrawTrSurf_CurveColor(savecol);
1087
1088   if (n < 2)
1089   {
1090     printColor(di, savecol);
1091   }
1092   else {
1093     col = recognizeColor(a[1], savecol);
1094     DrawTrSurf_CurveColor(col);
1095   }
1096   return 0;
1097 }
1098
1099 //=======================================================================
1100 //function : changecurvcolor
1101 //purpose  : 
1102 //=======================================================================
1103
1104 static Standard_Integer changecurvcolor(Draw_Interpretor&,
1105                                         Standard_Integer n, const char** a)
1106 {
1107   Draw_Color col, savecol;
1108
1109   savecol = DrawTrSurf_CurveColor(Draw_Color(Draw_jaune));
1110   DrawTrSurf_CurveColor(savecol);
1111
1112   if ( n < 3 )
1113     return 1;
1114
1115   col = recognizeColor(a[1], savecol);
1116     
1117   Handle(DrawTrSurf_Curve) D = Handle(DrawTrSurf_Curve)::DownCast( Draw::Get(a[2]) );
1118   if ( !D.IsNull() )
1119   {
1120     D->SetColor(col);
1121     Draw::Repaint();
1122   }
1123
1124   return 0;
1125 }
1126
1127 //=======================================================================
1128 //function : setpointcolor
1129 //purpose  : 
1130 //=======================================================================
1131
1132 static Standard_Integer setpointcolor(Draw_Interpretor& di,
1133                                       Standard_Integer n, const char** a)
1134 {
1135   Draw_Color col, savecol;
1136
1137   savecol = DrawTrSurf_PointColor(Draw_Color(Draw_jaune));
1138   DrawTrSurf_PointColor(savecol);
1139
1140   if (n < 2)
1141   {
1142     printColor(di, savecol);
1143   }
1144   else {
1145     col = recognizeColor(a[1], savecol);
1146     DrawTrSurf_PointColor(col);
1147   }
1148   return 0;
1149 }
1150
1151 //=======================================================================
1152 //function : changepointcolor
1153 //purpose  : 
1154 //=======================================================================
1155
1156 static Standard_Integer changepointcolor(Draw_Interpretor&,
1157                                          Standard_Integer n, const char** a)
1158 {
1159   Draw_Color col, savecol;
1160
1161   savecol = DrawTrSurf_PointColor(Draw_Color(Draw_jaune));
1162   DrawTrSurf_PointColor(savecol);
1163
1164   if ( n < 3 )
1165     return 1;
1166
1167   col = recognizeColor(a[1], savecol);
1168     
1169   Handle(DrawTrSurf_Point) D = Handle(DrawTrSurf_Point)::DownCast( Draw::Get(a[2]) );
1170   if ( !D.IsNull() )
1171   {
1172     D->Color(col);
1173     Draw::Repaint();
1174   }
1175
1176   return 0;
1177 }
1178
1179 //=======================================================================
1180 //function : printMarker
1181 //purpose  : 
1182 //=======================================================================
1183
1184 static void printMarker(Draw_Interpretor& di, const Draw_MarkerShape& theMarker)
1185 {
1186   switch ( theMarker )
1187   {
1188     case Draw_Square:     di << "square "      << "\n"; break;
1189     case Draw_Losange:    di << "diamond "     << "\n"; break;
1190     case Draw_X:          di << "x "           << "\n"; break;
1191     case Draw_Plus:       di << "plus "        << "\n"; break;
1192     case Draw_Circle:     di << "circle "      << "\n"; break;
1193     case Draw_CircleZoom: di << "circle_zoom " << "\n"; break;
1194   }
1195 }
1196
1197 //=======================================================================
1198 //function : recognizeMarker
1199 //purpose  : 
1200 //=======================================================================
1201
1202 static Draw_MarkerShape recognizeMarker(const char* theMarkerStr,
1203                                         const Draw_MarkerShape& theDefaultMarker)
1204 {
1205   Draw_MarkerShape aResult = theDefaultMarker;
1206
1207   if ( !strcasecmp(theMarkerStr, "square") )
1208     aResult = Draw_Square;
1209   if ( !strcasecmp(theMarkerStr, "diamond") )
1210     aResult = Draw_Losange;
1211   if ( !strcasecmp(theMarkerStr, "x") )
1212     aResult = Draw_X;
1213   if ( !strcasecmp(theMarkerStr, "plus") )
1214     aResult = Draw_Plus;
1215   if ( !strcasecmp(theMarkerStr, "circle") )
1216     aResult = Draw_Circle;
1217   if ( !strcasecmp(theMarkerStr, "circle_zoom") )
1218     aResult = Draw_CircleZoom;
1219
1220   return aResult;
1221 }
1222
1223 //=======================================================================
1224 //function : setpointmarker
1225 //purpose  : 
1226 //=======================================================================
1227
1228 static Standard_Integer setpointmarker(Draw_Interpretor& di,
1229                                        Standard_Integer n, const char** a)
1230 {
1231   Draw_MarkerShape mark, savemark;
1232
1233   savemark = DrawTrSurf_PointMarker(Draw_MarkerShape(Draw_Plus));
1234   DrawTrSurf_PointMarker(savemark);
1235
1236   if ( n < 2 )
1237   {
1238     printMarker(di, savemark);
1239   }
1240   else {
1241     mark = recognizeMarker(a[1], savemark);
1242     DrawTrSurf_PointMarker(mark);
1243   }
1244   return 0;
1245 }
1246
1247 //=======================================================================
1248 //function : changepointmarker
1249 //purpose  : 
1250 //=======================================================================
1251
1252 static Standard_Integer changepointmarker(Draw_Interpretor&,
1253                                           Standard_Integer n, const char** a)
1254 {
1255   Draw_MarkerShape mark, savemark;
1256
1257   savemark = DrawTrSurf_PointMarker(Draw_MarkerShape(Draw_Plus));
1258   DrawTrSurf_PointMarker(savemark);
1259
1260   if ( n < 3 )
1261     return 1;
1262
1263   mark = recognizeMarker(a[1], savemark);
1264     
1265   Handle(DrawTrSurf_Point) D = Handle(DrawTrSurf_Point)::DownCast( Draw::Get(a[2]) );
1266   if ( !D.IsNull() )
1267   {
1268     D->Shape(mark);
1269     Draw::Repaint();
1270   }
1271
1272   return 0;
1273 }
1274
1275 //=======================================================================
1276 //function : BasicCommands
1277 //purpose  : 
1278 //=======================================================================
1279
1280 static Standard_Boolean done = Standard_False;
1281 void  DrawTrSurf::BasicCommands(Draw_Interpretor& theCommands)
1282 {
1283   if (done) return;
1284   done = Standard_True;
1285
1286   const char* g;
1287   g = "geometric display commands";
1288   
1289   theCommands.Add("nbiso",
1290                   "nbiso name [names...] nuiso nviso",
1291                   __FILE__,
1292                   nbiso,g);
1293   
1294   theCommands.Add("clpoles",
1295                   "clpoles [name], no args : modal ",
1296                   __FILE__,
1297                   drawpoles,g);
1298   
1299   theCommands.Add("shpoles",
1300                   "shpoles [name], no args : modal ",
1301                   __FILE__,
1302                   drawpoles,g);
1303   
1304   theCommands.Add("clknots",
1305                   "clknots [name], no args : modal ",
1306                   __FILE__,
1307                   drawpoles,g);
1308   
1309   theCommands.Add("shknots",
1310                   "shknots [name], no args : modal ",
1311                   __FILE__,
1312                   drawpoles,g);
1313   
1314   theCommands.Add("dmode",
1315                   "dmode [names...] Uniform/Discret",
1316                   __FILE__,
1317                   draw,g);
1318
1319   theCommands.Add("discr",
1320                   "discr [names...] nbintervals",
1321                   __FILE__,
1322                   draw,g);
1323
1324   theCommands.Add("defle",
1325                   "defle [names...] defle",
1326                   __FILE__,
1327                   draw,g);
1328
1329   theCommands.Add("setcurvcolor",
1330                   TCollection_AsciiString("setcurvcolor [color] : set curve color\
1331  by default, or print the current curve color if no argument (this does not modify\
1332  the color of the curve)\n\n").Cat(ColorsHint).ToCString(),
1333                   __FILE__,setcurvcolor,g);
1334
1335   theCommands.Add("changecurvcolor",
1336                   TCollection_AsciiString("changecurvcolor color curve: change\
1337  color of the curve\n\n").Cat(ColorsHint).ToCString(),
1338                   __FILE__,changecurvcolor,g);
1339
1340   theCommands.Add("setpointcolor",
1341                   TCollection_AsciiString("setpointcolor [color] : set point color\
1342  by default, or print the current point color if no argument (this does not modify\
1343  the color of the point)\n\n").Cat(ColorsHint).ToCString(),
1344                   __FILE__,setpointcolor,g);
1345
1346   theCommands.Add("changepointcolor",
1347                   TCollection_AsciiString("changepointcolor color point: change\
1348  color of the point\n\n").Cat(ColorsHint).ToCString(),
1349                   __FILE__,changepointcolor,g);
1350   
1351   theCommands.Add("setpointmarker",
1352                   TCollection_AsciiString("setpointmarker [marker] : set point marker\
1353  by default, or print the current point marker if no argument (this does not modify\
1354  the marker of the point)\n\n").Cat(MarkersHint).ToCString(),
1355                   __FILE__,setpointmarker,g);
1356
1357   theCommands.Add("changepointmarker",
1358                   TCollection_AsciiString("changepointmarker marker point: change\
1359  marker of the point\n\n").Cat(MarkersHint).ToCString(),
1360                   __FILE__,changepointmarker,g);
1361
1362   g = "Geometric tranformations";
1363   
1364   theCommands.Add("translate",
1365                   "translate name [names...] dx dy dz",
1366                   __FILE__,
1367                   transform,g);
1368
1369   theCommands.Add("rotate",
1370                   "rotate name [names...] x y z dx dy dz angle",
1371                   __FILE__,
1372                   transform,g);
1373
1374   theCommands.Add("pmirror",
1375                   "pmirror name [names...] x y z",
1376                   __FILE__,
1377                   transform,g);
1378
1379   theCommands.Add("lmirror",
1380                   "lmirror name [names...] x y z dx dy dz",
1381                   __FILE__,
1382                   transform,g);
1383
1384   theCommands.Add("smirror",
1385                   "smirror name [names...] x y z dx dy dz",
1386                   __FILE__,
1387                   transform,g);
1388
1389   theCommands.Add("pscale",
1390                   "pscale name [names...] x y z s",
1391                   __FILE__,
1392                   transform,g);
1393
1394   theCommands.Add("2dtranslate",
1395                   "translate name [names...] dx dy",
1396                   __FILE__,
1397                   d2transform,g);
1398
1399   theCommands.Add("2drotate",
1400                   "rotate name [names...] x y dx dy  angle",
1401                   __FILE__,
1402                   d2transform,g);
1403
1404   theCommands.Add("2dpmirror",
1405                   "pmirror name [names...] x y",
1406                   __FILE__,
1407                   d2transform,g);
1408
1409   theCommands.Add("2dlmirror",
1410                   "lmirror name [names...] x y dx dy",
1411                   __FILE__,
1412                   d2transform,g);
1413
1414   theCommands.Add("2dpscale",
1415                   "pscale name [names...] x y s",
1416                   __FILE__,
1417                   d2transform,g);
1418 }
1419
1420
1421 //=================================================================
1422 // save and restore curves
1423 //=================================================================
1424
1425 static Standard_Boolean ctest(const Handle(Draw_Drawable3D)& d) 
1426 {
1427   return d->IsInstance(STANDARD_TYPE(DrawTrSurf_Curve));
1428 }
1429
1430 static void csave(const Handle(Draw_Drawable3D)&d, ostream& OS)
1431 {
1432   Handle(DrawTrSurf_Curve) N = Handle(DrawTrSurf_Curve)::DownCast(d);
1433   GeomTools_CurveSet::PrintCurve(N->GetCurve(),OS,Standard_True);
1434 }
1435
1436 static Handle(Draw_Drawable3D) crestore (istream& is)
1437 {
1438   Handle(Geom_Curve) G;
1439   GeomTools_CurveSet::ReadCurve(is,G);
1440   Handle(DrawTrSurf_Curve) N = 
1441     new DrawTrSurf_Curve(G,CurvColor,Discret,Deflection,DrawMode);
1442   return N;
1443 }
1444
1445
1446 static Draw_SaveAndRestore csr("DrawTrSurf_Curve",
1447                                ctest,csave,crestore);
1448
1449
1450
1451
1452 //=================================================================
1453 // save and restore bezier curves
1454 //=================================================================
1455
1456 static Standard_Boolean bzctest(const Handle(Draw_Drawable3D)& d) 
1457 {
1458   return d->IsInstance(STANDARD_TYPE(DrawTrSurf_BezierCurve));
1459 }
1460
1461 static void bzcsave(const Handle(Draw_Drawable3D)&d, ostream& OS)
1462 {
1463   Handle(DrawTrSurf_BezierCurve) 
1464     N = Handle(DrawTrSurf_BezierCurve)::DownCast(d);
1465   GeomTools_CurveSet::PrintCurve(N->GetCurve(),OS,Standard_True);
1466 }
1467
1468 static Handle(Draw_Drawable3D) bzcrestore (istream& is)
1469 {
1470   Handle(Geom_BezierCurve) G;
1471   GeomTools_CurveSet::ReadCurve(is,G);
1472   Handle(DrawTrSurf_BezierCurve) N = 
1473     new DrawTrSurf_BezierCurve(G,CurvColor,PolesColor,ShowPoles,
1474                                Discret,Deflection,DrawMode);
1475   return N;
1476 }
1477
1478
1479 static Draw_SaveAndRestore bzcsr("DrawTrSurf_BezierCurve",
1480                                bzctest,bzcsave,bzcrestore);
1481
1482
1483
1484
1485 //=================================================================
1486 // save and restore bspline curves
1487 //=================================================================
1488
1489 static Standard_Boolean bsctest(const Handle(Draw_Drawable3D)& d) 
1490 {
1491   return d->IsInstance(STANDARD_TYPE(DrawTrSurf_BSplineCurve));
1492 }
1493
1494 static void bscsave(const Handle(Draw_Drawable3D)&d, ostream& OS)
1495 {
1496   Handle(DrawTrSurf_BSplineCurve) 
1497     N = Handle(DrawTrSurf_BSplineCurve)::DownCast(d);
1498   GeomTools_CurveSet::PrintCurve(N->GetCurve(),OS,Standard_True);
1499 }
1500
1501 static Handle(Draw_Drawable3D) bscrestore (istream& is)
1502 {
1503   Handle(Geom_BSplineCurve) G;
1504   GeomTools_CurveSet::ReadCurve(is,G);
1505   Handle(DrawTrSurf_BSplineCurve) N = 
1506     new DrawTrSurf_BSplineCurve(G, CurvColor,PolesColor,
1507                                 KnotsColor,
1508                                 KnotsShape,KnotsSize,
1509                                 ShowPoles,ShowKnots,
1510                                 Discret,Deflection,DrawMode);
1511   return N;
1512 }
1513
1514
1515 static Draw_SaveAndRestore bscsr("DrawTrSurf_BSplineCurve",
1516                                bsctest,bscsave,bscrestore);
1517
1518
1519 //=================================================================
1520 // save and restore curves 2d
1521 //=================================================================
1522
1523 static Standard_Boolean c2dtest(const Handle(Draw_Drawable3D)& d) 
1524 {
1525   return d->IsInstance(STANDARD_TYPE(DrawTrSurf_Curve2d));
1526 }
1527
1528 static void c2dsave(const Handle(Draw_Drawable3D)&d, ostream& OS)
1529 {
1530   Handle(DrawTrSurf_Curve2d) N = Handle(DrawTrSurf_Curve2d)::DownCast(d);
1531   GeomTools_Curve2dSet::PrintCurve2d(N->GetCurve(),OS,Standard_True);
1532 }
1533
1534 static Handle(Draw_Drawable3D) c2drestore (istream& is)
1535 {
1536   Handle(Geom2d_Curve) G;
1537   GeomTools_Curve2dSet::ReadCurve2d(is,G);
1538   Handle(DrawTrSurf_Curve2d) N = 
1539     new DrawTrSurf_Curve2d(G,CurvColor,Discret);
1540   return N;
1541 }
1542
1543
1544 static Draw_SaveAndRestore c2dsr("DrawTrSurf_Curve2d",
1545                                c2dtest,c2dsave,c2drestore);
1546
1547
1548
1549
1550 //=================================================================
1551 // save and restore bezier curves 2d
1552 //=================================================================
1553
1554 static Standard_Boolean bzc2dtest(const Handle(Draw_Drawable3D)& d) 
1555 {
1556   return d->IsInstance(STANDARD_TYPE(DrawTrSurf_BezierCurve2d));
1557 }
1558
1559 static void bzc2dsave(const Handle(Draw_Drawable3D)&d, ostream& OS)
1560 {
1561   Handle(DrawTrSurf_BezierCurve2d) 
1562     N = Handle(DrawTrSurf_BezierCurve2d)::DownCast(d);
1563   GeomTools_Curve2dSet::PrintCurve2d(N->GetCurve(),OS,Standard_True);
1564 }
1565
1566 static Handle(Draw_Drawable3D) bzc2drestore (istream& is)
1567 {
1568   Handle(Geom2d_BezierCurve) G;
1569   GeomTools_Curve2dSet::ReadCurve2d(is,G);
1570   Handle(DrawTrSurf_BezierCurve2d) N = 
1571     new DrawTrSurf_BezierCurve2d(G,CurvColor,PolesColor,ShowPoles,
1572                                Discret);
1573   return N;
1574 }
1575
1576
1577 static Draw_SaveAndRestore bzc2dsr("DrawTrSurf_BezierCurve2d",
1578                                bzc2dtest,bzc2dsave,bzc2drestore);
1579
1580
1581
1582
1583 //=================================================================
1584 // save and restore bspline curves 2d
1585 //=================================================================
1586
1587 static Standard_Boolean bsc2dtest(const Handle(Draw_Drawable3D)& d) 
1588 {
1589   return d->IsInstance(STANDARD_TYPE(DrawTrSurf_BSplineCurve2d));
1590 }
1591
1592 static void bsc2dsave(const Handle(Draw_Drawable3D)&d, ostream& OS)
1593 {
1594   Handle(DrawTrSurf_BSplineCurve2d) 
1595     N = Handle(DrawTrSurf_BSplineCurve2d)::DownCast(d);
1596   GeomTools_Curve2dSet::PrintCurve2d(N->GetCurve(),OS,Standard_True);
1597 }
1598
1599 static Handle(Draw_Drawable3D) bsc2drestore (istream& is)
1600 {
1601   Handle(Geom2d_BSplineCurve) G;
1602   GeomTools_Curve2dSet::ReadCurve2d(is,G);
1603   Handle(DrawTrSurf_BSplineCurve2d) N = 
1604     new DrawTrSurf_BSplineCurve2d(G, CurvColor,PolesColor,
1605                                 KnotsColor,
1606                                 KnotsShape,KnotsSize,
1607                                 ShowPoles,ShowKnots,
1608                                 Discret);
1609   return N;
1610 }
1611
1612
1613 static Draw_SaveAndRestore bsc2dsr("DrawTrSurf_BSplineCurve2d",
1614                                bsc2dtest,bsc2dsave,bsc2drestore);
1615
1616
1617 //=================================================================
1618 // save and restore surfaces
1619 //=================================================================
1620
1621 static Standard_Boolean stest(const Handle(Draw_Drawable3D)& d) 
1622 {
1623   return d->IsInstance(STANDARD_TYPE(DrawTrSurf_Surface));
1624 }
1625
1626 static void ssave(const Handle(Draw_Drawable3D)&d, ostream& OS)
1627 {
1628   Handle(DrawTrSurf_Surface) N = Handle(DrawTrSurf_Surface)::DownCast(d);
1629   GeomTools_SurfaceSet::PrintSurface(N->GetSurface(),OS,Standard_True);
1630 }
1631
1632 static Handle(Draw_Drawable3D) srestore (istream& is)
1633 {
1634   Handle(Geom_Surface) G;
1635   GeomTools_SurfaceSet::ReadSurface(is,G);
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, 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 (istream& is)
1668 {
1669   Handle(Geom_BezierSurface) G;
1670   GeomTools_SurfaceSet::ReadSurface(is,G);
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, 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 (istream& is)
1703 {
1704   Handle(Geom_BSplineSurface) G;
1705   GeomTools_SurfaceSet::ReadSurface(is,G);
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, ostream& OS)
1741 {
1742   Handle(DrawTrSurf_Point) 
1743     N = Handle(DrawTrSurf_Point)::DownCast(d);
1744 #if defined(HAVE_IOS) && !defined(__sgi) && !defined(IRIX)
1745   ios::fmtflags F = OS.flags();
1746   OS.setf(ios::scientific,ios::floatfield);
1747   OS.precision(15);
1748 #else
1749   long form = OS.setf(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(HAVE_IOS) && !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 (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, ostream& OS)
1803 {
1804   Handle(DrawTrSurf_Triangulation) 
1805     T = Handle(DrawTrSurf_Triangulation)::DownCast(d);
1806 #if defined(HAVE_IOS) && !defined(__sgi) && !defined(IRIX)
1807   ios::fmtflags F = OS.flags();
1808   OS.setf(ios::scientific,ios::floatfield);
1809   OS.precision(15);
1810 #else
1811   long form = OS.setf(ios::scientific);
1812   std::streamsize prec = OS.precision(15);
1813 #endif
1814   Poly::Write(T->Triangulation(),OS);
1815 #if defined(HAVE_IOS) && !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 (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, ostream& OS)
1844 {
1845   Handle(DrawTrSurf_Polygon3D) 
1846     T = Handle(DrawTrSurf_Polygon3D)::DownCast(d);
1847 #if defined(HAVE_IOS) && !defined(__sgi) && !defined(IRIX)
1848   ios::fmtflags F = OS.flags();
1849   OS.setf(ios::scientific,ios::floatfield);
1850   OS.precision(15);
1851 #else
1852   long form = OS.setf(ios::scientific);
1853   std::streamsize prec = OS.precision(15);
1854 #endif
1855   Poly::Write(T->Polygon3D(),OS);
1856 #if defined(HAVE_IOS) && !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 (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, ostream& OS)
1884 {
1885   Handle(DrawTrSurf_Polygon2D) 
1886     T = Handle(DrawTrSurf_Polygon2D)::DownCast(d);
1887 #if defined(HAVE_IOS) && !defined(__sgi) && !defined(IRIX)
1888   ios::fmtflags F = OS.flags();
1889   OS.setf(ios::scientific, ios::floatfield);
1890   OS.precision(15);
1891 #else
1892   long form = OS.setf(ios::scientific);
1893   std::streamsize prec = OS.precision(15);
1894 #endif
1895   Poly::Write(T->Polygon2D(),OS);
1896 #if defined(HAVE_IOS) && !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 (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