19#include <QtAlgorithms>
22#include <boost/lexical_cast.hpp>
55 const bool showWaterfallOption,
const bool showTiledOption,
56 const bool isAdvanced)
57 : QWidget(parent, flags), m_spectra(false), m_waterfall(showWaterfallOption), m_tiled(showTiledOption),
58 m_advanced(isAdvanced), m_plotOptions(), m_wsNames(wsNames), m_wsIndexIntervals(), m_spectraNumIntervals(),
59 m_wsIndexChoice(), m_spectraNumChoice() {
100 userInputAdvanced.
logName =
"";
110 options.
advanced = std::move(userInputAdvanced);
122 int spectrumIndex = 0;
125 if (!userInput.empty()) {
126 const auto indexList = userInput.values();
127 if (!indexList.empty()) {
128 const auto &spectrumIndexes = indexList.at(0);
129 if (!spectrumIndexes.empty()) {
130 spectrumIndex = *spectrumIndexes.begin();
134 return spectrumIndex;
142 if (!message.isEmpty()) {
143 QMessageBox errorMessage;
144 errorMessage.setText(message);
145 errorMessage.setIcon(QMessageBox::Critical);
158 std::set<double> logValues;
161 foreach (QString
value, values) {
163 double number =
value.toDouble(&ok);
165 logValues.insert(number);
197 plots.insert(wsName, intSet);
213 std::set<int>::iterator it = origSet.begin();
214 std::set<int> convertedSet;
216 for (; it != origSet.end(); ++it) {
218 int convertedInt =
static_cast<int>(spec2index.find(origInt)->second);
219 convertedSet.insert(convertedInt);
222 plots.insert(wsName, convertedSet);
286 bool acceptable =
false;
290 QValidator::State wsState =
m_wsField->
lineEdit()->validator()->validate(wsText, npos);
292 if (wsState == QValidator::Acceptable) {
299 else if (spectraState == QValidator::Acceptable) {
307 QString error_message(
"Invalid input. It is not in the range available");
308 if (!wsText.isEmpty())
310 if (!spectraText.isEmpty())
312 if (wsText.isEmpty() && spectraText.isEmpty()) {
342 bool validOptions =
true;
348 bool firstValue =
true;
349 double previousValue = 0.0;
350 for (
const auto &
value : values) {
352 double currentValue =
value.toDouble(&ok);
356 validOptions =
false;
362 previousValue = currentValue;
364 if (previousValue < currentValue) {
366 previousValue = currentValue;
369 validOptions =
false;
376 int numCustomLogValues = values.size();
377 QString nCustomLogValues;
378 nCustomLogValues.setNum(numCustomLogValues);
382 nWorkspaces.setNum(numWorkspaces);
384 if (numCustomLogValues != numWorkspaces) {
386 ") is not equal to the number of workspaces (" + nWorkspaces +
").");
387 validOptions =
false;
396 nPlots.setNum(numWorkspaces * numSpectra);
398 if (numCustomLogValues != numWorkspaces * numSpectra) {
400 ") is not equal to the number of plots (" + nPlots +
").");
401 validOptions =
false;
436 const QString label =
"Enter Workspace Indices: " + wsIndices;
441 if (wsIndices ==
"0") {
497 connect(
m_plotOptions, SIGNAL(currentIndexChanged(
const QString &)),
this,
505 int spacingAboveShowErrorBars = 10;
518 m_logLabel =
new QLabel(tr(
"Log value to plot against:"));
525 m_axisLabel =
new QLabel(tr(
"<br>Label for plot axis:"));
567 auto isSurfaceOrContourPlot =
572 m_logValues->setEnabled(useLogNames && isLogSelectorCustom);
588struct LogTestStruct {
610 std::map<std::string, LogTestStruct> usableLogs;
614 const auto runObj = ws->run();
615 const std::vector<Mantid::Kernel::Property *> &logData = runObj.getLogData();
616 for (
auto &log : logData) {
617 const std::string &name = log->name();
620 usableLogs[name] = LogTestStruct{
true,
value};
621 }
catch (std::invalid_argument &) {
632 const auto runObj = ws->run();
633 for (
auto &logItem : usableLogs) {
634 if (runObj.hasProperty(logItem.first)) {
636 if (logItem.second.isconstantvalue) {
639 logItem.second.isconstantvalue = (
value == logItem.second.value);
642 usableLogs.erase(logItem.first);
649 for (
auto &logItem : usableLogs) {
650 if (!(logItem.second.isconstantvalue)) {
660 return std::dynamic_pointer_cast<const Mantid::API::MatrixWorkspace>(
682 for (; it !=
m_wsNames.constEnd(); ++it) {
688 for (
int i = 0; i < ws->axes(); i++) {
689 if (ws->getAxis(i)->isSpectra())
708 for (; it !=
m_wsNames.constEnd(); ++it) {
714 const int endWs =
static_cast<int>(ws->getNumberHistograms() - 1);
741 for (
const auto &pair : spec2index) {
742 spectraIntervalList.
addInterval(
static_cast<int>(pair.first));
776 const bool showWaterfallOption,
const bool showPlotAll,
777 const bool showTiledOption,
const bool isAdvanced)
778 : QDialog(parent, flags), m_widget(this, flags, wsNames, showWaterfallOption, showTiledOption, isAdvanced),
779 m_plotAll(showPlotAll) {
860 setWindowTitle(tr(
"Plot Advanced"));
862 setWindowTitle(tr(
"Plot Spectrum"));
899 const QString patternSingle(
"^\\d+$");
900 const QString patternRange(
"^\\d+-\\d+$");
901 const QRegExp regExpSingle(patternSingle);
902 const QRegExp regExpRange(patternRange);
904 if (regExpSingle.exactMatch(intervalString)) {
905 int single = intervalString.toInt();
906 init(single, single);
907 }
else if (regExpRange.exactMatch(intervalString)) {
908 QStringList range = intervalString.split(
"-");
909 int start = range[0].toInt();
910 int end = range[1].toInt();
913 throw std::exception();
929 if (other.end() >
m_end)
936 return !(other.start() >
m_end + 1 || other.end() + 1 <
m_start);
948 std::set<int> intSet;
963 output += boost::lexical_cast<std::string>(
m_start);
965 output += boost::lexical_cast<std::string>(
m_start) +
"-";
966 output += boost::lexical_cast<std::string>(
m_end);
976 output.append(QString(
"%1").arg(
m_start));
978 output.append(QString(
"%1").arg(
m_start));
980 output.append(QString(
"%1").arg(
m_end));
1015 return std::accumulate(
m_list.cbegin(),
m_list.cend(), 0,
1016 [](
int lhs,
const auto &interval) { return lhs + interval.length(); });
1022 if (
m_list.size() <= numOfIntervals) {
1023 for (
int i = 0; i <
m_list.size(); i++) {
1027 output +=
m_list.at(i).toStdString();
1035 for (
int i = 0; i < numOfIntervals - 1; i++) {
1039 output +=
m_list[i].toStdString();
1042 output +=
", ..., ";
1043 output +=
m_list.back().toStdString();
1049 QString output(
toStdString(numOfIntervals).c_str());
1064 if (
m_list.size() == 0) {
1072 for (
int i =
m_list.size() - 1; i >= 0; i--) {
1081 else if (
m_list.at(i).canMerge(interval)) {
1083 for (
int j = i; j >= 0; j--) {
1085 if (
m_list.at(j).canMerge(interval)) {
1089 deleteList.append(j);
1098 m_list.insert(i + 1, interval);
1104 if (deleteList.size() > 0) {
1106 sort(std::begin(deleteList), std::end(deleteList));
1108 for (
int i = deleteList.size() - 1; i >= 0; i--) {
1109 m_list.removeAt(deleteList[i]);
1114 m_list.insert(0, interval);
1126 intervals = intervals.simplified();
1127 intervals = intervals.replace(
" ",
"");
1130 QStringList intervalList = intervals.split(
",");
1131 for (
int i = 0; i < intervalList.size(); i++) {
1132 Interval interval(intervalList[i]);
1142 for (; it != list.constEnd(); ++it) {
1152 std::set<int> intSet;
1154 for (
const auto &i :
m_list) {
1155 std::set<int> intervalSet = i.getIntSet();
1156 intSet.insert(intervalSet.begin(), intervalSet.end());
1164 std::find_if(
m_list.cbegin(),
m_list.cend(), [&other](
const auto &interval) { return interval.contains(other); });
1165 return it !=
m_list.cend();
1169 const auto it = std::find_if((other.m_list).cbegin(), (other.m_list).cend(),
1170 [
this](
const auto &interval) { return !IntervalList::contains(interval); });
1171 return it == (other.m_list).cend();
1178 }
catch (std::exception &) {
1187 }
catch (std::exception &) {
1201 const std::set<int> aInts = a.
getIntSet();
1202 const std::set<int> bInts = b.
getIntSet();
1204 for (
const auto &aInt : aInts) {
1205 const bool inIntervalListB = bInts.find(aInt) != bInts.end();
1206 if (inIntervalListB)
1217 : QValidator(parent), m_intervalList(
std::move(intervalList)) {}
1222 return QValidator::Acceptable;
1224 const QString pattern(
"^(\\d|-|,)*$");
1225 const QRegExp regExp(pattern);
1227 if (regExp.exactMatch(input))
1228 return QValidator::Intermediate;
1230 return QValidator::Invalid;
1237 auto *layout =
new QGridLayout();
1241 pal.setColor(QPalette::WindowText, Qt::darkRed);
1250 if (
error.isEmpty()) {
1251 m_validLbl->setVisible(
false);
1253 m_validLbl->setVisible(
true);
1254 m_validLbl->setToolTip(
error.trimmed());
double value
The value of the point.
#define UNUSED_ARG(x)
Function arguments are sometimes unused in certain implmentations but are required for documentation ...
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
std::shared_ptr< const MatrixWorkspace > MatrixWorkspace_const_sptr
shared pointer to the matrix workspace base class (const version)
std::unordered_map< specnum_t, size_t > spec2index_map
Map with key = spectrum number, value = workspace index.