Files
Aislo/B07_DesignDetail/B07_DesignDetail_Router_Support_Io.py
T
eomsangdonandClaude Opus 5.5 df0e64ffe2 feat(B07): 종단도 장마다 우측 상단 평면 위치도 · 종단 ⚙ 「평면도」 척도 칸 (521-2 · 요구 340-2)
- 새 Engine_Cad_LongPlan — 작도 영역 우상단 5 mm 안쪽 150×100 mm 칸 · 자동 = 전체 노선 맞춤(분모 500 올림) · 척도 정함 = 이 장 중심 확대 · 밖 노선 흐린 파선 · 칸 밖 잘림 · 이 장 굵게 · 시 · 종점 측점 · 방위표 · 「평면도 S=1/n」 · 「n/N 장」 · 좌표 없으면 안 그림
- 장 나눔 — 그래프가 칸을 덮으면 측점 줄여 장 더 나눔 · 장 목록에 number · total
- 축척 — longitudinal.plan 기본 자동 · 범위 1/500~1/50,000 · ⚙ 칸 = 서버 기본값 열쇠 그대로(셋째 칸 + 자동)
- 칸 앞 확정 종단 저장본 — 목록 받을 때 종단만 한 번 모두 풂(DRAWING_FORMAT 그대로)
- 시험 — 칸 자리 · 안 겹침 · 장마다 강조 · 척도 확대 · 좌표 없음 · 한 번 풂 · plan 범위 · ⚙ 평면 칸

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-25 08:01:02 +09:00

111 lines
4.5 KiB
Python

"""B07 도면 조립 지원 — 원본 JSON·매니페스트 읽기/쓰기와 측점 대응표.
지원 모듈이 700줄을 넘어 떼어냈다(2026-09-04). 유역도 조각과 본체가 함께 쓴다.
"""
import json
import logging
import re
from pathlib import Path
from typing import Any
from B05_Profile.B05_Profile_Engine_Sections import cross_files_in_order, cross_station
logger = logging.getLogger(__name__)
_STAGE_DIR = "B07_DesignDetail"
_CROSS_ID = re.compile(r"^cross_(\d+)m$")
_LONG_ID = re.compile(r"^longitudinal(?:_(\d+))?$")
# 노선 전장에 한 장씩만 나오는 도면 — 라우터가 원본 자료를 따로 실어 넘긴다.
MASS_HAUL_ID = "mass_haul"
COVER_ID = "cover"
# ⚠ 빈-도각 목록이 여기 있었다 — 계획평면도·표준 횡단면도·용지도·표준도 일곱 줄.
# 2026-09-09 지웠다: 일곱 **전부 실제 도면이 되어** 아무도 이 목록을 import 하지 않았다
# (표준도가 마지막이었다). 남겨 두면 「계획평면도가 빈 도각으로 열리나?」로 읽히는 덫이다.
def _read_json(path: Path) -> dict[str, Any]:
payload = json.loads(path.read_text(encoding="utf-8"))
if not isinstance(payload, dict):
raise ValueError("도면 원본 JSON 형식이 올바르지 않습니다.")
return payload
def _cross_files(longitudinal_path: Path, longitudinal: dict[str, Any]) -> list[Path]:
cross_dir = longitudinal_path.parent.parent / "cross_sections"
if not cross_dir.is_dir():
raise FileNotFoundError("B06 횡단면 파일을 찾을 수 없습니다.")
stations = longitudinal.get("stations")
# 읽기는 지우지 않음 — 잔재는 걸러 읽기만(지우기는 측점을 쓰는 쪽 몫 · R26) · 측점 차례(472-2)
return cross_files_in_order(cross_dir, stations if isinstance(stations, list) else [])
def _station_map(longitudinal: dict[str, Any]) -> dict[int | float, dict[str, Any]]:
stations = longitudinal.get("stations", [])
if not isinstance(stations, list):
return {}
return {
cross_station(station.get("chainage_m", 0)): station
for station in stations
if isinstance(station, dict)
}
def _design_root(project_root: Path) -> Path:
return project_root / _STAGE_DIR
def _read_manifest(project_root: Path) -> dict[str, Any]:
path = _design_root(project_root) / "manifest.json"
if not path.is_file():
return {"drawings": {}}
payload = _read_json(path)
return payload if isinstance(payload.get("drawings"), dict) else {"drawings": {}}
def _write_manifest(project_root: Path, manifest: dict[str, Any]) -> None:
"""쓰기 한 곳 — 풀린 장(`confirmed` 거짓)의 저장본 json · 수량표 찌꺼기를 함께 걷음."""
stage_root = _design_root(project_root)
stage_root.mkdir(parents=True, exist_ok=True)
for drawing_id, entry in manifest["drawings"].items():
if entry.get("confirmed") or "file" not in entry:
continue
(stage_root / "drawings" / f"{drawing_id}.json").unlink(missing_ok=True)
for key in ("file", "quantity_table", "quantity_tables"):
entry.pop(key, None)
path = stage_root / "manifest.json"
temporary = path.with_suffix(".tmp")
temporary.write_text(json.dumps(manifest, ensure_ascii=False, indent=2), encoding="utf-8")
temporary.replace(path)
def release_old_long_sheets(project_root: Path) -> None:
"""평면 위치도(521-2) 앞 확정 종단 저장본 — 종단만 모두 한 번 풂(칸 · 장 나눔이 바뀜).
풀린 장의 저장본은 `_write_manifest` 가 걷으니 다음부터는 새 저장본(칸 층 있음)만 남음.
"""
# 엔진 → 양식 → 이 모듈 차례라 위에서 부르면 돌고 돎
from B07_DesignDetail.B07_DesignDetail_Engine_Cad_LongPlan import LONG_PLAN_LAYER_ID
manifest = _read_manifest(project_root)
confirmed = [
(drawing_id, entry)
for drawing_id, entry in manifest["drawings"].items()
if _LONG_ID.fullmatch(drawing_id) and entry.get("confirmed")
]
if not confirmed:
return
# ponytail: 첫 장만 봄 — 옛 장은 한꺼번에 풀리므로 새 장과 섞이지 않음
saved = _design_root(project_root) / "drawings" / f"{confirmed[0][0]}.json"
try:
if f'"{LONG_PLAN_LAYER_ID}"' in saved.read_text(encoding="utf-8"):
return
except OSError:
pass
for _drawing_id, entry in confirmed:
entry["confirmed"] = False
_write_manifest(project_root, manifest)