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. r5402 - trunk/eda/fped (wer...@docs.openmoko.org)
   2. r5403 - in trunk/eda/fped: . icons (wer...@docs.openmoko.org)
   3. r5404 - in trunk/eda/fped: . icons (wer...@docs.openmoko.org)
--- Begin Message ---
Author: werner
Date: 2009-08-07 20:53:01 +0200 (Fri, 07 Aug 2009)
New Revision: 5402

Modified:
   trunk/eda/fped/gui_status.c
   trunk/eda/fped/inst.c
Log:
- moved more common editing code from field-type specific functions into
  wrappers
- editable fields can now be traversed with Tab
- Enter commits all editable fields
- Esc resets all editable fields to their initial content



Modified: trunk/eda/fped/gui_status.c
===================================================================
--- trunk/eda/fped/gui_status.c 2009-08-07 16:19:23 UTC (rev 5401)
+++ trunk/eda/fped/gui_status.c 2009-08-07 18:53:01 UTC (rev 5402)
@@ -16,6 +16,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <gtk/gtk.h>
+#include <gdk/gdkkeysyms.h>
 
 #include "util.h"
 #include "coord.h"
@@ -27,12 +28,23 @@
 #include "gui_status.h"
 
 
+enum edit_status {
+       es_unchanged,
+       es_good,
+       es_bad,
+};
+
+
 struct edit_ops {
-       int (*changed)(GtkWidget *widget, const char *s, void *ctx);
-       int (*activate)(GtkWidget *widget, const char *s, void *ctx);
+       char *(*retrieve)(void *ctx);
+       enum edit_status (*status)(const char *s, void *ctx);
+       void (*store)(const char *s, void *ctx);
 };
 
+static GtkWidget *open_edits = NULL;
+static GtkWidget *last_edit = NULL;
 
+
 /* ----- setter functions -------------------------------------------------- */
 
 
@@ -109,16 +121,74 @@
 /* ----- helper functions -------------------------------------------------- */
 
 
-static void setup_edit(GtkWidget *widget, const char *s,
-    struct edit_ops *ops, void *ctx, int focus)
+static void reset_edit(GtkWidget *widget)
 {
+       struct edit_ops *ops;
+       void *ctx;
+       char *s;
+
+       ops = gtk_object_get_data(GTK_OBJECT(widget), "edit-ops");
+       ctx = gtk_object_get_data(GTK_OBJECT(widget), "edit-ctx");
+       assert(ops);
+       s = ops->retrieve(ctx);
+       gtk_object_set_data(GTK_OBJECT(widget), "edit-ops", NULL);
        gtk_entry_set_text(GTK_ENTRY(widget), s);
+       free(s);
        entry_color(widget, COLOR_EDIT_ASIS);
+       gtk_object_set_data(GTK_OBJECT(widget), "edit-ops", ops);
+}
+
+
+static void reset_edits(void)
+{
+       GtkWidget *edit;
+
+       for (edit = open_edits; edit;
+           edit = gtk_object_get_data(GTK_OBJECT(edit), "edit-next"))
+               reset_edit(edit);
+       gtk_widget_grab_focus(GTK_WIDGET(open_edits));
+}
+
+
+static gboolean edit_key_press_event(GtkWidget *widget, GdkEventKey *event,
+    gpointer data)
+{
+       GtkWidget *next = gtk_object_get_data(GTK_OBJECT(widget), "edit-next");
+
+       switch (event->keyval) {
+       case GDK_Tab:
+               gtk_widget_grab_focus(GTK_WIDGET(next ? next : open_edits));
+               return TRUE;
+       case GDK_Escape:
+               reset_edits();
+               return TRUE;
+       default:
+               return FALSE;
+       }
+}
+
+
+static void setup_edit(GtkWidget *widget, struct edit_ops *ops, void *ctx,
+    int focus)
+{
+       gtk_object_set_data(GTK_OBJECT(widget), "edit-ops", ops);
+       gtk_object_set_data(GTK_OBJECT(widget), "edit-ctx", ctx);
+       gtk_object_set_data(GTK_OBJECT(widget), "edit-next", NULL);
+
+       reset_edit(widget);
+
        if (focus)
                gtk_widget_grab_focus(GTK_WIDGET(widget));
        gtk_widget_show(widget);
-       gtk_object_set_data(GTK_OBJECT(widget), "edit-ops", ops);
-       gtk_object_set_data(GTK_OBJECT(widget), "edit-ctx", ctx);
+
+       g_signal_connect(G_OBJECT(widget), "key_press_event",
+           G_CALLBACK(edit_key_press_event), open_edits);
+
+       if (last_edit)
+               gtk_object_set_data(GTK_OBJECT(last_edit), "edit-next", widget);
+       else
+               open_edits = widget;
+       last_edit = widget;
 }
 
 
@@ -132,37 +202,41 @@
 };
 
 
-static int unique_changed(GtkWidget *widget, const char *s, void *ctx)
+/*
+ * Handle NULL so that we can also use it for unique_null
+ */
+
+static char *unique_retrieve(void *ctx)
 {
+       struct edit_unique_ctx *unique_ctx = ctx;
+
+       return stralloc(*unique_ctx->s ? *unique_ctx->s : "");
+}
+
+
+static enum edit_status unique_status(const char *s, void *ctx)
+{
        const struct edit_unique_ctx *unique_ctx = ctx;
-       int ok;
 
-       if (!strcmp(s, *unique_ctx->s)) {
-               entry_color(widget, COLOR_EDIT_ASIS);
-               return 1;
-       }
-       ok = !unique_ctx->validate || unique_ctx->validate(s, unique_ctx->ctx);
-       entry_color(widget, ok ? COLOR_EDIT_GOOD : COLOR_EDIT_BAD);
-       return ok;
+       if (!strcmp(s, *unique_ctx->s))
+               return es_unchanged;
+       return !unique_ctx->validate ||
+           unique_ctx->validate(s, unique_ctx->ctx) ? es_good : es_bad;
 }
 
 
-static int unique_activate(GtkWidget *widget, const char *s, void *ctx)
+static void unique_store(const char *s, void *ctx)
 {
        const struct edit_unique_ctx *unique_ctx = ctx;
 
-       if (strcmp(s, *unique_ctx->s) &&
-            unique_ctx->validate && !unique_ctx->validate(s, unique_ctx->ctx))
-               return 0;
        *unique_ctx->s = unique(s);
-       entry_color(widget, COLOR_EDIT_ASIS);
-       return 1;
 }
 
 
 static struct edit_ops edit_ops_unique = {
-       .changed        = unique_changed,
-       .activate       = unique_activate,
+       .retrieve       = unique_retrieve,
+       .status         = unique_status,
+       .store          = unique_store,
 };
 
 
@@ -174,51 +248,41 @@
        unique_ctx.s = s;
        unique_ctx.validate = validate;
        unique_ctx.ctx = ctx;
