add relative support to gcode parsing

This commit is contained in:
Stewart Allen 2020-11-11 16:33:56 -05:00
commit ef32999dfc
3 changed files with 30 additions and 9 deletions

View file

@ -1165,7 +1165,6 @@
}
poly.parent = parent || this.parent;
poly.area2 = this.area2;
poly.open = this.open;
return poly;
};

View file

@ -168,11 +168,14 @@
lines.forEach(function(line) {
if (line.indexOf('- LAYER ') > 0) {
seq.height = defh;
const hd = line.replace('(','').replace(')','').split(' ');
defh = parseFloat(hd[4]);
if (fdm) dz = -defh / 2;
}
line = line.split(";")[0].split(" ");
line = line.split(";")[0].split(" ").filter(v => v);
let cmd = line.shift();
if (!cmd) return;
if (cmd.charAt(0) === 'T') {
let ext = scope.settings.device.extruders;
let pos = parseInt(cmd.charAt(1));
@ -201,10 +204,21 @@
G0G1(true);
break;
case 'G1':
const mov = {};
line.forEach(function(tok) {
pos[tok.charAt(0)] = parseFloat(tok.substring(1));
if (abs) {
pos[tok.charAt(0)] = parseFloat(tok.substring(1));
} else {
mov[tok.charAt(0)] = parseFloat(tok.substring(1));
}
});
G0G1(fdm ? pos.E == 0 : false);
if (!abs) {
for (let [k,v] of Object.entries(mov)) {
console.log(k, v, line);
pos[k] += v;
}
}
G0G1(fdm ? pos.E <= 0 : false);
break;
case 'M6':
break;

View file

@ -436,6 +436,13 @@
const output = new KIRI.Render();
layers.push(output);
// const updateTool = (toolid) => {
// toolid = toolid || 0;
// const array = prints[toolid] = prints[toolid] || [];
// const tool = tools[toolid] || {};
// array.width = (tool.extNozzle || 1) / 2;
// }
const pushPrint = (toolid, poly) => {
toolid = toolid || 0;
const array = prints[toolid] = prints[toolid] || [];
@ -462,6 +469,7 @@
current.color = color(out);
pushPrint(out.tool, current);
}
// updateTool(out.tool);
current.push(out.point);
} else {
if (lastOut.emit) {
@ -483,11 +491,11 @@
}
lastOut = out;
});
if (lastOut.emit) {
// pushPrint(lastOut.tool, current)
} else {
moves.push(current);
}
// if (lastOut.emit) {
// pushPrint(lastOut.tool, current)
// } else {
// moves.push(current);
// }
output
.setLayer('move', moveColor, opts.moves !== true)
.addPolys(moves, { thin: true, z: opts.z });