1
0
mirror of git://projects.qi-hardware.com/fped.git synced 2024-06-30 21:57:39 +03: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
- - - - - -
*** This is obsolete - see the section on new-style mesurements at the end. ***
Measurements show the distance between two points:
meas <point-a> <point-b> <offset>
@ -439,16 +441,15 @@ New-style measurements are placed in the root frame after all other
items.
Known issues:
- they are currently not dumped and they can't be entered or edited
through the GUI
-
- they currently can't be edited through the GUI
- tie-breaking heuristics don't always do what one expects
Syntax:
<type> [<label>] <from> <op> <to> [<offset>]
Types:
- measxy: measure diagonally
- meas: measure diagonally
- measx: measure along the X 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)
- add default unit (combine with grid unit selection ?)
- 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)
- add KiCad 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 rows in a table (can use text editor)
- reorder columns in a table
@ -17,6 +20,8 @@ Error detection:
Style:
- 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
- add button with GTK_STOCK_UNDELETE for "undelete" to menu bar
- 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:
return obj->u.arc.start == ref || obj->u.arc.end == ref;
case ot_meas:
return obj->u.meas.high == ref;
default:
abort();
}
@ -203,7 +204,8 @@ static void destroy_obj(struct obj *obj)
free_expr(obj->u.arc.width);
break;
case ot_meas:
free_expr(obj->u.meas.offset);
if (obj->u.meas.offset)
free_expr(obj->u.meas.offset);
break;
default:
abort();

42
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);
break;
case ot_meas:
n |= need(obj->u.meas.other, prev);
l |= later(obj->u.meas.other, prev);
break;
return 0;
default:
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,
const struct vec *prev)
{
@ -262,11 +275,22 @@ static void dump_obj(FILE *file, struct obj *obj, const char *indent,
free(s3);
break;
case ot_meas:
s1 = obj_base_name(obj->u.meas.other, prev);
s2 = unparse(obj->u.meas.offset);
fprintf(file, "%smeas %s %s %s\n", indent, base, s1, s2);
free(s1);
free(s2);
fprintf(file, "%s%s ", indent,
meas_type_name[obj->u.meas.type]);
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);
}
break;
default:
abort();
@ -340,7 +364,7 @@ static void dump_frame(FILE *file, const struct frame *frame,
obj->dumped = 0;
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)
dump_obj(file, obj, indent, NULL);
}

2
fpd.l
View File

