Unverified Commit 2314d6ea authored by Martyn Gigg's avatar Martyn Gigg Committed by GitHub
Browse files

Merge pull request #21617 from mantidproject/15552_engggui_gsas_load_run

Engineering Diffraction GUI enable loading and plotting runs in the new GSAS tab
parents d9e8622b bbba305e
......@@ -4,6 +4,7 @@ set ( SRC_FILES
EnggDiffFittingViewQtWidget.cpp
EnggDiffGSASFittingModel.cpp
EnggDiffGSASFittingPresenter.cpp
EnggDiffGSASFittingViewQtWidget.cpp
EnggDiffMultiRunFittingWidgetPresenter.cpp
EnggDiffractionPresenter.cpp
EnggDiffractionViewQtGUI.cpp
......@@ -20,6 +21,7 @@ set ( INC_FILES
EnggDiffFittingViewQtWidget.h
EnggDiffGSASFittingModel.h
EnggDiffGSASFittingPresenter.h
EnggDiffGSASFittingViewQtWidget.h
EnggDiffGSASRefinementMethod.h
EnggDiffMultiRunFittingWidgetPresenter.h
EnggDiffractionPresWorker.h
......@@ -43,6 +45,7 @@ set ( MOC_FILES
EnggDiffFittingPresenter.h
EnggDiffFittingPresWorker.h
EnggDiffFittingViewQtWidget.h
EnggDiffGSASFittingViewQtWidget.h
EnggDiffractionPresenter.h
EnggDiffractionPresWorker.h
EnggDiffractionViewQtGUI.h
......@@ -54,6 +57,7 @@ set ( UI_FILES
EnggDiffractionQtTabFocus.ui
EnggDiffractionQtTabPreproc.ui
EnggDiffractionQtTabFitting.ui
EnggDiffractionQtTabGSAS.ui
EnggDiffractionQtTabSettings.ui
)
......
......@@ -7,13 +7,12 @@ namespace CustomInterfaces {
EnggDiffGSASFittingPresenter::EnggDiffGSASFittingPresenter(
std::unique_ptr<IEnggDiffGSASFittingModel> model,
std::unique_ptr<IEnggDiffGSASFittingView> view)
: m_model(std::move(model)), m_view(std::move(view)),
m_viewHasClosed(false) {}
IEnggDiffGSASFittingView *view)
: m_model(std::move(model)), m_view(view), m_viewHasClosed(false) {}
EnggDiffGSASFittingPresenter::EnggDiffGSASFittingPresenter(
EnggDiffGSASFittingPresenter &&other)
: m_model(std::move(other.m_model)), m_view(std::move(other.m_view)),
: m_model(std::move(other.m_model)), m_view(other.m_view),
m_viewHasClosed(other.m_viewHasClosed) {}
EnggDiffGSASFittingPresenter &EnggDiffGSASFittingPresenter::
......@@ -130,8 +129,12 @@ void EnggDiffGSASFittingPresenter::processDoRefinement() {
}
void EnggDiffGSASFittingPresenter::processLoadRun() {
const auto focusedFileName = m_view->getFocusedFileName();
const auto loadSuccessful = m_model->loadFocusedRun(focusedFileName);
const auto focusedFileNames = m_view->getFocusedFileNames();
bool loadSuccessful = true;
for (const auto &fileName : focusedFileNames) {
loadSuccessful &= m_model->loadFocusedRun(fileName);
}
if (loadSuccessful) {
const auto runLabels = m_model->getRunLabels();
......
......@@ -19,7 +19,7 @@ class MANTIDQT_ENGGDIFFRACTION_DLL EnggDiffGSASFittingPresenter
public:
EnggDiffGSASFittingPresenter(std::unique_ptr<IEnggDiffGSASFittingModel> model,
std::unique_ptr<IEnggDiffGSASFittingView> view);
IEnggDiffGSASFittingView *view);
EnggDiffGSASFittingPresenter(EnggDiffGSASFittingPresenter &&other);
......@@ -86,7 +86,7 @@ private:
std::unique_ptr<IEnggDiffGSASFittingModel> m_model;
std::unique_ptr<IEnggDiffGSASFittingView> m_view;
IEnggDiffGSASFittingView *m_view;
bool m_viewHasClosed;
};
......
#include "EnggDiffGSASFittingViewQtWidget.h"
#include "EnggDiffGSASFittingModel.h"
#include "EnggDiffGSASFittingPresenter.h"
#include <QFileDialog>
namespace MantidQt {
namespace CustomInterfaces {
EnggDiffGSASFittingViewQtWidget::EnggDiffGSASFittingViewQtWidget() {
setupUI();
m_zoomTool = Mantid::Kernel::make_unique<QwtPlotZoomer>(
QwtPlot::xBottom, QwtPlot::yLeft,
QwtPicker::DragSelection | QwtPicker::CornerToCorner,
QwtPicker::AlwaysOff, m_ui.plotArea->canvas());
m_zoomTool->setRubberBandPen(QPen(Qt::black));
setZoomToolEnabled(false);
auto model = Mantid::Kernel::make_unique<EnggDiffGSASFittingModel>();
m_presenter = Mantid::Kernel::make_unique<EnggDiffGSASFittingPresenter>(
std::move(model), this);
m_presenter->notify(IEnggDiffGSASFittingPresenter::Start);
}
EnggDiffGSASFittingViewQtWidget::~EnggDiffGSASFittingViewQtWidget() {
m_presenter->notify(IEnggDiffGSASFittingPresenter::ShutDown);
for (auto &curves : m_focusedRunCurves) {
curves->detach();
}
m_focusedRunCurves.clear();
}
void EnggDiffGSASFittingViewQtWidget::browseFocusedRun() {
const auto filenames(
QFileDialog::getOpenFileNames(this, tr("Find focused run files")));
setFocusedRunFileNames(filenames);
}
void EnggDiffGSASFittingViewQtWidget::displayLatticeParams(
const Mantid::API::ITableWorkspace_sptr latticeParams) const {
UNUSED_ARG(latticeParams);
throw std::runtime_error("displayLatticeParams not yet implemented");
}
void EnggDiffGSASFittingViewQtWidget::displayRwp(const double rwp) const {
UNUSED_ARG(rwp);
throw std::runtime_error("displayRwp not yet implemented");
}
std::vector<std::string>
EnggDiffGSASFittingViewQtWidget::getFocusedFileNames() const {
const auto filenamesQStringList = m_ui.lineEdit_runFile->text().split(",");
std::vector<std::string> filenames;
for (const auto &filenameQString : filenamesQStringList) {
filenames.push_back(filenameQString.toStdString());
}
return filenames;
}
std::string EnggDiffGSASFittingViewQtWidget::getGSASIIProjectPath() const {
throw std::runtime_error("getGSASIIProjectPath not yet implemented");
}
std::string EnggDiffGSASFittingViewQtWidget::getInstrumentFileName() const {
throw std::runtime_error("getInstrumentFileName not yet implemented");
}
std::string EnggDiffGSASFittingViewQtWidget::getPathToGSASII() const {
throw std::runtime_error("getPathToGSASII not yet implemented");
}
double EnggDiffGSASFittingViewQtWidget::getPawleyDMin() const {
throw std::runtime_error("getPawleyDMin not yet implemented");
}
double EnggDiffGSASFittingViewQtWidget::getPawleyNegativeWeight() const {
throw std::runtime_error("getPawleyNegativeWeight not yet implemented");
}
std::vector<std::string>
EnggDiffGSASFittingViewQtWidget::getPhaseFileNames() const {
throw std::runtime_error("getPhaseFileNames not yet implemented");
}
GSASRefinementMethod
EnggDiffGSASFittingViewQtWidget::getRefinementMethod() const {
throw std::runtime_error("getRefinementMethod not yet implemented");
}
RunLabel EnggDiffGSASFittingViewQtWidget::getSelectedRunLabel() const {
const auto currentItemLabel =
m_ui.listWidget_runLabels->currentItem()->text();
const auto pieces = currentItemLabel.split("_");
if (pieces.size() != 2) {
throw std::runtime_error(
"Unexpected run label: \"" + currentItemLabel.toStdString() +
"\". Please contact the development team with this message");
}
return RunLabel(pieces[0].toInt(), pieces[1].toUInt());
}
void EnggDiffGSASFittingViewQtWidget::loadFocusedRun() {
m_presenter->notify(IEnggDiffGSASFittingPresenter::LoadRun);
}
void EnggDiffGSASFittingViewQtWidget::plotCurve(
const std::vector<boost::shared_ptr<QwtData>> &curves) {
m_focusedRunCurves.reserve(curves.size());
for (const auto &curve : curves) {
auto plotCurve = Mantid::Kernel::make_unique<QwtPlotCurve>();
plotCurve->setData(*curve);
plotCurve->attach(m_ui.plotArea);
m_focusedRunCurves.push_back(std::move(plotCurve));
}
m_ui.plotArea->replot();
m_zoomTool->setZoomBase();
setZoomToolEnabled(true);
}
void EnggDiffGSASFittingViewQtWidget::resetCanvas() {
for (auto &curve : m_focusedRunCurves) {
curve->detach();
}
m_focusedRunCurves.clear();
resetPlotZoomLevel();
}
void EnggDiffGSASFittingViewQtWidget::resetPlotZoomLevel() {
m_ui.plotArea->setAxisAutoScale(QwtPlot::xBottom);
m_ui.plotArea->setAxisAutoScale(QwtPlot::yLeft);
m_zoomTool->setZoomBase(true);
}
void EnggDiffGSASFittingViewQtWidget::selectRun() {
m_presenter->notify(IEnggDiffGSASFittingPresenter::SelectRun);
}
void EnggDiffGSASFittingViewQtWidget::setEnabled(const bool enabled) {
m_ui.lineEdit_runFile->setEnabled(enabled);
m_ui.pushButton_browseRunFile->setEnabled(enabled);
m_ui.pushButton_loadRun->setEnabled(enabled);
m_ui.lineEdit_instParamsFile->setEnabled(enabled);
m_ui.pushButton_browseInstParams->setEnabled(enabled);
m_ui.lineEdit_phaseFiles->setEnabled(enabled);
m_ui.pushButton_browsePhaseFiles->setEnabled(enabled);
m_ui.lineEdit_gsasProjPath->setEnabled(enabled);
m_ui.pushButton_gsasProjPath->setEnabled(enabled);
m_ui.lineEdit_gsasHome->setEnabled(enabled);
m_ui.pushButton_browseGSASHome->setEnabled(enabled);
m_ui.comboBox_refinementMethod->setEnabled(enabled);
m_ui.lineEdit_pawleyDMin->setEnabled(enabled);
m_ui.lineEdit_pawleyNegativeWeight->setEnabled(enabled);
m_ui.checkBox_showRefinementResults->setEnabled(enabled);
}
void EnggDiffGSASFittingViewQtWidget::setFocusedRunFileNames(
const QStringList &filenames) {
m_ui.lineEdit_runFile->setText(filenames.join(tr(",")));
}
void EnggDiffGSASFittingViewQtWidget::setupUI() {
m_ui.setupUi(this);
connect(m_ui.pushButton_browseRunFile, SIGNAL(clicked()), this,
SLOT(browseFocusedRun()));
connect(m_ui.pushButton_loadRun, SIGNAL(clicked()), this,
SLOT(loadFocusedRun()));
connect(m_ui.listWidget_runLabels, SIGNAL(itemSelectionChanged()), this,
SLOT(selectRun()));
}
void EnggDiffGSASFittingViewQtWidget::setZoomToolEnabled(const bool enabled) {
m_zoomTool->setEnabled(enabled);
}
bool EnggDiffGSASFittingViewQtWidget::showRefinementResultsSelected() const {
return m_ui.checkBox_showRefinementResults->isChecked();
}
void EnggDiffGSASFittingViewQtWidget::updateRunList(
const std::vector<RunLabel> &runLabels) {
m_ui.listWidget_runLabels->clear();
for (const auto &runLabel : runLabels) {
const auto labelStr = QString::number(runLabel.runNumber) + tr("_") +
QString::number(runLabel.bank);
m_ui.listWidget_runLabels->addItem(labelStr);
}
}
void EnggDiffGSASFittingViewQtWidget::userWarning(
const std::string &warningDescription) const {
UNUSED_ARG(warningDescription);
throw std::runtime_error("userWarning not yet implemented");
}
} // CustomInterfaces
} // MantidQt
#ifndef MANTIDQTCUSTOMINTERFACES_ENGGDIFFRACTION_IENGGDIFFGSASFITTINGVIEWQTWIDGET_H_
#define MANTIDQTCUSTOMINTERFACES_ENGGDIFFRACTION_IENGGDIFFGSASFITTINGVIEWQTWIDGET_H_
#include "DllConfig.h"
#include "IEnggDiffGSASFittingPresenter.h"
#include "IEnggDiffGSASFittingView.h"
#include <qwt_plot_curve.h>
#include <qwt_plot_zoomer.h>
#include "ui_EnggDiffractionQtTabGSAS.h"
namespace MantidQt {
namespace CustomInterfaces {
class MANTIDQT_ENGGDIFFRACTION_DLL EnggDiffGSASFittingViewQtWidget
: public QWidget,
public IEnggDiffGSASFittingView {
Q_OBJECT
public:
EnggDiffGSASFittingViewQtWidget();
~EnggDiffGSASFittingViewQtWidget() override;
void displayLatticeParams(
const Mantid::API::ITableWorkspace_sptr latticeParams) const override;
void displayRwp(const double rwp) const override;
void setZoomToolEnabled(const bool enabled);
std::vector<std::string> getFocusedFileNames() const override;
std::string getGSASIIProjectPath() const override;
std::string getInstrumentFileName() const override;
std::string getPathToGSASII() const override;
double getPawleyDMin() const override;
double getPawleyNegativeWeight() const override;
std::vector<std::string> getPhaseFileNames() const override;
GSASRefinementMethod getRefinementMethod() const override;
RunLabel getSelectedRunLabel() const override;
void plotCurve(const std::vector<boost::shared_ptr<QwtData>> &curve) override;
void resetCanvas() override;
void resetPlotZoomLevel();
void setEnabled(const bool enabled);
bool showRefinementResultsSelected() const override;
void updateRunList(const std::vector<RunLabel> &runLabels) override;
void userWarning(const std::string &warningDescription) const override;
private slots:
void browseFocusedRun();
void loadFocusedRun();
void selectRun();
private:
std::vector<std::unique_ptr<QwtPlotCurve>> m_focusedRunCurves;
std::unique_ptr<IEnggDiffGSASFittingPresenter> m_presenter;
Ui::EnggDiffractionQtTabGSAS m_ui;
std::unique_ptr<QwtPlotZoomer> m_zoomTool;
void setFocusedRunFileNames(const QStringList &filenames);
void setupUI();
};
} // MantidQt
} // CustomInterfaces
#endif // MANTIDQTCUSTOMINTERFACES_ENGGDIFFRACTION_IENGGDIFFGSASFITTINGVIEWQTWIDGET_H_
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>EnggDiffractionQtTabGSAS</class>
<widget class="QWidget" name="EnggDiffractionQtTabGSAS">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>549</width>
<height>658</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="groupBox_generalParams">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>1</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>General Parameters</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="2" column="0">
<widget class="QLabel" name="label_phaseFiles">
<property name="toolTip">
<string>*.cif files containing the phases to refine</string>
</property>
<property name="text">
<string>Phase Files</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_gsasProjPath">
<property name="toolTip">
<string>The name of a new *.gpx project to write refinement results out to. This can be opened and used for more complex refinements in GSAS-II</string>
</property>
<property name="text">
<string>New GSAS-II Project</string>
</property>
</widget>
</item>
<item row="3" column="2">
<widget class="QPushButton" name="pushButton_gsasProjPath">
<property name="text">
<string>Browse</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_runFile">
<property name="toolTip">
<string>Nexus file containing a spectrum focused using EnggFocus or the Focus tab</string>
</property>
<property name="text">
<string>Focused Run File</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="lineEdit_gsasProjPath"/>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="lineEdit_instParamsFile"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_instParamsFile">
<property name="toolTip">
<string>GSAS-style instrument file (extension *.prm)</string>
</property>
<property name="text">
<string>Instrument Parameter File</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="pushButton_browseRunFile">
<property name="text">
<string>Browse</string>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QPushButton" name="pushButton_loadRun">
<property name="text">
<string>Load</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QPushButton" name="pushButton_browseInstParams">
<property name="text">
<string>Browse</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="lineEdit_runFile"/>
</item>
<item row="4" column="2">
<widget class="QPushButton" name="pushButton_browseGSASHome">
<property name="text">
<string>Browse</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_refinementMethod">
<property name="toolTip">
<string>Rietveld or Pawley</string>
</property>
<property name="text">
<string>Refinement Method</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLineEdit" name="lineEdit_gsasHome"/>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_gsasHome">
<property name="toolTip">
<string>Directory containing GSAS-II installation. This directory must contain GSASIIscriptable.py</string>
</property>
<property name="text">
<string>GSAS-II Installation Directory</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QPushButton" name="pushButton_browsePhaseFiles">
<property name="text">
<string>Browse</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="lineEdit_phaseFiles"/>
</item>
<item row="5" column="1">
<widget class="QComboBox" name="comboBox_refinementMethod">
<item>
<property name="text">
<string>Pawley</string>
</property>
</item>
<item>
<property name="text">
<string>Rietveld</string>
</property>
</item>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_pawleyParams">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>Pawley Parameters</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label_pawleyDMin">
<property name="toolTip">
<string>The minimum d-spacing to use. Leave empty to use the default (1)</string>
</property>
<property name="text">
<string>DMin</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_pawleyDMin">
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_8">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>