-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
42 additions
and
1 deletion.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
src/specklepy/objects/graph_traversal/default_traversal.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from specklepy.objects.base import Base | ||
from specklepy.objects.graph_traversal.traversal import GraphTraversal, TraversalRule | ||
|
||
DISPLAY_VALUE_PROPERTY_ALIASES = {"displayValue", "@displayValue"} | ||
ELEMENTS_PROPERTY_ALIASES = {"elements", "@elements"} | ||
|
||
|
||
def has_display_value(x: Base): | ||
return any(hasattr(x, alias) for alias in DISPLAY_VALUE_PROPERTY_ALIASES) | ||
|
||
|
||
def create_default_traversal_function() -> GraphTraversal: | ||
""" | ||
Traversal func for traversing the root object of a Speckle Model | ||
""" | ||
|
||
convertible_rule = TraversalRule( | ||
[lambda b: b.speckle_type != "Base", has_display_value], | ||
lambda _: ELEMENTS_PROPERTY_ALIASES, | ||
) | ||
|
||
default_rule = TraversalRule( | ||
[lambda _: True], | ||
lambda o: o.get_member_names(), # NOTE: Unlike the C# implementation, this does not ignore Obsolete members | ||
False, | ||
) | ||
|
||
return GraphTraversal([convertible_rule, default_rule]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters