From a5c18606bc92e5c4ccc301a676d8f9f6fe77dd39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Vital?= Date: Thu, 22 Sep 2022 16:42:46 +0200 Subject: [PATCH 1/3] use most recent project as base folder when using Open action --- meshroom/ui/qml/main.qml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/meshroom/ui/qml/main.qml b/meshroom/ui/qml/main.qml index 4dbfe6f5f8..4f0a13e70f 100755 --- a/meshroom/ui/qml/main.qml +++ b/meshroom/ui/qml/main.qml @@ -512,9 +512,14 @@ ApplicationWindow { shortcut: "Ctrl+O" onTriggered: ensureSaved(function() { if(_reconstruction.graph && _reconstruction.graph.filepath) { - openFileDialog.folder = Filepath.stringToUrl(Filepath.dirname(_reconstruction.graph.filepath)) + openFileDialog.folder = Filepath.stringToUrl(Filepath.dirname(_reconstruction.graph.filepath)); + } else { + var projects = MeshroomApp.recentProjectFiles; + if (projects.length > 0 && Filepath.exists(projects[0])) { + openFileDialog.folder = Filepath.stringToUrl(Filepath.dirname(projects[0])); + } } - openFileDialog.open() + openFileDialog.open(); }) } Menu { From f4352e5254905b44a6249bf4a6527466800f0463 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Vital?= Date: Fri, 23 Sep 2022 09:39:22 +0200 Subject: [PATCH 2/3] [ui] file dialogs: use most recent project dir instead of system default --- meshroom/ui/qml/main.qml | 48 ++++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/meshroom/ui/qml/main.qml b/meshroom/ui/qml/main.qml index 4f0a13e70f..eab3cc7470 100755 --- a/meshroom/ui/qml/main.qml +++ b/meshroom/ui/qml/main.qml @@ -462,6 +462,20 @@ ApplicationWindow { onTriggered: _PaletteManager.togglePalette() } + + // Utility functions for elements in the menubar + + function initFileDialogFolder(dialog) { + if(_reconstruction.graph && _reconstruction.graph.filepath) { + dialog.folder = Filepath.stringToUrl(Filepath.dirname(_reconstruction.graph.filepath)); + } else { + var projects = MeshroomApp.recentProjectFiles; + if (projects.length > 0 && Filepath.exists(projects[0])) { + dialog.folder = Filepath.stringToUrl(Filepath.dirname(projects[0])); + } + } + } + header: MenuBar { palette.window: Qt.darker(activePalette.window, 1.15) Menu { @@ -511,14 +525,7 @@ ApplicationWindow { text: "Open" shortcut: "Ctrl+O" onTriggered: ensureSaved(function() { - if(_reconstruction.graph && _reconstruction.graph.filepath) { - openFileDialog.folder = Filepath.stringToUrl(Filepath.dirname(_reconstruction.graph.filepath)); - } else { - var projects = MeshroomApp.recentProjectFiles; - if (projects.length > 0 && Filepath.exists(projects[0])) { - openFileDialog.folder = Filepath.stringToUrl(Filepath.dirname(projects[0])); - } - } + initFileDialogFolder(openFileDialog); openFileDialog.open(); }) } @@ -566,13 +573,19 @@ ApplicationWindow { id: importSceneAction text: "Import Scene" shortcut: "Ctrl+Shift+I" - onTriggered: importSceneDialog.open() + onTriggered: { + initFileDialogFolder(importSceneDialog); + importSceneDialog.open(); + } } Action { id: importActionItem text: "Import Images" shortcut: "Ctrl+I" - onTriggered: importFilesDialog.open() + onTriggered: { + initFileDialogFolder(importFilesDialog); + importFilesDialog.open(); + } } Action { @@ -609,7 +622,8 @@ ApplicationWindow { } else { - saveFileDialog.open() + initFileDialogFolder(saveFileDialog); + saveFileDialog.open(); } } } @@ -618,10 +632,8 @@ ApplicationWindow { text: "Save As..." shortcut: "Ctrl+Shift+S" onTriggered: { - if(_reconstruction.graph && _reconstruction.graph.filepath) { - saveFileDialog.folder = Filepath.stringToUrl(Filepath.dirname(_reconstruction.graph.filepath)) - } - saveFileDialog.open() + initFileDialogFolder(saveFileDialog); + saveFileDialog.open(); } } Action { @@ -629,10 +641,8 @@ ApplicationWindow { text: "Save As Template..." shortcut: "Ctrl+Shift+T" onTriggered: { - if(_reconstruction.graph && _reconstruction.graph.filepath) { - saveTemplateDialog.folder = Filepath.stringToUrl(Filepath.dirname(_reconstruction.graph.filepath)) - } - saveTemplateDialog.open() + initFileDialogFolder(saveTemplateDialog); + saveTemplateDialog.open(); } } MenuSeparator { } From d0fcb67d1cfc5afe66b602a9e29d4bd746367086 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Vital?= Date: Fri, 23 Sep 2022 11:22:36 +0200 Subject: [PATCH 3/3] [ui] rename Import Scene to Import Project for coherent naming --- meshroom/core/graph.py | 20 ++++++++++---------- meshroom/ui/commands.py | 12 ++++++------ meshroom/ui/graph.py | 4 ++-- meshroom/ui/qml/main.qml | 16 ++++++++-------- 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/meshroom/core/graph.py b/meshroom/core/graph.py index 8b7e84878c..e2a75eddde 100644 --- a/meshroom/core/graph.py +++ b/meshroom/core/graph.py @@ -241,7 +241,7 @@ def fileFeatures(self): return Graph.IO.getFeaturesForVersion(self.header.get(Graph.IO.Keys.FileVersion, "0.0")) @Slot(str) - def load(self, filepath, setupProjectFile=True, importScene=False): + def load(self, filepath, setupProjectFile=True, importProject=False): """ Load a meshroom graph ".mg" file. @@ -250,7 +250,7 @@ def load(self, filepath, setupProjectFile=True, importScene=False): 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. """ - if not importScene: + if not importProject: self.clear() with open(filepath) as jsonFile: fileData = json.load(jsonFile) @@ -258,9 +258,9 @@ def load(self, filepath, setupProjectFile=True, importScene=False): # older versions of Meshroom files only contained the serialized nodes graphData = fileData.get(Graph.IO.Keys.Graph, fileData) - if importScene: + if importProject: self._importedNodes.clear() - graphData = self.updateImportedScene(graphData) + graphData = self.updateImportedProject(graphData) if not isinstance(graphData, dict): raise RuntimeError('loadGraph error: Graph is not a dict. File: {}'.format(filepath)) @@ -289,7 +289,7 @@ def load(self, filepath, setupProjectFile=True, importScene=False): # Add node to the graph with raw attributes values self._addNode(n, nodeName) - if importScene: + if importProject: self._importedNodes.add(n) # Create graph edges by resolving attributes expressions @@ -302,12 +302,12 @@ def load(self, filepath, setupProjectFile=True, importScene=False): return True - def updateImportedScene(self, data): + def updateImportedProject(self, data): """ - Update the names and links of the scene to import so that it can fit + Update the names and links of the project to import so that it can fit correctly in the existing graph. - Parse all the nodes from the scene that is going to be imported. + Parse all the nodes from the project that is going to be imported. If their name already exists in the graph, replace them with new names, then parse all the nodes' inputs/outputs to replace the old names with the new ones in the links. @@ -336,7 +336,7 @@ def createUniqueNodeName(nodeNames, inputName): # First pass to get all the names that already exist in the graph, update them, and keep track of the changes for nodeName, nodeData in sorted(data.items(), key=lambda x: self.getNodeIndexFromName(x[0])): if not isinstance(nodeData, dict): - raise RuntimeError('updateImportedScene error: Node is not a dict.') + raise RuntimeError('updateImportedProject error: Node is not a dict.') if nodeName in self._nodes.keys() or nodeName in updatedData.keys(): newName = createUniqueNodeName(self._nodes.keys(), nodeData["nodeType"]) @@ -1403,7 +1403,7 @@ def edges(self): @property def importedNodes(self): - """" Return the list of nodes that were added to the graph with the latest 'Import Scene' action. """ + """" Return the list of nodes that were added to the graph with the latest 'Import Project' action. """ return self._importedNodes @property diff --git a/meshroom/ui/commands.py b/meshroom/ui/commands.py index c34d674baf..a5db90ae72 100755 --- a/meshroom/ui/commands.py +++ b/meshroom/ui/commands.py @@ -206,7 +206,7 @@ def __init__(self, graph, data, position=None, parent=None): self.nodeNames = [] def redoImpl(self): - data = self.graph.updateImportedScene(self.data) + data = self.graph.updateImportedProject(self.data) nodes = self.graph.pasteNodes(data, self.position) self.nodeNames = [node.name for node in nodes] self.setText("Paste Node{} ({})".format("s" if len(self.nodeNames) > 1 else "", ", ".join(self.nodeNames))) @@ -217,20 +217,20 @@ def undoImpl(self): self.graph.removeNode(name) -class ImportSceneCommand(GraphCommand): +class ImportProjectCommand(GraphCommand): """ - Handle the import of a scene into a Graph. + Handle the import of a project into a Graph. """ def __init__(self, graph, filepath=None, yOffset=0, parent=None): - super(ImportSceneCommand, self).__init__(graph, parent) + super(ImportProjectCommand, self).__init__(graph, parent) self.filepath = filepath self.importedNames = [] self.yOffset = yOffset def redoImpl(self): - status = self.graph.load(self.filepath, setupProjectFile=False, importScene=True) + status = self.graph.load(self.filepath, setupProjectFile=False, importProject=True) importedNodes = self.graph.importedNodes - self.setText("Import Scene ({} nodes)".format(importedNodes.count)) + self.setText("Import Project ({} nodes)".format(importedNodes.count)) lowestY = 0 for node in self.graph.nodes: diff --git a/meshroom/ui/graph.py b/meshroom/ui/graph.py index c615137c4e..16c58dacbf 100644 --- a/meshroom/ui/graph.py +++ b/meshroom/ui/graph.py @@ -354,7 +354,7 @@ def loadGraph(self, filepath, setupProjectFile=True): return status @Slot(QUrl, result=bool) - def importScene(self, filepath): + def importProject(self, filepath): if isinstance(filepath, (QUrl)): # depending how the QUrl has been initialized, # toLocalFile() may return the local path or an empty string @@ -364,7 +364,7 @@ def importScene(self, filepath): else: localFile = filepath yOffset = self.layout.gridSpacing + self.layout.nodeHeight - return self.push(commands.ImportSceneCommand(self._graph, localFile, yOffset=yOffset)) + return self.push(commands.ImportProjectCommand(self._graph, localFile, yOffset=yOffset)) @Slot(QUrl) def saveAs(self, url): diff --git a/meshroom/ui/qml/main.qml b/meshroom/ui/qml/main.qml index eab3cc7470..846605ad0f 100755 --- a/meshroom/ui/qml/main.qml +++ b/meshroom/ui/qml/main.qml @@ -322,12 +322,12 @@ ApplicationWindow { } FileDialog { - id: importSceneDialog - title: "Import Scene" + id: importProjectDialog + title: "Import Project" selectMultiple: false nameFilters: ["Meshroom Graphs (*.mg)"] onAccepted: { - graphEditor.uigraph.importScene(importSceneDialog.fileUrl) + graphEditor.uigraph.importProject(importProjectDialog.fileUrl) } } @@ -451,7 +451,7 @@ ApplicationWindow { Action { id: pasteAction - property string tooltip: "Paste the clipboard content to the scene if it contains valid nodes" + property string tooltip: "Paste the clipboard content to the project if it contains valid nodes" text: "Paste Node(s)" shortcut: "Ctrl+V" onTriggered: graphEditor.pasteNodes() @@ -570,12 +570,12 @@ ApplicationWindow { } } Action { - id: importSceneAction - text: "Import Scene" + id: importProjectAction + text: "Import Project" shortcut: "Ctrl+Shift+I" onTriggered: { - initFileDialogFolder(importSceneDialog); - importSceneDialog.open(); + initFileDialogFolder(importProjectDialog); + importProjectDialog.open(); } } Action {