Fill IfcPropertySetTemplate.TemplateType in ifc2x3 pset templates

This commit is contained in:
Andrej730
2024-05-28 15:15:14 +05:00
parent a09cb5dee4
commit eeaa0a5530
2 changed files with 363 additions and 321 deletions
@@ -18,6 +18,7 @@
RUN_FROM_DEV_REPO = False
import ifcopenshell.ifcopenshell_wrapper as ifcopenshell_wrapper
import ifcopenshell.api
import ifcopenshell.guid
import ifcopenshell.util.attribute
@@ -100,7 +101,7 @@ class PsetTemplatesGenerator:
print("Starting parsing data for IFC2X3...")
if not IFC2x3_HTML_ZIP_LOCATION.is_file():
raise Exception(
f'ISO release for IFC2x3 TC1 expected to be in folder "{IFC2x3_HTML_ZIP_LOCATION.resolve()}\\"\n'
f'ISO release for IFC2x3 TC1 expected to be located in "{IFC2x3_HTML_ZIP_LOCATION.resolve()}"\n'
"For doc extraction please either setup docs as described above \n"
"or change IFC2x3_HTML_LOCATION in the script accordingly.\n"
"You can download docs from the url: \n"
@@ -176,8 +177,12 @@ class PsetTemplatesGenerator:
TemplateType=root_xml.get("templatetype"),
Name=pset_name,
Description=root_xml.find("Definition").text,
ApplicableEntity=",".join(applicable_entities),
ApplicableEntity=",".join(applicable_entities).strip(),
)
if project_name.startswith("IFC2X3"):
pset.TemplateType = self.get_pset_template_type_ifc2x3(pset)
else:
pset.TemplateType = root_xml.get("templatetype")
# NOTE: there is also Applicability tag
# but it's seems always empty in ifc4 and ifc4x3
@@ -369,6 +374,43 @@ class PsetTemplatesGenerator:
pset_property.PrimaryMeasureType = primary_measure_type
def get_pset_template_type_ifc2x3(self, pset_template: ifcopenshell.entity_instance) -> str:
def declaration_is_a(declaration: ifcopenshell_wrapper.declaration, ifc_class: str) -> bool:
if declaration.name() == ifc_class:
return True
super_type = declaration.supertype()
if not super_type:
return False
return declaration_is_a(super_type, ifc_class)
name = pset_template.Name
applicability = pset_template.ApplicableEntity
schema = ifcopenshell.schema_by_name("IFC2X3")
if "PHistory" in name:
return "PSET_PERFORMANCEDRIVEN"
applicable_types = applicability.replace(", ", ",").split(",")
for applicable_type in applicable_types:
if not applicable_type:
continue
parts = applicable_type.split("/")
assert 3 > len(parts) > 0
if parts[0].isupper(): # IFC2X3 thing
applicable_type = parts[1]
else:
applicable_type = parts[0]
applicable_type = applicable_type.strip()
declaration = schema.declaration_by_name(applicable_type)
if declaration_is_a(declaration, "IfcTypeObject"):
return "PSET_TYPEDRIVENOVERRIDE"
# ifc4x3+
elif declaration_is_a(declaration, "IfcProfileDef"):
return "PSET_PROFILEDRIVEN"
elif declaration_is_a(declaration, "IfcMaterialDefinition"):
return "PSET_MATERIALDRIVEN"
return "PSET_OCCURRENCEDRIVEN"
if __name__ == "__main__":
templates_generator = PsetTemplatesGenerator()
File diff suppressed because it is too large Load Diff