|
17 | 17 | # along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>. |
18 | 18 |
|
19 | 19 | import os |
| 20 | +from pathlib import Path |
20 | 21 | import bpy |
21 | 22 | import mathutils |
22 | 23 | import ifcopenshell |
|
27 | 28 | from blenderbim.bim.ifc import IfcStore |
28 | 29 | from blenderbim.bim.module.drawing.data import DecoratorData |
29 | 30 |
|
| 31 | +import xml.etree.ElementTree as ET |
| 32 | + |
30 | 33 |
|
31 | 34 | class TestImplementsTool(NewFile): |
32 | 35 | def test_run(self): |
@@ -601,6 +604,57 @@ def test_run(self): |
601 | 604 | assert bpy.context.scene.DocProperties.should_draw_decorations is True |
602 | 605 |
|
603 | 606 |
|
| 607 | +class TestDrawingMaintainingSheetPosition(NewFile): |
| 608 | + def get_sheet_drawing_data(self, layout_path): |
| 609 | + SVG = "{http://www.w3.org/2000/svg}" |
| 610 | + ET.register_namespace("", SVG) |
| 611 | + layout_tree = ET.parse(layout_path) |
| 612 | + layout_root = layout_tree.getroot() |
| 613 | + |
| 614 | + drawing_view = layout_root.findall(f'{SVG}g[@data-type="drawing"]')[0] |
| 615 | + |
| 616 | + drawing_data = {} |
| 617 | + for image in drawing_view.findall(f"{SVG}image"): |
| 618 | + attribs = ["x", "y", "width", "height"] |
| 619 | + image_type = image.attrib["data-type"] |
| 620 | + drawing_data[image_type] = tuple([round(float(image.attrib[attr]), 2) for attr in attribs]) |
| 621 | + |
| 622 | + return drawing_data |
| 623 | + |
| 624 | + def test_run(self): |
| 625 | + bpy.ops.bim.create_project() |
| 626 | + ifc = tool.Ifc.get() |
| 627 | + sheet_path = Path.cwd() / "layouts" / "A00 - UNTITLED.svg" |
| 628 | + |
| 629 | + bpy.ops.bim.load_sheets() |
| 630 | + bpy.ops.bim.add_sheet() |
| 631 | + |
| 632 | + bpy.ops.bim.load_drawings() |
| 633 | + bpy.ops.bim.add_drawing() |
| 634 | + |
| 635 | + drawing = ifc.by_type("IfcAnnotation")[0] |
| 636 | + bpy.ops.bim.activate_drawing(drawing=drawing.id()) |
| 637 | + bpy.ops.bim.create_drawing() |
| 638 | + bpy.ops.bim.add_drawing_to_sheet() |
| 639 | + bpy.ops.bim.open_sheet() |
| 640 | + |
| 641 | + # check drawing default position |
| 642 | + drawing_data = self.get_sheet_drawing_data(sheet_path) |
| 643 | + assert drawing_data["foreground"] == (30.0, 30.0, 500.0, 500.0) |
| 644 | + assert drawing_data["view-title"] == (30.0, 535.0, 50.22, 10.0) |
| 645 | + |
| 646 | + bpy.context.scene.camera.data.BIMCameraProperties.raster_x = 1200 |
| 647 | + bpy.ops.bim.create_drawing() |
| 648 | + bpy.ops.bim.open_sheet() |
| 649 | + |
| 650 | + assert sheet_path.is_file(), f"Sheet path {sheet_path} doesn't exist" |
| 651 | + |
| 652 | + # check drawing position on the sheet |
| 653 | + drawing_data = self.get_sheet_drawing_data(sheet_path) |
| 654 | + assert drawing_data["foreground"] == (30.0, 71.67, 500.0, 416.67) |
| 655 | + assert drawing_data["view-title"] == (30.0, 493.33, 50.22, 10.0) |
| 656 | + |
| 657 | + |
604 | 658 | class TestUpdateTextValue(NewFile): |
605 | 659 | def test_updating_arbitrary_strings(self): |
606 | 660 | TestGetTextLiteral().test_run() |
|
0 commit comments