From 503036c22e7e66aac68274323ded83c5eb3b7cb0 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Tue, 28 Feb 2017 18:38:23 -0300 Subject: [PATCH] cameo/gerber.c: support %FSLAX46Y46*% and %MOMM*% --- cameo/gerber.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/cameo/gerber.c b/cameo/gerber.c index 3486e0d..b3f00eb 100644 --- a/cameo/gerber.c +++ b/cameo/gerber.c @@ -1,8 +1,8 @@ /* * gerber.c - Gerber file input * - * Written 2010, 2013, 2015 by Werner Almesberger - * Copyright 2010, 2013, 2015 Werner Almesberger + * Written 2010, 2013, 2015, 2017 by Werner Almesberger + * Copyright 2010, 2013, 2015, 2017 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 @@ -27,9 +27,9 @@ #include "gerber.h" -/* KiCad Gerber uses 0.1 mil units */ +static double scale; /* KiCad Gerber units */ -#define KU2MM(in) ((in)/10000.0*25.4) +#define KU2MM(in) ((in)/scale) /* @@ -90,15 +90,22 @@ struct path *gerber_read(const char *name, double r_tool_default) while (fgets(buf, sizeof(buf), file)) { lineno++; if (!strncmp(buf, "%FS", 3)) { - if (strcmp(buf, "%FSLAX34Y34*%\n")) { + if (!strcmp(buf, "%FSLAX34Y34*%\n")) { + scale = 10 * 1000; + } else if (!strcmp(buf, "%FSLAX46Y46*%\n")) { + scale = 1000 * 1000; + } else { fprintf(stderr, "unrecognized format %s\n", buf); exit(1); } continue; } + /* @@@ we assume that %MO follows %FS */ if (!strncmp(buf, "%MO", 3)) { - if (strcmp(buf, "%MOIN*%\n")) { + if (!strcmp(buf, "%MOIN*%\n")) { + scale /= 25.4; + } else if (strcmp(buf, "%MOMM*%\n")) { fprintf(stderr, "unrecognized mode %s\n", buf); exit(1);