2000-04-27 22:03:57 +02:00
|
|
|
/**********
|
|
|
|
|
Copyright 1990 Regents of the University of California. All rights reserved.
|
|
|
|
|
**********/
|
|
|
|
|
|
2011-12-11 19:05:00 +01:00
|
|
|
#include "ngspice/ngspice.h"
|
|
|
|
|
#include "ngspice/graph.h"
|
|
|
|
|
#include "ngspice/ftedev.h"
|
2000-05-13 19:28:16 +02:00
|
|
|
|
2000-04-27 22:03:57 +02:00
|
|
|
#include "plot5.h"
|
2005-05-29 03:05:33 +02:00
|
|
|
#include "graf.h"
|
2011-12-11 19:05:00 +01:00
|
|
|
#include "ngspice/fteext.h"
|
2000-04-27 22:03:57 +02:00
|
|
|
|
2012-09-20 20:30:53 +02:00
|
|
|
|
2000-04-27 22:03:57 +02:00
|
|
|
static FILE *plotfile;
|
|
|
|
|
|
2012-09-19 20:16:27 +02:00
|
|
|
#define putsi(a) \
|
|
|
|
|
do { \
|
|
|
|
|
putc((char) (a), plotfile); \
|
|
|
|
|
putc((char) ((a) >> 8), plotfile); \
|
|
|
|
|
} while(0)
|
|
|
|
|
|
2000-04-27 22:03:57 +02:00
|
|
|
|
|
|
|
|
#define SOLID 0
|
2012-09-20 20:30:53 +02:00
|
|
|
|
|
|
|
|
static char *linestyle[] = {
|
|
|
|
|
"solid", "dotted", "longdashed", "shortdashed", "dotdashed" };
|
|
|
|
|
|
2000-04-27 22:03:57 +02:00
|
|
|
static int currentlinestyle = SOLID;
|
|
|
|
|
|
2012-09-20 20:30:53 +02:00
|
|
|
|
2019-12-15 07:17:04 +01:00
|
|
|
int Plt5_Init(void)
|
2000-04-27 22:03:57 +02:00
|
|
|
{
|
|
|
|
|
dispdev->numlinestyles = 4;
|
|
|
|
|
dispdev->numcolors = 2;
|
|
|
|
|
|
|
|
|
|
/* arbitrary */
|
|
|
|
|
dispdev->width = 1000;
|
|
|
|
|
dispdev->height = 1000;
|
|
|
|
|
|
2019-12-15 07:17:04 +01:00
|
|
|
return 0;
|
2000-04-27 22:03:57 +02:00
|
|
|
}
|
|
|
|
|
|
2012-09-20 20:30:53 +02:00
|
|
|
|
2019-12-15 07:17:04 +01:00
|
|
|
int Plt5_NewViewport(GRAPH *graph)
|
2000-04-27 22:03:57 +02:00
|
|
|
{
|
2010-11-19 19:54:40 +01:00
|
|
|
if ((plotfile = fopen((char*) graph->devdep, "w")) == NULL) {
|
2019-12-15 07:17:04 +01:00
|
|
|
perror((char *) graph->devdep);
|
|
|
|
|
free(graph->devdep);
|
2012-09-20 20:30:53 +02:00
|
|
|
graph->devdep = NULL;
|
2019-12-15 07:17:04 +01:00
|
|
|
graph->n_byte_devdep = 0;
|
|
|
|
|
return 1;
|
2000-04-27 22:03:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (graph->absolute.width) {
|
|
|
|
|
|
2012-09-20 20:30:53 +02:00
|
|
|
/* hardcopying from the scree,
|
|
|
|
|
ie, we are passed a copy of an existing graph */
|
|
|
|
|
putc('s', plotfile);
|
|
|
|
|
putsi(0);
|
|
|
|
|
putsi(0);
|
|
|
|
|
putsi(graph->absolute.width);
|
|
|
|
|
putsi(graph->absolute.height);
|
2000-04-27 22:03:57 +02:00
|
|
|
|
2012-09-20 20:30:53 +02:00
|
|
|
/* re-scale linestyles */
|
|
|
|
|
gr_relinestyle(graph);
|
2000-04-27 22:03:57 +02:00
|
|
|
|
2019-12-15 07:17:04 +01:00
|
|
|
}
|
|
|
|
|
else {
|
2012-09-20 20:30:53 +02:00
|
|
|
/* scale space */
|
|
|
|
|
putc('s', plotfile);
|
|
|
|
|
putsi(0);
|
|
|
|
|
putsi(0);
|
|
|
|
|
putsi(dispdev->width);
|
|
|
|
|
putsi(dispdev->height);
|
2000-04-27 22:03:57 +02:00
|
|
|
|
2012-09-20 20:30:53 +02:00
|
|
|
/* reasonable values, used in gr_ for placement */
|
|
|
|
|
graph->fontwidth = 12;
|
|
|
|
|
graph->fontheight = 24;
|
2000-04-27 22:03:57 +02:00
|
|
|
|
2012-09-20 20:30:53 +02:00
|
|
|
graph->absolute.width = dispdev->width;
|
|
|
|
|
graph->absolute.height = dispdev->height;
|
2000-04-27 22:03:57 +02:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* set to NULL so graphdb doesn't incorrectly de-allocate it */
|
2010-10-24 15:15:35 +02:00
|
|
|
graph->devdep = NULL;
|
2019-12-15 07:17:04 +01:00
|
|
|
graph->n_byte_devdep = 0;
|
2000-04-27 22:03:57 +02:00
|
|
|
|
2019-12-15 07:17:04 +01:00
|
|
|
return 0;
|
2000-04-27 22:03:57 +02:00
|
|
|
}
|
|
|
|
|
|
2012-09-20 20:30:53 +02:00
|
|
|
|
2019-12-15 07:17:04 +01:00
|
|
|
int Plt5_Close(void)
|
2000-04-27 22:03:57 +02:00
|
|
|
{
|
|
|
|
|
/* in case Plt5_Close is called as part of an abort,
|
2012-09-20 20:30:53 +02:00
|
|
|
w/o having reached Plt5_NewViewport */
|
2000-04-27 22:03:57 +02:00
|
|
|
if (plotfile)
|
|
|
|
|
fclose(plotfile);
|
2012-09-20 20:30:53 +02:00
|
|
|
|
2005-05-30 22:28:29 +02:00
|
|
|
return 0;
|
2000-04-27 22:03:57 +02:00
|
|
|
}
|
|
|
|
|
|
2012-09-20 20:30:53 +02:00
|
|
|
|
2019-12-15 07:17:04 +01:00
|
|
|
int Plt5_Clear(void)
|
2000-04-27 22:03:57 +02:00
|
|
|
{
|
|
|
|
|
/* do nothing */
|
2005-05-30 22:28:29 +02:00
|
|
|
return 0;
|
2000-04-27 22:03:57 +02:00
|
|
|
}
|
|
|
|
|
|
2012-09-20 20:30:53 +02:00
|
|
|
|
2017-10-06 22:54:42 +02:00
|
|
|
int
|
|
|
|
|
Plt5_DrawLine(int x1, int y1, int x2, int y2, bool isgrid)
|
2000-04-27 22:03:57 +02:00
|
|
|
{
|
2017-10-06 22:54:42 +02:00
|
|
|
NG_IGNORE(isgrid);
|
|
|
|
|
|
2000-04-27 22:03:57 +02:00
|
|
|
putc('l', plotfile);
|
|
|
|
|
putsi(x1);
|
|
|
|
|
putsi(y1);
|
|
|
|
|
putsi(x2);
|
|
|
|
|
putsi(y2);
|
2012-09-20 20:30:53 +02:00
|
|
|
|
2005-05-30 22:28:29 +02:00
|
|
|
return 0;
|
2000-04-27 22:03:57 +02:00
|
|
|
}
|
|
|
|
|
|
2012-09-20 20:30:53 +02:00
|
|
|
|
2019-12-15 07:17:04 +01:00
|
|
|
int Plt5_Arc(int xc, int yc, int radius, double theta, double delta_theta)
|
2000-04-27 22:03:57 +02:00
|
|
|
{
|
2012-09-20 20:30:53 +02:00
|
|
|
int x0, y0, x1, y1;
|
2010-08-02 18:31:35 +02:00
|
|
|
|
2012-09-20 20:30:53 +02:00
|
|
|
if (delta_theta < 0) {
|
2010-08-02 18:31:35 +02:00
|
|
|
theta += delta_theta;
|
|
|
|
|
delta_theta = -delta_theta;
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-20 20:30:53 +02:00
|
|
|
if ((2*M_PI - delta_theta)*radius < 0.5) {
|
2010-08-02 18:31:35 +02:00
|
|
|
|
2012-09-20 20:30:53 +02:00
|
|
|
putc('c', plotfile);
|
|
|
|
|
putsi(xc);
|
|
|
|
|
putsi(yc);
|
|
|
|
|
putsi(radius);
|
2010-08-02 18:31:35 +02:00
|
|
|
|
2012-09-20 20:30:53 +02:00
|
|
|
return 0;
|
2010-08-02 18:31:35 +02:00
|
|
|
}
|
|
|
|
|
|
2012-09-20 20:30:53 +02:00
|
|
|
while (delta_theta*radius > 0.5) {
|
2010-08-02 18:31:35 +02:00
|
|
|
|
|
|
|
|
double delta_phi = M_PI/2;
|
|
|
|
|
|
2012-09-20 20:30:53 +02:00
|
|
|
if (delta_phi > delta_theta)
|
2010-08-02 18:31:35 +02:00
|
|
|
delta_phi = delta_theta;
|
|
|
|
|
|
2011-06-11 19:07:38 +02:00
|
|
|
x0 = xc + (int)(radius * cos(theta));
|
|
|
|
|
y0 = yc + (int)(radius * sin(theta));
|
|
|
|
|
x1 = xc + (int)(radius * cos(theta + delta_phi));
|
|
|
|
|
y1 = yc + (int)(radius * sin(theta + delta_phi));
|
2010-08-02 18:31:35 +02:00
|
|
|
|
|
|
|
|
putc('a', plotfile);
|
|
|
|
|
putsi(xc);
|
|
|
|
|
putsi(yc);
|
|
|
|
|
putsi(x0);
|
|
|
|
|
putsi(y0);
|
|
|
|
|
putsi(x1);
|
|
|
|
|
putsi(y1);
|
|
|
|
|
|
|
|
|
|
delta_theta -= delta_phi;
|
|
|
|
|
theta += delta_phi;
|
|
|
|
|
}
|
2000-04-27 22:03:57 +02:00
|
|
|
|
2005-05-30 22:28:29 +02:00
|
|
|
return 0;
|
2000-04-27 22:03:57 +02:00
|
|
|
}
|
|
|
|
|
|
2012-09-20 20:30:53 +02:00
|
|
|
|
2019-12-15 07:17:04 +01:00
|
|
|
int Plt5_Text(char *text, int x, int y, int angle)
|
2000-04-27 22:03:57 +02:00
|
|
|
{
|
|
|
|
|
int savedlstyle;
|
2018-11-01 22:50:54 +01:00
|
|
|
NG_IGNORE(angle);
|
2000-04-27 22:03:57 +02:00
|
|
|
|
|
|
|
|
/* set linestyle to solid
|
2012-09-20 20:30:53 +02:00
|
|
|
or may get funny color text on some plotters */
|
2000-04-27 22:03:57 +02:00
|
|
|
savedlstyle = currentlinestyle;
|
|
|
|
|
Plt5_SetLinestyle(SOLID);
|
|
|
|
|
|
|
|
|
|
/* move to (x, y) */
|
|
|
|
|
putc('m', plotfile);
|
|
|
|
|
putsi(x);
|
|
|
|
|
putsi(y);
|
|
|
|
|
|
|
|
|
|
/* use the label option */
|
|
|
|
|
fprintf(plotfile, "t%s\n", text);
|
|
|
|
|
|
|
|
|
|
/* restore old linestyle */
|
|
|
|
|
Plt5_SetLinestyle(savedlstyle);
|
2012-09-20 20:30:53 +02:00
|
|
|
|
2005-05-30 22:28:29 +02:00
|
|
|
return 0;
|
2000-04-27 22:03:57 +02:00
|
|
|
}
|
|
|
|
|
|
2012-09-20 20:30:53 +02:00
|
|
|
|
2019-12-15 07:17:04 +01:00
|
|
|
int Plt5_SetLinestyle(int linestyleid)
|
2000-04-27 22:03:57 +02:00
|
|
|
{
|
|
|
|
|
if (linestyleid < 0 || linestyleid > dispdev->numlinestyles) {
|
2012-09-20 20:30:53 +02:00
|
|
|
internalerror("bad linestyleid");
|
|
|
|
|
return 0;
|
2000-04-27 22:03:57 +02:00
|
|
|
}
|
|
|
|
|
putc('f', plotfile);
|
|
|
|
|
fprintf(plotfile, "%s\n", linestyle[linestyleid]);
|
|
|
|
|
currentlinestyle = linestyleid;
|
2012-09-20 20:30:53 +02:00
|
|
|
|
2000-04-27 22:03:57 +02:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-20 20:30:53 +02:00
|
|
|
|
2000-04-27 22:03:57 +02:00
|
|
|
/* ARGSUSED */
|
2019-12-15 07:17:04 +01:00
|
|
|
int Plt5_SetColor(int colorid)
|
2000-04-27 22:03:57 +02:00
|
|
|
{
|
2010-11-16 21:38:24 +01:00
|
|
|
NG_IGNORE(colorid);
|
2000-04-27 22:03:57 +02:00
|
|
|
|
|
|
|
|
/* do nothing */
|
2005-05-30 22:28:29 +02:00
|
|
|
return 0;
|
2000-04-27 22:03:57 +02:00
|
|
|
}
|
|
|
|
|
|
2012-09-20 20:30:53 +02:00
|
|
|
|
2019-12-15 07:17:04 +01:00
|
|
|
int Plt5_Update(void)
|
2000-04-27 22:03:57 +02:00
|
|
|
{
|
|
|
|
|
fflush(plotfile);
|
2005-05-30 22:28:29 +02:00
|
|
|
return 0;
|
2000-04-27 22:03:57 +02:00
|
|
|
}
|