Send commitlog mailing list submissions to
        commitlog@lists.openmoko.org

To subscribe or unsubscribe via the World Wide Web, visit
        http://lists.openmoko.org/mailman/listinfo/commitlog
or, via email, send a message with subject or body 'help' to
        commitlog-requ...@lists.openmoko.org

You can reach the person managing the list at
        commitlog-ow...@lists.openmoko.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of commitlog digest..."
Today's Topics:

   1. r5388 - trunk/eda/fped (wer...@docs.openmoko.org)
   2. r5389 - in trunk/eda/fped: . icons (wer...@docs.openmoko.org)
--- Begin Message ---
Author: werner
Date: 2009-08-05 12:35:48 +0200 (Wed, 05 Aug 2009)
New Revision: 5388

Added:
   trunk/eda/fped/dump.c
   trunk/eda/fped/dump.h
Modified:
   trunk/eda/fped/Makefile
   trunk/eda/fped/TODO
   trunk/eda/fped/delete.h
   trunk/eda/fped/fped.c
   trunk/eda/fped/gui.c
   trunk/eda/fped/gui.h
Log:
- started functions to dump .fpd files (automatic labeling doesn't quite work 
  yet)
- don't pass argc, argv to gui_main. They've been harvested before.



Modified: trunk/eda/fped/Makefile
===================================================================
--- trunk/eda/fped/Makefile     2009-08-05 00:32:38 UTC (rev 5387)
+++ trunk/eda/fped/Makefile     2009-08-05 10:35:48 UTC (rev 5388)
@@ -11,7 +11,7 @@
 #
 
 OBJS = fped.o expr.o coord.o obj.o delete.o inst.o util.o error.o \
-       unparse.o \
+       unparse.o dump.o \
        cpp.o lex.yy.o y.tab.o \
        gui.o gui_util.o gui_style.o gui_inst.o gui_status.o gui_canvas.o \
        gui_tools.o

Modified: trunk/eda/fped/TODO
===================================================================
--- trunk/eda/fped/TODO 2009-08-05 00:32:38 UTC (rev 5387)
+++ trunk/eda/fped/TODO 2009-08-05 10:35:48 UTC (rev 5388)
@@ -8,6 +8,7 @@
 - add KiCad output
 - add postscript output
 - add option to include/omit helper vecs and frames (display and postscript)
+- define part name
 
 Error detection:
 - eliminate duplicate instances
@@ -15,6 +16,7 @@
 Style:
 - make column of entry field greedily consume all unallocated space
 - status area looks awful
+- status area bounces when something becomes editable
 
 Bugs:
 - default silk width has no business being hard-coded in obj.c

Modified: trunk/eda/fped/delete.h
===================================================================
--- trunk/eda/fped/delete.h     2009-08-05 00:32:38 UTC (rev 5387)
+++ trunk/eda/fped/delete.h     2009-08-05 10:35:48 UTC (rev 5388)
@@ -23,4 +23,4 @@
 int destroy(void);
 int undelete(void);
 
-#endif /* !OBJ_H */
+#endif /* !DELETE_H */

