mirror of
git://projects.qi-hardware.com/cae-tools.git
synced 2024-12-23 00:41:10 +02:00
cameo: adding toolpath adaptation language (in progress)
- README: added description of toolpath adaptation language (in progress) - Makefile (OBJS): added lex.yy.o and y.tab.o - Makefile (SLOPPY): relaxed compiler warnings for files generated by flex/yacc - Makefile (clean): added lex/yacc intermediate files - Makefile: added lex and yacc (bison) to build process - Makefile: added rules for lex/yacc intermediate files - lang.l, lang.y: toolpath adaptation language (in progress)
This commit is contained in:
parent
8999b3016a
commit
f80a01a9c0
@ -15,26 +15,45 @@ PREFIX ?= /usr/local
|
||||
SHELL=/bin/bash
|
||||
|
||||
MAIN=cameo
|
||||
OBJS=cameo.o gerber.o gnuplot.o path.o
|
||||
OBJS=cameo.o gerber.o gnuplot.o path.o lex.yy.o y.tab.o
|
||||
|
||||
CFLAGS_WARN=-Wall -Wshadow -Wmissing-prototypes \
|
||||
-Wmissing-declarations -Wno-format-zero-length
|
||||
SLOPPY = -Wno-unused -Wno-implicit-function-declaration
|
||||
|
||||
# An older version of SLOPPY (seems that bison and flex got tidier):
|
||||
#
|
||||
#SLOPPY = -Wno-unused -Wno-implicit-function-declaration \
|
||||
# -Wno-missing-prototypes -Wno-missing-declarations
|
||||
#
|
||||
|
||||
CFLAGS=$(CFLAGS_WARN) -g
|
||||
LDFLAGS=-lm
|
||||
LDFLAGS=
|
||||
LDLIBS=-lm -lfl
|
||||
YACC = bison -y
|
||||
YYFLAGS = -v
|
||||
|
||||
# ----- Verbosity control -----------------------------------------------------
|
||||
|
||||
CC_normal := $(CC)
|
||||
YACC_normal := $(YACC)
|
||||
LEX_normal := $(LEX)
|
||||
DEPEND_normal := $(CPP) $(CFLAGS) -MM -MG
|
||||
|
||||
CC_quiet = @echo " CC " $@ && $(CC_normal)
|
||||
YACC_quiet = @echo " YACC " $@ && $(YACC_normal)
|
||||
LEX_quiet = @echo " LEX " $@ && $(LEX_normal)
|
||||
DEPEND_quiet = @$(DEPEND_normal)
|
||||
|
||||
ifeq ($(V),1)
|
||||
CC = $(CC_normal)
|
||||
LEX = $(LEX_normal)
|
||||
YACC = $(YACC_normal)
|
||||
DEPEND = $(DEPEND_normal)
|
||||
else
|
||||
CC = $(CC_quiet)
|
||||
LEX = $(LEX_quiet)
|
||||
YACC = $(YACC_quiet)
|
||||
DEPEND = $(DEPEND_quiet)
|
||||
endif
|
||||
|
||||
@ -46,8 +65,21 @@ all: $(MAIN)
|
||||
|
||||
$(MAIN): $(OBJS)
|
||||
|
||||
lex.yy.c: lang.l y.tab.h
|
||||
$(LEX) lang.l
|
||||
|
||||
lex.yy.o: lex.yy.c y.tab.h
|
||||
$(CC) -c $(CFLAGS) $(SLOPPY) lex.yy.c
|
||||
|
||||
y.tab.c y.tab.h: lang.y
|
||||
$(YACC) $(YYFLAGS) -d lang.y
|
||||
|
||||
y.tab.o: y.tab.c y.tab.h
|
||||
$(CC) -c $(CFLAGS) $(SLOPPY) y.tab.c
|
||||
|
||||
clean:
|
||||
rm -f $(OBJS) $(OBJS:.o=.d)
|
||||
rm -f lex.yy.c y.output y.tab.c y.tab.h
|
||||
|
||||
spotless: clean
|
||||
rm -f $(MAIN)
|
||||
|
59
cameo/README
59
cameo/README
@ -19,3 +19,62 @@ LICENSE, Version 2:
|
||||
|
||||
For your convenience, a copy of the complete license has been included
|
||||
in the file COPYING.GPLv2.
|
||||
|
||||
|
||||
Toolpath adaptation language
|
||||
----------------------------
|
||||
|
||||
Loading paths:
|
||||
|
||||
gerber <diameter> [<filename>]
|
||||
gnuplot <diameter> [<filename>]
|
||||
clear
|
||||
|
||||
"gerber" and "gnuplot" each add paths from a file to the list of paths
|
||||
already loaded. "clear" removes all paths.
|
||||
|
||||
If the a file name is omitted, standard input is read. The diameter is
|
||||
the default tool diameter.
|
||||
|
||||
Note that "clear" preserves the translation set with "align", "array",
|
||||
and "translate". This way, multiple files can be processed with the same
|
||||
translation.
|
||||
|
||||
File output:
|
||||
|
||||
write [<filename>]
|
||||
|
||||
Writes all loaded paths in gnuplot format to the specified file. If the
|
||||
file name is omitted, "write" writes to standard output.
|
||||
|
||||
Units:
|
||||
|
||||
mm
|
||||
mil
|
||||
<number>mm
|
||||
<number>mil
|
||||
|
||||
The words "mm" and "mil" set the input to the specified unit. The
|
||||
default unit is millimeter. If a number is followed by "mm" or "mil"
|
||||
without intervening space, the unit is overridden for this number,
|
||||
without affecting the default input unit.
|
||||
|
||||
Note that "mm" and "mil" only affect dimensions in the command file
|
||||
and have no effect on the interpretation of toolpath files.
|
||||
|
||||
|
||||
Horizontal adjustments:
|
||||
|
||||
align <ref> <x> <y>
|
||||
align <ref> <x0> <y0> <x1> <y1>
|
||||
array <x-step> <y-step> <x-index> <y-index>
|
||||
translate <X> <y>
|
||||
reset
|
||||
|
||||
Vertical adjustment:
|
||||
|
||||
z [<z0>] <z0-depth>
|
||||
|
||||
Tool compensation:
|
||||
|
||||
tool
|
||||
|
93
cameo/lang.l
Normal file
93
cameo/lang.l
Normal file
@ -0,0 +1,93 @@
|
||||
%{
|
||||
/*
|
||||
* lang.l - Toolpath adaptation language
|
||||
*
|
||||
* Written 2010 by Werner Almesberger
|
||||
* Copyright 2010 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
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*/
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "y.tab.h"
|
||||
|
||||
|
||||
void yyerror(const char *s);
|
||||
|
||||
static int lineno = 1;
|
||||
static int metric = 1;
|
||||
|
||||
#define MIL2MM(mil) ((mil)/1000*25.4)
|
||||
|
||||
%}
|
||||
|
||||
/* file name can contain any characters */
|
||||
%s FILENAME
|
||||
|
||||
/* "align" has a one-digit argument we don't want to subject to unit
|
||||
conversion */
|
||||
%s DIGIT
|
||||
|
||||
NUM [0-9]+\.?[0-9]*
|
||||
|
||||
%%
|
||||
|
||||
|
||||
<INITIAL>align { BEGIN(DIGIT);
|
||||
return TOK_ALIGN; }
|
||||
<INITIAL>array return TOK_ARRAY;
|
||||
<INITIAL>clear return TOK_CLEAR;
|
||||
<INITIAL>reset return TOK_RESET;
|
||||
<INITIAL>tool return TOK_TOOL;
|
||||
<INITIAL>translate return TOK_TRANSLATE;
|
||||
<INITIAL>z return TOK_Z;
|
||||
|
||||
<INITIAL>gerber { BEGIN(FILENAME);
|
||||
return TOK_GERBER; }
|
||||
<INITIAL>gnuplot { BEGIN(FILENAME);
|
||||
return TOK_GNUPLOT; }
|
||||
<INITIAL>write { BEGIN(FILENAME);
|
||||
return TOK_WRITE; }
|
||||
|
||||
<INITIAL>mm metric = 1;
|
||||
<INITIAL>mil metric = 0;
|
||||
|
||||
<INITIAL,FILENAME>{NUM}mm { yylval.num = strtod(yytext, NULL);
|
||||
return NUMBER; }
|
||||
<INITIAL,FILENAME>{NUM}mil { yylval.num = MIL2MM(strtod(yytext, NULL));
|
||||
return NUMBER; }
|
||||
<INITIAL,FILENAME>{NUM} { yylval.num = strtod(yytext, NULL);
|
||||
if (!metric)
|
||||
yylval.num = MIL2MM(yylval.num);
|
||||
return NUMBER; }
|
||||
|
||||
<FILENAME>[^ \t\n]+([^\t\n]*[^ \t\n]+)? {
|
||||
BEGIN(INITIAL);
|
||||
yylval.str = yytext;
|
||||
return STRING; }
|
||||
|
||||
<DIGIT>[1-9] { BEGIN(INITIAL);
|
||||
yylval.num = strtod(yytext, NULL);
|
||||
return NUMBER; }
|
||||
|
||||
[ \t] ;
|
||||
\n lineno++;
|
||||
|
||||
^#\ [0-9]+\ \"[^"]*\"(\ [0-9]+)*\n {
|
||||
lineno = strtol(yytext+2, NULL, 0); }
|
||||
|
||||
. return *yytext;
|
||||
|
||||
%%
|
||||
|
||||
void yyerror(const char *s)
|
||||
{
|
||||
fprintf(stderr, "%d: %s near \"%s\"\n", lineno, s, yytext);
|
||||
exit(1);
|
||||
}
|
183
cameo/lang.y
Normal file
183
cameo/lang.y
Normal file
@ -0,0 +1,183 @@
|
||||
%{
|
||||
/*
|
||||
* lang.y - Toolpath adaptation language
|
||||
*
|
||||
* Written 2010 by Werner Almesberger
|
||||
* Copyright 2010 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
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*/
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "path.h"
|
||||
#include "gnuplot.h"
|
||||
#include "gerber.h"
|
||||
|
||||
#include "y.tab.h"
|
||||
|
||||
|
||||
static double xo = 0, yo = 0, zo = 0;
|
||||
static struct path *paths = NULL;
|
||||
|
||||
|
||||
static void add_paths(struct path *new)
|
||||
{
|
||||
struct path **anchor = &paths;
|
||||
|
||||
while (*anchor)
|
||||
anchor = &(*anchor)->next;
|
||||
*anchor = new;
|
||||
}
|
||||
|
||||
|
||||
static void translate(double x, double y, double z)
|
||||
{
|
||||
struct path *path;
|
||||
struct point *p;
|
||||
|
||||
for (path = paths; path; path = path->next)
|
||||
for (p = path->first; p; p = p->next) {
|
||||
p->x += x;
|
||||
p->y += y;
|
||||
p->z += z;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static double ref_pick_1(int ref, double a, double b)
|
||||
{
|
||||
switch (ref) {
|
||||
case 0:
|
||||
return a;
|
||||
case 1:
|
||||
return (a+b)/2;
|
||||
case 2:
|
||||
return b;
|
||||
default:
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void ref_pick_xy(int ref, double xa, double ya, double xb, double yb,
|
||||
double *x, double *y)
|
||||
{
|
||||
*x = ref_pick_1((ref-1) % 3, xa, xb);
|
||||
*y = ref_pick_1((ref-1)/3, ya, yb);
|
||||
}
|
||||
|
||||
|
||||
static void align(int ref, double x, double y)
|
||||
{
|
||||
/* @@@ */
|
||||
}
|
||||
|
||||
|
||||
%}
|
||||
|
||||
|
||||
%union {
|
||||
double num;
|
||||
char *str;
|
||||
};
|
||||
|
||||
|
||||
%token TOK_ALIGN TOK_ARRAY TOK_CLEAR TOK_RESET TOK_TOOL
|
||||
%token TOK_TRANSLATE TOK_Z
|
||||
%token TOK_GERBER TOK_GNUPLOT TOK_WRITE
|
||||
|
||||
%token <num> NUMBER
|
||||
%token <str> STRING
|
||||
|
||||
%type <str> opt_filename
|
||||
|
||||
%%
|
||||
|
||||
all:
|
||||
| command all
|
||||
;
|
||||
|
||||
command:
|
||||
TOK_ALIGN NUMBER NUMBER NUMBER
|
||||
{
|
||||
align((int) $2, $3, $4);
|
||||
}
|
||||
| TOK_ALIGN NUMBER NUMBER NUMBER NUMBER NUMBER
|
||||
{
|
||||
int ref = $2;
|
||||
double x, y;
|
||||
|
||||
ref_pick_xy(ref, $3, $4, $5, $6, &x, &y);
|
||||
align(ref, x, y);
|
||||
}
|
||||
| TOK_ARRAY NUMBER NUMBER NUMBER NUMBER
|
||||
{
|
||||
double x = $2*$4;
|
||||
double y = $3*$5;
|
||||
|
||||
translate(x, y, 0);
|
||||
}
|
||||
| TOK_CLEAR
|
||||
{
|
||||
struct path *next;
|
||||
|
||||
while (paths) {
|
||||
next = paths->next;
|
||||
path_free(paths);
|
||||
paths = next;
|
||||
}
|
||||
}
|
||||
| TOK_RESET
|
||||
{
|
||||
xo = yo = 0;
|
||||
}
|
||||
| TOK_TOOL
|
||||
{
|
||||
// @@@ process_paths(paths);
|
||||
}
|
||||
| TOK_TRANSLATE NUMBER NUMBER
|
||||
{
|
||||
translate($2, $3, 0);
|
||||
xo += $2;
|
||||
yo += $3;
|
||||
}
|
||||
| TOK_Z NUMBER
|
||||
{
|
||||
zo -= $2;
|
||||
}
|
||||
| TOK_Z NUMBER NUMBER
|
||||
{
|
||||
zo -= $2+$3;
|
||||
}
|
||||
| TOK_GERBER NUMBER opt_filename
|
||||
{
|
||||
add_paths(gerber_read($3, $2/2));
|
||||
translate(xo, yo, 0);
|
||||
}
|
||||
| TOK_GNUPLOT NUMBER opt_filename
|
||||
{
|
||||
add_paths(gnuplot_read($3, $2/2));
|
||||
translate(xo, yo, 0);
|
||||
}
|
||||
| TOK_WRITE opt_filename
|
||||
{
|
||||
translate(0, 0, zo);
|
||||
gnuplot_write($2, paths);
|
||||
translate(0, 0, -zo);
|
||||
}
|
||||
;
|
||||
|
||||
opt_filename:
|
||||
{
|
||||
$$ = NULL;
|
||||
}
|
||||
| STRING
|
||||
{
|
||||
$$ = $1;
|
||||
}
|
||||
;
|
Loading…
Reference in New Issue
Block a user