Root/
| 1 | #!/usr/bin/perl |
| 2 | # |
| 3 | # drl2gerber - Convert a KiCAD-generated Excellon drill file to Gerber |
| 4 | # |
| 5 | # Written 2011 by Werner Almesberger |
| 6 | # Copyright 2011 Werner Almesberger |
| 7 | # |
| 8 | # This program is free software; you can redistribute it and/or modify |
| 9 | # it under the terms of the GNU General Public License as published by |
| 10 | # the Free Software Foundation; either version 2 of the License, or |
| 11 | # (at your option) any later version. |
| 12 | # |
| 13 | |
| 14 | |
| 15 | print "G04 MACHINE-GENERATED FROM DRILL FILE*\n" || die; |
| 16 | print "G01*\n" || die; # linear Interpolation |
| 17 | print "G70*\n" || die; # inch units |
| 18 | print "G90*\n" || die; # absolute Mode |
| 19 | print "%MOIN*%*\n" || die; # inches, RS274X-style |
| 20 | print "%FSLAX34Y34*%\n" || die; # format |
| 21 | |
| 22 | # M1rc3 |
| 23 | $x0 = 7300; |
| 24 | $y0 = 268910; |
| 25 | # M1r4 |
| 26 | if ($ENV{"REV"} eq "r4") { |
| 27 | $x0 = 34022; |
| 28 | $y0 = 293540; |
| 29 | } |
| 30 | |
| 31 | |
| 32 | sub u() |
| 33 | { |
| 34 | my $f = 1000000; |
| 35 | |
| 36 | $_[0] =~ /^(-?)(\d+)$/; |
| 37 | my $s = 0; |
| 38 | for (split("", $2)) { |
| 39 | $s += $_*$f; |
| 40 | $f /= 10; |
| 41 | } |
| 42 | return $1 eq "-" ? -$s : $s; |
| 43 | } |
| 44 | |
| 45 | |
| 46 | while (<>) { |
| 47 | chop; |
| 48 | if (/^T(\d+)C/) { |
| 49 | print "%ADD", $1+10, "C,$'*%\n" || die; |
| 50 | print "G54D", $1+10, "*\n" || die; |
| 51 | $faux_g85 = 0; |
| 52 | # we dont' seem to have easily machine-readable |
| 53 | # information in Altium's Excellon to tell what should |
| 54 | # be a hole and what should be a slot |
| 55 | undef $last; |
| 56 | next; |
| 57 | } |
| 58 | if (/^T(\d+)$/) { |
| 59 | print "G54D", $1+10, "*\n" || die; |
| 60 | next; |
| 61 | } |
| 62 | if (/^X([-0-9.]+)Y([-0-9.]+)$/) { |
| 63 | my $c = sprintf("X%dY%d", &u($1)+$x0, &u($2)+$y0); |
| 64 | |
| 65 | if ($faux_g85) { |
| 66 | print "${last}D02*\n${c}D01*\n" if defined $last; |
| 67 | $last = $c; |
| 68 | } else { |
| 69 | print "${c}D03*\n" || die; |
| 70 | } |
| 71 | next; |
| 72 | } |
| 73 | if (/^X([-0-9.]+)Y([-0-9.]+)G85X([-0-9.]+)Y([-0-9.]+)$/) { |
| 74 | printf("X%dY%dD02*\nX%dY%dD01*\n", |
| 75 | &u($1)+$x0, &u($2)+$y0, &u($3)+$x0, &u($4)+$y0) || die; |
| 76 | next; |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | print "M02*\n" || die; |
| 81 |
Branches:
master