Added: trunk/eda/fped/dump.c
===================================================================
--- trunk/eda/fped/dump.c                               (rev 0)
+++ trunk/eda/fped/dump.c       2009-08-05 10:35:48 UTC (rev 5388)
@@ -0,0 +1,326 @@
+/*
+ * dump.c - Dump objects in the native FPD format
+ *
+ * Written 2009 by Werner Almesberger
+ * Copyright 2009 by Werner Almesberger
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "util.h"
+#include "unparse.h"
+#include "obj.h"
+#include "dump.h"
+
+
+/* ----- variables --------------------------------------------------------- */
+
+
+static void dump_var(FILE *file, const struct table *table,
+    const char *indent)
+{
+       char *s;
+
+       s = unparse(table->rows->values->expr);
+       fprintf(file, "%sset %s = %s\n\n", indent, table->vars->name, s);
+       free(s);
+}
+
+
+static void dump_table(FILE *file, const struct table *table,
+    const char *indent)
+{
+       const struct var *var;
+       const struct row *row;
+       const struct value *value;
+       char *s;
+
+       if (table->vars && !table->vars->next &&
+           table->rows && !table->rows->next) {
+               dump_var(file, table, indent);
+               return;
+       }
+       fprintf(file, "%stable\n%s    {", indent, indent);
+       for (var = table->vars; var; var = var->next)
+               fprintf(file, "%s %s", var == table->vars ? "" : ",",
+                   var->name);
+       fprintf(file, " }\n");
+       for (row = table->rows; row; row = row->next) {
+               fprintf(file, "%s    {", indent);
+               for (value = row->values; value; value = value->next) {
+                       s = unparse(value->expr);
+                       fprintf(file, "%s %s",
+                           value == row->values? "" : ",", s);
+                       free(s);
+               }
+               fprintf(file, " }\n");
+       }
+       fprintf(file, "\n");
+}
+
+
+static void dump_loop(FILE *file, const struct loop *loop, const char *indent)
+{
+       char *from, *to;
+
+       from = unparse(loop->from.expr);
+       to = unparse(loop->to.expr);
+       fprintf(file, "%sloop %s = %s, %s\n\n",
+           indent, loop->var.name, from, to);
+       free(from);
+       free(to);
+}
+
+
+/* ----- vectors and objects ----------------------------------------------- */
+
+
+static char *base_name(const struct vec *vec, const struct vec *base)
+{
+       const struct vec *walk;
+       int n;
+
+       if (!base)
+               return stralloc("@");
+       if (vec && base->next == vec)
+               return stralloc(".");
+       if (base->name)
+               return stralloc(base->name);
+       n = 0;
+       for (walk = base->frame->vecs; walk != base; walk = walk->next)
+               n++;
+       return stralloc_printf("_%s_%d",
+           base->frame->name ? base->frame->name : "", n);
+}
+
+
+static char *obj_base_name(const struct vec *base, const struct vec *prev)
+{
+       if (base && base == prev)
+               return stralloc(".");
+       return base_name(NULL, base);
+}
+
+
+static int n_vec_refs(const struct vec *vec)
+{
+       const struct vec *walk;
+       int n;
+
+       if (!vec->n_refs)
+               return 0;
+       n = 0;
+       for (walk = vec->frame->vecs; walk; walk = walk->next)
+               if (walk->base == vec)
+                       n++;
+       return n;
+}
+
+
+/*
+ * "need" operates in two modes:
+ *
+ * - if "prev" is non-NULL, we're looking for objects that need to be put after
+ *   the current vector (in "prev"). Only those objects need to be put there
+ *   that have at least one base that isn't the frame's origin or already has a
+ *   name.
+ *
+ * - if "prev" is NULL, we're at the end of the frame. We have already used all
+ *   the . references we could, so now we have to find out which objects
+ *   haven't been dumped yet. "need" still returns the ones that had a need to
+ *   be dumped. Again, that's those that have at least one possible "." base.
+ *   Since this "." base will have been used by now, the object must have been
+ *   dumped.
+ */
+
+static int need(const struct vec *base, const struct vec *prev)
+{
+       if (!base)
+               return 0;
+       if (base->name)
+               return 0;
+       if (prev)
+               return base == prev;
+       return 1;
+}
+
+
+static void dump_obj(FILE *file, const struct obj *obj, const char *indent,
+    const struct vec *prev)
+{
+       char *base, *s1, *s2, *s3;
+       int n;
+
+       n = need(obj->base, prev);
+
+       switch (obj->type) {
+       case ot_frame:
+               break;
+       case ot_line:
+               n |= need(obj->u.line.other, prev);
+               break;
+       case ot_rect:
+               n |= need(obj->u.rect.other, prev);
+               break;
+       case ot_pad:
+               n |= need(obj->u.pad.other, prev);
+               break;
+       case ot_arc:
+               n |= need(obj->u.arc.start, prev);
+               n |= need(obj->u.arc.end, prev);
+               break;
+       case ot_meas:
+               n |= need(obj->u.meas.other, prev);
+               break;
+       default:
+               abort();
+       }
+
+       if (prev ? !n : n)
+               return;
+
+       base = obj_base_name(obj->base, prev);
+       switch (obj->type) {
+       case ot_frame:
+               fprintf(file, "%sframe %s %s\n",
+                   indent, obj->u.frame.ref->name, base);
+               break;
+       case ot_line:
+               s1 = obj_base_name(obj->u.line.other, prev);
+               s2 = unparse(obj->u.line.width);
+               fprintf(file, "%sline %s %s %s\n", indent, base, s1, s2);
+               free(s1);
+               free(s2);
+               break;
+       case ot_rect:
+               s1 = obj_base_name(obj->u.rect.other, prev);
+               s2 = unparse(obj->u.rect.width);
+               fprintf(file, "%srect %s %s %s\n", indent, base, s1, s2);
+               free(s1);
+               free(s2);
+               break;
+       case ot_pad:
+               s1 = obj_base_name(obj->u.pad.other, prev);
+               fprintf(file, "%spad \"%s\" %s %s\n", indent,
+                   obj->u.pad.name, base, s1);
+               free(s1);
+               break;
+       case ot_arc:
+               s1 = obj_base_name(obj->u.arc.start, prev);
+               s3 = unparse(obj->u.arc.width);
+               if (obj->u.arc.start == obj->u.arc.end) {
+                       fprintf(file, "%scirc %s %s %s\n",
+                           indent, base, s1, s3);
+               } else {
+                       s2 = obj_base_name(obj->u.arc.end, prev);
+                       fprintf(file, "%sarc %s %s %s %s\n", indent,
+                           base, s1, s2, s3);
+                       free(s2);
+               }
+               free(s1);
+               free(s3);
+               break;
+       case ot_meas:
+               s1 = obj_base_name(obj->u.meas.other, prev);
+               s2 = unparse(obj->u.meas.offset);
+               fprintf(file, "%smeas %s %s %s\n", indent, base, s1, s2);
+               free(s1);
+               free(s2);
+               break;
+       default:
+               abort();
+       }
+       free(base);
+}
+
+
+/*
+ * Tricky logic ahead: when dumping a vector, we search for a vectors that
+ * depends on that vector for ".". If we find one, we dump it immediately after
+ * this vector.
+ */
+
+static void recurse_vec(FILE *file, const struct vec *vec, const char *indent)
+{
+       const struct vec *next;
+       const struct obj *obj;
+       char *base, *x, *y;
+
+       base = base_name(vec, vec->base);
+       x = unparse(vec->x);
+       y = unparse(vec->y);
+       if (vec->name)
+               fprintf(file, "%s%s: vec %s(%s, %s)\n",
+                   indent, vec->name, base, x, y);
+       else
+               fprintf(file, "%svec %s(%s, %s)\n", indent, base, x, y);
+       free(base);
+       free(x);
+       free(y);
+
+       for (obj = vec->frame->objs; obj; obj = obj->next)
+               dump_obj(file, obj, indent, vec);
+       if (n_vec_refs(vec) == 1) {
+               for (next = vec->next; next->base != vec; next = next->next);
+               recurse_vec(file, next, indent);
+       }
+}
+
+
+static void dump_vecs(FILE *file, const struct vec *vecs, const char *indent)
+{
+       const struct vec *vec;
+
+       for (vec = vecs; vec; vec = vec->next)
+               if (!vec->base || n_vec_refs(vec->base) != 1)
+                       recurse_vec(file, vec, indent);
+}
+
+
+/* ----- frames ------------------------------------------------------------ */
+
+
+static void dump_frame(FILE *file, const struct frame *frame,
+    const char *indent)
+{
+       const struct table *table;
+       const struct loop *loop;
+       const struct obj *obj;
+
+       for (table = frame->tables; table; table = table->next)
+               dump_table(file, table, indent);
+       for (loop = frame->loops; loop; loop = loop->next)
+               dump_loop(file, loop, indent);
+       dump_vecs(file, frame->vecs, indent);
+       for (obj = frame->objs; obj; obj = obj->next)
+               dump_obj(file, obj, indent, NULL);
+}
+
+
+/* ----- file -------------------------------------------------------------- */
+
+
+int dump(FILE *file)
+{
+       const struct frame *frame;
+
+       fprintf(file, "/* MACHINE-GENERATED ! */\n\n");
+       for (frame = frames; frame; frame = frame->next) {
+               if (!frame->name)
+                       dump_frame(file, frame, "");
+               else {
+                       fprintf(file, "frame %s {\n", frame->name);
+                       dump_frame(file, frame, "\t");
+                       fprintf(file, "}\n\n");
+               }
+       }
+       fflush(file);
+       return !ferror(file);
+}

