diff --git a/meshroom/core/graph.py b/meshroom/core/graph.py index bbf6960a..d92555a2 100644 --- a/meshroom/core/graph.py +++ b/meshroom/core/graph.py @@ -442,6 +442,13 @@ class Graph(BaseObject): return inEdges, outEdges + def upgradeAllNodes(self): + """ Upgrade all upgradable CompatibilityNode instances in the graph. """ + nodeNames = [name for name, n in self._compatibilityNodes.items() if n.canUpgrade] + with GraphModification(self): + for nodeName in nodeNames: + self.upgradeNode(nodeName) + @Slot(str, result=Attribute) def attribute(self, fullName): # type: (str) -> Attribute diff --git a/meshroom/ui/commands.py b/meshroom/ui/commands.py index a0a4e453..1c1a851c 100755 --- a/meshroom/ui/commands.py +++ b/meshroom/ui/commands.py @@ -270,6 +270,8 @@ class UpgradeNodeCommand(GraphCommand): self.setText("Upgrade Node {}".format(self.nodeName)) def redoImpl(self): + if not self.graph.node(self.nodeName).canUpgrade: + return False inEdges, self.outEdges = self.graph.upgradeNode(self.nodeName) return True diff --git a/meshroom/ui/graph.py b/meshroom/ui/graph.py index 998e17b2..45bfd114 100644 --- a/meshroom/ui/graph.py +++ b/meshroom/ui/graph.py @@ -302,6 +302,14 @@ class UIGraph(QObject): """ Upgrade a CompatibilityNode. """ self.push(commands.UpgradeNodeCommand(self._graph, node)) + @Slot() + def upgradeAllNodes(self): + """ Upgrade all upgradable CompatibilityNode instances in the graph. """ + with self.groupedGraphModification("Upgrade all Nodes"): + nodes = [n for n in self._graph._compatibilityNodes.values() if n.canUpgrade] + for node in nodes: + self.upgradeNode(node) + @Slot(Attribute, QJsonValue) def appendAttribute(self, attribute, value=QJsonValue()): if isinstance(value, QJsonValue): diff --git a/tests/test_compatibility.py b/tests/test_compatibility.py index 541dbce6..307331ce 100644 --- a/tests/test_compatibility.py +++ b/tests/test_compatibility.py @@ -112,3 +112,40 @@ def test_description_conflict(): assert hasattr(n, "in") # check uid has changed (not the same set of attributes) assert n.internalFolder != internalFolder + unregisterNodeType(SampleNodeV1) + + +def test_upgradeAllNodes(): + registerNodeType(SampleNodeV1) + registerNodeType(SampleNodeV2) + + g = Graph('') + n1 = g.addNewNode("SampleNodeV1") + n2 = g.addNewNode("SampleNodeV2") + n1Name = n1.name + n2Name = n2.name + graphFile = os.path.join(tempfile.mkdtemp(), "test_description_conflict.mg") + g.save(graphFile) + + # make SampleNodeV2 an unknown type + unregisterNodeType(SampleNodeV2) + # replace SampleNodeV1 by SampleNodeV2 + meshroom.core.nodesDesc[SampleNodeV1.__name__] = SampleNodeV2 + + # reload file + g = loadGraph(graphFile) + os.remove(graphFile) + + # both nodes are CompatibilityNodes + assert len(g.compatibilityNodes) == 2 + assert g.node(n1Name).canUpgrade # description conflict + assert not g.node(n2Name).canUpgrade # unknown type + + # upgrade all upgradable nodes + g.upgradeAllNodes() + + # only the node with an unknown type has not been upgraded + assert len(g.compatibilityNodes) == 1 + assert n2Name in g.compatibilityNodes.keys() + + unregisterNodeType(SampleNodeV1)