Files
Aislo/B06_Section/B06_Section_Cross_Design_Session.ts
T
eomsangdonandClaude Opus 5.5 1c090c0f5e feat(횡단초안): 344-3 측점 열쇠 — 세션 횡단 초안을 측점 열쇠로 · 옛 초안 옮김 · 노선 바뀜 넘김 · 노선 밖 고침 알림
- 열쇠 규칙 한 벌 = common_util_station_key(ts · py 짝 · 거울 시험) — 일반 grid:k · 관 pipe:<id> · 구조물 structure:<id> · 시종점 end:BP/EP · id 모름 at:<0.01 m>
- 세션 칸 다섯(카드 선택 · 노견 확장 · 소단 깊이 · 암 경계 · 암 경사) = 측점 열쇠로 담음 · 부르는 쪽은 그대로 누가거리로 읽고 씀 · 칸마다 쓴 때 자리를 함께 담아 구조물 id 를 아직 모를 때도 그 측점 고침을 읽음
- 옛 초안(누가거리 열쇠)은 읽을 때 측점 열쇠로 옮김 · 지금 측점에 없는 고침은 지우지 않고 남김
- 측점 목록 = 상세가 초안 측점을 얹을 때 · 다시 셈 때 세움(관 id = 관 장부 · 구조물 id = 측점 계획 · 구조물 목록)
- 노선 바뀜 넘김 carryStationDrafts — 카드 선택 넷(지반 유형 · 측구 종류 · 측구 선택 · 2단 경사) · 암 경계 · 암 경사만 · 단면 유형 · 측구 방향은 새 지형이 정함 · 사라진 측점 = 「노선 밖 고침 N 건」 한 줄(부르는 자리 = 3파)
- 옛 시험 셋 새 창구로 맞춤

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QfHKQs7J3hQELKMWQMUJEy
2026-10-16 11:45:31 +09:00

129 lines
5.4 KiB
TypeScript

