diff --git a/src/callback.c b/src/callback.c index 225437c7..7f7ece6e 100644 --- a/src/callback.c +++ b/src/callback.c @@ -861,99 +861,12 @@ static int waves_callback(int event, int mx, int my, KeySym key, int button, int if(xctx->graph_values) { if(xctx->graph_left) { /* full Y zoom*/ if(i == xctx->graph_master) { - if(!gr->digital) { - int dset; - int p, v; - const char *bus_msb = NULL; - int sweep_idx = 0; - double val, start, end; - double min=0.0, max=0.0; - int first = 1; - char *saves, *sptr, *stok, *sweep = NULL, *saven, *nptr, *ntok, *node = NULL; - my_strdup2(_ALLOC_ID_, &node, get_tok_value(r->prop_ptr,"node",0)); - my_strdup2(_ALLOC_ID_, &sweep, get_tok_value(r->prop_ptr,"sweep",0)); - nptr = node; - sptr = sweep; - start = (gr->gx1 <= gr->gx2) ? gr->gx1 : gr->gx2; - end = (gr->gx1 <= gr->gx2) ? gr->gx2 : gr->gx1; - - while( (ntok = my_strtok_r(nptr, "\n\t ", "\"", &saven)) ) { - stok = my_strtok_r(sptr, "\n\t ", "\"", &saves); - nptr = sptr = NULL; - if(stok && stok[0]) { - sweep_idx = get_raw_index(stok); - if( sweep_idx == -1) sweep_idx = 0; - } - bus_msb = strstr(ntok, ","); - v = -1; - if(!bus_msb) { - char *express = NULL; - if(strstr(ntok, ";")) { - my_strdup2(_ALLOC_ID_, &express, find_nth(ntok, ";", 2)); - } else { - my_strdup2(_ALLOC_ID_, &express, ntok); - } - if(strpbrk(express, " \n\t")) { - /* just probe a single point to get the index. custom data column already calculated */ - v = calc_custom_data_yrange(sweep_idx, express, gr); - } else { - v = get_raw_index(express); - } - my_free(_ALLOC_ID_, &express); - } - if(v >= 0) { - int ofs = 0; - for(dset = 0 ; dset < xctx->graph_datasets; dset++) { - for(p = ofs; p < ofs + xctx->graph_npoints[dset]; ++p) { - double sweepval; - if(gr->logx) sweepval = mylog10(xctx->graph_values[sweep_idx][p]); - else sweepval = xctx->graph_values[sweep_idx][p]; - if(dataset >= 0 && dataset != dset) continue; - if( sweepval < start || - sweepval > end) continue; - if(gr->logy) - val =mylog10(xctx->graph_values[v][p]); - else - val = xctx->graph_values[v][p]; - if(first || val < min) min = val; - if(first || val > max) max = val; - first = 0; - } - ofs += xctx->graph_npoints[dset]; - } - } - } /* while( (ntok = my_strtok_r(nptr, "\n\t ", "\"", &saven)) ) */ - if(max == min) max += 0.01; - min = floor_to_n_digits(min, 2); - max = ceil_to_n_digits(max, 2); - my_free(_ALLOC_ID_, &node); - my_free(_ALLOC_ID_, &sweep); - my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "y1", dtoa(min))); - my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "y2", dtoa(max))); - need_redraw = 1; - } else { /* digital plot */ - my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "ypos1", - get_tok_value(r->prop_ptr, "y1", 0) )); - my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "ypos2", - get_tok_value(r->prop_ptr, "y2", 0) )); - need_redraw = 1; - } + need_redraw = graph_fullyzoom(r, gr, dataset); } /* graph_master */ } else { /* not graph_left, full X zoom*/ - int idx = get_raw_index(find_nth(get_tok_value(r->prop_ptr, "sweep", 0), ", ", 1)); - int dset = dataset == -1 ? 0 : dataset; - if(idx < 0 ) idx = 0; /* selected or locked or master */ if(r->sel || !(r->flags & 2) || i == xctx->graph_master) { - xx1 = get_raw_value(dset, idx, 0); - xx2 = get_raw_value(dset, idx, xctx->graph_npoints[dset] -1); - if(gr->logx) { - xx1 = mylog10(xx1); - xx2 = mylog10(xx2); - } - my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "x1", dtoa(xx1))); - my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "x2", dtoa(xx2))); - need_redraw = 1; + need_redraw = graph_fullxzoom(r, gr, dataset); } } } /* graph_values */ diff --git a/src/draw.c b/src/draw.c index a796a5c3..745060ad 100644 --- a/src/draw.c +++ b/src/draw.c @@ -1870,6 +1870,108 @@ static void set_thick_waves(int what, int wcnt, int wave_col, Graph_ctx *gr) } } +int graph_fullxzoom(xRect *r, Graph_ctx *gr, int dataset) +{ + int need_redraw = 0; + double xx1, xx2; + int idx = get_raw_index(find_nth(get_tok_value(r->prop_ptr, "sweep", 0), ", ", 1)); + int dset = dataset == -1 ? 0 : dataset; + if(idx < 0 ) idx = 0; + xx1 = get_raw_value(dset, idx, 0); + xx2 = get_raw_value(dset, idx, xctx->graph_npoints[dset] -1); + if(gr->logx) { + xx1 = mylog10(xx1); + xx2 = mylog10(xx2); + } + my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "x1", dtoa(xx1))); + my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "x2", dtoa(xx2))); + need_redraw = 1; + return need_redraw; +} + +int graph_fullyzoom(xRect *r, Graph_ctx *gr, int dataset) +{ + int need_redraw = 0; + if(!gr->digital) { + int dset; + int p, v; + const char *bus_msb = NULL; + int sweep_idx = 0; + double val, start, end; + double min=0.0, max=0.0; + int first = 1; + char *saves, *sptr, *stok, *sweep = NULL, *saven, *nptr, *ntok, *node = NULL; + my_strdup2(_ALLOC_ID_, &node, get_tok_value(r->prop_ptr,"node",0)); + my_strdup2(_ALLOC_ID_, &sweep, get_tok_value(r->prop_ptr,"sweep",0)); + nptr = node; + sptr = sweep; + start = (gr->gx1 <= gr->gx2) ? gr->gx1 : gr->gx2; + end = (gr->gx1 <= gr->gx2) ? gr->gx2 : gr->gx1; + + while( (ntok = my_strtok_r(nptr, "\n\t ", "\"", &saven)) ) { + stok = my_strtok_r(sptr, "\n\t ", "\"", &saves); + nptr = sptr = NULL; + if(stok && stok[0]) { + sweep_idx = get_raw_index(stok); + if( sweep_idx == -1) sweep_idx = 0; + } + bus_msb = strstr(ntok, ","); + v = -1; + if(!bus_msb) { + char *express = NULL; + if(strstr(ntok, ";")) { + my_strdup2(_ALLOC_ID_, &express, find_nth(ntok, ";", 2)); + } else { + my_strdup2(_ALLOC_ID_, &express, ntok); + } + if(strpbrk(express, " \n\t")) { + /* just probe a single point to get the index. custom data column already calculated */ + v = calc_custom_data_yrange(sweep_idx, express, gr); + } else { + v = get_raw_index(express); + } + my_free(_ALLOC_ID_, &express); + } + if(v >= 0) { + int ofs = 0; + for(dset = 0 ; dset < xctx->graph_datasets; dset++) { + for(p = ofs; p < ofs + xctx->graph_npoints[dset]; ++p) { + double sweepval; + if(gr->logx) sweepval = mylog10(xctx->graph_values[sweep_idx][p]); + else sweepval = xctx->graph_values[sweep_idx][p]; + if(dataset >= 0 && dataset != dset) continue; + if( sweepval < start || + sweepval > end) continue; + if(gr->logy) + val =mylog10(xctx->graph_values[v][p]); + else + val = xctx->graph_values[v][p]; + if(first || val < min) min = val; + if(first || val > max) max = val; + first = 0; + } + ofs += xctx->graph_npoints[dset]; + } + } + } /* while( (ntok = my_strtok_r(nptr, "\n\t ", "\"", &saven)) ) */ + if(max == min) max += 0.01; + min = floor_to_n_digits(min, 2); + max = ceil_to_n_digits(max, 2); + my_free(_ALLOC_ID_, &node); + my_free(_ALLOC_ID_, &sweep); + my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "y1", dtoa(min))); + my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "y2", dtoa(max))); + need_redraw = 1; + } else { /* digital plot */ + my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "ypos1", + get_tok_value(r->prop_ptr, "y1", 0) )); + my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "ypos2", + get_tok_value(r->prop_ptr, "y2", 0) )); + need_redraw = 1; + } + return need_redraw; +} + /* draw bussed signals: ntok is a comma separated list of items, first item is bus name, * following are bits that are bundled together: LDA,LDA[3],LDA[2],LDA1],LDA[0] diff --git a/src/scheduler.c b/src/scheduler.c index eefcfa56..7edcdda0 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -2745,7 +2745,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg } } else if(argc > 5 && !strcmp(argv[2], "rect")) { /* 0 1 2 3 4 5 6 7 - * xschem setprop rect c n token value [fast] */ + * xschem setprop rect c n token [value] [fast] */ int change_done = 0; int fast = 0; xRect *r; @@ -2779,7 +2779,24 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg if(!fast) { bbox(START,0.0,0.0,0.0,0.0); } - if(argc > 6) { + if(argc > 5 && c == 2 && !strcmp(argv[5], "fullxzoom")) { + xRect *r = &xctx->rect[c][n]; + Graph_ctx *gr = &xctx->graph_struct; + int dataset; + if(gr->dataset >= 0 && gr->dataset < xctx->graph_datasets) dataset = gr->dataset; + else dataset = -1; + graph_fullxzoom(r, gr, dataset); + } + if(argc > 5 && c == 2 && !strcmp(argv[5], "fullyzoom")) { + xRect *r = &xctx->rect[c][n]; + Graph_ctx *gr = &xctx->graph_struct; + int dataset; + setup_graph_data(n, 0, gr); + if(gr->dataset >= 0 && gr->dataset < xctx->graph_datasets) dataset =gr->dataset; + else dataset = -1; + graph_fullyzoom(r, gr, dataset); + } + else if(argc > 6) { /* verify if there is some difference */ if(strcmp(argv[6], get_tok_value(r->prop_ptr, argv[5], 0))) { change_done = 1; diff --git a/src/xschem.h b/src/xschem.h index a963335a..5a4ca3a6 100644 --- a/src/xschem.h +++ b/src/xschem.h @@ -1109,6 +1109,8 @@ extern int edit_wave_attributes(int what, int i, Graph_ctx *gr); extern void draw_graph(int i, int flags, Graph_ctx *gr, void *ct); extern int find_closest_wave(int i, Graph_ctx *gr); extern void setup_graph_data(int i, int skip, Graph_ctx *gr); +extern int graph_fullyzoom(xRect *r, Graph_ctx *gr, int dataset); +extern int graph_fullxzoom(xRect *r, Graph_ctx *gr, int dataset); extern double timer(int start); extern void enable_layers(void); extern void set_snap(double);