diff --git a/qt/scientific_interfaces/Indirect/ISISEnergyTransfer.cpp b/qt/scientific_interfaces/Indirect/ISISEnergyTransfer.cpp index 10f1d75a203a5505c378e4337e15cf17f197ba32..679295fc2f5fbc19535cddbdf7f2be1bd4fd24bb 100644 --- a/qt/scientific_interfaces/Indirect/ISISEnergyTransfer.cpp +++ b/qt/scientific_interfaces/Indirect/ISISEnergyTransfer.cpp @@ -1,14 +1,54 @@ #include "ISISEnergyTransfer.h" +#include "../General/UserInputValidator.h" #include "MantidAPI/MatrixWorkspace.h" #include "MantidAPI/WorkspaceGroup.h" -#include "../General/UserInputValidator.h" #include <QFileInfo> using namespace Mantid::API; using MantidQt::API::BatchAlgorithmRunner; +namespace { + +std::string createRangeString(std::size_t from, std::size_t to) { + return std::to_string(from) + "-" + std::to_string(to); +} + +std::string createGroupString(std::size_t start, std::size_t size) { + return createRangeString(start, start + size - 1); +} + +std::string createGroupingString(std::size_t groupSize, + std::size_t numberOfGroups) { + auto groupingString = createRangeString(0, groupSize - 1); + for (auto i = groupSize; i < groupSize * numberOfGroups; i += groupSize) + groupingString += "," + createGroupString(i, groupSize); + return groupingString; +} + +std::string createDetectorGroupingString(std::size_t groupSize, + std::size_t numberOfGroups, + std::size_t numberOfDetectors) { + const auto groupingString = createGroupingString(groupSize, numberOfGroups); + const auto remainder = numberOfDetectors % numberOfGroups; + if (remainder == 0) + return groupingString; + return groupingString + "," + createRangeString(numberOfDetectors - remainder, + numberOfDetectors - 1); +} + +std::string createDetectorGroupingString(std::size_t numberOfDetectors, + std::size_t numberOfGroups) { + const auto groupSize = numberOfDetectors / numberOfGroups; + if (groupSize == 0) + return createRangeString(0, numberOfDetectors - 1); + return createDetectorGroupingString(groupSize, numberOfGroups, + numberOfDetectors); +} + +} // namespace + namespace MantidQt { namespace CustomInterfaces { //---------------------------------------------------------------------------------------------- @@ -457,7 +497,7 @@ ISISEnergyTransfer::createMapFile(const std::string &groupType) { return std::make_pair("File", groupFile.toStdString()); } else if (groupType == "Groups") - return std::make_pair("Custom", createDetectorGroupingString()); + return std::make_pair("Custom", getDetectorGroupingString()); else if (groupType == "Default") return std::make_pair("IPF", ""); else if (groupType == "Custom") @@ -469,25 +509,12 @@ ISISEnergyTransfer::createMapFile(const std::string &groupType) { } } -const std::string ISISEnergyTransfer::createDetectorGroupingString() { - +std::string ISISEnergyTransfer::getDetectorGroupingString() const { const unsigned int nGroups = m_uiForm.spNumberGroups->value(); const unsigned int nSpectra = - m_uiForm.spSpectraMax->value() - m_uiForm.spSpectraMin->value(); - const unsigned int groupSize = nSpectra / nGroups; - auto n = groupSize; - std::stringstream groupingString; - groupingString << "0-" << std::to_string(n); - for (auto i = 1u; i < nGroups; ++i) { - groupingString << ", " << std::to_string(n + 1) << "-"; - n += groupSize; - groupingString << std::to_string(n); - } - if (n != nSpectra) // add remainder as extra group - groupingString << ", " << std::to_string(n + 1) << "-" - << std::to_string(nSpectra); - - return groupingString.str(); + 1 + m_uiForm.spSpectraMax->value() - m_uiForm.spSpectraMin->value(); + return createDetectorGroupingString(static_cast<std::size_t>(nSpectra), + static_cast<std::size_t>(nGroups)); } /** @@ -575,6 +602,7 @@ void ISISEnergyTransfer::plotRaw() { if (m_uiForm.ckBackgroundRemoval->isChecked()) { MatrixWorkspace_sptr tempWs = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(name); + const double minBack = tempWs->x(0)[0]; const double maxBack = tempWs->x(0)[tempWs->blocksize()]; @@ -744,4 +772,4 @@ void ISISEnergyTransfer::saveClicked() { } } // namespace CustomInterfaces -} // namespace Mantid +} // namespace MantidQt diff --git a/qt/scientific_interfaces/Indirect/ISISEnergyTransfer.h b/qt/scientific_interfaces/Indirect/ISISEnergyTransfer.h index 35d45304eb7bdabde3c35b33f5b5f02975f5a5a5..0d2e8792ea1a3df7ecceef09993ae9cb1de071b3 100644 --- a/qt/scientific_interfaces/Indirect/ISISEnergyTransfer.h +++ b/qt/scientific_interfaces/Indirect/ISISEnergyTransfer.h @@ -76,7 +76,7 @@ private: std::vector<std::string> m_outputWorkspaces; ///< get a vector of workspaces to plot QString validateDetectorGrouping(); - const std::string createDetectorGroupingString(); + std::string getDetectorGroupingString() const; }; } // namespace CustomInterfaces } // namespace Mantid diff --git a/qt/scientific_interfaces/Indirect/ISISEnergyTransfer.ui b/qt/scientific_interfaces/Indirect/ISISEnergyTransfer.ui index 1585025f02389920ccca2f28dac35263e3588dc2..8fea6d1d7f674e7f19714b8b8f18f00999340697 100644 --- a/qt/scientific_interfaces/Indirect/ISISEnergyTransfer.ui +++ b/qt/scientific_interfaces/Indirect/ISISEnergyTransfer.ui @@ -289,7 +289,11 @@ </widget> </item> <item> - <widget class="QSpinBox" name="spNumberGroups"/> + <widget class="QSpinBox" name="spNumberGroups"> + <property name="minimum"> + <number>1</number> + </property> + </widget> </item> <item> <spacer name="horizontalSpacer_5"> @@ -313,19 +317,19 @@ <property name="enabled"> <bool>true</bool> </property> - <property name="toolTip"> - <string>, allows you to specify additional indices. 1,2,4 will keep indices 1, 2 and 4 only. -: indicates a continuous range of indices. For example, 1:5 is the same as 1,2,3,4,5. -+ sums two spectra together. 7+9 will produce a single spectra listing the sum of 7 and 9, ignoring any others. -- sums a range of spectra together. For example, 3-8 is the same as 3+4+5+6+7+8. - </string> - </property> <property name="maximumSize"> <size> <width>16777215</width> <height>16777215</height> </size> </property> + <property name="toolTip"> + <string>, allows you to specify additional indices. 1,2,4 will keep indices 1, 2 and 4 only. +: indicates a continuous range of indices. For example, 1:5 is the same as 1,2,3,4,5. ++ sums two spectra together. 7+9 will produce a single spectra listing the sum of 7 and 9, ignoring any others. +- sums a range of spectra together. For example, 3-8 is the same as 3+4+5+6+7+8. + </string> + </property> <property name="layoutDirection"> <enum>Qt::LeftToRight</enum> </property> @@ -572,7 +576,16 @@ <property name="spacing"> <number>0</number> </property> - <property name="margin"> + <property name="leftMargin"> + <number>0</number> + </property> + <property name="topMargin"> + <number>0</number> + </property> + <property name="rightMargin"> + <number>0</number> + </property> + <property name="bottomMargin"> <number>0</number> </property> <item> @@ -580,7 +593,16 @@ <property name="spacing"> <number>6</number> </property> - <property name="margin"> + <property name="leftMargin"> + <number>6</number> + </property> + <property name="topMargin"> + <number>6</number> + </property> + <property name="rightMargin"> + <number>6</number> + </property> + <property name="bottomMargin"> <number>6</number> </property> <item>