Jspice3
display.c File Reference
#include "spice.h"
#include "plotdefs.h"
Include dependency graph for display.c:

Go to the source code of this file.

Macros

#define XtNumber(arr)   (sizeof(arr) / sizeof(arr[0]))
 

Functions

static int gen_DatatoScreen ()
 
static int gen_Input ()
 
static int nodev ()
 
static int nop ()
 
DISPDEVICEFindDev (char *name)
 
int DevXterm (char *string)
 
void DevGrHalt ()
 
void DevInit ()
 
int DevNewViewport (GRAPH *pgraph)
 
void DevClose ()
 
void DevHalt ()
 
void DevClear ()
 
void DevTitle (char *wintitle, char *icontitle)
 
void DevPixel (int x, int y)
 
void DevLine (int x1, int y1, int x2, int y2)
 
void DevBox (int x1, int y1, int x2, int y2)
 
void DevArc (int x0, int y0, int radius, double theta1, double theta2)
 
void DevPolygon (POLYGON *p)
 
void DevText (char *text, int x, int y)
 
void DevSetGhost (void(*callback)(), int x, int y)
 
void DevDefineColor (int colorid, double red, double green, double blue)
 
void DevDefineLinestyle (int linestyleid, int mask)
 
void DevSetLinestyle (int linestyleid)
 
void DevSetColor (int colorid)
 
void DevUpdate ()
 
static int gen_DatatoScreen (GRAPH *graph, double x, double y, int *screenx, int *screeny)
 
void DevDatatoScreen (GRAPH *graph, double x, double y, int *screenx, int *screeny)
 
void DevInput (REQUEST *request, RESPONSE *response)
 
static int gen_Input (REQUEST *request, RESPONSE *response)
 
void SaveText (GRAPH *graph, char *text, int x, int y)
 
int DevSwitch (char *devname)
 
int DevGetchar (FILE *fp)
 

Variables

DISPDEVICE device []
 
DISPDEVICEdispdev
 

Macro Definition Documentation

#define XtNumber (   arr)    (sizeof(arr) / sizeof(arr[0]))

Definition at line 114 of file display.c.

Function Documentation

void DevArc ( int  x0,
int  y0,
int  radius,
double  theta1,
double  theta2 
)

Definition at line 278 of file display.c.

282 {
283  (void)(*(dispdev->Arc))(x0, y0, radius, theta1, theta2);
284 }
int(* Arc)()
Definition: plotdev.h:77
DISPDEVICE * dispdev
Definition: display.c:112
void DevBox ( int  x1,
int  y1,
int  x2,
int  y2 
)

Definition at line 269 of file display.c.

272 {
273  (void)(*(dispdev->Box))(x1, y1, x2, y2);
274 }
DISPDEVICE * dispdev
Definition: display.c:112
int(* Box)()
Definition: plotdev.h:76
void DevClear ( )

Definition at line 234 of file display.c.

236 {
237  (void)(*(dispdev->Clear))();
238 }
DISPDEVICE * dispdev
Definition: display.c:112
int(* Clear)()
Definition: plotdev.h:72
void DevClose ( )

Definition at line 218 of file display.c.

220 {
221  (void)(*(dispdev->Close))();
222 }
DISPDEVICE * dispdev
Definition: display.c:112
int(* Close)()
Definition: plotdev.h:70
void DevDatatoScreen ( GRAPH graph,
double  x,
double  y,
int *  screenx,
int *  screeny 
)

Definition at line 414 of file display.c.

419 {
420  (void)(*(dispdev->DatatoScreen))(graph, x, y, screenx, screeny);
421 }
int(* DatatoScreen)()
Definition: plotdev.h:91
DISPDEVICE * dispdev
Definition: display.c:112
void DevDefineColor ( int  colorid,
double  red,
double  green,
double  blue 
)

Definition at line 321 of file display.c.

325 {
326  (void)(*(dispdev->DefineColor))(colorid, red, green, blue);
327 }
DISPDEVICE * dispdev
Definition: display.c:112
int(* DefineColor)()
Definition: plotdev.h:81
void DevDefineLinestyle ( int  linestyleid,
int  mask 
)

Definition at line 331 of file display.c.

335 {
336  (void)(*(dispdev->DefineLinestyle))(linestyleid, mask);
337 }
int(* DefineLinestyle)()
Definition: plotdev.h:82
DISPDEVICE * dispdev
Definition: display.c:112
int DevGetchar ( FILE *  fp)

