various tcl_hook2() additions on instance names to handle procedures, fix bbox calculation in xschem replace_symbol command

This commit is contained in:
stefan schippers 2023-05-01 14:37:10 +02:00
parent 6b857f7b7d
commit 4c3b4d0321
14 changed files with 57 additions and 32 deletions

View File

@ -992,7 +992,7 @@ void delete_files(void)
rebuild_selected_array();
if(xctx->lastsel && xctx->sel_array[0].type==ELEMENT) {
my_snprintf(str, S(str), "delete_files {%s}",
abs_sym_path(xctx->inst[xctx->sel_array[0].n].name, ""));
abs_sym_path(tcl_hook2(xctx->inst[xctx->sel_array[0].n].name), ""));
} else {
my_snprintf(str, S(str), "delete_files {%s}",
abs_sym_path(xctx->sch[xctx->currsch], ""));
@ -1037,6 +1037,15 @@ int place_symbol(int pos, const char *symbol_name, double x, double y, short rot
}
dbg(1, "place_symbol(): load_file_dialog returns: name=%s\n",name);
my_strncpy(name, rel_sym_path(name), S(name));
if(strstr(name, "tcleval(") == name) {
my_strncpy(name, tcl_hook2(name), S(name));
} else if(strstr(name, "/tcleval(") || strstr(name, "tcleval(") == name) {
my_strncpy(name, get_cell(name, 0), S(name));
my_strncpy(name, tcl_hook2(name), S(name));
} else {
my_strncpy(name, rel_sym_path(name), S(name));
}
dbg(1, "place_symbol(): after tcl_hook2: name=%s\n",name);
if(name[0]) {
if(first_call && to_push_undo) xctx->push_undo();
} else return 0;
@ -1142,7 +1151,7 @@ void symbol_in_new_window(int new_process)
else new_schematic("create", NULL, filename);
}
else {
my_strncpy(filename, abs_sym_path(xctx->inst[xctx->sel_array[0].n].name, ""), S(filename));
my_strncpy(filename, abs_sym_path(tcl_hook2(xctx->inst[xctx->sel_array[0].n].name), ""), S(filename));
if(!check_loaded(filename, win_path)) {
if(new_process) new_xschem_process(filename, 1);
else new_schematic("create", NULL, filename);

View File

@ -125,7 +125,7 @@ static void start_place_symbol(double mx, double my)
rebuild_selected_array();
if(xctx->lastsel && xctx->sel_array[0].type==ELEMENT) {
tclvareval("set INITIALINSTDIR [file dirname {",
abs_sym_path(xctx->inst[xctx->sel_array[0].n].name, ""), "}]", NULL);
abs_sym_path(tcl_hook2(xctx->inst[xctx->sel_array[0].n].name), ""), "}]", NULL);
}
unselect_all(1);
xctx->mx_double_save = xctx->mousex_snap;
@ -1856,7 +1856,7 @@ int callback(const char *winpath, int event, int mx, int my, KeySym key,
}
else if(xctx->sel_array[0].type==ELEMENT) {
my_snprintf(str, S(str), "edit_file {%s}",
abs_sym_path(xctx->inst[xctx->sel_array[0].n].name, ""));
abs_sym_path(tcl_hook2(xctx->inst[xctx->sel_array[0].n].name), ""));
tcleval(str);
}

View File

