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. r5328 - developers/werner/fped (wer...@docs.openmoko.org)
   2. r5329 - developers/werner/openness (wer...@docs.openmoko.org)
   3. r5330 - developers/werner/openness (wer...@docs.openmoko.org)
   4. r5331 - developers/werner/fped (wer...@docs.openmoko.org)
   5. r5332 - developers/werner/fped (wer...@docs.openmoko.org)
--- Begin Message ---
Author: werner
Date: 2009-07-28 20:03:43 +0200 (Tue, 28 Jul 2009)
New Revision: 5328

Modified:
   developers/werner/fped/TODO
   developers/werner/fped/gui_canvas.c
   developers/werner/fped/gui_inst.c
   developers/werner/fped/obj.c
   developers/werner/fped/qfn.fpd
Log:
- bug: vectors always started at the origin of the frame
- corrected various bugs in qfn.fpd
- gui_draw_frame: frame origin was translated twice



Modified: developers/werner/fped/TODO
===================================================================
--- developers/werner/fped/TODO 2009-07-28 16:10:50 UTC (rev 5327)
+++ developers/werner/fped/TODO 2009-07-28 18:03:43 UTC (rev 5328)
@@ -21,3 +21,6 @@
 - consider adding auto/mm/mil selection for each dimension
 - syntax seems a little cryptic. too many dots and at signs.
 - add measurements
+- add continuous coordinate display
+- add user coordinates. hide if inactive ?
+- arc syntax is weird, with comma where we use spaces

Modified: developers/werner/fped/gui_canvas.c
===================================================================
--- developers/werner/fped/gui_canvas.c 2009-07-28 16:10:50 UTC (rev 5327)
+++ developers/werner/fped/gui_canvas.c 2009-07-28 18:03:43 UTC (rev 5328)
@@ -22,7 +22,7 @@
 #include "gui.h"
 
 
-struct draw_ctx ctx;
+static struct draw_ctx ctx;
 
 
 /* ----- zoom display ------------------------------------------------------ */

Modified: developers/werner/fped/gui_inst.c
===================================================================
--- developers/werner/fped/gui_inst.c   2009-07-28 16:10:50 UTC (rev 5327)
+++ developers/werner/fped/gui_inst.c   2009-07-28 18:03:43 UTC (rev 5328)
@@ -70,7 +70,6 @@
 static void draw_eye(struct draw_ctx *ctx, GdkGC *gc, struct coord center,
     int r1, int r2)
 {
-       center = translate(ctx, center);
        draw_circle(ctx, gc, TRUE, center.x, center.y, r1);
        draw_circle(ctx, gc, FALSE, center.x, center.y, r2);
 }
@@ -117,10 +116,10 @@
        struct coord from = translate(ctx, self->base);
        struct coord to = translate(ctx, self->u.end);
 
-       draw_circle(ctx, gc_vec_bg, FALSE, to.x, to.y, VEC_EYE_R);
        draw_arrow(ctx, gc_vec_bg, TRUE, from, to,
          VEC_ARROW_LEN, VEC_ARROW_ANGLE);
        gdk_draw_line(DA, gc_vec_bg, from.x, from.y, to.x, to.y);
+       draw_circle(ctx, gc_vec_bg, FALSE, to.x, to.y, VEC_EYE_R);
 }
 
 
@@ -180,10 +179,10 @@
 
 void gui_draw_frame(struct inst *self, struct draw_ctx *ctx)
 {
-       struct coord pos = translate(ctx, self->base);
+       struct coord center = translate(ctx, self->base);
        struct coord corner = { self->bbox.min.x, self->bbox.max.y };
 
-       draw_eye(ctx, gc_frame_bg, pos, FRAME_EYE_R1, FRAME_EYE_R2);
+       draw_eye(ctx, gc_frame_bg, center, FRAME_EYE_R1, FRAME_EYE_R2);
        if (!self->u.frame.ref->name)
                return;
        corner = translate(ctx, corner);

Modified: developers/werner/fped/obj.c
===================================================================
--- developers/werner/fped/obj.c        2009-07-28 16:10:50 UTC (rev 5327)
+++ developers/werner/fped/obj.c        2009-07-28 18:03:43 UTC (rev 5328)
@@ -27,6 +27,7 @@
 
 static int generate_objects(struct frame *frame, struct coord base)
 {
+       struct coord vec_base;
        struct vec *vec;
        struct obj *obj;
        double x, y;
@@ -38,10 +39,11 @@
                y = eval_num(vec->y, frame);
                if (y == UNDEF)
                        return 0;
-               vec->pos = vec->base ? vec->base->pos : base;
+               vec_base = vec->base ? vec->base->pos : base;
+               vec->pos = vec_base;
                vec->pos.x += x;
                vec->pos.y += y;
-               if (!inst_vec(vec, base))
+               if (!inst_vec(vec, vec_base))
                        return 0;
        }
        for (obj = frame->objs; obj; obj = obj->next)

Modified: developers/werner/fped/qfn.fpd
===================================================================
--- developers/werner/fped/qfn.fpd      2009-07-28 16:10:50 UTC (rev 5327)
+++ developers/werner/fped/qfn.fpd      2009-07-28 18:03:43 UTC (rev 5328)
@@ -1,17 +1,17 @@
 # http://www.nxp.com/acrobat/packages/footprint/SOT616-1_fp_reflow.pdf
 
 .frame pad_up {
-       .vec @ -D/2, 0
+       c = .vec @ -D/2, 0
        .vec . D, C
-       .pad "N/4+n" @ .
+       .pad "N/4+n" c .
 }
 
 N = 24
 
 .table
-    { P, Ax, Ay, By, C, D, SLx, SLy, SPx_tot, SPy_tot, SPx, SPy, Gx, Gy, Hx, 
Hy }
+    { P, Ax, Ay, Bx, By, C, D, SLx, SLy, SPx_tot, SPy_tot, SPx, SPy, Gx, Gy, 
Hx, Hy }
     { 0.5mm, 5mm, 5mm, 3.2mm, 3.2mm, 0.9mm, 0.24mm, 2.1mm, 2.1mm, 1.2mm,
-      0.45mm, 0.45mm, 4.3mm, 4.3mm, 5.25mm, 5.25mm }
+      1.2mm, 0.45mm, 0.45mm, 4.3mm, 4.3mm, 5.25mm, 5.25mm }
 
 h_x0y0 = .vec @ -Hx/2, -Hy/2
 h_x1y1 = .vec . Hx, Hy
