Files
Aislo/common_util/common_util_structure_catalog.py
T
eomsangdonandClaude Opus 5.5 6c87207f76 feat(구조물표): 322-3 측점 계획 한 벌(TS · 파이썬 짝) — 카드 목록 · B05 종단 · 3D 막대 · B06 종단 띠(모든 종류) · 서버 측점이 같은 목록 · 일반 측점 자리 새 구조물 이름 · 형상(219) · 서버 낡음 = 자리 + 이름 · 옮긴 관 고름 유지 · 배수 패널 되먹임 끊음
- 측점 계획 planStations(TS) ↔ plan_stations(py): 관 · 구조물 + 구조물 표 → 측점 · 역할 · 카드 이름 · 덮는 구조물 id · 빈칸 경고(형상 부품 필수 칸) · 같은 m 하나(이름 = 관 먼저 · 앞선 것)
- 서버 resolve_extra_stations = 계획(같은 자리 한 번 · 옛 「마지막 이름」 걷음) · _stale_marks = 자리 + 이름(종류 · 관 공식 · 정의 판 이름)
- 카드 목록(Section_Drafts) = 계획 이름 · 일반 측점 자리(regular)에 새로 놓은 구조물 = 그 자리 구조물 없는 사본에 이름 칩 · 관 그림 · 벽 · 포장(219 흠)
- B05 종단 · 3D 측점 = 계획(design_structure_status.plannedIrregular) · 배수유역도로 관 자리 되먹임 끊음
- B06 종단 띠 = 계획(관만 → 모든 종류 · 관 구간도 넘김)
- 고름: followMovedPipe — 고른 관을 옮기면 고름도 새 자리(B05 폼 · 종단 끌기 · B06 옮김)
- 부품 상자 형상 「필수 칸」(관경 · 벽 높이 · 맹암거 높이 · 물넘이 높이 · 기슭막이 높이)
- 시험: test_322_3_plan_mirror(거울 · 규칙 · 서버 공급자 · 낡음) · test_322_3_flow(흐름 일곱 + 고름 따라감) · 272_1 = 같은 자리 한 번 · 318 도움 파일 표 모듈 한 줄

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ji4nuyLVHcxrXWHTdb5nRD
2026-10-14 16:03:33 +09:00

134 lines
5.4 KiB
Python

