[ui][commands] expose UpgradeNode command

This commit is contained in:
Yann Lanthony 2018-07-15 13:30:45 +02:00
parent 1d309136ec
commit a18d75c0f9
2 changed files with 34 additions and 1 deletions

View file

@ -229,6 +229,34 @@ class ListAttributeRemoveCommand(GraphCommand):
listAttribute.insert(self.index, self.value)
class UpgradeNodeCommand(GraphCommand):
"""
Perform node upgrade on a CompatibilityNode.
"""
def __init__(self, graph, node, parent=None):
super(UpgradeNodeCommand, self).__init__(graph, parent)
self.nodeDict = node.toDict()
self.nodeName = node.getName()
self.outEdges = {}
self.setText("Upgrade Node {}".format(self.nodeName))
def redoImpl(self):
inEdges, self.outEdges = self.graph.upgradeNode(self.nodeName)
return True
def undoImpl(self):
# delete upgraded node
self.graph.removeNode(self.nodeName)
# recreate compatibility node
with GraphModification(self.graph):
node = node_factory(self.nodeDict)
self.graph.addNode(node, self.nodeName)
# recreate out edges
for dstAttr, srcAttr in self.outEdges.items():
self.graph.addEdge(self.graph.attribute(srcAttr),
self.graph.attribute(dstAttr))
class EnableGraphUpdateCommand(GraphCommand):
""" Command to enable/disable graph update.
Should not be used directly, use GroupedGraphModification context manager instead.

View file

@ -9,7 +9,7 @@ from PySide2.QtCore import Slot, QJsonValue, QObject, QUrl, Property, Signal
from meshroom.common.qt import QObjectListModel
from meshroom.core.attribute import Attribute, ListAttribute
from meshroom.core.graph import Graph, Edge, submitGraph, executeGraph
from meshroom.core.node import NodeChunk, Node, Status
from meshroom.core.node import NodeChunk, Node, Status, CompatibilityNode
from meshroom.ui import commands
@ -353,6 +353,11 @@ class UIGraph(QObject):
"""
return self.duplicateNodesFromNode(fromNode).values()
@Slot(CompatibilityNode)
def upgradeNode(self, node):
""" Upgrade a CompatibilityNode. """
self.push(commands.UpgradeNodeCommand(self._graph, node))
@Slot(Attribute, QJsonValue)
def appendAttribute(self, attribute, value=QJsonValue()):
if isinstance(value, QJsonValue):