From 37b52f23fe1b1f43182b9bed1af1772c65274d2f Mon Sep 17 00:00:00 2001 From: werner Date: Tue, 18 Aug 2009 20:52:09 +0000 Subject: [PATCH] Finally found a nice way to draw arcs in the GUI. - we freed a package's samples list after recalculating the number of samples, which caused a crash after adding a new vector. We now record the original list length in the package structure. - when dragging a circle, offer the end point first, so that it becomes an arc git-svn-id: http://svn.openmoko.org/trunk/eda/fped@5480 99fdad57-331a-0410-800a-d7fa5415bdb3 --- TODO | 1 - gui_tool.c | 20 +++++++------------- inst.c | 11 ++++++++--- inst.h | 1 + meas.c | 4 ++-- meas.h | 2 +- 6 files changed, 19 insertions(+), 20 deletions(-) diff --git a/TODO b/TODO index 62c34b5..1bea5fd 100644 --- a/TODO +++ b/TODO @@ -35,7 +35,6 @@ Bugs: - whenever we call parse_* for input parsing, we may leak lots of expressions - can't edit measurement labels through the GUI - r of rpads is misleading, particularly if we have a circle -- we can't enter an arc through the GUI / can't convert a circle to an arc - using variables in a measurement offset causes a crash because evaluation takes place after all table entries have been visited diff --git a/gui_tool.c b/gui_tool.c index 6fc2470..de17af5 100644 --- a/gui_tool.c +++ b/gui_tool.c @@ -471,12 +471,10 @@ struct pix_buf *draw_move_arc(struct inst *inst, struct coord pos, int i) case 0: c = pos; break; - case 1: - from = pos; - if (inst->obj->u.arc.start != inst->obj->u.arc.end) - break; - /* fall through */ case 2: + from = pos; + break; + case 1: to = pos; break; default: @@ -502,7 +500,7 @@ struct pix_buf *draw_move_arc(struct inst *inst, struct coord pos, int i) buf = save_pix_buf(DA, c.x-r_save, c.y-r_save, c.x+r_save, c.y+r_save, 1); draw_arc(DA, gc_drag, FALSE, c.x, c.y, r, a1, a2); - if (i == 2) { + if (i == 1) { end = rotate_r(c, r_save, -a2); gdk_draw_line(DA, gc_drag, c.x, c.y, end.x, end.y); } @@ -514,19 +512,15 @@ void do_move_to_arc(struct inst *inst, struct inst *to, int i) { struct vec *vec = inst_get_vec(to); struct obj *obj = inst->obj; - int is_circle; - is_circle = obj->u.arc.start == obj->u.arc.end; switch (i) { case 0: obj->base = vec; break; - case 1: - obj->u.arc.start = vec; - if (!is_circle) - break; - /* fall through */ case 2: + obj->u.arc.start = vec; + break; + case 1: obj->u.arc.end = vec; break; default: diff --git a/inst.c b/inst.c index 5695cf2..c9c7928 100644 --- a/inst.c +++ b/inst.c @@ -737,9 +737,13 @@ static int arc_op_anchors(struct inst *inst, struct vec ***anchors) { struct obj *obj = inst->obj; + /* + * Put end point first so that this is what we grab if dragging a + * circle (thereby turning it into an arc). + */ anchors[0] = &obj->base; - anchors[1] = &obj->u.arc.start; - anchors[2] = &obj->u.arc.end; + anchors[1] = &obj->u.arc.end; + anchors[2] = &obj->u.arc.start; return 3; } @@ -959,6 +963,7 @@ void inst_select_pkg(const char *name) (*pkg)->next_inst[prio] = &(*pkg)->insts[prio]; (*pkg)->samples = zalloc_size(sizeof(struct sample *)*n_samples); + (*pkg)->n_samples = n_samples; } curr_pkg = *pkg; } @@ -986,7 +991,7 @@ static void free_pkgs(struct pkg *pkg) next = inst->next; free(inst); } - reset_samples(pkg->samples); + reset_samples(pkg->samples, pkg->n_samples); free(pkg->samples); free(pkg); pkg = next_pkg; diff --git a/inst.h b/inst.h index b929769..a5276ec 100644 --- a/inst.h +++ b/inst.h @@ -114,6 +114,7 @@ struct pkg { struct inst *insts[ip_n]; struct inst **next_inst[ip_n]; struct sample **samples; + int n_samples; struct pkg *next; }; diff --git a/meas.c b/meas.c index 7c70327..27e5aec 100644 --- a/meas.c +++ b/meas.c @@ -27,12 +27,12 @@ int n_samples; struct num eval_unit(const struct expr *expr, const struct frame *frame); -void reset_samples(struct sample **samples) +void reset_samples(struct sample **samples, int n) { struct sample *next; int i; - for (i = 0; i != n_samples; i++) + for (i = 0; i != n; i++) while (samples[i]) { next = samples[i]->next; free(samples[i]); diff --git a/meas.h b/meas.h index 1d42341..f2148d3 100644 --- a/meas.h +++ b/meas.h @@ -60,7 +60,7 @@ struct coord meas_find_next(lt_op_type lt, const struct sample *s, struct coord meas_find_max(lt_op_type lt, const struct sample *s); -void reset_samples(struct sample **samples); +void reset_samples(struct sample **samples, int n); void meas_start(void); void meas_post(const struct vec *vec, struct coord pos); int instantiate_meas(void);