/* ============================================================================= * A00_Common/design/design_pick_match.ts * 고름 강조 한 규칙(323-5) — 그린 것(카드 형상 · 3D 부재 · 알약 · 측점선)마다 신원표 `{구조물 id · 부분 · 자리}` * 를 달고, 고름 한 칸(`structure-pick`)과 이 함수 하나로 켜짐을 가름. * * ① 고름 · 그림 둘 다 구조물 id 가 있으면 id 가 같아야(관 = 세션 id `design_pipe_ids` · 옮겨도 그대로) * ② 아니면 같은 자리(`PIPE_MATCH_M` — 같은 자리 거리는 이 한 값) * ③ 고른 부분(부재키)이 있으면 그 부분만 · 부분을 안 골랐으면 그 구조물 그림 모두 * DOM 은 `data-structure-id` · `data-part`(`tagShape`) — 부분 그림(관 · 벽 · 날개벽 · 물넘이 콘크리트)은 * 조정창 손잡이가 같은 고름으로 칠함(`paintPicked` 는 부분 없는 형상만 · 307 「측점 길은 부분 안 켬」). * ========================================================================== */ import { isNear, type DesignSelection } from "./design_selection"; export interface PickTag { structureId?: string | null; part?: string | null; chainageM?: number | null; } export type PickSelection = (Partial & { partKey?: string | null }) | null | undefined; /** 이 그림이 고름에 켜지나 — 위 ① ② ③. */ export function pickLights(selection: PickSelection, tag: PickTag): boolean { if (!selection) return false; let here: boolean; if (selection.structureId && tag.structureId) here = selection.structureId === tag.structureId; else if (selection.chainageM == null || tag.chainageM == null) return false; else here = isNear(tag.chainageM, selection.chainageM); if (!here) return false; return !selection.partKey || tag.part === selection.partKey; } /** 그린 형상에 신원표를 닮(부분 없으면 통째 형상). */ export function tagShape(el: Element, structureId: string | null, part?: string | null): void { if (structureId) el.setAttribute("data-structure-id", structureId); if (part) el.setAttribute("data-part", part); } /** 카드 안 통째 형상 칠하기 — 고른 구조물 id 와 같은 형상만. 부분 그림(`data-part`) · 관 계열(`pipe-`) · * 노면공 포장층은 제 손잡이(조정창 · 포장층 고름)가 칠함 — 측점 길(알약 · 목록 · 측점선)은 부분을 안 켬(307). */ export function paintPicked(root: ParentNode, selection: PickSelection): void { for (const shape of root.querySelectorAll("[data-structure-id]")) { const id = shape.getAttribute("data-structure-id") ?? ""; if (id.startsWith("pipe-") || shape.getAttribute("data-part") !== null) continue; if (shape.getAttribute("data-pave-type") !== null) continue; shape.classList.toggle( "is-active", !!selection?.structureId && pickLights(selection, { structureId: id }), ); } }