add autoload checkbutton in graph properties to automatically load or not custom graph-specified raw files

This commit is contained in:
stefan schippers 2024-06-23 15:59:22 +02:00
parent f25d3f8db5
commit 89eb02f188
5 changed files with 77 additions and 33 deletions

View File

@ -2300,12 +2300,15 @@ int graph_fullxzoom(int i, Graph_ctx *gr, int dataset)
char *custom_rawfile = NULL; /* "rawfile" attr. set in graph: load and switch to specified raw */
char *sim_type = NULL;
int k, save_datasets = -1, save_npoints = -1;
int autoload = 0;
Raw *raw = NULL;
autoload = !strboolcmp(get_tok_value(r->prop_ptr,"autoload",0), "1");
if(autoload == 0) autoload = 2;
my_strdup2(_ALLOC_ID_, &custom_rawfile, get_tok_value(r->prop_ptr,"rawfile",0));
my_strdup2(_ALLOC_ID_, &sim_type, get_tok_value(r->prop_ptr,"sim_type",0));
if((i == xctx->graph_master) && custom_rawfile[0]) {
extra_rawfile(1, custom_rawfile, sim_type[0] ? sim_type : xctx->raw->sim_type, -1.0, -1.0);
extra_rawfile(autoload, custom_rawfile, sim_type[0] ? sim_type : xctx->raw->sim_type, -1.0, -1.0);
}
idx = get_raw_index(find_nth(get_tok_value(r->prop_ptr, "sweep", 0), ", ", "\"", 0, 1), NULL);
dbg(1, "graph_fullxzoom(): sweep idx=%d\n", idx);
@ -2316,7 +2319,7 @@ int graph_fullxzoom(int i, Graph_ctx *gr, int dataset)
my_strdup2(_ALLOC_ID_, &sim_type,
get_tok_value(xctx->rect[GRIDLAYER][xctx->graph_master].prop_ptr,"sim_type",0));
if(custom_rawfile[0]) {
extra_rawfile(1, custom_rawfile, sim_type[0] ? sim_type : xctx->raw->sim_type, -1.0, -1.0);
extra_rawfile(autoload, custom_rawfile, sim_type[0] ? sim_type : xctx->raw->sim_type, -1.0, -1.0);
}
}
@ -2382,9 +2385,10 @@ int graph_fullyzoom(xRect *r, Graph_ctx *gr, int graph_dataset)
Raw *raw = NULL;
char *tmp_ptr = NULL;
int save_extra_idx = -1;
int save_datasets = -1, save_npoints = -1;
int autoload = 0, save_datasets = -1, save_npoints = -1;
autoload = !strboolcmp(get_tok_value(r->prop_ptr,"autoload",0), "1");
if(autoload == 0) autoload = 2;
dbg(1, "graph_fullyzoom(): graph_dataset=%d\n", graph_dataset);
my_strdup2(_ALLOC_ID_, &node, get_tok_value(r->prop_ptr,"node",0));
my_strdup2(_ALLOC_ID_, &sweep, get_tok_value(r->prop_ptr,"sweep",0));
@ -2404,7 +2408,7 @@ int graph_fullyzoom(xRect *r, Graph_ctx *gr, int graph_dataset)
char str_extra_idx[30];
if(sch_waves_loaded() != -1 && custom_rawfile[0]) {
extra_rawfile(1, custom_rawfile, sim_type[0] ? sim_type : xctx->raw->sim_type, -1.0, -1.0);
extra_rawfile(autoload, custom_rawfile, sim_type[0] ? sim_type : xctx->raw->sim_type, -1.0, -1.0);
}
raw = xctx->raw;
@ -2423,7 +2427,7 @@ int graph_fullyzoom(xRect *r, Graph_ctx *gr, int graph_dataset)
sim_type[0] ? sim_type : xctx->raw->sim_type);
dbg(1, "node_rawfile=|%s| node_sim_type=|%s|\n", node_rawfile, node_sim_type);
if(node_rawfile && node_rawfile[0]) {
extra_rawfile(1, node_rawfile, node_sim_type, -1.0, -1.0);
extra_rawfile(autoload, node_rawfile, node_sim_type, -1.0, -1.0);
raw = xctx->raw;
}
my_free(_ALLOC_ID_, &node_rawfile);
@ -3411,7 +3415,7 @@ int find_closest_wave(int i, Graph_ctx *gr)
int wcnt = 0, idx, expression;
char *express = NULL;
xRect *r = &xctx->rect[GRIDLAYER][i];
int closest_dataset = -1;
int autoload = 0, closest_dataset = -1;
double min=-1.0;
Raw *raw = NULL;
char *custom_rawfile = NULL; /* "rawfile" attr. set in graph: load and switch to specified raw */
@ -3422,6 +3426,9 @@ int find_closest_wave(int i, Graph_ctx *gr)
return -1;
}
if(gr->digital) return -1;
autoload = !strboolcmp(get_tok_value(r->prop_ptr,"autoload",0), "1");
if(autoload == 0) autoload = 2;
yval = G_Y(xctx->mousey);
xval = G_X(xctx->mousex);
/* get data to plot */
@ -3431,7 +3438,7 @@ int find_closest_wave(int i, Graph_ctx *gr)
my_strdup2(_ALLOC_ID_, &custom_rawfile, get_tok_value(r->prop_ptr,"rawfile",0));
my_strdup2(_ALLOC_ID_, &sim_type, get_tok_value(r->prop_ptr,"sim_type",0));
if(sch_waves_loaded()!= -1 && custom_rawfile[0]) {
extra_rawfile(1, custom_rawfile, sim_type[0] ? sim_type : xctx->raw->sim_type, -1.0, -1.0);
extra_rawfile(autoload, custom_rawfile, sim_type[0] ? sim_type : xctx->raw->sim_type, -1.0, -1.0);
}
raw = xctx->raw;
@ -3597,6 +3604,7 @@ void draw_graph(int i, const int flags, Graph_ctx *gr, void *ct)
/* draw stuff */
if(flags & 8) {
int autoload = 0;
char *tmp_ptr = NULL;
int save_datasets = -1, save_npoints = -1;
#if !defined(__unix__) && HAS_CAIRO==1
@ -3605,6 +3613,8 @@ void draw_graph(int i, const int flags, Graph_ctx *gr, void *ct)
clear_cairo_surface(xctx->cairo_save_ctx, gr->sx1, gr->sy1, sw, sh);
clear_cairo_surface(xctx->cairo_ctx, gr->sx1, gr->sy1, sw, sh);
#endif
autoload = !strboolcmp(get_tok_value(r->prop_ptr,"autoload",0), "1");
if(autoload == 0) autoload = 2;
/* graph box, gridlines and axes */
draw_graph_grid(gr, ct);
/* get data to plot */
@ -3626,11 +3636,14 @@ void draw_graph(int i, const int flags, Graph_ctx *gr, void *ct)
char *nd = NULL;
char str_extra_idx[30];
nptr = NULL;
measure_p = -1;
measure_x = 0.0;
measure_prev_x = 0.0;
if(sch_waves_loaded()!= -1 && custom_rawfile[0]) {
extra_rawfile(1, custom_rawfile, sim_type[0] ? sim_type : xctx->raw->sim_type, -1.0, -1.0);
if(extra_rawfile(autoload, custom_rawfile, sim_type[0] ? sim_type : xctx->raw->sim_type, -1.0, -1.0) == 0) {
continue;
}
}
raw = xctx->raw;
@ -3656,7 +3669,12 @@ void draw_graph(int i, const int flags, Graph_ctx *gr, void *ct)
sim_type[0] ? sim_type : xctx->raw->sim_type);
dbg(1, "node_rawfile=|%s| node_sim_type=|%s|\n", node_rawfile, node_sim_type);
if(node_rawfile && node_rawfile[0]) {
extra_rawfile(1, node_rawfile, node_sim_type, -1.0, -1.0);
if(extra_rawfile(autoload, node_rawfile, node_sim_type, -1.0, -1.0) == 0) {
my_free(_ALLOC_ID_, &node_rawfile);
my_free(_ALLOC_ID_, &node_sim_type);
my_free(_ALLOC_ID_, &nd);
continue;
}
raw = xctx->raw;
}
my_free(_ALLOC_ID_, &node_rawfile);
@ -3692,7 +3710,7 @@ void draw_graph(int i, const int flags, Graph_ctx *gr, void *ct)
dbg(1, "ntok_copy=|%s|, bus_msb=|%s|\n", ntok_copy, bus_msb ? bus_msb : "NULL");
ctok = my_strtok_r(cptr, " ", "", 0, &savec);
stok = my_strtok_r(sptr, "\t\n ", "\"", 0, &saves);
nptr = cptr = sptr = NULL;
cptr = sptr = NULL;
dbg(1, "ntok_copy=%s ctok=%s\n", ntok_copy, ctok? ctok: "NULL");
if(ctok && ctok[0]) wc = atoi(ctok);
if(wc < 0) wc = 4;

