add gcode macro if/elif/else/end logic flow
This commit is contained in:
parent
18f140a9ec
commit
03664c27ae
2 changed files with 46 additions and 7 deletions
|
|
@ -132,6 +132,12 @@
|
|||
purgeOn = 0,
|
||||
purgeOff = 0;
|
||||
|
||||
let tools_used = Object.keys(print.tools);
|
||||
for (let tool of tools_used) {
|
||||
subst[`tool_used_${tool}`] = true;
|
||||
}
|
||||
subst.tool_count = tools_used.length;
|
||||
|
||||
// smallish band-aid. refactor above to remove redundancy
|
||||
function updateParams(layer) {
|
||||
let params = getRangeParameters(process, layer);
|
||||
|
|
@ -204,8 +210,31 @@
|
|||
appendSub(line, true);
|
||||
}
|
||||
|
||||
let subon = true;
|
||||
let ifhit = false;
|
||||
|
||||
// eval() based var substitution (from print)
|
||||
// with logic flow IF / ELIF / ELSE / END
|
||||
// IF / IF is valid but will not nest
|
||||
function appendSub(line, pad) {
|
||||
append(print.constReplace(line, subst, 0, pad));
|
||||
if (line.indexOf(';; IF ') === 0) {
|
||||
line = line.substring(6).trim();
|
||||
let evil = print.constReplace(line, subst, 0, 666);
|
||||
subon = evil;
|
||||
ifhit = subon;
|
||||
} else if (line.indexOf(';; ELIF ') === 0) {
|
||||
line = line.substring(6).trim();
|
||||
let evil = print.constReplace(line, subst, 0, 666);
|
||||
subon = !subon && evil;
|
||||
ifhit = ifhit || subon;
|
||||
} else if (line.indexOf(';; ELSE') === 0) {
|
||||
subon = !ifhit && !subon;
|
||||
} else if (line.indexOf(';; END') === 0) {
|
||||
subon = true;
|
||||
ifhit = false;
|
||||
} else if (subon) {
|
||||
append(print.constReplace(line, subst, 0, pad));
|
||||
}
|
||||
}
|
||||
|
||||
function appendAll(arr) {
|
||||
|
|
@ -244,7 +273,6 @@
|
|||
}
|
||||
append("; --- process ---");
|
||||
for (let pk in process) {
|
||||
// append("; " + pk + " = " + process[pk]);
|
||||
appendTok("; ", pk, " = ", process[pk]);
|
||||
}
|
||||
append("; --- startup ---");
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@
|
|||
lastE,
|
||||
lastPos,
|
||||
nextType,
|
||||
tools = {},
|
||||
debugE; // set to 1 to enable flow rate analysis (console)
|
||||
|
||||
KIRI.Print = Print;
|
||||
|
|
@ -36,6 +37,7 @@
|
|||
lastEmit = null;
|
||||
lastOut = null;
|
||||
lastPos = null;
|
||||
tools = {};
|
||||
return new Print(settings, widgets, id);
|
||||
};
|
||||
|
||||
|
|
@ -49,6 +51,7 @@
|
|||
this.settings = settings;
|
||||
this.widgets = widgets;
|
||||
this.setType = setType;
|
||||
this.tools = tools;
|
||||
debugE = settings ? (settings.controller.devel ? 1 : 0) : 0;
|
||||
}
|
||||
|
||||
|
|
@ -420,6 +423,7 @@
|
|||
this.speed = speed;
|
||||
this.tool = tool;
|
||||
this.type = type;
|
||||
if (tool !== undefined) tools[tool] = true;
|
||||
}
|
||||
|
||||
clone(z) {
|
||||
|
|
@ -1295,11 +1299,15 @@
|
|||
tok = str.substring(cs+1,ce);
|
||||
let eva = [];
|
||||
for (let [k,v] of Object.entries(consts)) {
|
||||
if (typeof v === 'number') {
|
||||
eva.push(`let ${k} = ${v};`);
|
||||
} else {
|
||||
if (v === undefined) v = '';
|
||||
eva.push(`let ${k} = "${v.replace(/\"/g,"\\\"")}";`);
|
||||
switch (typeof v) {
|
||||
case 'number':
|
||||
case 'boolean':
|
||||
eva.push(`let ${k} = ${v};`);
|
||||
break;
|
||||
default:
|
||||
if (v === undefined) v = '';
|
||||
eva.push(`let ${k} = "${v.replace(/\"/g,"\\\"")}";`);
|
||||
break;
|
||||
}
|
||||
}
|
||||
eva.push(`function range(a,b) { return (a + (layer / layers) * (b-a)).round(4) }`)
|
||||
|
|
@ -1307,6 +1315,9 @@
|
|||
let scr = eva.join('');
|
||||
let evl = eval(`{ ${scr} }`);
|
||||
nutok = evl;
|
||||
if (pad === 666) {
|
||||
return evl;
|
||||
}
|
||||
if (pad) {
|
||||
nutok = nutok.toString();
|
||||
let oldln = ce-cs+1;
|
||||
|
|
|
|||
Loading…
Reference in a new issue