make first part of slicing cancellable
This commit is contained in:
parent
217129a4fd
commit
26bf2baf5e
6 changed files with 55 additions and 24 deletions
|
|
@ -71,7 +71,7 @@ var gs_kiri_fdm = exports;
|
|||
}, onSliceDone, onSliceUpdate);
|
||||
|
||||
function onSliceUpdate(update) {
|
||||
onupdate(0.0 + update * 0.5);
|
||||
return onupdate(0.0 + update * 0.5);
|
||||
}
|
||||
|
||||
function onSliceDone(slices) {
|
||||
|
|
|
|||
|
|
@ -257,9 +257,10 @@ var gs_kiri_slicer = exports;
|
|||
}
|
||||
}
|
||||
|
||||
/* -- synchronous slice -- can't be cancelled --
|
||||
// create a Slice for each z offset in the zIndexes array
|
||||
for (var i = 0; i < zIndexes.length; i++) {
|
||||
// mark the slice height
|
||||
// slice next layer and add to slices[] array
|
||||
sliceZ(zIndexes[i], zHeights[i]);
|
||||
// kill slicing if onupdate() returns 42
|
||||
if (onupdate(i / zIndexes.length) === 42) {
|
||||
|
|
@ -283,6 +284,39 @@ var gs_kiri_slicer = exports;
|
|||
|
||||
// pass Slices array back to ondone function
|
||||
ondone(slices);
|
||||
*/
|
||||
|
||||
var sliceIndex = 0;
|
||||
|
||||
function kickSlice() {
|
||||
sliceZ(zIndexes[sliceIndex], zHeights[sliceIndex]);
|
||||
// kill slicing if onupdate() returns 42
|
||||
if (onupdate(sliceIndex / zIndexes.length) === 42) {
|
||||
return ondone(null);
|
||||
}
|
||||
if (++sliceIndex < zIndexes.length) {
|
||||
setTimeout(kickSlice, 0);
|
||||
} else {
|
||||
// for cam, mark top and bottom as mandatory (hasFlats)
|
||||
if (options.cam && slices.length > 0) {
|
||||
slices[0].hasFlats = true;
|
||||
slices[slices.length-1].hasFlats = true;
|
||||
}
|
||||
|
||||
// connect slices into linked list for island/bridge projections
|
||||
for (i=1; i<slices.length; i++) {
|
||||
slices[i-1].up = slices[i];
|
||||
slices[i].down = slices[i-1];
|
||||
}
|
||||
|
||||
slices.slice_time = time() - timeStart;
|
||||
|
||||
// pass Slices array back to ondone function
|
||||
ondone(slices);
|
||||
}
|
||||
}
|
||||
|
||||
kickSlice();
|
||||
|
||||
/** ***** SLICING FUNCTIONS ***** */
|
||||
|
||||
|
|
|
|||
|
|
@ -577,7 +577,12 @@ var gs_kiri_widget = exports;
|
|||
|
||||
var catchupdate = function(progress, message) {
|
||||
onupdate(progress, message);
|
||||
return widget.cancel ? 42 : 0;
|
||||
if (widget.cancel) {
|
||||
ondone("canceled");
|
||||
return 42;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
var driver = null;
|
||||
|
|
|
|||
|
|
@ -165,13 +165,14 @@ if (self.window) {
|
|||
},
|
||||
|
||||
cancel: function(data) {
|
||||
// console.log({work_cancel: data});
|
||||
if (data.id) {
|
||||
var widget = cache[data.id];
|
||||
if (widget) widget.cancel = true;
|
||||
} else {
|
||||
for (var id in cache) {
|
||||
if (cache.hasOwnProperty(id)) cache[id].cancel = true;
|
||||
if (cache.hasOwnProperty(id)) {
|
||||
cache[id].cancel = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
@ -188,8 +189,8 @@ if (self.window) {
|
|||
last = util.time(),
|
||||
now;
|
||||
|
||||
// clear previous widget data before reslice
|
||||
delete cache[data.id];
|
||||
// do it here so cancel can work
|
||||
cache[data.id] = widget;
|
||||
|
||||
// fake mesh object to satisfy printing
|
||||
widget.mesh = {
|
||||
|
|
@ -199,6 +200,7 @@ if (self.window) {
|
|||
|
||||
widget.slice(settings, function(error) {
|
||||
if (error) {
|
||||
delete cache[data.id];
|
||||
send.data({error: error});
|
||||
} else {
|
||||
var slices = widget.slices || [];
|
||||
|
|
@ -215,7 +217,7 @@ if (self.window) {
|
|||
}
|
||||
send.done({done: true});
|
||||
// cache results for future printing
|
||||
cache[data.id] = widget;
|
||||
// cache[data.id] = widget;
|
||||
}, function(update, msg) {
|
||||
now = util.time();
|
||||
if (now - last < 10 && update < 0.99) return;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
var exports = {
|
||||
COPYRIGHT:"Copyright (C) 2014-2017 Stewart Allen <stewart@neuron.com> - All Rights Reserved",
|
||||
LICENSE:"Unauthorized copying, modification and re-distribution are strictly prohibited without prior written consent.",
|
||||
VERSION:"1.1.8c"
|
||||
VERSION:"1.1.9"
|
||||
};
|
||||
if (!module) var module = {};
|
||||
module.exports = exports;
|
||||
|
|
|
|||
Loading…
Reference in a new issue