View File

@ -531,7 +531,7 @@ static int read_dataset(FILE *fd, Raw **rawptr, const char *type)
tcleval("alert_ {read_dataset(): ASCII raw files can not be read. "
"Use binary format in ngspice (set filetype=binary)}");
extra_rawfile(3, NULL, NULL, -1.0, -1.0);
free_rawfile(rawptr, 0);
/* free_rawfile(rawptr, 0); */
exit_status = 0;
goto read_dataset_done;
}
@ -614,7 +614,7 @@ static int read_dataset(FILE *fd, Raw **rawptr, const char *type)
if(n < 1) {
dbg(0, "read_dataset(): WAARNING: malformed raw file, aborting\n");
extra_rawfile(3, NULL, NULL, -1.0, -1.0);
free_rawfile(rawptr, 0);
/* free_rawfile(rawptr, 0); */
exit_status = 0;
goto read_dataset_done;
}
@ -643,7 +643,7 @@ static int read_dataset(FILE *fd, Raw **rawptr, const char *type)
if(n < 1) {
dbg(0, "read_dataset(): WAARNING: malformed raw file, aborting\n");
extra_rawfile(3, NULL, NULL, -1.0, -1.0);
free_rawfile(rawptr, 0);
/* free_rawfile(rawptr, 0); */
exit_status = 0;
goto read_dataset_done;
}
@ -656,7 +656,7 @@ static int read_dataset(FILE *fd, Raw **rawptr, const char *type)
if(n < 1) {
dbg(0, "read_dataset(): WAARNING: malformed raw file, aborting\n");
extra_rawfile(3, NULL, NULL, -1.0, -1.0);
free_rawfile(rawptr, 0);
/* free_rawfile(rawptr, 0); */
exit_status = 0;
goto read_dataset_done;
}
@ -679,7 +679,7 @@ static int read_dataset(FILE *fd, Raw **rawptr, const char *type)
if(n < 2) {
dbg(0, "read_dataset(): WAARNING: malformed raw file, aborting\n");
extra_rawfile(3, NULL, NULL, -1.0, -1.0);
free_rawfile(rawptr, 0);
/* free_rawfile(rawptr, 0); */
exit_status = 0;
goto read_dataset_done;
}
@ -728,6 +728,7 @@ void free_rawfile(Raw **rawptr, int dr)
Raw *raw;
if(!rawptr || !*rawptr) {
dbg(0, "free_rawfile(): no raw file to clear\n");
if(dr) draw();
return;
}

