if strings passed to translate() are encloded in tcleval(...) the translated string is passed to tcl for evaluation. This allows to display formula results for symbols, for example capacitance values based on W and L: tcleval(C=[ expr @ca * @L * @W ]) --> tcl will substitute the calculated value: C=1.234e-14

This commit is contained in:
Stefan Schippers 2020-10-12 17:25:57 +02:00
parent 42a8e55956
commit 26fdaae83d
3 changed files with 29 additions and 23 deletions

View File

@ -2739,28 +2739,6 @@ const char *translate(int inst, char* s)
/* memcpy(result+result_pos,xctx.sch[xctx.currsch], tmp+1); */
memcpy(result+result_pos, xctx.current_name, tmp+1);
result_pos+=tmp;
} else if (!strncmp(token,"@tcleval", 8)) {
size_t s;
char *tclcmd=NULL;
char *instname = NULL;
const char *c;
my_strdup(643, &instname,xctx.inst[inst].instname);
if (!instname) my_strdup(1188, &instname, get_tok_value((xctx.inst[inst].ptr+ xctx.sym)->templ, "name", 0));
s = token_pos + strlen(instname) + strlen(xctx.inst[inst].name) + 100;
tclcmd = my_malloc(1191, s);
Tcl_ResetResult(interp);
my_snprintf(tclcmd, s, "tclpropeval {%s} {%s} {%s}", token, instname, xctx.inst[inst].name);
dbg(1, "tclpropeval {%s} {%s} {%s}", token, instname, xctx.inst[inst].name);
tcleval(tclcmd);
tmp = strlen( c = tclresult());
if(result_pos + tmp>=size) {
size=(1+(result_pos + tmp) / CADCHUNKALLOC) * CADCHUNKALLOC;
my_realloc(1189, &result,size);
}
memcpy(result+result_pos, c, tmp+1);
result_pos+=tmp;
my_free(1190, &tclcmd);
my_free(1192, &instname);
} else if(strcmp(token,"@prop_ptr")==0 && xctx.inst[inst].prop_ptr) {
tmp=strlen(xctx.inst[inst].prop_ptr);
if(result_pos + tmp>=size)
@ -2845,6 +2823,22 @@ const char *translate(int inst, char* s)
}
dbg(2, "translate(): returning %s\n", result);
my_free(1067, &token);
if(result && strstr(result, "tcleval(")== result) {
size_t s;
char *tclcmd=NULL;
char *instname = NULL;
my_strdup(643, &instname,xctx.inst[inst].instname);
if (!instname) my_strdup(1188, &instname, get_tok_value((xctx.inst[inst].ptr+ xctx.sym)->templ, "name", 0));
s = result_pos + strlen(instname) + strlen(xctx.inst[inst].name) + 100;
tclcmd = my_malloc(1191, s);
my_snprintf(tclcmd, s, "tclpropeval2 {%s} {%s} {%s}", result, instname, xctx.inst[inst].name);
dbg(1, "tclpropeval2 {%s} {%s} {%s}", result, instname, xctx.inst[inst].name);
tcleval(tclcmd);
my_strdup2(1189, &result, tclresult());
my_free(1190, &tclcmd);
my_free(1192, &instname);
}
return result;
}

View File

@ -1860,6 +1860,18 @@ proc tclpropeval {s instname symname} {
return [eval $s]
}
# this hook is called in translate() if whole string is contained in a tcleval(...) construct
proc tclpropeval2 {s instname symname} {
# puts ">>>> $s $instname $symname"
regsub {^tcleval\(} $s {} s
regsub {\) *$} $s {} s
if { [catch {subst $s} res] } {
puts "tclpropeval2: $res instance: $instname"
set res {}
}
return $res
}
#20171005
proc attach_labels_to_inst {} {
global use_lab_wire use_label_prefix custom_label_prefix rcode do_all_inst rotated_text

View File

@ -169,7 +169,7 @@ set disable_unique_names 0
# set cairo_font_line_spacing 1.0
#### Specify a font
set cairo_font_name {Monospace Regular}
set cairo_font_name {Liberation Sans}
#### Lift up text by some zoom-corrected pixels for
#### better compatibility wrt no cairo version.