Skip to content

Commit

Permalink
[ui] Generate the "New Pipeline" menu based on the found project files
Browse files Browse the repository at this point in the history
The "New Pipeline" menu is automatically filled with the list
of the project files that were found dynamically. Pipelines can thus
be initialized with templates without restarting Meshroom app.
  • Loading branch information
cbentejac committed Jul 13, 2022
1 parent 8fb0c77 commit c29574b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 30 deletions.
15 changes: 15 additions & 0 deletions meshroom/ui/app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import os
import re
import argparse

from PySide2.QtCore import Qt, QUrl, Slot, QJsonValue, Property, Signal, qInstallMessageHandler, QtMsgType, QSettings
Expand Down Expand Up @@ -177,6 +178,18 @@ def __init__(self, args):

self.engine.load(os.path.normpath(url))


def _pipelineTemplateFiles(self):
templates = []
for key in sorted(meshroom.core.pipelineTemplates.keys()):
# Use uppercase letters in the names as separators to format the templates' name nicely
# e.g: the template "panoramaHdr" will be shown as "Panorama Hdr" in the menu
name = " ".join(re.findall('[A-Z][^A-Z]*', key[0].upper() + key[1:]))
variant = {"name": name, "key": key, "path": meshroom.core.pipelineTemplates[key]}
templates.append(variant)
return templates


def _recentProjectFiles(self):
projects = []
settings = QSettings()
Expand Down Expand Up @@ -318,5 +331,7 @@ def licensesModel(self):
]

recentProjectFilesChanged = Signal()
pipelineTemplateFilesChanged = Signal()
recentProjectFiles = Property("QVariantList", _recentProjectFiles, notify=recentProjectFilesChanged)
pipelineTemplateFiles = Property("QVariantList", _pipelineTemplateFiles, notify=pipelineTemplateFilesChanged)

60 changes: 30 additions & 30 deletions meshroom/ui/qml/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -409,38 +409,38 @@ ApplicationWindow {
onTriggered: ensureSaved(function() { _reconstruction.new() })
}
Menu {
id: newPipelineMenu
title: "New Pipeline"
TextMetrics {
id: textMetrics
font: action_PG_CT.font
elide: Text.ElideNone
text: action_PG_CT.text
}
implicitWidth: textMetrics.width + 10 // largest text width + margin
Action {
text: "Photogrammetry"
onTriggered: ensureSaved(function() { _reconstruction.new("photogrammetry") })
}
Action {
text: "Panorama HDR"
onTriggered: ensureSaved(function() { _reconstruction.new("panoramahdr") })
}
Action {
text: "Panorama Fisheye HDR"
onTriggered: ensureSaved(function() { _reconstruction.new("panoramafisheyehdr") })
}
Action {
id: action_PG_CT
text: "Photogrammetry and Camera Tracking (experimental)"
onTriggered: ensureSaved(function() { _reconstruction.new("photogrammetryandcameratracking") })
}
Action {
text: "Camera Tracking (experimental)"
onTriggered: ensureSaved(function() { _reconstruction.new("cameratracking") })
enabled: newPipelineMenuItems.model != undefined && newPipelineMenuItems.model.length > 0
property int maxWidth: 1000
property int fullWidth: {
var result = 0;
for (var i = 0; i < count; ++i) {
var item = itemAt(i);
result = Math.max(item.implicitWidth + item.padding * 2, result);
}
return result;
}
Action {
text: "Photogrammetry Draft (No CUDA)"
onTriggered: ensureSaved(function() { _reconstruction.new("photogrammetrydraft") })
implicitWidth: fullWidth
Repeater {
id: newPipelineMenuItems
model: MeshroomApp.pipelineTemplateFiles
MenuItem {
onTriggered: ensureSaved(function() {
_reconstruction.new(modelData["key"])
})

text: fileTextMetrics.elidedText
TextMetrics {
id: fileTextMetrics
text: modelData["name"]
elide: Text.ElideLeft
elideWidth: newPipelineMenu.maxWidth
}
ToolTip.text: modelData["path"]
ToolTip.visible: hovered
ToolTip.delay: 200
}
}
}
Action {
Expand Down

0 comments on commit c29574b

Please sign in to comment.