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