-
Notifications
You must be signed in to change notification settings - Fork 4
/
render-pcb.sh
90 lines (73 loc) · 2.37 KB
/
render-pcb.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/bin/bash
set -e
help() {
echo "Convert .kicad_pcb file to front and back image and optionaly render an animation"
echo
echo "Syntax: render-pcb.sh [-f|o|a|h]"
echo "options:"
echo "f Path to .kicad_pcb file"
echo "b Image background. Options: transparent, opaque. Default: transparent for PNG, opaque for JPEG"
echo "o Directory where the images and optinally the animation should be written to."
echo "a Render animation and select animation output format (mp4 or gif)."
echo "z Camera zoom default 1"
echo "v Print protgram version"
echo "h Print this Help."
echo
exit
}
extract_project_name() {
echo "$1" | rev | cut -d '/' -f 1 | rev | sed -e "s/.kicad_pcb//g"
}
extract_output_path() {
echo "$1" | sed -e 's/[^\/]*\.kicad_pcb//g'
}
background="transparent"
while getopts :f:o:a:b:z:hv option
do
case "${option}" in
f) kicad_pcb=${OPTARG};;
o) output_path=${OPTARG};;
a) animation=${OPTARG};;
b) background=${OPTARG};;
z) zoom=${OPTARG};;
h) help;;
v) echo "IMAGE version: ${VERSION:-none}" && exit;;
\?)
echo "Error: -${OPTARG} is invalid option"
exit;
esac
done
if [[ -z "$kicad_pcb" ]]; then
help
fi
if [[ -z "$output_path" ]]; then
path=$(extract_output_path "$2")
name=$(extract_project_name "$2")
echo "name: $name"
echo "path: $path"
output_path="$path"
output_top="${path}${name}_top.png"
output_bottom="${path}${name}_bottom.png"
echo "output_top: $output_top"
echo "output_bottom: $output_bottom"
else
output_top="$output_path/top.png"
output_bottom="$output_path/bottom.png"
output_animation="$output_path"
fi
KICAD_CLI=$(which kicad-cli || which kicad-cli-nightly)
echo "$output_path"
mkdir -p "$output_path"
KICAD_CLI_OPTIONAL_ARGS=""
if [[ -n "$zoom" ]]; then
KICAD_CLI_OPTIONAL_ARGS="$KICAD_CLI_OPTIONAL_ARGS --zoom $zoom"
fi
echo "rendering top"
$KICAD_CLI pcb render --side top --background $background -o "$output_top" "$kicad_pcb" $KICAD_CLI_OPTIONAL_ARGS
echo "rendering bottom"
$KICAD_CLI pcb render --side bottom --background $background -o "$output_bottom" "$kicad_pcb" $KICAD_CLI_OPTIONAL_ARGS
if [[ -n "$animation" ]]; then
echo "rendering animation"
kicad_animation.sh $animation "$kicad_pcb" "$output_animation"
fi
ls "$output_path"