diff --git a/cameo/cameo.c b/cameo/cameo.c index 2fef161..8d82073 100644 --- a/cameo/cameo.c +++ b/cameo/cameo.c @@ -13,11 +13,14 @@ #include #include +#include #include "path.h" #include "gnuplot.h" +static int dog_bone = 0; + static void process_path(struct path *path, int inside) { @@ -26,9 +29,9 @@ static void process_path(struct path *path, int inside) left = path_tool_is_left(path); if (inside) - new = path_offset(path, !left, 0); + new = path_offset(path, !left, path->notch); else - new = path_offset(path, left, 1); + new = path_offset(path, left, path->notch || dog_bone); path_replace(path, new); } @@ -61,8 +64,10 @@ static void process_paths(struct path *paths) static void usage(const char *name) { - fprintf(stderr, "usage: %s r_mm [in.gnuplot [out.gnuplot]]\n", - name); + fprintf(stderr, +"usage: %s [-d] r_mm [in.gnuplot [out.gnuplot]]\n\n" +" -d put a dog-bone notch in each concave external corner\n" + , name); exit(1); } @@ -72,16 +77,26 @@ int main(int argc, char **argv) char *in = NULL, *out = NULL; double r; struct path *paths; + int c; - switch (argc) { - case 4: - out = argv[3]; - /* fall through */ + while ((c = getopt(argc, argv, "d")) != EOF) + switch (c) { + case 'd': + dog_bone = 1; + break; + default: + usage(*argv); + } + + switch (argc-optind) { case 3: - in = argv[2]; + out = argv[optind+2]; /* fall through */ case 2: - r = atof(argv[1]); + in = argv[optind+1]; + /* fall through */ + case 1: + r = atof(argv[optind]); break; default: usage(*argv); diff --git a/cameo/gnuplot.c b/cameo/gnuplot.c index 239b803..566567b 100644 --- a/cameo/gnuplot.c +++ b/cameo/gnuplot.c @@ -26,7 +26,7 @@ struct path *gnuplot_read(const char *name, double r_tool_default) char buf[1024]; double x, y, z, tmp; double r_tool = r_tool_default; - int outside = 0; + int outside = 0, notch = 0; int n; struct path *paths = NULL, *path = NULL; struct path **lnk = &paths; @@ -43,6 +43,8 @@ struct path *gnuplot_read(const char *name, double r_tool_default) r_tool = tmp; if (!strcmp(buf, "#%outside\n")) outside = 1; + if (!strcmp(buf, "#%notch\n")) + notch = 1; if (*buf == '#') continue; n = sscanf(buf, "%lf %lf %lf\n", &x, &y, &z); @@ -50,7 +52,7 @@ struct path *gnuplot_read(const char *name, double r_tool_default) case -1: path = NULL; r_tool = r_tool_default; - outside = 0; + outside = notch = 0; continue; case 2: z = 0; @@ -66,6 +68,7 @@ struct path *gnuplot_read(const char *name, double r_tool_default) if (!path) { path = path_new(r_tool); path->outside = outside; + path->notch = notch; *lnk = path; lnk = &path->next; } @@ -89,6 +92,8 @@ static int gnuplot_do_write(FILE *file, const struct path *paths) return 0; if (path->outside && fprintf(file, "#%%outside\n") < 0) return 0; + if (path->notch && fprintf(file, "#%%notch\n") < 0) + return 0; for (p = path->first; p; p = p->next) if (fprintf(file, "%f %f %f\n", p->x, p->y, p->z) < 0) return 0; diff --git a/cameo/path.c b/cameo/path.c index 6df4689..be3b37e 100644 --- a/cameo/path.c +++ b/cameo/path.c @@ -46,6 +46,7 @@ struct path *path_new(double r_tool) path = alloc_type(struct path); path->r_tool = r_tool; path->outside = 0; + path->notch = 0; path->first = path->last = NULL; path->next = NULL; return path; @@ -58,6 +59,7 @@ static struct path *path_from(const struct path *old) new = path_new(old->r_tool); new->outside = old->outside; + new->notch = old->notch; return new; } diff --git a/cameo/path.h b/cameo/path.h index 3f1b3ed..351ecef 100644 --- a/cameo/path.h +++ b/cameo/path.h @@ -24,6 +24,7 @@ struct path { struct point *first, *last; double r_tool; /* mm */ int outside; /* non-zero to mark path as an outside edge */ + int notch; /* non-zero to enable dog-boning for path */ struct path *next; };