@@ -23,7 +23,7 @@
 
 n = 0, N/4-1
 
-.vec @ P*(n-N/4/2), -Ay/2
+.vec @ P*(n-(N/4-1)/2), -Ay/2
 .frame pad_up .
 
 # ARC, just for testing




--- End Message ---
--- Begin Message ---
Author: werner
Date: 2009-07-28 21:05:01 +0200 (Tue, 28 Jul 2009)
New Revision: 5329

Modified:
   developers/werner/openness/odhwdr.tex
Log:
Final version. Removed the explanation box.



Modified: developers/werner/openness/odhwdr.tex
===================================================================
--- developers/werner/openness/odhwdr.tex       2009-07-28 18:03:43 UTC (rev 
5328)
+++ developers/werner/openness/odhwdr.tex       2009-07-28 19:05:01 UTC (rev 
5329)
@@ -19,7 +19,7 @@
 
 \title{Open Design Hardware --- Disclosure Requisites}
 \author{Werner Almesberger \\ \url{wer...@openmoko.org}}
-\date{July 26, 2009}
+\date{July 28, 2009}
 
 \parindent=0pt
 \parskip=8pt
@@ -29,31 +29,31 @@
 \maketitle
 \thispagestyle{empty}
 
-\framebox[\textwidth][c]{
-\begin{minipage}{0.9\textwidth}
-~\vskip1mm
-\parskip=8pt
-This is a draft. The term ``Open Design Hardware'' and the title
-``Disclosure Requisites'' are both open for discussion, along with
-the rest of the document. This box will be removed in the final
-version.
+% \framebox[\textwidth][c]{
+% \begin{minipage}{0.9\textwidth}
+% ~\vskip1mm
+% \parskip=8pt
+% This is a draft. The term ``Open Design Hardware'' and the title
+% ``Disclosure Requisites'' are both open for discussion, along with
+% the rest of the document. This box will be removed in the final
+% version.
+% 
+% This short document aims to familiarize component vendors with the concepts
+% of Open Design Hardware and to explain the specific needs of OSH. The
+% objectives:
+% \begin{itemize}
+%   \item accurately present our needs
+%   \item be understandable (to a corporate readership)
+%   \item convince them to provide documentation in a way we can use
+% \end{itemize}
+% 
+% Open Source Software and firmware requirements have been deliberately
+% excluded to keep this short and because they should/might be covered
+% in a separate document.
+% \vskip-2mm~
+% \end{minipage}}
+% \vskip2mm
 
-This short document aims to familiarize component vendors with the concepts
-of Open Design Hardware and to explain the specific needs of OSH. The
-objectives:
-\begin{itemize}
-  \item accurately present our needs
-  \item be understandable (to a corporate readership)
-  \item convince them to provide documentation in a way we can use
-\end{itemize}
-
-Open Source Software and firmware requirements have been deliberately
-excluded to keep this short and because they should/might be covered
-in a separate document.
-\vskip-2mm~
-\end{minipage}}
-\vskip2mm
-
 Open Source Software has proven that an open design process and liberal
 licensing contribute towards enhancing the quality, utility, and overall
 success of software products, and encourage convergence and cooperation




--- End Message ---
--- Begin Message ---
Author: werner
Date: 2009-07-28 21:07:11 +0200 (Tue, 28 Jul 2009)
New Revision: 5330

Modified:
   developers/werner/openness/Makefile
Log:
New location and version number:
http://people.openmoko.org/werner/openness/odhwdr-v1.pdf



