diff --git a/src/core/dxf-table.ts b/src/core/dxf-table.ts index 9e0e8dc..0bc4e80 100644 --- a/src/core/dxf-table.ts +++ b/src/core/dxf-table.ts @@ -118,8 +118,13 @@ export interface SolplateTableRow { * their headers, as in the bearing ELEVATION table. */ export function parseSolplateTable(texts: DxfText[]): { rows: SolplateTableRow[]; errors: string[] } { - const sHeader = texts.find((t) => norm(t.text) === 's(%)' || norm(t.text) === 's%'); - if (!sHeader) return { rows: [], errors: ['솔플레이트 TABLE의 S(%) 머리글을 찾지 못했습니다.'] }; + // The drawing has more than one "S(%)" label: the header is the one with L, W, T, T1 and T2 on its row. + const SOL_NAMES = ['l', 'w', 't', 't1', 't2']; + const solScore = (t: DxfText) => texts.filter((u) => Math.abs(u.y - t.y) <= 60 && SOL_NAMES.includes(norm(u.text))).length; + const sCandidates = texts.filter((t) => norm(t.text) === 's(%)' || norm(t.text) === 's%'); + const sBest = sCandidates.map((t) => ({ t, score: solScore(t) })).sort((a, b) => b.score - a.score)[0]; + if (!sBest || sBest.score < 5) return { rows: [], errors: ['솔플레이트 TABLE의 머리글(NO, L, W, T, T1, T2)이 모두 있어야 합니다.'] }; + const sHeader = sBest.t; const headerY = sHeader.y; const headerRow = texts.filter((t) => Math.abs(t.y - headerY) <= 60); const key = (name: string) => headerRow.find((t) => norm(t.text) === name); diff --git a/tests/dxf-table.test.ts b/tests/dxf-table.test.ts index d232afc..0314260 100644 --- a/tests/dxf-table.test.ts +++ b/tests/dxf-table.test.ts @@ -47,6 +47,12 @@ import { SOLPLATE_REF } from '../src/core/bearing-ref'; describe('솔플레이트 TABLE 읽기 (승인 2026-10-23)', () => { const sp = JSON.parse(readFileSync(new URL('./fixtures/solplate-table-texts.json', import.meta.url), 'utf-8')) as DxfText[]; + it('a stray "S(%)" label elsewhere on the drawing does not replace the solplate header', () => { + const r = parseSolplateTable([{ x: 16000, y: 16200, text: 'S(%)' }, ...sp]); + expect(r.errors).toEqual([]); + expect(r.rows.length).toBe(10); + }); + it('reads S, L, W, T, T1 and T2 for all ten bearings, and they equal the reference values', () => { const r = parseSolplateTable(sp); expect(r.errors).toEqual([]);