1 /* Hello, Emacs, this is -*-C-*- */
6 * Copyright (C) 1992-1995, 1999, 2004 James Darrell McCauley
8 * Permission to use, copy, and distribute this software and its
9 * documentation for any purpose with or without fee is hereby granted,
10 * provided that the above copyright notice appear in all copies and
11 * that both that copyright notice and this permission notice appear
12 * in supporting documentation.
14 * Permission to modify the software is granted, but not the right to
15 * distribute the complete modified source code. Modifications are to
16 * be distributed as patches to the released version. Permission to
17 * distribute binaries produced by compiling modified sources is granted,
19 * 1. distribute the corresponding source modifications from the
20 * released version in the form of a patch file along with the binaries,
21 * 2. add special version identification to distinguish your version
22 * in addition to the base release version number,
23 * 3. provide your name and address as the primary contact for the
24 * support of your modified version, and
25 * 4. retain our contact information in regard to use of the base
27 * Permission to distribute the released version of the source code along
28 * with corresponding source modifications in the form of a patch file is
29 * granted with same provisions 2 through 4 for binary distributions.
31 * This software is provided "as is" without express or implied warranty
32 * to the extent permitted by applicable law.
34 * This software is provided "as is" without express or implied warranty.
36 * This file is included by ../term.c.
38 * This terminal driver supports:
39 * GRASS graphics driver
42 * James Darrell McCauley, PhD http://soils.ecn.purdue.edu/~mccauley/
43 * Dept of Agricultural Engineering mccauley@ecn.purdue.edu
44 * Purdue University tel: 317.494.1198 fax: 317.496.1115
46 * 05 Apr 1995 - cleaned up code by adding explicit function declarations.
47 * compiles clean with 'gcc -Wall'
48 * 14 Apr 1995 - adapted for new layout, added font selection
50 * 13 Jan 1999 - Copyright statement changed to new gnuplot copyright
51 * Permission given by orig author in private email (lh)
53 * send your comments or suggestions to (grassp-list@moon.cecer.army.mil).
65 TERM_PUBLIC void GRASS_move __PROTO((unsigned int x, unsigned int y));
66 TERM_PUBLIC void GRASS_options __PROTO((void));
67 TERM_PUBLIC void GRASS_init __PROTO((void));
68 TERM_PUBLIC void GRASS_reset __PROTO((void));
69 TERM_PUBLIC void GRASS_graphics __PROTO((void));
70 TERM_PUBLIC void GRASS_text __PROTO((void));
71 TERM_PUBLIC void GRASS_vector __PROTO((unsigned int x, unsigned int y));
72 TERM_PUBLIC void GRASS_linetype __PROTO((int lt));
73 TERM_PUBLIC void GRASS_put_text __PROTO((unsigned int x, unsigned int y, const char *str));
74 TERM_PUBLIC int GRASS_text_angle __PROTO((int ang));
75 TERM_PUBLIC int GRASS_justify_text __PROTO((enum JUSTIFY mode));
76 TERM_PUBLIC void GRASS_point __PROTO((unsigned int x, unsigned int y, int point));
77 TERM_PUBLIC int GRASS_set_font __PROTO((const char *font));
78 /* TERM_PUBLIC void GRASS_set_pointsize __PROTO((double size)); */
79 TERM_PUBLIC void GRASS_arrow __PROTO((unsigned int sx, unsigned int sy, unsigned int ex, unsigned int ey, int head));
80 #endif /* TERM_PROTO */
82 #ifndef TERM_PROTO_ONLY
87 /* #include "gis.h" */ /* this causes conflicts with things in term.c */
89 #define GRASS_XMAX 1000
90 #define GRASS_YMAX 1000
101 #define TYPE_DIAMOND 3 /* need type 4 and 5 */
102 #define TYPE_TRIANGLE 4
104 #define TYPE_ITRIANGLE 6
106 #define TYPE_FTRIANGLE 8
107 #define TYPE_FITRIANGLE 9
108 #define TYPE_FOCTO 10
110 static void cont_abs __PROTO((int x, int y));
111 static void draw_points_dot __PROTO((int x, int y));
112 static void draw_points_diamond __PROTO((int x, int y));
113 static void draw_points_box __PROTO((int x, int y));
114 static void draw_points_fbox __PROTO((int x, int y));
115 static void draw_points_itriangle __PROTO((int x, int y));
116 static void draw_points_fitriangle __PROTO((int x, int y));
117 static void draw_points_triangle __PROTO((int x, int y));
118 static void draw_points_ftriangle __PROTO((int x, int y));
119 static void draw_points_plus __PROTO((int x, int y));
120 static void draw_points_octo __PROTO((int x, int y));
121 static void draw_points_focto __PROTO((int x, int y));
122 static void draw_points_x __PROTO((int x, int y));
124 static int R__curx, R__cury;
126 static int grass_yoffset;
127 static int grass_xoffset;
129 static int points_buf_x[PNT_SIZE*PNT_SIZE]; /* for filled point types */
130 static int points_buf_y[PNT_SIZE*PNT_SIZE];
132 extern int R_move_abs ();
133 extern int R_cont_abs ();
136 GRASS_move(unsigned int x, unsigned int y)
138 /* R_move_abs (grass_xoffset+x, grass_yoffset-y + y_max); */
139 R_move_abs (grass_xoffset+x, grass_yoffset-y);
143 cont_abs(int x, int y)
145 /* R_cont_abs (grass_xoffset+x, grass_xoffset-y + y_max); */
146 R_cont_abs (grass_xoffset+x, grass_yoffset-y);
152 options_null (); /* no options to begin with */
158 /* char buff[128]; */
159 char window_name[64];
165 struct termentry *t = term;
167 extern int G_gisinit();
168 extern int R_open_driver();
169 extern int D_setup();
170 extern int D_get_cur_wind();
171 extern int G_fatal_error();
172 extern int D_set_cur_wind();
173 extern int D_get_screen_window();
174 extern int R_set_window();
175 extern int R_text_size();
177 extern int R_screen_top();
178 extern int R_screen_bot();
179 extern int D_erase_window();
181 G_gisinit ("g.gnuplot");
187 if (D_get_cur_wind (window_name))
188 G_fatal_error ("No current window");
190 if (D_set_cur_wind (window_name))
191 G_fatal_error ("Current window not available");
193 /* Set up the screen, conversions, and graphics */
194 D_get_screen_window (&top, &b, &l, &r);
195 /* D_set_overlay_mode (1); */
197 /* Figure out where to put text */
199 R_set_window (top, b, l, r);
205 dots_per_line = (int) (size / 100.0 * (float) (t->ymax));
206 t->v_char = t->h_char = (int) (.8 * (float) dots_per_line);
207 R_text_size (t->h_char, t->v_char);
210 t->v_tic = t->h_tic = 4;
212 y_max = t->ymax; /* kludge? */
214 R__curx = R_screen_top ();
215 R__cury = R_screen_bot () + grass_yoffset;
219 fprintf(stderr,"**********************************************\n");
220 fprintf(stderr,"DIAGNOSTIC TERMINAL SETUP\n");
221 fprintf(stderr,"top = %d\tb = %d\tl = %d\tr = %d\n", top,b,l,r);
222 fprintf(stderr,"name = %s\n", t->name);
223 fprintf(stderr,"description = %s\n", t->description);
224 fprintf(stderr,"xmax = %d\t", (int)t->xmax);
225 fprintf(stderr,"ymax = %d\n", (int)t->ymax);
226 fprintf(stderr,"v_char = %d\t", (int)t->v_char);
227 fprintf(stderr,"h_char = %d\n", (int)t->h_char);
228 fprintf(stderr,"v_tic = %d\t", (int)t->v_tic);
229 fprintf(stderr,"h_tic = %d\n", (int)t->h_tic);
230 fprintf(stderr,"**********************************************\n\n");
236 extern int R_standard_color();
237 extern int D_translate_color();
238 extern int R_flush();
239 extern int R_stabilize();
240 extern int R_close_driver();
242 R_standard_color (D_translate_color ("black"));
243 /* D_erase_window(); .* don't clear after g.gnuplot is finished */
252 extern int D_erase_window();
253 extern int R_flush();
254 extern int R_stabilize();
255 extern int R_standard_color();
256 extern int D_translate_color();
260 R_standard_color (D_translate_color ("black"));
268 extern int R_flush ();
269 extern int R_stabilize ();
273 return; /* device can't be used as a terminal */
277 GRASS_vector(unsigned int x, unsigned int y)
279 extern int R_flush ();
280 extern int R_stabilize ();
288 GRASS_linetype(int lt)
290 extern int R_standard_color();
291 extern int D_translate_color();
292 extern int R_flush ();
293 extern int R_stabilize ();
295 while (lt > 10) lt-=10;
298 R_standard_color (D_translate_color ("gray"));
299 else if (lt == LT_AXIS)
300 R_standard_color (D_translate_color ("white"));
302 R_standard_color (D_translate_color ("red"));
304 R_standard_color (D_translate_color ("green"));
306 R_standard_color (D_translate_color ("magenta"));
308 R_standard_color (D_translate_color ("brown"));
310 R_standard_color (D_translate_color ("orange"));
312 R_standard_color (D_translate_color ("yellow"));
314 R_standard_color (D_translate_color ("blue"));
316 R_standard_color (D_translate_color ("violet"));
318 R_standard_color (D_translate_color ("indigo"));
320 R_standard_color (D_translate_color ("gray"));
321 else /* if (lt == 10) */
322 R_standard_color (D_translate_color ("white"));
328 /* originally /usr/grass4/src/display/d.label/cmd/label.c */
331 GRASS_put_text(unsigned int x, unsigned int y, const char *str)
334 extern int R_flush ();
335 extern int R_stabilize ();
337 if (strlen (str) == 0)
341 /* R_standard_color (D_translate_color ("white")); */
348 GRASS_text_angle (int ang)
350 extern int R_text_rotation();
352 R_text_rotation((float)ang);
353 return TRUE; /* GRASS can (?) rotate text */
357 GRASS_justify_text (enum JUSTIFY mode)
359 return (FALSE); /* don't mess with this now */
364 GRASS_point (unsigned int x, unsigned y, int point)
368 draw_points_dot (x, y);
371 draw_points_x (x, y);
374 draw_points_plus (x, y);
377 draw_points_box (x, y);
380 draw_points_diamond (x, y);
383 draw_points_triangle (x, y);
386 draw_points_octo (x, y);
389 draw_points_itriangle (x, y);
392 draw_points_fbox (x, y);
395 draw_points_ftriangle (x, y);
397 case TYPE_FITRIANGLE:
398 draw_points_fitriangle (x, y);
401 draw_points_focto (x, y);
406 /* modified from /usr/grass4/src/display/d.points/cmd/main.c */
409 draw_points_dot(int x, int y)
416 draw_points_diamond(int x, int y)
418 GRASS_move (x, y + PNT_SIZE);
419 GRASS_vector (x + PNT_SIZE, y);
420 GRASS_vector (x, y - PNT_SIZE);
421 GRASS_vector (x - PNT_SIZE, y);
422 GRASS_vector (x, y + PNT_SIZE);
426 draw_points_box(int x, int y)
428 GRASS_move (x - PNT_SIZE, y - PNT_SIZE);
429 GRASS_vector (x - PNT_SIZE, y + PNT_SIZE);
430 GRASS_vector (x + PNT_SIZE, y + PNT_SIZE);
431 GRASS_vector (x + PNT_SIZE, y - PNT_SIZE);
432 GRASS_vector (x - PNT_SIZE, y - PNT_SIZE);
436 draw_points_fbox(int x, int y)
439 points_buf_x[0] = grass_xoffset + x - PNT_SIZE;
440 points_buf_y[0]= grass_yoffset - (y + PNT_SIZE);
441 points_buf_x[1] = grass_xoffset + x + PNT_SIZE;
442 points_buf_y[1]= grass_yoffset - (y + PNT_SIZE);
443 points_buf_x[2] = grass_xoffset + x + PNT_SIZE;
444 points_buf_y[2]= grass_yoffset - (y - PNT_SIZE);
445 points_buf_x[3] = grass_xoffset + x - PNT_SIZE;
446 points_buf_y[3]= grass_yoffset - (y - PNT_SIZE);
447 R_polygon_abs(points_buf_x, points_buf_y, 4 );
451 draw_points_itriangle(int x, int y)
453 GRASS_move (x - PNT_SIZE, y + PNT_SIZE);
454 GRASS_vector (x + PNT_SIZE, y + PNT_SIZE);
455 GRASS_vector (x , y - PNT_SIZE);
456 GRASS_vector (x - PNT_SIZE, y + PNT_SIZE);
460 draw_points_fitriangle(int x, int y)
464 points_buf_x[0] = grass_xoffset + x + PNT_SIZE;
465 points_buf_y[0] = grass_yoffset - (y + PNT_SIZE);
466 points_buf_x[1] = grass_xoffset + x ;
467 points_buf_y[1] = grass_yoffset - (y - PNT_SIZE);
468 points_buf_x[2] = grass_xoffset + x - PNT_SIZE;
469 points_buf_y[2] = grass_yoffset - (y + PNT_SIZE);
470 R_polygon_abs(points_buf_x, points_buf_y, 3 );
474 draw_points_triangle(int x, int y)
476 GRASS_move (x - PNT_SIZE, y - PNT_SIZE);
477 GRASS_vector (x , y + PNT_SIZE);
478 GRASS_vector (x + PNT_SIZE, y - PNT_SIZE);
479 GRASS_vector (x - PNT_SIZE, y - PNT_SIZE);
483 draw_points_ftriangle(int x, int y)
487 points_buf_x[0] = grass_xoffset + x;
488 points_buf_y[0]= grass_yoffset - (y + PNT_SIZE);
489 points_buf_x[1] = grass_xoffset + x + PNT_SIZE;
490 points_buf_y[1]= grass_yoffset - (y - PNT_SIZE);
491 points_buf_x[2] = grass_xoffset + x - PNT_SIZE;
492 points_buf_y[2]= grass_yoffset - (y - PNT_SIZE);
493 R_polygon_abs(points_buf_x, points_buf_y, 3 );
497 draw_points_plus(int x, int y)
499 GRASS_move (x - PNT_SIZE, y);
500 GRASS_vector (x + PNT_SIZE, y);
501 GRASS_move (x, y - PNT_SIZE);
502 GRASS_vector (x, y + PNT_SIZE);
505 /* depends on PNT_SIZE */
507 draw_points_octo(int x, int y)
510 GRASS_move (x - (int) (PNT_SIZE/3), y - PNT_SIZE); /* 1 */
511 GRASS_vector (x + (int) (PNT_SIZE/3), y - PNT_SIZE); /* 2 */
512 GRASS_vector (x + PNT_SIZE, y - (int) (PNT_SIZE/3)); /* 3 */
513 GRASS_vector (x + PNT_SIZE, y + (int) (PNT_SIZE/3)); /* 4 */
514 GRASS_vector (x + (int) (PNT_SIZE/3), y + PNT_SIZE); /* 5 */
515 GRASS_vector (x - (int) (PNT_SIZE/3), y + PNT_SIZE); /* 6 */
516 GRASS_vector (x - PNT_SIZE, y + (int) (PNT_SIZE/3)); /* 7 */
517 GRASS_vector (x - PNT_SIZE, y - (int) (PNT_SIZE/3)); /* 8 */
518 GRASS_vector (x - (int) (PNT_SIZE/3), y - PNT_SIZE); /* 1 */
521 /* depends on PNT_SIZE */
523 draw_points_focto(int x, int y)
528 points_buf_x[0] = grass_xoffset + x + (int) (PNT_SIZE/3);
529 points_buf_y[0] = grass_yoffset - (y - PNT_SIZE);
530 points_buf_x[1] = grass_xoffset + x + PNT_SIZE;
531 points_buf_y[1] = grass_yoffset - (y - (int) (PNT_SIZE/3));
532 points_buf_x[2] = grass_xoffset + x + PNT_SIZE;
533 points_buf_y[2] = grass_yoffset - (y + (int) (PNT_SIZE/3));
534 points_buf_x[3] = grass_xoffset + x + (int) (PNT_SIZE/3);
535 points_buf_y[3] = grass_yoffset - (y + PNT_SIZE);
536 points_buf_x[4] = grass_xoffset + x - (int) (PNT_SIZE/3);
537 points_buf_y[4] = grass_yoffset - (y + PNT_SIZE);
538 points_buf_x[5] = grass_xoffset + x - PNT_SIZE;
539 points_buf_y[5] = grass_yoffset - (y + (int) (PNT_SIZE/3));
540 points_buf_x[6] = grass_xoffset + x - PNT_SIZE;
541 points_buf_y[6] = grass_yoffset - (y - (int) (PNT_SIZE/3));
542 points_buf_x[7] = grass_xoffset + x - (int) (PNT_SIZE/3);
543 points_buf_y[7] = grass_yoffset - (y - PNT_SIZE);
544 R_polygon_abs(points_buf_x, points_buf_y, 8 );
548 draw_points_x(int x, int y)
550 GRASS_move (x - PNT_SIZE, y - PNT_SIZE);
551 GRASS_vector (x + PNT_SIZE, y + PNT_SIZE);
552 GRASS_move (x + PNT_SIZE, y - PNT_SIZE);
553 GRASS_vector (x - PNT_SIZE, y + PNT_SIZE);
557 GRASS_set_font(const char *font)
560 int size,sep, R_font();
561 struct termentry *t = term;
562 int R_text_size (), dots_per_line;
564 /* G_warning(font); */
566 sep=strcspn(font,",");
567 strncpy(name,font,sep); name[sep]=NUL;
568 sscanf (&(font[sep+1]),"%d",&size);
572 dots_per_line = (int) (size / 100.0 * (float) (t->ymax));
573 t->v_char = t->h_char = (int) (.8 * (float) dots_per_line);
574 R_text_size (t->h_char, t->v_char);
575 /* cyrilc,gothgbt,gothgrt,gothitt,greekc,greekcs,greekp,
576 greeks,italicc,italiccs,italict,romanc,romancs,romand,
577 romans,romant,scriptc,scripts */
579 if (strlen(name) > 5 )
586 #ifdef GRASS_POINTSIZE
587 /* HBB FIXME 20040619: argument type wrong, but luckily unused anyway... */
589 GRASS_set_pointsize(double *size)
593 #endif /* GRASS_POINTSIZE */
598 unsigned int sx, unsigned int sy,
599 unsigned int ex, unsigned int ey,
602 do_arrow (sx, sy, ex, ey, 1);
606 #endif /* TERM_BODY */
609 TERM_TABLE_START(grass_driver)
610 "grass", "GRASS Graphics Monitor",
611 GRASS_XMAX, GRASS_YMAX, GRASS_VCHAR, GRASS_HCHAR,
612 GRASS_VTIC, GRASS_HTIC, GRASS_options, GRASS_init, GRASS_reset,
613 GRASS_text, null_scale, GRASS_graphics, GRASS_move, GRASS_vector,
614 GRASS_linetype, GRASS_put_text, GRASS_text_angle,
615 GRASS_justify_text, GRASS_point, GRASS_arrow, GRASS_set_font
616 TERM_TABLE_END(grass_driver)
620 #define LAST_TERM grass_driver
621 #endif /* TERM_TABLE */
622 #endif /* TERM_PROTO_ONLY */
628 "?commands set terminal grass",
629 "?set terminal grass",
634 " The `grass` terminal driver gives `gnuplot` capabilities to users of the ",
635 " GRASS geographic information system. Contact grassp-list@moon.cecer.army.mil",
636 " for more information. Pages are written to the current frame of the GRASS",
637 " Graphics Window. There are no options."