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. r5335 - developers/werner/fped (wer...@docs.openmoko.org)
   2. r5336 - developers/werner/fped (wer...@docs.openmoko.org)
--- Begin Message ---
Author: werner
Date: 2009-07-29 12:59:02 +0200 (Wed, 29 Jul 2009)
New Revision: 5335

Modified:
   developers/werner/fped/TODO
   developers/werner/fped/coord.c
   developers/werner/fped/coord.h
   developers/werner/fped/error.c
   developers/werner/fped/error.h
   developers/werner/fped/expr.c
   developers/werner/fped/expr.h
   developers/werner/fped/fpd.l
   developers/werner/fped/fpd.y
   developers/werner/fped/fped.c
   developers/werner/fped/obj.c
   developers/werner/fped/obj.h
   developers/werner/fped/qfn.fpd
   developers/werner/fped/unparse.c
   developers/werner/fped/unparse.h
Log:
- units are now part of value and checked for conformity
- line number is now reported when expressions fail
- corrected line number counting for cpp "noise"



Modified: developers/werner/fped/TODO
===================================================================
--- developers/werner/fped/TODO 2009-07-29 03:31:56 UTC (rev 5334)
+++ developers/werner/fped/TODO 2009-07-29 10:59:02 UTC (rev 5335)
@@ -14,7 +14,6 @@
 - decide on table presentation
 - add table/var/loop editor
 - add incremental expression parser (for editor)
-- make units part of value and check for conformity
 - add default unit (combine with grid unit selection ?)
 - consider adding auto/mm/mil selection for each dimension
 - syntax seems a little cryptic. too many dots and at signs.

Modified: developers/werner/fped/coord.c
===================================================================
--- developers/werner/fped/coord.c      2009-07-29 03:31:56 UTC (rev 5334)
+++ developers/werner/fped/coord.c      2009-07-29 10:59:02 UTC (rev 5335)
@@ -16,6 +16,23 @@
 #include "coord.h"
 
 
+/* ----- unit conversion --------------------------------------------------- */
+
+
+double mm_to_mil(double mm, int exponent)
+{
+       return mm*pow(MIL_IN_MM, -exponent);
+}
+
+
+double mil_to_mm(double mil, int exponent)
+{
+        return mil*pow(MIL_IN_MM, exponent);
+}
+
+/* ----- vector operations ------------------------------------------------- */
+
+
 struct coord normalize(struct coord v, unit_type len)
 {
        double f;

Modified: developers/werner/fped/coord.h
===================================================================
--- developers/werner/fped/coord.h      2009-07-29 03:31:56 UTC (rev 5334)
+++ developers/werner/fped/coord.h      2009-07-29 10:59:02 UTC (rev 5335)
@@ -22,7 +22,9 @@
 #define        MM_UNITS        (1000.0*MICRON_UNITS)
 #define        KICAD_UNIT      (10.0*MIL_UNITS)
 
+#define        MIL_IN_MM       0.0254
 
+
 typedef int32_t unit_type;
 
 
@@ -58,6 +60,9 @@
 }
 
 
+double mm_to_mil(double mm, int exponent);
+double mil_to_mm(double mil, int exponent);
+
 struct coord normalize(struct coord v, unit_type len);
 struct coord rotate(struct coord v, double angle);
 struct coord add_vec(struct coord a, struct coord b);

Modified: developers/werner/fped/error.c
===================================================================
--- developers/werner/fped/error.c      2009-07-29 03:31:56 UTC (rev 5334)
+++ developers/werner/fped/error.c      2009-07-29 10:59:02 UTC (rev 5335)
@@ -50,6 +50,5 @@
        vfprintf(stderr, fmt, ap);
        va_end(ap);
        fprintf(stderr, "\n");
-       exit(1);
 }
 

Modified: developers/werner/fped/error.h
===================================================================
--- developers/werner/fped/error.h      2009-07-29 03:31:56 UTC (rev 5334)
+++ developers/werner/fped/error.h      2009-07-29 10:59:02 UTC (rev 5335)
@@ -21,6 +21,6 @@
 void __attribute__((noreturn)) yyerrorf(const char *fmt, ...);
 void __attribute__((noreturn)) yyerror(const char *s);
 
-void __attribute__((noreturn)) fail(const char *fmt, ...);
+void fail(const char *fmt, ...);
 
 #endif /* !ERROR_H */

Modified: developers/werner/fped/expr.c
===================================================================
--- developers/werner/fped/expr.c       2009-07-29 03:31:56 UTC (rev 5334)
+++ developers/werner/fped/expr.c       2009-07-29 10:59:02 UTC (rev 5335)
@@ -12,20 +12,102 @@
 
 
 #include <stdlib.h>
+#include <math.h>
 
 #include "util.h"
 #include "error.h"
 #include "obj.h"
+#include "unparse.h"
 #include "expr.h"
 
 
