You can now add plan views based on a building storey. See #890.

This commit is contained in:
Dion Moult
2022-02-03 17:28:09 +11:00
parent 098ab2c237
commit 3e99393895
6 changed files with 45 additions and 2 deletions
@@ -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
@@ -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):
@@ -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")
@@ -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")
@@ -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
+14
View File
@@ -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):