Browse Source

Add parameter 'isgrid' to plotting of arcs.

Smithgrid and polar plots could not discern between xgridwidth and
xbrushwidth. This is now available, similar to straight line plotting.
Tested also for PS and SVG.
pre-master-46
Holger Vogt 4 years ago
parent
commit
4f82a24df2
  1. 4
      src/frontend/display.c
  2. 2
      src/frontend/display.h
  3. 4
      src/frontend/hpgl.c
  4. 32
      src/frontend/plotting/grid.c
  5. 3
      src/frontend/plotting/plot5.c
  6. 12
      src/frontend/plotting/x11.c
  7. 8
      src/frontend/postsc.c
  8. 8
      src/frontend/svg.c
  9. 7
      src/frontend/wdisp/windisp.c
  10. 2
      src/include/ngspice/ftedev.h

4
src/frontend/display.c

@ -249,9 +249,9 @@ DevDrawLine(int x1, int y1, int x2, int y2, bool isgrid)
void void
DevDrawArc(int x0, int y0, int radius, double theta, double delta_theta)
DevDrawArc(int x0, int y0, int radius, double theta, double delta_theta, bool isgrid)
{ {
dispdev->DrawArc (x0, y0, radius, theta, delta_theta);
dispdev->DrawArc (x0, y0, radius, theta, delta_theta, isgrid);
} }

2
src/frontend/display.h

@ -18,7 +18,7 @@ int NewViewport(GRAPH *pgraph);
void DevClose(void); void DevClose(void);
void DevClear(void); void DevClear(void);
void DevDrawLine(int x1, int y1, int x2, int y2, bool isgrid); void DevDrawLine(int x1, int y1, int x2, int y2, bool isgrid);
void DevDrawArc(int x0, int y0, int radius, double theta, double delta_theta);
void DevDrawArc(int x0, int y0, int radius, double theta, double delta_theta, bool isgrid);
void DevDrawText(const char *text, int x, int y, int angle); void DevDrawText(const char *text, int x, int y, int angle);
void DefineColor(int colorid, double red, double green, double blue); void DefineColor(int colorid, double red, double green, double blue);
void DefineLinestyle(int linestyleid, int mask); void DefineLinestyle(int linestyleid, int mask);

4
src/frontend/hpgl.c

