/* ============================================================================= * B05_Profile_UI_Structure_Pick_Session.ts * 3D에서 고른 구조물을 **좌측 「구조물 배치」 패널로 넘기고**, 그 선택을 세션 한 칸에 * 남겨 **B06 진입 때 같은 측점 카드가 열리게** 한다(2026-09-04 사용자 확정). * * B05·B06은 라우터가 따로 띄우는 화면이라 실시간 양방향이 아니다 — 조작 상태는 캐시 * 몫이라는 데이터 3층 규칙대로 sessionStorage 한 칸에 남긴다. 값은 **지우지 않고 남긴다** * (2026-09-04 사용자: 두 화면이 한 페이지처럼 움직여야 함) — B06에서 고른 것도 같은 칸에 * 적혀, 어느 쪽으로 오가든 마지막 선택이 그대로 살아 있다. * ========================================================================== */ import { NO_SELECTION, readSelection, selectDesign, type DesignSelection, } from "../A00_Common/design/design_selection"; import type { StructurePick, StructurePickControls } from "./B05_Profile_UI_Viewer_Structure_Pick"; import type { StructuresSection } from "./B05_Profile_UI_Structures_Panel_Types"; /** B06으로 넘기는 선택 — B06이 쓰는 `{ 측점, 부재키 }` 한 쌍에 구조물 id 가 붙는다. */ export interface StructurePickHandoff { at: number; key?: string; structureId?: string; } /* 넘김값은 `design_selection` 의 selection 한 곳이다 — 3D · 알약 · 목록 · 횡단 카드 어디서 골라도 그 함수 하나로 적고(`selectDesign`), 여기서는 읽기만 한다. 값은 ② 설계 초안이라 등록표(`b_page_state`)를 쓴다(2026-09-06 캐시·세션 일원화). */ /** 세션에 남은 선택을 읽는다(지우지 않는다). 없으면 null. */ export function readStructurePick(projectId: string | null): StructurePickHandoff | null { const value = readSelection(projectId); if (!value || value.chainageM === null) return null; return { at: value.chainageM, key: value.partKey, structureId: value.structureId ?? undefined, }; } /** * 3D 클릭 결과를 화면 전체에 적용한다. * * 배수관 세트(기슭막이·집수정·배관)는 `selectStation`(=기존 선택 동기화)이 좌측 폼·종단 * 그래프·3D 마커·유역도를 한 줄로 맞춘다. 그 줄에서 아무것도 안 잡히면 옛 정본 구조물로 * 보고 폼이 구조물 id 로 연다 — 관·구조물 찾는 거리와 순서는 `resolveSelection` 한 곳이다. */ export function wireStructurePick( controls: StructurePickControls, projectId: string | null, structures: StructuresSection, /** 기존 선택 동기화(`selectStationOfPipe`) — 누가거리 하나로 전 화면을 맞춘다. */ selectStation: (chainageM: number | null) => void, ): void { controls.onPick = (pick: StructurePick | null): void => { if (!pick) { selectDesign(projectId, NO_SELECTION, { from: "b05" }); selectStation(null); return; } const selection: DesignSelection = { chainageM: pick.chainageM, structureId: null }; const { structureId } = structures.resolveAt(selection); selectDesign(projectId, { ...selection, structureId }, { partKey: pick.key, from: "b05" }); selectStation(pick.chainageM); if (!structures.hasSelection()) structures.selectAt({ ...selection, structureId }); }; } /** * 화면에 들어올 때 세션에 남은 선택을 되살린다 — B06에서 고른 것도 그대로 이어 받는다 * (2026-09-04 사용자: 두 화면이 한 페이지처럼). 3D 강조는 코리도가 뜬 뒤 자동으로 다시 * 칠해지므로 여기서는 선택만 세워 둔다. * * **되살렸으면 true.** 관 목록이 아직 안 실렸으면 폼이 그 시설을 못 찾으므로 false를 * 돌려준다 — 부르는 쪽은 목록이 실릴 때마다 다시 부르면 된다. */ export function restoreStructurePick( controls: StructurePickControls, projectId: string | null, structures: StructuresSection, selectStation: (chainageM: number | null) => void, ): boolean { const handoff = readStructurePick(projectId); if (!handoff) return true; // 되살릴 것이 없으면 끝난 것으로 본다. controls.select({ chainageM: handoff.at, kind: "", key: handoff.key }); selectStation(handoff.at); // 구조물 id 가 적혀 있을 때만 구조물로 연다 — 관 목록이 아직 안 실렸을 때 측점만으로 구조물을 // 짐작하면 그 측점을 덮는 다른 구조물이 열린다(관은 목록이 실릴 때 위 `selectStation` 이 연다). if (!structures.hasSelection() && handoff.structureId) { structures.selectAt({ chainageM: handoff.at, structureId: handoff.structureId }); } return structures.hasSelection(); }