diff --git a/src/blenderbim/blenderbim/bim/module/drawing/data.py b/src/blenderbim/blenderbim/bim/module/drawing/data.py index 2408e9e12e..635346c291 100644 --- a/src/blenderbim/blenderbim/bim/module/drawing/data.py +++ b/src/blenderbim/blenderbim/bim/module/drawing/data.py @@ -78,9 +78,16 @@ class DrawingsData: @classmethod def load(cls): - cls.data = {"total_drawings": cls.total_drawings()} + cls.data = {"total_drawings": cls.total_drawings(), "location_hint": cls.location_hint()} cls.is_loaded = True @classmethod def total_drawings(cls): return len([e for e in tool.Ifc.get().by_type("IfcAnnotation") if e.ObjectType == "DRAWING"]) + + @classmethod + def location_hint(cls): + if bpy.context.scene.DocProperties.target_view == "PLAN_VIEW": + results = [("0", "Origin", "")] + results.extend([(str(s.id()), s.Name or "Unnamed", "") for s in tool.Ifc.get().by_type("IfcBuildingStorey")]) + return results diff --git a/src/blenderbim/blenderbim/bim/module/drawing/operator.py b/src/blenderbim/blenderbim/bim/module/drawing/operator.py index 4b2091cb82..9ed497d0cf 100644 --- a/src/blenderbim/blenderbim/bim/module/drawing/operator.py +++ b/src/blenderbim/blenderbim/bim/module/drawing/operator.py @@ -72,7 +72,13 @@ class AddDrawing(bpy.types.Operator, Operator): def _execute(self, context): self.props = context.scene.DocProperties - core.add_drawing(tool.Ifc, tool.Collector, tool.Drawing, target_view=self.props.target_view, location_hint=None) + core.add_drawing( + tool.Ifc, + tool.Collector, + tool.Drawing, + target_view=self.props.target_view, + location_hint=int(self.props.location_hint), + ) class CreateDrawing(bpy.types.Operator): diff --git a/src/blenderbim/blenderbim/bim/module/drawing/prop.py b/src/blenderbim/blenderbim/bim/module/drawing/prop.py index b23b771657..5ce6e7477f 100644 --- a/src/blenderbim/blenderbim/bim/module/drawing/prop.py +++ b/src/blenderbim/blenderbim/bim/module/drawing/prop.py @@ -24,6 +24,7 @@ import blenderbim.tool as tool import blenderbim.bim.module.drawing.annotation as annotation import blenderbim.bim.module.drawing.decoration as decoration import enum +from blenderbim.bim.module.drawing.data import DrawingsData from pathlib import Path from blenderbim.bim.prop import Attribute, StrProperty from bpy.types import PropertyGroup @@ -56,6 +57,12 @@ def purge(): vector_styles_enum = [] +def get_location_hint(self, context): + if not DrawingsData.is_loaded: + DrawingsData.load() + return DrawingsData.data["location_hint"] + + def update_diagram_scale(self, context): scale = self.diagram_scale if scale == "CUSTOM": @@ -285,6 +292,7 @@ class DocProperties(PropertyGroup): name="Target View", default="PLAN_VIEW", ) + location_hint: EnumProperty(items=get_location_hint, name="Location Hint") drawings: CollectionProperty(name="Drawings", type=Drawing) active_drawing_index: IntProperty(name="Active Drawing Index") current_drawing_index: IntProperty(name="Current Drawing Index") diff --git a/src/blenderbim/blenderbim/bim/module/drawing/ui.py b/src/blenderbim/blenderbim/bim/module/drawing/ui.py index 618f2c0358..48e442b6cb 100644 --- a/src/blenderbim/blenderbim/bim/module/drawing/ui.py +++ b/src/blenderbim/blenderbim/bim/module/drawing/ui.py @@ -169,6 +169,7 @@ class BIM_PT_drawings(Panel): row = self.layout.row(align=True) row.prop(self.props, "target_view", text="") + row.prop(self.props, "location_hint", text="") row.operator("bim.add_drawing", text="", icon="ADD") row.operator("bim.disable_editing_drawings", text="", icon="CANCEL") diff --git a/src/blenderbim/blenderbim/tool/drawing.py b/src/blenderbim/blenderbim/tool/drawing.py index e4f1d7c16a..ff6b1bf444 100644 --- a/src/blenderbim/blenderbim/tool/drawing.py +++ b/src/blenderbim/blenderbim/tool/drawing.py @@ -119,6 +119,13 @@ class Drawing(blenderbim.core.tool.Drawing): @classmethod def generate_drawing_matrix(cls, target_view, location_hint): + if target_view == "PLAN_VIEW": + if location_hint: + m = tool.Ifc.get_object(tool.Ifc.get().by_id(location_hint)).matrix_world.copy() + m[0][3] = bpy.context.scene.cursor.matrix[0][3] + m[1][3] = bpy.context.scene.cursor.matrix[1][3] + m[2][3] += 1.6 + return m return mathutils.Matrix() @classmethod diff --git a/src/blenderbim/test/tool/test_drawing.py b/src/blenderbim/test/tool/test_drawing.py index 95c54217a4..9f10e3596e 100644 --- a/src/blenderbim/test/tool/test_drawing.py +++ b/src/blenderbim/test/tool/test_drawing.py @@ -175,6 +175,20 @@ class TestGenerateDrawingMatrix(NewFile): def test_returning_the_origin_as_a_fallback(self): assert subject.generate_drawing_matrix("PLAN_VIEW", None) == mathutils.Matrix() + def test_using_the_matrix_from_the_cursor_and_a_preexisting_object(self): + ifc = ifcopenshell.file() + tool.Ifc.set(ifc) + obj = bpy.data.objects.new("Object", None) + element = ifc.createIfcBuildingStorey() + tool.Ifc.link(element, obj) + bpy.context.scene.collection.objects.link(obj) + obj.matrix_world[2][3] = 3 + bpy.context.scene.cursor.location = (1.0, 2.0, 0.0) + m = subject.generate_drawing_matrix("PLAN_VIEW", element.id()) + assert round(m[0][3], 3) == 1 + assert round(m[1][3], 3) == 2 + assert round(m[2][3], 3) == 4.6 + class TestGenerateSheetIdentification(NewFile): def test_run(self):