More general solution for #3466

This commit is contained in:
Andrej730
2023-07-31 11:44:32 +05:00
parent 3a812a9ec1
commit 0e69f484f4
3 changed files with 109 additions and 12 deletions
@@ -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)
@@ -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"
]
}
}
@@ -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"
]