1
0
mirror of git://projects.qi-hardware.com/cae-tools.git synced 2024-12-23 11:12:05 +02:00
cae-tools/cameo/ops.c
Werner Almesberger b1652fc50a cameo: adding support for dril/mill substitutions (in progress)
- Makefile (OBJS): added shape.o
- README: added section for drill/mill substitutions
- lang.l, lang.y: added commands "drill", "empty", "mill", "remainder", and
  "reset"
- lang.y (clear_paths): moved freeing of all paths from "clean" to shared
  function clear_paths
- ops.h, ops.c (try_drill, try_mill): helper functions for "drill" and
  "mill" commands
- shape.h. shape.c (slot, circle): functions to generate toolpaths for
  basic shapes
2010-12-15 04:56:58 -03:00

91 lines
2.4 KiB
C

/*
* ops.c - Higher-level toolpath operations
*
* Written 2010 by Werner Almesberger
* Copyright 2010 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
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*/
#include <stddef.h>
#include "path.h"
#include "shape.h"
#include "ops.h"
static void tool_comp_1(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);
else
new = path_offset(path, left, path->notch || dog_bone);
path_replace(path, new);
}
void tool_comp_paths(struct path *paths, int dog_bone, int all_inside)
{
struct path *leftmost, *path;
/*
* We don't have an algorithm (yet) that can detect which paths are
* inside other paths. Therefore, we fake it by looking for the path
* that contains lowest x coordinate. This ought to be the outer
* boundary of the piece.
*
* Note that this heuristic falls apart when a job consists of
* multiple pieces. In this case, the #%outside hint can be used to
* explicitly tell cameo to treat the path as an outside edge.
*/
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 (!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);
}
struct path *try_drill(struct path *path, double d_min, double d_max)
{
struct path *new;
if (path->r_tool*2 < d_min || path->r_tool*2 > d_max)
return NULL;
if (!path->first || path->first != path->last)
return NULL;
new = path_new((d_min+d_max)/2); /* @@@ fishy */
path_add(new, path->first->x, path->first->y, path->first->z);
return new;
}
struct path *try_mill(struct path *path, double diam, double step)
{
if (path->r_tool*2 < diam)
return NULL;
if (!path->first)
return NULL;
if (path->first == path->last)
return circle(path->first->x, path->first->y, path->first->z,
path->r_tool, diam/2, step);
if (path->first->next == path->last)
return slot(path->first->x, path->first->y,
path->first->next->x, path->first->next->y,
path->first->z, path->r_tool, diam/2, step);
return NULL;
}