Definition at line 550 of file display.c.

553 {
556 
557  request.option = char_option;
558  request.fp = fp;
559  DevInput(&request, &response);
560  return(response.reply.ch);
561 }
FILE * fp
Definition: ftegraph.h:188
OPTION option
Definition: ftegraph.h:187
void DevInput(REQUEST *request, RESPONSE *response)
Definition: display.c:438
int ch
Definition: ftegraph.h:196
union response::@11 reply
void DevGrHalt ( )

Definition at line 151 of file display.c.

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 }
void DevHalt()
Definition: display.c:226
#define GR_SCED
Definition: ftegraph.h:23
bool windows
Definition: plotdev.h:61
int graphtype
Definition: ftegraph.h:31
int graphid
Definition: ftegraph.h:30
DISPDEVICE * dispdev
Definition: display.c:112
void PopGraphContext()
Definition: graphdb.c:270
int DestroyGraph()
GRAPH * currentgraph
Definition: graphdb.c:21
void DevHalt ( )

Definition at line 226 of file display.c.

228 {
229  (void)(*(dispdev->Halt))();
230 }
DISPDEVICE * dispdev
Definition: display.c:112
int(* Halt)()
Definition: plotdev.h:71
void DevInit ( )

Definition at line 168 of file display.c.

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 }
static char buf[MAXPROMPT]
Definition: arg.c:18
DISPDEVICE * FindDev(char *name)
Definition: display.c:118
FILE * cp_err
Definition: help.c:101
int(* Init)()
Definition: plotdev.h:68
char * kw_display
Definition: options.c:352
DISPDEVICE * dispdev
Definition: display.c:112
char * cp_display
Definition: main.c:44
externalerror(char *message)
Definition: error.c:100
void DevInput ( REQUEST request,
RESPONSE response 
)

Definition at line 438 of file display.c.

442 {
443  (void)(*(dispdev->Input))(request, response);
444 }
DISPDEVICE * dispdev
Definition: display.c:112
int(* Input)()
Definition: plotdev.h:90
void DevLine ( int  x1,
int  y1,
int  x2,
int  y2 
)

Definition at line 260 of file display.c.

263 {
264  (void)(*(dispdev->Line))(x1, y1, x2, y2);
265 }
int(* Line)()
Definition: plotdev.h:75
DISPDEVICE * dispdev
Definition: display.c:112
int DevNewViewport ( GRAPH pgraph)

Definition at line 209 of file display.c.

212 {
213  return (*(dispdev->NewViewport))(pgraph);
214 }
DISPDEVICE * dispdev
Definition: display.c:112
int(* NewViewport)()
Definition: plotdev.h:69
void DevPixel ( int  x,
int  y 
)

Definition at line 251 of file display.c.

254 {
255  (void)(*(dispdev->Pixel))(x, y);
256 }
int(* Pixel)()
Definition: plotdev.h:74
DISPDEVICE * dispdev
Definition: display.c:112
void DevPolygon ( POLYGON p)

Definition at line 288 of file display.c.

291 {
292  (void)(*(dispdev->Polygon))(p);
293 }
DISPDEVICE * dispdev
Definition: display.c:112
int(* Polygon)()
Definition: plotdev.h:78
void DevSetColor ( int  colorid)

Definition at line 350 of file display.c.

353 {
354  (void)(*(dispdev->SetColor))(colorid);
355 }
int(* SetColor)()
Definition: plotdev.h:84
DISPDEVICE * dispdev
Definition: display.c:112
void DevSetGhost ( void (*)()  callback,
int  x,
int  y 
)

Definition at line 307 of file display.c.

315 {
316  (void)(*(dispdev->SetGhost))(callback, x, y);
317 }
DISPDEVICE * dispdev
Definition: display.c:112
int(* SetGhost)()
Definition: plotdev.h:80
void DevSetLinestyle ( int  linestyleid)

Definition at line 341 of file display.c.

344 {
345  (void)(*(dispdev->SetLinestyle))(linestyleid);
346 }
int(* SetLinestyle)()
Definition: plotdev.h:83
DISPDEVICE * dispdev
Definition: display.c:112
int DevSwitch ( char *  devname)