Modified: developers/werner/openness/Makefile
===================================================================
--- developers/werner/openness/Makefile 2009-07-28 19:05:01 UTC (rev 5329)
+++ developers/werner/openness/Makefile 2009-07-28 19:07:11 UTC (rev 5330)
@@ -1,3 +1,5 @@
+VERSION=v1
+
 .PHONY:        all dvi xdvi pdf xpdf print print4 upload
 
 all:   xpdf
@@ -21,4 +23,5 @@
        dvips -f odhwdr | mpage -4 | lpr
 
 upload:        pdf
-       scp odhwdr.pdf wer...@sita.openmoko.org:public_html/
+       scp odhwdr.pdf \
+         wer...@sita.openmoko.org:public_html/openness/odhwdr-$(VERSION).pdf




--- End Message ---
--- Begin Message ---
Author: werner
Date: 2009-07-28 21:50:12 +0200 (Tue, 28 Jul 2009)
New Revision: 5331

Added:
   developers/werner/fped/cpp.c
   developers/werner/fped/cpp.h
Modified:
   developers/werner/fped/Makefile
   developers/werner/fped/TODO
   developers/werner/fped/fpd.y
   developers/werner/fped/fped.c
   developers/werner/fped/gui_canvas.c
   developers/werner/fped/gui_inst.c
   developers/werner/fped/inst.c
   developers/werner/fped/qfn.fpd
Log:
- added continuous coordinate display and user coordinates
- corrected calculation of second angle in arc
- circles were stored and rendered incorrectly
- we now run CPP on the input file
- enabled more compiler warnings



Modified: developers/werner/fped/Makefile
===================================================================
--- developers/werner/fped/Makefile     2009-07-28 19:07:11 UTC (rev 5330)
+++ developers/werner/fped/Makefile     2009-07-28 19:50:12 UTC (rev 5331)
@@ -1,12 +1,27 @@
-OBJS = fped.o expr.o coord.o obj.o inst.o util.o error.o lex.yy.o y.tab.o \
+#
+# Makefile - Makefile of fped, the footprint editor
+#
+# 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.
+#
+
+OBJS = fped.o expr.o coord.o obj.o inst.o util.o error.o \
+       cpp.o lex.yy.o y.tab.o \
        gui.o gui_style.o gui_inst.o gui_status.o gui_canvas.o
 
 CFLAGS_GTK = `pkg-config --cflags gtk+-2.0`
 LIBS_GTK = `pkg-config --libs gtk+-2.0`
 
-CFLAGS=-Wall -g $(CFLAGS_GTK)
-CFLAGS_LEX=-g
-CFLAGS_YACC=-g
+CFLAGS_WARN=-Wall -Wshadow -Wmissing-prototypes \
+            -Wmissing-declarations
+CFLAGS=-g $(CFLAGS_GTK) -DCPP='"cpp"' $(CFLAGS_WARN)
+SLOPPY=-Wno-unused -Wno-implicit-function-declaration -Wno-missing-prototypes \
+       -Wno-missing-declarations
 LDLIBS = -lm -lfl $(LIBS_GTK)
 YACC=bison -y
 YYFLAGS=-v
@@ -20,13 +35,13 @@
                $(LEX) fpd.l
 
 lex.yy.o:      lex.yy.c y.tab.h
-               $(CC) -c $(CFLAGS_LEX) lex.yy.c
+               $(CC) -c $(CFLAGS) $(SLOPPY) lex.yy.c
 
 y.tab.c y.tab.h: fpd.y
                $(YACC) $(YYFLAGS) -d fpd.y
 
 y.tab.o:       y.tab.c
-               $(CC) -c $(CFLAGS_YACC) y.tab.c
+               $(CC) -c $(CFLAGS) $(SLOPPY) y.tab.c
 
 # ----- Dependencies ----------------------------------------------------------
 

Modified: developers/werner/fped/TODO
===================================================================
--- developers/werner/fped/TODO 2009-07-28 19:07:11 UTC (rev 5330)
+++ developers/werner/fped/TODO 2009-07-28 19:50:12 UTC (rev 5331)
@@ -8,9 +8,7 @@
 - stack elements (3): circle on top of vec
 - detect recursive evaluation (through variables)
 - eliminate duplicate instances
-- populate input area
-- bug: center moves in qfn.fpd
-- bug: pad and silk geometry doesn't match in qfn.fpd
+- populate input area (still needed: mm/mil, rezoom)
 - add vec editor
 - add obj editor
 - decide on table presentation
@@ -21,6 +19,8 @@
 - consider adding auto/mm/mil selection for each dimension
 - syntax seems a little cryptic. too many dots and at signs.
 - add measurements
-- add continuous coordinate display
-- add user coordinates. hide if inactive ?
 - arc syntax is weird, with comma where we use spaces
+- Q: allow reassignment of vector names ?
+- add KiCad output
+- add postscript output
+- add option to include/omit helper vecs and frames (display and postscript)

