mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 17:58:20 +00:00
Fallback for queries if no elements filter is provided #5901
This commit is contained in:
@@ -771,6 +771,23 @@ class FacetTransformer(lark.Transformer):
|
||||
results |= r
|
||||
return results
|
||||
|
||||
def transform(self, tree: lark.ParseTree):
|
||||
def has_elements_token(tree: lark.tree.ParseTree) -> bool:
|
||||
for child in tree.iter_subtrees_topdown():
|
||||
data = child.data
|
||||
# Tokens that add elements to filter.
|
||||
if data in ("entity", "instance"):
|
||||
return True
|
||||
return False
|
||||
|
||||
# Only elements tokens can add elements to the filter.
|
||||
# Fallback to default elements if they are not provided.
|
||||
if self.base_elements is None and not has_elements_token(tree):
|
||||
self.elements.update(self.file.by_type("IfcProduct"))
|
||||
self.elements.update(self.file.by_type("IfcTypeProduct"))
|
||||
|
||||
return super().transform(tree)
|
||||
|
||||
def facet_list(self, args):
|
||||
if self.elements:
|
||||
self.results.append(self.elements)
|
||||
|
||||
Reference in New Issue
Block a user