1 /***************************************************************************
2 JSPICE3 adaptation of Spice3e2 - Copyright (c) Stephen R. Whiteley 1992
3 Copyright 1990 Regents of the University of California.  All rights reserved.
4 Authors: 1988 Jeffery M. Hsu
5          1992 Stephen R. Whiteley
6 ****************************************************************************/
7 
8 /*
9  * This file contains the graph structure.
10  */
11 
12 #ifndef _GRAPH_H_
13 #define _GRAPH_H_
14 
15 #include "fteconst.h"
16 #include "ftedata.h"      /* for struct dvec */
17 
18 #define NUMCOLORS 32
19 
20 #define GR_PLOT 0
21 #define GR_GRAF 1
22 #define GR_MPLT 2
23 #define GR_SCED 3
24 
25 /* generic pointer to type specific data structure */
26 typedef char * GRDATA;
27 
28 /* Device-independent data structure for plots. */
29 typedef struct graph {
30     int graphid;
31     int graphtype;     /* type of graph: GR_? */
32 
33     GRDATA plotdata;   /* normalized data */
34 
35     char *plotname;    /* name of plot this graph is in */
36     int onevalue;      /* boolean variable,
37                           true if plotting one value
38                           against itself (real vs imaginary) */
39     int degree;        /* degree of polynomial interpretation */
40 
41     int currentcolor;
42     int linestyle;
43 
44     struct {
45         int height, width;
46     } viewport;
47     int viewportxoff;  /* x offset of viewport w/in graph */
48     int viewportyoff;  /* y offset of viewport w/in graph */
49 
50     struct {
51         int xpos;      /* x position of graph in screen coord */
52         int ypos;      /* y position of graph in screen coord */
53         int width;     /* width of window on screen */
54         int height;    /* height of window on screen */
55     } absolute;
56 
57     struct {
58         double xmin, ymin, xmax, ymax;
59         /* cache:  width = xmax - xmin  height = ymax - ymin */
60         double width, height;
61     } datawindow;
62 
63     /* callbacks:
64      */
65 #ifdef __STDC__
66     void (*redraw)(struct graph*);  /* redraw procedure */
67     void (*destroy)(GRDATA);        /* free data procedure */
68     GRDATA (*copydata)(GRDATA);     /* copy data procedure */
69 #else
70     void (*redraw)();
71     void (*destroy)();
72     GRDATA (*copydata)();
73 #endif
74 
75     /* note: this int is device dependent */
76     int colors[NUMCOLORS];
77 
78     /* cache (datawindow size) / (viewport size) */
79     double aspectratiox, aspectratioy;
80 
81     int ticmarks;               /* mark every ticmark'th point */
82     int fontwidth, fontheight;  /* for use in grid */
83 
84     PLOTTYPE plottype;      /* defined in FTEconstant.h */
85     struct {
86         GRIDTYPE gridtype;    /* defined in FTEconstant.h */
87         int circular;         /* TRUE if circular plot area */
88         union {
89             struct {
90                 char units[16]; /* unit labels */
91                 int spacing, numspace, distance, lowlimit, highlimit, mult;
92                 int onedec;     /* a boolean */
93                 int hacked;     /* true if hi - lo already hacked up */
94             } lin;
95             struct {
96                 int hmt, lmt, decsp, subs, pp;
97             } log;
98             struct {
99                 int radius, center;
100                 double mrad;
101                 int lmt;
102             } circular;     /* bogus, rework when write polar grids, etc */
103         } xaxis, yaxis;
104         int xdatatype, ydatatype;
105         double xdelta, ydelta; /* if non-zero, user-specified deltas */
106         char *xlabel, *ylabel;
107     } grid;
108 
109     int numbuttons;     /* number of buttons */
110     struct {
111         int id;
112         char *message;
113     } *buttons;
114     int buttonsxoff;    /* viewportxoff + x size of viewport */
115     int buttonsyoff;
116 
117     struct {
118         int width, height;
119         char message[161];        /* two lines of text */
120     } messagebox;
121     int messagexoff;
122     int messageyoff;
123 
124     /* characters the user typed on graph */
125     struct _keyed {
126         char *text;
127         int x, y;
128         int colorindex;       /* index into colors array */
129         struct _keyed *next;
130     } *keyed;
131 
132     /* for zoomin */
133     char *commandline;
134 
135     /* Need to have device dependent info here because
136      * otherwise every device implementation would need to handle
137      * its own device dependent analog of GRAPH.  I want a
138      * language with generics.
139      * Use pointer so we don't have to include device dependent
140      * header files here.
141      * Space here is allocated by NewViewport
142      * and de-allocated by DestroyGraph.
143      */
144     char *devdep;
145 
146 } GRAPH;
147 
148 extern GRAPH *currentgraph;
149 extern int numgraphcxsw;
150 
151 #define NEWGRAPH (GRAPH *) calloc(1, sizeof(GRAPH))
152 
153 
154 
155 /***************************************************************************
156 Defs for the Input routine.
157 
158 char_option: Used by the lexer and elsewhere.  response.reply.ch contains the
159     character, obtained from the graphics package if request.fp is 0,
160     otherwise from the standard input.
161 
162 button_option: Used by the menu system and the help package,
163     response.reply.button contains the button number.
164 
165 click_option: Used in the X10 version for the hardcopy command,
166     response.reply.graph is the associated graph structure.
167 
168 point_option: Used in the SCED schematic capture editor.  Returns the window
169     coords of the pointer in response.x,response.y.  If there was a button
170     press, thr reply option is button_option and response.reply.button
171     contains the button number.  If the keyboard was used, the character
172     is returned in response.reply.ch, and the response option is char_option.
173 
174 checkup_option: For handling pending asynchonous events.
175 ****************************************************************************/
176 
177 typedef enum {
178     error_option,       /* a reply option only */
179     button_option,      /* get a button press */
180     char_option,        /* get a char */
181     click_option,       /* point at a widget */
182     point_option,       /* get a char or button, return coords */
183     checkup_option      /* see if events in queue */
184 } OPTION;
185 
186 typedef struct request {
187     OPTION option;
188     FILE *fp;
189 } REQUEST;
190 
191 typedef struct response {
192     OPTION option;
193     int x;
194     int y;
195     union {
196       int ch;
197       GRAPH *graph;
198       int button;
199     } reply;
200 } RESPONSE;
201 
202 
203 #define rnd(x)  (int) ((x)+0.5)
204 
205 /* graphdb.c */
206 #ifdef __STDC__
207 extern GRAPH *NewGraph(void);
208 extern GRAPH *FindGraph(int);
209 extern GRAPH *CopyGraph(GRAPH*);
210 extern int   DestroyGraph(int);
211 extern void  FreeGraphs(void);
212 extern void  SetGraphContext(int);
213 extern void  PushGraphContext(GRAPH*);
214 extern void  PopGraphContext(void);
215 #else
216 extern GRAPH *NewGraph();
217 extern GRAPH *FindGraph();
218 extern GRAPH *CopyGraph();
219 extern int   DestroyGraph();
220 extern void  FreeGraphs();
221 extern void  SetGraphContext();
222 extern void  PushGraphContext();
223 extern void  PopGraphContext();
224 #endif
225 
226 
227 #endif  /* notdef _GRAPH_H_ */
228