Added: developers/werner/fped/cpp.c
===================================================================
--- developers/werner/fped/cpp.c                                (rev 0)
+++ developers/werner/fped/cpp.c        2009-07-28 19:50:12 UTC (rev 5331)
@@ -0,0 +1,217 @@
+/*
+ * cpp.c - CPP subprocess
+ *
+ * Written 2002-2004, 2006, 2008 by Werner Almesberger
+ * Copyright 2002, 2003 California Institute of Technology
+ * Copyright 2004, 2006 Werner Almesberger
+ * Copyright 2008 by OpenMoko, Inc.
+ *
+ * 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 <unistd.h>
+#include <string.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+#include "cpp.h"
+
+
+const char *cpp_command = CPP;
+
+static pid_t cpp_pid;
+static int cpp_argc = 0;
+static const char **cpp_argv = NULL;
+static int real_stdin = -1;
+
+
+void add_cpp_arg(const char *arg)
+{
+    if (!cpp_argc)
+       cpp_argc = 1;
+    cpp_argv = realloc(cpp_argv,sizeof(const char *)*(cpp_argc+1));
+    if (!cpp_argv) {
+       perror("realloc");
+       exit(1);
+    }
+    if (cpp_argc == 1)
+       cpp_argv[0] = cpp_command;
+    if (arg) {
+       arg = strdup(arg);
+       if (!arg) {
+           perror("strdup");
+           exit(1);
+       }
+    }
+    cpp_argv[cpp_argc++] = arg;
+}
+
+
+void add_cpp_Wp(const char *arg)
+{
+    char *tmp = strdup(arg);
+    char *curr,*end;
+
+    if (!tmp) {
+       perror("strdup");
+       exit(1);
+    }
+    curr = tmp;
+    do {
+       end = strchr(curr,',');
+       if (end)
+           *end++ = 0;
+       add_cpp_arg(curr);
+       curr = end;
+    }
+    while (end);
+    free(tmp);
+}
+
+
+static void kill_cpp(void)
+{
+    if (cpp_pid)
+       (void) kill(cpp_pid,SIGTERM);
+}
+
+
+static void run_cpp(const char *name,int fd,int close_fd)
+{
+    char **arg;
+    int fds[2];
+
+    if (pipe(fds) < 0) {
+        perror("pipe");
+        exit(1);
+    }
+    if (name)
+       add_cpp_arg(name);
+    add_cpp_arg(NULL);
+    cpp_pid = fork();
+    if (cpp_pid < 0) {
+        perror("fork");
+        exit(1);
+    }
+    if (!cpp_pid) {
+       if (close(fds[0]) < 0) {
+           perror("close");
+           exit(1);
+       }
+       if (close_fd != -1 && close(close_fd) < 0) {
+           perror("close");
+           exit(1);
+       }
+       if (fd != -1 && dup2(fd,0) < 0) {
+           perror("dup2");
+           exit(1);
+       }
+       if (dup2(fds[1],1) < 0) {
+           perror("dup2");
+           exit(1);
+       }
+       if (execvp(cpp_command,(char **) cpp_argv) < 0) {
+         /* prototype is weird */
+           perror(cpp_command);
+           exit(1);
+       }
+       /* not reached */
+    }
+    if (close(fds[1]) < 0) {
+       perror("close");
+       exit(1);
+    }
+    real_stdin = dup(0);
+    if (real_stdin < 0) {
+       perror("dup");
+       exit(1);
+    }
+    if (fd != -1 && close(fd) < 0) {
+       perror("close");
+       exit(1);
+    }
+    if (dup2(fds[0],0) < 0) {
+       perror("dup2");
+       exit(1);
+    }
+    for (arg = (char **) cpp_argv+1; *arg; arg++)
+       free(*arg);
+    free(cpp_argv);
+    cpp_argv = NULL;
+    cpp_argc = 0;
+}
+
+
+void run_cpp_on_file(const char *name)
+{
+    run_cpp(name,name ? -1 : 0,-1);
+    atexit(kill_cpp);
+}
+
+
+void run_cpp_on_string(const char *str)
+{
+    int fds[2];
+    pid_t pid;
+    int left,wrote;
+
+    if (pipe(fds) < 0) {
+        perror("pipe");
+        exit(1);
+    }
+    run_cpp(NULL,fds[0],fds[1]);
+    pid = fork();
+    if (pid < 0) {
+       perror("fork");
+       exit(1);
+    }
+    if (!pid) {
+       for (left = strlen(str); left; left -= wrote) {
+           wrote = write(fds[1],str,left);
+           if (wrote < 0)
+               break; /* die silently */
+           str += wrote;
+       }
+       exit(0);
+    }
+    if (close(fds[1]) < 0) {
+       perror("close");
+       exit(1);
+    }
+    atexit(kill_cpp);
+}
+
+
+void reap_cpp(void)
+{
+    int status;
+
+    cpp_pid = 0;
+    if (waitpid(cpp_pid,&status,0) < 0) {
+       perror("waitpid");
+       exit(1);
+    }
+    if (!status) {
+       if (dup2(real_stdin,0) < 0) {
+           perror("dup2");
+           exit(1);
+       }
+       return;
+    }
+    if (WIFEXITED(status))
+       exit(WEXITSTATUS(status));
+    if (WIFSIGNALED(status))
+       fprintf(stderr,"cpp terminated with signal %d\n",WTERMSIG(status));
+    else
+       fprintf(stderr,"cpp terminated with incomprehensible status %d\n",
+         status);
+    exit(1);
+}