-       setup_edit(status_entry, *s, &edit_ops_unique, &unique_ctx, focus);
+       setup_edit(status_entry, &edit_ops_unique, &unique_ctx, focus);
 }
 
 
 /* ----- identifier fields with NULL --------------------------------------- */
 
 
-static int unique_null_changed(GtkWidget *widget, const char *s, void *ctx)
+static enum edit_status unique_null_status(const char *s, void *ctx)
 {
        const struct edit_unique_ctx *unique_ctx = ctx;
-       int ok;
 
-       if (!strcmp(s, *unique_ctx->s ? *unique_ctx->s : "")) {
-               entry_color(widget, COLOR_EDIT_ASIS);
-               return 1;
-       }
-       ok = !*s;
-       if (!ok)
-               ok = !unique_ctx->validate ||
-                    unique_ctx->validate(s, unique_ctx->ctx);
-       entry_color(widget, ok ? COLOR_EDIT_GOOD : COLOR_EDIT_BAD);
-       return ok;
+       if (!strcmp(s, *unique_ctx->s ? *unique_ctx->s : ""))
+               return es_unchanged;
+       if (!*s)
+               return es_good;
+       return !unique_ctx->validate ||
+           unique_ctx->validate(s, unique_ctx->ctx) ? es_good : es_bad;
 }
 
 
-static int unique_null_activate(GtkWidget *widget, const char *s, void *ctx)
+static void unique_null_store(const char *s, void *ctx)
 {
        const struct edit_unique_ctx *unique_ctx = ctx;
 
        if (!*s)
-                *unique_ctx->s = NULL;
-       else {
-               if (unique_ctx->validate &&
-                   !unique_ctx->validate(s, unique_ctx->ctx))
-                       return 0;
+               *unique_ctx->s = NULL;
+       else
                *unique_ctx->s = unique(s);
-       }
-       entry_color(widget, COLOR_EDIT_ASIS);
-       return 1;
 }
 
 
 static struct edit_ops edit_ops_null_unique = {
-       .changed        = unique_null_changed,
-       .activate       = unique_null_activate,
+       .retrieve       = unique_retrieve,
+       .status         = unique_null_status,
+       .store          = unique_null_store,
 };
 
 
@@ -230,8 +294,7 @@
        unique_ctx.s = s;
        unique_ctx.validate = validate;
        unique_ctx.ctx = ctx;
-       setup_edit(status_entry, *s ? *s : "",
-           &edit_ops_null_unique, &unique_ctx, focus);
+       setup_edit(status_entry, &edit_ops_null_unique, &unique_ctx, focus);
 }
 
 
@@ -245,37 +308,38 @@
 };
 
 
-static int name_changed(GtkWidget *widget, const char *s, void *ctx)
+static char *name_retrieve(void *ctx)
 {
+       struct edit_name_ctx *name_ctx = ctx;
+
+       return stralloc(*name_ctx->s ? *name_ctx->s : "");
+}
+
+
+static enum edit_status name_status(const char *s, void *ctx)
+{
        const struct edit_name_ctx *name_ctx = ctx;
-       int ok;
 
-       if (!strcmp(s, *name_ctx->s)) {
-               entry_color(widget, COLOR_EDIT_ASIS);
-               return 1;
-       }
-       ok = !name_ctx->validate || name_ctx->validate(s, name_ctx->ctx);
-       entry_color(widget, ok ? COLOR_EDIT_GOOD : COLOR_EDIT_BAD);
-       return ok;
+       if (!strcmp(s, *name_ctx->s))
+               return es_unchanged;
+       return !name_ctx->validate || name_ctx->validate(s, name_ctx->ctx) ?
+           es_good : es_bad;
 }
 
 
-static int name_activate(GtkWidget *widget, const char *s, void *ctx)
+static void name_store(const char *s, void *ctx)
 {
        const struct edit_name_ctx *name_ctx = ctx;
 
-       if (name_ctx->validate && !name_ctx->validate(s, name_ctx->ctx))
-               return 0;
        free(*name_ctx->s);
        *name_ctx->s = stralloc(s);
-       entry_color(widget, COLOR_EDIT_ASIS);
-       return 1;
 }
 
 
 static struct edit_ops edit_ops_name = {
-       .changed        = name_changed,
-       .activate       = name_activate,
+       .retrieve       = name_retrieve,
+       .status         = name_status,
+       .store          = name_store,
 };
 
 
@@ -287,7 +351,7 @@
        name_ctx.s = s;
        name_ctx.validate = validate;
        name_ctx.ctx = ctx;
-       setup_edit(status_entry, *s, &edit_ops_name, &name_ctx, focus);
+       setup_edit(status_entry, &edit_ops_name, &name_ctx, focus);
 }
 
 
@@ -301,50 +365,49 @@
 }
 
 
-static int expr_changed(GtkWidget *widget, const char *s, void *ctx)
+static char *expr_retrieve(void *ctx)
 {
+       struct expr **expr = ctx;
+
+       return unparse(*expr);
+}
+
+
+static enum edit_status expr_status(const char *s, void *ctx)
+{
        struct expr *expr;
 
        expr = try_parse_expr(s);
-       if (!expr) {
-               entry_color(widget, COLOR_EDIT_BAD);
-               return 0;
-       }
-       entry_color(widget, COLOR_EDIT_GOOD);
+       if (!expr)
+               return es_bad;
        free_expr(expr);
-       return 1;
+       return es_good;
 }
 
 
-static int expr_activate(GtkWidget *widget, const char *s, void *ctx)
+static void expr_store(const char *s, void *ctx)
 {
        struct expr **anchor = ctx;
        struct expr *expr;
 
        expr = try_parse_expr(s);
-       if (!expr)
-               return 0;
+       assert(expr);
        if (*anchor)
                free_expr(*anchor);
        *anchor = expr;
-       entry_color(widget, COLOR_EDIT_ASIS);
-       return 1;
 }
 
 
 static struct edit_ops edit_ops_expr = {
-       .changed        = expr_changed,
-       .activate       = expr_activate,
+       .retrieve       = expr_retrieve,
+       .status         = expr_status,
+       .store          = expr_store,
 };
 
 
 static void edit_any_expr(GtkWidget *widget, struct expr **expr, int focus)
 {
-       char *s;
-
-       s = unparse(*expr);
-       setup_edit(widget, s, &edit_ops_expr, expr, focus);
-       free(s);
+       setup_edit(widget, &edit_ops_expr, expr, focus);
 }
 
 
@@ -369,16 +432,53 @@
 /* ----- text entry -------------------------------------------------------- */
 
 
