Files
Aislo/common_util/common_util_structure_station.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

168 lines
7.1 KiB
Python

"""구조물 · 관 기준 측점 = 정수 m(반올림 · .5 는 올림) · 노선 끝 안쪽(요구 167 · 272).
측점 값(측점 + 거리 · 누가거리)에 소수를 안 씀 — 일반 측점(격자)과 같은 m 면 서버 측점
만들기가 한 측점으로 합침(구조물 측점이 위 · `B05_Profile_Engine_Sections_Core`).
234-1 의 「일반 측점 1 m 안 붙기」는 뺌(그냥 정수 · 사용자 167).
TS 짝 = `common_util/common_util_structure_station.ts`
(화면 입력 · 끌기 · 방향키 · 옛 자료 정수 옮김 ·
측점 계획 `plan_stations` ↔ `planStations` · 322-3).
거울 시험 = `resources/tester/test_234_1_structure_station.py`.
일반 측점 = 격자(간격) · 시종점 — 끝(노선 길이)을 넘지 않게 자르는 데만 씀.
"""
from __future__ import annotations
import math
from collections.abc import Sequence
from dataclasses import replace
from typing import TypeVar
from common_util.common_util_route_geometry import RouteVertex, interpolate_vertex
from config.config_system_design import SECTION_STATION_INTERVAL_M
_Candidate = TypeVar("_Candidate")
_EPS = 1e-6
def general_stations(total_m: float, interval_m: float) -> list[float]:
"""격자 측점 + 끝 측점(`Sections_Core._chainages` 와 같은 줄)."""
if not (total_m > 0 and interval_m > 0):
return [0.0]
values = [index * interval_m for index in range(int(total_m // interval_m) + 1)]
if total_m - values[-1] > _EPS:
values.append(float(total_m))
return values
def snap_structure_station(chainage_m: float, stations: Sequence[float]) -> float:
"""기준 측점 = 정수 m(.5 는 올림) · 0 ~ 노선 끝(소수 끝은 그 아래 정수) 안 · 멱등."""
value = float(chainage_m)
if not math.isfinite(value):
return value
end = max(stations) if stations else math.inf
whole = float(math.floor(value + 0.5))
return max(0.0, min(whole, float(math.floor(end + _EPS))))
def route_general_stations(total_m: float) -> list[float]:
"""노선 길이의 일반 측점 — 서버 측점 간격(`SECTION_STATION_INTERVAL_M`)."""
return general_stations(total_m, SECTION_STATION_INTERVAL_M)
def snap_candidates(
candidates: Sequence[_Candidate], vertices: Sequence[RouteVertex]
) -> list[_Candidate]:
"""자동 배치 관 자리 맞춤 — 좌표는 맞춘 자리로 다시 찍고, 같은 자리로 모이면 앞선 것만.
`candidates` 는 `chainage_m · x · y` 를 가진 dataclass(`StructureCandidate`)."""
total_m = float(vertices[-1].chainage_m)
stations = route_general_stations(total_m)
snapped: list[_Candidate] = []
taken: set[float] = set()
for candidate in candidates:
at = snap_structure_station(candidate.chainage_m, stations)
if at in taken:
continue
taken.add(at)
x, y, _ = interpolate_vertex(list(vertices), at)
snapped.append(replace(candidate, chainage_m=at, x=x, y=y))
return snapped
# ── 측점 계획 한 벌(322-3 · TS `planStations` 짝 · 거울 = test_322_3_plan_mirror.py) ──
#: 같은 측점으로 볼 거리(m) — TS `SAME_STATION_M` 짝
SAME_STATION_M = 0.005
def _empty(value: object) -> bool:
return value is None or value == ""
def _station_marks(
start: object, anchor: object, end: object, span3: bool
) -> list[tuple[str, float]]:
"""TS `marksOf` 짝 — 수인 자리만 (역할, 누가거리)."""
marks = [("start", start), ("anchor", anchor), ("end", end)] if span3 else [("anchor", anchor)]
return [
(role, float(at))
for role, at in marks
if isinstance(at, (int, float)) and not isinstance(at, bool) and math.isfinite(at)
]
def plan_stations(pipes: Sequence[object], structures: Sequence[object]) -> list[dict[str, object]]:
"""관 · 구조물(현황) + 구조물 표 → 측점 계획 `[{chainage_m, role, title, owners, blank}]`.
오름차순 · 같은 m(0.005) 는 하나 — 이름 = 관이 있으면 첫 관 · 아니면 앞선 구조물(표 카드 이름)
· 덮는 구조물 id(관 = 자리 이름 `pipe-{누가거리}` · 구조물 = structure_id) · 빈칸 경고(형상
부품 필수 칸 중 값이 빈 옵션 키). 표에 없는 종류는 뺌.
"""
from common_util.common_util_structure_catalog import card_title, catalog_row, shape_needs
def blank(type_id: str, options: dict | None) -> list[str]:
"""형상 부품 필수 칸 중 값이 빈 키(정의 기본값으로 안 채움 · TS `blankKeys` 짝)."""
return [key for key in shape_needs(type_id) if _empty((options or {}).get(key))]
marks: list[dict[str, object]] = []
for pipe in pipes:
facility = getattr(pipe, "facility", None) or "pipe"
row = catalog_row(facility)
if row is None:
continue
options = getattr(pipe, "options", None)
chainage = float(getattr(pipe, "chainage_m"))
station = row["station"]
for role, at in (
[]
if station == "none"
else _station_marks(
getattr(pipe, "start_m", None),
chainage,
getattr(pipe, "end_m", None),
station == "span3",
)
):
marks.append(
{
"chainage_m": at,
"role": role,
"title": card_title(facility, options),
"owner": getattr(pipe, "id", None) or f"pipe-{chainage:.2f}",
"blank": blank(facility, options),
"pipe": True,
}
)
for item in structures:
row = catalog_row(item.type_id)
if row is None or row["owner"] == "pipe_points" or row["station"] == "none":
continue
anchor = item.chainage_m if item.chainage_m is not None else item.start_m
found = _station_marks(item.start_m, anchor, item.end_m, row["station"] == "span3")
base = next((at for role, at in found if role == "anchor"), 0.0)
for role, at in found:
marks.append(
{
"chainage_m": at,
"role": role,
"title": card_title(item.type_id, item.options),
"owner": item.structure_id or f"structure-{base:.2f}",
"blank": blank(item.type_id, item.options),
"pipe": False,
}
)
marks.sort(key=lambda mark: mark["chainage_m"])
out: list[dict[str, object]] = []
for mark in marks:
last = out[-1] if out else None
if last is not None and abs(mark["chainage_m"] - last["chainage_m"]) < SAME_STATION_M:
if mark["pipe"] and not last["pipe"]:
last["title"], last["pipe"] = mark["title"], True
if mark["owner"] not in last["owners"]:
last["owners"].append(mark["owner"])
last["blank"] += [key for key in mark["blank"] if key not in last["blank"]]
continue
out.append({**mark, "owners": [mark["owner"]], "blank": list(mark["blank"])})
return [{k: v for k, v in station.items() if k not in ("pipe", "owner")} for station in out]