diff --git a/cameo/lang.l b/cameo/lang.l index d7e841e..f8b42c3 100644 --- a/cameo/lang.l +++ b/cameo/lang.l @@ -68,6 +68,8 @@ NUM -?[0-9]+\.?[0-9]* dog return TOK_DOG; inside return TOK_INSIDE; +any return TOK_ANY; + mm metric = 1; mil metric = 0; diff --git a/cameo/lang.y b/cameo/lang.y index d690c0c..48bdd7c 100644 --- a/cameo/lang.y +++ b/cameo/lang.y @@ -178,6 +178,7 @@ static struct path **classify(struct path **anchor, struct path *path) %union { double num; char *str; + int flag; enum { OO_DOG = 1 << 0, OO_INSIDE = 1 << 1, @@ -189,13 +190,14 @@ static struct path **classify(struct path **anchor, struct path *path) %token TOK_MILL TOK_OFFSET TOK_OPTIMIZE TOK_REMAINDER TOK_RESET %token TOK_ROTATE TOK_STATS TOK_TRANSLATE TOK_Z %token TOK_APPEND TOK_GERBER TOK_GNUPLOT TOK_EXCELLON TOK_WRITE -%token TOK_DOG TOK_INSIDE +%token TOK_DOG TOK_INSIDE TOK_ANY %token NUM_EXP_MIL NUM_EXP_MM NUM_IMP_MIL NUM_IMP_MM REF %token STRING %type opt_filename %type dimen number x_size y_size +%type opt_any %type offset_options offset_option %% @@ -321,7 +323,7 @@ command: walk = classify(walk, try_drill(*walk, $2, $4)); } - | TOK_MILL dimen dimen + | TOK_MILL opt_any dimen dimen { struct path **walk; @@ -329,7 +331,8 @@ command: paths = NULL; walk = &remain; while (*walk) - walk = classify(walk, try_mill(*walk, $2, $3)); + walk = classify(walk, + try_mill(*walk, $3, $4, $2)); } | TOK_REMAINDER { @@ -437,3 +440,13 @@ offset_option: opt_comma: | ',' ; + +opt_any: + { + $$ = 0; + } + | TOK_ANY + { + $$ = 1; + } + ; diff --git a/cameo/ops.c b/cameo/ops.c index 93ba2ea..59a7354 100644 --- a/cameo/ops.c +++ b/cameo/ops.c @@ -1,8 +1,8 @@ /* * ops.c - Higher-level toolpath operations * - * Written 2010 by Werner Almesberger - * Copyright 2010 Werner Almesberger + * Written 2010-2011 by Werner Almesberger + * Copyright 2010-2011 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 @@ -74,9 +74,9 @@ struct path *try_drill(struct path *path, double d_min, double d_max) } -struct path *try_mill(struct path *path, double diam, double step) +struct path *try_mill(struct path *path, double diam, double step, int any) { - if (path->r_tool*2 < diam) + if (!any && path->r_tool*2 < diam) return NULL; if (!path->first) return NULL; diff --git a/cameo/ops.h b/cameo/ops.h index 7e3dd16..52fff4d 100644 --- a/cameo/ops.h +++ b/cameo/ops.h @@ -1,8 +1,8 @@ /* * ops.h - Higher-level toolpath operations * - * Written 2010 by Werner Almesberger - * Copyright 2010 Werner Almesberger + * Written 2010-2011 by Werner Almesberger + * Copyright 2010-2011 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 @@ -19,7 +19,7 @@ void tool_comp_paths(struct path *paths, int dog_bone, int all_inside); struct path *try_drill(struct path *path, double d_min, double d_max); -struct path *try_mill(struct path *path, double diam, double step); +struct path *try_mill(struct path *path, double diam, double step, int any); struct path *optimize_paths(struct path *paths); #endif /* !OPS_H */ diff --git a/cameo/shape.c b/cameo/shape.c index 61879a6..978980a 100644 --- a/cameo/shape.c +++ b/cameo/shape.c @@ -1,8 +1,8 @@ /* * shape.c - Toolpaths for basic shapes * - * Written 2010 by Werner Almesberger - * Copyright 2010 Werner Almesberger + * Written 2010-2011 by Werner Almesberger + * Copyright 2010-2011 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 @@ -57,14 +57,19 @@ struct path *slot(double xa, double ya, double xb, double yb, double z, double nx, ny; double f; - f = (sr-tr)/hypot(dx, dy); - nx = -dy*f; - ny = dx*f; - path = path_new(tr); - half_circle(xa, ya, nx, ny, z, s); - half_circle(xb, yb, -nx, -ny, z, s); - path_add(path, xa+nx, ya+ny, z); + if (sr <= tr) { + path_add(path, xa, ya, z); + path_add(path, xb, yb, z); + } else { + f = (sr-tr)/hypot(dx, dy); + nx = -dy*f; + ny = dx*f; + + half_circle(xa, ya, nx, ny, z, s); + half_circle(xb, yb, -nx, -ny, z, s); + path_add(path, xa+nx, ya+ny, z); + } return path; } @@ -76,8 +81,13 @@ struct path *circle(double cx, double cy, double cz, double cr, double tr, double a; path = path_new(tr); - for (a = 0; a < 2*M_PI; a += s) - path_add(path, cx+(cr-tr)*cos(a), cy+(cr-tr)*sin(a), cz); - path_add(path, cx+(cr-tr), cy, cz); + if (cr <= tr) { + path_add(path, cx, cy, cz); + } else { + for (a = 0; a < 2*M_PI; a += s) + path_add(path, + cx+(cr-tr)*cos(a), cy+(cr-tr)*sin(a), cz); + path_add(path, cx+(cr-tr), cy, cz); + } return path; }