From 7abceb334418bc66eab9189fbc57712b8d8beab2 Mon Sep 17 00:00:00 2001 From: Stefan Frederik Date: Tue, 20 Sep 2022 00:12:27 +0200 Subject: [PATCH] fix regression in ngspice::get_current, simplified voltage reporting in net label symbols --- src/callback.c | 1 + src/ngspice_backannotate.tcl | 8 +++++--- src/save.c | 1 + src/token.c | 10 ++++++++++ src/xinit.c | 1 + src/xschem.h | 1 + xschem_library/devices/ammeter.sym | 2 +- xschem_library/devices/lab_pin.sym | 2 +- xschem_library/devices/lab_wire.sym | 2 +- xschem_library/devices/spice_probe.sym | 2 +- xschem_library/devices/vsource.sym | 2 +- xschem_library/examples/poweramp.sch | 18 +++++++++--------- 12 files changed, 33 insertions(+), 17 deletions(-) diff --git a/src/callback.c b/src/callback.c index a25538ab..4e4173dc 100644 --- a/src/callback.c +++ b/src/callback.c @@ -242,6 +242,7 @@ static void backannotate_at_cursor_b_pos(xRect *r, Graph_ctx *gr) } dbg(1, "xx=%g, p=%d\n", xx, p); tcleval("array unset ::ngspice::ngspice_data"); + xctx->graph_backannotate_p = p; for(i = 0; i < xctx->graph_nvars; i++) { char s[100]; my_snprintf(s, S(s), "%.4g", xctx->graph_values[i][p]); diff --git a/src/ngspice_backannotate.tcl b/src/ngspice_backannotate.tcl index fd5081e3..d6d52243 100644 --- a/src/ngspice_backannotate.tcl +++ b/src/ngspice_backannotate.tcl @@ -115,14 +115,16 @@ proc ngspice::get_current {n} { set prefix [string range $n 0 0] set path [string range [xschem get sch_path] 1 end] set n $path$n - if { ![sim_is_xyce] && $path ne {} } { - set n $prefix.$n + if { ![sim_is_xyce] } { + if {$path ne {} } { + set n $prefix.$n + } if { ![regexp $prefix {[ve]}] } { set n @$n } } set n i($n) - # puts "ngspice::get_current --> $n" + puts "ngspice::get_current --> $n" set err [catch {set ::ngspice::ngspice_data($n)} res] if { $err } { set res {?} diff --git a/src/save.c b/src/save.c index 5e7aca7b..5f20bd2d 100644 --- a/src/save.c +++ b/src/save.c @@ -455,6 +455,7 @@ void free_rawfile(int dr) if(xctx->graph_raw_schname) my_free(1393, &xctx->graph_raw_schname); xctx->graph_datasets = 0; xctx->graph_nvars = 0; + xctx->graph_backannotate_p = -1; int_hash_free(xctx->graph_raw_table); if(deleted && dr) draw(); } diff --git a/src/token.c b/src/token.c index c245f99d..611fadc3 100644 --- a/src/token.c +++ b/src/token.c @@ -3015,6 +3015,16 @@ const char *translate(int inst, const char* s) memcpy(result+result_pos,xctx->inst[inst].prop_ptr, tmp+1); result_pos+=tmp; } + else if(strcmp(token,"@spice_get_voltage")==0 ) + { + if(xctx->graph_values && xctx->graph_backannotate_p>=0) { + int multip; + int no_of_pins= (xctx->inst[inst].ptr + xctx->sym)->rects[PINLAYER]; + if(no_of_pins>0) { + dbg(0, "inst %d, net=%s\n",inst, net_name(inst,0, &multip, 0, 0)); + } + } + } else if(strcmp(token,"@schvhdlprop")==0 && xctx->schvhdlprop) { tmp=strlen(xctx->schvhdlprop); diff --git a/src/xinit.c b/src/xinit.c index 83208439..fa523b3c 100644 --- a/src/xinit.c +++ b/src/xinit.c @@ -450,6 +450,7 @@ static void alloc_xschem_data(const char *top_path, const char *win_path) xctx->graph_left = 0; xctx->graph_lastsel = -1; xctx->graph_sim_type = 0; /* type of sim, 1: Tran, 2: Dc, 3: Ac */ + xctx->graph_backannotate_p = -1; /* point in raw file to use for annotating voltages/currents/etc */ xctx->graph_struct.hilight_wave = -1; /* index of wave */ xctx->graph_raw_schname = NULL; xctx->wires = 0; diff --git a/src/xschem.h b/src/xschem.h index 43d4228c..591254ff 100644 --- a/src/xschem.h +++ b/src/xschem.h @@ -909,6 +909,7 @@ typedef struct { int graph_left; int graph_lastsel; /* last graph that was clicked (selected) */ int graph_sim_type; /* type of sim, 1: Tran, 2: Dc, 3: Ac */ + int graph_backannotate_p; /* point in raw file to use for annotating schematic voltages/currents/etc */ Int_hashentry **graph_raw_table; /* when descending hierarchy xctx->current_name changes, xctx->graph_raw_schname * holds the name of the top schematic from which the raw file was loaded */ diff --git a/xschem_library/devices/ammeter.sym b/xschem_library/devices/ammeter.sym index 6458dc84..17731543 100644 --- a/xschem_library/devices/ammeter.sym +++ b/xschem_library/devices/ammeter.sym @@ -16,5 +16,5 @@ B 5 -2.5 27.5 2.5 32.5 {name=minus dir=inout propag=0} T {@name} 15 -18.75 0 0 0.2 0.2 {} T {@#0:net_name} 10 -28.75 0 0 0.15 0.15 {layer=15} T {@#1:net_name} 10 20 0 0 0.15 0.15 {layer=15} -T {tcleval(i=[ngspice::get_current @name\\])} 12.5 0 0 0 0.2 0.2 {layer=15 +T {tcleval(i=[ ngspice::get_current @name ])} 12.5 0 0 0 0.2 0.2 {layer=15 hide=true} diff --git a/xschem_library/devices/lab_pin.sym b/xschem_library/devices/lab_pin.sym index de4fe4bd..a1bb548d 100644 --- a/xschem_library/devices/lab_pin.sym +++ b/xschem_library/devices/lab_pin.sym @@ -9,4 +9,4 @@ S {} E {} B 5 -1.25 -1.25 1.25 1.25 {name=p dir=in} T {@lab} -7.5 -8.125 0 1 0.33 0.33 {} -T {tcleval( [ ngspice::get_node v($\{path\}@@p\\) ] )} -16.875 17.65625 0 1 0.2 0.2 {vcenter=true layer=15 hide=true} +T {tcleval( [ ngspice::get_voltage @@p ] )} -16.875 11.40625 0 1 0.2 0.2 {layer=15 hide=true} diff --git a/xschem_library/devices/lab_wire.sym b/xschem_library/devices/lab_wire.sym index 175023a5..59c852f4 100644 --- a/xschem_library/devices/lab_wire.sym +++ b/xschem_library/devices/lab_wire.sym @@ -9,4 +9,4 @@ S {} E {} B 5 -1.25 -1.25 1.25 1.25 {name=p dir=in} T {@lab} -2.5 -1.25 2 0 0.27 0.27 {} -T {tcleval( [ ngspice::get_node v($\{path\}@@p\\) ] )} -1.875 -24.84375 0 1 0.2 0.2 {vcenter=true layer=15 hide=true} +T {tcleval( [ ngspice::get_voltage @@p ] )} -1.875 -24.84375 0 1 0.2 0.2 {vcenter=true layer=15 hide=true} diff --git a/xschem_library/devices/spice_probe.sym b/xschem_library/devices/spice_probe.sym index 801e54d6..4c58768b 100644 --- a/xschem_library/devices/spice_probe.sym +++ b/xschem_library/devices/spice_probe.sym @@ -23,4 +23,4 @@ L 15 21.25 -20 25 -20 {} L 15 25 -23.75 25 -20 {} L 15 25 -23.75 27.8125 -23.75 {} B 5 -0.46875 -0.46875 0.46875 0.46875 {name=p dir=xxx} -T {tcleval( [ ngspice::get_node v($\{path\}@@p\\) ] )} 11.875 -34.84375 0 0 0.2 0.2 {vcenter=true layer=15 hide=true} +T {tcleval( [ ngspice::get_voltage @@p ] )} 11.875 -34.84375 0 0 0.2 0.2 {vcenter=true layer=15 hide=true} diff --git a/xschem_library/devices/vsource.sym b/xschem_library/devices/vsource.sym index 8a860f68..9bf6cb61 100644 --- a/xschem_library/devices/vsource.sym +++ b/xschem_library/devices/vsource.sym @@ -18,5 +18,5 @@ T {@name} 20 -18.75 0 0 0.2 0.2 {} T {@value} 20 6.25 0 0 0.2 0.2 {} T {@#0:net_name} 10 -28.75 0 0 0.15 0.15 {layer=15} T {@#1:net_name} 10 20 0 0 0.15 0.15 {layer=15} -T {tcleval(i=[ngspice::get_current @name\\])} 20 -6.25 0 0 0.2 0.2 {layer=15 +T {tcleval(i=[ ngspice::get_current @name ])} 20 -6.25 0 0 0.2 0.2 {layer=15 hide=true} diff --git a/xschem_library/examples/poweramp.sch b/xschem_library/examples/poweramp.sch index 44e71728..e9f1a958 100644 --- a/xschem_library/examples/poweramp.sch +++ b/xschem_library/examples/poweramp.sch @@ -19,8 +19,8 @@ B 2 1200 -500 1880 -310 {flags=graph y1 = -0.0059 y2 = 11 divy = 6 -x1=0.024209 -x2=0.0246776 +x1=0.00757478 +x2=0.00916695 divx=10 node="i(v.x1.vu) i(v.x0.vu) @@ -32,8 +32,8 @@ B 2 1200 -830 1880 -520 {flags=graph y1 = -49 y2 = 59 divy = 12 -x1=0.024209 -x2=0.0246776 +x1=0.00757478 +x2=0.00916695 divx=10 node="outp outm @@ -47,8 +47,8 @@ B 2 1200 -1020 1880 -830 {flags=graph y1 = 2.4e-11 y2 = 840 divy = 6 -x1=0.024209 -x2=0.0246776 +x1=0.00757478 +x2=0.00916695 divx=10 @@ -60,8 +60,8 @@ B 2 1200 -310 1880 -120 {flags=graph y1 = 0.0077 y2 = 850 divy = 6 -x1=0.024209 -x2=0.0246776 +x1=0.00757478 +x2=0.00916695 divx=10 @@ -284,7 +284,7 @@ node="[ngspice::get_current \{r19[i]\}]" descr = current } C {ngspice_get_expr.sym} 820 -510 2 0 {name=r29 -node="[format %.4g [expr ([ngspice::get_voltage outm] - [ngspice::get_voltage outp]) * [ngspice::get_current \{r1[i]\}]]] W" +node="[format %.4g [expr ([ngspice::get_voltage outm] - [ngspice::get_voltage outp]) * [ngspice::get_current \{r1[i]\}]]] " descr = power } C {launcher.sym} 780 -190 0 0 {name=h3