#!/bin/sh # # prettygerbv - Use gerbv to generate "pretty" views of a PCB # # Written 2011, 2013, 2017 by Werner Almesberger # Copyright 2011, 2013, 2017 Werner Almesberger # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # COPPER="(cons 'color #(65535 50401 10000))" PASTE="(cons 'color #(39083 39083 50000))" MASK="(cons 'inverted #t) (cons 'color #(8839 53994 8178))" SILK="(cons 'color #(65535 65535 65535))" EDGE="(cons 'color #(65535 65535 0))" DRILL="(cons 'color #(0 0 40000))" FRONT="(cons 'color #(65535 10000 10000))" BACK="(cons 'color #(30000 65535 30000))" EDGE2="(cons 'color #(30000 40000 65535))" usage() { cat <&2 usage: $0 [-y] [-d file] project-name view png-file view "front", "back", "conn", "all" -d file also use drill file (converted to Gerber) EOF exit 1 } layers_begin() { curr_layer=$1 echo '(gerbv-file-version! "2.0A")' >_gvp } layer() { file=$1 shift [ -e "$file" ] || return cat <>_gvp (define-layer! $curr_layer (cons 'filename "$file") $*) EOF curr_layer=`expr $curr_layer - 1` } choose() { name=$1 shift for n in "$@"; do if [ -e "$name-$n" ]; then echo "$name-$n" return fi done echo "no choice for $@" 1>&2 exit 1 } layers_end() { echo '(set-render-type! 2)' >>_gvp } run_gerbv() { gerbv -p _gvp --dpi=600 -x png -o "$1" } front() { layers_begin 5 layer `choose $NAME Front.gtl F_Cu.gtl F.Cu.gbr` $COPPER [ "$drill" ] && layer $drill $DRILL layer `choose $NAME SoldP_Front.gtp F_Paste.gtp F.Paste.gbr` $PASTE layer `choose $NAME Mask_Front.gts F_Mask.gts F.Mask.gbr` $INV $MASK layer `choose $NAME SilkS_Front.gto F_SilkS.gto F.SilkS.gbr` $SILK layer `choose $NAME PCB_Edges.gbr Edge_Cuts.gbr Edge.Cuts.gbr` $EDGE layers_end run_gerbv "$1" } back() { layers_begin 5 layer `choose $NAME Back.gbl B_Cu.gbl B.Cu.gbr` $COPPER [ "$drill" ] && layer $drill $DRILL layer `choose $NAME SoldP_Back.gbp B_Paste.gbp B.Paste.gbr` $PASTE layer `choose $NAME Mask_Back.gbs B_Mask.gbs B.Mask.gbr` $INV $MASK layer `choose $NAME SilkS_Back.gbo B_SilkS.gbo B.SilkS.gbr` $SILK layer `choose $NAME PCB_Edges.gbr Edge_Cuts.gbr Edge.Cuts.gbr` $EDGE layers_end run_gerbv _tmp.png convert -flop _tmp.png "$1" rm -f _tmp.png } conn() { layers_begin 3 layer `choose $NAME Back.gbl B_Cu.gbl B.Cu.gbr` $BACK layer `choose $NAME Front.gtl F_Cu.gtl F.Cu.gbr` $FRONT layer `choose $NAME PCB_Edges.gbr Edge_Cuts.gbr Edge.Cuts.gbr` $EDGE2 layers_end run_gerbv "$1" } all() { front _front.png back _back.png conn _conn.png montage -geometry +4+4 $tile _front.png _back.png _conn.png "$1" rm -f _front.png _back.png _conn.png } tile= if [ "$1" = -y ]; then tile="-tile 1x3" shift fi drill= if [ "$1" = -d ]; then drill=$2 shift 2 fi [ "$4" ] && usage [ ! "$3" ] && usage NAME=$1 OUT=$3 case "$2" in front|back|conn) ;; all) ;; *) usage;; esac $2 "$OUT" rm -f _gvp