grid-apps-cmms/src/kiri/mode/cam/op-rough.js

88 lines
2.5 KiB
JavaScript
Raw Normal View History

2025-07-05 10:49:09 -04:00
/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
import { CamOp } from './op.js';
import { OpArea } from './op-area.js';
import { newPolygon } from '../../../geo/polygon.js';
import { polygons as POLY } from '../../../geo/polygons.js';
2025-07-05 10:49:09 -04:00
class OpRough extends CamOp {
constructor(state, op) {
super(state, op);
}
// todo: cutThruBypass
2025-07-05 10:49:09 -04:00
async slice(progress) {
let { op, state } = this;
let { shadow, tool, widget } = state;
2025-07-05 10:49:09 -04:00
let { workarea } = state;
let cutThruBypass = op.down > workarea.top_stock - workarea.bottom_part;
let cutOutside = !op.inside;
let shadowBase = shadow.base;
2025-07-05 10:49:09 -04:00
if (op.down <= 0) {
throw `invalid step down "${op.down}"`;
2025-07-05 10:49:09 -04:00
}
if (op.all) {
shadowBase = [ newPolygon().centerRectangle(stock.center, stock.x, stock.y) ];
2025-07-05 10:49:09 -04:00
}
let areas = POLY.flatten(POLY.expand(shadowBase, tool.fluteDiameter() / 2 - 0.001));
let rough = {
rename: op.rename ?? "rough",
spindle: op.spindle,
tool: op.tool,
rate: op.rate,
plunge: op.plunge,
mode: 'clear',
over: op.step,
down: op.down,
expand: 0,
smooth: 0,
outline: true,
omitthru: op.omitthru,
leave_xy: op.leave,
leave_z: op.leavez,
ov_botz: op.ov_botz,
ov_topz: op.ov_topz,
areas: { [widget.id]: areas.map(p => p.toArray()) },
surfaces: {}
};
this.op_rough = new OpArea(state, rough);
await this.op_rough.slice(progress);
if (cutOutside) {
let cutout = {
rename: op.rename ?? "rough",
spindle: op.spindle,
tool: op.tool,
rate: op.rate,
plunge: op.plunge,
mode: 'trace',
tr_type: 'none',
down: op.down,
expand: 0,
smooth: 1,
outline: !op.omitthru,
ov_botz: op.ov_botz,
ov_topz: op.ov_topz,
areas: { [widget.id]: areas.map(p => p.toArray()) },
surfaces: {}
};
this.op_cutout = new OpArea(state, cutout);
await this.op_cutout.slice(progress);
2025-07-05 10:49:09 -04:00
}
}
async prepare(ops, progress) {
await this.op_rough.prepare(ops, progress);
if (this.op_cutout) await this.op_cutout.prepare(ops, progress);
2025-07-05 10:49:09 -04:00
}
}
export { OpRough };