Add support for groups in selection queries

This commit is contained in:
Dion Moult
2024-01-09 16:44:40 +11:00
parent e71aac84dc
commit bfabc0db0f
4 changed files with 28 additions and 3 deletions
@@ -33,7 +33,7 @@ filter_elements_grammar = lark.Lark(
filter_group: facet_list ("+" facet_list)*
facet_list: facet ("," facet)*
facet: instance | entity | attribute | type | material | query | classification | location | property
facet: instance | entity | attribute | type | material | query | classification | location | property | group
instance: not? globalid
globalid: /[0-3][a-zA-Z0-9_$]{21}/
@@ -44,6 +44,7 @@ filter_elements_grammar = lark.Lark(
property: pset "." prop comparison value
classification: "classification" comparison value
location: "location" comparison value
group: "group" comparison value
query: "query:" keys comparison value
pset: quoted_string | regex_string | unquoted_string
@@ -512,6 +513,19 @@ class FacetTransformer(lark.Transformer):
self.elements = set(filter(filter_function, self.elements))
def group(self, args):
comparison, value = args
def filter_function(element):
result = False
for rel in getattr(element, "HasAssignments", []):
if rel.is_a("IfcRelAssignsToGroup") and rel.RelatingGroup:
if self.compare(rel.RelatingGroup.Name, comparison, value):
result = True
return result if comparison == "=" else not result
self.elements = set(filter(filter_function, self.elements))
def query(self, args):
keys, comparison, value = args