Added: developers/werner/fped/cpp.h
===================================================================
--- developers/werner/fped/cpp.h                                (rev 0)
+++ developers/werner/fped/cpp.h        2009-07-28 19:50:12 UTC (rev 5331)
@@ -0,0 +1,26 @@
+/*
+ * cpp.h - CPP subprocess
+ *
+ * Written 2002, 2003, 2008 by Werner Almesberger
+ * Copyright 2002, 2003 Caltech Netlab FAST project
+ * Copyright 2008 by OpenMoko, Inc.
+ *
+ * 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 CPP_H
+#define CPP_H
+
+
+extern const char *cpp_command;
+
+void add_cpp_arg(const char *arg);
+void add_cpp_Wp(const char *arg);
+void run_cpp_on_file(const char *name); /* NULL for stdin */
+void run_cpp_on_string(const char *str);
+void reap_cpp(void);
+
+#endif /* CPP_H */

Modified: developers/werner/fped/fpd.y
===================================================================
--- developers/werner/fped/fpd.y        2009-07-28 19:07:11 UTC (rev 5330)
+++ developers/werner/fped/fpd.y        2009-07-28 19:50:12 UTC (rev 5331)
@@ -356,7 +356,7 @@
                        $$ = new_obj(ot_arc);
                        $$->base = $2;
                        $$->u.arc.start = $3;
-                       $$->u.arc.end = $3;
+                       $$->u.arc.end = $4 ? $4 : $3;
                }
        | TOK_FRAME ID base
                {

Modified: developers/werner/fped/fped.c
===================================================================
--- developers/werner/fped/fped.c       2009-07-28 19:07:11 UTC (rev 5330)
+++ developers/werner/fped/fped.c       2009-07-28 19:50:12 UTC (rev 5331)
@@ -11,13 +11,8 @@
  */
 
 
-#include <stdarg.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <fcntl.h>
 
-
+#include "cpp.h"
 #include "obj.h"
 #include "inst.h"
 #include "gui.h"
@@ -28,17 +23,7 @@
 
 static void load_file(const char *name)
 {
-       int fd;
-
-       fd = open(name, O_RDONLY);
-       if (fd < 0) {
-               perror(name);
-               exit(1);
-       }
-       if (dup2(fd, 0) < 0) {
-               perror("dup2");
-               exit(1);
-       }
+       run_cpp_on_file(name);
        (void) yyparse();
 }
 

Modified: developers/werner/fped/gui_canvas.c
===================================================================
--- developers/werner/fped/gui_canvas.c 2009-07-28 19:07:11 UTC (rev 5330)
+++ developers/werner/fped/gui_canvas.c 2009-07-28 19:50:12 UTC (rev 5331)
@@ -20,12 +20,15 @@
 #include "gui_style.h"
 #include "gui_status.h"
 #include "gui.h"
+#include "gui_canvas.h"
 
 
 static struct draw_ctx ctx;
+static struct coord curr_pos;
+static struct coord user_origin = { 0, 0 };
 
 
-/* ----- zoom display ------------------------------------------------------ */
+/* ----- status display ---------------------------------------------------- */
 
 
 static void update_zoom(void)
@@ -34,6 +37,15 @@
 }
 
 
+static void update_pos(struct coord pos)
+{
+       status_set_sys_pos("%5.2lf %5.2lf mm",
+           units_to_mm(pos.x), units_to_mm(pos.y));
+       status_set_user_pos("%5.2lf %5.2lf mm",
+           units_to_mm(pos.x-user_origin.x), units_to_mm(pos.y-user_origin.y));
+}
+
+
 /* ----- coordinate system ------------------------------------------------- */
 
 
@@ -106,10 +118,13 @@
 {
        struct coord pos = canvas_to_coord(&ctx, event->x, event->y);
 
+       curr_pos.x = event->x;
+       curr_pos.y = event->y;
        if (event->state & GDK_BUTTON1_MASK)
                drag_left(pos);
        if (event->state & GDK_BUTTON2_MASK)
                drag_middle(pos);
+       update_pos(pos);
        return TRUE;
 }
 
@@ -125,6 +140,7 @@
        switch (event->button) {
        case 1:
                /* select */ ;
+               break;
        case 2:
                ctx.center = pos;
                redraw();
@@ -137,7 +153,6 @@
 static gboolean button_release_event(GtkWidget *widget, GdkEventButton *event,
      gpointer data)
 {
-printf("R %d\n", event->button);
        return TRUE;
 }
 
@@ -195,6 +210,24 @@
 }
 
 
+/* ----- keys -------------------------------------------------------------- */
+
+
+static gboolean key_press_event(GtkWidget *widget, GdkEventKey *event,
+     gpointer data)
+{
+       struct coord pos = canvas_to_coord(&ctx, curr_pos.x, curr_pos.y);
+
+       switch (event->keyval) {
+       case ' ':
+               user_origin = pos;
+               update_pos(pos);
+               break;
+       }
+       return TRUE;
+}
+
+
 /* ----- expose event ------------------------------------------------------ */
 
 
