when descending from a modified schematic with highlight nets and not saving schematic before descending, clear highlights to avoid inconsistent state when returning back. save() and save_schematic() have more decent return values

This commit is contained in:
Stefan Frederik 2021-11-22 00:26:49 +01:00
parent fddd3f84fb
commit 1c37e7eeee
3 changed files with 36 additions and 22 deletions

View File

@ -352,25 +352,26 @@ int samefile(const char *fa, const char *fb)
return 0; /* not same of one of the two not existing */ return 0; /* not same of one of the two not existing */
} }
int save(int confirm) /* 20171006 add confirm */
{
int cancel;
int save_ok;
save_ok=0; /* return value:
cancel=0; * 1 : file saved or not needed to save since no change
* -1 : user cancel
* 0 : file not saved due to errors or per user request
*/
int save(int confirm)
{
if(xctx->modified) if(xctx->modified)
{ {
if(confirm) { if(confirm) {
tcleval("ask_save"); tcleval("ask_save");
if(!strcmp(tclresult(), "") ) cancel=1; if(!strcmp(tclresult(), "") ) return -1; /* user clicks "Cancel" */
if(!strcmp(tclresult(), "yes") ) save_ok = save_schematic(xctx->sch[xctx->currsch]); else if(!strcmp(tclresult(), "yes") ) return save_schematic(xctx->sch[xctx->currsch]);
else return 0; /* user clicks "no" */
} else { } else {
save_ok = save_schematic(xctx->sch[xctx->currsch]); return save_schematic(xctx->sch[xctx->currsch]);
} }
} }
if(save_ok==-1) return 1; return 1; /* circuit not changed: always succeeed */
return cancel;
} }
void saveas(const char *f, int type) /* changed name from ask_save_file to saveas 20121201 */ void saveas(const char *f, int type) /* changed name from ask_save_file to saveas 20121201 */
@ -1038,7 +1039,7 @@ void descend_schematic(int instnumber)
if(!res[0]) return; if(!res[0]) return;
dbg(1, "descend_schematic(): saving: %s\n",res); dbg(1, "descend_schematic(): saving: %s\n",res);
save_ok = save_schematic(res); save_ok = save_schematic(res);
if(save_ok==-1) return; if(save_ok==0) return;
} }
dbg(1, "descend_schematic(): inst type: %s\n", (xctx->inst[xctx->sel_array[0].n].ptr+ xctx->sym)->type); dbg(1, "descend_schematic(): inst type: %s\n", (xctx->inst[xctx->sel_array[0].n].ptr+ xctx->sym)->type);
@ -1051,7 +1052,18 @@ void descend_schematic(int instnumber)
if(xctx->modified) if(xctx->modified)
{ {
if(save(1)) return; int ret;
ret = save(1);
/* if circuit is changed but not saved before descending
* state will be inconsistent when returning, can not propagare hilights
* save() return value:
* 1 : file saved
* -1 : user cancel
* 0 : file not saved due to errors or per user request
*/
if(ret == 0) clear_all_hilights();
if(ret == -1) return; /* user cancel */
} }
/* build up current hierarchy path */ /* build up current hierarchy path */
@ -1136,7 +1148,7 @@ void go_back(int confirm) /* 20171006 add confirm */
char filename[PATH_MAX]; char filename[PATH_MAX];
int prev_sch_type; int prev_sch_type;
save_ok=0; save_ok=1;
prev_sch_type = xctx->netlist_type; /* if CAD_SYMBOL_ATTRS do not hilight_parent_pins */ prev_sch_type = xctx->netlist_type; /* if CAD_SYMBOL_ATTRS do not hilight_parent_pins */
if(xctx->currsch>0) if(xctx->currsch>0)
{ {
@ -1151,7 +1163,7 @@ void go_back(int confirm) /* 20171006 add confirm */
save_ok = save_schematic(xctx->sch[xctx->currsch]); save_ok = save_schematic(xctx->sch[xctx->currsch]);
} }
} }
if(save_ok==-1) return; if(save_ok==0) return;
unselect_all(); unselect_all();
remove_symbols(); remove_symbols();
from_embedded_sym=0; from_embedded_sym=0;

View File

