fixed a potential parse error in edit_prop if list_tokens returns a non list due to malformed input. Added @spice_get_diff_voltage to get a voltage difference between 2 nodes.

This commit is contained in:
Stefan Frederik 2022-09-22 17:35:14 +02:00
parent 03842a3e4a
commit e61ef2eabf
3 changed files with 85 additions and 6 deletions

View File

@ -3070,6 +3070,74 @@ const char *translate(int inst, const char* s)
}
}
}
else if(strcmp(token,"@spice_get_diff_voltage")==0 )
{
int start_level; /* hierarchy level where waves were loaded */
if((start_level = sch_waves_loaded()) >= 0 && xctx->graph_annotate_p>=0) {
int multip;
int no_of_pins= (xctx->inst[inst].ptr + xctx->sym)->rects[PINLAYER];
if(no_of_pins == 2) {
char *fqnet1 = NULL, *fqnet2 = NULL;
const char *path = xctx->sch_path[xctx->currsch] + 1;
const char *net1, *net2;
size_t len;
int idx1, idx2;
double val = 0.0, val1 = 0.0, val2 = 0.0;
char valstr[120];
if(path) {
int skip = 0;
/* skip path components that are above the level where raw file was loaded */
while(*path && skip < start_level) {
if(*path == '.') skip++;
path++;
}
prepare_netlist_structs(0);
net1 = net_name(inst, 0, &multip, 0, 0);
len = strlen(path) + strlen(net1) + 1;
dbg(0, "net1=%s\n", net1);
fqnet1 = my_malloc(1552, len);
my_snprintf(fqnet1, len, "%s%s", path, net1);
strtolower(fqnet1);
net2 = net_name(inst, 1, &multip, 0, 0);
len = strlen(path) + strlen(net2) + 1;
dbg(0, "net2=%s\n", net2);
fqnet2 = my_malloc(1554, len);
my_snprintf(fqnet2, len, "%s%s", path, net2);
strtolower(fqnet2);
dbg(0, "translate(): fqnet1=%s start_level=%d\n", fqnet1, start_level);
dbg(0, "translate(): fqnet2=%s start_level=%d\n", fqnet2, start_level);
idx1 = get_raw_index(fqnet1);
if(idx1 >= 0) {
val1 = xctx->graph_values[idx1][xctx->graph_annotate_p];
}
idx2 = get_raw_index(fqnet2);
if(idx2 >= 0) {
val2 = xctx->graph_values[idx2][xctx->graph_annotate_p];
}
val = val1 - val2;
if(idx1 < 0 || idx2 < 0) {
my_snprintf(valstr, S(valstr), "");
} else if( fabs(val) < 1.0e-5) {
my_snprintf(valstr, S(valstr), "0");
} else if( fabs(val) < 1.0e-3 && val != 0.0) {
my_snprintf(valstr, S(valstr), "%.4e", val);
} else {
my_snprintf(valstr, S(valstr), "%.4g", val);
}
len = strlen(valstr);
if(len) {
STR_ALLOC(&result, len + result_pos, &size);
memcpy(result+result_pos, valstr, len+1);
result_pos += len;
}
dbg(0, "inst %d, fqnet1=%s fqnet2=%s idx1=%d idx2=%d, val1=%g val2=%g valstr=%s\n",
inst, fqnet1, fqnet2, idx1, idx2, val1, val2, valstr);
my_free(1553, &fqnet1);
my_free(1555, &fqnet2);
}
}
}
}
else if(strcmp(token,"@spice_get_current")==0 )
{
int start_level; /* hierarchy level where waves were loaded */
@ -3092,7 +3160,7 @@ const char *translate(int inst, const char* s)
strtolower(dev);
len = strlen(path) + strlen(dev) + 11; /* some extra chars for i(..) wrapper */
dbg(1, "dev=%s\n", dev);
fqdev = my_malloc(1548, len);
fqdev = my_malloc(1556, len);
if(!sim_is_xyce) {
int prefix=dev[0];
int vsource = (prefix == 'v') || (prefix == 'e');
@ -3126,7 +3194,7 @@ const char *translate(int inst, const char* s)
result_pos += len;
}
dbg(1, "inst %d, dev=%s, fqdev=%s idx=%d valstr=%s\n", inst, dev, fqdev, idx, valstr);
my_free(1549, &fqdev);
my_free(1557, &fqdev);
my_free(1551, &dev);
}
}

View File

@ -675,11 +675,22 @@ proc sim_is_xyce {} {
return 0
}
# wrapper to "xschem list_tokens" comand to handle non list results
# usually as a result of malformed input strings
proc list_tokens {s} {
set res [xschem list_tokens $s 0]
if {[string is list $res]} {
return $res
} else {
return [split $res]
}
}
# generates a proper list, trimming multiple separators
proc tolist {s} {
set s [string trim $s]
regsub -all {[\t\n ]+} $s { } s
if { [string is list $s] } {
if {[string is list $s] } {
return $s
} else {
return [split $s]
@ -3487,7 +3498,7 @@ proc edit_prop {txtlabel} {
checkbutton .dialog.f2.r1 -text "No change properties" -variable no_change_attrs -state normal
checkbutton .dialog.f2.r2 -text "Preserve unchanged props" -variable preserve_unchanged_attrs -state normal
checkbutton .dialog.f2.r3 -text "Copy cell" -variable copy_cell -state normal
set tok_list "<ALL> [xschem list_tokens $retval 0]"
set tok_list "<ALL> [list_tokens $retval]"
set selected_tok {<ALL>}
set old_selected_tok {<ALL>}
label .dialog.f2.r4 -text { Edit Attr:}
@ -3615,7 +3626,7 @@ proc text_line {txtlabel clear {preserve_disabled disabled} } {
set X [expr {[winfo pointerx .dialog] - 60}]
set Y [expr {[winfo pointery .dialog] - 35}]
set tok_list "<ALL> [xschem list_tokens $retval 0]"
set tok_list "<ALL> [list_tokens $retval]"
set selected_tok {<ALL>}
set old_selected_tok {<ALL>}
bind .dialog <Configure> {

View File

@ -12,4 +12,4 @@ L 15 -2.5 -12.5 2.5 -12.5 {}
L 15 -2.5 12.5 2.5 12.5 {}
B 5 -1.25 -21.25 1.25 -18.75 {name=p dir=in}
B 5 -1.25 18.75 1.25 21.25 {name=m dir=in}
T {tcleval([ngspice::get_diff_voltage @@p @@m ])} 1.875 -6.09375 0 0 0.2 0.2 {layer=15 hcenter=true}
T {@spice_get_diff_voltage} 1.875 -6.09375 0 0 0.2 0.2 {layer=15 hcenter=true}