mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-18 14:31:39 +00:00
all tests in test_selector.py now passing
This commit is contained in:
@@ -21,6 +21,7 @@ import ifcopenshell.util.fm
|
|||||||
import ifcopenshell.util.element
|
import ifcopenshell.util.element
|
||||||
import lark
|
import lark
|
||||||
|
|
||||||
|
|
||||||
class Selector:
|
class Selector:
|
||||||
@classmethod
|
@classmethod
|
||||||
def parse(cls, ifc_file, query, elements=None):
|
def parse(cls, ifc_file, query, elements=None):
|
||||||
@@ -36,7 +37,7 @@ class Selector:
|
|||||||
filter: "[" filter_key (comparison filter_value)? "]"
|
filter: "[" filter_key (comparison filter_value)? "]"
|
||||||
filter_key: WORD | pset_or_qto
|
filter_key: WORD | pset_or_qto
|
||||||
filter_value: ESCAPED_STRING | SIGNED_FLOAT | SIGNED_INT | BOOLEAN | NULL
|
filter_value: ESCAPED_STRING | SIGNED_FLOAT | SIGNED_INT | BOOLEAN | NULL
|
||||||
pset_or_qto: /[^\W][^.=]*[^\W]/ "." /[^\W][^.=]*[^\W]/
|
pset_or_qto: /[^\W][^.=<>]*[^\W]/ "." /[^\W][^.=<>]*[^\W]/
|
||||||
lfunction: and | or
|
lfunction: and | or
|
||||||
inverse_relationship: types | decomposed_by | bounded_by
|
inverse_relationship: types | decomposed_by | bounded_by
|
||||||
types: "*"
|
types: "*"
|
||||||
@@ -141,8 +142,7 @@ class Selector:
|
|||||||
elif hasattr(element, "ObjectTypeOf") and element.ObjectTypeOf:
|
elif hasattr(element, "ObjectTypeOf") and element.ObjectTypeOf:
|
||||||
results.extend(element.ObjectTypeOf[0].RelatedObjects)
|
results.extend(element.ObjectTypeOf[0].RelatedObjects)
|
||||||
elif inverse_relationship == "decomposed_by":
|
elif inverse_relationship == "decomposed_by":
|
||||||
results.extend(
|
results.extend(ifcopenshell.util.element.get_decomposition(element))
|
||||||
ifcopenshell.util.element.get_decomposition(element))
|
|
||||||
elif inverse_relationship == "bounded_by" and hasattr(element, "BoundedBy"):
|
elif inverse_relationship == "bounded_by" and hasattr(element, "BoundedBy"):
|
||||||
for relationship in element.BoundedBy:
|
for relationship in element.BoundedBy:
|
||||||
results.append(relationship.RelatedBuildingElement)
|
results.append(relationship.RelatedBuildingElement)
|
||||||
@@ -160,8 +160,7 @@ class Selector:
|
|||||||
if cls.elements is None:
|
if cls.elements is None:
|
||||||
elements = cls.file.by_type(class_selector.children[0])
|
elements = cls.file.by_type(class_selector.children[0])
|
||||||
else:
|
else:
|
||||||
elements = [e for e in cls.elements if e.is_a(
|
elements = [e for e in cls.elements if e.is_a(class_selector.children[0])]
|
||||||
class_selector.children[0])]
|
|
||||||
if len(class_selector.children) > 1 and class_selector.children[1].data == "filter":
|
if len(class_selector.children) > 1 and class_selector.children[1].data == "filter":
|
||||||
return cls.filter_elements(elements, class_selector.children[1])
|
return cls.filter_elements(elements, class_selector.children[1])
|
||||||
return elements
|
return elements
|
||||||
@@ -185,7 +184,7 @@ class Selector:
|
|||||||
elif token_type == "SIGNED_FLOAT":
|
elif token_type == "SIGNED_FLOAT":
|
||||||
value = float(filter_rule.children[2].children[0])
|
value = float(filter_rule.children[2].children[0])
|
||||||
elif token_type == "BOOLEAN":
|
elif token_type == "BOOLEAN":
|
||||||
value = filter_rule.children[2].children[0].lower() == 'true'
|
value = filter_rule.children[2].children[0].lower() == "true"
|
||||||
elif token_type == "NULL":
|
elif token_type == "NULL":
|
||||||
value = None
|
value = None
|
||||||
for element in elements:
|
for element in elements:
|
||||||
@@ -210,8 +209,7 @@ class Selector:
|
|||||||
key = ".".join(key.split(".")[1:])
|
key = ".".join(key.split(".")[1:])
|
||||||
elif "." in key and key.split(".")[0] == "material":
|
elif "." in key and key.split(".")[0] == "material":
|
||||||
try:
|
try:
|
||||||
element = ifcopenshell.util.element.get_material(
|
element = ifcopenshell.util.element.get_material(element, should_skip_usage=True)
|
||||||
element, should_skip_usage=True)
|
|
||||||
if not element:
|
if not element:
|
||||||
return None
|
return None
|
||||||
except:
|
except:
|
||||||
|
|||||||
Reference in New Issue
Block a user