Added: trunk/eda/fped/dump.h
===================================================================
--- trunk/eda/fped/dump.h                               (rev 0)
+++ trunk/eda/fped/dump.h       2009-08-05 10:35:48 UTC (rev 5388)
@@ -0,0 +1,22 @@
+/*
+ * dump.h - Dump objects in the native FPD format
+ *
+ * Written 2009 by Werner Almesberger
+ * Copyright 2009 by Werner Almesberger
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+
+#ifndef DUMP_H
+#define DUMP_H
+
+#include <stdio.h>
+
+
+int dump(FILE *file);
+
+#endif /* !DUMP_H */

Modified: trunk/eda/fped/fped.c
===================================================================
--- trunk/eda/fped/fped.c       2009-08-05 00:32:38 UTC (rev 5387)
+++ trunk/eda/fped/fped.c       2009-08-05 10:35:48 UTC (rev 5388)
@@ -50,8 +50,11 @@
        if (!instantiate())
                return 1;
 //     inst_debug();
-       error = gui_main(argc, argv);
+       error = gui_main();
        if (error)
                return error;
+
+//     dump(stdout);
+
        return 0;
 }

Modified: trunk/eda/fped/gui.c
===================================================================
--- trunk/eda/fped/gui.c        2009-08-05 00:32:38 UTC (rev 5387)
+++ trunk/eda/fped/gui.c        2009-08-05 10:35:48 UTC (rev 5388)
@@ -678,7 +678,7 @@
 }
 
 
-int gui_main(int argc, char **argv)
+int gui_main(void)
 {
        root = gtk_window_new(GTK_WINDOW_TOPLEVEL);
        gtk_window_set_position(GTK_WINDOW(root), GTK_WIN_POS_CENTER);

Modified: trunk/eda/fped/gui.h
===================================================================
--- trunk/eda/fped/gui.h        2009-08-05 00:32:38 UTC (rev 5387)
+++ trunk/eda/fped/gui.h        2009-08-05 10:35:48 UTC (rev 5388)
@@ -24,6 +24,6 @@
 void change_world(void);
 
 int gui_init(int *argc, char ***argv);
-int gui_main(int argc, char **argv);
+int gui_main(void);
 
 #endif /* !GUI_H */




--- End Message ---
--- Begin Message ---
Author: werner
Date: 2009-08-05 16:44:36 +0200 (Wed, 05 Aug 2009)
New Revision: 5389

Added:
   trunk/eda/fped/icons/frame_locked.fig
   trunk/eda/fped/icons/frame_ready.fig
Modified:
   trunk/eda/fped/Makefile
   trunk/eda/fped/expr.c
   trunk/eda/fped/expr.h
   trunk/eda/fped/gui.c
   trunk/eda/fped/gui_canvas.c
   trunk/eda/fped/gui_tools.c
   trunk/eda/fped/gui_tools.h
   trunk/eda/fped/icons/frame.fig
   trunk/eda/fped/inst.c
Log:
- GUI: added creation and moving of vectors, measurements, and frame references



Modified: trunk/eda/fped/Makefile
===================================================================
--- trunk/eda/fped/Makefile     2009-08-05 10:35:48 UTC (rev 5388)
+++ trunk/eda/fped/Makefile     2009-08-05 14:44:36 UTC (rev 5389)
@@ -16,7 +16,7 @@
        gui.o gui_util.o gui_style.o gui_inst.o gui_status.o gui_canvas.o \
        gui_tools.o
 
-XPMS = point.xpm vec.xpm frame.xpm \
+XPMS = point.xpm vec.xpm frame.xpm frame_locked.xpm frame_ready.xpm \
        line.xpm rect.xpm pad.xpm circ.xpm meas.xpm
 
 CFLAGS_GTK = `pkg-config --cflags gtk+-2.0`

Modified: trunk/eda/fped/expr.c
===================================================================
--- trunk/eda/fped/expr.c       2009-08-05 10:35:48 UTC (rev 5388)
+++ trunk/eda/fped/expr.c       2009-08-05 14:44:36 UTC (rev 5389)
@@ -384,6 +384,19 @@
 }
 
 
