2020-06-03 22:39:30 -04:00
|
|
|
/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
|
2017-04-18 17:09:33 -04:00
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
|
|
2020-11-08 13:04:54 -05:00
|
|
|
const KIRI = self.kiri,
|
2017-04-18 17:09:33 -04:00
|
|
|
CAM = KIRI.driver.CAM = {
|
2020-11-05 18:29:04 -05:00
|
|
|
// init, // src/mode/cam/client.js
|
2020-11-05 15:41:52 -05:00
|
|
|
// slice, // src/mode/cam/slice.js
|
2020-11-08 16:44:32 -05:00
|
|
|
// prepare, // src/mode/cam/prepare.js
|
2020-11-08 18:39:21 -05:00
|
|
|
// export // src/mode/cam/export.js
|
2017-04-18 17:09:33 -04:00
|
|
|
},
|
|
|
|
|
CPRO = CAM.process = {
|
2020-06-29 13:48:52 -04:00
|
|
|
LEVEL: 1,
|
|
|
|
|
ROUGH: 2,
|
|
|
|
|
OUTLINE: 3,
|
|
|
|
|
CONTOUR_X: 4,
|
|
|
|
|
CONTOUR_Y: 5,
|
|
|
|
|
TRACE: 6,
|
|
|
|
|
DRILL: 7
|
2020-11-05 18:29:04 -05:00
|
|
|
};
|
2017-04-18 17:09:33 -04:00
|
|
|
|
|
|
|
|
/**
|
2020-11-05 15:25:27 -05:00
|
|
|
* Find top paths to trace when using ball and taper mills
|
|
|
|
|
* in waterline outlining and tracing modes.
|
2017-04-18 17:09:33 -04:00
|
|
|
*/
|
2020-11-05 15:25:27 -05:00
|
|
|
function findTracingPaths(widget, slice, tool, profile, partial) {
|
|
|
|
|
// for now, only emit completed polys and not segments
|
|
|
|
|
// TODO consider limiting to nup path lengths that are >= tool radius
|
|
|
|
|
let only_whole = !partial;
|
|
|
|
|
// check for ball and taper mills paths and add to top[0].inner
|
|
|
|
|
let polys = [];
|
|
|
|
|
let nups = [];
|
|
|
|
|
let cull = [];
|
|
|
|
|
slice.gatherTopPolys([]).forEach(poly => poly.flattenTo(polys));
|
|
|
|
|
polys.forEach(poly => {
|
|
|
|
|
let pz = poly.first().z;
|
|
|
|
|
let mz = -Infinity;
|
|
|
|
|
let np = newPolygon().setOpen();
|
|
|
|
|
let mp = 0;
|
|
|
|
|
// find top poly segments that are not significantly offset
|
|
|
|
|
// from tool profile and add to new polygons which accumulate
|
|
|
|
|
// to the top inner array
|
|
|
|
|
poly.forEachSegment((p1,p2) => {
|
|
|
|
|
let nz = getTopoZPathMax(widget, profile, p1.x, p1.y, p2.x, p2.y);
|
|
|
|
|
if (nz > mz) {
|
|
|
|
|
mz = nz;
|
2017-04-18 17:09:33 -04:00
|
|
|
}
|
2020-11-05 15:25:27 -05:00
|
|
|
// this # should be computed from topo resolution
|
|
|
|
|
if (nz - pz < 0.01) {
|
|
|
|
|
mp++
|
|
|
|
|
if (np.length) {
|
|
|
|
|
if (!np.first().isEqual(p2)) {
|
|
|
|
|
np.append(p2);
|
|
|
|
|
} else {
|
|
|
|
|
np.setClosed();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
np.append(p1).append(p2);
|
|
|
|
|
}
|
|
|
|
|
} else if (np.length) {
|
|
|
|
|
if (!only_whole) {
|
|
|
|
|
nups.append(np);
|
|
|
|
|
}
|
|
|
|
|
np = newPolygon().setOpen();
|
2020-11-02 18:53:40 -05:00
|
|
|
}
|
2020-11-05 15:25:27 -05:00
|
|
|
});
|
|
|
|
|
if (np.length) {
|
|
|
|
|
if (np.length === poly.length) {
|
|
|
|
|
np.setClosed();
|
2020-07-08 12:18:15 -04:00
|
|
|
}
|
2020-11-05 15:25:27 -05:00
|
|
|
// if a trace poly has no interruptions for an endmill
|
|
|
|
|
// and it's an inner poly, eliminate it from the parent
|
|
|
|
|
// so it won't be offset.
|
|
|
|
|
let parent = poly.parent;
|
|
|
|
|
if (np.isClosed() && parent) {
|
|
|
|
|
// console.log(slice.z,'cull',poly);
|
|
|
|
|
if (parent.inner) {
|
|
|
|
|
parent.inner = parent.inner.filter(p => p !== poly);
|
|
|
|
|
}
|
|
|
|
|
if (only_whole) {
|
|
|
|
|
nups.append(np);
|
|
|
|
|
}
|
2017-04-18 17:09:33 -04:00
|
|
|
}
|
2020-11-05 15:25:27 -05:00
|
|
|
if (!only_whole) {
|
|
|
|
|
nups.append(np);
|
2018-04-21 18:06:39 -04:00
|
|
|
}
|
2017-04-18 17:09:33 -04:00
|
|
|
}
|
|
|
|
|
});
|
2020-11-05 15:25:27 -05:00
|
|
|
if (nups.length) {
|
|
|
|
|
// console.log(slice.z,'nups',nups.length);
|
|
|
|
|
slice.tops[0].inner = nups;
|
|
|
|
|
}
|
2020-06-09 18:12:59 -04:00
|
|
|
}
|
|
|
|
|
|
2017-04-18 17:09:33 -04:00
|
|
|
})();
|