From 4c322b3e39fc7ac5cd7b9afc6c6ce4d1adf404c8 Mon Sep 17 00:00:00 2001 From: Filip Leonarski Date: Fri, 20 Nov 2026 02:41:11 +0100 Subject: [PATCH] jfjoch_viewer: list every format it opens in the file browser and the open dialog The file browser listed only *_master.h5, *_process.h5 and *.cbf, and the open dialog had no filter covering frames numbered in their extension, so a marCCD or ADSC sweep written as name.001 / name.0001 was invisible in both, as were .cbf.gz, .mccd, .osc, .sfrm, .nxs, .cxi and .xtc in the browser. One list of wildcards (reader/FileNamePatterns.h) now serves both: the HDF5 masters and processing results, .nxs, .cxi, .xtc, the raw frame extensions and frame numbers of three to five digits. The open dialog offers it first as "All supported", plus any .h5 and .geom for the files of an XFEL run. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01HVeDQrPqZ52Tp6rzzZGxf3 --- reader/CMakeLists.txt | 1 + reader/FileNamePatterns.h | 20 ++++++++++++++++++++ viewer/JFJochViewerMenu.cpp | 11 +++++++++-- viewer/widgets/JFJochViewerFileBrowser.cpp | 12 ++++++++---- viewer/widgets/JFJochViewerFileBrowser.h | 3 +-- 5 files changed, 39 insertions(+), 8 deletions(-) create mode 100644 reader/FileNamePatterns.h diff --git a/reader/CMakeLists.txt b/reader/CMakeLists.txt index 5c098bbea..ad5ec4954 100644 --- a/reader/CMakeLists.txt +++ b/reader/CMakeLists.txt @@ -38,6 +38,7 @@ ADD_LIBRARY(JFJochReader STATIC SFRM.h JFJochSFRMReader.cpp JFJochSFRMReader.h + FileNamePatterns.h HDF5ImageLocator.cpp JFJochStartMessageReader.cpp JFJochStartMessageReader.h diff --git a/reader/FileNamePatterns.h b/reader/FileNamePatterns.h new file mode 100644 index 000000000..bb214cb1c --- /dev/null +++ b/reader/FileNamePatterns.h @@ -0,0 +1,20 @@ +// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute +// SPDX-License-Identifier: GPL-3.0-only + +#pragma once + +#include +#include + +// The files the viewer lists as openable, as wildcards in the QDir name-filter syntax. Only what is +// listed is decided here: the readers tell the formats apart by content (.img is miniCBF, marCCD or +// SMV depending on the writer). +// +// An HDF5 dataset is opened by its master or its processing result, never by the _data_NNNNNN.h5 +// shards a master links to. A raw frame is one image per file, and naming any frame opens its whole +// sweep; the marCCD and ADSC software number a frame in its extension ("name.001", "name.0001"). +inline const std::vector OPENABLE_FILE_PATTERNS = { + "*_master.h5", "*_process.h5", "*.nxs", "*.cxi", "*.xtc", + "*.cbf", "*.cbf.gz", "*.img", "*.mccd", "*.marccd", "*.tif", "*.tiff", "*.smv", "*.osc", "*.sfrm", + "*.[0-9][0-9][0-9]", "*.[0-9][0-9][0-9][0-9]", "*.[0-9][0-9][0-9][0-9][0-9]" +}; diff --git a/viewer/JFJochViewerMenu.cpp b/viewer/JFJochViewerMenu.cpp index f25a4f804..980bcd5f0 100644 --- a/viewer/JFJochViewerMenu.cpp +++ b/viewer/JFJochViewerMenu.cpp @@ -27,6 +27,7 @@ #include "windows/JFJochAcknowledgementWindow.h" #include "../common/GitInfo.h" #include "../common/CUDAWrapper.h" +#include "../reader/FileNamePatterns.h" JFJochViewerMenu::JFJochViewerMenu(QWidget *parent) : QMenuBar(parent) { // Create "File" menu @@ -261,12 +262,18 @@ void JFJochViewerMenu::acknowledgementsSelected() { void JFJochViewerMenu::openSelected() { // Several files are one dataset: the files of a serial XFEL run (SACLA HDF5, CXI, XTC), opened as // rugnux opens them, with a CrystFEL geometry file among them taken as their module geometry. + // A raw frame is one image per file: picking any frame opens the sweep it belongs to. Any .h5 and + // a .geom are offered as well, for the files of an XFEL run. + QStringList supported; + for (const auto &p: OPENABLE_FILE_PATTERNS) + supported << QString::fromStdString(p); + supported << "*.h5" << "*.geom"; const QStringList fileNames = QFileDialog::getOpenFileNames( this, "Open File(s)", // Dialog title "", // Default folder - // A CBF is one frame per file: picking any frame opens the sweep it belongs to. - "HDF5 Master Files (*_master.h5 *_process.h5);; HDF5 Files (*.h5);; CBF Images (*.cbf *.cbf.gz);; CCD Images (*.img *.mccd *.smv);; XFEL Stills (*.h5 *.cxi *.xtc *.geom);;All Files (*)" + "All supported (" + supported.join(' ') + ");;HDF5 Master Files (*_master.h5 *_process.h5);;" + "XFEL Stills (*.h5 *.cxi *.xtc *.geom);;All Files (*)" ); if (!fileNames.isEmpty()) { diff --git a/viewer/widgets/JFJochViewerFileBrowser.cpp b/viewer/widgets/JFJochViewerFileBrowser.cpp index 4739968ca..a60cdb1c6 100644 --- a/viewer/widgets/JFJochViewerFileBrowser.cpp +++ b/viewer/widgets/JFJochViewerFileBrowser.cpp @@ -21,6 +21,8 @@ #include #include +#include "../../reader/FileNamePatterns.h" + namespace { constexpr auto kDataRootEnvVar = "JUNGFRAUJOCH_DATA_ROOT"; constexpr auto kSettingsKey = "fileBrowserRoot"; @@ -101,10 +103,12 @@ JFJochViewerFileBrowser::JFJochViewerFileBrowser(QWidget *parent) : QWidget(pare model_ = new QFileSystemModel(this); model_->setFilter(QDir::AllDirs | QDir::Files | QDir::NoDotAndDotDot); - // Directories are always listed regardless of these; only *_master.h5 / *_process.h5 and - // miniCBF frames among files. The many _data_NNNNNN.h5 shards of a dataset are not meant to be - // opened directly; a .cbf is one frame per file, and opening any of them opens its whole sweep. - model_->setNameFilters({"*_master.h5", "*_process.h5", "*.cbf"}); + // Directories are always listed regardless of these; among files only those the viewer opens + // (FileNamePatterns.h). + QStringList patterns; + for (const auto &p: OPENABLE_FILE_PATTERNS) + patterns << QString::fromStdString(p); + model_->setNameFilters(patterns); model_->setNameFilterDisables(false); // hide non-matching files rather than just greying them out proxy_ = new FileOnlyFilterProxy(this); diff --git a/viewer/widgets/JFJochViewerFileBrowser.h b/viewer/widgets/JFJochViewerFileBrowser.h index fddabea33..8361c7694 100644 --- a/viewer/widgets/JFJochViewerFileBrowser.h +++ b/viewer/widgets/JFJochViewerFileBrowser.h @@ -14,8 +14,7 @@ class QTreeView; class QModelIndex; // Left-side dock alternative to the Processing (reprocessing settings) panel: a directory tree rooted at a -// configurable data root, filtered down to subdirectories and *_master.h5 / *_process.h5 / *.cbf -// files, for browsing to and opening a dataset without caring about reprocessing. Backed by QFileSystemModel, +// configurable data root, filtered down to subdirectories and the files the viewer opens, for browsing to and opening a dataset without caring about reprocessing. Backed by QFileSystemModel, // which only lists a directory once it is expanded - so a root with hundreds of sibling directories // (e.g. an SLS beamline's /sls/mx/data/) costs one readdir at each level actually opened, never a // recursive scan of the whole tree.