From ef32999dfcb97761e78c9bc6a585f1fe12ff1b86 Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Wed, 11 Nov 2020 16:33:56 -0500 Subject: [PATCH] add relative support to gcode parsing --- src/geo/polygon.js | 1 - src/kiri/print.js | 20 +++++++++++++++++--- src/mode/fdm/prepare.js | 18 +++++++++++++----- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/src/geo/polygon.js b/src/geo/polygon.js index 68bd1a9a..a1e168c1 100644 --- a/src/geo/polygon.js +++ b/src/geo/polygon.js @@ -1165,7 +1165,6 @@ } poly.parent = parent || this.parent; poly.area2 = this.area2; - poly.open = this.open; return poly; }; diff --git a/src/kiri/print.js b/src/kiri/print.js index 5f019f10..a486c23d 100644 --- a/src/kiri/print.js +++ b/src/kiri/print.js @@ -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; diff --git a/src/mode/fdm/prepare.js b/src/mode/fdm/prepare.js index a4068106..2dd20cff 100644 --- a/src/mode/fdm/prepare.js +++ b/src/mode/fdm/prepare.js @@ -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 });