##// END OF EJS Templates
Merge pull request 325 from SciQLop-fork develop...
trabillard -
r899:976564133b88 merge
parent child
Show More
@@ -1,211 +1,274
1 #include "CosinusProvider.h"
1 #include "CosinusProvider.h"
2 #include "MockDefs.h"
2 #include "MockDefs.h"
3
3
4 #include <Data/DataProviderParameters.h>
4 #include <Data/DataProviderParameters.h>
5 #include <Data/ScalarSeries.h>
5 #include <Data/ScalarSeries.h>
6 #include <Data/SpectrogramSeries.h>
6 #include <Data/VectorSeries.h>
7 #include <Data/VectorSeries.h>
7
8
8 #include <cmath>
9 #include <cmath>
9
10
10 #include <QFuture>
11 #include <QFuture>
11 #include <QThread>
12 #include <QThread>
12 #include <QtConcurrent/QtConcurrent>
13 #include <QtConcurrent/QtConcurrent>
13
14
14 Q_LOGGING_CATEGORY(LOG_CosinusProvider, "CosinusProvider")
15 Q_LOGGING_CATEGORY(LOG_CosinusProvider, "CosinusProvider")
15
16
16 namespace {
17 namespace {
17
18
19 /// Number of bands generated for a spectrogram
20 const auto SPECTROGRAM_NUMBER_BANDS = 30;
21
18 /// Abstract cosinus type
22 /// Abstract cosinus type
19 struct ICosinusType {
23 struct ICosinusType {
20 virtual ~ICosinusType() = default;
24 virtual ~ICosinusType() = default;
21 /// @return the number of components generated for the type
25 /// @return the number of components generated for the type
22 virtual int componentCount() const = 0;
26 virtual int componentCount() const = 0;
23 /// @return the data series created for the type
27 /// @return the data series created for the type
24 virtual std::shared_ptr<IDataSeries> createDataSeries(std::vector<double> xAxisData,
28 virtual std::shared_ptr<IDataSeries> createDataSeries(std::vector<double> xAxisData,
25 std::vector<double> valuesData,
29 std::vector<double> valuesData,
26 Unit xAxisUnit,
30 Unit xAxisUnit,
27 Unit valuesUnit) const = 0;
31 Unit valuesUnit) const = 0;
32 /// Generates values (one value per component)
33 /// @param x the x-axis data used to generate values
34 /// @param values the vector in which to insert the generated values
35 /// @param dataIndex the index of insertion of the generated values
36 ///
37 virtual void generateValues(double x, std::vector<double> &values, int dataIndex) const = 0;
28 };
38 };
29
39
30 struct ScalarCosinus : public ICosinusType {
40 struct ScalarCosinus : public ICosinusType {
31 int componentCount() const override { return 1; }
41 int componentCount() const override { return 1; }
32
42
33 std::shared_ptr<IDataSeries> createDataSeries(std::vector<double> xAxisData,
43 std::shared_ptr<IDataSeries> createDataSeries(std::vector<double> xAxisData,
34 std::vector<double> valuesData, Unit xAxisUnit,
44 std::vector<double> valuesData, Unit xAxisUnit,
35 Unit valuesUnit) const override
45 Unit valuesUnit) const override
36 {
46 {
37 return std::make_shared<ScalarSeries>(std::move(xAxisData), std::move(valuesData),
47 return std::make_shared<ScalarSeries>(std::move(xAxisData), std::move(valuesData),
38 xAxisUnit, valuesUnit);
48 xAxisUnit, valuesUnit);
39 }
49 }
50
51 void generateValues(double x, std::vector<double> &values, int dataIndex) const override
52 {
53 values[dataIndex] = std::cos(x);
54 }
40 };
55 };
56
57 struct SpectrogramCosinus : public ICosinusType {
58 /// Ctor with y-axis
59 explicit SpectrogramCosinus(std::vector<double> yAxisData, Unit yAxisUnit)
60 : m_YAxisData{std::move(yAxisData)}, m_YAxisUnit{std::move(yAxisUnit)}
61 {
62 }
63
64 int componentCount() const override { return m_YAxisData.size(); }
65
66 std::shared_ptr<IDataSeries> createDataSeries(std::vector<double> xAxisData,
67 std::vector<double> valuesData, Unit xAxisUnit,
68 Unit valuesUnit) const override
69 {
70 return std::make_shared<SpectrogramSeries>(std::move(xAxisData), m_YAxisData,
71 std::move(valuesData), xAxisUnit, m_YAxisUnit,
72 valuesUnit);
73 }
74
75 void generateValues(double x, std::vector<double> &values, int dataIndex) const override
76 {
77 auto componentCount = this->componentCount();
78 for (int i = 0; i < componentCount; ++i) {
79 auto y = m_YAxisData[i];
80 auto r = 3 * std::sqrt(x * x + y * y) + 1e-2;
81 auto value = 2 * x * (std::cos(r + 2) / r - std::sin(r + 2) / r);
82
83 values[componentCount * dataIndex + i] = value;
84 }
85 }
86
87 std::vector<double> m_YAxisData;
88 Unit m_YAxisUnit;
89 };
90
41 struct VectorCosinus : public ICosinusType {
91 struct VectorCosinus : public ICosinusType {
42 int componentCount() const override { return 3; }
92 int componentCount() const override { return 3; }
43
93
44 std::shared_ptr<IDataSeries> createDataSeries(std::vector<double> xAxisData,
94 std::shared_ptr<IDataSeries> createDataSeries(std::vector<double> xAxisData,
45 std::vector<double> valuesData, Unit xAxisUnit,
95 std::vector<double> valuesData, Unit xAxisUnit,
46 Unit valuesUnit) const override
96 Unit valuesUnit) const override
47 {
97 {
48 return std::make_shared<VectorSeries>(std::move(xAxisData), std::move(valuesData),
98 return std::make_shared<VectorSeries>(std::move(xAxisData), std::move(valuesData),
49 xAxisUnit, valuesUnit);
99 xAxisUnit, valuesUnit);
50 }
100 }
101
102 void generateValues(double x, std::vector<double> &values, int dataIndex) const override
103 {
104 // Generates value for each component: cos(x), cos(x)/2, cos(x)/3
105 auto xValue = std::cos(x);
106 auto componentCount = this->componentCount();
107 for (auto i = 0; i < componentCount; ++i) {
108 values[componentCount * dataIndex + i] = xValue / (i + 1);
109 }
110 }
51 };
111 };
52
112
53 /// Converts string to cosinus type
113 /// Converts string to cosinus type
54 /// @return the cosinus type if the string could be converted, nullptr otherwise
114 /// @return the cosinus type if the string could be converted, nullptr otherwise
55 std::unique_ptr<ICosinusType> cosinusType(const QString &type) noexcept
115 std::unique_ptr<ICosinusType> cosinusType(const QString &type) noexcept
56 {
116 {
57 if (type.compare(QStringLiteral("scalar"), Qt::CaseInsensitive) == 0) {
117 if (type.compare(QStringLiteral("scalar"), Qt::CaseInsensitive) == 0) {
58 return std::make_unique<ScalarCosinus>();
118 return std::make_unique<ScalarCosinus>();
59 }
119 }
120 else if (type.compare(QStringLiteral("spectrogram"), Qt::CaseInsensitive) == 0) {
121 // Generates default y-axis data for spectrogram [0., 1., 2., ...]
122 std::vector<double> yAxisData(SPECTROGRAM_NUMBER_BANDS);
123 std::iota(yAxisData.begin(), yAxisData.end(), 0.);
124
125 return std::make_unique<SpectrogramCosinus>(std::move(yAxisData), Unit{"eV"});
126 }
60 else if (type.compare(QStringLiteral("vector"), Qt::CaseInsensitive) == 0) {
127 else if (type.compare(QStringLiteral("vector"), Qt::CaseInsensitive) == 0) {
61 return std::make_unique<VectorCosinus>();
128 return std::make_unique<VectorCosinus>();
62 }
129 }
63 else {
130 else {
64 return nullptr;
131 return nullptr;
65 }
132 }
66 }
133 }
67
134
68 } // namespace
135 } // namespace
69
136
70 std::shared_ptr<IDataProvider> CosinusProvider::clone() const
137 std::shared_ptr<IDataProvider> CosinusProvider::clone() const
71 {
138 {
72 // No copy is made in clone
139 // No copy is made in clone
73 return std::make_shared<CosinusProvider>();
140 return std::make_shared<CosinusProvider>();
74 }
141 }
75
142
76 std::shared_ptr<IDataSeries> CosinusProvider::retrieveData(QUuid acqIdentifier,
143 std::shared_ptr<IDataSeries> CosinusProvider::retrieveData(QUuid acqIdentifier,
77 const SqpRange &dataRangeRequested,
144 const SqpRange &dataRangeRequested,
78 const QVariantHash &data)
145 const QVariantHash &data)
79 {
146 {
80 // TODO: Add Mutex
147 // TODO: Add Mutex
81 auto dataIndex = 0;
148 auto dataIndex = 0;
82
149
83 // Retrieves cosinus type
150 // Retrieves cosinus type
84 auto typeVariant = data.value(COSINUS_TYPE_KEY, COSINUS_TYPE_DEFAULT_VALUE);
151 auto typeVariant = data.value(COSINUS_TYPE_KEY, COSINUS_TYPE_DEFAULT_VALUE);
85 if (!typeVariant.canConvert<QString>()) {
152 if (!typeVariant.canConvert<QString>()) {
86 qCCritical(LOG_CosinusProvider()) << tr("Can't retrieve data: invalid type");
153 qCCritical(LOG_CosinusProvider()) << tr("Can't retrieve data: invalid type");
87 return nullptr;
154 return nullptr;
88 }
155 }
89
156
90 auto type = cosinusType(typeVariant.toString());
157 auto type = cosinusType(typeVariant.toString());
91 if (!type) {
158 if (!type) {
92 qCCritical(LOG_CosinusProvider()) << tr("Can't retrieve data: unknown type");
159 qCCritical(LOG_CosinusProvider()) << tr("Can't retrieve data: unknown type");
93 return nullptr;
160 return nullptr;
94 }
161 }
95
162
96 // Retrieves frequency
163 // Retrieves frequency
97 auto freqVariant = data.value(COSINUS_FREQUENCY_KEY, COSINUS_FREQUENCY_DEFAULT_VALUE);
164 auto freqVariant = data.value(COSINUS_FREQUENCY_KEY, COSINUS_FREQUENCY_DEFAULT_VALUE);
98 if (!freqVariant.canConvert<double>()) {
165 if (!freqVariant.canConvert<double>()) {
99 qCCritical(LOG_CosinusProvider()) << tr("Can't retrieve data: invalid frequency");
166 qCCritical(LOG_CosinusProvider()) << tr("Can't retrieve data: invalid frequency");
100 return nullptr;
167 return nullptr;
101 }
168 }
102
169
103 // Gets the timerange from the parameters
170 // Gets the timerange from the parameters
104 double freq = freqVariant.toDouble();
171 double freq = freqVariant.toDouble();
105 double start = std::ceil(dataRangeRequested.m_TStart * freq);
172 double start = std::ceil(dataRangeRequested.m_TStart * freq);
106 double end = std::floor(dataRangeRequested.m_TEnd * freq);
173 double end = std::floor(dataRangeRequested.m_TEnd * freq);
107
174
108 // We assure that timerange is valid
175 // We assure that timerange is valid
109 if (end < start) {
176 if (end < start) {
110 std::swap(start, end);
177 std::swap(start, end);
111 }
178 }
112
179
113 // Generates scalar series containing cosinus values (one value per second, end value is
180 // Generates scalar series containing cosinus values (one value per second, end value is
114 // included)
181 // included)
115 auto dataCount = end - start + 1;
182 auto dataCount = end - start + 1;
116
183
117 // Number of components (depending on the cosinus type)
184 // Number of components (depending on the cosinus type)
118 auto componentCount = type->componentCount();
185 auto componentCount = type->componentCount();
119
186
120 auto xAxisData = std::vector<double>{};
187 auto xAxisData = std::vector<double>{};
121 xAxisData.resize(dataCount);
188 xAxisData.resize(dataCount);
122
189
123 auto valuesData = std::vector<double>{};
190 auto valuesData = std::vector<double>{};
124 valuesData.resize(dataCount * componentCount);
191 valuesData.resize(dataCount * componentCount);
125
192
126 int progress = 0;
193 int progress = 0;
127 auto progressEnd = dataCount;
194 auto progressEnd = dataCount;
128 for (auto time = start; time <= end; ++time, ++dataIndex) {
195 for (auto time = start; time <= end; ++time, ++dataIndex) {
129 auto it = m_VariableToEnableProvider.find(acqIdentifier);
196 auto it = m_VariableToEnableProvider.find(acqIdentifier);
130 if (it != m_VariableToEnableProvider.end() && it.value()) {
197 if (it != m_VariableToEnableProvider.end() && it.value()) {
131 const auto timeOnFreq = time / freq;
198 const auto x = time / freq;
132
199
133 xAxisData[dataIndex] = timeOnFreq;
200 xAxisData[dataIndex] = x;
134
201
135 // Generates all components' values
202 // Generates values (depending on the type)
136 // Example: for a vector, values will be : cos(x), cos(x)/2, cos(x)/3
203 type->generateValues(x, valuesData, dataIndex);
137 auto value = std::cos(timeOnFreq);
138 for (auto i = 0; i < componentCount; ++i) {
139 valuesData[componentCount * dataIndex + i] = value / (i + 1);
140 }
141
204
142 // progression
205 // progression
143 int currentProgress = (time - start) * 100.0 / progressEnd;
206 int currentProgress = (time - start) * 100.0 / progressEnd;
144 if (currentProgress != progress) {
207 if (currentProgress != progress) {
145 progress = currentProgress;
208 progress = currentProgress;
146
209
147 emit dataProvidedProgress(acqIdentifier, progress);
210 emit dataProvidedProgress(acqIdentifier, progress);
148 qCDebug(LOG_CosinusProvider()) << "TORM: CosinusProvider::retrieveData"
211 qCDebug(LOG_CosinusProvider()) << "TORM: CosinusProvider::retrieveData"
149 << QThread::currentThread()->objectName()
212 << QThread::currentThread()->objectName()
150 << progress;
213 << progress;
151 // NOTE: Try to use multithread if possible
214 // NOTE: Try to use multithread if possible
152 }
215 }
153 }
216 }
154 else {
217 else {
155 if (!it.value()) {
218 if (!it.value()) {
156 qCDebug(LOG_CosinusProvider())
219 qCDebug(LOG_CosinusProvider())
157 << "CosinusProvider::retrieveData: ARRET De l'acquisition detectΓ©"
220 << "CosinusProvider::retrieveData: ARRET De l'acquisition detectΓ©"
158 << end - time;
221 << end - time;
159 }
222 }
160 }
223 }
161 }
224 }
162 if (progress != 100) {
225 if (progress != 100) {
163 // We can close progression beacause all data has been retrieved
226 // We can close progression beacause all data has been retrieved
164 emit dataProvidedProgress(acqIdentifier, 100);
227 emit dataProvidedProgress(acqIdentifier, 100);
165 }
228 }
166 return type->createDataSeries(std::move(xAxisData), std::move(valuesData),
229 return type->createDataSeries(std::move(xAxisData), std::move(valuesData),
167 Unit{QStringLiteral("t"), true}, Unit{});
230 Unit{QStringLiteral("t"), true}, Unit{});
168 }
231 }
169
232
170 void CosinusProvider::requestDataLoading(QUuid acqIdentifier,
233 void CosinusProvider::requestDataLoading(QUuid acqIdentifier,
171 const DataProviderParameters &parameters)
234 const DataProviderParameters &parameters)
172 {
235 {
173 // TODO: Add Mutex
236 // TODO: Add Mutex
174 m_VariableToEnableProvider[acqIdentifier] = true;
237 m_VariableToEnableProvider[acqIdentifier] = true;
175 qCDebug(LOG_CosinusProvider()) << "TORM: CosinusProvider::requestDataLoading"
238 qCDebug(LOG_CosinusProvider()) << "TORM: CosinusProvider::requestDataLoading"
176 << QThread::currentThread()->objectName();
239 << QThread::currentThread()->objectName();
177 // NOTE: Try to use multithread if possible
240 // NOTE: Try to use multithread if possible
178 const auto times = parameters.m_Times;
241 const auto times = parameters.m_Times;
179
242
180 for (const auto &dateTime : qAsConst(times)) {
243 for (const auto &dateTime : qAsConst(times)) {
181 if (m_VariableToEnableProvider[acqIdentifier]) {
244 if (m_VariableToEnableProvider[acqIdentifier]) {
182 auto scalarSeries = this->retrieveData(acqIdentifier, dateTime, parameters.m_Data);
245 auto scalarSeries = this->retrieveData(acqIdentifier, dateTime, parameters.m_Data);
183 emit dataProvided(acqIdentifier, scalarSeries, dateTime);
246 emit dataProvided(acqIdentifier, scalarSeries, dateTime);
184 }
247 }
185 }
248 }
186 }
249 }
187
250
188 void CosinusProvider::requestDataAborting(QUuid acqIdentifier)
251 void CosinusProvider::requestDataAborting(QUuid acqIdentifier)
189 {
252 {
190 qCDebug(LOG_CosinusProvider()) << "CosinusProvider::requestDataAborting" << acqIdentifier
253 qCDebug(LOG_CosinusProvider()) << "CosinusProvider::requestDataAborting" << acqIdentifier
191 << QThread::currentThread()->objectName();
254 << QThread::currentThread()->objectName();
192 auto it = m_VariableToEnableProvider.find(acqIdentifier);
255 auto it = m_VariableToEnableProvider.find(acqIdentifier);
193 if (it != m_VariableToEnableProvider.end()) {
256 if (it != m_VariableToEnableProvider.end()) {
194 it.value() = false;
257 it.value() = false;
195 }
258 }
196 else {
259 else {
197 qCDebug(LOG_CosinusProvider())
260 qCDebug(LOG_CosinusProvider())
198 << tr("Aborting progression of inexistant identifier detected !!!");
261 << tr("Aborting progression of inexistant identifier detected !!!");
199 }
262 }
200 }
263 }
201
264
202 std::shared_ptr<IDataSeries> CosinusProvider::provideDataSeries(const SqpRange &dataRangeRequested,
265 std::shared_ptr<IDataSeries> CosinusProvider::provideDataSeries(const SqpRange &dataRangeRequested,
203 const QVariantHash &data)
266 const QVariantHash &data)
204 {
267 {
205 auto uid = QUuid::createUuid();
268 auto uid = QUuid::createUuid();
206 m_VariableToEnableProvider[uid] = true;
269 m_VariableToEnableProvider[uid] = true;
207 auto dataSeries = this->retrieveData(uid, dataRangeRequested, data);
270 auto dataSeries = this->retrieveData(uid, dataRangeRequested, data);
208
271
209 m_VariableToEnableProvider.remove(uid);
272 m_VariableToEnableProvider.remove(uid);
210 return dataSeries;
273 return dataSeries;
211 }
274 }
@@ -1,109 +1,114
1 #include "MockPlugin.h"
1 #include "MockPlugin.h"
2 #include "CosinusProvider.h"
2 #include "CosinusProvider.h"
3 #include "MockDefs.h"
3 #include "MockDefs.h"
4
4
5 #include <DataSource/DataSourceController.h>
5 #include <DataSource/DataSourceController.h>
6 #include <DataSource/DataSourceItem.h>
6 #include <DataSource/DataSourceItem.h>
7 #include <DataSource/DataSourceItemAction.h>
7 #include <DataSource/DataSourceItemAction.h>
8
8
9 #include <SqpApplication.h>
9 #include <SqpApplication.h>
10
10
11 Q_LOGGING_CATEGORY(LOG_MockPlugin, "MockPlugin")
11 Q_LOGGING_CATEGORY(LOG_MockPlugin, "MockPlugin")
12
12
13 namespace {
13 namespace {
14
14
15 /// Name of the data source
15 /// Name of the data source
16 const auto DATA_SOURCE_NAME = QStringLiteral("MMS");
16 const auto DATA_SOURCE_NAME = QStringLiteral("MMS");
17
17
18 /// Creates the data provider relative to the plugin
18 /// Creates the data provider relative to the plugin
19 std::unique_ptr<IDataProvider> createDataProvider() noexcept
19 std::unique_ptr<IDataProvider> createDataProvider() noexcept
20 {
20 {
21 return std::make_unique<CosinusProvider>();
21 return std::make_unique<CosinusProvider>();
22 }
22 }
23
23
24 std::unique_ptr<DataSourceItem> createProductItem(const QVariantHash &data,
24 std::unique_ptr<DataSourceItem> createProductItem(const QVariantHash &data,
25 const QUuid &dataSourceUid)
25 const QUuid &dataSourceUid)
26 {
26 {
27 auto result = std::make_unique<DataSourceItem>(DataSourceItemType::PRODUCT, data);
27 auto result = std::make_unique<DataSourceItem>(DataSourceItemType::PRODUCT, data);
28 auto productName = data.value(DataSourceItem::NAME_DATA_KEY).toString();
28 auto productName = data.value(DataSourceItem::NAME_DATA_KEY).toString();
29
29
30 // Add action to load product from DataSourceController
30 // Add action to load product from DataSourceController
31 result->addAction(std::make_unique<DataSourceItemAction>(
31 result->addAction(std::make_unique<DataSourceItemAction>(
32 QObject::tr("Load %1 product").arg(productName),
32 QObject::tr("Load %1 product").arg(productName),
33 [productName, dataSourceUid](DataSourceItem &item) {
33 [productName, dataSourceUid](DataSourceItem &item) {
34 if (auto app = sqpApp) {
34 if (auto app = sqpApp) {
35 app->dataSourceController().loadProductItem(dataSourceUid, item);
35 app->dataSourceController().loadProductItem(dataSourceUid, item);
36 }
36 }
37 }));
37 }));
38
38
39 return result;
39 return result;
40 }
40 }
41
41
42 /// Creates the data source item relative to the plugin
42 /// Creates the data source item relative to the plugin
43 std::unique_ptr<DataSourceItem> createDataSourceItem(const QUuid &dataSourceUid) noexcept
43 std::unique_ptr<DataSourceItem> createDataSourceItem(const QUuid &dataSourceUid) noexcept
44 {
44 {
45 // Magnetic field products
45 // Magnetic field products
46 auto magneticFieldFolder = std::make_unique<DataSourceItem>(DataSourceItemType::NODE,
46 auto magneticFieldFolder = std::make_unique<DataSourceItem>(DataSourceItemType::NODE,
47 QStringLiteral("Magnetic field"));
47 QStringLiteral("Magnetic field"));
48 magneticFieldFolder->appendChild(
48 magneticFieldFolder->appendChild(
49 createProductItem({{DataSourceItem::NAME_DATA_KEY, QStringLiteral("Scalar 10 Hz")},
49 createProductItem({{DataSourceItem::NAME_DATA_KEY, QStringLiteral("Scalar 10 Hz")},
50 {COSINUS_TYPE_KEY, "scalar"},
50 {COSINUS_TYPE_KEY, "scalar"},
51 {COSINUS_FREQUENCY_KEY, 10.}},
51 {COSINUS_FREQUENCY_KEY, 10.}},
52 dataSourceUid));
52 dataSourceUid));
53 magneticFieldFolder->appendChild(
53 magneticFieldFolder->appendChild(
54 createProductItem({{DataSourceItem::NAME_DATA_KEY, QStringLiteral("Scalar 60 Hz")},
54 createProductItem({{DataSourceItem::NAME_DATA_KEY, QStringLiteral("Scalar 60 Hz")},
55 {COSINUS_TYPE_KEY, "scalar"},
55 {COSINUS_TYPE_KEY, "scalar"},
56 {COSINUS_FREQUENCY_KEY, 60.}},
56 {COSINUS_FREQUENCY_KEY, 60.}},
57 dataSourceUid));
57 dataSourceUid));
58 magneticFieldFolder->appendChild(
58 magneticFieldFolder->appendChild(
59 createProductItem({{DataSourceItem::NAME_DATA_KEY, QStringLiteral("Scalar 100 Hz")},
59 createProductItem({{DataSourceItem::NAME_DATA_KEY, QStringLiteral("Scalar 100 Hz")},
60 {COSINUS_TYPE_KEY, "scalar"},
60 {COSINUS_TYPE_KEY, "scalar"},
61 {COSINUS_FREQUENCY_KEY, 100.}},
61 {COSINUS_FREQUENCY_KEY, 100.}},
62 dataSourceUid));
62 dataSourceUid));
63 magneticFieldFolder->appendChild(
63 magneticFieldFolder->appendChild(
64 createProductItem({{DataSourceItem::NAME_DATA_KEY, QStringLiteral("Vector 10 Hz")},
64 createProductItem({{DataSourceItem::NAME_DATA_KEY, QStringLiteral("Vector 10 Hz")},
65 {COSINUS_TYPE_KEY, "vector"},
65 {COSINUS_TYPE_KEY, "vector"},
66 {COSINUS_FREQUENCY_KEY, 10.}},
66 {COSINUS_FREQUENCY_KEY, 10.}},
67 dataSourceUid));
67 dataSourceUid));
68 magneticFieldFolder->appendChild(
68 magneticFieldFolder->appendChild(
69 createProductItem({{DataSourceItem::NAME_DATA_KEY, QStringLiteral("Vector 60 Hz")},
69 createProductItem({{DataSourceItem::NAME_DATA_KEY, QStringLiteral("Vector 60 Hz")},
70 {COSINUS_TYPE_KEY, "vector"},
70 {COSINUS_TYPE_KEY, "vector"},
71 {COSINUS_FREQUENCY_KEY, 60.}},
71 {COSINUS_FREQUENCY_KEY, 60.}},
72 dataSourceUid));
72 dataSourceUid));
73 magneticFieldFolder->appendChild(
73 magneticFieldFolder->appendChild(
74 createProductItem({{DataSourceItem::NAME_DATA_KEY, QStringLiteral("Vector 100 Hz")},
74 createProductItem({{DataSourceItem::NAME_DATA_KEY, QStringLiteral("Vector 100 Hz")},
75 {COSINUS_TYPE_KEY, "vector"},
75 {COSINUS_TYPE_KEY, "vector"},
76 {COSINUS_FREQUENCY_KEY, 100.}},
76 {COSINUS_FREQUENCY_KEY, 100.}},
77 dataSourceUid));
77 dataSourceUid));
78 magneticFieldFolder->appendChild(
79 createProductItem({{DataSourceItem::NAME_DATA_KEY, QStringLiteral("Spectrogram 1 Hz")},
80 {COSINUS_TYPE_KEY, "spectrogram"},
81 {COSINUS_FREQUENCY_KEY, 1.}},
82 dataSourceUid));
78
83
79 // Electric field products
84 // Electric field products
80 auto electricFieldFolder = std::make_unique<DataSourceItem>(DataSourceItemType::NODE,
85 auto electricFieldFolder = std::make_unique<DataSourceItem>(DataSourceItemType::NODE,
81 QStringLiteral("Electric field"));
86 QStringLiteral("Electric field"));
82
87
83 // Root
88 // Root
84 auto root = std::make_unique<DataSourceItem>(DataSourceItemType::NODE, DATA_SOURCE_NAME);
89 auto root = std::make_unique<DataSourceItem>(DataSourceItemType::NODE, DATA_SOURCE_NAME);
85 root->appendChild(std::move(magneticFieldFolder));
90 root->appendChild(std::move(magneticFieldFolder));
86 root->appendChild(std::move(electricFieldFolder));
91 root->appendChild(std::move(electricFieldFolder));
87
92
88 return root;
93 return root;
89 }
94 }
90
95
91 } // namespace
96 } // namespace
92
97
93 void MockPlugin::initialize()
98 void MockPlugin::initialize()
94 {
99 {
95 if (auto app = sqpApp) {
100 if (auto app = sqpApp) {
96 // Registers to the data source controller
101 // Registers to the data source controller
97 auto &dataSourceController = app->dataSourceController();
102 auto &dataSourceController = app->dataSourceController();
98 auto dataSourceUid = dataSourceController.registerDataSource(DATA_SOURCE_NAME);
103 auto dataSourceUid = dataSourceController.registerDataSource(DATA_SOURCE_NAME);
99
104
100 // Sets data source tree
105 // Sets data source tree
101 dataSourceController.setDataSourceItem(dataSourceUid, createDataSourceItem(dataSourceUid));
106 dataSourceController.setDataSourceItem(dataSourceUid, createDataSourceItem(dataSourceUid));
102
107
103 // Sets data provider
108 // Sets data provider
104 dataSourceController.setDataProvider(dataSourceUid, createDataProvider());
109 dataSourceController.setDataProvider(dataSourceUid, createDataProvider());
105 }
110 }
106 else {
111 else {
107 qCWarning(LOG_MockPlugin()) << tr("Can't access to SciQlop application");
112 qCWarning(LOG_MockPlugin()) << tr("Can't access to SciQlop application");
108 }
113 }
109 }
114 }
General Comments 0
You need to be logged in to leave comments. Login now