From 47b53c8ef37d7d55a527243951380a6c73ccad7c Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Wed, 23 Mar 2011 04:34:06 -0300 Subject: [PATCH] fpdoc: new utility to generate a PDF with the footprints used in a project - fab/pos2fab: can be called with "do", to read .pos and .cmp file - fpd2pdf/fpd2pdf: added syntax extension file.fpd:package to allow selection of a single package - fpd2pdf/fpdoc: generate a PDF with the footprints used in a specific project --- fab/pos2fab | 10 ++++--- fpd2pdf/fpd2pdf | 7 +++-- fpd2pdf/fpdoc | 69 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+), 5 deletions(-) create mode 100755 fpd2pdf/fpdoc diff --git a/fab/pos2fab b/fab/pos2fab index a422afd..c7e14fa 100755 --- a/fab/pos2fab +++ b/fab/pos2fab @@ -19,10 +19,12 @@ sub usage } -&usage unless @ARGV == 2; +if (!defined caller) { + &usage unless @ARGV == 2; -$pos = $ARGV[0]; -$cmp = $ARGV[1]; + $pos = $ARGV[0]; + $cmp = $ARGV[1]; +} open(FILE, $pos) || die "$pos: $!"; while () { @@ -55,6 +57,8 @@ while () { } close FILE; +return 1 if defined caller; + print "\"Ref\",\"Footprint\",\"PosX(in)\",\"PosY(in)\",\"Rot(ccw)\"\n" || die; for (@order) { print "\"$_\",\"$fp{$_}\",$pos{$_}[0],$pos{$_}[1],$pos{$_}[2]\n" || diff --git a/fpd2pdf/fpd2pdf b/fpd2pdf/fpd2pdf index 3c1e277..fec93c2 100755 --- a/fpd2pdf/fpd2pdf +++ b/fpd2pdf/fpd2pdf @@ -15,7 +15,7 @@ usage() { cat <&2 -usage: $0 [-a] [-o out.pdf] [-P] file.fpd ... +usage: $0 [-a] [-o out.pdf] [-P] file.fpd[:package] ... -a also include files whose name contains a tilde (backup files) -o out.pdf write to the specified file (default: standard output) @@ -47,4 +47,7 @@ done eval gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=$out -f \ `for n in "$@"; do $all || [ "$n" = "${n/\~/}" ] && \ - echo "<(fped $p_opt \"$n\" -)"; done` + echo "<(fped $p_opt \ + \"\`echo \\"$n\\" | sed 's/:.*//'\`\" \ + \`echo \"$n\" | sed 's/.*:/-1/p;d'\` \ + -)"; done` diff --git a/fpd2pdf/fpdoc b/fpd2pdf/fpdoc new file mode 100755 index 0000000..a8d47cd --- /dev/null +++ b/fpd2pdf/fpdoc @@ -0,0 +1,69 @@ +#!/usr/bin/perl +# +# fpdoc - Generate a PDF with the footprints used in a specific project +# +# 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 pro-file pdf-file\n"; + exit(1); +} + + +&usage unless @ARGV == 2; + +$pro = $ARGV[0]; +$out = $ARGV[1]; + +($base = $pro) =~ s|\.pro$||; + +$pos = "${base}Front.pos"; +$cmp = "$base.cmp"; + +my $on = 0; +open(FILE, $pro) || die "$pro: $!"; +while () { + chop; + if (m|^\[pcbnew/libraries\]|) { + $on = 1; + next; + } + $on = 0 if /^\[/; + next unless $on; + next unless /LibName\d+=/; + my $mod = "$'.mod"; + my $fpd = "$'.fpd"; + open(MOD, $mod) || die "$mod: $!"; + while () { + chop; + next unless /^\$MODULE\s+/; + $fpd{$'} = $fpd; + } + close MOD; +} +close FILE; + +push(@INC, split(":", $ENV{"PATH"})); +do "pos2fab" || die "pos2fab: $!"; + +# +# We iterate over the items in the .pos file so that we skip NC and virtual +# components. +# + +for (@order) { + my $fp = $fp{$_}; + die "don't have $fp" unless defined $fpd{$fp}; + $need{$fp} = 1; +} + +exec "fpd2pdf", "-o", $out, map { "$fpd{$_}:$_" } sort keys %need;