From 9e4109a3f8b66e74045f6165680d4e30e926053d Mon Sep 17 00:00:00 2001 From: casperlamboo Date: Sat, 23 Apr 2016 09:56:15 +0200 Subject: [PATCH] cleanup slices to geode --- src/sliceActions/slicesToGCode.js | 75 +++++++++++++++---------------- 1 file changed, 36 insertions(+), 39 deletions(-) diff --git a/src/sliceActions/slicesToGCode.js b/src/sliceActions/slicesToGCode.js index 5abe6f5..76e0fc4 100644 --- a/src/sliceActions/slicesToGCode.js +++ b/src/sliceActions/slicesToGCode.js @@ -1,39 +1,37 @@ import GCode from '../gcode.js'; -export default function slicesToGCode(slices, settings) { - var gcode = new GCode().setSettings(settings); +function pathToGCode(gcode, shape, retract, unRetract, layer, type) { + for (let i = 0; i < shape.paths.length; i ++) { + const line = shape.paths[i]; - function pathToGCode (shape, retract, unRetract, type) { - for (var i = 0; i < shape.paths.length; i ++) { - var line = shape.paths[i]; + const length = shape.closed ? (line.length + 1) : line.length; + for (let i = 0; i < length; i ++) { + const point = line[i % line.length]; - var length = shape.closed ? (line.length + 1) : line.length; + if (i === 0) { + // TODO + // moveTo should impliment combing + gcode.moveTo(point.X, point.Y, layer); - for (var j = 0; j < length; j ++) { - var point = line[j % line.length]; - - if (j === 0) { - // TODO - // moveTo should impliment combing - gcode.moveTo(point.X, point.Y, layer); - - if (unRetract) { - gcode.unRetract(); - } - } - else { - gcode.lineTo(point.X, point.Y, layer, type); + if (unRetract) { + gcode.unRetract(); } + } else { + gcode.lineTo(point.X, point.Y, layer, type); } } - - if (retract) { - gcode.retract(); - } } - for (var layer = 0; layer < slices.length; layer ++) { - var slice = slices[layer]; + if (retract) { + gcode.retract(); + } +} + +export default function slicesToGCode(slices, settings) { + const gcode = new GCode().setSettings(settings); + + for (let layer = 0; layer < slices.length; layer ++) { + const slice = slices[layer]; if (layer === 1) { gcode.turnFanOn(); @@ -41,30 +39,29 @@ export default function slicesToGCode(slices, settings) { } if (slice.brim !== undefined) { - pathToGCode(slice.brim, true, true, "brim"); + pathToGCode(gcode, slice.brim, true, true, layer, 'brim'); } - for (var i = 0; i < slice.parts.length; i ++) { - var part = slice.parts[i]; + for (let i = 0; i < slice.parts.length; i ++) { + const part = slice.parts[i]; if (part.shape.closed) { - pathToGCode(part.outerLine, false, true, "outerLine"); + pathToGCode(gcode, part.outerLine, false, true, layer, 'outerLine'); - for (var j = 0; j < part.innerLines.length; j ++) { - var innerLine = part.innerLines[j]; - pathToGCode(innerLine, false, false, "innerLine"); + for (let i = 0; i < part.innerLines.length; i ++) { + const innerLine = part.innerLines[i]; + pathToGCode(gcode, innerLine, false, false, layer, 'innerLine'); } - pathToGCode(part.fill, true, false, "fill"); - } - else { - var retract = !(slice.parts.length === 1 && slice.support === undefined); - pathToGCode(part.shape, retract, retract, "outerLine"); + pathToGCode(gcode, part.fill, true, false, layer, 'fill'); + } else { + const retract = !(slice.parts.length === 1 && slice.support === undefined); + pathToGCode(gcode, part.shape, retract, retract, layer, 'outerLine'); } } if (slice.support !== undefined) { - pathToGCode(slice.support, true, true, "support"); + pathToGCode(gcode, slice.support, true, true, layer, 'support'); } }