+static enum edit_status get_status(GtkWidget *widget)
+{
+       struct edit_ops *ops;
+       void *ctx;
+       const char *s;
+
+       ops = gtk_object_get_data(GTK_OBJECT(widget), "edit-ops");
+       if (!ops)
+               return es_unchanged;
+       ctx = gtk_object_get_data(GTK_OBJECT(widget), "edit-ctx");
+       s = gtk_entry_get_text(GTK_ENTRY(widget));
+       return ops->status(s, ctx);
+}
+
+
+static void set_edit(GtkWidget *widget)
+{
+       struct edit_ops *ops;
+       void *ctx;
+       const char *s;
+
+       ops = gtk_object_get_data(GTK_OBJECT(widget), "edit-ops");
+       if (!ops)
+               return;
+       ctx = gtk_object_get_data(GTK_OBJECT(widget), "edit-ctx");
+       s = gtk_entry_get_text(GTK_ENTRY(widget));
+       if (ops->store)
+               ops->store(s, ctx);
+}
+
+
 static gboolean changed(GtkWidget *widget, GdkEventMotion *event,
     gpointer data)
 {
-       struct edit_ops *ops =
-           gtk_object_get_data(GTK_OBJECT(widget), "edit-ops");
-       void *ctx = gtk_object_get_data(GTK_OBJECT(widget), "edit-ctx");
-
-       if (ops && ops->changed)
-               ops->changed(widget, gtk_entry_get_text(GTK_ENTRY(widget)),
-                   ctx);
+       switch (get_status(widget)) {
+       case es_unchanged:
+               entry_color(widget, COLOR_EDIT_ASIS);
+               break;
+       case es_good:
+               entry_color(widget, COLOR_EDIT_GOOD);
+               break;
+       case es_bad:
+               entry_color(widget, COLOR_EDIT_BAD);
+               break;
+       default:
+               abort();
+       }
        return TRUE;
 }
 
@@ -386,16 +486,30 @@
 static gboolean activate(GtkWidget *widget, GdkEventMotion *event,
     gpointer data)
 {
-       struct edit_ops *ops =
-           gtk_object_get_data(GTK_OBJECT(widget), "edit-ops");
-       void *ctx = gtk_object_get_data(GTK_OBJECT(widget), "edit-ctx");
+       GtkWidget *edit;
+       enum edit_status status;
+       int unchanged = 1;
 
-       if (ops && ops->activate)
-               if (ops->activate(widget,
-                   gtk_entry_get_text(GTK_ENTRY(widget)), ctx)) {
-                       inst_deselect();
-                       change_world();
+       for (edit = open_edits; edit;
+           edit = gtk_object_get_data(GTK_OBJECT(edit), "edit-next")) {
+               status = get_status(edit);
+               if (status == es_bad)
+                       return TRUE;
+               if (status == es_good)
+                       unchanged = 0;
+       }
+       if (unchanged)
+               return TRUE;
+       for (edit = open_edits; edit;
+           edit = gtk_object_get_data(GTK_OBJECT(edit), "edit-next"))
+{
+               if (get_status(edit) == es_good) {
+                       entry_color(edit, COLOR_EDIT_ASIS);
+                       set_edit(edit);
                }
+}
+       inst_deselect();
+       change_world();
        return TRUE;
 }
 
@@ -405,6 +519,8 @@
        gtk_widget_hide(status_entry);
        gtk_widget_hide(status_entry_x);
        gtk_widget_hide(status_entry_y);
+       open_edits = NULL;
+       last_edit = NULL;
 }
 
 

Modified: trunk/eda/fped/inst.c
===================================================================
--- trunk/eda/fped/inst.c       2009-08-07 16:19:23 UTC (rev 5401)
+++ trunk/eda/fped/inst.c       2009-08-07 18:53:01 UTC (rev 5402)
@@ -356,9 +356,9 @@
        status_set_type_entry("ref =");
        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, 0);
        edit_x(&self->vec->x);
        edit_y(&self->vec->y);
+       edit_unique_null(&self->vec->name, validate_vec_name, self->vec, 0);
 }
 
 




--- End Message ---
--- Begin Message ---
Author: werner
Date: 2009-08-07 21:42:57 +0200 (Fri, 07 Aug 2009)
New Revision: 5403

Added:
   trunk/eda/fped/icons/delete.fig
Modified:
   trunk/eda/fped/Makefile
   trunk/eda/fped/README
   trunk/eda/fped/gui.c
   trunk/eda/fped/gui_canvas.c
   trunk/eda/fped/gui_status.c
   trunk/eda/fped/gui_status.h
   trunk/eda/fped/gui_tools.c
   trunk/eda/fped/inst.c
Log:
- gui_tools.c:new_vec didn't initialize vec->samples, causing fped to crash
- we didn't dehover before deleting, which could cause a crash
- added delete tool to canvas. Thus ...
- we no longer need the Delete key on the canvas, so we can ...
- always focus the (first) entry field, and ...
- removed "focus" parameter to edit functions



Modified: trunk/eda/fped/Makefile
===================================================================
--- trunk/eda/fped/Makefile     2009-08-07 18:53:01 UTC (rev 5402)
+++ trunk/eda/fped/Makefile     2009-08-07 19:42:57 UTC (rev 5403)
@@ -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 frame_locked.xpm frame_ready.xpm \
+XPMS = point.xpm delete.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/README
===================================================================
--- trunk/eda/fped/README       2009-08-07 18:53:01 UTC (rev 5402)
+++ trunk/eda/fped/README       2009-08-07 19:42:57 UTC (rev 5403)
@@ -399,7 +399,6 @@
 .      cursor position to screen center (like middle click)
 *      zoom and center to extents
 #      zoom and center to currently active frame instance
-Delete delete the currently selected object
 U      undelete the previously deleted object
 
 

Modified: trunk/eda/fped/gui.c
===================================================================
--- trunk/eda/fped/gui.c        2009-08-07 18:53:01 UTC (rev 5402)
+++ trunk/eda/fped/gui.c        2009-08-07 19:42:57 UTC (rev 5403)
@@ -534,7 +534,7 @@
        label_in_box_bg(var->widget, COLOR_VAR_EDITING);
        status_set_type_entry("name =");
        status_set_name("%s", var->name);
-       edit_unique(&var->name, validate_var_name, var, 1);
+       edit_unique(&var->name, validate_var_name, var);
 }
 
 
@@ -555,7 +555,7 @@
 {
        inst_select_outside(value, unselect_value);
        label_in_box_bg(value->widget, COLOR_EXPR_EDITING);
-       edit_expr(&value->expr, 1);
+       edit_expr(&value->expr);
 }
 
 
@@ -958,7 +958,7 @@
                label_in_box_bg(widget, COLOR_PART_NAME_EDITING);
                status_set_type_entry("part =");
                status_set_name("%s", part_name);
-               edit_name(&part_name, validate_part_name, NULL, 1);
+               edit_name(&part_name, validate_part_name, NULL);
                break;
        }
        return TRUE;
@@ -1019,7 +1019,7 @@
        label_in_box_bg(frame->label, COLOR_FRAME_EDITING);
        status_set_type_entry("name =");
        status_set_name("%s", frame->name);
-       edit_unique(&frame->name, validate_frame_name, frame, 1);
+       edit_unique(&frame->name, validate_frame_name, frame);
 }
 
 

Modified: trunk/eda/fped/gui_canvas.c
===================================================================
--- trunk/eda/fped/gui_canvas.c 2009-08-07 18:53:01 UTC (rev 5402)
+++ trunk/eda/fped/gui_canvas.c 2009-08-07 19:42:57 UTC (rev 5403)
@@ -307,6 +307,7 @@
                break;
        case GDK_BackSpace:
        case GDK_Delete:
