add progress reporting

This commit is contained in:
Simon Voordouw 2017-07-04 14:19:07 +02:00
parent 1f206e5784
commit dc99f417da
2 changed files with 28 additions and 2 deletions

View File

@ -47,6 +47,11 @@ export default class {
resolve(data.gcode); resolve(data.gcode);
break; break;
} }
case 'PROGRESS': {
if (this.onprogress) {
this.onprogress(data);
}
}
} }
}); });

View File

@ -13,32 +13,53 @@ import applyPrecision from './applyPrecision.js';
import removePrecision from './removePrecision.js'; import removePrecision from './removePrecision.js';
export default function(geometry, settings) { export default function(geometry, settings) {
geometry.mergeVertices(); const totalStages = 15;
geometry.computeFaceNormals(); let current = 0;
const progressMessage = () => {
current++;
postMessage({ message: 'PROGRESS', data: { done: current, total: totalStages } });
};
geometry.mergeVertices();
progressMessage();
geometry.computeFaceNormals();
progressMessage();
// get unique lines from geometry; // get unique lines from geometry;
const openClosed = detectOpenClosed(geometry); const openClosed = detectOpenClosed(geometry);
progressMessage();
const lines = createLines(geometry, settings, openClosed); const lines = createLines(geometry, settings, openClosed);
progressMessage();
const { const {
layerIntersectionIndexes, layerIntersectionIndexes,
layerIntersectionPoints layerIntersectionPoints
} = calculateLayersIntersections(lines, settings); } = calculateLayersIntersections(lines, settings);
progressMessage();
const shapes = intersectionsToShapes(layerIntersectionIndexes, layerIntersectionPoints, lines, settings); const shapes = intersectionsToShapes(layerIntersectionIndexes, layerIntersectionPoints, lines, settings);
progressMessage();
applyPrecision(shapes); applyPrecision(shapes);
progressMessage();
const slices = shapesToSlices(shapes, settings); const slices = shapesToSlices(shapes, settings);
progressMessage();
generateInnerLines(slices, settings); generateInnerLines(slices, settings);
progressMessage();
generateInfills(slices, settings); generateInfills(slices, settings);
progressMessage();
generateSupport(slices, settings); generateSupport(slices, settings);
progressMessage();
addBrim(slices, settings); addBrim(slices, settings);
progressMessage();
optimizePaths(slices, settings); optimizePaths(slices, settings);
progressMessage();
removePrecision(slices); removePrecision(slices);
progressMessage();
const gcode = slicesToGCode(slices, settings); const gcode = slicesToGCode(slices, settings);
progressMessage();
return gcode; return gcode;
} }