Skip to content

Commit 86980a1

Browse files
committed
output option is now optional
1 parent 31bef9d commit 86980a1

File tree

3 files changed

+52
-13
lines changed

3 files changed

+52
-13
lines changed

Dockerfile

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@ COPY *.sh /usr/bin/
1313

1414
RUN sudo chmod a+rx /usr/bin/render-pcb.sh && sudo chmod a+rx /usr/bin/kicad_animation.sh
1515

16-
USER root
16+
USER root
17+
18+
WORKDIR /pwd

kicad_animation.sh

+23-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,26 @@
44
# Original by: arturo182
55
# gist: https://gist.github.com/arturo182/57ab066e6a4a36ee22979063e4d5cce1
66
#
7+
8+
extract_project_name() {
9+
echo "$1" | rev | cut -d '/' -f 1 | rev | sed -e "s/.kicad_pcb//g"
10+
}
11+
12+
extract_output_path() {
13+
echo "$1" | sed -e "s/[^\/]*\.kicad_pcb//g"
14+
}
15+
16+
OUTPUT_FILE=""
17+
18+
if [[ -z "$3" ]]; then
19+
path=$(extract_output_path "$2")
20+
name=$(extract_project_name "$2")
21+
OUTPUT_FILE="${path}${name}"
22+
echo "OUTPUT_FILE: $OUTPUT_FILE"
23+
else
24+
OUTPUT_FILE="$3/rotating"
25+
fi
26+
727
FORMAT="$1"
828
OUTPUT_DIR="${3:-/pwd}"
929
FRAME_DIR="/tmp/render"
@@ -27,17 +47,17 @@ for ((i = 0; i < FRAMES; i++)); do
2747
ROTATE_Y=-$(($i * STEP))
2848
OUTPUT_PATH="$FRAME_DIR/frame$i.png"
2949
echo "Rendering frame $i ($ROTATE_Y degrees) to $OUTPUT_PATH"
30-
$KICAD_CLI pcb render --rotate "$ROTATE_X,$ROTATE_Y,$ROTATE_Z" --zoom $ZOOM -w $WIDTH -h $HEIGHT --background opaque -o $OUTPUT_PATH $INPUT_FILE > /dev/null
50+
$KICAD_CLI pcb render --rotate "$ROTATE_X,$ROTATE_Y,$ROTATE_Z" --zoom $ZOOM -w $WIDTH -h $HEIGHT --background opaque -o $OUTPUT_PATH "$INPUT_FILE" > /dev/null
3151
done
3252

3353
# Combine frames into an MP4 with the specified framerate
3454
if [[ $FORMAT == "mp4" ]]; then
3555
echo "Combining frames into an MP4..."
36-
ffmpeg -y -framerate $FRAMERATE -i "$FRAME_DIR/frame%d.png" -c:v libx264 -r 30 -pix_fmt yuv420p "$OUTPUT_DIR/rotating.mp4"
56+
ffmpeg -y -framerate $FRAMERATE -i "$FRAME_DIR/frame%d.png" -c:v libx264 -r 30 -pix_fmt yuv420p "$OUTPUT_FILE.mp4"
3757
echo "MP4 created successfully."
3858
elif [[ $FORMAT == "gif" ]]; then
3959
echo "Combining frames into an GIF..."
40-
ffmpeg -y -framerate $FRAMERATE -i "$FRAME_DIR/frame%d.png" "$OUTPUT_DIR/rotating.gif"
60+
ffmpeg -y -framerate $FRAMERATE -i "$FRAME_DIR/frame%d.png" "$OUTPUT_FILE.gif"
4161
echo "GIF created successfully."
4262
else
4363
# TODO: this should be vaildated before rendering anything

render-pcb.sh

+26-9
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,14 @@ help() {
1515
exit
1616
}
1717

18-
output_path="/pwd"
18+
extract_project_name() {
19+
echo "$1" | rev | cut -d '/' -f 1 | rev | sed -e "s/.kicad_pcb//g"
20+
}
21+
22+
extract_output_path() {
23+
echo "$1" | sed -e 's/[^\/]*\.kicad_pcb//g'
24+
}
25+
1926
background="transparent"
2027

2128
while getopts :f:o:a:b:hv option
@@ -37,27 +44,37 @@ if [[ -z "$kicad_pcb" ]]; then
3744
help
3845
fi
3946

40-
if [[ -n "$animation" ]]; then
41-
if [ "$animation" != "gif" ] -a [[ "$animation" != "mp4" ]]; then
42-
help
43-
fi
47+
if [[ -z "$output_path" ]]; then
48+
path=$(extract_output_path "$2")
49+
name=$(extract_project_name "$2")
50+
echo "name: $name"
51+
echo "path: $path"
52+
output_path="$path"
53+
output_top="${path}${name}_top.png"
54+
output_bottom="${path}${name}_bottom.png"
55+
echo "output_top: $output_top"
56+
echo "output_bottom: $output_bottom"
57+
else
58+
output_top="$output_path/top.png"
59+
output_bottom="$output_path/bottom.png"
60+
output_animation="$output_path"
4461
fi
4562

4663

47-
4864
KICAD_CLI=$(which kicad-cli || which kicad-cli-nightly)
4965

5066
echo "$output_path"
5167

5268
mkdir -p "$output_path"
69+
5370
echo "rendering top"
54-
$KICAD_CLI pcb render --side top --background $background -o "$output_path/top.png" "$kicad_pcb"
71+
$KICAD_CLI pcb render --side top --background $background -o "$output_top" "$kicad_pcb"
5572
echo "rendering bottom"
56-
$KICAD_CLI pcb render --side bottom --background $background -o "$output_path/bottom.png" "$kicad_pcb"
73+
$KICAD_CLI pcb render --side bottom --background $background -o "$output_bottom" "$kicad_pcb"
5774

5875
if [[ -n "$animation" ]]; then
5976
echo "rendering animation"
60-
kicad_animation.sh $animation "$kicad_pcb" "$output_path"
77+
kicad_animation.sh $animation "$kicad_pcb" "$output_animation"
6178
fi
6279

6380
ls "$output_path"

0 commit comments

Comments
 (0)