-
Notifications
You must be signed in to change notification settings - Fork 122
/
ResNorm.cpp
172 lines (144 loc) · 5.08 KB
/
ResNorm.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
#include "MantidQtCustomInterfaces/ResNorm.h"
namespace MantidQt
{
namespace CustomInterfaces
{
ResNorm::ResNorm(QWidget * parent) :
IndirectBayesTab(parent)
{
m_uiForm.setupUi(parent);
//add the plot to the ui form
m_uiForm.plotSpace->addWidget(m_plot);
//add the properties browser to the ui form
m_uiForm.treeSpace->addWidget(m_propTree);
m_properties["EMin"] = m_dblManager->addProperty("EMin");
m_properties["EMax"] = m_dblManager->addProperty("EMax");
m_properties["VanBinning"] = m_dblManager->addProperty("Van Binning");
m_dblManager->setDecimals(m_properties["EMin"], NUM_DECIMALS);
m_dblManager->setDecimals(m_properties["EMax"], NUM_DECIMALS);
m_dblManager->setDecimals(m_properties["VanBinning"], INT_DECIMALS);
m_propTree->addProperty(m_properties["EMin"]);
m_propTree->addProperty(m_properties["EMax"]);
m_propTree->addProperty(m_properties["VanBinning"]);
//set default values
m_dblManager->setValue(m_properties["VanBinning"], 1);
m_dblManager->setMinimum(m_properties["VanBinning"], 1);
// Connect data selector to handler method
connect(m_uiForm.dsVanadium, SIGNAL(dataReady(const QString&)), this, SLOT(handleVanadiumInputReady(const QString&)));
}
/**
* Validate the form to check the program can be run
*
* @return :: Whether the form was valid
*/
bool ResNorm::validate()
{
//check that the sample file exists
QString sampleName = m_uiForm.dsVanadium->getCurrentDataName();
QString samplePath = m_uiForm.dsVanadium->getFullFilePath();
if(!checkFileLoaded(sampleName, samplePath)) return false;
//check that the resolution file exists
QString resName = m_uiForm.dsResolution->getCurrentDataName();
QString resPath = m_uiForm.dsResolution->getFullFilePath();
if(!checkFileLoaded(resName, resPath)) return false;
return true;
}
/**
* Collect the settings on the GUI and build a python
* script that runs ResNorm
*/
void ResNorm::run()
{
QString verbose("False");
QString save("False");
QString pyInput =
"from IndirectBayes import ResNormRun\n";
// get the file names
QString VanName = m_uiForm.dsVanadium->getCurrentDataName();
QString ResName = m_uiForm.dsResolution->getCurrentDataName();
// get the parameters for ResNorm
QString EMin = m_properties["EMin"]->valueText();
QString EMax = m_properties["EMax"]->valueText();
QString ERange = "[" + EMin + "," + EMax + "]";
QString nBin = m_properties["VanBinning"]->valueText();
// get output options
if(m_uiForm.chkVerbose->isChecked()){ verbose = "True"; }
if(m_uiForm.chkSave->isChecked()){ save ="True"; }
QString plot = m_uiForm.cbPlot->currentText();
pyInput += "ResNormRun('"+VanName+"', '"+ResName+"', "+ERange+", "+nBin+","
" Save="+save+", Plot='"+plot+"', Verbose="+verbose+")\n";
runPythonScript(pyInput);
}
/**
* Set the data selectors to use the default save directory
* when browsing for input files.
*
* @param filename :: The name of the workspace to plot
*/
void ResNorm::loadSettings(const QSettings& settings)
{
m_uiForm.dsVanadium->readSettings(settings.group());
m_uiForm.dsResolution->readSettings(settings.group());
}
/**
* Plots the loaded file to the miniplot and sets the guides
* and the range
*
* @param filename :: The name of the workspace to plot
*/
void ResNorm::handleVanadiumInputReady(const QString& filename)
{
plotMiniPlot(filename, 0);
std::pair<double,double> res;
std::pair<double,double> range = getCurveRange();
//Use the values from the instrument parameter file if we can
if(getInstrumentResolution(filename, res))
{
//ResNorm resolution should be +/- 10 * the IPF resolution
res.first = res.first * 10;
res.second = res.second * 10;
setMiniPlotGuides(m_properties["EMin"], m_properties["EMax"], res);
}
else
{
setMiniPlotGuides(m_properties["EMin"], m_properties["EMax"], range);
}
setPlotRange(m_properties["EMin"], m_properties["EMax"], range);
}
/**
* Updates the property manager when the lower guide is moved on the mini plot
*
* @param min :: The new value of the lower guide
*/
void ResNorm::minValueChanged(double min)
{
m_dblManager->setValue(m_properties["EMin"], min);
}
/**
* Updates the property manager when the upper guide is moved on the mini plot
*
* @param max :: The new value of the upper guide
*/
void ResNorm::maxValueChanged(double max)
{
m_dblManager->setValue(m_properties["EMax"], max);
}
/**
* Handles when properties in the property manager are updated.
*
* @param prop :: The property being updated
* @param val :: The new value for the property
*/
void ResNorm::updateProperties(QtProperty* prop, double val)
{
if(prop == m_properties["EMin"])
{
updateLowerGuide(m_properties["EMin"], m_properties["EMax"], val);
}
else if (prop == m_properties["EMax"])
{
updateUpperGuide(m_properties["EMin"], m_properties["EMax"], val);
}
}
} // namespace CustomInterfaces
} // namespace MantidQt