Merge pull request #393 from GridSpace/improved-register

Improved register
This commit is contained in:
Stewart Allen 2025-07-21 08:47:36 -07:00 committed by GitHub
commit 560ca3d53e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 92 additions and 88 deletions

View file

@ -126,6 +126,7 @@
"camTraceBottom": false,
"cmaPocketOutline": false,
"camRegisterThru": 5,
"camRegisterOffset": 10,
"camFlatness": 0,
"camContourBridge": 10,
"camForceZMax": false,

View file

@ -518,6 +518,7 @@ export const conf = {
camDrillingOn: false,
camRegisterSpeed: 1000,
camRegisterThru: 5,
camRegisterOffset: 10,
camHelicalTool: 1000,
camHelicalSpindle: 1000,
camHelicalDownSpeed: 250,

View file

@ -101,12 +101,12 @@ export function createPopOp(type, map) {
const settings = conf.get();
const { tool } = new Tool(settings, op.rec.tool); //get tool by id
const opType = op.rec.type
const drillOrRegister = opType == "drill" || opType == "register"
const drillingOp = opType == "drill" || ( opType == "register" && op.rec.axis != "-" )
if (!drillOrRegister && tool.type == "drill") {
alerts.show(`Warning: Drills should not be used for ${opType} operations.`)
if (!drillingOp && tool.type == "drill") {
alerts.show(`Warning: Drills should not be used for non-drilling operations.`)
}
else if (drillOrRegister && tool.type != "drill") {
else if (drillingOp && tool.type != "drill") {
alerts.show(`Warning: Only drills should be used for drilling operations.`)
}
@ -501,28 +501,30 @@ export function createPopOps() {
};
createPopOp('register', {
tool: 'camDrillTool',
tool: 'camDrillTool',
spindle: 'camDrillSpindle',
down: 'camDrillDown',
rate: 'camDrillDownSpeed',
dwell: 'camDrillDwell',
lift: 'camDrillLift',
feed: 'camRegisterSpeed',
thru: 'camRegisterThru'
down: 'camDrillDown',
rate: 'camDrillDownSpeed',
dwell: 'camDrillDwell',
lift: 'camDrillLift',
feed: 'camRegisterSpeed',
offset: 'camRegisterOffset',
thru: 'camRegisterThru',
}).inputs = {
tool: UC.newSelect(LANG.cc_tool, {}, "tools"),
axis: UC.newSelect(LANG.cd_axis, {}, "regaxis"),
points: UC.newSelect(LANG.cd_points, { show: () => env.poppedRec.axis !== '-' }, "regpoints"),
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_plng_s, { title: LANG.cc_plng_l, convert: UC.toInt, units: true }),
feed: UC.newInput(LANG.cc_feed_s, { title: LANG.cc_feed_l, convert: UC.toInt, units: true, show: () => env.poppedRec.axis === '-' }),
sep: UC.newBlank({ class: "pop-sep" }),
down: UC.newInput(LANG.cc_sdwn_s, { title: LANG.cc_sdwn_l, convert: UC.toFloat, units: true }),
dwell: UC.newInput(LANG.cd_dwll_s, { title: LANG.cd_dwll_l, convert: UC.toFloat, show: () => env.poppedRec.axis !== '-' }),
lift: UC.newInput(LANG.cd_lift_s, { title: LANG.cd_lift_l, convert: UC.toFloat, units: true, show: () => env.poppedRec.axis !== '-' }),
sep: UC.newBlank({ class: "pop-sep" }),
thru: UC.newInput(LANG.cd_thru_s, { title: LANG.cd_thru_l, convert: UC.toFloat, units: true }),
tool: UC.newSelect(LANG.cc_tool, {}, "tools"),
axis: UC.newSelect(LANG.cd_axis, {}, "regaxis"),
points: UC.newSelect(LANG.cd_points, {show:() => env.poppedRec.axis !== '-'}, "regpoints"),
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_plng_s, {title:LANG.cc_plng_l, convert:UC.toInt, units:true}),
feed: UC.newInput(LANG.cc_feed_s, {title:LANG.cc_feed_l, convert:UC.toInt, units:true, show:() => env.poppedRec.axis === '-'}),
sep: UC.newBlank({class:"pop-sep"}),
down: UC.newInput(LANG.cc_sdwn_s, {title:LANG.cc_sdwn_l, convert:UC.toFloat, units:true}),
dwell: UC.newInput(LANG.cd_dwll_s, {title:LANG.cd_dwll_l, convert:UC.toFloat, show:() => env.poppedRec.axis !== '-'}),
lift: UC.newInput(LANG.cd_lift_s, {title:LANG.cd_lift_l, convert:UC.toFloat, units:true, show:() => env.poppedRec.axis !== '-'}),
sep: UC.newBlank({class:"pop-sep"}),
offset: UC.newInput(LANG.cd_rego_s, {title:LANG.cd_rego_l, convert:UC.toFloat, units:true, }),
thru: UC.newInput(LANG.cd_thru_s, {title:LANG.cd_thru_l, convert:UC.toFloat, units:true}),
};
createPopOp('helical', {

View file

@ -23,99 +23,95 @@ class OpRegister extends CamOp {
updateToolDiams(tool.fluteDiameter());
let { stock } = settings,
tz = widget.track.pos.z,
lx = bounds.min.x,
hx = bounds.max.x,
ly = bounds.min.y,
hy = bounds.max.y,
o3 = tool.fluteDiameter() * 2,
mx = (lx + hx) / 2,
my = (ly + hy) / 2,
mz = op.thru || zThru || 0,
dx = (stock.x - (hx - lx)) / 4,
dy = (stock.y - (hy - ly)) / 4,
dz = stock.z,
points = [],
wo = stock.z - bounds.max.z,
z1 = bounds.max.z + wo + tz,
z2 = tz - mz;
toolZ = widget.track.pos.z,
boundMinX = bounds.min.x,
boundMaxX = bounds.max.x,
boundMinY = bounds.min.y,
boundMaxY = bounds.max.y,
toolOffset = tool.fluteDiameter() * 2,
centerX = (boundMinX + boundMaxX) / 2,
centerY = (boundMinY + boundMaxY) / 2,
cutDepth = op.thru || zThru || 0,
pathPoints = [],
stockToSurfaceOffset = stock.z - bounds.max.z,
startZ = bounds.max.z + stockToSurfaceOffset + toolZ,
endZ = toolZ - cutDepth,
cutOffset = op.offset;
if (!(stock.x && stock.y && stock.z)) {
return;
}
switch (op.axis) {
case "X":
switch (op.axis.toLowerCase()) {
case "x":
if (op.points == 3) {
points.push(newPoint(lx - dx, my, 0));
points.push(newPoint(hx + dx, my - o3, 0));
points.push(newPoint(hx + dx, my + o3, 0));
pathPoints.push(newPoint(boundMinX - cutOffset, centerY, 0));
pathPoints.push(newPoint(boundMaxX + cutOffset, centerY - toolOffset, 0));
pathPoints.push(newPoint(boundMaxX + cutOffset, centerY + toolOffset, 0));
} else {
points.push(newPoint(lx - dx, my, 0));
points.push(newPoint(hx + dx, my, 0));
pathPoints.push(newPoint(boundMinX - cutOffset, centerY, 0));
pathPoints.push(newPoint(boundMaxX + cutOffset, centerY, 0));
}
break;
case "Y":
case "y":
if (op.points == 3) {
points.push(newPoint(mx, ly - dy, 0));
points.push(newPoint(mx - o3, hy + dy, 0));
points.push(newPoint(mx + o3, hy + dy, 0));
pathPoints.push(newPoint(centerX, boundMinY - cutOffset, 0));
pathPoints.push(newPoint(centerX - toolOffset, boundMaxY + cutOffset, 0));
pathPoints.push(newPoint(centerX + toolOffset, boundMaxY + cutOffset, 0));
} else {
points.push(newPoint(mx, ly - dy, 0));
points.push(newPoint(mx, hy + dy, 0));
pathPoints.push(newPoint(centerX, boundMinY - cutOffset, 0));
pathPoints.push(newPoint(centerX, boundMaxY + cutOffset, 0));
}
break;
case "-":
let o2 = o3 / 2,
x0 = lx - dx,
x1 = hx + dx,
y0 = ly - dy - o2,
y1 = hy + dy + o2,
x4 = (x1 - x0 - o2) / 4,
y4 = (y1 - y0 - o2 * 3) / 4,
poly, cp, cz;
let halfOffset = toolOffset / 2,
loopMinX = boundMinX - cutOffset,
loopMaxX = boundMaxX + cutOffset,
loopMinY = boundMinY - cutOffset - halfOffset,
loopMaxY = boundMaxY + cutOffset + halfOffset,
deltaX = (loopMaxX - loopMinX - halfOffset) / 4,
deltaY = (loopMaxY - loopMinY - halfOffset * 3) / 4,
poly, currentPoint, currentZ;
function start(z) {
cz = z;
cp = { x: x0 + o2 * 0.5, y: y0 + o2 * 1.5 };
poly = newPolygon().add(cp.x, cp.y, z);
currentZ = z;
currentPoint = { x: loopMinX + halfOffset * 0.5, y: loopMinY + halfOffset * 1.5 };
poly = newPolygon().add(currentPoint.x, currentPoint.y, z);
}
function move(dx, dy) {
cp.x += dx;
cp.y += dy;
poly.add(cp.x, cp.y, cz);
currentPoint.x += dx;
currentPoint.y += dy;
poly.add(currentPoint.x, currentPoint.y, currentZ);
}
function rept(count, tv, fn) {
function rept(count, step, fn) {
while (count-- > 0) {
fn(tv, count === 0);
tv = -tv;
fn(step, count === 0);
step = -step;
}
}
for (let z of base_util.lerp(z1, z2, op.down)) {
for (let z of base.util.lerp(startZ, endZ, op.down)) {
let slice = newSlice(z);
addSlices(slice);
sliceOut.push(slice);
start(z);
rept(4, o2, oy => {
rept(4, halfOffset, oy => {
move(0, -oy);
move(x4, 0);
move(deltaX, 0);
});
rept(4, o2, ox => {
rept(4, halfOffset, ox => {
move(ox, 0);
move(0, y4);
move(0, deltaY);
});
rept(4, o2, oy => {
rept(4, halfOffset, oy => {
move(0, oy);
move(-x4, 0);
move(-deltaX, 0);
});
rept(4, o2, ox => {
rept(4, halfOffset, ox => {
move(-ox, 0);
move(0, -y4);
move(0, -deltaY);
});
poly.points.pop();
slice.camTrace = { tool: tool.getID(), rate: op.feed, plunge: op.rate };
slice.camLines = [poly];
slice.camLines = [ poly ];
slice.output()
.setLayer("register", { line: color }, false)
.addPolys(slice.camLines)
@ -123,16 +119,16 @@ class OpRegister extends CamOp {
break;
}
if (points.length) {
let slice = newSlice(0, null), polys = [];
points.forEach(point => {
if (pathPoints.length) {
let slice = newSlice(0,null), polys = [];
pathPoints.forEach(point => {
polys.push(newPolygon()
.append(point.clone().setZ(z1))
.append(point.clone().setZ(z2)));
.append(point.clone().setZ(startZ))
.append(point.clone().setZ(endZ)));
});
slice.camLines = polys;
slice.output()
.setLayer("register", { face: color, line: color })
.setLayer("register", {face: color, line: color})
.addPolys(polys);
addSlices(slice);
sliceOut.push(slice);

View file

@ -592,8 +592,6 @@ self.lang['en-us'] = {
cd_dwll_l: ["dwell time","between plunges in","in milliseconds"],
cd_lift_s: "drill lift",
cd_lift_l: ["lift between plunges","after dwell period","in workspace units","0 to disable"],
cd_regi_s: "register",
cd_regi_l: ["drill registration holes","for double-sided parts","independent of enable","drilling but uses same","tool and settings"],
cd_thru_s: "z extend",
cd_thru_l: ["extend downward cut through stock","in workspace units"],
cd_dtru_s: "drill through",
@ -609,6 +607,12 @@ self.lang['en-us'] = {
cd_sela_s: "Select Matching Diameter",
cd_sela_l: ["select all holes that", "match selected tool diameter"],
//CNC Registration
cd_regi_s: "register",
cd_regi_l: ["drill registration holes","for double-sided parts","independent of enable","drilling but uses same","tool and settings"],
cd_rego_s: "part offset",
cd_rego_l: ["offset of hole center","from part bounding box","in workspace units"],
// CNC HELICAL tolpath
ch_menu: "helical",
ch_sdwn_s: "step down (pitch)",