mirror of
git://projects.qi-hardware.com/ben-wpan.git
synced 2025-04-21 12:27:27 +03:00
Split gitsch2ppm into its constituents.
- scripts/gitsch2ps: generate PS files for KiCad schematics in git - scripts/normalizeschps: normalize eeschema Postscript - scripts/schps2ppm: generate PPM files from normalized Eeschema Postscript - scripts/gitsch2ppm: wrapper and cache manager for the above scripts
This commit is contained in:
@@ -12,36 +12,6 @@
|
||||
#
|
||||
|
||||
|
||||
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
|
||||
/rectfill { rectstroke } bind def
|
||||
EOF
|
||||
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'; ) |
|
||||
gs -sDEVICE=ppmraw -sOutputFile=- -g$IRES -r$res \
|
||||
-dTextAlphaBits=4 -dGraphicsAlphaBits=4 -q - |
|
||||
pnmflip -r270 |
|
||||
cat >"${1%.ps}.ppm"
|
||||
}
|
||||
|
||||
|
||||
usage()
|
||||
{
|
||||
cat <<EOF 1>&2
|
||||
@@ -59,7 +29,9 @@ EOF
|
||||
|
||||
cache=false
|
||||
keep=false
|
||||
sanitize=true
|
||||
res=
|
||||
sanitize=
|
||||
width=
|
||||
while true; do
|
||||
case "$1" in
|
||||
-c) cache=true
|
||||
@@ -67,13 +39,12 @@ while true; do
|
||||
-k) keep=true
|
||||
shift;;
|
||||
-r) [ -z "$2" ] && usage
|
||||
RES="$2"
|
||||
res="-r $2"
|
||||
shift 2;;
|
||||
-S) sanitize=`PATH="$PATH":\`dirname "$0"\` which sanitize-profile`
|
||||
[ "$sanitize" = "${sanitize#/}" ] && sanitize=`pwd`/"$sanitize"
|
||||
-S) sanitize=-S
|
||||
shift;;
|
||||
-w) [ -z "$2" ] && usage
|
||||
LINEWIDTH="$2"
|
||||
width="-r $2"
|
||||
shift 2;;
|
||||
-*)
|
||||
usage;;
|
||||
@@ -82,53 +53,30 @@ while true; do
|
||||
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
|
||||
tmp=`pwd`/_gitsch2ppm
|
||||
eval outdir=\${$#}
|
||||
|
||||
[ "$dir" != "${dir#/}" ] || dir=`pwd`/$dir
|
||||
|
||||
[ "$commit" != HEAD -o -f "$dir/$schem" ] || usage
|
||||
[ -d "$dir/.git" ] || usage
|
||||
|
||||
tmp="$dir/../_gitsch2ppm"
|
||||
sch="$tmp/$sdir"
|
||||
# with thanks to http://www.faqs.org/faqs/unix-faq/faq/part2/section-12.html
|
||||
argv=
|
||||
while [ $# -gt 1 ]; do
|
||||
argv="$argv \"$1\""
|
||||
shift
|
||||
done
|
||||
eval set x "$argv"
|
||||
shift
|
||||
|
||||
if ! $cache; then
|
||||
rm -rf "$tmp"
|
||||
rm -rf "$outdir"
|
||||
|
||||
git clone -s -n "$dir/.git" "$tmp" || exit
|
||||
( cd "$tmp" && git checkout -q "$commit"; ) || exit
|
||||
|
||||
if [ ! -f "$tmp/$schem" ]; then
|
||||
echo "$schem not found (checked out into $tmp)" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
(
|
||||
cd "$sch" || exit
|
||||
rm -f *.ps *.ppm
|
||||
$sanitize "$tmp/${schem%.sch}.pro" ||
|
||||
exit
|
||||
eeschema --plot "$tmp/$schem"
|
||||
) || exit
|
||||
gitsch2ps $sanitize "$@" "$tmp"
|
||||
for n in "$tmp"/*.ps; do
|
||||
normalizeschps $width "$n"
|
||||
done
|
||||
fi
|
||||
|
||||
for n in "$sch"/*.ps; do
|
||||
ps2ppm "$n"
|
||||
mkdir -p "$outdir"
|
||||
for n in "$tmp"/*.ps; do
|
||||
schps2ppm $res "$n" "$outdir/`basename \"${n%.ps}.ppm\"`"
|
||||
done
|
||||
|
||||
mkdir -p "$outdir"
|
||||
|
||||
mv "$sch"/*.ppm "$outdir"
|
||||
|
||||
$keep || rm -rf "$tmp"
|
||||
|
||||
Reference in New Issue
Block a user