Root/scripts/gitsch2ppm

Source at commit a241265aaf21f6e1989618272105c2b7c9321ce7 created 10 years 2 months ago.
By Werner Almesberger, Run eeschema only once (not twice) per commit. 20% speed improvement.
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
29EOF
30    sed 1d <"$1"; ) |
31    gs -sDEVICE=ppmraw -sOutputFile=- -g$IRES -r$res \
32      -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -q - |
33      pnmflip -r270 |
34      cat >`dirname "$1"`/`basename "$1" .ps`.ppm
35}
36
37
38usage()
39{
40    cat <<EOF 1>&2
41usage: $0 [options] top-dir top-schem [commit] outdir
42
43  -c use cached Postscript files (from previous run, with -k)
44  -k keep checked-out tree (for immediate reuse with -c)
45  -r XxY image resolution (default: $RES)
46  -w points Postscript line width (default: $LINEWIDTH)
47EOF
48    exit 1
49}
50
51
52cache=false
53keep=false
54while true; do
55    case "$1" in
56    -c) cache=true
57    shift;;
58    -k) keep=true
59    shift;;
60    -r) [ -z "$2" ] && usage
61    RES="$2"
62    shift 2;;
63    -w) [ -z "$2" ] && usage
64    LINEWIDTH="$2"
65    shift 2;;
66    -*)
67    usage;;
68    *)
69    break;;
70    esac
71done
72
73[ ! -z "$3" -a -z "$5" ] || usage
74dir="$1"
75schem="$2"
76sdir=`dirname "$schem"`
77if [ -z "$4" ]; then
78    commit=HEAD
79    outdir="$3"
80else
81    commit="$3"
82    outdir="$4"
83fi
84
85[ "$dir" != "${dir#/}" ] || dir=`pwd`/$dir
86
87[ "$commit" != HEAD -o -f "$dir/$schem" ] || usage
88[ -d "$dir/.git" ] || usage
89
90tmp="$dir/../_gitsch2ppm"
91sch="$tmp/$sdir"
92
93if ! $cache; then
94    rm -rf "$tmp"
95    rm -rf "$outdir"
96
97    git clone -s -n "$dir/.git" "$tmp" || exit
98    ( cd "$tmp" && git checkout -q "$commit"; ) || exit
99
100    if [ ! -f "$tmp/$schem" ]; then
101        echo "$schem not found (checked out into $tmp)" 1>&2
102        exit 1
103    fi
104
105    ( cd "$sch" && rm -f *.ps *.ppm && eeschema --plot "$tmp/$schem"; ) || exit
106fi
107
108for n in "$sch"/*.ps; do
109    ps2ppm "$n"
110done
111
112mkdir -p "$outdir"
113
114mv "$sch"/*.ppm "$outdir"
115
116$keep || rm -rf "$tmp"
117

Archive Download this file



interactive