mirror of
git://projects.qi-hardware.com/cae-tools.git
synced 2024-12-22 23:43:00 +02:00
drl2gp: drilling and circle milling work, various fixes (more to come)
This commit is contained in:
parent
1ab262247f
commit
49a42cb500
@ -11,10 +11,9 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* KiCad drill files are in the Excellon format. The format is described
|
||||
* here:
|
||||
* KiCad drill files are in the Excellon format. The format is described here:
|
||||
*
|
||||
* http://web.archive.org/web/20071030075236/http://www.excellon.com/manuals/program.htm
|
||||
* http://www.excellon.com/manuals/program.htm
|
||||
*
|
||||
* Note that drl2gp currently only implements the subset necessary to process
|
||||
* the KiCad drill files encountered in a few projects, may not work correctly
|
||||
@ -26,18 +25,21 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <math.h>
|
||||
#include <assert.h>
|
||||
|
||||
|
||||
#define MAX_ARGS 3
|
||||
#define MAX_TOOL 10
|
||||
|
||||
#define MAX_STEP 0.01 /* max arc step, in mm */
|
||||
|
||||
|
||||
static double tool_d[MAX_TOOL+1];
|
||||
static FILE *out = NULL;
|
||||
static int lineno = 1;
|
||||
|
||||
static int mill;
|
||||
static int mill = 0;
|
||||
static double depth, d0, d1;
|
||||
|
||||
|
||||
@ -59,6 +61,7 @@ static void header(void)
|
||||
} state = ts_nl;
|
||||
int c, tool;
|
||||
double f = 1;
|
||||
double tmp;
|
||||
|
||||
while ((c = getchar()) != EOF) {
|
||||
if (out) {
|
||||
@ -104,10 +107,13 @@ static void header(void)
|
||||
break;
|
||||
case ts_tc:
|
||||
if (isdigit(c)) {
|
||||
tmp = c-'0';
|
||||
tmp = IN2MM(tmp);
|
||||
if (f == 1)
|
||||
tool_d[tool] = tool_d[tool]*10+c-'0';
|
||||
tool_d[tool] =
|
||||
tool_d[tool]*10+tmp;
|
||||
else {
|
||||
tool_d[tool] += f*(c-'0');
|
||||
tool_d[tool] += f*tmp;
|
||||
f /= 10;
|
||||
}
|
||||
} else if (c == '.') {
|
||||
@ -139,12 +145,22 @@ static void slot(double xa, double ya, double xb, double yb, double d)
|
||||
|
||||
static void circle(double cx, double cy, double d)
|
||||
{
|
||||
double cr = d/2;
|
||||
double tr = d0/2;
|
||||
double s = acos(1-MAX_STEP*MAX_STEP/(cr*cr)/2);
|
||||
double a;
|
||||
|
||||
assert(mill);
|
||||
for (a = 0; a < 2*M_PI; a += s)
|
||||
printf("%f %f %f\n",
|
||||
cx+(cr-tr)*cos(a), cy+(cr-tr)*sin(a), -depth);
|
||||
printf("%f %f %f\n\n", cx+(cr-tr), cy, -depth);
|
||||
}
|
||||
|
||||
|
||||
static void drill(double x, double y)
|
||||
{
|
||||
printf("%f %f %f\n\n", x, y, -depth);
|
||||
}
|
||||
|
||||
|
||||
@ -153,7 +169,7 @@ static void do_cmd(char cmd, double v, int nl)
|
||||
static int active = 0;
|
||||
static int metric = 1;
|
||||
static int slotting = 0;
|
||||
double x = 0, y = 0, x0 = 0, d = 0;
|
||||
static double x = 0, y = 0, x0 = 0, d = 0;
|
||||
int n = v;
|
||||
|
||||
switch (cmd) {
|
||||
@ -202,10 +218,12 @@ static void do_cmd(char cmd, double v, int nl)
|
||||
exit(1);
|
||||
}
|
||||
d = tool_d[n];
|
||||
fprintf(stderr, "T%d -> %f\n", n, d);
|
||||
if (mill)
|
||||
active = d <= d0;
|
||||
active = d >= d0;
|
||||
else
|
||||
active = d >= d0 && d <= d1;
|
||||
fprintf(stderr, "%g %g %g -> %d\n", d, d0, d1, active);
|
||||
break;
|
||||
case 'X':
|
||||
x = metric ? v : IN2MM(v);
|
||||
@ -215,6 +233,8 @@ static void do_cmd(char cmd, double v, int nl)
|
||||
slotting = 0;
|
||||
break;
|
||||
}
|
||||
if (!metric)
|
||||
v = IN2MM(v);
|
||||
if (slotting) {
|
||||
slot(x0, y, x, v, d);
|
||||
slotting = 0;
|
||||
@ -228,7 +248,7 @@ static void do_cmd(char cmd, double v, int nl)
|
||||
drill(x, v);
|
||||
break;
|
||||
}
|
||||
y = metric ? v : IN2MM(v);
|
||||
y = v;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "unrecognized command \"%c\" at line %d\n",
|
||||
@ -344,10 +364,10 @@ int main(int argc, char **argv)
|
||||
switch (n_arg) {
|
||||
case 2:
|
||||
d1 = d0;
|
||||
mill = 0;
|
||||
mill = 1;
|
||||
break;
|
||||
case 3:
|
||||
mill = 1;
|
||||
mill = 0;
|
||||
break;
|
||||
default:
|
||||
usage(*argv);
|
||||
|
Loading…
Reference in New Issue
Block a user