diff --git a/meshroom/core/exception.py b/meshroom/core/exception.py index 06173b01..9bffd49a 100644 --- a/meshroom/core/exception.py +++ b/meshroom/core/exception.py @@ -28,3 +28,18 @@ class NodeUpgradeError(GraphException): if details: msg += ": {}".format(details) super(NodeUpgradeError, self).__init__(msg) + + +class GraphVisitMessage(GraphException): + """ Base class for sending messages via exceptions during a graph visit. """ + pass + + +class StopGraphVisit(GraphVisitMessage): + """ Immediately interrupt graph visit. """ + pass + + +class StopBranchVisit(GraphVisitMessage): + """ Immediately stop branch visit. """ + pass diff --git a/meshroom/core/graph.py b/meshroom/core/graph.py index 0d12b597..0ccabff5 100644 --- a/meshroom/core/graph.py +++ b/meshroom/core/graph.py @@ -14,7 +14,7 @@ import meshroom import meshroom.core from meshroom.common import BaseObject, DictModel, Slot, Signal, Property from meshroom.core.attribute import Attribute, ListAttribute -from meshroom.core.exception import UnknownNodeTypeError +from meshroom.core.exception import StopGraphVisit, StopBranchVisit from meshroom.core.node import node_factory, Status, Node, CompatibilityNode # Replace default encoder to support Enums @@ -586,10 +586,19 @@ class Graph(BaseObject): assert not self.dirtyTopology nodes = sorted(nodes, key=lambda item: item.depth) - for node in nodes: - self.dfsVisit(node, visitor, colors, nodeChildren, longestPathFirst) + try: + for node in nodes: + self.dfsVisit(node, visitor, colors, nodeChildren, longestPathFirst) + except StopGraphVisit: + pass def dfsVisit(self, u, visitor, colors, nodeChildren, longestPathFirst): + try: + self._dfsVisit(u, visitor, colors, nodeChildren, longestPathFirst) + except StopBranchVisit: + pass + + def _dfsVisit(self, u, visitor, colors, nodeChildren, longestPathFirst): colors[u] = GRAY visitor.discoverVertex(u, self) # d_time[u] = time = time + 1