@ -230,8 +230,10 @@ GL_DrawLine(int x1, int y1, int x2, int y2, bool isgrid)
/* ARGSUSED */ /* ARGSUSED */
int GL_Arc(int x0, int y0, int r, double theta, double delta_theta)
int GL_Arc(int x0, int y0, int r, double theta, double delta_theta, bool isgrid)
{ {
NG_IGNORE(isgrid);
int x1, y1, angle; int x1, y1, angle;
x1 = x0 + (int)(r * cos(theta)); x1 = x0 + (int)(r * cos(theta));

32
src/frontend/plotting/grid.c

@ -55,9 +55,9 @@ static void smithgrid(GRAPH *graph);
static void drawsmithgrid(GRAPH *graph); static void drawsmithgrid(GRAPH *graph);
static void arcset(GRAPH *graph, double rad, double prevrad, double irad, double iprevrad, static void arcset(GRAPH *graph, double rad, double prevrad, double irad, double iprevrad,
double radoff, int maxrad, int centx, int centy, int xoffset, int yoffset, double radoff, int maxrad, int centx, int centy, int xoffset, int yoffset,
char *plab, char *nlab, int pdeg, int ndeg, int pxmin, int pxmax);
char *plab, char *nlab, int pdeg, int ndeg, int pxmin, int pxmax, bool isgrid);
static double cliparc(double cx, double cy, double rad, double start, double end, int iclipx, static double cliparc(double cx, double cy, double rad, double start, double end, int iclipx,
int iclipy, int icliprad, int flag);
int iclipy, int icliprad, int flag, bool isgrid);
static void drawlingrid(GRAPH *graph, char *units, int spacing, int nsp, double dst, double lmt, static void drawlingrid(GRAPH *graph, char *units, int spacing, int nsp, double dst, double lmt,
double hmt, bool onedec, int mult, double mag, int digits, Axis axis); double hmt, bool onedec, int mult, double mag, int digits, Axis axis);
@ -1078,7 +1078,7 @@ drawpolargrid(GRAPH *graph)
DevDrawArc(graph->grid.xaxis.circular.center, DevDrawArc(graph->grid.xaxis.circular.center,
graph->grid.yaxis.circular.center, graph->grid.yaxis.circular.center,
graph->grid.xaxis.circular.radius, graph->grid.xaxis.circular.radius,
0.0, 2*M_PI);
0.0, 2*M_PI, TRUE);
SetLinestyle(1); SetLinestyle(1);
/* Now draw the circles. */ /* Now draw the circles. */
@ -1092,7 +1092,7 @@ drawpolargrid(GRAPH *graph)
(double) relrad, 0.0, 2*M_PI, (double) relrad, 0.0, 2*M_PI,
graph->grid.xaxis.circular.center, graph->grid.xaxis.circular.center,
graph->grid.yaxis.circular.center, graph->grid.yaxis.circular.center,
graph->grid.xaxis.circular.radius, 0);
graph->grid.xaxis.circular.radius, 0, TRUE);
/* Toss on the label */ /* Toss on the label */
if (relcx || relcy) if (relcx || relcy)
theta = atan2((double) relcy, (double) relcx); theta = atan2((double) relcy, (double) relcx);
@ -1476,7 +1476,7 @@ drawsmithgrid(GRAPH *graph)
(int) (0.5 + RAD_TO_DEG * (M_PI - dphi[k])), (int) (0.5 + RAD_TO_DEG * (M_PI - dphi[k])),
(int) (0.5 + RAD_TO_DEG * (M_PI + dphi[k])), (int) (0.5 + RAD_TO_DEG * (M_PI + dphi[k])),
gr_xcenter - zheight, gr_xcenter - zheight,
gr_xcenter + zheight);
gr_xcenter + zheight, TRUE);
} }
if (mag == 20) { if (mag == 20) {
fprintf(cp_err, "smithgrid: Internal Error: screwed up\n"); fprintf(cp_err, "smithgrid: Internal Error: screwed up\n");
@ -1485,7 +1485,7 @@ drawsmithgrid(GRAPH *graph)
SetLinestyle(0); SetLinestyle(0);
DevDrawArc(gr_xcenter, gr_ycenter, gr_radius, 0.0, 2*M_PI);
DevDrawArc(gr_xcenter, gr_ycenter, gr_radius, 0.0, 2*M_PI, TRUE);
/* /*
* if ((xoff > - gr_radius) && (xoff < gr_radius)) { * if ((xoff > - gr_radius) && (xoff < gr_radius)) {
@ -1529,7 +1529,7 @@ drawsmithgrid(GRAPH *graph)
*/ */
static void static void
arcset(GRAPH *graph, double rad, double prevrad, double irad, double iprevrad, double radoff, int maxrad, int centx, int centy, int xoffset, int yoffset, char *plab, char *nlab, int pdeg, int ndeg, int pxmin, int pxmax)
arcset(GRAPH *graph, double rad, double prevrad, double irad, double iprevrad, double radoff, int maxrad, int centx, int centy, int xoffset, int yoffset, char *plab, char *nlab, int pdeg, int ndeg, int pxmin, int pxmax, bool isgrid)
{ {
double aclip; double aclip;
double angle = atan2((double) iprevrad, (double) rad); double angle = atan2((double) iprevrad, (double) rad);
@ -1545,21 +1545,21 @@ arcset(GRAPH *graph, double rad, double prevrad, double irad, double iprevrad, d
cliparc((double) (centx + xoffset + radoff - rad), cliparc((double) (centx + xoffset + radoff - rad),
(double) (centy + yoffset), rad, 2*angle, (double) (centy + yoffset), rad, 2*angle,
2 * M_PI - 2 * angle, centx, centy, maxrad, 0);
2 * M_PI - 2 * angle, centx, centy, maxrad, 0, isgrid);
/* These circles are not part of the smith chart /* These circles are not part of the smith chart
* Let's draw them anyway * Let's draw them anyway
*/ */
cliparc((double) (centx + xoffset + radoff + rad), cliparc((double) (centx + xoffset + radoff + rad),
(double) (centy + yoffset), rad, M_PI + 2 * angle, (double) (centy + yoffset), rad, M_PI + 2 * angle,
M_PI - 2 * angle, centx, centy, maxrad, 0);
M_PI - 2 * angle, centx, centy, maxrad, 0, isgrid);
/* Draw the upper and lower circles. */ /* Draw the upper and lower circles. */
SetColor(19); SetColor(19);
aclip = cliparc((double) (centx + xoffset + radoff), aclip = cliparc((double) (centx + xoffset + radoff),
(double) (centy + yoffset + irad), irad, (double) (centy + yoffset + irad), irad,
(double) (M_PI * 1.5 + 2 * iangle), (double) (M_PI * 1.5 + 2 * iangle),
(double) (M_PI * 1.5 - 2 * iangle), centx, centy, maxrad, 1);
(double) (M_PI * 1.5 - 2 * iangle), centx, centy, maxrad, 1, isgrid);
if ((aclip > M_PI / 180) && (pdeg > 1)) { if ((aclip > M_PI / 180) && (pdeg > 1)) {
xlab = (int)(centx + xoffset + radoff + irad * cos(aclip)); xlab = (int)(centx + xoffset + radoff + irad * cos(aclip));
ylab = (int)(centy + yoffset + irad * (1 + sin(aclip))); ylab = (int)(centy + yoffset + irad * (1 + sin(aclip)));
@ -1579,7 +1579,7 @@ arcset(GRAPH *graph, double rad, double prevrad, double irad, double iprevrad, d
(double) (centy + yoffset - irad), irad, (double) (centy + yoffset - irad), irad,
(double) (M_PI / 2 + 2 * iangle), (double) (M_PI / 2 + 2 * iangle),
(double) (M_PI / 2 - 2 * iangle), centx, centy, maxrad, (double) (M_PI / 2 - 2 * iangle), centx, centy, maxrad,
(iangle == 0) ? 2 : 0);
(iangle == 0) ? 2 : 0, isgrid);
if ((aclip >= 0 && aclip < 2*M_PI - M_PI/180) && (pdeg < 359)) { if ((aclip >= 0 && aclip < 2*M_PI - M_PI/180) && (pdeg < 359)) {
xlab = (int)(centx + xoffset + radoff + irad * cos(aclip)); xlab = (int)(centx + xoffset + radoff + irad * cos(aclip));
ylab = (int)(centy + yoffset + irad * (sin(aclip) - 1)); ylab = (int)(centy + yoffset + irad * (sin(aclip) - 1));
@ -1616,7 +1616,7 @@ arcset(GRAPH *graph, double rad, double prevrad, double irad, double iprevrad, d
*/ */
static double static double
cliparc(double cx, double cy, double rad, double start, double end, int iclipx, int iclipy, int icliprad, int flag)
cliparc(double cx, double cy, double rad, double start, double end, int iclipx, int iclipy, int icliprad, int flag, bool isgrid)
{ {
double clipx, clipy, cliprad; double clipx, clipy, cliprad;
double sclip = 0.0, eclip = 0.0; double sclip = 0.0, eclip = 0.0;
@ -1635,7 +1635,7 @@ cliparc(double cx, double cy, double rad, double start, double end, int iclipx,
return (-1); return (-1);
if (dist + rad < cliprad) { if (dist + rad < cliprad) {
/* The arc is entirely in the boundary. */ /* The arc is entirely in the boundary. */
DevDrawArc((int)cx, (int)cy, (int)rad, start, end-start);
DevDrawArc((int)cx, (int)cy, (int)rad, start, end-start, isgrid);
return (flag?start:end); return (flag?start:end);
} else if ((dist - rad >= cliprad) || (rad - dist >= cliprad)) { } else if ((dist - rad >= cliprad) || (rad - dist >= cliprad)) {
/* The arc is outside of the boundary. */ /* The arc is outside of the boundary. */
@ -1704,7 +1704,7 @@ cliparc(double cx, double cy, double rad, double start, double end, int iclipx,
if (start > d) { if (start > d) {
SWAP(double, start, d); SWAP(double, start, d);
} }
DevDrawArc((int)cx, (int)cy, (int)rad, start, d-start);
DevDrawArc((int)cx, (int)cy, (int)rad, start, d-start, isgrid);
sclip = start; sclip = start;
eclip = d; eclip = d;
} }
@ -1733,7 +1733,7 @@ cliparc(double cx, double cy, double rad, double start, double end, int iclipx,
} }
if (in) { if (in) {
DevDrawArc((int)cx, (int)cy, (int)rad, l, d-l);
DevDrawArc((int)cx, (int)cy, (int)rad, l, d-l, isgrid);
sclip = l; sclip = l;
eclip = d; eclip = d;
} }
@ -1745,7 +1745,7 @@ cliparc(double cx, double cy, double rad, double start, double end, int iclipx,
/* And from here to the end. */ /* And from here to the end. */
if (in) { if (in) {
DevDrawArc((int)cx, (int)cy, (int)rad, d, end-d);
DevDrawArc((int)cx, (int)cy, (int)rad, d, end-d, isgrid);
/* special case */ /* special case */
if (flag != 2) { if (flag != 2) {
sclip = d; sclip = d;

3
src/frontend/plotting/plot5.c

@ -123,8 +123,9 @@ Plt5_DrawLine(int x1, int y1, int x2, int y2, bool isgrid)
} }
int Plt5_Arc(int xc, int yc, int radius, double theta, double delta_theta)
int Plt5_Arc(int xc, int yc, int radius, double theta, double delta_theta, bool isgrid)
{ {
NG_IGNORE(isgrid);
int x0, y0, x1, y1; int x0, y0, x1, y1;
if (delta_theta < 0) { if (delta_theta < 0) {

12
src/frontend/plotting/x11.c

@ -696,7 +696,7 @@ X11_DrawLine(int x1, int y1, int x2, int y2, bool isgrid)
int int
X11_Arc(int x0, int y0, int radius, double theta, double delta_theta)
X11_Arc(int x0, int y0, int radius, double theta, double delta_theta, bool isgrid)
{ {
int t1, t2; int t1, t2;
@ -708,10 +708,18 @@ X11_Arc(int x0, int y0, int radius, double theta, double delta_theta)
t2 = (int) (64 * (180.0 / M_PI) * delta_theta); t2 = (int) (64 * (180.0 / M_PI) * delta_theta);
if (t2 == 0) if (t2 == 0)
return 0; return 0;
XDrawArc(display, DEVDEP(currentgraph).window, DEVDEP(currentgraph).gc,
if (isgrid) {
XDrawArc(display, DEVDEP(currentgraph).window, DEVDEP(currentgraph).gridgc,
x0 - radius,
currentgraph->absolute.height - radius - y0,
(Dimension)(2 * radius), (Dimension)(2 * radius), t1, t2);
}
else {
XDrawArc(display, DEVDEP(currentgraph).window, DEVDEP(currentgraph).gc,
x0 - radius, x0 - radius,
currentgraph->absolute.height - radius - y0, currentgraph->absolute.height - radius - y0,
(Dimension) (2 * radius), (Dimension) (2 * radius), t1, t2); (Dimension) (2 * radius), (Dimension) (2 * radius), t1, t2);
}
} }
return 0; return 0;

8
src/frontend/postsc.c

@ -381,7 +381,7 @@ PS_DrawLine(int x1, int y1, int x2, int y2, bool isgrid)
} }
int PS_Arc(int x0, int y0, int r, double theta, double delta_theta)
int PS_Arc(int x0, int y0, int r, double theta, double delta_theta, bool isgrid)
{ {
double x1, y1; double x1, y1;
double angle1, angle2; double angle1, angle2;
@ -395,6 +395,12 @@ int PS_Arc(int x0, int y0, int r, double theta, double delta_theta)
fprintf(plotfile, "%f %f moveto ", x1+(double)xoff, y1+(double)yoff); fprintf(plotfile, "%f %f moveto ", x1+(double)xoff, y1+(double)yoff);
fprintf(plotfile, "%d %d %d %f %f arc\n", x0+xoff, y0+yoff, r, fprintf(plotfile, "%d %d %d %f %f arc\n", x0+xoff, y0+yoff, r,
angle1, angle2); angle1, angle2);
if(isgrid)
fprintf(plotfile, "%f setlinewidth\n", gridlinewidth);
else
fprintf(plotfile, "%f setlinewidth\n", linewidth);
fprintf(plotfile, "stroke\n"); fprintf(plotfile, "stroke\n");
DEVDEP(currentgraph).linecount = 0; DEVDEP(currentgraph).linecount = 0;

8
src/frontend/svg.c

@ -384,7 +384,7 @@ SVG_DrawLine(int x1, int y1, int x2, int y2, bool isgrid)
int int
SVG_Arc(int x0, int y0, int r, double theta, double delta_theta)
SVG_Arc(int x0, int y0, int r, double theta, double delta_theta, bool isgrid)
{ {
double x1, y1, x2, y2, left; double x1, y1, x2, y2, left;
SVGdevdep *ddp; SVGdevdep *ddp;
@ -405,6 +405,12 @@ SVG_Arc(int x0, int y0, int r, double theta, double delta_theta)
} }
ddp = DEVDEP_P(currentgraph); ddp = DEVDEP_P(currentgraph);
if (isgrid != ddp->isgrid) {
closepath(ddp);
ddp->isgrid = isgrid;
}
if (isgrid && ddp->inpath == NOPATH)
startpath_width(ddp, SVGgrid_width);
CHECK_PATH; CHECK_PATH;
x1 = (double) x0 + r * cos(theta); x1 = (double) x0 + r * cos(theta);

7
src/frontend/wdisp/windisp.c

@ -957,7 +957,7 @@ WIN_DrawLine(int x1, int y1, int x2, int y2, bool isgrid)
} }
int WIN_Arc(int x0, int y0, int radius, double theta, double delta_theta)
int WIN_Arc(int x0, int y0, int radius, double theta, double delta_theta, bool isgrid)
/* /*
* Notes: * Notes:
* Draws an arc of <radius> and center at (x0,y0) beginning at * Draws an arc of <radius> and center at (x0,y0) beginning at
@ -1006,7 +1006,10 @@ int WIN_Arc(int x0, int y0, int radius, double theta, double delta_theta)
ye = (int)(dy0 + (r * sin(theta + delta_theta))); ye = (int)(dy0 + (r * sin(theta + delta_theta)));
/* plot */ /* plot */
NewPen = CreatePen(LType(wd->ColorIndex), linewidth, currentgraph->colorarray[wd->ColorIndex]);
if (isgrid)
NewPen = CreatePen(LType(wd->ColorIndex), currentgraph->gridwidth, currentgraph->colorarray[wd->ColorIndex]);
else
NewPen = CreatePen(LType(wd->ColorIndex), currentgraph->graphwidth, currentgraph->colorarray[wd->ColorIndex]);
OldPen = SelectObject(wd->hDC, NewPen); OldPen = SelectObject(wd->hDC, NewPen);
Arc(wd->hDC, left, yb-top, right, yb-bottom, xs, yb-ys, xe, yb-ye); Arc(wd->hDC, left, yb-top, right, yb-bottom, xs, yb-ys, xe, yb-ye);
OldPen = SelectObject(wd->hDC, OldPen); OldPen = SelectObject(wd->hDC, OldPen);

2
src/include/ngspice/ftedev.h

@ -22,7 +22,7 @@ typedef int disp_fn_NewViewport_t (struct graph *);
typedef int disp_fn_Close_t (void); typedef int disp_fn_Close_t (void);
typedef int disp_fn_Clear_t (void); typedef int disp_fn_Clear_t (void);
typedef int disp_fn_DrawLine_t (int x1, int y1, int x2, int y2, bool isgrid); typedef int disp_fn_DrawLine_t (int x1, int y1, int x2, int y2, bool isgrid);
typedef int disp_fn_Arc_t (int x0, int y0, int radius, double theta, double delta_theta);
typedef int disp_fn_Arc_t (int x0, int y0, int radius, double theta, double delta_theta, bool isgrid);
typedef int disp_fn_Text_t (const char *text, int x, int y, int angle); typedef int disp_fn_Text_t (const char *text, int x, int y, int angle);
typedef int disp_fn_DefineColor_t (int colorid, double red, double green, double blue); typedef int disp_fn_DefineColor_t (int colorid, double red, double green, double blue);
typedef int disp_fn_DefineLinestyle_t (int linestyleid, int mask); typedef int disp_fn_DefineLinestyle_t (int linestyleid, int mask);

Loading…
Cancel
Save