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. r5418 - trunk/eda/fped (wer...@docs.openmoko.org)
   2. r5419 - in trunk/eda/fped: . icons (wer...@docs.openmoko.org)
   3. r5420 - trunk/eda/fped (wer...@docs.openmoko.org)
   4. r5421 - trunk/eda/fped (wer...@docs.openmoko.org)
--- Begin Message ---
Author: werner
Date: 2009-08-11 22:17:39 +0200 (Tue, 11 Aug 2009)
New Revision: 5418

Added:
   trunk/eda/fped/file.c
   trunk/eda/fped/file.h
Modified:
   trunk/eda/fped/Makefile
   trunk/eda/fped/dump.c
   trunk/eda/fped/fped.c
   trunk/eda/fped/gui.c
   trunk/eda/fped/postscript.c
Log:
- vector labels are already in a per-frame namespace, so we don't need to add
  the frame name when auto-generating them
- moved file I/O from gui.c to file.c
- ps_line used the wrong endpoint coordinate
- option -k makes fped write KiCad non-interactively
- option -p makes fped write Postscript non-interactively



Modified: trunk/eda/fped/Makefile
===================================================================
--- trunk/eda/fped/Makefile     2009-08-11 01:20:15 UTC (rev 5417)
+++ trunk/eda/fped/Makefile     2009-08-11 20:17:39 UTC (rev 5418)
@@ -11,7 +11,7 @@
 #
 
 OBJS = fped.o expr.o coord.o obj.o delete.o inst.o util.o error.o \
-       unparse.o dump.o kicad.o postscript.o meas.o \
+       unparse.o file.o dump.o kicad.o postscript.o meas.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_tool.o gui_over.o gui_meas.o gui_frame.o

Modified: trunk/eda/fped/dump.c
===================================================================
--- trunk/eda/fped/dump.c       2009-08-11 01:20:15 UTC (rev 5417)
+++ trunk/eda/fped/dump.c       2009-08-11 20:17:39 UTC (rev 5418)
@@ -90,8 +90,7 @@
        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);
+       return stralloc_printf("__%d", n);
 }
 
 

Added: trunk/eda/fped/file.c
===================================================================
--- trunk/eda/fped/file.c                               (rev 0)
+++ trunk/eda/fped/file.c       2009-08-11 20:17:39 UTC (rev 5418)
@@ -0,0 +1,177 @@
+/*
+ * file.c - File handling
+ *
+ * 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 <string.h>
+#include <errno.h>
+#include <sys/stat.h>
+
+#include "dump.h"
+#include "kicad.h"
+#include "postscript.h"
+
+#include "util.h"
+#include "file.h"
+
+
+extern char *save_file_name;
+
+
+/* ----- general helper functions ------------------------------------------ */
+
+
+char *set_extension(const char *name, const char *ext)
+{
+       char *s = stralloc(name);
+       char *slash, *dot;
+       char *res;
+
+       slash = strrchr(s, '/');
+       dot = strrchr(slash ? slash : s, '.');
+       if (dot)
+               *dot = 0;
+       res = stralloc_printf("%s.%s", s, ext);
+       free(s);
+       return res;
+}
+
+
+int save_to(const char *name, int (*fn)(FILE *file))
+{
+       FILE *file;
+
+       file = fopen(name, "w");
+       if (!file) {
+               perror(name);
+               return 0;
+       }
+       if (!fn(file)) {
+               perror(name);
+               return 0;
+       }
+       if (fclose(file) == EOF) {
+               perror(name);
+               return 0;
+       }
+       return 1;
+}
+
+
+void save_with_backup(const char *name, int (*fn)(FILE *file))
+{
+       char *s = stralloc(name);
+       char *back, *tmp;
+       char *slash, *dot;
+       int n;
+       struct stat st;
+
+       /* save to temporary file */
+
+       slash = strrchr(s, '/');
+       if (!slash)
+               tmp = stralloc_printf("~%s", s);
+       else {
+               *slash = 0;
+               tmp = stralloc_printf("%s/~%s", s, slash+1);
+               *slash = '/';
+       }
+
+       if (!save_to(tmp, fn))
+               return;
+
+       /* move existing file out of harm's way */
+
+       dot = strrchr(slash ? slash : s, '.');
+       if (dot)
+               *dot = 0;
+       n = 0;
+       while (1) {
+               back = stralloc_printf("%s~%d%s%s",
+                   s, n, dot ? "." : "", dot ? dot+1 : "");
+               if (stat(back, &st) < 0) {
+                       if (errno == ENOENT)
+                               break;
+                       perror(back);
+                       free(back);
+                       return;
+               }
+               free(back);
+               n++;
+       }
+       if (rename(name, back) < 0) {
+               if (errno != ENOENT) {
+                       perror(name);
+                       free(back);
+                       return;
+               }
+       } else {
+               fprintf(stderr, "renamed %s to %s\n", name, back);
+       }
+       free(back);
+
+       /* rename to final name */
+
+       if (rename(tmp, name) < 0) {
+               perror(name);
+               free(tmp);
+               return;
+       }
+       free(tmp);
+
+       fprintf(stderr, "saved to %s\n", name);
+}
+
+
+/* ----- application-specific save handlers -------------------------------- */
+
+
+void save_fpd(void)
+{
+       if (save_file_name)
+               save_with_backup(save_file_name, dump);
+       else {
+               if (!dump(stdout))
+                       perror("stdout");
+       }
+}
+
+
+void write_kicad(void)
+{
+       char *name;
+
+       if (save_file_name) {
+               name = set_extension(save_file_name, "mod");
+               save_to(name, kicad);
+               free(name);
+       } else {
+               if (!kicad(stdout))
+                       perror("stdout");
+       }
+}
+
+
+void write_ps(void)
+{
+       char *name;
+
+       if (save_file_name) {
+               name = set_extension(save_file_name, "ps");
+               save_to(name, postscript);
+               free(name);
+       } else {
+               if (!postscript(stdout))
+                       perror("stdout");
+       }
+}

