--- Begin Message ---
Author: werner
Date: 2009-08-04 20:03:06 +0200 (Tue, 04 Aug 2009)
New Revision: 5385
Modified:
trunk/eda/fped/gui.c
trunk/eda/fped/gui_inst.c
trunk/eda/fped/gui_inst.h
trunk/eda/fped/gui_style.c
trunk/eda/fped/gui_style.h
trunk/eda/fped/gui_tools.c
trunk/eda/fped/inst.c
trunk/eda/fped/inst.h
trunk/eda/fped/obj.c
Log:
- previous Makefile change was: tentative fix for compatibility with older
ImageMagick versions (reported by Alvaro Lopes)
- we can now also select the frame's origin as a reference
- added general frame selection logic
- make sure we always use %s when passing names to status_set_name
- we can now drag endpoints (in progress)
Modified: trunk/eda/fped/gui.c
===================================================================
--- trunk/eda/fped/gui.c 2009-08-04 12:06:04 UTC (rev 5384)
+++ trunk/eda/fped/gui.c 2009-08-04 18:03:06 UTC (rev 5385)
@@ -115,7 +115,7 @@
inst_select_outside(var, unselect_var);
label_in_box_bg(var->widget, COLOR_VAR_EDITING);
status_set_type_entry("name =");
- status_set_name(var->name);
+ status_set_name("%s", var->name);
edit_unique(&var->name, validate_var_name, var);
}
@@ -493,7 +493,7 @@
inst_select_outside(frame, unselect_frame);
label_in_box_bg(frame->label, COLOR_FRAME_EDITING);
status_set_type_entry("name =");
- status_set_name(frame->name);
+ status_set_name("%s", frame->name);
edit_unique(&frame->name, validate_frame_name, frame);
}
Modified: trunk/eda/fped/gui_inst.c
===================================================================
--- trunk/eda/fped/gui_inst.c 2009-08-04 12:06:04 UTC (rev 5384)
+++ trunk/eda/fped/gui_inst.c 2009-08-04 18:03:06 UTC (rev 5385)
@@ -393,7 +393,8 @@
/* ----- frame ------------------------------------------------------------- */
-unit_type gui_dist_frame(struct inst *self, struct coord pos, unit_type scale)
+unit_type gui_dist_frame_eye(struct inst *self, struct coord pos,
+ unit_type scale)
{
unit_type d;
@@ -402,6 +403,40 @@
}
+static unit_type dist_from_corner_line(struct inst *self, struct coord pos,
+ struct coord vec, unit_type scale)
+{
+ struct coord ref;
+
+ ref.x = self->bbox.min.x;
+ ref.y = self->bbox.max.y;
+ return dist_line(pos, ref, add_vec(ref, vec))/scale;
+}
+
+
+unit_type gui_dist_frame(struct inst *self, struct coord pos, unit_type scale)
+{
+ unit_type d_min, d;
+ struct coord vec;
+
+ d_min = dist_point(pos, self->base)/scale;
+
+ vec.x = FRAME_SHORT_X*scale;
+ vec.y = 0;
+ d = dist_from_corner_line(self, pos, vec, scale);
+ if (d < d_min)
+ d_min = d;
+
+ vec.x = 0;
+ vec.y = FRAME_SHORT_Y*scale;
+ d = dist_from_corner_line(self, pos, vec, scale);
+ if (d < d_min)
+ d_min = d;
+
+ return d_min > SELECT_R ? -1 : d_min;
+}
+
+
void gui_hover_frame(struct inst *self, struct draw_ctx *ctx)
{
struct coord center = translate(ctx, self->base);
@@ -418,7 +453,7 @@
struct coord corner = { self->bbox.min.x, self->bbox.max.y };
GdkGC *gc;
- gc = gc_frame[get_mode(self)];
+ gc = self->u.frame.active ? gc_active_frame : gc_frame[get_mode(self)];
draw_eye(ctx, gc, center, FRAME_EYE_R1, FRAME_EYE_R2);
if (!self->u.frame.ref->name)
return;
Modified: trunk/eda/fped/gui_inst.h
===================================================================
--- trunk/eda/fped/gui_inst.h 2009-08-04 12:06:04 UTC (rev 5384)
+++ trunk/eda/fped/gui_inst.h 2009-08-04 18:03:06 UTC (rev 5385)
@@ -39,6 +39,8 @@
unit_type gui_dist_arc(struct inst *self, struct coord pos, unit_type scale);
unit_type gui_dist_meas(struct inst *self, struct coord pos, unit_type scale);
unit_type gui_dist_frame(struct inst *self, struct coord pos, unit_type scale);
+unit_type gui_dist_frame_eye(struct inst *self, struct coord pos,
+ unit_type scale);
void gui_draw_vec(struct inst *self, struct draw_ctx *ctx);
void gui_draw_line(struct inst *self, struct draw_ctx *ctx);
Modified: trunk/eda/fped/gui_style.c
===================================================================
--- trunk/eda/fped/gui_style.c 2009-08-04 12:06:04 UTC (rev 5384)
+++ trunk/eda/fped/gui_style.c 2009-08-04 18:03:06 UTC (rev 5385)
@@ -24,6 +24,7 @@
GdkGC *gc_bg;
GdkGC *gc_drag;
+GdkGC *gc_active_frame;
GdkGC *gc_vec[mode_n];
GdkGC *gc_obj[mode_n];
GdkGC *gc_pad[mode_n];
@@ -67,7 +68,8 @@
style(gc_pad, "#400000", INVALID, "#ff0000", INVALID, "#ffff80");
style(gc_ptext, "#404040", INVALID, "#ffffff", INVALID, "#ffffff");
style(gc_meas, "#280040", INVALID, "#ff00ff", INVALID, "#ffff80");
- style(gc_frame, "#004000", "#205020", "#00ff00", INVALID, INVALID);
+ style(gc_frame, "#004000", "#205020", "#009000", INVALID, "#ffff80");
+ gc_active_frame = gc("#00ff00", 2);
gc_frame[mode_hover] = gc_vec[mode_hover] = gc("#c00000", 1);
}
Modified: trunk/eda/fped/gui_style.h
===================================================================
--- trunk/eda/fped/gui_style.h 2009-08-04 12:06:04 UTC (rev 5384)
+++ trunk/eda/fped/gui_style.h 2009-08-04 18:03:06 UTC (rev 5385)
@@ -84,6 +84,7 @@
extern GdkGC *gc_bg;
extern GdkGC *gc_drag;
+extern GdkGC *gc_active_frame;
extern GdkGC *gc_vec[mode_n];
extern GdkGC *gc_obj[mode_n];
extern GdkGC *gc_pad[mode_n];
Modified: trunk/eda/fped/gui_tools.c
===================================================================
--- trunk/eda/fped/gui_tools.c 2009-08-04 12:06:04 UTC (rev 5384)
+++ trunk/eda/fped/gui_tools.c 2009-08-04 18:03:06 UTC (rev 5385)
@@ -11,6 +11,8 @@
*/
+#include <stdlib.h>
+#include <assert.h>
#include <gtk/gtk.h>
#include "util.h"
@@ -36,9 +38,10 @@
struct tool_ops {
- struct pix_buf *(*drag)(struct draw_ctx *ctx, struct inst *from,
+ struct pix_buf *(*drag_new)(struct draw_ctx *ctx, struct inst *from,
struct coord to);
- int (*end)(struct draw_ctx *ctx, struct inst *from, struct inst *to);
+ int (*end_new)(struct draw_ctx *ctx, struct inst *from,
+ struct inst *to);
};
@@ -47,7 +50,16 @@
static struct tool_ops *active_ops = NULL;
static struct inst *hover_inst = NULL;
-static struct inst *drag;
+static struct drag_state {
+ struct inst *new; /* non-NULL if dragging a new object */
+ int anchors_n; /* number of anchors, 0 if no moving */
+ int anchor_i; /* current anchor */
+ struct vec **anchors[3];
+} drag = {
+ .new = NULL,
+ .anchors_n = 0,
+};
+
static struct pix_buf *pix_buf;
static struct tool_ops vec_ops;
@@ -104,8 +116,8 @@
static struct tool_ops line_ops = {
- .drag = drag_new_line,
- .end = end_new_line,
+ .drag_new = drag_new_line,
+ .end_new = end_new_line,
};
@@ -156,8 +168,8 @@
static struct tool_ops rect_ops = {
- .drag = drag_new_rect,
- .end = end_new_rect,
+ .drag_new = drag_new_rect,
+ .end_new = end_new_rect,
};
@@ -196,14 +208,79 @@
static struct tool_ops circ_ops = {
- .drag = drag_new_circ,
- .end = end_new_circ,
+ .drag_new = drag_new_circ,
+ .end_new = end_new_circ,
};
-/* ----- mouse actions ----------------------------------------------------- */
+/* ----- moving references ------------------------------------------------- */
+static int may_move(struct inst *curr)
+{
+ if (!selected_inst)
+ return 0;
+ if (drag.anchors_n)
+ return 0; /* already moving something else */
+ drag.anchors_n = inst_anchors(selected_inst, drag.anchors);
+ for (drag.anchor_i = 0; drag.anchor_i != drag.anchors_n;
+ drag.anchor_i++)
+ if (*drag.anchors[drag.anchor_i] == inst_get_vec(curr))
+ return 1;
+ drag.anchors_n = 0;
+ return 0;
+}
+
+
+static int would_be_equal(const struct drag_state *state,
+ int a, int b, struct inst *curr)
+{
+ const struct vec *va;
+ const struct vec *vb;
+
+ va = a == state->anchor_i ? inst_get_vec(curr) : *state->anchors[a];
+ vb = b == state->anchor_i ? inst_get_vec(curr) : *state->anchors[b];
+ return va == vb;
+}
+
+
+static int may_move_to(const struct drag_state *state, struct inst *curr)
+{
+ assert(selected_inst);
+ assert(state->anchors_n);
+ switch (state->anchors_n) {
+ case 3:
+ if (would_be_equal(state, 0, 2, curr))
+ return 0;
+ /* fall through */
+ case 2:
+ if (would_be_equal(state, 0, 1, curr))
+ return 0;
+ /* fall through */
+ case 1:
+ return 1;
+ default:
+ abort();
+ }
+}
+
+
+static void do_move_to(struct drag_state *state, struct inst *curr)
+{
+ struct vec *old;
+
+ assert(may_move_to(state, curr));
+ old = *state->anchors[state->anchor_i];
+ if (old)
+ old->n_refs--;
+ *state->anchors[state->anchor_i] = inst_get_ref(curr);
+ state->anchors_n = 0;
+}
+
+
+/* ----- hover ------------------------------------------------------------- */
+
+
void tool_dehover(struct draw_ctx *ctx)
{
if (hover_inst)
@@ -214,29 +291,46 @@
void tool_hover(struct draw_ctx *ctx, struct coord pos)
{
- struct inst *inst;
+ struct inst *curr;
- if (!active_ops)
- return;
- inst = inst_find_point(ctx, pos);
- if (inst != hover_inst)
+ curr = inst_find_point(ctx, pos);
+ if (curr && !active_ops) {
+ if (drag.anchors_n) {
+ if (!may_move_to(&drag, curr))
+ curr = NULL;
+ } else {
+ if (!may_move(curr))
+ curr = NULL;
+ drag.anchors_n = 0;
+ }
+ }
+ if (curr != hover_inst)
tool_dehover(ctx);
- if (inst) {
- inst_hover(inst, ctx, 1);
- hover_inst = inst;
+ if (curr) {
+ inst_hover(curr, ctx, 1);
+ hover_inst = curr;
}
}
+/* ----- mouse actions ----------------------------------------------------- */
+
+
int tool_consider_drag(struct draw_ctx *ctx, struct coord pos)
{
- if (!active_ops)
+ struct inst *curr;
+
+ assert(!drag.new);
+ assert(!drag.anchors_n);
+ curr = inst_find_point(ctx, pos);
+ if (!curr)
return 0;
- drag = inst_find_point(ctx, pos);
- if (!drag)
- return 0;
pix_buf = NULL;
- return 1;
+ if (active_ops) {
+ drag.new = curr;
+ return 1;
+ }
+ return may_move(curr);
}
@@ -245,7 +339,7 @@
if (pix_buf)
restore_pix_buf(pix_buf);
tool_hover(ctx, to);
- pix_buf = active_ops->drag(ctx, drag, to);
+ pix_buf = drag.new ? active_ops->drag_new(ctx, drag.new, to) : NULL;
}
@@ -255,22 +349,28 @@
tool_reset();
if (pix_buf)
restore_pix_buf(pix_buf);
- drag = NULL;
+ drag.new = NULL;
active_ops = NULL;
+ drag.anchors_n = 0;
}
int tool_end_drag(struct draw_ctx *ctx, struct coord to)
{
- struct inst *from = drag;
+ struct drag_state state = drag;
struct inst *end;
struct tool_ops *ops = active_ops;
tool_cancel_drag(ctx);
end = inst_find_point(ctx, to);
- if (end)
- return ops->end(ctx, from, end);
- return 0;
+ if (!end)
+ return 0;
+ if (state.new)
+ return ops->end_new(ctx, state.new, end);
+ if (!may_move_to(&state, end))
+ return 0;
+ do_move_to(&state, end);
+ return 1;
}
Modified: trunk/eda/fped/inst.c
===================================================================
--- trunk/eda/fped/inst.c 2009-08-04 12:06:04 UTC (rev 5384)
+++ trunk/eda/fped/inst.c 2009-08-04 18:03:06 UTC (rev 5385)
@@ -33,6 +33,7 @@
unit_type (*distance)(struct inst *self, struct coord pos,
unit_type scale);
void (*select)(struct inst *self);
+ int (*anchors)(struct inst *self, struct vec ***anchors);
};
enum inst_prio {
@@ -179,9 +180,9 @@
found = NULL;
for (inst = insts[ip_frame]; inst; inst = inst->next) {
- if (!inst->active || !inst->ops->distance)
+ if (!inst->active)
continue;
- dist = inst->ops->distance(inst, pos, ctx->scale);
+ dist = gui_dist_frame_eye(inst, pos, ctx->scale);
if (dist >= 0 && (!found || best_dist > dist)) {
found = inst;
best_dist = dist;
@@ -225,6 +226,22 @@
}
+struct vec *inst_get_vec(const struct inst *inst)
+{
+ if (inst->ops == &vec_ops)
+ return inst->vec;
+ if (inst->ops == &frame_ops)
+ return NULL;
+ abort();
+}
+
+
+int inst_anchors(struct inst *inst, struct vec ***anchors)
+{
+ return inst->ops->anchors ? inst->ops->anchors(inst, anchors) : 0;
+}
+
+
void inst_deselect(void)
{
if (selected_inst)
@@ -343,7 +360,7 @@
static void vec_op_select(struct inst *self)
{
status_set_type_entry("ref =");
- status_set_name(self->vec->name ? self->vec->name : "");
+ status_set_name("%s", self->vec->name ? self->vec->name : "");
rect_status(self->base, self->u.rect.end, -1);
edit_unique_null(&self->vec->name, validate_vec_name, self->vec);
edit_x(&self->vec->x);
@@ -351,12 +368,20 @@
}
+static int vec_op_anchors(struct inst *inst, struct vec ***anchors)
+{
+ anchors[0] = &inst->vec->base;
+ return 1;
+}
+
+
static struct inst_ops vec_ops = {
.debug = vec_op_debug,
.draw = gui_draw_vec,
.hover = gui_hover_vec,
.distance = gui_dist_vec,
.select = vec_op_select,
+ .anchors = vec_op_anchors,
};
@@ -391,11 +416,22 @@
}
+static int line_op_anchors(struct inst *inst, struct vec ***anchors)
+{
+ struct obj *obj = inst->obj;
+
+ anchors[0] = &obj->base;
+ anchors[1] = &obj->u.rect.other;
+ return 2;
+}
+
+
static struct inst_ops line_ops = {
.debug = line_op_debug,
.draw = gui_draw_line,
.distance = gui_dist_line,
.select = line_op_select,
+ .anchors = line_op_anchors,
};
@@ -437,6 +473,7 @@
.draw = gui_draw_rect,
.distance = gui_dist_rect,
.select = rect_op_select,
+ .anchors = line_op_anchors,
};
@@ -481,17 +518,28 @@
static void pad_op_select(struct inst *self)
{
status_set_type_entry("label =");
- status_set_name(self->u.name);
+ status_set_name("%s", self->u.name);
rect_status(self->bbox.min, self->bbox.max, -1);
edit_name(&self->obj->u.pad.name, validate_pad_name, NULL);
}
+static int pad_op_anchors(struct inst *inst, struct vec ***anchors)
+{
+ struct obj *obj = inst->obj;
+
+ anchors[0] = &obj->base;
+ anchors[1] = &obj->u.pad.other;
+ return 2;
+}
+
+
static struct inst_ops pad_ops = {
.debug = pad_op_debug,
.draw = gui_draw_pad,
.distance = gui_dist_pad,
.select = pad_op_select,
+ .anchors = pad_op_anchors,
};
@@ -532,11 +580,23 @@
}
+static int arc_op_anchors(struct inst *inst, struct vec ***anchors)
+{
+ struct obj *obj = inst->obj;
+
+ anchors[0] = &obj->base;
+ anchors[1] = &obj->u.arc.start;
+ anchors[2] = &obj->u.arc.end;
+ return 3;
+}
+
+
static struct inst_ops arc_ops = {
.debug = arc_op_debug,
.draw = gui_draw_arc,
.distance = gui_dist_arc,
.select = arc_op_select,
+ .anchors = arc_op_anchors,
};
@@ -590,11 +650,22 @@
}
+static int meas_op_anchors(struct inst *inst, struct vec ***anchors)
+{
+ struct obj *obj = inst->obj;
+
+ anchors[0] = &obj->base;
+ anchors[1] = &obj->u.meas.other;
+ return 2;
+}
+
+
static struct inst_ops meas_ops = {
.debug = meas_op_debug,
.draw = gui_draw_meas,
.distance = gui_dist_meas,
.select = meas_op_select,
+ .anchors = meas_op_anchors,
};
@@ -640,19 +711,39 @@
}
+static void frame_op_select(struct inst *self)
+{
+ rect_status(self->bbox.min, self->bbox.max, -1);
+ status_set_type_entry("name =");
+ status_set_name("%s", self->u.frame.ref->name);
+}
+
+
+static int frame_op_anchors(struct inst *inst, struct vec ***anchors)
+{
+ anchors[0] = &inst->vec->base;
+ return 1;
+}
+
+
static struct inst_ops frame_ops = {
- .debug = frame_op_debug,
- .draw = gui_draw_frame,
- .hover = gui_hover_frame,
+ .debug = frame_op_debug,
+ .draw = gui_draw_frame,
+ .hover = gui_hover_frame,
+ .distance = gui_dist_frame,
+ .select = frame_op_select,
+ .anchors = frame_op_anchors,
};
-void inst_begin_frame(const struct frame *frame, struct coord base, int active)
+void inst_begin_frame(const struct frame *frame, struct coord base,
+ int active, int is_active_frame)
{
struct inst *inst;
inst = add_inst(&frame_ops, ip_frame, base);
inst->u.frame.ref = frame;
+ inst->u.frame.active = is_active_frame;
inst->active = active;
curr_frame = inst;
}
Modified: trunk/eda/fped/inst.h
===================================================================
--- trunk/eda/fped/inst.h 2009-08-04 12:06:04 UTC (rev 5384)
+++ trunk/eda/fped/inst.h 2009-08-04 18:03:06 UTC (rev 5385)
@@ -51,6 +51,7 @@
union {
struct {
const struct frame *ref;
+ int active;
} frame;
const char *name;
struct {
@@ -81,7 +82,9 @@
struct inst *inst_find_point(const struct draw_ctx *ctx, struct coord pos);
struct coord inst_get_point(const struct inst *inst);
+int inst_anchors(struct inst *inst, struct vec ***anchors);
struct vec *inst_get_ref(const struct inst *inst);
+struct vec *inst_get_vec(const struct inst *inst);
int inst_vec(struct vec *vec, struct coord base);
int inst_line(struct obj *obj, struct coord a, struct coord b, unit_type
width);
@@ -95,7 +98,8 @@
void inst_begin_active(int active);
void inst_end_active(void);
-void inst_begin_frame(const struct frame *frame, struct coord base, int
active);
+void inst_begin_frame(const struct frame *frame, struct coord base,
+ int active, int is_active_frame);
void inst_end_frame(const struct frame *frame);
struct bbox inst_get_bbox(void);
Modified: trunk/eda/fped/obj.c
===================================================================
--- trunk/eda/fped/obj.c 2009-08-04 12:06:04 UTC (rev 5384)
+++ trunk/eda/fped/obj.c 2009-08-04 18:03:06 UTC (rev 5385)
@@ -244,7 +244,9 @@
/*
* We ensure during construction that frames can never recurse.
*/
- inst_begin_frame(frame, base, active && frame == active_frame);
+ inst_begin_frame(frame, base,
+ active && parent == active_frame,
+ active && frame == active_frame);
frame->curr_parent = parent;
ok = iterate_tables(frame, frame->tables, base, active);
inst_end_frame(frame);
--- End Message ---
--- Begin Message ---
Author: werner
Date: 2009-08-04 23:45:33 +0200 (Tue, 04 Aug 2009)
New Revision: 5386
Modified:
trunk/eda/fped/Makefile
trunk/eda/fped/README
trunk/eda/fped/TODO
trunk/eda/fped/coord.c
trunk/eda/fped/coord.h
trunk/eda/fped/fpd.l
trunk/eda/fped/gui_inst.c
trunk/eda/fped/gui_tools.c
trunk/eda/fped/gui_tools.h
trunk/eda/fped/gui_util.c
trunk/eda/fped/inst.c
trunk/eda/fped/inst.h
Log:
- README: described use of semicolons
- README: added that loops can also execute zero times
- accept labels only at the beginning of a line
- rectangles and lines no longer use the bounding box for drawing (caused
offset problems since we now correct for the line width)
- dist_rect and inside_rect no longer require their input pre-sorted
- pad instances now have their own structure and no longer abuse the bounding
box to know the pad coordinates
- Makefile: use $(GEN) for fig2dev, to reduce chattiness
- when dragging a point, the symbol is now adjusted accordingly
- added moving of rects, pads, circles, and arcs
- added creation of pads
- moved rotate_r from gui_inst.c to coord.c
- new function "theta" that combines most of the angle calculations
- save_pix_buf: y < 0 clipping changed width, not height
Modified: trunk/eda/fped/Makefile
===================================================================
--- trunk/eda/fped/Makefile 2009-08-04 18:03:06 UTC (rev 5385)
+++ trunk/eda/fped/Makefile 2009-08-04 21:45:33 UTC (rev 5386)
@@ -74,7 +74,7 @@
# sed '/2 2 0 1 /{s//2 2 0 15 /;s/ 0 7 / 22 7 /;}' $< | \
.fig.xpm:
- fig2dev -L xpm -Z 0.32 -S 4 $< | \
+ $(GEN) fig2dev -L xpm -Z 0.32 -S 4 $< | \
convert -crop 24x24+1+1 - - | \
sed "s/*.*\[]/*xpm_`basename $@ .xpm`[]/" >$@
Modified: trunk/eda/fped/README
===================================================================
--- trunk/eda/fped/README 2009-08-04 18:03:06 UTC (rev 5385)
+++ trunk/eda/fped/README 2009-08-04 21:45:33 UTC (rev 5386)
@@ -50,7 +50,8 @@
fped uses the C preprocessor for comments, conditional compilation,
and - to a limited extent - also macros. Long lines can be split by
-ending them with a backslash.
+ending them with a backslash. If multiple items need to be placed in a
+single line, e.g., in a macro, they can be separated with semicolons.
Geometry model
@@ -279,8 +280,11 @@
loop n = 1, 3.5
-both assign the values 1, 2, and 3 to the variable "n".
+both assign the values 1, 2, and 3 to the variable "n". The
+following loop would not execute at all:
+loop n = 1, 0
+
When a loop is executed, the objects contained in the body of the
enclosing frame are generated for each value of the variable. If
a frame contains multiple loops, all possible combinations of the
Modified: trunk/eda/fped/TODO
===================================================================
--- trunk/eda/fped/TODO 2009-08-04 18:03:06 UTC (rev 5385)
+++ trunk/eda/fped/TODO 2009-08-04 21:45:33 UTC (rev 5386)
@@ -18,6 +18,7 @@
Bugs:
- default silk width has no business being hard-coded in obj.c
+- after moving, arc sometimes wrap the wrong way
Code cleanup:
- merge edit_unique with edit_name
Modified: trunk/eda/fped/coord.c
===================================================================
--- trunk/eda/fped/coord.c 2009-08-04 18:03:06 UTC (rev 5385)
+++ trunk/eda/fped/coord.c 2009-08-04 21:45:33 UTC (rev 5386)
@@ -79,6 +79,54 @@
}
+/* ----- point on circle --------------------------------------------------- */
+
+
+struct coord rotate_r(struct coord c, unit_type r, double angle)
+{
+ struct coord p;
+
+ angle = angle/180.0*M_PI;
+ p.x = c.x+r*cos(angle);
+ p.y = c.y+r*sin(angle);
+ return p;
+}
+
+
+double theta(struct coord c, struct coord p)
+{
+ double a;
+
+ a = atan2(p.y-c.y, p.x-c.x)/M_PI*180.0;
+ if (a < 0)
+ a += 360.0;
+ return a;
+}
+
+
+/* ----- sorting coordinates ----------------------------------------------- */
+
+
+void swap_coord(unit_type *a, unit_type *b)
+{
+ unit_type tmp;
+
+ tmp = *a;
+ *a = *b;
+ *b = tmp;
+}
+
+
+void sort_coord(struct coord *min, struct coord *max)
+{
+ if (min->x > max->x)
+ swap_coord(&min->x, &max->x);
+ if (min->y > max->y)
+ swap_coord(&min->y, &max->y);
+
+}
+
+
/* ----- distance calculations --------------------------------------------- */
@@ -127,29 +175,30 @@
}
-unit_type dist_rect(struct coord p, struct coord min, struct coord max)
+unit_type dist_rect(struct coord p, struct coord a, struct coord b)
{
unit_type d_min, d;
- d_min = dist_line_xy(p.x, p.y, min.x, min.y, max.x, min.y);
- d = dist_line_xy(p.x, p.y, min.x, min.y, min.x, max.y);
+ d_min = dist_line_xy(p.x, p.y, a.x, a.y, b.x, a.y);
+ d = dist_line_xy(p.x, p.y, a.x, a.y, a.x, b.y);
if (d < d_min)
d_min = d;
- d = dist_line_xy(p.x, p.y, min.x, max.y, max.x, max.y);
+ d = dist_line_xy(p.x, p.y, a.x, b.y, b.x, b.y);
if (d < d_min)
d_min = d;
- d = dist_line_xy(p.x, p.y, max.x, min.y, max.x, max.y);
+ d = dist_line_xy(p.x, p.y, b.x, a.y, b.x, b.y);
if (d < d_min)
d_min = d;
return d_min;
}
-int inside_rect(struct coord p, struct coord min, struct coord max)
+int inside_rect(struct coord p, struct coord a, struct coord b)
{
- if (p.x < min.x || p.x > max.x)
+ sort_coord(&a, &b);
+ if (p.x < a.x || p.x > b.x)
return 0;
- if (p.y < min.y || p.y > max.y)
+ if (p.y < a.y || p.y > b.y)
return 0;
return 1;
}
Modified: trunk/eda/fped/coord.h
===================================================================
--- trunk/eda/fped/coord.h 2009-08-04 18:03:06 UTC (rev 5385)
+++ trunk/eda/fped/coord.h 2009-08-04 21:45:33 UTC (rev 5386)
@@ -69,10 +69,16 @@
struct coord sub_vec(struct coord a, struct coord b);
struct coord neg_vec(struct coord v);
+struct coord rotate_r(struct coord c, unit_type r, double angle);
+double theta(struct coord c, struct coord p);
+
+void swap_coord(unit_type *a, unit_type *b);
+void sort_coord(struct coord *min, struct coord *max);
+
unit_type dist_point(struct coord a, struct coord b);
unit_type dist_line(struct coord p, struct coord a, struct coord b);
-unit_type dist_rect(struct coord p, struct coord min, struct coord max);
-int inside_rect(struct coord p, struct coord min, struct coord max);
+unit_type dist_rect(struct coord p, struct coord a, struct coord b);
+int inside_rect(struct coord p, struct coord a, struct coord b);
unit_type dist_circle(struct coord p, struct coord c, unit_type r);
#endif /* !COORD_H */
Modified: trunk/eda/fped/fpd.l
===================================================================
--- trunk/eda/fped/fpd.l 2009-08-04 18:03:06 UTC (rev 5385)
+++ trunk/eda/fped/fpd.l 2009-08-04 21:45:33 UTC (rev 5386)
@@ -93,7 +93,7 @@
<INITIAL>"meas" { BEGIN(NOKEYWORD);
return TOK_MEAS; }
-[a-zA-Z_][a-zA-Z_0-9]*: { *strchr(yytext, ':') = 0;
+<INITIAL>[a-zA-Z_][a-zA-Z_0-9]*: { *strchr(yytext, ':') = 0;
yylval.id = unique(yytext);
return LABEL; }
[a-zA-Z_][a-zA-Z_0-9]* { yylval.id = unique(yytext);
Modified: trunk/eda/fped/gui_inst.c
===================================================================
--- trunk/eda/fped/gui_inst.c 2009-08-04 18:03:06 UTC (rev 5385)
+++ trunk/eda/fped/gui_inst.c 2009-08-04 21:45:33 UTC (rev 5386)
@@ -176,7 +176,7 @@
r = self->u.rect.width/scale/2;
if (r < SELECT_R)
r = SELECT_R;
- d = dist_line(pos, self->bbox.min, self->bbox.max)/scale;
+ d = dist_line(pos, self->base, self->u.rect.end)/scale;
return d > r ? -1 : d;
}
@@ -203,21 +203,22 @@
r = self->u.rect.width/scale/2;
if (r < SELECT_R)
r = SELECT_R;
- d = dist_rect(pos, self->bbox.min, self->bbox.max)/scale;
+ d = dist_rect(pos, self->base, self->u.rect.end)/scale;
return d > r ? -1 : d;
}
void gui_draw_rect(struct inst *self, struct draw_ctx *ctx)
{
- struct coord min = translate(ctx, self->bbox.min);
- struct coord max = translate(ctx, self->bbox.max);
+ struct coord min = translate(ctx, self->base);
+ struct coord max = translate(ctx, self->u.rect.end);
GdkGC *gc;
+ sort_coord(&min, &max);
gc = gc_obj[get_mode(self)];
set_width(gc, self->u.rect.width/ctx->scale);
gdk_draw_rectangle(DA, gc, FALSE,
- min.x, max.y, max.x-min.x, min.y-max.y);
+ min.x, min.y, max.x-min.x, max.y-min.y);
}
@@ -228,31 +229,32 @@
{
unit_type d;
- if (inside_rect(pos, self->bbox.min, self->bbox.max))
+ if (inside_rect(pos, self->base, self->u.pad.other))
return SELECT_R;
- d = dist_rect(pos, self->bbox.min, self->bbox.max)/scale;
+ d = dist_rect(pos, self->base, self->u.pad.other)/scale;
return d > SELECT_R ? -1 : d;
}
void gui_draw_pad(struct inst *self, struct draw_ctx *ctx)
{
- struct coord min = translate(ctx, self->bbox.min);
- struct coord max = translate(ctx, self->bbox.max);
+ struct coord min = translate(ctx, self->base);
+ struct coord max = translate(ctx, self->u.pad.other);
GdkGC *gc;
struct coord c;
unit_type h, w;
gc = gc_pad[get_mode(self)];
+ sort_coord(&min, &max);
gdk_draw_rectangle(DA, gc, TRUE,
- min.x, max.y, max.x-min.x, min.y-max.y);
+ min.x, min.y, max.x-min.x, max.y-min.y);
gc = gc_ptext[get_mode(self)];
c = add_vec(min, max);
- h = min.y-max.y;
+ h = max.y-min.y;
w = max.x-min.x;
- render_text(DA, gc, c.x/2, c.y/2, w <= h*1.1 ? 0 : 90, self->u.name,
- PAD_FONT, 0.5, 0.5,
+ render_text(DA, gc, c.x/2, c.y/2, w <= h*1.1 ? 0 : 90,
+ self->u.pad.name, PAD_FONT, 0.5, 0.5,
w-2*PAD_BORDER, h-2*PAD_BORDER);
}
@@ -260,17 +262,6 @@
/* ----- arc --------------------------------------------------------------- */
-static struct coord rotate_r(struct coord center, unit_type r, double angle)
-{
- struct coord res;
-
- angle = angle/180.0*M_PI;
- res.x = center.x+r*cos(angle);
- res.y = center.y+r*sin(angle);
- return res;
-}
-
-
unit_type gui_dist_arc(struct inst *self, struct coord pos, unit_type scale)
{
struct coord c = self->base;
@@ -305,9 +296,7 @@
/* see if we're close to the part that's actually drawn */
- angle = atan2(pos.y-c.y, pos.x-c.x)/M_PI*180.0;
- if (angle < 0)
- angle += 180;
+ angle = theta(c, pos);
a2 = self->u.arc.a2;
if (a2 < self->u.arc.a1)
a2 += 180;
Modified: trunk/eda/fped/gui_tools.c
===================================================================
--- trunk/eda/fped/gui_tools.c 2009-08-04 18:03:06 UTC (rev 5385)
+++ trunk/eda/fped/gui_tools.c 2009-08-04 21:45:33 UTC (rev 5386)
@@ -65,7 +65,6 @@
static struct tool_ops vec_ops;
static struct tool_ops frame_ops;
static struct tool_ops pad_ops;
-static struct tool_ops circ_ops;
static struct tool_ops meas_ops;
@@ -101,6 +100,31 @@
}
+struct pix_buf *draw_move_line(struct inst *inst, struct draw_ctx *ctx,
+ struct coord pos, int i)
+{
+ struct coord from, to;
+ struct pix_buf *buf;
+
+ from = translate(ctx, inst->base);
+ to = translate(ctx, inst->u.rect.end);
+ pos = translate(ctx, pos);
+ switch (i) {
+ case 0:
+ from = pos;
+ break;
+ case 1:
+ to = pos;
+ break;
+ default:
+ abort();
+ }
+ buf = save_pix_buf(DA, from.x, from.y, to.x, to.y, 1);
+ gdk_draw_line(DA, gc_drag, from.x, from.y, to.x, to.y);
+ return buf;
+}
+
+
static int end_new_line(struct draw_ctx *ctx,
struct inst *from, struct inst *to)
{
@@ -124,16 +148,6 @@
/* ----- rect -------------------------------------------------------------- */
-static void swap_coord(unit_type *a, unit_type *b)
-{
- unit_type tmp;
-
- tmp = *a;
- *a = *b;
- *b = tmp;
-}
-
-
static struct pix_buf *drag_new_rect(struct draw_ctx *ctx,
struct inst *from, struct coord to)
{
@@ -142,10 +156,7 @@
pos = translate(ctx, inst_get_point(from));
to = translate(ctx, to);
- if (pos.x > to.x)
- swap_coord(&pos.x, &to.x);
- if (pos.y > to.y)
- swap_coord(&pos.y, &to.y);
+ sort_coord(&pos, &to);
buf = save_pix_buf(DA, pos.x, pos.y, to.x, to.y, 1);
gdk_draw_rectangle(DA, gc_drag, FALSE,
pos.x, pos.y, to.x-pos.x, to.y-pos.y);
@@ -153,6 +164,40 @@
}
+static struct pix_buf *draw_move_rect_common(struct inst *inst,
+ struct coord other, struct draw_ctx *ctx, struct coord pos, int i)
+{
+ struct coord min, max;
+ struct pix_buf *buf;
+
+ min = translate(ctx, inst->base);
+ max = translate(ctx, other);
+ pos = translate(ctx, pos);
+ switch (i) {
+ case 0:
+ min = pos;
+ break;
+ case 1:
+ max = pos;
+ break;
+ default:
+ abort();
+ }
+ sort_coord(&min, &max);
+ buf = save_pix_buf(DA, min.x, min.y, max.x, max.y, 1);
+ gdk_draw_rectangle(DA, gc_drag, FALSE,
+ min.x, min.y, max.x-min.x, max.y-min.y);
+ return buf;
+}
+
+
+struct pix_buf *draw_move_rect(struct inst *inst, struct draw_ctx *ctx,
+ struct coord pos, int i)
+{
+ return draw_move_rect_common(inst, inst->u.rect.end, ctx, pos, i);
+}
+
+
static int end_new_rect(struct draw_ctx *ctx,
struct inst *from, struct inst *to)
{
@@ -173,6 +218,36 @@
};
+/* ----- pad --------------------------------------------------------------- */
+
+
+static int end_new_pad(struct draw_ctx *ctx,
+ struct inst *from, struct inst *to)
+{
+ struct obj *obj;
+
+ if (from == to)
+ return 0;
+ obj = new_obj(ot_pad, from);
+ obj->u.pad.other = inst_get_ref(to);
+ obj->u.pad.name = stralloc("?");
+ return 1;
+}
+
+
+struct pix_buf *draw_move_pad(struct inst *inst, struct draw_ctx *ctx,
+ struct coord pos, int i)
+{
+ return draw_move_rect_common(inst, inst->u.pad.other, ctx, pos, i);
+}
+
+
+static struct tool_ops pad_ops = {
+ .drag_new = drag_new_rect,
+ .end_new = end_new_pad,
+};
+
+
/* ----- circ -------------------------------------------------------------- */
@@ -207,6 +282,83 @@
}
+struct pix_buf *draw_move_arc(struct inst *inst, struct draw_ctx *ctx,
+ struct coord pos, int i)
+{
+ struct coord c, from, to;
+ double r, a1, a2;
+ struct pix_buf *buf;
+
+ c = translate(ctx, inst->base);
+ from =
+ translate(ctx, rotate_r(inst->base, inst->u.arc.r, inst->u.arc.a1));
+ to =
+ translate(ctx, rotate_r(inst->base, inst->u.arc.r, inst->u.arc.a2));
+ pos = translate(ctx, pos);
+ switch (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:
+ to = pos;
+ break;
+ default:
+ abort();
+ }
+ r = hypot(from.x-c.x, from.y-c.y);
+ /*
+ * the screen coordinate system is reversed with y growing downward,
+ * so we have to negate the angles.
+ */
+ a1 = -theta(c, from);
+ a2 = -theta(c, to);
+ if (a2 < a1)
+ a2 += 360.0;
+ buf = save_pix_buf(DA, c.x-r, c.y-r, c.x+r, c.y+r, 1);
+ draw_arc(DA, gc_drag, FALSE, c.x, c.y, r, a1, a2);
+ return buf;
+}
+
+
+static void replace(struct vec **anchor, struct vec *new)
+{
+ if (*anchor)
+ (*anchor)->n_refs--;
+ *anchor = new;
+ if (new)
+ new->n_refs++;
+}
+
+
+void do_move_to_arc(struct inst *inst, struct vec *vec, int i)
+{
+ struct obj *obj = inst->obj;
+ int is_circle;
+
+ is_circle = obj->u.arc.start == obj->u.arc.end;
+ switch (i) {
+ case 0:
+ replace(&obj->base, vec);
+ break;
+ case 1:
+ replace(&obj->u.arc.start, vec);
+ if (!is_circle)
+ break;
+ /* fall through */
+ case 2:
+ replace(&obj->u.arc.end, vec);
+ break;
+ default:
+ abort();
+ }
+}
+
+
static struct tool_ops circ_ops = {
.drag_new = drag_new_circ,
.end_new = end_new_circ,
@@ -274,7 +426,6 @@
if (old)
old->n_refs--;
*state->anchors[state->anchor_i] = inst_get_ref(curr);
- state->anchors_n = 0;
}
@@ -339,7 +490,8 @@
if (pix_buf)
restore_pix_buf(pix_buf);
tool_hover(ctx, to);
- pix_buf = drag.new ? active_ops->drag_new(ctx, drag.new, to) : NULL;
+ pix_buf = drag.new ? active_ops->drag_new(ctx, drag.new, to) :
+ inst_draw_move(selected_inst, ctx, to, drag.anchor_i);
}
@@ -369,7 +521,8 @@
return ops->end_new(ctx, state.new, end);
if (!may_move_to(&state, end))
return 0;
- do_move_to(&state, end);
+ if (!inst_do_move_to(selected_inst, inst_get_vec(end), state.anchor_i))
+ do_move_to(&state, end);
return 1;
}
Modified: trunk/eda/fped/gui_tools.h
===================================================================
--- trunk/eda/fped/gui_tools.h 2009-08-04 18:03:06 UTC (rev 5385)
+++ trunk/eda/fped/gui_tools.h 2009-08-04 21:45:33 UTC (rev 5386)
@@ -19,6 +19,17 @@
#include "inst.h"
+struct pix_buf *draw_move_line(struct inst *inst, struct draw_ctx *ctx,
+ struct coord pos, int i);
+struct pix_buf *draw_move_rect(struct inst *inst, struct draw_ctx *ctx,
+ struct coord pos, int i);
+struct pix_buf *draw_move_pad(struct inst *inst, struct draw_ctx *ctx,
+ struct coord pos, int i);
+struct pix_buf *draw_move_arc(struct inst *inst, struct draw_ctx *ctx,
+ struct coord pos, int i);
+
+void do_move_to_arc(struct inst *inst, struct vec *vec, int i);
+
void tool_dehover(struct draw_ctx *ctx);
void tool_hover(struct draw_ctx *ctx, struct coord pos);
int tool_consider_drag(struct draw_ctx *ctx, struct coord pos);
Modified: trunk/eda/fped/gui_util.c
===================================================================
--- trunk/eda/fped/gui_util.c 2009-08-04 18:03:06 UTC (rev 5385)
+++ trunk/eda/fped/gui_util.c 2009-08-04 21:45:33 UTC (rev 5386)
@@ -79,7 +79,7 @@
buf->x = 0;
}
if (buf->y < 0) {
- w += buf->y;
+ h += buf->y;
buf->y = 0;
}
buf->buf = gdk_pixbuf_get_from_drawable(NULL, da, NULL,
Modified: trunk/eda/fped/inst.c
===================================================================
--- trunk/eda/fped/inst.c 2009-08-04 18:03:06 UTC (rev 5385)
+++ trunk/eda/fped/inst.c 2009-08-04 21:45:33 UTC (rev 5386)
@@ -20,7 +20,7 @@
#include "expr.h"
#include "obj.h"
#include "gui_status.h"
-#include "gui_status.h"
+#include "gui_tools.h"
#include "gui_inst.h"
#include "inst.h"
@@ -34,6 +34,10 @@
unit_type scale);
void (*select)(struct inst *self);
int (*anchors)(struct inst *self, struct vec ***anchors);
+ struct pix_buf *(*draw_move)(struct inst *inst, struct draw_ctx *ctx,
+ struct coord pos, int i);
+ /* arcs need this special override */
+ void (*do_move_to)(struct inst *inst, struct vec *vec, int i);
};
enum inst_prio {
@@ -269,9 +273,7 @@
if (!d.x && !d.y)
status_set_angle("a = 0 deg");
else {
- angle = atan2(d.y, d.x)/M_PI*180.0;
- if (angle < 0)
- angle += 360;
+ angle = theta(a, b);
status_set_angle("a = %3.1f deg", angle);
}
status_set_r("r = %5.2f mm", hypot(units_to_mm(d.x), units_to_mm(d.y)));
@@ -432,6 +434,7 @@
.distance = gui_dist_line,
.select = line_op_select,
.anchors = line_op_anchors,
+ .draw_move = draw_move_line,
};
@@ -474,6 +477,7 @@
.distance = gui_dist_rect,
.select = rect_op_select,
.anchors = line_op_anchors,
+ .draw_move = draw_move_rect,
};
@@ -498,8 +502,8 @@
static void pad_op_debug(struct inst *self)
{
printf("pad \"%s\" %lg, %lg / %lg, %lg\n", self->u.name,
- units_to_mm(self->bbox.min.x), units_to_mm(self->bbox.min.y),
- units_to_mm(self->bbox.max.x), units_to_mm(self->bbox.max.y));
+ units_to_mm(self->base.x), units_to_mm(self->base.y),
+ units_to_mm(self->u.pad.other.x), units_to_mm(self->u.pad.other.y));
}
@@ -518,8 +522,8 @@
static void pad_op_select(struct inst *self)
{
status_set_type_entry("label =");
- status_set_name("%s", self->u.name);
- rect_status(self->bbox.min, self->bbox.max, -1);
+ status_set_name("%s", self->u.pad.name);
+ rect_status(self->base, self->u.pad.other, -1);
edit_name(&self->obj->u.pad.name, validate_pad_name, NULL);
}
@@ -540,6 +544,7 @@
.distance = gui_dist_pad,
.select = pad_op_select,
.anchors = pad_op_anchors,
+ .draw_move = draw_move_pad,
};
@@ -549,7 +554,8 @@
inst = add_inst(&pad_ops, ip_pad, a);
inst->obj = obj;
- inst->u.name = stralloc(name);
+ inst->u.pad.name = stralloc(name);
+ inst->u.pad.other = b;
update_bbox(&inst->bbox, b);
propagate_bbox(inst);
return 1;
@@ -597,6 +603,8 @@
.distance = gui_dist_arc,
.select = arc_op_select,
.anchors = arc_op_anchors,
+ .draw_move = draw_move_arc,
+ .do_move_to = do_move_to_arc,
};
@@ -609,13 +617,9 @@
inst = add_inst(&arc_ops, ip_arc, center);
inst->obj = obj;
r = hypot(start.x-center.x, start.y-center.y);
- a1 = atan2(start.y-center.y, start.x-center.x)/M_PI*180.0;
- a2 = atan2(end.y-center.y, end.x-center.x)/M_PI*180.0;
- if (a1 < 0)
- a1 += 360.0;
- if (a2 < 0)
- a2 += 360.0;
inst->u.arc.r = r;
+ a1 = theta(center, start);
+ a2 = theta(center, end);
inst->u.arc.a1 = a1;
inst->u.arc.a2 = a2;
inst->u.arc.width = width;
@@ -834,6 +838,22 @@
}
+struct pix_buf *inst_draw_move(struct inst *inst, struct draw_ctx *ctx,
+ struct coord pos, int i)
+{
+ return inst->ops->draw_move(inst, ctx, pos, i);
+}
+
+
+int inst_do_move_to(struct inst *inst, struct vec *vec, int i)
+{
+ if (!inst->ops->do_move_to)
+ return 0;
+ inst->ops->do_move_to(inst, vec, i);
+ return 1;
+}
+
+
void inst_hover(struct inst *inst, struct draw_ctx *ctx, int on)
{
if (!inst->ops->hover)
Modified: trunk/eda/fped/inst.h
===================================================================
--- trunk/eda/fped/inst.h 2009-08-04 18:03:06 UTC (rev 5385)
+++ trunk/eda/fped/inst.h 2009-08-04 21:45:33 UTC (rev 5386)
@@ -59,6 +59,10 @@
unit_type width;
} rect;
struct {
+ const char *name;
+ struct coord other;
+ } pad;
+ struct {
unit_type r;
double a1, a2;
unit_type width;
@@ -109,6 +113,9 @@
void inst_revert(void);
void inst_draw(struct draw_ctx *ctx);
+struct pix_buf *inst_draw_move(struct inst *inst, struct draw_ctx *ctx,
+ struct coord pos, int i);
+int inst_do_move_to(struct inst *inst, struct vec *vec, int i);
void inst_hover(struct inst *inst, struct draw_ctx *ctx, int on);
void inst_debug(void);
--- End Message ---