From cad7db0162dd8b995d8d8ce1fc2176ed8da3ad77 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Sat, 15 Jun 2024 14:05:37 +1000 Subject: [PATCH] See #4838. Consistently use schema_identifiers throughout the code instead of schema to be more explicit. This also means in the future we are better shaped to be a prototyping platform for future IFC versions. --- src/blenderbim/blenderbim/bim/ifc.py | 4 ++-- .../blenderbim/bim/module/project/data.py | 2 +- .../blenderbim/bim/module/project/operator.py | 2 +- src/blenderbim/blenderbim/bim/schema.py | 15 +++++++-------- src/ifcopenshell-python/ifcopenshell/util/pset.py | 10 +++++----- 5 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/ifc.py b/src/blenderbim/blenderbim/bim/ifc.py index e67069d334..87612d6dcc 100644 --- a/src/blenderbim/blenderbim/bim/ifc.py +++ b/src/blenderbim/blenderbim/bim/ifc.py @@ -74,7 +74,7 @@ class IfcStore: last_transaction = "" history: list[TransactionStep] = [] future: list[TransactionStep] = [] - schema_identifiers = ["IFC4", "IFC2X3", "IFC4X3"] + schema_identifiers = ["IFC4", "IFC2X3", "IFC4X3_ADD2"] session_files: dict[str, ifcopenshell.file] = {} @staticmethod @@ -94,7 +94,7 @@ class IfcStore: IfcStore.last_transaction = "" IfcStore.history = [] IfcStore.future = [] - IfcStore.schema_identifiers = ["IFC4", "IFC2X3", "IFC4X3"] + IfcStore.schema_identifiers = ["IFC4", "IFC2X3", "IFC4X3_ADD2"] IfcStore.session_files = {} @staticmethod diff --git a/src/blenderbim/blenderbim/bim/module/project/data.py b/src/blenderbim/blenderbim/bim/module/project/data.py index 73a620a7c0..8949e7f407 100644 --- a/src/blenderbim/blenderbim/bim/module/project/data.py +++ b/src/blenderbim/blenderbim/bim/module/project/data.py @@ -43,7 +43,7 @@ class ProjectData: @classmethod def get_export_schema(cls): - return [(s, s, "") for s in IfcStore.schema_identifiers] + return [(s, "IFC4X3" if s == "IFC4X3_ADD2" else s, "") for s in IfcStore.schema_identifiers] @classmethod def library_file(cls): diff --git a/src/blenderbim/blenderbim/bim/module/project/operator.py b/src/blenderbim/blenderbim/bim/module/project/operator.py index bbfc46b036..99eeb1c81c 100644 --- a/src/blenderbim/blenderbim/bim/module/project/operator.py +++ b/src/blenderbim/blenderbim/bim/module/project/operator.py @@ -116,7 +116,6 @@ class CreateProject(bpy.types.Operator): def _execute(self, context): props = context.scene.BIMProjectProperties template = None if props.template_file == "0" else props.template_file - blenderbim.bim.schema.reload(props.export_schema) if tool.Blender.is_default_scene(): for obj in bpy.data.objects: bpy.data.objects.remove(obj) @@ -125,6 +124,7 @@ class CreateProject(bpy.types.Operator): for mat in bpy.data.materials: bpy.data.materials.remove(mat) core.create_project(tool.Ifc, tool.Project, tool.Spatial, schema=props.export_schema, template=template) + blenderbim.bim.schema.reload(tool.Ifc.get().schema_identifier) tool.Blender.register_toolbar() def rollback(self, data): diff --git a/src/blenderbim/blenderbim/bim/schema.py b/src/blenderbim/blenderbim/bim/schema.py index 5206038439..e2cc5a3d1e 100644 --- a/src/blenderbim/blenderbim/bim/schema.py +++ b/src/blenderbim/blenderbim/bim/schema.py @@ -27,11 +27,10 @@ cwd = os.path.dirname(os.path.realpath(__file__)) class IfcSchema: - def __init__(self, schema_name="IFC4"): - schema_name = schema_name.upper() - if schema_name not in ("IFC2X3", "IFC4", "IFC4X3"): - schema_name = "IFC4" - self.schema_name = schema_name + def __init__(self, schema_identifier="IFC4"): + if schema_identifier not in ("IFC2X3", "IFC4", "IFC4X3_ADD2"): + schema_identifier = "IFC4" + self.schema_identifier = schema_identifier self.schema_dir = Path(cwd).joinpath("schema") self.data_dir = Path(cwd).joinpath("data") @@ -55,7 +54,7 @@ class IfcSchema: def load_pset_templates(self): property_paths = self.data_dir.joinpath("pset").glob("*.ifc") - self.psetqto = ifcopenshell.util.pset.get_template(self.schema_name) + self.psetqto = ifcopenshell.util.pset.get_template(self.schema_identifier) # Keep only the first template, which is the official buildingSMART one self.psetqto.templates = self.psetqto.templates[0:1] self.psetqto.get_applicable.cache_clear() @@ -96,6 +95,6 @@ class IfcSchema: ifc = IfcSchema() -def reload(schema_name): +def reload(schema_identifier): global ifc - ifc = IfcSchema(schema_name) + ifc = IfcSchema(schema_identifier) diff --git a/src/ifcopenshell-python/ifcopenshell/util/pset.py b/src/ifcopenshell-python/ifcopenshell/util/pset.py index 13a6d0c5f8..d002a16b03 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/pset.py +++ b/src/ifcopenshell-python/ifcopenshell/util/pset.py @@ -40,19 +40,19 @@ class PsetQto: templates_path = { "IFC2X3": "Pset_IFC2X3.ifc", "IFC4": "Pset_IFC4_ADD2.ifc", - "IFC4X3": "Pset_IFC4X3.ifc" + "IFC4X3_ADD2": "Pset_IFC4X3.ifc" } # fmt: on - def __init__(self, schema: str, templates=None) -> None: - self.schema = ifcopenshell.ifcopenshell_wrapper.schema_by_name(schema) + def __init__(self, schema_identifier: str, templates=None) -> None: + self.schema = ifcopenshell.ifcopenshell_wrapper.schema_by_name(schema_identifier) if not templates: folder_path = pathlib.Path(__file__).parent.absolute() - path = str(folder_path.joinpath("schema", self.templates_path[schema])) + path = str(folder_path.joinpath("schema", self.templates_path[schema_identifier])) templates = [ifcopenshell.open(path)] # See bug 3583. We backport this change from IFC4X3 because it just makes sense. # Users aren't forced to use it. - if schema == "IFC4": + if schema_identifier == "IFC4": for element in templates[0].by_type("IfcPropertySetTemplate"): if element.TemplateType == "QTO_OCCURRENCEDRIVEN": element.TemplateType = "QTO_TYPEDRIVENOVERRIDE"