@@ -0,0 +1,56 | |||||
|
1 | #ifndef SCIQLOP_ARRAYDATA_H | |||
|
2 | #define SCIQLOP_ARRAYDATA_H | |||
|
3 | ||||
|
4 | #include <QVector> | |||
|
5 | ||||
|
6 | /** | |||
|
7 | * @brief The ArrayData class represents a dataset for a data series. | |||
|
8 | * | |||
|
9 | * A dataset can be unidimensional or two-dimensional. This property is determined by the Dim | |||
|
10 | * template-parameter. | |||
|
11 | * | |||
|
12 | * @tparam Dim the dimension of the ArrayData (one or two) | |||
|
13 | * @sa IDataSeries | |||
|
14 | */ | |||
|
15 | template <int Dim> | |||
|
16 | class ArrayData { | |||
|
17 | public: | |||
|
18 | /** | |||
|
19 | * Ctor for a unidimensional ArrayData | |||
|
20 | * @param nbColumns the number of values the ArrayData will hold | |||
|
21 | */ | |||
|
22 | template <int D = Dim, typename = std::enable_if_t<D == 1> > | |||
|
23 | explicit ArrayData(int nbColumns) : m_Data{1, QVector<double>{}} | |||
|
24 | { | |||
|
25 | m_Data[0].resize(nbColumns); | |||
|
26 | } | |||
|
27 | ||||
|
28 | /** | |||
|
29 | * Sets a data at a specified index. The index has to be valid to be effective | |||
|
30 | * @param index the index to which the data will be set | |||
|
31 | * @param data the data to set | |||
|
32 | * @remarks this method is only available for a unidimensional ArrayData | |||
|
33 | */ | |||
|
34 | template <int D = Dim, typename = std::enable_if_t<D == 1> > | |||
|
35 | void setData(int index, double data) noexcept | |||
|
36 | { | |||
|
37 | if (index >= 0 && index < m_Data.at(0).size()) { | |||
|
38 | m_Data[0].replace(index, data); | |||
|
39 | } | |||
|
40 | } | |||
|
41 | ||||
|
42 | /** | |||
|
43 | * @return the data as a vector | |||
|
44 | * @remarks this method is only available for a unidimensional ArrayData | |||
|
45 | */ | |||
|
46 | template <int D = Dim, typename = std::enable_if_t<D == 1> > | |||
|
47 | QVector<double> data() const noexcept | |||
|
48 | { | |||
|
49 | return m_Data.at(0); | |||
|
50 | } | |||
|
51 | ||||
|
52 | private: | |||
|
53 | QVector<QVector<double> > m_Data; | |||
|
54 | }; | |||
|
55 | ||||
|
56 | #endif // SCIQLOP_ARRAYDATA_H |
@@ -0,0 +1,16 | |||||
|
1 | #ifndef SCIQLOP_DATAPROVIDERPARAMETERS_H | |||
|
2 | #define SCIQLOP_DATAPROVIDERPARAMETERS_H | |||
|
3 | ||||
|
4 | /** | |||
|
5 | * @brief The DataProviderParameters struct holds the information needed to retrieve data from a | |||
|
6 | * data provider | |||
|
7 | * @sa IDataProvider | |||
|
8 | */ | |||
|
9 | struct DataProviderParameters { | |||
|
10 | /// Start time | |||
|
11 | double m_TStart; | |||
|
12 | /// End time | |||
|
13 | double m_TEnd; | |||
|
14 | }; | |||
|
15 | ||||
|
16 | #endif // SCIQLOP_DATAPROVIDERPARAMETERS_H |
@@ -0,0 +1,50 | |||||
|
1 | #ifndef SCIQLOP_DATASERIES_H | |||
|
2 | #define SCIQLOP_DATASERIES_H | |||
|
3 | ||||
|
4 | #include <Data/ArrayData.h> | |||
|
5 | #include <Data/IDataSeries.h> | |||
|
6 | ||||
|
7 | #include <memory> | |||
|
8 | ||||
|
9 | /** | |||
|
10 | * @brief The DataSeries class is the base (abstract) implementation of IDataSeries. | |||
|
11 | * | |||
|
12 | * It proposes to set a dimension for the values ββdata | |||
|
13 | * | |||
|
14 | * @tparam Dim The dimension of the values data | |||
|
15 | * | |||
|
16 | */ | |||
|
17 | template <int Dim> | |||
|
18 | class DataSeries : public IDataSeries { | |||
|
19 | public: | |||
|
20 | /// @sa IDataSeries::xAxisData() | |||
|
21 | std::shared_ptr<ArrayData<1> > xAxisData() override { return m_XAxisData; } | |||
|
22 | ||||
|
23 | /// @sa IDataSeries::xAxisUnit() | |||
|
24 | QString xAxisUnit() const override { return m_XAxisUnit; } | |||
|
25 | ||||
|
26 | /// @return the values dataset | |||
|
27 | std::shared_ptr<ArrayData<Dim> > valuesData() const { return m_ValuesData; } | |||
|
28 | ||||
|
29 | /// @sa IDataSeries::valuesUnit() | |||
|
30 | QString valuesUnit() const override { return m_ValuesUnit; } | |||
|
31 | ||||
|
32 | protected: | |||
|
33 | /// Protected ctor (DataSeries is abstract) | |||
|
34 | explicit DataSeries(std::shared_ptr<ArrayData<1> > xAxisData, const QString &xAxisUnit, | |||
|
35 | std::shared_ptr<ArrayData<Dim> > valuesData, const QString &valuesUnit) | |||
|
36 | : m_XAxisData{xAxisData}, | |||
|
37 | m_XAxisUnit{xAxisUnit}, | |||
|
38 | m_ValuesData{valuesData}, | |||
|
39 | m_ValuesUnit{valuesUnit} | |||
|
40 | { | |||
|
41 | } | |||
|
42 | ||||
|
43 | private: | |||
|
44 | std::shared_ptr<ArrayData<1> > m_XAxisData; | |||
|
45 | QString m_XAxisUnit; | |||
|
46 | std::shared_ptr<ArrayData<Dim> > m_ValuesData; | |||
|
47 | QString m_ValuesUnit; | |||
|
48 | }; | |||
|
49 | ||||
|
50 | #endif // SCIQLOP_DATASERIES_H |
@@ -0,0 +1,25 | |||||
|
1 | #ifndef SCIQLOP_IDATAPROVIDER_H | |||
|
2 | #define SCIQLOP_IDATAPROVIDER_H | |||
|
3 | ||||
|
4 | #include <memory> | |||
|
5 | ||||
|
6 | class DataProviderParameters; | |||
|
7 | class IDataSeries; | |||
|
8 | ||||
|
9 | /** | |||
|
10 | * @brief The IDataProvider interface aims to declare a data provider. | |||
|
11 | * | |||
|
12 | * A data provider is an entity that generates data and returns it according to various parameters | |||
|
13 | * (time interval, product to retrieve the data, etc.) | |||
|
14 | * | |||
|
15 | * @sa IDataSeries | |||
|
16 | */ | |||
|
17 | class IDataProvider { | |||
|
18 | public: | |||
|
19 | virtual ~IDataProvider() noexcept = default; | |||
|
20 | ||||
|
21 | virtual std::unique_ptr<IDataSeries> | |||
|
22 | retrieveData(const DataProviderParameters ¶meters) const = 0; | |||
|
23 | }; | |||
|
24 | ||||
|
25 | #endif // SCIQLOP_IDATAPROVIDER_H |
@@ -0,0 +1,37 | |||||
|
1 | #ifndef SCIQLOP_IDATASERIES_H | |||
|
2 | #define SCIQLOP_IDATASERIES_H | |||
|
3 | ||||
|
4 | #include <QString> | |||
|
5 | ||||
|
6 | #include <memory> | |||
|
7 | ||||
|
8 | template <int Dim> | |||
|
9 | class ArrayData; | |||
|
10 | ||||
|
11 | /** | |||
|
12 | * @brief The IDataSeries aims to declare a data series. | |||
|
13 | * | |||
|
14 | * A data series is an entity that contains at least : | |||
|
15 | * - one dataset representing the x-axis | |||
|
16 | * - one dataset representing the values | |||
|
17 | * | |||
|
18 | * Each dataset is represented by an ArrayData, and is associated with a unit. | |||
|
19 | * | |||
|
20 | * An ArrayData can be unidimensional or two-dimensional, depending on the implementation of the | |||
|
21 | * IDataSeries. The x-axis dataset is always unidimensional. | |||
|
22 | * | |||
|
23 | * @sa ArrayData | |||
|
24 | */ | |||
|
25 | class IDataSeries { | |||
|
26 | public: | |||
|
27 | virtual ~IDataSeries() noexcept = default; | |||
|
28 | ||||
|
29 | /// Returns the x-axis dataset | |||
|
30 | virtual std::shared_ptr<ArrayData<1> > xAxisData() = 0; | |||
|
31 | ||||
|
32 | virtual QString xAxisUnit() const = 0; | |||
|
33 | ||||
|
34 | virtual QString valuesUnit() const = 0; | |||
|
35 | }; | |||
|
36 | ||||
|
37 | #endif // SCIQLOP_IDATASERIES_H |
@@ -0,0 +1,28 | |||||
|
1 | #ifndef SCIQLOP_SCALARSERIES_H | |||
|
2 | #define SCIQLOP_SCALARSERIES_H | |||
|
3 | ||||
|
4 | #include <Data/DataSeries.h> | |||
|
5 | ||||
|
6 | /** | |||
|
7 | * @brief The ScalarSeries class is the implementation for a data series representing a scalar. | |||
|
8 | */ | |||
|
9 | class ScalarSeries : public DataSeries<1> { | |||
|
10 | public: | |||
|
11 | /** | |||
|
12 | * Ctor | |||
|
13 | * @param size the number of data the series will hold | |||
|
14 | * @param xAxisUnit x-axis unit | |||
|
15 | * @param valuesUnit values unit | |||
|
16 | */ | |||
|
17 | explicit ScalarSeries(int size, const QString &xAxisUnit, const QString &valuesUnit); | |||
|
18 | ||||
|
19 | /** | |||
|
20 | * Sets data for a specific index. The index has to be valid to be effective | |||
|
21 | * @param index the index to which the data will be set | |||
|
22 | * @param x the x-axis data | |||
|
23 | * @param value the value data | |||
|
24 | */ | |||
|
25 | void setData(int index, double x, double value) noexcept; | |||
|
26 | }; | |||
|
27 | ||||
|
28 | #endif // SCIQLOP_SCALARSERIES_H |
@@ -0,0 +1,13 | |||||
|
1 | #include <Data/ScalarSeries.h> | |||
|
2 | ||||
|
3 | ScalarSeries::ScalarSeries(int size, const QString &xAxisUnit, const QString &valuesUnit) | |||
|
4 | : DataSeries{std::make_shared<ArrayData<1> >(size), xAxisUnit, | |||
|
5 | std::make_shared<ArrayData<1> >(size), valuesUnit} | |||
|
6 | { | |||
|
7 | } | |||
|
8 | ||||
|
9 | void ScalarSeries::setData(int index, double x, double value) noexcept | |||
|
10 | { | |||
|
11 | xAxisData()->setData(index, x); | |||
|
12 | valuesData()->setData(index, value); | |||
|
13 | } |
@@ -0,0 +1,16 | |||||
|
1 | #ifndef SCIQLOP_COSINUSPROVIDER_H | |||
|
2 | #define SCIQLOP_COSINUSPROVIDER_H | |||
|
3 | ||||
|
4 | #include <Data/IDataProvider.h> | |||
|
5 | ||||
|
6 | /** | |||
|
7 | * @brief The CosinusProvider class is an example of how a data provider can generate data | |||
|
8 | */ | |||
|
9 | class CosinusProvider : public IDataProvider { | |||
|
10 | public: | |||
|
11 | /// @sa IDataProvider::retrieveData() | |||
|
12 | std::unique_ptr<IDataSeries> | |||
|
13 | retrieveData(const DataProviderParameters ¶meters) const override; | |||
|
14 | }; | |||
|
15 | ||||
|
16 | #endif // SCIQLOP_COSINUSPROVIDER_H |
@@ -0,0 +1,28 | |||||
|
1 | #include "CosinusProvider.h" | |||
|
2 | ||||
|
3 | #include <Data/DataProviderParameters.h> | |||
|
4 | #include <Data/ScalarSeries.h> | |||
|
5 | ||||
|
6 | std::unique_ptr<IDataSeries> | |||
|
7 | CosinusProvider::retrieveData(const DataProviderParameters ¶meters) const | |||
|
8 | { | |||
|
9 | // Gets the timerange from the parameters | |||
|
10 | auto start = parameters.m_TStart; | |||
|
11 | auto end = parameters.m_TEnd; | |||
|
12 | ||||
|
13 | // We assure that timerange is valid | |||
|
14 | if (end < start) { | |||
|
15 | std::swap(start, end); | |||
|
16 | } | |||
|
17 | ||||
|
18 | // Generates scalar series containing cosinus values (one value per second) | |||
|
19 | auto scalarSeries | |||
|
20 | = std::make_unique<ScalarSeries>(end - start, QStringLiteral("t"), QStringLiteral("")); | |||
|
21 | ||||
|
22 | for (auto time = start; time < end; ++time) { | |||
|
23 | auto dataIndex = time - start; | |||
|
24 | scalarSeries->setData(dataIndex, time, std::cos(time)); | |||
|
25 | } | |||
|
26 | ||||
|
27 | return scalarSeries; | |||
|
28 | } |
@@ -10,6 +10,7 | |||||
10 | Q_DECLARE_LOGGING_CATEGORY(LOG_DataSourceController) |
|
10 | Q_DECLARE_LOGGING_CATEGORY(LOG_DataSourceController) | |
11 |
|
11 | |||
12 | class DataSourceItem; |
|
12 | class DataSourceItem; | |
|
13 | class IDataProvider; | |||
13 |
|
14 | |||
14 | /** |
|
15 | /** | |
15 | * @brief The DataSourceController class aims to make the link between SciQlop and its plugins. This |
|
16 | * @brief The DataSourceController class aims to make the link between SciQlop and its plugins. This | |
@@ -42,6 +43,17 public: | |||||
42 | void setDataSourceItem(const QUuid &dataSourceUid, |
|
43 | void setDataSourceItem(const QUuid &dataSourceUid, | |
43 | std::unique_ptr<DataSourceItem> dataSourceItem) noexcept; |
|
44 | std::unique_ptr<DataSourceItem> dataSourceItem) noexcept; | |
44 |
|
45 | |||
|
46 | /** | |||
|
47 | * Sets the data provider used to retrieve data from of a data source. The controller takes | |||
|
48 | * ownership of the provider. | |||
|
49 | * @param dataSourceUid the unique id with which the data source has been registered into the | |||
|
50 | * controller. If it is invalid, the method has no effect. | |||
|
51 | * @param dataProvider the provider of the data source | |||
|
52 | * @sa registerDataSource() | |||
|
53 | */ | |||
|
54 | void setDataProvider(const QUuid &dataSourceUid, | |||
|
55 | std::unique_ptr<IDataProvider> dataProvider) noexcept; | |||
|
56 | ||||
45 | public slots: |
|
57 | public slots: | |
46 | /// Manage init/end of the controller |
|
58 | /// Manage init/end of the controller | |
47 | void initialize(); |
|
59 | void initialize(); |
@@ -1,6 +1,8 | |||||
1 | #include <DataSource/DataSourceController.h> |
|
1 | #include <DataSource/DataSourceController.h> | |
2 | #include <DataSource/DataSourceItem.h> |
|
2 | #include <DataSource/DataSourceItem.h> | |
3 |
|
3 | |||
|
4 | #include <Data/IDataProvider.h> | |||
|
5 | ||||
4 | #include <QMutex> |
|
6 | #include <QMutex> | |
5 | #include <QThread> |
|
7 | #include <QThread> | |
6 |
|
8 | |||
@@ -16,6 +18,8 public: | |||||
16 | QHash<QUuid, QString> m_DataSources; |
|
18 | QHash<QUuid, QString> m_DataSources; | |
17 | /// Data sources structures |
|
19 | /// Data sources structures | |
18 | std::map<QUuid, std::unique_ptr<DataSourceItem> > m_DataSourceItems; |
|
20 | std::map<QUuid, std::unique_ptr<DataSourceItem> > m_DataSourceItems; | |
|
21 | /// Data providers registered | |||
|
22 | std::map<QUuid, std::unique_ptr<IDataProvider> > m_DataProviders; | |||
19 | }; |
|
23 | }; | |
20 |
|
24 | |||
21 | DataSourceController::DataSourceController(QObject *parent) |
|
25 | DataSourceController::DataSourceController(QObject *parent) | |
@@ -59,6 +63,19 void DataSourceController::setDataSourceItem( | |||||
59 | } |
|
63 | } | |
60 | } |
|
64 | } | |
61 |
|
65 | |||
|
66 | void DataSourceController::setDataProvider(const QUuid &dataSourceUid, | |||
|
67 | std::unique_ptr<IDataProvider> dataProvider) noexcept | |||
|
68 | { | |||
|
69 | if (impl->m_DataSources.contains(dataSourceUid)) { | |||
|
70 | impl->m_DataProviders.insert(std::make_pair(dataSourceUid, std::move(dataProvider))); | |||
|
71 | } | |||
|
72 | else { | |||
|
73 | qCWarning(LOG_DataSourceController()) << tr("Can't set data provider for uid %1 : no data " | |||
|
74 | "source has been registered with the uid") | |||
|
75 | .arg(dataSourceUid.toString()); | |||
|
76 | } | |||
|
77 | } | |||
|
78 | ||||
62 | void DataSourceController::initialize() |
|
79 | void DataSourceController::initialize() | |
63 | { |
|
80 | { | |
64 | qCDebug(LOG_DataSourceController()) << tr("DataSourceController init") |
|
81 | qCDebug(LOG_DataSourceController()) << tr("DataSourceController init") |
@@ -4,3 +4,7 Common/spimpl\.h:\d+:.* | |||||
4 | # Ignore false positive relative to two class definitions in a same file |
|
4 | # Ignore false positive relative to two class definitions in a same file | |
5 | DataSourceItem\.h:\d+:.*IPSIS_S01.* |
|
5 | DataSourceItem\.h:\d+:.*IPSIS_S01.* | |
6 |
|
6 | |||
|
7 | # Ignore false positive relative to a template class | |||
|
8 | ArrayData\.h:\d+:.*IPSIS_S04_VARIABLE.*found: (D) | |||
|
9 | ArrayData\.h:\d+:.*IPSIS_S06.*found: (D) | |||
|
10 | ArrayData\.h:\d+:.*IPSIS_S06.*found: (Dim) |
@@ -18,10 +18,6 class MockPlugin : public QObject, public IPlugin { | |||||
18 | public: |
|
18 | public: | |
19 | /// @sa IPlugin::initialize() |
|
19 | /// @sa IPlugin::initialize() | |
20 | void initialize() override; |
|
20 | void initialize() override; | |
21 |
|
||||
22 | private: |
|
|||
23 | /// Creates the data source item relative to the plugin |
|
|||
24 | std::unique_ptr<DataSourceItem> createDataSourceItem() const noexcept; |
|
|||
25 | }; |
|
21 | }; | |
26 |
|
22 | |||
27 | #endif // SCIQLOP_MOCKPLUGIN_H |
|
23 | #endif // SCIQLOP_MOCKPLUGIN_H |
@@ -1,4 +1,5 | |||||
1 |
#include |
|
1 | #include "MockPlugin.h" | |
|
2 | #include "CosinusProvider.h" | |||
2 |
|
3 | |||
3 | #include <DataSource/DataSourceController.h> |
|
4 | #include <DataSource/DataSourceController.h> | |
4 | #include <DataSource/DataSourceItem.h> |
|
5 | #include <DataSource/DataSourceItem.h> | |
@@ -12,23 +13,14 namespace { | |||||
12 | /// Name of the data source |
|
13 | /// Name of the data source | |
13 | const auto DATA_SOURCE_NAME = QStringLiteral("MMS"); |
|
14 | const auto DATA_SOURCE_NAME = QStringLiteral("MMS"); | |
14 |
|
15 | |||
15 | } // namespace |
|
16 | /// Creates the data provider relative to the plugin | |
16 |
|
17 | std::unique_ptr<IDataProvider> createDataProvider() noexcept | ||
17 | void MockPlugin::initialize() |
|
|||
18 | { |
|
18 | { | |
19 | if (auto app = sqpApp) { |
|
19 | return std::make_unique<CosinusProvider>(); | |
20 | // Registers to the data source controller |
|
|||
21 | auto &dataSourceController = app->dataSourceController(); |
|
|||
22 | auto dataSourceUid = dataSourceController.registerDataSource(DATA_SOURCE_NAME); |
|
|||
23 |
|
||||
24 | dataSourceController.setDataSourceItem(dataSourceUid, createDataSourceItem()); |
|
|||
25 | } |
|
|||
26 | else { |
|
|||
27 | qCWarning(LOG_MockPlugin()) << tr("Can't access to SciQlop application"); |
|
|||
28 | } |
|
|||
29 | } |
|
20 | } | |
30 |
|
21 | |||
31 | std::unique_ptr<DataSourceItem> MockPlugin::createDataSourceItem() const noexcept |
|
22 | /// Creates the data source item relative to the plugin | |
|
23 | std::unique_ptr<DataSourceItem> createDataSourceItem() noexcept | |||
32 | { |
|
24 | { | |
33 | // Magnetic field products |
|
25 | // Magnetic field products | |
34 | auto fgmProduct = std::make_unique<DataSourceItem>(DataSourceItemType::PRODUCT, |
|
26 | auto fgmProduct = std::make_unique<DataSourceItem>(DataSourceItemType::PRODUCT, | |
@@ -51,5 +43,25 std::unique_ptr<DataSourceItem> MockPlugin::createDataSourceItem() const noexcep | |||||
51 | root->appendChild(std::move(magneticFieldFolder)); |
|
43 | root->appendChild(std::move(magneticFieldFolder)); | |
52 | root->appendChild(std::move(electricFieldFolder)); |
|
44 | root->appendChild(std::move(electricFieldFolder)); | |
53 |
|
45 | |||
54 |
return |
|
46 | return root; | |
|
47 | } | |||
|
48 | ||||
|
49 | } // namespace | |||
|
50 | ||||
|
51 | void MockPlugin::initialize() | |||
|
52 | { | |||
|
53 | if (auto app = sqpApp) { | |||
|
54 | // Registers to the data source controller | |||
|
55 | auto &dataSourceController = app->dataSourceController(); | |||
|
56 | auto dataSourceUid = dataSourceController.registerDataSource(DATA_SOURCE_NAME); | |||
|
57 | ||||
|
58 | // Sets data source tree | |||
|
59 | dataSourceController.setDataSourceItem(dataSourceUid, createDataSourceItem()); | |||
|
60 | ||||
|
61 | // Sets data provider | |||
|
62 | dataSourceController.setDataProvider(dataSourceUid, createDataProvider()); | |||
|
63 | } | |||
|
64 | else { | |||
|
65 | qCWarning(LOG_MockPlugin()) << tr("Can't access to SciQlop application"); | |||
|
66 | } | |||
55 | } |
|
67 | } |
General Comments 0
You need to be logged in to leave comments.
Login now