From 81cbbfa39f43dccd535c7e90380bcb051d58e74f Mon Sep 17 00:00:00 2001 From: Stefan Frederik Date: Mon, 3 Jan 2022 00:27:15 +0100 Subject: [PATCH] better vertical scrolling of digital graphs --- src/callback.c | 190 +++++++++++++++++++-------------- src/draw.c | 48 ++++----- src/scheduler.c | 2 + xschem_library/rom8k/rom8k.sch | 11 +- 4 files changed, 139 insertions(+), 112 deletions(-) diff --git a/src/callback.c b/src/callback.c index 3bcd89e8..8ef93757 100644 --- a/src/callback.c +++ b/src/callback.c @@ -164,6 +164,8 @@ void start_wire(double mx, double my) #define W_Y(y) (cy * (y) + dy) #define G_X(x) (((x) - dx) / cx) #define G_Y(y) (((y) - dy) / cy) +/* for digital graphs (ypos1, ypos2 instead of wy1, wy2) */ +#define DG_Y(y) (((y) - ddy) / dcy) /* xctx->graph_flags: * 1: @@ -181,7 +183,7 @@ static int waves_callback(int event, int mx, int my, KeySym key, int button, int double wy1 = -1, wy2 = 4; double ypos1 = 0, ypos2 = 5; double x1, y1, x2, y2, marginx, marginy; - double cx, dx, cy, dy; + double cx, dx, cy, dy, dcy, ddy; int divx = 10, divy = 5; const char *val; char s[30]; @@ -339,6 +341,10 @@ static int waves_callback(int event, int mx, int my, KeySym key, int button, int dx = x1 - wx1 * cx; cy = (y1 - y2) / (wy2 - wy1); dy = y2 - wy1 * cy; + /* graph --> xschem transform for digital waves y axis */ + dcy = (y1 - y2) / (ypos2 - ypos1); + ddy = y2 - ypos1 * dcy; + dbg(1, "%g %g %g %g - %d %d\n", wx1, wy1, wx2, wy2, divx, divy); if( event == KeyPress || event == ButtonPress || event == MotionNotify ) { /* move cursor1 */ @@ -374,9 +380,9 @@ static int waves_callback(int event, int mx, int my, KeySym key, int button, int yy1 = wy1 + (xctx->my_double_save - xctx->mousey_snap) / cy; yy2 = wy2 + (xctx->my_double_save - xctx->mousey_snap) / cy; my_snprintf(s, S(s), "%g", yy1); - my_strdup(1424, &r->prop_ptr, subst_token(r->prop_ptr, "y1", s)); + my_strdup(1435, &r->prop_ptr, subst_token(r->prop_ptr, "y1", s)); my_snprintf(s, S(s), "%g", yy2); - my_strdup(1425, &r->prop_ptr, subst_token(r->prop_ptr, "y2", s)); + my_strdup(1437, &r->prop_ptr, subst_token(r->prop_ptr, "y2", s)); xctx->my_double_save = xctx->mousey_snap; need_redraw = 1; } @@ -408,16 +414,27 @@ static int waves_callback(int event, int mx, int my, KeySym key, int button, int else if((button == Button5 && !(state & ShiftMask))) { double delta; if(xctx->graph_left) { - if(!digital && i == xctx->graph_master) { - delta = (wy2 - wy1) / divy; - delta_threshold = 1.0; - yy1 = wy1 + delta * delta_threshold; - yy2 = wy2 + delta * delta_threshold; - my_snprintf(s, S(s), "%g", yy1); - my_strdup(1420, &r->prop_ptr, subst_token(r->prop_ptr, "y1", s)); - my_snprintf(s, S(s), "%g", yy2); - my_strdup(1421, &r->prop_ptr, subst_token(r->prop_ptr, "y2", s)); - need_redraw = 1; + if(i == xctx->graph_master) { + if(digital) { + delta = (ypos2 - ypos1) * 0.05; + yy1 = ypos1 + delta; + yy2 = ypos2 + delta; + my_snprintf(s, S(s), "%g", yy1); + my_strdup(1456, &r->prop_ptr, subst_token(r->prop_ptr, "ypos1", s)); + my_snprintf(s, S(s), "%g", yy2); + my_strdup(1457, &r->prop_ptr, subst_token(r->prop_ptr, "ypos2", s)); + need_redraw = 1; + } else { + delta = (wy2 - wy1) / divy; + delta_threshold = 1.0; + yy1 = wy1 + delta * delta_threshold; + yy2 = wy2 + delta * delta_threshold; + my_snprintf(s, S(s), "%g", yy1); + my_strdup(1420, &r->prop_ptr, subst_token(r->prop_ptr, "y1", s)); + my_snprintf(s, S(s), "%g", yy2); + my_strdup(1421, &r->prop_ptr, subst_token(r->prop_ptr, "y2", s)); + need_redraw = 1; + } } } else { if( r->sel || !(r->flags & 2) || i == xctx->graph_master) { @@ -465,16 +482,27 @@ static int waves_callback(int event, int mx, int my, KeySym key, int button, int else if(button == Button4 && !(state & ShiftMask)) { double delta; if(xctx->graph_left) { - if(!digital && i == xctx->graph_master) { - delta = (wy2 - wy1) / divy; - delta_threshold = 1.0; - yy1 = wy1 - delta * delta_threshold; - yy2 = wy2 - delta * delta_threshold; - my_snprintf(s, S(s), "%g", yy1); - my_strdup(1416, &r->prop_ptr, subst_token(r->prop_ptr, "y1", s)); - my_snprintf(s, S(s), "%g", yy2); - my_strdup(1417, &r->prop_ptr, subst_token(r->prop_ptr, "y2", s)); - need_redraw = 1; + if(i == xctx->graph_master) { + if(digital) { + delta = (ypos2 - ypos1) * 0.05; + yy1 = ypos1 - delta; + yy2 = ypos2 - delta; + my_snprintf(s, S(s), "%g", yy1); + my_strdup(1416, &r->prop_ptr, subst_token(r->prop_ptr, "ypos1", s)); + my_snprintf(s, S(s), "%g", yy2); + my_strdup(1417, &r->prop_ptr, subst_token(r->prop_ptr, "ypos2", s)); + need_redraw = 1; + } else { + delta = (wy2 - wy1) / divy; + delta_threshold = 1.0; + yy1 = wy1 - delta * delta_threshold; + yy2 = wy2 - delta * delta_threshold; + my_snprintf(s, S(s), "%g", yy1); + my_strdup(1458, &r->prop_ptr, subst_token(r->prop_ptr, "y1", s)); + my_snprintf(s, S(s), "%g", yy2); + my_strdup(1434, &r->prop_ptr, subst_token(r->prop_ptr, "y2", s)); + need_redraw = 1; + } } } else { if(r->sel || !(r->flags & 2) || i == xctx->graph_master) { @@ -521,19 +549,35 @@ static int waves_callback(int event, int mx, int my, KeySym key, int button, int } else if(button == Button5 && (state & ShiftMask)) { if(xctx->graph_left) { - if(!digital && i == xctx->graph_master) { - double m = G_Y(xctx->mousey); - double a = m - wy1; - double b = wy2 -m; - double delta = (wy2 - wy1); - double var = delta * 0.2; - yy2 = wy2 + var * b / delta; - yy1 = wy1 - var * a / delta; - my_snprintf(s, S(s), "%g", yy1); - my_strdup(1447, &r->prop_ptr, subst_token(r->prop_ptr, "y1", s)); - my_snprintf(s, S(s), "%g", yy2); - my_strdup(1436, &r->prop_ptr, subst_token(r->prop_ptr, "y2", s)); - need_redraw = 1; + if(i == xctx->graph_master) { + if(digital) { + double m = DG_Y(xctx->mousey); + double a = m - ypos1; + double b = ypos2 -m; + double delta = (ypos2 - ypos1); + double var = delta * 0.05; + yy2 = ypos2 + var * b / delta; + yy1 = ypos1 - var * a / delta; + my_snprintf(s, S(s), "%g", yy1); + my_strdup(1461, &r->prop_ptr, subst_token(r->prop_ptr, "ypos1", s)); + my_snprintf(s, S(s), "%g", yy2); + my_strdup(1459, &r->prop_ptr, subst_token(r->prop_ptr, "ypos2", s)); + need_redraw = 1; + + } else { + double m = G_Y(xctx->mousey); + double a = m - wy1; + double b = wy2 -m; + double delta = (wy2 - wy1); + double var = delta * 0.2; + yy2 = wy2 + var * b / delta; + yy1 = wy1 - var * a / delta; + my_snprintf(s, S(s), "%g", yy1); + my_strdup(1460, &r->prop_ptr, subst_token(r->prop_ptr, "y1", s)); + my_snprintf(s, S(s), "%g", yy2); + my_strdup(1438, &r->prop_ptr, subst_token(r->prop_ptr, "y2", s)); + need_redraw = 1; + } } } else { if(r->sel || !(r->flags & 2) || i == xctx->graph_master) { @@ -549,20 +593,7 @@ static int waves_callback(int event, int mx, int my, KeySym key, int button, int } } else if(key == XK_Down) { - double delta; - if(xctx->graph_left) { - if(!digital && i == xctx->graph_master) { - delta = (wy2 - wy1) / divy; - delta_threshold = 1.0; - yy1 = wy1 - delta * delta_threshold; - yy2 = wy2 - delta * delta_threshold; - my_snprintf(s, S(s), "%g", yy1); - my_strdup(1434, &r->prop_ptr, subst_token(r->prop_ptr, "y1", s)); - my_snprintf(s, S(s), "%g", yy2); - my_strdup(1435, &r->prop_ptr, subst_token(r->prop_ptr, "y2", s)); - need_redraw = 1; - } - } else { + if(!xctx->graph_left) { if(r->sel || !(r->flags & 2) || i == xctx->graph_master) { double var = 0.2 * (wx2 -wx1); xx2 = wx2 + var * (1 - zoom_m); @@ -577,19 +608,34 @@ static int waves_callback(int event, int mx, int my, KeySym key, int button, int } else if(button == Button4 && (state & ShiftMask)) { if(xctx->graph_left) { - if(!digital && i == xctx->graph_master) { - double m = G_Y(xctx->mousey); - double a = m - wy1; - double b = wy2 -m; - double delta = (wy2 - wy1); - double var = delta * 0.2; - yy2 = wy2 - var * b / delta; - yy1 = wy1 + var * a / delta; - my_snprintf(s, S(s), "%g", yy1); - my_strdup(1419, &r->prop_ptr, subst_token(r->prop_ptr, "y1", s)); - my_snprintf(s, S(s), "%g", yy2); - my_strdup(1444, &r->prop_ptr, subst_token(r->prop_ptr, "y2", s)); - need_redraw = 1; + if(i == xctx->graph_master) { + if(digital) { + double m = DG_Y(xctx->mousey); + double a = m - ypos1; + double b = ypos2 -m; + double delta = (ypos2 - ypos1); + double var = delta * 0.05; + yy2 = ypos2 - var * b / delta; + yy1 = ypos1 + var * a / delta; + my_snprintf(s, S(s), "%g", yy1); + my_strdup(1447, &r->prop_ptr, subst_token(r->prop_ptr, "ypos1", s)); + my_snprintf(s, S(s), "%g", yy2); + my_strdup(1436, &r->prop_ptr, subst_token(r->prop_ptr, "ypos2", s)); + need_redraw = 1; + } else { + double m = G_Y(xctx->mousey); + double a = m - wy1; + double b = wy2 -m; + double delta = (wy2 - wy1); + double var = delta * 0.2; + yy2 = wy2 - var * b / delta; + yy1 = wy1 + var * a / delta; + my_snprintf(s, S(s), "%g", yy1); + my_strdup(1419, &r->prop_ptr, subst_token(r->prop_ptr, "y1", s)); + my_snprintf(s, S(s), "%g", yy2); + my_strdup(1444, &r->prop_ptr, subst_token(r->prop_ptr, "y2", s)); + need_redraw = 1; + } } } else { if(r->sel || !(r->flags & 2) || i == xctx->graph_master) { @@ -604,22 +650,8 @@ static int waves_callback(int event, int mx, int my, KeySym key, int button, int } } } - else if(key == XK_Up) { - double delta; - if(xctx->graph_left) { - if(!digital && i == xctx->graph_master) { - delta = (wy2 - wy1) / divy; - delta_threshold = 1.0; - yy1 = wy1 + delta * delta_threshold; - yy2 = wy2 + delta * delta_threshold; - my_snprintf(s, S(s), "%g", yy1); - my_strdup(1437, &r->prop_ptr, subst_token(r->prop_ptr, "y1", s)); - my_snprintf(s, S(s), "%g", yy2); - my_strdup(1438, &r->prop_ptr, subst_token(r->prop_ptr, "y2", s)); - need_redraw = 1; - } - } else { + if(!xctx->graph_left) { if(r->sel || !(r->flags & 2) || i == xctx->graph_master) { double var = 0.2 * (wx2 -wx1); xx2 = wx2 - var * (1 - zoom_m); @@ -823,7 +855,7 @@ int callback(const char *winpath, int event, int mx, int my, KeySym key, switch(event) { case EnterNotify: - tcleval("catch {destroy .ctxmenu}"); + /* tcleval("catch {destroy .ctxmenu}"); */ if(!xctx->sel_or_clip[0]) my_snprintf(xctx->sel_or_clip, S(xctx->sel_or_clip), "%s/%s", user_conf_dir, ".selection.sch"); diff --git a/src/draw.c b/src/draw.c index 96d4c030..776a8dd6 100644 --- a/src/draw.c +++ b/src/draw.c @@ -1807,14 +1807,15 @@ int schematic_waves_loaded(void) static void draw_graph_bus_points(const char *ntok, int first, int last, double cx, double dx, double dcy, double ddy, int wave_col, int sweep_idx, - int digital, int dig_max_waves, int wcnt, int n_nodes, + int digital, int wcnt, int n_nodes, double wy1, double wy2, double ypos1, double ypos2) { int p, i; - int n = dig_max_waves; - double s1 = 1.0 / n; - double s2 = s1 * .66; - double c = (ypos2 - ypos1) * (n_nodes - wcnt) * s1; + double deltag = wy2 - wy1; + double delta = ypos2 - ypos1; + double s1 = 0.1 * deltag / delta; /* dig_max_waves; */ + double s2 = s1 * .8; + double c = delta * (n_nodes - wcnt) * s1; double x1 = W_X(xctx->graph_values[sweep_idx][first]); double x2 = W_X(xctx->graph_values[sweep_idx][last-1]); double ylow = DW_Y(c + wy2 * s2); /* swapped as xschem Y coordinates are top-bottom */ @@ -1895,24 +1896,22 @@ static void draw_graph_bus_points(const char *ntok, int first, int last, static void draw_graph_points(int v, int first, int last, double scy, double sdy, double dscy, double dsdy, XPoint *point, int wave_col, - int digital, int dig_max_waves, int wcnt, int n_nodes, double wy1, double wy2, + int digital, int wcnt, int n_nodes, double wy1, double wy2, double ypos1, double ypos2) { int p; double yy; - double ydelta; int poly_npoints = 0; - int n = dig_max_waves; - double s1 = 1.0 / n; - double s2 = s1 * .66; + double deltag = wy2 - wy1; + double delta = ypos2 - ypos1; + double s1 = 0.1 * deltag / delta; /* dig_max_waves; */ + double s2 = s1 * .8; double c; if(digital) { - ydelta = ypos2 - ypos1; - c = ydelta * (n_nodes - wcnt) * s1; + c = delta * (n_nodes - wcnt) * s1; } - - if( !digital || (c >= wy1 && c <= wy2) ) { + if( !digital || (c >= ypos1 && c <= ypos2) ) { for(p = first ; p <= last; p++) { yy = xctx->graph_values[v][p]; if(digital) { @@ -2055,7 +2054,6 @@ void draw_graph(int c, int i, int flags) double x1, y1, x2, y2; /* graph coordinate, some defaults */ int digital = 0; - int dig_max_waves = 10; /* max waves that can be stacked, then vertical pan can be used to view more */ double wx1 = 0, wy1 = 0, wx2 = 1e-6, wy2 = 5, ypos1 = 0, ypos2 = 5; double marginx = 20; /* will be recalculated later */ double marginy = 20; /* will be recalculated later */ @@ -2127,11 +2125,6 @@ void draw_graph(int c, int i, int flags) else ypos2 = 5; val = get_tok_value(r->prop_ptr,"digital",0); if(val[0]) digital = atoi(val); - if(digital) { - val = get_tok_value(r->prop_ptr,"dig_max_waves",0); - if(val[0]) dig_max_waves = atoi(val); - } - /* plot single dataset */ val = get_tok_value(r->prop_ptr,"dataset",0); if(val[0]) dataset = atoi(val); @@ -2214,10 +2207,11 @@ void draw_graph(int c, int i, int flags) else my_snprintf(tmpstr, S(tmpstr), "%s", ntok); } if(digital) { - /* int n = n_nodes > dig_max_waves ? dig_max_waves : n_nodes; */ - int n = dig_max_waves; double xt = x1 - 10 * txtsizelab; - double delta_div_n = (ypos2 - ypos1) / n; + double deltag = wy2 - wy1; + double delta = ypos2 - ypos1; + double s1 = 0.1 * deltag / delta; + double delta_div_n = delta * s1; /* dig_max_waves; */ double yt = delta_div_n * (double)(n_nodes - wcnt); if(yt <= ypos2 && yt >= ypos1) { @@ -2271,12 +2265,12 @@ void draw_graph(int c, int i, int flags) if(bus_msb) { if(digital) { draw_graph_bus_points(ntok, first, last, cx, dx, dcy, ddy, wave_color, - sweep_idx, digital, dig_max_waves, wcnt, n_nodes, + sweep_idx, digital, wcnt, n_nodes, wy1, wy2, ypos1, ypos2); } } else { draw_graph_points(v, first, last, scy, sdy, dscy, dsdy, point, wave_color, - digital, dig_max_waves, wcnt, n_nodes, wy1, wy2, ypos1, ypos2); + digital, wcnt, n_nodes, wy1, wy2, ypos1, ypos2); } poly_npoints = 0; first = -1; @@ -2299,12 +2293,12 @@ void draw_graph(int c, int i, int flags) if(bus_msb) { if(digital) { draw_graph_bus_points(ntok, first, last, cx, dx, dcy, ddy, wave_color, - sweep_idx, digital, dig_max_waves, wcnt, n_nodes, + sweep_idx, digital, wcnt, n_nodes, wy1, wy2, ypos1, ypos2); } } else { draw_graph_points(v, first, last, scy, sdy, dscy, dsdy, point, wave_color, - digital, dig_max_waves, wcnt, n_nodes, wy1, wy2, ypos1, ypos2); + digital, wcnt, n_nodes, wy1, wy2, ypos1, ypos2); } } } /* if(dataset == -1 || dset == dataset) */ diff --git a/src/scheduler.c b/src/scheduler.c index fa310a1b..c74194ac 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -2910,6 +2910,8 @@ const char *tcleval(const char str[]) { if( Tcl_GlobalEval(interp, str) != TCL_OK) { fprintf(errfp, "tcleval(): evaluation of script: %s failed\n", str); + fprintf(errfp, " : %s\n", Tcl_GetStringResult(interp)); + Tcl_ResetResult(interp); } return Tcl_GetStringResult(interp); } diff --git a/xschem_library/rom8k/rom8k.sch b/xschem_library/rom8k/rom8k.sch index 585da451..19da7785 100644 --- a/xschem_library/rom8k/rom8k.sch +++ b/xschem_library/rom8k/rom8k.sch @@ -78,14 +78,13 @@ node="v(ldymsref)" color=3 unitx=n subdivy=4} B 2 1840 -880 2890 -420 {flags=3 digital=1 -dig_max_waves=12 y1 = 0 -y2 = 2 -ypos1=-0.690976 -ypos2=1.30903 +y2 = 1.6 +ypos1=0.0211877 +ypos2=2.22059 divy = 1 -x1=2e-12 -x2=4.8e-07 +x1=1.16679e-07 +x2=2.68175e-07 divx=12 subdivx=4 node="