Newer
Older
#include "MantidKernel/ConfigService.h"
#include "MantidQtAPI/AlgorithmRunner.h"
#include "MantidQtAPI/AlgorithmInputHistory.h"
#include "MantidQtAPI/HelpWindow.h"
#include "MantidQtCustomInterfaces/EnggDiffraction/EnggDiffractionViewQtGUI.h"
#include "MantidQtCustomInterfaces/EnggDiffraction/EnggDiffractionPresenter.h"
using namespace Mantid::API;
using namespace MantidQt::CustomInterfaces;
#include <boost/lexical_cast.hpp>
#include <Poco/Path.h>
#include <QCheckBox>
#include <QCloseEvent>
#include <QFileDialog>
#include <QMessageBox>
#include <QSettings>
namespace MantidQt {
namespace CustomInterfaces {
// Add this class to the list of specialised dialogs in this namespace
DECLARE_SUBWINDOW(EnggDiffractionViewQtGUI)
const double EnggDiffractionViewQtGUI::g_defaultRebinWidth = -0.0005;
const std::string EnggDiffractionViewQtGUI::g_iparmExtStr =
Federico Montesino Pouzols
committed
"GSAS instrument parameters, IPARM file: PRM, PAR, IPAR, IPARAM "
"(*.prm *.par *.ipar *.iparam);;"
"Other extensions/all files (*.*)";
const std::string EnggDiffractionViewQtGUI::g_pixelCalibExt =
Federico Montesino Pouzols
committed
"Comma separated values text file with calibration table, CSV"
"(*.csv);;"
Federico Montesino Pouzols
committed
"Nexus file with calibration table: NXS, NEXUS"
"(*.nxs *.nexus);;"
"Supported formats: CSV, NXS "
"(*.csv *.nxs *.nexus);;"
"Other extensions/all files (*.*)";
const std::string EnggDiffractionViewQtGUI::g_DetGrpExtStr =
"Detector Grouping File: CSV "
"(*.csv *.txt);;"
"Other extensions/all files (*.*)";
const std::string EnggDiffractionViewQtGUI::m_settingsGroup =
"CustomInterfaces/EnggDiffractionView";
/**
* Default constructor.
*
* @param parent Parent window (most likely the Mantid main app window).
*/
EnggDiffractionViewQtGUI::EnggDiffractionViewQtGUI(QWidget *parent)
Federico Montesino Pouzols
committed
: UserSubWindow(parent), IEnggDiffractionView(), m_currentInst("ENGIN-X"),
m_currentCalibFilename(""), m_presenter(NULL) {}
EnggDiffractionViewQtGUI::~EnggDiffractionViewQtGUI() {}
void EnggDiffractionViewQtGUI::initLayout() {
// setup container ui
m_ui.setupUi(this);
// add tab contents and set up their ui's
QWidget *wCalib = new QWidget(m_ui.tabMain);
m_uiTabCalib.setupUi(wCalib);
m_ui.tabMain->addTab(wCalib, QString("Calibration"));
QWidget *wFocus = new QWidget(m_ui.tabMain);
m_uiTabFocus.setupUi(wFocus);
m_ui.tabMain->addTab(wFocus, QString("Focus"));
QWidget *wSettings = new QWidget(m_ui.tabMain);
m_uiTabSettings.setupUi(wSettings);
m_ui.tabMain->addTab(wSettings, QString("Settings"));
readSettings();
// basic UI setup, connect signals, etc.
doSetupGeneralWidgets();
doSetupTabCalib();
Federico Montesino Pouzols
committed
doSetupTabFocus();
doSetupTabSettings();
// presenter that knows how to handle a IEnggDiffractionView should take care
// of all the logic
// note that the view needs to know the concrete presenter
m_presenter.reset(new EnggDiffractionPresenter(this));
// it will know what compute resources and tools we have available:
// This view doesn't even know the names of compute resources, etc.
m_presenter->notify(IEnggDiffractionPresenter::Start);
}
void EnggDiffractionViewQtGUI::doSetupTabCalib() {
Federico Montesino Pouzols
committed
// Last available runs. This (as well as the empty defaults just
// above) should probably be made persistent - and encapsulated into a
// CalibrationParameters or similar class/structure
const std::string vanadiumRun = "236516";
const std::string ceriaRun = "241391";
m_uiTabCalib.lineEdit_new_vanadium_num->setText(
QString::fromStdString(vanadiumRun));
m_uiTabCalib.lineEdit_new_ceria_num->setText(
QString::fromStdString(ceriaRun));
// push button signals/slots
connect(m_uiTabCalib.pushButton_load_calib, SIGNAL(released()), this,
SLOT(loadCalibrationClicked()));
connect(m_uiTabCalib.pushButton_new_calib, SIGNAL(released()), this,
SLOT(calibrateClicked()));
Federico Montesino Pouzols
committed
enableCalibrateAndFocusActions(true);
void EnggDiffractionViewQtGUI::doSetupTabSettings() {
// line edits that display paths and the like
m_uiTabSettings.lineEdit_input_dir_calib->setText(
QString::fromStdString(m_calibSettings.m_inputDirCalib));
m_uiTabSettings.lineEdit_input_dir_raw->setText(
QString::fromStdString(m_calibSettings.m_inputDirRaw));
m_uiTabSettings.lineEdit_pixel_calib_filename->setText(
QString::fromStdString(m_calibSettings.m_pixelCalibFilename));
m_uiTabSettings.lineEdit_template_gsas_prm->setText(
QString::fromStdString(m_calibSettings.m_templateGSAS_PRM));
Federico Montesino Pouzols
committed
m_calibSettings.m_forceRecalcOverwrite = false;
m_uiTabSettings.checkBox_force_recalculate_overwrite->setChecked(
m_calibSettings.m_forceRecalcOverwrite);
Federico Montesino Pouzols
committed
m_uiTabSettings.lineEdit_dir_focusing->setText(
QString::fromStdString(m_focusDir));
// push button signals/slots
connect(m_uiTabSettings.pushButton_browse_input_dir_calib, SIGNAL(released()),
this, SLOT(browseInputDirCalib()));
connect(m_uiTabSettings.pushButton_browse_input_dir_raw, SIGNAL(released()),
this, SLOT(browseInputDirRaw()));
connect(m_uiTabSettings.pushButton_browse_pixel_calib_filename,
SIGNAL(released()), this, SLOT(browsePixelCalibFilename()));
connect(m_uiTabSettings.pushButton_browse_template_gsas_prm,
SIGNAL(released()), this, SLOT(browseTemplateGSAS_PRM()));
Federico Montesino Pouzols
committed
connect(m_uiTabSettings.pushButton_browse_dir_focusing, SIGNAL(released()),
this, SLOT(browseDirFocusing()));
}
void EnggDiffractionViewQtGUI::doSetupTabFocus() {
Federico Montesino Pouzols
committed
connect(m_uiTabFocus.pushButton_focus, SIGNAL(released()), this,
SLOT(focusClicked()));
Federico Montesino Pouzols
committed
connect(m_uiTabFocus.pushButton_focus_cropped, SIGNAL(released()), this,
SLOT(focusCroppedClicked()));
connect(m_uiTabFocus.pushButton_texture_browse_grouping_file,
SIGNAL(released()), this, SLOT(browseTextureDetGroupingFile()));
Federico Montesino Pouzols
committed
connect(m_uiTabFocus.pushButton_focus_texture, SIGNAL(released()), this,
SLOT(focusTextureClicked()));
connect(m_uiTabFocus.pushButton_reset, SIGNAL(released()), this,
SLOT(focusResetClicked()));
}
void EnggDiffractionViewQtGUI::doSetupGeneralWidgets() {
// change instrument
connect(m_ui.comboBox_instrument, SIGNAL(currentIndexChanged(int)), this,
SLOT(instrumentChanged(int)));
connect(m_ui.pushButton_help, SIGNAL(released()), this, SLOT(openHelpWin()));
// note connection to the parent window, otherwise an empty frame window
// may remain open and visible after this close
connect(m_ui.pushButton_close, SIGNAL(released()), this->parent(),
SLOT(close()));
}
void EnggDiffractionViewQtGUI::readSettings() {
QSettings qs;
qs.beginGroup(QString::fromStdString(m_settingsGroup));
m_uiTabCalib.lineEdit_RBNumber->setText(
qs.value("user-params-RBNumber", "").toString());
m_uiTabCalib.lineEdit_current_vanadium_num->setText(
qs.value("user-params-current-vanadium-num", "").toString());
m_uiTabCalib.lineEdit_current_ceria_num->setText(
qs.value("user-params-current-ceria-num", "").toString());
QString calibFname = qs.value("current-calib-filename", "").toString();
m_uiTabCalib.lineEdit_current_calib_filename->setText(calibFname);
m_currentCalibFilename = calibFname.toStdString();
m_uiTabCalib.lineEdit_new_vanadium_num->setText(
qs.value("user-params-new-vanadium-num", "").toString());
m_uiTabCalib.lineEdit_new_ceria_num->setText(
qs.value("user-params-new-ceria-num", "").toString());
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
m_uiTabCalib.lineEdit_new_vanadium_num->setText(
qs.value("user-params-new-vanadium-num", "").toString());
m_uiTabCalib.lineEdit_new_ceria_num->setText(
qs.value("user-params-new-ceria-num", "").toString());
// user params - focusing
m_uiTabFocus.lineEdit_run_num->setText(
qs.value("user-params-focus-runno", "").toString());
qs.beginReadArray("user-params-focus-bank_i");
qs.setArrayIndex(0);
m_uiTabFocus.checkBox_focus_bank1->setChecked(qs.value("value", true).toBool());
qs.setArrayIndex(1);
m_uiTabFocus.checkBox_focus_bank2->setChecked(qs.value("value", true).toBool());
qs.endArray();
m_uiTabFocus.lineEdit_cropped_run_num->setText(
qs.value("user-params-focus-cropped-runno", "").toString());
m_uiTabFocus.lineEdit_cropped_spec_ids->setText(
qs.value("user-params-focus-cropped-spectrum-nos", "").toString());
m_uiTabFocus.lineEdit_texture_run_num->setText(
qs.value("user-params-focus-texture-runno", "").toString());
m_uiTabFocus.lineEdit_texture_grouping_file->setText(
qs.value("user-params-focus-texture-detector-grouping-file", "")
.toString());
m_uiTabFocus.checkBox_FocusedWS->setChecked(
qs.value("user-params-focus-plot-ws", true).toBool());
QString lastPath =
MantidQt::API::AlgorithmInputHistory::Instance().getPreviousDirectory();
// TODO: this should become << >> operators on
// EnggDiffCalibSettings
m_calibSettings.m_inputDirCalib =
qs.value("input-dir-calib-files", lastPath).toString().toStdString();
m_calibSettings.m_inputDirRaw =
qs.value("input-dir-raw-files", lastPath).toString().toStdString();
m_calibSettings.m_pixelCalibFilename =
qs.value("pixel-calib-filename", "").toString().toStdString();
// 'advanced' block
m_calibSettings.m_forceRecalcOverwrite =
qs.value("force-recalc-overwrite", false).toBool();
std::string templ = guessGSASTemplatePath();
m_calibSettings.m_templateGSAS_PRM =
qs.value("template-gsas-prm", QString::fromStdString(templ))
.toString()
.toStdString();
m_calibSettings.m_forceRecalcOverwrite =
qs.value("rebin-calib", g_defaultRebinWidth).toFloat();
// 'focusing' block
m_focusDir = qs.value("focus-dir").toString().toStdString();
restoreGeometry(qs.value("interface-win-geometry").toByteArray());
qs.endGroup();
}
void EnggDiffractionViewQtGUI::saveSettings() const {
QSettings qs;
qs.beginGroup(QString::fromStdString(m_settingsGroup));
qs.setValue("user-params-RBNumber", m_uiTabCalib.lineEdit_RBNumber->text());
qs.setValue("user-params-current-vanadium-num",
m_uiTabCalib.lineEdit_current_vanadium_num->text());
Federico Montesino Pouzols
committed
qs.setValue("user-params-current-ceria-num",
m_uiTabCalib.lineEdit_current_ceria_num->text());
qs.setValue("current-calib-filename",
m_uiTabCalib.lineEdit_current_calib_filename->text());
qs.setValue("user-params-new-vanadium-num",
m_uiTabCalib.lineEdit_new_vanadium_num->text());
Federico Montesino Pouzols
committed
qs.setValue("user-params-new-ceria-num",
m_uiTabCalib.lineEdit_new_ceria_num->text());
// user params - focusing
qs.setValue("user-params-focus-runno", m_uiTabFocus.lineEdit_run_num->text());
qs.beginWriteArray("user-params-focus-bank_i");
qs.setArrayIndex(0);
qs.setValue("value", m_uiTabFocus.checkBox_focus_bank1->isChecked());
qs.setArrayIndex(1);
qs.setValue("value", m_uiTabFocus.checkBox_focus_bank2->isChecked());
qs.endArray();
qs.setValue("user-params-focus-cropped-runno",
m_uiTabFocus.lineEdit_cropped_run_num->text());
qs.setValue("user-params-focus-cropped-spectrum-nos",
m_uiTabFocus.lineEdit_cropped_spec_ids->text());
qs.setValue("user-params-focus-texture-runno",
m_uiTabFocus.lineEdit_texture_run_num->text());
qs.setValue("user-params-focus-texture-detector-grouping-file",
m_uiTabFocus.lineEdit_texture_grouping_file->text());
qs.setValue("user-params-focus-plot-ws",
m_uiTabFocus.checkBox_FocusedWS->checkState());
// TODO: this should become << >> operators on EnggDiffCalibSettings
qs.setValue("input-dir-calib-files",
QString::fromStdString(m_calibSettings.m_inputDirCalib));
qs.setValue("input-dir-raw-files",
QString::fromStdString(m_calibSettings.m_inputDirRaw));
qs.setValue("pixel-calib-filename",
QString::fromStdString(m_calibSettings.m_pixelCalibFilename));
// 'advanced' block
qs.setValue("force-recalc-overwrite", m_calibSettings.m_forceRecalcOverwrite);
qs.setValue("template-gsas-prm",
QString::fromStdString(m_calibSettings.m_templateGSAS_PRM));
qs.setValue("rebin-calib", m_calibSettings.m_rebinCalibrate);
// 'focusing' block
Federico Montesino Pouzols
committed
qs.setValue("focus-dir", QString::fromStdString(m_focusDir));
qs.setValue("interface-win-geometry", saveGeometry());
qs.endGroup();
}
std::string EnggDiffractionViewQtGUI::guessGSASTemplatePath() const {
// +scripts/Engineering/template_ENGINX_241391_236516_North_and_South_banks.par
Poco::Path templ =
Mantid::Kernel::ConfigService::Instance().getInstrumentDirectory();
templ = templ.makeParent();
templ.append("scripts");
templ.append("Engineering");
templ.append("template_ENGINX_241391_236516_North_and_South_banks.par");
return templ.toString();
}
void EnggDiffractionViewQtGUI::userWarning(const std::string &err,
const std::string &description) {
QMessageBox::warning(this, QString::fromStdString(err),
QString::fromStdString(description), QMessageBox::Ok,
QMessageBox::Ok);
}
void EnggDiffractionViewQtGUI::userError(const std::string &err,
const std::string &description) {
QMessageBox::critical(this, QString::fromStdString(err),
QString::fromStdString(description), QMessageBox::Ok,
QMessageBox::Ok);
}
std::string EnggDiffractionViewQtGUI::askNewCalibrationFilename(
const std::string &suggestedFname) {
// append dir (basename) + filename
QString prevPath = QString::fromStdString(m_calibSettings.m_inputDirCalib);
if (prevPath.isEmpty()) {
prevPath =
MantidQt::API::AlgorithmInputHistory::Instance().getPreviousDirectory();
}
QDir path(prevPath);
QString suggestion = path.filePath(QString::fromStdString(suggestedFname));
Federico Montesino Pouzols
committed
QString choice = QFileDialog::getSaveFileName(
this, tr("Please select the name of the calibration file"), suggestion,
QString::fromStdString(g_iparmExtStr));
return choice.toStdString();
}
std::string EnggDiffractionViewQtGUI::getRBNumber() const {
return m_uiTabCalib.lineEdit_RBNumber->text().toStdString();
}
std::string EnggDiffractionViewQtGUI::currentVanadiumNo() const {
Federico Montesino Pouzols
committed
return m_uiTabCalib.lineEdit_current_vanadium_num->text().toStdString();
}
std::string EnggDiffractionViewQtGUI::currentCeriaNo() const {
Federico Montesino Pouzols
committed
return m_uiTabCalib.lineEdit_current_ceria_num->text().toStdString();
}
std::string EnggDiffractionViewQtGUI::newVanadiumNo() const {
return m_uiTabCalib.lineEdit_new_vanadium_num->text().toStdString();
}
std::string EnggDiffractionViewQtGUI::newCeriaNo() const {
return m_uiTabCalib.lineEdit_new_ceria_num->text().toStdString();
}
std::string EnggDiffractionViewQtGUI::currentCalibFile() const {
return m_uiTabCalib.lineEdit_current_calib_filename->text().toStdString();
}
void EnggDiffractionViewQtGUI::newCalibLoaded(const std::string &vanadiumNo,
const std::string &ceriaNo,
const std::string &fname) {
Federico Montesino Pouzols
committed
m_uiTabCalib.lineEdit_current_vanadium_num->setText(
QString::fromStdString(vanadiumNo));
Federico Montesino Pouzols
committed
m_uiTabCalib.lineEdit_current_ceria_num->setText(
QString::fromStdString(ceriaNo));
m_uiTabCalib.lineEdit_current_calib_filename->setText(
QString::fromStdString(fname));
Federico Montesino Pouzols
committed
if (!fname.empty()) {
MantidQt::API::AlgorithmInputHistory::Instance().setPreviousDirectory(
QString::fromStdString(fname));
}
}
Federico Montesino Pouzols
committed
void EnggDiffractionViewQtGUI::enableCalibrateAndFocusActions(bool enable) {
// calibrate
Federico Montesino Pouzols
committed
m_uiTabCalib.lineEdit_RBNumber->setEnabled(enable);
m_uiTabCalib.groupBox_make_new_calib->setEnabled(enable);
m_uiTabCalib.groupBox_current_calib->setEnabled(enable);
m_ui.pushButton_close->setEnabled(enable);
Federico Montesino Pouzols
committed
// focus
m_uiTabFocus.lineEdit_run_num->setEnabled(enable);
m_uiTabFocus.pushButton_focus->setEnabled(enable);
m_uiTabFocus.checkBox_FocusedWS->setEnabled(enable);
Federico Montesino Pouzols
committed
m_uiTabFocus.pushButton_focus->setEnabled(enable);
m_uiTabFocus.pushButton_focus_cropped->setEnabled(enable);
m_uiTabFocus.pushButton_focus_texture->setEnabled(enable);
void EnggDiffractionViewQtGUI::plotFocusedSpectrum(const std::string &wsName) {
std::string pyCode = "plotSpectrum('" + wsName + "', 0)";
Federico Montesino Pouzols
committed
std::string status =
runPythonCode(QString::fromStdString(pyCode), false).toStdString();
m_logMsgs.push_back("Plotted output focused data, with status string " +
status);
m_presenter->notify(IEnggDiffractionPresenter::LogMsg);
}
Federico Montesino Pouzols
committed
void EnggDiffractionViewQtGUI::resetFocus() {
m_uiTabFocus.lineEdit_run_num->setText("");
m_uiTabFocus.checkBox_focus_bank1->setChecked(true);
m_uiTabFocus.checkBox_focus_bank2->setChecked(true);
m_uiTabFocus.lineEdit_cropped_run_num->setText("");
m_uiTabFocus.lineEdit_cropped_spec_ids->setText("");
m_uiTabFocus.lineEdit_texture_run_num->setText("");
m_uiTabFocus.lineEdit_texture_grouping_file->setText("");
}
void
EnggDiffractionViewQtGUI::writeOutCalibFile(const std::string &outFilename,
const std::vector<double> &difc,
const std::vector<double> &tzero) {
Federico Montesino Pouzols
committed
// TODO: this is horrible and should not last much here.
// Avoid running Python code
// Update this as soon as we have a more stable way of generating IPARM
// files
Federico Montesino Pouzols
committed
// Writes a file doing this:
// write_ENGINX_GSAS_iparam_file(output_file, difc, zero, ceria_run=241391,
// vanadium_run=236516, template_file=None):
// this replace is to prevent issues with network drives on windows:
const std::string safeOutFname =
boost::replace_all_copy(outFilename, "\\", "/");
Federico Montesino Pouzols
committed
std::string pyCode = "import EnggUtils\n";
pyCode += "import os\n";
// normalize apparently not needed after the replace, but to be double-safe:
pyCode += "GSAS_iparm_fname= os.path.normpath('" + safeOutFname + "')\n";
Federico Montesino Pouzols
committed
pyCode += "Difcs = []\n";
pyCode += "Zeros = []\n";
for (size_t i = 0; i < difc.size(); i++) {
pyCode +=
"Difcs.append(" + boost::lexical_cast<std::string>(difc[i]) + ")\n";
pyCode +=
"Zeros.append(" + boost::lexical_cast<std::string>(tzero[i]) + ")\n";
}
pyCode += "EnggUtils.write_ENGINX_GSAS_iparam_file(GSAS_iparm_fname, Difcs, "
"Zeros) \n";
std::string status =
runPythonCode(QString::fromStdString(pyCode), false).toStdString();
// g_log.information()
// << "Saved output calibration file through Python. Status: " << status
// << std::endl;
m_logMsgs.push_back(
"Run Python code to save output file, with status string: " + status);
m_presenter->notify(IEnggDiffractionPresenter::LogMsg);
Federico Montesino Pouzols
committed
}
std::string EnggDiffractionViewQtGUI::askExistingCalibFilename() {
QString prevPath = QString::fromStdString(m_calibSettings.m_inputDirCalib);
if (prevPath.isEmpty()) {
QString prevPath =
MantidQt::API::AlgorithmInputHistory::Instance().getPreviousDirectory();
}
QString filename =
QFileDialog::getOpenFileName(this, tr("Open calibration file"), prevPath,
QString::fromStdString(g_iparmExtStr));
if (!filename.isEmpty()) {
MantidQt::API::AlgorithmInputHistory::Instance().setPreviousDirectory(
filename);
}
return filename.toStdString();
}
void EnggDiffractionViewQtGUI::loadCalibrationClicked() {
m_presenter->notify(IEnggDiffractionPresenter::LoadExistingCalib);
}
void EnggDiffractionViewQtGUI::calibrateClicked() {
m_presenter->notify(IEnggDiffractionPresenter::CalcCalib);
}
Federico Montesino Pouzols
committed
void EnggDiffractionViewQtGUI::focusClicked() {
m_presenter->notify(IEnggDiffractionPresenter::FocusRun);
}
Federico Montesino Pouzols
committed
void EnggDiffractionViewQtGUI::focusCroppedClicked() {
m_presenter->notify(IEnggDiffractionPresenter::FocusCropped);
}
void EnggDiffractionViewQtGUI::focusTextureClicked() {
m_presenter->notify(IEnggDiffractionPresenter::FocusTexture);
}
void EnggDiffractionViewQtGUI::focusResetClicked() {
m_presenter->notify(IEnggDiffractionPresenter::ResetFocus);
// TODO
}
void EnggDiffractionViewQtGUI::browseInputDirCalib() {
QString prevPath = QString::fromStdString(m_calibSettings.m_inputDirCalib);
if (prevPath.isEmpty()) {
prevPath =
MantidQt::API::AlgorithmInputHistory::Instance().getPreviousDirectory();
}
QString dir = QFileDialog::getExistingDirectory(
this, tr("Open Directory"), prevPath,
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
if (dir.isEmpty()) {
return;
}
MantidQt::API::AlgorithmInputHistory::Instance().setPreviousDirectory(dir);
m_calibSettings.m_inputDirCalib = dir.toStdString();
m_uiTabSettings.lineEdit_input_dir_calib->setText(
QString::fromStdString(m_calibSettings.m_inputDirCalib));
}
void EnggDiffractionViewQtGUI::browseInputDirRaw() {
QString prevPath = QString::fromStdString(m_calibSettings.m_inputDirRaw);
if (prevPath.isEmpty()) {
prevPath =
MantidQt::API::AlgorithmInputHistory::Instance().getPreviousDirectory();
}
QString dir = QFileDialog::getExistingDirectory(
this, tr("Open Directory"), prevPath,
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
if (dir.isEmpty()) {
return;
}
MantidQt::API::AlgorithmInputHistory::Instance().setPreviousDirectory(dir);
m_calibSettings.m_inputDirRaw = dir.toStdString();
m_uiTabSettings.lineEdit_input_dir_raw->setText(
QString::fromStdString(m_calibSettings.m_inputDirRaw));
}
void EnggDiffractionViewQtGUI::browsePixelCalibFilename() {
QString prevPath = QString::fromStdString(m_calibSettings.m_inputDirCalib);
if (prevPath.isEmpty()) {
QString prevPath =
MantidQt::API::AlgorithmInputHistory::Instance().getPreviousDirectory();
}
Federico Montesino Pouzols
committed
QString filename = QFileDialog::getOpenFileName(
this, tr("Open pixel calibration (full calibration) file"), prevPath,
Federico Montesino Pouzols
committed
QString::fromStdString(g_pixelCalibExt));
if (filename.isEmpty()) {
return;
}
m_calibSettings.m_pixelCalibFilename = filename.toStdString();
m_uiTabSettings.lineEdit_pixel_calib_filename->setText(
QString::fromStdString(m_calibSettings.m_pixelCalibFilename));
}
void EnggDiffractionViewQtGUI::browseTemplateGSAS_PRM() {
QString prevPath = QString::fromStdString(m_calibSettings.m_templateGSAS_PRM);
QString path(QFileDialog::getOpenFileName(
this, tr("Open GSAS IPAR template file"), prevPath,
QString::fromStdString(g_iparmExtStr)));
if (path.isEmpty()) {
return;
}
m_calibSettings.m_templateGSAS_PRM = path.toStdString();
m_uiTabSettings.lineEdit_template_gsas_prm->setText(
QString::fromStdString(m_calibSettings.m_templateGSAS_PRM));
}
void EnggDiffractionViewQtGUI::browseDirFocusing() {
QString prevPath = QString::fromStdString(m_focusDir);
if (prevPath.isEmpty()) {
prevPath =
MantidQt::API::AlgorithmInputHistory::Instance().getPreviousDirectory();
}
QString dir = QFileDialog::getExistingDirectory(
this, tr("Open Directory"), prevPath,
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
if (dir.isEmpty()) {
return;
}
MantidQt::API::AlgorithmInputHistory::Instance().setPreviousDirectory(dir);
m_focusDir = dir.toStdString();
m_uiTabSettings.lineEdit_dir_focusing->setText(
QString::fromStdString(m_focusDir));
}
void EnggDiffractionViewQtGUI::browseTextureDetGroupingFile() {
QString prevPath = QString::fromStdString(m_calibSettings.m_inputDirRaw);
if (prevPath.isEmpty()) {
prevPath =
MantidQt::API::AlgorithmInputHistory::Instance().getPreviousDirectory();
}
QString path(QFileDialog::getOpenFileName(
this, tr("Open detector grouping file"), prevPath,
QString::fromStdString(g_DetGrpExtStr)));
if (path.isEmpty()) {
return;
}
MantidQt::API::AlgorithmInputHistory::Instance().setPreviousDirectory(path);
m_uiTabFocus.lineEdit_texture_grouping_file->setText(path);
}
Federico Montesino Pouzols
committed
std::string EnggDiffractionViewQtGUI::focusingRunNo() const {
return m_uiTabFocus.lineEdit_run_num->text().toStdString();
}
Federico Montesino Pouzols
committed
std::string EnggDiffractionViewQtGUI::focusingCroppedRunNo() const {
return m_uiTabFocus.lineEdit_cropped_run_num->text().toStdString();
}
std::string EnggDiffractionViewQtGUI::focusingTextureRunNo() const {
return m_uiTabFocus.lineEdit_texture_run_num->text().toStdString();
}
Federico Montesino Pouzols
committed
std::string EnggDiffractionViewQtGUI::focusingDir() const {
return m_uiTabSettings.lineEdit_dir_focusing->text().toStdString();
}
Federico Montesino Pouzols
committed
std::vector<bool> EnggDiffractionViewQtGUI::focusingBanks() const {
std::vector<bool> res;
res.push_back(m_uiTabFocus.checkBox_focus_bank1->isChecked());
res.push_back(m_uiTabFocus.checkBox_focus_bank2->isChecked());
Federico Montesino Pouzols
committed
return res;
}
std::string EnggDiffractionViewQtGUI::focusingCroppedSpectrumIDs() const {
return m_uiTabFocus.lineEdit_cropped_spec_ids->text().toStdString();
}
std::string EnggDiffractionViewQtGUI::focusingTextureGroupingFile() const {
return m_uiTabFocus.lineEdit_texture_grouping_file->text().toStdString();
Federico Montesino Pouzols
committed
}
bool EnggDiffractionViewQtGUI::focusedOutWorkspace() const {
return m_uiTabFocus.checkBox_FocusedWS->checkState();
void EnggDiffractionViewQtGUI::instrumentChanged(int /*idx*/) {
QComboBox *inst = m_ui.comboBox_instrument;
if (!inst)
return;
m_currentInst = inst->currentText().toStdString();
m_presenter->notify(IEnggDiffractionPresenter::InstrumentChange);
}
void EnggDiffractionViewQtGUI::closeEvent(QCloseEvent *event) {
int answer = QMessageBox::AcceptRole;
QMessageBox msgBox;
Federico Montesino Pouzols
committed
if (false /* TODO: get this from user settings if eventually used */) {
msgBox.setWindowTitle("Close the engineering diffraction interface");
// with something like this, we'd have layout issues:
// msgBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
// msgBox.setDefaultButton(QMessageBox::Yes);
msgBox.setIconPixmap(QPixmap(":/win/unknown.png"));
QCheckBox confirmCheckBox("Always ask for confirmation", &msgBox);
confirmCheckBox.setCheckState(Qt::Checked);
msgBox.layout()->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding));
msgBox.layout()->addWidget(&confirmCheckBox);
QPushButton *bYes = msgBox.addButton("Yes", QMessageBox::YesRole);
bYes->setIcon(style()->standardIcon(QStyle::SP_DialogYesButton));
QPushButton *bNo = msgBox.addButton("No", QMessageBox::NoRole);
bNo->setIcon(style()->standardIcon(QStyle::SP_DialogNoButton));
msgBox.setDefaultButton(bNo);
msgBox.setText("You are about to close this interface");
msgBox.setInformativeText("Are you sure?");
answer = msgBox.exec();
}
Federico Montesino Pouzols
committed
if (answer == QMessageBox::AcceptRole && m_ui.pushButton_close->isEnabled()) {
m_presenter->notify(IEnggDiffractionPresenter::ShutDown);
event->accept();
} else {
event->ignore();
}
}
void EnggDiffractionViewQtGUI::openHelpWin() {
MantidQt::API::HelpWindow::showCustomInterface(
NULL, QString("Engineering_Diffraction"));
}
} // namespace CustomInterfaces
} // namespace MantidQt