mirror of
git://projects.qi-hardware.com/cae-tools.git
synced 2024-12-22 23:26:27 +02:00
cameo/: new gnuplot tag #%id= with generator-assigned identifier
Excellon and Gerber store the file name there.
This commit is contained in:
parent
41bffa8f79
commit
a42a18fef3
@ -159,7 +159,7 @@ static void header(FILE *file)
|
|||||||
/* ----- body parsing ------------------------------------------------------ */
|
/* ----- body parsing ------------------------------------------------------ */
|
||||||
|
|
||||||
|
|
||||||
static int do_cmd(char cmd, double v, int nl)
|
static int do_cmd(char cmd, double v, int nl, const char *name)
|
||||||
{
|
{
|
||||||
static int metric = 1;
|
static int metric = 1;
|
||||||
static int slotting = 0;
|
static int slotting = 0;
|
||||||
@ -220,7 +220,7 @@ static int do_cmd(char cmd, double v, int nl)
|
|||||||
if (!metric)
|
if (!metric)
|
||||||
v = IN2MM(v);
|
v = IN2MM(v);
|
||||||
if (slotting) {
|
if (slotting) {
|
||||||
*anchor = path_new(d/2);
|
*anchor = path_new(d/2, name);
|
||||||
path_add(*anchor, x0, y, 0);
|
path_add(*anchor, x0, y, 0);
|
||||||
path_add(*anchor, x, v, 0);
|
path_add(*anchor, x, v, 0);
|
||||||
anchor = &(*anchor)->next;
|
anchor = &(*anchor)->next;
|
||||||
@ -229,7 +229,7 @@ static int do_cmd(char cmd, double v, int nl)
|
|||||||
}
|
}
|
||||||
if (nl) {
|
if (nl) {
|
||||||
assert(d);
|
assert(d);
|
||||||
*anchor = path_new(d/2);
|
*anchor = path_new(d/2, name);
|
||||||
path_add(*anchor, x, v, 0);
|
path_add(*anchor, x, v, 0);
|
||||||
anchor = &(*anchor)->next;
|
anchor = &(*anchor)->next;
|
||||||
break;
|
break;
|
||||||
@ -245,7 +245,7 @@ static int do_cmd(char cmd, double v, int nl)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void body(FILE *file)
|
static void body(FILE *file, const char *name)
|
||||||
{
|
{
|
||||||
char cmd = 0;
|
char cmd = 0;
|
||||||
double v = 0, f = 1;
|
double v = 0, f = 1;
|
||||||
@ -255,7 +255,7 @@ static void body(FILE *file)
|
|||||||
if (c == '\n') {
|
if (c == '\n') {
|
||||||
lineno++;
|
lineno++;
|
||||||
if (cmd)
|
if (cmd)
|
||||||
do_cmd(cmd, s ? -v : v, 1);
|
do_cmd(cmd, s ? -v : v, 1, name);
|
||||||
cmd = 0;
|
cmd = 0;
|
||||||
} else if (isdigit(c)) {
|
} else if (isdigit(c)) {
|
||||||
if (f == 1)
|
if (f == 1)
|
||||||
@ -270,7 +270,7 @@ static void body(FILE *file)
|
|||||||
s = !s;
|
s = !s;
|
||||||
} else {
|
} else {
|
||||||
if (cmd)
|
if (cmd)
|
||||||
if (!do_cmd(cmd, s ? -v : v, 0))
|
if (!do_cmd(cmd, s ? -v : v, 0, name))
|
||||||
return;
|
return;
|
||||||
cmd = c;
|
cmd = c;
|
||||||
v = 0;
|
v = 0;
|
||||||
@ -296,7 +296,7 @@ struct path *excellon_read(const char *name)
|
|||||||
anchor = &paths;
|
anchor = &paths;
|
||||||
|
|
||||||
header(file);
|
header(file);
|
||||||
body(file);
|
body(file, name);
|
||||||
|
|
||||||
fclose(file);
|
fclose(file);
|
||||||
return paths;
|
return paths;
|
||||||
|
@ -72,7 +72,7 @@ struct path *gerber_read(const char *name, double r_tool_default)
|
|||||||
switch (d) {
|
switch (d) {
|
||||||
case 1:
|
case 1:
|
||||||
if (!path) {
|
if (!path) {
|
||||||
path = path_new(r_tool_default);
|
path = path_new(r_tool_default, name);
|
||||||
*anchor = path;
|
*anchor = path;
|
||||||
anchor = &path->next;
|
anchor = &path->next;
|
||||||
path_add(path, start_x, start_y, 0);
|
path_add(path, start_x, start_y, 0);
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* gnuplot.c - Gnuplot file input/output
|
* gnuplot.c - Gnuplot file input/output
|
||||||
*
|
*
|
||||||
* Written 2010 by Werner Almesberger
|
* Written 2010-2011 by Werner Almesberger
|
||||||
* Copyright 2010 Werner Almesberger
|
* Copyright 2010-2011 Werner Almesberger
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -16,6 +16,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
#include "util.h"
|
||||||
#include "path.h"
|
#include "path.h"
|
||||||
#include "gnuplot.h"
|
#include "gnuplot.h"
|
||||||
|
|
||||||
@ -25,6 +26,7 @@ struct path *gnuplot_read(const char *name, double r_tool_default)
|
|||||||
FILE *file;
|
FILE *file;
|
||||||
int lineno = 0;
|
int lineno = 0;
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
|
char *id = NULL, *s;
|
||||||
double x, y, z, tmp;
|
double x, y, z, tmp;
|
||||||
double r_tool = r_tool_default;
|
double r_tool = r_tool_default;
|
||||||
int outside = 0, notch = 0;
|
int outside = 0, notch = 0;
|
||||||
@ -46,6 +48,13 @@ struct path *gnuplot_read(const char *name, double r_tool_default)
|
|||||||
outside = 1;
|
outside = 1;
|
||||||
if (!strcmp(buf, "#%notch\n"))
|
if (!strcmp(buf, "#%notch\n"))
|
||||||
notch = 1;
|
notch = 1;
|
||||||
|
if (!strncmp(buf, "#%id=", 5)) {
|
||||||
|
free(id);
|
||||||
|
id = stralloc(buf+5);
|
||||||
|
s = strchr(id, '\n');
|
||||||
|
if (s)
|
||||||
|
*s = 0;
|
||||||
|
}
|
||||||
if (*buf == '#')
|
if (*buf == '#')
|
||||||
continue;
|
continue;
|
||||||
n = sscanf(buf, "%lf %lf %lf\n", &x, &y, &z);
|
n = sscanf(buf, "%lf %lf %lf\n", &x, &y, &z);
|
||||||
@ -67,7 +76,7 @@ struct path *gnuplot_read(const char *name, double r_tool_default)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!path) {
|
if (!path) {
|
||||||
path = path_new(r_tool);
|
path = path_new(r_tool, id);
|
||||||
path->outside = outside;
|
path->outside = outside;
|
||||||
path->notch = notch;
|
path->notch = notch;
|
||||||
*lnk = path;
|
*lnk = path;
|
||||||
@ -89,6 +98,9 @@ static int gnuplot_do_write(FILE *file, const struct path *paths)
|
|||||||
if (path != paths)
|
if (path != paths)
|
||||||
if (fprintf(file, "\n") < 0)
|
if (fprintf(file, "\n") < 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
if (path->id &&
|
||||||
|
fprintf(file, "#%%id=%s\n", path->id) < 0)
|
||||||
|
return 0;
|
||||||
if (path->r_tool &&
|
if (path->r_tool &&
|
||||||
fprintf(file, "#%%r_tool=%f\n", path->r_tool) < 0)
|
fprintf(file, "#%%r_tool=%f\n", path->r_tool) < 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -68,7 +68,7 @@ struct path *try_drill(struct path *path, double d_min, double d_max)
|
|||||||
return NULL;
|
return NULL;
|
||||||
if (!path->first || path->first != path->last)
|
if (!path->first || path->first != path->last)
|
||||||
return NULL;
|
return NULL;
|
||||||
new = path_new((d_min+d_max)/2); /* @@@ fishy */
|
new = path_new((d_min+d_max)/2, path->id); /* @@@ fishy */
|
||||||
path_add(new, path->first->x, path->first->y, path->first->z);
|
path_add(new, path->first->x, path->first->y, path->first->z);
|
||||||
return new;
|
return new;
|
||||||
}
|
}
|
||||||
@ -82,11 +82,11 @@ struct path *try_mill(struct path *path, double diam, double step, int any)
|
|||||||
return NULL;
|
return NULL;
|
||||||
if (path->first == path->last)
|
if (path->first == path->last)
|
||||||
return circle(path->first->x, path->first->y, path->first->z,
|
return circle(path->first->x, path->first->y, path->first->z,
|
||||||
path->r_tool, diam/2, step);
|
path->r_tool, diam/2, step, path->id);
|
||||||
if (path->first->next == path->last)
|
if (path->first->next == path->last)
|
||||||
return slot(path->first->x, path->first->y,
|
return slot(path->first->x, path->first->y,
|
||||||
path->first->next->x, path->first->next->y,
|
path->first->next->x, path->first->next->y,
|
||||||
path->first->z, path->r_tool, diam/2, step);
|
path->first->z, path->r_tool, diam/2, step, path->id);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,11 +43,12 @@ static void free_points(struct point *points)
|
|||||||
void path_free(struct path *path)
|
void path_free(struct path *path)
|
||||||
{
|
{
|
||||||
free_points(path->first);
|
free_points(path->first);
|
||||||
|
free((void *) path->id);
|
||||||
free(path);
|
free(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct path *path_new(double r_tool)
|
struct path *path_new(double r_tool, const char *id)
|
||||||
{
|
{
|
||||||
struct path *path;
|
struct path *path;
|
||||||
|
|
||||||
@ -55,6 +56,7 @@ struct path *path_new(double r_tool)
|
|||||||
path->r_tool = r_tool;
|
path->r_tool = r_tool;
|
||||||
path->outside = 0;
|
path->outside = 0;
|
||||||
path->notch = 0;
|
path->notch = 0;
|
||||||
|
path->id = id ? stralloc(id) : NULL;
|
||||||
path->first = path->last = NULL;
|
path->first = path->last = NULL;
|
||||||
path->next = NULL;
|
path->next = NULL;
|
||||||
return path;
|
return path;
|
||||||
@ -65,7 +67,7 @@ static struct path *path_from(const struct path *old)
|
|||||||
{
|
{
|
||||||
struct path *new;
|
struct path *new;
|
||||||
|
|
||||||
new = path_new(old->r_tool);
|
new = path_new(old->r_tool, old->id);
|
||||||
new->outside = old->outside;
|
new->outside = old->outside;
|
||||||
new->notch = old->notch;
|
new->notch = old->notch;
|
||||||
return new;
|
return new;
|
||||||
|
@ -25,11 +25,12 @@ struct path {
|
|||||||
double r_tool; /* mm */
|
double r_tool; /* mm */
|
||||||
int outside; /* non-zero to mark path as an outside edge */
|
int outside; /* non-zero to mark path as an outside edge */
|
||||||
int notch; /* non-zero to enable dog-boning for path */
|
int notch; /* non-zero to enable dog-boning for path */
|
||||||
|
const char *id; /* identifier assigned by generator */
|
||||||
struct path *next;
|
struct path *next;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct path *path_new(double r_tool);
|
struct path *path_new(double r_tool, const char *id);
|
||||||
void path_add(struct path *path, double x, double y, double z);
|
void path_add(struct path *path, double x, double y, double z);
|
||||||
void path_replace(struct path *old, struct path *new);
|
void path_replace(struct path *old, struct path *new);
|
||||||
struct path *path_reverse(const struct path *path);
|
struct path *path_reverse(const struct path *path);
|
||||||
|
@ -49,7 +49,7 @@ static void half_circle(double cx, double cy, double rx, double ry, double z,
|
|||||||
|
|
||||||
|
|
||||||
struct path *slot(double xa, double ya, double xb, double yb, double z,
|
struct path *slot(double xa, double ya, double xb, double yb, double z,
|
||||||
double sr, double tr, double step)
|
double sr, double tr, double step, const char *id)
|
||||||
{
|
{
|
||||||
double dx = xb-xa;
|
double dx = xb-xa;
|
||||||
double dy = yb-ya;
|
double dy = yb-ya;
|
||||||
@ -57,7 +57,7 @@ struct path *slot(double xa, double ya, double xb, double yb, double z,
|
|||||||
double nx, ny;
|
double nx, ny;
|
||||||
double f;
|
double f;
|
||||||
|
|
||||||
path = path_new(tr);
|
path = path_new(tr, id);
|
||||||
if (sr <= tr) {
|
if (sr <= tr) {
|
||||||
path_add(path, xa, ya, z);
|
path_add(path, xa, ya, z);
|
||||||
path_add(path, xb, yb, z);
|
path_add(path, xb, yb, z);
|
||||||
@ -75,12 +75,12 @@ struct path *slot(double xa, double ya, double xb, double yb, double z,
|
|||||||
|
|
||||||
|
|
||||||
struct path *circle(double cx, double cy, double cz, double cr, double tr,
|
struct path *circle(double cx, double cy, double cz, double cr, double tr,
|
||||||
double step)
|
double step, const char *id)
|
||||||
{
|
{
|
||||||
double s = arc2angle(step, cr);
|
double s = arc2angle(step, cr);
|
||||||
double a;
|
double a;
|
||||||
|
|
||||||
path = path_new(tr);
|
path = path_new(tr, id);
|
||||||
if (cr <= tr) {
|
if (cr <= tr) {
|
||||||
path_add(path, cx, cy, cz);
|
path_add(path, cx, cy, cz);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* shape.h - Toolpaths for basic shapes
|
* shape.h - Toolpaths for basic shapes
|
||||||
*
|
*
|
||||||
* Written 2010 by Werner Almesberger
|
* Written 2010-2011 by Werner Almesberger
|
||||||
* Copyright 2010 Werner Almesberger
|
* Copyright 2010-2011 Werner Almesberger
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -18,8 +18,8 @@
|
|||||||
|
|
||||||
|
|
||||||
struct path *slot(double xa, double ya, double xb, double yb, double z,
|
struct path *slot(double xa, double ya, double xb, double yb, double z,
|
||||||
double sr, double tr, double step);
|
double sr, double tr, double step, const char *id);
|
||||||
struct path *circle(double cx, double cy, double cz, double cr, double tr,
|
struct path *circle(double cx, double cy, double cz, double cr, double tr,
|
||||||
double step);
|
double step, const char *id);
|
||||||
|
|
||||||
#endif /* !SHAPE_H */
|
#endif /* !SHAPE_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user