cleanup/rename some xctx variables and graph-related functions, avoid drawing graphs using data file loaded from from schematics that are unmatched with current schematic or up in the hierarchy levels
This commit is contained in:
parent
c5c4d48729
commit
e67ff344c8
|
|
@ -1436,7 +1436,7 @@ void calc_drawing_bbox(xRect *boundbox, int selected)
|
|||
{
|
||||
const char *tmp = tclgetvar("hide_empty_graphs");
|
||||
int hide_graphs = (tmp && tmp[0] == '1') ? 1 : 0;
|
||||
int waves = schematic_waves_loaded();
|
||||
int waves = (sch_waves_loaded() >= 0);
|
||||
|
||||
for(i=0;i<xctx->lines[c];i++)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ static int waves_selected(int event, KeySym key, int state, int button)
|
|||
static unsigned int excl = STARTZOOM | STARTRECT | STARTLINE | STARTWIRE |
|
||||
STARTPAN | STARTSELECT | STARTMOVE | STARTCOPY;
|
||||
if(xctx->ui_state & excl) skip = 1;
|
||||
else if(!xctx->graph_values) skip = 1;
|
||||
else if(sch_waves_loaded() < 0 ) skip = 1;
|
||||
else if(key !='a' && (state & Mod1Mask)) skip = 1;
|
||||
else if(event == MotionNotify && (state & Button2Mask)) skip = 1;
|
||||
else if(event == MotionNotify && (state & Button1Mask) && (state & ShiftMask)) skip = 1;
|
||||
|
|
@ -176,7 +176,7 @@ static void start_wire(double mx, double my)
|
|||
static void backannotate_at_cursor_b_pos(xRect *r, Graph_ctx *gr)
|
||||
{
|
||||
|
||||
if(xctx->graph_values) {
|
||||
if(sch_waves_loaded() >= 0) {
|
||||
int dset, first, last, dataset = gr->dataset, i, p, ofs = 0;
|
||||
double start, end;
|
||||
int sweepvar_wrap = 0, sweep_idx;
|
||||
|
|
@ -247,7 +247,7 @@ static void backannotate_at_cursor_b_pos(xRect *r, Graph_ctx *gr)
|
|||
}
|
||||
dbg(1, "xx=%g, p=%d\n", xx, p);
|
||||
tcleval("array unset ngspice::ngspice_data");
|
||||
xctx->graph_backannotate_p = p;
|
||||
xctx->graph_annotate_p = p;
|
||||
for(i = 0; i < xctx->graph_nvars; i++) {
|
||||
char s[100];
|
||||
my_snprintf(s, S(s), "%.4g", xctx->graph_values[i][p]);
|
||||
|
|
@ -872,7 +872,7 @@ static int waves_callback(int event, int mx, int my, KeySym key, int button, int
|
|||
}
|
||||
bus_msb = strstr(ntok, ",");
|
||||
j = -1;
|
||||
if(!bus_msb && xctx->graph_values) {
|
||||
if(!bus_msb) {
|
||||
char *express = NULL;
|
||||
if(strstr(ntok, ";")) {
|
||||
my_strdup2(1505, &express, find_nth(ntok, ";", 2));
|
||||
|
|
|
|||
20
src/draw.c
20
src/draw.c
|
|
@ -1639,15 +1639,17 @@ static double get_unit(const char *val)
|
|||
return 1.0;
|
||||
}
|
||||
|
||||
int schematic_waves_loaded(void)
|
||||
/* return hierarchy level where raw file was loaded (so may include top level 0) or -1
|
||||
* if there is no matching schematic name up in the hierarchy */
|
||||
int sch_waves_loaded(void)
|
||||
{
|
||||
int i;
|
||||
if(xctx->graph_values && xctx->graph_raw_schname) {
|
||||
if(xctx->graph_values && xctx->graph_names && xctx->graph_raw_schname) {
|
||||
for(i = xctx->currsch; i >= 0; i--) {
|
||||
if( !strcmp(xctx->graph_raw_schname, xctx->sch[i]) ) return 1;
|
||||
if( !strcmp(xctx->graph_raw_schname, xctx->sch[i]) ) return i;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void get_bus_value(int n_bits, int hex_digits, SPICE_DATA **idx_arr, int p, char *busval,
|
||||
|
|
@ -1967,7 +1969,6 @@ void setup_graph_data(int i, const int flags, int skip, Graph_ctx *gr)
|
|||
const char *val;
|
||||
xRect *r = &xctx->rect[GRIDLAYER][i];
|
||||
|
||||
gr->i = i;
|
||||
/* default values */
|
||||
gr->divx = gr->divy = 5;
|
||||
gr->subdivx = gr->subdivy = 0;
|
||||
|
|
@ -2189,7 +2190,7 @@ static void draw_graph_variables(int wcnt, int wave_color, int n_nodes, int swee
|
|||
bbox(SET_INSIDE, 0.0, 0.0, 0.0, 0.0);
|
||||
/* draw sweep variable(s) on x-axis */
|
||||
if(wcnt == 0 || (stok && stok[0])) {
|
||||
if(xctx->graph_values) stok = xctx->graph_names[sweep_idx];
|
||||
if(sch_waves_loaded() >= 0) stok = xctx->graph_names[sweep_idx];
|
||||
if(gr->unitx != 1.0) my_snprintf(tmpstr, S(tmpstr), "%s[%c]", stok ? stok : "" , gr->unitx_suffix);
|
||||
else my_snprintf(tmpstr, S(tmpstr), "%s", stok ? stok : "");
|
||||
draw_string(wave_color, NOW, tmpstr, 2, 1, 0, 0,
|
||||
|
|
@ -2862,10 +2863,11 @@ static void draw_graph_all(int flags)
|
|||
int save_bbx1, save_bby1, save_bbx2, save_bby2;
|
||||
dbg(1, "draw_graph_all(): flags=%d\n", flags);
|
||||
/* save bbox data, since draw_graph_all() is called from draw() which may be called after a bbox(SET) */
|
||||
sch_loaded = schematic_waves_loaded();
|
||||
sch_loaded = (sch_waves_loaded() >= 0);
|
||||
dbg(1, "draw_graph_all(): sch_loaded=%d\n", sch_loaded);
|
||||
hide_graphs = tclgetboolvar("hide_empty_graphs");
|
||||
if(sch_loaded || !hide_graphs) {
|
||||
if(xctx->sem) {
|
||||
if(xctx->bbox_set) {
|
||||
bbox_set = 1;
|
||||
save_bbx1 = xctx->bbx1;
|
||||
save_bby1 = xctx->bby1;
|
||||
|
|
@ -2898,7 +2900,7 @@ static void draw_graph_all(int flags)
|
|||
xctx->bby1 = save_bby1;
|
||||
xctx->bbx2 = save_bbx2;
|
||||
xctx->bby2 = save_bby2;
|
||||
xctx->sem = 1;
|
||||
xctx->bbox_set = 1;
|
||||
bbox(SET, 0.0, 0.0, 0.0, 0.0);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -489,7 +489,7 @@ void free_rawfile(int dr)
|
|||
if(xctx->graph_raw_schname) my_free(1393, &xctx->graph_raw_schname);
|
||||
xctx->graph_datasets = 0;
|
||||
xctx->graph_nvars = 0;
|
||||
xctx->graph_backannotate_p = -1;
|
||||
xctx->graph_annotate_p = -1;
|
||||
int_hash_free(xctx->graph_raw_table);
|
||||
if(deleted && dr) draw();
|
||||
}
|
||||
|
|
@ -595,7 +595,7 @@ int get_raw_index(const char *node)
|
|||
|
||||
|
||||
dbg(1, "get_raw_index(): node=%s\n", node);
|
||||
if(xctx->graph_values) {
|
||||
if(sch_waves_loaded() >= 0) {
|
||||
my_strncpy(inode, node, S(inode));
|
||||
strtolower(inode);
|
||||
entry = int_hash_lookup(xctx->graph_raw_table, inode, 0, XLOOKUP);
|
||||
|
|
|
|||
|
|
@ -379,7 +379,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
|
|||
tcleval("array unset ngspice::ngspice_data");
|
||||
raw_read(f, "op");
|
||||
if(xctx->graph_values) {
|
||||
xctx->graph_backannotate_p = 0;
|
||||
xctx->graph_annotate_p = 0;
|
||||
for(i = 0; i < xctx->graph_nvars; i++) {
|
||||
char s[100];
|
||||
int p = 0;
|
||||
|
|
@ -2121,7 +2121,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
|
|||
cmd_found = 1;
|
||||
Tcl_ResetResult(interp);
|
||||
if(argc > 2 && !strcmp(argv[2], "loaded")) {
|
||||
Tcl_SetResult(interp, schematic_waves_loaded() ? "1" : "0", TCL_STATIC);
|
||||
Tcl_SetResult(interp, (sch_waves_loaded() >= 0) ? "1" : "0", TCL_STATIC);
|
||||
} else if(xctx->graph_values) {
|
||||
/* xschem rawfile_query value v(ldcp) 123 */
|
||||
if(argc > 4 && !strcmp(argv[2], "value")) {
|
||||
|
|
@ -2191,14 +2191,14 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
|
|||
if(!strcmp(argv[1], "raw_read"))
|
||||
{
|
||||
cmd_found = 1;
|
||||
if(schematic_waves_loaded()) {
|
||||
if(sch_waves_loaded() >= 0) {
|
||||
free_rawfile(1);
|
||||
tclsetvar("rawfile_loaded", "0");
|
||||
} else if(argc > 2) {
|
||||
free_rawfile(0);
|
||||
if(argc > 3) raw_read(argv[2], argv[3]);
|
||||
else raw_read(argv[2], NULL);
|
||||
if(schematic_waves_loaded()) {
|
||||
if(sch_waves_loaded() >= 0) {
|
||||
tclsetvar("rawfile_loaded", "1");
|
||||
draw();
|
||||
}
|
||||
|
|
@ -2209,13 +2209,13 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
|
|||
if(!strcmp(argv[1], "raw_read_from_attr"))
|
||||
{
|
||||
cmd_found = 1;
|
||||
if(schematic_waves_loaded()) {
|
||||
if(sch_waves_loaded() >= 0) {
|
||||
free_rawfile(1);
|
||||
} else {
|
||||
free_rawfile(0);
|
||||
if(argc > 2) raw_read_from_attr(argv[2]);
|
||||
else raw_read_from_attr(NULL);
|
||||
if(schematic_waves_loaded()) {
|
||||
if(sch_waves_loaded() >= 0) {
|
||||
tclsetvar("rawfile_loaded", "1");
|
||||
draw();
|
||||
}
|
||||
|
|
|
|||
14
src/select.c
14
src/select.c
|
|
@ -470,7 +470,7 @@ void bbox(int what,double x1,double y1, double x2, double y2)
|
|||
switch(what)
|
||||
{
|
||||
case START:
|
||||
if(xctx->sem==1) {
|
||||
if(xctx->bbox_set==1) {
|
||||
fprintf(errfp, "ERROR: rentrant bbox() call\n");
|
||||
tcleval("alert_ {ERROR: reentrant bbox() call} {}");
|
||||
}
|
||||
|
|
@ -485,10 +485,10 @@ void bbox(int what,double x1,double y1, double x2, double y2)
|
|||
xctx->savew = xctx->areaw;
|
||||
xctx->saveh = xctx->areah;
|
||||
xctx->savexrect = xctx->xrect[0];
|
||||
xctx->sem=1;
|
||||
xctx->bbox_set=1;
|
||||
break;
|
||||
case ADD:
|
||||
if(xctx->sem==0) {
|
||||
if(xctx->bbox_set==0) {
|
||||
fprintf(errfp, "ERROR: bbox(ADD) call before bbox(START)\n");
|
||||
tcleval("alert_ {ERROR: bbox(ADD) call before bbox(START)} {}");
|
||||
}
|
||||
|
|
@ -509,7 +509,7 @@ void bbox(int what,double x1,double y1, double x2, double y2)
|
|||
if(y1 > xctx->bby2) xctx->bby2 = (int) y1;
|
||||
break;
|
||||
case END:
|
||||
if(xctx->sem) {
|
||||
if(xctx->bbox_set) {
|
||||
xctx->areax1 = xctx->savex1;
|
||||
xctx->areax2 = xctx->savex2;
|
||||
xctx->areay1 = xctx->savey1;
|
||||
|
|
@ -522,11 +522,11 @@ void bbox(int what,double x1,double y1, double x2, double y2)
|
|||
xctx->xrect[0].x, xctx->xrect[0].y, xctx->xrect[0].width, xctx->xrect[0].height);
|
||||
set_clip_mask(END);
|
||||
}
|
||||
xctx->sem=0;
|
||||
xctx->bbox_set=0;
|
||||
}
|
||||
break;
|
||||
case SET:
|
||||
if(xctx->sem==0) {
|
||||
if(xctx->bbox_set==0) {
|
||||
fprintf(errfp, "ERROR: bbox(SET) call before bbox(START)\n");
|
||||
tcleval("alert_ {ERROR: bbox(SET) call before bbox(START)} {}");
|
||||
}
|
||||
|
|
@ -551,7 +551,7 @@ void bbox(int what,double x1,double y1, double x2, double y2)
|
|||
|
||||
|
||||
case SET_INSIDE: /* do not add line widths to clip rectangle so everything remains inside */
|
||||
if(xctx->sem==0) {
|
||||
if(xctx->bbox_set==0) {
|
||||
fprintf(errfp, "ERROR: bbox(SET_INSIDE) call before bbox(START)\n");
|
||||
tcleval("alert_ {ERROR: bbox(SET_INSIDE) call before bbox(START)} {}");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3018,7 +3018,7 @@ const char *translate(int inst, const char* s)
|
|||
}
|
||||
else if(strcmp(token,"@spice_get_voltage")==0 )
|
||||
{
|
||||
if(xctx->graph_values && xctx->graph_backannotate_p>=0) {
|
||||
if((sch_waves_loaded() >= 0) && xctx->graph_annotate_p>=0) {
|
||||
int multip;
|
||||
int no_of_pins= (xctx->inst[inst].ptr + xctx->sym)->rects[PINLAYER];
|
||||
if(no_of_pins == 1) {
|
||||
|
|
@ -3039,7 +3039,7 @@ const char *translate(int inst, const char* s)
|
|||
strtolower(fqnet);
|
||||
idx = get_raw_index(fqnet);
|
||||
if(idx >= 0) {
|
||||
val = xctx->graph_values[idx][xctx->graph_backannotate_p];
|
||||
val = xctx->graph_values[idx][xctx->graph_annotate_p];
|
||||
}
|
||||
if(idx < 0) {
|
||||
my_snprintf(valstr, S(valstr), "?");
|
||||
|
|
@ -3062,7 +3062,7 @@ const char *translate(int inst, const char* s)
|
|||
}
|
||||
else if(strcmp(token,"@spice_get_current")==0 )
|
||||
{
|
||||
if(xctx->graph_values && xctx->graph_backannotate_p>=0) {
|
||||
if((sch_waves_loaded() >= 0) && xctx->graph_annotate_p>=0) {
|
||||
char *fqdev = NULL;
|
||||
const char *path = xctx->sch_path[xctx->currsch] + 1;
|
||||
char *dev = NULL;
|
||||
|
|
@ -3093,7 +3093,7 @@ const char *translate(int inst, const char* s)
|
|||
strtolower(fqdev);
|
||||
idx = get_raw_index(fqdev);
|
||||
if(idx >= 0) {
|
||||
val = xctx->graph_values[idx][xctx->graph_backannotate_p];
|
||||
val = xctx->graph_values[idx][xctx->graph_annotate_p];
|
||||
}
|
||||
if(idx < 0) {
|
||||
my_snprintf(valstr, S(valstr), "?");
|
||||
|
|
|
|||
|
|
@ -443,14 +443,13 @@ static void alloc_xschem_data(const char *top_path, const char *win_path)
|
|||
xctx->graph_datasets = 0;
|
||||
xctx->graph_master = 0;
|
||||
xctx->graph_cursor1_x = 0;
|
||||
xctx->graph_unlock_x = 0;
|
||||
xctx->graph_flags = 0;
|
||||
xctx->graph_top = 0;
|
||||
xctx->graph_bottom = 0;
|
||||
xctx->graph_left = 0;
|
||||
xctx->graph_lastsel = -1;
|
||||
xctx->graph_sim_type = NULL; /* type of sim, "tran", "dc", "op", "ac", ... */
|
||||
xctx->graph_backannotate_p = -1; /* point in raw file to use for annotating voltages/currents/etc */
|
||||
xctx->graph_annotate_p = -1; /* point in raw file to use for annotating voltages/currents/etc */
|
||||
xctx->graph_struct.hilight_wave = -1; /* index of wave */
|
||||
xctx->graph_raw_schname = NULL;
|
||||
xctx->wires = 0;
|
||||
|
|
@ -609,7 +608,7 @@ static void alloc_xschem_data(const char *top_path, const char *win_path)
|
|||
xctx->save_netlist_type = 0;
|
||||
xctx->loaded_symbol = 0;
|
||||
xctx->no_draw = 0;
|
||||
xctx->sem = 0; /* bbox */
|
||||
xctx->bbox_set = 0; /* bbox */
|
||||
xctx->old_prop = NULL;
|
||||
xctx->edit_sym_i = -1;
|
||||
xctx->netlist_commands = 0;
|
||||
|
|
|
|||
|
|
@ -684,7 +684,6 @@ typedef struct
|
|||
|
||||
/* context struct for waveform graphs */
|
||||
typedef struct {
|
||||
int i; /* index number of container rectangle */
|
||||
int digital;
|
||||
double rx1, ry1, rx2, ry2, rw, rh; /* container rectangle */
|
||||
double sx1, sy1, sx2, sy2; /* screen coordinates of above */
|
||||
|
|
@ -869,7 +868,7 @@ typedef struct {
|
|||
/* bbox */
|
||||
int bbx1, bbx2, bby1, bby2;
|
||||
int savew, saveh, savex1, savex2, savey1, savey2;
|
||||
int sem; /* set to 1 if a clipping bbox is set (void bbox() ) */
|
||||
int bbox_set; /* set to 1 if a clipping bbox is set (void bbox() ) */
|
||||
XRectangle savexrect;
|
||||
/* new_prop_string */
|
||||
char prefix;
|
||||
|
|
@ -892,7 +891,6 @@ typedef struct {
|
|||
/* 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;
|
||||
/* graph_flags:
|
||||
* 1: dnu, reserved, used in draw_graphs()
|
||||
* 2: draw x-cursor1
|
||||
|
|
@ -909,7 +907,7 @@ typedef struct {
|
|||
int graph_left;
|
||||
int graph_lastsel; /* last graph that was clicked (selected) */
|
||||
const char *graph_sim_type; /* type of sim, "tran", "dc", "ac", "op", ... */
|
||||
int graph_backannotate_p; /* point in raw file to use for annotating schematic voltages/currents/etc */
|
||||
int graph_annotate_p; /* point in raw file to use for annotating schematic voltages/currents/etc */
|
||||
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 */
|
||||
|
|
@ -1044,7 +1042,7 @@ extern int raw_read(const char *f, const char *type);
|
|||
extern double get_raw_value(int dataset, int idx, int point);
|
||||
extern int plot_raw_custom_data(int sweep_idx, int first, int last, const char *ntok);
|
||||
extern int calc_custom_data_yrange(int sweep_idx, const char *express, Graph_ctx *gr);
|
||||
extern int schematic_waves_loaded(void);
|
||||
extern int sch_waves_loaded(void);
|
||||
extern int edit_wave_attributes(int what, int i, Graph_ctx *gr);
|
||||
extern void draw_graph(int i, int flags, Graph_ctx *gr);
|
||||
extern int find_closest_wave(int i, Graph_ctx *gr);
|
||||
|
|
|
|||
Loading…
Reference in New Issue