stub in topo4 / lathe op

This commit is contained in:
Stewart Allen 2023-01-16 13:56:08 -05:00
commit 8a8f4d8485
7 changed files with 232 additions and 16 deletions

View file

@ -83,7 +83,12 @@ CAM.init = function(kiri, api) {
animVer = isIndexed ? 1 : 0; animVer = isIndexed ? 1 : 0;
SPACE.platform.setVisible(!isIndexed); SPACE.platform.setVisible(!isIndexed);
SPACE.platform.showGrid2(!isIndexed || camStockIndexGrid); SPACE.platform.showGrid2(!isIndexed || camStockIndexGrid);
$('cam-index').style.display = isIndexed ? '' : 'none'; const showIndexed = isIndexed ? '' : 'none';
const showNonIndexed = isIndexed ? 'none' : '';
$('cam-index').style.display = showIndexed;
$('cam-lathe').style.display = showIndexed;
$('cam-flip').style.display = showNonIndexed;
$('cam-reg').style.display = showNonIndexed;
if (!changed) { if (!changed) {
return; return;
} }
@ -282,13 +287,21 @@ CAM.init = function(kiri, api) {
case "rough": return func.opAddRough(); case "rough": return func.opAddRough();
case "outline": return func.opAddOutline(); case "outline": return func.opAddOutline();
case "contour": case "contour":
let oplist = current.process.ops, axis = "X"; let caxis = "X";
for (let op of oplist) { for (let op of current.process.ops) {
if (op.type === "contour" && op.axis === "X") { if (op.type === "contour" && op.axis === "X") {
axis = "Y"; caxis = "Y";
} }
} }
return func.opAddContour(axis); return func.opAddContour(caxis);
case "lathe":
let laxis = "X";
for (let op of current.process.ops) {
if (op.type === "lathe" && op.axis === "X") {
laxis = "Y";
}
}
return func.opAddLathe(laxis);
case "register": return func.opAddRegister('X', 2); case "register": return func.opAddRegister('X', 2);
case "drill": return func.opAddDrill(); case "drill": return func.opAddDrill();
case "trace": return func.opAddTrace(); case "trace": return func.opAddTrace();
@ -344,6 +357,12 @@ CAM.init = function(kiri, api) {
func.opAdd(rec); func.opAdd(rec);
}; };
func.opAddLathe = (axis) => {
let rec = popOp.lathe.new();
rec.axis = axis.toUpperCase();
func.opAdd(rec);
};
func.opAddTrace = () => { func.opAddTrace = () => {
let rec = popOp.trace.new(); let rec = popOp.trace.new();
rec.areas = { /* widget.id: [ polygons... ] */ }; rec.areas = { /* widget.id: [ polygons... ] */ };
@ -1285,7 +1304,7 @@ CAM.init = function(kiri, api) {
axis: 'X' axis: 'X'
}).inputs = { }).inputs = {
tool: UC.newSelect(LANG.cc_tool, {}, "tools"), tool: UC.newSelect(LANG.cc_tool, {}, "tools"),
axis: UC.newSelect(LANG.cd_axis, {}, "regaxis"), axis: UC.newSelect(LANG.cd_axis, {}, "xyaxis"),
sep: UC.newBlank({class:"pop-sep"}), sep: UC.newBlank({class:"pop-sep"}),
spindle: UC.newInput(LANG.cc_spnd_s, {title:LANG.cc_spnd_l, convert:UC.toInt, show:hasSpindle}), spindle: UC.newInput(LANG.cc_spnd_s, {title:LANG.cc_spnd_l, convert:UC.toInt, show:hasSpindle}),
rate: UC.newInput(LANG.cc_feed_s, {title:LANG.cc_feed_l, convert:UC.toInt, units:true}), rate: UC.newInput(LANG.cc_feed_s, {title:LANG.cc_feed_l, convert:UC.toInt, units:true}),
@ -1302,6 +1321,23 @@ CAM.init = function(kiri, api) {
bottom: UC.newBoolean(LANG.cf_botm_s, undefined, {title:LANG.cf_botm_l, show:(op,conf) => conf ? conf.process.camZBottom : 0}) bottom: UC.newBoolean(LANG.cf_botm_s, undefined, {title:LANG.cf_botm_l, show:(op,conf) => conf ? conf.process.camZBottom : 0})
}; };
createPopOp('lathe', {
tool: 'camLatheTool',
spindle: 'camLatheSpindle',
step: 'camLatheOver',
rate: 'camLatheSpeed',
tolerance: 'camTolerance',
axis: 'X'
}).inputs = {
tool: UC.newSelect(LANG.cc_tool, {}, "tools"),
axis: UC.newSelect(LANG.cd_axis, {}, "xyaxis"),
sep: UC.newBlank({class:"pop-sep"}),
spindle: UC.newInput(LANG.cc_spnd_s, {title:LANG.cc_spnd_l, convert:UC.toInt, show:hasSpindle}),
rate: UC.newInput(LANG.cc_feed_s, {title:LANG.cc_feed_l, convert:UC.toInt, units:true}),
step: UC.newInput(LANG.cc_sovr_s, {title:LANG.cc_sovr_l, convert:UC.toFloat, bound:UC.bound(0.01,2.0)}),
tolerance: UC.newInput(LANG.ou_toll_s, {title:LANG.ou_toll_l, convert:UC.toFloat, bound:UC.bound(0,10.0), units:true, round:4}),
};
createPopOp('trace', { createPopOp('trace', {
mode: 'camTraceType', mode: 'camTraceType',
offset: 'camTraceOffset', offset: 'camTraceOffset',

View file

@ -9,6 +9,7 @@
// dep: geo.slicer // dep: geo.slicer
// dep: kiri.slice // dep: kiri.slice
// use: kiri-mode.cam.topo // use: kiri-mode.cam.topo
// use: kiri-mode.cam.topo4
gapp.register("kiri-mode.cam.ops", [], (root, exports) => { gapp.register("kiri-mode.cam.ops", [], (root, exports) => {
const { base, kiri } = root; const { base, kiri } = root;
@ -767,16 +768,15 @@ class OpContour extends CamOp {
prepare(ops, progress) { prepare(ops, progress) {
let { op, state, sliceOut } = this; let { op, state, sliceOut } = this;
let { setTolerance, setTool, setSpindle, setPrintPoint } = ops;
let { polyEmit } = ops;
let { camOut, newLayer, printPoint, lastPoint } = ops;
let { bounds, zmax } = ops;
let { settings, widget } = state; let { settings, widget } = state;
let { process } = settings; let { process } = settings;
let { setTolerance, setTool, setSpindle, setPrintPoint } = ops;
let { camOut, polyEmit, newLayer, printPoint, lastPoint } = ops;
let { bounds, zmax } = ops;
let toolDiam = this.toolDiam = new CAM.Tool(settings, op.tool).fluteDiameter(); let toolDiam = this.toolDiam = new CAM.Tool(settings, op.tool).fluteDiameter();
let stepover = toolDiam * op.step * 2; let stepover = toolDiam * op.step * 2;
let cutdir = process.camConventional;
let depthFirst = process.camDepthFirst; let depthFirst = process.camDepthFirst;
let depthData = []; let depthData = [];
@ -830,6 +830,78 @@ class OpContour extends CamOp {
} }
} }
class OpLathe extends CamOp {
constructor(state, op) {
super(state, op);
}
async slice(progress) {
let { op, state } = this;
let { addSlices } = state;
this.topo = await CAM.Topo4({
op,
state: state,
onupdate: (pct, msg) => {
progress(pct, msg);
},
ondone: (slices) => {
this.slices = slices;
addSlices(slices);
}
});
}
prepare(ops, progress) {
let { op, state, slices, topo } = this;
let { settings, widget } = state;
let { process } = settings;
let { setTolerance, setTool, setSpindle, setPrintPoint } = ops;
let { camOut, newLayer, polyEmit, printPoint, lastPoint } = ops;
let { bounds, zmax } = ops;
let toolDiam = new CAM.Tool(settings, op.tool).fluteDiameter();
let stepover = toolDiam * op.step * 2;
let cutdir = process.camConventional;
let depthFirst = process.camDepthFirst;
let depthData = [];
setTool(op.tool, op.rate, op.plunge);
setSpindle(op.spindle);
setTolerance(topo.tolerance);
// start top center, X = 0, Y = 0 closest to 4th axis chuck
printPoint = newPoint(0, 0, zmax);
for (let slice of slices) {
// ignore debug slices
if (!slice.camLines) {
continue;
}
let polys = [], poly, emit;
slice.camLines.forEach(poly => {
polys.push({ first:poly.first(), last:poly.last(), poly:poly });
});
printPoint = tip2tipEmit(polys, printPoint, (el, point, count) => {
poly = el.poly;
if (poly.last() === point) {
poly.reverse();
}
poly.forEachPoint((point, pidx) => {
camOut(point.clone(), pidx > 0, stepover);
}, false);
});
newLayer();
}
setPrintPoint(printPoint);
}
}
class OpTrace extends CamOp { class OpTrace extends CamOp {
constructor(state, op) { constructor(state, op) {
super(state, op); super(state, op);
@ -1701,6 +1773,7 @@ CAM.OPS = CamOp.MAP = {
"outline": OpOutline, "outline": OpOutline,
"contour": OpContour, "contour": OpContour,
"pocket": OpPocket, "pocket": OpPocket,
"lathe": OpLathe,
"trace": OpTrace, "trace": OpTrace,
"drill": OpDrill, "drill": OpDrill,
"register": OpRegister, "register": OpRegister,

100
src/kiri-mode/cam/topo4.js Normal file
View file

@ -0,0 +1,100 @@
/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
"use strict";
// dep: geo.base
// dep: geo.line
// dep: geo.point
// dep: geo.polygon
// dep: geo.polygons
// dep: kiri.slice
// dep: kiri-mode.cam.driver
// dep: kiri-mode.cam.slicer2
// dep: moto.broker
gapp.register("kiri-mode.cam.topo", [], (root, exports) => {
const { base, kiri } = root;
const { driver, newSlice } = kiri;
const { CAM } = driver;
const { polygons, newLine, newSlope, newPoint, newPolygon } = base;
const PRO = CAM.process;
const POLY = polygons;
const RAD2DEG = 180 / Math.PI;
class Topo4 {
constructor() { }
async generate(opt = {}) {
let { state, op, onupdate, ondone } = opt;
let { widget, settings, tabs } = opt.state;
let { controller, process } = settings;
let axis = op.axis.toLowerCase(),
tool = new CAM.Tool(settings, op.tool),
bounds = widget.getBoundingBox().clone(),
density = parseInt(controller.animesh || 100) * 2500,
{ min, max } = bounds,
span = {
x: max.x - min.x,
y: max.y - min.y
},
contour = {
x: axis === "x",
y: axis === "y"
},
tolerance = op.tolerance,
zMin = min.z + 0.0001,
resolution = tolerance ? tolerance : 1 / Math.sqrt(density / (span.x * span.y)),
toolOffset = tool.generateProfile(resolution).profile,
toolDiameter = tool.fluteDiameter(),
toolStep = toolDiameter * op.step,
steps = {
x: Math.ceil(span.x / resolution),
y: Math.ceil(span.y / resolution)
};
if (tolerance === 0) {
console.log(widget.id, 'topo4 auto tolerance', resolution.round(4));
}
this.tolerance = resolution;
onupdate(0, "lathe");
onupdate(1, "lathe");
ondone([]);
}
}
CAM.Topo4 = async function(opt) {
return new Topo4().generate(opt);
};
moto.broker.subscribe("minion.started", msg => {
const { funcs, cache, reply, log } = msg;
funcs.topo4_raster = (data, seq) => {
};
funcs.trace4_init = data => {
};
funcs.trace4_y = (data, seq) => {
};
funcs.trace4_x = (data, seq) => {
const { cache } = self;
const { trace } = cache.trace;
trace.crossX_sync(data.params, slice => {
slice = kiri.codec.encode(slice);
reply({ seq, slice });
});
};
funcs.trace4_cleanup = () => {
delete cache.trace;
};
});
});

View file

@ -498,6 +498,11 @@ const conf = exports({
camContourIn: false, camContourIn: false,
camContourXOn: true, camContourXOn: true,
camContourYOn: true, camContourYOn: true,
camLatheTool: 1000,
camLatheSpindle: 1000,
camLatheOver: 0.1,
camLatheSpeed: 500,
camTolerance: 0,
camTraceTool: 1000, camTraceTool: 1000,
camTraceSpindle: 1000, camTraceSpindle: 1000,
camTraceType: "follow", camTraceType: "follow",

View file

@ -101,6 +101,10 @@ const LISTS = {
{ name: "middle" }, { name: "middle" },
{ name: "bottom" } { name: "bottom" }
], ],
xyaxis: [
{ name: "X" },
{ name: "Y" }
],
regaxis: [ regaxis: [
{ name: "X" }, { name: "X" },
{ name: "Y" }, { name: "Y" },

View file

@ -938,9 +938,6 @@ th, tr, td, label {
align-items: center; align-items: center;
gap: 5px; gap: 5px;
} }
#cam-index {
grid-column-start: span 2;
}
#op-add-list { #op-add-list {
padding: 4px; padding: 4px;
display: flex; display: flex;

View file

@ -485,10 +485,11 @@
<div id="op-add-pop" class="f-col"> <div id="op-add-pop" class="f-col">
<div id="op-add-list" class="opdiv op-grid"> <div id="op-add-list" class="opdiv op-grid">
<div id="cam-index" title="rotate index axis">index</div> <div id="cam-index" title="rotate index axis">index</div>
<div id="cam-lathe" title="lathe operation">lathe</div>
<div id="laser-on" title="turn on laser mode">laser on</div> <div id="laser-on" title="turn on laser mode">laser on</div>
<div id="laser-off" title="turn off laser mode">laser off</div> <div id="laser-off" title="turn off laser mode">laser off</div>
<div title="flip part and load&#13;profile for other side&#13;for double-sided work">flip</div> <div id="cam-flip" title="flip part and load&#13;profile for other side&#13;for double-sided work">flip</div>
<div title="drill registration holes&#13;along the X or Y axis&#13;for double-sided work">register</div> <div id="cam-reg" title="drill registration holes&#13;along the X or Y axis&#13;for double-sided work">register</div>
<div title="drill any holes matching&#13;selected tool diameter">drill</div> <div title="drill any holes matching&#13;selected tool diameter">drill</div>
<div title="clear stock face&#13;or top of part&#13;when no stock">level</div> <div title="clear stock face&#13;or top of part&#13;when no stock">level</div>
<div title="follow selected features with&#13;a specified tool. often used&#13;for lettering and engraving">trace</div> <div title="follow selected features with&#13;a specified tool. often used&#13;for lettering and engraving">trace</div>