@ -95,8 +95,6 @@ SP [\t ]*
return TOK_ARC; }
<INITIAL>"meas" { BEGIN(NOKEYWORD);
return TOK_MEAS; }
<INITIAL>"measxy" { BEGIN(NOKEYWORD);
return TOK_MEASXY; }
<INITIAL>"measx" { BEGIN(NOKEYWORD);
return TOK_MEASX; }
<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 vec *vec;
struct obj *obj;
struct meas *meas;
enum meas_type mt;
struct {
int inverted;
@ -153,7 +152,7 @@ static struct obj *new_obj(enum obj_type type)
%token START_FPD START_EXPR
%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_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 <num> NUMBER
@ -165,9 +164,8 @@ static struct obj *new_obj(enum obj_type type)
%type <row> rows
%type <value> row value
%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 <meas> measurements meas
%type <str> opt_string
%type <mt> meas_type
%type <mo> meas_op
@ -246,9 +244,6 @@ frame_def:
frame_items:
measurements
{
measurements = $1;
}
| frame_item frame_items
;
@ -455,13 +450,6 @@ obj:
$$->u.arc.end = $4;
$$->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
{
$<num>$.n = lineno;
@ -482,26 +470,26 @@ obj:
;
measurements:
| measurements meas
{
$$ = NULL;
}
| meas measurements
{
$$ = $1;
$$->next = $2;
*next_obj = $2;
next_obj = &$2->next;
}
;
meas:
meas_type opt_string qbase meas_op qbase opt_expr
{
$$ = alloc_type(struct meas);
$$->type = $4.max ? $1+3 : $1;
$$->label = $2;
$$->low = $3;
$$->inverted = $4.inverted;
$$->high = $5;
$$->offset = $6;
struct meas *meas;
$$ = new_obj(ot_meas);
meas = &$$->u.meas;
meas->type = $4.max ? $1+3 : $1;
meas->label = $2;
$$->base = $3;
meas->inverted = $4.inverted;
meas->high = $5;
meas->offset = $6;
$$->next = NULL;
}
;
@ -529,7 +517,7 @@ qbase:
;
meas_type:
TOK_MEASXY
TOK_MEAS
{
$$ = 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;
GdkGC *gc;
double len;
const char *label = self->u.meas.meas ?
self->u.meas.meas->label ? self->u.meas.meas->label : "" : "";
const struct meas *meas = &self->obj->u.meas;
char *s;
a0 = translate(self->base);
b0 = translate(self->u.meas.end);
a1 = self->base;
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_max:
break;
@ -394,7 +393,7 @@ void gui_draw_meas(struct inst *self)
c = add_vec(a1, b1);
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,
MEAS_FONT, 0.5, -MEAS_BASELINE_OFFSET,
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)
{
struct obj *obj;
struct meas *meas;
meas_inst = NULL;
if (from == to)
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;
switch (mode) {
case min_to_next_or_max:
@ -270,17 +273,17 @@ static int end_new_meas(struct inst *from, struct inst *to)
} else {
meas->type = meas_dsc->type+3;
}
meas->low = from->vec;
obj->base = from->vec;
meas->high = to->vec;
break;
case next_to_min:
meas->type = meas_dsc->type;
meas->low = to->vec;
obj->base = to->vec;
meas->high = from->vec;
break;
case max_to_min:
meas->type = meas_dsc->type+3;
meas->low = to->vec;
obj->base = to->vec;
meas->high = from->vec;
break;
default:
@ -296,9 +299,7 @@ char *st[] = { "nxy", "nx", "ny", "mxy", "mx", "my" };
fprintf(stderr, "mode %s type %s, inverted %d\n",
sm[mode], st[meas->type], meas->inverted);
}
meas->offset = parse_expr("0mm");
meas->next = measurements;
measurements = meas;
meas->offset = NULL;
meas_dsc = NULL;
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;

View File

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

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;
if (!inst->obj)
return 0; /* @@@ new-style measurements */
anchors[0] = &obj->base;
anchors[1] = &obj->u.meas.other;
anchors[1] = &obj->u.meas.high;
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 inst *inst;
@ -704,9 +702,7 @@ int inst_meas(struct obj *obj, struct meas *meas,
inst->obj = obj;
inst->u.meas.end = to;
inst->u.meas.offset = offset;
inst->u.meas.meas = meas;
if (!obj)
inst->active = 1; /* @@@ new-style measurements */
inst->active = 1; /* measurements are always active */
/* @@@ our bbox is actually a bit more complex than this */
update_bbox(&inst->bbox, to);
propagate_bbox(inst);

5
inst.h
View File

@ -70,7 +70,6 @@ struct inst {
struct {
struct coord end;
double offset;
struct meas *meas; /* new-style measurement */
} meas;
} u;
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_arc(struct obj *obj, struct coord center, struct coord start,
struct coord stop, unit_type width);
int inst_meas(struct obj *obj, struct meas *meas,
struct coord from, struct coord to, unit_type offset);
int inst_meas(struct obj *obj, struct coord from, struct coord to,
unit_type offset);
void inst_begin_active(int active);
void inst_end_active(void);

16
meas.c
View File

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

View File

@ -11,14 +11,14 @@ C: vec @(0mm, 4mm)
/*
* If we measure (x, y), y trumps x
*/
measxy "A -> B = " A -> B 0.2mm
measxy "A <- B = " A <- B 0.5mm
meas "A -> B = " A -> B 0.2mm
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 -1mm
measy "y(A -> B) = " A -> B -2mm
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
#define MEAS_H
#include "obj.h"
#include "coord.h"
#include "expr.h"
typedef int (*lt_op_type)(struct coord a, struct coord b);
struct vec;
struct obj;
struct meas {
enum meas_type {
@ -32,18 +36,14 @@ struct meas {
} type;
char *label; /* or NULL */
int inverted;
struct vec *low;
/* low is obj->base */
struct vec *high;
struct expr *offset;
struct meas *next;
};
struct sample;
extern struct meas *measurements;
int lt_x(struct coord a, struct coord b);
int lt_y(struct coord a, struct coord b);
int lt_xy(struct coord a, struct coord b);

10
obj.c
View File

@ -92,7 +92,7 @@ static int generate_objs(struct frame *frame, struct coord base, int active)
struct obj *obj;
char *name;
int ok;
struct num width, offset;
struct num width;
for (obj = frame->objs; obj; obj = obj->next)
switch (obj->type) {
@ -145,14 +145,6 @@ static int generate_objs(struct frame *frame, struct coord base, int active)
return 0;
break;
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;
default:
abort();

8
obj.h
View File

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

View File

@ -9,9 +9,7 @@
frame pad_up {
c: vec @(-D/2, 0mm)
vec .(0mm, C)
meas c . 0.2mm
vec c(D, C)
o: vec c(D, C)
set pad = n+1
pad "$pad" c .
}
@ -71,3 +69,5 @@ x1 = 1+2*3
x2 = (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)
nw: vec sw(0mm, Py)
pad "$pad" se nw
// meas sw se -0.1mm
// meas sw nw 0.1mm
}
frame pad_ne {