From dc99f417da8d657e63cb63bdc66cabf6f9dea56c Mon Sep 17 00:00:00 2001 From: Simon Voordouw Date: Tue, 4 Jul 2017 14:19:07 +0200 Subject: [PATCH] add progress reporting --- src/Slicer.js | 5 +++++ src/sliceActions/slice.js | 25 +++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/Slicer.js b/src/Slicer.js index a0a7069..e8f4f5b 100644 --- a/src/Slicer.js +++ b/src/Slicer.js @@ -47,6 +47,11 @@ export default class { resolve(data.gcode); break; } + case 'PROGRESS': { + if (this.onprogress) { + this.onprogress(data); + } + } } }); diff --git a/src/sliceActions/slice.js b/src/sliceActions/slice.js index 2b3f47f..7ddcb65 100644 --- a/src/sliceActions/slice.js +++ b/src/sliceActions/slice.js @@ -13,32 +13,53 @@ import applyPrecision from './applyPrecision.js'; import removePrecision from './removePrecision.js'; export default function(geometry, settings) { - geometry.mergeVertices(); - geometry.computeFaceNormals(); + const totalStages = 15; + 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; const openClosed = detectOpenClosed(geometry); + progressMessage(); const lines = createLines(geometry, settings, openClosed); + progressMessage(); const { layerIntersectionIndexes, layerIntersectionPoints } = calculateLayersIntersections(lines, settings); + progressMessage(); const shapes = intersectionsToShapes(layerIntersectionIndexes, layerIntersectionPoints, lines, settings); + progressMessage(); applyPrecision(shapes); + progressMessage(); const slices = shapesToSlices(shapes, settings); + progressMessage(); generateInnerLines(slices, settings); + progressMessage(); generateInfills(slices, settings); + progressMessage(); generateSupport(slices, settings); + progressMessage(); addBrim(slices, settings); + progressMessage(); optimizePaths(slices, settings); + progressMessage(); removePrecision(slices); + progressMessage(); const gcode = slicesToGCode(slices, settings); + progressMessage(); return gcode; }