View File

@ -327,7 +327,8 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
tclsetboolvar("live_cursor2_backannotate", 1);
/* clear all raw files */
extra_rawfile(3, NULL, NULL, -1.0, -1.0);
free_rawfile(&xctx->raw, 1);
/* free_rawfile(&xctx->raw, 1); */
draw();
raw_read(f, &xctx->raw, "op", -1.0, -1.0);
if(level >= 0) {
xctx->raw->level = level;
@ -3934,7 +3935,8 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
{
if(!xctx) {Tcl_SetResult(interp, not_avail, TCL_STATIC); return TCL_ERROR;}
extra_rawfile(3, NULL, NULL, -1.0, -1.0); /* unload additional raw files */
free_rawfile(&xctx->raw, 1); /* unload base (current) raw file */
/* free_rawfile(&xctx->raw, 1); */ /* unload base (current) raw file */
draw();
Tcl_ResetResult(interp);
}
@ -3960,7 +3962,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
double sweep1 = -1.0, sweep2 = -1.0;
tcleval("array unset ngspice::ngspice_data");
extra_rawfile(3, NULL, NULL, -1.0, -1.0);
free_rawfile(&xctx->raw, 0);
/* free_rawfile(&xctx->raw, 0); */
my_snprintf(f, S(f),"regsub {^~/} {%s} {%s/}", argv[2], home_dir);
tcleval(f);
my_strncpy(f, tclresult(), S(f));
@ -3988,10 +3990,11 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
if(!xctx) {Tcl_SetResult(interp, not_avail, TCL_STATIC); return TCL_ERROR;}
if(sch_waves_loaded() >= 0) {
extra_rawfile(3, NULL, NULL, -1.0, -1.0);
free_rawfile(&xctx->raw, 1);
/* free_rawfile(&xctx->raw, 1); */
draw();
} else {
extra_rawfile(3, NULL, NULL, -1.0, -1.0);
free_rawfile(&xctx->raw, 0);
/* free_rawfile(&xctx->raw, 0); */
if(argc > 2) raw_read_from_attr(&xctx->raw, argv[2], -1.0, -1.0);
else raw_read_from_attr(&xctx->raw, NULL, -1.0, -1.0);
if(sch_waves_loaded() >= 0) {
@ -5466,13 +5469,14 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
if(!xctx) {Tcl_SetResult(interp, not_avail, TCL_STATIC); return TCL_ERROR;}
if(sch_waves_loaded() >= 0) {
extra_rawfile(3, NULL, NULL, -1.0, -1.0);
free_rawfile(&xctx->raw, 1);
/* free_rawfile(&xctx->raw, 1); */
draw();
} else if(argc > 2) {
my_snprintf(f, S(f),"regsub {^~/} {%s} {%s/}", argv[2], home_dir);
tcleval(f);
my_strncpy(f, tclresult(), S(f));
extra_rawfile(3, NULL, NULL, -1.0, -1.0);
free_rawfile(&xctx->raw, 0);
/* free_rawfile(&xctx->raw, 0); */
table_read(f);
if(sch_waves_loaded() >= 0) {
draw();

View File

@ -719,7 +719,7 @@ static void delete_schematic_data(int delete_pixmap)
sanitize(NULL);
is_generator(NULL);
extra_rawfile(3, NULL, NULL, -1.0, -1.0);
free_rawfile(&xctx->raw, 0);
/* free_rawfile(&xctx->raw, 0); */
statusmsg("", 1); /* clear allocated string */
record_global_node(2, NULL, NULL); /* delete global node array */
free_xschem_data(); /* delete the xctx struct */

View File

@ -2567,22 +2567,24 @@ proc graph_fill_listbox {} {
global graph_selected
set retval [.graphdialog.top.search get]
set autoload [uplevel #0 {subst [xschem getprop rect 2 $graph_selected autoload 2]}]
set rawfile [uplevel #0 {subst [xschem getprop rect 2 $graph_selected rawfile 2]}]
set sim_type [uplevel #0 {subst [xschem getprop rect 2 $graph_selected sim_type 2]}]
if {$autoload ne {} && $autoload } { set autoload read} else {set autoload switch}
# puts "graph_fill_listbox: $rawfile $sim_type"
if {$rawfile ne {}} {
if {$sim_type eq {table}} {
set res [xschem raw table_read $rawfile $sim_type]
} else {
set res [xschem raw read $rawfile $sim_type]
set res [xschem raw $autoload $rawfile $sim_type]
}
if {$res} {
set retval [graph_get_signal_list [xschem raw_query list] $retval]
xschem raw switch_back
} else {
set retval {}
}
# puts "switch back"
xschem raw switch_back
} else {
set retval [graph_get_signal_list [xschem raw_query list] $retval]
}
@ -2652,6 +2654,7 @@ proc graph_edit_properties {n} {
global graph_bus graph_sort graph_digital graph_selected graph_sel_color
global graph_unlocked graph_schname graph_logx graph_logy cadlayers graph_rainbow
global graph_linewidth_mult graph_change_done has_x graph_dialog_default_geometry
global graph_autoload
if { ![info exists has_x]} {return}
set graph_change_done 0
@ -2676,11 +2679,19 @@ proc graph_edit_properties {n} {
if {[xschem getprop rect 2 $n logy] == 1} {set graph_logy 1}
set graph_digital 0
if {[xschem getprop rect 2 $n digital] == 1} {set graph_digital 1}
if {[regexp {unlocked} [xschem getprop rect 2 $n flags]]} {
set graph_unlocked 1
} else {
set graph_unlocked 0
}
set autoload [xschem getprop rect 2 $n autoload]
if {$autoload ne {} && $autoload} {
set graph_autoload 1
} else {
set graph_autoload 0
}
frame .graphdialog.top
# another row of buttons
@ -2698,7 +2709,7 @@ proc graph_edit_properties {n} {
pack .graphdialog.bottom -side top -fill x
# center-left frame
label .graphdialog.center.left.lab1 -text {Signal list}
label .graphdialog.center.left.lab1 -text {Sig. list}
button .graphdialog.center.left.add -text Add -command {
graph_add_nodes; graph_update_nodelist
}
@ -2717,7 +2728,15 @@ proc graph_edit_properties {n} {
grid columnconfig .graphdialog.center.left 1 -weight 1
# center right frame
label .graphdialog.center.right.lab1 -text { Signals in graph }
label .graphdialog.center.right.lab1 -text { Signals }
checkbutton .graphdialog.center.right.autoload -text {Auto load} -variable graph_autoload \
-command {
if {$graph_autoload} {
xschem setprop rect 2 $graph_selected autoload 1 fast
} else {
xschem setprop rect 2 $graph_selected autoload 0 fast
}
}
label .graphdialog.center.right.lab2 -text { Sim type:}
if { [info tclversion] > 8.4} {
ttk::combobox .graphdialog.center.right.list -values {dc ac tran op sp spectrum noise table} -width 9
@ -2782,11 +2801,12 @@ proc graph_edit_properties {n} {
scrollbar .graphdialog.center.right.yscroll -command {.graphdialog.center.right.text1 yview}
scrollbar .graphdialog.center.right.xscroll -orient horiz -command {.graphdialog.center.right.text1 xview}
grid .graphdialog.center.right.lab1 .graphdialog.center.right.lab2 .graphdialog.center.right.list \
grid .graphdialog.center.right.lab1 .graphdialog.center.right.autoload \
.graphdialog.center.right.lab2 .graphdialog.center.right.list \
.graphdialog.center.right.rawbut .graphdialog.center.right.rawentry -
grid configure .graphdialog.center.right.rawentry -sticky ew
grid .graphdialog.center.right.text1 - - - - .graphdialog.center.right.yscroll -sticky nsew
grid .graphdialog.center.right.xscroll - - - - - -sticky ew
grid .graphdialog.center.right.text1 - - - - - .graphdialog.center.right.yscroll -sticky nsew
grid .graphdialog.center.right.xscroll - - - - - - -sticky ew
grid rowconfig .graphdialog.center.right 0 -weight 0
grid rowconfig .graphdialog.center.right 1 -weight 1 -minsize 3c
grid rowconfig .graphdialog.center.right 2 -weight 0
@ -2794,8 +2814,9 @@ proc graph_edit_properties {n} {
grid columnconfig .graphdialog.center.right 1 -weight 0
grid columnconfig .graphdialog.center.right 2 -weight 0
grid columnconfig .graphdialog.center.right 3 -weight 0
grid columnconfig .graphdialog.center.right 4 -weight 1
grid columnconfig .graphdialog.center.right 5 -weight 0
grid columnconfig .graphdialog.center.right 4 -weight 0
grid columnconfig .graphdialog.center.right 5 -weight 1
grid columnconfig .graphdialog.center.right 6 -weight 0
# bottom frame
button .graphdialog.bottom.cancel -text Cancel -command {