2010-08-27 09:54:26 +03:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# gitsch2ppm - Generate PPM files for KiCad schematics in git
|
|
|
|
#
|
|
|
|
# Written 2010 by Werner Almesberger
|
|
|
|
# Copyright 2010 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.
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
|
|
RES=1280x850
|
|
|
|
LINEWIDTH=120
|
|
|
|
|
|
|
|
|
|
|
|
ps2ppm()
|
|
|
|
{
|
|
|
|
X=`echo $RES | sed 's/x.*//'`
|
|
|
|
Y=`echo $RES | sed 's/.*x//'`
|
|
|
|
IRES=${Y}x$X
|
|
|
|
res=`expr 72 \* $X / 800`
|
|
|
|
|
|
|
|
( cat <<EOF
|
|
|
|
%!PS-Adobe-3.0
|
|
|
|
/setlinewidth { $LINEWIDTH 2 copy lt { exch } if pop setlinewidth } bind def
|
2010-08-28 03:15:32 +03:00
|
|
|
/rectfill { rectstroke } bind def
|
2010-08-27 09:54:26 +03:00
|
|
|
EOF
|
2010-08-29 21:08:03 +03:00
|
|
|
sed <"$1" '1d
|
|
|
|
/%%DocumentMedia: A4.*/a-20 -10 translate
|
|
|
|
/%%DocumentMedia: A3.*/{s/A3/A4/;a-20 -10 translate 0.70 dup scale
|
|
|
|
}
|
|
|
|
/%%DocumentMedia: A2.*/{s/A2/A4/;a-18 -12 translate 0.49 dup scale
|
|
|
|
}
|
|
|
|
/%%Orientation: Landscape/d'; ) |
|
2010-08-27 09:54:26 +03:00
|
|
|
gs -sDEVICE=ppmraw -sOutputFile=- -g$IRES -r$res \
|
|
|
|
-dTextAlphaBits=4 -dGraphicsAlphaBits=4 -q - |
|
|
|
|
pnmflip -r270 |
|
2010-08-29 05:12:27 +03:00
|
|
|
cat >"${1%.ps}.ppm"
|
2010-08-27 09:54:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
usage()
|
|
|
|
{
|
|
|
|
cat <<EOF 1>&2
|
|
|
|
usage: $0 [options] top-dir top-schem [commit] outdir
|
|
|
|
|
2010-08-27 20:31:05 +03:00
|
|
|
-c use cached Postscript files (from previous run, with -k)
|
|
|
|
-k keep checked-out tree (for immediate reuse with -c)
|
2010-08-27 09:54:26 +03:00
|
|
|
-r XxY image resolution (default: $RES)
|
2010-08-28 02:42:40 +03:00
|
|
|
-S sanitize the KiCad profile
|
2010-08-27 09:54:26 +03:00
|
|
|
-w points Postscript line width (default: $LINEWIDTH)
|
|
|
|
EOF
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-27 20:31:05 +03:00
|
|
|
cache=false
|
|
|
|
keep=false
|
2010-08-28 02:42:40 +03:00
|
|
|
sanitize=true
|
2010-08-27 09:54:26 +03:00
|
|
|
while true; do
|
|
|
|
case "$1" in
|
2010-08-27 20:31:05 +03:00
|
|
|
-c) cache=true
|
|
|
|
shift;;
|
|
|
|
-k) keep=true
|
|
|
|
shift;;
|
2010-08-27 09:54:26 +03:00
|
|
|
-r) [ -z "$2" ] && usage
|
|
|
|
RES="$2"
|
2010-08-27 20:31:05 +03:00
|
|
|
shift 2;;
|
2010-08-28 02:42:40 +03:00
|
|
|
-S) sanitize=`PATH="$PATH":\`dirname "$0"\` which sanitize-profile`
|
|
|
|
[ "$sanitize" = "${sanitize#/}" ] && sanitize=`pwd`/"$sanitize"
|
|
|
|
shift;;
|
2010-08-27 09:54:26 +03:00
|
|
|
-w) [ -z "$2" ] && usage
|
|
|
|
LINEWIDTH="$2"
|
2010-08-27 20:31:05 +03:00
|
|
|
shift 2;;
|
2010-08-27 09:54:26 +03:00
|
|
|
-*)
|
|
|
|
usage;;
|
|
|
|
*)
|
|
|
|
break;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
[ ! -z "$3" -a -z "$5" ] || usage
|
|
|
|
dir="$1"
|
|
|
|
schem="$2"
|
|
|
|
sdir=`dirname "$schem"`
|
|
|
|
if [ -z "$4" ]; then
|
|
|
|
commit=HEAD
|
|
|
|
outdir="$3"
|
|
|
|
else
|
|
|
|
commit="$3"
|
|
|
|
outdir="$4"
|
|
|
|
fi
|
|
|
|
|
|
|
|
[ "$dir" != "${dir#/}" ] || dir=`pwd`/$dir
|
|
|
|
|
|
|
|
[ "$commit" != HEAD -o -f "$dir/$schem" ] || usage
|
|
|
|
[ -d "$dir/.git" ] || usage
|
|
|
|
|
2010-08-27 18:47:51 +03:00
|
|
|
tmp="$dir/../_gitsch2ppm"
|
2010-08-27 09:54:26 +03:00
|
|
|
sch="$tmp/$sdir"
|
|
|
|
|
2010-08-27 20:31:05 +03:00
|
|
|
if ! $cache; then
|
|
|
|
rm -rf "$tmp"
|
|
|
|
rm -rf "$outdir"
|
2010-08-27 09:54:26 +03:00
|
|
|
|
2010-08-27 20:31:05 +03:00
|
|
|
git clone -s -n "$dir/.git" "$tmp" || exit
|
|
|
|
( cd "$tmp" && git checkout -q "$commit"; ) || exit
|
2010-08-27 09:54:26 +03:00
|
|
|
|
2010-08-27 20:31:05 +03:00
|
|
|
if [ ! -f "$tmp/$schem" ]; then
|
|
|
|
echo "$schem not found (checked out into $tmp)" 1>&2
|
|
|
|
exit 1
|
|
|
|
fi
|
2010-08-27 09:54:26 +03:00
|
|
|
|
2010-08-28 02:42:40 +03:00
|
|
|
(
|
|
|
|
cd "$sch" || exit
|
|
|
|
rm -f *.ps *.ppm
|
2010-08-29 05:12:27 +03:00
|
|
|
$sanitize "$tmp/${schem%.sch}.pro" ||
|
2010-08-28 02:42:40 +03:00
|
|
|
exit
|
|
|
|
eeschema --plot "$tmp/$schem"
|
|
|
|
) || exit
|
2010-08-27 20:31:05 +03:00
|
|
|
fi
|
2010-08-27 09:54:26 +03:00
|
|
|
|
|
|
|
for n in "$sch"/*.ps; do
|
|
|
|
ps2ppm "$n"
|
|
|
|
done
|
|
|
|
|
|
|
|
mkdir -p "$outdir"
|
|
|
|
|
|
|
|
mv "$sch"/*.ppm "$outdir"
|
|
|
|
|
2010-08-27 20:31:05 +03:00
|
|
|
$keep || rm -rf "$tmp"
|