Skip to content

Commit d57fc0f

Browse files
committed
[core] Attribute: Add notion of depth for attributes with parents
For attributes in `GroupAttribute` and `ListAttribute`, the notion of parent attribute exists through the `root` property. As a parent can itself have a parent, the `depth` property describes how many levels there are between the attribute and the root level. A value of 0 means that the attribute is at the root level, and it increases as it gets deeper.
1 parent 9088f0b commit d57fc0f

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

meshroom/core/attribute.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ def __init__(self, node, attributeDesc, isOutput, root=None, parent=None):
6161
self._description = attributeDesc.description
6262
self._invalidate = False if self._isOutput else attributeDesc.invalidate
6363

64+
self._depth = 0
65+
if root is not None:
66+
current = self
67+
while current.root is not None:
68+
self._depth += 1
69+
current = current.root
70+
6471
# invalidation value for output attributes
6572
self._invalidationValue = ""
6673

@@ -77,6 +84,9 @@ def node(self):
7784
def root(self):
7885
return self._root() if self._root else None
7986

87+
def getDepth(self):
88+
return self._depth
89+
8090
def getName(self):
8191
""" Attribute name """
8292
return self._name
@@ -454,6 +464,7 @@ def updateInternals(self):
454464
validValueChanged = Signal()
455465
validValue = Property(bool, getValidValue, setValidValue, notify=validValueChanged)
456466
root = Property(BaseObject, root.fget, constant=True)
467+
depth = Property(int, getDepth, constant=True)
457468

458469

459470
def raiseIfLink(func):

0 commit comments

Comments
 (0)