- 그림칸 = 양식 drawing_area 그대로(여백 2 % 없앰) · 도각 편집이 영역 싣고 [완료] 때 저장 - 도면 응답 guide(작도 영역 도면 좌표) · M02 구조물 도각 응답 area - CAD 그리기 겹판 점선 사각형(저장 · DXF · 인쇄 제외) · 모서리 · 변 끌기(도각 편집 · M02 양식만) - 숫자 칸 공용 부품(왼쪽 · 위 · 폭 · 높이 mm) — M02 양식 · B07 도각 편집 · 끌기와 한 벌 - B08 구조물도 · M02 도면 카드 = 얹은 도각 영역 가이드(보기만) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TNMXVCZXMpHpVvqmFkeChL
107 lines
4.0 KiB
Python
107 lines
4.0 KiB
Python
"""M02 도면 양식 — 작도 영역 칸 · B07 도각 층(프로젝트 작업본 → 시스템) (PLAN 10-3)."""
|
|
|
|
import json
|
|
|
|
from B07_DesignDetail import B07_DesignDetail_Engine_Template as engine
|
|
from M02_MasterTemplete import M02_Template_Layers as layers
|
|
|
|
A1 = engine.A1_TEMPLATE
|
|
|
|
|
|
def _project_template(project_root, document):
|
|
path = engine.project_template_path(project_root)
|
|
path.parent.mkdir(parents=True)
|
|
path.write_text(json.dumps(document), encoding="utf-8")
|
|
return path
|
|
|
|
|
|
def _entities(project_root):
|
|
engine.use_project_templates(project_root)
|
|
try:
|
|
return engine.template_entities()
|
|
finally:
|
|
engine.use_project_templates(None)
|
|
|
|
|
|
def test_system_a1_reads_drawing_area():
|
|
engine.use_project_templates(None)
|
|
assert engine.drawing_area() == (42.0, 47.0, 812.0, 567.0)
|
|
assert len(engine.template_entities()) == 51
|
|
|
|
|
|
def test_missing_area_falls_back_to_a1(tmp_path):
|
|
_project_template(tmp_path, {"format": 6, "entities": [], "layers": []})
|
|
engine.use_project_templates(tmp_path)
|
|
try:
|
|
assert engine.drawing_area() == engine._A1_INNER
|
|
finally:
|
|
engine.use_project_templates(None)
|
|
|
|
|
|
def test_template_area_moves_content(tmp_path):
|
|
line = {
|
|
"id": "a",
|
|
"type": "Line",
|
|
"shapeData": {"startPoint": {"x": 0, "y": 0}, "endPoint": {"x": 10, "y": 0}},
|
|
}
|
|
_project_template(
|
|
tmp_path,
|
|
{"format": 6, "drawing_area": [0, 0, 400, 200], "entities": [line], "layers": []},
|
|
)
|
|
engine.use_project_templates(tmp_path)
|
|
try:
|
|
assert engine.drawing_area() == (0.0, 0.0, 400.0, 200.0)
|
|
assert engine.usable_area() == (400.0, 200.0) # 여백 없음(169-1)
|
|
# 콘텐츠 중심(500, 500) 이 작도 영역 중심(200, 100) 에 온다 — 이동량 (300, 400).
|
|
placed = engine.frame_entities("t", (490.0, 490.0, 510.0, 510.0), fit=False)
|
|
assert placed[0]["shapeData"]["startPoint"] == {"x": 300.0, "y": 400.0}
|
|
finally:
|
|
engine.use_project_templates(None)
|
|
|
|
|
|
def test_bad_area_falls_back(tmp_path):
|
|
_project_template(tmp_path, {"drawing_area": [10, 10, 5, 5], "entities": []})
|
|
engine.use_project_templates(tmp_path)
|
|
try:
|
|
assert engine.drawing_area() == engine._A1_INNER
|
|
finally:
|
|
engine.use_project_templates(None)
|
|
|
|
|
|
def test_old_project_reads_system(tmp_path):
|
|
# 작업본이 없는 옛 프로젝트 — 시스템 양식으로 떨어진다.
|
|
assert len(_entities(tmp_path)) == 51
|
|
assert engine.is_project_template_customized(tmp_path) is False
|
|
|
|
|
|
def test_save_reset_on_seeded_project(tmp_path):
|
|
layers.seed_project(tmp_path)
|
|
assert engine.project_template_path(tmp_path).is_file()
|
|
assert engine.is_project_template_customized(tmp_path) is False
|
|
|
|
# [완료] — 작업본에만 쓴다 · 작도 영역은 이어 받는다 · `_initial/` · 시스템은 그대로.
|
|
path = engine.save_project_template(tmp_path, [])
|
|
saved = json.loads(path.read_text(encoding="utf-8"))
|
|
assert saved["drawing_area"] == [42, 47, 812, 567]
|
|
assert _entities(tmp_path) == []
|
|
assert engine.is_project_template_customized(tmp_path) is True
|
|
initial = layers.template_path(layers.initial_dir(tmp_path), "drawing", A1)
|
|
assert len(json.loads(initial.read_text(encoding="utf-8"))["entities"]) == 51
|
|
assert (
|
|
len(json.loads(engine.system_template_path().read_text(encoding="utf-8"))["entities"]) == 51
|
|
)
|
|
|
|
# [기본 도각으로] — `_initial/` 을 작업본에 덮어쓴다.
|
|
assert engine.reset_project_template(tmp_path) is True
|
|
assert len(_entities(tmp_path)) == 51
|
|
assert engine.is_project_template_customized(tmp_path) is False
|
|
|
|
|
|
def test_reset_on_old_project_drops_to_system(tmp_path):
|
|
engine.save_project_template(tmp_path, [])
|
|
assert _entities(tmp_path) == []
|
|
assert engine.reset_project_template(tmp_path) is True
|
|
assert not engine.project_template_path(tmp_path).exists()
|
|
assert len(_entities(tmp_path)) == 51
|
|
assert engine.reset_project_template(tmp_path) is False
|