+#if 0
        case GDK_KP_Delete:
                if (selected_inst) {
                        inst_delete(selected_inst);
@@ -314,6 +315,7 @@
                        change_world();
                }
                break;
+#endif
        case 'u':
                if (undelete())
                        change_world();

Modified: trunk/eda/fped/gui_status.c
===================================================================
--- trunk/eda/fped/gui_status.c 2009-08-07 18:53:01 UTC (rev 5402)
+++ trunk/eda/fped/gui_status.c 2009-08-07 19:42:57 UTC (rev 5403)
@@ -168,8 +168,7 @@
 }
 
 
-static void setup_edit(GtkWidget *widget, struct edit_ops *ops, void *ctx,
-    int focus)
+static void setup_edit(GtkWidget *widget, struct edit_ops *ops, void *ctx)
 {
        gtk_object_set_data(GTK_OBJECT(widget), "edit-ops", ops);
        gtk_object_set_data(GTK_OBJECT(widget), "edit-ctx", ctx);
@@ -177,7 +176,7 @@
 
        reset_edit(widget);
 
-       if (focus)
+       if (!open_edits)
                gtk_widget_grab_focus(GTK_WIDGET(widget));
        gtk_widget_show(widget);
 
@@ -241,14 +240,14 @@
 
 
 void edit_unique(const char **s, int (*validate)(const char *s, void *ctx), 
-    void *ctx, int focus)
+    void *ctx)
 {
        static struct edit_unique_ctx unique_ctx;
 
        unique_ctx.s = s;
        unique_ctx.validate = validate;
        unique_ctx.ctx = ctx;
-       setup_edit(status_entry, &edit_ops_unique, &unique_ctx, focus);
+       setup_edit(status_entry, &edit_ops_unique, &unique_ctx);
 }
 
 
@@ -287,14 +286,14 @@
 
 
 void edit_unique_null(const char **s,
-    int (*validate)(const char *s, void *ctx), void *ctx, int focus)
+    int (*validate)(const char *s, void *ctx), void *ctx)
 {
        static struct edit_unique_ctx unique_ctx;
 
        unique_ctx.s = s;
        unique_ctx.validate = validate;
        unique_ctx.ctx = ctx;
-       setup_edit(status_entry, &edit_ops_null_unique, &unique_ctx, focus);
+       setup_edit(status_entry, &edit_ops_null_unique, &unique_ctx);
 }
 
 
@@ -343,15 +342,14 @@
 };
 
 
-void edit_name(char **s, int (*validate)(const char *s, void *ctx), void *ctx,
-    int focus)
+void edit_name(char **s, int (*validate)(const char *s, void *ctx), void *ctx)
 {
        static struct edit_name_ctx name_ctx;
 
        name_ctx.s = s;
        name_ctx.validate = validate;
        name_ctx.ctx = ctx;
-       setup_edit(status_entry, &edit_ops_name, &name_ctx, focus);
+       setup_edit(status_entry, &edit_ops_name, &name_ctx);
 }
 
 
@@ -405,27 +403,27 @@
 };
 
 
-static void edit_any_expr(GtkWidget *widget, struct expr **expr, int focus)
+static void edit_any_expr(GtkWidget *widget, struct expr **expr)
 {
-       setup_edit(widget, &edit_ops_expr, expr, focus);
+       setup_edit(widget, &edit_ops_expr, expr);
 }
 
 
-void edit_expr(struct expr **expr, int focus)
+void edit_expr(struct expr **expr)
 {
-       edit_any_expr(status_entry, expr, focus);
+       edit_any_expr(status_entry, expr);
 }
 
 
 void edit_x(struct expr **expr)
 {
-       edit_any_expr(status_entry_x, expr, 0);
+       edit_any_expr(status_entry_x, expr);
 }
 
 
 void edit_y(struct expr **expr)
 {
-       edit_any_expr(status_entry_y, expr, 0);
+       edit_any_expr(status_entry_y, expr);
 }
 
 

Modified: trunk/eda/fped/gui_status.h
===================================================================
--- trunk/eda/fped/gui_status.h 2009-08-07 18:53:01 UTC (rev 5402)
+++ trunk/eda/fped/gui_status.h 2009-08-07 19:42:57 UTC (rev 5403)
@@ -21,12 +21,11 @@
 
 
 void edit_unique(const char **s, int (*validate)(const char *s, void *ctx),
-    void *ctx, int focus);
+    void *ctx);
 void edit_unique_null(const char **s, int (*validate)(const char *s, void 
*ctx),
-    void *ctx, int focus);
-void edit_name(char **s, int (*validate)(const char *s, void *ctx), void *ctx,
-    int focus);
-void edit_expr(struct expr **expr, int focus);
+    void *ctx);
+void edit_name(char **s, int (*validate)(const char *s, void *ctx), void *ctx);
+void edit_expr(struct expr **expr);
 void edit_x(struct expr **expr);
 void edit_y(struct expr **expr);
 void edit_nothing(void);

Modified: trunk/eda/fped/gui_tools.c
===================================================================
--- trunk/eda/fped/gui_tools.c  2009-08-07 18:53:01 UTC (rev 5402)
+++ trunk/eda/fped/gui_tools.c  2009-08-07 19:42:57 UTC (rev 5403)
@@ -35,6 +35,7 @@
 #include "icons/meas.xpm"
 #include "icons/pad.xpm"
 #include "icons/point.xpm"
+#include "icons/delete.xpm"
 #include "icons/rect.xpm"
 #include "icons/vec.xpm"
 
@@ -44,6 +45,7 @@
 
 struct tool_ops {
        void (*tool_selected)(void);
+       void (*click)(struct draw_ctx *ctx, struct coord pos);
        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,
@@ -83,6 +85,7 @@
        vec->base = inst_get_vec(base);
        vec->next = NULL;
        vec->frame = active_frame;
+       vec->samples = NULL;
        for (walk = &active_frame->vecs; *walk; walk = &(*walk)->next);
        *walk = vec;
        return vec;
@@ -160,6 +163,27 @@
 }
 
 
+/* ----- delete ------------------------------------------------------------ */
+
+
+static void click_delete(struct draw_ctx *ctx, struct coord pos)
+{
+       inst_deselect();
+       inst_select(ctx, pos);
+       if (selected_inst) {
+               tool_dehover(ctx);
+               inst_delete(selected_inst);
+       }
+       change_world();
+       tool_reset();
+}
+
+
+static struct tool_ops delete_ops = {
+       .click          = click_delete,
+};
+
+
 /* ----- vec --------------------------------------------------------------- */
 
 
@@ -707,6 +731,10 @@
        assert(!drag.new);
        assert(!drag.anchors_n);
        last_canvas_pos = translate(ctx, pos);
+       if (active_ops && active_ops->click) {
+               active_ops->click(ctx, pos);
+               return 0;
+       }
        curr = inst_find_point(ctx, pos);
        if (!curr)
                return 0;
