-
Notifications
You must be signed in to change notification settings - Fork 122
/
DataManipulationInterface.cpp
180 lines (148 loc) · 5.72 KB
/
DataManipulationInterface.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
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
// NScD Oak Ridge National Laboratory, European Spallation Source,
// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
// SPDX - License - Identifier: GPL - 3.0 +
//----------------------
// Includes
//----------------------
#include "DataManipulationInterface.h"
#include "Common/Settings.h"
#include "ElwinPresenter.h"
#include "IqtPresenter.h"
#include "MantidAPI/AlgorithmManager.h"
#include "MantidAPI/AnalysisDataService.h"
#include "MantidAPI/ExperimentInfo.h"
#include "MantidGeometry/IComponent.h"
#include "MantidGeometry/Instrument.h"
#include "MantidKernel/ConfigService.h"
#include "MantidKernel/FacilityInfo.h"
#include "MomentsPresenter.h"
#include "SqwPresenter.h"
#include "SymmetrisePresenter.h"
#include <QDir>
#include <QMessageBox>
using namespace Mantid::API;
using namespace Mantid::Geometry;
using namespace MantidQt;
namespace {
Mantid::Kernel::Logger g_log("DataManipulationInterface");
}
namespace MantidQt::CustomInterfaces {
DECLARE_SUBWINDOW(DataManipulationInterface)
DataManipulationInterface::DataManipulationInterface(QWidget *parent) : IndirectInterface(parent) {}
DataManipulationInterface::~DataManipulationInterface() {}
std::string DataManipulationInterface::documentationPage() const { return "Inelastic Data Manipulation"; }
/**
* Called when the user clicks the Python export button.
*/
void DataManipulationInterface::exportTabPython() {
QString tabName = m_uiForm.twIDRTabs->tabText(m_uiForm.twIDRTabs->currentIndex());
m_tabs[tabName].second->exportPythonScript();
}
/**
* Sets up Qt UI file and connects signals, slots.
*/
void DataManipulationInterface::initLayout() {
m_uiForm.setupUi(this);
m_uiForm.pbSettings->setIcon(Settings::icon());
// Create the tabs
addMVPTab<SymmetrisePresenter, SymmetriseView>("Symmetrise");
addMVPTab<SqwPresenter, SqwView>("S(Q, w)");
addMVPTab<MomentsPresenter, MomentsView>("Moments");
addMVPTab<ElwinPresenter, ElwinView>("Elwin");
addMVPTab<IqtPresenter, IqtView>("Iqt");
connect(m_uiForm.pbSettings, SIGNAL(clicked()), this, SLOT(settings()));
// Connect "?" (Help) Button
connect(m_uiForm.pbHelp, SIGNAL(clicked()), this, SLOT(help()));
// Connect the Python export button
connect(m_uiForm.pbPythonExport, SIGNAL(clicked()), this, SLOT(exportTabPython()));
// Connect the "Manage User Directories" Button
connect(m_uiForm.pbManageDirectories, SIGNAL(clicked()), this, SLOT(manageUserDirectories()));
auto const &facility = Mantid::Kernel::ConfigService::Instance().getFacility();
filterUiForFacility(QString::fromStdString(facility.name()));
IndirectInterface::initLayout();
}
void DataManipulationInterface::applySettings(std::map<std::string, QVariant> const &settings) {
for (auto tab = m_tabs.begin(); tab != m_tabs.end(); ++tab) {
tab->second->filterInputData(settings.at("RestrictInput").toBool());
}
}
/**
* This function is ran after initLayout(), and runPythonCode is unavailable
* before this function
* has run (because of the setup of the base class). For this reason, "setup"
* functions that require
* Python scripts are located here.
*/
void DataManipulationInterface::initLocalPython() {}
/**
* Gets a parameter from an instrument component as a string.
*
* @param comp Instrument component
* @param param Parameter name
* @return Value as QString
*/
QString DataManipulationInterface::getInstrumentParameterFrom(const Mantid::Geometry::IComponent_const_sptr &comp,
const std::string ¶m) {
QString value;
if (!comp->hasParameter(param)) {
g_log.debug() << "Component " << comp->getName() << " has no parameter " << param << '\n';
return "";
}
// Determine it's type and call the corresponding get function
std::string paramType = comp->getParameterType(param);
if (paramType == "string")
value = QString::fromStdString(comp->getStringParameter(param)[0]);
if (paramType == "double")
value = QString::number(comp->getNumberParameter(param)[0]);
return value;
}
/**
* Tasks to be carried out after an empty instument has finished loading
*/
void DataManipulationInterface::instrumentLoadingDone(bool error) {
if (error) {
g_log.warning("Instument loading failed! This instrument (or "
"analyser/reflection configuration) may not be supported by "
"this interface.");
return;
}
}
/**
* Remove the Poco observer on the config service when the interfaces is closed.
*
* @param close Close event (unused)
*/
void DataManipulationInterface::closeEvent(QCloseEvent *close) { UNUSED_ARG(close); }
/**
* Filters the displayed tabs based on the current facility.
*
* @param facility Name of facility
*/
void DataManipulationInterface::filterUiForFacility(const QString &facility) {
g_log.information() << "Facility selected: " << facility.toStdString() << '\n';
QStringList enabledTabs;
QStringList disabledInstruments;
// These tabs work at any facility (always at end of tabs)
enabledTabs << "Symmetrise"
<< "S(Q, w)"
<< "Moments"
<< "Elwin"
<< "Iqt";
// First remove all tabs
while (m_uiForm.twIDRTabs->count() > 0) {
QString tabName = m_uiForm.twIDRTabs->tabText(0);
// Remove the tab
m_uiForm.twIDRTabs->removeTab(0);
g_log.debug() << "Removing tab " << tabName.toStdString() << '\n';
}
// Add the required tabs
for (auto &enabledTab : enabledTabs) {
// Add the tab
m_uiForm.twIDRTabs->addTab(m_tabs[enabledTab].first, enabledTab);
g_log.debug() << "Adding tab " << enabledTab.toStdString() << '\n';
}
}
} // namespace MantidQt::CustomInterfaces