Date:2010-08-30 06:53:59 (10 years 1 month ago)
Author:Werner Almesberger
Commit:b3f201486360ad2ffeb7d1ac24d14972d850f8ca
Message: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
Files: scripts/gitsch2ppm (4 diffs)
scripts/gitsch2ps (1 diff)
scripts/normalizeschps (1 diff)
scripts/schps2ppm (1 diff)

Change Details

scripts/gitsch2ppm
1212#
1313
1414
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 <"$1" '1d
32/%%DocumentMedia: A4.*/a-20 -10 translate
33/%%DocumentMedia: A3.*/{s/A3/A4/;a-20 -10 translate 0.70 dup scale
34}
35/%%DocumentMedia: A2.*/{s/A2/A4/;a-18 -12 translate 0.49 dup scale
36}
37/%%Orientation: Landscape/d'; ) |
38    gs -sDEVICE=ppmraw -sOutputFile=- -g$IRES -r$res \
39      -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -q - |
40      pnmflip -r270 |
41      cat >"${1%.ps}.ppm"
42}
43
44
4515usage()
4616{
4717    cat <<EOF 1>&2
...... 
5929
6030cache=false
6131keep=false
62sanitize=true
32res=
33sanitize=
34width=
6335while true; do
6436    case "$1" in
6537    -c) cache=true
...... 
6739    -k) keep=true
6840    shift;;
6941    -r) [ -z "$2" ] && usage
70    RES="$2"
42    res="-r $2"
7143    shift 2;;
72    -S) sanitize=`PATH="$PATH":\`dirname "$0"\` which sanitize-profile`
73    [ "$sanitize" = "${sanitize#/}" ] && sanitize=`pwd`/"$sanitize"
44    -S) sanitize=-S
7445    shift;;
7546    -w) [ -z "$2" ] && usage
76    LINEWIDTH="$2"
47    width="-r $2"
7748    shift 2;;
7849    -*)
7950    usage;;
...... 
8253    esac
8354done
8455
85[ ! -z "$3" -a -z "$5" ] || usage
86dir="$1"
87schem="$2"
88sdir=`dirname "$schem"`
89if [ -z "$4" ]; then
90    commit=HEAD
91    outdir="$3"
92else
93    commit="$3"
94    outdir="$4"
95fi
56tmp=`pwd`/_gitsch2ppm
57eval outdir=\${$#}
9658
97[ "$dir" != "${dir#/}" ] || dir=`pwd`/$dir
98
99[ "$commit" != HEAD -o -f "$dir/$schem" ] || usage
100[ -d "$dir/.git" ] || usage
101
102tmp="$dir/../_gitsch2ppm"
103sch="$tmp/$sdir"
59# with thanks to http://www.faqs.org/faqs/unix-faq/faq/part2/section-12.html
60argv=
61while [ $# -gt 1 ]; do
62    argv="$argv \"$1\""
63    shift
64done
65eval set x "$argv"
66shift
10467
10568if ! $cache; then
10669    rm -rf "$tmp"
10770    rm -rf "$outdir"
108
109    git clone -s -n "$dir/.git" "$tmp" || exit
110    ( cd "$tmp" && git checkout -q "$commit"; ) || exit
111
112    if [ ! -f "$tmp/$schem" ]; then
113        echo "$schem not found (checked out into $tmp)" 1>&2
114        exit 1
115    fi
116
117    (
118    cd "$sch" || exit
119    rm -f *.ps *.ppm
120    $sanitize "$tmp/${schem%.sch}.pro" ||
121      exit
122    eeschema --plot "$tmp/$schem"
123    ) || exit
71    gitsch2ps $sanitize "$@" "$tmp"
72    for n in "$tmp"/*.ps; do
73    normalizeschps $width "$n"
74    done
12475fi
12576
126for n in "$sch"/*.ps; do
127    ps2ppm "$n"
128done
129
13077mkdir -p "$outdir"
131
132mv "$sch"/*.ppm "$outdir"
78for n in "$tmp"/*.ps; do
79    schps2ppm $res "$n" "$outdir/`basename \"${n%.ps}.ppm\"`"
80done
13381
13482$keep || rm -rf "$tmp"
scripts/gitsch2ps
1#!/bin/sh
2#
3# gitsch2ps - Generate PS 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
15usage()
16{
17    cat <<EOF 1>&2
18usage: $0 [options] top-dir top-schem [commit] outdir
19
20  -S sanitize the KiCad profile
21EOF
22    exit 1
23}
24
25
26sanitize=true
27while true; do
28    case "$1" in
29    -S) sanitize=`PATH="$PATH":\`dirname "$0"\` which sanitize-profile`
30    [ "$sanitize" = "${sanitize#/}" ] && sanitize=`pwd`/"$sanitize"
31    shift;;
32    -*)
33    usage;;
34    *)
35    break;;
36    esac
37done
38
39[ ! -z "$3" -a -z "$5" ] || usage
40dir="$1"
41schem="$2"
42sdir=`dirname "$schem"`
43if [ -z "$4" ]; then
44    commit=HEAD
45    outdir="$3"
46else
47    commit="$3"
48    outdir="$4"
49fi
50
51[ "$dir" != "${dir#/}" ] || dir=`pwd`/$dir
52
53[ "$commit" != HEAD -o -f "$dir/$schem" ] || usage
54[ -d "$dir/.git" ] || usage
55
56tmp="$dir/../_gitsch2ps"
57sch="$tmp/$sdir"
58
59rm -rf "$tmp"
60rm -rf "$outdir"
61
62git clone -s -n "$dir/.git" "$tmp" || exit
63( cd "$tmp" && git checkout -q "$commit"; ) || exit
64
65if [ ! -f "$tmp/$schem" ]; then
66    echo "$schem not found (checked out into $tmp)" 1>&2
67    exit 1
68fi
69
70(
71    cd "$sch" || exit
72    rm -f *.ps
73    $sanitize "$tmp/${schem%.sch}.pro" ||
74      exit
75    eeschema --plot "$tmp/$schem"
76) || exit
77
78mkdir -p "$outdir"
79mv "$sch"/*.ps "$outdir"
80
81rm -rf "$tmp"
scripts/normalizeschps
1#!/bin/sh
2#
3# normalizeschps - Normalize eeschema Postscript
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
15LINEWIDTH=120
16
17
18usage()
19{
20    cat <<EOF 1>&2
21usage: $0 [options] file ...
22
23  -w points Postscript line width (default: $LINEWIDTH)
24EOF
25    exit 1
26}
27
28
29while true; do
30    case "$1" in
31    -w) [ -z "$2" ] && usage
32    LINEWIDTH="$2"
33    shift 2;;
34    -*)
35    usage;;
36    *)
37    break;;
38    esac
39done
40
41for n in "$@"; do
42    sed -i '
43      1c%!PS-Adobe-3.0\
44      currentdict /DidNormalize known not { \
45          /setlinewidth { '$LINEWIDTH' 2 copy lt { exch } if pop \
46            setlinewidth } bind def \
47          /rectfill { rectstroke } bind def \
48      /DidNormalize true def \
49      } if \
50      gsave
51      /%%DocumentMedia: A4.*/a-20 -10 translate
52      /%%DocumentMedia: A3.*/{s/A3/A4/;a-20 -10 translate 0.70 dup scale
53      }
54      /%%DocumentMedia: A2.*/{s/A2/A4/;a-18 -12 translate 0.49 dup scale
55      }
56      $agrestore' "$n"
57done
58
59# /%%Orientation: Landscape/d' "$n"
scripts/schps2ppm
1#!/bin/sh
2#
3# schps2ppm - Generate PPM files from normalized Eeschema Postscript
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
16
17
18usage()
19{
20    cat <<EOF 1>&2
21usage: $0 [options] [file.ps [file.ppm]]
22
23  -r XxY image resolution (default: $RES)
24EOF
25    exit 1
26}
27
28
29while true; do
30    case "$1" in
31    -r) [ -z "$2" ] && usage
32    RES="$2"
33    shift 2;;
34    -*)
35    usage;;
36    *)
37    break;;
38    esac
39done
40
41[ ! -z "$3" ] && usage
42in=${1:--}
43out=${2:-/dev/stdout}
44
45X=`echo $RES | sed 's/x.*//'`
46Y=`echo $RES | sed 's/.*x//'`
47IRES=${Y}x$X
48res=`expr 72 \* $X / 800`
49
50cat "$in" |
51  gs -sDEVICE=ppmraw -sOutputFile=- -g$IRES -r$res \
52  -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -q - |
53  pnmflip -r270 >"$out"

Archive Download the corresponding diff file



interactive