/* ============================================================================= * B06_Section_Section_Adjusts.ts * 저장 안 한 조정창 값(세션 · 측점 누가거리 열쇠)을 상세 설계 칸에 얹음 — 상세 가게가 읽을 때 한 번(387-4). * * 조정창(`_UI_Page_Station_Controls` · `_Ford_Controls` · `_Span_Control`)이 고칠 때 캐시에 얹는 것과 같은 * 칸 · 같은 꼴. 예전에는 고칠 때만 얹어 새로고침 · B05 만 연 페이지는 세션 값을 몰랐음 — 카드 그리기가 면적을 * 고쳐 들어 B06 을 연 뒤에만 면적이 바뀜(B05 만 연 면적 ≠ B06). 조정창은 세션 → 설계 순으로 읽으니 겹쳐도 같음. * * 관 옵션(폼 칸 · 관 초안 ?? 저장 관)의 조정값 몫도 여기서(387-4b · `layPipeOptions`) — 관 벽 높이 · 형태(h · m) · * 흙막이 n 단(h · m · 구간). 예전에는 B06 보기가 열릴 때 폼이 되보내야만 얹혀 B05 만 연 면적이 달랐음. * 형상(관 세트 · 흙막이 세트 · 도수로 · 세월교 · BOX 제원)은 형상 얹기(`attachShapes`)가 이미 함. * 같은 규칙 = `B06_Section_UI_Page_Pipe_Options`(폼을 고친 그 자리 즉시 반영 몫). * * 조정창 값 주인 = 세션 칸(472-5 5-D) — 얹기 = 「조정창이 처음 고치기 전 설계 칸 + 지금 세션 칸」. ↶ ↷ 가 칸을 * 지워도 캐시 설계(그림 · [저장] 바탕)에 옛 값이 안 남음. 상세가 새로 서면(받음 · [저장] · 떠남) 새 객체라 빔. * ========================================================================== */ import { readState } from "../A00_Common/b_page_state"; import type { CrossSection, SectionDetailResponse } from "./B06_Section_Api_Fetch"; import { readBermDepths, readShoulderExtends } from "./B06_Section_Cross_Design_Session"; import { layCarriedEdits, layDraftAdjusts, layPipeOptions, type Cells, type OptionPipe, } from "./B06_Section_Route_Carry_Patch"; // 얹기 몸통 = `B06_Section_Route_Carry_Patch` 한 벌(서버 노선 바뀐 [저장] 넘김도 · 472-6) — 여기는 세션 겉. export { layPipeOptions, type OptionPipe }; /** 조정창이 처음 고치기 전 설계 칸(측점 객체마다 · 칸 이름 → 값 · 다시 셈이 설계 객체를 갈아도 측점은 그대로). */ const beforeAdjust = new WeakMap>(); /** 조정창이 캐시 설계 칸을 고치기 직전 — 그 칸의 처음 값을 한 번 떠 둠. */ export function noteAdjustBase(section: CrossSection, keys: readonly string[]): void { const design = section.design as unknown as Record | null | undefined; if (!design) return; const base = beforeAdjust.get(section) ?? {}; for (const key of keys) if (!(key in base)) base[key] = structuredClone(design[key]); beforeAdjust.set(section, base); } export function withDraftAdjusts( detail: SectionDetailResponse, projectId: string, routeId: number, ): void { for (const section of detail.cross_sections) { const base = beforeAdjust.get(section); const design = section.design as unknown as Record | null | undefined; if (!base || !design) continue; for (const [key, value] of Object.entries(base)) if (value === undefined) delete design[key]; else design[key] = structuredClone(value); } layDraftAdjusts(detail, (name) => readState(name as never, projectId, routeId) ?? {}); } /** 노선 저장 뒤 새 노선으로 옮긴 세션 고침(417) — 사면 쉬프트 · 소단 깊이 · 측점 폭 · 메모 · 상세 표를 설계 칸에 얹음 · * 같은 [저장]의 횡단 패치(`crossPatchesFromCache`)가 실음. 조절 4축 · 형식은 `withDraftAdjusts`. */ export function withCarriedEdits( detail: SectionDetailResponse, projectId: string, routeId: number, ): void { layCarriedEdits(detail, (name) => readState(name as never, projectId, routeId) ?? {}, { shoulder: readShoulderExtends(projectId, routeId), berm: readBermDepths(projectId, routeId), }); } /** 관 옵션 조정값 몫 얹기(387-4b) — 관 초안 ?? 저장 관(페이지 자료 줄). 가게 · 자료 줄은 부를 때 늦게 불러옴 — * 이 파일을 끄는 시험 · 묶음이 그 줄기(fetch · 가게)를 안 끌게. 못 받으면 그대로. * `reshape` = 관 제원도 형상 얹기 규칙으로 다시(다시 셈 창구 앞 · B06 폼 되보내기가 옵션 값을 제원에 그대로 * 써 넣어 최소 높이 · 집수정 쪽 칸이 서버와 갈림 — 집수정 높이 1.5 ↔ 2 등). */ export async function withPipeOptions( detail: SectionDetailResponse, projectId: string, reshape = false, ): Promise { if (reshape) await import("./B06_Section_Section_Drafts") .then(({ withDraftShapes }) => withDraftShapes(detail, projectId)) .catch(() => undefined); const pipes = await import("../B05_Profile/B05_Profile_Api_Pipes_Draft") .then( async ({ readPendingPipes }) => readPendingPipes(projectId) ?? (await import("../A00_Common/design/design_page_data")) .pagePipes(projectId) .then((res) => res.pipe_points), ) .catch(() => null); if (pipes) layPipeOptions(detail, pipes as OptionPipe[]); }