some small code refactoring, allow multiple selected (bold) waves, one per graph, store the bold waves into file

This commit is contained in:
Stefan Frederik 2022-08-27 12:56:33 +02:00
parent 53efa4c381
commit 41acfd91dd
12 changed files with 176 additions and 54 deletions

View File

@ -127,6 +127,9 @@ void deps_default_init(void)
dep_add("libs/types/stdint/*", find_types_stdint);
dep_add("sys/types/size/*", find_types_sizes);
dep_add("libs/time/Sleep/*", find_time_Sleep);
dep_add("libs/time/clock_gettime/*",find_time_clock_gettime);
dep_add("libs/time/CLOCK_MONOTONIC_RAW/*",find_time_CLOCK_MONOTONIC_RAW);
dep_add("libs/time/mach_absolute_time/*", find_time_mach_absolute_time);
dep_add("libs/time/gettimeofday/*", find_time_gettimeofday);
dep_add("libs/time/ftime/*", find_time_ftime);
dep_add("libs/time/timegm/*", find_time_timegm);

View File

@ -145,6 +145,9 @@ int find_io_popen(const char *name, int logdepth, int fatal);
/* find_time.c */
int find_time_usleep(const char *name, int logdepth, int fatal);
int find_time_Sleep(const char *name, int logdepth, int fatal);
int find_time_clock_gettime(const char *name, int logdepth, int fatal);
int find_time_CLOCK_MONOTONIC_RAW(const char *name, int logdepth, int fatal);
int find_time_mach_absolute_time(const char *name, int logdepth, int fatal);
int find_time_gettimeofday(const char *name, int logdepth, int fatal);
int find_time_ftime(const char *name, int logdepth, int fatal);
int find_time_timegm(const char *name, int logdepth, int fatal);

View File

@ -73,6 +73,74 @@ int find_time_Sleep(const char *name, int logdepth, int fatal)
return try_fail(logdepth, "libs/time/Sleep");
}
static int test_clock_gettime(const char *name_, int logdepth, int fatal, const char *print_name, const char *src_name)
{
char name[64], test_c[512], *test_c_in =
NL "#include <stdio.h>"
NL "int main() {"
NL " struct timespec now;"
NL " if (clock_gettime(%s, &now) == 0)"
NL " puts(\"OK\");"
NL " return 0;"
NL "}"
NL;
int len = strlen(name_);
/* truncate "/*" from the end of the node name */
memcpy(name, name_, len);
if (name[len-1] == '*')
name[len-2] = '\0';
sprintf(test_c, test_c_in, src_name);
require("cc/cc", logdepth, fatal);
report("Checking for %s... ", name);
logprintf(logdepth, "test_clock_gettime: trying to find %s...\n", name);
logdepth++;
if (try_icl(logdepth, name, test_c, "#include <time.h>", NULL, NULL))
return 0;
return try_fail(logdepth, name);
}
int find_time_clock_gettime(const char *name, int logdepth, int fatal)
{
return test_clock_gettime(name, logdepth, fatal, "clock_gettime", "CLOCK_MONOTONIC");
}
int find_time_CLOCK_MONOTONIC_RAW(const char *name, int logdepth, int fatal)
{
/* this is Linux-specific */
return test_clock_gettime(name, logdepth, fatal, "clock_gettime", "CLOCK_MONOTONIC_RAW");
}
int find_time_mach_absolute_time(const char *name, int logdepth, int fatal)
{
char *test_c =
NL "#include <stdio.h>"
NL "int main() {"
NL " uint64_t now = mach_absolute_time();"
NL " if (now > 1)"
NL " puts(\"OK\");"
NL " return 0;"
NL "}"
NL;
require("cc/cc", logdepth, fatal);
report("Checking for mach_absolute_time()... ");
logprintf(logdepth, "find_time_mach_absolute_time: trying to find mach_absolute_time...\n");
logdepth++;
if (try_icl(logdepth, "libs/time/mach_absolute_time", test_c, "#include <mach/mach_time.h>", NULL, NULL))
return 0;
return try_fail(logdepth, "libs/time/mach_absolute_time");
}
int find_time_gettimeofday(const char *name, int logdepth, int fatal)
{
char *test_c =

View File

@ -179,3 +179,44 @@ int find_sdl2_ttf(const char *name, int logdepth, int fatal)
return try_fail(logdepth, node);
}
int find_sdl2_GetTicks64(const char *name, int logdepth, int fatal)
{
const char *test_c =
NL "#include <SDL.h>"
NL "#include <stdio.h>"
NL "int main()"
NL "{"
NL " if (SDL_Init(SDL_INIT_TIMER) == 0) {"
NL " SDL_GetTicks64();"
NL " puts(\"OK\");"
NL " }"
NL " return 0;"
NL "}"
NL;
char *cflags, *ldflags;
const char *ocf, *olf;
const char *node = "libs/gui/sdl2_GetTicks64";
if (require("cc/cc", logdepth, fatal))
return 1;
report("Checking for SDL_GetTicks64()... ");
logprintf(logdepth, "SDL_GetTicks64():\n");
logdepth++;
/* extend SDL2's cflags and ldflags */
if (require("libs/gui/sdl2/cflags", logdepth, fatal))
return try_fail(logdepth, node);
if (require("libs/gui/sdl2/ldflags", logdepth, fatal))
return try_fail(logdepth, node);
ocf = get("libs/gui/sdl2/cflags");
olf = get("libs/gui/sdl2/ldflags");
if (try_icl(logdepth, node, test_c, NULL, ocf, olf) != 0)
return 0;
return try_fail(logdepth, node);
}