-double op_num(const struct expr *self, const struct frame *frame)
+struct num undef = { .type = nt_none };
+
+
+/* ----- error reporting --------------------------------------------------- */
+
+
+void fail_expr(const struct expr *expr)
 {
+       char *s;
+
+       s = unparse(expr);
+       fail("in \"%s\" at line %d", s, expr->lineno);
+       free(s);
+}
+
+
+/* ----- unit conversion --------------------------------------------------- */
+
+
+const char *str_unit(struct num n)
+{
+       if (n.exponent == 0)
+               return "";
+       if (n.type == nt_mm) {
+               switch (n.exponent) {
+               case -2:
+                       return "mm^-2";
+               case -1:
+                       return "mm^-1";
+               case 1:
+                       return "mm";
+               case 2:
+                       return "mm^2";
+               default:
+                       abort();
+               }
+       }
+       if (n.type == nt_mil) {
+               switch (n.exponent) {
+               case -2:
+                       return "mil^(-2)";
+               case -1:
+                       return "mil^(-1)";
+               case 1:
+                       return "mil";
+               case 2:
+                       return "mil^2";
+               default:
+                       abort();
+               }
+       }
+       abort();
+}
+
+
+int to_unit(struct num *n)
+{
+       if (!is_distance(*n)) {
+               fail("%s^%d is not a distance",
+                   n->type == nt_mm ? "mm" : n->type == nt_mil ? "mil" : "?",
+                   n->exponent);
+               return 0;
+       }
+       switch (n->type) {
+       case nt_mil:
+               n->n = mil_to_units(n->n);
+               break;
+       case nt_mm:
+               n->n = mm_to_units(n->n);
+               break;
+       default:
+               abort();
+       }
+       return 1;
+}
+
+
+/* ----- primary expressions ----------------------------------------------- */
+
+
+struct num op_num(const struct expr *self, const struct frame *frame)
+{
        return self->u.num;
 }
 
 
-double eval_var(const struct frame *frame, const char *name)
+struct num eval_var(const struct frame *frame, const char *name)
 {
        const struct table *table;
        const struct loop *loop;
@@ -42,71 +124,136 @@
        }
        for (loop = frame->loops; loop; loop = loop->next)
                if (loop->var == name)
-                       return loop->curr_value;
+                       return make_num(loop->curr_value);
        if (frame->curr_parent)
                return eval_var(frame->curr_parent, name);
-       return UNDEF;
+       return undef;
 }
 
 
-double op_var(const struct expr *self, const struct frame *frame)
+struct num op_var(const struct expr *self, const struct frame *frame)
 {
-       double res;
+       struct num res;
 
        res = eval_var(frame, self->u.var);
-       if (res == UNDEF)
+       if (is_undef(res))
                fail("undefined variable \"%s\"", self->u.var);
        return res;
 }
 
 
-double op_minus(const struct expr *self, const struct frame *frame)
+/* ----- arithmetic -------------------------------------------------------- */
+
+
+static struct num compatible_sum(struct num *a, struct num *b)
 {
-       double res;
+       struct num res;
 
+       if (a->type != b->type) {
+               if (a->type == nt_mil) {
+                       a->type = nt_mm;
+                       a->n = mil_to_mm(a->n, a->exponent);
+               }
+               if (b->type == nt_mil) {
+                       b->type = nt_mm;
+                       b->n = mil_to_mm(b->n, a->exponent);
+               }
+       }
+       if (a->exponent != b->exponent) {
+               fail("incompatible exponents (%d, %d)",
+                   a->exponent, b->exponent);
+               return undef;
+       }
+       res.type = a->type;
+       res.exponent = a->exponent;
+       return res;
+}
+
+
+static struct num compatible_mult(struct num *a, struct num *b,
+    int exponent)
+{
+       struct num res;
+
+       if (a->type != b->type) {
+               if (a->type == nt_mil) {
+                       a->type = nt_mm;
+                       a->n = mil_to_mm(a->n, a->exponent);
+               }
+               if (b->type == nt_mil) {
+                       b->type = nt_mm;
+                       b->n = mil_to_mm(b->n, b->exponent);
+               }
+       }
+       res.type = a->type;
+       res.exponent = exponent;
+       return res;
+}
+
+
+struct num op_minus(const struct expr *self, const struct frame *frame)
+{
+       struct num res;
+
        res = eval_num(self->u.op.a, frame);
-       return res == UNDEF ? UNDEF : -res;
+       if (!is_undef(res))
+               res.n = -res.n;
+       return res;
 }
 
 
-#define        BINARY                                  \
-       double a, b;                            \
-                                               \
-       a = eval_num(self->u.op.a, frame);      \
-       b = eval_num(self->u.op.b, frame);      \
-       if (a == UNDEF || b == UNDEF)           \
-               return UNDEF;                   \
+#define        BINARY                                          \
+       struct num a, b, res;                           \
+                                                       \
+       a = eval_num(self->u.op.a, frame);              \
+       if (is_undef(a))                                \
+               return undef;                           \
+       b = eval_num(self->u.op.b, frame);              \
+       if (is_undef(b))                                \
+               return undef;
 
 
-double op_add(const struct expr *self, const struct frame *frame)
+struct num op_add(const struct expr *self, const struct frame *frame)
 {
        BINARY;
-       return a+b;
+       res = compatible_sum(&a, &b);
+       if (is_undef(res))
+               return undef;
+       res.n = a.n+b.n;
+       return res;
 }
 
 