+/* ----- make a number -----------------------------------------------------*/
+
+
+struct expr *new_num(struct num num)
+{
+       struct expr *expr;
+
+       expr = new_op(op_num);
+       expr->u.num = num;
+       return expr;
+}
+
+
 /* ----- expression-only parser -------------------------------------------- */
 
 

Modified: trunk/eda/fped/expr.h
===================================================================
--- trunk/eda/fped/expr.h       2009-08-05 10:35:48 UTC (rev 5388)
+++ trunk/eda/fped/expr.h       2009-08-05 14:44:36 UTC (rev 5389)
@@ -81,6 +81,17 @@
 }
 
 
+static inline struct num make_mm(double mm)
+{
+       struct num res;
+
+       res.type = nt_mm;
+       res.exponent = 1;
+       res.n = mm;
+       return res;
+}
+
+
 static inline struct num make_mil(double mil)
 {
        struct num res;
@@ -114,6 +125,7 @@
 /* if frame == NULL, we only check the syntax without expanding */
 char *expand(const char *name, const struct frame *frame);
 
+struct expr *new_num(struct num num);
 struct expr *parse_expr(const char *s);
 void free_expr(struct expr *expr);
 

Modified: trunk/eda/fped/gui.c
===================================================================
--- trunk/eda/fped/gui.c        2009-08-05 10:35:48 UTC (rev 5388)
+++ trunk/eda/fped/gui.c        2009-08-05 14:44:36 UTC (rev 5389)
@@ -503,6 +503,7 @@
        if (active_frame)
                label_in_box_bg(active_frame->label, COLOR_FRAME_UNSELECTED);
        active_frame = frame;
+       tool_frame_update();
        change_world();
 }
 
