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";
|
|
|
|
|
|
2022-02-21 10:01:19 -05:00
|
|
|
// dep: main.kiri
|
2022-03-05 10:58:07 -05:00
|
|
|
// use: kiri.codec
|
2022-04-04 21:37:15 -04:00
|
|
|
// use: mesh.tool
|
2022-02-21 10:01:19 -05:00
|
|
|
gapp.register("kiri-mode.cam.driver", [], (root, exports) => {
|
|
|
|
|
|
|
|
|
|
const { kiri } = root;
|
|
|
|
|
const { driver } = kiri;
|
|
|
|
|
const CAM = driver.CAM = {};
|
|
|
|
|
|
|
|
|
|
CAM.process = {
|
|
|
|
|
LEVEL: 1,
|
|
|
|
|
ROUGH: 2,
|
|
|
|
|
OUTLINE: 3,
|
|
|
|
|
CONTOUR_X: 4,
|
|
|
|
|
CONTOUR_Y: 5,
|
|
|
|
|
TRACE: 6,
|
|
|
|
|
DRILL: 7
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// defer loading until kiri.client and kiri.worker exist
|
|
|
|
|
kiri.load(api => {
|
|
|
|
|
|
|
|
|
|
if (kiri.client)
|
|
|
|
|
CAM.traces = function(ondone, single) {
|
|
|
|
|
kiri.client.sync();
|
|
|
|
|
const settings = api.conf.get();
|
|
|
|
|
const widgets = api.widgets.map();
|
|
|
|
|
kiri.client.send("cam_traces", { settings, single }, output => {
|
|
|
|
|
const ids = [];
|
|
|
|
|
kiri.codec.decode(output).forEach(rec => {
|
|
|
|
|
ids.push(rec.id);
|
|
|
|
|
widgets[rec.id].traces = rec.traces;
|
|
|
|
|
});
|
|
|
|
|
ondone(ids);
|
2017-04-18 17:09:33 -04:00
|
|
|
});
|
2022-02-21 10:01:19 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (kiri.worker)
|
|
|
|
|
kiri.worker.cam_traces = function(data, send) {
|
|
|
|
|
const { settings, single } = data;
|
2022-03-05 10:58:07 -05:00
|
|
|
const widgets = Object.values(kiri.worker.cache);
|
2022-02-21 10:01:19 -05:00
|
|
|
const fresh = widgets.filter(widget => CAM.traces(settings, widget, single));
|
|
|
|
|
send.done(kiri.codec.encode(fresh.map(widget => { return {
|
|
|
|
|
id: widget.id,
|
|
|
|
|
traces: widget.traces,
|
|
|
|
|
} } )));
|
|
|
|
|
};
|
|
|
|
|
|
2022-04-04 21:37:15 -04:00
|
|
|
if (kiri.client)
|
|
|
|
|
CAM.surfaces = function(ondone) {
|
|
|
|
|
kiri.client.sync();
|
|
|
|
|
const settings = api.conf.get();
|
|
|
|
|
kiri.client.send("cam_surfaces", { settings }, output => {
|
|
|
|
|
ondone(output);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (kiri.worker)
|
|
|
|
|
kiri.worker.cam_surfaces = function(data, send) {
|
|
|
|
|
const { settings } = data;
|
|
|
|
|
const widgets = Object.values(kiri.worker.cache);
|
|
|
|
|
for (let widget of widgets) {
|
|
|
|
|
if (!widget.tool) {
|
|
|
|
|
let tool = widget.tool = new mesh.tool();
|
|
|
|
|
tool.generateFaceMap(widget.getVertices().array);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
send.done({});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (kiri.client)
|
|
|
|
|
CAM.surface_find = function(id, face, ondone) {
|
|
|
|
|
kiri.client.send("cam_surface_find", { id, face }, faces => {
|
|
|
|
|
ondone(faces);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (kiri.worker)
|
|
|
|
|
kiri.worker.cam_surface_find = function(data, send) {
|
|
|
|
|
const { id, face } = data;
|
|
|
|
|
const widget = kiri.worker.cache[id];
|
|
|
|
|
const faces = widget.tool.findConnectedSurface([face], 0.1, 0.001);
|
|
|
|
|
send.done(faces);
|
|
|
|
|
};
|
2022-02-21 10:01:19 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
});
|