summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorP. J. McDermott <pj@pehjota.net>2019-02-12 14:37:19 (EST)
committer P. J. McDermott <pj@pehjota.net>2019-02-12 14:37:19 (EST)
commit67ae256949aec4520b594e8707208571a0ce7d03 (patch)
treeb4b2f9d3657997fd060d0bfa0474b8083883dad8 /bin
parent09a6a74787952bda502bf00c73e67e5260b116ff (diff)
downloadslic3r-67ae256949aec4520b594e8707208571a0ce7d03.zip
slic3r-67ae256949aec4520b594e8707208571a0ce7d03.tar.gz
slic3r-67ae256949aec4520b594e8707208571a0ce7d03.tar.bz2
slic3r-gpp: Rewrite
Diffstat (limited to 'bin')
-rwxr-xr-xbin/slic3r-gpp100
1 files changed, 100 insertions, 0 deletions
diff --git a/bin/slic3r-gpp b/bin/slic3r-gpp
new file mode 100755
index 0000000..0c4b7ff
--- /dev/null
+++ b/bin/slic3r-gpp
@@ -0,0 +1,100 @@
+#!/bin/sh
+
+set -eu
+
+SLIC3R_CONFIG_BASE="${HOME}/.Slic3r"
+TEMPERATURES='retraction wiping probing removal_bed'
+
+warn()
+{
+ local fmt="${1}"
+ shift 1
+
+ printf "Warning: ${fmt}\n" "${@}"
+ return 0
+}
+
+preprocess()
+{
+ local printer="${1}"
+ local gcode="${2}"
+ local filament="${3}"
+ shift 3
+ local ini=
+ local temp=
+ local temp_val=
+ local script=
+ local gcode_pp=
+
+ # Find and back up printer/filament configuration
+ ini="${SLIC3R_CONFIG_BASE}/printer/${printer}, ${filament}.ini"
+ if ! cp "${ini}" "${ini}~" 2>/dev/null; then
+ warn 'Missing configuration for printer "%s" and filament "%s"'\
+ "${printer}" "${filament}"
+ return 0
+ fi
+
+ # Load and validate filament temperature settings
+ for temp in ${TEMPERATURES}; do
+ eval "local ${temp}_temperature="
+ done
+ . "${SLIC3R_CONFIG_BASE}/filament/${filament}.rc"
+ for temp in ${TEMPERATURES}; do
+ temp_val="$(eval "printf '%s' \"\${${temp}_temperature}\"")"
+ case "${temp_val}" in
+ '')
+ eval "${temp}_temperature=0"
+ ;;
+ *[!0-9]*)
+ warn 'Invalid "%s" value "%s" of filament "%s"'\
+ "${temp}_temperature" "${temp_val}" \
+ "${filament}"
+ return 0
+ ;;
+ esac
+ done
+
+ # Preprocess G-code and insert into printer/filament configuration
+ script='1h; 1!H; ${ g; s/\n/\\n/g; '
+ for temp in ${TEMPERATURES}; do
+ temp="${temp}_temperature"
+ eval "script=\"\${script}s/<\${temp}>/\${${temp}}/g; \""
+ done
+ script="${script}"'s|[\/&]|\\&|g; p; };'
+ gcode_pp="${SLIC3R_CONFIG_BASE}/printer/${printer} - ${gcode}.gcode"
+ gcode_pp="$(sed -n "${script}" 0<"${gcode_pp}")"
+ sed "s/^\\(${gcode}_gcode *= *\\).*\$/\\1${gcode_pp}/;" \
+ "${ini}~" 1>"${ini}"
+
+ return 0
+}
+
+preprocess_all()
+{
+ local gcode=
+ local printer=
+ local rc=
+ local filament=
+
+ for gcode in "${SLIC3R_CONFIG_BASE}/printer/"*' - '*'.gcode'; do
+ gcode="${gcode##*/}"
+ printer="${gcode% - *.gcode}"
+ gcode="${gcode##${printer} - }"
+ gcode="${gcode%.gcode}"
+ for rc in "${SLIC3R_CONFIG_BASE}/filament/"*'.rc'; do
+ filament="${rc##*/}"
+ filament="${filament%.rc}"
+ preprocess "${printer}" "${gcode}" "${filament}"
+ done
+ done
+
+ return 0
+}
+
+main()
+{
+ preprocess_all
+ return 0
+}
+
+main "${@}"