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