-
Notifications
You must be signed in to change notification settings - Fork 122
/
IndirectSymmetrise.cpp
183 lines (142 loc) · 6.52 KB
/
IndirectSymmetrise.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#include "MantidQtCustomInterfaces/IndirectSymmetrise.h"
#include "MantidAPI/MatrixWorkspace.h"
#include "MantidKernel/Logger.h"
#include "MantidQtCustomInterfaces/UserInputValidator.h"
#include <QFileInfo>
namespace
{
Mantid::Kernel::Logger g_log("IndirectSymmetrise");
}
namespace MantidQt
{
namespace CustomInterfaces
{
//----------------------------------------------------------------------------------------------
/** Constructor
*/
IndirectSymmetrise::IndirectSymmetrise(Ui::IndirectDataReduction& uiForm, QWidget * parent) :
IndirectDataReductionTab(uiForm, parent)
{
// Property Tree
m_propTrees["SymmPropTree"] = new QtTreePropertyBrowser();
m_uiForm.symm_properties->addWidget(m_propTrees["SymmPropTree"]);
// Editor Factories
DoubleEditorFactory *doubleEditorFactory = new DoubleEditorFactory();
m_propTrees["SymmPropTree"]->setFactoryForManager(m_dblManager, doubleEditorFactory);
// Create Properties
m_properties["XCut"] = m_dblManager->addProperty("X Cut");
m_propTrees["SymmPropTree"]->addProperty(m_properties["XCut"]);
QtProperty* rawPlotProps = m_grpManager->addProperty("Raw Plot");
m_propTrees["SymmPropTree"]->addProperty(rawPlotProps);
m_properties["PreviewSpec"] = m_dblManager->addProperty("Spectrum No");
m_dblManager->setDecimals(m_properties["PreviewSpec"], 0);
rawPlotProps->addSubProperty(m_properties["PreviewSpec"]);
m_properties["PreviewRange"] = m_dblManager->addProperty("X Range");
rawPlotProps->addSubProperty(m_properties["PreviewRange"]);
// Raw plot
m_plots["SymmRawPlot"] = new QwtPlot(m_parentWidget);
m_curves["SymmRawPlot"] = new QwtPlotCurve();
m_rangeSelectors["NegativeXCut"] = new MantidWidgets::RangeSelector(m_plots["SymmRawPlot"], MantidWidgets::RangeSelector::XSINGLE, true, false);
m_rangeSelectors["PositiveXCut"] = new MantidWidgets::RangeSelector(m_plots["SymmRawPlot"], MantidWidgets::RangeSelector::XSINGLE, true, false);
m_rangeSelectors["CentreMark"] = new MantidWidgets::RangeSelector(m_plots["SymmRawPlot"],
MantidWidgets::RangeSelector::XSINGLE, true, true);
m_rangeSelectors["CentreMark"]->setColour(Qt::cyan);
m_rangeSelectors["CentreMark"]->setMinimum(0.0);
m_plots["SymmRawPlot"]->setAxisFont(QwtPlot::xBottom, parent->font());
m_plots["SymmRawPlot"]->setAxisFont(QwtPlot::yLeft, parent->font());
m_plots["SymmRawPlot"]->setCanvasBackground(Qt::white);
m_uiForm.symm_plot->addWidget(m_plots["SymmRawPlot"]);
// Refresh the plot windows
m_plots["SymmRawPlot"]->replot();
// SIGNAL/SLOT CONNECTIONS
// Update range selctors when a property is changed
connect(m_dblManager, SIGNAL(valueChanged(QtProperty*, double)), this, SLOT(updateRangeSelectors(QtProperty*, double)));
// Plot a new spectrum when the user changes the value of the preview spectrum
connect(m_dblManager, SIGNAL(valueChanged(QtProperty*, double)), this, SLOT(replotNewSpectrum(QtProperty*, double)));
// Plot miniplot when file has finished loading
connect(m_uiForm.symm_dsInput, SIGNAL(dataReady(const QString&)), this, SLOT(plotRawInput(const QString&)));
// Set default XCut value
m_dblManager->setValue(m_properties["XCut"], 0.3);
// Set default x axis range
std::pair<double, double> defaultRange(-1.0, 1.0);
setAxisRange("SymmRawPlot", QwtPlot::xBottom, defaultRange);
}
//----------------------------------------------------------------------------------------------
/** Destructor
*/
IndirectSymmetrise::~IndirectSymmetrise()
{
}
void IndirectSymmetrise::setup()
{
}
bool IndirectSymmetrise::validate()
{
// Check for a valid input file
if(!m_uiForm.symm_dsInput->isValid())
return false;
// Check for a valid XCut value
if(m_dblManager->value(m_properties["XCut"]) <= 0.0)
return false;
return true;
}
void IndirectSymmetrise::run()
{
using namespace Mantid::API;
QString workspaceName = m_uiForm.symm_dsInput->getCurrentDataName();
QString outputWorkspaceName = workspaceName.left(workspaceName.length() - 4) + "_Symmetrise";
bool plot = m_uiForm.symm_ckPlot->isChecked();
bool verbose = m_uiForm.symm_ckVerbose->isChecked();
bool save = m_uiForm.symm_ckSave->isChecked();
double x_cut = m_dblManager->value(m_properties["XCut"]);
IAlgorithm_sptr symmetriseAlg = AlgorithmManager::Instance().create("Symmetrise", -1);
symmetriseAlg->initialize();
symmetriseAlg->setProperty("Sample", workspaceName.toStdString());
symmetriseAlg->setProperty("XCut", x_cut);
symmetriseAlg->setProperty("Plot", plot);
symmetriseAlg->setProperty("Verbose", verbose);
symmetriseAlg->setProperty("Save", save);
symmetriseAlg->setProperty("OutputWorkspace", outputWorkspaceName.toStdString());
// Execute algorithm on seperate thread
runAlgorithm(symmetriseAlg);
}
void IndirectSymmetrise::plotRawInput(const QString &workspaceName)
{
UNUSED_ARG(workspaceName);
updateRawPlot();
auto axisRange = getCurveRange("SymmRawPlot");
double symmRange = std::max(fabs(axisRange.first), fabs(axisRange.second));
g_log.information() << "Symmetrise x axis range +/- " << symmRange << std::endl;
m_dblManager->setValue(m_properties["PreviewRange"], symmRange);
updateRawPlot();
}
void IndirectSymmetrise::updateRawPlot()
{
if(!m_uiForm.symm_dsInput->isValid())
return;
QString workspaceName = m_uiForm.symm_dsInput->getCurrentDataName();
int spectrumNumber = static_cast<int>(m_dblManager->value(m_properties["PreviewSpec"]));
Mantid::API::MatrixWorkspace_sptr input = boost::dynamic_pointer_cast<Mantid::API::MatrixWorkspace>(
Mantid::API::AnalysisDataService::Instance().retrieve(workspaceName.toStdString()));
std::pair<double, double>range;
range.first = -m_dblManager->value(m_properties["PreviewRange"]);
range.second = m_dblManager->value(m_properties["PreviewRange"]);
setAxisRange("SymmRawPlot", QwtPlot::xBottom, range);
plotMiniPlot(input, spectrumNumber, "SymmRawPlot");
}
void IndirectSymmetrise::replotNewSpectrum(QtProperty *prop, double value)
{
UNUSED_ARG(value);
if((prop == m_properties["PreviewSpec"]) || (prop == m_properties["PreviewRange"]))
updateRawPlot();
}
void IndirectSymmetrise::updateRangeSelectors(QtProperty *prop, double value)
{
if(prop == m_properties["XCut"])
{
m_rangeSelectors["NegativeXCut"]->setMinimum(-value);
m_rangeSelectors["PositiveXCut"]->setMinimum(value);
}
}
} // namespace CustomInterfaces
} // namespace Mantid