Date:2011-09-05 12:54:29 (12 years 6 months ago)
Author:Werner Almesberger
Commit:639b0fa2d6349a7891f2c47c4d3a74338ff3ba93
Message:cameo/: make tool_comp_paths output paths in the order processed

Files: cameo/cameo.c (2 diffs)
cameo/lang.y (1 diff)
cameo/ops.c (2 diffs)
cameo/ops.h (1 diff)
cameo/path.c (2 diffs)
cameo/path.h (1 diff)

Change Details

cameo/cameo.c
11/*
22 * cameo.c - Toolpath adaptation and machine control
33 *
4 * Written 2010 by Werner Almesberger
5 * Copyright 2010 Werner Almesberger
4 * Written 2010-2011 by Werner Almesberger
5 * Copyright 2010-2011 Werner Almesberger
66 *
77 * This program is free software; you can redistribute it and/or modify
88 * it under the terms of the GNU General Public License as published by
...... 
100100        paths = gerber_read(in, r);
101101    else
102102        paths = gnuplot_read(in, r);
103    tool_comp_paths(paths, dog_bone, 0);
103    paths = tool_comp_paths(paths, dog_bone, 0); /* @@@ memory leak */
104104    gnuplot_write(out, paths);
105105
106106    return 0;
cameo/lang.y
243243        }
244244    | TOK_OFFSET offset_options
245245        {
246            tool_comp_paths(paths,
246            struct path *new;
247
248            new = tool_comp_paths(paths,
247249                !!($2 & OO_DOG), !!($2 & OO_INSIDE));
250            clear_paths();
251            paths = new;
248252        }
249253    | TOK_OPTIMIZE
250254        {
cameo/ops.c
1919#include "ops.h"
2020
2121
22static void tool_comp_1(struct path *path, int inside, int dog_bone)
22static struct path *tool_comp_1(const struct path *path, int inside,
23    int dog_bone)
2324{
2425    int left;
25    struct path *new;
2626
2727    left = path_tool_is_left(path);
2828    if (inside)
29        new = path_offset(path, !left, path->notch);
29        return path_offset(path, !left, path->notch);
3030    else
31        new = path_offset(path, left, path->notch || dog_bone);
32    path_replace(path, new);
31        return path_offset(path, left, path->notch || dog_bone);
3332}
3433
3534
36void tool_comp_paths(struct path *paths, int dog_bone, int all_inside)
35struct path *tool_comp_paths(const struct path *paths, int dog_bone,
36    int all_inside)
3737{
38    struct path *leftmost, *path;
38    const struct path *leftmost, *path;
39    struct path *new = NULL, **anchor = &new;
3940
4041    /*
4142     * We don't have an algorithm (yet) that can detect which paths are
...... 
5051
5152    leftmost = path_find_leftmost(paths);
5253    for (path = paths; path; path = path->next)
53        if (path != leftmost && (all_inside || !path->outside))
54            tool_comp_1(path, 1, dog_bone);
54        if (path != leftmost && (all_inside || !path->outside)) {
55            *anchor = tool_comp_1(path, 1, dog_bone);
56            anchor = &(*anchor)->next;
57        }
5558    if (!all_inside)
5659        for (path = paths; path; path = path->next)
57            if (path != leftmost && path->outside)
58                tool_comp_1(path, 0, dog_bone);
59    tool_comp_1(leftmost, all_inside, dog_bone);
60            if (path != leftmost && path->outside) {
61                *anchor = tool_comp_1(path, 0, dog_bone);
62                anchor = &(*anchor)->next;
63            }
64    *anchor = tool_comp_1(leftmost, all_inside, dog_bone);
65    return new;
6066}
6167
6268
cameo/ops.h
1717#include "path.h"
1818
1919
20void tool_comp_paths(struct path *paths, int dog_bone, int all_inside);
20struct path *tool_comp_paths(const struct path *paths, int dog_bone,
21    int all_inside);
2122struct path *try_drill(struct path *path, double d_min, double d_max);
2223struct path *try_mill(struct path *path, double diam, double step, int any);
2324struct path *optimize_paths(struct path *paths);
cameo/path.c
134134}
135135
136136
137void path_replace(struct path *old, struct path *new)
138{
139    struct path *next = old->next;
140
141    free_points(old->first);
142    free((void *) old->id);
143    *old = *new;
144    old->next = next;
145    free(new);
146}
147
148
149137struct path *path_reverse(const struct path *path)
150138{
151139    struct path *new;
...... 
348336}
349337
350338
351struct path *path_find_leftmost(struct path *path)
339const struct path *path_find_leftmost(const struct path *path)
352340{
353341    const struct point *p;
354    struct path *best = NULL;
342    const struct path *best = NULL;
355343    double best_x = HUGE_VAL;
356344
357345    while (path) {
cameo/path.h
3232
3333struct path *path_new(double r_tool, const char *id);
3434void path_add(struct path *path, double x, double y, double z);
35void path_replace(struct path *old, struct path *new);
3635struct path *path_reverse(const struct path *path);
3736int path_tool_is_left(const struct path *path);
3837struct path *path_offset(const struct path *path, int left, int notch);
39struct path *path_find_leftmost(struct path *path);
38const struct path *path_find_leftmost(const struct path *path);
4039void path_free(struct path *path);
4140struct path *path_connect(struct path *path);
4241void path_stats(const struct path *path);

Archive Download the corresponding diff file

Branches:
master



interactive