Root/
| 1 | #!/usr/bin/perl |
| 2 | # |
| 3 | # pos2fab - Condition a KiCAD .pos file for SMT fab use |
| 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 | sub usage |
| 16 | { |
| 17 | print STDERR "usage: $0 pos-file cmp-file\n"; |
| 18 | exit(1); |
| 19 | } |
| 20 | |
| 21 | |
| 22 | if (!defined caller) { |
| 23 | &usage unless @ARGV == 2; |
| 24 | |
| 25 | $pos = $ARGV[0]; |
| 26 | $cmp = $ARGV[1]; |
| 27 | } |
| 28 | |
| 29 | open(FILE, $pos) || die "$pos: $!"; |
| 30 | while (<FILE>) { |
| 31 | chop; |
| 32 | next if /^#/; |
| 33 | my @f = split(/\s+/); |
| 34 | $pos{$f[0]} = [ $f[2], -$f[3]+0, $f[4] ]; |
| 35 | push(@order, $f[0]); |
| 36 | } |
| 37 | close FILE; |
| 38 | |
| 39 | open(FILE, $cmp) || die "$cmp: $!"; |
| 40 | while (<FILE>) { |
| 41 | chop; |
| 42 | if (/^BeginCmp/) { |
| 43 | undef $ref; |
| 44 | undef $mod; |
| 45 | next; |
| 46 | } |
| 47 | if (/^Reference\s*=\s*(\S+)\s*;/) { |
| 48 | $ref = $1; |
| 49 | next; |
| 50 | } |
| 51 | if (/^IdModule\s*=\s*(\S+)\s*;/) { |
| 52 | $mod = $1; |
| 53 | next; |
| 54 | } |
| 55 | next unless /^EndCmp/; |
| 56 | $fp{$ref} = $mod; |
| 57 | } |
| 58 | close FILE; |
| 59 | |
| 60 | return 1 if defined caller; |
| 61 | |
| 62 | print "\"Ref\",\"Footprint\",\"PosX(in)\",\"PosY(in)\",\"Rot(ccw)\"\n" || die; |
| 63 | for (@order) { |
| 64 | print "\"$_\",\"$fp{$_}\",$pos{$_}[0],$pos{$_}[1],$pos{$_}[2]\n" || |
| 65 | die; |
| 66 | } |
| 67 |
Branches:
master
