Mantid
Loading...
Searching...
No Matches
PlotAsymmetryByLogValueDialog.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
9
10#include "MantidAPI/Algorithm.h"
13#include "MantidAPI/Run.h"
16
17#include <QCheckBox>
18#include <QComboBox>
19#include <QDir>
20#include <QFileInfo>
21#include <QGridLayout>
22#include <QGroupBox>
23#include <QHBoxLayout>
24#include <QLabel>
25#include <QLineEdit>
26#include <QPushButton>
27#include <QSignalMapper>
28#include <QVBoxLayout>
29
30// Add this class to the list of specialised dialogs in this namespace
33} // namespace MantidQt::CustomDialogs
34
35using namespace MantidQt::CustomDialogs;
36using namespace MantidQt::API;
37
42 browseButtonMapper = new QSignalMapper();
43
44 connect(browseButtonMapper, SIGNAL(mapped(const QString &)), this, SLOT(openFileDialog(const QString &)));
45}
46
51
56 m_uiForm.setupUi(this);
57
58 // Tie all the properties
59 tie(m_uiForm.runs, "WorkspaceNames", m_uiForm.runsLayout);
60 tie(m_uiForm.logBox, "LogValue");
61 tie(m_uiForm.typeBoxLog, "Function");
62 tie(m_uiForm.outWSBox, "OutputWorkspace", m_uiForm.OutputWSLayout);
63 tie(m_uiForm.typeBox, "Type");
64 tie(m_uiForm.redBox, "Red");
65 tie(m_uiForm.greenBox, "Green");
66 tie(m_uiForm.forwardBox, "ForwardSpectra");
67 tie(m_uiForm.backwardBox, "BackwardSpectra");
68 tie(m_uiForm.alpha, "Alpha");
69 tie(m_uiForm.timeMinBox, "TimeMin");
70 tie(m_uiForm.timeMaxBox, "TimeMax");
71 tie(m_uiForm.dtcType, "DeadTimeCorrType");
72 tie(m_uiForm.dtcFile, "DeadTimeCorrFile");
73
74 // Set-up browse button mapping
75 browseButtonMapper->setMapping(m_uiForm.dtcFileBrowseButton, "DeadTimeCorrFile");
76
77 // Connect Browse buttons to the mapper
78 connect(m_uiForm.dtcFileBrowseButton, SIGNAL(clicked()), browseButtonMapper, SLOT(map()));
79
80 connect(m_uiForm.runs, SIGNAL(fileFindingFinished()), this, SLOT(fillLogBox()));
81
82 connect(m_uiForm.dtcType, SIGNAL(currentIndexChanged(int)), this, SLOT(showHideDeadTimeFileWidget(int)));
83
84 // Fill ComboBoxes with allowed values
85 fillAndSetComboBox("Type", m_uiForm.typeBox);
86 fillAndSetComboBox("Function", m_uiForm.typeBoxLog);
87 fillAndSetComboBox("DeadTimeCorrType", m_uiForm.dtcType);
88
89 // Fill log values from the file
90 if (!m_uiForm.runs->getText().isEmpty())
91 fillLogBox();
92
93 // So user can enter a custom value
94 m_uiForm.logBox->setEditable(true);
95
96 // Create and add the OK/Cancel/Help. buttons
97 m_uiForm.verticalLayout->addLayout(this->createDefaultButtonLayout());
98}
99
104void PlotAsymmetryByLogValueDialog::openFileDialog(const QString &filePropName) {
105 QString selectedPath = AlgorithmDialog::openFileDialog(filePropName);
106
107 if (!selectedPath.isEmpty()) {
108 // Save used directory for the next time
109 AlgorithmInputHistory::Instance().setPreviousDirectory(QFileInfo(selectedPath).absoluteDir().path());
110
111 // Get the widget for the file property
112 QLineEdit *lineEdit = dynamic_cast<QLineEdit *>(m_tied_properties[filePropName]);
113
114 if (!lineEdit)
115 throw std::runtime_error("Widget of the file property was not found");
116
117 lineEdit->setText(selectedPath.trimmed());
118 }
119}
120
126 QString nexusFileName = m_uiForm.runs->getFirstFilename();
127 QFileInfo file(nexusFileName);
128 if (!file.exists()) {
129 return;
130 }
131
132 m_uiForm.logBox->clear();
133
135 alg->initialize();
136 try {
137 alg->setPropertyValue("Filename", nexusFileName.toStdString());
138 alg->setPropertyValue("OutputWorkspace", "PlotAsymmetryByLogValueDialog_tmp");
139 alg->setPropertyValue("SpectrumList",
140 "1"); // Need to load at least one spectrum
141 alg->execute();
142 if (alg->isExecuted()) {
143 std::string wsName = alg->getPropertyValue("OutputWorkspace");
145 if (!ws) {
146 return;
147 }
148 Mantid::API::MatrixWorkspace_sptr mws = std::dynamic_pointer_cast<Mantid::API::MatrixWorkspace>(ws);
149 Mantid::API::WorkspaceGroup_sptr gws = std::dynamic_pointer_cast<Mantid::API::WorkspaceGroup>(ws);
150 if (gws) {
151 if (gws->getNumberOfEntries() < 2)
152 return;
153 mws = std::dynamic_pointer_cast<Mantid::API::MatrixWorkspace>(
154 Mantid::API::AnalysisDataService::Instance().retrieve(gws->getNames()[1]));
155 }
156 const std::vector<Mantid::Kernel::Property *> &props = mws->run().getLogData();
157 if (gws) {
158 m_uiForm.alpha->setEnabled(false);
159 for (auto const &name : gws->getNames()) {
161 }
162 } else {
163 m_uiForm.alpha->setEnabled(true);
164 Mantid::API::AnalysisDataService::Instance().remove("PlotAsymmetryByLogValueDialog_tmp");
165 }
166 for (auto prop : props) {
167 m_uiForm.logBox->addItem(QString::fromStdString(prop->name()));
168 }
169 // Display the appropriate value
170 QString displayed("");
171 if (!isForScript()) {
172 displayed =
173 MantidQt::API::AlgorithmInputHistory::Instance().previousInput("PlotAsymmetryByLogValue", "LogValue");
174 }
175 if (!displayed.isEmpty()) {
176 int index = m_uiForm.logBox->findText(displayed);
177 if (index >= 0) {
178 m_uiForm.logBox->setCurrentIndex(index);
179 }
180 }
181 }
182
183 } catch (std::exception &) {
184 }
185}
186
193 // Show only if "Using specified file" selected
194 m_uiForm.dtcFileContainer->setVisible(deadTimeTypeIndex == 2);
195}
#define DECLARE_DIALOG(classname)
std::map< DeltaEMode::Type, std::string > index
Definition: DeltaEMode.cpp:19
This class should be the basis for all customised algorithm dialogs.
QHash< QString, QWidget * > m_tied_properties
A list pointers to the widget for each property.
bool isForScript() const
Get the usage boolean value.
void fillAndSetComboBox(const QString &propName, QComboBox *optionsBox) const
Fill a combo box for the named algorithm's allowed values.
QString openFileDialog(const QString &propName)
Open a file dialog to select a file.
QLayout * createDefaultButtonLayout(const QString &helpText=QString("?"), const QString &loadText=QString("Run"), const QString &cancelText=QString("Close"), const QString &keepOpenText=QString("Keep Open"))
Create a row layout of buttons with specified text.
QWidget * tie(QWidget *widget, const QString &property, QLayout *parent_layout=nullptr, bool readHistory=true)
Tie a widget to a property.
This class gives specialised dialog for the LoadRaw algorithm.
QSignalMapper * browseButtonMapper
Maps Browse buttons to file properties.
void openFileDialog(const QString &filePropName)
Opens a file dialog.
void showHideDeadTimeFileWidget(int deadTimeTypeIndex)
Show or hide Dead Time file widget depending on which Dead Time type is selected.
void fillLogBox()
Fill m_uiForm.logBox with names of the log values read from one of the input files.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
std::shared_ptr< IAlgorithm > IAlgorithm_sptr
shared pointer to Mantid::API::IAlgorithm
std::shared_ptr< WorkspaceGroup > WorkspaceGroup_sptr
shared pointer to Mantid::API::WorkspaceGroup
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
Definition: Workspace_fwd.h:20
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class