-double op_sub(const struct expr *self, const struct frame *frame)
+struct num op_sub(const struct expr *self, const struct frame *frame)
 {
        BINARY;
-       return a-b;
+       res = compatible_sum(&a, &b);
+       if (is_undef(res))
+               return undef;
+       res.n = a.n-b.n;
+       return res;
 }
 
 
-double op_mult(const struct expr *self, const struct frame *frame)
+struct num op_mult(const struct expr *self, const struct frame *frame)
 {
        BINARY;
-       return a*b;
+       res = compatible_mult(&a, &b, a.exponent+b.exponent);
+       res.n = a.n*b.n;
+       return res;
 }
 
 
-double op_div(const struct expr *self, const struct frame *frame)
+struct num op_div(const struct expr *self, const struct frame *frame)
 {
        BINARY;
-       if (!b) {
+       if (!b.n) {
                fail("Division by zero");
-               return UNDEF;
+               return undef;
        }
-       return a/b;
+       res = compatible_mult(&a, &b, a.exponent-b.exponent);
+       res.n = a.n/b.n;
+       return res;
 }
 
 
@@ -116,6 +263,7 @@
 
        expr = alloc_type(struct expr);
        expr->op = op;
+       expr->lineno = lineno;
        return expr;
 }
 
@@ -137,7 +285,7 @@
 }
 
 
-double eval_num(const struct expr *expr, const struct frame *frame)
+struct num eval_num(const struct expr *expr, const struct frame *frame)
 {
        return expr->op(expr, frame);
 }

Modified: developers/werner/fped/expr.h
===================================================================
--- developers/werner/fped/expr.h       2009-07-29 03:31:56 UTC (rev 5334)
+++ developers/werner/fped/expr.h       2009-07-29 10:59:02 UTC (rev 5335)
@@ -23,37 +23,79 @@
 struct frame;
 struct expr;
 
+enum num_type {
+       nt_none,
+       nt_mm,
+       nt_mil,
+};
 
-typedef double (*op_type)(const struct expr *self, const struct frame *frame);
+struct num {
+       enum num_type type;
+       int exponent;
+       double n;
+};
 
+typedef struct num (*op_type)(const struct expr *self,
+    const struct frame *frame);
+
 struct expr {
        op_type op;
        union {
-               double num;
+               struct num num;
                const char *var;
                struct {
                        struct expr *a;
                        struct expr *b;
                } op;
        } u;
+       int lineno;
 };
 
 
-double op_num(const struct expr *self, const struct frame *frame);
-double op_var(const struct expr *self, const struct frame *frame);
+struct num undef;
 
-double op_minus(const struct expr *self, const struct frame *frame);
 
-double op_add(const struct expr *self, const struct frame *frame);
-double op_sub(const struct expr *self, const struct frame *frame);
-double op_mult(const struct expr *self, const struct frame *frame);
-double op_div(const struct expr *self, const struct frame *frame);
+#define        is_undef(num)           ((num).type == nt_none)
+#define        is_dimensionless(num)   (!(num).exponent)
 
+
+static inline int is_distance(struct num num)
+{
+       return (num.type == nt_mm || num.type == nt_mil) && num.exponent == 1;
+}
+
+
+void fail_expr(const struct expr *expr);
+
+const char *str_unit(struct num n);
+
+static inline struct num make_num(double n)
+{
+       struct num res;
+
+       res.type = nt_mm;
+       res.exponent = 0;
+       res.n = n;
+       return res;
+}
+
+int to_unit(struct num *n);
+
+struct num op_num(const struct expr *self, const struct frame *frame);
+struct num op_var(const struct expr *self, const struct frame *frame);
+
+struct num op_minus(const struct expr *self, const struct frame *frame);
+
+struct num op_add(const struct expr *self, const struct frame *frame);
+struct num op_sub(const struct expr *self, const struct frame *frame);
+struct num op_mult(const struct expr *self, const struct frame *frame);
+struct num op_div(const struct expr *self, const struct frame *frame);
+
 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);
+struct num 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);
+struct num eval_num(const struct expr *expr, const struct frame *frame);
 
 #endif /* !EXPR_H */

Modified: developers/werner/fped/fpd.l
===================================================================
--- developers/werner/fped/fpd.l        2009-07-29 03:31:56 UTC (rev 5334)
+++ developers/werner/fped/fpd.l        2009-07-29 10:59:02 UTC (rev 5335)
@@ -12,8 +12,11 @@
  */
 
 
+#include <stdlib.h>
+
 #include "util.h"
 #include "coord.h"
+#include "expr.h"
 #include "error.h"
 
 #include "y.tab.h"
@@ -39,13 +42,17 @@
 [a-zA-Z_][a-zA-Z_0-9]*         { yylval.id = unique(yytext);
                                  return ID; }
 