View File

@ -1,4 +1,5 @@
int find_sdl2(const char *name, int logdepth, int fatal);
int find_sdl2_gfx(const char *name, int logdepth, int fatal);
int find_sdl2_ttf(const char *name, int logdepth, int fatal);
int find_sdl2_GetTicks64(const char *name, int logdepth, int fatal);

View File

@ -52,4 +52,5 @@ void deps_gui_init()
dep_add("libs/gui/sdl2/*", find_sdl2);
dep_add("libs/gui/sdl2_gfx/*", find_sdl2_gfx);
dep_add("libs/gui/sdl2_ttf/*", find_sdl2_ttf);
dep_add("libs/gui/sdl2_GetTicks64/*", find_sdl2_GetTicks64);
}

View File

@ -1635,9 +1635,9 @@ static double get_unit(const char *val)
int schematic_waves_loaded(void)
{
int i;
if(xctx->graph_values && xctx->raw_schname) {
if(xctx->graph_values && xctx->graph_raw_schname) {
for(i = xctx->currsch; i >= 0; i--) {
if( !strcmp(xctx->raw_schname, xctx->sch[i]) ) return 1;
if( !strcmp(xctx->graph_raw_schname, xctx->sch[i]) ) return 1;
}
}
return 0;
@ -1721,11 +1721,11 @@ static SPICE_DATA **get_bus_idx_array(const char *ntok, int *n_bits)
static void set_thick_waves(int what, int wcnt, int wave_col, Graph_ctx *gr)
{
if(what) {
if(gr->hilight_wave[0] == gr->i && gr->hilight_wave[1] == wcnt)
if(gr->hilight_wave == wcnt)
XSetLineAttributes (display, xctx->gc[wave_col],
3 * INT_WIDTH(xctx->lw) ,LineSolid, CapRound , JoinRound);
} else {
if(gr->hilight_wave[0] == gr->i && gr->hilight_wave[1] == wcnt)
if(gr->hilight_wave == wcnt)
XSetLineAttributes (display, xctx->gc[wave_col],
INT_WIDTH(xctx->lw) ,LineSolid, CapRound , JoinRound);
}
@ -2001,6 +2001,11 @@ void setup_graph_data(int i, const int flags, int skip, Graph_ctx *gr)
gr->rw = gr->rx2 - gr->rx1;
gr->rh = gr->ry2 - gr->ry1;
/* wave to display in bold, -1=none */
val=get_tok_value(r->prop_ptr,"hilight_wave",0);
if(val[0]) gr->hilight_wave = atoi(val);
else gr->hilight_wave = -1;
/* get x/y range, grid info etc */
val = get_tok_value(r->prop_ptr,"unitx",0);
gr->unitx_suffix = val[0];
@ -2212,7 +2217,7 @@ static void draw_graph_variables(int wcnt, int wave_color, int n_nodes, int swee
if(yt <= gr->ypos2 && yt >= gr->ypos1) {
#if HAS_CAIRO == 1
if(gr->hilight_wave[0] == gr->i && gr->hilight_wave[1] == wcnt) {
if(gr->hilight_wave == wcnt) {
cairo_select_font_face(xctx->cairo_ctx, "Sans-Serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
cairo_select_font_face(xctx->cairo_save_ctx, "Sans-Serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
}
@ -2220,7 +2225,7 @@ static void draw_graph_variables(int wcnt, int wave_color, int n_nodes, int swee
draw_string(wave_color, NOW, tmpstr, 2, 0, 0, 0,
xt, DW_Y(yt), gr->digtxtsizelab, gr->digtxtsizelab);
#if HAS_CAIRO == 1
if(gr->hilight_wave[0] == gr->i && gr->hilight_wave[1] == wcnt) {
if(gr->hilight_wave == wcnt) {
cairo_select_font_face(xctx->cairo_ctx, "Sans-Serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_select_font_face(xctx->cairo_save_ctx, "Sans-Serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
}
@ -2228,7 +2233,7 @@ static void draw_graph_variables(int wcnt, int wave_color, int n_nodes, int swee
}
} else {
#if HAS_CAIRO == 1
if(gr->hilight_wave[0] == gr->i && gr->hilight_wave[1] == wcnt) {
if(gr->hilight_wave == wcnt) {
cairo_select_font_face(xctx->cairo_ctx, "Sans-Serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
cairo_select_font_face(xctx->cairo_save_ctx, "Sans-Serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
}
@ -2236,7 +2241,7 @@ static void draw_graph_variables(int wcnt, int wave_color, int n_nodes, int swee
draw_string(wave_color, NOW, tmpstr, 0, 0, 0, 0,
gr->rx1 + 2 + gr->rw / n_nodes * wcnt, gr->ry1, gr->txtsizelab, gr->txtsizelab);
#if HAS_CAIRO == 1
if(gr->hilight_wave[0] == gr->i && gr->hilight_wave[1] == wcnt) {
if(gr->hilight_wave == wcnt) {
cairo_select_font_face(xctx->cairo_ctx, "Sans-Serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_select_font_face(xctx->cairo_save_ctx, "Sans-Serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
}
@ -2387,19 +2392,18 @@ int edit_wave_attributes(int what, int i, Graph_ctx *gr)
char s[30];
ret = 1;
if(what == 1) {
int save = gr->hilight_wave;
my_snprintf(s, S(s), "%d %d", i, wcnt);
gr->hilight_wave[0] = i;
gr->hilight_wave[1] = wcnt;
gr->hilight_wave = wcnt;
tclvareval("graph_edit_wave ", s, NULL);
gr->hilight_wave[0] = -1;
gr->hilight_wave[1] = -1;
gr->hilight_wave = save;
} else {
if(gr->hilight_wave[0] == i && gr->hilight_wave[1] == wcnt) {
gr->hilight_wave[0] = -1;
gr->hilight_wave[1] = -1;
if(gr->hilight_wave == wcnt) {
gr->hilight_wave = -1;
my_strdup2(1522, &r->prop_ptr, subst_token(r->prop_ptr, "hilight_wave", my_itoa(gr->hilight_wave)));
} else {
gr->hilight_wave[0] = i;
gr->hilight_wave[1] = wcnt;
gr->hilight_wave = wcnt;
my_strdup2(1525, &r->prop_ptr, subst_token(r->prop_ptr, "hilight_wave", my_itoa(gr->hilight_wave)));
}
}
}
@ -2413,19 +2417,18 @@ int edit_wave_attributes(int what, int i, Graph_ctx *gr)
char s[50];
ret = 1;
if(what == 1) {
int save = gr->hilight_wave;
my_snprintf(s, S(s), "%d %d", i, wcnt);
gr->hilight_wave[0] = i;
gr->hilight_wave[1] = wcnt;
gr->hilight_wave = wcnt;
tclvareval("graph_edit_wave ", s, NULL);
gr->hilight_wave[0] = -1;
gr->hilight_wave[1] = -1;
gr->hilight_wave = save;
} else {
if(gr->hilight_wave[0] == i && gr->hilight_wave[1] == wcnt) {
gr->hilight_wave[0] = -1;
gr->hilight_wave[1] = -1;
if(gr->hilight_wave == wcnt) {
gr->hilight_wave = -1;
my_strdup2(1538, &r->prop_ptr, subst_token(r->prop_ptr, "hilight_wave", my_itoa(gr->hilight_wave)));
} else {
gr->hilight_wave[0] = i;
gr->hilight_wave[1] = wcnt;
gr->hilight_wave = wcnt;
my_strdup2(1539, &r->prop_ptr, subst_token(r->prop_ptr, "hilight_wave", my_itoa(gr->hilight_wave)));
}
}
}

View File

@ -383,16 +383,16 @@ static int read_dataset(FILE *fd)
sscanf(line, "%d %s", &i, varname); /* read index and name of saved waveform */
if(xctx->graph_sim_type == 3) { /* AC */
my_strcat(415, &xctx->graph_names[i << 1], varname);
int_hash_lookup(xctx->raw_table, xctx->graph_names[i << 1], (i << 1), XINSERT_NOREPLACE);
int_hash_lookup(xctx->graph_raw_table, xctx->graph_names[i << 1], (i << 1), XINSERT_NOREPLACE);
if(strstr(varname, "v(") == varname || strstr(varname, "i(") == varname ||
strstr(varname, "V(") == varname || strstr(varname, "I(") == varname)
my_mstrcat(664, &xctx->graph_names[(i << 1) + 1], "ph(", varname + 2, NULL);
else
my_mstrcat(540, &xctx->graph_names[(i << 1) + 1], "ph(", varname, ")", NULL);
int_hash_lookup(xctx->raw_table, xctx->graph_names[(i << 1) + 1], (i << 1) + 1, XINSERT_NOREPLACE);
int_hash_lookup(xctx->graph_raw_table, xctx->graph_names[(i << 1) + 1], (i << 1) + 1, XINSERT_NOREPLACE);
} else {
my_strcat(541, &xctx->graph_names[i], varname);
int_hash_lookup(xctx->raw_table, xctx->graph_names[i], i, XINSERT_NOREPLACE);
int_hash_lookup(xctx->graph_raw_table, xctx->graph_names[i], i, XINSERT_NOREPLACE);
}
/* use hash table to store index number of variables */
dbg(1, "read_dataset(): get node list -> names[%d] = %s\n", i, xctx->graph_names[i]);
@ -429,10 +429,10 @@ void free_rawfile(int dr)
}
if(xctx->graph_npoints) my_free(1413, &xctx->graph_npoints);
xctx->graph_allpoints = 0;
if(xctx->raw_schname) my_free(1393, &xctx->raw_schname);
if(xctx->graph_raw_schname) my_free(1393, &xctx->graph_raw_schname);
xctx->graph_datasets = 0;
xctx->graph_nvars = 0;
int_hash_free(xctx->raw_table);
int_hash_free(xctx->graph_raw_table);
if(deleted && dr) draw();
}
@ -502,7 +502,7 @@ int read_rawfile(const char *f)
if((res = read_dataset(fd)) == 1) {
int i;
dbg(0, "Raw file data read\n");
my_strdup2(1394, &xctx->raw_schname, xctx->sch[xctx->currsch]);
my_strdup2(1394, &xctx->graph_raw_schname, xctx->sch[xctx->currsch]);
xctx->graph_allpoints = 0;
for(i = 0; i < xctx->graph_datasets; i++) {
xctx->graph_allpoints += xctx->graph_npoints[i];
@ -525,14 +525,14 @@ int get_raw_index(const char *node)
Int_hashentry *entry;
dbg(1, "get_raw_index(): node=%s, node=%s\n", node, node);
if(xctx->graph_values) {
entry = int_hash_lookup(xctx->raw_table, node, 0, XLOOKUP);
entry = int_hash_lookup(xctx->graph_raw_table, node, 0, XLOOKUP);
if(!entry) {
my_snprintf(vnode, S(vnode), "v(%s)", node);
entry = int_hash_lookup(xctx->raw_table, vnode, 0, XLOOKUP);
entry = int_hash_lookup(xctx->graph_raw_table, vnode, 0, XLOOKUP);
if(!entry) {
my_strncpy(lnode, vnode, S(lnode));
strtolower(lnode);
entry = int_hash_lookup(xctx->raw_table, lnode, 0, XLOOKUP);
entry = int_hash_lookup(xctx->graph_raw_table, lnode, 0, XLOOKUP);
}
}
if(entry) return entry->value;

View File

@ -1616,7 +1616,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
int skip = 0;
dbg(1, "scheduler(): load: filename=%s\n", argv[2]);
my_strncpy(f, abs_sym_path(argv[2], ""), S(f));
if(f[0] && check_loaded(f, win_path)) {
if(!force && f[0] && check_loaded(f, win_path) ) {
char msg[PATH_MAX + 100];
my_snprintf(msg, S(msg),
"tk_messageBox -type okcancel -icon warning -parent [xschem get topwindow] "
@ -2089,7 +2089,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
/* xschem rawfile_query index v(ldcp) */
Int_hashentry *entry;
int idx;
entry = int_hash_lookup(xctx->raw_table, argv[3], 0, XLOOKUP);
entry = int_hash_lookup(xctx->graph_raw_table, argv[3], 0, XLOOKUP);
idx = entry ? entry->value : -1;
Tcl_AppendResult(interp, my_itoa(idx), NULL);
} else if(argc > 3 && !strcmp(argv[2], "values")) {

View File

@ -325,7 +325,7 @@ static void free_xschem_data()
my_free(1385, &xctx->inst_table);
my_free(1386, &xctx->node_redraw_table);
my_free(1387, &xctx->hilight_table);
my_free(1388, &xctx->raw_table);
my_free(1388, &xctx->graph_raw_table);
my_free(1098, &xctx->wire);
my_free(1100, &xctx->text);
@ -448,9 +448,8 @@ 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_struct.hilight_wave[0] = -1; /* graph index of hilight wave */
xctx->graph_struct.hilight_wave[1] = -1; /* index of wave */
xctx->raw_schname = NULL;
xctx->graph_struct.hilight_wave = -1; /* index of wave */
xctx->graph_raw_schname = NULL;
xctx->wires = 0;
xctx->instances = 0;
xctx->symbols = 0;
@ -496,7 +495,7 @@ static void alloc_xschem_data(const char *top_path, const char *win_path)
xctx->node_redraw_table = my_calloc(973, HASHSIZE, sizeof(Int_hashentry *));
xctx->inst_table = my_calloc(1382, HASHSIZE, sizeof(Inst_hashentry *));
xctx->hilight_table = my_calloc(1383, HASHSIZE, sizeof(Hilight_hashentry *));
xctx->raw_table = my_calloc(1384, HASHSIZE, sizeof(Int_hashentry *));
xctx->graph_raw_table = my_calloc(1384, HASHSIZE, sizeof(Int_hashentry *));
xctx->inst_redraw_table = NULL;
xctx->inst_redraw_table_size = 0;
@ -686,7 +685,7 @@ int compare_schematics(const char *f)
/* HASH SCHEMATIC 1 */
for(i = 0; i < xctx->instances; i++) {
l = 1024 + strlen(xctx->inst[i].prop_ptr ? xctx->inst[i].prop_ptr : "");
my_realloc(1534, &s, l);
my_realloc(1540, &s, l);
my_snprintf(s, l, "C %s %g %g %d %d %s", 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 : "");
@ -695,7 +694,7 @@ int compare_schematics(const char *f)
for(i=0;i<xctx->wires;i++)
{
l =1024 + strlen(xctx->wire[i].prop_ptr ? xctx->wire[i].prop_ptr : "");
my_realloc(1535, &s, l);
my_realloc(1541, &s, l);
my_snprintf(s, l, "N %g %g %g %g", xctx->wire[i].x1, xctx->wire[i].y1,
xctx->wire[i].x2, xctx->wire[i].y2);
int_hash_lookup(table1, s, i, XINSERT_NOREPLACE);

View File

@ -709,7 +709,7 @@ typedef struct {
int unity_suffix;
double txtsizelab, digtxtsizelab, txtsizey, txtsizex;
int dataset;
int hilight_wave[2]; /* [0] : graph index, [1] : wave index */
int hilight_wave; /* wave index */
int logx, logy;
} Graph_ctx;
@ -848,6 +848,7 @@ typedef struct {
int nl_points, nl_maxpoints;
/* select_rect */
double nl_xr, nl_yr, nl_xr2, nl_yr2;
int nl_sel, nl_sem;
/* compare_schematics */
char sch_to_compare[PATH_MAX];
/* pan */
@ -878,13 +879,14 @@ typedef struct {
int undo_initialized;
/* graph context struct */
Graph_ctx graph_struct;
/* read raw files (draw.c) */
/* spice raw file specific data */
char **graph_names;
SPICE_DATA **graph_values;
int graph_nvars;
int *graph_npoints;
int graph_allpoints; /* all points of all datasets combined */
int graph_datasets;
/* data related to all graphs, so not stored in per-graph graph_struct */
double graph_cursor1_x;
double graph_cursor2_x;
int graph_unlock_x;
@ -904,10 +906,11 @@ 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_hashentry **raw_table;
char *raw_schname;
/* */
int nl_sel, nl_sem;
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 */
char *graph_raw_schname;
/* */
XSegment *biggridpoint;
XPoint *gridpoint;
char plotfile[PATH_MAX];
@ -918,7 +921,7 @@ typedef struct {
int draw_single_layer;
int draw_dots;
int only_probes;
int menu_removed; /* fullscreen pervious setting */
int menu_removed; /* fullscreen previous setting */
double save_lw; /* used to save linewidth when selecting 'only_probes' view */
int no_draw;
int draw_pixmap; /* pixmap used as 2nd buffer */

View File

@ -1162,7 +1162,7 @@ proc simulate {{callback {}}} {
set N ${n}.${tool}
}
if { ![info exists sim($tool,default)] } {
if { $has_x} {alert_ "Warning: simulator for $tool is not configured"}
if { [info exists has_x] } {alert_ "Warning: simulator for $tool is not configured"}
puts "Warning: simulator for $tool is not configured"
return
}
@ -1291,7 +1291,7 @@ proc waves {} {
}
set tool ${tool}wave
if { ![info exists sim($tool,default)] } {
if { $has_x} {alert_ "Warning: viewer for $tool is not configured"}
if { [info exists has_x] } {alert_ "Warning: viewer for $tool is not configured"}
puts "Warning: viewer for $tool is not configured"
return
}
@ -4623,7 +4623,7 @@ set tctx::global_array_list {
proc delete_ctx {context} {
global has_x
if {![info exists $has_x]} {return}
if {![info exists has_x]} {return}
set tctx::tctx $context
uplevel #0 {
# puts "delete_ctx $tctx::tctx"