cleanup slices to geode

This commit is contained in:
casperlamboo 2016-04-23 09:56:15 +02:00 committed by Simon Voordouw
parent 1056be13bd
commit 7e9bb39ba9

View File

@ -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');
}
}