Root/scripts/gitsch2ppm

Source at commit 56a95040ca2fe2a265bd27fce365515f7656383e created 13 years 6 months ago.
By Werner Almesberger, Generate commit entry and show diffs also for the first commit. Plus cleanup.
1#!/bin/sh
2#
3# gitsch2ppm - Generate PPM files for KiCad schematics in git
4#
5# Written 2010 by Werner Almesberger
6# Copyright 2010 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
15RES=1280x850
16LINEWIDTH=120
17
18
19ps2ppm()
20{
21    X=`echo $RES | sed 's/x.*//'`
22    Y=`echo $RES | sed 's/.*x//'`
23    IRES=${Y}x$X
24    res=`expr 72 \* $X / 800`
25
26    ( cat <<EOF
27%!PS-Adobe-3.0
28/setlinewidth { $LINEWIDTH 2 copy lt { exch } if pop setlinewidth } bind def
29/rectfill { rectstroke } bind def
30EOF
31    sed 1d <"$1"; ) |
32    gs -sDEVICE=ppmraw -sOutputFile=- -g$IRES -r$res \
33      -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -q - |
34      pnmflip -r270 |
35      cat >"${1%.ps}.ppm"
36}
37
38
39usage()
40{
41    cat <<EOF 1>&2
42usage: $0 [options] top-dir top-schem [commit] outdir
43
44  -c use cached Postscript files (from previous run, with -k)
45  -k keep checked-out tree (for immediate reuse with -c)
46  -r XxY image resolution (default: $RES)
47  -S sanitize the KiCad profile
48  -w points Postscript line width (default: $LINEWIDTH)
49EOF
50    exit 1
51}
52
53
54cache=false
55keep=false
56sanitize=true
57while true; do
58    case "$1" in
59    -c) cache=true
60    shift;;
61    -k) keep=true
62    shift;;
63    -r) [ -z "$2" ] && usage
64    RES="$2"
65    shift 2;;
66    -S) sanitize=`PATH="$PATH":\`dirname "$0"\` which sanitize-profile`
67    [ "$sanitize" = "${sanitize#/}" ] && sanitize=`pwd`/"$sanitize"
68    shift;;
69    -w) [ -z "$2" ] && usage
70    LINEWIDTH="$2"
71    shift 2;;
72    -*)
73    usage;;
74    *)
75    break;;
76    esac
77done
78
79[ ! -z "$3" -a -z "$5" ] || usage
80dir="$1"
81schem="$2"
82sdir=`dirname "$schem"`
83if [ -z "$4" ]; then
84    commit=HEAD
85    outdir="$3"
86else
87    commit="$3"
88    outdir="$4"
89fi
90
91[ "$dir" != "${dir#/}" ] || dir=`pwd`/$dir
92
93[ "$commit" != HEAD -o -f "$dir/$schem" ] || usage
94[ -d "$dir/.git" ] || usage
95
96tmp="$dir/../_gitsch2ppm"
97sch="$tmp/$sdir"
98
99if ! $cache; then
100    rm -rf "$tmp"
101    rm -rf "$outdir"
102
103    git clone -s -n "$dir/.git" "$tmp" || exit
104    ( cd "$tmp" && git checkout -q "$commit"; ) || exit
105
106    if [ ! -f "$tmp/$schem" ]; then
107        echo "$schem not found (checked out into $tmp)" 1>&2
108        exit 1
109    fi
110
111    (
112    cd "$sch" || exit
113    rm -f *.ps *.ppm
114    $sanitize "$tmp/${schem%.sch}.pro" ||
115      exit
116    eeschema --plot "$tmp/$schem"
117    ) || exit
118fi
119
120for n in "$sch"/*.ps; do
121    ps2ppm "$n"
122done
123
124mkdir -p "$outdir"
125
126mv "$sch"/*.ppm "$outdir"
127
128$keep || rm -rf "$tmp"
129

Archive Download this file



interactive