From f6bf626349f122477f6af27a9c8b45860a0c0f98 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Thu, 9 Dec 2021 13:36:33 +1100 Subject: [PATCH] Little utility to help printing out maintainable classes and other classes in contractual documentation. --- src/ifcfm/ifcfm/util.py | 42 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/src/ifcfm/ifcfm/util.py b/src/ifcfm/ifcfm/util.py index 7dcff45e79..8772285952 100644 --- a/src/ifcfm/ifcfm/util.py +++ b/src/ifcfm/ifcfm/util.py @@ -20,10 +20,11 @@ import textwrap import ifcopenshell import ifcopenshell.util.fm +import ifcopenshell.util.schema import ifcopenshell.util.attribute -def print_element(declaration): +def print_element(declaration, should_print_subtypes=True): if declaration.name() in ifcopenshell.util.fm.fmhem_excluded_classes: pass elif declaration.is_abstract(): @@ -39,8 +40,9 @@ def print_element(declaration): if types: for line in textwrap.wrap(", ".join(types), width=70): print("\t\t{}".format(line)) - for subtype in declaration.subtypes(): - print_element(subtype) + if should_print_subtypes: + for subtype in declaration.subtypes(): + print_element(subtype) def print_fmhem_documentation(schema="IFC4"): @@ -56,4 +58,36 @@ def print_fmhem_documentation(schema="IFC4"): except: pass -print_fmhem_documentation("IFC2X3") + +def print_all_documentation(schema="IFC4"): + if schema == "IFC4": + classes = ifcopenshell.util.fm.fmhem_classes_ifc4 + elif schema == "IFC2X3": + classes = ifcopenshell.util.fm.fmhem_classes_ifc2x3 + schema = ifcopenshell.ifcopenshell_wrapper.schema_by_name(schema) + class_queue = [schema.declaration_by_name("IfcElementType")] + maintainable_declarations = [] + other_declarations = [] + while class_queue: + declaration = class_queue.pop(0) + class_queue.extend(declaration.subtypes()) + if declaration.is_abstract(): + continue + is_maintainable = False + for ifc_class in classes: + if ifcopenshell.util.schema.is_a(declaration, ifc_class): + is_maintainable = True + break + if is_maintainable: + maintainable_declarations.append(declaration) + else: + other_declarations.append(declaration) + print("# Maintainable classes\n") + for declaration in maintainable_declarations: + print_element(declaration, should_print_subtypes=False) + print("\n\n# Other classes\n") + for declaration in other_declarations: + print_element(declaration, should_print_subtypes=False) + + +print_all_documentation("IFC2X3")