@ -961,6 +961,10 @@ void make_schematic(const char *schname)
} }
/* ALWAYS call with absolute path in schname!!! */ /* ALWAYS call with absolute path in schname!!! */
/* return value:
* 0 : did not save
* 1 : schematic saved
*/
int save_schematic(const char *schname) /* 20171020 added return value */ int save_schematic(const char *schname) /* 20171020 added return value */
{ {
FILE *fd; FILE *fd;
@ -971,7 +975,7 @@ int save_schematic(const char *schname) /* 20171020 added return value */
top_path = xctx->top_path[0] ? xctx->top_path : "."; top_path = xctx->top_path[0] ? xctx->top_path : ".";
if( strcmp(schname,"") ) my_strncpy(xctx->sch[xctx->currsch], schname, S(xctx->sch[xctx->currsch])); if( strcmp(schname,"") ) my_strncpy(xctx->sch[xctx->currsch], schname, S(xctx->sch[xctx->currsch]));
else return -1; else return 0;
dbg(1, "save_schematic(): currsch=%d name=%s\n",xctx->currsch, schname); dbg(1, "save_schematic(): currsch=%d name=%s\n",xctx->currsch, schname);
dbg(1, "save_schematic(): sch[currsch]=%s\n", xctx->sch[xctx->currsch]); dbg(1, "save_schematic(): sch[currsch]=%s\n", xctx->sch[xctx->currsch]);
dbg(1, "save_schematic(): abs_sym_path=%s\n", abs_sym_path(xctx->sch[xctx->currsch], "")); dbg(1, "save_schematic(): abs_sym_path=%s\n", abs_sym_path(xctx->sch[xctx->currsch], ""));
@ -985,9 +989,7 @@ int save_schematic(const char *schname) /* 20171020 added return value */
if(xctx->time_last_modify && xctx->time_last_modify != buf.st_mtime) { if(xctx->time_last_modify && xctx->time_last_modify != buf.st_mtime) {
Tcl_VarEval(interp, "ask_save \"Schematic file: ", name, Tcl_VarEval(interp, "ask_save \"Schematic file: ", name,
"\nHas been changed since opening.\nSave anyway?\" 0", NULL); "\nHas been changed since opening.\nSave anyway?\" 0", NULL);
if(strcmp(tclresult(), "yes") ) { if(strcmp(tclresult(), "yes") ) return 0;
return -1;
}
} }
} }
@ -995,7 +997,7 @@ int save_schematic(const char *schname) /* 20171020 added return value */
{ {
fprintf(errfp, "save_schematic(): problems opening file %s \n",name); fprintf(errfp, "save_schematic(): problems opening file %s \n",name);
tcleval("alert_ {file opening for write failed!} {}"); tcleval("alert_ {file opening for write failed!} {}");
return -1; return 0;
} }
unselect_all(); unselect_all();
write_xschem_file(fd); write_xschem_file(fd);
@ -1013,7 +1015,7 @@ int save_schematic(const char *schname) /* 20171020 added return value */
if(!strstr(xctx->sch[xctx->currsch], ".xschem_embedded_")) { if(!strstr(xctx->sch[xctx->currsch], ".xschem_embedded_")) {
set_modify(0); set_modify(0);
} }
return 0; return 1;
} }
/* from == -1 --> link symbols to all instances, from 0 to instances-1 */ /* from == -1 --> link symbols to all instances, from 0 to instances-1 */

View File

@ -4142,7 +4142,7 @@ proc build_widgets { {topwin {} } } {
$topwin.menubar.tools.menu add command -label "Select conn. wires, stop at junctions" -accelerator {Ctrl-Righ Butt.} \ $topwin.menubar.tools.menu add command -label "Select conn. wires, stop at junctions" -accelerator {Ctrl-Righ Butt.} \
-command { xschem connected_nets 1 } -command { xschem connected_nets 1 }
$topwin.menubar.hilight.menu add command -label {Highlight net-pin name mismatches on selected instancs} \ $topwin.menubar.hilight.menu add command -label {Highlight net-pin name mismatches on selected instances} \
-command "xschem net_pin_mismatch" \ -command "xschem net_pin_mismatch" \
-accelerator {Shift-X} -accelerator {Shift-X}
$topwin.menubar.hilight.menu add command -label {Highlight duplicate instance names} \ $topwin.menubar.hilight.menu add command -label {Highlight duplicate instance names} \