maintain gcode header/footer padding with substitutions

This commit is contained in:
Stewart Allen 2021-01-30 11:46:31 -05:00
commit 00ca621f4a
3 changed files with 18 additions and 11 deletions

View file

@ -980,7 +980,7 @@
} }
} }
function constReplace(str, consts, start) { function constReplace(str, consts, start, pad) {
let cs = str.indexOf("{", start || 0), let cs = str.indexOf("{", start || 0),
ce = str.indexOf("}", cs), ce = str.indexOf("}", cs),
tok, nutok, nustr; 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 }) ||
constOp(tok, consts, "*", function(v1,v2) { return v1*v2 }) || constOp(tok, consts, "*", function(v1,v2) { return v1*v2 }) ||
consts[tok] || 0; consts[tok] || 0;
if (pad) {
nutok = nutok.toString().padEnd(ce-cs+1, ' ');
}
nustr = str.replace("{"+tok+"}",nutok); nustr = str.replace("{"+tok+"}",nutok);
return constReplace(nustr, consts, ce+1+(nustr.length-str.length)); return constReplace(nustr, consts, ce+1+(nustr.length-str.length));
} else { } else {

View file

@ -116,8 +116,12 @@
} }
}; };
function appendSub(line) { function appendSubPad(line, pad) {
append(print.constReplace(line, subst)); appendSub(line, true);
}
function appendSub(line, pad) {
append(print.constReplace(line, subst, 0, pad));
} }
function appendAll(arr) { function appendAll(arr) {
@ -126,10 +130,10 @@
arr.forEach(function(line) { append(line) }); arr.forEach(function(line) { append(line) });
} }
function appendAllSub(arr) { function appendAllSub(arr, pad) {
if (!arr) return; if (!arr) return;
if (!Array.isArray(arr)) arr = [ arr ]; 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}`); append(`; Generated by Kiri:Moto ${KIRI.version}`);
@ -174,11 +178,11 @@
if (line.indexOf("{tool}") > 0 && extruders.length > 1) { if (line.indexOf("{tool}") > 0 && extruders.length > 1) {
for (let i=0; i<extruders.length; i++) { for (let i=0; i<extruders.length; i++) {
subst.tool = i; subst.tool = i;
appendSub(line); appendSubPad(line);
} }
subst.tool = 0; subst.tool = 0;
} else { } else {
appendSub(line); appendSubPad(line);
} }
} }
@ -275,8 +279,8 @@
path.layer === 0 ? path.layer === 0 ?
(process.firstSliceHeight || process.sliceHeight) : path.height); (process.firstSliceHeight || process.sliceHeight) : path.height);
subst.z = zpos = path.z; zpos = path.z;
subst.Z = subst.z; subst.z = subst.Z = zpos.round(3);
subst.e = subst.E = outputLength; subst.e = subst.E = outputLength;
subst.layer = layer; subst.layer = layer;
subst.height = path.height.toFixed(3); subst.height = path.height.toFixed(3);

View file

@ -873,8 +873,8 @@ th, tr, td, label {
min-height: 4em !important; min-height: 4em !important;
} }
#code-preview-textarea { #code-preview-textarea {
width: 100%; width: 40em;
height: 250px; height: 12em;
font-size: 10px; font-size: 10px;
} }
.mod-end { .mod-end {