18#include <QRegularExpression>
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 for (QString
const &
value : values) {
163 double number =
value.toDouble(&ok);
165 logValues.insert(number);
197 plots.insert(wsName, intSet);
206 Mantid::API::AnalysisDataService::Instance().retrieve(wsName.toStdString()));
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 =
static_cast<int>(values.size());
377 QString nCustomLogValues;
378 nCustomLogValues.setNum(numCustomLogValues);
379 int numWorkspaces =
static_cast<int>(
m_wsNames.size());
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(currentTextChanged(
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>(
661 Mantid::API::AnalysisDataService::Instance().retrieve(workspaceName.toStdString()));
682 for (; it !=
m_wsNames.constEnd(); ++it) {
684 Mantid::API::AnalysisDataService::Instance().retrieve((*it).toStdString()));
688 for (
int i = 0; i < ws->axes(); i++) {
689 if (ws->getAxis(i)->isSpectra())
708 for (; it !=
m_wsNames.constEnd(); ++it) {
710 Mantid::API::AnalysisDataService::Instance().retrieve((*it).toStdString()));
714 const int endWs =
static_cast<int>(ws->getNumberHistograms() - 1);
734 Mantid::API::AnalysisDataService::Instance().retrieve(wsName.toStdString()));
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+");
902 const QRegularExpression regExpSingle(QRegularExpression::anchoredPattern(patternSingle));
903 const QRegularExpression regExpRange(QRegularExpression::anchoredPattern(patternRange));
905 if (regExpSingle.match(intervalString).hasMatch()) {
906 int single = intervalString.toInt();
907 init(single, single);
908 }
else if (regExpRange.match(intervalString).hasMatch()) {
909 QStringList range = intervalString.split(
"-");
910 int first = range[0].toInt();
911 int last = range[1].toInt();
914 throw std::exception();
930 if (other.end() >
m_end)
937 return !(other.start() >
m_end + 1 || other.end() + 1 <
m_start);
949 std::set<int> intSet;
964 output += boost::lexical_cast<std::string>(
m_start);
966 output += boost::lexical_cast<std::string>(
m_start) +
"-";
967 output += boost::lexical_cast<std::string>(
m_end);
977 output.append(QString(
"%1").arg(
m_start));
979 output.append(QString(
"%1").arg(
m_start));
981 output.append(QString(
"%1").arg(
m_end));
1016 return std::accumulate(
m_list.cbegin(),
m_list.cend(), 0,
1017 [](
int lhs,
const auto &interval) { return lhs + interval.length(); });
1023 if (
m_list.size() <= numOfIntervals) {
1024 for (
int i = 0; i <
m_list.size(); i++) {
1028 output +=
m_list.at(i).toStdString();
1036 for (
int i = 0; i < numOfIntervals - 1; i++) {
1040 output +=
m_list[i].toStdString();
1043 output +=
", ..., ";
1044 output +=
m_list.back().toStdString();
1050 QString output(
toStdString(numOfIntervals).c_str());
1065 if (
m_list.size() == 0) {
1073 for (
int i =
static_cast<int>(
m_list.size()) - 1; i >= 0; i--) {
1082 else if (
m_list.at(i).canMerge(interval)) {
1084 for (
int j = i; j >= 0; j--) {
1086 if (
m_list.at(j).canMerge(interval)) {
1090 deleteList.append(j);
1099 m_list.insert(i + 1, interval);
1105 if (deleteList.size() > 0) {
1107 sort(std::begin(deleteList), std::end(deleteList));
1109 for (
int i =
static_cast<int>(deleteList.size()) - 1; i >= 0; i--) {
1110 m_list.removeAt(deleteList[i]);
1115 m_list.insert(0, interval);
1127 intervals = intervals.simplified();
1128 intervals = intervals.replace(
" ",
"");
1131 QStringList intervalList = intervals.split(
",");
1132 for (
int i = 0; i < intervalList.size(); i++) {
1133 Interval interval(intervalList[i]);
1143 for (; it != list.constEnd(); ++it) {
1153 std::set<int> intSet;
1155 for (
const auto &i :
m_list) {
1156 std::set<int> intervalSet = i.getIntSet();
1157 intSet.insert(intervalSet.begin(), intervalSet.end());
1165 std::find_if(
m_list.cbegin(),
m_list.cend(), [&other](
const auto &interval) { return interval.contains(other); });
1166 return it !=
m_list.cend();
1170 const auto it = std::find_if((other.m_list).cbegin(), (other.m_list).cend(),
1171 [
this](
const auto &interval) { return !IntervalList::contains(interval); });
1172 return it == (other.m_list).cend();
1179 }
catch (std::exception &) {
1188 }
catch (std::exception &) {
1202 const std::set<int> aInts = a.
getIntSet();
1203 const std::set<int> bInts = b.
getIntSet();
1205 for (
const auto &aInt : aInts) {
1206 const bool inIntervalListB = bInts.find(aInt) != bInts.end();
1207 if (inIntervalListB)
1218 : QValidator(parent), m_intervalList(
std::move(intervalList)) {}
1223 return QValidator::Acceptable;
1225 const QString pattern(
"(\\d|-|,)*");
1227 const QRegularExpression regExp(QRegularExpression::anchoredPattern(pattern));
1229 if (regExp.match(input).hasMatch())
1230 return QValidator::Intermediate;
1232 return QValidator::Invalid;
1239 auto *layout =
new QGridLayout();
1243 pal.setColor(QPalette::WindowText, Qt::darkRed);
1252 if (
error.isEmpty()) {
1253 m_validLbl->setVisible(
false);
1255 m_validLbl->setVisible(
true);
1256 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 ...
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.