From d2417e4ac6ae9905e6b3c255e8c18f7204ed8add Mon Sep 17 00:00:00 2001 From: Yann Lanthony Date: Tue, 19 Dec 2017 14:59:12 +0100 Subject: [PATCH] [core] add optional 'name' argument to addNewNode method allow to create a new node with a target name, that will get prefixed if not unique --- meshroom/core/graph.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/meshroom/core/graph.py b/meshroom/core/graph.py index 4cb8f272..93960e09 100644 --- a/meshroom/core/graph.py +++ b/meshroom/core/graph.py @@ -1128,16 +1128,21 @@ class Graph(BaseObject): return inEdges, outEdges - @Slot(str, result=Node) - def addNewNode(self, nodeType, **kwargs): + def addNewNode(self, nodeDesc, name=None, **kwargs): """ + Create and add a new node to the graph. - :param nodeType: - :param kwargs: - :return: - :rtype: Node + Args: + nodeDesc (desc.Node): the node description to use. + name (str): if specified, the desired name for this node. If not unique, will be prefixed (_N). + **kwargs: keyword arguments to initialize node's attributes + + Returns: + The newly created node. """ - n = self.addNode(Node(nodeDesc=nodeType, **kwargs)) + if name and name in self._nodes.keys(): + name = self._createUniqueNodeName(name) + n = self.addNode(Node(nodeDesc=nodeDesc, **kwargs), uniqueName=name) n.updateInternals() return n