2010-11-01 19:58:29 +02:00
|
|
|
/*
|
|
|
|
* cameo.c - Toolpath adaptation and machine control
|
|
|
|
*
|
2011-09-05 13:54:29 +03:00
|
|
|
* Written 2010-2011 by Werner Almesberger
|
|
|
|
* Copyright 2010-2011 Werner Almesberger
|
2010-11-01 19:58:29 +02:00
|
|
|
*
|
|
|
|
* 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>
|
2010-11-02 00:15:35 +02:00
|
|
|
#include <unistd.h>
|
2010-11-01 19:58:29 +02:00
|
|
|
|
|
|
|
#include "path.h"
|
2010-12-14 19:15:52 +02:00
|
|
|
#include "ops.h"
|
2010-11-01 19:58:29 +02:00
|
|
|
#include "gnuplot.h"
|
2010-12-13 22:45:33 +02:00
|
|
|
#include "gerber.h"
|
2010-11-01 19:58:29 +02:00
|
|
|
|
|
|
|
|
2010-12-14 21:17:29 +02:00
|
|
|
extern int yyparse(void);
|
|
|
|
extern FILE *yyin;
|
|
|
|
|
|
|
|
|
|
|
|
static void run_script(const char *file)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (file) {
|
|
|
|
yyin = fopen(file, "r");
|
|
|
|
if (!yyin) {
|
|
|
|
perror(file);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
yyparse();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-01 19:58:29 +02:00
|
|
|
static void usage(const char *name)
|
|
|
|
{
|
2010-11-02 00:15:35 +02:00
|
|
|
fprintf(stderr,
|
2010-12-13 22:45:33 +02:00
|
|
|
"usage: %s [-d] r_mm [in.gnuplot [out.gnuplot]]\n"
|
2010-12-14 21:17:29 +02:00
|
|
|
" %s -g [-d] r_mm [in.gerber [out.gnuplot]]\n"
|
|
|
|
" %s [script]\n\n"
|
2010-11-02 00:15:35 +02:00
|
|
|
" -d put a dog-bone notch in each concave external corner\n"
|
2010-12-13 22:45:33 +02:00
|
|
|
" -g input format is KiCad Gerber, not gnuplot\n"
|
2010-12-14 21:17:29 +02:00
|
|
|
, name, name, name);
|
2010-11-01 19:58:29 +02:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
char *in = NULL, *out = NULL;
|
2010-12-14 21:17:29 +02:00
|
|
|
char *end;
|
2010-12-14 18:54:00 +02:00
|
|
|
int gerber = 0, dog_bone = 0;
|
2010-11-01 19:58:29 +02:00
|
|
|
double r;
|
|
|
|
struct path *paths;
|
2010-11-02 00:15:35 +02:00
|
|
|
int c;
|
|
|
|
|
2010-12-13 22:45:33 +02:00
|
|
|
while ((c = getopt(argc, argv, "dg")) != EOF)
|
2010-11-02 00:15:35 +02:00
|
|
|
switch (c) {
|
|
|
|
case 'd':
|
|
|
|
dog_bone = 1;
|
|
|
|
break;
|
2010-12-13 22:45:33 +02:00
|
|
|
case 'g':
|
|
|
|
gerber = 1;
|
|
|
|
break;
|
2010-11-02 00:15:35 +02:00
|
|
|
default:
|
|
|
|
usage(*argv);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (argc-optind) {
|
2010-11-01 19:58:29 +02:00
|
|
|
case 3:
|
2010-11-02 00:15:35 +02:00
|
|
|
out = argv[optind+2];
|
2010-11-01 19:58:29 +02:00
|
|
|
/* fall through */
|
|
|
|
case 2:
|
2010-11-02 00:15:35 +02:00
|
|
|
in = argv[optind+1];
|
|
|
|
/* fall through */
|
|
|
|
case 1:
|
2010-12-14 21:17:29 +02:00
|
|
|
r = strtod(argv[optind], &end);
|
|
|
|
if (*end) {
|
|
|
|
if (argc-optind != 1)
|
|
|
|
usage(*argv);
|
|
|
|
run_script(argv[optind]);
|
|
|
|
return 0;
|
|
|
|
}
|
2010-11-01 19:58:29 +02:00
|
|
|
break;
|
2010-12-14 21:17:29 +02:00
|
|
|
case 0:
|
|
|
|
run_script(NULL);
|
|
|
|
return 0;
|
2010-11-01 19:58:29 +02:00
|
|
|
default:
|
|
|
|
usage(*argv);
|
|
|
|
}
|
|
|
|
|
2010-12-13 22:45:33 +02:00
|
|
|
if (gerber)
|
|
|
|
paths = gerber_read(in, r);
|
|
|
|
else
|
|
|
|
paths = gnuplot_read(in, r);
|
2011-09-05 13:54:29 +03:00
|
|
|
paths = tool_comp_paths(paths, dog_bone, 0); /* @@@ memory leak */
|
2010-11-01 19:58:29 +02:00
|
|
|
gnuplot_write(out, paths);
|
2010-11-01 22:23:19 +02:00
|
|
|
|
2010-11-01 19:58:29 +02:00
|
|
|
return 0;
|
|
|
|
}
|