Skip to content

Commit

Permalink
make first part of slicing cancellable
Browse files Browse the repository at this point in the history
  • Loading branch information
stewartoallen committed Mar 8, 2018
1 parent 217129a commit 26bf2ba
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 24 deletions.
2 changes: 1 addition & 1 deletion js/kiri-driver-fdm.js
Expand Up @@ -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) {
Expand Down
36 changes: 35 additions & 1 deletion js/kiri-slicer.js
Expand Up @@ -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) {
Expand All @@ -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 ***** */

Expand Down
7 changes: 6 additions & 1 deletion js/kiri-widget.js
Expand Up @@ -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;
Expand Down
12 changes: 7 additions & 5 deletions js/kiri-work.js
Expand Up @@ -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;
}
}
}
},
Expand All @@ -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 = {
Expand All @@ -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 || [];
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion js/license.js
@@ -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;
20 changes: 5 additions & 15 deletions notes.md
@@ -1,6 +1,5 @@
# Kiri:Moto todo

* fix slicing cancellation
* widget general add-ons (fdm supports, cam tabs)
* extend mesh object to store raw + annotations (rot,scale,pos), share raw data w/ dups, encode/decode
* bail on decimation if it's proving ineffective
Expand Down Expand Up @@ -30,11 +29,6 @@
* option to support interior bridges when 0% infill
* fix multiple part layout export offset (resend position @ print time)

# Laser todo

* overcuts, radii for drag knives
* sla :: svg modified from http://garyhodgson.github.io/slic3rsvgviewer/?file=examples/belt_pulley3.svg

# CAM todo

* add imperial / metric units switch in (future) global config options
Expand Down Expand Up @@ -66,20 +60,16 @@
* linear x/y not obeying inset from pocket only
* check normals for downward facing facets. mark top for slice skirt/pancake

# References
# Laser todo

* shader examples to enable object-clipping
-----
* http://jsfiddle.net/LK84y/9/
* http://www.html5rocks.com/en/tutorials/webgl/shaders/
* overcuts, radii for drag knives
* sla :: svg modified from http://garyhodgson.github.io/slic3rsvgviewer/?file=examples/belt_pulley3.svg

# References

* other
-----
* http://lcamtuf.coredump.cx/gcnc/full/
* http://www.tcs.fudan.edu.cn/rudolf/Courses/Algorithms/Alg_cs_07w/Webprojects/Zhaobo_hull/
* https://en.wikipedia.org/wiki/Graham_scan
* http://www.cambam.info/doc/0.9.7/cam/Pocket.aspx
* http://hackaday.com/2016/01/22/pack-your-plywood-cuts-with-genetic-algortihms/
* http://wiki.imal.org/howto/cnc-milling-introduction-cutting-tools
* http://www.twak.co.uk/2011/01/degeneracy-in-weighted-straight.html

Expand Down

0 comments on commit 26bf2ba

Please sign in to comment.