@@ -882,6 +910,16 @@
 }
 
 
+static void tool_separator(GtkWidget *bar)
+{
+       GtkToolItem *item;
+
+       item = gtk_separator_tool_item_new();
+       gtk_separator_tool_item_set_draw(GTK_SEPARATOR_TOOL_ITEM(item), FALSE);
+       gtk_toolbar_insert(GTK_TOOLBAR(bar), item, -1);
+}
+
+
 GtkWidget *gui_setup_tools(GdkDrawable *drawable)
 {
        GtkWidget *bar;
@@ -893,7 +931,9 @@
            GTK_ORIENTATION_VERTICAL);
 
        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_delete, ev_point, &delete_ops);
+       tool_separator(bar);
+       last = tool_button(bar, drawable, xpm_vec, last, &vec_ops);
        ev_frame = tool_button(bar, drawable, NULL, last, &frame_ops);
        last = ev_frame;
        last = tool_button(bar, drawable, xpm_pad, last, &pad_ops);

Added: trunk/eda/fped/icons/delete.fig
===================================================================
--- trunk/eda/fped/icons/delete.fig                             (rev 0)
+++ trunk/eda/fped/icons/delete.fig     2009-08-07 19:42:57 UTC (rev 5403)
@@ -0,0 +1,15 @@
+#FIG 3.2  Produced by xfig version 3.2.5a
+Landscape
+Center
+Inches
+A4      
+100.00
+Single
+-2
+1200 2
+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 15 18 7 50 -1 -1 0.000 0 1 -1 0 0 2
+        4125 2925 5475 4275
+2 1 0 15 18 7 50 -1 -1 0.000 0 1 -1 0 0 2
+        4125 4275 5475 2925

Modified: trunk/eda/fped/inst.c
===================================================================
--- trunk/eda/fped/inst.c       2009-08-07 18:53:01 UTC (rev 5402)
+++ trunk/eda/fped/inst.c       2009-08-07 19:42:57 UTC (rev 5403)
@@ -358,7 +358,7 @@
        rect_status(self->base, self->u.rect.end, -1);
        edit_x(&self->vec->x);
        edit_y(&self->vec->y);
-       edit_unique_null(&self->vec->name, validate_vec_name, self->vec, 0);
+       edit_unique_null(&self->vec->name, validate_vec_name, self->vec);
 }
 
 
@@ -407,7 +407,7 @@
 static void line_op_select(struct inst *self)
 {
        rect_status(self->bbox.min, self->bbox.max, self->u.rect.width);
-       edit_expr(&self->obj->u.line.width, 0);
+       edit_expr(&self->obj->u.line.width);
 }
 
 
@@ -460,7 +460,7 @@
 static void rect_op_select(struct inst *self)
 {
        rect_status(self->bbox.min, self->bbox.max, self->u.rect.width);
-       edit_expr(&self->obj->u.rect.width, 0);
+       edit_expr(&self->obj->u.rect.width);
 }
 
 
@@ -517,7 +517,7 @@
        status_set_type_entry("label =");
        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, 0);
+       edit_name(&self->obj->u.pad.name, validate_pad_name, NULL);
 }
 
 
@@ -575,7 +575,7 @@
        status_set_r("r = %5.2f mm", units_to_mm(self->u.arc.r));
        status_set_type_entry("width =");
        status_set_name("%5.2f mm", units_to_mm(self->u.arc.width));
-       edit_expr(&self->obj->u.arc.width, 0);
+       edit_expr(&self->obj->u.arc.width);
 }
 
 
@@ -645,7 +645,7 @@
        status_set_name("%5.2f mm", units_to_mm(self->u.meas.offset));
        if (!self->obj)
                return; /* @@@ new-style measurements */
-       edit_expr(&self->obj->u.meas.offset, 0);
+       edit_expr(&self->obj->u.meas.offset);
 }
 
 




--- End Message ---
--- Begin Message ---
Author: werner
Date: 2009-08-07 23:47:51 +0200 (Fri, 07 Aug 2009)
New Revision: 5404

Added:
   trunk/eda/fped/icons/meas_x.fig
   trunk/eda/fped/icons/meas_y.fig
Modified:
   trunk/eda/fped/Makefile
   trunk/eda/fped/README
   trunk/eda/fped/gui.c
   trunk/eda/fped/gui_canvas.c
   trunk/eda/fped/gui_canvas.h
   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/icons/meas.fig
   trunk/eda/fped/inst.c
   trunk/eda/fped/inst.h
   trunk/eda/fped/meas.c
   trunk/eda/fped/meas.h
   trunk/eda/fped/obj.c
   trunk/eda/fped/obj.h
Log:
- added icons for new-style measurements (on-going)
- increased default window size for make room for new icons
- switch the canvas to dark blue when instantiation fails
- modularized point lookup logic of instantiate_meas
- added highlight mode (on-going)



Modified: trunk/eda/fped/Makefile
===================================================================
--- trunk/eda/fped/Makefile     2009-08-07 19:42:57 UTC (rev 5403)
+++ trunk/eda/fped/Makefile     2009-08-07 21:47:51 UTC (rev 5404)
@@ -17,7 +17,7 @@
        gui_tools.o
 
 XPMS = point.xpm delete.xpm vec.xpm frame.xpm frame_locked.xpm frame_ready.xpm 
\
-       line.xpm rect.xpm pad.xpm circ.xpm meas.xpm
+       line.xpm rect.xpm pad.xpm circ.xpm meas.xpm meas_x.xpm meas_y.xpm
 
 CFLAGS_GTK = `pkg-config --cflags gtk+-2.0`
 LIBS_GTK = `pkg-config --libs gtk+-2.0`

Modified: trunk/eda/fped/README
===================================================================
--- trunk/eda/fped/README       2009-08-07 19:42:57 UTC (rev 5403)
+++ trunk/eda/fped/README       2009-08-07 21:47:51 UTC (rev 5404)
@@ -422,10 +422,10 @@
 to its new location. To edit the object's parameters, select it and
 make the changes in the input area at the bottom.
 
-To delete an object, select it and press Delete. Deleted objects can
-be undeleted by pressing "u". If any other changes have been made
-since deletion, fped may misbehave. If deleting a vector, all items
-that reference it are deleted.
+To delete an object, select the delete tool and click on the object.
+Deleted objects can be undeleted by pressing "u". If any other changes
+have been made since deletion, fped may misbehave. If deleting a vector,
+all items that reference it are deleted as well.
 
 
 Experimental: new-style measurements