Added: trunk/eda/fped/file.h
===================================================================
--- trunk/eda/fped/file.h                               (rev 0)
+++ trunk/eda/fped/file.h       2009-08-11 20:17:39 UTC (rev 5418)
@@ -0,0 +1,28 @@
+/*
+ * file.h - File handling
+ *
+ * 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 FILE_H
+#define FILE_H
+
+#include <stdio.h>
+
+
+char *set_extension(const char *name, const char *ext);
+int save_to(const char *name, int (*fn)(FILE *file));
+void save_with_backup(const char *name, int (*fn)(FILE *file));
+
+void save_fpd(void);
+void write_kicad(void);
+void write_ps(void);
+
+#endif /* !FILE_H */

Modified: trunk/eda/fped/fped.c
===================================================================
--- trunk/eda/fped/fped.c       2009-08-11 01:20:15 UTC (rev 5417)
+++ trunk/eda/fped/fped.c       2009-08-11 20:17:39 UTC (rev 5418)
@@ -13,19 +13,21 @@
 
 #include <stdlib.h>
 #include <stdio.h>
+#include <unistd.h>
 
 #include "cpp.h"
 #include "util.h"
 #include "error.h"
 #include "obj.h"
 #include "inst.h"
+#include "file.h"
 #include "gui.h"
 
 
 extern void scan_empty(void);
 extern int yyparse(void);
 
-char *save_file = NULL;
+char *save_file_name = NULL;
 
 
 static void load_file(const char *name)
@@ -38,7 +40,9 @@
 
 static void usage(const char *name)
 {
-       fprintf(stderr, "usage: %s [in_file [out_file]]\n", name);
+       fprintf(stderr, "usage: %s [-k|-p] [in_file [out_file]]\n\n", name);
+       fprintf(stderr, "  -k  write KiCad output, then exit\n");
+       fprintf(stderr, "  -p  write Postscript output, then exit\n");
        exit(1);
 }
 
