Little utility to help printing out maintainable classes and other classes in contractual documentation.

This commit is contained in:
Dion Moult
2021-12-09 13:36:33 +11:00
parent b66792f981
commit f6bf626349
+38 -4
View File
@@ -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")