Initial release
This commit is contained in:
67
scripts/kicad_pcb.sh
Normal file
67
scripts/kicad_pcb.sh
Normal file
@@ -0,0 +1,67 @@
|
||||
#!/bin/bash
|
||||
#set -x
|
||||
INPUT="$*"
|
||||
OUTDIR=$(mktemp -d)
|
||||
IMGDIR="$GITEA_WORK_DIR/custom/public/assets/img"
|
||||
|
||||
KIOPTS=(
|
||||
# --subtract-soldermask
|
||||
--mode-single
|
||||
--exclude-drawing-sheet
|
||||
--page-size-mode 2
|
||||
--sketch-pads-on-fab-layers
|
||||
)
|
||||
|
||||
ln -s "$INPUT" "$OUTDIR"/pcb.kicad_pcb
|
||||
|
||||
if [[ -d "$IMGDIR" && -w "$IMGDIR" ]]; then
|
||||
# We can use caching
|
||||
HASH=$(sha256sum "$INPUT" | cut -c1-64)
|
||||
|
||||
shopt -s nullglob
|
||||
IMAGES=("${IMGDIR}"/${HASH}.*.svg)
|
||||
shopt -u nullglob
|
||||
|
||||
if [ ${#IMAGES[@]} -le 0 ]; then
|
||||
kicad-cli pcb export svg "${KIOPTS[@]}" --layers Edge.Cuts,F.Cu,F.Mask,F.Silkscreen,F.Adhesive,F.Paste --output "${OUTDIR}/${HASH}.1.svg" "$OUTDIR"/pcb.kicad_pcb >/dev/null
|
||||
kicad-cli pcb export svg "${KIOPTS[@]}" --mirror --layers Edge.Cuts,B.Cu,B.Mask,B.Silkscreen,B.Adhesive,B.Paste --output "${OUTDIR}/${HASH}.2.svg" "$OUTDIR"/pcb.kicad_pcb >/dev/null
|
||||
|
||||
inkscape --actions="page-fit-to-selection" -o "${IMGDIR}/${HASH}.1.svg" "${OUTDIR}/${HASH}.1.svg"
|
||||
inkscape --actions="page-fit-to-selection" -o "${IMGDIR}/${HASH}.2.svg" "${OUTDIR}/${HASH}.2.svg"
|
||||
|
||||
shopt -s nullglob
|
||||
IMAGES=("${IMGDIR}"/${HASH}.*.svg)
|
||||
shopt -u nullglob
|
||||
fi
|
||||
|
||||
echo '<div class="file">'
|
||||
for IMG in "${IMAGES[@]}"; do
|
||||
echo '<div class="page">'
|
||||
# echo "bla"
|
||||
echo -n '<img src="/assets/img/'
|
||||
echo -n "$(basename "${IMG}")"
|
||||
echo -n '"'
|
||||
echo -n ' class="full_width kicad_pcb pan_zoom"'
|
||||
echo '/>'
|
||||
echo '</div>'
|
||||
done
|
||||
echo '</div></div>'
|
||||
|
||||
else
|
||||
echo "<p>Error: Unable to write to $IMGDIR. Please check permissions.</p>"
|
||||
# TODO: Implement base64 method
|
||||
# We'll be generating the images on the fly, including them as base64
|
||||
# mapfile -t FILES \
|
||||
# < <(kicad-cli sch export svg --exclude-drawing-sheet --no-background-color --output "$OUTDIR" "$OUTDIR/pcb.kicad_pcb" | grep -E 'Plotted to' | sed -r "s/^[^']+'|'[^']+$//g" )
|
||||
# for FILE in "${FILES[@]}"; do
|
||||
# echo -n '<div class="file"><div class="page">'
|
||||
# echo -n '<img src="data:image/svg+xml;base64,'
|
||||
# inkscape --actions="page-fit-to-selection" -o - "$FILE" | base64 --wrap=0
|
||||
# echo -n '"'
|
||||
# echo -n ' class="full_width kicad_pcb pan_zoom"'
|
||||
# echo -n '/>'
|
||||
# echo '</div></div>'
|
||||
# done
|
||||
fi
|
||||
|
||||
rm -R "$OUTDIR"
|
62
scripts/kicad_sch.sh
Normal file
62
scripts/kicad_sch.sh
Normal file
@@ -0,0 +1,62 @@
|
||||
#!/bin/bash
|
||||
#set -x
|
||||
INPUT="$*"
|
||||
OUTDIR=$(mktemp -d)
|
||||
IMGDIR="$GITEA_WORK_DIR/custom/public/assets/img"
|
||||
|
||||
ln -s "$INPUT" "$OUTDIR"/schematic.kicad_sch
|
||||
|
||||
if [[ -d "$IMGDIR" && -w "$IMGDIR" ]]; then
|
||||
# We can use caching
|
||||
HASH=$(sha256sum "$INPUT" | cut -c1-64)
|
||||
|
||||
shopt -s nullglob
|
||||
IMAGES=("${IMGDIR}"/${HASH}.*.svg)
|
||||
shopt -u nullglob
|
||||
|
||||
if [ ${#IMAGES[@]} -le 0 ]; then
|
||||
mapfile -t FILES \
|
||||
< <(kicad-cli sch export svg --exclude-drawing-sheet --no-background-color --output "$OUTDIR" "$OUTDIR/schematic.kicad_sch" | grep -E 'Plotted to' | sed -r "s/^[^']+'|'[^']+$//g" )
|
||||
|
||||
file_num=1
|
||||
for FILE in "${FILES[@]}"; do
|
||||
FN="${IMGDIR}/${HASH}.${file_num}.svg"
|
||||
inkscape --actions="page-fit-to-selection" -o "$FN" "$FILE"
|
||||
file_num=$((file_num + 1))
|
||||
break # TODO: find some way to handle related (hierarchical) schematic files, as currently only the active file is made available
|
||||
done
|
||||
|
||||
shopt -s nullglob
|
||||
IMAGES=("${IMGDIR}"/${HASH}.*.svg)
|
||||
shopt -u nullglob
|
||||
fi
|
||||
|
||||
for FILE in "${IMAGES[@]}"; do
|
||||
echo '<div class="file"><div class="page">'
|
||||
# echo "bla"
|
||||
echo -n '<img src="/assets/img/'
|
||||
echo -n "$(basename "${FILE}")"
|
||||
echo -n '"'
|
||||
echo -n ' class="full_width kicad_sch pan_zoom"'
|
||||
echo '/>'
|
||||
echo '</div></div>'
|
||||
done
|
||||
|
||||
else
|
||||
# We'll be generating the images on the fly, including them as base64
|
||||
mapfile -t FILES \
|
||||
< <(kicad-cli sch export svg --exclude-drawing-sheet --no-background-color --output "$OUTDIR" "$OUTDIR/schematic.kicad_sch" | grep -E 'Plotted to' | sed -r "s/^[^']+'|'[^']+$//g" )
|
||||
for FILE in "${FILES[@]}"; do
|
||||
echo -n '<div class="file"><div class="page">'
|
||||
echo -n '<img src="data:image/svg+xml;base64,'
|
||||
inkscape --actions="page-fit-to-selection" -o - "$FILE" | base64 --wrap=0
|
||||
echo -n '"'
|
||||
echo -n ' class="full_width kicad_sch pan_zoom"'
|
||||
echo -n '/>'
|
||||
echo '</div></div>'
|
||||
|
||||
break # TODO: find some way to handle related (hierarchical) schematic files, as currently only the active file is made available
|
||||
done
|
||||
fi
|
||||
|
||||
rm -R "$OUTDIR"
|
72
scripts/libreoffice.sh
Normal file
72
scripts/libreoffice.sh
Normal file
@@ -0,0 +1,72 @@
|
||||
#!/bin/bash
|
||||
#set -x
|
||||
INPUT="$*"
|
||||
OUTDIR=$(mktemp -d)
|
||||
IMGDIR="$GITEA_WORK_DIR/custom/public/assets/img"
|
||||
|
||||
if [[ -d "$IMGDIR" && -w "$IMGDIR" ]]; then
|
||||
# We can use caching
|
||||
HASH=$(sha256sum "$INPUT" | cut -c1-64)
|
||||
|
||||
shopt -s nullglob
|
||||
IMAGES=("${IMGDIR}"/${HASH}.*.svg)
|
||||
shopt -u nullglob
|
||||
|
||||
if [ ${#IMAGES[@]} -le 0 ]; then
|
||||
libreoffice --headless --convert-to pdf --outdir "$OUTDIR" $INPUT >/dev/null
|
||||
|
||||
PDF_FILE="$OUTDIR/$(basename "${INPUT%.*}".pdf)"
|
||||
|
||||
NUM_PAGES=$(pdfinfo "$PDF_FILE" | grep Pages | awk '{print $2}')
|
||||
|
||||
for (( i=1; i<=$NUM_PAGES; i++ )); do
|
||||
FN="${IMGDIR}/${HASH}.${i}.svg"
|
||||
pdftocairo -svg -f $i -l $i "$PDF_FILE" "${FN}"
|
||||
done
|
||||
|
||||
shopt -s nullglob
|
||||
IMAGES=("${IMGDIR}"/${HASH}.*.svg)
|
||||
shopt -u nullglob
|
||||
fi
|
||||
|
||||
echo '<div class="file">'
|
||||
for IMG in "${IMAGES[@]}"; do
|
||||
echo '<div class="page">'
|
||||
echo -n '<img src="/assets/img/'
|
||||
echo -n "$(basename "${IMG}")"
|
||||
echo -n '"'
|
||||
echo -n ' class="full_width libreoffice pan_zoom"'
|
||||
echo '/>'
|
||||
echo '</div>'
|
||||
done
|
||||
echo '</div>'
|
||||
|
||||
else
|
||||
# We'll be generating the images on the fly, including them as base64
|
||||
libreoffice --headless --convert-to pdf --outdir "$OUTDIR" $INPUT >/dev/null
|
||||
PDF_FILE="$OUTDIR/$(basename "${INPUT%.*}".pdf)"
|
||||
NUM_PAGES=$(pdfinfo "$PDF_FILE" | grep Pages | awk '{print $2}')
|
||||
|
||||
for (( i=1; i<=$NUM_PAGES; i++ )); do
|
||||
FN="${IMGDIR}/${HASH}.${i}.svg"
|
||||
pdftocairo -svg -f $i -l $i "$PDF_FILE" "${FN}"
|
||||
done
|
||||
|
||||
shopt -s nullglob
|
||||
IMAGES=("${IMGDIR}"/${HASH}.*.svg)
|
||||
shopt -u nullglob
|
||||
|
||||
echo '<div class="file">'
|
||||
for IMG in "${IMAGES[@]}"; do
|
||||
echo '<div class="page">'
|
||||
echo -n '<img src="/assets/img/'
|
||||
base64 --wrap=0 < "${IMG}"
|
||||
echo -n '"'
|
||||
echo -n ' class="full_width libreoffice pan_zoom"'
|
||||
echo '/>'
|
||||
echo '</div>'
|
||||
done
|
||||
echo '</div>'
|
||||
fi
|
||||
|
||||
rm -R "$OUTDIR"
|
Reference in New Issue
Block a user