mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-19 03:33:48 +00:00
More general solution for #3466
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user