2010-11-01 19:58:29 +02:00
|
|
|
/*
|
|
|
|
* cameo.c - Toolpath adaptation and machine control
|
|
|
|
*
|
|
|
|
* Written 2010 by Werner Almesberger
|
|
|
|
* Copyright 2010 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 "path.h"
|
|
|
|
#include "gnuplot.h"
|
|
|
|
|
|
|
|
|
2010-11-01 22:23:19 +02:00
|
|
|
|
|
|
|
static void process_path(struct path *path, int inside)
|
|
|
|
{
|
|
|
|
int left;
|
|
|
|
struct path *new;
|
|
|
|
|
|
|
|
left = path_tool_is_left(path);
|
|
|
|
if (inside)
|
|
|
|
new = path_offset(path, !left, 0);
|
|
|
|
else
|
|
|
|
new = path_offset(path, left, 1);
|
|
|
|
path_replace(path, new);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void process_paths(struct path *paths)
|
|
|
|
{
|
|
|
|
struct path *leftmost, *path;
|
|
|
|
|
|
|
|
leftmost = path_find_leftmost(paths);
|
|
|
|
for (path = paths; path; path = path->next)
|
|
|
|
if (path != leftmost)
|
|
|
|
process_path(path, 1);
|
|
|
|
process_path(leftmost, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-01 19:58:29 +02:00
|
|
|
static void usage(const char *name)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "usage: %s r_mm [in.gnuplot [out.gnuplot]]\n",
|
|
|
|
name);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
char *in = NULL, *out = NULL;
|
|
|
|
double r;
|
|
|
|
struct path *paths;
|
|
|
|
|
|
|
|
switch (argc) {
|
|
|
|
case 4:
|
|
|
|
out = argv[3];
|
|
|
|
/* fall through */
|
|
|
|
case 3:
|
|
|
|
in = argv[2];
|
|
|
|
/* fall through */
|
|
|
|
case 2:
|
|
|
|
r = atof(argv[1]);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
usage(*argv);
|
|
|
|
}
|
|
|
|
|
|
|
|
paths = gnuplot_read(in, r);
|
2010-11-01 22:23:19 +02:00
|
|
|
process_paths(paths);
|
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;
|
|
|
|
}
|