Root/fab/prettygerbv

Source at commit 1d762923e448b1640377d6fad33096000300b99e created 6 years 9 months ago.
By Werner Almesberger, fab/prettygerbv: search also for current KiCad Gerber file names
1#!/bin/sh
2#
3# prettygerbv - Use gerbv to generate "pretty" views of a PCB
4#
5# Written 2011, 2013, 2017 by Werner Almesberger
6# Copyright 2011, 2013, 2017 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    name=$1
62    shift
63    for n in "$@"; do
64        if [ -e "$name-$n" ]; then
65            echo "$name-$n"
66            return
67        fi
68    done
69    echo "no choice for $@" 1>&2
70    exit 1
71}
72
73
74layers_end()
75{
76    echo '(set-render-type! 2)' >>_gvp
77}
78
79
80run_gerbv()
81{
82    gerbv -p _gvp --dpi=600 -x png -o "$1"
83}
84
85
86front()
87{
88    layers_begin 5
89    layer `choose $NAME Front.gtl F_Cu.gtl F.Cu.gbr` $COPPER
90    [ "$drill" ] && layer $drill $DRILL
91    layer `choose $NAME SoldP_Front.gtp F_Paste.gtp F.Paste.gbr` $PASTE
92    layer `choose $NAME Mask_Front.gts F_Mask.gts F.Mask.gbr` $INV $MASK
93    layer `choose $NAME SilkS_Front.gto F_SilkS.gto F.SilkS.gbr` $SILK
94    layer `choose $NAME PCB_Edges.gbr Edge_Cuts.gbr Edge.Cuts.gbr` $EDGE
95    layers_end
96
97    run_gerbv "$1"
98}
99
100
101back()
102{
103    layers_begin 5
104    layer `choose $NAME Back.gbl B_Cu.gbl B.Cu.gbr` $COPPER
105    [ "$drill" ] && layer $drill $DRILL
106    layer `choose $NAME SoldP_Back.gbp B_Paste.gbp B.Paste.gbr` $PASTE
107    layer `choose $NAME Mask_Back.gbs B_Mask.gbs B.Mask.gbr` $INV $MASK
108    layer `choose $NAME SilkS_Back.gbo B_SilkS.gbo B.SilkS.gbr` $SILK
109    layer `choose $NAME PCB_Edges.gbr Edge_Cuts.gbr Edge.Cuts.gbr` $EDGE
110    layers_end
111
112    run_gerbv _tmp.png
113    convert -flop _tmp.png "$1"
114    rm -f _tmp.png
115}
116
117
118conn()
119{
120    layers_begin 3
121    layer `choose $NAME Back.gbl B_Cu.gbl B.Cu.gbr` $BACK
122    layer `choose $NAME Front.gtl F_Cu.gtl F.Cu.gbr` $FRONT
123    layer `choose $NAME PCB_Edges.gbr Edge_Cuts.gbr Edge.Cuts.gbr` $EDGE2
124    layers_end
125
126    run_gerbv "$1"
127}
128
129
130all()
131{
132    front _front.png
133    back _back.png
134    conn _conn.png
135    montage -geometry +4+4 $tile _front.png _back.png _conn.png "$1"
136    rm -f _front.png _back.png _conn.png
137}
138
139tile=
140if [ "$1" = -y ]; then
141    tile="-tile 1x3"
142    shift
143fi
144
145drill=
146if [ "$1" = -d ]; then
147    drill=$2
148    shift 2
149fi
150
151[ "$4" ] && usage
152[ ! "$3" ] && usage
153
154NAME=$1
155OUT=$3
156
157case "$2" in
158    front|back|conn) ;;
159    all) ;;
160    *) usage;;
161esac
162
163$2 "$OUT"
164
165rm -f _gvp
166

Archive Download this file

Branches:
master



interactive