1
0
mirror of git://projects.qi-hardware.com/cae-tools.git synced 2024-12-22 23:04:16 +02:00

cameo/: make tool_comp_paths output paths in the order processed

This commit is contained in:
Werner Almesberger 2011-09-05 07:54:29 -03:00
parent 828763b747
commit 639b0fa2d6
6 changed files with 31 additions and 33 deletions

View File

@ -1,8 +1,8 @@
/*
* cameo.c - Toolpath adaptation and machine control
*
* Written 2010 by Werner Almesberger
* Copyright 2010 Werner Almesberger
* Written 2010-2011 by Werner Almesberger
* Copyright 2010-2011 Werner Almesberger
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -100,7 +100,7 @@ int main(int argc, char **argv)
paths = gerber_read(in, r);
else
paths = gnuplot_read(in, r);
tool_comp_paths(paths, dog_bone, 0);
paths = tool_comp_paths(paths, dog_bone, 0); /* @@@ memory leak */
gnuplot_write(out, paths);
return 0;

View File

@ -243,8 +243,12 @@ command:
}
| TOK_OFFSET offset_options
{
tool_comp_paths(paths,
struct path *new;
new = tool_comp_paths(paths,
!!($2 & OO_DOG), !!($2 & OO_INSIDE));
clear_paths();
paths = new;
}
| TOK_OPTIMIZE
{

View File

@ -19,23 +19,24 @@
#include "ops.h"
static void tool_comp_1(struct path *path, int inside, int dog_bone)
static struct path *tool_comp_1(const struct path *path, int inside,
int dog_bone)
{
int left;
struct path *new;
left = path_tool_is_left(path);
if (inside)
new = path_offset(path, !left, path->notch);
return path_offset(path, !left, path->notch);
else
new = path_offset(path, left, path->notch || dog_bone);
path_replace(path, new);
return path_offset(path, left, path->notch || dog_bone);
}
void tool_comp_paths(struct path *paths, int dog_bone, int all_inside)
struct path *tool_comp_paths(const struct path *paths, int dog_bone,
int all_inside)
{
struct path *leftmost, *path;
const struct path *leftmost, *path;
struct path *new = NULL, **anchor = &new;
/*
* We don't have an algorithm (yet) that can detect which paths are
@ -50,13 +51,18 @@ void tool_comp_paths(struct path *paths, int dog_bone, int all_inside)
leftmost = path_find_leftmost(paths);
for (path = paths; path; path = path->next)
if (path != leftmost && (all_inside || !path->outside))
tool_comp_1(path, 1, dog_bone);
if (path != leftmost && (all_inside || !path->outside)) {
*anchor = tool_comp_1(path, 1, dog_bone);
anchor = &(*anchor)->next;
}
if (!all_inside)
for (path = paths; path; path = path->next)
if (path != leftmost && path->outside)
tool_comp_1(path, 0, dog_bone);
tool_comp_1(leftmost, all_inside, dog_bone);
if (path != leftmost && path->outside) {
*anchor = tool_comp_1(path, 0, dog_bone);
anchor = &(*anchor)->next;
}
*anchor = tool_comp_1(leftmost, all_inside, dog_bone);
return new;
}

View File

@ -17,7 +17,8 @@
#include "path.h"
void tool_comp_paths(struct path *paths, int dog_bone, int all_inside);
struct path *tool_comp_paths(const struct path *paths, int dog_bone,
int all_inside);
struct path *try_drill(struct path *path, double d_min, double d_max);
struct path *try_mill(struct path *path, double diam, double step, int any);
struct path *optimize_paths(struct path *paths);

View File

@ -134,18 +134,6 @@ void path_add(struct path *path, double x, double y, double z)
}
void path_replace(struct path *old, struct path *new)
{
struct path *next = old->next;
free_points(old->first);
free((void *) old->id);
*old = *new;
old->next = next;
free(new);
}
struct path *path_reverse(const struct path *path)
{
struct path *new;
@ -348,10 +336,10 @@ struct path *path_offset(const struct path *path, int left, int notch)
}
struct path *path_find_leftmost(struct path *path)
const struct path *path_find_leftmost(const struct path *path)
{
const struct point *p;
struct path *best = NULL;
const struct path *best = NULL;
double best_x = HUGE_VAL;
while (path) {

View File

@ -32,11 +32,10 @@ struct path {
struct path *path_new(double r_tool, const char *id);
void path_add(struct path *path, double x, double y, double z);
void path_replace(struct path *old, struct path *new);
struct path *path_reverse(const struct path *path);
int path_tool_is_left(const struct path *path);
struct path *path_offset(const struct path *path, int left, int notch);
struct path *path_find_leftmost(struct path *path);
const struct path *path_find_leftmost(const struct path *path);
void path_free(struct path *path);
struct path *path_connect(struct path *path);
void path_stats(const struct path *path);