grid-apps-cmms/src/mode/cam/driver.js

99 lines
3.4 KiB
JavaScript
Raw Normal View History

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
// sliceRender, // src/mode/cam/client.js
// printRender // src/mode/cam/client.js
// slice, // src/mode/cam/slice.js
// printSetup, // src/mode/cam/prepare.js
// printExport, // src/mode/cam/export.js
2017-04-18 17:09:33 -04:00
},
CPRO = CAM.process = {
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
/**
* 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
*/
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
}
// 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();
}
});
if (np.length) {
if (np.length === poly.length) {
np.setClosed();
}
// 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
}
if (!only_whole) {
nups.append(np);
2018-04-21 18:06:39 -04:00
}
2017-04-18 17:09:33 -04: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
})();