[core/ui] replace and remove depending/required nodes methods

This commit is contained in:
Julien-Haudegond 2020-08-24 11:59:03 +02:00
parent 11e68e77ed
commit ba1994deb9
3 changed files with 25 additions and 28 deletions

View file

@ -916,14 +916,6 @@ class Graph(BaseObject):
outputNodes, edges = self.nodesFromNode(node, filterTypes=None, reverse=True) outputNodes, edges = self.nodesFromNode(node, filterTypes=None, reverse=True)
return outputNodes[1:] # exclude current node return outputNodes[1:] # exclude current node
def nodesDependingOnNode(self, startNode, filterTypes=None):
nodes, edges = self.nodesFromNode(startNode, filterTypes=filterTypes, reverse=True)
return nodes
def nodesRequiredForNode(self, startNode, filterTypes=None):
nodes, edges = self.nodesFromNode(startNode, filterTypes=filterTypes, reverse=False)
return nodes
@Slot(Node, result=int) @Slot(Node, result=int)
def canSubmitOrCompute(self, startNode): def canSubmitOrCompute(self, startNode):
if startNode.isAlreadySubmittedOrFinished(): if startNode.isAlreadySubmittedOrFinished():

View file

@ -857,8 +857,9 @@ class BaseNode(BaseObject):
# Unlock required nodes if the current node changes to Error or Stopped # Unlock required nodes if the current node changes to Error or Stopped
if currentStatus in (Status.ERROR, Status.STOPPED): if currentStatus in (Status.ERROR, Status.STOPPED):
requiredNodes = self.graph.nodesRequiredForNode(self) self.setLocked(False)
for node in requiredNodes: inputNodes = self.getInputNodes(recursive=True)
for node in inputNodes:
node.setLocked(False) node.setLocked(False)
# Avoid useless travel through nodes # Avoid useless travel through nodes
@ -868,23 +869,25 @@ class BaseNode(BaseObject):
if currentStatus == Status.SUCCESS: if currentStatus == Status.SUCCESS:
# At this moment, the node is necessarily locked because of previous if statement # At this moment, the node is necessarily locked because of previous if statement
requiredNodes = self.graph.nodesRequiredForNode(self) inputNodes = self.getInputNodes(recursive=True)
dependentNodes = self.graph.nodesDependingOnNode(self) outputNodes = self.getOutputNodes(recursive=True)
stayLocked = None stayLocked = None
# Check if at least one dependentNode is submitted or currently running # Check if at least one dependentNode is submitted or currently running
for node in dependentNodes: for node in outputNodes:
if node.getGlobalStatus() in lockedStatus and node._chunks.at(0).statusNodeName == node.name: if node.getGlobalStatus() in lockedStatus and node._chunks.at(0).statusNodeName == node.name:
stayLocked = True stayLocked = True
break break
if not stayLocked: if not stayLocked:
# Unlock every required node self.setLocked(False)
for node in requiredNodes: # Unlock every input node
for node in inputNodes:
node.setLocked(False) node.setLocked(False)
return return
elif currentStatus in lockedStatus: elif currentStatus in lockedStatus:
requiredNodes = self.graph.nodesRequiredForNode(self) self.setLocked(True)
for node in requiredNodes: inputNodes = self.getInputNodes(recursive=True)
for node in inputNodes:
node.setLocked(True) node.setLocked(True)
return return

View file

@ -401,11 +401,11 @@ class UIGraph(QObject):
# If some dependent nodes are submitted, the first one will be in error # If some dependent nodes are submitted, the first one will be in error
# Make sure to remove those nodes from the Task Manager list # Make sure to remove those nodes from the Task Manager list
dependentNodes = self._graph.nodesDependingOnNode(node) outputNodes = node.getOutputNodes(recursive=True)
for node in dependentNodes[1:]: # exclude current node for n in outputNodes:
if node.getGlobalStatus() == Status.ERROR: if n.getGlobalStatus() == Status.ERROR:
node.upgradeStatusTo(Status.NONE) n.upgradeStatusTo(Status.NONE)
self._taskManager.removeNode(node) self._taskManager.removeNode(n)
self.computeStatusChanged.emit() self.computeStatusChanged.emit()
@ -413,13 +413,15 @@ class UIGraph(QObject):
def cancelNodeComputation(self, node): def cancelNodeComputation(self, node):
""" Cancel the computation of the node and all the nodes depending on it. """ """ Cancel the computation of the node and all the nodes depending on it. """
if node.getGlobalStatus() == Status.SUBMITTED: if node.getGlobalStatus() == Status.SUBMITTED:
# Current node belongs to this list
for node in self._graph.nodesDependingOnNode(node):
# Status from SUBMITTED to NONE # Status from SUBMITTED to NONE
# Make sure to remove the nodes from the Task Manager list
node.clearSubmittedChunks() node.clearSubmittedChunks()
# Make sure to remove the node from the Task Manager list
self._taskManager.removeNode(node) self._taskManager.removeNode(node)
for n in node.getOutputNodes(recursive=True):
n.clearSubmittedChunks()
self._taskManager.removeNode(n)
@Slot(Node) @Slot(Node)
def submit(self, node=None): def submit(self, node=None):
""" Submit the graph to the default Submitter. """ Submit the graph to the default Submitter.