/* Hello, Emacs, this is -*-C-*- */
/*[
* GNUPLOT - grass.trm
*-
* Copyright (C) 1992-1995, 1999, 2004 James Darrell McCauley
*
* Permission to use, copy, and distribute this software and its
* documentation for any purpose with or without fee is hereby granted,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation.
*
* Permission to modify the software is granted, but not the right to
* distribute the complete modified source code. Modifications are to
* be distributed as patches to the released version. Permission to
* distribute binaries produced by compiling modified sources is granted,
* provided you
* 1. distribute the corresponding source modifications from the
* released version in the form of a patch file along with the binaries,
* 2. add special version identification to distinguish your version
* in addition to the base release version number,
* 3. provide your name and address as the primary contact for the
* support of your modified version, and
* 4. retain our contact information in regard to use of the base
* software.
* Permission to distribute the released version of the source code along
* with corresponding source modifications in the form of a patch file is
* granted with same provisions 2 through 4 for binary distributions.
*
* This software is provided "as is" without express or implied warranty
* to the extent permitted by applicable law.
*
* This software is provided "as is" without express or implied warranty.
*
* This file is included by ../term.c.
*
* This terminal driver supports:
* GRASS graphics driver
*
* AUTHOR
* James Darrell McCauley, PhD http://soils.ecn.purdue.edu/~mccauley/
* Dept of Agricultural Engineering mccauley@ecn.purdue.edu
* Purdue University tel: 317.494.1198 fax: 317.496.1115
*
* 05 Apr 1995 - cleaned up code by adding explicit function declarations.
* compiles clean with 'gcc -Wall'
* 14 Apr 1995 - adapted for new layout, added font selection
*
* 13 Jan 1999 - Copyright statement changed to new gnuplot copyright
* Permission given by orig author in private email (lh)
*
* send your comments or suggestions to (grassp-list@moon.cecer.army.mil).
*
]*/
#include "driver.h"
#ifdef TERM_REGISTER
register_term(grass)
#endif
#ifdef TERM_PROTO
TERM_PUBLIC void GRASS_move(unsigned int x, unsigned int y);
TERM_PUBLIC void GRASS_options(void);
TERM_PUBLIC void GRASS_init(void);
TERM_PUBLIC void GRASS_reset(void);
TERM_PUBLIC void GRASS_graphics(void);
TERM_PUBLIC void GRASS_text(void);
TERM_PUBLIC void GRASS_vector(unsigned int x, unsigned int y);
TERM_PUBLIC void GRASS_linetype(int lt);
TERM_PUBLIC void GRASS_put_text(unsigned int x, unsigned int y, const char *str);
TERM_PUBLIC int GRASS_text_angle(float ang);
TERM_PUBLIC int GRASS_justify_text(enum JUSTIFY mode);
TERM_PUBLIC void GRASS_point(unsigned int x, unsigned int y, int point);
TERM_PUBLIC int GRASS_set_font(const char *font);
#endif /* TERM_PROTO */
#ifndef TERM_PROTO_ONLY
#ifdef TERM_BODY
#include
#include
/* #include "gis.h" */ /* this causes conflicts with things in term.c */
#define GRASS_XMAX 1000
#define GRASS_YMAX 1000
#define GRASS_VCHAR 5
#define GRASS_HCHAR 5
#define GRASS_VTIC 3
#define GRASS_HTIC 3
#define PNT_SIZE 3
#define TYPE_DOT -1
#define TYPE_X 0
#define TYPE_PLUS 1
#define TYPE_BOX 2
#define TYPE_DIAMOND 3 /* need type 4 and 5 */
#define TYPE_TRIANGLE 4
#define TYPE_OCTO 5
#define TYPE_ITRIANGLE 6
#define TYPE_FBOX 7
#define TYPE_FTRIANGLE 8
#define TYPE_FITRIANGLE 9
#define TYPE_FOCTO 10
static void cont_abs(int x, int y);
static void draw_points_dot(int x, int y);
static void draw_points_diamond(int x, int y);
static void draw_points_box(int x, int y);
static void draw_points_fbox(int x, int y);
static void draw_points_itriangle(int x, int y);
static void draw_points_fitriangle(int x, int y);
static void draw_points_triangle(int x, int y);
static void draw_points_ftriangle(int x, int y);
static void draw_points_plus(int x, int y);
static void draw_points_octo(int x, int y);
static void draw_points_focto(int x, int y);
static void draw_points_x(int x, int y);
static int R__curx, R__cury;
static int grass_yoffset;
static int grass_xoffset;
static int y_max;
static int points_buf_x[PNT_SIZE*PNT_SIZE]; /* for filled point types */
static int points_buf_y[PNT_SIZE*PNT_SIZE];
extern int R_move_abs ();
extern int R_cont_abs ();
TERM_PUBLIC void
GRASS_move(unsigned int x, unsigned int y)
{
/* R_move_abs (grass_xoffset+x, grass_yoffset-y + y_max); */
R_move_abs (grass_xoffset+x, grass_yoffset-y);
}
static void
cont_abs(int x, int y)
{
/* R_cont_abs (grass_xoffset+x, grass_xoffset-y + y_max); */
R_cont_abs (grass_xoffset+x, grass_yoffset-y);
}
TERM_PUBLIC void
GRASS_options()
{
options_null (); /* no options to begin with */
}
TERM_PUBLIC void
GRASS_init()
{
/* char buff[128]; */
char window_name[64];
float size = 3.0;
/* int backcolor; */
int dots_per_line;
int top, b, l, r;
/* int textcolor; */
struct termentry *t = term;
extern int G_gisinit();
extern int R_open_driver();
extern int D_setup();
extern int D_get_cur_wind();
extern int G_fatal_error();
extern int D_set_cur_wind();
extern int D_get_screen_window();
extern int R_set_window();
extern int R_text_size();
extern int R_font();
extern int R_screen_top();
extern int R_screen_bot();
extern int D_erase_window();
G_gisinit ("g.gnuplot");
R_open_driver ();
D_setup (0);
if (D_get_cur_wind (window_name))
G_fatal_error ("No current window");
if (D_set_cur_wind (window_name))
G_fatal_error ("Current window not available");
/* Set up the screen, conversions, and graphics */
D_get_screen_window (&top, &b, &l, &r);
/* D_set_overlay_mode (1); */
/* Figure out where to put text */
R_set_window (top, b, l, r);
t->xmax = r-l;
t->ymax = b-top;
grass_xoffset=l;
grass_yoffset=b;
dots_per_line = (int) (size / 100.0 * (float) (t->ymax));
t->v_char = t->h_char = (int) (.8 * (float) dots_per_line);
R_text_size (t->h_char, t->v_char);
R_font("romans");
t->v_tic = t->h_tic = 4;
y_max = t->ymax; /* kludge? */
R__curx = R_screen_top ();
R__cury = R_screen_bot () + grass_yoffset;
D_erase_window();
fprintf(stderr,"**********************************************\n");
fprintf(stderr,"DIAGNOSTIC TERMINAL SETUP\n");
fprintf(stderr,"top = %d\tb = %d\tl = %d\tr = %d\n", top,b,l,r);
fprintf(stderr,"name = %s\n", t->name);
fprintf(stderr,"description = %s\n", t->description);
fprintf(stderr,"xmax = %d\t", (int)t->xmax);
fprintf(stderr,"ymax = %d\n", (int)t->ymax);
fprintf(stderr,"v_char = %d\t", (int)t->v_char);
fprintf(stderr,"h_char = %d\n", (int)t->h_char);
fprintf(stderr,"v_tic = %d\t", (int)t->v_tic);
fprintf(stderr,"h_tic = %d\n", (int)t->h_tic);
fprintf(stderr,"**********************************************\n\n");
}
TERM_PUBLIC void
GRASS_reset ()
{
extern int R_standard_color();
extern int D_translate_color();
extern int R_flush();
extern int R_stabilize();
extern int R_close_driver();
R_standard_color (D_translate_color ("black"));
/* D_erase_window(); .* don't clear after g.gnuplot is finished */
R_flush ();
R_stabilize ();
R_close_driver ();
}
TERM_PUBLIC void
GRASS_graphics ()
{
extern int D_erase_window();
extern int R_flush();
extern int R_stabilize();
extern int R_standard_color();
extern int D_translate_color();
R_flush ();
R_stabilize ();
R_standard_color (D_translate_color ("black"));
D_erase_window();
return;
}
TERM_PUBLIC void
GRASS_text ()
{
extern int R_flush ();
extern int R_stabilize ();
R_flush ();
R_stabilize ();
return; /* device can't be used as a terminal */
}
TERM_PUBLIC void
GRASS_vector(unsigned int x, unsigned int y)
{
extern int R_flush ();
extern int R_stabilize ();
cont_abs (x, y);
R_flush ();
R_stabilize ();
}
TERM_PUBLIC void
GRASS_linetype(int lt)
{
extern int R_standard_color();
extern int D_translate_color();
extern int R_flush ();
extern int R_stabilize ();
while (lt > 10) lt-=10;
if (lt