@@ -216,6 +249,24 @@
 }
 
 
+/* ----- enter/leave ------------------------------------------------------- */
+
+
+static gboolean enter_notify_event(GtkWidget *widget, GdkEventCrossing *event,
+     gpointer data)
+{
+       gtk_widget_grab_focus(widget);
+       return TRUE;
+}
+
+
+static gboolean leave_notify_event(GtkWidget *widget, GdkEventCrossing *event,
+     gpointer data)
+{
+       return TRUE;
+}
+
+
 /* ----- canvas setup ------------------------------------------------------ */
 
 
@@ -239,11 +290,21 @@
        g_signal_connect(G_OBJECT(canvas), "scroll_event",
            G_CALLBACK(scroll_event), NULL);
 
+       GTK_WIDGET_SET_FLAGS(canvas, GTK_CAN_FOCUS);
+
+       g_signal_connect(G_OBJECT(canvas), "key_press_event",
+           G_CALLBACK(key_press_event), NULL);
+
        g_signal_connect(G_OBJECT(canvas), "expose_event",
            G_CALLBACK(expose_event), NULL);
+       g_signal_connect(G_OBJECT(canvas), "enter_notify_event",
+           G_CALLBACK(enter_notify_event), NULL);
+       g_signal_connect(G_OBJECT(canvas), "leave_notify_event",
+           G_CALLBACK(leave_notify_event), NULL);
 
        gtk_widget_set_events(canvas,
-           GDK_EXPOSE | GDK_LEAVE_NOTIFY_MASK |
+           GDK_EXPOSE | GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK |
+           GDK_KEY_PRESS_MASK |
            GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
            GDK_SCROLL |
            GDK_POINTER_MOTION_MASK);

Modified: developers/werner/fped/gui_inst.c
===================================================================
--- developers/werner/fped/gui_inst.c   2009-07-28 19:07:11 UTC (rev 5330)
+++ developers/werner/fped/gui_inst.c   2009-07-28 19:50:12 UTC (rev 5331)
@@ -56,7 +56,9 @@
 static void draw_arc(struct draw_ctx *ctx, GdkGC *gc, int fill,
     int x, int y, int r, double a1, double a2)
 {
-       gdk_draw_arc(DA, gc, fill, x-r, y-r, 2*r, 2*r, a1*64, a2*64);
+       if (a1 == a2)
+               a2 = a1+360;
+       gdk_draw_arc(DA, gc, fill, x-r, y-r, 2*r, 2*r, a1*64, (a2-a1)*64);
 }
 
 

Modified: developers/werner/fped/inst.c
===================================================================
--- developers/werner/fped/inst.c       2009-07-28 19:07:11 UTC (rev 5330)
+++ developers/werner/fped/inst.c       2009-07-28 19:50:12 UTC (rev 5331)
@@ -199,13 +199,13 @@
        double r, a1, a2;
 
        inst = add_inst(&arc_ops, center);
-       r =hypot(start.x-center.x, start.y-center.y);
+       r = hypot(start.x-center.x, start.y-center.y);
        a1 = atan2(start.y-center.y, start.x-center.x)/M_PI*180.0;
        a2 = atan2(end.y-center.y, end.x-center.x)/M_PI*180.0;
        if (a1 < 0)
                a1 += 360.0;
        if (a2 < 0)
-               a2 += 2*M_PI;
+               a2 += 360.0;
        inst->u.arc.r = r;
        inst->u.arc.a1 = a1;
        inst->u.arc.a2 = a2;

Modified: developers/werner/fped/qfn.fpd
===================================================================
--- developers/werner/fped/qfn.fpd      2009-07-28 19:07:11 UTC (rev 5330)
+++ developers/werner/fped/qfn.fpd      2009-07-28 19:50:12 UTC (rev 5331)
@@ -32,3 +32,6 @@
 r = .vec c 0mm, 0.5mm
 e = .vec c -0.5mm, 0mm
 .arc c r, e
+
+r2 = .vec c 0mm, 0.8mm
+.arc c r2




--- End Message ---
--- Begin Message ---
Author: werner
Date: 2009-07-28 23:50:48 +0200 (Tue, 28 Jul 2009)
New Revision: 5332

Modified:
   developers/werner/fped/Makefile
   developers/werner/fped/TODO
   developers/werner/fped/expr.c
   developers/werner/fped/expr.h
   developers/werner/fped/inst.c
   developers/werner/fped/obj.c
   developers/werner/fped/qfn.fpd
   developers/werner/fped/util.h
Log:
- added pad name expansion
- made build process less verbose (make V=1 turns on full output)



Modified: developers/werner/fped/Makefile
===================================================================
--- developers/werner/fped/Makefile     2009-07-28 19:50:12 UTC (rev 5331)
+++ developers/werner/fped/Makefile     2009-07-28 21:50:48 UTC (rev 5332)
@@ -26,6 +26,39 @@
 YACC=bison -y
 YYFLAGS=-v
 
