Skip to content

Commit dbb14ce

Browse files
tinicclaude
andcommitted
refactor: extract updatePitchFromThread/Turning into useCannedCyclePitch
Pulls the compound-angle + TPI label math out of App.vue along with the xpitchlabel/zpitchlabel/xpitchangle refs. Also inlines the TPI formatting into a small helper so the thread-mode branch is easier to read. The larger thread/turn run handlers (threadStartClicked etc) stay in App.vue for now — their coupling to 15+ composable refs doesn't justify extraction at this size. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 65b9999 commit dbb14ce

2 files changed

Lines changed: 74 additions & 44 deletions

File tree

elle-app/elle-frontend/src/App.vue

Lines changed: 4 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
removeDiameter,
2424
toDisplayLength
2525
} from './composables/useUnits'
26+
import { useCannedCyclePitch } from './composables/useCannedCyclePitch'
2627
import { useFormatters } from './composables/useFormatters'
2728
import { useHALLifecycle } from './composables/useHALLifecycle'
2829
import { useMachineStatus } from './composables/useMachineStatus'
@@ -138,10 +139,6 @@ const { machineStatus, statusDisplay } = useMachineStatus(
138139
selectedMenu
139140
)
140141
141-
// Internal
142-
const xpitchlabel = ref('')
143-
const zpitchlabel = ref('')
144-
const xpitchangle = ref(0)
145142
// Get settings from composable
146143
const {
147144
metric,
@@ -163,6 +160,9 @@ const selectedFeedMode = ref(FeedMode.longitudinal)
163160
const selectedDirectionMode = ref(DirectionMode.forward)
164161
const selectedCannedCycle = ref(CannedCycle.none)
165162
163+
const { xpitchlabel, zpitchlabel, xpitchangle, updatePitchFromThread, updatePitchFromTurning } =
164+
useCannedCyclePitch({ threadPitch, threadXDepth, threadZDepth, metric, xpitch, zpitch })
165+
166166
const { preview, showOperationPreviewDialog, onPreviewContinue, onPreviewCancel } =
167167
useOperationPreview()
168168
const showBackplot = ref(false)
@@ -643,40 +643,6 @@ const threadResetClicked = () => {
643643
updatePitchFromThread()
644644
}
645645
646-
const updatePitchFromThread = () => {
647-
// Update PZ (longitudinal) with thread pitch parameter
648-
if (threadPitch.value !== null) {
649-
zpitch.value = Math.abs(threadPitch.value)
650-
if (metric.value) {
651-
zpitchlabel.value = `${threadPitch.value}mm`
652-
} else {
653-
// In imperial mode, show TPI (threads per inch)
654-
const tpi = 1 / threadPitch.value
655-
// Show integer if close to whole number, otherwise 1 decimal place
656-
const rounded = Math.round(tpi)
657-
const formatted = Math.abs(tpi - rounded) < 0.1 ? rounded.toString() : tpi.toFixed(1)
658-
zpitchlabel.value = `${formatted} TPI`
659-
}
660-
} else {
661-
zpitchlabel.value = ''
662-
}
663-
664-
// If we have Z depth (compound threading), calculate cross feed
665-
if (threadZDepth.value !== null && threadZDepth.value !== 0 && threadXDepth.value !== null) {
666-
// Calculate compound angle from X and Z depths
667-
const angle =
668-
Math.atan2(Math.abs(threadZDepth.value), Math.abs(threadXDepth.value)) * (180 / Math.PI)
669-
const angleRad = angle * (Math.PI / 180)
670-
xpitch.value = threadPitch.value ? Math.abs(threadPitch.value * Math.tan(angleRad)) : 0.001
671-
xpitchlabel.value = `${angle.toFixed(1)}°`
672-
xpitchangle.value = angle
673-
} else {
674-
// Straight threading - minimal cross feed
675-
xpitch.value = 0.001 // Very small value for threading
676-
xpitchangle.value = 0
677-
}
678-
}
679-
680646
const threadMetricClicked = () => {
681647
treatOffClickAsEnter()
682648
metric.value = !metric.value
@@ -778,12 +744,6 @@ const turningResetClicked = () => {
778744
updatePitchFromTurning()
779745
}
780746
781-
const updatePitchFromTurning = () => {
782-
// Minimal cross feed for turning
783-
xpitch.value = 0.001
784-
xpitchangle.value = 0
785-
}
786-
787747
onMounted(async () => {
788748
// Load settings first (includes tool table and current tool)
789749
await loadSettings()
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import { ref, type Ref } from 'vue'
2+
3+
interface Deps {
4+
threadPitch: Ref<number | null>
5+
threadXDepth: Ref<number | null>
6+
threadZDepth: Ref<number | null>
7+
metric: Ref<boolean>
8+
xpitch: Ref<number>
9+
zpitch: Ref<number>
10+
}
11+
12+
// Computes the feed-axis pitch values shown in the DRO when a threading or
13+
// turning cycle is armed. Owns the human-readable labels for PX/PZ, plus the
14+
// compound angle derived from threading X/Z depths.
15+
export function useCannedCyclePitch(deps: Deps) {
16+
const { threadPitch, threadXDepth, threadZDepth, metric, xpitch, zpitch } = deps
17+
18+
const xpitchlabel = ref('…')
19+
const zpitchlabel = ref('…')
20+
const xpitchangle = ref(0)
21+
22+
const formatPitchLabel = (pitchMm: number): string => {
23+
if (metric.value) {
24+
return `${pitchMm}mm`
25+
}
26+
// Imperial convention: show TPI. Round to int if within 0.1, else 1 decimal.
27+
const tpi = 1 / pitchMm
28+
const rounded = Math.round(tpi)
29+
const formatted = Math.abs(tpi - rounded) < 0.1 ? rounded.toString() : tpi.toFixed(1)
30+
return `${formatted} TPI`
31+
}
32+
33+
const updatePitchFromThread = () => {
34+
const pitch = threadPitch.value
35+
if (pitch !== null) {
36+
zpitch.value = Math.abs(pitch)
37+
zpitchlabel.value = formatPitchLabel(pitch)
38+
} else {
39+
zpitchlabel.value = '…'
40+
}
41+
42+
// Compound threading: derive cross feed + angle from Z depth and X depth.
43+
if (threadZDepth.value !== null && threadZDepth.value !== 0 && threadXDepth.value !== null) {
44+
const angle =
45+
Math.atan2(Math.abs(threadZDepth.value), Math.abs(threadXDepth.value)) * (180 / Math.PI)
46+
const angleRad = angle * (Math.PI / 180)
47+
xpitch.value = pitch ? Math.abs(pitch * Math.tan(angleRad)) : 0.001
48+
xpitchlabel.value = `${angle.toFixed(1)}°`
49+
xpitchangle.value = angle
50+
} else {
51+
// Straight threading — minimal cross feed.
52+
xpitch.value = 0.001
53+
xpitchangle.value = 0
54+
}
55+
}
56+
57+
const updatePitchFromTurning = () => {
58+
// Minimal cross feed; turning uses the Z axis pitch from feedRate directly.
59+
xpitch.value = 0.001
60+
xpitchangle.value = 0
61+
}
62+
63+
return {
64+
xpitchlabel,
65+
zpitchlabel,
66+
xpitchangle,
67+
updatePitchFromThread,
68+
updatePitchFromTurning
69+
}
70+
}

0 commit comments

Comments
 (0)