Modified: trunk/eda/fped/gui.c
===================================================================
--- trunk/eda/fped/gui.c        2009-08-07 19:42:57 UTC (rev 5403)
+++ trunk/eda/fped/gui.c        2009-08-07 21:47:51 UTC (rev 5404)
@@ -1225,7 +1225,7 @@
 {
        root = gtk_window_new(GTK_WINDOW_TOPLEVEL);
        gtk_window_set_position(GTK_WINDOW(root), GTK_WIN_POS_CENTER);
-       gtk_window_set_default_size(GTK_WINDOW(root), 600, 400);
+       gtk_window_set_default_size(GTK_WINDOW(root), 620, 460);
        gtk_window_set_title(GTK_WINDOW(root), "fped");
 
        /* get root->window */

Modified: trunk/eda/fped/gui_canvas.c
===================================================================
--- trunk/eda/fped/gui_canvas.c 2009-08-07 19:42:57 UTC (rev 5403)
+++ trunk/eda/fped/gui_canvas.c 2009-08-07 21:47:51 UTC (rev 5404)
@@ -26,6 +26,8 @@
 #include "gui_canvas.h"
 
 
+void (*highlight)(struct draw_ctx *ctx) = NULL;
+
 static struct draw_ctx ctx;
 static struct coord curr_pos;
 static struct coord user_origin = { 0, 0 };
@@ -101,9 +103,12 @@
 
        aw = ctx.widget->allocation.width;
        ah = ctx.widget->allocation.height;
-       gdk_draw_rectangle(ctx.widget->window, gc_bg, TRUE, 0, 0, aw, ah);
+       gdk_draw_rectangle(ctx.widget->window,
+           instantiation_ok ? gc_bg : gc_bg_error, TRUE, 0, 0, aw, ah);
 
        inst_draw(&ctx);
+       if (highlight)
+               highlight(&ctx);
        tool_redraw(&ctx);
 }
 

Modified: trunk/eda/fped/gui_canvas.h
===================================================================
--- trunk/eda/fped/gui_canvas.h 2009-08-07 19:42:57 UTC (rev 5403)
+++ trunk/eda/fped/gui_canvas.h 2009-08-07 21:47:51 UTC (rev 5404)
@@ -17,6 +17,14 @@
 #include <gtk/gtk.h>
 
 
+/*
+ * "highlight" is invoked at the end of each redraw, for optional highlighting
+ * of objects.
+ */
+
+extern void (*highlight)(struct draw_ctx *ctx);
+
+
 void redraw(void);
 
 GtkWidget *make_canvas(void);

Modified: trunk/eda/fped/gui_inst.c
===================================================================
--- trunk/eda/fped/gui_inst.c   2009-08-07 19:42:57 UTC (rev 5403)
+++ trunk/eda/fped/gui_inst.c   2009-08-07 21:47:51 UTC (rev 5404)
@@ -159,6 +159,14 @@
 }
 
 
