Newer
Older
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
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2019 ISIS Rutherford Appleton Laboratory UKRI,
// NScD Oak Ridge National Laboratory, European Spallation Source
// & Institut Laue - Langevin
// SPDX - License - Identifier: GPL - 3.0 +
#include "Decoder.h"
#include "Encoder.h"
#include "MantidQtWidgets/Common/SignalBlocker.h"
namespace MantidQt {
namespace CustomInterfaces {
BatchPresenter *Decoder::findBatchPresenter(const BatchView *gui,
const MainWindowView &mwv) {
for (auto ipresenter : mwv.m_presenter->m_batchPresenters) {
auto presenter = std::dynamic_pointer_cast<BatchPresenter>(ipresenter);
if (presenter->m_view == gui) {
return presenter.get();
}
}
return nullptr;
}
void Decoder::decode(const MainWindowView &gui,
const QMap<QString, QVariant> &map) {
UNUSED_ARG(gui);
UNUSED_ARG(map);
}
void Decoder::decodeBatch(const BatchView *gui, const MainWindowView &mwv,
QMap<QString, QVariant> &map,
const BatchPresenter *presenter) {
auto batchPresenter = presenter;
if (!batchPresenter) {
batchPresenter = findBatchPresenter(gui, mwv);
}
if (!batchPresenter) {
throw std::runtime_error(
"BatchPresenter could not be found during decode.");
}
auto runsPresenter =
dynamic_cast<RunsPresenter *>(batchPresenter->m_runsPresenter.get());
auto runsTablePresenter =
dynamic_cast<RunsTablePresenter *>(runsPresenter->m_tablePresenter.get());
auto reductionJobs = &runsTablePresenter->m_model.m_reductionJobs;
decodeRuns(gui->m_runs.get(), reductionJobs, runsTablePresenter,
map[QString("runsView")].toMap());
decodeEvent(gui->m_eventHandling.get(), map[QString("eventView")].toMap());
decodeExperiment(gui->m_experiment.get(),
map[QString("experimentView")].toMap());
decodeInstrument(gui->m_instrument.get(),
map[QString("instrumentView")].toMap());
decodeSave(gui->m_save.get(), map[QString("saveView")].toMap());
}
void Decoder::decodeBatch(const IBatchPresenter *presenter,
const IMainWindowView *mwv,
QMap<QString, QVariant> &map) {
auto batchPresenter = dynamic_cast<const BatchPresenter *>(presenter);
decodeBatch(dynamic_cast<BatchView *>(batchPresenter->m_view),
*dynamic_cast<const MainWindowView *>(mwv), map, batchPresenter);
}
void Decoder::decodeExperiment(const ExperimentView *gui,
const QMap<QString, QVariant> &map) {
gui->m_ui.analysisModeComboBox->setCurrentIndex(
map[QString("analysisModeComboBox")].toInt());
gui->m_ui.debugCheckBox->setChecked(map[QString("debugCheckbox")].toBool());
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
gui->m_ui.summationTypeComboBox->setCurrentIndex(
map[QString("summationTypeComboBox")].toInt());
gui->m_ui.reductionTypeComboBox->setCurrentIndex(
map[QString("reductionTypeComboBox")].toInt());
gui->m_ui.includePartialBinsCheckBox->setChecked(
map[QString("includePartialBinsCheckBox")].toBool());
decodePerAngleDefaults(gui->m_ui.optionsTable,
map[QString("perAngleDefaults")].toMap());
gui->m_ui.startOverlapEdit->setValue(
map[QString("startOverlapEdit")].toDouble());
gui->m_ui.endOverlapEdit->setValue(map[QString("endOverlapEdit")].toDouble());
gui->m_ui.transStitchParamsEdit->setText(
map[QString("transStitchParamsEdit")].toString());
gui->m_ui.transScaleRHSCheckBox->setChecked(
map[QString("transScaleRHSCheckBox")].toBool());
gui->m_ui.polCorrCheckBox->setChecked(
map[QString("polCorrCheckBox")].toBool());
gui->m_ui.floodCorComboBox->setCurrentIndex(
map[QString("floodCorComboBox")].toInt());
gui->m_ui.floodWorkspaceWsSelector->setCurrentIndex(
map[QString("floodWorkspaceWsSelector")].toInt());
gui->m_stitchEdit->setText(map[QString("stitchEdit")].toString());
}
void Decoder::decodePerAngleDefaults(QTableWidget *tab,
const QMap<QString, QVariant> &map) {
// Clear the rows
for (auto rowIndex = 0; rowIndex < tab->rowCount(); ++rowIndex) {
tab->removeRow(rowIndex);
}
const int rowsNum = map[QString("rowsNum")].toInt();
const int columnsNum = map[QString("columnsNum")].toInt();
decodePerAngleDefaultsRows(tab, rowsNum, columnsNum,
map[QString("rows")].toList());
}
void Decoder::decodePerAngleDefaultsRows(QTableWidget *tab, int rowsNum,
int columnsNum,
const QList<QVariant> &list) {
for (auto rowIndex = 0; rowIndex < rowsNum; ++rowIndex) {
tab->insertRow(rowIndex);
decodePerAngleDefaultsRow(tab, rowIndex, columnsNum,
list[rowIndex].toList());
}
}
void Decoder::decodePerAngleDefaultsRow(QTableWidget *tab, int rowIndex,
int columnsNum,
const QList<QVariant> &list) {
MantidQt::API::SignalBlocker blocker(tab);
for (auto columnIndex = 0; columnIndex < columnsNum; ++columnIndex) {
auto tableWidgetItem = new QTableWidgetItem(list[columnIndex].toString());
tab->setItem(rowIndex, columnIndex, tableWidgetItem);
}
}
void Decoder::decodeInstrument(const InstrumentView *gui,
const QMap<QString, QVariant> &map) {
gui->m_ui.intMonCheckBox->setChecked(map[QString("intMonCheckBox")].toBool());
gui->m_ui.monIntMinEdit->setValue(map[QString("monIntMinEdit")].toDouble());
gui->m_ui.monIntMaxEdit->setValue(map[QString("monIntMaxEdit")].toDouble());
gui->m_ui.monBgMinEdit->setValue(map[QString("monBgMinEdit")].toDouble());
gui->m_ui.monBgMaxEdit->setValue(map[QString("monBgMaxEdit")].toDouble());
gui->m_ui.lamMinEdit->setValue(map[QString("lamMinEdit")].toDouble());
gui->m_ui.lamMaxEdit->setValue(map[QString("lamMaxEdit")].toDouble());
gui->m_ui.I0MonitorIndex->setValue(
static_cast<int>(map[QString("I0MonitorIndex")].toDouble()));
gui->m_ui.correctDetectorsCheckBox->setChecked(
map[QString("correctDetectorsCheckBox")].toBool());
gui->m_ui.detectorCorrectionTypeComboBox->setCurrentIndex(
map[QString("detectorCorrectionTypeComboBox")].toInt());
}
void Decoder::decodeRuns(RunsView *gui, ReductionJobs *redJobs,
RunsTablePresenter *presenter,
const QMap<QString, QVariant> &map) {
decodeRunsTable(gui->m_tableView, redJobs, presenter,
map[QString("runsTable")].toMap());
gui->m_ui.comboSearchInstrument->setCurrentIndex(
map[QString("comboSearchInstrument")].toInt());
gui->m_ui.textSearch->setText(map[QString("textSearch")].toString());
}
namespace HIDDEN_LOCAL {
std::vector<MantidQt::MantidWidgets::Batch::Cell> cellsFromRow(Row const &row) {
return std::vector<MantidQt::MantidWidgets::Batch::Cell>(
{MantidQt::MantidWidgets::Batch::Cell(boost::join(row.runNumbers(), "+")),
MantidQt::MantidWidgets::Batch::Cell(std::to_string(row.theta())),
MantidQt::MantidWidgets::Batch::Cell(
row.transmissionWorkspaceNames().firstRunList()),
MantidQt::MantidWidgets::Batch::Cell(
row.transmissionWorkspaceNames().secondRunList()),
qRangeCellOrDefault(row.qRange(), row.qRangeOutput(), &RangeInQ::min),
qRangeCellOrDefault(row.qRange(), row.qRangeOutput(), &RangeInQ::max),
qRangeCellOrDefault(row.qRange(), row.qRangeOutput(), &RangeInQ::step),
MantidQt::MantidWidgets::Batch::Cell(
optionalToString(row.scaleFactor())),
MantidQt::MantidWidgets::Batch::Cell(
MantidWidgets::optionsToString(row.reductionOptions()))});
}
} // namespace HIDDEN_LOCAL
void Decoder::updateRunsTableViewFromModel(RunsTableView *view,
const ReductionJobs *model) {
auto jobTreeView = view->m_jobs.get();
auto groups = model->groups();
for (auto groupIndex = 0u; groupIndex < groups.size(); ++groupIndex) {
// Update view for groups
auto group = groups[groupIndex];
// MantidQt::MantidWidgets::Batch::RowLocation location(
// {static_cast<int>(groupIndex)});
// MantidQt::MantidWidgets::Batch::Cell groupCell(group.name());
// jobTreeView->setCellAt({location}, 0, groupCell);
// Update view for rows
auto rows = groups[groupIndex].rows();
for (auto rowIndex = 0u; rowIndex < rows.size(); ++rowIndex) {
auto row = rows[rowIndex];
// If row has content in the model.
if (row) {
MantidQt::MantidWidgets::Batch::RowLocation location(
{static_cast<int>(groupIndex), static_cast<int>(rowIndex)});
jobTreeView->setCellsAt({location},
HIDDEN_LOCAL::cellsFromRow(row.get()));
}
}
}
}
void Decoder::decodeRunsTable(RunsTableView *gui, ReductionJobs *redJobs,
RunsTablePresenter *presenter,
const QMap<QString, QVariant> &map) {
MantidQt::API::SignalBlocker signalBlockerView(gui);
gui->m_ui.filterBox->setText(map[QString("filterBox")].toString());
bool projectSave = map[QString("projectSave")].toBool();
auto runsTable = map[QString("runsTableModel")].toList();
// Clear
presenter->removeAllRowsAndGroupsFromView();
presenter->removeAllRowsAndGroupsFromModel();
// Construct the table.
for (auto groupIndex = 1; groupIndex < runsTable.size() + 1; ++groupIndex) {
presenter->appendEmptyGroupInModel();
presenter->appendEmptyGroupInView();
for (auto rowIndex = 0;
rowIndex <
runsTable[groupIndex - 1].toMap()[QString("rows")].toList().size();
++rowIndex) {
presenter->appendRowsToGroupsInView({groupIndex});
presenter->appendRowsToGroupsInModel({groupIndex});
}
}
// Remove initial group made on construction
presenter->removeGroupsFromView({0});
presenter->removeGroupsFromModel({0});
decodeRunsTableModel(redJobs, runsTable);
// Still need to do this for groups
updateRunsTableViewFromModel(gui, redJobs);
if (projectSave) {
// Apply styling and restore completed state for output range values best
// way to achieve this is yet to be decided.
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
}
}
void Decoder::decodeRunsTableModel(ReductionJobs *jobs,
const QList<QVariant> &list) {
for (auto groupIndex = 0; groupIndex < list.size(); ++groupIndex) {
auto group = decodeGroup(list[groupIndex].toMap());
jobs->mutableGroups()[groupIndex] = group;
}
}
MantidQt::CustomInterfaces::Group
Decoder::decodeGroup(const QMap<QString, QVariant> &map) {
auto rows = decodeRows(map["rows"].toList());
MantidQt::CustomInterfaces::Group group(
map[QString("name")].toString().toStdString(), rows);
group.m_postprocessedWorkspaceName =
map[QString("postprocessedWorkspaceName")].toString().toStdString();
return group;
}
std::vector<boost::optional<MantidQt::CustomInterfaces::Row>>
Decoder::decodeRows(const QList<QVariant> &list) {
std::vector<boost::optional<MantidQt::CustomInterfaces::Row>> rows;
for (const auto &rowMap : list) {
rows.emplace_back(decodeRow(rowMap.toMap()));
}
return rows;
}
namespace {
ReductionOptionsMap decodeReductionOptions(const QMap<QString, QVariant> &map) {
ReductionOptionsMap rom;
for (const auto &key : map.keys()) {
rom.insert(std::pair<std::string, std::string>(
key.toStdString(), map[key].toString().toStdString()));
}
return rom;
}
} // namespace
boost::optional<MantidQt::CustomInterfaces::Row>
Decoder::decodeRow(const QMap<QString, QVariant> &map) {
std::vector<std::string> number;
for (const auto &runNumber : map[QString("runNumbers")].toList()) {
number.emplace_back(runNumber.toString().toStdString());
}
boost::optional<double> scaleFactor = boost::none;
if (map[QString("scaleFactorPresent")].toBool()) {
scaleFactor = map[QString("scaleFactor")].toDouble();
}
MantidQt::CustomInterfaces::Row row(
number, map[QString("theta")].toDouble(),
decodeTransmissionRunPair(map[QString("transRunNums")].toMap()),
decodeRangeInQ(map[QString("qRange")].toMap()), scaleFactor,
decodeReductionOptions(map[QString("reductionOptions")].toMap()),
decodeReductionWorkspace(map[QString("reductionWorkspaces")].toMap()));
return row;
}
RangeInQ Decoder::decodeRangeInQ(const QMap<QString, QVariant> &map) {
boost::optional<double> min = boost::none;
boost::optional<double> step = boost::none;
boost::optional<double> max = boost::none;
if (map[QString("minPresent")].toBool()) {
min = map[QString("min")].toDouble();
}
if (map[QString("maxPresent")].toBool()) {
max = map[QString("max")].toDouble();
}
if (map[QString("stepPresent")].toBool()) {
step = map[QString("step")].toDouble();
}
return RangeInQ(min, step, max);
}
TransmissionRunPair
Decoder::decodeTransmissionRunPair(const QMap<QString, QVariant> &map) {
auto firstTransRunsQt = map[QString("firstTransRuns")].toList();
auto secondTransRunsQt = map[QString("secondTransRuns")].toList();
std::vector<std::string> firstTransRuns;
std::vector<std::string> secondTransRuns;
for (const auto &item : firstTransRunsQt) {
firstTransRuns.emplace_back(item.toString().toStdString());
}
for (const auto &item : secondTransRunsQt) {
secondTransRuns.emplace_back(item.toString().toStdString());
}
return TransmissionRunPair(firstTransRuns, secondTransRuns);
}
ReductionWorkspaces
Decoder::decodeReductionWorkspace(const QMap<QString, QVariant> &map) {
std::vector<std::string> inputRunNumbers;
for (const auto &elem : map[QString("inputRunNumbers")].toList()) {
inputRunNumbers.emplace_back(elem.toString().toStdString());
}
auto transmissionRunPair =
decodeTransmissionRunPair(map[QString("transPair")].toMap());
ReductionWorkspaces redWs(inputRunNumbers, transmissionRunPair);
redWs.setOutputNames(map[QString("iVsLambda")].toString().toStdString(),
map[QString("iVsQ")].toString().toStdString(),
map[QString("iVsQBinned")].toString().toStdString());
return redWs;
}
void Decoder::decodeSave(const SaveView *gui,
const QMap<QString, QVariant> &map) {
gui->m_ui.savePathEdit->setText(map[QString("savePathEdit")].toString());
gui->m_ui.prefixEdit->setText(map[QString("prefixEdit")].toString());
gui->m_ui.titleCheckBox->setChecked(map[QString("titleCheckBox")].toBool());
gui->m_ui.qResolutionCheckBox->setChecked(
map[QString("qResolutionCheckBox")].toBool());
gui->m_ui.commaRadioButton->setChecked(
map[QString("commaRadioButton")].toBool());
gui->m_ui.spaceRadioButton->setChecked(
map[QString("spaceRadioButton")].toBool());
gui->m_ui.tabRadioButton->setChecked(map[QString("tabRadioButton")].toBool());
gui->m_ui.fileFormatComboBox->setCurrentIndex(
map[QString("fileFormatComboBox")].toInt());
gui->m_ui.filterEdit->setText(map[QString("filterEdit")].toString());
gui->m_ui.regexCheckBox->setChecked(map[QString("regexCheckBox")].toBool());
gui->m_ui.saveReductionResultsCheckBox->setChecked(
map[QString("saveReductionResultsCheckBox")].toBool());
}
void Decoder::decodeEvent(const EventView *gui,
const QMap<QString, QVariant> &map) {
gui->m_ui.disabledSlicingButton->setChecked(
map[QString("disabledSlicingButton")].toBool());
gui->m_ui.uniformEvenButton->setChecked(
map[QString("uniformEvenButton")].toBool());
gui->m_ui.uniformEvenEdit->setValue(
static_cast<int>(map[QString("uniformEvenEdit")].toDouble()));
gui->m_ui.uniformButton->setChecked(map[QString("uniformButton")].toBool());
gui->m_ui.uniformEdit->setValue(map[QString("uniformEdit")].toDouble());
gui->m_ui.customButton->setChecked(map[QString("customButton")].toBool());
gui->m_ui.customEdit->setText(map[QString("customEdit")].toString());
gui->m_ui.logValueButton->setChecked(map[QString("logValueButton")].toBool());
gui->m_ui.logValueEdit->setText(map[QString("logValueEdit")].toString());
gui->m_ui.logValueTypeEdit->setText(
map[QString("logValueTypeEdit")].toString());
}
} // namespace CustomInterfaces
} // namespace MantidQt