1
0
mirror of git://projects.qi-hardware.com/fped.git synced 2024-11-22 17:24:03 +02:00

More work on measurements. Getting there ...

- removed support for old-style measurements
- new-style measurements are now embedded in "struct obj", so we can dump and 
  delete them
- "measxy" is now called "meas"
- updated examples to use new-style measurements



git-svn-id: http://svn.openmoko.org/trunk/eda/fped@5412 99fdad57-331a-0410-800a-d7fa5415bdb3
This commit is contained in:
werner 2009-08-09 00:06:54 +00:00
parent 851c82af6f
commit 4a0fd61016
19 changed files with 107 additions and 105 deletions

9
README
View File

@ -202,6 +202,8 @@ pad "1" @ .
Measurements Measurements
- - - - - - - - - - - -
*** This is obsolete - see the section on new-style mesurements at the end. ***
Measurements show the distance between two points: Measurements show the distance between two points:
meas <point-a> <point-b> <offset> meas <point-a> <point-b> <offset>
@ -439,16 +441,15 @@ New-style measurements are placed in the root frame after all other
items. items.
Known issues: Known issues:
- they are currently not dumped and they can't be entered or edited - they currently can't be edited through the GUI
through the GUI - tie-breaking heuristics don't always do what one expects
-
Syntax: Syntax:
<type> [<label>] <from> <op> <to> [<offset>] <type> [<label>] <from> <op> <to> [<offset>]
Types: Types:
- measxy: measure diagonally - meas: measure diagonally
- measx: measure along the X axis - measx: measure along the X axis
- measy: measure along the y axis - measy: measure along the y axis

9
TODO
View File

@ -1,4 +1,4 @@
Missing features: Major missing features:
- populate input area (still needed: mm/mil, rezoom) - populate input area (still needed: mm/mil, rezoom)
- add default unit (combine with grid unit selection ?) - add default unit (combine with grid unit selection ?)
- consider adding auto/mm/mil selection for each dimension - consider adding auto/mm/mil selection for each dimension
@ -6,7 +6,10 @@ Missing features:
non-trivial endpoints, e.g., some vector in last iteration of loop) non-trivial endpoints, e.g., some vector in last iteration of loop)
- add KiCad output - add KiCad output
- add postscript output - add postscript output
- add option to include/omit helper vecs and frames (display and postscript) - add option to include/omit helper vecs and frames (done for display, still
need postscript)
Minor missing features:
- reorder frames (can use text editor) - reorder frames (can use text editor)
- reorder rows in a table (can use text editor) - reorder rows in a table (can use text editor)
- reorder columns in a table - reorder columns in a table
@ -17,6 +20,8 @@ Error detection:
Style: Style:
- make column of entry field greedily consume all unallocated space - make column of entry field greedily consume all unallocated space
- make menu bar consume all unallocated space instead of sharing it evenly with
upper toolbar
- status area looks awful - status area looks awful
- add button with GTK_STOCK_UNDELETE for "undelete" to menu bar - add button with GTK_STOCK_UNDELETE for "undelete" to menu bar
- edit names/values/etc. in place if possible - edit names/values/etc. in place if possible

View File

@ -124,6 +124,7 @@ static int obj_has_ref(const struct obj *obj, const struct vec *ref)
case ot_arc: case ot_arc:
return obj->u.arc.start == ref || obj->u.arc.end == ref; return obj->u.arc.start == ref || obj->u.arc.end == ref;
case ot_meas: case ot_meas:
return obj->u.meas.high == ref;
default: default:
abort(); abort();
} }
@ -203,6 +204,7 @@ static void destroy_obj(struct obj *obj)
free_expr(obj->u.arc.width); free_expr(obj->u.arc.width);
break; break;
case ot_meas: case ot_meas:
if (obj->u.meas.offset)
free_expr(obj->u.meas.offset); free_expr(obj->u.meas.offset);
break; break;
default: default:

40
dump.c
View File

