Files
Aislo/B06_Section/B06_Section_UI_Page_Structure_Pick.ts
T
eomsangdonandClaude Opus 5.5 42673505e7 fix(B06): 측점만 남은 고름의 노면공 범위 강조 막음 · B05 3D 같은 구멍 · 카드 옮겨 감 · 관 넘김 카드(231-1)
- B06 폼 다시 세움(load) 의 selectAt 에 노면공 거름(coverable) · 측점 고름이 연 폼은 카드 그대로 · 범위 테두리 없음
- B05 3D 부재 고름 resolveAt · selectAt 에 같은 거름 — 노면공 id 를 고름 한 칸에 안 적음
- 넘김 되얹기 카드 = 찾는 거리 안 가장 가까운 카드(관 80.17 이 카드 80 으로 안 감)
- 새 시험 test_231_1 · test_106 배선 문자열 맞춤

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01STqEqztUthVFBmEP18wBSz
2026-10-10 17:49:12 +09:00

106 lines
5.5 KiB
TypeScript

/* =============================================================================
* B06_Section_UI_Page_Structure_Pick.ts
* B05 3D에서 고른 구조물을 **B06 화면에 얹는다**(2026-09-04 사용자 확정) — 그 측점
* 카드를 고르고 화면에 드러낸 뒤, 부재키가 있으면 그 시설의 조정창까지 연다.
*
* 부재키는 **횡단도가 그 부재를 부르는 이름 그대로**다. 이름이 겹쳐도(배수관 유입 ↔
* 세월교 유입) 한 측점에는 시설이 하나뿐이라 헷갈리지 않는다 — 그 측점이 세월교면
* 세월교 조정창, BOX암거면 BOX 조정창, 아니면 기슭막이 조정창으로 보낸다.
* 본체(`body` — 세월교 월류부 상판·BOX 구체)는 세월교 · BOX 에서 좌측 본체 상자를 고른다(66-1) ·
* 그 밖 시설은 카드까지만 연다.
*
* 세월교·BOX는 조정창 하나가 그 측 부재 여럿(벽·바닥·날개벽·에이프런)을 함께 다루므로
* 부재키가 `측이름:부재`(예 `inlet:wall`) 꼴이다 — **앞칸이 조정창 이름**이다. 3D 강조는
* 부재 하나만 켜야 해서 뒤칸까지 나눠 두었다(2026-09-04 사용자 확정).
* ========================================================================== */
import type { SectionDetailResponse } from "./B06_Section_Api_Fetch";
import type { RevetPick } from "./B06_Section_UI_Cross_Culvert";
import type { StructurePickHandoff } from "../B05_Profile/B05_Profile_UI_Structure_Pick_Session";
import {
coversChainage,
nearestWithin,
type SelectableStructure,
} from "../A00_Common/design/design_selection";
/** 벽 고름이 받는 부재키 — 관 · 도수로 띠는 강조만(118-1 · 152-4) · 집수정·본체는 여기서 빠진다. */
const REVET_KEYS = /^(inlet|outlet|own|extra\d+|bextra\d+|pipe|chute)$/;
interface PickTargets {
focusStation: (stationId: string) => void;
refreshCard: (chainageM: number) => void;
revetSelect: (chainageM: number, key: RevetPick) => void;
fordSelect: (chainageM: number, role: "inlet" | "outlet" | "body") => void;
boxSelect: (chainageM: number, role: "left" | "right" | "body") => void;
}
/**
* 넘김값을 화면에 적용한다. 값이 없거나 그 측점이 이 노선에 없으면 아무것도 안 한다.
* 카드가 다 선 뒤에 고른다 — 스크롤이 자리를 잡아야 한다. 카드를 찾아 적용했으면 true —
* 못 찾았으면(구조물 목록이 아직 안 실린 경우 등) false 라 부르는 쪽이 나중에 다시 부른다.
*/
export function applyStructurePick(
handoff: StructurePickHandoff | null,
detail: SectionDetailResponse | null,
targets: PickTargets,
/** 구조물 정본 — 카드 위치가 아닌 곳(구간형 옹벽 한가운데 등)을 골랐을 때 그 카드를 찾는 데 쓴다. */
structures: ReadonlyArray<SelectableStructure> = [],
): boolean {
if (!handoff) return false;
// 허용오차는 관·구조물 찾는 거리 한 값이다 — 0.01m 로는 3D 가 준 누가거리가
// 소수점 아래에서 조금만 달라도 그 측점을 못 찾고 조용히 끝났다(2026-09-05 진단).
const sections = detail?.cross_sections ?? [];
// 구조물 id 가 있으면 그 구조물의 카드가 먼저다 — 같은 측점 근처에 다른 카드(관)가 있어도.
const byId = handoff.structureId
? structures.find((entry) => entry.structure_id === handoff.structureId)
: undefined;
const covering = structures.find((entry) => coversChainage(entry, handoff.at));
const target =
(byId && cardOfStructure(sections, byId, handoff.at)) ||
// 찾는 거리 안 가장 가까운 카드 — 첫 카드면 관 80.17 이 이웃 측점 80 카드로 감(231-1)
nearestWithin(sections, handoff.at, (section) => section.chainage_m) ||
(covering && cardOfStructure(sections, covering, handoff.at));
if (!target) return false;
// 조정창은 앞칸(측 이름)만 본다 — 뒤칸은 3D 강조를 부재 하나로 좁히는 몫이다.
const key = handoff.key?.split(":")[0];
requestAnimationFrame(() => {
targets.focusStation(target.station_id);
if (!key) return;
if (target.ford) {
if (key !== "inlet" && key !== "outlet" && key !== "body") return;
targets.fordSelect(target.chainage_m, key);
} else if (target.box) {
if (key !== "left" && key !== "right" && key !== "body") return;
targets.boxSelect(target.chainage_m, key);
} else {
if (!REVET_KEYS.test(key)) return;
targets.revetSelect(target.chainage_m, key as RevetPick);
}
targets.refreshCard(target.chainage_m);
});
return true;
}
type Sections = SectionDetailResponse["cross_sections"];
/** 구조물이 자리한 카드 — 구간형이면 그 안의 첫 카드, 점형이면 가장 가까운 카드. 옹벽 · 기슭막이는
* 횡단 제원이라 시작 측점 카드가 주인이다(관은 `nearestWithin` 으로 카드를 바로 찾는다). */
function cardOfStructure(
sections: Sections,
structure: SelectableStructure,
at: number,
): Sections[number] | undefined {
if (!sections.length) return undefined;
const start = structure.start_m ?? structure.chainage_m;
const end = structure.end_m ?? structure.chainage_m;
if (start != null && end != null) {
const inside = sections.find(
(section) => section.chainage_m >= start - 0.01 && section.chainage_m <= end + 0.01,
);
if (inside) return inside;
}
return sections.reduce((best, entry) =>
Math.abs(entry.chainage_m - at) < Math.abs(best.chainage_m - at) ? entry : best,
);
}