mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 17:31:45 +00:00
Fix #2354 - add support for selector queries for enumerated properties
This commit is contained in:
@@ -238,8 +238,12 @@ class Selector:
|
||||
def filter_element(cls, element, element_value, comparison, value):
|
||||
if comparison.startswith("not"):
|
||||
return not cls.filter_element(element, element_value, comparison[3:], value)
|
||||
elif comparison == "equal" and isinstance(element_value, list):
|
||||
return value in element_value
|
||||
elif comparison == "equal":
|
||||
return element_value == value
|
||||
elif comparison == "contains" and isinstance(element_value, list):
|
||||
return bool([ev for ev in element_value if value in str(ev)])
|
||||
elif comparison == "contains":
|
||||
return value in str(element_value)
|
||||
elif comparison == "morethan":
|
||||
|
||||
@@ -37,8 +37,8 @@ class TestSelector(test.bootstrap.IFC4):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
element.Name = "Foobar"
|
||||
ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSlab")
|
||||
assert subject.Selector.parse(self.file, '.IfcElement[Name]') == [element]
|
||||
assert subject.Selector.parse(self.file, '.IfcElement[Description]') == []
|
||||
assert subject.Selector.parse(self.file, ".IfcElement[Name]") == [element]
|
||||
assert subject.Selector.parse(self.file, ".IfcElement[Description]") == []
|
||||
|
||||
def test_selecting_by_attribute(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
@@ -51,8 +51,8 @@ class TestSelector(test.bootstrap.IFC4):
|
||||
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": "Bar"})
|
||||
assert subject.Selector.parse(self.file, '.IfcElement[Foo_Bar.Foo]') == [element]
|
||||
assert subject.Selector.parse(self.file, '.IfcElement[Foo_Bar.Fox]') == []
|
||||
assert subject.Selector.parse(self.file, ".IfcElement[Foo_Bar.Foo]") == [element]
|
||||
assert subject.Selector.parse(self.file, ".IfcElement[Foo_Bar.Fox]") == []
|
||||
|
||||
def test_selecting_by_string_property(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
@@ -60,6 +60,15 @@ class TestSelector(test.bootstrap.IFC4):
|
||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Foo": "Bar"})
|
||||
assert subject.Selector.parse(self.file, '.IfcElement[Foo_Bar.Foo="Bar"]') == [element]
|
||||
|
||||
def test_selecting_by_enumerated_property(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="Pset_WallCommon")
|
||||
template = ifcopenshell.util.pset.get_template("IFC4").get_by_name("Pset_WallCommon")
|
||||
ifcopenshell.api.run(
|
||||
"pset.edit_pset", self.file, pset=pset, properties={"Status": ["NEW"]}, pset_template=template
|
||||
)
|
||||
assert subject.Selector.parse(self.file, '.IfcElement[Pset_WallCommon.Status="NEW"]') == [element]
|
||||
|
||||
def test_selecting_by_integer_property(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")
|
||||
@@ -121,17 +130,20 @@ class TestSelector(test.bootstrap.IFC4):
|
||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset_2, properties={"Foo": "BOO"})
|
||||
assert subject.Selector.parse(self.file, '.IfcElement[Foo_Bar.Foo != "Bar"]') == [element_2]
|
||||
assert subject.Selector.parse(self.file, '.IfcElement[Foo_Bar.Foo != "BOO"]') == [element_1]
|
||||
|
||||
|
||||
def test_selecting_when_attribute_is_none(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
assert subject.Selector.parse(self.file, '.IfcElement[PredefinedType !="non-existent predefined type"]') == [element]
|
||||
|
||||
assert subject.Selector.parse(self.file, '.IfcElement[PredefinedType !="non-existent predefined type"]') == [
|
||||
element
|
||||
]
|
||||
|
||||
def test_selecting_a_property_which_includes_non_standard_characters(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="a !%$§&/()?|*-+,€~#@µ^°a")
|
||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"a !%$§&/()?|*-+,€~#@µ^°a": "Bar"})
|
||||
assert subject.Selector.parse(self.file, '.IfcElement[a !%$§&/()?|*-+,€~#@µ^°a.a !%$§&/()?|*-+,€~#@µ^°a="Bar"]') == [element]
|
||||
assert subject.Selector.parse(
|
||||
self.file, '.IfcElement[a !%$§&/()?|*-+,€~#@µ^°a.a !%$§&/()?|*-+,€~#@µ^°a="Bar"]'
|
||||
) == [element]
|
||||
|
||||
def test_comparing_if_value_is_in_a_list(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
|
||||
Reference in New Issue
Block a user