add drill profile svg

This commit is contained in:
bakedpotatolord 2025-04-20 22:37:02 -06:00
commit e69566623b
2 changed files with 39 additions and 14 deletions

View file

@ -105,7 +105,7 @@ class Tool {
}
hasTaper() {
return this.isTaperMill() || this.isDrill();
return this.isTaperMill();
}
generateProfile(resolution) {

View file

@ -42,14 +42,7 @@ gapp.register("kiri-mode.cam.tools", (root, exports) => {
});
}
/**
* Check if a tool is a tapermill or drill (i.e. has a taper angle)
* @param {String} tool - a string representing the tool type
* @return {boolean} true if the tool has a taper angle, false if not
*/
function hasTaper(tool) {
return tool === 'tapermill' || tool === 'drill';
}
function selectTool(tool) {
selectedTool = tool;
@ -62,10 +55,13 @@ gapp.register("kiri-mode.cam.tools", (root, exports) => {
ui.toolTaperTip.value = tool.taper_tip || 0;
ui.toolMetric.checked = tool.metric;
ui.toolType.selectedIndex = toolNames.indexOf(tool.type);
if (hasTaper(tool)) {
if (tool === 'tapermill') {
ui.toolTaperAngle.value = kiri.driver.CAM.calcTaperAngle(
(tool.flute_diam - tool.taper_tip) / 2, tool.flute_len
).round(1);
} else if(tool === 'drill'){
ui.toolTaperAngle.value = 118;
} else {
ui.toolTaperAngle.value = 0;
}
@ -93,7 +89,9 @@ gapp.register("kiri-mode.cam.tools", (root, exports) => {
function renderTool(tool) {
let type = selectedTool.type;
let taper = hasTaper(type)
let taper = type=== 'tapermill'
let drill = type === 'drill'
const drillAngleRad = 140 * Math.PI / 180
ui.toolTaperAngle.disabled = taper ? undefined : 'true';
ui.toolTaperTip.disabled = taper ? undefined : 'true';
$('tool-view').innerHTML = '<svg id="tool-svg" width="100%" height="100%"></svg>';
@ -111,10 +109,12 @@ gapp.register("kiri-mode.cam.tools", (root, exports) => {
stroke_thin = stroke_width / 2,
shaft = tool.shaft_len || 1,
flute = tool.flute_len || 1,
total_len = shaft + flute,
drillTip = drill ? 0.5 * tool.flute_diam * Math.sin(drillAngleRad) : 0,
total_len = shaft + flute+drillTip,
units = dim.h / total_len,
shaft_len = (shaft / total_len) * max.h,
flute_len = ((flute / total_len) * max.h),
flute_len = (flute / total_len) * max.h,
drill_tip_len = (drillTip / total_len) * max.h,
shaft_diam = tool.shaft_diam * units,
flute_diam = tool.flute_diam * units,
// total_wid = Math.max(flute_diam, shaft_diam),
@ -143,6 +143,31 @@ gapp.register("kiri-mode.cam.tools", (root, exports) => {
`L ${dim.w - off.x - flute_off} ${yoff}`,
`z`
].join('\n')}});
} else if(drill){
const x1 = off.x + flute_off,
y1 = off.y + shaft_len,
x2 = dim.w - off.x - flute_off,
y2 = y1 + flute_len,
xMid = dim.w / 2
parts.push({path: {stroke_width, stroke, fill:flute_fill, d:[
`M ${x1} ${y1}`, //move to top left
`L ${x1} ${y2}`, //line to bottom left
`L ${xMid} ${y2+drill_tip_len}`, //line to bottom mid point
`L ${x2} ${y2}`, //line to bottom right
`L ${x2} ${y1}`, //line to top right
`z`
].join('\n')}});
//add drill flute lines
parts.push({ line: {
x1, y1, x2, y2: (y1 + y2) / 2,
stroke, stroke_width: stroke_thin
} });
parts.push({ line: {
x1, y1: (y1 + y2) / 2, x2, y2,
stroke, stroke_width: stroke_thin
} });
} else {
let fl = isBall ? flute_len - flute_diam/2 : flute_len;
let x1 = off.x + flute_off;
@ -194,7 +219,7 @@ gapp.register("kiri-mode.cam.tools", (root, exports) => {
selectedTool.taper_tip = parseFloat(ui.toolTaperTip.value);
selectedTool.metric = ui.toolMetric.checked;
selectedTool.type = toolNames[ui.toolType.selectedIndex];
if (hasTaper(selectedTool.type)) {
if (selectedTool.type === 'tapermill') {
const CAM = kiri.driver.CAM;
const rad = (selectedTool.flute_diam - selectedTool.taper_tip) / 2;
if (ev && ev.target === ui.toolTaperAngle) {