+void gui_highlight_vec(struct inst *self, struct draw_ctx *ctx)
+{
+       struct coord center = translate(ctx, self->u.rect.end);
+
+       draw_circle(DA, gc_highlight, FALSE, center.x, center.y, VEC_EYE_R);
+}
+
+
 void gui_draw_vec(struct inst *self, struct draw_ctx *ctx)
 {
        struct coord from = translate(ctx, self->base);

Modified: trunk/eda/fped/gui_inst.h
===================================================================
--- trunk/eda/fped/gui_inst.h   2009-08-07 19:42:57 UTC (rev 5403)
+++ trunk/eda/fped/gui_inst.h   2009-08-07 21:47:51 UTC (rev 5404)
@@ -50,6 +50,7 @@
 void gui_draw_meas(struct inst *self, struct draw_ctx *ctx);
 void gui_draw_frame(struct inst *self, struct draw_ctx *ctx);
 
+void gui_highlight_vec(struct inst *self, struct draw_ctx *ctx);
 void gui_hover_vec(struct inst *self, struct draw_ctx *ctx);
 void gui_hover_frame(struct inst *self, struct draw_ctx *ctx);
 

Modified: trunk/eda/fped/gui_style.c
===================================================================
--- trunk/eda/fped/gui_style.c  2009-08-07 19:42:57 UTC (rev 5403)
+++ trunk/eda/fped/gui_style.c  2009-08-07 21:47:51 UTC (rev 5404)
@@ -1,5 +1,4 @@
-/*
- * gui_style.c - GUI, style definitions
+/* * gui_style.c - GUI, style definitions
  *
  * Written 2009 by Werner Almesberger
  * Copyright 2009 by Werner Almesberger
@@ -22,8 +21,9 @@
 #define        INVALID "#00ffff"
 
 
-GdkGC *gc_bg;
+GdkGC *gc_bg, *gc_bg_error;
 GdkGC *gc_drag;
+GdkGC *gc_highlight;
 GdkGC *gc_active_frame;
 GdkGC *gc_vec[mode_n];
 GdkGC *gc_obj[mode_n];
@@ -61,6 +61,7 @@
 void gui_setup_style(GdkDrawable *drawable)
 {
        gc_bg = gc("#000000", 0);
+       gc_bg_error = gc("#000040", 0);
        gc_drag = gc("#ffffff", 2);
        /*              inactive   in+path    active     act+path   selected */
        style(gc_vec,   "#202000", "#404020", "#909040", "#c0c080", "#ffff80");
@@ -69,7 +70,9 @@
        style(gc_ptext, "#404040", INVALID,   "#ffffff", INVALID,   "#ffffff");
        style(gc_meas,  "#280040", INVALID,   "#ff00ff", INVALID,   "#ffff80");
        style(gc_frame, "#004000", "#205020", "#009000", INVALID,   "#ffff80");
+
        gc_active_frame = gc("#00ff00", 2);
-
+//     gc_highlight = gc("#ff8020", 2);
+       gc_highlight = gc("#ff90d0", 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-07 19:42:57 UTC (rev 5403)
+++ trunk/eda/fped/gui_style.h  2009-08-07 21:47:51 UTC (rev 5404)
@@ -88,8 +88,9 @@
 /* ----- canvas drawing styles --------------------------------------------- */
 
 
-extern GdkGC *gc_bg;
+extern GdkGC *gc_bg, *gc_bg_error;
 extern GdkGC *gc_drag;
+extern GdkGC *gc_highlight;
 extern GdkGC *gc_active_frame;
 extern GdkGC *gc_vec[mode_n];
 extern GdkGC *gc_obj[mode_n];

Modified: trunk/eda/fped/gui_tools.c
===================================================================
--- trunk/eda/fped/gui_tools.c  2009-08-07 19:42:57 UTC (rev 5403)
+++ trunk/eda/fped/gui_tools.c  2009-08-07 21:47:51 UTC (rev 5404)
@@ -22,6 +22,7 @@
 #include "gui_util.h"
 #include "gui_style.h"
 #include "gui_inst.h"
+#include "gui_canvas.h"
 #include "gui_status.h"
 #include "gui.h"
 #include "gui_tools.h"
@@ -33,6 +34,8 @@
 #include "icons/frame_ready.xpm"
 #include "icons/line.xpm"
 #include "icons/meas.xpm"
+#include "icons/meas_x.xpm"
+#include "icons/meas_y.xpm"
 #include "icons/pad.xpm"
 #include "icons/point.xpm"
 #include "icons/delete.xpm"
@@ -45,6 +48,7 @@
 
 struct tool_ops {
        void (*tool_selected)(void);
+       void (*tool_deselected)(void);
        void (*click)(struct draw_ctx *ctx, struct coord pos);
        struct pix_buf *(*drag_new)(struct draw_ctx *ctx, struct inst *from,
             struct coord to);
@@ -517,12 +521,64 @@
 }
 
 
+static int meas_x_pick_vec(struct inst *inst, void *ctx)
+{
+       struct vec *vec = inst->vec;
+       struct coord min;
+
+       if (!vec->samples)
+               return 0;
+       min = meas_find_min(lt_xy, vec->samples);
+       return inst->u.rect.end.x == min.x && inst->u.rect.end.y == min.y;
+}
+
+
+static void highlight_vecs(struct draw_ctx *ctx)
+{
+       inst_highlight_vecs(ctx, meas_x_pick_vec, NULL);
+}
+
+
+static void tool_selected_meas_x(void)
+{
+       highlight = highlight_vecs;
+       redraw();
+}
+
+
+static void tool_selected_meas_y(void)
+{
+       highlight = NULL;
+       redraw();
+}
+
+
+static void tool_deselected_meas(void)
+{
+       highlight = NULL;
+       redraw();
+}
+
+
 static struct tool_ops meas_ops = {
        .drag_new       = drag_new_line,
        .end_new        = end_new_meas,
 };
 
+static struct tool_ops meas_ops_x = {
+       .tool_selected  = tool_selected_meas_x,
+       .tool_deselected= tool_deselected_meas,
+       .drag_new       = drag_new_line,
+       .end_new        = end_new_meas,
+};
+static struct tool_ops meas_ops_y = {
+       .tool_selected  = tool_selected_meas_y,
+       .tool_deselected= tool_deselected_meas,
+       .drag_new       = drag_new_line,
+       .end_new        = end_new_meas,
+};
 
+
 /* ----- frame helper ------------------------------------------------------ */
 
 
@@ -828,6 +884,8 @@
        GdkColor col;
 
        if (active_tool) {
+               if (active_ops && active_ops->tool_deselected)
+                       active_ops->tool_deselected();
                col = get_color(TOOL_UNSELECTED);
                gtk_widget_modify_bg(active_tool, GTK_STATE_NORMAL, &col);
                active_tool = NULL;
@@ -940,7 +998,10 @@
        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);
+       tool_separator(bar);
        last = tool_button(bar, drawable, xpm_meas, last, &meas_ops);
+       last = tool_button(bar, drawable, xpm_meas_x, last, &meas_ops_x);
+       last = tool_button(bar, drawable, xpm_meas_y, last, &meas_ops_y);
 
        frame_image = gtk_widget_ref(make_image(drawable, xpm_frame));
        frame_image_locked =

Modified: trunk/eda/fped/icons/meas.fig
===================================================================
--- trunk/eda/fped/icons/meas.fig       2009-08-07 19:42:57 UTC (rev 5403)
+++ trunk/eda/fped/icons/meas.fig       2009-08-07 21:47:51 UTC (rev 5404)
@@ -10,10 +10,10 @@
 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 21 7 50 -1 -1 0.000 0 0 -1 0 0 2
-        3900 3300 3900 3900
-2 1 0 10 21 7 50 -1 -1 0.000 0 0 -1 0 0 2
-        5700 3300 5700 3900
+        3900 3600 4200 4200
 2 1 0 10 21 7 50 -1 -1 0.000 0 0 -1 1 1 2
        0 0 10.00 450.00 450.00
        0 0 10.00 450.00 450.00
-        3900 3600 5700 3600
+        4050 3900 5550 3150
+2 1 0 10 21 7 50 -1 -1 0.000 0 0 -1 0 0 2
+        5400 2850 5700 3450

Added: trunk/eda/fped/icons/meas_x.fig
===================================================================
--- trunk/eda/fped/icons/meas_x.fig                             (rev 0)
+++ trunk/eda/fped/icons/meas_x.fig     2009-08-07 21:47:51 UTC (rev 5404)
@@ -0,0 +1,23 @@
+#FIG 3.2  Produced by xfig version 3.2.5a
+Landscape
+Center
+Inches
+A4      
+100.00
+Single
+-2
+1200 2
+6 3975 2775 5625 4125
+2 1 0 10 0 7 45 -1 -1 0.000 0 1 -1 0 0 2
+        4050 3600 5550 2850
+2 1 0 10 21 7 50 -1 -1 0.000 0 1 -1 0 0 2
+        5550 2850 5550 3900
+2 1 0 10 21 7 50 -1 -1 0.000 0 1 -1 0 0 2
+        4050 3600 4050 3900
+2 1 0 10 21 7 50 -1 -1 0.000 0 0 -1 1 1 2
+       0 0 10.00 450.00 450.00
+       0 0 10.00 450.00 450.00
+        4050 3900 5550 3900
+-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

Added: trunk/eda/fped/icons/meas_y.fig
===================================================================
--- trunk/eda/fped/icons/meas_y.fig                             (rev 0)
+++ trunk/eda/fped/icons/meas_y.fig     2009-08-07 21:47:51 UTC (rev 5404)
@@ -0,0 +1,23 @@
+#FIG 3.2  Produced by xfig version 3.2.5a
+Landscape
+Center
+Inches
+A4      
+100.00
+Single
+-2
+1200 2
+6 3825 2700 5475 4200
+2 1 0 10 21 7 50 -1 -1 0.000 0 0 -1 1 1 2
+       0 0 10.00 450.00 450.00
+       0 0 10.00 450.00 450.00
+        5250 2775 5250 4125
+2 1 0 10 21 7 50 -1 -1 0.000 0 1 -1 0 0 2
+        3900 4125 5250 4125
+2 1 0 10 0 7 45 -1 -1 0.000 0 1 -1 0 0 2
+        3900 4125 4650 2775
+2 1 0 10 21 7 50 -1 -1 0.000 0 1 -1 0 0 2
+        4650 2775 5250 2775
+-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

Modified: trunk/eda/fped/inst.c
===================================================================
--- trunk/eda/fped/inst.c       2009-08-07 19:42:57 UTC (rev 5403)
+++ trunk/eda/fped/inst.c       2009-08-07 21:47:51 UTC (rev 5404)
@@ -841,6 +841,17 @@
 }
 
 
+void inst_highlight_vecs(struct draw_ctx *ctx,
+    int (*pick)(struct inst *inst, void *user), void *user)
+{
+       struct inst *inst;
+
+       for (inst = insts[ip_vec]; inst; inst = inst->next)
+               if (pick(inst, user))
+                       gui_highlight_vec(inst, ctx);
+}
+
+
 struct pix_buf *inst_draw_move(struct inst *inst, struct draw_ctx *ctx,
     struct coord pos, int i)
 {

Modified: trunk/eda/fped/inst.h
===================================================================
--- trunk/eda/fped/inst.h       2009-08-07 19:42:57 UTC (rev 5403)
+++ trunk/eda/fped/inst.h       2009-08-07 21:47:51 UTC (rev 5404)
@@ -114,6 +114,8 @@
 void inst_revert(void);
 
 void inst_draw(struct draw_ctx *ctx);
+void inst_highlight_vecs(struct draw_ctx *ctx, 
+    int (*pick)(struct inst *inst, void *user), void *user);
 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);

Modified: trunk/eda/fped/meas.c
===================================================================
--- trunk/eda/fped/meas.c       2009-08-07 19:42:57 UTC (rev 5403)
+++ trunk/eda/fped/meas.c       2009-08-07 21:47:51 UTC (rev 5404)
@@ -75,25 +75,25 @@
 }
 
 
