From e2ef6362092b7ebb0be368e8724e25e8bbc502b0 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Fri, 9 Feb 2024 11:55:00 +0500 Subject: [PATCH] add fallback to the previous schema versions for docs and mappings before it was breaking part of BlenderBIM UI if we would open IFC4X1 file --- src/ifcopenshell-python/ifcopenshell/util/doc.py | 3 +++ src/ifcopenshell-python/ifcopenshell/util/schema.py | 10 ++++++++++ src/ifcopenshell-python/ifcopenshell/util/type.py | 7 +++++-- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/util/doc.py b/src/ifcopenshell-python/ifcopenshell/util/doc.py index c852120909..6ee10ada7f 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/doc.py +++ b/src/ifcopenshell-python/ifcopenshell/util/doc.py @@ -98,11 +98,14 @@ def get_db(version): with open(schema_path, "r") as fi: db[ifc_version][data_type] = json.load(fi) + + version = ifcopenshell.util.schema.get_fallback_schema(version) return db.get(version) def get_schema_by_name(version): global schema_by_name + version = ifcopenshell.util.schema.get_fallback_schema(version) if not schema_by_name[version]: schema_by_name[version] = ifcopenshell.ifcopenshell_wrapper.schema_by_name(version) return schema_by_name[version] diff --git a/src/ifcopenshell-python/ifcopenshell/util/schema.py b/src/ifcopenshell-python/ifcopenshell/util/schema.py index a4abda19c2..2c6f7888d0 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/schema.py +++ b/src/ifcopenshell-python/ifcopenshell/util/schema.py @@ -28,6 +28,16 @@ import ifcopenshell.util.attribute cwd = os.path.dirname(os.path.realpath(__file__)) +def get_fallback_schema(version): + """fallback to the schema version we do have docs and mapping for, + needed to support IFC versions like 4X3_RC1, 4X1 etc""" + if version.startswith("IFC4X3"): + version = "IFC4X3" + elif version.startswith("IFC4"): + version = "IFC4" + return version + + def is_a(entity, ifc_class): ifc_class = ifc_class.upper() if entity.name_uc() == ifc_class: diff --git a/src/ifcopenshell-python/ifcopenshell/util/type.py b/src/ifcopenshell-python/ifcopenshell/util/type.py index 39e87bcb64..d5927a016f 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/type.py +++ b/src/ifcopenshell-python/ifcopenshell/util/type.py @@ -18,6 +18,7 @@ import os import json +import ifcopenshell.util.schema cwd = os.path.dirname(os.path.realpath(__file__)) @@ -51,8 +52,10 @@ for schema in mapped_schemas: def get_applicable_types(ifc_class, schema="IFC4"): - return entity_to_type_map[schema.upper()].get(ifc_class, []) + schema = ifcopenshell.util.schema.get_fallback_schema(schema.upper()) + return entity_to_type_map[schema].get(ifc_class, []) def get_applicable_entities(ifc_type_class, schema="IFC4"): - return type_to_entity_map[schema.upper()].get(ifc_type_class, []) + schema = ifcopenshell.util.schema.get_fallback_schema(schema.upper()) + return type_to_entity_map[schema].get(ifc_type_class, [])