- Optification is done by auto builder now
[gnuplot] / term / vws.trm
1 /* Hello, Emacs, this is -*-C-*-
2  * $Id: vws.trm,v 1.18 2006/07/21 02:35:48 sfeam Exp $
3  *
4  */
5
6 /* GNUPLOT - vws.trm */
7
8 /*[
9  * Copyright 1990 - 1993, 1998, 2004
10  *
11  * Permission to use, copy, and distribute this software and its
12  * documentation for any purpose with or without fee is hereby granted,
13  * provided that the above copyright notice appear in all copies and
14  * that both that copyright notice and this permission notice appear
15  * in supporting documentation.
16  *
17  * Permission to modify the software is granted, but not the right to
18  * distribute the complete modified source code.  Modifications are to
19  * be distributed as patches to the released version.  Permission to
20  * distribute binaries produced by compiling modified sources is granted,
21  * provided you
22  *   1. distribute the corresponding source modifications from the
23  *    released version in the form of a patch file along with the binaries,
24  *   2. add special version identification to distinguish your version
25  *    in addition to the base release version number,
26  *   3. provide your name and address as the primary contact for the
27  *    support of your modified version, and
28  *   4. retain our contact information in regard to use of the base
29  *    software.
30  * Permission to distribute the released version of the source code along
31  * with corresponding source modifications in the form of a patch file is
32  * granted with same provisions 2 through 4 for binary distributions.
33  *
34  * This software is provided "as is" without express or implied warranty
35  * to the extent permitted by applicable law.
36 ]*/
37
38 /*
39  * This file is included by ../term.c.
40  *
41  * This terminal driver supports:
42  *   IRIS terminals
43  *
44  * AUTHORS
45  *   Walter Speth
46  *           BITNET: SPETH@DBNPIB5
47  *
48  * send your comments or suggestions to (gnuplot-info@lists.sourceforge.net).
49  *
50  */
51 /*
52  * adapted to the new terminal layout by Stefan Bodewig (Dec. 1995)
53  * adapted to VAX VMS 4.7, VAX C 2.4 and activated the INTENSITY and COLOR
54  * monitor features (Lucas P. Hart, June 1997)
55  */
56
57 #include "driver.h"
58
59 #ifdef TERM_REGISTER
60 register_term(vws)
61 #endif
62
63 #ifdef TERM_PROTO
64 TERM_PUBLIC void VWS_init __PROTO((void));
65 TERM_PUBLIC void VWS_reset __PROTO((void));
66 TERM_PUBLIC void VWS_graphics __PROTO((void));
67 TERM_PUBLIC void VWS_text __PROTO((void));
68 TERM_PUBLIC void VWS_move __PROTO((unsigned int x, unsigned int y));
69 TERM_PUBLIC void VWS_vector __PROTO((unsigned int x, unsigned int y));
70 TERM_PUBLIC void VWS_linetype __PROTO((int lt));
71 TERM_PUBLIC void VWS_put_text __PROTO((unsigned int x, unsigned int y, const char *str));
72 TERM_PUBLIC int VWS_text_angle __PROTO((int ang));
73 TERM_PUBLIC int VWS_justify_text __PROTO((enum JUSTIFY mode));
74 TERM_PUBLIC void VWS_point __PROTO((unsigned int x, unsigned int y, int point));
75 TERM_PUBLIC void VWS_arrow __PROTO((unsigned int sx, unsigned int sy,
76                                     unsigned int ex, unsigned int ey, int head));
77
78 #define VWS_XMAX 1024
79 #define VWS_YMAX 780            /* VAXstation 2000 is 864 */
80 #define VWS_VCHAR 25
81 #define VWS_HCHAR 15
82 #define VWS_VTIC 10
83 #define VWS_HTIC 10
84 #endif /* TERM_PROTO */
85
86 #ifndef TERM_PROTO_ONLY
87 #ifdef TERM_BODY
88 void VWS_resize_ast __PROTO((void));
89
90 #include <ssdef.h>
91 /* */
92 #include <descrip.h>
93
94 #include <uisentry.h>
95 #include <uisusrdef.h>
96
97 #define DEFAULT_ATTR 0
98 #define OVER_ATTR 1
99 #define ERAS_ATTR 2
100 #define BIS_ATTR 3
101 #define COLOR_ATTR 4
102 #define TEXT_ATTR 5
103 #define LINE_ATTR 6
104 #define BACK_ATTR 7
105
106 float current_x, current_y;
107
108 int vd_id, wd_id;
109 int vcm_id, ws_type;
110
111 static $DESCRIPTOR(ws_devname, "SYS$WORKSTATION");
112 static $DESCRIPTOR(vd_title, "gnuplot");
113
114 static float x0, y0, xsiz, ysiz, wc_xmin_new, wc_ymin_new, wc_xmax_new, wc_ymax_new, wc_xmin,
115 wc_ymin, wc_xmax, wc_ymax, vd_width, vd_height;
116
117 void
118 VWS_resize_ast()
119 {
120     uis$resize_window(&vd_id, &wd_id, &x0, &y0, &xsiz, &ysiz,
121                       &wc_xmin, &wc_ymin, &wc_xmax, &wc_ymax);
122     replotrequest();
123 }
124
125 /****************************************************************************/
126 TERM_PUBLIC void
127 VWS_init()
128 {
129     int i;
130     int cattr;
131     $DESCRIPTOR(a_font, "DTABER0003WK00PG0001UZZZZ02A000");
132     const int i0 = 0, i1 = 1, i2 = 2, i3 = 3, i4 = 4, i5 = 5, i6 = 6, i7 = 7, i8 = 8;
133     const float p0 = 0.0, p1 = 0.1, p2 = 0.2, p3 = 0.3, p4 = 0.4;
134     const float p5 = 0.5, p6 = 0.6, p7 = 0.7, p8 = 0.8, p9 = 0.9;
135     const int n1 = 0xFFFFFFFF;
136     const int uis$c_mode_over = UIS$C_MODE_OVER;
137     const int uis$c_mode_eras = UIS$C_MODE_ERAS;
138     const int uis$c_mode_bis = UIS$C_MODE_BIS;
139     const float vws_hchar = (float) VWS_HCHAR;
140     const float vws_vchar = (float) VWS_VCHAR;
141     const int default_attr = DEFAULT_ATTR;
142     const int over_attr = OVER_ATTR;
143     const int eras_attr = ERAS_ATTR;
144     const int bis_attr = BIS_ATTR;
145     const int color_attr = COLOR_ATTR;
146     const int text_attr = TEXT_ATTR;
147     const int line_attr = LINE_ATTR;
148     const int back_attr = BACK_ATTR;
149
150 /* lph:  the similar notation may lead to some confusion
151  * attributes are grouped in "attribute block" data structures
152  * which are referenced by block number
153  * attribute block 0 contains default attribute settings
154  *
155  * To customize settings, a function will read the source
156  * attribute block, set the particular attribute, and
157  * write to the destination attribute block.
158  * Both the block number and attribute are integers, so it
159  * is easy to confuse an attribute and an attribute blcok
160  */
161
162 /*  lph:  Color map corresponding to an example in
163  *  MicroVMS Graphics Progamming Guide (V3.0) */
164
165     const float r_map[8] = { 0.40, 0.50, 0.50, 0.00, 0.25, 0.90, 0.80, 0.35 };
166     const float g_map[8] = { 0.30, 0.50, 0.25, 0.70, 0.25, 0.50, 0.30, 0.65 };
167     const float b_map[8] = { 0.00, 0.50, 0.50, 0.30, 0.90, 0.00, 0.00, 0.95 };
168
169 /* the array format is easier to customize */
170
171     vd_width = 14;
172     vd_height = 10;             /* aspect sqrt(2) as DIN A paper */
173
174     wc_xmin = 0.0;
175     wc_ymin = 0.0;
176     wc_xmax = (float) VWS_XMAX;
177     wc_ymax = (float) VWS_YMAX;
178
179     vcm_id = uis$create_color_map(&i8);
180
181     vd_id = uis$create_display(&wc_xmin, &wc_ymin, &wc_xmax, &wc_ymax,
182                                &vd_width, &vd_height, &vcm_id);
183     uis$get_hw_color_info(&ws_devname, &ws_type);
184
185 /* lph: ws's color table for monochrome  */
186 /* by default,  color table index 0 is backgound, and 1 is foregound */
187 /* a color {index into the color table} is assigned to the active line */
188 /* in VWS_linetype */
189
190     if (ws_type == UIS$C_DEV_MONO) {
191         uis$set_color(&vd_id, &i0, &p5, &p5, &p5);
192         uis$set_color(&vd_id, &i1, &p0, &p0, &p0);
193         uis$set_color(&vd_id, &i2, &p0, &p0, &p0);
194         uis$set_color(&vd_id, &i3, &p0, &p0, &p0);
195         uis$set_color(&vd_id, &i4, &p0, &p0, &p0);
196         uis$set_color(&vd_id, &i5, &p0, &p0, &p0);
197         uis$set_color(&vd_id, &i6, &p0, &p0, &p0);
198         uis$set_color(&vd_id, &i7, &p0, &p0, &p0);
199     } else if (ws_type == UIS$C_DEV_INTENSITY) {
200         /* Intensity scale, untested */
201         uis$set_color(&vd_id, &i2, &p2, &p2, &p2);
202         uis$set_color(&vd_id, &i3, &p3, &p3, &p3);
203         uis$set_color(&vd_id, &i4, &p4, &p4, &p4);
204         uis$set_color(&vd_id, &i5, &p5, &p5, &p5);
205         uis$set_color(&vd_id, &i6, &p6, &p6, &p6);
206         uis$set_color(&vd_id, &i7, &p7, &p7, &p7);
207     }
208     /* ws: perhaps better for color terms (which I do not have) */
209
210     else if (ws_type == UIS$C_DEV_COLOR) {
211 /* */
212         uis$set_color(&vd_id, &i0, &p0, &p0, &p0);
213         uis$set_color(&vd_id, &i1, &p9, &p0, &p0);
214         uis$set_color(&vd_id, &i2, &p0, &p9, &p0);
215         uis$set_color(&vd_id, &i3, &p9, &p9, &p0);
216         uis$set_color(&vd_id, &i4, &p0, &p0, &p9);
217         uis$set_color(&vd_id, &i5, &p9, &p0, &p9);
218         uis$set_color(&vd_id, &i6, &p0, &p9, &p9);
219         uis$set_color(&vd_id, &i7, &p9, &p9, &p9);
220         /*
221            * lph: Another way to set up the color table is to use arrays,
222            * which simplifies customizing the appearance.
223            *
224            uis$set_colors(&vd_id, &i0, &i8, &r_map, &g_map, &b_map);
225          */
226     }
227     uis$disable_display_list(&vd_id);
228
229     wd_id = uis$create_window(&vd_id, &ws_devname, &vd_title,
230                               &wc_xmin, &wc_ymin, &wc_xmax, &wc_ymax,
231                               &vd_width, &vd_height);
232
233     uis$set_resize_ast(&vd_id, &wd_id, &VWS_resize_ast, &i0,
234                        &x0, &y0, &xsiz, &ysiz,
235                        &wc_xmin_new, &wc_ymin_new, &wc_xmax_new, &wc_ymax_new);
236 /*
237  * lph: This sets up three different attribute blocks, each having a different
238  * mode, but they are never utilized and it is not clear when they might
239  * be of use.
240  * The attribute blocks used for writing are line_attr, text_attr.
241  *
242   uis$set_writing_mode(&vd_id, &default_attr, &over_attr, &uis$c_mode_over);
243   uis$set_writing_mode(&vd_id, &default_attr, &eras_attr, &uis$c_mode_eras);
244   uis$set_writing_mode(&vd_id, &default_attr, &bis_attr, &uis$c_mode_bis);
245  */
246
247 /* lph:  this was commented out;  it changes the COLOR_ATTR BLOCK and
248  * the following BLOCKS
249  *
250 if (ws_type >=  UIS$C_DEV_INTENSITY) {
251   for (i=0; i<8; i++) {
252   cattr = COLOR_ATTR+i;
253   uis$set_writing_index(&vd_id, &default_attr, &cattr, &i);
254   }
255   }
256  *
257   */
258
259 /* lph: default value for the background index into the virtual color
260  * table is 0, and the back_attr block is never used
261  *
262   uis$set_background_index(&vd_id, &default_attr, &back_attr, &i0);
263  *
264  * the rest look OK, setting up the two attribute blocks
265  */
266     uis$set_writing_mode(&vd_id, &default_attr, &text_attr, &uis$c_mode_over);
267     uis$set_font(&vd_id, &text_attr, &text_attr, &a_font);
268     uis$set_char_size(&vd_id, &text_attr, &text_attr, &i0, &vws_hchar, &vws_vchar);
269     uis$set_line_style(&vd_id, &line_attr, &line_attr, &n1);
270 }
271
272 /****************************************************************************/
273
274 TERM_PUBLIC void
275 VWS_reset()
276 {
277     uis$delete_display(&vd_id);
278 }
279
280 /****************************************************************************/
281 TERM_PUBLIC void
282 VWS_graphics()
283 {
284     uis$erase(&vd_id, &wc_xmin, &wc_ymin, &wc_xmax, &wc_ymax);
285 }
286
287 /****************************************************************************/
288 TERM_PUBLIC void
289 VWS_text()
290 {
291 }
292
293 /****************************************************************************/
294 TERM_PUBLIC void
295 VWS_move(unsigned int x, unsigned int y)
296 {
297     current_x = (float) (x);
298     current_y = (float) (y);
299 }
300
301 /****************************************************************************/
302 TERM_PUBLIC void
303 VWS_vector(unsigned int x, unsigned int y)
304 {
305     int col;
306     int line_attr = LINE_ATTR;
307     float fx, fy;
308     fx = (float) x;
309     fy = (float) y;
310
311     uis$line(&vd_id, &line_attr, &current_x, &current_y, &fx, &fy);
312     VWS_move(x, y);
313 }
314
315 /****************************************************************************/
316 TERM_PUBLIC void
317 VWS_linetype(int lt)
318 {
319     const int n1 = 0xFFFFFFFF;
320     /* indices into the color map */
321     const int i[8] = {0, 1, 2, 3, 4, 5, 6, 7};
322     const float p15 = 2.0, p20 = 3.0, p10 = 1.0;
323     long int lstyle[9] =
324     {0xffffffff,
325      0Xff00ff00,
326      0xffffff00,
327      0xffff0000,
328      0xf0f0f0f0,
329      0Xfff0fff0,
330      0xf000f000,
331      0xa5a5a5af,
332      0xf00f00f0
333     };
334     int line_attr = LINE_ATTR;
335     /* use multiplier of normal line width; default is width in pixels */
336     const int uis$c_width_world = UIS$C_WIDTH_WORLD;
337
338     if (lt < 0) {
339         switch (lt) {
340         case LT_AXIS:           /* used for axis */
341             uis$set_line_style(&vd_id, &line_attr, &line_attr, &n1);
342             uis$set_line_width(&vd_id, &line_attr, &line_attr, &p15,
343                                &uis$c_width_world);
344             if (ws_type >= UIS$C_DEV_INTENSITY) {
345                 uis$set_writing_index(&vd_id, &line_attr, &line_attr, &i[1]);
346             }
347             break;
348         case LT_BLACK:          /* the borders */
349             uis$set_line_style(&vd_id, &line_attr, &line_attr, &n1);
350             uis$set_line_width(&vd_id, &line_attr, &line_attr, &p20,
351                                &uis$c_width_world);
352             if (ws_type >= UIS$C_DEV_INTENSITY) {
353                 uis$set_writing_index(&vd_id, &line_attr, &line_attr, &i[1]);
354             }
355             break;
356         default:                /* else a thick line ? */
357             uis$set_line_style(&vd_id, &line_attr, &line_attr, &n1);
358             uis$set_line_width(&vd_id, &line_attr, &line_attr, &p20,
359                                &uis$c_width_world);
360             if (ws_type >= UIS$C_DEV_INTENSITY) {
361                 uis$set_writing_index(&vd_id, &line_attr, &line_attr,
362                                       &i[1 + ((-lt) % 7)]);
363             }
364             break;
365         }
366     } else {
367 /* assign the color index (excluding the background index, 0*/
368         if (ws_type >= UIS$C_DEV_INTENSITY) {
369             uis$set_writing_index(&vd_id, &line_attr, &line_attr, &i[1 + lt % 7]);
370         }
371 /* assign the line style
372     uis$set_line_style(&vd_id,&line_attr,&line_attr,&lstyle[lt % 8]);
373  * ws: makes part of curve disappear on my workstation
374  * lph: also observed w/ VS2000 and 4 plane graphics coprocesssor; line
375  * types change appropriately, but has problems as pixels/line segment
376  * decreases.  Better with full screen display and "set samples" smaller
377  * but start out with only solid lines
378   */
379         uis$set_line_style(&vd_id, &line_attr, &line_attr, &n1);
380
381         uis$set_line_width(&vd_id, &line_attr, &line_attr, &p10,
382                            &uis$c_width_world);
383     }
384 }
385
386 /****************************************************************************/
387 static int justify_mode = CENTRE, up;
388
389 TERM_PUBLIC void
390 VWS_put_text(unsigned int x, unsigned int y, const char *str)
391 {
392     float fx, fy, thih, twid;
393     int text_attr = TEXT_ATTR;
394
395     /* uis$text parameter is descriptor string not character string */
396
397     struct dsc$descriptor_s textline =
398     {0, DSC$K_DTYPE_T, DSC$K_CLASS_S, ""};
399
400
401     textline.dsc$a_pointer = str;
402     textline.dsc$w_length = strlen(textline.dsc$a_pointer);
403     uis$measure_text(&vd_id, &text_attr, &textline, &twid, &thih);
404     fx = (float) x;
405     fy = (float) y;
406
407     switch (justify_mode) {
408     case LEFT:
409         fy += thih / 2.;
410         break;
411     case RIGHT:
412         fy += thih / 2.;
413         fx -= twid;
414         break;
415
416     case CENTRE:
417         fy += thih / 2.;
418         fx -= twid / 2;
419         break;
420     };
421
422     uis$text(&vd_id, &text_attr, &textline, &fx, &fy);
423     /* write to Example Viewport window */
424
425
426 }
427 /****************************************************************************/
428 TERM_PUBLIC int
429 VWS_text_angle(int ang)
430 {
431     float degrees;
432     int text_attr = TEXT_ATTR;
433     up = (ang ? 1 : 0);
434     degrees = 90. * up;
435     uis$set_text_slope(&vd_id, &text_attr, &text_attr, &degrees);
436     return TRUE;
437 }
438 /****************************************************************************/
439 TERM_PUBLIC int
440 VWS_justify_text(enum JUSTIFY mode)
441 {
442     justify_mode = mode;
443     return TRUE;
444 }
445 /****************************************************************************/
446 TERM_PUBLIC void
447 VWS_point(unsigned int x, unsigned int y, int point)
448 {
449     do_point(x, y, point);
450 }
451
452 /****************************************************************************/
453 TERM_PUBLIC void
454 VWS_arrow(
455     unsigned int sx, unsigned int sy,
456     unsigned int ex, unsigned int ey,
457     int head)
458 {
459     do_arrow(sx, sy, ex, ey, head);
460 }
461
462 #endif /* TERM_BODY */
463
464 #ifdef TERM_TABLE
465
466 TERM_TABLE_START(vws_driver)
467     "VWS", "VAX Windowing System (UIS)",
468     VWS_XMAX, VWS_YMAX, VWS_VCHAR, VWS_HCHAR,
469     VWS_VTIC, VWS_HTIC, options_null, VWS_init, VWS_reset,
470     VWS_text, null_scale, VWS_graphics, VWS_move, VWS_vector,
471     VWS_linetype, VWS_put_text, VWS_text_angle,
472     VWS_justify_text, do_point, do_arrow, set_font_null
473 TERM_TABLE_END(vws_driver)
474
475 #undef LAST_TERM
476 #define LAST_TERM vws_driver
477
478 #endif /* TERM_TABLE */
479 #endif /* TERM_PROTO_ONLY */
480
481 #ifdef TERM_HELP
482 START_HELP(VWS)
483 "1 VWS",
484 "?commands set terminal VWS",
485 "?set terminal VWS",
486 "?set term VWS",
487 "?terminal VWS",
488 "?term VWS",
489 "?VWS",
490 " The `VWS` terminal driver supports the VAX Windowing System.  It has",
491 " no options.  It will sense the display type (monochrome, gray scale,",
492 " or color.)  All line styles are plotted as solid lines."
493 END_HELP(VWS)
494 #endif /* TERM_HELP */