@@ -648,7 +649,6 @@
 
 void change_world(void)
 {
-       tool_reset();
        inst_deselect();
        status_begin_reporting();
        instantiate();

Modified: trunk/eda/fped/gui_canvas.c
===================================================================
--- trunk/eda/fped/gui_canvas.c 2009-08-05 10:35:48 UTC (rev 5388)
+++ trunk/eda/fped/gui_canvas.c 2009-08-05 14:44:36 UTC (rev 5389)
@@ -154,6 +154,7 @@
 {
        struct coord pos = canvas_to_coord(&ctx, event->x, event->y);
        const struct inst *prev;
+       int res;
 
        switch (event->button) {
        case 1:
@@ -162,7 +163,15 @@
                        tool_cancel_drag(&ctx);
                        dragging = 0;
                }
-               if (tool_consider_drag(&ctx, pos)) {
+               res = tool_consider_drag(&ctx, pos);
+               /* tool doesn't do drag */
+               if (res < 0) {
+                       change_world();
+                       inst_deselect();
+                       break;
+               }
+               if (res) {
+                       inst_deselect();
                        dragging = 1;
                        drag_escaped = 0;
                        drag_start = pos;
@@ -292,8 +301,10 @@
        case GDK_BackSpace:
        case GDK_Delete:
        case GDK_KP_Delete:
-               if (selected_inst && inst_delete(selected_inst))
+               if (selected_inst && inst_delete(selected_inst)) {
+                       tool_frame_update();
                        change_world();
+               }
                break;
        case 'u':
                if (undelete())

Modified: trunk/eda/fped/gui_tools.c
===================================================================
--- trunk/eda/fped/gui_tools.c  2009-08-05 10:35:48 UTC (rev 5388)
+++ trunk/eda/fped/gui_tools.c  2009-08-05 14:44:36 UTC (rev 5389)
@@ -12,6 +12,7 @@
 
 
 #include <stdlib.h>
+#include <math.h>
 #include <assert.h>
 #include <gtk/gtk.h>
 
@@ -21,11 +22,15 @@
 #include "gui_util.h"
 #include "gui_style.h"
 #include "gui_inst.h"
+#include "gui_status.h"
+#include "gui.h"
 #include "gui_tools.h"
 
 
 #include "icons/circ.xpm"
 #include "icons/frame.xpm"
+#include "icons/frame_locked.xpm"
+#include "icons/frame_ready.xpm"
 #include "icons/line.xpm"
 #include "icons/meas.xpm"
 #include "icons/pad.xpm"
@@ -38,19 +43,25 @@
 
 
 struct tool_ops {
+       void (*tool_selected)(void);
        struct pix_buf *(*drag_new)(struct draw_ctx *ctx, struct inst *from,
             struct coord to);
+       int (*end_new_raw)(struct draw_ctx *ctx, struct inst *from,
+           struct coord to);
        int (*end_new)(struct draw_ctx *ctx, struct inst *from,
            struct inst *to);
 };
 
 
-static GtkWidget *ev_point;
+static GtkWidget *ev_point, *ev_frame;
 static GtkWidget *active_tool;
 static struct tool_ops *active_ops = NULL;
 static struct inst *hover_inst = NULL;
+static GtkWidget *frame_image, *frame_image_locked, *frame_image_ready;
 
+
 static struct drag_state {
+       struct inst *inst; /* non-NULL if dragging an existing object */
        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 */
@@ -62,18 +73,30 @@
 
 static struct pix_buf *pix_buf;
 
-static struct tool_ops vec_ops;
-static struct tool_ops frame_ops;
-static struct tool_ops pad_ops;
-static struct tool_ops meas_ops;
 
+static struct vec *new_vec(struct inst *base)
+{
+       struct vec *vec, **walk;
 
+       vec = alloc_type(struct vec);
+       vec->name = NULL;
+       vec->base = inst_get_ref(base);
+       vec->n_refs = 0;
+       vec->next = NULL;
+       vec->frame = active_frame;
+       for (walk = &active_frame->vecs; *walk; walk = &(*walk)->next);
+       *walk = vec;
+       return vec;
+}
+
+
 static struct obj *new_obj(enum obj_type type, struct inst *base)
 {
        struct obj *obj, **walk;
 
        obj = alloc_type(struct obj);
        obj->type = type;
+       obj->frame = active_frame;
        obj->base = inst_get_ref(base);
        obj->next = NULL;
        obj->lineno = 0;
@@ -83,48 +106,144 @@
 }
 
 
-/* ----- line -------------------------------------------------------------- */
+/* ----- shared functions -------------------------------------------------- */
 
 
-static struct pix_buf *drag_new_line(struct draw_ctx *ctx,
-    struct inst *from, struct coord to)
+static struct pix_buf *draw_move_line_common(struct inst *inst,
+    struct coord end, struct draw_ctx *ctx, struct coord pos, int i)
 {
-       struct coord pos;
+       struct coord from, to;
        struct pix_buf *buf;
 
-       pos = translate(ctx, inst_get_point(from));
-       to = translate(ctx, to);
-       buf = save_pix_buf(DA, pos.x, pos.y, to.x, to.y, 1);
-       gdk_draw_line(DA, gc_drag, pos.x, pos.y, to.x, to.y);
+       from = translate(ctx, inst->base);
+       to = translate(ctx, 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;
 }
 
 
-struct pix_buf *draw_move_line(struct inst *inst, struct draw_ctx *ctx,
-    struct coord pos, int i)
+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 from, to;
+       struct coord min, max;
        struct pix_buf *buf;
 
-       from = translate(ctx, inst->base);
-       to = translate(ctx, inst->u.rect.end);
+       min = translate(ctx, inst->base);
+       max = translate(ctx, other);
        pos = translate(ctx, pos);
        switch (i) {
        case 0:
-               from = pos;
+               min = pos;
                break;
        case 1:
-               to = pos;
+               max = 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);
+       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;
 }
 
 
+/* ----- vec --------------------------------------------------------------- */
+
+
+static void gridify(struct coord base, struct coord *pos)
+{
+       pos->x -= fmod(pos->x-base.x, mm_to_units(0.1));
+       pos->y -= fmod(pos->y-base.y, mm_to_units(0.1));
+}
+
+
+static struct pix_buf *drag_new_vec(struct draw_ctx *ctx,
+    struct inst *from, struct coord to)
+{
+       struct coord pos;
+       struct pix_buf *buf;
+
+       pos = inst_get_point(from);
+       gridify(pos, &to);
+       status_set_type_x("dX =");
+       status_set_type_y("dX =");
+       status_set_x("%lg mm", units_to_mm(to.x-pos.x));
+       status_set_y("%lg mm", units_to_mm(to.y-pos.y));
+       pos = translate(ctx, pos);
+       to = translate(ctx, to);
+       buf = save_pix_buf(DA, pos.x, pos.y, to.x, to.y, 1);
+       gdk_draw_line(DA, gc_drag, pos.x, pos.y, to.x, to.y);
+       return buf;
+}
+
+
+struct pix_buf *draw_move_vec(struct inst *inst, struct draw_ctx *ctx,
+    struct coord pos, int i)
+{
+       return draw_move_line_common(inst,
+           add_vec(sub_vec(inst->u.rect.end, inst->base), pos), ctx, pos, i);
+}
+
+
+static int end_new_raw_vec(struct draw_ctx *ctx,
+    struct inst *from, struct coord to)
+{
+       struct vec *vec;
+       struct coord pos;
+
+       vec = new_vec(from);
+       pos = inst_get_point(from);
+       gridify(pos, &to);
+       vec->x = new_num(make_mm(units_to_mm(to.x-pos.x)));
+       vec->y = new_num(make_mm(units_to_mm(to.y-pos.y)));
+       return 1;
+}
+
+
+static struct tool_ops vec_ops = {
+       .drag_new       = drag_new_vec,
+       .end_new_raw    = end_new_raw_vec,
+};
+
+
+/* ----- line -------------------------------------------------------------- */
+
+
+static struct pix_buf *drag_new_line(struct draw_ctx *ctx,
+    struct inst *from, struct coord to)
+{
+       struct coord pos;
+       struct pix_buf *buf;
+
+       pos = translate(ctx, inst_get_point(from));
+       to = translate(ctx, to);
+       buf = save_pix_buf(DA, pos.x, pos.y, to.x, to.y, 1);
+       gdk_draw_line(DA, gc_drag, pos.x, pos.y, to.x, to.y);
+       return buf;
+}
+
+
+struct pix_buf *draw_move_line(struct inst *inst, struct draw_ctx *ctx,
+    struct coord pos, int i)
+{
+       return draw_move_line_common(inst, inst->u.rect.end, ctx, pos, i);
+}
+
+
 static int end_new_line(struct draw_ctx *ctx,
     struct inst *from, struct inst *to)
 {
@@ -164,33 +283,6 @@
 }
 
 
-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)
 {
@@ -365,6 +457,138 @@
 };
 
 
+/* ----- meas -------------------------------------------------------------- */
+
+
+struct pix_buf *draw_move_meas(struct inst *inst, struct draw_ctx *ctx,
+    struct coord pos, int i)
+{
+       return draw_move_line_common(inst, inst->u.meas.end, ctx, pos, i);
+}
+
+
+static int end_new_meas(struct draw_ctx *ctx,
+    struct inst *from, struct inst *to)
+{
+       struct obj *obj;
+
+       if (from == to)
+               return 0;
+       obj = new_obj(ot_meas, from);
+       obj->u.meas.other = inst_get_ref(to);
+       obj->u.meas.offset = parse_expr("0mm");
+       return 1;
+}
+
+
+static struct tool_ops meas_ops = {
+       .drag_new       = NULL,
+       .end_new        = end_new_meas,
+};
+
+
+/* ----- frame helper ------------------------------------------------------ */
+
+
+static int is_parent_of(const struct frame *p, const struct frame *c)
+{
+       const struct obj *obj;
+
+       if (p == c)
+               return 1;
+       for (obj = p->objs; obj; obj = obj->next)
+               if (obj->type == ot_frame)
+                       if (is_parent_of(obj->u.frame.ref, c))
+                               return 1;
+       return 0;
+}
+
+
+/* ----- frame cache ------------------------------------------------------- */
+
+
+static struct frame *locked_frame = NULL;
+
+
+static void remove_child(GtkWidget *widget, gpointer data)
+{
+       gtk_container_remove(GTK_CONTAINER(data), widget);
+}
+
+
+static void set_frame_image(GtkWidget *image)
+{
+       gtk_container_foreach(GTK_CONTAINER(ev_frame), remove_child, ev_frame);
+       gtk_container_add(GTK_CONTAINER(ev_frame), image);
+       gtk_widget_show_all(ev_frame);
+}
+
+
+void tool_frame_update(void)
+{
+       set_frame_image(!locked_frame ? frame_image :
+           is_parent_of(locked_frame, active_frame) ?
+           frame_image_locked : frame_image_ready);
+}
+
+
+void tool_frame_deleted(const struct frame *frame)
+{
+       if (frame == locked_frame) {
+               locked_frame = NULL;
+               set_frame_image(frame_image);
+       }
+}
+
+
+static void tool_selected_frame(void)
+{
+       if (active_frame != root_frame) {
+               locked_frame = active_frame;
+               set_frame_image(frame_image_locked);
+       }
+}
+
+
+/* ----- frame ------------------------------------------------------------- */
+
+
+struct pix_buf *draw_move_frame(struct inst *inst, struct draw_ctx *ctx,
+    struct coord pos, int i)
+{
+       struct pix_buf *buf;
+       int r = FRAME_EYE_R2;
+
+       pos = translate(ctx, pos);
+       buf = save_pix_buf(DA, pos.x-r, pos.y-r, pos.x+r, pos.y+r, 1);
+       draw_arc(DA, gc_drag, FALSE, pos.x, pos.y, r, 0, 360);
+       return buf;
+}
+
+
+static int end_new_frame(struct draw_ctx *ctx,
+    struct inst *from, struct inst *to)
+{
+       struct obj *obj;
+
+       if (!locked_frame || is_parent_of(locked_frame, active_frame))
+               return 0;
+       obj = new_obj(ot_frame, from);
+       obj->u.frame.ref = locked_frame;
+       obj->u.frame.lineno = 0;
+       locked_frame = NULL;
+       tool_frame_update();
+       return 1;
+}
+
+
+static struct tool_ops frame_ops = {
+       .tool_selected  = tool_selected_frame,
+       .drag_new       = NULL,
+       .end_new        = end_new_frame,
+};
+
+
 /* ----- moving references ------------------------------------------------- */
 
 
@@ -398,7 +622,7 @@
 
 static int may_move_to(const struct drag_state *state, struct inst *curr)
 {
-       assert(selected_inst);
+       assert(drag.inst);
        assert(state->anchors_n);
        switch (state->anchors_n) {
        case 3:
@@ -478,10 +702,24 @@
                return 0;
        pix_buf = NULL;
        if (active_ops) {
-               drag.new = curr;
-               return 1;
+               if (active_ops->drag_new) {
+                       drag.inst = NULL;
+                       drag.new = curr;
+                       return 1;
+               } else {
+                       /* object is created without dragging */
+                       if (active_ops->end_new(ctx, curr, NULL)) {
+                               tool_cancel_drag(ctx);
+                               return -1;
+                       }
+                       return 0;
+               }
        }
-       return may_move(curr);
+       if (!may_move(curr))
+               return 0;
+       drag.inst = selected_inst;
+       drag.new = NULL;
+       return 1;
 }
 
 
@@ -491,7 +729,7 @@
                restore_pix_buf(pix_buf);
        tool_hover(ctx, to);
        pix_buf = drag.new ? active_ops->drag_new(ctx, drag.new, to) :
-           inst_draw_move(selected_inst, ctx, to, drag.anchor_i);
+           inst_draw_move(drag.inst, ctx, to, drag.anchor_i);
 }
 
 
@@ -514,6 +752,8 @@
        struct tool_ops *ops = active_ops;
 
        tool_cancel_drag(ctx);
+       if (state.new && ops->end_new_raw)
+               return ops->end_new_raw(ctx, state.new, to);
        end = inst_find_point(ctx, to);
        if (!end)
                return 0;
@@ -521,7 +761,7 @@
                return ops->end_new(ctx, state.new, end);
        if (!may_move_to(&state, end))
                return 0;
-       if (!inst_do_move_to(selected_inst, inst_get_vec(end), state.anchor_i))
+       if (!inst_do_move_to(drag.inst, inst_get_vec(end), state.anchor_i))
                do_move_to(&state, end);
        return 1;
 }
@@ -543,6 +783,8 @@
        gtk_widget_modify_bg(evbox, GTK_STATE_NORMAL, &col);
        active_tool = evbox;
        active_ops = ops;
+       if (ops && ops->tool_selected)
+               ops->tool_selected();
 }
 
 
@@ -560,10 +802,21 @@
 }
 
 
+static GtkWidget *make_image(GdkDrawable *drawable,  char **xpm)
+{
+       GdkPixmap *pixmap;
+       GtkWidget *image;
+
+       pixmap = gdk_pixmap_create_from_xpm_d(drawable, NULL, NULL, xpm);
+       image = gtk_image_new_from_pixmap(pixmap, NULL);
+       gtk_misc_set_padding(GTK_MISC(image), 1, 1);
+       return image;
+}
+
+
 static GtkWidget *tool_button(GtkWidget *bar, GdkDrawable *drawable,
     char **xpm, GtkWidget *last_evbox, struct tool_ops *ops)
 {
-       GdkPixmap *pixmap;
        GtkWidget *image, *evbox;       
        GtkToolItem *item;
        GtkToolItem *last = NULL;
@@ -571,8 +824,6 @@
        if (last_evbox)
                last = GTK_TOOL_ITEM(gtk_widget_get_ancestor(last_evbox,
                    GTK_TYPE_TOOL_ITEM));
-       pixmap = gdk_pixmap_create_from_xpm_d(drawable, NULL, NULL, xpm);
-       image = gtk_image_new_from_pixmap(pixmap, NULL);
 
 /*
  * gtk_radio_tool_button_new_from_widget is *huge*. we try to do things in a
@@ -587,8 +838,10 @@
        gtk_tool_button_set_icon_widget(GTK_TOOL_BUTTON(item), image);
 #else
        evbox = gtk_event_box_new();
-       gtk_misc_set_padding(GTK_MISC(image), 1, 1);
-       gtk_container_add(GTK_CONTAINER(evbox), image);
+       if (xpm) {
+               image = make_image(drawable, xpm);
+               gtk_container_add(GTK_CONTAINER(evbox), image);
+       }
        g_signal_connect(G_OBJECT(evbox), "button_press_event",
             G_CALLBACK(tool_button_press_event), ops);
 
@@ -616,13 +869,21 @@
 
        ev_point = tool_button(bar, drawable, xpm_point, NULL, NULL);
        last = tool_button(bar, drawable, xpm_vec, ev_point, &vec_ops);
-       last = tool_button(bar, drawable, xpm_frame, last, &frame_ops);
+       ev_frame = tool_button(bar, drawable, NULL, last, &frame_ops);
+       last = ev_frame;
        last = tool_button(bar, drawable, xpm_pad, last, &pad_ops);
        last = tool_button(bar, drawable, xpm_line, last, &line_ops);
        last = tool_button(bar, drawable, xpm_rect, last, &rect_ops);
        last = tool_button(bar, drawable, xpm_circ, last, &circ_ops);
        last = tool_button(bar, drawable, xpm_meas, last, &meas_ops);
 
+       frame_image = gtk_widget_ref(make_image(drawable, xpm_frame));
+       frame_image_locked =
+           gtk_widget_ref(make_image(drawable, xpm_frame_locked));
+       frame_image_ready =
+           gtk_widget_ref(make_image(drawable, xpm_frame_ready));
+       set_frame_image(frame_image);
+
        tool_reset();
 
        return bar;

Modified: trunk/eda/fped/gui_tools.h
===================================================================
--- trunk/eda/fped/gui_tools.h  2009-08-05 10:35:48 UTC (rev 5388)
+++ trunk/eda/fped/gui_tools.h  2009-08-05 14:44:36 UTC (rev 5389)
@@ -19,6 +19,8 @@
 #include "inst.h"
 
 
+struct pix_buf *draw_move_vec(struct inst *inst, struct draw_ctx *ctx,
+    struct coord pos, int i);
 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,
@@ -27,6 +29,10 @@
     struct coord pos, int i);
 struct pix_buf *draw_move_arc(struct inst *inst, struct draw_ctx *ctx,
     struct coord pos, int i);
+struct pix_buf *draw_move_meas(struct inst *inst, struct draw_ctx *ctx,
+    struct coord pos, int i);
+struct pix_buf *draw_move_frame(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);
 
@@ -37,6 +43,13 @@
 void tool_cancel_drag(struct draw_ctx *ctx);
 int tool_end_drag(struct draw_ctx *ctx, struct coord to);
 
+/*
+ * Cache the frame and track it.
+ */
+
+void tool_frame_update(void);
+void tool_frame_deleted(const struct frame *frame);
+
 void tool_reset(void);
 
 GtkWidget *gui_setup_tools(GdkDrawable *drawable);

Modified: trunk/eda/fped/icons/frame.fig
===================================================================
--- trunk/eda/fped/icons/frame.fig      2009-08-05 10:35:48 UTC (rev 5388)
+++ trunk/eda/fped/icons/frame.fig      2009-08-05 14:44:36 UTC (rev 5389)
@@ -7,8 +7,10 @@
 Single
 -2
 1200 2
+6 3750 3225 5775 4200
+2 1 0 10 12 7 50 -1 -1 0.000 0 0 -1 0 0 3
+        3900 4125 3900 3525 5700 3525
+4 0 12 50 -1 22 42 0.0000 4 135 450 3750 3375 FRAME\001
+-6
 2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
         3600 2400 6000 2400 6000 4800 3600 4800 3600 2400
-2 1 0 10 12 7 50 -1 -1 0.000 0 0 -1 0 0 3
-        3900 4275 3900 3675 5700 3675
-4 0 12 50 -1 22 42 0.0000 4 135 450 3750 3525 FRAME\001

Added: trunk/eda/fped/icons/frame_locked.fig
===================================================================
--- trunk/eda/fped/icons/frame_locked.fig                               (rev 0)
+++ trunk/eda/fped/icons/frame_locked.fig       2009-08-05 14:44:36 UTC (rev 
5389)
@@ -0,0 +1,17 @@
+#FIG 3.2  Produced by xfig version 3.2.5a
+Landscape
+Center
+Inches
+A4      
+100.00
+Single
+-2
+1200 2
+6 3750 3225 5775 4200
+2 1 0 10 12 7 50 -1 -1 0.000 0 0 -1 0 0 3
+        3900 4125 3900 3525 5700 3525
+4 0 12 50 -1 22 42 0.0000 4 135 450 3750 3375 FRAME\001
+-6
+1 3 0 0 0 0 50 -1 20 0.000 1 0.0000 5400 4200 375 375 5400 4200 5775 4200
+2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
+        3600 2400 6000 2400 6000 4800 3600 4800 3600 2400

Added: trunk/eda/fped/icons/frame_ready.fig
===================================================================
--- trunk/eda/fped/icons/frame_ready.fig                                (rev 0)
+++ trunk/eda/fped/icons/frame_ready.fig        2009-08-05 14:44:36 UTC (rev 
5389)
@@ -0,0 +1,15 @@
+#FIG 3.2  Produced by xfig version 3.2.5a
+Landscape
+Center
+Inches
+A4      
+100.00
+Single
+-2
+1200 2
+1 3 0 0 0 12 50 -1 20 0.000 1 0.0000 5400 4200 375 375 5400 4200 5775 4200
+2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
+        3600 2400 6000 2400 6000 4800 3600 4800 3600 2400
+2 1 0 10 12 7 50 -1 -1 0.000 0 0 -1 0 0 3
+        3900 4125 3900 3525 5700 3525
+4 0 12 50 -1 22 42 0.0000 4 135 450 3750 3375 FRAME\001

Modified: trunk/eda/fped/inst.c
===================================================================
--- trunk/eda/fped/inst.c       2009-08-05 10:35:48 UTC (rev 5388)
+++ trunk/eda/fped/inst.c       2009-08-05 14:44:36 UTC (rev 5389)
@@ -185,7 +185,7 @@
 
        found = NULL;
        for (inst = insts[ip_frame]; inst; inst = inst->next) {
-               if (!inst->active)
+               if (!inst->u.frame.active)
                        continue;
                dist = gui_dist_frame_eye(inst, pos, ctx->scale);
                if (dist >= 0 && (!found || best_dist > dist)) {
@@ -385,6 +385,7 @@
        .distance       = gui_dist_vec,
        .select         = vec_op_select,
        .anchors        = vec_op_anchors,
+       .draw_move      = draw_move_vec,
 };
 
 
@@ -671,6 +672,7 @@
        .distance       = gui_dist_meas,
        .select         = meas_op_select,
        .anchors        = meas_op_anchors,
+       .draw_move      = draw_move_meas,
 };
 
 
@@ -726,7 +728,7 @@
 
 static int frame_op_anchors(struct inst *inst, struct vec ***anchors)
 {
-       anchors[0] = &inst->vec->base;
+       anchors[0] = &inst->obj->base;
        return 1;
 }
 
@@ -738,6 +740,7 @@
        .distance       = gui_dist_frame,
        .select         = frame_op_select,
        .anchors        = frame_op_anchors,
+       .draw_move      = draw_move_frame,
 };
 
 




--- End Message ---
_______________________________________________
commitlog mailing list
commitlog@lists.openmoko.org
http://lists.openmoko.org/mailman/listinfo/commitlog

Reply via email to