@ -559,14 +559,12 @@ void draw_symbol(int what,int c, int n,int layer,short tmp_flip, short rot,
}
if( (layer==TEXTWIRELAYER && !(xctx->inst[n].flags&2) ) ||
(xctx->sym_txt && (layer==TEXTLAYER) && (xctx->inst[n].flags&2) ) ) {
const char *txtptr;
for(j=0;j< symptr->texts; ++j)
{
text = symptr->text[j];
if(!text.txt_ptr || !text.txt_ptr[0] || text.xscale*FONTWIDTH*xctx->mooz<1) continue;
if(!xctx->show_hidden_texts && (text.flags & HIDE_TEXT)) continue;
if( hide && text.txt_ptr && strcmp(text.txt_ptr, "@symname") && strcmp(text.txt_ptr, "@name") ) continue;
txtptr= translate(n, text.txt_ptr);
ROTATION(rot, flip, 0.0,0.0,text.x0,text.y0,x1,y1);
textlayer = c;
/* do not allow custom text color on hilighted instances */
@ -577,6 +575,7 @@ void draw_symbol(int what,int c, int n,int layer,short tmp_flip, short rot,
}
/* display PINLAYER colored instance texts even if PINLAYER disabled */
if(xctx->inst[n].color == -PINLAYER || xctx->enable_layer[textlayer]) {
char *txtptr = NULL;
#if HAS_CAIRO==1
textfont = symptr->text[j].font;
if((textfont && textfont[0]) || (symptr->text[j].flags & (TEXT_BOLD | TEXT_OBLIQUE | TEXT_ITALIC))) {
@ -597,11 +596,13 @@ void draw_symbol(int what,int c, int n,int layer,short tmp_flip, short rot,
cairo_font_face_destroy(xctx->cairo_font);
}
#endif
my_strdup2(_ALLOC_ID_, &txtptr, translate(n, text.txt_ptr));
dbg(1, "drawing string: str=%s prop=%s\n", txtptr, text.prop_ptr);
draw_string(textlayer, what, txtptr,
(text.rot + ( (flip && (text.rot & 1) ) ? rot+2 : rot) ) & 0x3,
flip^text.flip, text.hcenter, text.vcenter,
x0+x1, y0+y1, text.xscale, text.yscale);
my_free(_ALLOC_ID_, &txtptr);
#if HAS_CAIRO!=1
drawrect(textlayer, END, 0.0, 0.0, 0.0, 0.0, 0);
drawline(textlayer, END, 0.0, 0.0, 0.0, 0.0, 0, NULL);
@ -744,20 +745,21 @@ void draw_temp_symbol(int what, GC gc, int n,int layer,short tmp_flip, short rot
if(layer==PROPERTYLAYER && xctx->sym_txt)
{
const char *txtptr;
char *txtptr = NULL;
for(j=0;j< symptr->texts; ++j)
{
text = symptr->text[j];
if(!text.txt_ptr || !text.txt_ptr[0] || text.xscale*FONTWIDTH*xctx->mooz<1) continue;
if(!xctx->show_hidden_texts && (text.flags & HIDE_TEXT)) continue;
txtptr= translate(n, text.txt_ptr);
ROTATION(rot, flip, 0.0,0.0,text.x0,text.y0,x1,y1);
#if HAS_CAIRO==1
customfont = set_text_custom_font(&text);
#endif
my_strdup2(_ALLOC_ID_, &txtptr, translate(n, text.txt_ptr));
if(txtptr[0]) draw_temp_string(gc, what, txtptr,
(text.rot + ( (flip && (text.rot & 1) ) ? rot+2 : rot) ) & 0x3,
flip^text.flip, text.hcenter, text.vcenter, x0+x1, y0+y1, text.xscale, text.yscale);
my_free(_ALLOC_ID_, &txtptr);
#if HAS_CAIRO==1
if(customfont) {
cairo_restore(xctx->cairo_ctx);

View File

@ -1293,8 +1293,11 @@ static void update_symbol(const char *result, int x)
prefix=0;
sym_number = -1;
if(strcmp(symbol, xctx->inst[*ii].name)) {
char *sym = NULL;
set_modify(1);
sym_number=match_symbol(symbol); /* check if exist */
my_strdup2(_ALLOC_ID_, &sym, tcl_hook2(symbol));
sym_number=match_symbol(sym); /* check if exist */
my_free(_ALLOC_ID_, &sym);
if(sym_number>=0) {
prefix=(get_tok_value((xctx->sym+sym_number)->templ, "name",0))[0]; /* get new symbol prefix */
}

View File

@ -1380,7 +1380,7 @@ int sym_vs_sch_pins()
err |= 1;
tcleval("show_infotext"); /* critical error: force ERC window showing */
for(j = 0; j < xctx->instances; ++j) {
if(!xctx->x_strcmp(xctx->inst[j].name, xctx->sym[i].name)) {
if(!xctx->x_strcmp(tcl_hook2(xctx->inst[j].name), xctx->sym[i].name)) {
xctx->inst[i].color = -PINLAYER;
xctx->hilight_nets=1;
}
@ -1398,7 +1398,8 @@ int sym_vs_sch_pins()
err |= 1;
tcleval("show_infotext"); /* critical error: force ERC window showing */
for(j = 0; j < xctx->instances; ++j) {
if(!xctx->x_strcmp(xctx->inst[j].name, xctx->sym[i].name)) {
dbg(1, "inst.name=%s, sym.name=%s\n", tcl_hook2(xctx->inst[j].name), xctx->sym[i].name);
if(!xctx->x_strcmp(tcl_hook2(xctx->inst[j].name), xctx->sym[i].name)) {
xctx->inst[i].color = -PINLAYER;
xctx->hilight_nets=1;
}
@ -1433,7 +1434,7 @@ int sym_vs_sch_pins()
err |= 1;
tcleval("show_infotext"); /* critical error: force ERC window showing */
for(j = 0; j < xctx->instances; ++j) {
if(!xctx->x_strcmp(xctx->inst[j].name, xctx->sym[i].name)) {
if(!xctx->x_strcmp(tcl_hook2(xctx->inst[j].name), xctx->sym[i].name)) {
xctx->inst[i].color = -PINLAYER;
xctx->hilight_nets=1;
}
@ -1458,7 +1459,7 @@ int sym_vs_sch_pins()
err |= 1;
tcleval("show_infotext"); /* critical error: force ERC window showing */
for(k = 0; k < xctx->instances; ++k) {
if(!xctx->x_strcmp(xctx->inst[k].name, xctx->sym[i].name)) {
if(!xctx->x_strcmp(tcl_hook2(xctx->inst[k].name), xctx->sym[i].name)) {
xctx->inst[i].color = -PINLAYER;
xctx->hilight_nets=1;
}

View File

@ -2383,6 +2383,7 @@ void link_symbols_to_instances(int from)
{
int cond, i, merge = 1;
char *type=NULL;
char *name = NULL;
if(from < 0 ) {
from = 0;
@ -2392,7 +2393,9 @@ void link_symbols_to_instances(int from)
dbg(2, "link_symbols_to_instances(): inst=%d\n", i);
dbg(2, "link_symbols_to_instances(): matching inst %d name=%s \n",i, xctx->inst[i].name);
dbg(2, "link_symbols_to_instances(): -------\n");
xctx->inst[i].ptr = match_symbol(xctx->inst[i].name);
my_strdup2(_ALLOC_ID_, &name, tcl_hook2(xctx->inst[i].name));
xctx->inst[i].ptr = match_symbol(name);
my_free(_ALLOC_ID_, &name);
}
for(i = from; i < xctx->instances; ++i) {
type=xctx->sym[xctx->inst[i].ptr].type;
@ -3864,7 +3867,7 @@ void create_sch_from_sym(void)
my_strncpy(schname, abs_sym_path(sch, ""), S(schname));
my_free(_ALLOC_ID_, &sch);
if(!schname[0]) {
my_strncpy(schname, add_ext(abs_sym_path(xctx->inst[xctx->sel_array[0].n].name, ""),
my_strncpy(schname, add_ext(abs_sym_path(tcl_hook2(xctx->inst[xctx->sel_array[0].n].name), ""),
".sch"), S(schname));
}
if( !stat(schname, &buf) ) {

View File

@ -646,7 +646,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
}
else if(xctx->sel_array[0].type==ELEMENT) {
my_snprintf(name, S(name), "edit_file {%s}",
abs_sym_path(xctx->inst[xctx->sel_array[0].n].name, ""));
abs_sym_path(tcl_hook2(xctx->inst[xctx->sel_array[0].n].name), ""));
tcleval(name);
}
}
@ -2351,7 +2351,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
rebuild_selected_array();
if(xctx->lastsel && xctx->sel_array[0].type==ELEMENT) {
tclvareval("set INITIALINSTDIR [file dirname {",
abs_sym_path(xctx->inst[xctx->sel_array[0].n].name, ""), "}]", NULL);
abs_sym_path(tcl_hook2(xctx->inst[xctx->sel_array[0].n].name), ""), "}]", NULL);
}
unselect_all(1);
xctx->mx_double_save = xctx->mousex_snap;
@ -2828,6 +2828,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
char *type;
char *name=NULL;
char *ptr=NULL;
char *sym = NULL;
bbox(START,0.0,0.0,0.0,0.0);
my_strncpy(symbol, argv[3], S(symbol));
xctx->push_undo();
@ -2837,7 +2838,11 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
xctx->prep_net_structs=0;
xctx->prep_hi_structs=0;
}
sym_number=match_symbol(symbol);
symbol_bbox(inst, &xctx->inst[inst].x1, &xctx->inst[inst].y1, &xctx->inst[inst].x2, &xctx->inst[inst].y2);
bbox(ADD, xctx->inst[inst].x1, xctx->inst[inst].y1, xctx->inst[inst].x2, xctx->inst[inst].y2);
my_strdup(_ALLOC_ID_, &sym, tcl_hook2(symbol));
sym_number=match_symbol(sym);
my_free(_ALLOC_ID_, &sym);
if(sym_number>=0)
{
prefix=(get_tok_value( (xctx->sym+sym_number)->templ , "name",0))[0]; /* get new symbol prefix */
@ -2848,8 +2853,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
/* changing ysmbol, otherwise i might end up deleting non allocated data. */
my_strdup2(_ALLOC_ID_, &xctx->inst[inst].name, rel_sym_path(symbol));
xctx->inst[inst].ptr=sym_number;
symbol_bbox(inst, &xctx->inst[inst].x1, &xctx->inst[inst].y1, &xctx->inst[inst].x2, &xctx->inst[inst].y2);
bbox(ADD, xctx->inst[inst].x1, xctx->inst[inst].y1, xctx->inst[inst].x2, xctx->inst[inst].y2);
dbg(0, "bbox1: %g %g %g %g\n", xctx->inst[inst].x1, xctx->inst[inst].y1, xctx->inst[inst].x2, xctx->inst[inst].y2);
my_strdup(_ALLOC_ID_, &name, xctx->inst[inst].instname);
if(name && name[0] )
{

View File

@ -450,7 +450,7 @@ int global_spice_netlist(int global) /* netlister driver */
if(!xctx->hilight_nets) xctx->hilight_nets = saved_hilight_nets;
}
/* restore hilight flags from errors found analyzing top level before descending hierarchy */
for(i=0;i<xctx->instances; ++i) xctx->inst[i].color = stored_flags[i];
for(i=0;i<xctx->instances; ++i) if(!xctx->inst[i].color) xctx->inst[i].color = stored_flags[i];
propagate_hilights(1, 0, XINSERT_NOREPLACE);
draw_hilight_net(1);
my_free(_ALLOC_ID_, &stored_flags);

View File

@ -240,7 +240,8 @@ int global_tedax_netlist(int global) /* netlister driver */
if(!xctx->hilight_nets) xctx->hilight_nets = saved_hilight_nets;
}
/* restore hilight flags from errors found analyzing top level before descending hierarchy */
for(i=0;i<xctx->instances; ++i) xctx->inst[i].color = stored_flags[i];
for(i=0;i<xctx->instances; ++i) if(!xctx->inst[i].color) xctx->inst[i].color = stored_flags[i];
propagate_hilights(1, 0, XINSERT_NOREPLACE);
draw_hilight_net(1);
my_free(_ALLOC_ID_, &stored_flags);

View File

@ -3102,7 +3102,7 @@ const char *translate(int inst, const char* s)
result_pos+=tmp;
}
} else if(strcmp(token,"@sym_last_modified")==0) {
my_strncpy(file_name, abs_sym_path(xctx->inst[inst].name, ""), S(file_name));
my_strncpy(file_name, abs_sym_path(tcl_hook2(xctx->inst[inst].name), ""), S(file_name));
if(!stat(file_name , &time_buf)) {
tm=localtime(&(time_buf.st_mtime) );
tmp=strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", tm);

View File

@ -390,7 +390,8 @@ int global_verilog_netlist(int global) /* netlister driver */
if(!xctx->hilight_nets) xctx->hilight_nets = saved_hilight_nets;
}
/* restore hilight flags from errors found analyzing top level before descending hierarchy */
for(i=0;i<xctx->instances; ++i) xctx->inst[i].color = stored_flags[i];
for(i=0;i<xctx->instances; ++i) if(!xctx->inst[i].color) xctx->inst[i].color = stored_flags[i];
propagate_hilights(1, 0, XINSERT_NOREPLACE);
draw_hilight_net(1);
my_free(_ALLOC_ID_, &stored_flags);

View File

@ -491,7 +491,8 @@ int global_vhdl_netlist(int global) /* netlister driver */
if(!xctx->hilight_nets) xctx->hilight_nets = saved_hilight_nets;
}
/* restore hilight flags from errors found analyzing top level before descending hierarchy */
for(i=0;i<xctx->instances; ++i) xctx->inst[i].color = stored_flags[i];
for(i=0;i<xctx->instances; ++i) if(!xctx->inst[i].color) xctx->inst[i].color = stored_flags[i];
propagate_hilights(1, 0, XINSERT_NOREPLACE);
draw_hilight_net(1);
my_free(_ALLOC_ID_, &stored_flags);
@ -667,7 +668,7 @@ int vhdl_block_netlist(FILE *fd, int i)
if(!strcmp(get_tok_value( (xctx->inst[l].ptr+ xctx->sym)->prop_ptr, "vhdl_ignore",0 ), "true") ) {
continue;
}
if(!xctx->x_strcmp(xctx->sym[j].name,xctx->inst[l].name))
if(!xctx->x_strcmp(xctx->sym[j].name, tcl_hook2(xctx->inst[l].name)))
{
found=1; break;
}

View File

@ -682,7 +682,7 @@ int compare_schematics(const char *f)
for(i = 0; i < xctx->instances; ++i) {
l = 1024 + strlen(xctx->inst[i].prop_ptr ? xctx->inst[i].prop_ptr : "");
my_realloc(_ALLOC_ID_, &s, l);
my_snprintf(s, l, "C %s %g %g %d %d %s", xctx->inst[i].name,
my_snprintf(s, l, "C %s %g %g %d %d %s", tcl_hook2(xctx->inst[i].name),
xctx->inst[i].x0, xctx->inst[i].y0, xctx->inst[i].rot, xctx->inst[i].flip,
xctx->inst[i].prop_ptr ? xctx->inst[i].prop_ptr : "");
int_hash_lookup(&table1, s, i, XINSERT_NOREPLACE);
@ -744,7 +744,7 @@ int compare_schematics(const char *f)
for(i = 0; i < xctx->instances; ++i) {
l = 1024 + strlen(xctx->inst[i].prop_ptr ? xctx->inst[i].prop_ptr : "");
my_realloc(_ALLOC_ID_, &s, l);
my_snprintf(s, l, "C %s %g %g %d %d %s", xctx->inst[i].name,
my_snprintf(s, l, "C %s %g %g %d %d %s", tcl_hook2(xctx->inst[i].name),
xctx->inst[i].x0, xctx->inst[i].y0, xctx->inst[i].rot, xctx->inst[i].flip,
xctx->inst[i].prop_ptr ? xctx->inst[i].prop_ptr : "");
int_hash_lookup(&table2, s, i, XINSERT_NOREPLACE);
@ -790,7 +790,7 @@ int compare_schematics(const char *f)
for(i = 0; i < xctx->instances; ++i) {
l = 1024 + strlen(xctx->inst[i].prop_ptr ? xctx->inst[i].prop_ptr : "");
my_realloc(_ALLOC_ID_,&s, l);
my_snprintf(s, l, "C %s %g %g %d %d %s", xctx->inst[i].name,
my_snprintf(s, l, "C %s %g %g %d %d %s", tcl_hook2(xctx->inst[i].name),
xctx->inst[i].x0, xctx->inst[i].y0, xctx->inst[i].rot, xctx->inst[i].flip,
xctx->inst[i].prop_ptr ? xctx->inst[i].prop_ptr : "");
found = int_hash_lookup(&table2, s, i, XLOOKUP);

View File

@ -3652,11 +3652,11 @@ proc property_search {} {
proc tclpropeval {s instname symname} {
# puts "tclpropeval: $s $instname $symname"
global env debug_var
if {$debug_var <=-1} {puts "tclpropeval: $s"}
regsub {^@tcleval\(} $s {} s
regsub {\)([ \t\n]*)$} $s {\1} s
if { [catch {eval $s} res] } {
if { $debug_var<=-1 } { puts "tclpropeval warning: $res"}
# puts "tclpropeval: $s $instname $symname"
if { [catch {subst $s} res] } {
# puts $res
set res ?\n
}
return $res