Skip to content
This repository was archived by the owner on Nov 24, 2024. It is now read-only.

Commit c69ead4

Browse files
committed
Test to cover drawing maintaining sheet position IfcOpenShell#3155
Updated to gitignore to include some new folders that are created during tests
1 parent e68fdb2 commit c69ead4

2 files changed

Lines changed: 56 additions & 0 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ src/blenderbim/blenderbim/libs
8686

8787
# blenderbim test temp files
8888
src/blenderbim/test/files/temp
89+
src/blenderbim/drawings
90+
src/blenderbim/layouts
8991

9092
# ifcopenshell swig and compiled files
9193
src/ifcopenshell-python/ifcopenshell/_ifcopenshell_wrapper.so

src/blenderbim/test/tool/test_drawing.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
1818

1919
import os
20+
from pathlib import Path
2021
import bpy
2122
import mathutils
2223
import ifcopenshell
@@ -27,6 +28,8 @@
2728
from blenderbim.bim.ifc import IfcStore
2829
from blenderbim.bim.module.drawing.data import DecoratorData
2930

31+
import xml.etree.ElementTree as ET
32+
3033

3134
class TestImplementsTool(NewFile):
3235
def test_run(self):
@@ -601,6 +604,57 @@ def test_run(self):
601604
assert bpy.context.scene.DocProperties.should_draw_decorations is True
602605

603606

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+
604658
class TestUpdateTextValue(NewFile):
605659
def test_updating_arbitrary_strings(self):
606660
TestGetTextLiteral().test_run()

0 commit comments

Comments
 (0)