do not accept 0 in graph `X div` and `Y div` textboxes, as this will cause an endless loop

This commit is contained in:
Stefan Frederik 2022-08-03 10:44:34 +02:00
parent 9e888b8b44
commit bd8c1fd6eb
2 changed files with 18 additions and 4 deletions

View File

@ -1574,6 +1574,7 @@ static double axis_increment(double a, double b, int div, int freq)
if(div == 1) { if(div == 1) {
return delta; return delta;
} }
if(div < 1) div = 1;
if(delta == 0.0) return delta; if(delta == 0.0) return delta;
/* if user wants only one division, just do what user asks */ /* if user wants only one division, just do what user asks */
if(div == 1) return delta; if(div == 1) return delta;
@ -1597,6 +1598,7 @@ static double axis_increment(double a, double b, int div, int freq)
static double axis_start(double n, double delta, int div) static double axis_start(double n, double delta, int div)
{ {
if(div < 1) div = 1;
if(delta == 0.0) return n; if(delta == 0.0) return n;
/* if user wants only one division, just do what user asks */ /* if user wants only one division, just do what user asks */
if(div == 1) return n; if(div == 1) return n;
@ -1995,8 +1997,10 @@ void setup_graph_data(int i, const int flags, int skip, Graph_ctx *gr)
if(val[0]) gr->subdivy = atoi(val); if(val[0]) gr->subdivy = atoi(val);
val = get_tok_value(r->prop_ptr,"divx",0); val = get_tok_value(r->prop_ptr,"divx",0);
if(val[0]) gr->divx = atoi(val); if(val[0]) gr->divx = atoi(val);
if(gr->divx < 1) gr->divx = 1;
val = get_tok_value(r->prop_ptr,"divy",0); val = get_tok_value(r->prop_ptr,"divy",0);
if(val[0]) gr->divy = atoi(val); if(val[0]) gr->divy = atoi(val);
if(gr->divy < 1) gr->divy = 1;
val = get_tok_value(r->prop_ptr,"y1",0); val = get_tok_value(r->prop_ptr,"y1",0);
if(val[0]) gr->gy1 = atof(val); if(val[0]) gr->gy1 = atof(val);
val = get_tok_value(r->prop_ptr,"y2",0); val = get_tok_value(r->prop_ptr,"y2",0);

View File

@ -1582,6 +1582,18 @@ proc update_graph_node {node} {
xschem draw_graph $graph_selected xschem draw_graph $graph_selected
} }
proc update_div {graph_selected div} {
set divis [.graphdialog.top2.$div get]
if {[regexp {^[0-9]+$} $divis] && $divis < 1} {
set divis 1
.graphdialog.top2.$div delete 0 end
.graphdialog.top2.$div insert 0 $divis
}
xschem setprop rect 2 $graph_selected $div $divis
xschem draw_graph $graph_selected
}
proc graph_edit_properties {n} { proc graph_edit_properties {n} {
global graph_bus graph_sort graph_digital graph_selected colors graph_sel_color global graph_bus graph_sort graph_digital graph_selected colors graph_sel_color
global graph_unlocked graph_schname global graph_unlocked graph_schname
@ -1727,15 +1739,13 @@ proc graph_edit_properties {n} {
label .graphdialog.top2.labdivx -text { X div.} label .graphdialog.top2.labdivx -text { X div.}
entry .graphdialog.top2.divx -width 2 entry .graphdialog.top2.divx -width 2
bind .graphdialog.top2.divx <KeyRelease> { bind .graphdialog.top2.divx <KeyRelease> {
xschem setprop rect 2 $graph_selected divx [.graphdialog.top2.divx get] update_div $graph_selected divx
xschem draw_graph $graph_selected
} }
label .graphdialog.top2.labdivy -text { Y div.} label .graphdialog.top2.labdivy -text { Y div.}
entry .graphdialog.top2.divy -width 2 entry .graphdialog.top2.divy -width 2
bind .graphdialog.top2.divy <KeyRelease> { bind .graphdialog.top2.divy <KeyRelease> {
xschem setprop rect 2 $graph_selected divy [.graphdialog.top2.divy get] update_div $graph_selected divy
xschem draw_graph $graph_selected
} }
label .graphdialog.top2.labsubdivx -text { X subdiv.} label .graphdialog.top2.labsubdivx -text { X subdiv.}