cleanup slices to geode

This commit is contained in:
casperlamboo 2016-04-23 09:56:15 +02:00
parent ebbe75ef2e
commit 9e4109a3f8

View File

@ -1,18 +1,14 @@
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;
for (var j = 0; j < length; j ++) {
var point = line[j % line.length];
if (j === 0) {
if (i === 0) {
// TODO
// moveTo should impliment combing
gcode.moveTo(point.X, point.Y, layer);
@ -20,8 +16,7 @@ export default function slicesToGCode(slices, settings) {
if (unRetract) {
gcode.unRetract();
}
}
else {
} else {
gcode.lineTo(point.X, point.Y, layer, type);
}
}
@ -30,10 +25,13 @@ export default function slicesToGCode(slices, settings) {
if (retract) {
gcode.retract();
}
}
}
for (var layer = 0; layer < slices.length; layer ++) {
var slice = slices[layer];
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');
}
}