From eb96858460f6e942ecf50aeff69c99ccfd95c4d2 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Mon, 8 Jan 2024 16:52:59 +1100 Subject: [PATCH] Fix #4167. Bug where pset template module didn't allow creating qto template types. --- .../bim/module/pset_template/data.py | 18 ++++++++++++++++-- .../bim/module/pset_template/operator.py | 3 ++- .../bim/module/pset_template/prop.py | 13 +++++++++---- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/module/pset_template/data.py b/src/blenderbim/blenderbim/bim/module/pset_template/data.py index de44529cb5..a3f6d07162 100644 --- a/src/blenderbim/blenderbim/bim/module/pset_template/data.py +++ b/src/blenderbim/blenderbim/bim/module/pset_template/data.py @@ -20,6 +20,7 @@ import os import bpy import pathlib import ifcopenshell +import ifcopenshell.util.attribute import blenderbim.tool as tool from blenderbim.bim.ifc import IfcStore @@ -36,6 +37,7 @@ class PsetTemplatesData: def load(cls): cls.is_loaded = True cls.data["primary_measure_type"] = cls.primary_measure_type() + cls.data["property_template_type"] = cls.property_template_type() cls.data["pset_template_files"] = cls.pset_template_files() cls.data["pset_templates"] = cls.pset_templates() cls.data["pset_template"] = cls.pset_template() @@ -43,13 +45,25 @@ class PsetTemplatesData: @classmethod def primary_measure_type(cls): - schema = tool.Ifc.schema() - version = tool.Ifc.get_schema() + ifc_file = IfcStore.pset_template_file + if not ifc_file: + return [] + schema = ifcopenshell.ifcopenshell_wrapper.schema_by_name(ifc_file.schema) + version = ifc_file.schema return [ (t, t, ifcopenshell.util.doc.get_type_doc(version, t).get("description", "")) for t in sorted([d.name() for d in schema.declarations() if hasattr(d, "declared_type")]) ] + @classmethod + def property_template_type(cls): + ifc_file = IfcStore.pset_template_file + if not ifc_file: + return [] + schema = ifcopenshell.ifcopenshell_wrapper.schema_by_name(ifc_file.schema) + attribute = schema.declaration_by_name("IfcSimplePropertyTemplate").attributes()[0] + return [(i, i, "") for i in ifcopenshell.util.attribute.get_enum_items(attribute)] + @classmethod def pset_template_files(cls): results = [] diff --git a/src/blenderbim/blenderbim/bim/module/pset_template/operator.py b/src/blenderbim/blenderbim/bim/module/pset_template/operator.py index 4d4534de80..895b512b65 100644 --- a/src/blenderbim/blenderbim/bim/module/pset_template/operator.py +++ b/src/blenderbim/blenderbim/bim/module/pset_template/operator.py @@ -307,7 +307,8 @@ class EditPropTemplate(bpy.types.Operator, Operator): bpy.ops.bim.disable_editing_prop_template() IfcStore.pset_template_file.write(IfcStore.pset_template_path) blenderbim.bim.handler.refresh_ui_data() - blenderbim.bim.schema.reload(tool.Ifc.get().schema) + if tool.Ifc.get(): + blenderbim.bim.schema.reload(tool.Ifc.get().schema) # TODO -This will need to go into the # api code at some point - vulevukusej diff --git a/src/blenderbim/blenderbim/bim/module/pset_template/prop.py b/src/blenderbim/blenderbim/bim/module/pset_template/prop.py index 2dba9b0504..9d94b28c8e 100644 --- a/src/blenderbim/blenderbim/bim/module/pset_template/prop.py +++ b/src/blenderbim/blenderbim/bim/module/pset_template/prop.py @@ -42,6 +42,8 @@ def updatePsetTemplateFiles(self, context): PsetTemplatesData.data["pset_template_files"] = PsetTemplatesData.pset_template_files() PsetTemplatesData.data["pset_templates"] = PsetTemplatesData.pset_templates() PsetTemplatesData.data["prop_templates"] = PsetTemplatesData.prop_templates() + PsetTemplatesData.data["primary_measure_type"] = PsetTemplatesData.primary_measure_type() + PsetTemplatesData.data["property_template_type"] = PsetTemplatesData.property_template_type() def getPsetTemplateFiles(self, context): @@ -67,6 +69,12 @@ def get_primary_measure_type(self, context): return PsetTemplatesData.data["primary_measure_type"] +def get_property_template_type(self, context): + if not PsetTemplatesData.is_loaded: + PsetTemplatesData.load() + return PsetTemplatesData.data["property_template_type"] + + def get_template_type(self, context): return [ ( @@ -157,10 +165,7 @@ class PropTemplate(PropertyGroup): description=get_attribute_doc("IFC4", "IfcPropertyTemplate", "Description"), ) primary_measure_type: EnumProperty(items=get_primary_measure_type, name="Primary Measure Type") - template_type: EnumProperty( - items=[("P_SINGLEVALUE", "P_SINGLEVALUE", ""), ("P_ENUMERATEDVALUE", "P_ENUMERATEDVALUE", "")], - name="Template Type", - ) + template_type: EnumProperty(items=get_property_template_type, name="Template Type") enum_values: CollectionProperty(type=EnumerationValues) def get_value_name(self):