226 lines
8.5 KiB
C++
226 lines
8.5 KiB
C++
/****************************************************************************
|
|
|
|
PGetNonMusrRunBlockDialog.cpp
|
|
|
|
Author: Andreas Suter
|
|
e-mail: andreas.suter@psi.ch
|
|
|
|
*****************************************************************************/
|
|
|
|
/***************************************************************************
|
|
* Copyright (C) 2009-2025 by Andreas Suter *
|
|
* andreas.suter@psi.ch *
|
|
* *
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
* it under the terms of the GNU General Public License as published by *
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
* (at your option) any later version. *
|
|
* *
|
|
* This program is distributed in the hope that it will be useful, *
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
* GNU General Public License for more details. *
|
|
* *
|
|
* You should have received a copy of the GNU General Public License *
|
|
* along with this program; if not, write to the *
|
|
* Free Software Foundation, Inc., *
|
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
|
***************************************************************************/
|
|
|
|
/**
|
|
* @file PGetNonMusrRunBlockDialog.cpp
|
|
* @brief Implementation of the PGetNonMusrRunBlockDialog class.
|
|
* @details This file implements the dialog for creating non-muSR type RUN blocks
|
|
* in msr files. It handles user input validation and generates properly formatted
|
|
* msr-file text for fitting generic x-y data.
|
|
*
|
|
* @author Andreas Suter
|
|
* @date 2009-2025
|
|
* @copyright Copyright (C) 2009-2025 by Andreas Suter
|
|
* @license GNU General Public License v2 or later
|
|
*/
|
|
|
|
#include <QLineEdit>
|
|
#include <QValidator>
|
|
#include <QComboBox>
|
|
#include <QMessageBox>
|
|
#include <QDesktopServices>
|
|
#include <QUrl>
|
|
|
|
#include "PGetNonMusrRunBlockDialog.h"
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
/**
|
|
* @brief Constructs the non-muSR RUN block dialog.
|
|
*
|
|
* @details Initializes the dialog UI and sets up input validators for numeric
|
|
* fields. The dialog is created as modal. The file format combo box is
|
|
* automatically set to "DB" (database format) as the default, which is the
|
|
* most common format for non-muSR data.
|
|
*
|
|
* @par Input Validators:
|
|
* - Double validators: fit range start and end values
|
|
*
|
|
* @param helpUrl URL to the online documentation for non-muSR RUN blocks.
|
|
* Defaults to empty string if not provided.
|
|
*/
|
|
PGetNonMusrRunBlockDialog::PGetNonMusrRunBlockDialog(const QString helpUrl) : fHelpUrl(helpUrl)
|
|
{
|
|
setupUi(this);
|
|
|
|
setModal(true);
|
|
|
|
fFitRangeStart_lineEdit->setValidator( new QDoubleValidator(fFitRangeStart_lineEdit) );
|
|
fFitRangeEnd_lineEdit->setValidator( new QDoubleValidator(fFitRangeEnd_lineEdit) );
|
|
|
|
int idx = -1;
|
|
for (int i=0; i<fFileFormat_comboBox->count(); i++) {
|
|
if (fFileFormat_comboBox->itemText(i) == "DB") {
|
|
idx = i;
|
|
break;
|
|
}
|
|
}
|
|
if (idx >= 0) {
|
|
fFileFormat_comboBox->setCurrentIndex(idx);
|
|
}
|
|
}
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
/**
|
|
* @brief Generates the RUN header line for the non-muSR block.
|
|
*
|
|
* @details Creates the first line of the RUN block containing the run file name,
|
|
* beamline identifier, institute name, and data file format. The beamline is
|
|
* converted to uppercase.
|
|
*
|
|
* @return Formatted RUN header string, e.g.:
|
|
* "RUN datafile BEAMLINE PSI DB (name beamline institute data-file-format)\\n"
|
|
*/
|
|
QString PGetNonMusrRunBlockDialog::getRunHeaderInfo()
|
|
{
|
|
QString str;
|
|
|
|
str = "RUN " + fRunFileName_lineEdit->text() + " ";
|
|
str += fBeamline_lineEdit->text().toUpper() + " ";
|
|
str += fInstitute_comboBox->currentText() + " ";
|
|
str += fFileFormat_comboBox->currentText() + " (name beamline institute data-file-format)\n";
|
|
|
|
return str;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
/**
|
|
* @brief Generates the parameter map line for the non-muSR block.
|
|
*
|
|
* @details The map line defines the mapping between theory function parameters
|
|
* and the fit parameters defined in the FITPARAMETER block. The method validates
|
|
* that the map contains only space-separated integers.
|
|
*
|
|
* @param[out] valid Set to true if the map contains only digits and spaces,
|
|
* false if invalid characters are found.
|
|
*
|
|
* @return Formatted map string, e.g.: "map 1 2 3\\n"
|
|
*/
|
|
QString PGetNonMusrRunBlockDialog::getMap(bool &valid)
|
|
{
|
|
QString str = fMap_lineEdit->text().trimmed().remove(" ");
|
|
|
|
// check if potentially proper map line
|
|
for (int i=0; i<str.length(); i++) {
|
|
if (!str[i].isDigit()) {
|
|
valid = false;
|
|
break;
|
|
}
|
|
}
|
|
|
|
str = "map " + fMap_lineEdit->text() + "\n";
|
|
|
|
return str;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
/**
|
|
* @brief Generates the xy-data specification line for the non-muSR block.
|
|
*
|
|
* @details Creates the "xy-data" line specifying which columns in the data file
|
|
* contain the x (independent variable) and y (dependent variable) values.
|
|
* Both columns must be specified for the line to be valid.
|
|
*
|
|
* @param[out] valid Set to true if both x and y data column numbers are provided,
|
|
* false if either is missing.
|
|
*
|
|
* @return Formatted xy-data string, e.g.: "xy-data 1 2\\n"
|
|
* Returns empty string if either x or y data is not specified.
|
|
*/
|
|
QString PGetNonMusrRunBlockDialog::getXYData(bool &valid)
|
|
{
|
|
QString str = "";
|
|
|
|
if (fXData_lineEdit->text().isEmpty() || fYData_lineEdit->text().isEmpty()) {
|
|
valid = false;
|
|
} else {
|
|
str = "xy-data ";
|
|
str += fXData_lineEdit->text() + " ";
|
|
str += fYData_lineEdit->text() + "\n";
|
|
valid = true;
|
|
}
|
|
|
|
return str;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
/**
|
|
* @brief Generates the fit range specification line for the non-muSR block.
|
|
*
|
|
* @details Creates the "fit" line specifying the x-value range over which the
|
|
* fit will be performed. If no fit range is provided by the user, a default
|
|
* range of [0.0, 10.0] is returned.
|
|
*
|
|
* @param[out] valid Set to true if both fit range values are provided by the user,
|
|
* false if using the default range.
|
|
*
|
|
* @return Formatted fit range string, e.g.: "fit 0.5 99.5\\n"
|
|
* Returns default "fit 0.0 10.0\\n" if values are missing.
|
|
*/
|
|
QString PGetNonMusrRunBlockDialog::getFitRange(bool &valid)
|
|
{
|
|
QString str = "";
|
|
|
|
if (fFitRangeStart_lineEdit->text().isEmpty() || fFitRangeEnd_lineEdit->text().isEmpty()) {
|
|
str += "fit 0.0 10.0\n";
|
|
valid = false;
|
|
} else {
|
|
str += "fit ";
|
|
str += fFitRangeStart_lineEdit->text() + " ";
|
|
str += fFitRangeEnd_lineEdit->text() + "\n";
|
|
valid = true;
|
|
}
|
|
|
|
return str;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
/**
|
|
* @brief Opens the online help documentation for non-muSR RUN blocks.
|
|
*
|
|
* @details Attempts to open the help URL in the system's default web browser
|
|
* using QDesktopServices. If the URL is empty, displays an informational message.
|
|
* If the browser fails to open, displays an error message with a clickable link.
|
|
*/
|
|
void PGetNonMusrRunBlockDialog::helpContent()
|
|
{
|
|
if (fHelpUrl.isEmpty()) {
|
|
QMessageBox::information(this, "INFO", "Will eventually show a help window");
|
|
} else {
|
|
bool ok = QDesktopServices::openUrl(QUrl(fHelpUrl, QUrl::TolerantMode));
|
|
if (!ok) {
|
|
QString msg = QString("<p>Sorry: Couldn't open default web-browser for the help.<br>Please try: <a href=\"%1\">musrfit docu</a> in your web-browser.").arg(fHelpUrl);
|
|
QMessageBox::critical( nullptr, tr("FATAL ERROR"), msg, QMessageBox::Close );
|
|
}
|
|
}
|
|
}
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
// END
|
|
//----------------------------------------------------------------------------------------------------
|