From 5cb1aed21c67461c615cc92a50035fec65bfa34c Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Tue, 22 Mar 2011 21:57:57 -0300 Subject: [PATCH] fab/pos2fab: condition a KiCAD .pos file for SMT fab use --- fab/pos2fab | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100755 fab/pos2fab diff --git a/fab/pos2fab b/fab/pos2fab new file mode 100755 index 0000000..a422afd --- /dev/null +++ b/fab/pos2fab @@ -0,0 +1,62 @@ +#!/usr/bin/perl +# +# pos2fab - Condition a KiCAD .pos file for SMT fab use +# +# Written 2011 by Werner Almesberger +# Copyright 2011 Werner Almesberger +# +# 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 +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# + + +sub usage +{ + print STDERR "usage: $0 pos-file cmp-file\n"; + exit(1); +} + + +&usage unless @ARGV == 2; + +$pos = $ARGV[0]; +$cmp = $ARGV[1]; + +open(FILE, $pos) || die "$pos: $!"; +while () { + chop; + next if /^#/; + my @f = split(/\s+/); + $pos{$f[0]} = [ $f[2], -$f[3]+0, $f[4] ]; + push(@order, $f[0]); +} +close FILE; + +open(FILE, $cmp) || die "$cmp: $!"; +while () { + chop; + if (/^BeginCmp/) { + undef $ref; + undef $mod; + next; + } + if (/^Reference\s*=\s*(\S+)\s*;/) { + $ref = $1; + next; + } + if (/^IdModule\s*=\s*(\S+)\s*;/) { + $mod = $1; + next; + } + next unless /^EndCmp/; + $fp{$ref} = $mod; +} +close FILE; + +print "\"Ref\",\"Footprint\",\"PosX(in)\",\"PosY(in)\",\"Rot(ccw)\"\n" || die; +for (@order) { + print "\"$_\",\"$fp{$_}\",$pos{$_}[0],$pos{$_}[1],$pos{$_}[2]\n" || + die; +}