+# ----- Verbosity control -----------------------------------------------------
+
+CPP := $(CPP)   # make sure changing CC won't affect CPP
+
+CC_normal      := $(CC)
+YACC_normal    := $(YACC)
+LEX_normal     := $(LEX)
+DEPEND_normal = \
+  $(CPP) $(CFLAGS) -MM -MG *.c >.depend || \
+  { rm -f .depend; exit 1; }
+
+CC_quiet       = @echo "  CC       " $@ && $(CC_normal)
+YACC_quiet     = @echo "  YACC     " $@ && $(YACC_normal)
+LEX_quiet      = @echo "  LEX      " $@ && $(LEX_normal)
+GEN_quiet      = @echo "  GENERATE " $@ &&
+DEPEND_quiet   = @echo "  DEPENDENCIES" && $(DEPEND_normal)
+
+ifeq ($(V),1)
+    CC         = $(CC_normal)
+    LEX                = $(LEX_normal)
+    YACC       = $(YACC_normal)
+    GEN                =
+    DEPEND     = $(DEPEND_normal)
+else
+    CC         = $(CC_quiet)
+    LEX                = $(LEX_quiet)
+    YACC       = $(YACC_quiet)
+    GEN                = $(GEN_quiet)
+    DEPEND     = $(DEPEND_quiet)
+endif
+
+# ----- Rules -----------------------------------------------------------------
+
 all:           fped
 
 fped:          $(OBJS)
@@ -46,8 +79,7 @@
 # ----- Dependencies ----------------------------------------------------------
 
 dep depend .depend: lex.yy.c y.tab.h y.tab.c
-               $(CPP) $(CFLAGS) -MM -MG *.c >.depend || \
-                 { rm -f .depend; exit 1; }
+               $(DEPEND)
 
 ifeq (.depend,$(wildcard .depend))
 include .depend

Modified: developers/werner/fped/TODO
===================================================================
--- developers/werner/fped/TODO 2009-07-28 19:50:12 UTC (rev 5331)
+++ developers/werner/fped/TODO 2009-07-28 21:50:48 UTC (rev 5332)
@@ -24,3 +24,4 @@
 - add KiCad output
 - add postscript output
 - add option to include/omit helper vecs and frames (display and postscript)
+- Q: how do we handle stacks of objects ?

Modified: developers/werner/fped/expr.c
===================================================================
--- developers/werner/fped/expr.c       2009-07-28 19:50:12 UTC (rev 5331)
+++ developers/werner/fped/expr.c       2009-07-28 21:50:48 UTC (rev 5332)
@@ -25,7 +25,7 @@
 }
 
 
-static double eval_var(const struct frame *frame, const char *name)
+double eval_var(const struct frame *frame, const char *name)
 {
        const struct table *table;
        const struct loop *loop;
@@ -131,11 +131,6 @@
 }
 
 
-double eval(const struct expr *expr, const struct frame *frame)
-{
-       return expr->op(expr, frame);
-}
-
 char *eval_str(const struct frame *frame, const struct expr *expr)
 {
        abort();

Modified: developers/werner/fped/expr.h
===================================================================
--- developers/werner/fped/expr.h       2009-07-28 19:50:12 UTC (rev 5331)
+++ developers/werner/fped/expr.h       2009-07-28 21:50:48 UTC (rev 5332)
@@ -52,6 +52,7 @@
 struct expr *new_op(op_type op);
 struct expr *binary_op(op_type op, struct expr *a, struct expr *b);
 
+double eval_var(const struct frame *frame, const char *name);
 char *eval_str(const struct frame *frame, const struct expr *expr);
 double eval_num(const struct expr *expr, const struct frame *frame);
 

Modified: developers/werner/fped/inst.c
===================================================================
--- developers/werner/fped/inst.c       2009-07-28 19:50:12 UTC (rev 5331)
+++ developers/werner/fped/inst.c       2009-07-28 21:50:48 UTC (rev 5332)
@@ -169,7 +169,7 @@
        struct inst *inst;
 
        inst = add_inst(&pad_ops, a);
-       inst->u.name = name;
+       inst->u.name = stralloc(name);
        update_bbox(&inst->bbox, b);
        propagate_bbox(inst);
        return 1;

Modified: developers/werner/fped/obj.c
===================================================================
--- developers/werner/fped/obj.c        2009-07-28 19:50:12 UTC (rev 5331)
+++ developers/werner/fped/obj.c        2009-07-28 21:50:48 UTC (rev 5332)
@@ -12,7 +12,10 @@
 
 
 #include <stdlib.h>
+#include <string.h>
 
+#include "util.h"
+#include "error.h"
 #include "expr.h"
 #include "obj.h"
 #include "inst.h"
@@ -25,12 +28,86 @@
     const struct frame *parent);
 
 
