mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 09:48:32 +00:00
New support for filtering elements by checking values against an enumeration
This commit is contained in:
@@ -46,7 +46,8 @@ class Selector:
|
||||
and: "&"
|
||||
or: "|"
|
||||
not: "!"
|
||||
comparison: (not)* (contains | morethanequalto | lessthanequalto | equal | morethan | lessthan)
|
||||
comparison: (not)* (oneof | contains | morethanequalto | lessthanequalto | equal | morethan | lessthan)
|
||||
oneof: "%="
|
||||
contains: "*="
|
||||
morethanequalto: ">="
|
||||
lessthanequalto: "<="
|
||||
@@ -245,6 +246,8 @@ class Selector:
|
||||
return element_value >= value
|
||||
elif comparison == "lessthanequalto":
|
||||
return element_value <= value
|
||||
elif comparison == "oneof":
|
||||
return element_value in value.split(",")
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
|
||||
@@ -90,3 +90,19 @@ class TestSelector(test.bootstrap.IFC4):
|
||||
assert subject.Selector.parse(self.file, '.IfcElement[Foo_Bar.Foo<20]') == [element]
|
||||
assert subject.Selector.parse(self.file, '.IfcElement[Foo_Bar.Foo>=4.2]') == [element]
|
||||
assert subject.Selector.parse(self.file, '.IfcElement[Foo_Bar.Foo<=4.2]') == [element]
|
||||
|
||||
def test_comparing_if_value_contains_a_wildcard_string(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
element.Name = "Foobar"
|
||||
assert subject.Selector.parse(self.file, '.IfcElement[Name*="Foo"]') == [element]
|
||||
assert subject.Selector.parse(self.file, '.IfcElement[Name*="oba"]') == [element]
|
||||
assert subject.Selector.parse(self.file, '.IfcElement[Name*="abc"]') == []
|
||||
|
||||
def test_comparing_if_value_is_in_a_list(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
element.Name = "Foobar"
|
||||
assert subject.Selector.parse(self.file, '.IfcElement[Name%="Foobar,Foobaz"]') == [element]
|
||||
element.Name = "Foobaz"
|
||||
assert subject.Selector.parse(self.file, '.IfcElement[Name%="Foobar,Foobaz"]') == [element]
|
||||
element.Name = "Foobat"
|
||||
assert subject.Selector.parse(self.file, '.IfcElement[Name%="Foobar,Foobaz"]') == []
|
||||
|
||||
Reference in New Issue
Block a user