Definition at line 516 of file display.c.

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 }
DISPDEVICE * FindDev(char *name)
Definition: display.c:118
char * name
Definition: plotdev.h:60
internalerror(char *message)
Definition: error.c:91
int(* Init)()
Definition: plotdev.h:68
#define NULL
Definition: spdefs.h:121
DISPDEVICE * dispdev
Definition: display.c:112
int(* Close)()
Definition: plotdev.h:70
void DevText ( char *  text,
int  x,
int  y 
)

Definition at line 297 of file display.c.

301 {
302  (void)(*(dispdev->Text))(text, x, y);
303 }
int(* Text)()
Definition: plotdev.h:79
DISPDEVICE * dispdev
Definition: display.c:112
void DevTitle ( char *  wintitle,
char *  icontitle 
)

Definition at line 242 of file display.c.

245 {
246  (void)(*(dispdev->Title))(wintitle,icontitle);
247 }
DISPDEVICE * dispdev
Definition: display.c:112
int(* Title)()
Definition: plotdev.h:73
void DevUpdate ( )

Definition at line 359 of file display.c.

360 {
361  (void)(*(dispdev->Update))();
362 }
int(* Update)()
Definition: plotdev.h:85
DISPDEVICE * dispdev
Definition: display.c:112
int DevXterm ( char *  string)

Definition at line 135 of file display.c.

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 }
static char buf[MAXPROMPT]
Definition: arg.c:18
#define BSIZE_SP
Definition: misc.h:19
int system(char *str)
Definition: libfuncs.c:85
bool windows
Definition: plotdev.h:61
DISPDEVICE * dispdev
Definition: display.c:112
DISPDEVICE* FindDev ( char *  name)

Definition at line 118 of file display.c.

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 }
DISPDEVICE device[]
Definition: display.c:24
internalerror(char *message)
Definition: error.c:91
char ErrorMessage[]
Definition: error.c:20
#define XtNumber(arr)
Definition: display.c:114
static int gen_DatatoScreen ( )
static
static int gen_DatatoScreen ( GRAPH graph,
double  x,
double  y,
int *  screenx,
int *  screeny 
)
static

Definition at line 369 of file display.c.

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 }
double aspectratiox
Definition: ftegraph.h:79
double ymin
Definition: ftegraph.h:58
int height
Definition: ftegraph.h:45
struct graph::@3 datawindow
int viewportyoff
Definition: ftegraph.h:48
double aspectratioy
Definition: ftegraph.h:79
int viewportxoff
Definition: ftegraph.h:47
GRIDTYPE gridtype
Definition: ftegraph.h:86
#define mylog10(xx)
Definition: ftedefs.h:53
int width
Definition: ftegraph.h:45
double xmax
Definition: ftegraph.h:58
struct graph::@4 grid
struct graph::@1 viewport
double ymax
Definition: ftegraph.h:58
double xmin
Definition: ftegraph.h:58
#define rnd(x)
Definition: ftegraph.h:203
static int gen_Input ( )
static
static int gen_Input ( REQUEST request,
RESPONSE response 
)
static

Definition at line 448 of file display.c.

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 }
int cp_inchar()
FILE * fp
Definition: ftegraph.h:188
OPTION option
Definition: ftegraph.h:187
int ch
Definition: ftegraph.h:196
union response::@11 reply
OPTION option
Definition: ftegraph.h:192
static int nodev ( )
static

Definition at line 476 of file display.c.

477 {
478  sprintf(ErrorMessage,
479  "This operation is not defined for display type %s.",
480  dispdev->name);
482  return (1);
483 }
char * name
Definition: plotdev.h:60
internalerror(char *message)
Definition: error.c:91
DISPDEVICE * dispdev
Definition: display.c:112
char ErrorMessage[]
Definition: error.c:20
static int nop ( )
static

Definition at line 469 of file display.c.

470 {
471  return (1); /* so NewViewport will fail */
472 }
void SaveText ( GRAPH graph,
char *  text,
int  x,
int  y 
)

Definition at line 487 of file display.c.

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 }
char * strcpy()
struct _keyed * next
Definition: ftegraph.h:129
char * calloc()
char * tmalloc()
struct graph::_keyed * keyed
char * text
Definition: ftegraph.h:126

Variable Documentation

DISPDEVICE device[]

Definition at line 24 of file display.c.

DISPDEVICE* dispdev

Definition at line 112 of file display.c.