From 4f82a24df29c18819a77399b2a1fb0270e80f313 Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Sat, 15 Jan 2022 10:16:01 +0100 Subject: [PATCH] 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. --- src/frontend/display.c | 4 ++-- src/frontend/display.h | 2 +- src/frontend/hpgl.c | 4 +++- src/frontend/plotting/grid.c | 32 ++++++++++++++++---------------- src/frontend/plotting/plot5.c | 3 ++- src/frontend/plotting/x11.c | 12 ++++++++++-- src/frontend/postsc.c | 8 +++++++- src/frontend/svg.c | 8 +++++++- src/frontend/wdisp/windisp.c | 7 +++++-- src/include/ngspice/ftedev.h | 2 +- 10 files changed, 54 insertions(+), 28 deletions(-) diff --git a/src/frontend/display.c b/src/frontend/display.c index 8ace0ee53..211aac2a3 100644 --- a/src/frontend/display.c +++ b/src/frontend/display.c @@ -249,9 +249,9 @@ DevDrawLine(int x1, int y1, int x2, int y2, bool isgrid) 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); } diff --git a/src/frontend/display.h b/src/frontend/display.h index e50eaf480..1b860d418 100644 --- a/src/frontend/display.h +++ b/src/frontend/display.h @@ -18,7 +18,7 @@ int NewViewport(GRAPH *pgraph); void DevClose(void); void DevClear(void); 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 DefineColor(int colorid, double red, double green, double blue); void DefineLinestyle(int linestyleid, int mask); diff --git a/src/frontend/hpgl.c b/src/frontend/hpgl.c index e8040685d..28d4e4956 100644 --- a/src/frontend/hpgl.c +++ b/src/frontend/hpgl.c @@ -230,8 +230,10 @@ GL_DrawLine(int x1, int y1, int x2, int y2, bool isgrid) /* 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; x1 = x0 + (int)(r * cos(theta)); diff --git a/src/frontend/plotting/grid.c b/src/frontend/plotting/grid.c index 4ef20cce4..3ac31b526 100644 --- a/src/frontend/plotting/grid.c +++ b/src/frontend/plotting/grid.c @@ -55,9 +55,9 @@ static void smithgrid(GRAPH *graph); static void drawsmithgrid(GRAPH *graph); 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); + 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, - 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, 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, graph->grid.yaxis.circular.center, graph->grid.xaxis.circular.radius, - 0.0, 2*M_PI); + 0.0, 2*M_PI, TRUE); SetLinestyle(1); /* Now draw the circles. */ @@ -1092,7 +1092,7 @@ drawpolargrid(GRAPH *graph) (double) relrad, 0.0, 2*M_PI, graph->grid.xaxis.circular.center, graph->grid.yaxis.circular.center, - graph->grid.xaxis.circular.radius, 0); + graph->grid.xaxis.circular.radius, 0, TRUE); /* Toss on the label */ if (relcx || relcy) 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])), gr_xcenter - zheight, - gr_xcenter + zheight); + gr_xcenter + zheight, TRUE); } if (mag == 20) { fprintf(cp_err, "smithgrid: Internal Error: screwed up\n"); @@ -1485,7 +1485,7 @@ drawsmithgrid(GRAPH *graph) 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)) { @@ -1529,7 +1529,7 @@ drawsmithgrid(GRAPH *graph) */ 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 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), (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 * Let's draw them anyway */ cliparc((double) (centx + xoffset + radoff + rad), (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. */ SetColor(19); aclip = cliparc((double) (centx + xoffset + radoff), (double) (centy + yoffset + irad), irad, (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)) { xlab = (int)(centx + xoffset + radoff + irad * cos(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) (M_PI / 2 + 2 * iangle), (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)) { xlab = (int)(centx + xoffset + radoff + irad * cos(aclip)); 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 -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 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); if (dist + rad < cliprad) { /* 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); } else if ((dist - rad >= cliprad) || (rad - dist >= cliprad)) { /* 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) { 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; eclip = d; } @@ -1733,7 +1733,7 @@ cliparc(double cx, double cy, double rad, double start, double end, int iclipx, } 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; 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. */ 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 */ if (flag != 2) { sclip = d; diff --git a/src/frontend/plotting/plot5.c b/src/frontend/plotting/plot5.c index b5723d5f4..248e6ee75 100644 --- a/src/frontend/plotting/plot5.c +++ b/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; if (delta_theta < 0) { diff --git a/src/frontend/plotting/x11.c b/src/frontend/plotting/x11.c index 590db2dd2..0b5d5f5eb 100644 --- a/src/frontend/plotting/x11.c +++ b/src/frontend/plotting/x11.c @@ -696,7 +696,7 @@ X11_DrawLine(int x1, int y1, int x2, int y2, bool isgrid) 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; @@ -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); if (t2 == 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, currentgraph->absolute.height - radius - y0, (Dimension) (2 * radius), (Dimension) (2 * radius), t1, t2); + } } return 0; diff --git a/src/frontend/postsc.c b/src/frontend/postsc.c index 9bcfec4c6..e71e115e9 100644 --- a/src/frontend/postsc.c +++ b/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 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, "%d %d %d %f %f arc\n", x0+xoff, y0+yoff, r, angle1, angle2); + + if(isgrid) + fprintf(plotfile, "%f setlinewidth\n", gridlinewidth); + else + fprintf(plotfile, "%f setlinewidth\n", linewidth); + fprintf(plotfile, "stroke\n"); DEVDEP(currentgraph).linecount = 0; diff --git a/src/frontend/svg.c b/src/frontend/svg.c index 9df9e0284..d6f9b83c4 100644 --- a/src/frontend/svg.c +++ b/src/frontend/svg.c @@ -384,7 +384,7 @@ SVG_DrawLine(int x1, int y1, int x2, int y2, bool isgrid) 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; SVGdevdep *ddp; @@ -405,6 +405,12 @@ SVG_Arc(int x0, int y0, int r, double theta, double delta_theta) } 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; x1 = (double) x0 + r * cos(theta); diff --git a/src/frontend/wdisp/windisp.c b/src/frontend/wdisp/windisp.c index 72461e0a4..93716f3e9 100644 --- a/src/frontend/wdisp/windisp.c +++ b/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: * Draws an arc of 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))); /* 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); Arc(wd->hDC, left, yb-top, right, yb-bottom, xs, yb-ys, xe, yb-ye); OldPen = SelectObject(wd->hDC, OldPen); diff --git a/src/include/ngspice/ftedev.h b/src/include/ngspice/ftedev.h index 3d5cb9102..3a9041283 100644 --- a/src/include/ngspice/ftedev.h +++ b/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_Clear_t (void); 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_DefineColor_t (int colorid, double red, double green, double blue); typedef int disp_fn_DefineLinestyle_t (int linestyleid, int mask);