BRL-CAD
dm-ps.c
Go to the documentation of this file.
1 /* D M - P S . C
2  * BRL-CAD
3  *
4  * Copyright (c) 1985-2014 United States Government as represented by
5  * the U.S. Army Research Laboratory.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License
9  * version 2.1 as published by the Free Software Foundation.
10  *
11  * This library is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this file; see the file named COPYING for more
18  * information.
19  */
20 /** @file libdm/dm-ps.c
21  *
22  * A useful hack to allow GED to generate
23  * PostScript files that not only contain the drawn objects, but
24  * also contain the faceplate display as well.
25  * Mostly, used for making viewgraphs and photographs
26  * of an editing session.
27  *
28  */
29 
30 #include "common.h"
31 
32 #include <string.h>
33 
34 #ifdef HAVE_SYS_TIME_H
35 # include <sys/time.h> /* for struct timeval */
36 #endif
37 
38 #include "tcl.h"
39 
40 #include "vmath.h"
41 #include "bn.h"
42 #include "mater.h"
43 #include "raytrace.h"
44 
45 #include "dm.h"
46 #include "dm-ps.h"
47 #include "dm-Null.h"
48 
49 #include "solid.h"
50 
51 #include "./dm_private.h"
52 
53 #define EPSILON 0.0001
54 
55 /* Display Manager package interface */
56 
57 #define PLOTBOUND 1000.0 /* Max magnification in Rot matrix */
58 
59 char ps_usage[] = "Usage: ps [-f font] [-t title] [-c creator] [-s size in inches]\
60  [-l linewidth] file";
61 
63 static mat_t psmat;
64 
65 
66 /*
67  * Gracefully release the display.
68  */
69 HIDDEN int
70 ps_close(dm *dmp)
71 {
72  if (!((struct ps_vars *)dmp->dm_vars.priv_vars)->ps_fp)
73  return TCL_ERROR;
74 
75  fputs("%end(plot)\n", ((struct ps_vars *)dmp->dm_vars.priv_vars)->ps_fp);
76  (void)fclose(((struct ps_vars *)dmp->dm_vars.priv_vars)->ps_fp);
77 
78  bu_vls_free(&dmp->dm_pathName);
79  bu_vls_free(&dmp->dm_tkName);
80  bu_vls_free(&((struct ps_vars *)dmp->dm_vars.priv_vars)->fname);
81  bu_vls_free(&((struct ps_vars *)dmp->dm_vars.priv_vars)->font);
82  bu_vls_free(&((struct ps_vars *)dmp->dm_vars.priv_vars)->title);
83  bu_vls_free(&((struct ps_vars *)dmp->dm_vars.priv_vars)->creator);
84  bu_free((void *)dmp->dm_vars.priv_vars, "ps_close: ps_vars");
85  bu_free((void *)dmp, "ps_close: dmp");
86 
87  return TCL_OK;
88 }
89 
90 
91 /*
92  * There are global variables which are parameters to this routine.
93  */
94 HIDDEN int
96 {
97  if (!dmp)
98  return TCL_ERROR;
99 
100  return TCL_OK;
101 }
102 
103 
104 HIDDEN int
106 {
107  if (!dmp)
108  return TCL_ERROR;
109 
110  if (!((struct ps_vars *)dmp->dm_vars.priv_vars)->ps_fp)
111  return TCL_ERROR;
112 
113  fputs("% showpage % uncomment to use raw file\n",
114  ((struct ps_vars *)dmp->dm_vars.priv_vars)->ps_fp);
115  (void)fflush(((struct ps_vars *)dmp->dm_vars.priv_vars)->ps_fp);
116 
117  return TCL_OK;
118 }
119 
120 
121 /*
122  * Load a new transformation matrix. This will be followed by
123  * many calls to ps_draw().
124  */
125 HIDDEN int
126 ps_loadMatrix(dm *dmp, fastf_t *mat, int which_eye)
127 {
128  Tcl_Obj *obj;
129 
130  obj = Tcl_GetObjResult(dmp->dm_interp);
131  if (Tcl_IsShared(obj))
132  obj = Tcl_DuplicateObj(obj);
133 
134  if (((struct ps_vars *)dmp->dm_vars.priv_vars)->debug) {
135  struct bu_vls tmp_vls = BU_VLS_INIT_ZERO;
136 
137  Tcl_AppendStringsToObj(obj, "ps_loadMatrix()\n", (char *)NULL);
138 
139  bu_vls_printf(&tmp_vls, "which eye = %d\t", which_eye);
140  bu_vls_printf(&tmp_vls, "transformation matrix = \n");
141  bu_vls_printf(&tmp_vls, "%g %g %g %g\n", mat[0], mat[4], mat[8], mat[12]);
142  bu_vls_printf(&tmp_vls, "%g %g %g %g\n", mat[1], mat[5], mat[9], mat[13]);
143  bu_vls_printf(&tmp_vls, "%g %g %g %g\n", mat[2], mat[6], mat[10], mat[14]);
144  bu_vls_printf(&tmp_vls, "%g %g %g %g\n", mat[3], mat[7], mat[11], mat[15]);
145 
146  Tcl_AppendStringsToObj(obj, bu_vls_addr(&tmp_vls), (char *)NULL);
147  bu_vls_free(&tmp_vls);
148  }
149 
150  MAT_COPY(psmat, mat);
151 
152  Tcl_SetObjResult(dmp->dm_interp, obj);
153  return TCL_OK;
154 }
155 
156 
157 /* ARGSUSED */
158 HIDDEN int
159 ps_drawVList(dm *dmp, struct bn_vlist *vp)
160 {
161  static vect_t last;
162  struct bn_vlist *tvp;
163  point_t *pt_prev=NULL;
164  fastf_t dist_prev=1.0;
165  fastf_t dist;
166  fastf_t delta;
167  int useful = 0;
168 
169  if (!((struct ps_vars *)dmp->dm_vars.priv_vars)->ps_fp)
170  return TCL_ERROR;
171 
172  /* delta is used in clipping to insure clipped endpoint is slightly
173  * in front of eye plane (perspective mode only).
174  * This value is a SWAG that seems to work OK.
175  */
176  delta = psmat[15]*0.0001;
177  if (delta < 0.0)
178  delta = -delta;
179  if (delta < SQRT_SMALL_FASTF)
180  delta = SQRT_SMALL_FASTF;
181 
182  for (BU_LIST_FOR(tvp, bn_vlist, &vp->l)) {
183  int i;
184  int nused = tvp->nused;
185  int *cmd = tvp->cmd;
186  point_t *pt = tvp->pt;
187  for (i = 0; i < nused; i++, cmd++, pt++) {
188  static vect_t start, fin;
189  switch (*cmd) {
190  case BN_VLIST_POLY_START:
192  case BN_VLIST_TRI_START:
194  continue;
195  case BN_VLIST_POLY_MOVE:
196  case BN_VLIST_LINE_MOVE:
197  case BN_VLIST_TRI_MOVE:
198  /* Move, not draw */
199  if (dmp->dm_perspective > 0) {
200  /* cannot apply perspective transformation to
201  * points behind eye plane!!!!
202  */
203  dist = VDOT(*pt, &psmat[12]) + psmat[15];
204  if (dist <= 0.0) {
205  pt_prev = pt;
206  dist_prev = dist;
207  continue;
208  } else {
209  MAT4X3PNT(last, psmat, *pt);
210  dist_prev = dist;
211  pt_prev = pt;
212  }
213  } else
214  MAT4X3PNT(last, psmat, *pt);
215  continue;
216  case BN_VLIST_POLY_DRAW:
217  case BN_VLIST_POLY_END:
218  case BN_VLIST_LINE_DRAW:
219  case BN_VLIST_TRI_DRAW:
220  case BN_VLIST_TRI_END:
221  /* draw */
222  if (dmp->dm_perspective > 0) {
223  /* cannot apply perspective transformation to
224  * points behind eye plane!!!!
225  */
226  dist = VDOT(*pt, &psmat[12]) + psmat[15];
227  if (dist <= 0.0) {
228  if (dist_prev <= 0.0) {
229  /* nothing to plot */
230  dist_prev = dist;
231  pt_prev = pt;
232  continue;
233  } else {
234  if (pt_prev) {
235  fastf_t alpha;
236  vect_t diff;
237  point_t tmp_pt;
238 
239  /* clip this end */
240  VSUB2(diff, *pt, *pt_prev);
241  alpha = (dist_prev - delta) / (dist_prev - dist);
242  VJOIN1(tmp_pt, *pt_prev, alpha, diff);
243  MAT4X3PNT(fin, psmat, tmp_pt);
244  }
245  }
246  } else {
247  if (dist_prev <= 0.0) {
248  if (pt_prev) {
249  fastf_t alpha;
250  vect_t diff;
251  point_t tmp_pt;
252 
253  /* clip other end */
254  VSUB2(diff, *pt, *pt_prev);
255  alpha = (-dist_prev + delta) / (dist - dist_prev);
256  VJOIN1(tmp_pt, *pt_prev, alpha, diff);
257  MAT4X3PNT(last, psmat, tmp_pt);
258  MAT4X3PNT(fin, psmat, *pt);
259  }
260  } else {
261  MAT4X3PNT(fin, psmat, *pt);
262  }
263  }
264  } else
265  MAT4X3PNT(fin, psmat, *pt);
266  VMOVE(start, last);
267  VMOVE(last, fin);
268  break;
269  }
270 
271  if (vclip(start, fin, dmp->dm_clipmin,
272  dmp->dm_clipmax) == 0)
273  continue;
274 
275  fprintf(((struct ps_vars *)dmp->dm_vars.priv_vars)->ps_fp,
276  "newpath %d %d moveto %d %d lineto stroke\n",
277  GED_TO_PS(start[0] * 2047),
278  GED_TO_PS(start[1] * 2047),
279  GED_TO_PS(fin[0] * 2047),
280  GED_TO_PS(fin[1] * 2047));
281  useful = 1;
282  }
283  }
284 
285  if (useful)
286  return TCL_OK;
287 
288  return TCL_ERROR;
289 }
290 
291 
292 /* ARGSUSED */
293 HIDDEN int
294 ps_draw(dm *dmp, struct bn_vlist *(*callback_function)(void *), void **data)
295 {
296  struct bn_vlist *vp;
297  if (!callback_function) {
298  if (data) {
299  vp = (struct bn_vlist *)data;
300  ps_drawVList(dmp, vp);
301  }
302  } else {
303  if (!data) {
304  return TCL_ERROR;
305  } else {
306  (void)callback_function(data);
307  }
308  }
309  return TCL_OK;
310 }
311 
312 
313 /*
314  * Restore the display processor to a normal mode of operation
315  * (i.e., not scaled, rotated, displaced, etc.).
316  * Turns off windowing.
317  */
318 HIDDEN int
320 {
321  if (!dmp)
322  return TCL_ERROR;
323 
324  return TCL_OK;
325 }
326 
327 
328 /*
329  * Output a string into the displaylist.
330  * The starting position of the beam is as specified.
331  */
332 /* ARGSUSED */
333 HIDDEN int
334 ps_drawString2D(dm *dmp, const char *str, fastf_t x, fastf_t y, int size, int UNUSED(use_aspect))
335 {
336  int sx, sy;
337 
338  if (!((struct ps_vars *)dmp->dm_vars.priv_vars)->ps_fp)
339  return TCL_ERROR;
340 
341  switch (size) {
342  default:
343  /* Smallest */
344  fprintf(((struct ps_vars *)dmp->dm_vars.priv_vars)->ps_fp, "DFntS ");
345  break;
346  case 1:
347  fprintf(((struct ps_vars *)dmp->dm_vars.priv_vars)->ps_fp, "DFntM ");
348  break;
349  case 2:
350  fprintf(((struct ps_vars *)dmp->dm_vars.priv_vars)->ps_fp, "DFntL ");
351  break;
352  case 3:
353  /* Largest */
354  fprintf(((struct ps_vars *)dmp->dm_vars.priv_vars)->ps_fp, "FntH ");
355  break;
356  }
357 
358  sx = x * 2047.0 + 2048;
359  sy = y * 2047.0 + 2048;
360  fprintf(((struct ps_vars *)dmp->dm_vars.priv_vars)->ps_fp,
361  "(%s) %d %d moveto show\n", str, sx, sy);
362 
363  return TCL_OK;
364 }
365 
366 
367 HIDDEN int
368 ps_drawLine2D(dm *dmp, fastf_t xpos1, fastf_t ypos1, fastf_t xpos2, fastf_t ypos2)
369 {
370  int sx1, sy1;
371  int sx2, sy2;
372 
373  if (!((struct ps_vars *)dmp->dm_vars.priv_vars)->ps_fp)
374  return TCL_ERROR;
375 
376  sx1 = xpos1 * 2047.0 + 2048;
377  sx2 = xpos2 * 2047.0 + 2048;
378  sy1 = ypos1 * 2047.0 + 2048;
379  sy2 = ypos2 * 2047.0 + 2048;
380 
381  fprintf(((struct ps_vars *)dmp->dm_vars.priv_vars)->ps_fp,
382  "newpath %d %d moveto %d %d lineto stroke\n",
383  sx1, sy1, sx2, sy2);
384 
385  return TCL_OK;
386 }
387 
388 
389 HIDDEN int
390 ps_drawLine3D(dm *dmp, point_t pt1, point_t pt2)
391 {
392  return draw_Line3D(dmp, pt1, pt2);
393 }
394 
395 
396 HIDDEN int
397 ps_drawLines3D(dm *dmp, int npoints, point_t *points, int UNUSED(sflag))
398 {
399  if (!dmp || npoints < 0 || !points)
400  return TCL_ERROR;
401 
402  return TCL_OK;
403 }
404 
405 
406 HIDDEN int
408 {
409  return ps_drawLine2D(dmp, x, y, x, y);
410 }
411 
412 
413 HIDDEN int
414 ps_setFGColor(dm *dmp, unsigned char r, unsigned char g, unsigned char b, int strict, fastf_t transparency)
415 {
416  if (!dmp) {
417  bu_log("WARNING: NULL display (r/g/b => %d/%d/%d; strict => %d; transparency => %f)\n", r, g, b, strict, transparency);
418  return TCL_ERROR;
419  }
420 
421  return TCL_OK;
422 }
423 
424 
425 HIDDEN int
426 ps_setBGColor(dm *dmp, unsigned char r, unsigned char g, unsigned char b)
427 {
428  if (!dmp) {
429  bu_log("WARNING: Null display (r/g/b==%d/%d/%d)\n", r, g, b);
430  return TCL_ERROR;
431  }
432 
433  return TCL_OK;
434 }
435 
436 
437 HIDDEN int
438 ps_setLineAttr(dm *dmp, int width, int style)
439 {
440  dmp->dm_lineWidth = width;
441  dmp->dm_lineStyle = style;
442 
443  if (style == DM_DASHED_LINE)
444  fprintf(((struct ps_vars *)dmp->dm_vars.priv_vars)->ps_fp, "DDV "); /* Dot-dashed vectors */
445  else
446  fprintf(((struct ps_vars *)dmp->dm_vars.priv_vars)->ps_fp, "NV "); /* Normal vectors */
447 
448  return TCL_OK;
449 }
450 
451 
452 /* ARGSUSED */
453 HIDDEN int
454 ps_debug(dm *dmp, int lvl)
455 {
456  dmp->dm_debugLevel = lvl;
457  return TCL_OK;
458 }
459 
460 HIDDEN int
461 ps_logfile(dm *dmp, const char *filename)
462 {
463  bu_vls_sprintf(&dmp->dm_log, "%s", filename);
464  return TCL_OK;
465 }
466 
467 HIDDEN int
469 {
470  /* Compute the clipping bounds */
471  dmp->dm_clipmin[0] = w[0] / 2048.0;
472  dmp->dm_clipmax[0] = w[1] / 2047.0;
473  dmp->dm_clipmin[1] = w[2] / 2048.0;
474  dmp->dm_clipmax[1] = w[3] / 2047.0;
475 
476  if (dmp->dm_zclip) {
477  dmp->dm_clipmin[2] = w[4] / 2048.0;
478  dmp->dm_clipmax[2] = w[5] / 2047.0;
479  } else {
480  dmp->dm_clipmin[2] = -1.0e20;
481  dmp->dm_clipmax[2] = 1.0e20;
482  }
483 
484  return TCL_OK;
485 }
486 
487 
489  ps_close,
490  ps_drawBegin,
491  ps_drawEnd,
492  ps_normal,
502  ps_drawVList,
503  ps_drawVList,
504  ps_draw,
514  ps_debug,
515  ps_logfile,
521  NULL,
522  null_getDisplayImage, /* display to image function */
523  null_reshape,
525  null_openFb,
526  NULL,
527  NULL,
528  0,
529  0, /* no displaylist */
530  0, /* no stereo */
531  PLOTBOUND, /* zoom-in limit */
532  1, /* bound flag */
533  "ps",
534  "Screen to PostScript",
535  DM_TYPE_PS,
536  0,
537  0,
538  0,
539  0, /* bytes per pixel */
540  0, /* bits per channel */
541  0,
542  0,
543  1.0, /* aspect ratio */
544  0,
545  {0, 0},
546  NULL,
547  NULL,
548  BU_VLS_INIT_ZERO, /* bu_vls path name*/
549  BU_VLS_INIT_ZERO, /* bu_vls full name drawing window */
550  BU_VLS_INIT_ZERO, /* bu_vls short name drawing window */
551  {0, 0, 0}, /* bg color */
552  {0, 0, 0}, /* fg color */
553  {0.0, 0.0, 0.0}, /* clipmin */
554  {0.0, 0.0, 0.0}, /* clipmax */
555  0, /* no debugging */
556  BU_VLS_INIT_ZERO, /* bu_vls logfile */
557  0, /* no perspective */
558  0, /* no lighting */
559  0, /* no transparency */
560  0, /* depth buffer is not writable */
561  0, /* no zbuffer */
562  0, /* no zclipping */
563  1, /* clear back buffer after drawing and swap */
564  0, /* not overriding the auto font size */
566  FB_NULL,
567  0 /* Tcl interpreter */
568 };
569 
570 
571 /*
572  * Open the output file, and output the PostScript prolog.
573  *
574  */
575 dm *
576 ps_open(Tcl_Interp *interp, int argc, const char *argv[])
577 {
578  static int count = 0;
579  dm *dmp;
580  Tcl_Obj *obj;
581 
582  BU_ALLOC(dmp, struct dm_internal);
583 
584  *dmp = dm_ps; /* struct copy */
585  dmp->dm_interp = interp;
586 
587  BU_ALLOC(dmp->dm_vars.priv_vars, struct ps_vars);
588 
589  obj = Tcl_GetObjResult(interp);
590  if (Tcl_IsShared(obj))
591  obj = Tcl_DuplicateObj(obj);
592 
593  bu_vls_init(&dmp->dm_pathName);
594  bu_vls_init(&dmp->dm_tkName);
595  bu_vls_printf(&dmp->dm_pathName, ".dm_ps%d", count++);
596  bu_vls_printf(&dmp->dm_tkName, "dm_ps%d", count++);
597 
598  bu_vls_init(&((struct ps_vars *)dmp->dm_vars.priv_vars)->fname);
599  bu_vls_init(&((struct ps_vars *)dmp->dm_vars.priv_vars)->font);
600  bu_vls_init(&((struct ps_vars *)dmp->dm_vars.priv_vars)->title);
601  bu_vls_init(&((struct ps_vars *)dmp->dm_vars.priv_vars)->creator);
602 
603  /* set defaults */
604  bu_vls_strcpy(&((struct ps_vars *)dmp->dm_vars.priv_vars)->font, "Courier");
605  bu_vls_strcpy(&((struct ps_vars *)dmp->dm_vars.priv_vars)->title, "No Title");
606  bu_vls_strcpy(&((struct ps_vars *)dmp->dm_vars.priv_vars)->creator, "LIBDM dm-ps");
607  ((struct ps_vars *)dmp->dm_vars.priv_vars)->scale = 0.0791;
608  ((struct ps_vars *)dmp->dm_vars.priv_vars)->linewidth = 4;
609  ((struct ps_vars *)dmp->dm_vars.priv_vars)->zclip = 0;
610 
611  /* skip first argument */
612  --argc; ++argv;
613 
614  /* Process any options */
615  while (argv[0] != (char *)0 && argv[0][0] == '-') {
616  switch (argv[0][1]) {
617  case 'f': /* font */
618  if (argv[0][2] != '\0')
619  bu_vls_strcpy(&((struct ps_vars *)dmp->dm_vars.priv_vars)->font, &argv[0][2]);
620  else {
621  argv++;
622  if (argv[0] == (char *)0 || argv[0][0] == '-') {
623  Tcl_AppendStringsToObj(obj, ps_usage, (char *)0);
624  (void)ps_close(dmp);
625 
626  Tcl_SetObjResult(interp, obj);
627  return DM_NULL;
628  } else
629  bu_vls_strcpy(&((struct ps_vars *)dmp->dm_vars.priv_vars)->font, &argv[0][0]);
630  }
631  break;
632  case 't': /* title */
633  if (argv[0][2] != '\0')
634  bu_vls_strcpy(&((struct ps_vars *)dmp->dm_vars.priv_vars)->title, &argv[0][2]);
635  else {
636  argv++;
637  if (argv[0] == (char *)0 || argv[0][0] == '-') {
638  Tcl_AppendStringsToObj(obj, ps_usage, (char *)0);
639  (void)ps_close(dmp);
640 
641  Tcl_SetObjResult(interp, obj);
642  return DM_NULL;
643  } else
644  bu_vls_strcpy(&((struct ps_vars *)dmp->dm_vars.priv_vars)->title, &argv[0][0]);
645  }
646  break;
647  case 'c': /* creator */
648  if (argv[0][2] != '\0')
649  bu_vls_strcpy(&((struct ps_vars *)dmp->dm_vars.priv_vars)->creator, &argv[0][2]);
650  else {
651  argv++;
652  if (argv[0] == (char *)0 || argv[0][0] == '-') {
653  Tcl_AppendStringsToObj(obj, ps_usage, (char *)0);
654  (void)ps_close(dmp);
655 
656  Tcl_SetObjResult(interp, obj);
657  return DM_NULL;
658  } else
659  bu_vls_strcpy(&((struct ps_vars *)dmp->dm_vars.priv_vars)->creator, &argv[0][0]);
660  }
661  break;
662  case 's': /* size in inches */
663  {
664  double size;
665 
666  if (argv[0][2] != '\0')
667  sscanf(&argv[0][2], "%lf", &size);
668  else {
669  argv++;
670  if (argv[0] == (char *)0 || argv[0][0] == '-') {
671  Tcl_AppendStringsToObj(obj, ps_usage, (char *)0);
672  (void)ps_close(dmp);
673 
674  Tcl_SetObjResult(interp, obj);
675  return DM_NULL;
676  } else
677  sscanf(&argv[0][0], "%lf", &size);
678  }
679 
680  ((struct ps_vars *)dmp->dm_vars.priv_vars)->scale = size * 0.017578125;
681  }
682  break;
683  case 'l': /* line width */
684  if (argv[0][2] != '\0')
685  sscanf(&argv[0][2], "%d", &((struct ps_vars *)dmp->dm_vars.priv_vars)->linewidth);
686  else {
687  argv++;
688  if (argv[0] == (char *)0 || argv[0][0] == '-') {
689  Tcl_AppendStringsToObj(obj, ps_usage, (char *)0);
690  (void)ps_close(dmp);
691 
692  Tcl_SetObjResult(interp, obj);
693  return DM_NULL;
694  } else
695  sscanf(&argv[0][0], "%d", &((struct ps_vars *)dmp->dm_vars.priv_vars)->linewidth);
696  }
697  break;
698  case 'z':
699  dmp->dm_zclip = 1;
700  break;
701  default:
702  Tcl_AppendStringsToObj(obj, ps_usage, (char *)0);
703  (void)ps_close(dmp);
704 
705  Tcl_SetObjResult(interp, obj);
706  return DM_NULL;
707  }
708  argv++;
709  }
710 
711  if (argv[0] == (char *)0) {
712  Tcl_AppendStringsToObj(obj, "no filename specified\n", (char *)NULL);
713  (void)ps_close(dmp);
714 
715  Tcl_SetObjResult(interp, obj);
716  return DM_NULL;
717  }
718 
719  bu_vls_strcpy(&((struct ps_vars *)dmp->dm_vars.priv_vars)->fname, argv[0]);
720 
721  if ((((struct ps_vars *)dmp->dm_vars.priv_vars)->ps_fp =
722  fopen(bu_vls_addr(&((struct ps_vars *)dmp->dm_vars.priv_vars)->fname), "wb")) == NULL) {
723  Tcl_AppendStringsToObj(obj, "f_ps: Error opening file - ",
724  ((struct ps_vars *)dmp->dm_vars.priv_vars)->fname,
725  "\n", (char *)NULL);
726  (void)ps_close(dmp);
727 
728  Tcl_SetObjResult(interp, obj);
729  return DM_NULL;
730  }
731 
732  setbuf(((struct ps_vars *)dmp->dm_vars.priv_vars)->ps_fp,
733  ((struct ps_vars *)dmp->dm_vars.priv_vars)->ttybuf);
734  fprintf(((struct ps_vars *)dmp->dm_vars.priv_vars)->ps_fp, "%%!PS-Adobe-1.0\n\
735 %%begin(plot)\n\
736 %%%%DocumentFonts: %s\n",
737  bu_vls_addr(&((struct ps_vars *)dmp->dm_vars.priv_vars)->font));
738 
739  fprintf(((struct ps_vars *)dmp->dm_vars.priv_vars)->ps_fp, "%%%%Title: %s\n",
740  bu_vls_addr(&((struct ps_vars *)dmp->dm_vars.priv_vars)->title));
741 
742  fprintf(((struct ps_vars *)dmp->dm_vars.priv_vars)->ps_fp, "\
743 %%%%Creator: %s\n\
744 %%%%BoundingBox: 0 0 324 324 %% 4.5in square, for TeX\n\
745 %%%%EndComments\n\
746 \n",
747  bu_vls_addr(&((struct ps_vars *)dmp->dm_vars.priv_vars)->creator));
748 
749  fprintf(((struct ps_vars *)dmp->dm_vars.priv_vars)->ps_fp, "\
750 %d setlinewidth\n\
751 \n\
752 %% Sizes, made functions to avoid scaling if not needed\n\
753 /FntH /%s findfont 80 scalefont def\n\
754 /DFntL { /FntL /%s findfont 73.4 scalefont def } def\n\
755 /DFntM { /FntM /%s findfont 50.2 scalefont def } def\n\
756 /DFntS { /FntS /%s findfont 44 scalefont def } def\n\
757 ",
758  ((struct ps_vars *)dmp->dm_vars.priv_vars)->linewidth,
759  bu_vls_addr(&((struct ps_vars *)dmp->dm_vars.priv_vars)->font),
760  bu_vls_addr(&((struct ps_vars *)dmp->dm_vars.priv_vars)->font),
761  bu_vls_addr(&((struct ps_vars *)dmp->dm_vars.priv_vars)->font),
762  bu_vls_addr(&((struct ps_vars *)dmp->dm_vars.priv_vars)->font));
763 
764  fprintf(((struct ps_vars *)dmp->dm_vars.priv_vars)->ps_fp, "\
765 \n\
766 %% line styles\n\
767 /NV { [] 0 setdash } def %% normal vectors\n\
768 /DV { [8] 0 setdash } def %% dotted vectors\n\
769 /DDV { [8 8 32 8] 0 setdash } def %% dot-dash vectors\n\
770 /SDV { [32 8] 0 setdash } def %% short-dash vectors\n\
771 /LDV { [64 8] 0 setdash } def %% long-dash vectors\n\
772 \n\
773 /NEWPG {\n\
774  %f %f scale %% 0-4096 to 324 units (4.5 inches)\n\
775 } def\n\
776 \n\
777 FntH setfont\n\
778 NEWPG\n\
779 ",
780  ((struct ps_vars *)dmp->dm_vars.priv_vars)->scale,
781  ((struct ps_vars *)dmp->dm_vars.priv_vars)->scale);
782 
783  MAT_IDN(psmat);
784 
785  Tcl_SetObjResult(interp, obj);
786  return dmp;
787 }
788 
789 
790 /*
791  * Local Variables:
792  * mode: C
793  * tab-width: 8
794  * indent-tabs-mode: t
795  * c-file-style: "stroustrup"
796  * End:
797  * ex: shiftwidth=4 tabstop=8
798  */
void bu_vls_init(struct bu_vls *vp)
Definition: vls.c:56
int null_setDepthMask(struct dm_internal *dmp, int mask)
Definition: dm-Null.c:199
#define BU_LIST_FOR(p, structure, hp)
Definition: list.h:365
char filename[MAXLENGTH]
Definition: human.c:105
size_t nused
elements 0..nused active
Definition: vlist.h:73
void bu_log(const char *,...) _BU_ATTR_PRINTF12
Definition: log.c:176
HIDDEN int ps_logfile(dm *dmp, const char *filename)
Definition: dm-ps.c:461
struct bu_list l
magic, forw, back
Definition: vlist.h:72
HIDDEN int ps_setLineAttr(dm *dmp, int width, int style)
Definition: dm-ps.c:438
dm * ps_open(Tcl_Interp *interp, int argc, const char *argv[])
Definition: dm-ps.c:576
ustring interp
#define DM_DASHED_LINE
Definition: dm.h:109
int dm_zclip
!0 means zclipping
Definition: dm_private.h:116
int cmd[BN_VLIST_CHUNK]
VL_CMD_*.
Definition: vlist.h:74
Definition: dm-ps.h:37
HIDDEN int ps_drawLine2D(dm *dmp, fastf_t xpos1, fastf_t ypos1, fastf_t xpos2, fastf_t ypos2)
Definition: dm-ps.c:368
int draw_Line3D(struct dm_internal *dmp, point_t pt1, point_t pt2)
Definition: dm_util.c:167
vect_t dm_clipmax
maximum clipping vector
Definition: dm_private.h:108
Tcl_Interp * dm_interp
Tcl interpreter.
Definition: dm_private.h:121
HIDDEN int ps_drawBegin(dm *dmp)
Definition: dm-ps.c:95
HIDDEN int ps_drawPoint2D(dm *dmp, fastf_t x, fastf_t y)
Definition: dm-ps.c:407
int null_genDLists(struct dm_internal *dmp, size_t range)
Definition: dm-Null.c:252
HIDDEN int ps_drawLine3D(dm *dmp, point_t pt1, point_t pt2)
Definition: dm-ps.c:390
Header file for the BRL-CAD common definitions.
int null_loadPMatrix(struct dm_internal *dmp, fastf_t *mat)
Definition: dm-Null.c:73
char ps_usage[]
Definition: dm-ps.c:59
HIDDEN int ps_setWinBounds(dm *dmp, fastf_t *w)
Definition: dm-ps.c:468
ustring width
int null_freeDLists(struct dm_internal *dmp, unsigned int list, int range)
Definition: dm-Null.c:245
#define HIDDEN
Definition: common.h:86
#define BN_VLIST_POLY_MOVE
move to first poly vertex
Definition: vlist.h:85
HIDDEN int ps_debug(dm *dmp, int lvl)
Definition: dm-ps.c:454
int null_openFb(struct dm_internal *dmp)
Definition: dm-Null.c:279
#define BN_VLIST_TRI_VERTNORM
per-vertex normal, for interpolation
Definition: vlist.h:93
struct bu_vls dm_tkName
short Tcl/Tk name of drawing window
Definition: dm_private.h:103
void bu_vls_free(struct bu_vls *vp)
Definition: vls.c:248
COMPLEX data[64]
Definition: fftest.c:34
#define DM_NULL
Definition: dm.h:43
#define PLOTBOUND
Definition: dm-ps.c:57
#define FB_NULL
Definition: fb.h:95
#define BU_ALLOC(_ptr, _type)
Definition: malloc.h:223
int dm_perspective
!0 means perspective on
Definition: dm_private.h:111
HIDDEN int ps_drawLines3D(dm *dmp, int npoints, point_t *points, int sflag)
Definition: dm-ps.c:397
struct bu_vls dm_log
!NULL && !empty means log debug output to the file
Definition: dm_private.h:110
HIDDEN int ps_draw(dm *dmp, struct bn_vlist *(*callback_function)(void *), void **data)
Definition: dm-ps.c:294
void bu_vls_sprintf(struct bu_vls *vls, const char *fmt,...) _BU_ATTR_PRINTF23
Definition: vls.c:707
int null_configureWin(struct dm_internal *dmp, int force)
Definition: dm-Null.c:171
#define BN_VLIST_POLY_START
pt[] has surface normal
Definition: vlist.h:84
#define BN_VLIST_LINE_MOVE
Definition: vlist.h:82
#define GED_TO_PS(x)
Definition: dm-ps.h:35
int null_makeCurrent(struct dm_internal *dmp)
Definition: dm-Null.c:272
#define SQRT_SMALL_FASTF
Definition: defines.h:346
int vclip(fastf_t *, fastf_t *, fastf_t *, fastf_t *)
#define BN_VLIST_LINE_DRAW
Definition: vlist.h:83
HIDDEN int ps_close(dm *dmp)
Definition: dm-ps.c:70
#define UNUSED(parameter)
Definition: common.h:239
int null_beginDList(struct dm_internal *dmp, unsigned int list)
Definition: dm-Null.c:225
#define BN_VLIST_POLY_DRAW
subsequent poly vertex
Definition: vlist.h:86
char * bu_vls_addr(const struct bu_vls *vp)
Definition: vls.c:111
#define BN_VLIST_TRI_END
last vert (repeats 1st), draw poly
Definition: vlist.h:92
int dm_lineWidth
Definition: dm_private.h:95
void null_reshape(struct dm_internal *dmp, int width, int height)
Definition: dm-Null.c:266
ustring alpha
HIDDEN int ps_setBGColor(dm *dmp, unsigned char r, unsigned char g, unsigned char b)
Definition: dm-ps.c:426
#define BU_STRUCTPARSE_NULL
Definition: parse.h:151
#define BN_VLIST_TRI_START
pt[] has surface normal
Definition: vlist.h:89
#define DM_TYPE_PS
Definition: dm.h:94
void * priv_vars
Definition: dm_private.h:36
vect_t dm_clipmin
minimum clipping vector
Definition: dm_private.h:107
Definition: vlist.h:71
struct dm_vars dm_vars
display manager dependent variables
Definition: dm_private.h:99
#define BN_VLIST_POLY_VERTNORM
per-vertex normal, for interpolation
Definition: vlist.h:88
void null_drawDList(unsigned int list)
Definition: dm-Null.c:239
#define BN_VLIST_POLY_END
last vert (repeats 1st), draw poly
Definition: vlist.h:87
void bu_vls_printf(struct bu_vls *vls, const char *fmt,...) _BU_ATTR_PRINTF23
Definition: vls.c:694
HIDDEN int ps_drawString2D(dm *dmp, const char *str, fastf_t x, fastf_t y, int size, int use_aspect)
Definition: dm-ps.c:334
int null_setTransparency(struct dm_internal *dmp, int transparency)
Definition: dm-Null.c:192
struct bu_vls dm_pathName
full Tcl/Tk name of drawing window
Definition: dm_private.h:102
HIDDEN int ps_setFGColor(dm *dmp, unsigned char r, unsigned char g, unsigned char b, int strict, fastf_t transparency)
Definition: dm-ps.c:414
HIDDEN int ps_drawEnd(dm *dmp)
Definition: dm-ps.c:105
#define BN_VLIST_TRI_DRAW
subsequent triangle vertex
Definition: vlist.h:91
struct ps_vars head_ps_vars
Definition: dm-ps.c:62
HIDDEN int ps_drawVList(dm *dmp, struct bn_vlist *vp)
Definition: dm-ps.c:159
int null_drawPoint3D(struct dm_internal *dmp, point_t point)
Definition: dm-Null.c:115
void bu_vls_strcpy(struct bu_vls *vp, const char *s)
Definition: vls.c:310
HIDDEN int ps_normal(dm *dmp)
Definition: dm-ps.c:319
int null_setZBuffer(struct dm_internal *dmp, int zbuffer_on)
Definition: dm-Null.c:206
void bu_free(void *ptr, const char *str)
Definition: malloc.c:328
int null_getDisplayImage(struct dm_internal *dmp, unsigned char **image)
Definition: dm-Null.c:259
int null_drawPoints3D(struct dm_internal *dmp, int npoints, point_t *points)
Definition: dm-Null.c:122
#define BU_VLS_INIT_ZERO
Definition: vls.h:84
point_t pt[BN_VLIST_CHUNK]
associated 3-point/vect
Definition: vlist.h:75
int dm_debugLevel
!0 means debugging
Definition: dm_private.h:109
int null_endDList(struct dm_internal *dmp)
Definition: dm-Null.c:232
Definition: vls.h:56
HIDDEN const point_t delta
Definition: sh_prj.c:618
double fastf_t
Definition: defines.h:300
HIDDEN int ps_loadMatrix(dm *dmp, fastf_t *mat, int which_eye)
Definition: dm-ps.c:126
int dm_lineStyle
Definition: dm_private.h:96
dm dm_ps
Definition: dm-ps.c:488
int null_setLight(struct dm_internal *dmp, int light_on)
Definition: dm-Null.c:185
#define BN_VLIST_TRI_MOVE
move to first triangle vertex
Definition: vlist.h:90