endofday 1207

240pm 14/07

draft version

cleanup
This commit is contained in:
Vukas Pajic
2022-07-11 16:33:24 +02:00
parent 1586c85314
commit e3d9dd747d
5 changed files with 458 additions and 29 deletions
@@ -21,13 +21,11 @@ import ifcopenshell.util.fm
import ifcopenshell.util.element
import lark
class Selector:
@classmethod
def parse(cls, ifc_file, query, elements=None):
cls.file = ifc_file
cls.elements = elements
l = lark.Lark(
"""start: query (lfunction query)*
query: selector | group
@@ -38,7 +36,7 @@ class Selector:
filter: "[" filter_key (comparison filter_value)? "]"
filter_key: WORD | pset_or_qto
filter_value: ESCAPED_STRING | SIGNED_FLOAT | SIGNED_INT | BOOLEAN | NULL
pset_or_qto: /[A-Za-z0-9_]+/ "." /[A-Za-z0-9_]+/
pset_or_qto: /[^.= ][^.=]*[^.= ]/ "." /[^.= ][^.=]*[^.= ](?= +\W+")/
lfunction: and | or
inverse_relationship: types | decomposed_by | bounded_by
types: "*"
@@ -143,7 +141,8 @@ class Selector:
elif hasattr(element, "ObjectTypeOf") and element.ObjectTypeOf:
results.extend(element.ObjectTypeOf[0].RelatedObjects)
elif inverse_relationship == "decomposed_by":
results.extend(ifcopenshell.util.element.get_decomposition(element))
results.extend(
ifcopenshell.util.element.get_decomposition(element))
elif inverse_relationship == "bounded_by" and hasattr(element, "BoundedBy"):
for relationship in element.BoundedBy:
results.append(relationship.RelatedBuildingElement)
@@ -161,7 +160,8 @@ class Selector:
if cls.elements is None:
elements = cls.file.by_type(class_selector.children[0])
else:
elements = [e for e in cls.elements if e.is_a(class_selector.children[0])]
elements = [e for e in cls.elements if e.is_a(
class_selector.children[0])]
if len(class_selector.children) > 1 and class_selector.children[1].data == "filter":
return cls.filter_elements(elements, class_selector.children[1])
return elements
@@ -210,7 +210,8 @@ class Selector:
key = ".".join(key.split(".")[1:])
elif "." in key and key.split(".")[0] == "material":
try:
element = ifcopenshell.util.element.get_material(element, should_skip_usage=True)
element = ifcopenshell.util.element.get_material(
element, should_skip_usage=True)
if not element:
return None
except: