Root/scripts/gitsch2ppm

Source at commit 2921bcea47bc9926587d60469c8bbd2e02d906a8 created 13 years 7 months ago.
By Werner Almesberger, New script sanitize-profile to remove glitches from a KiCad profile.
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  -S sanitize the KiCad profile
47  -w points Postscript line width (default: $LINEWIDTH)
48EOF
49    exit 1
50}
51
52
53cache=false
54keep=false
55sanitize=true
56while true; do
57    case "$1" in
58    -c) cache=true
59    shift;;
60    -k) keep=true
61    shift;;
62    -r) [ -z "$2" ] && usage
63    RES="$2"
64    shift 2;;
65    -S) sanitize=`PATH="$PATH":\`dirname "$0"\` which sanitize-profile`
66    [ "$sanitize" = "${sanitize#/}" ] && sanitize=`pwd`/"$sanitize"
67    shift;;
68    -w) [ -z "$2" ] && usage
69    LINEWIDTH="$2"
70    shift 2;;
71    -*)
72    usage;;
73    *)
74    break;;
75    esac
76done
77
78[ ! -z "$3" -a -z "$5" ] || usage
79dir="$1"
80schem="$2"
81sdir=`dirname "$schem"`
82if [ -z "$4" ]; then
83    commit=HEAD
84    outdir="$3"
85else
86    commit="$3"
87    outdir="$4"
88fi
89
90[ "$dir" != "${dir#/}" ] || dir=`pwd`/$dir
91
92[ "$commit" != HEAD -o -f "$dir/$schem" ] || usage
93[ -d "$dir/.git" ] || usage
94
95tmp="$dir/../_gitsch2ppm"
96sch="$tmp/$sdir"
97
98if ! $cache; then
99    rm -rf "$tmp"
100    rm -rf "$outdir"
101
102    git clone -s -n "$dir/.git" "$tmp" || exit
103    ( cd "$tmp" && git checkout -q "$commit"; ) || exit
104
105    if [ ! -f "$tmp/$schem" ]; then
106        echo "$schem not found (checked out into $tmp)" 1>&2
107        exit 1
108    fi
109
110    (
111    cd "$sch" || exit
112    rm -f *.ps *.ppm
113    $sanitize "$tmp"/`dirname "$schem"`/`basename "$schem" .sch`.pro ||
114      exit
115    eeschema --plot "$tmp/$schem"
116    ) || exit
117fi
118
119for n in "$sch"/*.ps; do
120    ps2ppm "$n"
121done
122
123mkdir -p "$outdir"
124
125mv "$sch"/*.ppm "$outdir"
126
127$keep || rm -rf "$tmp"
128

Archive Download this file



interactive