[ui/core] Count for loop added on nodes in graph

This commit is contained in:
Aurore LAFAURIE 2024-08-22 14:00:29 +02:00
parent 91ebc1619c
commit 32b0ed5c8b
4 changed files with 36 additions and 0 deletions

View file

@ -1320,6 +1320,25 @@ class BaseNode(BaseObject):
if attr.enabled and attr.isOutput and hasSupportedExt:
return True
return False
def _countForLoop(self):
"""
Return in how many ForLoop nodes this node is.
"""
count = 0
# Access to the input attributes of the node
for attr in self._attributes:
if attr.isInput and attr.isLink:
# Access to the attribute connected to the input attribute
srcAttr = attr.getLinkParam()
# If the srcAttr is a ListAttribute, it means that the node is in a ForLoop
if isinstance(srcAttr.root, ListAttribute) and srcAttr.type == attr.type:
# Access the countForLoop of the node of the ListAttribute
count = srcAttr.root.node.countForLoop + 1
if srcAttr.root.isInput:
count = count - 1 if count > 1 else 1
return count
name = Property(str, getName, constant=True)
@ -1373,6 +1392,9 @@ class BaseNode(BaseObject):
hasSequenceOutput = Property(bool, hasSequenceOutputAttribute, notify=outputAttrEnabledChanged)
has3DOutput = Property(bool, has3DOutputAttribute, notify=outputAttrEnabledChanged)
countForLoopChanged = Signal()
countForLoop = Property(int, _countForLoop, notify=countForLoopChanged)
class Node(BaseNode):
"""
A standard Graph node based on a node type.