Fix bug where selector didn't handle "not equals" correctly for locations or groups

This commit is contained in:
Dion Moult
2024-06-01 14:53:55 +10:00
parent f67911902f
commit 128ffc8fd7
2 changed files with 12 additions and 2 deletions
@@ -660,7 +660,7 @@ class FacetTransformer(lark.Transformer):
containers = self.get_container_tree(container)
result = False if containers else None
for container in containers:
if self.compare(container.Name, comparison, value):
if self.compare(container.Name, "=", value):
result = True
if result is not None:
return result if comparison == "=" else not result
@@ -675,7 +675,7 @@ class FacetTransformer(lark.Transformer):
result = False
for rel in getattr(element, "HasAssignments", []):
if rel.is_a("IfcRelAssignsToGroup") and rel.RelatingGroup:
if self.compare(rel.RelatingGroup.Name, comparison, value):
if self.compare(rel.RelatingGroup.Name, "=", value):
result = True
return result if comparison == "=" else not result
@@ -238,6 +238,7 @@ class TestFilterElements(test.bootstrap.IFC4):
assert subject.filter_elements(self.file, "IfcWall, classification=NULL") == {element2}
assert subject.filter_elements(self.file, "IfcWall, classification=X") == {element}
assert subject.filter_elements(self.file, "IfcWall, classification=Foobar") == {element}
assert subject.filter_elements(self.file, "IfcWall, classification!=X") == {element2}
def test_selecting_by_location(self):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
@@ -255,6 +256,15 @@ class TestFilterElements(test.bootstrap.IFC4):
assert subject.filter_elements(self.file, "IfcWall, location=Space") == {element}
assert subject.filter_elements(self.file, "IfcWall, location=G") == {element, element2}
assert subject.filter_elements(self.file, "IfcWall, location=Building") == {element, element2}
assert subject.filter_elements(self.file, "IfcWall, location!=Space") == {element2}
def test_selecting_by_group(self):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
group = ifcopenshell.api.run("group.add_group", self.file, name="Foo")
ifcopenshell.api.run("group.assign_group", self.file, products=[element], group=group)
assert subject.filter_elements(self.file, "IfcWall, group=Foo") == {element}
assert subject.filter_elements(self.file, "IfcWall, group!=Foo") == {element2}
def test_selecting_multiple_filter_groups(self):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")