mirror of
https://github.com/alicevision/Meshroom.git
synced 2025-04-29 18:27:23 +02:00
[core] add GraphVisitMessage exceptions mecanism
allow to stop branch or graph visit by throwing specific exceptions in visitor callbacks
This commit is contained in:
parent
52d1d1fb89
commit
ab4e82aa88
2 changed files with 27 additions and 3 deletions
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
||||
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
|
||||
|
|
Loading…
Add table
Reference in a new issue