@ -201,9 +201,7 @@ static int may_dump_obj_now(const struct obj *obj, const struct vec *prev)
l |= later(obj->u.arc.end, prev); l |= later(obj->u.arc.end, prev);
break; break;
case ot_meas: case ot_meas:
n |= need(obj->u.meas.other, prev); return 0;
l |= later(obj->u.meas.other, prev);
break;
default: default:
abort(); abort();
} }
@ -212,6 +210,21 @@ static int may_dump_obj_now(const struct obj *obj, const struct vec *prev)
} }
static const char *meas_type_name[mt_n] = {
"meas", "measx", "measy",
"meas", "measx", "measy",
};
static void print_meas_base(FILE *file, struct vec *base)
{
if (base->frame != root_frame)
fprintf(file, "%s.", base->frame->name);
fprintf(file, "%s", base->name);
}
static void dump_obj(FILE *file, struct obj *obj, const char *indent, static void dump_obj(FILE *file, struct obj *obj, const char *indent,
const struct vec *prev) const struct vec *prev)
{ {
@ -262,11 +275,22 @@ static void dump_obj(FILE *file, struct obj *obj, const char *indent,
free(s3); free(s3);
break; break;
case ot_meas: case ot_meas:
s1 = obj_base_name(obj->u.meas.other, prev); fprintf(file, "%s%s ", indent,
s2 = unparse(obj->u.meas.offset); meas_type_name[obj->u.meas.type]);
fprintf(file, "%smeas %s %s %s\n", indent, base, s1, s2); if (obj->u.meas.label)
fprintf(file, "\"%s\" ", obj->u.meas.label);
print_meas_base(file, obj->base);
fprintf(file, " %s ",
obj->u.meas.type < 3 ? obj->u.meas.inverted ? "<-" : "->" :
obj->u.meas.inverted ? "<<" : ">>");
print_meas_base(file, obj->u.meas.high);
if (!obj->u.meas.offset)
fprintf(file, "\n");
else {
s1 = unparse(obj->u.meas.offset);
fprintf(file, " %s\n", s1);
free(s1); free(s1);
free(s2); }
break; break;
default: default:
abort(); abort();
@ -340,7 +364,7 @@ static void dump_frame(FILE *file, const struct frame *frame,
obj->dumped = 0; obj->dumped = 0;
dump_vecs(file, frame->vecs, indent); dump_vecs(file, frame->vecs, indent);
/* duh. do we need this ? */ /* do we need this for anything but measurements ? */
for (obj = frame->objs; obj; obj = obj->next) for (obj = frame->objs; obj; obj = obj->next)
dump_obj(file, obj, indent, NULL); dump_obj(file, obj, indent, NULL);
} }

2
fpd.l
View File

@ -95,8 +95,6 @@ SP [\t ]*
return TOK_ARC; } return TOK_ARC; }
<INITIAL>"meas" { BEGIN(NOKEYWORD); <INITIAL>"meas" { BEGIN(NOKEYWORD);
return TOK_MEAS; } return TOK_MEAS; }
<INITIAL>"measxy" { BEGIN(NOKEYWORD);
return TOK_MEASXY; }
<INITIAL>"measx" { BEGIN(NOKEYWORD); <INITIAL>"measx" { BEGIN(NOKEYWORD);
return TOK_MEASX; } return TOK_MEASX; }
<INITIAL>"measy" { BEGIN(NOKEYWORD); <INITIAL>"measy" { BEGIN(NOKEYWORD);

44
fpd.y
View File

@ -141,7 +141,6 @@ static struct obj *new_obj(enum obj_type type)
struct value *value; struct value *value;
struct vec *vec; struct vec *vec;
struct obj *obj; struct obj *obj;
struct meas *meas;
enum meas_type mt; enum meas_type mt;
struct { struct {
int inverted; int inverted;
@ -153,7 +152,7 @@ static struct obj *new_obj(enum obj_type type)
%token START_FPD START_EXPR %token START_FPD START_EXPR
%token TOK_SET TOK_LOOP TOK_PART TOK_FRAME TOK_TABLE TOK_VEC %token TOK_SET TOK_LOOP TOK_PART TOK_FRAME TOK_TABLE TOK_VEC
%token TOK_PAD TOK_RECT TOK_LINE TOK_CIRC TOK_ARC %token TOK_PAD TOK_RECT TOK_LINE TOK_CIRC TOK_ARC
%token TOK_MEAS TOK_MEASXY TOK_MEASX TOK_MEASY %token TOK_MEAS TOK_MEASX TOK_MEASY
%token TOK_NEXT TOK_NEXT_INVERTED TOK_MAX TOK_MAX_INVERTED %token TOK_NEXT TOK_NEXT_INVERTED TOK_MAX TOK_MAX_INVERTED
%token <num> NUMBER %token <num> NUMBER
@ -165,9 +164,8 @@ static struct obj *new_obj(enum obj_type type)
%type <row> rows %type <row> rows
%type <value> row value %type <value> row value
%type <vec> vec base qbase %type <vec> vec base qbase
%type <obj> obj %type <obj> obj meas
%type <expr> expr opt_expr add_expr mult_expr unary_expr primary_expr %type <expr> expr opt_expr add_expr mult_expr unary_expr primary_expr
%type <meas> measurements meas
%type <str> opt_string %type <str> opt_string
%type <mt> meas_type %type <mt> meas_type
%type <mo> meas_op %type <mo> meas_op
@ -246,9 +244,6 @@ frame_def:
frame_items: frame_items:
measurements measurements
{
measurements = $1;
}
| frame_item frame_items | frame_item frame_items
; ;
@ -455,13 +450,6 @@ obj:
$$->u.arc.end = $4; $$->u.arc.end = $4;
$$->u.arc.width = $5; $$->u.arc.width = $5;
} }
| TOK_MEAS base base expr
{
$$ = new_obj(ot_meas);
$$->base = $2;
$$->u.meas.other = $3;
$$->u.meas.offset = $4;
}
| TOK_FRAME ID | TOK_FRAME ID
{ {
$<num>$.n = lineno; $<num>$.n = lineno;
@ -482,26 +470,26 @@ obj:
; ;
measurements: measurements:
| measurements meas
{ {
$$ = NULL; *next_obj = $2;
} next_obj = &$2->next;
| meas measurements
{
$$ = $1;
$$->next = $2;
} }
; ;
meas: meas:
meas_type opt_string qbase meas_op qbase opt_expr meas_type opt_string qbase meas_op qbase opt_expr
{ {
$$ = alloc_type(struct meas); struct meas *meas;
$$->type = $4.max ? $1+3 : $1;
$$->label = $2; $$ = new_obj(ot_meas);
$$->low = $3; meas = &$$->u.meas;
$$->inverted = $4.inverted; meas->type = $4.max ? $1+3 : $1;
$$->high = $5; meas->label = $2;
$$->offset = $6; $$->base = $3;
meas->inverted = $4.inverted;
meas->high = $5;
meas->offset = $6;
$$->next = NULL; $$->next = NULL;
} }
; ;
@ -529,7 +517,7 @@ qbase:
; ;
meas_type: meas_type:
TOK_MEASXY TOK_MEAS
{ {
$$ = mt_xy_next; $$ = mt_xy_next;
} }

View File

@ -358,15 +358,14 @@ void gui_draw_meas(struct inst *self)
struct coord a0, b0, a1, b1, off, c, d; struct coord a0, b0, a1, b1, off, c, d;
GdkGC *gc; GdkGC *gc;
double len; double len;
const char *label = self->u.meas.meas ? const struct meas *meas = &self->obj->u.meas;
self->u.meas.meas->label ? self->u.meas.meas->label : "" : "";
char *s; char *s;
a0 = translate(self->base); a0 = translate(self->base);
b0 = translate(self->u.meas.end); b0 = translate(self->u.meas.end);
a1 = self->base; a1 = self->base;
b1 = self->u.meas.end; b1 = self->u.meas.end;
switch (self->u.meas.meas ? self->u.meas.meas->type : mt_xy_next) { switch (meas->type) {
case mt_xy_next: case mt_xy_next:
case mt_xy_max: case mt_xy_max:
break; break;
@ -394,7 +393,7 @@ void gui_draw_meas(struct inst *self)
c = add_vec(a1, b1); c = add_vec(a1, b1);
d = sub_vec(b1, a1); d = sub_vec(b1, a1);
s = stralloc_printf("%s%lgmm", label, len); s = stralloc_printf("%s%lgmm", meas->label ? meas->label : "", len);
render_text(DA, gc, c.x/2, c.y/2, -atan2(d.y, d.x)/M_PI*180, s, render_text(DA, gc, c.x/2, c.y/2, -atan2(d.y, d.x)/M_PI*180, s,
MEAS_FONT, 0.5, -MEAS_BASELINE_OFFSET, MEAS_FONT, 0.5, -MEAS_BASELINE_OFFSET,
dist_point(a1, b1)-1.5*MEAS_ARROW_LEN, 0); dist_point(a1, b1)-1.5*MEAS_ARROW_LEN, 0);

View File

@ -256,12 +256,15 @@ static void begin_drag_new_meas(struct inst *inst)
static int end_new_meas(struct inst *from, struct inst *to) static int end_new_meas(struct inst *from, struct inst *to)
{ {
struct obj *obj;
struct meas *meas; struct meas *meas;
meas_inst = NULL; meas_inst = NULL;
if (from == to) if (from == to)
return 0; return 0;
meas = alloc_type(struct meas); /* it's safe to pass "from" here, but we may change it later */
obj = new_obj(ot_meas, from);
meas = &obj->u.meas;
meas->label = NULL; meas->label = NULL;
switch (mode) { switch (mode) {
case min_to_next_or_max: case min_to_next_or_max:
@ -270,17 +273,17 @@ static int end_new_meas(struct inst *from, struct inst *to)
} else { } else {
meas->type = meas_dsc->type+3; meas->type = meas_dsc->type+3;
} }
meas->low = from->vec; obj->base = from->vec;
meas->high = to->vec; meas->high = to->vec;
break; break;
case next_to_min: case next_to_min:
meas->type = meas_dsc->type; meas->type = meas_dsc->type;
meas->low = to->vec; obj->base = to->vec;
meas->high = from->vec; meas->high = from->vec;
break; break;
case max_to_min: case max_to_min:
meas->type = meas_dsc->type+3; meas->type = meas_dsc->type+3;
meas->low = to->vec; obj->base = to->vec;
meas->high = from->vec; meas->high = from->vec;
break; break;
default: default:
@ -296,9 +299,7 @@ char *st[] = { "nxy", "nx", "ny", "mxy", "mx", "my" };
fprintf(stderr, "mode %s type %s, inverted %d\n", fprintf(stderr, "mode %s type %s, inverted %d\n",
sm[mode], st[meas->type], meas->inverted); sm[mode], st[meas->type], meas->inverted);
} }
meas->offset = parse_expr("0mm"); meas->offset = NULL;
meas->next = measurements;
measurements = meas;
meas_dsc = NULL; meas_dsc = NULL;
return 1; return 1;
} }

View File

@ -81,7 +81,7 @@ static struct vec *new_vec(struct inst *base)
} }
static struct obj *new_obj(enum obj_type type, struct inst *base) struct obj *new_obj(enum obj_type type, struct inst *base)
{ {
struct obj *obj, **walk; struct obj *obj, **walk;

View File

@ -59,6 +59,7 @@ void tool_redraw(void);
* compilation unit. * compilation unit.
*/ */
struct obj *new_obj(enum obj_type type, struct inst *base);
struct pix_buf *draw_move_line_common(struct inst *inst, struct pix_buf *draw_move_line_common(struct inst *inst,
struct coord end, struct coord pos, int i); struct coord end, struct coord pos, int i);
struct pix_buf *drag_new_line(struct inst *from, struct coord to); struct pix_buf *drag_new_line(struct inst *from, struct coord to);

10
inst.c
View File

@ -677,10 +677,8 @@ static int meas_op_anchors(struct inst *inst, struct vec ***anchors)
{ {
struct obj *obj = inst->obj; struct obj *obj = inst->obj;
if (!inst->obj)
return 0; /* @@@ new-style measurements */
anchors[0] = &obj->base; anchors[0] = &obj->base;
anchors[1] = &obj->u.meas.other; anchors[1] = &obj->u.meas.high;
return 2; return 2;
} }
@ -695,7 +693,7 @@ static struct inst_ops meas_ops = {
}; };
int inst_meas(struct obj *obj, struct meas *meas, int inst_meas(struct obj *obj,
struct coord from, struct coord to, unit_type offset) struct coord from, struct coord to, unit_type offset)
{ {
struct inst *inst; struct inst *inst;
@ -704,9 +702,7 @@ int inst_meas(struct obj *obj, struct meas *meas,
inst->obj = obj; inst->obj = obj;
inst->u.meas.end = to; inst->u.meas.end = to;
inst->u.meas.offset = offset; inst->u.meas.offset = offset;
inst->u.meas.meas = meas; inst->active = 1; /* measurements are always active */
if (!obj)
inst->active = 1; /* @@@ new-style measurements */
/* @@@ our bbox is actually a bit more complex than this */ /* @@@ our bbox is actually a bit more complex than this */
update_bbox(&inst->bbox, to); update_bbox(&inst->bbox, to);
propagate_bbox(inst); propagate_bbox(inst);

5
inst.h
View File

@ -70,7 +70,6 @@ struct inst {
struct { struct {
struct coord end; struct coord end;
double offset; double offset;
struct meas *meas; /* new-style measurement */
} meas; } meas;
} u; } u;
struct inst *next; struct inst *next;
@ -96,8 +95,8 @@ int inst_rect(struct obj *obj, struct coord a, struct coord b, unit_type width);
int inst_pad(struct obj *obj, const char *name, struct coord a, struct coord b); int inst_pad(struct obj *obj, const char *name, struct coord a, struct coord b);
int inst_arc(struct obj *obj, struct coord center, struct coord start, int inst_arc(struct obj *obj, struct coord center, struct coord start,
struct coord stop, unit_type width); struct coord stop, unit_type width);
int inst_meas(struct obj *obj, struct meas *meas, int inst_meas(struct obj *obj, struct coord from, struct coord to,
struct coord from, struct coord to, unit_type offset); unit_type offset);
void inst_begin_active(int active); void inst_begin_active(int active);
void inst_end_active(void); void inst_end_active(void);

16
meas.c
View File

@ -28,8 +28,6 @@ struct sample {
struct sample *next; struct sample *next;
}; };
struct meas *measurements = NULL;
static void reset_samples(struct sample **samples) static void reset_samples(struct sample **samples)
{ {
@ -210,17 +208,21 @@ struct coord meas_find_max(lt_op_type lt, const struct sample *s)
int instantiate_meas(void) int instantiate_meas(void)
{ {
struct meas *meas; struct obj *obj;
const struct meas *meas;
struct coord a0, b0; struct coord a0, b0;
lt_op_type lt; lt_op_type lt;
struct num offset; struct num offset;
for (meas = measurements; meas; meas = meas->next) { for (obj = root_frame->objs; obj; obj = obj->next) {
if (!meas->low->samples || !meas->high->samples) if (obj->type != ot_meas)
continue; continue;
meas = &obj->u.meas;
if (!obj->base->samples || !meas->high->samples)
return 1;
lt = lt_op[meas->type]; lt = lt_op[meas->type];
a0 = meas_find_min(lt, meas->low->samples); a0 = meas_find_min(lt, obj->base->samples);
if (is_next[meas->type]) if (is_next[meas->type])
b0 = meas_find_next(lt, meas->high->samples, a0); b0 = meas_find_next(lt, meas->high->samples, a0);
else else
@ -233,7 +235,7 @@ int instantiate_meas(void)
if (is_undef(offset)) if (is_undef(offset))
return 0; return 0;
} }
inst_meas(NULL, meas, inst_meas(obj,
meas->inverted ? b0 : a0, meas->inverted ? a0 : b0, meas->inverted ? b0 : a0, meas->inverted ? a0 : b0,
offset.n); offset.n);
} }

View File

@ -11,14 +11,14 @@ C: vec @(0mm, 4mm)
/* /*
* If we measure (x, y), y trumps x * If we measure (x, y), y trumps x
*/ */
measxy "A -> B = " A -> B 0.2mm meas "A -> B = " A -> B 0.2mm
measxy "A <- B = " A <- B 0.5mm meas "A <- B = " A <- B 0.5mm
measxy "A >> B = " A >> B 1.5mm meas "A >> B = " A >> B 1.5mm
measx "x(A -> B) = " A -> B -0.5mm measx "x(A -> B) = " A -> B -0.5mm
measx "x(A >> B) = " A >> B -1mm measx "x(A >> B) = " A >> B -1mm
measy "y(A -> B) = " A -> B -2mm measy "y(A -> B) = " A -> B -2mm
measy "y(A >> B) = " A >> B -4.5mm measy "y(A >> B) = " A >> B -4.5mm
measxy "B -> C = " B -> C 0.5mm meas "B -> C = " B -> C 0.5mm

12
meas.h
View File

@ -14,11 +14,15 @@
#ifndef MEAS_H #ifndef MEAS_H
#define MEAS_H #define MEAS_H
#include "obj.h"
#include "coord.h"
#include "expr.h"
typedef int (*lt_op_type)(struct coord a, struct coord b); typedef int (*lt_op_type)(struct coord a, struct coord b);
struct vec;
struct obj;
struct meas { struct meas {
enum meas_type { enum meas_type {
@ -32,18 +36,14 @@ struct meas {
} type; } type;
char *label; /* or NULL */ char *label; /* or NULL */
int inverted; int inverted;
struct vec *low; /* low is obj->base */
struct vec *high; struct vec *high;
struct expr *offset; struct expr *offset;
struct meas *next;
}; };
struct sample; struct sample;
extern struct meas *measurements;
int lt_x(struct coord a, struct coord b); int lt_x(struct coord a, struct coord b);
int lt_y(struct coord a, struct coord b); int lt_y(struct coord a, struct coord b);
int lt_xy(struct coord a, struct coord b); int lt_xy(struct coord a, struct coord b);

10
obj.c
View File

@ -92,7 +92,7 @@ static int generate_objs(struct frame *frame, struct coord base, int active)
struct obj *obj; struct obj *obj;
char *name; char *name;
int ok; int ok;
struct num width, offset; struct num width;
for (obj = frame->objs; obj; obj = obj->next) for (obj = frame->objs; obj; obj = obj->next)
switch (obj->type) { switch (obj->type) {
@ -145,14 +145,6 @@ static int generate_objs(struct frame *frame, struct coord base, int active)
return 0; return 0;
break; break;
case ot_meas: case ot_meas:
offset = eval_unit(obj->u.meas.offset, frame);
if (is_undef(offset))
return 0;
if (!inst_meas(obj, NULL,
obj->base ? obj->base->pos : base,
obj->u.meas.other ? obj->u.meas.other->pos : base,
offset.n))
return 0;
break; break;
default: default:
abort(); abort();

8
obj.h
View File

@ -19,6 +19,7 @@
#include "expr.h" #include "expr.h"
#include "coord.h" #include "coord.h"
#include "meas.h"
struct var { struct var {
@ -152,11 +153,6 @@ struct arc {
struct expr *width; struct expr *width;
}; };
struct old_meas {
struct vec *other; /* NULL if frame origin */
struct expr *offset;
};
struct obj { struct obj {
enum obj_type type; enum obj_type type;
union { union {
@ -165,7 +161,7 @@ struct obj {
struct rect line; struct rect line;
struct pad pad; struct pad pad;
struct arc arc; struct arc arc;
struct old_meas meas; struct meas meas;
} u; } u;
struct frame *frame; struct frame *frame;
struct vec *base; struct vec *base;

View File

@ -9,9 +9,7 @@
frame pad_up { frame pad_up {
c: vec @(-D/2, 0mm) c: vec @(-D/2, 0mm)
vec .(0mm, C) o: vec c(D, C)
meas c . 0.2mm
vec c(D, C)
set pad = n+1 set pad = n+1
pad "$pad" c . pad "$pad" c .
} }
@ -71,3 +69,5 @@ x1 = 1+2*3
x2 = (1+2)*3 x2 = (1+2)*3
x3 = 1-(2+3) x3 = 1-(2+3)
*/ */
measy pad_up.c -> pad_up.o 0.2mm

View File

@ -5,8 +5,6 @@ frame pad {
se: vec sw(Px, 0mm) se: vec sw(Px, 0mm)
nw: vec sw(0mm, Py) nw: vec sw(0mm, Py)
pad "$pad" se nw pad "$pad" se nw
// meas sw se -0.1mm
// meas sw nw 0.1mm
} }
frame pad_ne { frame pad_ne {