"""구조물 표(catalog · PLAN 322-1) — 종류마다 「무엇을 할지」 한 줄.
한 줄 = 정의 `반영` ⊕ 부품 상자 처음값 ⊕ 부품 끔. 종류 키 · 군 글자 · 자리꼴 · managed_by 로
가리던 자리(측점 · 카드 이름 · 형상)가 이 한 줄을 읽음 · 그리는 함수는 그대로.
부품 상자 = `common_util_structure_parts.json`(TS 와 같은 파일) · 줄 열쇠도 TS 와 같은 이름.
TS 짝 = `common_util_structure_catalog.ts`
거울 시험 = `resources/tester/test_322_1_catalog_mirror.py`.
"""
from __future__ import annotations
import json
import math
from functools import lru_cache
from pathlib import Path
from typing import Any
PARTS_PATH = Path(__file__).with_name("common_util_structure_parts.json")
# 갈래 → 부품을 끈 값(`부품.{갈래}.{id} == false`)
_OFF = {"횡단도": "none", "카드이름": "name", "형상": "none", "3D": "none"}
@lru_cache(maxsize=1)
def load_parts() -> dict[str, Any]:
with open(PARTS_PATH, encoding="utf-8") as handle:
return json.load(handle)
def resolve_catalog(
definition: dict[str, Any] | None, parts: dict[str, Any] | None = None
) -> dict[str, dict[str, Any]]:
"""정의 + 부품 상자 → 종류마다 한 줄(정의 types 차례 · 정의가 없으면 처음값 차례)."""
start = (parts or load_parts())["처음값"]
definition = definition or {}
groups = definition.get("구조물군") or {}
group_keys = list(groups)
off = {key for key, on in (definition.get("부품") or {}).items() if on is False}
reflect = definition.get("반영") or {}
types = definition.get("types") or [{"type_id": key} for key in start]
rows: dict[str, dict[str, Any]] = {}
for order, item in enumerate(types):
type_id = item["type_id"]
base = start.get(type_id) or {}
mine = reflect.get(type_id) or {}
def part(branch: str, base=base, mine=mine) -> str:
value = mine.get(branch, base.get(branch, _OFF[branch]))
return _OFF[branch] if f"{branch}.{value}" in off else value
group = item.get("group") or ""
# 반영이 없으면 옛 짝 — 처음값 hidden 은 숨김 · 그 밖은 정의 enabled 가 가름(꺼짐 = B06 만)
if "목록" in mine:
listed = mine["목록"]
elif base.get("목록") == "hidden":
listed = "hidden"
else:
listed = "b06" if item.get("enabled") is False else "both"
rows[type_id] = {
"typeId": type_id,
"name": item.get("name") or type_id,
"group": group,
"groupName": groups.get(group, group),
"groupOrder": group_keys.index(group) if group in group_keys else len(group_keys),
"typeOrder": order,
"placement": base.get("자리꼴") or item.get("placement") or "point",
"owner": "pipe_points" if item.get("managed_by") == "pipe_points" else "structures",
"list": listed,
"station": part("횡단도"),
"title": part("카드이름"),
"shape": part("형상"),
"shapeOpts": {**(base.get("형상칸") or {}), **(mine.get("형상칸") or {})},
"model3d": part("3D"),
"color": (item.get("style") or {}).get("color") or None,
}
return rows
@lru_cache(maxsize=4)
def _catalog_at(path: str, mtime: int, size: int) -> dict[str, dict[str, Any]]:
from B05_Profile.B05_Profile_Structures_Schema import _read_definition
return resolve_catalog(_read_definition(path, mtime, size))
def catalog() -> dict[str, dict[str, Any]]:
"""지금 정의 판의 표 — 정의 파일이 바뀌면(M02 저장) 다음 부름부터 새 표(파일 시각 캐시)."""
from B05_Profile.B05_Profile_Structures_Schema import _stamp
return _catalog_at(*_stamp())
def catalog_row(type_id: str) -> dict[str, Any] | None:
return catalog().get(type_id)
def type_ids_with(**match: str) -> set[str]:
"""표에서 칸 값이 맞는 종류들 — 예 `type_ids_with(shape="pavement")`."""
return {key for key, row in catalog().items() if all(row[k] == v for k, v in match.items())}
def shape_needs(type_id: str) -> list[str]:
"""형상 부품의 필수 칸(비면 그 그림이 안 섬 · 빈칸 경고 · 322-3) — TS `shapeNeeds` 짝."""
row = catalog_row(type_id)
part = load_parts()["parts"]["형상"].get(row["shape"]) if row else None
return list(part.get("필수 칸", [])) if part else []
def card_title(type_id: str, options: dict[str, Any] | None) -> str | None:
"""카드 · 측점 이름 — 카드이름 pipe = 「관종 D관경」(빈칸 = 그 종류 정의 기본값) · 그 밖 = 이름.
표에 없는 종류면 None(측점 안 붙임). TS `cardTitle` 짝(옛 빈칸 D800 ↔ 화면 D1000 어긋남 없앰).
"""
from B05_Profile.B05_Profile_Structures_Schema import structure_type_map
row = catalog_row(type_id)
if row is None:
return None
if row["title"] != "pipe":
return row["name"]
definition = structure_type_map().get(type_id)
defaults = {o.key: o.default for o in definition.options} if definition else {}
values = options or {}
def value(key: str) -> Any:
own = values.get(key)
return defaults.get(key) if own is None or own == "" else own
try:
diameter = math.trunc(float(value("pipe_diameter_mm")))
except (TypeError, ValueError):
diameter = 0
return f"{value('pipe_kind') or ''} D{diameter}"