better node color tagging in graph edit property dialog

This commit is contained in:
Stefan Frederik 2022-02-13 02:51:14 +01:00
parent fbeae175dd
commit a6b4d998d1
2 changed files with 54 additions and 14 deletions

View File

@ -507,8 +507,7 @@ int get_raw_index(const char *node)
return -1;
}
/* <<<< */
#define STACKMAX 200
#define PLUS -2
#define MINUS -3
#define MULT -4
@ -516,12 +515,16 @@ int get_raw_index(const char *node)
#define POW -6
#define SIN -7
#define COS -8
#define ABS -9
#define SGN -10
#define INTEG -11
#define AVG -12
#define DERIV -13
#define EXP -9
#define LN -10
#define LOG10 -11
#define ABS -12
#define SGN -13
#define INTEG -14
#define AVG -15
#define DERIV -16
#define NUMBER -60
typedef struct {
int i;
double d;
@ -535,15 +538,20 @@ void plot_raw_custom_data(int sweep_idx, int first, int last, const char *expr)
int i, p, idx;
const char *n;
char *endptr, *ntok_copy = NULL, *ntok_save, *ntok_ptr;
Stack1 stack1[200];
double v, stack2[200];
Stack1 stack1[STACKMAX];
double v, stack2[STACKMAX];
int stackptr1 = 0, stackptr2 = 0;
SPICE_DATA *y = xctx->graph_values[xctx->graph_nvars]; /* custom plot data column */
SPICE_DATA *x = xctx->graph_values[sweep_idx];
my_strdup2(574, &ntok_copy, expr);
ntok_ptr = ntok_copy;
while( (n = my_strtok_r(ntok_ptr, " ", "", &ntok_save)) ) {
while( (n = my_strtok_r(ntok_ptr, " \t\n", "", &ntok_save)) ) {
if(stackptr1 >= STACKMAX -1) {
dbg(0, "stack overflow in graph expression parsing. Interrupted\n");
my_free(576, &ntok_copy);
return;
}
ntok_ptr = NULL;
dbg(1, " plot_raw_custom_data(): n = %s\n", n);
if(!strcmp(n, "+")) stack1[stackptr1++].i = PLUS;
@ -555,6 +563,9 @@ void plot_raw_custom_data(int sweep_idx, int first, int last, const char *expr)
else if(!strcmp(n, "cos()")) stack1[stackptr1++].i = COS;
else if(!strcmp(n, "abs()")) stack1[stackptr1++].i = ABS;
else if(!strcmp(n, "sgn()")) stack1[stackptr1++].i = SGN;
else if(!strcmp(n, "exp()")) stack1[stackptr1++].i = EXP;
else if(!strcmp(n, "ln()")) stack1[stackptr1++].i = LN;
else if(!strcmp(n, "log10()")) stack1[stackptr1++].i = LOG10;
else if(!strcmp(n, "integ()")) stack1[stackptr1++].i = INTEG;
else if(!strcmp(n, "avg()")) stack1[stackptr1++].i = AVG;
else if(!strcmp(n, "deriv()")) stack1[stackptr1++].i = DERIV;
@ -566,6 +577,7 @@ void plot_raw_custom_data(int sweep_idx, int first, int last, const char *expr)
idx = get_raw_index(n);
if(idx == -1) {
dbg(1, "plot_raw_custom_data(): no data found: %s\n", n);
my_free(645, &ntok_copy);
return; /* no data found in raw file */
}
stack1[stackptr1].i = idx;
@ -616,6 +628,15 @@ void plot_raw_custom_data(int sweep_idx, int first, int last, const char *expr)
else if(stack1[i].i == ABS) {
stack2[stackptr2 - 1] = fabs(stack2[stackptr2 - 1]);
}
else if(stack1[i].i == EXP) {
stack2[stackptr2 - 1] = exp(stack2[stackptr2 - 1]);
}
else if(stack1[i].i == LN) {
stack2[stackptr2 - 1] = log(stack2[stackptr2 - 1]);
}
else if(stack1[i].i == LOG10) {
stack2[stackptr2 - 1] = log10(stack2[stackptr2 - 1]);
}
else if(stack1[i].i == SGN) {
stack2[stackptr2 - 1] = stack2[stackptr2 - 1] > 0.0 ? 1 :
stack2[stackptr2 - 1] < 0.0 ? -1 : 0;

View File

@ -1350,6 +1350,14 @@ proc graph_edit_wave {n n_wave} {
# replace selected text:
# .graphdialog.center.right.text1 replace sel.first sel.last BUS
#
# programmatically select text:
# .graphdialog.center.right.text1 tag add sel 1.0 {end - 1 chars}
# clear selection
# .graphdialog.center.right.text1 tag remove sel 1.0 end
# get position of cursor:
# .graphdialog.center.right.text1 index insert
# set cursor position:
# .graphdialog.center.right.text1 mark set insert 2.18
# add nodes from provided list of {node color} ....
@ -1505,9 +1513,20 @@ proc graph_update_nodelist {} {
# tagging nodes in text widget:
set col [xschem getprop rect 2 $graph_selected color]
set col [string trim $col " \n"]
set tt [.graphdialog.center.right.text1 search -all -nolinestop -regexp -count cc {"[^"]+"|[^ \n]+} 1.0] ;#"4vim
set regx {(?:"[^"]+")|(?:[^\n \t]+)}
set txt [.graphdialog.center.right.text1 get 1.0 {end - 1 chars}]
set tt {}
set cc {}
set start 0
while {[regexp -indices -start $start $regx $txt idx]} {
lappend tt [lindex $idx 0]
set start [expr {[lindex $idx 1] + 1}]
lappend cc $start
}
set n 0
if { [info exists cc] && ($tt ne {}) } {
if { $tt ne {} } {
foreach t $tt c $cc {
set col_idx [lindex $col $n]
# add missing colors
@ -1516,8 +1535,8 @@ proc graph_update_nodelist {} {
lappend col $graph_sel_color
}
set b [lindex $colors $col_idx]
.graphdialog.center.right.text1 tag add t$n $t "$t + $c chars"
.graphdialog.center.right.text1 tag configure t$n -background $b
.graphdialog.center.right.text1 tag add t$n "1.0 + $t chars" "1.0 + $c chars"
.graphdialog.center.right.text1 tag configure t$n -background $b -selectbackground grey60
incr n
}
# remove excess colors