From 0e69f484f45ddae416ac3868e51fe64d92349e73 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Mon, 31 Jul 2023 11:44:32 +0500 Subject: [PATCH] More general solution for #3466 --- .../scripts/generate_util_type_json.py | 23 ++++++++- .../util/entity_to_type_map_4.json | 50 +++++++++++++++---- .../util/entity_to_type_map_4x3.json | 48 ++++++++++++++++++ 3 files changed, 109 insertions(+), 12 deletions(-) diff --git a/src/blenderbim/scripts/generate_util_type_json.py b/src/blenderbim/scripts/generate_util_type_json.py index b4cf7db9f9..adbcc46ba5 100644 --- a/src/blenderbim/scripts/generate_util_type_json.py +++ b/src/blenderbim/scripts/generate_util_type_json.py @@ -76,9 +76,10 @@ def generate_ifc4_entity_map(filepath, schema_name, manual_corrections={}): type_to_entity_map = {value: [key] for key in entity_to_type_map for value in entity_to_type_map[key]} + check_all_types_are_mapped(schema, type_to_entity_map) schema_version = schema_name.lower().strip("ifc") with open(f"src/ifcopenshell-python/ifcopenshell/util/entity_to_type_map_{schema_version}.json", "w") as f: - json.dump(entity_to_type_map, f, indent=4) + json.dump(entity_to_type_map, f, indent=4, sort_keys=False) return entity_to_type_map @@ -120,13 +121,26 @@ def generate_ifc2x3_entity_map(): entity_to_type_map.setdefault(declaration.name(), []).append(subtype.name()) type_to_entity_map2x3 = {value: [key] for key in entity_to_type_map for value in entity_to_type_map[key]} + check_all_types_are_mapped(schema2x3, type_to_entity_map2x3) with open("src/ifcopenshell-python/ifcopenshell/util/entity_to_type_map_2x3.json", "w") as f: - json.dump(entity_to_type_map, f, indent=4) + json.dump(entity_to_type_map, f, indent=4, sort_keys=False) return entity_to_type_map +def check_all_types_are_mapped(schema, type_to_entity_map): + def is_element_type(declaration): + if not hasattr(declaration, "supertype"): + return False + return ifcopenshell.util.schema.is_a(declaration, "IfcElementType") + + for declaration in schema.declarations(): + type_name = declaration.name() + if is_element_type(declaration) and type_name not in type_to_entity_map and not declaration.is_abstract(): + print(f"WARNING. {type_name} (not abstract) is not present in the mapping {schema.name()}.") + + # specs: https://technical.buildingsmart.org/standards/ifc/ifc-schema-specifications # ifc4x3 - https://github.com/buildingSMART/IFC4.3-html/releases/tag/sep-13-release (inside .zip) # ifc4 - https://standards.buildingsmart.org/IFC/RELEASE/IFC4/FINAL/EXPRESS/IFC4.exp @@ -136,6 +150,9 @@ def generate_ifc2x3_entity_map(): ifc4x3_corrections = { "IfcCivilElement": ["IfcCivilElementType"], + "IfcFurnishingElement": ["IfcFurnishingElementType"], + "IfcDistributionElement": ["IfcDistributionElementType"], + "IfcBuiltElement": ["IfcBuiltElementType"], } entity_to_type_map4x3 = generate_ifc4_entity_map("IFC4X3_TC1.exp", "ifc4x3", ifc4x3_corrections) @@ -144,6 +161,8 @@ ifc4_corrections = { "IfcDoor": ["IfcDoorStyle"], # also will apply change to IfcDoorStandardCase "IfcWindow": ["IfcWindowStyle"], # also will aply change to IfcWindowStandardCase "IfcCivilElement": ["IfcCivilElementType"], + "IfcFurnishingElement": ["IfcFurnishingElementType"], + "IfcDistributionElement": ["IfcDistributionElementType"], } # entity_to_type_map4 = generate_ifc4_entity_map("IFC4.exp", "ifc4", ifc4_corrections) 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 6627548e76..b2e9c46421 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 @@ -50,9 +50,6 @@ "IfcChimney": [ "IfcChimneyType" ], - "IfcCivilElement": [ - "IfcCivilElementType" - ], "IfcCoil": [ "IfcCoilType" ], @@ -92,9 +89,6 @@ "IfcDistributionChamberElement": [ "IfcDistributionChamberElementType" ], - "IfcDistributionElement": [ - "IfcDistributionElementType" - ], "IfcDoor": [ "IfcDoorType", "IfcDoorStyle" @@ -159,9 +153,6 @@ "IfcFooting": [ "IfcFootingType" ], - "IfcFurnishingElement": [ - "IfcFurnishingElementType" - ], "IfcFurniture": [ "IfcFurnitureType" ], @@ -319,16 +310,55 @@ "IfcWindowType", "IfcWindowStyle" ], + "IfcCivilElement": [ + "IfcCivilElementType" + ], + "IfcFurnishingElement": [ + "IfcFurnishingElementType" + ], + "IfcDistributionElement": [ + "IfcDistributionElementType" + ], "IfcBeamStandardCase": [ "IfcBeamType" ], "IfcColumnStandardCase": [ "IfcColumnType" ], + "IfcDistributionControlElement": [ + "IfcDistributionElementType" + ], + "IfcDistributionFlowElement": [ + "IfcDistributionElementType" + ], "IfcDoorStandardCase": [ "IfcDoorType", "IfcDoorStyle" ], + "IfcEnergyConversionDevice": [ + "IfcDistributionElementType" + ], + "IfcFlowController": [ + "IfcDistributionElementType" + ], + "IfcFlowFitting": [ + "IfcDistributionElementType" + ], + "IfcFlowMovingDevice": [ + "IfcDistributionElementType" + ], + "IfcFlowSegment": [ + "IfcDistributionElementType" + ], + "IfcFlowStorageDevice": [ + "IfcDistributionElementType" + ], + "IfcFlowTerminal": [ + "IfcDistributionElementType" + ], + "IfcFlowTreatmentDevice": [ + "IfcDistributionElementType" + ], "IfcMemberStandardCase": [ "IfcMemberType" ], @@ -351,4 +381,4 @@ "IfcWindowType", "IfcWindowStyle" ] -} +} \ No newline at end of file diff --git a/src/ifcopenshell-python/ifcopenshell/util/entity_to_type_map_4x3.json b/src/ifcopenshell-python/ifcopenshell/util/entity_to_type_map_4x3.json index 9b24aefb5d..2b11c29192 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/entity_to_type_map_4x3.json +++ b/src/ifcopenshell-python/ifcopenshell/util/entity_to_type_map_4x3.json @@ -374,6 +374,54 @@ "IfcCivilElement": [ "IfcCivilElementType" ], + "IfcFurnishingElement": [ + "IfcFurnishingElementType" + ], + "IfcDistributionElement": [ + "IfcDistributionElementType" + ], + "IfcBuiltElement": [ + "IfcBuiltElementType" + ], + "IfcDistributionControlElement": [ + "IfcDistributionElementType" + ], + "IfcDistributionFlowElement": [ + "IfcDistributionElementType" + ], + "IfcEarthworksElement": [ + "IfcBuiltElementType" + ], + "IfcEarthworksFill": [ + "IfcBuiltElementType" + ], + "IfcEnergyConversionDevice": [ + "IfcDistributionElementType" + ], + "IfcFlowController": [ + "IfcDistributionElementType" + ], + "IfcFlowFitting": [ + "IfcDistributionElementType" + ], + "IfcFlowMovingDevice": [ + "IfcDistributionElementType" + ], + "IfcFlowSegment": [ + "IfcDistributionElementType" + ], + "IfcFlowStorageDevice": [ + "IfcDistributionElementType" + ], + "IfcFlowTerminal": [ + "IfcDistributionElementType" + ], + "IfcFlowTreatmentDevice": [ + "IfcDistributionElementType" + ], + "IfcReinforcedSoil": [ + "IfcBuiltElementType" + ], "IfcWallStandardCase": [ "IfcWallType" ]