summaryrefslogtreecommitdiff
path: root/kicad
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2016-09-08 04:42:11 (GMT)
committerWerner Almesberger <werner@almesberger.net>2016-09-08 04:42:11 (GMT)
commitf31d15bda0c609910388210d0edbf0bb952afc4a (patch)
treebbe2516a895203c11a765926f33b5f53dee1f05e /kicad
parent61c29a9d460573cb1095351c8de48c4f985facbe (diff)
downloadeeshow-f31d15bda0c609910388210d0edbf0bb952afc4a.zip
eeshow-f31d15bda0c609910388210d0edbf0bb952afc4a.tar.gz
eeshow-f31d15bda0c609910388210d0edbf0bb952afc4a.tar.bz2
kicad/: support parsing polygons in page layout
Diffstat (limited to 'kicad')
-rw-r--r--kicad/pl-common.h16
-rw-r--r--kicad/pl-parse.c64
2 files changed, 78 insertions, 2 deletions
diff --git a/kicad/pl-common.h b/kicad/pl-common.h
index 44aa5e0..8d8955f 100644
--- a/kicad/pl-common.h
+++ b/kicad/pl-common.h
@@ -30,17 +30,28 @@ enum page_constraint {
};
+struct pl_point {
+ float x, y;
+ struct pl_point *next;
+};
+
+struct pl_poly {
+ struct pl_point *points;
+ struct pl_poly *next;
+};
+
struct pl_obj {
enum pl_obj_type {
pl_obj_rect,
pl_obj_line,
pl_obj_text,
+ pl_obj_poly,
} type;
enum page_constraint pc;
const char *s; /* tbtext */
int repeat; /* line, rect, tbtext */
- float x, y; /* line, rect, tbtext */
+ float x, y; /* line, rect, tbtext, poly */
int dx, dy;
float ex, ey; /* line, rect; font size for tbtext */
int edx, edy;
@@ -49,7 +60,8 @@ struct pl_obj {
int font; /* tbtext (flags) */
enum text_align hor; /* tbtext */
enum text_align vert; /* tbtext */
- float rotate; /* tbtext */
+ float rotate; /* tbtext, poly */
+ struct pl_poly *poly; /* poly */
struct pl_obj *next;
};
diff --git a/kicad/pl-parse.c b/kicad/pl-parse.c
index 27a4628..4cd8b1c 100644
--- a/kicad/pl-parse.c
+++ b/kicad/pl-parse.c
@@ -283,6 +283,45 @@ static bool process_option(struct pl_obj *obj, const struct expr *e)
}
+static bool process_poly(struct pl_obj *obj, const struct expr *e)
+{
+ struct pl_poly *poly;
+ struct pl_point *p, **anchor;
+ const char *s;
+ const struct expr *next;
+
+ poly = alloc_type(struct pl_poly);
+ poly->points = NULL;
+ poly->next = obj->poly;
+ obj->poly = poly;
+ anchor = &poly->points;
+
+ for (; e; e = e->next) {
+ if (!e->e) {
+ warning("pts: ignoring non-list");
+ continue;
+ }
+
+ s = e->e->s;
+ next = e->e->next;
+
+ if (!strcmp(s, "xy")) {
+ p = alloc_type(struct pl_point);
+ *anchor = p;
+ anchor = &p->next;
+ if (!get_xy(next, &p->x, &p->y))
+ return 0;
+ } else {
+ warning("pts: ignoring \"%s\"", s);
+ }
+ }
+
+ *anchor = NULL;
+
+ return 1;
+}
+
+
static bool process_obj(struct pl_ctx *pl, const struct expr *e,
enum pl_obj_type type)
{
@@ -304,6 +343,7 @@ static bool process_obj(struct pl_ctx *pl, const struct expr *e,
obj->hor = text_min;
obj->vert = text_mid;
obj->rotate = 0;
+ obj->poly = 0;
for (; e; e = e->next) {
if (e->s) {
@@ -361,6 +401,9 @@ static bool process_obj(struct pl_ctx *pl, const struct expr *e,
} else if (!strcmp(s, "option")) {
if (!process_option(obj, next))
return 0;
+ } else if (!strcmp(s, "pts")) {
+ if (!process_poly(obj, next))
+ return 0;
} else
warning("pl_obj: ignoring \"%s\"", s);
}
@@ -400,6 +443,9 @@ static bool process_layout(struct pl_ctx *pl, const struct expr *e)
} else if (!strcmp(s, "tbtext")) {
if (!process_obj(pl, next, pl_obj_text))
return 0;
+ } else if (!strcmp(s, "polygon")) {
+ if (!process_obj(pl, next, pl_obj_poly))
+ return 0;
} else {
warning("layout: ignoring \"%s\"", s);
}
@@ -491,6 +537,23 @@ struct pl_ctx *pl_parse_search(const char *name, const struct file *related)
}
+static void free_polys(struct pl_poly *poly)
+{
+ struct pl_poly *next_poly;
+ struct pl_point *p, *next_point;
+
+ while (poly) {
+ next_poly = poly->next;
+ for (p = poly->points; p; p = next_point) {
+ next_point = p->next;
+ free(p);
+ }
+ free(poly);
+ poly = next_poly;
+ }
+}
+
+
void pl_free(struct pl_ctx *pl)
{
struct pl_obj *next;
@@ -498,6 +561,7 @@ void pl_free(struct pl_ctx *pl)
while (pl->objs) {
next = pl->objs->next;
free((void *) pl->objs->s);
+ free_polys(pl->objs->poly);
free(pl->objs);
pl->objs = next;
}