/* =============================================================================
* B06_Section_Cross_Design_Session.ts
* 횡단 카드 버튼(지반유형·단면유형·측구·포장·2단 비탈) 선택의 **세션 보관소**.
*
* 왜 생겼나(2026-09-06 사용자 확정) — 예전에는 버튼을 누를 때마다
* `POST …/sections/{route}/cross-design` 이 나가 서버가 계산하고 **바로 저장**했다.
* 조작은 캐시에 쌓이고 [저장]·[확정]에서만 정본으로 나가야 한다는 규칙에 어긋난다.
* 계산은 브라우저가 하고(`common_util_cross_design.ts`), 선택값은 여기 담긴다.
*
* 담는 것은 **사용자가 고른 것만**이다 — 계산 결과(면적·설계선)는 담지 않는다.
* 세션 열쇠 = 측점 열쇠(344-3 · `B06_Section_Station_Keys`) · 부르는 쪽에는 누가거리로 내줌.
* ========================================================================== */
import { chainageKey } from "@util/common_util_station_key";
import { readKeyed, writeKeyed } from "./B06_Section_Station_Keys";
/** 카드에서 고를 수 있는 값 한 벌 — 서버 `CrossDesignRequest` 와 같은 이름을 쓴다. */
export interface CrossDesignChoice {
ground_type: string;
section_mode: string;
ditch_side?: string | null;
ditch_type?: string | null;
paved?: boolean;
two_stage_slope?: boolean;
/** 측구를 둘지 **사용자가 정한 선택**(`null` = 자동 판정). 결과(`ditch_enabled`)가 아니다.
* ⚠ 이 칸이 없으면 측구 토글이 눌려도 캐시에 안 담겨 **화면에서 안 돈다**(2026-09-09). */
ditch_choice?: boolean | null;
}
/** 누가거리(0.01 m 글) → 선택값 — 지금 측점에 있는 것만. */
const readAll = (projectId: string, routeId: number) =>
readKeyed<CrossDesignChoice>("crossdesign", projectId, routeId);
/** 이 측점의 선택값(없으면 null). */
export function readCrossDesignChoice(
projectId: string,
routeId: number,
chainageM: number,
): CrossDesignChoice | null {
return readAll(projectId, routeId).get(chainageKey(chainageM)) ?? null;
}
/** 선택값을 세션에 담는다. 같은 측점의 앞선 값은 덮어쓴다. */
export function writeCrossDesignChoice(
projectId: string,
routeId: number,
chainageM: number,
choice: CrossDesignChoice,
): void {
const at = chainageKey(chainageM);
writeKeyed("crossdesign", projectId, routeId, new Map([[at, choice]]), [at]);
}
/** [저장]·[확정]이 patch 로 실을 목록 — 누가거리(숫자) → 선택값. */
export function crossDesignChoices(
projectId: string | null,
routeId: number | null,
): Map<number, CrossDesignChoice> {
const choices = new Map<number, CrossDesignChoice>();
if (!projectId || routeId === null) return choices;
for (const [key, value] of readAll(projectId, routeId)) {
const chainage = Number(key);
if (Number.isFinite(chainage) && value) choices.set(chainage, value);
}
return choices;
}
/* ── 설계선 쉬프트 = 쪽마다 노견 확장(m · ≥ 0 · 139-6) — 카드 버튼 선택과 따로 담음(버튼 선택이
* 통째로 덮어써도 안 지워지게). [저장]·[확정] 이 patch 로 싣고, 브라우저 재계산이 입력으로 씀. */
export type ShoulderSide = "left" | "right";
export type ShoulderExtends = Map<number, Partial<Record<ShoulderSide, number>>>;
type SideState = "shoulderext" | "bermdepth";
/** 누가거리(숫자) → 쪽마다 값(세션에 있는 쪽만). */
function readSides(name: SideState, projectId: string | null, routeId: number | null) {
const out: ShoulderExtends = new Map();
if (!projectId || routeId === null) return out;
for (const [key, value] of readKeyed<Partial<Record<ShoulderSide, number>>>(
name,
projectId,
routeId,
)) {
const chainage = Number(key);
if (Number.isFinite(chainage) && value) out.set(chainage, value);
}
return out;
}
function writeSide(
name: SideState,
projectId: string,
routeId: number,
chainageM: number,
side: ShoulderSide,
valueM: number,
): void {
const at = chainageKey(chainageM);
const own = readKeyed<Partial<Record<ShoulderSide, number>>>(name, projectId, routeId).get(at);
const next = { ...(own ?? {}), [side]: Math.max(valueM, 0) };
writeKeyed(name, projectId, routeId, new Map([[at, next]]), [at]);
}
/** 누가거리(숫자) → 쪽마다 노견 확장(세션에 있는 쪽만). */
export const readShoulderExtends = (projectId: string | null, routeId: number | null) =>
readSides("shoulderext", projectId, routeId);
/** 한 측점 한 쪽 노견 확장을 담는다(0 = 되돌림 · 저장 때 정본의 옛 값을 지움). */
export const writeShoulderExtend = (
projectId: string,
routeId: number,
chainageM: number,
side: ShoulderSide,
valueM: number,
) => writeSide("shoulderext", projectId, routeId, chainageM, side, valueM);
/* ── 소단 쪽마다 옮긴 깊이(노면 끝 아래 m · ≥ 0 · 194-1 · 횡단도 ▲▼) — 노견 확장과 같은 꼴.
* [저장]·[확정] 이 patch 로 싣고(서버가 다시 셈), 브라우저 재계산이 입력으로 씀. */
export const readBermDepths = (projectId: string | null, routeId: number | null) =>
readSides("bermdepth", projectId, routeId);
export const writeBermDepth = (
projectId: string,
routeId: number,
chainageM: number,
side: ShoulderSide,
depthM: number,
) => writeSide("bermdepth", projectId, routeId, chainageM, side, depthM);