Root/fab/prettygerbv

1#!/bin/sh
2#
3# prettygerbv - Use gerbv to generate "pretty" views of a PCB
4#
5# Written 2011, 2013 by Werner Almesberger
6# Copyright 2011, 2013 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))"
25
26
27usage()
28{
29    cat <<EOF 1>&2
30usage: $0 [-y] [-d file] project-name view png-file
31
32  view "front", "back", "conn", "all"
33
34  -d file also use drill file (converted to Gerber)
35EOF
36    exit 1
37}
38
39
40layers_begin()
41{
42    curr_layer=$1
43    echo '(gerbv-file-version! "2.0A")' >_gvp
44}
45
46
47layer()
48{
49    file=$1
50    shift
51    [ -e "$file" ] || return
52    cat <<EOF >>_gvp
53(define-layer! $curr_layer (cons 'filename "$file") $*)
54EOF
55    curr_layer=`expr $curr_layer - 1`
56}
57
58
59choose()
60{
61    if [ -e "$1-$3" ]; then
62        echo "$1-$3"
63    else
64        echo "$1-$2"
65    fi
66}
67
68
69layers_end()
70{
71    echo '(set-render-type! 2)' >>_gvp
72}
73
74
75run_gerbv()
76{
77    gerbv -p _gvp --dpi=600 -x png -o "$1"
78}
79
80
81front()
82{
83    layers_begin 5
84    layer `choose $NAME Front.gtl F_Cu.gtl` $COPPER
85    [ "$drill" ] && layer $drill $DRILL
86    layer `choose $NAME SoldP_Front.gtp F_Paste.gtp` $PASTE
87    layer `choose $NAME Mask_Front.gts F_Mask.gts` $INV $MASK
88    layer `choose $NAME SilkS_Front.gto F_SilkS.gto` $SILK
89    layer `choose $NAME PCB_Edges.gbr Edge_Cuts.gbr` $EDGE
90    layers_end
91
92    run_gerbv "$1"
93}
94
95
96back()
97{
98    layers_begin 5
99    layer `choose $NAME Back.gbl B_Cu.gbl` $COPPER
100    [ "$drill" ] && layer $drill $DRILL
101    layer `choose $NAME SoldP_Back.gbp B_Paste.gbp` $PASTE
102    layer `choose $NAME Mask_Back.gbs B_Mask.gbs` $INV $MASK
103    layer `choose $NAME SilkS_Back.gbo B_SilkS.gbo` $SILK
104    layer `choose $NAME PCB_Edges.gbr Edge_Cuts.gbr` $EDGE
105    layers_end
106
107    run_gerbv _tmp.png
108    convert -flop _tmp.png "$1"
109    rm -f _tmp.png
110}
111
112
113conn()
114{
115    layers_begin 3
116    layer `choose $NAME Back.gbl B_Cu.gbl` $BACK
117    layer `choose $NAME Front.gtl F_Cu.gtl` $FRONT
118    layer `choose $NAME PCB_Edges.gbr Edge_Cuts.gbr` $EDGE2
119    layers_end
120
121    run_gerbv "$1"
122}
123
124
125all()
126{
127    front _front.png
128    back _back.png
129    conn _conn.png
130    montage -geometry +4+4 $tile _front.png _back.png _conn.png "$1"
131    rm -f _front.png _back.png _conn.png
132}
133
134tile=
135if [ "$1" = -y ]; then
136    tile="-tile 1x3"
137    shift
138fi
139
140drill=
141if [ "$1" = -d ]; then
142    drill=$2
143    shift 2
144fi
145
146[ "$4" ] && usage
147[ ! "$3" ] && usage
148
149NAME=$1
150OUT=$3
151
152case "$2" in
153    front|back|conn) ;;
154    all) ;;
155    *) usage;;
156esac
157
158$2 "$OUT"
159
160rm -f _gvp
161

Archive Download this file

Branches:
master



interactive