[ui] save after drag&drop: meshroom scenes detected as separated type of file

In FilesByType, new attribute meshroomScene allowing to detected
separately the meshroom scenes from the other types of file.
This commit is contained in:
Aurore LAFAURIE 2024-03-22 10:43:36 +01:00
parent 58e9bafa45
commit b74cada8ef
4 changed files with 30 additions and 21 deletions

View file

@ -69,6 +69,7 @@ videoExtensions = (
'.mxf', '.mxf',
) )
panoramaInfoExtensions = ('.xml') panoramaInfoExtensions = ('.xml')
meshroomSceneExtensions = ('.mg')
def hasExtension(filepath, extensions): def hasExtension(filepath, extensions):
@ -81,15 +82,17 @@ class FilesByType:
self.images = [] self.images = []
self.videos = [] self.videos = []
self.panoramaInfo = [] self.panoramaInfo = []
self.meshroomScene = []
self.other = [] self.other = []
def __bool__(self): def __bool__(self):
return self.images or self.videos or self.panoramaInfo return self.images or self.videos or self.panoramaInfo or self.meshroomScene
def extend(self, other): def extend(self, other):
self.images.extend(other.images) self.images.extend(other.images)
self.videos.extend(other.videos) self.videos.extend(other.videos)
self.panoramaInfo.extend(other.panoramaInfo) self.panoramaInfo.extend(other.panoramaInfo)
self.meshroomScene.extend(other.meshroomScene)
self.other.extend(other.other) self.other.extend(other.other)
def addFile(self, file): def addFile(self, file):
@ -99,6 +102,8 @@ class FilesByType:
self.videos.append(file) self.videos.append(file)
elif hasExtension(file, panoramaInfoExtensions): elif hasExtension(file, panoramaInfoExtensions):
self.panoramaInfo.append(file) self.panoramaInfo.append(file)
elif hasExtension(file, meshroomSceneExtensions):
self.meshroomScene.append(file)
else: else:
self.other.append(file) self.other.append(file)

View file

@ -82,7 +82,7 @@ Item {
onAllViewpointsCleared: { reconstruction.removeAllImages(); reconstruction.selectedViewId = "-1" } onAllViewpointsCleared: { reconstruction.removeAllImages(); reconstruction.selectedViewId = "-1" }
onFilesDropped: { onFilesDropped: {
var filesByType = _reconstruction.getFilesByTypeFromDrop(drop.urls) var filesByType = _reconstruction.getFilesByTypeFromDrop(drop.urls)
if (filesByType["other"].length > 0) { if (filesByType["meshroomScene"].length == 1) {
ensureSaved(function() { ensureSaved(function() {
reconstruction.handleFilesUrl(filesByType, augmentSfm ? null : cameraInit) reconstruction.handleFilesUrl(filesByType, augmentSfm ? null : cameraInit)
}) })

View file

@ -1188,7 +1188,7 @@ ApplicationWindow {
} }
onFilesDropped: { onFilesDropped: {
var filesByType = _reconstruction.getFilesByTypeFromDrop(drop.urls) var filesByType = _reconstruction.getFilesByTypeFromDrop(drop.urls)
if (filesByType["other"].length > 0) { if (filesByType["meshroomScene"].length == 1) {
ensureSaved(function() { ensureSaved(function() {
_reconstruction.handleFilesUrl(filesByType, null, mousePosition) _reconstruction.handleFilesUrl(filesByType, null, mousePosition)
}) })

View file

@ -785,24 +785,28 @@ class Reconstruction(UIGraph):
"", "",
)) ))
if not filesByType["images"] and not filesByType["videos"] and not filesByType["panoramaInfo"]: if filesByType["meshroomScene"]:
if filesByType["other"]: if len(filesByType["meshroomScene"]) > 1:
singleMgFile = False self.error.emit(
if len(filesByType["other"]) == 1: Message(
url = filesByType["other"][0] "Too much Meshroom Scenes",
ext = os.path.splitext(url)[1] "You should only import 1 .mg file"
if ext == '.mg':
self.loadUrl(url)
singleMgFile = True
if not singleMgFile:
extensions = set([os.path.splitext(url)[1] for url in filesByType["other"]])
self.error.emit(
Message(
"No Recognized Input File",
"No recognized input file in the {} dropped files".format(len(filesByType["other"])),
"Unknown file extensions: " + ', '.join(extensions)
)
) )
)
else:
self.loadUrl(filesByType["meshroomScene"][0])
if not filesByType["images"] and not filesByType["videos"] and not filesByType["panoramaInfo"] and not filesByType["meshroomScene"]:
if filesByType["other"]:
extensions = set([os.path.splitext(url)[1] for url in filesByType["other"]])
self.error.emit(
Message(
"No Recognized Input File",
"No recognized input file in the {} dropped files".format(len(filesByType["other"])),
"Unknown file extensions: " + ', '.join(extensions)
)
)
@Slot("QList<QUrl>", result="QVariantMap") @Slot("QList<QUrl>", result="QVariantMap")
def getFilesByTypeFromDrop(self, urls): def getFilesByTypeFromDrop(self, urls):
@ -822,7 +826,7 @@ class Reconstruction(UIGraph):
filesByType.extend(multiview.findFilesByTypeInFolder(localFile)) filesByType.extend(multiview.findFilesByTypeInFolder(localFile))
else: else:
filesByType.addFile(localFile) filesByType.addFile(localFile)
return {"images": filesByType.images, "videos": filesByType.videos, "panoramaInfo":filesByType.panoramaInfo, "other":filesByType.other} return {"images": filesByType.images, "videos": filesByType.videos, "panoramaInfo": filesByType.panoramaInfo, "meshroomScene": filesByType.meshroomScene, "other": filesByType.other}
def importImagesFromFolder(self, path, recursive=False): def importImagesFromFolder(self, path, recursive=False):
""" """