Ignore "Publish" nodes when loading a template unless specified otherwise

This commit adds an option to the "load" method, "publishOutputs", that
determines whether "Publish" nodes in a template project file should be
ignored during the graph's creation.

If "publishOutputs=True", then the "Publish" nodes from the template will
be added to the graph. "Publish" nodes in a project file that is not
a template will not be affected by this and will always be added to the
graph, as any other node.

This allows to have templates that are compatible with meshroom_batch,
which requires a "Publish" node when the --output option is specified,
while not having unneeded nodes in the UI or unneeded operations:
when --output is specified in meshroom_batch, "publishOutputs=True",
otherwise it will be set to False so that the "Publish" nodes are not
executed needlessly.
This commit is contained in:
Candice Bentéjac 2023-02-27 18:34:51 +01:00
parent fd5fc8e3ba
commit 99b82e601f
4 changed files with 24 additions and 18 deletions

View file

@ -241,7 +241,7 @@ class Graph(BaseObject):
return Graph.IO.getFeaturesForVersion(self.header.get(Graph.IO.Keys.FileVersion, "0.0"))
@Slot(str)
def load(self, filepath, setupProjectFile=True, importProject=False):
def load(self, filepath, setupProjectFile=True, importProject=False, publishOutputs=False):
"""
Load a meshroom graph ".mg" file.
@ -249,6 +249,9 @@ class Graph(BaseObject):
filepath: project filepath to load
setupProjectFile: Store the reference to the project file and setup the cache directory.
If false, it only loads the graph of the project file as a template.
importProject: True if the project that is loaded will be imported in the current graph, instead
of opened.
publishOutputs: True if "Publish" nodes from templates should not be ignored.
"""
if not importProject:
self.clear()
@ -284,6 +287,11 @@ class Graph(BaseObject):
if "version" not in nodeData:
nodeData["version"] = nodesVersions.get(nodeData["nodeType"], "0.0")
# if the node is a "Publish" node and comes from a template file, it should be ignored
# unless publishOutputs is True
if isTemplate and not publishOutputs and nodeData["nodeType"] == "Publish":
continue
n = nodeFactory(nodeData, nodeName, template=isTemplate)
# Add node to the graph with raw attributes values