-static int lt_x(struct coord a, struct coord b)
+int lt_x(struct coord a, struct coord b)
 {
        return a.x < b.x;
 }
 
 
-static int lt_y(struct coord a, struct coord b)
+int lt_y(struct coord a, struct coord b)
 {
        return a.y < b.y;
 }
 
 
-static int lt_xy(struct coord a, struct coord b)
+int lt_xy(struct coord a, struct coord b)
 {
        return a.y < b.y || (a.y == b.y && a.x < b.x);
 }
 
 
-static int (*lt_op[mt_n])(struct coord a, struct coord b) = {
+static lt_op_type lt_op[mt_n] = {
        lt_xy,
        lt_x,
        lt_y,
@@ -109,7 +109,7 @@
 };
 
 
-static int better_next(int (*lt)(struct coord a, struct coord b),
+static int better_next(lt_op_type lt,
     struct coord a0, struct coord b0, struct coord b)
 {
        /* if we don't have any suitable point A0 < B0 yet, use this one */
@@ -143,12 +143,64 @@
 }
 
 
+/*
+ * In order to obtain a stable order, we sort points equal on the measured
+ * coordinate also by xy:
+ *
+ * if (*a < a0) use *a
+ * else if (*a == a0 && *a <xy a0) use *a
+ */
+
+struct coord meas_find_min(lt_op_type lt, const struct sample *s)
+{
+       struct coord min;
+
+       min = s->pos;
+       while (s) {
+               if (lt(s->pos, min) ||
+                   (!lt(min, s->pos) && lt_xy(s->pos, min)))
+                       min = s->pos;
+               s = s->next;
+       }
+       return min;
+}
+
+
+struct coord meas_find_next(lt_op_type lt, const struct sample *s,
+    struct coord ref)
+{
+       struct coord next;
+
+       next = s->pos;
+       while (s) {
+               if (better_next(lt, ref, next, s->pos))
+                       next = s->pos;
+               s = s->next;
+       }
+       return next;
+}
+
+
+struct coord meas_find_max(lt_op_type lt, const struct sample *s)
+{
+       struct coord max;
+
+       max = s->pos;
+       while (s) {
+               if (lt(max, s->pos) ||
+                   (!lt(s->pos, max) && lt_xy(max, s->pos)))
+                       max = s->pos;
+               s = s->next;
+       }
+       return max;
+}
+
+
 int instantiate_meas(void)
 {
        struct meas *meas;
        struct coord a0, b0;
-       const struct sample *a, *b;
-       int (*lt)(struct coord a, struct coord b);
+       lt_op_type lt;
        struct num offset;
 
        for (meas = measurements; meas; meas = meas->next) {
@@ -156,32 +208,12 @@
                        continue;
 
                lt = lt_op[meas->type];
+               a0 = meas_find_min(lt, meas->low->samples);
+               if (is_next[meas->type])
+                       b0 = meas_find_next(lt, meas->high->samples, a0);
+               else
+                       b0 = meas_find_max(lt, meas->high->samples);
 
-               /*
-                * In order to obtain a stable order, we sort points equal on
-                * the measured coordinate also by xy:
-                *
-                * if (*a < a0) use *a
-                * else if (*a == a0 && *a <xy a0) use *a
-                */
-               a0 = meas->low->samples->pos;
-               for (a = meas->low->samples; a; a = a->next)
-                       if (lt(a->pos, a0) ||
-                           (!lt(a0, a->pos) && lt_xy(a->pos, a0)))
-                               a0 = a->pos;
-
-               b0 = meas->high->samples->pos;
-               for (b = meas->high->samples; b; b = b->next) {
-                       if (is_next[meas->type]) {
-                               if (better_next(lt, a0, b0, b->pos))
-                                       b0 = b->pos;
-                       } else {
-                               if (lt(b0, b->pos) ||
-                                   (!lt(b->pos, b0) && lt_xy(b0, b->pos)))
-                                       b0 = b->pos;
-                       }
-               }
-
                offset = eval_unit(meas->offset, root_frame);
                if (is_undef(offset))
                        return 0;

Modified: trunk/eda/fped/meas.h
===================================================================
--- trunk/eda/fped/meas.h       2009-08-07 19:42:57 UTC (rev 5403)
+++ trunk/eda/fped/meas.h       2009-08-07 21:47:51 UTC (rev 5404)
@@ -17,6 +17,9 @@
 #include "obj.h"
 
 
+typedef int (*lt_op_type)(struct coord a, struct coord b);
+
+
 struct meas {
        enum meas_type {
                mt_xy_next,
@@ -35,10 +38,21 @@
        struct meas *next;
 };
 
+struct sample;
 
+
 extern struct meas *measurements;
 
 
+int lt_x(struct coord a, struct coord b);
+int lt_y(struct coord a, struct coord b);
+int lt_xy(struct coord a, struct coord b);
+
+struct coord meas_find_min(lt_op_type lt, const struct sample *s);
+struct coord meas_find_next(lt_op_type lt, const struct sample *s,
+    struct coord ref);
+struct coord meas_find_max(lt_op_type lt, const struct sample *s);
+
 void meas_start(void);
 void meas_post(struct vec *vec, struct coord pos);
 int instantiate_meas(void);

Modified: trunk/eda/fped/obj.c
===================================================================
--- trunk/eda/fped/obj.c        2009-08-07 19:42:57 UTC (rev 5403)
+++ trunk/eda/fped/obj.c        2009-08-07 21:47:51 UTC (rev 5404)
@@ -32,6 +32,7 @@
 struct frame *frames = NULL;
 struct frame *root_frame = NULL;
 struct frame *active_frame = NULL;
+int instantiation_ok;
 
 
 static int generate_frame(struct frame *frame, struct coord base,
@@ -273,5 +274,6 @@
                inst_commit();
        else
                inst_revert();
+       instantiation_ok = ok;
        return ok;
 }

Modified: trunk/eda/fped/obj.h
===================================================================
--- trunk/eda/fped/obj.h        2009-08-07 19:42:57 UTC (rev 5403)
+++ trunk/eda/fped/obj.h        2009-08-07 21:47:51 UTC (rev 5404)
@@ -181,6 +181,7 @@
 extern struct frame *frames;
 extern struct frame *root_frame;
 extern struct frame *active_frame;
+extern int instantiation_ok;
 
 
 int instantiate(void);




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

Reply via email to