diff --git a/meshroom/ui/components/filepath.py b/meshroom/ui/components/filepath.py index 233a67f5..1e06d20f 100644 --- a/meshroom/ui/components/filepath.py +++ b/meshroom/ui/components/filepath.py @@ -49,6 +49,12 @@ class FilepathHelper(QObject): """ Returns the extension (.ext) of a pathname """ return os.path.splitext(self.asStr(path))[-1] + @Slot(str, result=str) + @Slot(QUrl, result=str) + def removeExtension(self, path): + """ Returns the pathname without its extension (.ext)""" + return os.path.splitext(self.asStr(path))[0] + @Slot(str, result=bool) @Slot(QUrl, result=bool) def isFile(self, path): diff --git a/meshroom/ui/qml/Viewer/Viewer2D.qml b/meshroom/ui/qml/Viewer/Viewer2D.qml index 96245af1..48835f91 100644 --- a/meshroom/ui/qml/Viewer/Viewer2D.qml +++ b/meshroom/ui/qml/Viewer/Viewer2D.qml @@ -219,37 +219,50 @@ FocusScope { return sourceExternal; } if (_reconstruction && (!displayedNode || outputAttribute.name == "gallery")) { - return getViewpointPath(_reconstruction.selectedViewId); + return Filepath.stringToUrl(getViewpointAttribute("path",_reconstruction.selectedViewId)); } - return getFileAttributePath(displayedNode, outputAttribute.name, _reconstruction ? _reconstruction.selectedViewId : -1); + + var viewId = -1; + var intrinsicId = -1; + var fileName = ""; + if (_reconstruction) { + viewId = _reconstruction.selectedViewId; + intrinsicId = getViewpointAttribute("intrinsicId", viewId); + fileName = Filepath.removeExtension(Filepath.basename(getViewpointAttribute("path",viewId))); + } + var patterns = {"": viewId,"": intrinsicId, "": fileName} + return getFileAttributePath(displayedNode, outputAttribute.name,patterns); } - function getFileAttributePath(node, attrName, viewId) { + function getFileAttributePath(node, attrName, patterns) { // get output attribute with matching name - // and parse its value to get the image filepath + // and parse with the patterns present in the patterns dict if (!node) return ""; for (var i = 0; i < node.attributes.count; i++) { var attr = node.attributes.at(i); if (attr.name == attrName) { - let pattern = String(attr.value).replace("", viewId); - let path = Filepath.globFirst(pattern); + let path = String(attr.value) + for (var key in patterns) { + if (patterns.hasOwnProperty(key)) { + path = path.replace(key, patterns[key]) + } + } return Filepath.stringToUrl(path); } } return ""; } - function getViewpointPath(viewId) { - // get viewpoint from cameraInit with matching id - // and get its image filepath + function getViewpointAttribute(attributeName, viewId) { + // get viewpoint from cameraInit with matching id and return the attribute corresponding to the attributeName for (var i = 0; i < _reconstruction.viewpoints.count; i++) { var vp = _reconstruction.viewpoints.at(i); if (vp.childAttribute("viewId").value == viewId) { - return Filepath.stringToUrl(vp.childAttribute("path").value); + return vp.childAttribute(attributeName).value; } } - return ""; + return undefined; } function getViewpointMetadata(viewId) {