From 90ce40da2cc684f8e3fd6c68867254c5946aac06 Mon Sep 17 00:00:00 2001 From: stefan schippers Date: Fri, 5 Jan 2024 02:08:13 +0100 Subject: [PATCH] Right click on a graph cursor allows to set the cursor position numerically --- src/callback.c | 26 ++++++++++++++++++++++++++ src/editprop.c | 35 +++++++++++++++++++++++++++++++++++ src/xschem.h | 1 + src/xschem.tcl | 1 + 4 files changed, 63 insertions(+) diff --git a/src/callback.c b/src/callback.c index 867e5d5b..4f2c7eb5 100644 --- a/src/callback.c +++ b/src/callback.c @@ -414,6 +414,32 @@ static int waves_callback(int event, int mx, int my, KeySym key, int button, int xctx->graph_flags |= 32; /* Start move cursor2 */ } } + else if(event == ButtonPress && button == Button3) { + /* Numerically set cursor position */ + if( (xctx->graph_flags & 2) && fabs(xctx->mousex - W_X(xctx->graph_cursor1_x)) < 10) { + if(gr->logx) { + double pos = pow(xctx->graph_cursor1_x, 10); + tclvareval("input_line {Pos:} {} ", dtoa_eng(pos), NULL); + pos = mylog10(atof_eng(tclresult())); + tclvareval("xschem set cursor1_x ", dtoa(pos), NULL); + } else { + tclvareval("input_line {Pos:} {xschem set cursor1_x} ", dtoa_eng(xctx->graph_cursor1_x), NULL); + } + + redraw_all_at_end = 1; + } + if( (xctx->graph_flags & 4) && fabs(xctx->mousex - W_X(xctx->graph_cursor2_x)) < 10) { + if(gr->logx) { + double pos = pow(xctx->graph_cursor2_x, 10); + tclvareval("input_line {Pos:} {} ", dtoa_eng(pos), NULL); + pos = mylog10(atof_eng(tclresult())); + tclvareval("xschem set cursor2_x ", dtoa(pos), NULL); + } else { + tclvareval("input_line {Pos:} {xschem set cursor2_x} ", dtoa_eng(xctx->graph_cursor2_x), NULL); + } + redraw_all_at_end = 1; + } + } else if(event == -3 && button == Button1) { if(!edit_wave_attributes(1, i, gr)) { tclvareval("graph_edit_properties ", my_itoa(i), NULL); diff --git a/src/editprop.c b/src/editprop.c index bc5861e0..01a34175 100644 --- a/src/editprop.c +++ b/src/editprop.c @@ -440,6 +440,41 @@ double atof_spice(const char *s) return a; } + +/* same as atof_spice, but recognizes 'M' ae Mega, and 'm' as Milli */ +double atof_eng(const char *s) +{ + int n; + double a = 0.0, mul=1.0; + char suffix[100]={0}; + const char *p; + + if(!s) return 0.0; + n = sscanf(s, "%lf%s", &a, suffix); + if(n == 0) { + return 0.0; + } else if(n == 1) { + mul = 1.0; + } else { + p = strpbrk(suffix, "TGMKUNPFAtgmkunpfa"); + if(p != suffix ) mul = 1.0; + else if(tolower(*p) == 't') mul=1e12; + else if(tolower(*p) == 'g') mul=1e9; + else if(*p == 'M') mul=1e6; + else if(*p == 'm') mul=1e-3; + else if(tolower(*p) == 'k') mul=1e3; + else if(tolower(*p) == 'u') mul=1e-6; + else if(tolower(*p) == 'n') mul=1e-9; + else if(tolower(*p) == 'p') mul=1e-12; + else if(tolower(*p) == 'f') mul=1e-15; + else if(tolower(*p) == 'a') mul=1e-18; + else mul = 1.0; + a *= mul; + } + return a; +} + + char *my_itoa(int i) { static char s[30]; diff --git a/src/xschem.h b/src/xschem.h index dee64246..6ee6bf48 100644 --- a/src/xschem.h +++ b/src/xschem.h @@ -1589,6 +1589,7 @@ extern size_t my_strcat(int id, char **, const char *); extern size_t my_mstrcat(int id, char **str, const char *append_str, ...); extern char *my_itoa(int i); extern double atof_spice(const char *s); +extern double atof_eng(const char *s); /* same as atof_spice, but recognizes 'M' as Mega and 'm' as Milli */ extern char *dtoa(double i); extern char *dtoa_eng(double i); extern char *dtoa_prec(double i); diff --git a/src/xschem.tcl b/src/xschem.tcl index 2eef5c05..35d2e7d5 100644 --- a/src/xschem.tcl +++ b/src/xschem.tcl @@ -5611,6 +5611,7 @@ proc input_line {txt {cmd {}} {preset {}} {w 12}} { pack .dialog.f2 -expand yes -fill x bind .dialog {.dialog.f2.cancel invoke} bind .dialog {.dialog.f2.ok invoke} + tkwait visibility .dialog grab set .dialog focus .dialog.f1.e tkwait window .dialog