1
0
mirror of git://projects.qi-hardware.com/cae-tools.git synced 2024-12-22 23:26:27 +02:00

cameo/: add "stl" command to generate STL slices (WIP)

This commit is contained in:
Werner Almesberger 2013-10-13 22:10:43 -03:00
parent ca271dd313
commit 8b6e4168d3
5 changed files with 75 additions and 8 deletions

View File

@ -1,8 +1,8 @@
# #
# Makefile - Makefile of cameo # Makefile - Makefile of cameo
# #
# Written 2010, 2012 by Werner Almesberger # Written 2010, 2012, 2013 by Werner Almesberger
# Copyright 2010, 2012 by Werner Almesberger # Copyright 2010, 2012, 2013 by Werner Almesberger
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
@ -16,7 +16,7 @@ SHELL=/bin/bash
MAIN=cameo MAIN=cameo
OBJS=cameo.o excellon.o area-poly2d.o gerber.o gnuplot.o ops.o path.o \ 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 \ CFLAGS_WARN=-Wall -Wshadow -Wmissing-prototypes \
-Wmissing-declarations -Wno-format-zero-length -Wmissing-declarations -Wno-format-zero-length

View File

@ -2,8 +2,8 @@
/* /*
* lang.l - Toolpath adaptation language * lang.l - Toolpath adaptation language
* *
* Written 2010-2012 by Werner Almesberger * Written 2010-2013 by Werner Almesberger
* Copyright 2010-2012 by Werner Almesberger * Copyright 2010-2013 by Werner Almesberger
* *
* This program is free software; you can redistribute it and/or modify * 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 * 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; } return TOK_GNUPLOT; }
<INITIAL>excellon { BEGIN(FILENAME); <INITIAL>excellon { BEGIN(FILENAME);
return TOK_EXCELLON; } return TOK_EXCELLON; }
<INITIAL>stl { BEGIN(FILENAME);
return TOK_STL; }
<INITIAL>write { BEGIN(FILENAME); <INITIAL>write { BEGIN(FILENAME);
return TOK_WRITE; } return TOK_WRITE; }

View File

@ -2,8 +2,8 @@
/* /*
* lang.y - Toolpath adaptation language * lang.y - Toolpath adaptation language
* *
* Written 2010-2012 by Werner Almesberger * Written 2010-2013 by Werner Almesberger
* Copyright 2010-2012 by Werner Almesberger * Copyright 2010-2013 by Werner Almesberger
* *
* This program is free software; you can redistribute it and/or modify * 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 * 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_FLIP TOK_KEEP TOK_MILL TOK_OFFSET TOK_OPTIMIZE
%token TOK_OUTSIDE TOK_REMAINDER %token TOK_OUTSIDE TOK_REMAINDER
%token TOK_REMOVE TOK_RESET %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_X TOK_Y TOK_Z
%token TOK_APPEND TOK_GERBER TOK_GNUPLOT TOK_EXCELLON TOK_WRITE %token TOK_APPEND TOK_GERBER TOK_GNUPLOT TOK_EXCELLON TOK_WRITE
%token TOK_DOG TOK_INSIDE TOK_ANY %token TOK_DOG TOK_INSIDE TOK_ANY
@ -410,6 +410,10 @@ command:
clear_paths(); clear_paths();
paths = tmp; paths = tmp;
} }
| TOK_STL opt_filename
{
stl($2, paths);
}
| TOK_MILL opt_any dimen dimen | TOK_MILL opt_any dimen dimen
{ {
struct path **walk; struct path **walk;

38
cameo/stl.c Normal file
View File

@ -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 <stdio.h>
#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);
}

23
cameo/stl.h Normal file
View File

@ -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 */