From 00ca621f4a10b58ef8b1304efca41634a09ec2b1 Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Sat, 30 Jan 2021 11:46:31 -0500 Subject: [PATCH] maintain gcode header/footer padding with substitutions --- src/kiri/print.js | 5 ++++- src/mode/fdm/export.js | 20 ++++++++++++-------- web/kiri/index.css | 4 ++-- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/kiri/print.js b/src/kiri/print.js index 2543eba6..5f98da55 100644 --- a/src/kiri/print.js +++ b/src/kiri/print.js @@ -980,7 +980,7 @@ } } - function constReplace(str, consts, start) { + function constReplace(str, consts, start, pad) { let cs = str.indexOf("{", start || 0), ce = str.indexOf("}", cs), tok, nutok, nustr; @@ -992,6 +992,9 @@ constOp(tok, consts, "/", function(v1,v2) { return v1/v2 }) || constOp(tok, consts, "*", function(v1,v2) { return v1*v2 }) || consts[tok] || 0; + if (pad) { + nutok = nutok.toString().padEnd(ce-cs+1, ' '); + } nustr = str.replace("{"+tok+"}",nutok); return constReplace(nustr, consts, ce+1+(nustr.length-str.length)); } else { diff --git a/src/mode/fdm/export.js b/src/mode/fdm/export.js index 6ee04fe1..761cda6b 100644 --- a/src/mode/fdm/export.js +++ b/src/mode/fdm/export.js @@ -116,8 +116,12 @@ } }; - function appendSub(line) { - append(print.constReplace(line, subst)); + function appendSubPad(line, pad) { + appendSub(line, true); + } + + function appendSub(line, pad) { + append(print.constReplace(line, subst, 0, pad)); } function appendAll(arr) { @@ -126,10 +130,10 @@ arr.forEach(function(line) { append(line) }); } - function appendAllSub(arr) { + function appendAllSub(arr, pad) { if (!arr) return; if (!Array.isArray(arr)) arr = [ arr ]; - arr.forEach(function(line) { appendSub(line) }); + arr.forEach(function(line) { appendSub(line, pad) }); } append(`; Generated by Kiri:Moto ${KIRI.version}`); @@ -174,11 +178,11 @@ if (line.indexOf("{tool}") > 0 && extruders.length > 1) { for (let i=0; i