Date: | 2010-11-01 23:15:35 (13 years 4 months ago) |
---|---|
Author: | Werner Almesberger |
Commit: | b47ef755ec325b6d9aebaab1fae15339002a9f7b |
Message: | 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 |
Files: |
cameo/cameo.c (4 diffs) cameo/gnuplot.c (5 diffs) cameo/path.c (2 diffs) cameo/path.h (1 diff) |
Change Details
cameo/cameo.c | ||
---|---|---|
13 | 13 | |
14 | 14 | #include <stdlib.h> |
15 | 15 | #include <stdio.h> |
16 | #include <unistd.h> | |
16 | 17 | |
17 | 18 | #include "path.h" |
18 | 19 | #include "gnuplot.h" |
19 | 20 | |
20 | 21 | |
22 | static int dog_bone = 0; | |
23 | ||
21 | 24 | |
22 | 25 | static void process_path(struct path *path, int inside) |
23 | 26 | { |
... | ... | |
26 | 29 | |
27 | 30 | left = path_tool_is_left(path); |
28 | 31 | if (inside) |
29 | new = path_offset(path, !left, 0); | |
32 | new = path_offset(path, !left, path->notch); | |
30 | 33 | else |
31 | new = path_offset(path, left, 1); | |
34 | new = path_offset(path, left, path->notch || dog_bone); | |
32 | 35 | path_replace(path, new); |
33 | 36 | } |
34 | 37 | |
... | ... | |
61 | 64 | |
62 | 65 | static void usage(const char *name) |
63 | 66 | { |
64 | fprintf(stderr, "usage: %s r_mm [in.gnuplot [out.gnuplot]]\n", | |
65 | name); | |
67 | fprintf(stderr, | |
68 | "usage: %s [-d] r_mm [in.gnuplot [out.gnuplot]]\n\n" | |
69 | " -d put a dog-bone notch in each concave external corner\n" | |
70 | , name); | |
66 | 71 | exit(1); |
67 | 72 | } |
68 | 73 | |
... | ... | |
72 | 77 | char *in = NULL, *out = NULL; |
73 | 78 | double r; |
74 | 79 | struct path *paths; |
75 | ||
76 | switch (argc) { | |
77 | case 4: | |
78 | out = argv[3]; | |
79 | /* fall through */ | |
80 | int c; | |
81 | ||
82 | while ((c = getopt(argc, argv, "d")) != EOF) | |
83 | switch (c) { | |
84 | case 'd': | |
85 | dog_bone = 1; | |
86 | break; | |
87 | default: | |
88 | usage(*argv); | |
89 | } | |
90 | ||
91 | switch (argc-optind) { | |
80 | 92 | case 3: |
81 | in = argv[2]; | |
93 | out = argv[optind+2]; | |
82 | 94 | /* fall through */ |
83 | 95 | case 2: |
84 | r = atof(argv[1]); | |
96 | in = argv[optind+1]; | |
97 | /* fall through */ | |
98 | case 1: | |
99 | r = atof(argv[optind]); | |
85 | 100 | break; |
86 | 101 | default: |
87 | 102 | usage(*argv); |
cameo/gnuplot.c | ||
---|---|---|
26 | 26 | char buf[1024]; |
27 | 27 | double x, y, z, tmp; |
28 | 28 | double r_tool = r_tool_default; |
29 | int outside = 0; | |
29 | int outside = 0, notch = 0; | |
30 | 30 | int n; |
31 | 31 | struct path *paths = NULL, *path = NULL; |
32 | 32 | struct path **lnk = &paths; |
... | ... | |
43 | 43 | r_tool = tmp; |
44 | 44 | if (!strcmp(buf, "#%outside\n")) |
45 | 45 | outside = 1; |
46 | if (!strcmp(buf, "#%notch\n")) | |
47 | notch = 1; | |
46 | 48 | if (*buf == '#') |
47 | 49 | continue; |
48 | 50 | n = sscanf(buf, "%lf %lf %lf\n", &x, &y, &z); |
... | ... | |
50 | 52 | case -1: |
51 | 53 | path = NULL; |
52 | 54 | r_tool = r_tool_default; |
53 | outside = 0; | |
55 | outside = notch = 0; | |
54 | 56 | continue; |
55 | 57 | case 2: |
56 | 58 | z = 0; |
... | ... | |
66 | 68 | if (!path) { |
67 | 69 | path = path_new(r_tool); |
68 | 70 | path->outside = outside; |
71 | path->notch = notch; | |
69 | 72 | *lnk = path; |
70 | 73 | lnk = &path->next; |
71 | 74 | } |
... | ... | |
89 | 92 | return 0; |
90 | 93 | if (path->outside && fprintf(file, "#%%outside\n") < 0) |
91 | 94 | return 0; |
95 | if (path->notch && fprintf(file, "#%%notch\n") < 0) | |
96 | return 0; | |
92 | 97 | for (p = path->first; p; p = p->next) |
93 | 98 | if (fprintf(file, "%f %f %f\n", p->x, p->y, p->z) < 0) |
94 | 99 | return 0; |
cameo/path.c | ||
---|---|---|
46 | 46 | path = alloc_type(struct path); |
47 | 47 | path->r_tool = r_tool; |
48 | 48 | path->outside = 0; |
49 | path->notch = 0; | |
49 | 50 | path->first = path->last = NULL; |
50 | 51 | path->next = NULL; |
51 | 52 | return path; |
... | ... | |
58 | 59 | |
59 | 60 | new = path_new(old->r_tool); |
60 | 61 | new->outside = old->outside; |
62 | new->notch = old->notch; | |
61 | 63 | return new; |
62 | 64 | } |
63 | 65 |
cameo/path.h | ||
---|---|---|
24 | 24 | struct point *first, *last; |
25 | 25 | double r_tool; /* mm */ |
26 | 26 | int outside; /* non-zero to mark path as an outside edge */ |
27 | int notch; /* non-zero to enable dog-boning for path */ | |
27 | 28 | struct path *next; |
28 | 29 | }; |
29 | 30 |
Branches:
master