Newer
Older
#include "InstrumentPresenter.h"
namespace MantidQt {
namespace CustomInterfaces {
InstrumentPresenter::InstrumentPresenter(IInstrumentView *view)
: m_view(view), m_model() {
m_view->subscribe(this);
notifySettingsChanged();
}
void InstrumentPresenter::notifySettingsChanged() { updateModelFromView(); }
Instrument const &InstrumentPresenter::instrument() const {
return m_model.get();
}
void InstrumentPresenter::onReductionPaused() { m_view->enableAll(); }
void InstrumentPresenter::onReductionResumed() { m_view->disableAll(); }
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
RangeInLambda InstrumentPresenter::wavelengthRangeFromView() {
auto const range =
RangeInLambda(m_view->getLambdaMin(), m_view->getLambdaMax());
if (range.isValid())
m_view->showLambdaRangeValid();
else
m_view->showLambdaRangeInvalid();
return range;
}
RangeInLambda InstrumentPresenter::monitorBackgroundRangeFromView() {
auto const range = RangeInLambda(m_view->getMonitorBackgroundMin(),
m_view->getMonitorBackgroundMax());
if (range.isValid())
m_view->showMonitorBackgroundRangeValid();
else
m_view->showMonitorBackgroundRangeInvalid();
return range;
}
RangeInLambda InstrumentPresenter::monitorIntegralRangeFromView() {
auto const range = RangeInLambda(m_view->getMonitorIntegralMin(),
m_view->getMonitorIntegralMax());
if (range.isValid())
m_view->showMonitorIntegralRangeValid();
else
m_view->showMonitorIntegralRangeInvalid();
return range;
}
MonitorCorrections InstrumentPresenter::monitorCorrectionsFromView() {
auto const monitorIndex = m_view->getMonitorIndex();
auto const integrate = m_view->getIntegrateMonitors();
auto const backgroundRange = monitorBackgroundRangeFromView();
auto const integralRange = monitorIntegralRangeFromView();
return MonitorCorrections(monitorIndex, integrate, backgroundRange,
integralRange);
}
DetectorCorrectionType InstrumentPresenter::detectorCorrectionTypeFromView() {
if (m_view->getDetectorCorrectionType() == "RotateAroundSample")
return DetectorCorrectionType::RotateAroundSample;
else
return DetectorCorrectionType::VerticalShift;
}
DetectorCorrections InstrumentPresenter::detectorCorrectionsFromView() {
auto const correctPositions = m_view->getCorrectDetectors();
auto const correctionType = detectorCorrectionTypeFromView();
return DetectorCorrections(correctPositions, correctionType);
}
void InstrumentPresenter::updateModelFromView() {
auto const wavelengthRange = wavelengthRangeFromView();
auto const monitorCorrections = monitorCorrectionsFromView();
auto const detectorCorrections = detectorCorrectionsFromView();
if (wavelengthRange.isValid() && monitorCorrections.isValid())
m_model =
Instrument(wavelengthRange, monitorCorrections, detectorCorrections);
else
m_model = boost::none;
} // namespace CustomInterfaces
} // namespace MantidQt