mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-18 06:21:40 +00:00
You can now use a "not" operator when selecting elements
This commit is contained in:
@@ -45,7 +45,8 @@ class Selector:
|
|||||||
boundedby: "@@"
|
boundedby: "@@"
|
||||||
and: "&"
|
and: "&"
|
||||||
or: "|"
|
or: "|"
|
||||||
comparison: contains | morethanequalto | lessthanequalto | equal | morethan | lessthan
|
not: "!"
|
||||||
|
comparison: (not)* (contains | morethanequalto | lessthanequalto | equal | morethan | lessthan)
|
||||||
contains: "*="
|
contains: "*="
|
||||||
morethanequalto: ">="
|
morethanequalto: ">="
|
||||||
lessthanequalto: "<="
|
lessthanequalto: "<="
|
||||||
@@ -170,6 +171,8 @@ class Selector:
|
|||||||
comparison = value = None
|
comparison = value = None
|
||||||
if len(filter_rule.children) > 1:
|
if len(filter_rule.children) > 1:
|
||||||
comparison = filter_rule.children[1].children[0].data
|
comparison = filter_rule.children[1].children[0].data
|
||||||
|
if comparison == "not":
|
||||||
|
comparison += filter_rule.children[1].children[1].data
|
||||||
token_type = filter_rule.children[2].children[0].type
|
token_type = filter_rule.children[2].children[0].type
|
||||||
if token_type == "ESCAPED_STRING":
|
if token_type == "ESCAPED_STRING":
|
||||||
value = str(filter_rule.children[2].children[0][1:-1])
|
value = str(filter_rule.children[2].children[0][1:-1])
|
||||||
@@ -228,18 +231,20 @@ class Selector:
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def filter_element(cls, element, element_value, comparison, value):
|
def filter_element(cls, element, element_value, comparison, value):
|
||||||
if comparison == "equal":
|
if comparison.startswith("not"):
|
||||||
|
return not cls.filter_element(element, element_value, comparison[3:], value)
|
||||||
|
elif comparison == "equal":
|
||||||
return element_value == value
|
return element_value == value
|
||||||
elif comparison == "contains":
|
elif comparison == "contains":
|
||||||
return value in str(element_value)
|
return value in str(element_value)
|
||||||
elif comparison == "morethan":
|
elif comparison == "morethan":
|
||||||
return element_value > float(value)
|
return element_value > value
|
||||||
elif comparison == "lessthan":
|
elif comparison == "lessthan":
|
||||||
return element_value < float(value)
|
return element_value < value
|
||||||
elif comparison == "morethanequalto":
|
elif comparison == "morethanequalto":
|
||||||
return element_value >= float(value)
|
return element_value >= value
|
||||||
elif comparison == "lessthanequalto":
|
elif comparison == "lessthanequalto":
|
||||||
return element_value <= float(value)
|
return element_value <= value
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|||||||
@@ -73,3 +73,20 @@ class TestSelector(test.bootstrap.IFC4):
|
|||||||
assert subject.Selector.parse(self.file, '.IfcElement[Foo_Bar.Foo=NULL]') == []
|
assert subject.Selector.parse(self.file, '.IfcElement[Foo_Bar.Foo=NULL]') == []
|
||||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Foo": None})
|
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Foo": None})
|
||||||
assert subject.Selector.parse(self.file, '.IfcElement[Foo_Bar.Foo=NULL]') == [element]
|
assert subject.Selector.parse(self.file, '.IfcElement[Foo_Bar.Foo=NULL]') == [element]
|
||||||
|
|
||||||
|
def test_comparing_by_not_equal(self):
|
||||||
|
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||||
|
element.Name = "Foobar"
|
||||||
|
assert subject.Selector.parse(self.file, '.IfcElement[Name!="Foobaz"]') == [element]
|
||||||
|
assert subject.Selector.parse(self.file, '.IfcElement[Name!="Foobar"]') == []
|
||||||
|
|
||||||
|
def test_comparing_by_ranges(self):
|
||||||
|
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||||
|
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="Foo_Bar")
|
||||||
|
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Foo": 4.2})
|
||||||
|
assert subject.Selector.parse(self.file, '.IfcElement[Foo_Bar.Foo>2]') == [element]
|
||||||
|
assert subject.Selector.parse(self.file, '.IfcElement[Foo_Bar.Foo>20]') == []
|
||||||
|
assert subject.Selector.parse(self.file, '.IfcElement[Foo_Bar.Foo<2]') == []
|
||||||
|
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]
|
||||||
|
|||||||
Reference in New Issue
Block a user