mirror of
git://projects.qi-hardware.com/cae-tools.git
synced 2024-12-23 08:39:33 +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 <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "path.h"
|
#include "path.h"
|
||||||
#include "gnuplot.h"
|
#include "gnuplot.h"
|
||||||
|
|
||||||
|
|
||||||
|
static int dog_bone = 0;
|
||||||
|
|
||||||
|
|
||||||
static void process_path(struct path *path, int inside)
|
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);
|
left = path_tool_is_left(path);
|
||||||
if (inside)
|
if (inside)
|
||||||
new = path_offset(path, !left, 0);
|
new = path_offset(path, !left, path->notch);
|
||||||
else
|
else
|
||||||
new = path_offset(path, left, 1);
|
new = path_offset(path, left, path->notch || dog_bone);
|
||||||
path_replace(path, new);
|
path_replace(path, new);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,8 +64,10 @@ static void process_paths(struct path *paths)
|
|||||||
|
|
||||||
static void usage(const char *name)
|
static void usage(const char *name)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "usage: %s r_mm [in.gnuplot [out.gnuplot]]\n",
|
fprintf(stderr,
|
||||||
name);
|
"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);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,16 +77,26 @@ int main(int argc, char **argv)
|
|||||||
char *in = NULL, *out = NULL;
|
char *in = NULL, *out = NULL;
|
||||||
double r;
|
double r;
|
||||||
struct path *paths;
|
struct path *paths;
|
||||||
|
int c;
|
||||||
|
|
||||||
switch (argc) {
|
while ((c = getopt(argc, argv, "d")) != EOF)
|
||||||
case 4:
|
switch (c) {
|
||||||
out = argv[3];
|
case 'd':
|
||||||
/* fall through */
|
dog_bone = 1;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
usage(*argv);
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (argc-optind) {
|
||||||
case 3:
|
case 3:
|
||||||
in = argv[2];
|
out = argv[optind+2];
|
||||||
/* fall through */
|
/* fall through */
|
||||||
case 2:
|
case 2:
|
||||||
r = atof(argv[1]);
|
in = argv[optind+1];
|
||||||
|
/* fall through */
|
||||||
|
case 1:
|
||||||
|
r = atof(argv[optind]);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
usage(*argv);
|
usage(*argv);
|
||||||
|
@ -26,7 +26,7 @@ struct path *gnuplot_read(const char *name, double r_tool_default)
|
|||||||
char buf[1024];
|
char buf[1024];
|
||||||
double x, y, z, tmp;
|
double x, y, z, tmp;
|
||||||
double r_tool = r_tool_default;
|
double r_tool = r_tool_default;
|
||||||
int outside = 0;
|
int outside = 0, notch = 0;
|
||||||
int n;
|
int n;
|
||||||
struct path *paths = NULL, *path = NULL;
|
struct path *paths = NULL, *path = NULL;
|
||||||
struct path **lnk = &paths;
|
struct path **lnk = &paths;
|
||||||
@ -43,6 +43,8 @@ struct path *gnuplot_read(const char *name, double r_tool_default)
|
|||||||
r_tool = tmp;
|
r_tool = tmp;
|
||||||
if (!strcmp(buf, "#%outside\n"))
|
if (!strcmp(buf, "#%outside\n"))
|
||||||
outside = 1;
|
outside = 1;
|
||||||
|
if (!strcmp(buf, "#%notch\n"))
|
||||||
|
notch = 1;
|
||||||
if (*buf == '#')
|
if (*buf == '#')
|
||||||
continue;
|
continue;
|
||||||
n = sscanf(buf, "%lf %lf %lf\n", &x, &y, &z);
|
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:
|
case -1:
|
||||||
path = NULL;
|
path = NULL;
|
||||||
r_tool = r_tool_default;
|
r_tool = r_tool_default;
|
||||||
outside = 0;
|
outside = notch = 0;
|
||||||
continue;
|
continue;
|
||||||
case 2:
|
case 2:
|
||||||
z = 0;
|
z = 0;
|
||||||
@ -66,6 +68,7 @@ struct path *gnuplot_read(const char *name, double r_tool_default)
|
|||||||
if (!path) {
|
if (!path) {
|
||||||
path = path_new(r_tool);
|
path = path_new(r_tool);
|
||||||
path->outside = outside;
|
path->outside = outside;
|
||||||
|
path->notch = notch;
|
||||||
*lnk = path;
|
*lnk = path;
|
||||||
lnk = &path->next;
|
lnk = &path->next;
|
||||||
}
|
}
|
||||||
@ -89,6 +92,8 @@ static int gnuplot_do_write(FILE *file, const struct path *paths)
|
|||||||
return 0;
|
return 0;
|
||||||
if (path->outside && fprintf(file, "#%%outside\n") < 0)
|
if (path->outside && fprintf(file, "#%%outside\n") < 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
if (path->notch && fprintf(file, "#%%notch\n") < 0)
|
||||||
|
return 0;
|
||||||
for (p = path->first; p; p = p->next)
|
for (p = path->first; p; p = p->next)
|
||||||
if (fprintf(file, "%f %f %f\n", p->x, p->y, p->z) < 0)
|
if (fprintf(file, "%f %f %f\n", p->x, p->y, p->z) < 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -46,6 +46,7 @@ struct path *path_new(double r_tool)
|
|||||||
path = alloc_type(struct path);
|
path = alloc_type(struct path);
|
||||||
path->r_tool = r_tool;
|
path->r_tool = r_tool;
|
||||||
path->outside = 0;
|
path->outside = 0;
|
||||||
|
path->notch = 0;
|
||||||
path->first = path->last = NULL;
|
path->first = path->last = NULL;
|
||||||
path->next = NULL;
|
path->next = NULL;
|
||||||
return path;
|
return path;
|
||||||
@ -58,6 +59,7 @@ static struct path *path_from(const struct path *old)
|
|||||||
|
|
||||||
new = path_new(old->r_tool);
|
new = path_new(old->r_tool);
|
||||||
new->outside = old->outside;
|
new->outside = old->outside;
|
||||||
|
new->notch = old->notch;
|
||||||
return new;
|
return new;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ struct path {
|
|||||||
struct point *first, *last;
|
struct point *first, *last;
|
||||||
double r_tool; /* mm */
|
double r_tool; /* mm */
|
||||||
int outside; /* non-zero to mark path as an outside edge */
|
int outside; /* non-zero to mark path as an outside edge */
|
||||||
|
int notch; /* non-zero to enable dog-boning for path */
|
||||||
struct path *next;
|
struct path *next;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user