Right click on a graph cursor allows to set the cursor position numerically

This commit is contained in:
stefan schippers 2024-01-05 02:08:13 +01:00
parent 7982c67bf6
commit 90ce40da2c
4 changed files with 63 additions and 0 deletions

View File

@ -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);

View File

@ -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];

View File

@ -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);

View File

@ -5611,6 +5611,7 @@ proc input_line {txt {cmd {}} {preset {}} {w 12}} {
pack .dialog.f2 -expand yes -fill x
bind .dialog <Escape> {.dialog.f2.cancel invoke}
bind .dialog <Return> {.dialog.f2.ok invoke}
tkwait visibility .dialog
grab set .dialog
focus .dialog.f1.e
tkwait window .dialog