"""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.96, 200 * 0.96) # 콘텐츠 중심(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