@@ -47,20 +51,39 @@
 {
        const char *name = *argv;
        int error;
+       int batch_write_kicad = 0, batch_write_ps = 0;
+       int c;
 
        error = gui_init(&argc, &argv);
        if (error)
                return error;
-       switch (argc) {
-       case 1:
+
+       while ((c = getopt(argc, argv, "kp")) != EOF)
+               switch (c) {
+               case 'k':
+                       batch_write_kicad = 1;
+                       break;
+               case 'p':
+                       batch_write_ps = 1;
+                       break;
+               default:
+                       usage(name);
+               }
+
+       switch (argc-optind) {
+       case 0:
                scan_empty();
                (void) yyparse();
                break;
-       case 3:
-               save_file = argv[2];
-               /* fall through */
+       case 1:
+               load_file(argv[optind]);
+               save_file_name = argv[optind];
+               break;
        case 2:
-               load_file(argv[1]);
+               load_file(argv[optind]);
+               save_file_name = argv[optind+1];
+               if (!strcmp(save_file_name, "-"))
+                       save_file_name = NULL;
                break;
        default:
                usage(name);
@@ -72,6 +95,14 @@
        reporter = report_to_stderr;
        if (!instantiate())
                return 1;
+
+       if (batch_write_kicad)
+               write_kicad();
+       if (batch_write_ps)
+               write_ps();
+       if (batch_write_kicad || batch_write_ps)
+               exit(0);
+               
 //     inst_debug();
        error = gui_main();
        if (error)

Modified: trunk/eda/fped/gui.c
===================================================================
--- trunk/eda/fped/gui.c        2009-08-11 01:20:15 UTC (rev 5417)
+++ trunk/eda/fped/gui.c        2009-08-11 20:17:39 UTC (rev 5418)
@@ -11,18 +11,10 @@
  */
 
 
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
-#include <sys/stat.h>
 #include <gtk/gtk.h>
 
-#include "util.h"
 #include "inst.h"
-#include "obj.h"
-#include "dump.h"
-#include "kicad.h"
-#include "postscript.h"
+#include "file.h"
 #include "gui_util.h"
 #include "gui_style.h"
 #include "gui_status.h"
@@ -37,8 +29,6 @@
 #include "icons/meas_off.xpm"
 
 
-extern char *save_file;
-
 GtkWidget *root;
 int show_stuff = 1;
 int show_meas = 1;
@@ -49,162 +39,16 @@
 static GtkWidget *stuff_image[2], *meas_image[2];
 
 
-/* ----- save/write operations --------------------------------------------- */
-
-
-static char *set_extension(const char *name, const char *ext)
-{
-       char *s = stralloc(name);
-       char *slash, *dot;
-       char *res;
-
-       slash = strrchr(s, '/');
-       dot = strrchr(slash ? slash : s, '.');
-       if (dot)
-               *dot = 0;
-       res = stralloc_printf("%s.%s", s, ext);
-       free(s);
-       return res;
-}
-
-
-static int save_to(const char *name, int (*fn)(FILE *file))
-{
-       FILE *file;
-
-       file = fopen(name, "w");
-       if (!file) {
-               perror(name);
-               return 0;
-       }
-       if (!fn(file)) {
-               perror(name);
-               return 0;
-       }
-       if (fclose(file) == EOF) {
-               perror(name);
-               return 0;
-       }
-       return 1;
-}
-
-
-static void save_with_backup(const char *name, int (*fn)(FILE *file))
-{
-       char *s = stralloc(name);
-       char *back, *tmp;
-       char *slash, *dot;
-       int n;
-       struct stat st;
-
-       /* save to temporary file */
-
-       slash = strrchr(s, '/');
-       if (!slash)
-               tmp = stralloc_printf("~%s", s);
-       else {
-               *slash = 0;
-               tmp = stralloc_printf("%s/~%s", s, slash+1);
-               *slash = '/';
-       }
-
-       if (!save_to(tmp, fn))
-               return;
-
-       /* move existing file out of harm's way */
-
-       dot = strrchr(slash ? slash : s, '.');
-       if (dot)
-               *dot = 0;
-       n = 0;
-       while (1) {
-               back = stralloc_printf("%s~%d%s%s",
-                   s, n, dot ? "." : "", dot ? dot+1 : "");
-               if (stat(back, &st) < 0) {
-                       if (errno == ENOENT)
-                               break;
-                       perror(back);
-                       free(back);
-                       return;
-               }
-               free(back);
-               n++;
-       }
-       if (rename(name, back) < 0) {
-               if (errno != ENOENT) {
-                       perror(name);
-                       free(back);
-                       return;
-               }
-       } else {
-               fprintf(stderr, "renamed %s to %s\n", name, back);
-       }
-       free(back);
-
-       /* rename to final name */
-
-       if (rename(tmp, name) < 0) {
-               perror(name);
-               free(tmp);
-               return;
-       }
-       free(tmp);
-
-       fprintf(stderr, "saved to %s\n", name);
-}
-
-
-static void menu_save(void)
-{
-       if (save_file)
-               save_with_backup(save_file, dump);
-       else {
-               if (!dump(stdout))
-                       perror("stdout");
-       }
-}
-
-
-static void menu_write_kicad(void)
-{
-       char *name;
-
-       if (save_file) {
-               name = set_extension(save_file, "mod");
-               save_to(name, kicad);
-               free(name);
-       } else {
-               if (!kicad(stdout))
-                       perror("stdout");
-       }
-}
-
-
-static void menu_write_ps(void)
-{
-       char *name;
-
-       if (save_file) {
-               name = set_extension(save_file, "ps");
-               save_to(name, postscript);
-               free(name);
-       } else {
-               if (!postscript(stdout))
-                       perror("stdout");
-       }
-}
-
-
 /* ----- menu bar ---------------------------------------------------------- */
 
 
 static GtkItemFactoryEntry menu_entries[] = {
        { "/File",              NULL,   NULL,           0, "<Branch>" },
-       { "/File/Save",         NULL,   menu_save,      0, "<Item>" },
+       { "/File/Save",         NULL,   save_fpd,       0, "<Item>" },
         { "/File/sep0",                NULL,   NULL,           0, 
"<Separator>" },
-        { "/File/Write KiCad", NULL,   menu_write_kicad, 0, "<Item>" },
+        { "/File/Write KiCad", NULL,   write_kicad,    0, "<Item>" },
         { "/File/Write Postscript",
-                               NULL,   menu_write_ps,  0, "<Item>" },
+                               NULL,   write_ps,       0, "<Item>" },
         { "/File/sep2",                NULL,   NULL,           0, 
"<Separator>" },
         { "/File/Quit",                NULL,   gtk_main_quit,  0, "<Item>" },
 };

Modified: trunk/eda/fped/postscript.c
===================================================================
--- trunk/eda/fped/postscript.c 2009-08-11 01:20:15 UTC (rev 5417)
+++ trunk/eda/fped/postscript.c 2009-08-11 20:17:39 UTC (rev 5418)
@@ -51,7 +51,7 @@
 static void ps_line(FILE *file, const struct inst *inst)
 {
        struct coord a = inst->base;
-       struct coord b = inst->u.pad.other;
+       struct coord b = inst->u.rect.end;
 
        fprintf(file, "1 setlinecap 0.5 setgray %d setlinewidth\n",
            inst->u.rect.width);




--- End Message ---
--- Begin Message ---
Author: werner
Date: 2009-08-11 22:52:33 +0200 (Tue, 11 Aug 2009)
New Revision: 5419

Added:
   trunk/eda/fped/icons/delete_off.fig
Modified:
   trunk/eda/fped/Makefile
   trunk/eda/fped/TODO
   trunk/eda/fped/gui_tool.c
   trunk/eda/fped/gui_tool.h
   trunk/eda/fped/icons/delete.fig
   trunk/eda/fped/inst.c
Log:
Make delete feel "safer".

- objects are now deleted by selecting them, then clicking on the delete icon
- removed tool_ops.click, which was only there because of delete



Modified: trunk/eda/fped/Makefile
===================================================================
--- trunk/eda/fped/Makefile     2009-08-11 20:17:39 UTC (rev 5418)
+++ trunk/eda/fped/Makefile     2009-08-11 20:52:33 UTC (rev 5419)
@@ -18,7 +18,7 @@
 
 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 meas_x.xpm meas_y.xpm \
-       stuff.xpm stuff_off.xpm meas_off.xpm
+       stuff.xpm stuff_off.xpm meas_off.xpm delete_off.xpm
 
 CFLAGS_GTK = `pkg-config --cflags gtk+-2.0`
 LIBS_GTK = `pkg-config --libs gtk+-2.0`

Modified: trunk/eda/fped/TODO
===================================================================
--- trunk/eda/fped/TODO 2009-08-11 20:17:39 UTC (rev 5418)
+++ trunk/eda/fped/TODO 2009-08-11 20:52:33 UTC (rev 5419)
@@ -2,9 +2,10 @@
 - populate input area (still needed: mm/mil, rezoom)
 - add default unit (combine with grid unit selection ?)
 - consider adding auto/mm/mil selection for each dimension
-- add postscript output
+- add postscript output (partially done)
 - add option to include/omit helper vecs and frames (done for display, still
-  need postscript)
+  need postscript). Better idea: in PS, print the component 10x, 1x, and then
+  each individual frame 10x.
 
 Minor missing features:
 - reorder frames (can use text editor)
@@ -35,6 +36,9 @@
 - the drag logic is too complex. Better: let tool/instance just generate the
   list of points at each stage, then handle the highlighting and hovering
   inside a dragging module.
+- code organization is very poor. E.g., functions belonging to the different
+  items (pads, silk objects, vectors, etc.) should be grouped by item, not by
+  type of function, similar to how some things are now with gui_meas.c
 
 Open decisions:
 - Q: should loop be (start, last) or (start, iterations) ? or start ... last ?
@@ -60,5 +64,8 @@
 - advanced: silk line width
 - future: when encountering an error after a change, we could try to find the
   same element in the old instance, and select it
-- future: consider editing off-canvas items in place
+- idea: run the sort algorithm of dump.c to generate a list of objects per
+  frame, then show the list per frame in the GUI, e.g., as an alternative to
+  the variables. Allow selection.
+- future: consider editing non-canvas items in place
 - near future: treat part name as pattern

Modified: trunk/eda/fped/gui_tool.c
===================================================================
--- trunk/eda/fped/gui_tool.c   2009-08-11 20:17:39 UTC (rev 5418)
+++ trunk/eda/fped/gui_tool.c   2009-08-11 20:52:33 UTC (rev 5419)
@@ -41,15 +41,17 @@
 #include "icons/pad.xpm"
 #include "icons/point.xpm"
 #include "icons/delete.xpm"
+#include "icons/delete_off.xpm"
 #include "icons/rect.xpm"
 #include "icons/vec.xpm"
 
 
-static GtkWidget *ev_point, *ev_frame;
+static GtkWidget *ev_point, *ev_delete, *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 GtkWidget *delete_image[2];
 
 static struct drag_state {
        struct inst *inst; /* non-NULL if dragging an existing object */
@@ -167,24 +169,28 @@
 /* ----- delete ------------------------------------------------------------ */
 
 
-static void click_delete(struct coord pos)
+static void tool_selected_delete(void)
 {
-       inst_deselect();
-       inst_select(pos);
        if (selected_inst) {
                tool_dehover();
                inst_delete(selected_inst);
+               change_world();
        }
-       change_world();
        tool_reset();
 }
 
 
 static struct tool_ops delete_ops = {
-       .click          = click_delete,
+       .tool_selected  = tool_selected_delete,
 };
 
 
+void tool_selected_inst(struct inst *inst)
+{
+       set_image(ev_delete, delete_image[inst != NULL]);
+}
+
+
 /* ----- vec --------------------------------------------------------------- */
 
 
@@ -772,7 +778,7 @@
  * |  |
  * N  N  don't
  * Y  -  if we could drag, drag_new/end_new, else fall over to tool
- * N  Y  click, else single-click creation, else drag_new/end_new
+ * N  Y  else single-click creation, else drag_new/end_new
  */
 
 int tool_consider_drag(struct coord pos)
@@ -800,10 +806,6 @@
        }
        if (!active_ops)
                return 0;
-       if (active_ops->click) {
-               active_ops->click(pos);
-               return 0;
-       }
 
        curr = get_hover_inst(pos);
        if (!curr)
@@ -961,8 +963,8 @@
 
        ev_point = tool_button(bar, drawable, xpm_point,
            tool_button_press_event, NULL);
-       tool_button(bar, drawable, xpm_delete,
-           tool_button_press_event, &delete_ops);
+       ev_delete = tool_button(bar, drawable, NULL,
+            tool_button_press_event, &delete_ops);
        tool_separator(bar);
        tool_button(bar, drawable, xpm_vec,
            tool_button_press_event, &vec_ops);
@@ -991,6 +993,10 @@
            gtk_widget_ref(make_image(drawable, xpm_frame_ready));
        set_frame_image(frame_image);
 
+       delete_image[0] = gtk_widget_ref(make_image(drawable, xpm_delete_off));
+       delete_image[1] = gtk_widget_ref(make_image(drawable, xpm_delete));
+       set_image(ev_delete, delete_image[0]);
+
        tool_reset();
 
        return bar;

Modified: trunk/eda/fped/gui_tool.h
===================================================================
--- trunk/eda/fped/gui_tool.h   2009-08-11 20:17:39 UTC (rev 5418)
+++ trunk/eda/fped/gui_tool.h   2009-08-11 20:52:33 UTC (rev 5419)
@@ -23,7 +23,6 @@
        void (*tool_selected)(void);
        void (*tool_deselected)(void);
        struct inst *(*find_point)(struct coord pos);
-       void (*click)(struct coord pos);
        void (*begin_drag_new)(struct inst *from);
        struct pix_buf *(*drag_new)(struct inst *from, struct coord to);
        int (*end_new_raw)(struct inst *from, struct coord to);
@@ -71,6 +70,8 @@
 void tool_frame_update(void);
 void tool_frame_deleted(const struct frame *frame);
 
+void tool_selected_inst(struct inst *inst);
+
 void tool_reset(void);
 
 GtkWidget *gui_setup_tools(GdkDrawable *drawable);

Modified: trunk/eda/fped/icons/delete.fig
===================================================================
--- trunk/eda/fped/icons/delete.fig     2009-08-11 20:17:39 UTC (rev 5418)
+++ trunk/eda/fped/icons/delete.fig     2009-08-11 20:52:33 UTC (rev 5419)
@@ -9,7 +9,7 @@
 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
+2 1 0 15 19 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
+2 1 0 15 19 7 50 -1 -1 0.000 0 1 -1 0 0 2
         4125 4275 5475 2925

Added: trunk/eda/fped/icons/delete_off.fig
===================================================================
--- trunk/eda/fped/icons/delete_off.fig                         (rev 0)
+++ trunk/eda/fped/icons/delete_off.fig 2009-08-11 20:52:33 UTC (rev 5419)
@@ -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 55 -1 10 0.000 0 0 -1 0 0 5
+        3600 2400 6000 2400 6000 4800 3600 4800 3600 2400
+2 1 0 15 0 7 50 -1 -1 0.000 0 1 -1 0 0 2
+        4125 2925 5475 4275
+2 1 0 15 0 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-11 20:17:39 UTC (rev 5418)
+++ trunk/eda/fped/inst.c       2009-08-11 20:52:33 UTC (rev 5419)
@@ -118,6 +118,8 @@
        deselect_outside();
        edit_nothing();
        selected_inst = NULL;
+       if (selected_inst)
+               tool_selected_inst(NULL);
        FOR_INST_PRIOS_DOWN(prio) {
                if (!show(prio))
                        continue;
@@ -154,6 +156,7 @@
 
 selected:
        set_path(1);
+       tool_selected_inst(selected_inst);
        if (selected_inst->ops->select)
                selected_inst->ops->select(selected_inst);
        return 1;
@@ -263,8 +266,10 @@
 
 void inst_deselect(void)
 {
-       if (selected_inst)
+       if (selected_inst) {
                set_path(0);
+               tool_selected_inst(NULL);
+       }
        deselect_outside();
        status_set_type_x("");
        status_set_type_y("");




--- End Message ---
--- Begin Message ---
Author: werner
Date: 2009-08-11 23:54:18 +0200 (Tue, 11 Aug 2009)
New Revision: 5420

Modified:
   trunk/eda/fped/gui_meas.c
   trunk/eda/fped/gui_tool.c
   trunk/eda/fped/gui_tool.h
Log:
- measurements entered through the GUI were connected to the active frame, not
  the root frame



Modified: trunk/eda/fped/gui_meas.c
===================================================================
--- trunk/eda/fped/gui_meas.c   2009-08-11 20:52:33 UTC (rev 5419)
+++ trunk/eda/fped/gui_meas.c   2009-08-11 21:54:18 UTC (rev 5420)
@@ -269,7 +269,8 @@
        if (from == to)
                return 0;
        /* it's safe to pass "from" here, but we may change it later */
-       obj = new_obj(ot_meas, from);
+       obj = new_obj_unconnected(ot_meas, from);
+       connect_obj(root_frame, obj);
        meas = &obj->u.meas;
        meas->label = NULL;
        switch (mode) {

Modified: trunk/eda/fped/gui_tool.c
===================================================================
--- trunk/eda/fped/gui_tool.c   2009-08-11 20:52:33 UTC (rev 5419)
+++ trunk/eda/fped/gui_tool.c   2009-08-11 21:54:18 UTC (rev 5420)
@@ -83,9 +83,9 @@
 }
 
 
-struct obj *new_obj(enum obj_type type, struct inst *base)
+struct obj *new_obj_unconnected(enum obj_type type, struct inst *base)
 {
-       struct obj *obj, **walk;
+       struct obj *obj;
 
        obj = alloc_type(struct obj);
        obj->type = type;
@@ -93,8 +93,25 @@
        obj->base = inst_get_vec(base);
        obj->next = NULL;
        obj->lineno = 0;
-       for (walk = &active_frame->objs; *walk; walk = &(*walk)->next);
+       return obj;
+}
+
+
+void connect_obj(struct frame *frame, struct obj *obj)
+{
+       struct obj **walk;
+
+       for (walk = &frame->objs; *walk; walk = &(*walk)->next);
        *walk = obj;
+}
+
+
+static struct obj *new_obj(enum obj_type type, struct inst *base)
+{
+       struct obj *obj;
+
+       obj = new_obj_unconnected(type, base);
+       connect_obj(active_frame, obj);
        return obj;
 }
 

Modified: trunk/eda/fped/gui_tool.h
===================================================================
--- trunk/eda/fped/gui_tool.h   2009-08-11 20:52:33 UTC (rev 5419)
+++ trunk/eda/fped/gui_tool.h   2009-08-11 21:54:18 UTC (rev 5420)
@@ -57,7 +57,8 @@
  * compilation unit.
  */
 
-struct obj *new_obj(enum obj_type type, struct inst *base);
+struct obj *new_obj_unconnected(enum obj_type type, struct inst *base);
+void connect_obj(struct frame *frame, struct obj *obj);
 struct pix_buf *draw_move_line_common(struct inst *inst,
     struct coord end, struct coord pos, int i);
 struct pix_buf *drag_new_line(struct inst *from, struct coord to);




--- End Message ---
--- Begin Message ---
Author: werner
Date: 2009-08-12 01:26:38 +0200 (Wed, 12 Aug 2009)
New Revision: 5421

Added:
   trunk/eda/fped/fbga.fpd
Modified:
   trunk/eda/fped/TODO
   trunk/eda/fped/expr.c
   trunk/eda/fped/expr.h
   trunk/eda/fped/file.c
   trunk/eda/fped/file.h
   trunk/eda/fped/fped.c
   trunk/eda/fped/gui_frame.c
   trunk/eda/fped/unparse.c
Log:
- added support for string constants to unparse()
- implemented eval_str
- expand() now tries to obtain a string
- added example fbga.fpd to demonstrate use of strings
- when invoked with an inexisting file, fped now starts with an empty model,
  instead of getting confused 
- we now religiously call edit_nothing before adding fields to edit, so that
  we won't create a loop through edit-next



Modified: trunk/eda/fped/TODO
===================================================================
--- trunk/eda/fped/TODO 2009-08-11 21:54:18 UTC (rev 5420)
+++ trunk/eda/fped/TODO 2009-08-11 23:26:38 UTC (rev 5421)
@@ -39,6 +39,9 @@
 - code organization is very poor. E.g., functions belonging to the different
   items (pads, silk objects, vectors, etc.) should be grouped by item, not by
   type of function, similar to how some things are now with gui_meas.c
+- eval_string_var should be merged into eval_var and the result should be a
+  struct num (?) that can contain both types. This also means changing all the
+  ops to handle/reject strings.
 
 Open decisions:
 - Q: should loop be (start, last) or (start, iterations) ? or start ... last ?

Modified: trunk/eda/fped/expr.c
===================================================================
--- trunk/eda/fped/expr.c       2009-08-11 21:54:18 UTC (rev 5420)
+++ trunk/eda/fped/expr.c       2009-08-11 23:26:38 UTC (rev 5421)
@@ -154,6 +154,38 @@
 }
 
 
+static const char *eval_string_var(const struct frame *frame, const char *name)
+{
+       const struct table *table;
+       const struct loop *loop;
+       const struct value *value;
+       struct var *var;
+       const char *res;
+
+       for (table = frame->tables; table; table = table->next) {
+               value = table->curr_row->values;
+               for (var = table->vars; var; var = var->next) {
+                       if (var->name == name) {
+                               if (var->visited)
+                                       return NULL;
+                               var->visited = 1;
+                               res = eval_str(value->expr, frame);
+                               var->visited = 0;
+                               return res;
+                               
+                       }
+                       value = value->next;
+               }
+       }
+       for (loop = frame->loops; loop; loop = loop->next)
+               if (loop->var.name == name)
+                       return NULL;
+       if (frame->curr_parent)
+               return eval_string_var(frame->curr_parent, name);
+       return NULL;
+}
+
+
 struct num op_var(const struct expr *self, const struct frame *frame)
 {
        struct num res;
@@ -307,9 +339,13 @@
 }
 
 
-char *eval_str(const struct frame *frame, const struct expr *expr)
+const char *eval_str(const struct expr *expr, const struct frame *frame)
 {
-       abort();
+       if (expr->op == op_string)
+               return expr->u.str;
+       if (expr->op == op_var)
+               return eval_string_var(frame, expr->u.var);
+       return NULL;
 }
 
 
@@ -329,7 +365,7 @@
        char num_buf[100]; /* enough :-) */
        const char *s, *s0;
        char *var;
-       const char *var_unique;
+       const char *var_unique, *value_string;
        struct num value;
        int i, value_len;
 
@@ -366,18 +402,24 @@
                        continue;
                var_unique = unique(var);
                free(var);
-               value = eval_var(frame, var_unique);
-               if (is_undef(value)) {
-                       fail("undefined variable \"%s\"", var_unique);
-                       goto fail;
+               value_string = eval_string_var(frame, var_unique);
+               if (value_string)
+                       value_len = strlen(value_string);
+               else {
+                       value = eval_var(frame, var_unique);
+                       if (is_undef(value)) {
+                               fail("undefined variable \"%s\"", var_unique);
+                               goto fail;
+                       }
+                       value_len = snprintf(num_buf, sizeof(num_buf), "%lg%s",
+                           value.n, str_unit(value));
+                       value_string = num_buf;
                }
-               value_len = snprintf(num_buf, sizeof(num_buf), "%lg%s",
-                   value.n, str_unit(value));
                len += value_len;
                buf = realloc(buf, len+1);
                if (!buf)
                        abort();
-               strcpy(buf+i, num_buf);
+               strcpy(buf+i, value_string);
                i += value_len;
        }
        buf[i] = 0;
@@ -410,6 +452,7 @@
 void scan_expr(const char *s);
 int yyparse(void);
 
+
 struct expr *expr_result;
 
 
@@ -422,14 +465,15 @@
 
 static void vacate_op(struct expr *expr)
 {
-       if (expr->op == &op_num || expr->op == &op_var)
+       if (expr->op == op_num || expr->op == op_string ||
+           expr->op == op_var)
                return;
-       if (expr->op == &op_minus) {
+       if (expr->op == op_minus) {
                free_expr(expr->u.op.a);
                return;
        }
-       if (expr->op == &op_add || expr->op == &op_sub ||
-           expr->op == &op_mult || expr->op == &op_div) {
+       if (expr->op == op_add || expr->op == op_sub ||
+           expr->op == op_mult || expr->op == op_div) {
                free_expr(expr->u.op.a);
                free_expr(expr->u.op.b);
                return;

Modified: trunk/eda/fped/expr.h
===================================================================
--- trunk/eda/fped/expr.h       2009-08-11 21:54:18 UTC (rev 5420)
+++ trunk/eda/fped/expr.h       2009-08-11 23:26:38 UTC (rev 5421)
@@ -121,7 +121,13 @@
 struct expr *binary_op(op_type op, struct expr *a, struct expr *b);
 
 struct num eval_var(const struct frame *frame, const char *name);
-char *eval_str(const struct frame *frame, const struct expr *expr);
+
+/*
+ * eval_str returns NULL if the result isn't a string. Evaluation may then
+ * be attempted with eval_num, and the result can be converted accordingly.
+ */
+const char *eval_str(const struct expr *expr, const struct frame *frame);
+
 struct num eval_num(const struct expr *expr, const struct frame *frame);
 
 /* if frame == NULL, we only check the syntax without expanding */

Added: trunk/eda/fped/fbga.fpd
===================================================================
--- trunk/eda/fped/fbga.fpd                             (rev 0)
+++ trunk/eda/fped/fbga.fpd     2009-08-11 23:26:38 UTC (rev 5421)
@@ -0,0 +1,52 @@
+/* MACHINE-GENERATED ! */
+
+frame pad {
+       set Px = 0.5mm
+
+       set Py = 0.5mm
+
+       set cname = col+1
+
+       __0: vec @(col*1mm-Px/2, row*-1mm-Py/2)
+       __1: vec .(0mm, Py)
+       __2: vec __0(Px, 0mm)
+       pad "$rname$cname" __1 __2
+}
+
+frame inner {
+       loop col = c0, c1
+
+       frame pad @
+}
+
+frame last {
+       loop col = 4, 5
+
+       frame pad @
+}
+
+frame first {
+       loop col = 0, 1
+
+       frame pad @
+}
+
+part "Fake_BGA"
+table
+    { row, rname, c0, c1 }
+    { 0, "A", 2, 3 }
+    { 1, "B", 2, 3 }
+    { 2, "C", 9, 0 }
+    { 3, "D", 9, 0 }
+    { 4, "E", 2, 3 }
+    { 5, "F", 2, 3 }
+
+frame last @
+frame first @
+frame inner @
+measy pad.__0 -> pad.__1 0.2mm
+measy pad.__0 -> pad.__0 0.5mm
+measx pad.__0 -> pad.__2 -0.3mm
+measx pad.__0 -> pad.__0 -0.6mm
+measy pad.__0 >> pad.__1 0.8mm
+measx pad.__0 >> pad.__2 -0.9mm

Modified: trunk/eda/fped/file.c
===================================================================
--- trunk/eda/fped/file.c       2009-08-11 21:54:18 UTC (rev 5420)
+++ trunk/eda/fped/file.c       2009-08-11 23:26:38 UTC (rev 5421)
@@ -47,6 +47,19 @@
 }
 
 
+int file_exists(const char *name)
+{
+       struct stat st;
+
+       if (stat(name, &st) >= 0)
+               return 1;
+       if (errno == ENOENT)
+               return 0;
+       perror(name);
+       return -1;
+}
+
+
 int save_to(const char *name, int (*fn)(FILE *file))
 {
        FILE *file;
@@ -73,8 +86,7 @@
        char *s = stralloc(name);
        char *back, *tmp;
        char *slash, *dot;
-       int n;
-       struct stat st;
+       int n, res;
 
        /* save to temporary file */
 
@@ -99,14 +111,12 @@
        while (1) {
                back = stralloc_printf("%s~%d%s%s",
                    s, n, dot ? "." : "", dot ? dot+1 : "");
-               if (stat(back, &st) < 0) {
-                       if (errno == ENOENT)
-                               break;
-                       perror(back);
-                       free(back);
+               res = file_exists(back);
+               if (!res)
+                       break;
+               free(back);
+               if (res < 0)
                        return;
-               }
-               free(back);
                n++;
        }
        if (rename(name, back) < 0) {

Modified: trunk/eda/fped/file.h
===================================================================
--- trunk/eda/fped/file.h       2009-08-11 21:54:18 UTC (rev 5420)
+++ trunk/eda/fped/file.h       2009-08-11 23:26:38 UTC (rev 5421)
@@ -17,6 +17,11 @@
 #include <stdio.h>
 
 
+/*
+ * Returns -1 on error.
+ */
+int file_exists(const char *name);
+
 char *set_extension(const char *name, const char *ext);
 int save_to(const char *name, int (*fn)(FILE *file));
 void save_with_backup(const char *name, int (*fn)(FILE *file));

Modified: trunk/eda/fped/fped.c
===================================================================
--- trunk/eda/fped/fped.c       2009-08-11 21:54:18 UTC (rev 5420)
+++ trunk/eda/fped/fped.c       2009-08-11 23:26:38 UTC (rev 5421)
@@ -32,8 +32,12 @@
 
 static void load_file(const char *name)
 {
-       reporter = report_parse_error;
-       run_cpp_on_file(name);
+       if (file_exists(name) == 1) {
+               reporter = report_parse_error;
+               run_cpp_on_file(name);
+       } else {
+               scan_empty();
+       }
        (void) yyparse();
 }
 

Modified: trunk/eda/fped/gui_frame.c
===================================================================
--- trunk/eda/fped/gui_frame.c  2009-08-11 21:54:18 UTC (rev 5420)
+++ trunk/eda/fped/gui_frame.c  2009-08-11 23:26:38 UTC (rev 5421)
@@ -487,6 +487,7 @@
        label_in_box_bg(var->widget, COLOR_VAR_EDITING);
        status_set_type_entry("name =");
        status_set_name("%s", var->name);
+       edit_nothing();
        edit_unique(&var->name, validate_var_name, var);
 }
 
@@ -508,6 +509,7 @@
 {
        inst_select_outside(value, unselect_value);
        label_in_box_bg(value->widget, COLOR_EXPR_EDITING);
+       edit_nothing();
        edit_expr(&value->expr);
 }
 
@@ -549,6 +551,7 @@
 
        switch (event->button) {
        case 1:
+               edit_nothing();
                edit_var(var);
                break;
        case 3:
@@ -566,6 +569,7 @@
 
        switch (event->button) {
        case 1:
+               edit_nothing();
                edit_value(value);
                break;
        }
@@ -633,6 +637,7 @@
 
        switch (event->button) {
        case 1:
+               edit_nothing();
                edit_var(var);
                break;
        case 3:
@@ -650,9 +655,11 @@
 
        switch (event->button) {
        case 1:
-               if (!value->row || value->row->table->active_row == value->row)
+               if (!value->row ||
+                   value->row->table->active_row == value->row) {
+                       edit_nothing();
                        edit_value(value);
-               else {
+               } else {
                        select_row(value->row);
                        change_world();
                }
@@ -745,6 +752,7 @@
 
        switch (event->button) {
        case 1:
+               edit_nothing();
                edit_var(&loop->var);
                break;
        case 3:
@@ -762,6 +770,7 @@
 
        switch (event->button) {
        case 1:
+               edit_nothing();
                edit_value(&loop->from);
                break;
        }
@@ -776,6 +785,7 @@
 
        switch (event->button) {
        case 1:
+               edit_nothing();
                edit_value(&loop->to);
                break;
        }
@@ -940,6 +950,7 @@
                label_in_box_bg(widget, COLOR_PART_NAME_EDITING);
                status_set_type_entry("part =");
                status_set_name("%s", part_name);
+               edit_nothing();
                edit_name(&part_name, validate_part_name, NULL);
                break;
        }
@@ -1001,6 +1012,7 @@
        label_in_box_bg(frame->label, COLOR_FRAME_EDITING);
        status_set_type_entry("name =");
        status_set_name("%s", frame->name);
+       edit_nothing();
        edit_unique(&frame->name, validate_frame_name, frame);
 }
 
@@ -1025,8 +1037,10 @@
                if (active_frame != frame)
                        select_frame(frame);
                else {
-                       if (active_frame->name)
+                       if (active_frame->name) {
+                               edit_nothing();
                                edit_frame(frame);
+                       }
                }
                break;
        case 3:

Modified: trunk/eda/fped/unparse.c
===================================================================
--- trunk/eda/fped/unparse.c    2009-08-11 21:54:18 UTC (rev 5420)
+++ trunk/eda/fped/unparse.c    2009-08-11 23:26:38 UTC (rev 5421)
@@ -38,7 +38,7 @@
                return prec_mult;
        if (op == op_minus)
                return prec_unary;
-       if (op == op_num || op == op_var)
+       if (op == op_num || op == op_string || op == op_var)
                return prec_primary;
        abort();
 }
@@ -85,6 +85,8 @@
                    expr->u.num.n, str_unit(expr->u.num));
                return stralloc(tmp);
        }
+       if (expr->op == op_string)
+               return stralloc_printf("\"%s\"", expr->u.str);
        if (expr->op == op_var)
                return stralloc(expr->u.var);
        if (expr->op == op_minus)




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

Reply via email to