0020716: Eliminate usage of "config.h" header file
[occt.git] / src / Draw / Draw_GraphicCommands.cxx
CommitLineData
b311480e 1// Created on: 1995-02-23
2// Created by: Remi LEQUETTE
3// Copyright (c) 1995-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.
b311480e 16
7fd59977 17// **************************************************************
7fd59977 18
19
20// Modif : DFO 05/11/96
7fd59977 21#include <Draw.ixx>
22#include <Draw_Appli.hxx>
23
24#include <Draw_Drawable3D.hxx>
25#include <Draw_Grid.hxx>
26#include <Draw_Display.hxx>
27#include <Draw_Text3D.hxx>
28#include <Draw_Text2D.hxx>
29
30#include <Standard_Stream.hxx>
31
32#include <stdio.h>
03155c18 33#ifdef _WIN32
7fd59977 34extern Draw_Viewer dout;
35extern Standard_Boolean Draw_Batch;
36#endif
7fd59977 37
38extern Standard_Boolean Draw_BlackBackGround;
39
40
c6541a0c 41#define DEFROTATE (5 * M_PI/ 180.)
7fd59977 42#define DEFMAGNIFY 1.1
43#define DEFPANNING 0.1
44#define DEFFOCAL 1.1
45#define DEFFRAME 10
46#define DEFGRIDSTEP 100.0
47static Standard_Real steprot = DEFROTATE;
48static Standard_Real steppan = DEFPANNING;
49static Standard_Real stepmagnify = DEFMAGNIFY;
50static Standard_Real stepfocal = DEFFOCAL;
51static Standard_Real frame = DEFFRAME;
52static Standard_Real DefaultGridStep = DEFGRIDSTEP ;
53
54#define FONTLENGTH
55static char Draw_fontname[FONTLENGTH]="Helvetica";
56static char Draw_fontsize[FONTLENGTH]="150";
57static char Draw_fontnamedefault[FONTLENGTH]="Helvetica";
58static char Draw_fontsizedefault[FONTLENGTH]="150";
59
60// *******************************************************************
61// Graphic commands
62// *******************************************************************
63
64static Standard_Integer ViewId(const Standard_CString a)
65{
91322f44 66 Standard_Integer id = Draw::Atoi(a);
7fd59977 67 if ((id < 0) || (id >= MAXVIEW)) {
68 cout << "Incorrect view-id, must be in 0.."<<MAXVIEW-1<<endl;
69 return -1;
70 }
71 if (!dout.HasView(id)) {
72 cout <<"View "<<id<<" does not exist."<<endl;
73 return -1;
74 }
75 return id;
76}
77
78static void SetTitle(const Standard_Integer id)
79{
80 if (dout.HasView(id)) {
81 char title[255];
91322f44 82 Sprintf(title,"%d : %s - Zoom %f",id,dout.GetType(id),dout.Zoom(id));
7fd59977 83 dout.SetTitle(id,title);
84 }
85}
86
87//=======================================================================
88//function : zoom
89//purpose :
90//=======================================================================
91
92static Standard_Integer zoom(Draw_Interpretor& , Standard_Integer n, const char** a)
93{
94 // one argument -> All Views
95 // two argument -> First is the view
96 Standard_Boolean z2d = !strcasecmp(a[0],"2dzoom");
97 if (n == 2) {
91322f44 98 Standard_Real z = Draw::Atof(a[1]);
7fd59977 99 for (Standard_Integer id = 0; id < MAXVIEW; id++) {
100 if (dout.HasView(id)) {
101 if ((z2d && !dout.Is3D(id)) || (!z2d && dout.Is3D(id))) {
102 dout.SetZoom(id,z);
103 SetTitle(id);
104 dout.RepaintView(id);
105 }
106 }
107 }
108 return 0;
109 }
110 else if (n >= 3) {
111 Standard_Integer id = ViewId(a[1]);
112 if (id < 0) return 1;
91322f44 113 Standard_Real z = Draw::Atof(a[2]);
7fd59977 114 dout.SetZoom(id,z);
115 dout.RepaintView(id);
116 SetTitle(id);
117 return 0;
118 }
119 else
120 return 1;
121}
122
123//=======================================================================
124//function : wzoom
125//purpose :
126//=======================================================================
127
4754e164 128static Standard_Integer wzoom(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
7fd59977 129{
1d47d8d0 130 Standard_Integer id,X,Y,W,H,X1,Y1,X2 = 0,Y2 = 0,b;
4754e164 131 Standard_Real dX1,dY1,dX2,dY2,zx,zy;
132 if(argc != 1 && argc != 6)
133 {
134 di<<"Usage : " << argv[0] << " [view-id X1 Y1 X2 Y2]\n";
135 return 1;
136 }
137 if(argc == 1)
138 {
139 di << "Pick first corner"<<"\n";
140 dout.Select(id,X1,Y1,b);
7fd59977 141
4754e164 142 gp_Trsf T;
143 gp_Pnt P0(0,0,0);
144 dout.GetTrsf(id,T);
145 T.Invert();
146 P0.Transform(T);
147 Standard_Real z = dout.Zoom(id);
7fd59977 148
4754e164 149 dX1=X1; dY1=Y1;
150 dX1-=P0.X(); dY1-=P0.Y();
151 dX1/=z; dY1/=z;
152
153 if (b != 1) return 0;
154 if (id < 0) return 0;
155 Draw_Display d = dout.MakeDisplay(id);
156 d.SetColor(Draw_blanc);
157 d.SetMode(10);
158 Standard_Real dOX2 = dX1;
159 Standard_Real dOY2 = dY1;
7fd59977 160 d.Draw(gp_Pnt2d(dX1,dY1),gp_Pnt2d(dX1,dOY2));
161 d.Draw(gp_Pnt2d(dX1,dOY2),gp_Pnt2d(dOX2,dOY2));
162 d.Draw(gp_Pnt2d(dOX2,dOY2),gp_Pnt2d(dOX2,dY1));
163 d.Draw(gp_Pnt2d(dOX2,dY1),gp_Pnt2d(dX1,dY1));
7fd59977 164 d.Flush();
4754e164 165 dout.GetPosSize(id,X,Y,W,H);
166 di << "Pick second corner"<<"\n";
167 b = 0;
168 while (b == 0) {
169 dout.Select(id,X2,Y2,b,Standard_False);
170 dX2=X2; dY2=Y2;
171 dX2-=P0.X(); dY2-=P0.Y();
172 dX2/=z; dY2/=z;
173
174 d.Draw(gp_Pnt2d(dX1,dY1),gp_Pnt2d(dX1,dOY2));
175 d.Draw(gp_Pnt2d(dX1,dOY2),gp_Pnt2d(dOX2,dOY2));
176 d.Draw(gp_Pnt2d(dOX2,dOY2),gp_Pnt2d(dOX2,dY1));
177 d.Draw(gp_Pnt2d(dOX2,dY1),gp_Pnt2d(dX1,dY1));
178 d.Draw(gp_Pnt2d(dX1,dY1),gp_Pnt2d(dX1,dY2));
179 d.Draw(gp_Pnt2d(dX1,dY2),gp_Pnt2d(dX2,dY2));
180 d.Draw(gp_Pnt2d(dX2,dY2),gp_Pnt2d(dX2,dY1));
181 d.Draw(gp_Pnt2d(dX2,dY1),gp_Pnt2d(dX1,dY1));
182 d.Flush();
183 dOX2 = dX2;
184 dOY2 = dY2;
185 }
186 d.Draw(gp_Pnt2d(dX1,dY1),gp_Pnt2d(dX1,dOY2));
187 d.Draw(gp_Pnt2d(dX1,dOY2),gp_Pnt2d(dOX2,dOY2));
188 d.Draw(gp_Pnt2d(dOX2,dOY2),gp_Pnt2d(dOX2,dY1));
189 d.Draw(gp_Pnt2d(dOX2,dY1),gp_Pnt2d(dX1,dY1));
190 d.Flush();
191 if (b != 1) return 0;
192 d.SetMode(0);
7fd59977 193 }
4754e164 194 else
195 {
196 id = atoi(argv[1]);
197 if ((id < 0) || (id >= MAXVIEW))
198 {
199 cout << "Incorrect view-id, must be in 0.."<<MAXVIEW-1<<endl;
200 return 1;
201 }
202 if (!dout.HasView(id))
203 {
204 cout <<"View "<<id<<" does not exist."<<endl;
205 return 1;
206 }
207 X1 = atoi (argv [2]);
208 Y1 = atoi (argv [3]);
209 X2 = atoi (argv [4]);
210 Y2 = atoi (argv [5]);
7fd59977 211
4754e164 212 dout.GetPosSize(id,X,Y,W,H);
213 }
7fd59977 214
4754e164 215 if ((X1 == X2) || (Y1 == Y2)) return 0;
7fd59977 216 zx = (Standard_Real) Abs(X2-X1) / (Standard_Real) W;
217 zy = (Standard_Real) Abs(Y2-Y1) / (Standard_Real) H;
218 if (zy > zx) zx = zy;
219 zx = 1/zx;
220 if (X2 < X1) X1 = X2;
221 if (Y2 > Y1) Y1 = Y2;
222 X1 = (Standard_Integer ) (X1*zx);
223 Y1 = (Standard_Integer ) (Y1*zx);
4754e164 224 dout.SetZoom(id,zx*dout.Zoom(id));
225 dout.SetPan(id,-X1,-Y1);
226 dout.RepaintView(id);
227 SetTitle(id);
7fd59977 228 return 0;
229}
230
231//=======================================================================
232//function : wclick
233//purpose :
234//=======================================================================
235
236static Standard_Integer wclick(Draw_Interpretor& di, Standard_Integer, const char**)
237{
238 Standard_Integer id1,X1,Y1,b;
239 dout.Flush();
240 di << "Just click."<<"\n";
241 dout.Select(id1,X1,Y1,b);
242 return 0;
243}
244
245//=======================================================================
246//function : view
247//purpose :
248//=======================================================================
249
250static Standard_Integer view(Draw_Interpretor& di, Standard_Integer n, const char** a)
251{
252 if (Draw_Batch) return 1;
253
254 if ((n >= 3) && (n != 4)) {
91322f44 255 Standard_Integer id = Draw::Atoi(a[1]);
7fd59977 256 if ((id < 0) || (id >= MAXVIEW)) {
257 di <<"View-id must be in 0.."<<MAXVIEW-1<<"\n";
258 return 1;
259 }
260 Standard_Integer X = 0;
261 Standard_Integer Y = 0;
262 Standard_Integer W = 500;
263 Standard_Integer H = 500;
264 // if view exist, get old values
265 if (dout.HasView(id))
266 dout.GetPosSize(id,X,Y,W,H);
267 if (n >= 4)
91322f44 268 X = Draw::Atoi(a[3]);
7fd59977 269 if (n >= 5)
91322f44 270 Y = Draw::Atoi(a[4]);
7fd59977 271 if (n >= 6)
91322f44 272 W = Draw::Atoi(a[5]);
7fd59977 273 if (n >= 7)
91322f44 274 H = Draw::Atoi(a[6]);
7fd59977 275 dout.MakeView(id,a[2],X,Y,W,H);
276 if (!dout.HasView(id)) {
277 di << "View creation failed"<<"\n";
278 return 1;
279 }
280 SetTitle(id);
281 dout.DisplayView(id);
282 return 0;
283 }
284 else if (n == 4) {
285 // create a view on a given window
91322f44 286 Standard_Integer id = Draw::Atoi(a[1]);
7fd59977 287 if ((id < 0) || (id >= MAXVIEW)) {
288 di <<"View-id must be in 0.."<<MAXVIEW-1<<"\n";
289 return 1;
290 }
291 dout.MakeView(id,a[2],a[3]);
292 if (!dout.HasView(id)) {
293 di << "View creation failed"<<"\n";
294 return 1;
295 }
296 SetTitle(id);
297 dout.DisplayView(id);
298 return 0;
299 }
300 else
301 return 1;
302}
303
304//=======================================================================
305//function : delview
306//purpose :
307//=======================================================================
308
309static Standard_Integer delview(Draw_Interpretor& , Standard_Integer n, const char** a)
310{
311 if (n == 1) {
312 for (Standard_Integer id = 0; id < MAXVIEW; id++)
313 dout.DeleteView(id);
314 return 0;
315 }
316 else if (n >= 2) {
317 Standard_Integer id = ViewId(a[1]);
318 if (id < 0) return 1;
319 dout.DeleteView(id);
320 return 0;
321 }
322 else
323 return 1;
324}
325
326//=======================================================================
327//function : fit
328//purpose :
329//=======================================================================
330
331static Standard_Integer fit(Draw_Interpretor& , Standard_Integer n, const char** a)
332{
333 Standard_Boolean f2d = !strcasecmp(a[0],"2dfit");
334 if (n == 1) {
335 Standard_Real zoom = RealLast();
336 Standard_Integer id;
337 for ( id = 0; id < MAXVIEW; id++) {
338 if (dout.HasView(id)) {
339 if ((f2d && !dout.Is3D(id)) || (!f2d && dout.Is3D(id))) {
340// dout.FitView(id,frame);
341 dout.FitView(id,(Standard_Integer ) frame);
342 if (dout.Zoom(id) < zoom) zoom = dout.Zoom(id);
343 }
344 }
345 }
346 for (id = 0; id < MAXVIEW; id++) {
347 if (dout.HasView(id)) {
348 if ((f2d && !dout.Is3D(id)) || (!f2d && dout.Is3D(id))) {
349 dout.SetZoom(id,zoom);
350 dout.RepaintView(id);
351 SetTitle(id);
352 }
353 }
354 }
355 return 0;
356 }
357 else if (n >= 2) {
358 Standard_Integer id = ViewId(a[1]);
359 if (id < 0) return 1;
360// dout.FitView(id,frame);
361 dout.FitView(id,(Standard_Integer ) frame);
362 dout.RepaintView(id);
363 SetTitle(id);
364 return 0;
365 }
366 else
367 return 1;
368}
369
370//=======================================================================
371//function : focal
372//purpose :
373//=======================================================================
374
375static Standard_Integer focal(Draw_Interpretor& , Standard_Integer n, const char** a)
376{
377 Standard_Integer start = 0;
378 Standard_Integer end = MAXVIEW-1;
379 if (n >= 2) {
380 Standard_Integer anid = ViewId(a[1]);
381 if (anid < 0) return 1;
382 start = end = anid;
383 }
384 Standard_Real df = 1.;
385 if (!strcasecmp(a[0],"fu"))
386 df = stepfocal;
387 if (!strcasecmp(a[0],"fd"))
388 df = 1./stepfocal;
389
390 for (Standard_Integer id = start; id <= end; id++) {
391 if (!strcasecmp(dout.GetType(id),"PERS")) {
392 dout.SetFocal(id,dout.Focal(id) * df);
393 dout.RepaintView(id);
394 }
395 }
396 return 0;
397}
398
399//=======================================================================
400//function : setfocal
401//purpose :
402//=======================================================================
403
404static Standard_Integer setfocal(Draw_Interpretor& di, Standard_Integer n, const char** a)
405{
406 if (n == 1) {
407 for (Standard_Integer id = 0; id < MAXVIEW; id++) {
408 if (!strcasecmp(dout.GetType(id),"PERS"))
409 di << "Focal view "<<id<<" is "<<dout.Focal(id)<<"\n";
410 }
411 }
412 else {
91322f44 413 Standard_Real f = Draw::Atof(a[1]);
7fd59977 414 for (Standard_Integer id = 0; id < MAXVIEW; id++) {
415 if (!strcasecmp(dout.GetType(id),"PERS"))
416 dout.SetFocal(id,f);
417 }
418 dout.RepaintAll();
419 }
420 return 0;
421}
422
423//=======================================================================
424//function : magnify
425//purpose :
426//=======================================================================
427
428//static Standard_Integer magnify(Draw_Interpretor& di, Standard_Integer n, const char** a)
429static Standard_Integer magnify(Draw_Interpretor& , Standard_Integer n, const char** a)
430{
431 Standard_Integer start = 0;
432 Standard_Integer end = MAXVIEW-1;
433 if (n >= 2) {
434 Standard_Integer anid = ViewId(a[1]);
435 if (anid < 0) return 1;
436 start = end = anid;
437 }
438 Standard_Boolean v2d = (a[0][0] == '2'); // 2dmu, 2dmd
439 const char* com = a[0];
440 if (v2d) com += 2;
441 Standard_Real dz = 1.;
442 if (!strcasecmp(com,"mu")) // mu, 2dmu
443 dz = stepmagnify;
444 else // md, 2dmd
445 dz = 1/stepmagnify;
446
447 for (Standard_Integer id = start; id <= end; id++) {
448 if (dout.HasView(id)) {
449 if ((v2d && !dout.Is3D(id)) || (!v2d && dout.Is3D(id))) {
450 dout.SetZoom(id,dout.Zoom(id) * dz);
451 SetTitle(id);
452 dout.RepaintView(id);
453 }
454 }
455 }
456 return 0;
457}
458
459Standard_EXPORT Standard_Integer Draw_magnify(Draw_Interpretor& di, Standard_Integer n, const char** a)
460{
461 return magnify(di,n,a);
462}
463
464//=======================================================================
465//function : rotate
466//purpose :
467//=======================================================================
468
469static Standard_Integer rotate(Draw_Interpretor& , Standard_Integer n, const char** a)
470{
471 Standard_Integer start = 0;
472 Standard_Integer end = MAXVIEW-1;
473 if (n >= 2) {
474 Standard_Integer anid = ViewId(a[1]);
475 if (anid < 0) return 1;
476 start = end = anid;
477 }
478
479 gp_Dir2d D;
480 Standard_Real ang=0;
481 if (!strcasecmp(a[0],"u")) {
482 D.SetCoord(1.,0.);
483 ang = -steprot;
484 }
485 if (!strcasecmp(a[0],"d")) {
486 D.SetCoord(1.,0.);
487 ang = steprot;
488 }
489 if (!strcasecmp(a[0],"l")) {
490 D.SetCoord(0.,1.);
491 ang = -steprot;
492 }
493 if (!strcasecmp(a[0],"r")) {
494 D.SetCoord(0.,1.);
495 ang = steprot;
496 }
497
498 for (Standard_Integer id = start; id <= end; id++) {
499 if ((!strcasecmp(dout.GetType(id),"AXON")) ||
500 (!strcasecmp(dout.GetType(id),"PERS"))) {
501 dout.RotateView(id,D,ang);
502 dout.RepaintView(id);
503 }
504 }
505 return 0;
506}
507
508//=======================================================================
509//function : panning
510//purpose :
511//=======================================================================
512
513static Standard_Integer panning(Draw_Interpretor& , Standard_Integer n, const char** a)
514{
515 Standard_Integer start = 0;
516 Standard_Integer end = MAXVIEW-1;
517 if (n >= 2) {
518 Standard_Integer anid = ViewId(a[1]);
519 if (anid < 0) return 1;
520 start = end = anid;
521 }
522 Standard_Integer DX = 0;
523 Standard_Integer DY = 0;
524 Standard_Integer X,Y,W,H;
525
526 Standard_Boolean v2d = (a[0][0] == '2'); // pu2d, pd2d, pr2d, pl2d
527 const char* com = a[0];
528 if (v2d) com += 2;
529
530 if (!strcasecmp(com,"pu")) // pu , 2dpu
531 DY = 1;
532 if (!strcasecmp(com,"pd")) // pd , 2dpd
533 DY = -1;
534 if (!strcasecmp(com,"pl")) // pl , 2dpl
535 DX = -1;
536 if (!strcasecmp(com,"pr")) // pr , 2dpr
537 DX = 1;
538
539 for (Standard_Integer id = start; id <= end; id++) {
540 if (dout.HasView(id)) {
541 if ((v2d && !dout.Is3D(id)) || (!v2d && dout.Is3D(id))) {
542 dout.GetPosSize(id,X,Y,W,H);
543// dout.PanView(id,W * DX * steppan, H * DY * steppan);
544 dout.PanView(id,(Standard_Integer )( W * DX * steppan),(Standard_Integer )( H * DY * steppan));
545 dout.RepaintView(id);
546 }
547 }
548 }
549 return 0;
550}
551
552//=======================================================================
553//function : ptv
554//purpose :
555//=======================================================================
556
557static Standard_Integer ptv(Draw_Interpretor& , Standard_Integer n, const char** a)
558{
559 Standard_Real X,Y,Z;
560 Standard_Integer start = 0;
561 Standard_Integer end = MAXVIEW-1;
562 if (n < 4) return 1;
563 if (n >= 5) {
564 Standard_Integer anid = ViewId(a[1]);
565 if (anid < 0) return 1;
566 start = end = anid;
91322f44 567 X = Draw::Atof(a[2]);
568 Y = Draw::Atof(a[3]);
569 Z = Draw::Atof(a[4]);
7fd59977 570 }
571 else {
91322f44 572 X = Draw::Atof(a[1]);
573 Y = Draw::Atof(a[2]);
574 Z = Draw::Atof(a[3]);
7fd59977 575 }
576
577 for (Standard_Integer id = start; id <= end; id++) {
578 gp_Trsf T;
579 dout.GetTrsf(id,T);
580 T.SetTranslationPart(gp_Vec(0,0,0));
581 gp_Trsf T1;
582 T1.SetTranslationPart(gp_Vec(-X,-Y,-Z));
583 gp_Trsf aLocalTrsf(T*T1);
584 dout.SetTrsf(id,aLocalTrsf);
585// dout.SetTrsf(id,T*T1);
586 dout.RepaintView(id);
587 }
588 return 0;
589}
590
591//=======================================================================
592//function : dptv
593//purpose :
594//=======================================================================
595
596static Standard_Integer dptv(Draw_Interpretor& , Standard_Integer n, const char** a)
597{
598 Standard_Real DX,DY,DZ;
599 Standard_Integer start = 0;
600 Standard_Integer end = MAXVIEW-1;
601 if (n < 4) return 1;
602 if (n >= 5) {
603 Standard_Integer anid = ViewId(a[1]);
604 if (anid < 0) return 1;
605 start = end = anid;
91322f44 606 DX = Draw::Atof(a[2]);
607 DY = Draw::Atof(a[3]);
608 DZ = Draw::Atof(a[4]);
7fd59977 609 }
610 else {
91322f44 611 DX = Draw::Atof(a[1]);
612 DY = Draw::Atof(a[2]);
613 DZ = Draw::Atof(a[3]);
7fd59977 614 }
615
616 for (Standard_Integer id = start; id <= end; id++) {
617 gp_Trsf T;
618 dout.GetTrsf(id,T);
619 gp_Trsf T1;
620 T1.SetTranslationPart(gp_Vec(-DX,-DY,-DZ));
621 gp_Trsf M = T*T1;
622 dout.SetTrsf(id,M);
623 dout.RepaintView(id);
624 }
625 return 0;
626}
627
628
629//=======================================================================
630//function : color
631//purpose :
632//=======================================================================
633
634static Standard_Integer color(Draw_Interpretor& di, Standard_Integer n, const char** a)
635{
636 if (n < 3) {
637 Draw_BlackBackGround = !Draw_BlackBackGround;
638 }
91322f44 639 else if (!dout.DefineColor(Draw::Atoi(a[1]),a[2])) {
7fd59977 640 di << "Could not allocate color "<<a[2]<<"\n";
641 return 1;
642 }
643 return 0;
644}
645
646
647
648//=======================================================================
649//function : hardcopy
650//purpose : hardcopy --> hardcopy of view 1
651// in file a4.ps
652// in format a4
653// hardcopy name view --> hardcopy of view <view>
654// in file <name>
655// in format a4
656// hardcopy name view format --> hardcopy of view <view>
657// in file <name>
658// in format <a4,a3,a2,a1,a0>
659//=======================================================================
660
661static Standard_Integer hardcopy(Draw_Interpretor& ,
662 Standard_Integer n, const char** a)
663{
664 // Inch = 25.40001969 mm.
665 // 28.4 pixels / mm.
666 // format par default papier a4 210 297 mm avec marge de 3 mm.
667
668 Standard_Real rap = 28.4;
669 Standard_Real cad = 3;
670 Standard_Real dx = 210;
671 Standard_Real dy = 210 * Sqrt(2.);
672
673 Standard_Integer iview = 1;
674 const char* file = "a4.ps";
675 if (n >= 2) {
676 file = a[1];
677 if (n >= 3) {
678 iview = ViewId(a[2]);
679 if (iview < 0) return 1;
680 if (n >= 4) {
74d80fb9 681 if (!strcmp(a[3],"a7")) {
682 cad = cad / (2 * Sqrt(2));
683 dx = dx / (2 * Sqrt(2));
684 dy = dy / (2 * Sqrt(2));
685 }
686 else if (!strcmp(a[3],"a6")) {
687 cad = cad / 2;
688 dx = dx / 2;
689 dy = dy / 2;
690 }
691 else if (!strcmp(a[3],"a5")) {
692 cad = cad / Sqrt(2);
693 dx = dx / Sqrt(2);
694 dy = dy / Sqrt(2);
695 }
696 else if (!strcmp(a[3],"a4")) {
697 // Do nothing
698 //cad == cad;
699 //dx == dx;
700 //dy == dy;
701 }
702 else if (!strcmp(a[3],"a3")) {
703 cad = cad * Sqrt(2);
704 dx = dx * Sqrt(2);
705 dy = dy * Sqrt(2);
706 }
707 else if (!strcmp(a[3],"a2")) {
708 cad = cad * 2;
709 dx = dx * 2;
710 dy = dy * 2;
711 }
712 else if (!strcmp(a[3],"a1")) {
713 cad = cad * 2 * Sqrt(2);
714 dx = dx * 2 * Sqrt(2);
715 dy = dy * 2 * Sqrt(2);
716 }
717 else if (!strcmp(a[3],"a0")) {
718 cad = cad * 4;
719 dx = dx * 4;
720 dy = dy * 4;
721 }
7fd59977 722 }
723 }
724 }
725
726 Standard_Integer pxmin = (Standard_Integer)(cad * rap);
727 Standard_Integer pymin = (Standard_Integer)(cad * rap);
728 Standard_Integer pxmax = (Standard_Integer)((dx - cad) * rap);
729 Standard_Integer pymax = (Standard_Integer)((dy - cad) * rap);
730
731 ofstream os(file);
732
733 Standard_Integer vxmin,vymin,vxmax,vymax;
734 if (dout.HasView(iview)) {
735 dout.GetFrame(iview,vxmin,vymin,vxmax,vymax);
736 Standard_Real kx = (Standard_Real) (pxmax - pxmin) / (vxmax - vxmin);
737 Standard_Real ky = (Standard_Real) (pymax - pymin) / (vymax - vymin);
738 Standard_Real k = Min(Abs(kx),Abs(ky));
739 kx = (kx > 0) ? k : -k;
740 ky = (ky > 0) ? k : -k;
741 pxmax = (Standard_Integer )( pxmin + kx * (vxmax - vxmin));
742 pymax = (Standard_Integer )( pymin + ky * (vymax - vymin));
743
744 // si on veut choisir l'orientation : 90 rotate
745
746 // ecriture du header
747
748 os << "%!PS-Adobe-3.0 EPSF-3.0\n";
749 os << "%%BoundingBox: " << pxmin << " " << pymin << " "
750 << pxmax << " " << pymax << "\n";
751 os << "%%Pages: 1\n";
752 os << "%%DocumentFonts: "<<Draw_fontname<<"\n";
753 os << "%%EndComments\n";
754
755 os << "/"<<Draw_fontname<<" findfont\n"<<Draw_fontsize<<" scalefont\nsetfont\n";
756 os << "/m {moveto} bind def\n";
757 os << "/l {lineto} bind def\n";
758 os <<".1 .1 scale\n";
759
760 // draw the frame
761
762 os <<"3 setlinewidth\n0 setgray\nnewpath\n";
763 os << pxmin << " " << pymin << " m\n";
764 os << pxmax << " " << pymin << " l\n";
765 os << pxmax << " " << pymax << " l\n";
766 os << pxmin << " " << pymax << " l\n";
767 os << "closepath\nstroke\n";
768
769 // frame the view
770
771 os <<"newpath\n";
772 os << pxmin << " " << pymin << " m\n";
773 os << pxmax << " " << pymin << " l\n";
774 os << pxmax << " " << pymax << " l\n";
775 os << pxmin << " " << pymax << " l\n";
776 os << "closepath\nclip\n";
777
778 dout.PostScriptView(iview,
779 vxmin,vymin,vxmax,vymax,
780 pxmin,pymin,pxmax,pymax,os);
781 os <<"showpage\n";
782 os <<"%%EOF\n";
783 }
784
785 return 0;
786}
787
788static Standard_Integer dfont(Draw_Interpretor& di,
789 Standard_Integer n, const char** a)
790{
791 if ( n == 1 ) {
792 strcpy(Draw_fontname, Draw_fontnamedefault);
793 strcpy(Draw_fontsize, Draw_fontsizedefault);
794 } else if ( n == 2 ) {
795 strcpy(Draw_fontname, a[1]);
796 } else if ( n == 3 ) {
797 strcpy(Draw_fontname, a[1]);
798 strcpy(Draw_fontsize, a[2]);
799 }
800 di<<Draw_fontname<<" "<<Draw_fontsize<<"\n";
801 return 0;
802} // dfont
803
804//=======================================================================
805//function : hcolor
806//purpose :
807//=======================================================================
808
809static Standard_Integer hcolor(Draw_Interpretor& di, Standard_Integer n, const char** a)
810{
811 if (n < 4) {
812 di << "code de couleur (Draw.cxx) : " << "\n" ;
813 di << "0 = White,\t 1 = Red,\t 2 = Green,\t 3 = Blue" << "\n" ;
814 di << "4 = Cyan,\t 5 = Gold,\t 6 = Magenta,\t 7 = Maroon" << "\n" ;
815 di << "8 = Orange,\t 9 = Pink,\t 10 = Salmon,\t 11 = Violet" << "\n" ;
816 di << "12 = Yellow,\t 13 = Khaki,\t 14 = Coral" << "\n" ;
817 di << "1 <= width <= 11, 0 (noir) <= gray <= 1 (blanc)" << "\n" ;
818 } else {
91322f44 819 dout.PostColor(Draw::Atoi(a[1]),Draw::Atoi(a[2]),Draw::Atof(a[3]));
7fd59977 820 }
821 return 0;
822}
823
824//=======================================================================
825//function : xwd
826//purpose : xwd file from a view
827//=======================================================================
828
829extern void Draw_RepaintNowIfNecessary();
830
831static Standard_Integer xwd(Draw_Interpretor& , Standard_Integer n, const char** a)
832{
833 if (n < 2) return 1;
834
835 // enforce repaint if necessary
836 Draw_RepaintNowIfNecessary();
837
838 Standard_Integer id = 1;
839 const char* file = a[1];
840 if (n > 2) {
91322f44 841 id = Draw::Atoi(a[1]);
7fd59977 842 file = a[2];
843 }
844 if (!dout.SaveView(id,file))
845 return 1;
846
847 return 0;
848}
849
850//=======================================================================
851//function : grid
852//purpose : Creation/Suppression d'une grille.
853//=======================================================================
854
855static Standard_Integer grid (Draw_Interpretor& , Standard_Integer NbArg, const char **Arg)
856{
857 Standard_Real StepX, StepY, StepZ ;
858
859 switch (NbArg) {
860 case 1 :
861 StepX = DefaultGridStep ;
862 StepY = DefaultGridStep ;
863 StepZ = DefaultGridStep ;
864 break ;
865 case 2 :
91322f44 866 StepX = Abs (Draw::Atof (Arg[1])) ;
867 StepY = Abs (Draw::Atof (Arg[1])) ;
868 StepZ = Abs (Draw::Atof (Arg[1])) ;
7fd59977 869 break ;
870 case 3 :
91322f44 871 StepX = Abs (Draw::Atof (Arg[1])) ;
872 StepY = Abs (Draw::Atof (Arg[2])) ;
873 StepZ = Abs (Draw::Atof (Arg[2])) ;
7fd59977 874 break ;
875 case 4 :
91322f44 876 StepX = Abs (Draw::Atof (Arg[1])) ;
877 StepY = Abs (Draw::Atof (Arg[2])) ;
878 StepZ = Abs (Draw::Atof (Arg[3])) ;
7fd59977 879 break ;
880 default :
881 return 1 ;
882 }
883
884#ifdef HPUX
885 const char *temp = "grid";
886#else
887 char temp1[] = "grid";
888 const char *temp = temp1;
889#endif
890 Handle (Draw_Grid) Grille = Handle(Draw_Grid)::DownCast (Draw::Get(temp)) ;
891
892 Grille->Steps (StepX, StepY, StepZ) ;
893 dout.RepaintAll () ;
894
895 return 0 ;
896}
897
898//=======================================================================
899//function : dflush
900//purpose :
901//=======================================================================
902
903static Standard_Integer dflush (Draw_Interpretor& , Standard_Integer, const char **)
904{
905 dout.Flush();
906 return 0;
907}
908
909//=======================================================================
910//function : dtext
911//purpose :
912//=======================================================================
913
914static Standard_Integer dtext(Draw_Interpretor& di, Standard_Integer n, const char** a)
915{
916 gp_Pnt P;
917 Standard_Boolean is3d;
918 if (n == 2) {
919 Standard_Integer id,X,Y,b;
920 di << "Pick position with button 1, other button escape"<<"\n";
921 dout.Select(id,X,Y,b);
922 if (b != 1)
923 return 0;
924 Standard_Real z = dout.Zoom(id);
925 P.SetCoord((Standard_Real)X /z,(Standard_Real)Y /z,0);
926 gp_Trsf T;
927 dout.GetTrsf(id,T);
928 T.Invert();
929 P.Transform(T);
930 is3d = dout.Is3D(id);
931 }
932 else if (n >= 4) {
933 is3d = n > 4;
91322f44 934 P.SetCoord(Draw::Atof(a[1]),Draw::Atof(a[2]),is3d ? Draw::Atof(a[3]) : 0);
7fd59977 935 }
936 else
937 return 0;
938
939 if (is3d) {
940 Handle(Draw_Text3D) D = new Draw_Text3D(P,a[n-1],Draw_vert);
941 dout << D;
942 }
943 else {
944 Handle(Draw_Text2D) D = new Draw_Text2D(gp_Pnt2d(P.X(),P.Y()),
945 a[n-1],Draw_vert);
946 dout << D;
947 }
948 return 0;
949}
950
951void Draw::GraphicCommands(Draw_Interpretor& theCommands)
952{
953 static Standard_Boolean Done = Standard_False;
954 if (Done) return;
955 Done = Standard_True;
956
957 const char* g = "DRAW Graphic Commands";
958 theCommands.Add("wclick","wait for a mouse click",
959 __FILE__,wclick,g);
960 theCommands.Add("zoom","zoom [view-id] z, or zoom z for all 3d views",
961 __FILE__,zoom,g);
962 theCommands.Add("2dzoom","2dzoom [view-id] z, or zoom2d z for all 2d views",
963 __FILE__,zoom,g);
4754e164 964 theCommands.Add("wzoom","wzoom [view-id X1 Y1 X2 Y2]\n"
965 "- fits the contents of a given rectangle into a view window.\n"
966 "- The view window and rectangle corners are specified through the arguments\n"
967 "- or selected interactively by the user if no arguments are given",
968 __FILE__,wzoom,g);
7fd59977 969 theCommands.Add("view","view view-id type X(0) Y(0) W(500) H(500)",
970 __FILE__,view,g);
971 theCommands.Add("delete","delete [view-id]",
972 __FILE__,delview,g);
973 theCommands.Add("fit","fit [view-id]",
974 __FILE__,fit,g);
975 theCommands.Add("2dfit","2dfit [view-id]",
976 __FILE__,fit,g);
977 theCommands.Add("fu","fu [view-id], focal up",
978 __FILE__,focal,g);
979 theCommands.Add("fd","fd [view-id], focal down",
980 __FILE__,focal,g);
981 theCommands.Add("focal","focal [f]",
982 __FILE__,setfocal,g);
983 theCommands.Add("mu","mu [view-id], magnify up",
984 __FILE__,magnify,g);
985 theCommands.Add("2dmu","2dmu [view-id], magnify up",
986 __FILE__,magnify,g);
987 theCommands.Add("md","md [view-id], magnify down",
988 __FILE__,magnify,g);
989 theCommands.Add("2dmd","2dmd [view-id], magnify down",
990 __FILE__,magnify,g);
991 theCommands.Add("u","u [view-id], rotate up",
992 __FILE__,rotate,g);
993 theCommands.Add("d","d [view-id], rotate down",
994 __FILE__,rotate,g);
995 theCommands.Add("l","l [view-id], rotate left",__FILE__,rotate,g);
996 theCommands.Add("r","r [view-id], rotate right",__FILE__,rotate,g);
997 theCommands.Add("pu","pu [view-id], panning up",__FILE__,panning,g);
998 theCommands.Add("pd","pd [view-id], panning down",__FILE__,panning,g);
999 theCommands.Add("pl","pl [view-id], panning left",__FILE__,panning,g);
1000 theCommands.Add("pr","pr [view-id], panning right",__FILE__,panning,g);
1001 theCommands.Add("2dpu","2dpu [view-id], panning up",__FILE__,panning,g);
1002 theCommands.Add("2dpd","2dpd [view-id], panning down",__FILE__,panning,g);
1003 theCommands.Add("2dpl","2dpl [view-id], panning left",__FILE__,panning,g);
1004 theCommands.Add("2dpr","2dpr [view-id], panning right",__FILE__,panning,g);
1005 theCommands.Add("ptv","ptv [view-id], X , Y , Z",
1006 __FILE__,ptv,g);
1007 theCommands.Add("dptv","dptv [view-id], dX , dY , dZ",
1008 __FILE__,dptv,g);
1009 theCommands.Add("color","color i colorname, define color i",
1010 __FILE__,color,g);
1011 theCommands.Add("hardcopy","hardcopy [file = a4.ps] [view-id = 1] [format = a4]", __FILE__,hardcopy,g);
1012 theCommands.Add("xwd","xwd [id = 1] <filename>.{png|bmp|jpg|gif}\n\t\t: Dump contents of viewer window to PNG, BMP, JPEG or GIF file",
1013 __FILE__,xwd,g);
1014 theCommands.Add("hcolor","hcolor icol width gray (< 1, 0 black)",
1015 __FILE__,hcolor,g);
1016 theCommands.Add("grid", "grid [stepX(100) [stepY [stepZ]]] / 0",
1017 __FILE__,grid, g);
1018 theCommands.Add("dflush","dflush, flush the viewer",
1019 __FILE__,dflush,g);
1020 theCommands.Add("dtext","dtext [x y [z]] string",
1021 __FILE__,dtext,g);
1022 theCommands.Add("dfont","dfont [name size] : set name and size of Draw font, or reset to default",
1023 __FILE__,dfont,g);
1024}
1025