+static int is_id(char c, int first)
+{
+       if ((c >= 'A' && c <= 'Z') ||
+           (c >= 'a' && c <= 'z') ||
+           c == '_')
+               return 1;
+       if (first)
+               return 0;
+       return c >= '0' && c <= '9';
+}
+
+
+static char *expand(const char *name, const struct frame *frame)
+{
+       int len = strlen(name);
+       char *buf = alloc_size(len+1);
+       char num_buf[100]; /* enough :-) */
+       const char *s, *s0;
+       char *var;
+       const char *var_unique;
+       double value;
+       int i, value_len;
+
+       i = 0;
+       for (s = name; *s; s++) {
+               if (*s != '$') {
+                       buf[i++] = *s;
+                       continue;
+               }
+               s0 = ++s;
+               if (*s != '{') {
+                       while (is_id(*s, s == s0))
+                               s++;
+                       var = strnalloc(s0, s-s0);
+                       len -= s-s0+1;
+                       s--;
+               } else {
+                       s++;
+                       while (*s != '}') {
+                               if (!is_id(*s, s == s0+1))
+                                       goto invalid;
+                               s++;
+                       }
+                       var = strnalloc(s0+1, s-s0-1);
+                       len -= s-s0+2;
+               }
+               var_unique = unique(var);
+               free(var);
+               value = eval_var(frame, var_unique);
+               if (value == UNDEF) {
+                       fail("undefined variable \"%s\"", var_unique);
+                       goto fail;
+               }
+               value_len = snprintf(num_buf, sizeof(num_buf), "%lg", value);
+               len += value_len;
+               buf = realloc(buf, len);
+               if (!buf)
+                       abort();
+               strcpy(buf+i, num_buf);
+               i += value_len;
+       }
+       buf[i] = 0;
+       return buf;
+
+invalid:
+       fail("invalid character in variable name");
+fail:
+       free(buf);
+       return NULL;
+}
+
+
 static int generate_objects(struct frame *frame, struct coord base)
 {
        struct coord vec_base;
        struct vec *vec;
        struct obj *obj;
        double x, y;
+       char *name;
+       int res;
 
        for (vec = frame->vecs; vec; vec = vec->next) {
                x = eval_num(vec->x, frame);
@@ -64,9 +141,14 @@
                                return 0;
                        break;
                case ot_pad:
-                       if (!inst_pad(obj->u.pad.name,
+                       name = expand(obj->u.pad.name, frame);
+                       if (!name)
+                               return 0;
+                       res = inst_pad(name,
                            obj->base ? obj->base->pos : base,
-                           obj->u.pad.other ? obj->u.pad.other->pos : base))
+                           obj->u.pad.other ? obj->u.pad.other->pos : base);
+                       free(name);
+                       if (!res)
                                return 0;
                        break;
                case ot_arc:

Modified: developers/werner/fped/qfn.fpd
===================================================================
--- developers/werner/fped/qfn.fpd      2009-07-28 19:50:12 UTC (rev 5331)
+++ developers/werner/fped/qfn.fpd      2009-07-28 21:50:48 UTC (rev 5332)
@@ -1,9 +1,10 @@
-# http://www.nxp.com/acrobat/packages/footprint/SOT616-1_fp_reflow.pdf
+// http://www.nxp.com/acrobat/packages/footprint/SOT616-1_fp_reflow.pdf
 
 .frame pad_up {
        c = .vec @ -D/2, 0
        .vec . D, C
-       .pad "N/4+n" c .
+       pad = n+1
+       .pad "$pad" c .
 }
 
 N = 24
@@ -26,7 +27,7 @@
 .vec @ P*(n-(N/4-1)/2), -Ay/2
 .frame pad_up .
 
-# ARC, just for testing
+// ARC, just for testing
 
 c = .vec @ -1mm, 1mm
 r = .vec c 0mm, 0.5mm

Modified: developers/werner/fped/util.h
===================================================================
--- developers/werner/fped/util.h       2009-07-28 19:50:12 UTC (rev 5331)
+++ developers/werner/fped/util.h       2009-07-28 21:50:48 UTC (rev 5332)
@@ -18,12 +18,14 @@
 #include <string.h>
 
 
-#define alloc_type(t)                                  \
-    ({ t *alloc_type_tmp = (t *) malloc(sizeof(t));    \
-       if (!alloc_type_tmp)                            \
+#define alloc_size(s)                                  \
+    ({ void *alloc_size_tmp = malloc(s);               \
+       if (!alloc_size_tmp)                            \
                abort();                                \
-       alloc_type_tmp; })
+       alloc_size_tmp; })
 
+#define alloc_type(t) ((t *) alloc_size(sizeof(t)))
+
 #define zalloc_type(t)                                 \
     ({ t *zalloc_type_tmp = alloc_type(t);             \
        memset(zalloc_type_tmp, 0, sizeof(t));          \
@@ -35,6 +37,14 @@
                abort();                                \
        stralloc_tmp; })
 
+#define strnalloc(s, n)                                        \
+    ({ char *strnalloc_tmp = alloc_size((n)+1);        \
+       if (!strnalloc_tmp)                             \
+               abort();                                \
+       strncpy(strnalloc_tmp, (s), (n));               \
+       strnalloc_tmp[n] = 0;                           \
+       strnalloc_tmp; })
+
 const char *unique(const char *s);
 
 #endif /* !UTIL_H */




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

Reply via email to