mirror of
git://projects.qi-hardware.com/cae-tools.git
synced 2024-12-23 03:22:25 +02:00
Dogbone notches are now optional and can be set in the gnuplot file.
- cameo/cameo.c (main): use getopt - cameo/cameo.c (main, usage, process_path): option -d to enable dog-bone notches (they're now disabled by default) - cameo/path.h (struct path), cameo/path.c (path_new, path_from): added attribute "notch" to enable notches for a path - cameo/gnuplot.c (gnuplot_read, gnuplot_do_write): read and write the #%notch hint
This commit is contained in:
parent
d77b4c8570
commit
b47ef755ec
@ -13,11 +13,14 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "path.h"
|
||||
#include "gnuplot.h"
|
||||
|
||||
|
||||
static int dog_bone = 0;
|
||||
|
||||
|
||||
static void process_path(struct path *path, int inside)
|
||||
{
|
||||
@ -26,9 +29,9 @@ static void process_path(struct path *path, int inside)
|
||||
|
||||
left = path_tool_is_left(path);
|
||||
if (inside)
|
||||
new = path_offset(path, !left, 0);
|
||||
new = path_offset(path, !left, path->notch);
|
||||
else
|
||||
new = path_offset(path, left, 1);
|
||||
new = path_offset(path, left, path->notch || dog_bone);
|
||||
path_replace(path, new);
|
||||
}
|
||||
|
||||
@ -61,8 +64,10 @@ static void process_paths(struct path *paths)
|
||||
|
||||
static void usage(const char *name)
|
||||
{
|
||||
fprintf(stderr, "usage: %s r_mm [in.gnuplot [out.gnuplot]]\n",
|
||||
name);
|
||||
fprintf(stderr,
|
||||
"usage: %s [-d] r_mm [in.gnuplot [out.gnuplot]]\n\n"
|
||||
" -d put a dog-bone notch in each concave external corner\n"
|
||||
, name);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@ -72,16 +77,26 @@ int main(int argc, char **argv)
|
||||
char *in = NULL, *out = NULL;
|
||||
double r;
|
||||
struct path *paths;
|
||||
int c;
|
||||
|
||||
switch (argc) {
|
||||
case 4:
|
||||
out = argv[3];
|
||||
/* fall through */
|
||||
while ((c = getopt(argc, argv, "d")) != EOF)
|
||||
switch (c) {
|
||||
case 'd':
|
||||
dog_bone = 1;
|
||||
break;
|
||||
default:
|
||||
usage(*argv);
|
||||
}
|
||||
|
||||
switch (argc-optind) {
|
||||
case 3:
|
||||
in = argv[2];
|
||||
out = argv[optind+2];
|
||||
/* fall through */
|
||||
case 2:
|
||||
r = atof(argv[1]);
|
||||
in = argv[optind+1];
|
||||
/* fall through */
|
||||
case 1:
|
||||
r = atof(argv[optind]);
|
||||
break;
|
||||
default:
|
||||
usage(*argv);
|
||||
|
@ -26,7 +26,7 @@ struct path *gnuplot_read(const char *name, double r_tool_default)
|
||||
char buf[1024];
|
||||
double x, y, z, tmp;
|
||||
double r_tool = r_tool_default;
|
||||
int outside = 0;
|
||||
int outside = 0, notch = 0;
|
||||
int n;
|
||||
struct path *paths = NULL, *path = NULL;
|
||||
struct path **lnk = &paths;
|
||||
@ -43,6 +43,8 @@ struct path *gnuplot_read(const char *name, double r_tool_default)
|
||||
r_tool = tmp;
|
||||
if (!strcmp(buf, "#%outside\n"))
|
||||
outside = 1;
|
||||
if (!strcmp(buf, "#%notch\n"))
|
||||
notch = 1;
|
||||
if (*buf == '#')
|
||||
continue;
|
||||
n = sscanf(buf, "%lf %lf %lf\n", &x, &y, &z);
|
||||
@ -50,7 +52,7 @@ struct path *gnuplot_read(const char *name, double r_tool_default)
|
||||
case -1:
|
||||
path = NULL;
|
||||
r_tool = r_tool_default;
|
||||
outside = 0;
|
||||
outside = notch = 0;
|
||||
continue;
|
||||
case 2:
|
||||
z = 0;
|
||||
@ -66,6 +68,7 @@ struct path *gnuplot_read(const char *name, double r_tool_default)
|
||||
if (!path) {
|
||||
path = path_new(r_tool);
|
||||
path->outside = outside;
|
||||
path->notch = notch;
|
||||
*lnk = path;
|
||||
lnk = &path->next;
|
||||
}
|
||||
@ -89,6 +92,8 @@ static int gnuplot_do_write(FILE *file, const struct path *paths)
|
||||
return 0;
|
||||
if (path->outside && fprintf(file, "#%%outside\n") < 0)
|
||||
return 0;
|
||||
if (path->notch && fprintf(file, "#%%notch\n") < 0)
|
||||
return 0;
|
||||
for (p = path->first; p; p = p->next)
|
||||
if (fprintf(file, "%f %f %f\n", p->x, p->y, p->z) < 0)
|
||||
return 0;
|
||||
|
@ -46,6 +46,7 @@ struct path *path_new(double r_tool)
|
||||
path = alloc_type(struct path);
|
||||
path->r_tool = r_tool;
|
||||
path->outside = 0;
|
||||
path->notch = 0;
|
||||
path->first = path->last = NULL;
|
||||
path->next = NULL;
|
||||
return path;
|
||||
@ -58,6 +59,7 @@ static struct path *path_from(const struct path *old)
|
||||
|
||||
new = path_new(old->r_tool);
|
||||
new->outside = old->outside;
|
||||
new->notch = old->notch;
|
||||
return new;
|
||||
}
|
||||
|
||||
|
@ -24,6 +24,7 @@ struct path {
|
||||
struct point *first, *last;
|
||||
double r_tool; /* mm */
|
||||
int outside; /* non-zero to mark path as an outside edge */
|
||||
int notch; /* non-zero to enable dog-boning for path */
|
||||
struct path *next;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user