mirror of
https://github.com/alicevision/Meshroom.git
synced 2025-05-20 20:46:28 +02:00
[core] add "Attribute.hasOutputConnections" property
Give access to whether an attribute has output connections.
This commit is contained in:
parent
f1267d7e67
commit
fcb2b23c1a
2 changed files with 17 additions and 2 deletions
|
@ -153,7 +153,10 @@ class Attribute(BaseObject):
|
|||
""" Whether the attribute is a link to another attribute. """
|
||||
# Note: Need to test self.node.graph.edges before accessing to edges.keys() to avoid errors in particular conditions.
|
||||
# For instance: open a scene, modify something and close without saving it.
|
||||
return self.node.graph and self.isInput and self.node.graph.edges and self in self.node.graph.edges.keys()
|
||||
if not self.node.graph or not self.node.graph.edges or not self.isInput:
|
||||
return False
|
||||
|
||||
return self in self.node.graph.edges.keys()
|
||||
|
||||
@staticmethod
|
||||
def isLinkExpression(value):
|
||||
|
@ -166,6 +169,14 @@ class Attribute(BaseObject):
|
|||
def getLinkParam(self):
|
||||
return self.node.graph.edge(self).src if self.isLink else None
|
||||
|
||||
@property
|
||||
def hasOutputConnections(self):
|
||||
""" Whether the attribute has output connections, i.e is the source of at least one edge. """
|
||||
# safety check to avoid evaluation errors
|
||||
if not self.node.graph or not self.node.graph.edges:
|
||||
return False
|
||||
return next((edge for edge in self.node.graph.edges.values() if edge.src == self), None) is not None
|
||||
|
||||
def _applyExpr(self):
|
||||
"""
|
||||
For string parameters with an expression (when loaded from file),
|
||||
|
@ -220,6 +231,8 @@ class Attribute(BaseObject):
|
|||
isOutput = Property(bool, isOutput.fget, constant=True)
|
||||
isLinkChanged = Signal()
|
||||
isLink = Property(bool, isLink.fget, notify=isLinkChanged)
|
||||
hasOutputConnectionsChanged = Signal()
|
||||
hasOutputConnections = Property(bool, hasOutputConnections.fget, notify=hasOutputConnectionsChanged)
|
||||
isDefault = Property(bool, _isDefault, notify=valueChanged)
|
||||
linkParam = Property(BaseObject, getLinkParam, notify=isLinkChanged)
|
||||
node = Property(BaseObject, node.fget, constant=True)
|
||||
|
|
|
@ -585,6 +585,7 @@ class Graph(BaseObject):
|
|||
self.markNodesDirty(dstAttr.node)
|
||||
dstAttr.valueChanged.emit()
|
||||
dstAttr.isLinkChanged.emit()
|
||||
srcAttr.hasOutputConnectionsChanged.emit()
|
||||
return edge
|
||||
|
||||
def addEdges(self, *edges):
|
||||
|
@ -596,10 +597,11 @@ class Graph(BaseObject):
|
|||
def removeEdge(self, dstAttr):
|
||||
if dstAttr not in self.edges.keys():
|
||||
raise RuntimeError('Attribute "{}" is not connected'.format(dstAttr.getFullName()))
|
||||
self.edges.pop(dstAttr)
|
||||
edge = self.edges.pop(dstAttr)
|
||||
self.markNodesDirty(dstAttr.node)
|
||||
dstAttr.valueChanged.emit()
|
||||
dstAttr.isLinkChanged.emit()
|
||||
edge.src.hasOutputConnectionsChanged.emit()
|
||||
|
||||
def getDepth(self, node, minimal=False):
|
||||
""" Return node's depth in this Graph.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue