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