Root/fab/m1/prettygerbv

1#!/bin/sh
2#
3# prettygerbv - Use gerbv to generate "pretty" views of a PCB
4#
5# Written 2011 by Werner Almesberger
6# Copyright 2011 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
15COPPER="(cons 'color #(65535 50401 10000))"
16PASTE="(cons 'color #(39083 39083 50000))"
17MASK="(cons 'inverted #t) (cons 'color #(8839 53994 8178))"
18SILK="(cons 'color #(65535 65535 65535))"
19EDGE="(cons 'color #(65535 65535 0))"
20DRILL="(cons 'color #(0 0 40000))"
21
22FRONT="(cons 'color #(65535 10000 10000))"
23BACK="(cons 'color #(30000 65535 30000))"
24EDGE2="(cons 'color #(30000 40000 65535))"
25L2="(cons 'color #(1000 1000 1000))"
26L3="(cons 'color #(1000 1000 1000))"
27L4="(cons 'color #(1000 1000 1000))"
28L5="(cons 'color #(1000 1000 1000))"
29
30
31usage()
32{
33    cat <<EOF 1>&2
34usage: $0 [-d file] project-name view png-file
35
36  view "front", "back", "conn", "all"
37
38  -d file also use drill file (converted to Gerber)
39EOF
40    exit 1
41}
42
43
44layers_begin()
45{
46    curr_layer=$1
47    echo '(gerbv-file-version! "2.0A")' >_gvp
48}
49
50
51layer()
52{
53    file=$1
54    shift
55    [ -e "$file" ] || return
56    cat <<EOF >>_gvp
57(define-layer! $curr_layer (cons 'filename "$file") $*)
58EOF
59    curr_layer=`expr $curr_layer - 1`
60}
61
62
63layers_end()
64{
65    echo '(set-render-type! 2)' >>_gvp
66}
67
68
69run_gerbv()
70{
71    gerbv -p _gvp --dpi=600 -x png -o "$1"
72}
73
74
75front()
76{
77    layers_begin 5
78    layer art01.pho $COPPER
79    [ "$drill" ] && layer $drill $DRILL
80    layer smd0129.pho $PASTE
81    layer sm0125.pho $INV $MASK
82    layer sst0127.pho $SILK
83# layer $NAME-PCB_Edges.gbr $EDGE
84    layers_end
85
86    run_gerbv "$1"
87}
88
89
90back()
91{
92    layers_begin 5
93    layer art06.pho $COPPER
94    [ "$drill" ] && layer $drill $DRILL
95    layer smd0630.pho $PASTE
96    layer sm0626.pho $INV $MASK
97    layer ssb0628.pho $SILK
98# layer $NAME-PCB_Edges.gbr $EDGE
99    layers_end
100
101    run_gerbv _tmp.png
102    convert -flop _tmp.png "$1"
103    rm -f _tmp.png
104}
105
106
107conn()
108{
109    layers_begin 3
110# layer art06.pho $BACK
111# layer art05.pho $L5
112# layer art04.pho $L4
113# layer art03.pho $L3
114# layer art02.pho $L2
115# layer art01.pho $FRONT
116# layer $NAME-PCB_Edges.gbr $EDGE2
117    layer art02.pho $BACK
118    layer art01.pho $FRONT
119    [ "$drill" ] && layer $drill $DRILL
120    layers_end
121
122    run_gerbv "$1"
123}
124
125
126all()
127{
128    front _front.png
129    back _back.png
130    conn _conn.png
131    montage -geometry +4+4 _front.png _back.png _conn.png "$1"
132    rm -f _front.png _back.png _conn.png
133}
134
135drill=
136if [ "$1" = -d ]; then
137    drill=$2
138    shift 2
139fi
140
141[ "$4" ] && usage
142[ ! "$3" ] && usage
143
144NAME=$1
145OUT=$3
146
147case "$2" in
148    front|back|conn) ;;
149    all) ;;
150    *) usage;;
151esac
152
153$2 "$OUT"
154
155#rm -f _gvp
156

Archive Download this file

Branches:
master



interactive