From a53fd97e5a849df5eae2e5d26a121880bfd2a605 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Thu, 17 Mar 2022 09:49:55 +1100 Subject: [PATCH] Fix #2092. Fix bug where door and window styles were excluded from authoring options. --- src/blenderbim/blenderbim/bim/import_ifc.py | 20 +++++++------- .../blenderbim/bim/module/bimtester/prop.py | 7 ++--- .../blenderbim/bim/module/document/ui.py | 8 ++---- .../blenderbim/bim/module/model/data.py | 7 ++++- .../blenderbim/bim/module/model/mep.py | 1 - .../blenderbim/bim/module/root/data.py | 23 +++++++++++----- .../blenderbim/bim/module/root/prop.py | 26 +++++++------------ .../util/entity_to_type_map_4.json | 6 +++-- 8 files changed, 50 insertions(+), 48 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/import_ifc.py b/src/blenderbim/blenderbim/bim/import_ifc.py index 5db604d555..4f9149f974 100644 --- a/src/blenderbim/blenderbim/bim/import_ifc.py +++ b/src/blenderbim/blenderbim/bim/import_ifc.py @@ -285,11 +285,13 @@ class IfcImporter: if c.ContextIdentifier in ["Body", "Facetation"] ] # Ideally, all representations should be in a subcontext, but some BIM programs don't do this correctly - self.body_contexts.extend([ - c.id() - for c in self.file.by_type("IfcGeometricRepresentationContext", include_subtypes=False) - if c.ContextType == "Model" - ]) + self.body_contexts.extend( + [ + c.id() + for c in self.file.by_type("IfcGeometricRepresentationContext", include_subtypes=False) + if c.ContextType == "Model" + ] + ) if self.body_contexts: self.settings.set_context_ids(self.body_contexts) # Annotation is to accommodate broken Revit files @@ -365,7 +367,7 @@ class IfcImporter: def is_native_swept_disk_solid(self, representations): for representation in representations: - items = representation["raw"].Items or [] # Be forgiving of invalid IFCs because Revit :( + items = representation["raw"].Items or [] # Be forgiving of invalid IFCs because Revit :( if len(items) == 1 and items[0].is_a("IfcSweptDiskSolid"): return True return False @@ -1724,10 +1726,10 @@ class IfcImporter: ): verts = [None] * len(geometry.verts) for i in range(0, len(geometry.verts), 3): - verts[i], verts[i+1], verts[i+2] = ifcopenshell.util.geolocation.enh2xyz( + verts[i], verts[i + 1], verts[i + 2] = ifcopenshell.util.geolocation.enh2xyz( geometry.verts[i], - geometry.verts[i+1], - geometry.verts[i+2], + geometry.verts[i + 1], + geometry.verts[i + 2], float(props.blender_eastings) * self.unit_scale, float(props.blender_northings) * self.unit_scale, float(props.blender_orthogonal_height) * self.unit_scale, diff --git a/src/blenderbim/blenderbim/bim/module/bimtester/prop.py b/src/blenderbim/blenderbim/bim/module/bimtester/prop.py index e3b438423b..a2ce7dad0d 100644 --- a/src/blenderbim/blenderbim/bim/module/bimtester/prop.py +++ b/src/blenderbim/blenderbim/bim/module/bimtester/prop.py @@ -19,7 +19,7 @@ import os from pathlib import Path from blenderbim.bim.prop import StrProperty -from blenderbim.bim.module.root.prop import getIfcClasses +from blenderbim.bim.module.root.prop import get_ifc_classes from bpy.types import PropertyGroup from bpy.props import ( PointerProperty, @@ -33,14 +33,11 @@ from bpy.props import ( ) scenarios_enum = [] -classes_enum = [] def purge(): global scenarios_enum - global classes_enum scenarios_enum = [] - classes_enum = [] def getScenarios(self, context): @@ -68,7 +65,7 @@ class BimTesterProperties(PropertyGroup): feature: StringProperty(default="", name="Feature / IDS", update=refreshScenarios) steps: StringProperty(default="", name="Custom Steps") ifc_file: StringProperty(default="", name="IFC File") - audit_ifc_class: EnumProperty(items=getIfcClasses, name="Audit Class") + audit_ifc_class: EnumProperty(items=get_ifc_classes, name="Audit Class") qa_reject_element_reason: StringProperty(name="Element Rejection Reason") scenario: EnumProperty(items=getScenarios, name="Scenario") should_load_from_memory: BoolProperty(default=False, name="Load from Memory") diff --git a/src/blenderbim/blenderbim/bim/module/document/ui.py b/src/blenderbim/blenderbim/bim/module/document/ui.py index 74a8f7cf2b..ba1b4704b4 100644 --- a/src/blenderbim/blenderbim/bim/module/document/ui.py +++ b/src/blenderbim/blenderbim/bim/module/document/ui.py @@ -69,9 +69,7 @@ class BIM_PT_documents(Panel): row.operator("bim.enable_editing_document", text="", icon="GREASEPENCIL").document = ifc_definition_id row.operator("bim.remove_document", text="", icon="X").document = ifc_definition_id - self.layout.template_list( - "BIM_UL_documents", "", self.props, "documents", self.props, "active_document_index" - ) + self.layout.template_list("BIM_UL_documents", "", self.props, "documents", self.props, "active_document_index") if self.props.active_document_id: draw_attributes(self.props.document_attributes, self.layout) @@ -136,9 +134,7 @@ class BIM_PT_object_documents(Panel): row.operator("bim.assign_document", text="", icon="ADD").document = document.ifc_definition_id row.operator("bim.disable_document_editing_ui", text="", icon="CANCEL") - self.layout.template_list( - "BIM_UL_documents", "", self.props, "documents", self.props, "active_document_index" - ) + self.layout.template_list("BIM_UL_documents", "", self.props, "documents", self.props, "active_document_index") class BIM_UL_documents(UIList): diff --git a/src/blenderbim/blenderbim/bim/module/model/data.py b/src/blenderbim/blenderbim/bim/module/model/data.py index 704b4f5228..1ee9a3f7be 100644 --- a/src/blenderbim/blenderbim/bim/module/model/data.py +++ b/src/blenderbim/blenderbim/bim/module/model/data.py @@ -39,7 +39,12 @@ class AuthoringData: @classmethod def ifc_classes(cls): results = [] - classes = {e.is_a() for e in tool.Ifc.get().by_type("IfcElementType")} + classes = { + e.is_a() + for e in tool.Ifc.get().by_type("IfcElementType") + + tool.Ifc.get().by_type("IfcDoorStyle") + + tool.Ifc.get().by_type("IfcWindowStyle") + } results.extend([(c, c, "") for c in sorted(classes)]) return results diff --git a/src/blenderbim/blenderbim/bim/module/model/mep.py b/src/blenderbim/blenderbim/bim/module/model/mep.py index 14784936d4..e971318d78 100644 --- a/src/blenderbim/blenderbim/bim/module/model/mep.py +++ b/src/blenderbim/blenderbim/bim/module/model/mep.py @@ -34,7 +34,6 @@ from math import pi, degrees from mathutils import Vector, Matrix - class MepGenerator: def __init__(self, relating_type): self.relating_type = relating_type diff --git a/src/blenderbim/blenderbim/bim/module/root/data.py b/src/blenderbim/blenderbim/bim/module/root/data.py index a6d3270e33..9d2ee77ae4 100644 --- a/src/blenderbim/blenderbim/bim/module/root/data.py +++ b/src/blenderbim/blenderbim/bim/module/root/data.py @@ -32,13 +32,13 @@ class IfcClassData: @classmethod def load(cls): cls.is_loaded = True - cls.data = { - "ifc_products": cls.ifc_products(), - "contexts": cls.contexts(), - "has_entity": cls.has_entity(), - "name": cls.name(), - "ifc_class": cls.ifc_class(), - } + cls.data = {} + cls.data["ifc_products"] = cls.ifc_products() + cls.data["ifc_classes"] = cls.ifc_classes() + cls.data["contexts"] = cls.contexts() + cls.data["has_entity"] = cls.has_entity() + cls.data["name"] = cls.name() + cls.data["ifc_class"] = cls.ifc_class() @classmethod def ifc_products(cls): @@ -64,6 +64,15 @@ class IfcClassData: ] return [(e, e, "") for e in products] + @classmethod + def ifc_classes(cls): + ifc_product = bpy.context.scene.BIMRootProperties.ifc_product + declaration = tool.Ifc.schema().declaration_by_name(ifc_product) + declarations = ifcopenshell.util.schema.get_subtypes(declaration) + names = [d.name() for d in declarations] + if ifc_product == "IfcElementType": + names.extend(("IfcDoorStyle", "IfcWindowStyle")) + return [(c, c, "") for c in sorted(names)] @classmethod def contexts(cls): diff --git a/src/blenderbim/blenderbim/bim/module/root/prop.py b/src/blenderbim/blenderbim/bim/module/root/prop.py index 74bdc4679a..8b598a2338 100644 --- a/src/blenderbim/blenderbim/bim/module/root/prop.py +++ b/src/blenderbim/blenderbim/bim/module/root/prop.py @@ -33,14 +33,11 @@ from bpy.props import ( CollectionProperty, ) -classes_enum = [] types_enum = [] def purge(): - global classes_enum global types_enum - classes_enum = [] types_enum = [] @@ -58,10 +55,9 @@ def getIfcPredefinedTypes(self, context): return types_enum -def refreshClasses(self, context): - global classes_enum - classes_enum.clear() - enum = getIfcClasses(self, context) +def refresh_classes(self, context): + IfcClassData.load() + enum = get_ifc_classes(self, context) context.scene.BIMRootProperties.ifc_class = enum[0][0] @@ -79,14 +75,10 @@ def get_ifc_products(self, context): return IfcClassData.data["ifc_products"] -def getIfcClasses(self, context): - global classes_enum - file = IfcStore.get_file() - if len(classes_enum) < 1 and file: - declaration = IfcStore.get_schema().declaration_by_name(context.scene.BIMRootProperties.ifc_product) - declarations = ifcopenshell.util.schema.get_subtypes(declaration) - classes_enum.extend([(c, c, "") for c in sorted([d.name() for d in declarations])]) - return classes_enum +def get_ifc_classes(self, context): + if not IfcClassData.is_loaded: + IfcClassData.load() + return IfcClassData.data["ifc_classes"] def get_contexts(self, context): @@ -97,7 +89,7 @@ def get_contexts(self, context): class BIMRootProperties(PropertyGroup): contexts: EnumProperty(items=get_contexts, name="Contexts") - ifc_product: EnumProperty(items=get_ifc_products, name="Products", update=refreshClasses) - ifc_class: EnumProperty(items=getIfcClasses, name="Class", update=refreshPredefinedTypes) + ifc_product: EnumProperty(items=get_ifc_products, name="Products", update=refresh_classes) + ifc_class: EnumProperty(items=get_ifc_classes, name="Class", update=refreshPredefinedTypes) ifc_predefined_type: EnumProperty(items=getIfcPredefinedTypes, name="Predefined Type", default=None) ifc_userdefined_type: StringProperty(name="Userdefined Type") diff --git a/src/ifcopenshell-python/ifcopenshell/util/entity_to_type_map_4.json b/src/ifcopenshell-python/ifcopenshell/util/entity_to_type_map_4.json index 8756097053..b719ad79b4 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/entity_to_type_map_4.json +++ b/src/ifcopenshell-python/ifcopenshell/util/entity_to_type_map_4.json @@ -90,7 +90,8 @@ "IfcDistributionChamberElementType" ], "IfcDoor": [ - "IfcDoorType" + "IfcDoorType", + "IfcDoorStyle" ], "IfcDuctFitting": [ "IfcDuctFittingType" @@ -306,7 +307,8 @@ "IfcWasteTerminalType" ], "IfcWindow": [ - "IfcWindowType" + "IfcWindowType", + "IfcWindowStyle" ], "IfcBeamStandardCase": [ "IfcBeamType"