Step toward building jfjoch_viewer on Windows/MSVC. No change to the Linux build: D-Bus stays on by default and the XCB plugin is still used. - CMake: make Qt6::DBus optional via JFJOCH_VIEWER_DBUS (ON on Linux, OFF on Windows/macOS where Qt6::DBus does not exist); compile/link/install the dbus/ adaptor + service file only when enabled. Select the platform integration plugin per-OS (QXcb on Linux, QWindows on Windows, QCocoa on macOS) instead of hard-coding QXcbIntegrationPlugin. - JFJochViewerWindow: wrap the adaptor include and D-Bus registration in #ifdef JFJOCH_VIEWER_DBUS. - JFJochImageReadingWorker: the POSIX open()/fstat()/NFS-errno preflight is now #ifndef _WIN32, with a portable QFileInfo fallback elsewhere; POSIX-only headers are guarded too. - Replace the POSIX M_PI/M_PI_2 extension with C++20 std::numbers::pi across the viewer (not defined by MSVC without _USE_MATH_DEFINES). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
94 lines
3.3 KiB
C++
94 lines
3.3 KiB
C++
// SPDX-FileCopyrightText: 2025 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#include "PowderCalibrationWidget.h"
|
|
#include <QPushButton>
|
|
#include <QGridLayout>
|
|
#include <QLabel>
|
|
#include <numbers>
|
|
|
|
#include "../image_analysis/geom_refinement/AssignSpotsToRings.h"
|
|
|
|
PowderCalibrationWidget::PowderCalibrationWidget(QWidget *parent) : QWidget(parent) {
|
|
auto layout = new QVBoxLayout(this);
|
|
|
|
calibrantCombo = new QComboBox(this);
|
|
updateCalibrantList();
|
|
|
|
auto findBeamCenterButton = new QPushButton("Guess detector calibration", this);
|
|
connect(findBeamCenterButton, &QPushButton::clicked,this, &PowderCalibrationWidget::findBeamCenterClicked);
|
|
|
|
auto optimizeBeamCenterButton = new QPushButton("Refine detector calibration", this);
|
|
connect(optimizeBeamCenterButton, &QPushButton::clicked,this, &PowderCalibrationWidget::optimizeBeamCenterClicked);
|
|
|
|
auto calibrantRingsButton = new QPushButton("Display calibrant rings", this);
|
|
connect(calibrantRingsButton, &QPushButton::clicked, this, [this]() {
|
|
std::vector<float> rings = CalculateXtalRings(GetCalibrant(), 10);
|
|
QVector<float> q_rings;
|
|
for (float ring : rings) {
|
|
q_rings.append(2 * std::numbers::pi / ring);
|
|
}
|
|
emit ringsFromCalibration(q_rings);
|
|
});
|
|
|
|
auto refine_row = new QGridLayout();
|
|
refine_row->setSpacing(12);
|
|
refine_row->addWidget(new QLabel("Calibrant:"),0,0);
|
|
refine_row->addWidget(calibrantCombo,0,1);
|
|
refine_row->addWidget(findBeamCenterButton,1, 0);
|
|
refine_row->addWidget(optimizeBeamCenterButton,1, 1);
|
|
|
|
refine_row->addWidget(calibrantRingsButton,2, 0);
|
|
|
|
layout->addLayout(refine_row);
|
|
setLayout(layout);
|
|
}
|
|
|
|
UnitCell PowderCalibrationWidget::GetCalibrant() const {
|
|
UnitCell uc(LAB6_CELL_A, LAB6_CELL_A, LAB6_CELL_A, 90, 90, 90);
|
|
switch (calibrantCombo->currentIndex()) {
|
|
case 1:
|
|
// T. C. Huang , H. Toraya, T. N. Blanton, Y. Wu, J. Appl. Cryst. 26 (1993), 180-184.
|
|
uc = UnitCell(5.1769, 4.7218, 58.380, 89.440, 89.634, 75.854);
|
|
break;
|
|
case 2:
|
|
if (sample_cell)
|
|
uc = sample_cell.value();
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
return uc;
|
|
}
|
|
|
|
void PowderCalibrationWidget::updateCalibrantList() {
|
|
calibrantCombo->clear();
|
|
|
|
calibrantCombo->addItem("LaB6");
|
|
calibrantCombo->addItem("Silver Behenate");
|
|
if (sample_cell)
|
|
calibrantCombo->addItem(QString("Current sample (%1 %2 %3 %4 %5 %6)")
|
|
.arg(QString::number(sample_cell->a, 'f', 1))
|
|
.arg(QString::number(sample_cell->b, 'f', 1))
|
|
.arg(QString::number(sample_cell->c, 'f', 1))
|
|
.arg(QString::number(sample_cell->alpha, 'f', 1))
|
|
.arg(QString::number(sample_cell->beta, 'f', 1))
|
|
.arg(QString::number(sample_cell->gamma, 'f', 1)));
|
|
calibrantCombo->setCurrentIndex(0);
|
|
}
|
|
|
|
void PowderCalibrationWidget::loadImage(std::shared_ptr<const JFJochReaderImage> image) {
|
|
if (image)
|
|
sample_cell = image->Dataset().experiment.GetUnitCell();
|
|
updateCalibrantList();
|
|
}
|
|
|
|
void PowderCalibrationWidget::findBeamCenterClicked() {
|
|
emit findBeamCenter(GetCalibrant(), true);
|
|
}
|
|
|
|
void PowderCalibrationWidget::optimizeBeamCenterClicked() {
|
|
emit findBeamCenter(GetCalibrant(), false);
|
|
}
|
|
|