diff --git a/qt/scientific_interfaces/Indirect/AbsorptionCorrections.cpp b/qt/scientific_interfaces/Indirect/AbsorptionCorrections.cpp index c44e7455197402af2851ea08af31bde8362cfa71..6f17759fe115e5179caff899739da59e97b6219f 100644 --- a/qt/scientific_interfaces/Indirect/AbsorptionCorrections.cpp +++ b/qt/scientific_interfaces/Indirect/AbsorptionCorrections.cpp @@ -10,6 +10,7 @@ #include <QRegExpValidator> using namespace Mantid::API; +using namespace Mantid::Geometry; namespace { Mantid::Kernel::Logger g_log("AbsorptionCorrections"); @@ -71,6 +72,8 @@ AbsorptionCorrections::AbsorptionCorrections(QWidget *parent) // Change of input connect(m_uiForm.dsSampleInput, SIGNAL(dataReady(const QString &)), this, SLOT(getBeamDefaults(const QString &))); + connect(m_uiForm.dsSampleInput, SIGNAL(dataReady(const QString &)), this, + SLOT(getMonteCarloDefaults(const QString &))); // Handle algorithm completion connect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this, @@ -401,6 +404,65 @@ void AbsorptionCorrections::getBeamDefaults(const QString &dataName) { } } +void AbsorptionCorrections::getMonteCarloDefaults(const QString &dataName) { + auto sampleWs = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>( + dataName.toStdString()); + + if (sampleWs) { + auto instrument = sampleWs->getInstrument(); + setWavelengthsValue(instrument, "Workflow.absorption-wavelengths"); + setEventsValue(instrument, "Workflow.absorption-events"); + setInterpolationValue(instrument, "Workflow.absorption-interpolation"); + setMaxAttemptsValue(instrument, "Workflow.absorption-attempts"); + } else + displayInvalidWorkspaceTypeError(dataName.toStdString(), g_log); +} + +void AbsorptionCorrections::setWavelengthsValue( + Instrument_const_sptr instrument, + const std::string &wavelengthsParamName) const { + if (instrument->hasParameter(wavelengthsParamName)) { + const auto wavelengths = QString::fromStdString( + instrument->getStringParameter(wavelengthsParamName)[0]); + const auto wavelengthsValue = wavelengths.toInt(); + m_uiForm.spNumberWavelengths->setValue(wavelengthsValue); + } +} + +void AbsorptionCorrections::setEventsValue( + Instrument_const_sptr instrument, + const std::string &eventsParamName) const { + if (instrument->hasParameter(eventsParamName)) { + const auto events = QString::fromStdString( + instrument->getStringParameter(eventsParamName)[0]); + const auto eventsValue = events.toInt(); + m_uiForm.spNumberEvents->setValue(eventsValue); + } +} + +void AbsorptionCorrections::setInterpolationValue( + Instrument_const_sptr instrument, + const std::string &interpolationParamName) const { + if (instrument->hasParameter(interpolationParamName)) { + const auto interpolation = QString::fromStdString( + instrument->getStringParameter(interpolationParamName)[0]); + const auto interpolationValue = interpolation.toStdString(); + m_uiForm.cbInterpolation->setCurrentIndex( + interpolationValue == "CSpline" ? 1 : 0); + } +} + +void AbsorptionCorrections::setMaxAttemptsValue( + Instrument_const_sptr instrument, + const std::string &maxAttemptsParamName) const { + if (instrument->hasParameter(maxAttemptsParamName)) { + const auto maxScatterAttempts = QString::fromStdString( + instrument->getStringParameter(maxAttemptsParamName)[0]); + const auto maxScatterAttemptsValue = maxScatterAttempts.toInt(); + m_uiForm.spMaxScatterPtAttempts->setValue(maxScatterAttemptsValue); + } +} + /** * Handle saving of workspace */ diff --git a/qt/scientific_interfaces/Indirect/AbsorptionCorrections.h b/qt/scientific_interfaces/Indirect/AbsorptionCorrections.h index d8040ad276c10f56b9949fef3ccb02cf0c742a99..89fa57a115de7d07284fde63f77a2bade83ac00b 100644 --- a/qt/scientific_interfaces/Indirect/AbsorptionCorrections.h +++ b/qt/scientific_interfaces/Indirect/AbsorptionCorrections.h @@ -28,6 +28,15 @@ private slots: void saveClicked(); void plotClicked(); void getBeamDefaults(const QString &dataName); + void getMonteCarloDefaults(const QString &dataName); + void setWavelengthsValue(Mantid::Geometry::Instrument_const_sptr instrument, + const std::string &wavelengthsParamName) const; + void setEventsValue(Mantid::Geometry::Instrument_const_sptr instrument, + const std::string &eventsParamName) const; + void setInterpolationValue(Mantid::Geometry::Instrument_const_sptr instrument, + const std::string &interpolationParamName) const; + void setMaxAttemptsValue(Mantid::Geometry::Instrument_const_sptr instrument, + const std::string &maxAttemptsParamName) const; void changeSampleDensityUnit(int); void changeCanDensityUnit(int); UserInputValidator doValidation();