From 461e71ca64d26c4b57cf611051f20abb59db830e Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Sun, 7 Feb 2021 20:52:11 -0500 Subject: [PATCH] fix retraction between widgets. put retraction in prepare instead of export. inline comments --- src/mode/fdm/export.js | 10 +++------- src/mode/fdm/prepare.js | 30 +++++++++++++++--------------- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/src/mode/fdm/export.js b/src/mode/fdm/export.js index 4c8aedf8..b60d69b5 100644 --- a/src/mode/fdm/export.js +++ b/src/mode/fdm/export.js @@ -212,9 +212,6 @@ let angle = -Math.PI / 4; function moveTo(newpos, rate, comment) { - if (comment) { - append(";; " + comment); - } let o = [!rate && !newpos.e ? 'G0' : 'G1']; let emit = { x: false, y: false, z: false }; if (typeof newpos.x === 'number' && newpos.x !== pos.x) { @@ -254,6 +251,9 @@ o.append(" F").append(Math.round(rate)); pos.f = rate } + if (comment) { + o.append(` ; ${comment}`); + } let line = o.join(''); if (last == line) { // console.log({dup:line}); @@ -325,10 +325,6 @@ append(`;; --- layer ${layer} (${subst.height} @ ${subst.z.round(3)}) ---`); } - if (layer > 0 && process.outputLayerRetract) { - retract(); - } - // enable fan at fan layer if (gcodeFan && layer === process.outputFanLayer) { appendAllSub(gcodeFan); diff --git a/src/mode/fdm/prepare.js b/src/mode/fdm/prepare.js index 2366ed00..d0b8c971 100644 --- a/src/mode/fdm/prepare.js +++ b/src/mode/fdm/prepare.js @@ -34,14 +34,9 @@ firstLayerMult = process.firstLayerPrintMult, firstLayerBrim = process.firstLayerBrim, firstLayerBrimTrig = process.firstLayerBrimTrig, + layerRetract = process.outputLayerRetract, layerno = 0, zoff = 0, - meshIndex, - lastIndex, - closest, - mindist, - minidx, - find, layerout = [], slices = [], print = self.worker.print = KIRI.newPrint(settings, widgets), @@ -271,7 +266,9 @@ let rec = track[nozzle]; if (rec) { track[nozzle] = null; - if (layer.last()) layer.last().retract = true; + if (layer.last()) { + layer.last().retract = true; + } start = print.polyPrintPath(rec.poly.clone().setZ(z), start, layer, { tool: using || nozzle, open: true, @@ -343,6 +340,8 @@ return a.z - b.z; }); + let lastWidget; + // walk cake layers bottom up for (let layer of cake) { // track purge blocks generated for each layer @@ -379,10 +378,11 @@ }); let { z, slice, offset } = order[0]; slice.prep = true; - // retract between widgets - if (layerout.length && minidx !== lastIndex) { + // retract between widgets or layers (when set) + if (layerout.length && slice.widget !== lastWidget) { layerout.last().retract = true; } + lastWidget = slice.widget; layerout.z = z + slice.height / 2; layerout.height = layerout.height || slice.height; // mark layer as anchor if slice is belt and flag set @@ -408,7 +408,9 @@ layerout.appendAll(tmpout); lastOut = slice; lastExt = lastOut.ext - lastIndex = minidx; + if (layerRetract) { + layerout.last().retract = true; + } } // if a declared extruder isn't used in a layer, use selected @@ -700,9 +702,7 @@ .setLayer(opts.other || 'move', moveOpt, opts.moves !== true) .addPolys(moves, { thin: true, z: opts.z }); // force level when present - if (level.z) { - opts.z = level.z - height; - } + let pz = level.z ? level.z - height : opts.z; Object.values(prints).forEach(array => { array.forEach(poly => { if (flat && poly.appearsClosed()) { @@ -715,10 +715,10 @@ .addPolys([ poly ], thin ? { thin, z: opts.z, color: poly.color } : flat ? { - flat, z: opts.z, color: poly.color, + flat, z: pz, color: poly.color, outline: true, offset: array.width, open: poly.open } : { - offset: array.width, height, z: opts.z, + offset: array.width, height, z: pz, color: { face: poly.color, line: poly.color } }) });