Jspice3
display.c
Go to the documentation of this file.
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: 1987 UCB
5  1992 Stephen R. Whiteley
6 ****************************************************************************/
7 
8 #include "spice.h"
9 #include "plotdefs.h"
10 
11 #ifdef __STDC__
12 static int gen_DatatoScreen(GRAPH*,double,double,int*,int*);
13 static int gen_Input(REQUEST*,RESPONSE*);
14 static int nodev();
15 static int nop();
16 #else
17 static int gen_DatatoScreen();
18 static int gen_Input();
19 static int nodev();
20 static int nop();
21 #endif
22 
23 
25 
26  {"error",
27  false, false, 0, 0, 0, 0, 0, 0, nop, nop,
28  nop, nop, nop, nop,
29  nop, nop, nop, nop,
30  nop, nop, nop,
31  nop, nop, nop,
32  nop, nop,
33  nop, nop, nop, gen_Input,
34  nop,},
35 
36 #ifdef HAVE_X11
37  {"X11",
38  true, false, 0, 0, 1024, 864, 0, 0, X11_Init, X11_NewViewport,
39  X11_Close, X11_Halt, X11_Clear, X11_Title,
40  X11_Pixel, X11_Line, X11_Box, X11_Arc,
41  X11_Polygon, X11_Text, X11_SetGhost,
42  X11_DefineColor, X11_DefineLinestyle, X11_SetLinestyle,
43  X11_SetColor, X11_Update,
44  nodev, nodev, nodev, X11_Input,
46 #endif
47 
48 #ifdef HAVE_MFB
49  {"MFB",
50  false, false, 0, 0, 1000, 1000, 0, 0, Mfb_Init, Mfb_NewViewport,
51  Mfb_Close, Mfb_Halt, Mfb_Clear, nop,
52  Mfb_Pixel, Mfb_Line, Mfb_Box, Mfb_Arc,
53  Mfb_Polygon, Mfb_Text, Mfb_SetGhost,
54  Mfb_DefineColor, Mfb_DefineLinestyle, Mfb_SetLinestyle,
55  Mfb_SetColor, Mfb_Update,
56  nodev, Mfb_MakeMenu, Mfb_MakeDialog, Mfb_Input,
58 #endif
59 
60  {"plot5",
61  false, true, 0, 0, 1000, 1000, 0, 0, Plt5_Init, Plt5_NewViewport,
67  nop, nop, nop, nop,
69 
70  {"postscript",
71  false, true, 0, 0, 1000, 1000, 0, 0, PS_Init, PS_NewViewport,
77  nop, nop, nop, nop,
79 
80  {"laser",
81  false, true, 0, 0, 1000, 1000, 0, 0, HP_Init, HP_NewViewport,
86  nop, nop,
87  nop, nop, nop, nop,
89 
90  {"wp",
91  false, true, 0, 0, 1000, 1000, 0, 0, WP_Init, WP_NewViewport,
96  nop, nop,
97  nop, nop, nop, nop,
99 
100  {"printf",
101  false, true, 0, 0, 24, 80, 0, 0, nodev, nodev,
102  nodev, nodev, nodev, nodev,
103  nodev, nodev, nodev, nodev,
104  nodev, nodev, nodev,
105  nodev, nodev, nodev,
106  nodev, nodev,
107  nodev, nodev, nodev, nodev,
108  nodev,},
109 
110 };
111 
113 
114 #define XtNumber(arr) (sizeof(arr) / sizeof(arr[0]))
115 
116 
117 DISPDEVICE *
118 FindDev(name)
119 
120 char *name;
121 {
122  int i;
123 
124  for (i=0; i < XtNumber(device); i++) {
125  if (!strcmp(name, device[i].name)) {
126  return (&device[i]);
127  }
128  }
129  sprintf(ErrorMessage, "Can't find device %s.", name);
131  return (&device[0]);
132 }
133 
134 int
135 DevXterm(string)
136 
137 char *string;
138 {
139  char buf[BSIZE_SP];
140 
141  if (dispdev->windows)
142  (void) sprintf(buf, "xterm -e %s", string);
143  else
144  (void) sprintf(buf, "%s", string);
145 
146  return (system(buf));
147 }
148 
149 
150 void
152 
153 {
154  int id;
155 
156  /* halt graphics if not windowed */
157  if (!dispdev->windows &&
159  DevHalt();
160  id = currentgraph->graphid;
161  PopGraphContext();
162  DestroyGraph(id);
163  }
164 }
165 
166 
167 void
169 
170 {
171  char buf[128];
172  extern char *kw_display;
173 
174 /* note: do better determination */
175 /*
176  dumb tradition that got passed on from gi_interface
177  to do compile time determination
178 */
179 #ifdef HAVE_MFB
180 #ifdef HAVE_X11
181  /* determine display type */
182  if (cp_display)
183  dispdev = FindDev("X11");
184  else
185  dispdev = FindDev("MFB");
186 #else /* MFB but not X */
187  dispdev = FindDev("MFB");
188 #endif
189 #else
190 #ifdef HAVE_X11
191  dispdev = FindDev("X11");
192 #else /* no MFB nor X */
194  "no graphics packages; need to define either WANT_X11, or WANT_MFB");
195  dispdev = FindDev("error");
196 #endif
197 #endif
198 
199  if ((*(dispdev->Init))()) {
200  fprintf(cp_err,
201  "Warning: can't initialize display device for graphics.\n");
202  dispdev = FindDev("error");
203  }
204 }
205 
206 
207 /* NewViewport is responsible for filling in graph->viewport */
208 int
210 
211 GRAPH *pgraph;
212 {
213  return (*(dispdev->NewViewport))(pgraph);
214 }
215 
216 
217 void
219 
220 {
221  (void)(*(dispdev->Close))();
222 }
223 
224 
225 void
227 
228 {
229  (void)(*(dispdev->Halt))();
230 }
231 
232 
233 void
235 
236 {
237  (void)(*(dispdev->Clear))();
238 }
239 
240 
241 void
242 DevTitle(wintitle,icontitle)
243 
244 char *wintitle, *icontitle;
245 {
246  (void)(*(dispdev->Title))(wintitle,icontitle);
247 }
248 
249 
250 void
251 DevPixel(x, y)
252 
253 int x, y;
254 {
255  (void)(*(dispdev->Pixel))(x, y);
256 }
257 
258 
259 void
260 DevLine(x1, y1, x2, y2)
261 
262 int x1, y1, x2, y2;
263 {
264  (void)(*(dispdev->Line))(x1, y1, x2, y2);
265 }
266 
267 
268 void
269 DevBox(x1, y1, x2, y2)
270 
271 int x1, y1, x2, y2;
272 {
273  (void)(*(dispdev->Box))(x1, y1, x2, y2);
274 }
275 
276 
277 void
278 DevArc(x0, y0, radius, theta1, theta2)
279 
280 int x0, y0, radius;
281 double theta1, theta2;
282 {
283  (void)(*(dispdev->Arc))(x0, y0, radius, theta1, theta2);
284 }
285 
286 
287 void
289 
290 POLYGON *p;
291 {
292  (void)(*(dispdev->Polygon))(p);
293 }
294 
295 
296 void
297 DevText(text, x, y)
298 
299 char *text;
300 int x, y;
301 {
302  (void)(*(dispdev->Text))(text, x, y);
303 }
304 
305 
306 void
307 DevSetGhost(callback,x,y)
308 
309 #ifdef __STDC__
310 void (*callback)(int,int,int,int);
311 #else
312 void (*callback)();
313 #endif
314 int x,y;
315 {
316  (void)(*(dispdev->SetGhost))(callback, x, y);
317 }
318 
319 
320 void
321 DevDefineColor(colorid, red, green, blue)
322 
323 int colorid;
324 double red, green, blue;
325 {
326  (void)(*(dispdev->DefineColor))(colorid, red, green, blue);
327 }
328 
329 
330 void
331 DevDefineLinestyle(linestyleid, mask)
332 
333 int linestyleid;
334 int mask;
335 {
336  (void)(*(dispdev->DefineLinestyle))(linestyleid, mask);
337 }
338 
339 
340 void
341 DevSetLinestyle(linestyleid)
342 
343 int linestyleid;
344 {
345  (void)(*(dispdev->SetLinestyle))(linestyleid);
346 }
347 
348 
349 void
350 DevSetColor(colorid)
351 
352 int colorid;
353 {
354  (void)(*(dispdev->SetColor))(colorid);
355 }
356 
357 
358 void
360 {
361  (void)(*(dispdev->Update))();
362 }
363 
364 
365 /* note: screen coordinates are relative to window
366  * so need to add viewport offsets
367  */
368 static int
369 gen_DatatoScreen(graph, x, y, screenx, screeny)
370 
371 GRAPH *graph;
372 double x, y;
373 int *screenx, *screeny;
374 {
375  double low, high;
376 
377  /* note: think this out---Is 1 part of the viewport? Do we handle
378  this correctly? */
379 
380  /* have to handle several types of grids */
381 
382  /* note: we can't compensate for X's demented y-coordinate system here
383  since the grid routines use DevLine w/o calling this routine */
384  if ((graph->grid.gridtype == GRID_LOGLOG) ||
385  (graph->grid.gridtype == GRID_YLOG)) {
386  low = mylog10(graph->datawindow.ymin);
387  high = mylog10(graph->datawindow.ymax);
388  *screeny = rnd( (((mylog10(y) - low) / (high - low))
389  * graph->viewport.height)
390  + graph->viewportyoff );
391  }
392  else {
393  *screeny = rnd( ((y - graph->datawindow.ymin) / graph->aspectratioy)
394  + graph->viewportyoff );
395  }
396 
397  if ((graph->grid.gridtype == GRID_LOGLOG) ||
398  (graph->grid.gridtype == GRID_XLOG)) {
399  low = mylog10(graph->datawindow.xmin);
400  high = mylog10(graph->datawindow.xmax);
401  *screenx = rnd( ((mylog10(x) - low) / (high - low))
402  * graph->viewport.width
403  + graph ->viewportxoff);
404  }
405  else {
406  *screenx = rnd( (x - graph->datawindow.xmin) / graph->aspectratiox
407  + graph ->viewportxoff);
408  }
409  return (0);
410 }
411 
412 
413 void
414 DevDatatoScreen(graph, x, y, screenx, screeny)
415 
416 GRAPH *graph;
417 double x, y;
418 int *screenx, *screeny;
419 {
420  (void)(*(dispdev->DatatoScreen))(graph, x, y, screenx, screeny);
421 }
422 
423 #ifdef notdef
424 /*
425 void
426 NDCtoScreen(x0, y0, px, py)
427 
428 double x0, y0;
429 int *px, *py;
430 {
431  (void)(*(dispdev->NDCtoScreen))(x0, y0, px, py);
432 }
433 */
434 #endif
435 
436 
437 void
439 
442 {
443  (void)(*(dispdev->Input))(request, response);
444 }
445 
446 
447 static int
449 
452 {
453  switch (request->option) {
454  case char_option:
455  response->reply.ch = cp_inchar(request->fp);
456  response->option = request->option;
457  break;
458  default:
459  /* just ignore, since we don't want a million error messages */
460  if (response)
461  response->option = error_option;
462  break;
463  }
464  return (0);
465 }
466 
467 
468 /* no operation, do nothing */
469 static int nop()
470 {
471  return (1); /* so NewViewport will fail */
472 }
473 
474 
475 static int
477 {
478  sprintf(ErrorMessage,
479  "This operation is not defined for display type %s.",
480  dispdev->name);
482  return (1);
483 }
484 
485 
486 void
487 SaveText(graph, text, x, y)
488 
489 GRAPH *graph;
490 char *text;
491 int x, y;
492 {
493  struct _keyed *keyed;
494 
495  keyed = (struct _keyed *) calloc(1, sizeof(struct _keyed));
496 
497  if (!graph->keyed) {
498  graph->keyed = keyed;
499  }
500  else {
501  keyed->next = graph->keyed;
502  graph->keyed = keyed;
503  }
504 
505  keyed->text = tmalloc(strlen(text) + 1);
506  strcpy(keyed->text, text);
507 
508  keyed->x = x;
509  keyed->y = y;
510 
511  keyed->colorindex = 1;
512 }
513 
514 
515 int
516 DevSwitch(devname)
517 
518 /* if given name of a hardcopy device, finds it and switches devices
519  * if given NULL, switches back
520  */
521 char *devname;
522 {
523  static DISPDEVICE *lastdev = NULL;
524 
525  if (devname != NULL) {
526  if (lastdev != NULL) {
527  internalerror("DevSwitch w/o changing back");
528  return (1);
529  }
530  lastdev = dispdev;
531  dispdev = FindDev(devname);
532  if (!strcmp(dispdev->name, "error")) {
533  internalerror("no hardcopy device");
534  dispdev = lastdev; /* undo */
535  lastdev = NULL;
536  return (1);
537  }
538  (*(dispdev->Init))();
539  }
540  else {
541  (*(dispdev->Close))();
542  dispdev = lastdev;
543  lastdev = NULL;
544  }
545  return (0);
546 }
547 
548 
549 int
551 
552 FILE *fp;
553 {
556 
557  request.option = char_option;
558  request.fp = fp;
559  DevInput(&request, &response);
560  return(response.reply.ch);
561 }
static char buf[MAXPROMPT]
Definition: arg.c:18
int cp_inchar()
#define BSIZE_SP
Definition: misc.h:19
int PS_Box()
int Plt5_Polygon()
int Plt5_Close()
Definition: plot5.c:82
int PS_Polygon()
int Plt5_Text()
DISPDEVICE * FindDev(char *name)
Definition: display.c:118
DISPDEVICE device[]
Definition: display.c:24
int DevSwitch(char *devname)
Definition: display.c:516
void DevArc(int x0, int y0, int radius, double theta1, double theta2)
Definition: display.c:278
int(* SetLinestyle)()
Definition: plotdev.h:83
int(* SetColor)()
Definition: plotdev.h:84
void DevGrHalt()
Definition: display.c:151
int PS_Halt()
Definition: postsc.c:117
int HP_Init()
Definition: hplaser.c:44
FILE * fp
Definition: ftegraph.h:188
int WP_Halt()
Definition: wp.c:135
int Plt5_Line()
char * strcpy()
void DevInit()
Definition: display.c:168
void DevDefineLinestyle(int linestyleid, int mask)
Definition: display.c:331
OPTION option
Definition: ftegraph.h:187
int(* DatatoScreen)()
Definition: plotdev.h:91
void DevClose()
Definition: display.c:218
void DevTitle(char *wintitle, char *icontitle)
Definition: display.c:242
static int nop()
Definition: display.c:469
int system(char *str)
Definition: libfuncs.c:85
static int nodev()
Definition: display.c:476
int HP_Halt()
Definition: hplaser.c:121
char * name
Definition: plotdev.h:60
internalerror(char *message)
Definition: error.c:91
int(* DefineLinestyle)()
Definition: plotdev.h:82
int(* Pixel)()
Definition: plotdev.h:74
void DevInput(REQUEST *request, RESPONSE *response)
Definition: display.c:438
void DevPixel(int x, int y)
Definition: display.c:251
void DevLine(int x1, int y1, int x2, int y2)
Definition: display.c:260
int Plt5_Halt()
Definition: plot5.c:90
Definition: cddefs.h:215
int ch
Definition: ftegraph.h:196
int PS_Update()
Definition: postsc.c:381
int HP_Close()
Definition: hplaser.c:113
Definition: plotdev.h:14
void DevUpdate()
Definition: display.c:359
union response::@11 reply
void DevHalt()
Definition: display.c:226
int Plt5_NewViewport()
int Plt5_SetLinestyle()
int(* Arc)()
Definition: plotdev.h:77
void DevSetColor(int colorid)
Definition: display.c:350
#define GR_SCED
Definition: ftegraph.h:23
int DevXterm(char *string)
Definition: display.c:135
char * calloc()
FILE * cp_err
Definition: help.c:101
int(* Init)()
Definition: plotdev.h:68
bool windows
Definition: plotdev.h:61
int PS_NewViewport()
char * tmalloc()
int WP_Polygon()
int DevNewViewport(GRAPH *pgraph)
Definition: display.c:209
int HP_Arc()
void DevDefineColor(int colorid, double red, double green, double blue)
Definition: display.c:321
int Plt5_Update()
Definition: plot5.c:230
char * kw_display
Definition: options.c:352
int WP_Close()
Definition: wp.c:127
void DevClear()
Definition: display.c:234
int WP_SetLinestyle()
void DevSetGhost(void(*callback)(), int x, int y)
Definition: display.c:307
#define NULL
Definition: spdefs.h:121
int graphtype
Definition: ftegraph.h:31
int(* Text)()
Definition: plotdev.h:79
int graphid
Definition: ftegraph.h:30
int Plt5_SetColor()
int WP_NewViewport()
int(* Line)()
Definition: plotdev.h:75
Definition: ftegraph.h:29
int(* Update)()
Definition: plotdev.h:85
DISPDEVICE * dispdev
Definition: display.c:112
void DevSetLinestyle(int linestyleid)
Definition: display.c:341
char * cp_display
Definition: main.c:44
int HP_Box()
int WP_Init()
Definition: wp.c:24
static int gen_Input()
int HP_Pixel()
#define mylog10(xx)
Definition: ftedefs.h:53
int PS_Close()
Definition: postsc.c:109
void DevBox(int x1, int y1, int x2, int y2)
Definition: display.c:269
int PS_SetColor()
int WP_Arc()
void PopGraphContext()
Definition: graphdb.c:270
int DestroyGraph()
void SaveText(GRAPH *graph, char *text, int x, int y)
Definition: display.c:487
int(* Input)()
Definition: plotdev.h:90
void DevDatatoScreen(GRAPH *graph, double x, double y, int *screenx, int *screeny)
Definition: display.c:414
OPTION option
Definition: ftegraph.h:192
int PS_Arc()
int HP_Line()
int HP_SetLinestyle()
int(* Close)()
Definition: plotdev.h:70
int(* SetGhost)()
Definition: plotdev.h:80
int PS_Pixel()
int PS_Init()
Definition: postsc.c:39
int(* Title)()
Definition: plotdev.h:73
int(* DefineColor)()
Definition: plotdev.h:81
int HP_Polygon()
int HP_Text()
GRAPH * currentgraph
Definition: graphdb.c:21
int HP_DefineLinestyle()
void DevPolygon(POLYGON *p)
Definition: display.c:288
int DevGetchar(FILE *fp)
Definition: display.c:550
int PS_SetLinestyle()
int(* Box)()
Definition: plotdev.h:76
int PS_Line()
static int gen_DatatoScreen()
int(* Halt)()
Definition: plotdev.h:71
char ErrorMessage[]
Definition: error.c:20
int Plt5_Box()
int WP_Text()
externalerror(char *message)
Definition: error.c:100
void DevText(char *text, int x, int y)
Definition: display.c:297
#define XtNumber(arr)
Definition: display.c:114
int WP_Line()
int Plt5_Arc()
int WP_Box()
int Plt5_Pixel()
int(* Clear)()
Definition: plotdev.h:72
int(* NewViewport)()
Definition: plotdev.h:69
int HP_NewViewport()
int Plt5_Init()
Definition: plot5.c:23
int PS_Text()
int WP_Pixel()
#define rnd(x)
Definition: ftegraph.h:203
int(* Polygon)()
Definition: plotdev.h:78