From 3d6ef489304eb34dea0106a690dc1137d41072b5 Mon Sep 17 00:00:00 2001 From: werner Date: Thu, 18 Feb 2010 13:39:20 +0000 Subject: [PATCH] As a shortcut, accept entry of "0" as a valid distance for dimensions. (For safety, this only works if used directly, not through variables.) - gui_status.c (edit_any_expr): replaced with dist_expr_store, which changes values of "0" to "0mm" - gui_status.c, gui_status.h (edit_dist_expr): new function to edit distance expressions - inst.c (obj_line_edit, obj_rect_edit, obj_arc_edit, obj_meas_edit): changed edit_expr to edit_dist_expr git-svn-id: http://svn.openmoko.org/trunk/eda/fped@5844 99fdad57-331a-0410-800a-d7fa5415bdb3 --- gui_status.c | 42 +++++++++++++++++++++++++++++++++++------- gui_status.h | 1 + inst.c | 8 ++++---- 3 files changed, 40 insertions(+), 11 deletions(-) diff --git a/gui_status.c b/gui_status.c index 0790e84..f59d3fd 100644 --- a/gui_status.c +++ b/gui_status.c @@ -615,16 +615,44 @@ static struct edit_ops edit_ops_expr = { }; -static void edit_any_expr(GtkWidget *widget, struct expr **expr, - const char *tooltip) +void edit_expr(struct expr **expr, const char *tooltip) { - setup_edit(widget, &edit_ops_expr, expr, tooltip); + setup_edit(status_entry, &edit_ops_expr, expr, tooltip); } -void edit_expr(struct expr **expr, const char *tooltip) +/* ----- distance expressions ---------------------------------------------- */ + + +static void dist_expr_store(const char *s, void *ctx) { - edit_any_expr(status_entry, expr, tooltip); + struct expr **anchor = ctx; + struct expr *expr; + + expr_store(s, ctx); + expr = *anchor; + if (expr->op == op_num && !expr->u.num.exponent && !expr->u.num.n) + expr->u.num.exponent = 1; +} + + +static struct edit_ops edit_ops_dist_expr = { + .retrieve = expr_retrieve, + .status = expr_status, + .store = dist_expr_store, +}; + + +static void edit_any_dist_expr(GtkWidget *widget, struct expr **expr, + const char *tooltip) +{ + setup_edit(widget, &edit_ops_dist_expr, expr, tooltip); +} + + +void edit_dist_expr(struct expr **expr, const char *tooltip) +{ + edit_any_dist_expr(status_entry, expr, tooltip); } @@ -633,13 +661,13 @@ void edit_x(struct expr **expr, const char *tooltip) vacate_widget(status_box_x); gtk_container_add(GTK_CONTAINER(status_box_x), status_entry_x); gtk_widget_show(status_box_x); - edit_any_expr(status_entry_x, expr, tooltip); + edit_any_dist_expr(status_entry_x, expr, tooltip); } void edit_y(struct expr **expr, const char *tooltip) { - edit_any_expr(status_entry_y, expr, tooltip); + edit_any_dist_expr(status_entry_y, expr, tooltip); } diff --git a/gui_status.h b/gui_status.h index 82af96a..52dde22 100644 --- a/gui_status.h +++ b/gui_status.h @@ -47,6 +47,7 @@ void edit_expr(struct expr **expr, const char *tooltip); void edit_expr_list(struct expr *expr, void (*set_values)(void *user, const struct value *values, int n_values), void *user, const char *tooltip); +void edit_dist_expr(struct expr **expr, const char *tooltip); void edit_x(struct expr **expr, const char *tooltip); void edit_y(struct expr **expr, const char *tooltip); void edit_nothing(void); diff --git a/inst.c b/inst.c index 1572b76..b9dee56 100644 --- a/inst.c +++ b/inst.c @@ -754,7 +754,7 @@ int inst_vec(struct vec *vec, struct coord base) static void obj_line_edit(struct obj *obj) { - edit_expr(&obj->u.line.width, "Line width"); + edit_dist_expr(&obj->u.line.width, "Line width"); } @@ -805,7 +805,7 @@ int inst_line(struct obj *obj, struct coord a, struct coord b, unit_type width) static void obj_rect_edit(struct obj *obj) { - edit_expr(&obj->u.rect.width, "Line width"); + edit_dist_expr(&obj->u.rect.width, "Line width"); } @@ -934,7 +934,7 @@ int inst_pad(struct obj *obj, const char *name, struct coord a, struct coord b) static void obj_arc_edit(struct obj *obj) { - edit_expr(&obj->u.arc.width, "Line width"); + edit_dist_expr(&obj->u.arc.width, "Line width"); } @@ -1008,7 +1008,7 @@ int inst_arc(struct obj *obj, struct coord center, struct coord start, static void obj_meas_edit(struct obj *obj) { - edit_expr(&obj->u.meas.offset, "Measurement line offset"); + edit_dist_expr(&obj->u.meas.offset, "Measurement line offset"); }