From 8b6e4168d3b9f88904d80e1b155c72cd78d94534 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Sun, 13 Oct 2013 22:10:43 -0300 Subject: [PATCH] cameo/: add "stl" command to generate STL slices (WIP) --- cameo/Makefile | 6 +++--- cameo/lang.l | 6 ++++-- cameo/lang.y | 10 +++++++--- cameo/stl.c | 38 ++++++++++++++++++++++++++++++++++++++ cameo/stl.h | 23 +++++++++++++++++++++++ 5 files changed, 75 insertions(+), 8 deletions(-) create mode 100644 cameo/stl.c create mode 100644 cameo/stl.h diff --git a/cameo/Makefile b/cameo/Makefile index be6173c..621cd9e 100644 --- a/cameo/Makefile +++ b/cameo/Makefile @@ -1,8 +1,8 @@ # # Makefile - Makefile of cameo # -# Written 2010, 2012 by Werner Almesberger -# Copyright 2010, 2012 by Werner Almesberger +# Written 2010, 2012, 2013 by Werner Almesberger +# Copyright 2010, 2012, 2013 by 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 @@ -16,7 +16,7 @@ SHELL=/bin/bash MAIN=cameo OBJS=cameo.o excellon.o area-poly2d.o gerber.o gnuplot.o ops.o path.o \ - poly2d.o shape.o lex.yy.o y.tab.o + poly2d.o shape.o stl.o lex.yy.o y.tab.o CFLAGS_WARN=-Wall -Wshadow -Wmissing-prototypes \ -Wmissing-declarations -Wno-format-zero-length diff --git a/cameo/lang.l b/cameo/lang.l index 70bdd5a..ac5493b 100644 --- a/cameo/lang.l +++ b/cameo/lang.l @@ -2,8 +2,8 @@ /* * lang.l - Toolpath adaptation language * - * Written 2010-2012 by Werner Almesberger - * Copyright 2010-2012 by Werner Almesberger + * Written 2010-2013 by Werner Almesberger + * Copyright 2010-2013 by 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 @@ -70,6 +70,8 @@ NUM -?[0-9]+\.?[0-9]* return TOK_GNUPLOT; } excellon { BEGIN(FILENAME); return TOK_EXCELLON; } +stl { BEGIN(FILENAME); + return TOK_STL; } write { BEGIN(FILENAME); return TOK_WRITE; } diff --git a/cameo/lang.y b/cameo/lang.y index b572271..1bd2db2 100644 --- a/cameo/lang.y +++ b/cameo/lang.y @@ -2,8 +2,8 @@ /* * lang.y - Toolpath adaptation language * - * Written 2010-2012 by Werner Almesberger - * Copyright 2010-2012 by Werner Almesberger + * Written 2010-2013 by Werner Almesberger + * Copyright 2010-2013 by 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 @@ -232,7 +232,7 @@ static struct path **classify(struct path **anchor, struct path *path) %token TOK_FLIP TOK_KEEP TOK_MILL TOK_OFFSET TOK_OPTIMIZE %token TOK_OUTSIDE TOK_REMAINDER %token TOK_REMOVE TOK_RESET -%token TOK_REVERSE TOK_ROTATE TOK_STATS TOK_TRANSLATE +%token TOK_REVERSE TOK_ROTATE TOK_STATS TOK_STL TOK_TRANSLATE %token TOK_X TOK_Y TOK_Z %token TOK_APPEND TOK_GERBER TOK_GNUPLOT TOK_EXCELLON TOK_WRITE %token TOK_DOG TOK_INSIDE TOK_ANY @@ -410,6 +410,10 @@ command: clear_paths(); paths = tmp; } + | TOK_STL opt_filename + { + stl($2, paths); + } | TOK_MILL opt_any dimen dimen { struct path **walk; diff --git a/cameo/stl.c b/cameo/stl.c new file mode 100644 index 0000000..d89fa01 --- /dev/null +++ b/cameo/stl.c @@ -0,0 +1,38 @@ +/* + * stl.c - Genererate STL slice from polygon set + * + * Written 2013 by Werner Almesberger + * Copyright 2013 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 + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + + +#include + +#include "poly2d.h" + +#include "path.h" +#include "stl.h" + + +void stl(const char *name, const struct path *paths) +{ + struct p2d *polys; + struct f2d *faces; + const struct f2d *f; + + polys = paths_to_polys(paths); + faces = f2d_tri(polys); + for (f = faces; f; f = f->next) + printf("%f/%f %f/%f %f/%f (%p %p %p)\n", + f->v[0]->x, f->v[0]->y, + f->v[1]->x, f->v[1]->y, + f->v[2]->x, f->v[2]->y, + f->v[0], f->v[1], f->v[2]); + p2d_free_all(polys); + f2d_free_all(faces); +} diff --git a/cameo/stl.h b/cameo/stl.h new file mode 100644 index 0000000..9308512 --- /dev/null +++ b/cameo/stl.h @@ -0,0 +1,23 @@ +/* + * stl.h - Genererate STL slice from polygon set + * + * Written 2013 by Werner Almesberger + * Copyright 2013 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 + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + + +#ifndef STL_H +#define STL_H + + +#include "path.h" + + +void stl(const char *name, const struct path *paths); + +#endif /* !STL_H */