mirror of
git://projects.qi-hardware.com/fped.git
synced 2024-11-22 14:08:28 +02:00
obj.c: move vector to coord translation to separate function (for future extension)
This commit is contained in:
parent
ea9b8f988e
commit
c8f5d29178
58
obj.c
58
obj.c
@ -168,7 +168,15 @@ static struct num eval_unit_default(const struct expr *expr,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int generate_vecs(struct frame *frame, struct coord base)
|
static int resolve_vec(const struct vec *vec, struct coord base_pos,
|
||||||
|
struct coord *res)
|
||||||
|
{
|
||||||
|
*res = vec ? vec->pos : base_pos;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int generate_vecs(struct frame *frame, struct coord base_pos)
|
||||||
{
|
{
|
||||||
struct coord vec_base;
|
struct coord vec_base;
|
||||||
struct vec *vec;
|
struct vec *vec;
|
||||||
@ -181,7 +189,8 @@ static int generate_vecs(struct frame *frame, struct coord base)
|
|||||||
y = eval_unit(vec->y, frame);
|
y = eval_unit(vec->y, frame);
|
||||||
if (is_undef(y))
|
if (is_undef(y))
|
||||||
goto error;
|
goto error;
|
||||||
vec_base = vec->base ? vec->base->pos : base;
|
if (!resolve_vec(vec->base, base_pos, &vec_base))
|
||||||
|
goto error;
|
||||||
vec->pos = vec_base;
|
vec->pos = vec_base;
|
||||||
vec->pos.x += x.n;
|
vec->pos.x += x.n;
|
||||||
vec->pos.y += y.n;
|
vec->pos.y += y.n;
|
||||||
@ -197,66 +206,72 @@ error:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int generate_objs(struct frame *frame, struct coord base, int active)
|
static int generate_objs(struct frame *frame, struct coord base_pos,
|
||||||
|
int active)
|
||||||
{
|
{
|
||||||
struct obj *obj;
|
struct obj *obj;
|
||||||
char *name;
|
char *name;
|
||||||
int ok;
|
int ok;
|
||||||
struct num width, offset;
|
struct num width, offset;
|
||||||
|
struct coord base, other, start, end;
|
||||||
|
|
||||||
for (obj = frame->objs; obj; obj = obj->next)
|
for (obj = frame->objs; obj; obj = obj->next) {
|
||||||
|
if (obj->type != ot_meas)
|
||||||
|
if (!resolve_vec(obj->base, base_pos, &base))
|
||||||
|
goto error;
|
||||||
switch (obj->type) {
|
switch (obj->type) {
|
||||||
case ot_frame:
|
case ot_frame:
|
||||||
if (!generate_frame(obj->u.frame.ref,
|
if (!generate_frame(obj->u.frame.ref, base, frame, obj,
|
||||||
obj->base ? obj->base->pos : base, frame, obj,
|
|
||||||
active && obj->u.frame.ref->active_ref == obj))
|
active && obj->u.frame.ref->active_ref == obj))
|
||||||
return 0;
|
return 0;
|
||||||
break;
|
break;
|
||||||
case ot_line:
|
case ot_line:
|
||||||
|
if (!resolve_vec(obj->u.line.other, base_pos, &other))
|
||||||
|
goto error;
|
||||||
width = eval_unit_default(obj->u.line.width, frame,
|
width = eval_unit_default(obj->u.line.width, frame,
|
||||||
DEFAULT_SILK_WIDTH);
|
DEFAULT_SILK_WIDTH);
|
||||||
if (is_undef(width))
|
if (is_undef(width))
|
||||||
goto error;
|
goto error;
|
||||||
if (!inst_line(obj, obj->base ? obj->base->pos : base,
|
if (!inst_line(obj, base, other, width.n))
|
||||||
obj->u.line.other ? obj->u.line.other->pos : base,
|
|
||||||
width.n))
|
|
||||||
goto error;
|
goto error;
|
||||||
break;
|
break;
|
||||||
case ot_rect:
|
case ot_rect:
|
||||||
|
if (!resolve_vec(obj->u.rect.other, base_pos, &other))
|
||||||
|
goto error;
|
||||||
width = eval_unit_default(obj->u.rect.width, frame,
|
width = eval_unit_default(obj->u.rect.width, frame,
|
||||||
DEFAULT_SILK_WIDTH);
|
DEFAULT_SILK_WIDTH);
|
||||||
if (is_undef(width))
|
if (is_undef(width))
|
||||||
goto error;
|
goto error;
|
||||||
if (!inst_rect(obj, obj->base ? obj->base->pos : base,
|
if (!inst_rect(obj, base, other, width.n))
|
||||||
obj->u.rect.other ? obj->u.rect.other->pos : base,
|
|
||||||
width.n))
|
|
||||||
goto error;
|
goto error;
|
||||||
break;
|
break;
|
||||||
case ot_pad:
|
case ot_pad:
|
||||||
|
if (!resolve_vec(obj->u.pad.other, base_pos, &other))
|
||||||
|
goto error;
|
||||||
name = expand(obj->u.pad.name, frame);
|
name = expand(obj->u.pad.name, frame);
|
||||||
if (!name)
|
if (!name)
|
||||||
goto error;
|
goto error;
|
||||||
ok = inst_pad(obj, name,
|
ok = inst_pad(obj, name, base, other);
|
||||||
obj->base ? obj->base->pos : base,
|
|
||||||
obj->u.pad.other ? obj->u.pad.other->pos : base);
|
|
||||||
free(name);
|
free(name);
|
||||||
if (!ok)
|
if (!ok)
|
||||||
goto error;
|
goto error;
|
||||||
break;
|
break;
|
||||||
case ot_hole:
|
case ot_hole:
|
||||||
if (!inst_hole(obj, obj->base ? obj->base->pos : base,
|
if (!resolve_vec(obj->u.hole.other, base_pos, &other))
|
||||||
obj->u.hole.other ? obj->u.hole.other->pos : base))
|
goto error;
|
||||||
|
if (!inst_hole(obj, base, other))
|
||||||
goto error;
|
goto error;
|
||||||
break;
|
break;
|
||||||
case ot_arc:
|
case ot_arc:
|
||||||
|
if (!resolve_vec(obj->u.arc.start, base_pos, &start))
|
||||||
|
goto error;
|
||||||
|
if (!resolve_vec(obj->u.arc.end, base_pos, &end))
|
||||||
|
goto error;
|
||||||
width = eval_unit_default(obj->u.arc.width, frame,
|
width = eval_unit_default(obj->u.arc.width, frame,
|
||||||
DEFAULT_SILK_WIDTH);
|
DEFAULT_SILK_WIDTH);
|
||||||
if (is_undef(width))
|
if (is_undef(width))
|
||||||
goto error;
|
goto error;
|
||||||
if (!inst_arc(obj, obj->base ? obj->base->pos : base,
|
if (!inst_arc(obj, base, start, end, width.n))
|
||||||
obj->u.arc.start ? obj->u.arc.start->pos : base,
|
|
||||||
obj->u.arc.end ? obj->u.arc.end->pos : base,
|
|
||||||
width.n))
|
|
||||||
goto error;
|
goto error;
|
||||||
break;
|
break;
|
||||||
case ot_meas:
|
case ot_meas:
|
||||||
@ -270,6 +285,7 @@ static int generate_objs(struct frame *frame, struct coord base, int active)
|
|||||||
default:
|
default:
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
|
Loading…
Reference in New Issue
Block a user