1
0
Fork 0

Adds gerbers as massaged for DirtyPCBs order

This commit is contained in:
Shawn Nock 2018-03-23 09:44:01 -04:00
parent 28e42498bb
commit 4ba1fd964f
7 changed files with 373 additions and 0 deletions

164
MergeDrl.pl Normal file
View File

@ -0,0 +1,164 @@
#!/usr/bin/perl -w
# MergeDrl.pl
#
# CC-BY 2012 9DOF <9dof.gg@gmail.com>
#
# Merges several Excellon format drill files into a single file.
#
# Usage: MergeDrl.pl input_file [...] > output_file
#
# Output's header will be copied from first input file
use strict;
use IO::File;
use Data::Dumper;
sub parseExcellon($);
# Get arguments
my @drills;
# Parse args and dump content
foreach my $fn (@ARGV) {
push @drills, parseExcellon($fn);
# my $f = new IO::File($fn, 'r');
# print 'Dumping ', $fn, "\n";
# dumpExcellon($f);
}
#print Dumper(\@drills);
# Combine drills
my %mergedDrills = (
tools => {},
coords => {});
my @comboTools = ();
foreach my $t(@drills) {
while (my($k,$v)=each %{$t->{tools}}){
push @comboTools, {spec => $v, coords => $t->{coords}->{$k}};
}
}
#print "Combo:\n";
#print Dumper(\@comboTools);
# Sort spec and allocate new indices
my $currTool;
my $prevTool;
my $currIndex = 1;
my @finalTools = ();
foreach my $e(sort {$a->{spec} cmp $b->{spec}} @comboTools) {
# Check if same spec as last one
if ($prevTool && $prevTool->{spec} eq $e->{spec}) {
push @{$prevTool->{coords}}, @{$e->{coords}};
} else {
$e->{tool} = 'T'.$currIndex++;
$prevTool = $e;
push @finalTools, $prevTool;
}
}
# print Dumper(\@finalTools);
# Output result
local $/ = "\r\n";
# Header
print "M48$/";
foreach my $h(@{$drills[0]->{headers}}) {
print "$h$/";
}
# List of tools
foreach my $t(@finalTools) {
print $t->{tool}.$t->{spec}.$/;
}
# End of header
print "\%$/";
# Body
print "G90$/";
print "G05$/";
print "M72$/";
# Coords
foreach my $t(@finalTools) {
print $t->{tool}, $/;
foreach my $c(@{$t->{coords}}) {
print "$c$/";
}
}
# End
print "T0$/";
print "M30$/";
exit 0;
# Excellon parser
sub parseExcellon($) {
my ($fn) = @_;
my %res = (
filename => $fn,
tools => {},
coords => {},
headers => []);
my $f = new IO::File($fn, 'r');
my $inHeader = 0;
my $inBody = 0;
my $currTool;
# print "Inside parseExcellon(${fn})\n";
while(<$f>){
local $/ = "\r\n";
chomp;
# chop; # input is MSDOS line terminated
if (!$inHeader && !$inBody) { # Search for start of header (^M48)
if (/^M48/) {
# Found start of header
$inHeader = 1;
} else {
# print 's';
}
} elsif ($inHeader) { # Inside header, collect info until end of header (^%)
if (!/^\%/) {
# print 'h';
if (/^(T\d+)(.*)/) {
$res{tools}->{$1} = $2;
$res{coords}->{$1} = [];
} else {
push @{$res{headers}}, $_;
}
} else {
$inHeader = 0;
$inBody = 1;
}
} elsif ($inBody) { # Inside body, collect coords until end of body (^M30)
if (!/^M30/) {
# print 'b';
if (/^(T\d+)/) {
$currTool = $1;
} elsif ($currTool && exists $res{coords}->{$currTool}) {
push @{$res{coords}->{$currTool}}, $_;
}
} else {
$inBody = 0;
# print "\n";
last;
}
}
}
$f->close;
# Dump info
# print "Info dump\n";
# print "Headers:\n";
# print @headers;
# print "Tools:\n";
# print join(",", @tools), "\n";
# print "Coords:\n";
# foreach my $t(@tools) {
# print "Tool: ", $t, "\n";
# print @{$coords{$t}};
\%res;
}

View File

@ -0,0 +1,209 @@
M48
;DRILL file {KiCad 4.0.7} date Tue Mar 13 19:37:50 2018
;FORMAT={-:-/ absolute / inch / decimal}
FMAT,2
INCH,TZ
T1C0.012
T2C0.035
T3C0.039
T4C0.047
T5C0.060
T6C0.108
T7C0.128
%
G90
G05
M72
T1
X4.1596Y-4.0831
X4.2296Y-4.1711
X4.3106Y-3.6681
X4.3356Y-4.0801
X4.5656Y-4.1071
X4.6118Y-3.9753
X4.6486Y-4.1831
X4.8266Y-4.0291
X4.8866Y-3.9731
X4.9983Y-4.061
X5.2156Y-4.3001
X5.2256Y-4.4401
X5.3256Y-4.3801
X5.3256Y-4.4101
X5.3856Y-4.3001
X5.4356Y-4.5801
X5.4868Y-4.5053
X5.5368Y-4.5653
X5.5468Y-4.6403
X5.5618Y-4.5903
T2
X4.3669Y-4.4685
X4.4169Y-4.3685
X4.4669Y-4.4685
X4.5169Y-4.3685
X4.5669Y-4.4685
X4.6169Y-4.3685
X4.6669Y-4.4685
X4.7169Y-4.3685
T3
X4.0748Y-4.1323
X4.0748Y-4.2323
X4.0748Y-4.3323
X4.2469Y-3.7295
X4.2469Y-3.8295
X4.3469Y-3.7295
X4.3469Y-3.8295
X4.4469Y-3.7295
X4.4469Y-3.8295
X4.4493Y-4.0301
X4.4493Y-4.1301
X4.4493Y-4.2301
X4.5469Y-3.7295
X4.5469Y-3.8295
X4.6469Y-3.7295
X4.6469Y-3.8295
X4.7469Y-3.7295
X4.7469Y-3.8295
X4.8469Y-3.7295
X4.8469Y-3.8295
X4.9469Y-3.7295
X4.9469Y-3.8295
X5.0168Y-4.7103
X5.0469Y-3.7295
X5.0469Y-3.8295
X5.1168Y-4.7103
X5.1469Y-3.7295
X5.1469Y-3.8295
X5.2469Y-3.7295
X5.2469Y-3.8295
X5.3469Y-3.7295
X5.3469Y-3.8295
X5.4469Y-3.7295
X5.4469Y-3.8295
X5.5469Y-3.7295
X5.5469Y-3.8295
X5.6469Y-3.7295
X5.6469Y-3.8295
X5.7469Y-3.7295
X5.7469Y-3.8295
X5.8469Y-3.7295
X5.8469Y-3.8295
X5.9469Y-3.7295
X5.9469Y-3.8295
X6.0469Y-3.7295
X6.0469Y-3.8295
X6.1469Y-3.7295
X6.1469Y-3.8295
T4
X6.1024Y-4.2323
X6.2992Y-4.0354
X6.2992Y-4.4291
X6.3976Y-4.0354
X6.3976Y-4.4291
T5
X6.1024Y-4.0354
X6.1024Y-4.4291
X6.2992Y-4.2323
T6
X4.0551Y-3.7795
X4.0551Y-4.685
X6.3386Y-3.7795
X6.3386Y-4.685
T7
X4.3083Y-4.7185
X4.7756Y-4.7185
T0
M30