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
1313
1414#include <stdlib.h>
1515#include <stdio.h>
16#include <unistd.h>
1617
1718#include "path.h"
1819#include "gnuplot.h"
1920
2021
22static int dog_bone = 0;
23
2124
2225static void process_path(struct path *path, int inside)
2326{
...... 
2629
2730    left = path_tool_is_left(path);
2831    if (inside)
29        new = path_offset(path, !left, 0);
32        new = path_offset(path, !left, path->notch);
3033    else
31        new = path_offset(path, left, 1);
34        new = path_offset(path, left, path->notch || dog_bone);
3235    path_replace(path, new);
3336}
3437
...... 
6164
6265static void usage(const char *name)
6366{
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);
6671    exit(1);
6772}
6873
...... 
7277    char *in = NULL, *out = NULL;
7378    double r;
7479    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) {
8092    case 3:
81        in = argv[2];
93        out = argv[optind+2];
8294        /* fall through */
8395    case 2:
84        r = atof(argv[1]);
96        in = argv[optind+1];
97        /* fall through */
98    case 1:
99        r = atof(argv[optind]);
85100        break;
86101    default:
87102        usage(*argv);
cameo/gnuplot.c
2626    char buf[1024];
2727    double x, y, z, tmp;
2828    double r_tool = r_tool_default;
29    int outside = 0;
29    int outside = 0, notch = 0;
3030    int n;
3131    struct path *paths = NULL, *path = NULL;
3232    struct path **lnk = &paths;
...... 
4343            r_tool = tmp;
4444        if (!strcmp(buf, "#%outside\n"))
4545            outside = 1;
46        if (!strcmp(buf, "#%notch\n"))
47            notch = 1;
4648        if (*buf == '#')
4749            continue;
4850        n = sscanf(buf, "%lf %lf %lf\n", &x, &y, &z);
...... 
5052        case -1:
5153            path = NULL;
5254            r_tool = r_tool_default;
53            outside = 0;
55            outside = notch = 0;
5456            continue;
5557        case 2:
5658            z = 0;
...... 
6668        if (!path) {
6769            path = path_new(r_tool);
6870            path->outside = outside;
71            path->notch = notch;
6972            *lnk = path;
7073            lnk = &path->next;
7174        }
...... 
8992            return 0;
9093        if (path->outside && fprintf(file, "#%%outside\n") < 0)
9194            return 0;
95        if (path->notch && fprintf(file, "#%%notch\n") < 0)
96            return 0;
9297        for (p = path->first; p; p = p->next)
9398            if (fprintf(file, "%f %f %f\n", p->x, p->y, p->z) < 0)
9499                return 0;
cameo/path.c
4646    path = alloc_type(struct path);
4747    path->r_tool = r_tool;
4848    path->outside = 0;
49    path->notch = 0;
4950    path->first = path->last = NULL;
5051    path->next = NULL;
5152    return path;
...... 
5859
5960    new = path_new(old->r_tool);
6061    new->outside = old->outside;
62    new->notch = old->notch;
6163    return new;
6264}
6365
cameo/path.h
2424    struct point *first, *last;
2525    double r_tool; /* mm */
2626    int outside; /* non-zero to mark path as an outside edge */
27    int notch; /* non-zero to enable dog-boning for path */
2728    struct path *next;
2829};
2930

Archive Download the corresponding diff file

Branches:
master



interactive