-{NUM}{SP}mm                    { sscanf(yytext, "%lf", &yylval.num);
-                                 yylval.num = mm_to_units(yylval.num);
+{NUM}{SP}mm                    { yylval.num.type = nt_mm;
+                                 yylval.num.exponent = 1;
+                                 sscanf(yytext, "%lf", &yylval.num.n);
                                  return NUMBER; }
-{NUM}{SP}mil                   { sscanf(yytext, "%lf", &yylval.num);
-                                 yylval.num = mil_to_units(yylval.num);
+{NUM}{SP}mil                   { yylval.num.type = nt_mil;
+                                 yylval.num.exponent = 1;
+                                 sscanf(yytext, "%lf", &yylval.num.n);
                                  return NUMBER; }
-{NUM}                          { sscanf(yytext, "%lf", &yylval.num);
+{NUM}                          { yylval.num.type = nt_mm; /* mm or mil */
+                                 yylval.num.exponent = 0;
+                                 sscanf(yytext, "%lf", &yylval.num.n);
                                  return NUMBER; }
 
 \"(\\[^\n\t]|[^\\"\n\t])*\"    { *strrchr(yytext, '"') = 0;
@@ -54,6 +61,7 @@
 
 {SP}                           ;
 \n                             lineno++;
-^#.*\n                         lineno++;
 
+^#\ [0-9]+\ \"[^"]*\"(\ [0-9]+)*\n lineno = strtol(yytext+2, NULL, 0);
+
 .                              return *yytext;

Modified: developers/werner/fped/fpd.y
===================================================================
--- developers/werner/fped/fpd.y        2009-07-29 03:31:56 UTC (rev 5334)
+++ developers/werner/fped/fpd.y        2009-07-29 10:59:02 UTC (rev 5335)
@@ -107,7 +107,7 @@
 
 
 %union {
-       double num;
+       struct num num;
        char *str;
        const char *id;
        struct expr *expr;

Modified: developers/werner/fped/fped.c
===================================================================
--- developers/werner/fped/fped.c       2009-07-29 03:31:56 UTC (rev 5334)
+++ developers/werner/fped/fped.c       2009-07-29 10:59:02 UTC (rev 5335)
@@ -40,7 +40,8 @@
                argc--;
                argv++;
        }
-       instantiate();
+       if (!instantiate())
+               return 1;
        inst_debug();
        error = gui_main(argc, argv);
        if (error)

Modified: developers/werner/fped/obj.c
===================================================================
--- developers/werner/fped/obj.c        2009-07-29 03:31:56 UTC (rev 5334)
+++ developers/werner/fped/obj.c        2009-07-29 10:59:02 UTC (rev 5335)
@@ -17,8 +17,8 @@
 #include "util.h"
 #include "error.h"
 #include "expr.h"
+#include "inst.h"
 #include "obj.h"
-#include "inst.h"
 
 
 struct frame *frames = NULL;
@@ -48,7 +48,7 @@
        const char *s, *s0;
        char *var;
        const char *var_unique;
-       double value;
+       struct num value;
        int i, value_len;
 
        i = 0;
@@ -77,11 +77,12 @@
                var_unique = unique(var);
                free(var);
                value = eval_var(frame, var_unique);
-               if (value == UNDEF) {
+               if (is_undef(value)) {
                        fail("undefined variable \"%s\"", var_unique);
                        goto fail;
                }
-               value_len = snprintf(num_buf, sizeof(num_buf), "%lg", value);
+               value_len = snprintf(num_buf, sizeof(num_buf), "%lg%s",
+                   value.n, str_unit(value));
                len += value_len;
                buf = realloc(buf, len);
                if (!buf)
@@ -105,21 +106,25 @@
        struct coord vec_base;
        struct vec *vec;
        struct obj *obj;
-       double x, y;
+       struct num x, y;
        char *name;
        int res;
 
        for (vec = frame->vecs; vec; vec = vec->next) {
                x = eval_num(vec->x, frame);
-               if (x == UNDEF)
+               if (is_undef(x) || !to_unit(&x)) {
+                       fail_expr(vec->x);
                        return 0;
+               }
                y = eval_num(vec->y, frame);
-               if (y == UNDEF)
+               if (is_undef(y) || !to_unit(&y)) {
+                       fail_expr(vec->y);
                        return 0;
+               }
                vec_base = vec->base ? vec->base->pos : base;
                vec->pos = vec_base;
-               vec->pos.x += x;
-               vec->pos.y += y;
+               vec->pos.x += x.n;
+               vec->pos.y += y.n;
                if (!inst_vec(vec, vec_base))
                        return 0;
        }
@@ -167,17 +172,31 @@
 static int run_loops(struct frame *frame, struct loop *loop,
     struct coord base)
 {
-       double from, to;
+       struct num from, to;
 
        if (!loop)
                return generate_objects(frame, base);
        from = eval_num(loop->from, frame);
-       if (from == UNDEF)
+       if (is_undef(from)) {
+               fail_expr(loop->from);
                return 0;
+       }
+       if (!is_dimensionless(from)) {
+               fail("incompatible type for start value");
+               fail_expr(loop->from);
+               return 0;
+       }
        to = eval_num(loop->to, frame);
-       if (from == UNDEF)
+       if (is_undef(to)) {
+               fail_expr(loop->to);
                return 0;
-       for (loop->curr_value = from; loop->curr_value <= to;
+       }
+       if (!is_dimensionless(to)) {
+               fail("incompatible type for end value");
+               fail_expr(loop->to);
+               return 0;
+       }
+       for (loop->curr_value = from.n; loop->curr_value <= to.n;
            loop->curr_value += 1)
                if (!run_loops(frame, loop->next, base))
                        return 0;
@@ -214,10 +233,10 @@
 }
 
 
-void instantiate(void)
+int instantiate(void)
 {
        struct coord zero = { 0, 0 };
 
        inst_reset();
-       generate_frame(frames, zero, NULL);
+       return generate_frame(frames, zero, NULL);
 }

Modified: developers/werner/fped/obj.h
===================================================================
--- developers/werner/fped/obj.h        2009-07-29 03:31:56 UTC (rev 5334)
+++ developers/werner/fped/obj.h        2009-07-29 10:59:02 UTC (rev 5335)
@@ -115,6 +115,6 @@
 struct frame *frames;
 
 
-void instantiate(void);
+int instantiate(void);
 
 #endif /* !OBJ_H */

Modified: developers/werner/fped/qfn.fpd
===================================================================
--- developers/werner/fped/qfn.fpd      2009-07-29 03:31:56 UTC (rev 5334)
+++ developers/werner/fped/qfn.fpd      2009-07-29 10:59:02 UTC (rev 5335)
@@ -1,7 +1,7 @@
 // http://www.nxp.com/acrobat/packages/footprint/SOT616-1_fp_reflow.pdf
 
 .frame pad_up {
-       c = .vec @ -D/2, 0
+       c = .vec @ -D/2, 0mm
        .vec . D, C
        pad = n+1
        .pad "$pad" c .

Modified: developers/werner/fped/unparse.c
===================================================================
--- developers/werner/fped/unparse.c    2009-07-29 03:31:56 UTC (rev 5334)
+++ developers/werner/fped/unparse.c    2009-07-29 10:59:02 UTC (rev 5335)
@@ -81,7 +81,8 @@
                return buf;
        }
        if (expr->op == op_num) {
-               snprintf(tmp, sizeof(tmp), "%lg", expr->u.num);
+               snprintf(tmp, sizeof(tmp), "%lg%s",
+                   expr->u.num.n, str_unit(expr->u.num));
                return stralloc(tmp);
        }
        if (expr->op == op_var)

Modified: developers/werner/fped/unparse.h
===================================================================
--- developers/werner/fped/unparse.h    2009-07-29 03:31:56 UTC (rev 5334)
+++ developers/werner/fped/unparse.h    2009-07-29 10:59:02 UTC (rev 5335)
@@ -1,3 +1,16 @@
+/*
+ * unparse.h - Dump an expression tree into a string
+ *
+ * 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 UNPARSE_H
 #define UNPARSE_H
 




--- End Message ---
--- Begin Message ---
Author: werner
Date: 2009-07-29 20:59:26 +0200 (Wed, 29 Jul 2009)
New Revision: 5336

Added:
   developers/werner/fped/gui_util.c
   developers/werner/fped/gui_util.h
Modified:
   developers/werner/fped/Makefile
   developers/werner/fped/fped.c
   developers/werner/fped/gui.c
   developers/werner/fped/gui.h
   developers/werner/fped/gui_status.c
   developers/werner/fped/gui_style.c
   developers/werner/fped/gui_style.h
   developers/werner/fped/qfn.fpd
Log:
- slight Makefile cleanup
- cleaned up variable display (on-going)



Modified: developers/werner/fped/Makefile
===================================================================
--- developers/werner/fped/Makefile     2009-07-29 10:59:02 UTC (rev 5335)
+++ developers/werner/fped/Makefile     2009-07-29 18:59:26 UTC (rev 5336)
@@ -13,7 +13,7 @@
 OBJS = fped.o expr.o coord.o obj.o inst.o util.o error.o \
        unparse.o \
        cpp.o lex.yy.o y.tab.o \
-       gui.o gui_style.o gui_inst.o gui_status.o gui_canvas.o
+       gui.o gui_util.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`
@@ -60,6 +60,8 @@
 
 # ----- Rules -----------------------------------------------------------------
 
+.PHONY:                all dep depend clean
+
 all:           fped
 
 fped:          $(OBJS)
@@ -89,4 +91,4 @@
 # ----- Cleanup ---------------------------------------------------------------
 
 clean:
-               rm -f $(OBJS) lex.yy.c y.tab.c y.tab.h y.output
+               rm -f $(OBJS) lex.yy.c y.tab.c y.tab.h y.output .depend

Modified: developers/werner/fped/fped.c
===================================================================
--- developers/werner/fped/fped.c       2009-07-29 10:59:02 UTC (rev 5335)
+++ developers/werner/fped/fped.c       2009-07-29 18:59:26 UTC (rev 5336)
@@ -42,7 +42,7 @@
        }
        if (!instantiate())
                return 1;
-       inst_debug();
+//     inst_debug();
        error = gui_main(argc, argv);
        if (error)
                return error;

Modified: developers/werner/fped/gui.c
===================================================================
--- developers/werner/fped/gui.c        2009-07-29 10:59:02 UTC (rev 5335)
+++ developers/werner/fped/gui.c        2009-07-29 18:59:26 UTC (rev 5336)
@@ -17,11 +17,17 @@
 
 #include "obj.h"
 #include "unparse.h"
+#include "gui_util.h"
 #include "gui_status.h"
 #include "gui_canvas.h"
 #include "gui.h"
 
 
+GtkWidget *root;
+
+static GtkWidget *vars_box;
+
+
 static void make_menu_bar(GtkWidget *vbox)
 {
        GtkWidget *bar;
@@ -80,6 +86,30 @@
 }
 
 
+static void build_assignment(GtkWidget *vbox, struct frame *frame,
+     struct table *table)
+{
+       GtkWidget *hbox;
+       char *expr;
+
+       if (!table->vars || table->vars->next)
+               return;
+       if (!table->rows || table->rows->next)
+               return;
+
+       hbox = gtk_hbox_new(FALSE, 0);
+       gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
+       gtk_box_pack_start(GTK_BOX(hbox), gtk_label_new(table->vars->name),
+           FALSE, FALSE, 0);
+       gtk_box_pack_start(GTK_BOX(hbox), gtk_label_new(" = "),
+           FALSE, FALSE, 0);
+       expr = unparse(table->rows->values->expr);
+       gtk_box_pack_start(GTK_BOX(hbox), gtk_label_new(expr),
+           FALSE, FALSE, 0);
+       free(expr);
+}
+
+
 static void build_table(GtkWidget *vbox, struct frame *frame,
      struct table *table)
 {
@@ -95,15 +125,20 @@
        for (row = table->rows; row; row = row->next)
                n_rows++;
 
+       if (n_vars == 1 && n_rows == 1)
+               return;
+
        tab = gtk_table_new(n_rows+1, n_vars, FALSE);
+//     gtk_misc_set_alignment(GTK_MISC(tab), 0, 0);
        gtk_table_set_row_spacings(GTK_TABLE(tab), 1);
        gtk_table_set_col_spacings(GTK_TABLE(tab), 1);
        gtk_box_pack_start(GTK_BOX(vbox), tab, FALSE, FALSE, 0);
 
        n_vars = 0;
        for (var = table->vars; var; var = var->next) {
-               field = gtk_label_new(var->name);
-               gtk_table_attach_defaults(GTK_TABLE(tab), field,
+               field = label_in_box_new(var->name);
+               label_in_box_bg(field, "pink");
+               gtk_table_attach_defaults(GTK_TABLE(tab), box_of_label(field),
                    n_vars, n_vars+1, 0, 1);
                n_vars++;
        }
@@ -112,9 +147,10 @@
                n_vars = 0;
                for (value = row->values; value; value = value->next) {
                        expr = unparse(value->expr);
-                       field = gtk_label_new(expr);
+                       field = label_in_box_new(expr);
                        free(expr);
-                       gtk_table_attach_defaults(GTK_TABLE(tab), field,
+                       gtk_table_attach_defaults(GTK_TABLE(tab),
+                           box_of_label(field),
                            n_vars, n_vars+1,
                            n_rows+1, n_rows+2);
                        n_vars++;
@@ -127,8 +163,25 @@
 static void build_loop(GtkWidget *vbox, struct frame *frame,
      struct loop *loop)
 {
-       gtk_box_pack_start(GTK_BOX(vbox), gtk_label_new(loop->var),
+       GtkWidget *hbox;
+       char *expr;
+
+       hbox = gtk_hbox_new(FALSE, 0);
+       gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
+       gtk_box_pack_start(GTK_BOX(hbox), gtk_label_new(loop->var),
            FALSE, FALSE, 0);
+       gtk_box_pack_start(GTK_BOX(hbox), gtk_label_new(" = "),
+           FALSE, FALSE, 0);
+       expr = unparse(loop->from);
+       gtk_box_pack_start(GTK_BOX(hbox), gtk_label_new(expr),
+           FALSE, FALSE, 0);
+       free(expr);
+       gtk_box_pack_start(GTK_BOX(hbox), gtk_label_new(" ... "),
+           FALSE, FALSE, 0);
+       expr = unparse(loop->to);
+       gtk_box_pack_start(GTK_BOX(hbox), gtk_label_new(expr),
+           FALSE, FALSE, 0);
+       free(expr);
 }
 
 
@@ -137,20 +190,23 @@
        struct table *table;
        struct loop *loop;
 
+       destroy_all_children(GTK_CONTAINER(vbox));
        for (table = frame->tables; table; table = table->next) {
                add_sep(vbox, 3);
+               build_assignment(vbox, frame, table);
                build_table(vbox, frame, table);
        }
        for (loop = frame->loops; loop; loop = loop->next) {
                add_sep(vbox, 3);
                build_loop(vbox, frame, loop);
        }
+       gtk_widget_show_all(vbox);
 }
 
 
 static void make_center_area(GtkWidget *vbox)
 {
-       GtkWidget *hbox, *vars, *paned, *v2box;
+       GtkWidget *hbox, *vars, *paned;
        GtkWidget *frame_list;
        GtkTreeSelection *sel;
 
@@ -178,23 +234,26 @@
 
        vars = gtk_scrolled_window_new(NULL, NULL);
        gtk_paned_add1(GTK_PANED(paned), vars);
-       gtk_widget_set_size_request(vars, 100, 100);
-       v2box = gtk_vbox_new(FALSE, 0);
-       gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(vars), v2box);
-       build_vars(v2box, frames);
+       gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(vars),
+           GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+       gtk_widget_set_size_request(vars, 150, 100);
+       vars_box = gtk_vbox_new(FALSE, 0);
 
+       gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(vars),
+           vars_box);
+
        /* Canvas */
 
        gtk_paned_add2(GTK_PANED(paned), make_canvas());
 }
 
 
-static void make_screen(GtkWidget *root)
+static void make_screen(GtkWidget *window)
 {
        GtkWidget *vbox;
 
        vbox = gtk_vbox_new(FALSE, 0);
-       gtk_container_add(GTK_CONTAINER(root), vbox);
+       gtk_container_add(GTK_CONTAINER(window), vbox);
 
        make_menu_bar(vbox);
        make_center_area(vbox);
@@ -211,20 +270,23 @@
 
 int gui_main(int argc, char **argv)
 {
-       GtkWidget *root;
-
        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_title(GTK_WINDOW(root), "fped");
 
+       /* get root->window */
+       gtk_widget_show_all(root);
+
        g_signal_connect_swapped(G_OBJECT(root), "destroy",
            G_CALLBACK(gtk_main_quit), NULL);
 
        make_screen(root);
+       build_vars(vars_box, frames);
 
        gtk_widget_show_all(root);
 
+
        gtk_main();
 
        return 0;

Modified: developers/werner/fped/gui.h
===================================================================
--- developers/werner/fped/gui.h        2009-07-29 10:59:02 UTC (rev 5335)
+++ developers/werner/fped/gui.h        2009-07-29 18:59:26 UTC (rev 5336)
@@ -17,6 +17,8 @@
 #include <gtk/gtk.h>
 
 
+extern GtkWidget *root;
+
 int gui_init(int *argc, char ***argv);
 int gui_main(int argc, char **argv);
 

Modified: developers/werner/fped/gui_status.c
===================================================================
--- developers/werner/fped/gui_status.c 2009-07-29 10:59:02 UTC (rev 5335)
+++ developers/werner/fped/gui_status.c 2009-07-29 18:59:26 UTC (rev 5336)
@@ -15,6 +15,7 @@
 #include <stdio.h>
 #include <gtk/gtk.h>
 
+#include "gui_util.h"
 #include "gui_status.h"
 
 
@@ -68,10 +69,11 @@
        v2box = gtk_vbox_new(FALSE, 0);
        gtk_box_pack_start(GTK_BOX(hbox), v2box, TRUE, TRUE, 1);
 
-       status_name = gtk_label_new("<name>");
-       gtk_box_pack_start(GTK_BOX(v2box), status_name, FALSE, FALSE, 1);
-       /* @@@ how to make label fill the space on the right - add a hbox ? */
-//     gtk_label_set_justify(GTK_LABEL(status_name), GTK_JUSTIFY_LEFT);
+       status_name = label_in_box_new("<name>");
+       gtk_box_pack_start(GTK_BOX(v2box), box_of_label(status_name),
+           FALSE, FALSE, 1);
+
+       gtk_misc_set_alignment(GTK_MISC(status_name), 0, 0);
        gtk_label_set_selectable(GTK_LABEL(status_name), TRUE);
 
        status_entry = gtk_entry_new();

Modified: developers/werner/fped/gui_style.c
===================================================================
--- developers/werner/fped/gui_style.c  2009-07-29 10:59:02 UTC (rev 5335)
+++ developers/werner/fped/gui_style.c  2009-07-29 18:59:26 UTC (rev 5336)
@@ -11,54 +11,38 @@
  */
 
 
-#include <stdlib.h>
 #include <gtk/gtk.h>
 
+#include "gui_util.h"
+#include "gui.h"
 #include "gui_style.h"
 
 
-#define        GC(spec)        gc(drawable, (spec))
-
-
-static GdkColor get_color(GdkColormap *cmap, const char *spec)
+static GdkGC *gc(const char *spec)
 {
-       GdkColor color;
-
-       if (!gdk_color_parse(spec, &color))
-               abort();
-       if (!gdk_colormap_alloc_color(cmap, &color, FALSE, TRUE))
-               abort();
-       return color;
-}
-
-
-static GdkGC *gc(GdkDrawable *drawable, const char *spec)
-{
        GdkGCValues gc_values = {
-               .background = get_color(gdk_drawable_get_colormap(drawable),
-                   "black"),
-               .foreground = get_color(gdk_drawable_get_colormap(drawable),
-                   spec),
+               .background = get_color("black"),
+               .foreground = get_color(spec),
        };
 
-       return gdk_gc_new_with_values(drawable, &gc_values,
+       return gdk_gc_new_with_values(root->window, &gc_values,
             GDK_GC_FOREGROUND | GDK_GC_BACKGROUND);
 }
 
 
 void gui_setup_style(GdkDrawable *drawable)
 {
-       gc_bg = GC("#000000");
-       gc_vec_bg = GC("#ffff00");
-       gc_vec_fg = GC("#ffff00");
-       gc_line_bg = GC("#ffffff");
-       gc_line_fg = GC("#ffffff");
+       gc_bg = gc("#000000");
+       gc_vec_bg = gc("#ffff00");
+       gc_vec_fg = gc("#ffff00");
+       gc_line_bg = gc("#ffffff");
+       gc_line_fg = gc("#ffffff");
        gc_rect_bg = gc_line_bg;
        gc_rect_fg = gc_line_fg;
-       gc_pad_bg = GC("#ff0000");
-       gc_pad_fg = GC("#ff0000");
+       gc_pad_bg = gc("#ff0000");
+       gc_pad_fg = gc("#ff0000");
        gc_arc_bg = gc_line_bg;
        gc_arc_fg = gc_line_fg;
-       gc_frame_bg = GC("#00ff00");
-       gc_frame_fg = GC("#00ff00");
+       gc_frame_bg = gc("#00ff00");
+       gc_frame_fg = gc("#00ff00");
 }

Modified: developers/werner/fped/gui_style.h
===================================================================
--- developers/werner/fped/gui_style.h  2009-07-29 10:59:02 UTC (rev 5335)
+++ developers/werner/fped/gui_style.h  2009-07-29 18:59:26 UTC (rev 5336)
@@ -14,6 +14,9 @@
 #ifndef GUI_STYLE_H
 #define        GUI_STYLE_H
 
+#include <gtk/gtk.h>
+
+
 #define        CANVAS_CLEARANCE        10
 
 #define        VEC_ARROW_LEN           10
@@ -33,6 +36,7 @@
 GdkGC *gc_arc_bg, *gc_arc_fg;
 GdkGC *gc_frame_bg, *gc_frame_fg;
 
+
 void gui_setup_style(GdkDrawable *drawable);
 
 #endif /* !GUI_STYLE_H */

Added: developers/werner/fped/gui_util.c
===================================================================
--- developers/werner/fped/gui_util.c                           (rev 0)
+++ developers/werner/fped/gui_util.c   2009-07-29 18:59:26 UTC (rev 5336)
@@ -0,0 +1,72 @@
+/*
+ * gui_util.c - GUI helper functions
+ *
+ * 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 <gtk/gtk.h>
+
+#include "gui.h"
+#include "gui_util.h"
+
+
+GdkColor get_color(const char *spec)
+{
+       GdkColormap *cmap;
+       GdkColor color;
+
+       cmap = gdk_drawable_get_colormap(root->window);
+       if (!gdk_color_parse(spec, &color))
+               abort();
+       if (!gdk_colormap_alloc_color(cmap, &color, FALSE, TRUE))
+               abort();
+       return color;
+}
+
+
+GtkWidget *label_in_box_new(const char *s)
+{
+       GtkWidget *evbox, *label;
+
+       evbox = gtk_event_box_new();
+       label = gtk_label_new(s);
+       gtk_misc_set_padding(GTK_MISC(label), 1, 1);
+       gtk_container_add(GTK_CONTAINER(evbox), label);
+       return label;
+}
+
+
+GtkWidget *box_of_label(GtkWidget *label)
+{
+       return gtk_widget_get_ancestor(label, GTK_TYPE_EVENT_BOX);
+}
+
+
+void label_in_box_bg(GtkWidget *label, const char *color)
+{
+       GtkWidget *box;
+       GdkColor col = get_color(color);
+
+       box = box_of_label(label);
+       gtk_widget_modify_bg(box, GTK_STATE_NORMAL, &col);
+}
+
+
+static void destroy_callback(GtkWidget *widget, gpointer data)
+{
+       gtk_widget_destroy(widget);
+}
+
+
+void destroy_all_children(GtkContainer *container)
+{
+       gtk_container_foreach(container, destroy_callback, NULL);
+}

Added: developers/werner/fped/gui_util.h
===================================================================
--- developers/werner/fped/gui_util.h                           (rev 0)
+++ developers/werner/fped/gui_util.h   2009-07-29 18:59:26 UTC (rev 5336)
@@ -0,0 +1,26 @@
+/*
+ * gui_util.h - GUI helper functions
+ *
+ * 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 GUI_UTIL_H
+#define        GUI_UTIL_H
+
+#include <gtk/gtk.h>
+
+
+GdkColor get_color(const char *spec);
+GtkWidget *label_in_box_new(const char *s);
+GtkWidget *box_of_label(GtkWidget *label);
+void label_in_box_bg(GtkWidget *box, const char *color);
+void destroy_all_children(GtkContainer *container);
+
+#endif /* !GUI_UTIL_H */

Modified: developers/werner/fped/qfn.fpd
===================================================================
--- developers/werner/fped/qfn.fpd      2009-07-29 10:59:02 UTC (rev 5335)
+++ developers/werner/fped/qfn.fpd      2009-07-29 18:59:26 UTC (rev 5336)
@@ -1,4 +1,11 @@
-// http://www.nxp.com/acrobat/packages/footprint/SOT616-1_fp_reflow.pdf
+/*
+ * Example of a QFN package (and general construction site to experiment with
+ * fped features during development)
+ *
+ * Everything you see here is likely to change sooner or later.
+ */
+ * http://www.nxp.com/acrobat/packages/footprint/SOT616-1_fp_reflow.pdf
+ */
 
 .frame pad_up {
        c = .vec @ -D/2, 0mm
@@ -9,6 +16,12 @@
 
 N = 24
 
+/*
+ * Note that this table is not a great example because it contains lots of
+ * fields we don't really need for iterations. But it's useful for driving
+ * the GUI to extremes.
+ */
+
 .table
     { 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,




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

Reply via email to