Files
Aislo/common_util/common_util_structure_station.py
T
eomsangdonandClaude Opus 5.5 81f7d98e6f feat(구조물표): 323-7 새 종류 · 정리 — M02 종류 더하기(본보기 복사 · 일곱 갈래 본보기 그대로) · 손코딩 동작 · 명세 = 본보기 키 · 특수 동작 = 동작 이름 · 정본 목록 = 표 · drawing_views 걷음 · 옛 이름 되짚기 걷음(자리로 가름) · 허용 거리 파이썬 한 곳 · 벽 툴팁 = 종류 이름
- M02 종류별 탭 [종류 더하기] = 본보기(구조물 정본 원본) 복사 — 키 자동 · 이름 「본보기 2」 · 옵션 · 표시 · 그룹 · 배치 · 규칙 · 종류 덧칸 · 반영 그대로 · 종류.{새}.본보기 · 관 지점 종류 · 복사본은 본보기 밖
- 구조물 표 = 본보기 처음값 이어받음(resolveCatalog · resolve_catalog 짝 · 줄 칸 base) · baseType/base_type · specFor(명세) · 덧단 · 길이 전후 풀기 · 옹벽 추가 단 콘크리트
- 검사(화면 = 서버 짝) — 본보기 = 원본 · 같은 군 · 자리꼴 · 정본 · 만든 뒤 고정 · 복사본은 본보기가 숨긴 칸 이어받음 · 서버 덧칸 본보기 받음
- 특수 동작 = 동작 이름 — 바로 안 놓기 · 포장 나누기 = 포장_물넘이_겹침 · 월류 높이 기다림 = 월류단면
- 정본 목록 = 표 — 파이썬 관 지점 종류 = catalog owner · B05 시설 서브폼 = 표 형상 · 안 쓰는 손 목록 걷음
- drawing_views — 스키마에서 빼고 읽을 때 버림 · M02 [저장] 때 빠짐(코드는 마스터 안 고침)
- 이관 = 지난 판 이름 대신 측점 계획 자리(planted)로 가름 · all_type_names 걷음
- 허용 거리 = common_util_structure_station.py 한 곳(SAME_STATION_M · EDGE_TOLERANCE_M · PIPE_MATCH_M) · TS 표는 station.ts 머리
- 시험: test_323_7_new_type(템플릿 · 일곱 갈래 · 그림 · 검사 짝 · 서버 읽기) · 322-0 유령 시험 = 자리 · 옛 도움 파일 동작 · 표 길 · 기대 글 고침

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

180 lines
7.8 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) ──
# ── 같은 자리 거리 한 곳(323-7 · 파이썬은 여기서 가져다 씀 · TS 짝은 이름이 같은 상수) ──
#: 같은 측점으로 볼 거리(m) — 측점 계획 · 반올림 차이만 · TS `SAME_STATION_M` 짝
SAME_STATION_M = 0.005
#: 구간 끝 · 관 세트가 걸치는 측점을 같은 자리로 볼 폭(m) — 정본이 누가거리를 0.01 m 로 끊어 씀 ·
#: TS `EDGE_TOLERANCE_M`(벽 · 포장 · 맹암거) · `CHAINAGE_TOLERANCE_M`(관 세트) 짝
EDGE_TOLERANCE_M = 0.02
#: 관 · 구조물 자리와 측점 · 고름을 같은 자리로 볼 폭(m) — 정수 m 기준 측점 · 옛 소수 자료 · TS
#: `design_selection.PIPE_MATCH_M` 짝
PIPE_MATCH_M = 0.51
def _empty(value: object) -> bool:
return value is None or value == ""
def blank_keys(type_id: str, options: dict | None) -> list[str]:
"""형상 부품 필수 칸 중 값이 빈 키(정의 기본값으로 안 채움 · TS `blankKeys` 짝)."""
from common_util.common_util_structure_catalog import shape_needs
return [key for key in shape_needs(type_id) if _empty((options or {}).get(key))]
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
blank = blank_keys
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]