From f41565f26b1f764c83701828f10347b7f2df8ae9 Mon Sep 17 00:00:00 2001 From: Julien-Haudegond <44610840+Julien-Haudegond@users.noreply.github.com> Date: Thu, 20 Aug 2020 16:20:55 +0200 Subject: [PATCH] [ui] Graph: stop and cancel node computation --- meshroom/ui/graph.py | 31 +++++++++++++++++++++ meshroom/ui/qml/GraphEditor/GraphEditor.qml | 14 ++++++++++ 2 files changed, 45 insertions(+) diff --git a/meshroom/ui/graph.py b/meshroom/ui/graph.py index 4b4bacc3..38752ee1 100644 --- a/meshroom/ui/graph.py +++ b/meshroom/ui/graph.py @@ -389,6 +389,37 @@ class UIGraph(QObject): self._taskManager._thread.join() self.computeStatusChanged.emit() + @Slot(Node) + def stopNodeComputation(self, node): + """ Stop the computation of the node and update all the nodes depending on it. """ + if not self.isComputingLocally(): + return + + # Stop the node and wait Task Manager + node.stopComputation() + self._taskManager._thread.join() + + # If some dependent nodes are submitted, the first one will be in error + # Make sure to remove those nodes from the Task Manager list + dependentNodes = self._graph.nodesDependingOnNode(node) + for node in dependentNodes[1:]: # exclude current node + if node.getGlobalStatus() == Status.ERROR: + node.upgradeStatusTo(Status.NONE) + self._taskManager.removeNode(node) + + self.computeStatusChanged.emit() + + @Slot(Node) + def cancelNodeComputation(self, node): + """ Cancel the computation of the node and all the nodes depending on it. """ + if node.getGlobalStatus() == Status.SUBMITTED: + # Current node belongs to this list + for node in self._graph.nodesDependingOnNode(node): + # Status from SUBMITTED to NONE + node.clearSubmittedChunks() + # Make sure to remove the node from the Task Manager list + self._taskManager.removeNode(node) + @Slot(Node) def submit(self, node=None): """ Submit the graph to the default Submitter. diff --git a/meshroom/ui/qml/GraphEditor/GraphEditor.qml b/meshroom/ui/qml/GraphEditor/GraphEditor.qml index 1e465f35..e48e4ada 100755 --- a/meshroom/ui/qml/GraphEditor/GraphEditor.qml +++ b/meshroom/ui/qml/GraphEditor/GraphEditor.qml @@ -289,6 +289,20 @@ Item { height: visible ? implicitHeight : 0 onTriggered: submitRequest(nodeMenu.currentNode) } + MenuItem { + text: "Stop Computation" + enabled: nodeMenu.currentNode ? nodeMenu.currentNode.globalStatus === "RUNNING" && nodeMenu.currentNode.globalExecMode === "LOCAL" : false + visible: enabled + height: visible ? implicitHeight : 0 + onTriggered: uigraph.stopNodeComputation(nodeMenu.currentNode) + } + MenuItem { + text: "Cancel Computation" + enabled: nodeMenu.currentNode ? nodeMenu.currentNode.globalStatus === "SUBMITTED" && nodeMenu.currentNode.globalExecMode === "LOCAL" : false + visible: enabled + height: visible ? implicitHeight : 0 + onTriggered: uigraph.cancelNodeComputation(nodeMenu.currentNode) + } MenuItem { text: "Open Folder" onTriggered: Qt.openUrlExternally(Filepath.stringToUrl(nodeMenu.currentNode.internalFolder))