diff --git a/furniture-3d-system/src/app/database/bom-library/accessory-models/AccessoryAssemblyProcessing.tsx b/furniture-3d-system/src/app/database/bom-library/accessory-models/AccessoryAssemblyProcessing.tsx
index 82d929ab3..bbca1dea1 100644
--- a/furniture-3d-system/src/app/database/bom-library/accessory-models/AccessoryAssemblyProcessing.tsx
+++ b/furniture-3d-system/src/app/database/bom-library/accessory-models/AccessoryAssemblyProcessing.tsx
@@ -3,7 +3,11 @@ import { accessoryMachiningSchema, type CamMachining } from '@/lib/intake-access
import { resolveAssemblyMachining, resolveCamWheelProcessing } from '@/lib/intake-accessory-machining-assets'
import type { AccessoryDraft } from '@/lib/intake-accessory-models'
import { accessoryComponentDrillSummary } from '@/lib/intake-accessory-component-drill'
+import { accessoryMachiningSummary } from '@/lib/intake-accessory-drilling'
import { camProcessingLines } from './AccessoryMachiningDetails'
+import { assemblyMemberProcessingLines, assemblyMemberStandards } from './accessory-connection-standards'
+import { draftAssemblyRod, draftInsertAnchor } from './accessory-assembly-model-draft'
+import Button from '@/components/ui/Button'
const fields = [
['firstDiameter', '孔径'], ['firstDepth', '深度'], ['rodDiameter', '杆孔孔径'],
@@ -19,21 +23,32 @@ export function assemblyProcessing(assembly: AccessoryAssembly, item: AccessoryD
const rodId = member('rod')
const wheelId = member('cam')
const insertId = member('insert')
- const drill = items.find(entry => entry.id === wheelId)?.componentDrill
- const first = rule?.rodMount === 'direct' ? rule.pilot : rule?.insert
+ const members = assemblyMemberStandards(assembly, items)
+ const wheelItem = members.find(entry => entry.role === 'cam')?.item
+ const wheelStandard = wheelItem?.drilling
+ const drill = wheelStandard ?? wheelItem?.componentDrill
+ const insert = members.find(entry => entry.role === 'insert')?.item
+ const insertStandard = insert?.drilling
+ const first = insertId && insertStandard ? (insertStandard.holeType === 'blind' ? insertStandard : undefined)
+ : rule?.rodMount === 'direct' ? rule.pilot : rule?.insert
+ const rod = members.find(entry => entry.role === 'rod')?.item
+ const suggested = !rule && insertId && !rod?.drilling ? draftAssemblyRod(rod?.model, first?.depthMm) : undefined
const values: Values = { firstDiameter: first?.diameterMm, firstDepth: first?.depthMm,
- rodDiameter: rule?.rodDiameterMm, rodLength: rule?.rodLengthMm, engagement: rule?.engagementMm, ...edits }
- const wheel = drill?.holeType === 'blind' ? { diameterMm: drill.diameterMm, depthMm: drill.depthMm } : rule?.wheel
- if (!edits) return { values, rule, drill, issue: undefined, machining: undefined }
- if (!wheel || drill?.holeType === 'through') return { values, rule, drill, machining: undefined,
+ rodDiameter: rule?.rodDiameterMm, rodLength: rule?.rodLengthMm, engagement: rule?.engagementMm,
+ ...suggested, ...edits }
+ const wheel = drill ? (drill.holeType === 'blind' ? { diameterMm: drill.diameterMm, depthMm: drill.depthMm } : undefined) : rule?.wheel
+ if (!edits) return { values, rule, drill, suggested, issue: undefined, machining: undefined }
+ if (!wheel) return { values, rule, drill, suggested, machining: undefined,
issue: '请先在偏心轮资料中确认盲孔孔径和深度。' }
+ if (insertId && insertStandard && insertStandard.holeType !== 'blind') return { values, rule, drill, suggested, machining: undefined,
+ issue: '请先在预埋件资料中确认盲孔孔径和深度。' }
const bore = { diameterMm: values.firstDiameter, depthMm: values.firstDepth }
const parsed = accessoryMachiningSchema.safeParse({
type: 'cam', rodId, wheelId, wheel, rodDiameterMm: values.rodDiameter, rodLengthMm: values.rodLength,
engagementMm: values.engagement, ...(insertId ? { rodMount: 'insert', insertId, insert: bore }
: { rodMount: 'direct', pilot: bore }),
})
- return { values, rule, drill, machining: parsed.success ? parsed.data as CamMachining : undefined,
+ return { values, rule, drill, suggested, machining: parsed.success ? parsed.data as CamMachining : undefined,
issue: parsed.success ? undefined : parsed.error.issues[0]?.message ?? '请补全零件加工参数。' }
}
@@ -46,11 +61,16 @@ export function AccessoryAssemblyProcessing({ assembly, items, data, fieldClassN
canEdit: boolean
onChange: (value: Values) => void
}) {
- const { values, rule, drill, issue } = data
+ const { values, rule, suggested, machining, issue } = data
const usesInsert = assembly.components.some(part => part.role === 'insert')
const firstHole = usesInsert ? '预埋孔' : '首板引孔'
- const wheel = rule && resolveCamWheelProcessing(rule, drill)
- const lines = rule ? camProcessingLines(rule, items) : ['未填写']
+ const members = assemblyMemberStandards(assembly, items)
+ const wheelItem = members.find(entry => entry.role === 'cam')?.item
+ const insert = members.find(entry => entry.role === 'insert')?.item
+ const wheel = rule && resolveCamWheelProcessing(rule, wheelItem?.drilling ? undefined : wheelItem?.componentDrill)
+ const lines = rule ? camProcessingLines(rule, items) : [
+ ...assemblyMemberProcessingLines(assembly, items), '整套开孔待确认。',
+ ]
return
-
-
-
-
- {
+ { setHoleType(value); setMachiningCheck(null); setError('') }}
+ holeDiameter={holeDiameter} setHoleDiameter={setHoleDiameter} holeDepth={holeDepth} setHoleDepth={setHoleDepth}
+ reverseHoleDepth={reverseHoleDepth} setReverseHoleDepth={setReverseHoleDepth}
+ headDiameterText={headDiameterText} headDiameterOverride={headDiameterOverride} setHeadDiameterOverride={setHeadDiameterOverride}
+ modelHeadDiameter={modelHeadDiameter} countersinkDiameterMm={countersinkDiameterMm} clearError={() => setError('')} />
+ {insertAnchor && generationModel && }
+ {(showProcessing || holeRows.length > 0) && {
setProcessingEdits(previous => ({ ...previous, [processingKey]: { ...previous[processingKey], ...patch } }))
setError('')
}}>
{!!holeRows.length && {
setHoleRows(rows); setError('')
}} />}
-
+ }
{ setApplication(value); setError('') }}>
{holeType && {
diff --git a/furniture-3d-system/src/app/database/bom-library/accessory-models/AccessoryProcessingEditor.tsx b/furniture-3d-system/src/app/database/bom-library/accessory-models/AccessoryProcessingEditor.tsx
index c2662c3fa..99762cf31 100644
--- a/furniture-3d-system/src/app/database/bom-library/accessory-models/AccessoryProcessingEditor.tsx
+++ b/furniture-3d-system/src/app/database/bom-library/accessory-models/AccessoryProcessingEditor.tsx
@@ -1,3 +1,4 @@
+import Button from '@/components/ui/Button'
import type { AccessoryDraft } from '@/lib/intake-accessory-models'
import { surfaceMountProcessing } from '@/lib/intake-accessory-surface-mount'
import { camProcessingLines } from './AccessoryMachiningDetails'
@@ -13,17 +14,18 @@ const dowelFields = [
['secondDiameter', '第二块板盲孔孔径'], ['secondDepth', '第二块板盲孔深度'],
] as const
-export function AccessoryProcessingEditor({ draft, edits, disabled, onChange, items, children }: {
- draft: ProcessingDraft
+export function AccessoryProcessingEditor({ draft, edits, disabled, onChange, items, children, references = [] }: {
+ draft?: ProcessingDraft
edits?: ProcessingValues
disabled: boolean
onChange: (patch: ProcessingValues) => void
items?: readonly AccessoryDraft[]
children?: ReactNode
+ references?: readonly string[]
}) {
- const { family, machining, componentDrill, comparison, suggestionSource } = draft
+ const { family = 'other', machining, componentDrill, comparison, suggestionSource } = draft ?? {}
const suggestionId = useId()
- const values = { ...draft.values, ...edits }
+ const values = { ...draft?.values, ...edits }
const automatic = (family === 'screw' || family === 'dowel' || family === 'component') && !machining && !componentDrill
const camLines = machining?.type === 'cam' ? camProcessingLines(machining, items) : []
const suggested = (key: ProcessingField) => !!suggestionSource && (key === 'pilot' || key === 'allowance') &&
@@ -45,7 +47,7 @@ export function AccessoryProcessingEditor({ draft, edits, disabled, onChange, it
}
return
-
+
{family === 'surface' && {surfaceMountProcessing}
}
{family === 'screw' && <>
{screwFields.map(([key, label]) => number(key, label))}
@@ -67,11 +69,19 @@ export function AccessoryProcessingEditor({ draft, edits, disabled, onChange, it
{family === 'cam' && (camLines.length ?
{camLines.map(line => - {line}
)}
: 这组五金还没有完整的加工参数。
)}
- {suggestionSource && 参考同结构的 {suggestionSource} 带出建议值,核对后保存。
}
+ {suggestionSource &&
+
+ 参考同结构的 {suggestionSource} 带出建议值。{edits ? '确认后的参数将在保存后生效。' : '请核对后采用,或直接修改。'}
+
+ {!edits &&
}
+
}
{automatic && !suggestionSource &&
{Object.values(values).some(value => typeof value === 'number') ? '已带出可读取的尺寸,补齐空项后保存。' : '按实际工艺填写后保存。'}
}
{comparison && {comparison}
}
+ {references.map(line => {line}
)}
{children}
}
diff --git a/furniture-3d-system/src/app/database/bom-library/accessory-models/accessory-assembly-model-draft.ts b/furniture-3d-system/src/app/database/bom-library/accessory-models/accessory-assembly-model-draft.ts
new file mode 100644
index 000000000..0dec750c0
--- /dev/null
+++ b/furniture-3d-system/src/app/database/bom-library/accessory-models/accessory-assembly-model-draft.ts
@@ -0,0 +1,74 @@
+import { accessoryAxialRange } from '@/lib/accessory-model-orientation'
+import type { AccessoryCadPrimitive } from '@/lib/intake-accessory-cad'
+import type { AccessoryAnchor, InstallationAxis } from '@/lib/intake-accessory-installation'
+import type { AccessoryModel } from '@/lib/intake-accessory-models'
+
+const mm = (n: number) => Number(n.toFixed(3))
+const additions = (part: NonNullable['parts'][number]) =>
+ [part.base, ...part.operations.flatMap(({ op, tool }) => op === 'add' ? [tool] : [])]
+const radius = (solid: AccessoryCadPrimitive) => {
+ if (solid.shape === 'cylinder' || solid.shape === 'thread') return solid.diameter / 2
+ if (solid.shape === 'revolve' && !solid.angle) return Math.max(...solid.outline.map(([r]) => r))
+}
+const coaxial = (a: readonly number[], b: readonly number[], axis: number) =>
+ a.every((value, i) => i === axis || Math.abs(value - b[i]) <= .01)
+
+/** Use the contact in the saved model to separate the exposed rod from its thread. */
+export function draftAssemblyRod(model?: AccessoryModel | null, insertDepth?: number) {
+ const cad = model?.cad
+ const anchors = model?.installationAnchors?.filter(anchor => anchor.role === 'rod')
+ if (!insertDepth || cad?.scale !== 'dimensioned' || cad.rotation || anchors?.length !== 1) return
+ const anchor = anchors[0]
+ const axis = anchor.direction[1] as 'x' | 'y' | 'z'
+ const index = 'xyz'.indexOf(axis)
+ const sign = anchor.direction.startsWith('+') ? 1 : -1
+ const solids = cad.parts.flatMap(additions)
+ const threads = solids.filter(solid => solid.shape === 'thread')
+ if (threads.length !== 1 || threads[0].axis !== axis) return
+ const thread = threads[0]
+ const coordinate = (value: number) => (value - anchor.originMm[index]) * sign
+ const threadEnds = [coordinate(thread.at[index]), coordinate(thread.at[index] + thread.length)]
+ if (Math.abs(Math.max(...threadEnds)) > .2 || Math.min(...threadEnds) >= 0) return
+
+ let rodReach = 0
+ let rodRadius = 0
+ for (const solid of solids) {
+ const range = accessoryAxialRange(solid, axis)
+ const r = radius(solid)
+ if (!range || r === undefined || !coaxial(solid.at, anchor.originMm, index)) return
+ const far = Math.max(...range.map(coordinate))
+ if (far <= .2) continue
+ rodReach = Math.max(rodReach, far)
+ rodRadius = Math.max(rodRadius, r)
+ }
+ const engagement = mm(-Math.min(...threadEnds))
+ if (rodReach <= 0 || rodRadius <= 0 || engagement > insertDepth) return
+ return { rodDiameter: Math.ceil(rodRadius * 2), rodLength: mm(rodReach + engagement), engagement }
+}
+
+/** The wider end of a simple coaxial insert is the mounting face. */
+export function draftInsertAnchor(model?: AccessoryModel | null): AccessoryAnchor | undefined {
+ const cad = model?.cad
+ if (model?.imported || model?.installationAnchors?.length || cad?.scale !== 'dimensioned' ||
+ cad.rotation || cad.parts.length !== 1) return
+ const { name, base, operations } = cad.parts[0]
+ if (base.shape !== 'revolve' || base.angle) return
+ const axis = 'xyz'.indexOf(base.axis)
+ const heights = base.outline.map(([, height]) => height)
+ const low = Math.min(...heights)
+ const high = Math.max(...heights)
+ const endRadius = (height: number) => Math.max(...base.outline.filter(([, y]) => y === height).map(([r]) => r))
+ const holes = operations.flatMap(({ op, tool }) => op === 'cut' && (tool.shape === 'cylinder' || tool.shape === 'thread') &&
+ tool.axis === base.axis && coaxial(base.at, tool.at, axis) ? [tool] : [])
+ if (holes.length !== 1) return
+ const start = holes[0].at[axis] - base.at[axis]
+ const end = start + holes[0].length
+ const opensLow = start <= low + .02 && end > low
+ const opensHigh = end >= high - .02 && start < high
+ if (!opensLow && !opensHigh || opensLow && opensHigh && Math.abs(endRadius(low) - endRadius(high)) < .1) return
+ const fromLow = opensLow && (!opensHigh || endRadius(low) > endRadius(high))
+ const originMm: AccessoryAnchor['originMm'] = [...base.at]
+ originMm[axis] = mm(originMm[axis] + (fromLow ? low : high))
+ return { partPath: '0/0', partName: name, role: 'insert', originMm,
+ direction: ((fromLow ? '+' : '-') + base.axis) as InstallationAxis }
+}
diff --git a/furniture-3d-system/src/app/database/bom-library/accessory-models/accessory-connection-standards.ts b/furniture-3d-system/src/app/database/bom-library/accessory-models/accessory-connection-standards.ts
new file mode 100644
index 000000000..06cdef54c
--- /dev/null
+++ b/furniture-3d-system/src/app/database/bom-library/accessory-models/accessory-connection-standards.ts
@@ -0,0 +1,56 @@
+import { assemblyRoleNames, type AccessoryAssembly } from '@/lib/intake-accessory-assembly'
+import { accessoryComponentDrillSummary } from '@/lib/intake-accessory-component-drill'
+import { accessoryMachiningSummary } from '@/lib/intake-accessory-drilling'
+import { readDowelModelGeometry } from '@/lib/intake-accessory-dowel-model'
+import type { AccessoryDraft } from '@/lib/intake-accessory-models'
+
+type Model = AccessoryDraft['model']
+
+export function connectionModelReference(kind: string, model?: Model) {
+ if (!model || model.assembly || (model.kind && model.kind !== kind)) return []
+ if (kind === '圆棒榫' || kind === '木销') {
+ const length = readDowelModelGeometry(kind, model)?.length
+ return length ? [`模型榫长 ${length} mm,需确认两块板各自的孔深`] : []
+ }
+ const cad = model.cad
+ if (cad?.scale !== 'dimensioned') return []
+ if (kind === '连接杆' || kind === '双头连接杆') {
+ const threads = cad.parts.flatMap(part => [part.base, ...part.operations.flatMap(op => op.op === 'add' ? [op.tool] : [])])
+ .filter(solid => solid.shape === 'thread')
+ if (threads.length === 1) {
+ const [{ diameter, length }] = threads
+ return [`模型螺纹外径 Ø${diameter} mm · 螺纹段长 ${length} mm`]
+ }
+ }
+ if (cad.parts.length !== 1 || !['偏心轮', '预埋件', '带介内外牙', '直通内外牙'].includes(kind)) return []
+ const part = cad.parts[0]
+ if (part.operations.some(op => op.op === 'add')) return []
+ if (part.base.shape === 'cylinder') return [`模型外径 Ø${part.base.diameter} mm · 高 ${part.base.length} mm`]
+ if (part.base.shape === 'revolve') {
+ const heights = part.base.outline.map(([, height]) => height)
+ const diameter = Math.max(...part.base.outline.map(([radius]) => radius)) * 2
+ const height = Number((Math.max(...heights) - Math.min(...heights)).toFixed(3))
+ return [`模型外径 Ø${diameter} mm · 高 ${height} mm`]
+ }
+ return []
+}
+
+export function assemblyMemberStandards(assembly: AccessoryAssembly | undefined, items: readonly AccessoryDraft[] = []) {
+ return assembly?.components.map(component => {
+ const item = items.find(entry => entry.id === component.sourceId)
+ const drill = item?.drilling ?? item?.componentDrill
+ return { ...component, item, drill }
+ }) ?? []
+}
+
+export function assemblyMemberProcessingLines(assembly: AccessoryAssembly | undefined, items?: readonly AccessoryDraft[]) {
+ return assemblyMemberStandards(assembly, items).map(({ role, sourceCode, item, drill }) => {
+ const label = [assemblyRoleNames[role], item?.code ?? sourceCode].join(' · ')
+ const lines = item?.drilling ? [accessoryMachiningSummary(item.drilling)]
+ : item?.componentDrill ? [accessoryComponentDrillSummary(item.componentDrill)]
+ : item ? connectionModelReference(item.kind, item.model) : []
+ if (!drill) lines.push('标准孔位待确认')
+ if (role === 'rod' && drill) lines.push('杆孔用途和进刀面待确认')
+ return label + ':' + lines.join(' · ')
+ })
+}
diff --git a/furniture-3d-system/src/app/database/bom-library/accessory-models/accessory-processing-draft.ts b/furniture-3d-system/src/app/database/bom-library/accessory-models/accessory-processing-draft.ts
index baa70e066..c8b25672f 100644
--- a/furniture-3d-system/src/app/database/bom-library/accessory-models/accessory-processing-draft.ts
+++ b/furniture-3d-system/src/app/database/bom-library/accessory-models/accessory-processing-draft.ts
@@ -4,6 +4,7 @@ import type { AccessoryAnchor, InstallationAxis } from '@/lib/intake-accessory-i
import { accessoryMachiningSchema, type AccessoryMachining } from '@/lib/intake-accessory-machining'
import type { AccessoryDraft } from '@/lib/intake-accessory-models'
import { accessoryStandaloneProcessingType } from '@/lib/intake-accessory-machining-assets'
+import { readDowelModelGeometry } from '@/lib/intake-accessory-dowel-model'
type Model = NonNullable
type Input = Pick &
@@ -91,25 +92,6 @@ function nominalScrew(spec = '') {
return match && Number(match[1]) > 0 && Number(match[2]) > 0 ? { diameter: Number(match[1]), length: Number(match[2]) } : undefined
}
-function pegFacts(kind: string, model?: Model | null) {
- if (!model || (model.kind && model.kind !== kind)) return
- const cad = model.cad
- if (cad) {
- const part = cad.parts[0]
- if (cad.rotation || cad.parts.length !== 1 || part.operations.length || part.base.shape !== 'cylinder') return
- const { axis, diameter, length } = part.base
- const originMm: AccessoryAnchor['originMm'] = [...part.base.at]
- originMm[axes.indexOf(axis)] += length / 2
- return { diameter: cad.scale === 'dimensioned' ? diameter : undefined,
- anchor: { partPath: '0/0', partName: part.name, role: 'other', originMm, direction: '+' + axis } as AccessoryAnchor }
- }
- if (kind !== '圆棒榫') return
- const { length, diameter } = model.dimensions
- if (!(length > 0 && diameter > 0) || model.pending.includes('length')) return
- return { diameter: model.pending.includes('diameter') ? undefined : diameter,
- anchor: { partPath: '0/0', partName: 'Wood dowel', role: 'other', originMm: [0, length / 2, 0], direction: '+y' } as AccessoryAnchor }
-}
-
function screwSuggestion(input: Input, measured: NonNullable>, items: readonly AccessoryDraft[]) {
if (!measured.profile || !input.module || input.kind !== '木螺丝') return
const candidates = items.flatMap(item => {
@@ -162,7 +144,7 @@ export function accessoryProcessingDraft(input: Input, items: readonly Accessory
}
}
} else if (family === 'dowel') {
- const facts = pegFacts(kind, matching)
+ const facts = readDowelModelGeometry(kind, matching)
anchor = facts?.anchor
if (machining?.type === 'dowel') Object.assign(values, { firstDiameter: machining.first.diameterMm,
firstDepth: machining.first.depthMm, secondDiameter: machining.second.diameterMm, secondDepth: machining.second.depthMm })
diff --git a/furniture-3d-system/src/lib/intake-accessory-dowel-model.ts b/furniture-3d-system/src/lib/intake-accessory-dowel-model.ts
new file mode 100644
index 000000000..668a84e88
--- /dev/null
+++ b/furniture-3d-system/src/lib/intake-accessory-dowel-model.ts
@@ -0,0 +1,28 @@
+import type { AccessoryAnchor } from './intake-accessory-installation'
+import type { AccessoryDraft } from './intake-accessory-models'
+
+export function readDowelModelGeometry(kind: string, model?: AccessoryDraft['model']) {
+ if (!model || (model.kind && model.kind !== kind)) return
+ const cad = model.cad
+ if (cad) {
+ const part = cad.parts[0]
+ if (cad.rotation || cad.parts.length !== 1 || !part || part.operations.length) return
+ const { base } = part
+ if (base.shape !== 'cylinder' && base.shape !== 'fluted-dowel') return
+ const { axis, diameter, length } = base
+ const originMm: AccessoryAnchor['originMm'] = [...base.at]
+ originMm['xyz'.indexOf(axis)] += length / 2
+ const anchor: AccessoryAnchor = {
+ partPath: '0/0', partName: part.name, role: 'other', originMm, direction: `+${axis}`,
+ }
+ return { diameter: cad.scale === 'dimensioned' ? diameter : undefined,
+ length: cad.scale === 'dimensioned' ? length : undefined, anchor }
+ }
+ if (kind !== '圆棒榫' || model.imported || model.source === 'imported-glb') return
+ const { length, diameter } = model.dimensions
+ if (!(length > 0 && diameter > 0) || model.pending.includes('length')) return
+ const anchor: AccessoryAnchor = {
+ partPath: '0/0', partName: 'Wood dowel', role: 'other', originMm: [0, length / 2, 0], direction: '+y',
+ }
+ return { diameter: model.pending.includes('diameter') ? undefined : diameter, length, anchor }
+}