@@ -1,82 +1,108 | |||||
1 | #ifndef SCIQLOP_ARRAYDATA_H |
|
1 | #ifndef SCIQLOP_ARRAYDATA_H | |
2 | #define SCIQLOP_ARRAYDATA_H |
|
2 | #define SCIQLOP_ARRAYDATA_H | |
3 |
|
3 | |||
|
4 | #include <QReadLocker> | |||
|
5 | #include <QReadWriteLock> | |||
4 | #include <QVector> |
|
6 | #include <QVector> | |
5 |
|
||||
6 | /** |
|
7 | /** | |
7 | * @brief The ArrayData class represents a dataset for a data series. |
|
8 | * @brief The ArrayData class represents a dataset for a data series. | |
8 | * |
|
9 | * | |
9 | * A dataset can be unidimensional or two-dimensional. This property is determined by the Dim |
|
10 | * A dataset can be unidimensional or two-dimensional. This property is determined by the Dim | |
10 | * template-parameter. |
|
11 | * template-parameter. | |
11 | * |
|
12 | * | |
12 | * @tparam Dim the dimension of the ArrayData (one or two) |
|
13 | * @tparam Dim the dimension of the ArrayData (one or two) | |
13 | * @sa IDataSeries |
|
14 | * @sa IDataSeries | |
14 | */ |
|
15 | */ | |
15 | template <int Dim> |
|
16 | template <int Dim> | |
16 | class ArrayData { |
|
17 | class ArrayData { | |
17 | public: |
|
18 | public: | |
18 | /** |
|
19 | /** | |
19 | * Ctor for a unidimensional ArrayData |
|
20 | * Ctor for a unidimensional ArrayData | |
20 | * @param nbColumns the number of values the ArrayData will hold |
|
21 | * @param nbColumns the number of values the ArrayData will hold | |
21 | */ |
|
22 | */ | |
22 | template <int D = Dim, typename = std::enable_if_t<D == 1> > |
|
23 | template <int D = Dim, typename = std::enable_if_t<D == 1> > | |
23 | explicit ArrayData(int nbColumns) : m_Data{1, QVector<double>{}} |
|
24 | explicit ArrayData(int nbColumns) : m_Data{1, QVector<double>{}} | |
24 | { |
|
25 | { | |
|
26 | QWriteLocker locker(&m_Lock); | |||
25 | m_Data[0].resize(nbColumns); |
|
27 | m_Data[0].resize(nbColumns); | |
26 | } |
|
28 | } | |
27 |
|
29 | |||
28 | /** |
|
30 | /** | |
|
31 | * Ctor for a unidimensional ArrayData | |||
|
32 | * @param nbColumns the number of values the ArrayData will hold | |||
|
33 | */ | |||
|
34 | explicit ArrayData(const ArrayData &other) | |||
|
35 | { | |||
|
36 | QReadLocker otherLocker(&other.m_Lock); | |||
|
37 | QWriteLocker locker(&m_Lock); | |||
|
38 | m_Data = other.m_Data; | |||
|
39 | } | |||
|
40 | ||||
|
41 | /** | |||
29 | * Sets a data at a specified index. The index has to be valid to be effective |
|
42 | * 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 |
|
43 | * @param index the index to which the data will be set | |
31 | * @param data the data to set |
|
44 | * @param data the data to set | |
32 | * @remarks this method is only available for a unidimensional ArrayData |
|
45 | * @remarks this method is only available for a unidimensional ArrayData | |
33 | */ |
|
46 | */ | |
34 | template <int D = Dim, typename = std::enable_if_t<D == 1> > |
|
47 | template <int D = Dim, typename = std::enable_if_t<D == 1> > | |
35 | void setData(int index, double data) noexcept |
|
48 | void setData(int index, double data) noexcept | |
36 | { |
|
49 | { | |
|
50 | QWriteLocker locker(&m_Lock); | |||
37 | if (index >= 0 && index < m_Data.at(0).size()) { |
|
51 | if (index >= 0 && index < m_Data.at(0).size()) { | |
38 | m_Data[0].replace(index, data); |
|
52 | m_Data[0].replace(index, data); | |
39 | } |
|
53 | } | |
40 | } |
|
54 | } | |
41 |
|
55 | |||
42 | /** |
|
56 | /** | |
43 | * @return the data as a vector |
|
57 | * @return the data as a vector | |
44 | * @remarks this method is only available for a unidimensional ArrayData |
|
58 | * @remarks this method is only available for a unidimensional ArrayData | |
45 | */ |
|
59 | */ | |
46 | template <int D = Dim, typename = std::enable_if_t<D == 1> > |
|
60 | template <int D = Dim, typename = std::enable_if_t<D == 1> > | |
47 |
|
|
61 | QVector<double> data() const noexcept | |
48 | { |
|
62 | { | |
|
63 | QReadLocker locker(&m_Lock); | |||
49 | return m_Data[0]; |
|
64 | return m_Data[0]; | |
50 | } |
|
65 | } | |
51 |
|
66 | |||
52 | /** |
|
67 | /** | |
53 | * @return the data as a vector |
|
68 | * @return the data as a vector | |
54 | * @remarks this method is only available for a unidimensional ArrayData |
|
69 | * @remarks this method is only available for a unidimensional ArrayData | |
55 | */ |
|
70 | */ | |
56 | template <int D = Dim, typename = std::enable_if_t<D == 1> > |
|
71 | template <int D = Dim, typename = std::enable_if_t<D == 1> > | |
57 |
|
|
72 | QVector<double> data(double tStart, double tEnd) const noexcept | |
58 | { |
|
73 | { | |
|
74 | QReadLocker locker(&m_Lock); | |||
59 | return m_Data.at(tStart); |
|
75 | return m_Data.at(tStart); | |
60 | } |
|
76 | } | |
61 |
|
77 | |||
62 | // TODO Comment |
|
78 | // TODO Comment | |
63 | template <int D = Dim, typename = std::enable_if_t<D == 1> > |
|
79 | template <int D = Dim, typename = std::enable_if_t<D == 1> > | |
64 | void merge(const ArrayData<1> &arrayData) |
|
80 | void merge(const ArrayData<1> &arrayData) | |
65 | { |
|
81 | { | |
|
82 | QWriteLocker locker(&m_Lock); | |||
66 | if (!m_Data.empty()) { |
|
83 | if (!m_Data.empty()) { | |
|
84 | QReadLocker otherLocker(&arrayData.m_Lock); | |||
67 | m_Data[0] += arrayData.data(); |
|
85 | m_Data[0] += arrayData.data(); | |
68 | } |
|
86 | } | |
69 | } |
|
87 | } | |
70 |
|
88 | |||
71 | template <int D = Dim, typename = std::enable_if_t<D == 1> > |
|
89 | template <int D = Dim, typename = std::enable_if_t<D == 1> > | |
72 | int size() |
|
90 | int size() const | |
73 | { |
|
91 | { | |
|
92 | QReadLocker locker(&m_Lock); | |||
74 | return m_Data[0].size(); |
|
93 | return m_Data[0].size(); | |
75 | } |
|
94 | } | |
76 |
|
95 | |||
|
96 | void clear() | |||
|
97 | { | |||
|
98 | QWriteLocker locker(&m_Lock); | |||
|
99 | m_Data.clear(); | |||
|
100 | } | |||
|
101 | ||||
77 |
|
102 | |||
78 | private: |
|
103 | private: | |
79 | QVector<QVector<double> > m_Data; |
|
104 | QVector<QVector<double> > m_Data; | |
|
105 | mutable QReadWriteLock m_Lock; | |||
80 | }; |
|
106 | }; | |
81 |
|
107 | |||
82 | #endif // SCIQLOP_ARRAYDATA_H |
|
108 | #endif // SCIQLOP_ARRAYDATA_H |
@@ -1,93 +1,107 | |||||
1 | #ifndef SCIQLOP_DATASERIES_H |
|
1 | #ifndef SCIQLOP_DATASERIES_H | |
2 | #define SCIQLOP_DATASERIES_H |
|
2 | #define SCIQLOP_DATASERIES_H | |
3 |
|
3 | |||
4 | #include <Data/ArrayData.h> |
|
4 | #include <Data/ArrayData.h> | |
5 | #include <Data/IDataSeries.h> |
|
5 | #include <Data/IDataSeries.h> | |
6 |
|
6 | |||
7 | #include <QLoggingCategory> |
|
7 | #include <QLoggingCategory> | |
8 |
|
8 | |||
|
9 | #include <QReadLocker> | |||
|
10 | #include <QReadWriteLock> | |||
9 | #include <memory> |
|
11 | #include <memory> | |
10 |
|
12 | |||
11 |
|
||||
12 | Q_DECLARE_LOGGING_CATEGORY(LOG_DataSeries) |
|
13 | Q_DECLARE_LOGGING_CATEGORY(LOG_DataSeries) | |
13 | Q_LOGGING_CATEGORY(LOG_DataSeries, "DataSeries") |
|
14 | Q_LOGGING_CATEGORY(LOG_DataSeries, "DataSeries") | |
14 |
|
15 | |||
15 |
|
16 | |||
16 | /** |
|
17 | /** | |
17 | * @brief The DataSeries class is the base (abstract) implementation of IDataSeries. |
|
18 | * @brief The DataSeries class is the base (abstract) implementation of IDataSeries. | |
18 | * |
|
19 | * | |
19 | * It proposes to set a dimension for the values ββdata |
|
20 | * It proposes to set a dimension for the values ββdata | |
20 | * |
|
21 | * | |
21 | * @tparam Dim The dimension of the values data |
|
22 | * @tparam Dim The dimension of the values data | |
22 | * |
|
23 | * | |
23 | */ |
|
24 | */ | |
24 | template <int Dim> |
|
25 | template <int Dim> | |
25 | class DataSeries : public IDataSeries { |
|
26 | class DataSeries : public IDataSeries { | |
26 | public: |
|
27 | public: | |
27 | /// @sa IDataSeries::xAxisData() |
|
28 | /// @sa IDataSeries::xAxisData() | |
28 | std::shared_ptr<ArrayData<1> > xAxisData() override { return m_XAxisData; } |
|
29 | std::shared_ptr<ArrayData<1> > xAxisData() override { return m_XAxisData; } | |
29 | const std::shared_ptr<ArrayData<1> > xAxisData() const { return m_XAxisData; } |
|
30 | const std::shared_ptr<ArrayData<1> > xAxisData() const { return m_XAxisData; } | |
30 |
|
31 | |||
31 | /// @sa IDataSeries::xAxisUnit() |
|
32 | /// @sa IDataSeries::xAxisUnit() | |
32 | Unit xAxisUnit() const override { return m_XAxisUnit; } |
|
33 | Unit xAxisUnit() const override { return m_XAxisUnit; } | |
33 |
|
34 | |||
34 | /// @return the values dataset |
|
35 | /// @return the values dataset | |
35 | std::shared_ptr<ArrayData<Dim> > valuesData() { return m_ValuesData; } |
|
36 | std::shared_ptr<ArrayData<Dim> > valuesData() { return m_ValuesData; } | |
36 | const std::shared_ptr<ArrayData<Dim> > valuesData() const { return m_ValuesData; } |
|
37 | const std::shared_ptr<ArrayData<Dim> > valuesData() const { return m_ValuesData; } | |
37 |
|
38 | |||
38 | /// @sa IDataSeries::valuesUnit() |
|
39 | /// @sa IDataSeries::valuesUnit() | |
39 | Unit valuesUnit() const override { return m_ValuesUnit; } |
|
40 | Unit valuesUnit() const override { return m_ValuesUnit; } | |
40 |
|
41 | |||
|
42 | void clear() | |||
|
43 | { | |||
|
44 | m_XAxisData->clear(); | |||
|
45 | m_ValuesData->clear(); | |||
|
46 | } | |||
|
47 | ||||
41 | /// @sa IDataSeries::merge() |
|
48 | /// @sa IDataSeries::merge() | |
42 | void merge(IDataSeries *dataSeries) override |
|
49 | void merge(IDataSeries *dataSeries) override | |
43 | { |
|
50 | { | |
44 | if (auto dimDataSeries = dynamic_cast<DataSeries<Dim> *>(dataSeries)) { |
|
51 | if (auto dimDataSeries = dynamic_cast<DataSeries<Dim> *>(dataSeries)) { | |
45 | m_XAxisData->merge(*dimDataSeries->xAxisData()); |
|
52 | m_XAxisData->merge(*dimDataSeries->xAxisData()); | |
46 | m_ValuesData->merge(*dimDataSeries->valuesData()); |
|
53 | m_ValuesData->merge(*dimDataSeries->valuesData()); | |
|
54 | dimDataSeries->clear(); | |||
47 | } |
|
55 | } | |
48 | else { |
|
56 | else { | |
49 | qCWarning(LOG_DataSeries()) |
|
57 | qCWarning(LOG_DataSeries()) | |
50 | << QObject::tr("Dection of a type of IDataSeries we cannot merge with !"); |
|
58 | << QObject::tr("Dection of a type of IDataSeries we cannot merge with !"); | |
51 | } |
|
59 | } | |
52 | } |
|
60 | } | |
53 |
|
61 | |||
|
62 | virtual void lockRead() { m_Lock.lockForRead(); } | |||
|
63 | virtual void lockWrite() { m_Lock.lockForWrite(); } | |||
|
64 | virtual void unlock() { m_Lock.unlock(); } | |||
|
65 | ||||
54 | protected: |
|
66 | protected: | |
55 | /// Protected ctor (DataSeries is abstract) |
|
67 | /// Protected ctor (DataSeries is abstract) | |
56 | explicit DataSeries(std::shared_ptr<ArrayData<1> > xAxisData, const Unit &xAxisUnit, |
|
68 | explicit DataSeries(std::shared_ptr<ArrayData<1> > xAxisData, const Unit &xAxisUnit, | |
57 | std::shared_ptr<ArrayData<Dim> > valuesData, const Unit &valuesUnit) |
|
69 | std::shared_ptr<ArrayData<Dim> > valuesData, const Unit &valuesUnit) | |
58 | : m_XAxisData{xAxisData}, |
|
70 | : m_XAxisData{xAxisData}, | |
59 | m_XAxisUnit{xAxisUnit}, |
|
71 | m_XAxisUnit{xAxisUnit}, | |
60 | m_ValuesData{valuesData}, |
|
72 | m_ValuesData{valuesData}, | |
61 | m_ValuesUnit{valuesUnit} |
|
73 | m_ValuesUnit{valuesUnit} | |
62 | { |
|
74 | { | |
63 | } |
|
75 | } | |
64 |
|
76 | |||
65 | /// Copy ctor |
|
77 | /// Copy ctor | |
66 | explicit DataSeries(const DataSeries<Dim> &other) |
|
78 | explicit DataSeries(const DataSeries<Dim> &other) | |
67 | : m_XAxisData{std::make_shared<ArrayData<1> >(*other.m_XAxisData)}, |
|
79 | : m_XAxisData{std::make_shared<ArrayData<1> >(*other.m_XAxisData)}, | |
68 | m_XAxisUnit{other.m_XAxisUnit}, |
|
80 | m_XAxisUnit{other.m_XAxisUnit}, | |
69 | m_ValuesData{std::make_shared<ArrayData<Dim> >(*other.m_ValuesData)}, |
|
81 | m_ValuesData{std::make_shared<ArrayData<Dim> >(*other.m_ValuesData)}, | |
70 | m_ValuesUnit{other.m_ValuesUnit} |
|
82 | m_ValuesUnit{other.m_ValuesUnit} | |
71 | { |
|
83 | { | |
72 | } |
|
84 | } | |
73 |
|
85 | |||
74 | /// Assignment operator |
|
86 | /// Assignment operator | |
75 | template <int D> |
|
87 | template <int D> | |
76 | DataSeries &operator=(DataSeries<D> other) |
|
88 | DataSeries &operator=(DataSeries<D> other) | |
77 | { |
|
89 | { | |
78 | std::swap(m_XAxisData, other.m_XAxisData); |
|
90 | std::swap(m_XAxisData, other.m_XAxisData); | |
79 | std::swap(m_XAxisUnit, other.m_XAxisUnit); |
|
91 | std::swap(m_XAxisUnit, other.m_XAxisUnit); | |
80 | std::swap(m_ValuesData, other.m_ValuesData); |
|
92 | std::swap(m_ValuesData, other.m_ValuesData); | |
81 | std::swap(m_ValuesUnit, other.m_ValuesUnit); |
|
93 | std::swap(m_ValuesUnit, other.m_ValuesUnit); | |
82 |
|
94 | |||
83 | return *this; |
|
95 | return *this; | |
84 | } |
|
96 | } | |
85 |
|
97 | |||
86 | private: |
|
98 | private: | |
87 | std::shared_ptr<ArrayData<1> > m_XAxisData; |
|
99 | std::shared_ptr<ArrayData<1> > m_XAxisData; | |
88 | Unit m_XAxisUnit; |
|
100 | Unit m_XAxisUnit; | |
89 | std::shared_ptr<ArrayData<Dim> > m_ValuesData; |
|
101 | std::shared_ptr<ArrayData<Dim> > m_ValuesData; | |
90 | Unit m_ValuesUnit; |
|
102 | Unit m_ValuesUnit; | |
|
103 | ||||
|
104 | QReadWriteLock m_Lock; | |||
91 | }; |
|
105 | }; | |
92 |
|
106 | |||
93 | #endif // SCIQLOP_DATASERIES_H |
|
107 | #endif // SCIQLOP_DATASERIES_H |
@@ -1,59 +1,63 | |||||
1 | #ifndef SCIQLOP_IDATASERIES_H |
|
1 | #ifndef SCIQLOP_IDATASERIES_H | |
2 | #define SCIQLOP_IDATASERIES_H |
|
2 | #define SCIQLOP_IDATASERIES_H | |
3 |
|
3 | |||
4 | #include <Common/MetaTypes.h> |
|
4 | #include <Common/MetaTypes.h> | |
5 |
|
5 | |||
6 | #include <memory> |
|
6 | #include <memory> | |
7 |
|
7 | |||
8 | #include <QString> |
|
8 | #include <QString> | |
9 |
|
9 | |||
10 | template <int Dim> |
|
10 | template <int Dim> | |
11 | class ArrayData; |
|
11 | class ArrayData; | |
12 |
|
12 | |||
13 | struct Unit { |
|
13 | struct Unit { | |
14 | explicit Unit(const QString &name = {}, bool timeUnit = false) |
|
14 | explicit Unit(const QString &name = {}, bool timeUnit = false) | |
15 | : m_Name{name}, m_TimeUnit{timeUnit} |
|
15 | : m_Name{name}, m_TimeUnit{timeUnit} | |
16 | { |
|
16 | { | |
17 | } |
|
17 | } | |
18 |
|
18 | |||
19 | QString m_Name; ///< Unit name |
|
19 | QString m_Name; ///< Unit name | |
20 | bool m_TimeUnit; ///< The unit is a unit of time |
|
20 | bool m_TimeUnit; ///< The unit is a unit of time | |
21 | }; |
|
21 | }; | |
22 |
|
22 | |||
23 | /** |
|
23 | /** | |
24 | * @brief The IDataSeries aims to declare a data series. |
|
24 | * @brief The IDataSeries aims to declare a data series. | |
25 | * |
|
25 | * | |
26 | * A data series is an entity that contains at least : |
|
26 | * A data series is an entity that contains at least : | |
27 | * - one dataset representing the x-axis |
|
27 | * - one dataset representing the x-axis | |
28 | * - one dataset representing the values |
|
28 | * - one dataset representing the values | |
29 | * |
|
29 | * | |
30 | * Each dataset is represented by an ArrayData, and is associated with a unit. |
|
30 | * Each dataset is represented by an ArrayData, and is associated with a unit. | |
31 | * |
|
31 | * | |
32 | * An ArrayData can be unidimensional or two-dimensional, depending on the implementation of the |
|
32 | * An ArrayData can be unidimensional or two-dimensional, depending on the implementation of the | |
33 | * IDataSeries. The x-axis dataset is always unidimensional. |
|
33 | * IDataSeries. The x-axis dataset is always unidimensional. | |
34 | * |
|
34 | * | |
35 | * @sa ArrayData |
|
35 | * @sa ArrayData | |
36 | */ |
|
36 | */ | |
37 | class IDataSeries { |
|
37 | class IDataSeries { | |
38 | public: |
|
38 | public: | |
39 | virtual ~IDataSeries() noexcept = default; |
|
39 | virtual ~IDataSeries() noexcept = default; | |
40 |
|
40 | |||
41 | /// Returns the x-axis dataset |
|
41 | /// Returns the x-axis dataset | |
42 | virtual std::shared_ptr<ArrayData<1> > xAxisData() = 0; |
|
42 | virtual std::shared_ptr<ArrayData<1> > xAxisData() = 0; | |
43 |
|
43 | |||
44 | /// Returns the x-axis dataset (as const) |
|
44 | /// Returns the x-axis dataset (as const) | |
45 | virtual const std::shared_ptr<ArrayData<1> > xAxisData() const = 0; |
|
45 | virtual const std::shared_ptr<ArrayData<1> > xAxisData() const = 0; | |
46 |
|
46 | |||
47 | virtual Unit xAxisUnit() const = 0; |
|
47 | virtual Unit xAxisUnit() const = 0; | |
48 |
|
48 | |||
49 | virtual Unit valuesUnit() const = 0; |
|
49 | virtual Unit valuesUnit() const = 0; | |
50 |
|
50 | |||
51 | virtual void merge(IDataSeries *dataSeries) = 0; |
|
51 | virtual void merge(IDataSeries *dataSeries) = 0; | |
52 |
|
52 | |||
53 | virtual std::unique_ptr<IDataSeries> clone() const = 0; |
|
53 | virtual std::unique_ptr<IDataSeries> clone() const = 0; | |
|
54 | ||||
|
55 | virtual void lockRead() = 0; | |||
|
56 | virtual void lockWrite() = 0; | |||
|
57 | virtual void unlock() = 0; | |||
54 | }; |
|
58 | }; | |
55 |
|
59 | |||
56 | // Required for using shared_ptr in signals/slots |
|
60 | // Required for using shared_ptr in signals/slots | |
57 | SCIQLOP_REGISTER_META_TYPE(IDATASERIES_PTR_REGISTRY, std::shared_ptr<IDataSeries>) |
|
61 | SCIQLOP_REGISTER_META_TYPE(IDATASERIES_PTR_REGISTRY, std::shared_ptr<IDataSeries>) | |
58 |
|
62 | |||
59 | #endif // SCIQLOP_IDATASERIES_H |
|
63 | #endif // SCIQLOP_IDATASERIES_H |
@@ -1,94 +1,101 | |||||
1 | #include "Variable/Variable.h" |
|
1 | #include "Variable/Variable.h" | |
2 |
|
2 | |||
3 | #include <Data/IDataSeries.h> |
|
3 | #include <Data/IDataSeries.h> | |
4 | #include <Data/SqpDateTime.h> |
|
4 | #include <Data/SqpDateTime.h> | |
5 |
|
5 | |||
|
6 | #include <QReadWriteLock> | |||
|
7 | #include <QThread> | |||
|
8 | ||||
6 | Q_LOGGING_CATEGORY(LOG_Variable, "Variable") |
|
9 | Q_LOGGING_CATEGORY(LOG_Variable, "Variable") | |
7 |
|
10 | |||
8 | struct Variable::VariablePrivate { |
|
11 | struct Variable::VariablePrivate { | |
9 | explicit VariablePrivate(const QString &name, const QString &unit, const QString &mission, |
|
12 | explicit VariablePrivate(const QString &name, const QString &unit, const QString &mission, | |
10 | const SqpDateTime &dateTime) |
|
13 | const SqpDateTime &dateTime) | |
11 | : m_Name{name}, |
|
14 | : m_Name{name}, | |
12 | m_Unit{unit}, |
|
15 | m_Unit{unit}, | |
13 | m_Mission{mission}, |
|
16 | m_Mission{mission}, | |
14 | m_DateTime{dateTime}, |
|
17 | m_DateTime{dateTime}, | |
15 | m_DataSeries{nullptr} |
|
18 | m_DataSeries{nullptr} | |
16 | { |
|
19 | { | |
17 | } |
|
20 | } | |
18 |
|
21 | |||
19 | QString m_Name; |
|
22 | QString m_Name; | |
20 | QString m_Unit; |
|
23 | QString m_Unit; | |
21 | QString m_Mission; |
|
24 | QString m_Mission; | |
22 |
|
25 | |||
23 | SqpDateTime m_DateTime; // The dateTime available in the view and loaded. not the cache. |
|
26 | SqpDateTime m_DateTime; // The dateTime available in the view and loaded. not the cache. | |
24 | std::unique_ptr<IDataSeries> m_DataSeries; |
|
27 | std::unique_ptr<IDataSeries> m_DataSeries; | |
25 | }; |
|
28 | }; | |
26 |
|
29 | |||
27 | Variable::Variable(const QString &name, const QString &unit, const QString &mission, |
|
30 | Variable::Variable(const QString &name, const QString &unit, const QString &mission, | |
28 | const SqpDateTime &dateTime) |
|
31 | const SqpDateTime &dateTime) | |
29 | : impl{spimpl::make_unique_impl<VariablePrivate>(name, unit, mission, dateTime)} |
|
32 | : impl{spimpl::make_unique_impl<VariablePrivate>(name, unit, mission, dateTime)} | |
30 | { |
|
33 | { | |
31 | } |
|
34 | } | |
32 |
|
35 | |||
33 | QString Variable::name() const noexcept |
|
36 | QString Variable::name() const noexcept | |
34 | { |
|
37 | { | |
35 | return impl->m_Name; |
|
38 | return impl->m_Name; | |
36 | } |
|
39 | } | |
37 |
|
40 | |||
38 | QString Variable::mission() const noexcept |
|
41 | QString Variable::mission() const noexcept | |
39 | { |
|
42 | { | |
40 | return impl->m_Mission; |
|
43 | return impl->m_Mission; | |
41 | } |
|
44 | } | |
42 |
|
45 | |||
43 | QString Variable::unit() const noexcept |
|
46 | QString Variable::unit() const noexcept | |
44 | { |
|
47 | { | |
45 | return impl->m_Unit; |
|
48 | return impl->m_Unit; | |
46 | } |
|
49 | } | |
47 |
|
50 | |||
48 | SqpDateTime Variable::dateTime() const noexcept |
|
51 | SqpDateTime Variable::dateTime() const noexcept | |
49 | { |
|
52 | { | |
50 | return impl->m_DateTime; |
|
53 | return impl->m_DateTime; | |
51 | } |
|
54 | } | |
52 |
|
55 | |||
53 | void Variable::setDateTime(const SqpDateTime &dateTime) noexcept |
|
56 | void Variable::setDateTime(const SqpDateTime &dateTime) noexcept | |
54 | { |
|
57 | { | |
55 | impl->m_DateTime = dateTime; |
|
58 | impl->m_DateTime = dateTime; | |
56 | } |
|
59 | } | |
57 |
|
60 | |||
58 | void Variable::setDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept |
|
61 | void Variable::setDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept | |
59 | { |
|
62 | { | |
|
63 | qCDebug(LOG_Variable()) << "Variable::setDataSeries" << QThread::currentThread()->objectName(); | |||
60 | if (!dataSeries) { |
|
64 | if (!dataSeries) { | |
61 | /// @todo ALX : log |
|
65 | /// @todo ALX : log | |
62 | return; |
|
66 | return; | |
63 | } |
|
67 | } | |
64 |
|
68 | |||
65 | // Inits the data series of the variable |
|
69 | // Inits the data series of the variable | |
66 | if (!impl->m_DataSeries) { |
|
70 | if (!impl->m_DataSeries) { | |
67 | impl->m_DataSeries = dataSeries->clone(); |
|
71 | impl->m_DataSeries = dataSeries->clone(); | |
68 | } |
|
72 | } | |
69 | else { |
|
73 | else { | |
|
74 | dataSeries->lockWrite(); | |||
|
75 | impl->m_DataSeries->lockWrite(); | |||
70 | impl->m_DataSeries->merge(dataSeries.get()); |
|
76 | impl->m_DataSeries->merge(dataSeries.get()); | |
71 |
|
77 | impl->m_DataSeries->unlock(); | ||
|
78 | dataSeries->unlock(); | |||
72 | emit updated(); |
|
79 | emit updated(); | |
73 | } |
|
80 | } | |
74 | } |
|
81 | } | |
75 |
|
82 | |||
76 | IDataSeries *Variable::dataSeries() const noexcept |
|
83 | IDataSeries *Variable::dataSeries() const noexcept | |
77 | { |
|
84 | { | |
78 | return impl->m_DataSeries.get(); |
|
85 | return impl->m_DataSeries.get(); | |
79 | } |
|
86 | } | |
80 |
|
87 | |||
81 | bool Variable::contains(const SqpDateTime &dateTime) const noexcept |
|
88 | bool Variable::contains(const SqpDateTime &dateTime) const noexcept | |
82 | { |
|
89 | { | |
83 | return impl->m_DateTime.contains(dateTime); |
|
90 | return impl->m_DateTime.contains(dateTime); | |
84 | } |
|
91 | } | |
85 |
|
92 | |||
86 | bool Variable::intersect(const SqpDateTime &dateTime) const noexcept |
|
93 | bool Variable::intersect(const SqpDateTime &dateTime) const noexcept | |
87 | { |
|
94 | { | |
88 | return impl->m_DateTime.intersect(dateTime); |
|
95 | return impl->m_DateTime.intersect(dateTime); | |
89 | } |
|
96 | } | |
90 |
|
97 | |||
91 | bool Variable::isInside(const SqpDateTime &dateTime) const noexcept |
|
98 | bool Variable::isInside(const SqpDateTime &dateTime) const noexcept | |
92 | { |
|
99 | { | |
93 | return dateTime.contains(SqpDateTime{impl->m_DateTime.m_TStart, impl->m_DateTime.m_TEnd}); |
|
100 | return dateTime.contains(SqpDateTime{impl->m_DateTime.m_TStart, impl->m_DateTime.m_TEnd}); | |
94 | } |
|
101 | } |
@@ -1,220 +1,228 | |||||
1 | #include "Variable/VariableCacheController.h" |
|
1 | #include "Variable/VariableCacheController.h" | |
2 |
|
2 | |||
3 | #include "Variable/Variable.h" |
|
3 | #include "Variable/Variable.h" | |
4 | #include <unordered_map> |
|
4 | #include <unordered_map> | |
5 |
|
5 | |||
|
6 | #include <QThread> | |||
6 | Q_LOGGING_CATEGORY(LOG_VariableCacheController, "VariableCacheController") |
|
7 | Q_LOGGING_CATEGORY(LOG_VariableCacheController, "VariableCacheController") | |
7 |
|
8 | |||
8 | struct VariableCacheController::VariableCacheControllerPrivate { |
|
9 | struct VariableCacheController::VariableCacheControllerPrivate { | |
9 |
|
10 | |||
10 | std::unordered_map<std::shared_ptr<Variable>, QVector<SqpDateTime> > |
|
11 | std::unordered_map<std::shared_ptr<Variable>, QVector<SqpDateTime> > | |
11 | m_VariableToSqpDateTimeListMap; |
|
12 | m_VariableToSqpDateTimeListMap; | |
12 |
|
13 | |||
13 | void addInCacheDataByEnd(const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, |
|
14 | void addInCacheDataByEnd(const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, | |
14 | QVector<SqpDateTime> ¬InCache, int cacheIndex, |
|
15 | QVector<SqpDateTime> ¬InCache, int cacheIndex, | |
15 | double currentTStart); |
|
16 | double currentTStart); | |
16 |
|
17 | |||
17 | void addInCacheDataByStart(const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, |
|
18 | void addInCacheDataByStart(const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, | |
18 | QVector<SqpDateTime> ¬InCache, int cacheIndex, |
|
19 | QVector<SqpDateTime> ¬InCache, int cacheIndex, | |
19 | double currentTStart); |
|
20 | double currentTStart); | |
20 |
|
21 | |||
21 |
|
22 | |||
22 | void addDateTimeRecurse(const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, |
|
23 | void addDateTimeRecurse(const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, | |
23 | int cacheIndex); |
|
24 | int cacheIndex); | |
24 | }; |
|
25 | }; | |
25 |
|
26 | |||
26 |
|
27 | |||
27 | VariableCacheController::VariableCacheController(QObject *parent) |
|
28 | VariableCacheController::VariableCacheController(QObject *parent) | |
28 | : QObject{parent}, impl{spimpl::make_unique_impl<VariableCacheControllerPrivate>()} |
|
29 | : QObject{parent}, impl{spimpl::make_unique_impl<VariableCacheControllerPrivate>()} | |
29 | { |
|
30 | { | |
30 | } |
|
31 | } | |
31 |
|
32 | |||
32 | void VariableCacheController::addDateTime(std::shared_ptr<Variable> variable, |
|
33 | void VariableCacheController::addDateTime(std::shared_ptr<Variable> variable, | |
33 | const SqpDateTime &dateTime) |
|
34 | const SqpDateTime &dateTime) | |
34 | { |
|
35 | { | |
|
36 | qCDebug(LOG_VariableCacheController()) << "VariableCacheController::addDateTime" | |||
|
37 | << QThread::currentThread()->objectName(); | |||
35 | if (variable) { |
|
38 | if (variable) { | |
36 | auto findVariableIte = impl->m_VariableToSqpDateTimeListMap.find(variable); |
|
39 | auto findVariableIte = impl->m_VariableToSqpDateTimeListMap.find(variable); | |
37 | if (findVariableIte == impl->m_VariableToSqpDateTimeListMap.end()) { |
|
40 | if (findVariableIte == impl->m_VariableToSqpDateTimeListMap.end()) { | |
38 | impl->m_VariableToSqpDateTimeListMap[variable].push_back(dateTime); |
|
41 | impl->m_VariableToSqpDateTimeListMap[variable].push_back(dateTime); | |
39 | } |
|
42 | } | |
40 | else { |
|
43 | else { | |
41 |
|
44 | |||
42 | // addDateTime modify the list<SqpDateTime> of the variable in a way to ensure |
|
45 | // addDateTime modify the list<SqpDateTime> of the variable in a way to ensure | |
43 | // that the list is ordered : l(0) < l(1). We assume also a < b |
|
46 | // that the list is ordered : l(0) < l(1). We assume also a < b | |
44 | // (with a & b of type SqpDateTime) means ts(b) > te(a) |
|
47 | // (with a & b of type SqpDateTime) means ts(b) > te(a) | |
45 |
|
48 | |||
46 | // The algorithm will try the merge of two interval: |
|
49 | // The algorithm will try the merge of two interval: | |
47 | // - dateTime will be compare with the first interval of the list: |
|
50 | // - dateTime will be compare with the first interval of the list: | |
48 | // A: if it is inferior, it will be inserted and it's finished. |
|
51 | // A: if it is inferior, it will be inserted and it's finished. | |
49 | // B: if it is in intersection, it will be merge then the merged one |
|
52 | // B: if it is in intersection, it will be merge then the merged one | |
50 | // will be compared to the next interval. The old one is remove from the list |
|
53 | // will be compared to the next interval. The old one is remove from the list | |
51 | // C: if it is superior, we do the same with the next interval of the list |
|
54 | // C: if it is superior, we do the same with the next interval of the list | |
52 |
|
55 | |||
53 | try { |
|
56 | try { | |
54 | impl->addDateTimeRecurse(dateTime, |
|
57 | impl->addDateTimeRecurse(dateTime, | |
55 | impl->m_VariableToSqpDateTimeListMap.at(variable), 0); |
|
58 | impl->m_VariableToSqpDateTimeListMap.at(variable), 0); | |
56 | } |
|
59 | } | |
57 | catch (const std::out_of_range &e) { |
|
60 | catch (const std::out_of_range &e) { | |
58 | qCWarning(LOG_VariableCacheController()) << "addDateTime" << e.what(); |
|
61 | qCWarning(LOG_VariableCacheController()) << "addDateTime" << e.what(); | |
59 | } |
|
62 | } | |
60 | } |
|
63 | } | |
61 | } |
|
64 | } | |
62 | } |
|
65 | } | |
63 |
|
66 | |||
64 | void VariableCacheController::clear(std::shared_ptr<Variable> variable) noexcept |
|
67 | void VariableCacheController::clear(std::shared_ptr<Variable> variable) noexcept | |
65 | { |
|
68 | { | |
66 | if (!variable) { |
|
69 | if (!variable) { | |
67 | qCCritical(LOG_VariableCacheController()) << "Can't clear variable cache: variable is null"; |
|
70 | qCCritical(LOG_VariableCacheController()) << "Can't clear variable cache: variable is null"; | |
68 | return; |
|
71 | return; | |
69 | } |
|
72 | } | |
70 |
|
73 | |||
71 | auto nbEntries = impl->m_VariableToSqpDateTimeListMap.erase(variable); |
|
74 | auto nbEntries = impl->m_VariableToSqpDateTimeListMap.erase(variable); | |
72 |
|
75 | |||
73 | auto clearCacheMessage |
|
76 | auto clearCacheMessage | |
74 | = (nbEntries != 0) |
|
77 | = (nbEntries != 0) | |
75 | ? tr("Variable cache cleared for variable %1").arg(variable->name()) |
|
78 | ? tr("Variable cache cleared for variable %1").arg(variable->name()) | |
76 | : tr("No deletion of variable cache: no cache was associated with the variable"); |
|
79 | : tr("No deletion of variable cache: no cache was associated with the variable"); | |
77 | qCDebug(LOG_VariableCacheController()) << clearCacheMessage; |
|
80 | qCDebug(LOG_VariableCacheController()) << clearCacheMessage; | |
78 | } |
|
81 | } | |
79 |
|
82 | |||
80 | QVector<SqpDateTime> |
|
83 | QVector<SqpDateTime> | |
81 | VariableCacheController::provideNotInCacheDateTimeList(std::shared_ptr<Variable> variable, |
|
84 | VariableCacheController::provideNotInCacheDateTimeList(std::shared_ptr<Variable> variable, | |
82 | const SqpDateTime &dateTime) |
|
85 | const SqpDateTime &dateTime) | |
83 | { |
|
86 | { | |
|
87 | qCDebug(LOG_VariableCacheController()) | |||
|
88 | << "VariableCacheController::provideNotInCacheDateTimeList" | |||
|
89 | << QThread::currentThread()->objectName(); | |||
84 | auto notInCache = QVector<SqpDateTime>{}; |
|
90 | auto notInCache = QVector<SqpDateTime>{}; | |
85 |
|
91 | |||
86 | // This algorithm is recursif. The idea is to localise the start time then the end time in the |
|
92 | // This algorithm is recursif. The idea is to localise the start time then the end time in the | |
87 | // list of date time request associated to the variable |
|
93 | // list of date time request associated to the variable | |
88 | // We assume that the list is ordered in a way that l(0) < l(1). We assume also a < b |
|
94 | // We assume that the list is ordered in a way that l(0) < l(1). We assume also a < b | |
89 | // (with a & b of type SqpDateTime) means ts(b) > te(a) |
|
95 | // (with a & b of type SqpDateTime) means ts(b) > te(a) | |
90 | auto it = impl->m_VariableToSqpDateTimeListMap.find(variable); |
|
96 | auto it = impl->m_VariableToSqpDateTimeListMap.find(variable); | |
91 | if (it != impl->m_VariableToSqpDateTimeListMap.end()) { |
|
97 | if (it != impl->m_VariableToSqpDateTimeListMap.end()) { | |
92 | impl->addInCacheDataByStart(dateTime, it->second, notInCache, 0, dateTime.m_TStart); |
|
98 | impl->addInCacheDataByStart(dateTime, it->second, notInCache, 0, dateTime.m_TStart); | |
93 | } |
|
99 | } | |
94 | else { |
|
100 | else { | |
95 | notInCache << dateTime; |
|
101 | notInCache << dateTime; | |
96 | } |
|
102 | } | |
97 |
|
103 | |||
98 | return notInCache; |
|
104 | return notInCache; | |
99 | } |
|
105 | } | |
100 |
|
106 | |||
101 | QVector<SqpDateTime> |
|
107 | QVector<SqpDateTime> | |
102 | VariableCacheController::dateCacheList(std::shared_ptr<Variable> variable) const noexcept |
|
108 | VariableCacheController::dateCacheList(std::shared_ptr<Variable> variable) const noexcept | |
103 | { |
|
109 | { | |
|
110 | qCDebug(LOG_VariableCacheController()) << "VariableCacheController::dateCacheList" | |||
|
111 | << QThread::currentThread()->objectName(); | |||
104 | try { |
|
112 | try { | |
105 | return impl->m_VariableToSqpDateTimeListMap.at(variable); |
|
113 | return impl->m_VariableToSqpDateTimeListMap.at(variable); | |
106 | } |
|
114 | } | |
107 | catch (const std::out_of_range &e) { |
|
115 | catch (const std::out_of_range &e) { | |
108 | qCWarning(LOG_VariableCacheController()) << e.what(); |
|
116 | qCWarning(LOG_VariableCacheController()) << e.what(); | |
109 | return QVector<SqpDateTime>{}; |
|
117 | return QVector<SqpDateTime>{}; | |
110 | } |
|
118 | } | |
111 | } |
|
119 | } | |
112 |
|
120 | |||
113 | void VariableCacheController::VariableCacheControllerPrivate::addDateTimeRecurse( |
|
121 | void VariableCacheController::VariableCacheControllerPrivate::addDateTimeRecurse( | |
114 | const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, int cacheIndex) |
|
122 | const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, int cacheIndex) | |
115 | { |
|
123 | { | |
116 | const auto dateTimeListSize = dateTimeList.count(); |
|
124 | const auto dateTimeListSize = dateTimeList.count(); | |
117 | if (cacheIndex >= dateTimeListSize) { |
|
125 | if (cacheIndex >= dateTimeListSize) { | |
118 | dateTimeList.push_back(dateTime); |
|
126 | dateTimeList.push_back(dateTime); | |
119 | // there is no anymore interval to compore, we can just push_back it |
|
127 | // there is no anymore interval to compore, we can just push_back it | |
120 | return; |
|
128 | return; | |
121 | } |
|
129 | } | |
122 |
|
130 | |||
123 | auto currentDateTime = dateTimeList[cacheIndex]; |
|
131 | auto currentDateTime = dateTimeList[cacheIndex]; | |
124 |
|
132 | |||
125 | if (dateTime.m_TEnd < currentDateTime.m_TStart) { |
|
133 | if (dateTime.m_TEnd < currentDateTime.m_TStart) { | |
126 | // The compared one is < to current one compared, we can insert it |
|
134 | // The compared one is < to current one compared, we can insert it | |
127 | dateTimeList.insert(cacheIndex, dateTime); |
|
135 | dateTimeList.insert(cacheIndex, dateTime); | |
128 | } |
|
136 | } | |
129 | else if (dateTime.m_TStart > currentDateTime.m_TEnd) { |
|
137 | else if (dateTime.m_TStart > currentDateTime.m_TEnd) { | |
130 | // The compared one is > to current one compared we can comparet if to the next one |
|
138 | // The compared one is > to current one compared we can comparet if to the next one | |
131 | addDateTimeRecurse(dateTime, dateTimeList, ++cacheIndex); |
|
139 | addDateTimeRecurse(dateTime, dateTimeList, ++cacheIndex); | |
132 | } |
|
140 | } | |
133 | else { |
|
141 | else { | |
134 | // Merge cases: we need to merge the two interval, remove the old one from the list then |
|
142 | // Merge cases: we need to merge the two interval, remove the old one from the list then | |
135 | // rerun the algo from this index with the merged interval |
|
143 | // rerun the algo from this index with the merged interval | |
136 | auto mTStart = std::min(dateTime.m_TStart, currentDateTime.m_TStart); |
|
144 | auto mTStart = std::min(dateTime.m_TStart, currentDateTime.m_TStart); | |
137 | auto mTEnd = std::max(dateTime.m_TEnd, currentDateTime.m_TEnd); |
|
145 | auto mTEnd = std::max(dateTime.m_TEnd, currentDateTime.m_TEnd); | |
138 | auto mergeDateTime = SqpDateTime{mTStart, mTEnd}; |
|
146 | auto mergeDateTime = SqpDateTime{mTStart, mTEnd}; | |
139 |
|
147 | |||
140 | dateTimeList.remove(cacheIndex); |
|
148 | dateTimeList.remove(cacheIndex); | |
141 | addDateTimeRecurse(mergeDateTime, dateTimeList, cacheIndex); |
|
149 | addDateTimeRecurse(mergeDateTime, dateTimeList, cacheIndex); | |
142 | } |
|
150 | } | |
143 | } |
|
151 | } | |
144 |
|
152 | |||
145 |
|
153 | |||
146 | void VariableCacheController::VariableCacheControllerPrivate::addInCacheDataByEnd( |
|
154 | void VariableCacheController::VariableCacheControllerPrivate::addInCacheDataByEnd( | |
147 | const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, |
|
155 | const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, | |
148 | QVector<SqpDateTime> ¬InCache, int cacheIndex, double currentTStart) |
|
156 | QVector<SqpDateTime> ¬InCache, int cacheIndex, double currentTStart) | |
149 | { |
|
157 | { | |
150 | const auto dateTimeListSize = dateTimeList.count(); |
|
158 | const auto dateTimeListSize = dateTimeList.count(); | |
151 | if (cacheIndex >= dateTimeListSize) { |
|
159 | if (cacheIndex >= dateTimeListSize) { | |
152 | if (currentTStart < dateTime.m_TEnd) { |
|
160 | if (currentTStart < dateTime.m_TEnd) { | |
153 |
|
161 | |||
154 | // te localised after all other interval: The last interval is [currentTsart, te] |
|
162 | // te localised after all other interval: The last interval is [currentTsart, te] | |
155 | notInCache.push_back(SqpDateTime{currentTStart, dateTime.m_TEnd}); |
|
163 | notInCache.push_back(SqpDateTime{currentTStart, dateTime.m_TEnd}); | |
156 | } |
|
164 | } | |
157 | return; |
|
165 | return; | |
158 | } |
|
166 | } | |
159 |
|
167 | |||
160 | auto currentDateTimeJ = dateTimeList[cacheIndex]; |
|
168 | auto currentDateTimeJ = dateTimeList[cacheIndex]; | |
161 | if (dateTime.m_TEnd <= currentDateTimeJ.m_TStart) { |
|
169 | if (dateTime.m_TEnd <= currentDateTimeJ.m_TStart) { | |
162 | // te localised between to interval: The last interval is [currentTsart, te] |
|
170 | // te localised between to interval: The last interval is [currentTsart, te] | |
163 | notInCache.push_back(SqpDateTime{currentTStart, dateTime.m_TEnd}); |
|
171 | notInCache.push_back(SqpDateTime{currentTStart, dateTime.m_TEnd}); | |
164 | } |
|
172 | } | |
165 | else { |
|
173 | else { | |
166 | notInCache.push_back(SqpDateTime{currentTStart, currentDateTimeJ.m_TStart}); |
|
174 | notInCache.push_back(SqpDateTime{currentTStart, currentDateTimeJ.m_TStart}); | |
167 | if (dateTime.m_TEnd > currentDateTimeJ.m_TEnd) { |
|
175 | if (dateTime.m_TEnd > currentDateTimeJ.m_TEnd) { | |
168 | // te not localised before the current interval: we need to look at the next interval |
|
176 | // te not localised before the current interval: we need to look at the next interval | |
169 | addInCacheDataByEnd(dateTime, dateTimeList, notInCache, ++cacheIndex, |
|
177 | addInCacheDataByEnd(dateTime, dateTimeList, notInCache, ++cacheIndex, | |
170 | currentDateTimeJ.m_TEnd); |
|
178 | currentDateTimeJ.m_TEnd); | |
171 | } |
|
179 | } | |
172 | } |
|
180 | } | |
173 | } |
|
181 | } | |
174 |
|
182 | |||
175 | void VariableCacheController::VariableCacheControllerPrivate::addInCacheDataByStart( |
|
183 | void VariableCacheController::VariableCacheControllerPrivate::addInCacheDataByStart( | |
176 | const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, |
|
184 | const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, | |
177 | QVector<SqpDateTime> ¬InCache, int cacheIndex, double currentTStart) |
|
185 | QVector<SqpDateTime> ¬InCache, int cacheIndex, double currentTStart) | |
178 | { |
|
186 | { | |
179 | const auto dateTimeListSize = dateTimeList.count(); |
|
187 | const auto dateTimeListSize = dateTimeList.count(); | |
180 | if (cacheIndex >= dateTimeListSize) { |
|
188 | if (cacheIndex >= dateTimeListSize) { | |
181 | // ts localised after all other interval: The last interval is [ts, te] |
|
189 | // ts localised after all other interval: The last interval is [ts, te] | |
182 | notInCache.push_back(SqpDateTime{currentTStart, dateTime.m_TEnd}); |
|
190 | notInCache.push_back(SqpDateTime{currentTStart, dateTime.m_TEnd}); | |
183 | return; |
|
191 | return; | |
184 | } |
|
192 | } | |
185 |
|
193 | |||
186 | auto currentDateTimeI = dateTimeList[cacheIndex]; |
|
194 | auto currentDateTimeI = dateTimeList[cacheIndex]; | |
187 | if (currentTStart < currentDateTimeI.m_TStart) { |
|
195 | if (currentTStart < currentDateTimeI.m_TStart) { | |
188 |
|
196 | |||
189 | // ts localised between to interval: let's localized te |
|
197 | // ts localised between to interval: let's localized te | |
190 | addInCacheDataByEnd(dateTime, dateTimeList, notInCache, cacheIndex, currentTStart); |
|
198 | addInCacheDataByEnd(dateTime, dateTimeList, notInCache, cacheIndex, currentTStart); | |
191 | } |
|
199 | } | |
192 | else if (currentTStart < currentDateTimeI.m_TEnd) { |
|
200 | else if (currentTStart < currentDateTimeI.m_TEnd) { | |
193 | if (dateTime.m_TEnd > currentDateTimeI.m_TEnd) { |
|
201 | if (dateTime.m_TEnd > currentDateTimeI.m_TEnd) { | |
194 | // ts not localised before the current interval: we need to look at the next interval |
|
202 | // ts not localised before the current interval: we need to look at the next interval | |
195 | // We can assume now current tstart is the last interval tend, because data between them |
|
203 | // We can assume now current tstart is the last interval tend, because data between them | |
196 | // are |
|
204 | // are | |
197 | // in the cache |
|
205 | // in the cache | |
198 | addInCacheDataByStart(dateTime, dateTimeList, notInCache, ++cacheIndex, |
|
206 | addInCacheDataByStart(dateTime, dateTimeList, notInCache, ++cacheIndex, | |
199 | currentDateTimeI.m_TEnd); |
|
207 | currentDateTimeI.m_TEnd); | |
200 | } |
|
208 | } | |
201 | } |
|
209 | } | |
202 | else { |
|
210 | else { | |
203 | // ts not localised before the current interval: we need to look at the next interval |
|
211 | // ts not localised before the current interval: we need to look at the next interval | |
204 | addInCacheDataByStart(dateTime, dateTimeList, notInCache, ++cacheIndex, currentTStart); |
|
212 | addInCacheDataByStart(dateTime, dateTimeList, notInCache, ++cacheIndex, currentTStart); | |
205 | } |
|
213 | } | |
206 | } |
|
214 | } | |
207 |
|
215 | |||
208 |
|
216 | |||
209 | void VariableCacheController::displayCache(std::shared_ptr<Variable> variable) const |
|
217 | void VariableCacheController::displayCache(std::shared_ptr<Variable> variable) const | |
210 | { |
|
218 | { | |
211 | auto variableDateTimeList = impl->m_VariableToSqpDateTimeListMap.find(variable); |
|
219 | auto variableDateTimeList = impl->m_VariableToSqpDateTimeListMap.find(variable); | |
212 | if (variableDateTimeList != impl->m_VariableToSqpDateTimeListMap.end()) { |
|
220 | if (variableDateTimeList != impl->m_VariableToSqpDateTimeListMap.end()) { | |
213 | qCInfo(LOG_VariableCacheController()) << tr("VariableCacheController::displayCache") |
|
221 | qCInfo(LOG_VariableCacheController()) << tr("VariableCacheController::displayCache") | |
214 | << variableDateTimeList->second; |
|
222 | << variableDateTimeList->second; | |
215 | } |
|
223 | } | |
216 | else { |
|
224 | else { | |
217 | qCWarning(LOG_VariableCacheController()) |
|
225 | qCWarning(LOG_VariableCacheController()) | |
218 | << tr("Cannot display a variable that is not in the cache"); |
|
226 | << tr("Cannot display a variable that is not in the cache"); | |
219 | } |
|
227 | } | |
220 | } |
|
228 | } |
@@ -1,207 +1,211 | |||||
1 | #include <Variable/Variable.h> |
|
1 | #include <Variable/Variable.h> | |
2 | #include <Variable/VariableCacheController.h> |
|
2 | #include <Variable/VariableCacheController.h> | |
3 | #include <Variable/VariableController.h> |
|
3 | #include <Variable/VariableController.h> | |
4 | #include <Variable/VariableModel.h> |
|
4 | #include <Variable/VariableModel.h> | |
5 |
|
5 | |||
6 | #include <Data/DataProviderParameters.h> |
|
6 | #include <Data/DataProviderParameters.h> | |
7 | #include <Data/IDataProvider.h> |
|
7 | #include <Data/IDataProvider.h> | |
8 | #include <Data/IDataSeries.h> |
|
8 | #include <Data/IDataSeries.h> | |
9 | #include <Time/TimeController.h> |
|
9 | #include <Time/TimeController.h> | |
10 |
|
10 | |||
11 | #include <QDateTime> |
|
11 | #include <QDateTime> | |
12 | #include <QMutex> |
|
12 | #include <QMutex> | |
13 | #include <QThread> |
|
13 | #include <QThread> | |
14 | #include <QtCore/QItemSelectionModel> |
|
14 | #include <QtCore/QItemSelectionModel> | |
15 |
|
15 | |||
16 | #include <unordered_map> |
|
16 | #include <unordered_map> | |
17 |
|
17 | |||
18 | Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController") |
|
18 | Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController") | |
19 |
|
19 | |||
20 | namespace { |
|
20 | namespace { | |
21 |
|
21 | |||
22 | /// @todo Generates default dataseries, according to the provider passed in parameter. This method |
|
22 | /// @todo Generates default dataseries, according to the provider passed in parameter. This method | |
23 | /// will be deleted when the timerange is recovered from SciQlop |
|
23 | /// will be deleted when the timerange is recovered from SciQlop | |
24 | std::shared_ptr<IDataSeries> generateDefaultDataSeries(const IDataProvider &provider, |
|
24 | std::shared_ptr<IDataSeries> generateDefaultDataSeries(const IDataProvider &provider, | |
25 | const SqpDateTime &dateTime) noexcept |
|
25 | const SqpDateTime &dateTime) noexcept | |
26 | { |
|
26 | { | |
27 | auto parameters = DataProviderParameters{dateTime}; |
|
27 | auto parameters = DataProviderParameters{dateTime}; | |
28 |
|
28 | |||
29 | return provider.retrieveData(parameters); |
|
29 | return provider.retrieveData(parameters); | |
30 | } |
|
30 | } | |
31 |
|
31 | |||
32 | } // namespace |
|
32 | } // namespace | |
33 |
|
33 | |||
34 | struct VariableController::VariableControllerPrivate { |
|
34 | struct VariableController::VariableControllerPrivate { | |
35 | explicit VariableControllerPrivate(VariableController *parent) |
|
35 | explicit VariableControllerPrivate(VariableController *parent) | |
36 | : m_WorkingMutex{}, |
|
36 | : m_WorkingMutex{}, | |
37 | m_VariableModel{new VariableModel{parent}}, |
|
37 | m_VariableModel{new VariableModel{parent}}, | |
38 | m_VariableSelectionModel{new QItemSelectionModel{m_VariableModel, parent}}, |
|
38 | m_VariableSelectionModel{new QItemSelectionModel{m_VariableModel, parent}}, | |
39 | m_VariableCacheController{std::make_unique<VariableCacheController>()} |
|
39 | m_VariableCacheController{std::make_unique<VariableCacheController>()} | |
40 | { |
|
40 | { | |
41 | } |
|
41 | } | |
42 |
|
42 | |||
43 | QMutex m_WorkingMutex; |
|
43 | QMutex m_WorkingMutex; | |
44 | /// Variable model. The VariableController has the ownership |
|
44 | /// Variable model. The VariableController has the ownership | |
45 | VariableModel *m_VariableModel; |
|
45 | VariableModel *m_VariableModel; | |
46 | QItemSelectionModel *m_VariableSelectionModel; |
|
46 | QItemSelectionModel *m_VariableSelectionModel; | |
47 |
|
47 | |||
48 |
|
48 | |||
49 | TimeController *m_TimeController{nullptr}; |
|
49 | TimeController *m_TimeController{nullptr}; | |
50 | std::unique_ptr<VariableCacheController> m_VariableCacheController; |
|
50 | std::unique_ptr<VariableCacheController> m_VariableCacheController; | |
51 |
|
51 | |||
52 | std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> > |
|
52 | std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> > | |
53 | m_VariableToProviderMap; |
|
53 | m_VariableToProviderMap; | |
54 | }; |
|
54 | }; | |
55 |
|
55 | |||
56 | VariableController::VariableController(QObject *parent) |
|
56 | VariableController::VariableController(QObject *parent) | |
57 | : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)} |
|
57 | : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)} | |
58 | { |
|
58 | { | |
59 | qCDebug(LOG_VariableController()) << tr("VariableController construction") |
|
59 | qCDebug(LOG_VariableController()) << tr("VariableController construction") | |
60 | << QThread::currentThread(); |
|
60 | << QThread::currentThread(); | |
61 | } |
|
61 | } | |
62 |
|
62 | |||
63 | VariableController::~VariableController() |
|
63 | VariableController::~VariableController() | |
64 | { |
|
64 | { | |
65 | qCDebug(LOG_VariableController()) << tr("VariableController destruction") |
|
65 | qCDebug(LOG_VariableController()) << tr("VariableController destruction") | |
66 | << QThread::currentThread(); |
|
66 | << QThread::currentThread(); | |
67 | this->waitForFinish(); |
|
67 | this->waitForFinish(); | |
68 | } |
|
68 | } | |
69 |
|
69 | |||
70 | VariableModel *VariableController::variableModel() noexcept |
|
70 | VariableModel *VariableController::variableModel() noexcept | |
71 | { |
|
71 | { | |
72 | return impl->m_VariableModel; |
|
72 | return impl->m_VariableModel; | |
73 | } |
|
73 | } | |
74 |
|
74 | |||
75 | QItemSelectionModel *VariableController::variableSelectionModel() noexcept |
|
75 | QItemSelectionModel *VariableController::variableSelectionModel() noexcept | |
76 | { |
|
76 | { | |
77 | return impl->m_VariableSelectionModel; |
|
77 | return impl->m_VariableSelectionModel; | |
78 | } |
|
78 | } | |
79 |
|
79 | |||
80 | void VariableController::setTimeController(TimeController *timeController) noexcept |
|
80 | void VariableController::setTimeController(TimeController *timeController) noexcept | |
81 | { |
|
81 | { | |
82 | impl->m_TimeController = timeController; |
|
82 | impl->m_TimeController = timeController; | |
83 | } |
|
83 | } | |
84 |
|
84 | |||
85 | void VariableController::deleteVariable(std::shared_ptr<Variable> variable) noexcept |
|
85 | void VariableController::deleteVariable(std::shared_ptr<Variable> variable) noexcept | |
86 | { |
|
86 | { | |
87 | if (!variable) { |
|
87 | if (!variable) { | |
88 | qCCritical(LOG_VariableController()) << "Can't delete variable: variable is null"; |
|
88 | qCCritical(LOG_VariableController()) << "Can't delete variable: variable is null"; | |
89 | return; |
|
89 | return; | |
90 | } |
|
90 | } | |
91 |
|
91 | |||
92 | // Spreads in SciQlop that the variable will be deleted, so that potential receivers can |
|
92 | // Spreads in SciQlop that the variable will be deleted, so that potential receivers can | |
93 | // make some treatments before the deletion |
|
93 | // make some treatments before the deletion | |
94 | emit variableAboutToBeDeleted(variable); |
|
94 | emit variableAboutToBeDeleted(variable); | |
95 |
|
95 | |||
96 | // Deletes provider |
|
96 | // Deletes provider | |
97 | auto nbProvidersDeleted = impl->m_VariableToProviderMap.erase(variable); |
|
97 | auto nbProvidersDeleted = impl->m_VariableToProviderMap.erase(variable); | |
98 | qCDebug(LOG_VariableController()) |
|
98 | qCDebug(LOG_VariableController()) | |
99 | << tr("Number of providers deleted for variable %1: %2") |
|
99 | << tr("Number of providers deleted for variable %1: %2") | |
100 | .arg(variable->name(), QString::number(nbProvidersDeleted)); |
|
100 | .arg(variable->name(), QString::number(nbProvidersDeleted)); | |
101 |
|
101 | |||
102 | // Clears cache |
|
102 | // Clears cache | |
103 | impl->m_VariableCacheController->clear(variable); |
|
103 | impl->m_VariableCacheController->clear(variable); | |
104 |
|
104 | |||
105 | // Deletes from model |
|
105 | // Deletes from model | |
106 | impl->m_VariableModel->deleteVariable(variable); |
|
106 | impl->m_VariableModel->deleteVariable(variable); | |
107 | } |
|
107 | } | |
108 |
|
108 | |||
109 | void VariableController::deleteVariables( |
|
109 | void VariableController::deleteVariables( | |
110 | const QVector<std::shared_ptr<Variable> > &variables) noexcept |
|
110 | const QVector<std::shared_ptr<Variable> > &variables) noexcept | |
111 | { |
|
111 | { | |
112 | for (auto variable : qAsConst(variables)) { |
|
112 | for (auto variable : qAsConst(variables)) { | |
113 | deleteVariable(variable); |
|
113 | deleteVariable(variable); | |
114 | } |
|
114 | } | |
115 | } |
|
115 | } | |
116 |
|
116 | |||
117 | void VariableController::createVariable(const QString &name, |
|
117 | void VariableController::createVariable(const QString &name, | |
118 | std::shared_ptr<IDataProvider> provider) noexcept |
|
118 | std::shared_ptr<IDataProvider> provider) noexcept | |
119 | { |
|
119 | { | |
120 |
|
120 | |||
121 | if (!impl->m_TimeController) { |
|
121 | if (!impl->m_TimeController) { | |
122 | qCCritical(LOG_VariableController()) |
|
122 | qCCritical(LOG_VariableController()) | |
123 | << tr("Impossible to create variable: The time controller is null"); |
|
123 | << tr("Impossible to create variable: The time controller is null"); | |
124 | return; |
|
124 | return; | |
125 | } |
|
125 | } | |
126 |
|
126 | |||
127 |
|
127 | |||
128 | /// @todo : for the moment : |
|
128 | /// @todo : for the moment : | |
129 | /// - the provider is only used to retrieve data from the variable for its initialization, but |
|
129 | /// - the provider is only used to retrieve data from the variable for its initialization, but | |
130 | /// it will be retained later |
|
130 | /// it will be retained later | |
131 | /// - default data are generated for the variable, without taking into account the timerange set |
|
131 | /// - default data are generated for the variable, without taking into account the timerange set | |
132 | /// in sciqlop |
|
132 | /// in sciqlop | |
133 | auto dateTime = impl->m_TimeController->dateTime(); |
|
133 | auto dateTime = impl->m_TimeController->dateTime(); | |
134 | if (auto newVariable = impl->m_VariableModel->createVariable(name, dateTime)) { |
|
134 | if (auto newVariable = impl->m_VariableModel->createVariable(name, dateTime)) { | |
135 |
|
135 | |||
136 | // store the provider |
|
136 | // store the provider | |
137 | impl->m_VariableToProviderMap[newVariable] = provider; |
|
137 | impl->m_VariableToProviderMap[newVariable] = provider; | |
138 |
|
138 | |||
139 | auto addDateTimeAcquired = [ this, varW = std::weak_ptr<Variable>{newVariable} ]( |
|
139 | auto addDateTimeAcquired = [ this, varW = std::weak_ptr<Variable>{newVariable} ]( | |
140 | auto dataSeriesAcquired, auto dateTimeToPutInCache) |
|
140 | auto dataSeriesAcquired, auto dateTimeToPutInCache) | |
141 | { |
|
141 | { | |
142 | if (auto variable = varW.lock()) { |
|
142 | if (auto variable = varW.lock()) { | |
143 | impl->m_VariableCacheController->addDateTime(variable, dateTimeToPutInCache); |
|
143 | impl->m_VariableCacheController->addDateTime(variable, dateTimeToPutInCache); | |
144 | variable->setDataSeries(dataSeriesAcquired); |
|
144 | variable->setDataSeries(dataSeriesAcquired); | |
145 | } |
|
145 | } | |
146 | }; |
|
146 | }; | |
147 |
|
147 | |||
148 | connect(provider.get(), &IDataProvider::dataProvided, addDateTimeAcquired); |
|
148 | connect(provider.get(), &IDataProvider::dataProvided, addDateTimeAcquired); | |
149 | this->onRequestDataLoading(newVariable, dateTime); |
|
149 | this->onRequestDataLoading(newVariable, dateTime); | |
150 | } |
|
150 | } | |
151 | } |
|
151 | } | |
152 |
|
152 | |||
153 | void VariableController::onDateTimeOnSelection(const SqpDateTime &dateTime) |
|
153 | void VariableController::onDateTimeOnSelection(const SqpDateTime &dateTime) | |
154 | { |
|
154 | { | |
|
155 | qCDebug(LOG_VariableController()) << "VariableController::onDateTimeOnSelection" | |||
|
156 | << QThread::currentThread()->objectName(); | |||
155 | auto selectedRows = impl->m_VariableSelectionModel->selectedRows(); |
|
157 | auto selectedRows = impl->m_VariableSelectionModel->selectedRows(); | |
156 |
|
158 | |||
157 | for (const auto &selectedRow : qAsConst(selectedRows)) { |
|
159 | for (const auto &selectedRow : qAsConst(selectedRows)) { | |
158 | if (auto selectedVariable = impl->m_VariableModel->variable(selectedRow.row())) { |
|
160 | if (auto selectedVariable = impl->m_VariableModel->variable(selectedRow.row())) { | |
159 | selectedVariable->setDateTime(dateTime); |
|
161 | selectedVariable->setDateTime(dateTime); | |
160 | this->onRequestDataLoading(selectedVariable, dateTime); |
|
162 | this->onRequestDataLoading(selectedVariable, dateTime); | |
161 | } |
|
163 | } | |
162 | } |
|
164 | } | |
163 | } |
|
165 | } | |
164 |
|
166 | |||
165 |
|
167 | |||
166 | void VariableController::onRequestDataLoading(std::shared_ptr<Variable> variable, |
|
168 | void VariableController::onRequestDataLoading(std::shared_ptr<Variable> variable, | |
167 | const SqpDateTime &dateTime) |
|
169 | const SqpDateTime &dateTime) | |
168 | { |
|
170 | { | |
|
171 | qCDebug(LOG_VariableController()) << "VariableController::onRequestDataLoading" | |||
|
172 | << QThread::currentThread()->objectName(); | |||
169 | // we want to load data of the variable for the dateTime. |
|
173 | // we want to load data of the variable for the dateTime. | |
170 | // First we check if the cache contains some of them. |
|
174 | // First we check if the cache contains some of them. | |
171 | // For the other, we ask the provider to give them. |
|
175 | // For the other, we ask the provider to give them. | |
172 | if (variable) { |
|
176 | if (variable) { | |
173 |
|
177 | |||
174 | auto dateTimeListNotInCache |
|
178 | auto dateTimeListNotInCache | |
175 | = impl->m_VariableCacheController->provideNotInCacheDateTimeList(variable, dateTime); |
|
179 | = impl->m_VariableCacheController->provideNotInCacheDateTimeList(variable, dateTime); | |
176 |
|
180 | |||
177 | if (!dateTimeListNotInCache.empty()) { |
|
181 | if (!dateTimeListNotInCache.empty()) { | |
178 | // Ask the provider for each data on the dateTimeListNotInCache |
|
182 | // Ask the provider for each data on the dateTimeListNotInCache | |
179 | impl->m_VariableToProviderMap.at(variable)->requestDataLoading( |
|
183 | impl->m_VariableToProviderMap.at(variable)->requestDataLoading( | |
180 | std::move(dateTimeListNotInCache)); |
|
184 | std::move(dateTimeListNotInCache)); | |
181 | } |
|
185 | } | |
182 | else { |
|
186 | else { | |
183 | emit variable->updated(); |
|
187 | emit variable->updated(); | |
184 | } |
|
188 | } | |
185 | } |
|
189 | } | |
186 | else { |
|
190 | else { | |
187 | qCCritical(LOG_VariableController()) << tr("Impossible to load data of a variable null"); |
|
191 | qCCritical(LOG_VariableController()) << tr("Impossible to load data of a variable null"); | |
188 | } |
|
192 | } | |
189 | } |
|
193 | } | |
190 |
|
194 | |||
191 |
|
195 | |||
192 | void VariableController::initialize() |
|
196 | void VariableController::initialize() | |
193 | { |
|
197 | { | |
194 | qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread(); |
|
198 | qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread(); | |
195 | impl->m_WorkingMutex.lock(); |
|
199 | impl->m_WorkingMutex.lock(); | |
196 | qCDebug(LOG_VariableController()) << tr("VariableController init END"); |
|
200 | qCDebug(LOG_VariableController()) << tr("VariableController init END"); | |
197 | } |
|
201 | } | |
198 |
|
202 | |||
199 | void VariableController::finalize() |
|
203 | void VariableController::finalize() | |
200 | { |
|
204 | { | |
201 | impl->m_WorkingMutex.unlock(); |
|
205 | impl->m_WorkingMutex.unlock(); | |
202 | } |
|
206 | } | |
203 |
|
207 | |||
204 | void VariableController::waitForFinish() |
|
208 | void VariableController::waitForFinish() | |
205 | { |
|
209 | { | |
206 | QMutexLocker locker{&impl->m_WorkingMutex}; |
|
210 | QMutexLocker locker{&impl->m_WorkingMutex}; | |
207 | } |
|
211 | } |
@@ -1,119 +1,124 | |||||
1 | #include "SqpApplication.h" |
|
1 | #include "SqpApplication.h" | |
2 |
|
2 | |||
3 | #include <Data/IDataProvider.h> |
|
3 | #include <Data/IDataProvider.h> | |
4 | #include <DataSource/DataSourceController.h> |
|
4 | #include <DataSource/DataSourceController.h> | |
5 | #include <QThread> |
|
5 | #include <QThread> | |
6 | #include <Time/TimeController.h> |
|
6 | #include <Time/TimeController.h> | |
7 | #include <Variable/Variable.h> |
|
7 | #include <Variable/Variable.h> | |
8 | #include <Variable/VariableController.h> |
|
8 | #include <Variable/VariableController.h> | |
9 | #include <Visualization/VisualizationController.h> |
|
9 | #include <Visualization/VisualizationController.h> | |
10 |
|
10 | |||
11 | Q_LOGGING_CATEGORY(LOG_SqpApplication, "SqpApplication") |
|
11 | Q_LOGGING_CATEGORY(LOG_SqpApplication, "SqpApplication") | |
12 |
|
12 | |||
13 | class SqpApplication::SqpApplicationPrivate { |
|
13 | class SqpApplication::SqpApplicationPrivate { | |
14 | public: |
|
14 | public: | |
15 | SqpApplicationPrivate() |
|
15 | SqpApplicationPrivate() | |
16 | : m_DataSourceController{std::make_unique<DataSourceController>()}, |
|
16 | : m_DataSourceController{std::make_unique<DataSourceController>()}, | |
17 | m_TimeController{std::make_unique<TimeController>()}, |
|
17 | m_TimeController{std::make_unique<TimeController>()}, | |
18 | m_VariableController{std::make_unique<VariableController>()}, |
|
18 | m_VariableController{std::make_unique<VariableController>()}, | |
19 | m_VisualizationController{std::make_unique<VisualizationController>()} |
|
19 | m_VisualizationController{std::make_unique<VisualizationController>()} | |
20 | { |
|
20 | { | |
|
21 | QThread::currentThread()->setObjectName("MainThread"); | |||
|
22 | m_DataSourceController->moveToThread(&m_DataSourceControllerThread); | |||
|
23 | m_DataSourceControllerThread.setObjectName("DataSourceControllerThread"); | |||
|
24 | m_VariableController->moveToThread(&m_VariableControllerThread); | |||
|
25 | m_VariableControllerThread.setObjectName("VariableControllerThread"); | |||
|
26 | m_VisualizationController->moveToThread(&m_VisualizationControllerThread); | |||
|
27 | m_VisualizationControllerThread.setObjectName("VisualizationControllerThread"); | |||
|
28 | ||||
21 | // /////////////////////////////// // |
|
29 | // /////////////////////////////// // | |
22 | // Connections between controllers // |
|
30 | // Connections between controllers // | |
23 | // /////////////////////////////// // |
|
31 | // /////////////////////////////// // | |
24 |
|
32 | |||
25 | // VariableController <-> DataSourceController |
|
33 | // VariableController <-> DataSourceController | |
26 | connect(m_DataSourceController.get(), |
|
34 | connect(m_DataSourceController.get(), | |
27 | SIGNAL(variableCreationRequested(const QString &, std::shared_ptr<IDataProvider>)), |
|
35 | SIGNAL(variableCreationRequested(const QString &, std::shared_ptr<IDataProvider>)), | |
28 | m_VariableController.get(), |
|
36 | m_VariableController.get(), | |
29 | SLOT(createVariable(const QString &, std::shared_ptr<IDataProvider>))); |
|
37 | SLOT(createVariable(const QString &, std::shared_ptr<IDataProvider>))); | |
30 |
|
38 | |||
31 | // VariableController <-> VisualizationController |
|
39 | // VariableController <-> VisualizationController | |
32 | connect(m_VariableController.get(), |
|
40 | connect(m_VariableController.get(), | |
33 | SIGNAL(variableAboutToBeDeleted(std::shared_ptr<Variable>)), |
|
41 | SIGNAL(variableAboutToBeDeleted(std::shared_ptr<Variable>)), | |
34 | m_VisualizationController.get(), |
|
42 | m_VisualizationController.get(), | |
35 | SIGNAL(variableAboutToBeDeleted(std::shared_ptr<Variable>)), Qt::DirectConnection); |
|
43 | SIGNAL(variableAboutToBeDeleted(std::shared_ptr<Variable>)), Qt::DirectConnection); | |
36 |
|
44 | |||
37 | m_DataSourceController->moveToThread(&m_DataSourceControllerThread); |
|
|||
38 | m_VariableController->moveToThread(&m_VariableControllerThread); |
|
|||
39 | m_VisualizationController->moveToThread(&m_VisualizationControllerThread); |
|
|||
40 |
|
45 | |||
41 | // Additionnal init |
|
46 | // Additionnal init | |
42 | m_VariableController->setTimeController(m_TimeController.get()); |
|
47 | m_VariableController->setTimeController(m_TimeController.get()); | |
43 | } |
|
48 | } | |
44 |
|
49 | |||
45 | virtual ~SqpApplicationPrivate() |
|
50 | virtual ~SqpApplicationPrivate() | |
46 | { |
|
51 | { | |
47 | qCInfo(LOG_SqpApplication()) << tr("SqpApplicationPrivate destruction"); |
|
52 | qCInfo(LOG_SqpApplication()) << tr("SqpApplicationPrivate destruction"); | |
48 | m_DataSourceControllerThread.quit(); |
|
53 | m_DataSourceControllerThread.quit(); | |
49 | m_DataSourceControllerThread.wait(); |
|
54 | m_DataSourceControllerThread.wait(); | |
50 |
|
55 | |||
51 | m_VariableControllerThread.quit(); |
|
56 | m_VariableControllerThread.quit(); | |
52 | m_VariableControllerThread.wait(); |
|
57 | m_VariableControllerThread.wait(); | |
53 |
|
58 | |||
54 | m_VisualizationControllerThread.quit(); |
|
59 | m_VisualizationControllerThread.quit(); | |
55 | m_VisualizationControllerThread.wait(); |
|
60 | m_VisualizationControllerThread.wait(); | |
56 | } |
|
61 | } | |
57 |
|
62 | |||
58 | std::unique_ptr<DataSourceController> m_DataSourceController; |
|
63 | std::unique_ptr<DataSourceController> m_DataSourceController; | |
59 | std::unique_ptr<VariableController> m_VariableController; |
|
64 | std::unique_ptr<VariableController> m_VariableController; | |
60 | std::unique_ptr<TimeController> m_TimeController; |
|
65 | std::unique_ptr<TimeController> m_TimeController; | |
61 | std::unique_ptr<VisualizationController> m_VisualizationController; |
|
66 | std::unique_ptr<VisualizationController> m_VisualizationController; | |
62 | QThread m_DataSourceControllerThread; |
|
67 | QThread m_DataSourceControllerThread; | |
63 | QThread m_VariableControllerThread; |
|
68 | QThread m_VariableControllerThread; | |
64 | QThread m_VisualizationControllerThread; |
|
69 | QThread m_VisualizationControllerThread; | |
65 | }; |
|
70 | }; | |
66 |
|
71 | |||
67 |
|
72 | |||
68 | SqpApplication::SqpApplication(int &argc, char **argv) |
|
73 | SqpApplication::SqpApplication(int &argc, char **argv) | |
69 | : QApplication{argc, argv}, impl{spimpl::make_unique_impl<SqpApplicationPrivate>()} |
|
74 | : QApplication{argc, argv}, impl{spimpl::make_unique_impl<SqpApplicationPrivate>()} | |
70 | { |
|
75 | { | |
71 | qCInfo(LOG_SqpApplication()) << tr("SqpApplication construction"); |
|
76 | qCInfo(LOG_SqpApplication()) << tr("SqpApplication construction"); | |
72 |
|
77 | |||
73 | connect(&impl->m_DataSourceControllerThread, &QThread::started, |
|
78 | connect(&impl->m_DataSourceControllerThread, &QThread::started, | |
74 | impl->m_DataSourceController.get(), &DataSourceController::initialize); |
|
79 | impl->m_DataSourceController.get(), &DataSourceController::initialize); | |
75 | connect(&impl->m_DataSourceControllerThread, &QThread::finished, |
|
80 | connect(&impl->m_DataSourceControllerThread, &QThread::finished, | |
76 | impl->m_DataSourceController.get(), &DataSourceController::finalize); |
|
81 | impl->m_DataSourceController.get(), &DataSourceController::finalize); | |
77 |
|
82 | |||
78 | connect(&impl->m_VariableControllerThread, &QThread::started, impl->m_VariableController.get(), |
|
83 | connect(&impl->m_VariableControllerThread, &QThread::started, impl->m_VariableController.get(), | |
79 | &VariableController::initialize); |
|
84 | &VariableController::initialize); | |
80 | connect(&impl->m_VariableControllerThread, &QThread::finished, impl->m_VariableController.get(), |
|
85 | connect(&impl->m_VariableControllerThread, &QThread::finished, impl->m_VariableController.get(), | |
81 | &VariableController::finalize); |
|
86 | &VariableController::finalize); | |
82 |
|
87 | |||
83 | connect(&impl->m_VisualizationControllerThread, &QThread::started, |
|
88 | connect(&impl->m_VisualizationControllerThread, &QThread::started, | |
84 | impl->m_VisualizationController.get(), &VisualizationController::initialize); |
|
89 | impl->m_VisualizationController.get(), &VisualizationController::initialize); | |
85 | connect(&impl->m_VisualizationControllerThread, &QThread::finished, |
|
90 | connect(&impl->m_VisualizationControllerThread, &QThread::finished, | |
86 | impl->m_VisualizationController.get(), &VisualizationController::finalize); |
|
91 | impl->m_VisualizationController.get(), &VisualizationController::finalize); | |
87 |
|
92 | |||
88 | impl->m_DataSourceControllerThread.start(); |
|
93 | impl->m_DataSourceControllerThread.start(); | |
89 | impl->m_VariableControllerThread.start(); |
|
94 | impl->m_VariableControllerThread.start(); | |
90 | impl->m_VisualizationControllerThread.start(); |
|
95 | impl->m_VisualizationControllerThread.start(); | |
91 | } |
|
96 | } | |
92 |
|
97 | |||
93 | SqpApplication::~SqpApplication() |
|
98 | SqpApplication::~SqpApplication() | |
94 | { |
|
99 | { | |
95 | } |
|
100 | } | |
96 |
|
101 | |||
97 | void SqpApplication::initialize() |
|
102 | void SqpApplication::initialize() | |
98 | { |
|
103 | { | |
99 | } |
|
104 | } | |
100 |
|
105 | |||
101 | DataSourceController &SqpApplication::dataSourceController() noexcept |
|
106 | DataSourceController &SqpApplication::dataSourceController() noexcept | |
102 | { |
|
107 | { | |
103 | return *impl->m_DataSourceController; |
|
108 | return *impl->m_DataSourceController; | |
104 | } |
|
109 | } | |
105 |
|
110 | |||
106 | TimeController &SqpApplication::timeController() noexcept |
|
111 | TimeController &SqpApplication::timeController() noexcept | |
107 | { |
|
112 | { | |
108 | return *impl->m_TimeController; |
|
113 | return *impl->m_TimeController; | |
109 | } |
|
114 | } | |
110 |
|
115 | |||
111 | VariableController &SqpApplication::variableController() noexcept |
|
116 | VariableController &SqpApplication::variableController() noexcept | |
112 | { |
|
117 | { | |
113 | return *impl->m_VariableController; |
|
118 | return *impl->m_VariableController; | |
114 | } |
|
119 | } | |
115 |
|
120 | |||
116 | VisualizationController &SqpApplication::visualizationController() noexcept |
|
121 | VisualizationController &SqpApplication::visualizationController() noexcept | |
117 | { |
|
122 | { | |
118 | return *impl->m_VisualizationController; |
|
123 | return *impl->m_VisualizationController; | |
119 | } |
|
124 | } |
@@ -1,155 +1,160 | |||||
1 | #include "Visualization/VisualizationGraphHelper.h" |
|
1 | #include "Visualization/VisualizationGraphHelper.h" | |
2 | #include "Visualization/qcustomplot.h" |
|
2 | #include "Visualization/qcustomplot.h" | |
3 |
|
3 | |||
4 | #include <Data/ScalarSeries.h> |
|
4 | #include <Data/ScalarSeries.h> | |
5 |
|
5 | |||
6 | #include <Variable/Variable.h> |
|
6 | #include <Variable/Variable.h> | |
7 |
|
7 | |||
8 | #include <QElapsedTimer> |
|
|||
9 |
|
||||
10 | Q_LOGGING_CATEGORY(LOG_VisualizationGraphHelper, "VisualizationGraphHelper") |
|
8 | Q_LOGGING_CATEGORY(LOG_VisualizationGraphHelper, "VisualizationGraphHelper") | |
11 |
|
9 | |||
12 | namespace { |
|
10 | namespace { | |
13 |
|
11 | |||
|
12 | class SqpDataContainer : public QCPGraphDataContainer { | |||
|
13 | public: | |||
|
14 | void appendGraphDataUnsorted(const QCPGraphData &data) { mData.append(data); } | |||
|
15 | }; | |||
|
16 | ||||
|
17 | ||||
14 | /// Format for datetimes on a axis |
|
18 | /// Format for datetimes on a axis | |
15 | const auto DATETIME_TICKER_FORMAT = QStringLiteral("yyyy/MM/dd \nhh:mm:ss"); |
|
19 | const auto DATETIME_TICKER_FORMAT = QStringLiteral("yyyy/MM/dd \nhh:mm:ss"); | |
16 |
|
20 | |||
17 | /// Generates the appropriate ticker for an axis, depending on whether the axis displays time or |
|
21 | /// Generates the appropriate ticker for an axis, depending on whether the axis displays time or | |
18 | /// non-time data |
|
22 | /// non-time data | |
19 | QSharedPointer<QCPAxisTicker> axisTicker(bool isTimeAxis) |
|
23 | QSharedPointer<QCPAxisTicker> axisTicker(bool isTimeAxis) | |
20 | { |
|
24 | { | |
21 | if (isTimeAxis) { |
|
25 | if (isTimeAxis) { | |
22 | auto dateTicker = QSharedPointer<QCPAxisTickerDateTime>::create(); |
|
26 | auto dateTicker = QSharedPointer<QCPAxisTickerDateTime>::create(); | |
23 | dateTicker->setDateTimeFormat(DATETIME_TICKER_FORMAT); |
|
27 | dateTicker->setDateTimeFormat(DATETIME_TICKER_FORMAT); | |
24 |
|
28 | |||
25 | return dateTicker; |
|
29 | return dateTicker; | |
26 | } |
|
30 | } | |
27 | else { |
|
31 | else { | |
28 | // default ticker |
|
32 | // default ticker | |
29 | return QSharedPointer<QCPAxisTicker>::create(); |
|
33 | return QSharedPointer<QCPAxisTicker>::create(); | |
30 | } |
|
34 | } | |
31 | } |
|
35 | } | |
32 |
|
36 | |||
33 | void updateScalarData(QCPAbstractPlottable *component, ScalarSeries &scalarSeries, |
|
37 | void updateScalarData(QCPAbstractPlottable *component, ScalarSeries &scalarSeries, | |
34 | const SqpDateTime &dateTime) |
|
38 | const SqpDateTime &dateTime) | |
35 | { |
|
39 | { | |
36 | QElapsedTimer timer; |
|
40 | qCDebug(LOG_VisualizationGraphHelper()) << "TORM: updateScalarData" | |
37 | timer.start(); |
|
41 | << QThread::currentThread()->objectName(); | |
38 | if (auto qcpGraph = dynamic_cast<QCPGraph *>(component)) { |
|
42 | if (auto qcpGraph = dynamic_cast<QCPGraph *>(component)) { | |
39 | // Clean the graph |
|
43 | // Clean the graph | |
40 | // NAIVE approch |
|
44 | // NAIVE approch | |
41 | const auto &xData = scalarSeries.xAxisData()->data(); |
|
45 | scalarSeries.lockRead(); | |
42 | const auto &valuesData = scalarSeries.valuesData()->data(); |
|
46 | { | |
|
47 | const auto xData = scalarSeries.xAxisData()->data(); | |||
|
48 | const auto valuesData = scalarSeries.valuesData()->data(); | |||
43 | const auto count = xData.count(); |
|
49 | const auto count = xData.count(); | |
44 |
qCInfo(LOG_VisualizationGraphHelper()) << "TORM: Current points in cache" |
|
50 | qCInfo(LOG_VisualizationGraphHelper()) << "TORM: Current points in cache" | |
45 | auto xValue = QVector<double>(count); |
|
51 | << xData.count(); | |
46 | auto vValue = QVector<double>(count); |
|
52 | ||
|
53 | auto dataContainer = qcpGraph->data(); | |||
|
54 | dataContainer->clear(); | |||
|
55 | auto sqpDataContainer = QSharedPointer<SqpDataContainer>::create(); | |||
|
56 | qcpGraph->setData(sqpDataContainer); | |||
47 |
|
57 | |||
48 | int n = 0; |
|
|||
49 | for (auto i = 0; i < count; ++i) { |
|
58 | for (auto i = 0; i < count; ++i) { | |
50 | const auto x = xData[i]; |
|
59 | const auto x = xData[i]; | |
51 | if (x >= dateTime.m_TStart && x <= dateTime.m_TEnd) { |
|
60 | if (x >= dateTime.m_TStart && x <= dateTime.m_TEnd) { | |
52 | xValue[n] = x; |
|
61 | sqpDataContainer->appendGraphDataUnsorted(QCPGraphData(x, valuesData[i])); | |
53 | vValue[n] = valuesData[i]; |
|
|||
54 | ++n; |
|
|||
55 | } |
|
62 | } | |
56 | } |
|
63 | } | |
57 |
|
64 | sqpDataContainer->sort(); | ||
58 | xValue.resize(n); |
|
|||
59 | vValue.resize(n); |
|
|||
60 |
|
||||
61 | qCInfo(LOG_VisualizationGraphHelper()) << "TORM: Current points displayed" |
|
65 | qCInfo(LOG_VisualizationGraphHelper()) << "TORM: Current points displayed" | |
62 |
<< |
|
66 | << sqpDataContainer->size(); | |
|
67 | } | |||
|
68 | scalarSeries.unlock(); | |||
63 |
|
69 | |||
64 | qcpGraph->setData(xValue, vValue); |
|
|||
65 |
|
70 | |||
66 | // Display all data |
|
71 | // Display all data | |
67 | component->rescaleAxes(); |
|
72 | component->rescaleAxes(); | |
68 | component->parentPlot()->replot(); |
|
73 | component->parentPlot()->replot(); | |
69 | } |
|
74 | } | |
70 | else { |
|
75 | else { | |
71 | /// @todo DEBUG |
|
76 | /// @todo DEBUG | |
72 | } |
|
77 | } | |
73 | } |
|
78 | } | |
74 |
|
79 | |||
75 | QCPAbstractPlottable *createScalarSeriesComponent(ScalarSeries &scalarSeries, QCustomPlot &plot, |
|
80 | QCPAbstractPlottable *createScalarSeriesComponent(ScalarSeries &scalarSeries, QCustomPlot &plot, | |
76 | const SqpDateTime &dateTime) |
|
81 | const SqpDateTime &dateTime) | |
77 | { |
|
82 | { | |
78 | auto component = plot.addGraph(); |
|
83 | auto component = plot.addGraph(); | |
79 |
|
84 | |||
80 | if (component) { |
|
85 | if (component) { | |
81 | // // Graph data |
|
86 | // // Graph data | |
82 | component->setData(scalarSeries.xAxisData()->data(), scalarSeries.valuesData()->data(), |
|
87 | component->setData(scalarSeries.xAxisData()->data(), scalarSeries.valuesData()->data(), | |
83 | true); |
|
88 | true); | |
84 |
|
89 | |||
85 | updateScalarData(component, scalarSeries, dateTime); |
|
90 | updateScalarData(component, scalarSeries, dateTime); | |
86 |
|
91 | |||
87 | // Axes properties |
|
92 | // Axes properties | |
88 | /// @todo : for the moment, no control is performed on the axes: the units and the tickers |
|
93 | /// @todo : for the moment, no control is performed on the axes: the units and the tickers | |
89 | /// are fixed for the default x-axis and y-axis of the plot, and according to the new graph |
|
94 | /// are fixed for the default x-axis and y-axis of the plot, and according to the new graph | |
90 |
|
95 | |||
91 | auto setAxisProperties = [](auto axis, const auto &unit) { |
|
96 | auto setAxisProperties = [](auto axis, const auto &unit) { | |
92 | // label (unit name) |
|
97 | // label (unit name) | |
93 | axis->setLabel(unit.m_Name); |
|
98 | axis->setLabel(unit.m_Name); | |
94 |
|
99 | |||
95 | // ticker (depending on the type of unit) |
|
100 | // ticker (depending on the type of unit) | |
96 | axis->setTicker(axisTicker(unit.m_TimeUnit)); |
|
101 | axis->setTicker(axisTicker(unit.m_TimeUnit)); | |
97 | }; |
|
102 | }; | |
98 | setAxisProperties(plot.xAxis, scalarSeries.xAxisUnit()); |
|
103 | setAxisProperties(plot.xAxis, scalarSeries.xAxisUnit()); | |
99 | setAxisProperties(plot.yAxis, scalarSeries.valuesUnit()); |
|
104 | setAxisProperties(plot.yAxis, scalarSeries.valuesUnit()); | |
100 |
|
105 | |||
101 | // Display all data |
|
106 | // Display all data | |
102 | component->rescaleAxes(); |
|
107 | component->rescaleAxes(); | |
103 | plot.replot(); |
|
108 | plot.replot(); | |
104 | } |
|
109 | } | |
105 | else { |
|
110 | else { | |
106 | qCDebug(LOG_VisualizationGraphHelper()) |
|
111 | qCDebug(LOG_VisualizationGraphHelper()) | |
107 | << QObject::tr("Can't create graph for the scalar series"); |
|
112 | << QObject::tr("Can't create graph for the scalar series"); | |
108 | } |
|
113 | } | |
109 |
|
114 | |||
110 | return component; |
|
115 | return component; | |
111 | } |
|
116 | } | |
112 |
|
117 | |||
113 | } // namespace |
|
118 | } // namespace | |
114 |
|
119 | |||
115 | QVector<QCPAbstractPlottable *> VisualizationGraphHelper::create(std::shared_ptr<Variable> variable, |
|
120 | QVector<QCPAbstractPlottable *> VisualizationGraphHelper::create(std::shared_ptr<Variable> variable, | |
116 | QCustomPlot &plot) noexcept |
|
121 | QCustomPlot &plot) noexcept | |
117 | { |
|
122 | { | |
118 | auto result = QVector<QCPAbstractPlottable *>{}; |
|
123 | auto result = QVector<QCPAbstractPlottable *>{}; | |
119 |
|
124 | |||
120 | if (variable) { |
|
125 | if (variable) { | |
121 | // Gets the data series of the variable to call the creation of the right components |
|
126 | // Gets the data series of the variable to call the creation of the right components | |
122 | // according to its type |
|
127 | // according to its type | |
123 | if (auto scalarSeries = dynamic_cast<ScalarSeries *>(variable->dataSeries())) { |
|
128 | if (auto scalarSeries = dynamic_cast<ScalarSeries *>(variable->dataSeries())) { | |
124 | result.append(createScalarSeriesComponent(*scalarSeries, plot, variable->dateTime())); |
|
129 | result.append(createScalarSeriesComponent(*scalarSeries, plot, variable->dateTime())); | |
125 | } |
|
130 | } | |
126 | else { |
|
131 | else { | |
127 | qCDebug(LOG_VisualizationGraphHelper()) |
|
132 | qCDebug(LOG_VisualizationGraphHelper()) | |
128 | << QObject::tr("Can't create graph plottables : unmanaged data series type"); |
|
133 | << QObject::tr("Can't create graph plottables : unmanaged data series type"); | |
129 | } |
|
134 | } | |
130 | } |
|
135 | } | |
131 | else { |
|
136 | else { | |
132 | qCDebug(LOG_VisualizationGraphHelper()) |
|
137 | qCDebug(LOG_VisualizationGraphHelper()) | |
133 | << QObject::tr("Can't create graph plottables : the variable is null"); |
|
138 | << QObject::tr("Can't create graph plottables : the variable is null"); | |
134 | } |
|
139 | } | |
135 |
|
140 | |||
136 | return result; |
|
141 | return result; | |
137 | } |
|
142 | } | |
138 |
|
143 | |||
139 | void VisualizationGraphHelper::updateData(QVector<QCPAbstractPlottable *> plotableVect, |
|
144 | void VisualizationGraphHelper::updateData(QVector<QCPAbstractPlottable *> plotableVect, | |
140 | IDataSeries *dataSeries, const SqpDateTime &dateTime) |
|
145 | IDataSeries *dataSeries, const SqpDateTime &dateTime) | |
141 | { |
|
146 | { | |
142 | if (auto scalarSeries = dynamic_cast<ScalarSeries *>(dataSeries)) { |
|
147 | if (auto scalarSeries = dynamic_cast<ScalarSeries *>(dataSeries)) { | |
143 | if (plotableVect.size() == 1) { |
|
148 | if (plotableVect.size() == 1) { | |
144 | updateScalarData(plotableVect.at(0), *scalarSeries, dateTime); |
|
149 | updateScalarData(plotableVect.at(0), *scalarSeries, dateTime); | |
145 | } |
|
150 | } | |
146 | else { |
|
151 | else { | |
147 | qCCritical(LOG_VisualizationGraphHelper()) << QObject::tr( |
|
152 | qCCritical(LOG_VisualizationGraphHelper()) << QObject::tr( | |
148 | "Can't update Data of a scalarSeries because there is not only one component " |
|
153 | "Can't update Data of a scalarSeries because there is not only one component " | |
149 | "associated"); |
|
154 | "associated"); | |
150 | } |
|
155 | } | |
151 | } |
|
156 | } | |
152 | else { |
|
157 | else { | |
153 | /// @todo DEBUG |
|
158 | /// @todo DEBUG | |
154 | } |
|
159 | } | |
155 | } |
|
160 | } |
@@ -1,285 +1,285 | |||||
1 | #include "Visualization/VisualizationGraphWidget.h" |
|
1 | #include "Visualization/VisualizationGraphWidget.h" | |
2 | #include "Visualization/IVisualizationWidgetVisitor.h" |
|
2 | #include "Visualization/IVisualizationWidgetVisitor.h" | |
3 | #include "Visualization/VisualizationGraphHelper.h" |
|
3 | #include "Visualization/VisualizationGraphHelper.h" | |
4 | #include "ui_VisualizationGraphWidget.h" |
|
4 | #include "ui_VisualizationGraphWidget.h" | |
5 |
|
5 | |||
6 | #include <Data/ArrayData.h> |
|
6 | #include <Data/ArrayData.h> | |
7 | #include <Data/IDataSeries.h> |
|
7 | #include <Data/IDataSeries.h> | |
8 | #include <SqpApplication.h> |
|
8 | #include <SqpApplication.h> | |
9 | #include <Variable/Variable.h> |
|
9 | #include <Variable/Variable.h> | |
10 | #include <Variable/VariableController.h> |
|
10 | #include <Variable/VariableController.h> | |
11 |
|
11 | |||
12 | #include <unordered_map> |
|
12 | #include <unordered_map> | |
13 |
|
13 | |||
14 | Q_LOGGING_CATEGORY(LOG_VisualizationGraphWidget, "VisualizationGraphWidget") |
|
14 | Q_LOGGING_CATEGORY(LOG_VisualizationGraphWidget, "VisualizationGraphWidget") | |
15 |
|
15 | |||
16 | namespace { |
|
16 | namespace { | |
17 |
|
17 | |||
18 | /// Key pressed to enable zoom on horizontal axis |
|
18 | /// Key pressed to enable zoom on horizontal axis | |
19 | const auto HORIZONTAL_ZOOM_MODIFIER = Qt::NoModifier; |
|
19 | const auto HORIZONTAL_ZOOM_MODIFIER = Qt::NoModifier; | |
20 |
|
20 | |||
21 | /// Key pressed to enable zoom on vertical axis |
|
21 | /// Key pressed to enable zoom on vertical axis | |
22 | const auto VERTICAL_ZOOM_MODIFIER = Qt::ControlModifier; |
|
22 | const auto VERTICAL_ZOOM_MODIFIER = Qt::ControlModifier; | |
23 |
|
23 | |||
24 | } // namespace |
|
24 | } // namespace | |
25 |
|
25 | |||
26 | struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate { |
|
26 | struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate { | |
27 |
|
27 | |||
28 | // 1 variable -> n qcpplot |
|
28 | // 1 variable -> n qcpplot | |
29 | std::multimap<std::shared_ptr<Variable>, QCPAbstractPlottable *> m_VariableToPlotMultiMap; |
|
29 | std::multimap<std::shared_ptr<Variable>, QCPAbstractPlottable *> m_VariableToPlotMultiMap; | |
30 | }; |
|
30 | }; | |
31 |
|
31 | |||
32 | VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget *parent) |
|
32 | VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget *parent) | |
33 | : QWidget{parent}, |
|
33 | : QWidget{parent}, | |
34 | ui{new Ui::VisualizationGraphWidget}, |
|
34 | ui{new Ui::VisualizationGraphWidget}, | |
35 | impl{spimpl::make_unique_impl<VisualizationGraphWidgetPrivate>()} |
|
35 | impl{spimpl::make_unique_impl<VisualizationGraphWidgetPrivate>()} | |
36 | { |
|
36 | { | |
37 | ui->setupUi(this); |
|
37 | ui->setupUi(this); | |
38 |
|
38 | |||
39 | ui->graphNameLabel->setText(name); |
|
39 | ui->graphNameLabel->setText(name); | |
40 |
|
40 | |||
41 | // 'Close' options : widget is deleted when closed |
|
41 | // 'Close' options : widget is deleted when closed | |
42 | setAttribute(Qt::WA_DeleteOnClose); |
|
42 | setAttribute(Qt::WA_DeleteOnClose); | |
43 | connect(ui->closeButton, &QToolButton::clicked, this, &VisualizationGraphWidget::close); |
|
43 | connect(ui->closeButton, &QToolButton::clicked, this, &VisualizationGraphWidget::close); | |
44 | ui->closeButton->setIcon(sqpApp->style()->standardIcon(QStyle::SP_TitleBarCloseButton)); |
|
44 | ui->closeButton->setIcon(sqpApp->style()->standardIcon(QStyle::SP_TitleBarCloseButton)); | |
45 |
|
45 | |||
46 | // Set qcpplot properties : |
|
46 | // Set qcpplot properties : | |
47 | // - Drag (on x-axis) and zoom are enabled |
|
47 | // - Drag (on x-axis) and zoom are enabled | |
48 | // - Mouse wheel on qcpplot is intercepted to determine the zoom orientation |
|
48 | // - Mouse wheel on qcpplot is intercepted to determine the zoom orientation | |
49 | ui->widget->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); |
|
49 | ui->widget->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); | |
50 | ui->widget->axisRect()->setRangeDrag(Qt::Horizontal); |
|
50 | ui->widget->axisRect()->setRangeDrag(Qt::Horizontal); | |
51 | connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel); |
|
51 | connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel); | |
52 | connect(ui->widget->xAxis, |
|
52 | connect(ui->widget->xAxis, | |
53 | static_cast<void (QCPAxis::*)(const QCPRange &)>(&QCPAxis::rangeChanged), this, |
|
53 | static_cast<void (QCPAxis::*)(const QCPRange &)>(&QCPAxis::rangeChanged), this, | |
54 | &VisualizationGraphWidget::onRangeChanged); |
|
54 | &VisualizationGraphWidget::onRangeChanged); | |
55 |
|
55 | |||
56 | // Activates menu when right clicking on the graph |
|
56 | // Activates menu when right clicking on the graph | |
57 | ui->widget->setContextMenuPolicy(Qt::CustomContextMenu); |
|
57 | ui->widget->setContextMenuPolicy(Qt::CustomContextMenu); | |
58 | connect(ui->widget, &QCustomPlot::customContextMenuRequested, this, |
|
58 | connect(ui->widget, &QCustomPlot::customContextMenuRequested, this, | |
59 | &VisualizationGraphWidget::onGraphMenuRequested); |
|
59 | &VisualizationGraphWidget::onGraphMenuRequested); | |
60 |
|
60 | |||
61 | connect(this, &VisualizationGraphWidget::requestDataLoading, &sqpApp->variableController(), |
|
61 | connect(this, &VisualizationGraphWidget::requestDataLoading, &sqpApp->variableController(), | |
62 | &VariableController::onRequestDataLoading); |
|
62 | &VariableController::onRequestDataLoading); | |
63 | } |
|
63 | } | |
64 |
|
64 | |||
65 |
|
65 | |||
66 | VisualizationGraphWidget::~VisualizationGraphWidget() |
|
66 | VisualizationGraphWidget::~VisualizationGraphWidget() | |
67 | { |
|
67 | { | |
68 | delete ui; |
|
68 | delete ui; | |
69 | } |
|
69 | } | |
70 |
|
70 | |||
71 | void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable) |
|
71 | void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable) | |
72 | { |
|
72 | { | |
73 | // Uses delegate to create the qcpplot components according to the variable |
|
73 | // Uses delegate to create the qcpplot components according to the variable | |
74 | auto createdPlottables = VisualizationGraphHelper::create(variable, *ui->widget); |
|
74 | auto createdPlottables = VisualizationGraphHelper::create(variable, *ui->widget); | |
75 |
|
75 | |||
76 | for (auto createdPlottable : qAsConst(createdPlottables)) { |
|
76 | for (auto createdPlottable : qAsConst(createdPlottables)) { | |
77 | impl->m_VariableToPlotMultiMap.insert({variable, createdPlottable}); |
|
77 | impl->m_VariableToPlotMultiMap.insert({variable, createdPlottable}); | |
78 | } |
|
78 | } | |
79 |
|
79 | |||
80 | connect(variable.get(), SIGNAL(updated()), this, SLOT(onDataCacheVariableUpdated())); |
|
80 | connect(variable.get(), SIGNAL(updated()), this, SLOT(onDataCacheVariableUpdated())); | |
81 | } |
|
81 | } | |
82 |
|
||||
83 | void VisualizationGraphWidget::addVariableUsingGraph(std::shared_ptr<Variable> variable) |
|
82 | void VisualizationGraphWidget::addVariableUsingGraph(std::shared_ptr<Variable> variable) | |
84 | { |
|
83 | { | |
85 |
|
84 | |||
86 | // when adding a variable, we need to set its time range to the current graph range |
|
85 | // when adding a variable, we need to set its time range to the current graph range | |
87 | auto grapheRange = ui->widget->xAxis->range(); |
|
86 | auto grapheRange = ui->widget->xAxis->range(); | |
88 | auto dateTime = SqpDateTime{grapheRange.lower, grapheRange.upper}; |
|
87 | auto dateTime = SqpDateTime{grapheRange.lower, grapheRange.upper}; | |
89 | variable->setDateTime(dateTime); |
|
88 | variable->setDateTime(dateTime); | |
90 |
|
89 | |||
91 | auto variableDateTimeWithTolerance = dateTime; |
|
90 | auto variableDateTimeWithTolerance = dateTime; | |
92 |
|
91 | |||
93 | // add 10% tolerance for each side |
|
92 | // add 10% tolerance for each side | |
94 | auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart); |
|
93 | auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart); | |
95 | variableDateTimeWithTolerance.m_TStart -= tolerance; |
|
94 | variableDateTimeWithTolerance.m_TStart -= tolerance; | |
96 | variableDateTimeWithTolerance.m_TEnd += tolerance; |
|
95 | variableDateTimeWithTolerance.m_TEnd += tolerance; | |
97 |
|
96 | |||
98 | // Uses delegate to create the qcpplot components according to the variable |
|
97 | // Uses delegate to create the qcpplot components according to the variable | |
99 | auto createdPlottables = VisualizationGraphHelper::create(variable, *ui->widget); |
|
98 | auto createdPlottables = VisualizationGraphHelper::create(variable, *ui->widget); | |
100 |
|
99 | |||
101 | for (auto createdPlottable : qAsConst(createdPlottables)) { |
|
100 | for (auto createdPlottable : qAsConst(createdPlottables)) { | |
102 | impl->m_VariableToPlotMultiMap.insert({variable, createdPlottable}); |
|
101 | impl->m_VariableToPlotMultiMap.insert({variable, createdPlottable}); | |
103 | } |
|
102 | } | |
104 |
|
103 | |||
105 | connect(variable.get(), SIGNAL(updated()), this, SLOT(onDataCacheVariableUpdated())); |
|
104 | connect(variable.get(), SIGNAL(updated()), this, SLOT(onDataCacheVariableUpdated())); | |
106 |
|
105 | |||
107 | // CHangement detected, we need to ask controller to request data loading |
|
106 | // CHangement detected, we need to ask controller to request data loading | |
108 | emit requestDataLoading(variable, variableDateTimeWithTolerance); |
|
107 | emit requestDataLoading(variable, variableDateTimeWithTolerance); | |
109 | } |
|
108 | } | |
110 |
|
109 | |||
111 | void VisualizationGraphWidget::removeVariable(std::shared_ptr<Variable> variable) noexcept |
|
110 | void VisualizationGraphWidget::removeVariable(std::shared_ptr<Variable> variable) noexcept | |
112 | { |
|
111 | { | |
113 | // Each component associated to the variable : |
|
112 | // Each component associated to the variable : | |
114 | // - is removed from qcpplot (which deletes it) |
|
113 | // - is removed from qcpplot (which deletes it) | |
115 | // - is no longer referenced in the map |
|
114 | // - is no longer referenced in the map | |
116 | auto componentsIt = impl->m_VariableToPlotMultiMap.equal_range(variable); |
|
115 | auto componentsIt = impl->m_VariableToPlotMultiMap.equal_range(variable); | |
117 | for (auto it = componentsIt.first; it != componentsIt.second;) { |
|
116 | for (auto it = componentsIt.first; it != componentsIt.second;) { | |
118 | ui->widget->removePlottable(it->second); |
|
117 | ui->widget->removePlottable(it->second); | |
119 | it = impl->m_VariableToPlotMultiMap.erase(it); |
|
118 | it = impl->m_VariableToPlotMultiMap.erase(it); | |
120 | } |
|
119 | } | |
121 |
|
120 | |||
122 | // Updates graph |
|
121 | // Updates graph | |
123 | ui->widget->replot(); |
|
122 | ui->widget->replot(); | |
124 | } |
|
123 | } | |
125 |
|
124 | |||
126 | void VisualizationGraphWidget::accept(IVisualizationWidgetVisitor *visitor) |
|
125 | void VisualizationGraphWidget::accept(IVisualizationWidgetVisitor *visitor) | |
127 | { |
|
126 | { | |
128 | if (visitor) { |
|
127 | if (visitor) { | |
129 | visitor->visit(this); |
|
128 | visitor->visit(this); | |
130 | } |
|
129 | } | |
131 | else { |
|
130 | else { | |
132 | qCCritical(LOG_VisualizationGraphWidget()) |
|
131 | qCCritical(LOG_VisualizationGraphWidget()) | |
133 | << tr("Can't visit widget : the visitor is null"); |
|
132 | << tr("Can't visit widget : the visitor is null"); | |
134 | } |
|
133 | } | |
135 | } |
|
134 | } | |
136 |
|
135 | |||
137 | bool VisualizationGraphWidget::canDrop(const Variable &variable) const |
|
136 | bool VisualizationGraphWidget::canDrop(const Variable &variable) const | |
138 | { |
|
137 | { | |
139 | /// @todo : for the moment, a graph can always accomodate a variable |
|
138 | /// @todo : for the moment, a graph can always accomodate a variable | |
140 | Q_UNUSED(variable); |
|
139 | Q_UNUSED(variable); | |
141 | return true; |
|
140 | return true; | |
142 | } |
|
141 | } | |
143 |
|
142 | |||
144 | bool VisualizationGraphWidget::contains(const Variable &variable) const |
|
143 | bool VisualizationGraphWidget::contains(const Variable &variable) const | |
145 | { |
|
144 | { | |
146 | // Finds the variable among the keys of the map |
|
145 | // Finds the variable among the keys of the map | |
147 | auto variablePtr = &variable; |
|
146 | auto variablePtr = &variable; | |
148 | auto findVariable |
|
147 | auto findVariable | |
149 | = [variablePtr](const auto &entry) { return variablePtr == entry.first.get(); }; |
|
148 | = [variablePtr](const auto &entry) { return variablePtr == entry.first.get(); }; | |
150 |
|
149 | |||
151 | auto end = impl->m_VariableToPlotMultiMap.cend(); |
|
150 | auto end = impl->m_VariableToPlotMultiMap.cend(); | |
152 | auto it = std::find_if(impl->m_VariableToPlotMultiMap.cbegin(), end, findVariable); |
|
151 | auto it = std::find_if(impl->m_VariableToPlotMultiMap.cbegin(), end, findVariable); | |
153 | return it != end; |
|
152 | return it != end; | |
154 | } |
|
153 | } | |
155 |
|
154 | |||
156 | QString VisualizationGraphWidget::name() const |
|
155 | QString VisualizationGraphWidget::name() const | |
157 | { |
|
156 | { | |
158 | return ui->graphNameLabel->text(); |
|
157 | return ui->graphNameLabel->text(); | |
159 | } |
|
158 | } | |
160 |
|
159 | |||
161 | void VisualizationGraphWidget::onGraphMenuRequested(const QPoint &pos) noexcept |
|
160 | void VisualizationGraphWidget::onGraphMenuRequested(const QPoint &pos) noexcept | |
162 | { |
|
161 | { | |
163 | QMenu graphMenu{}; |
|
162 | QMenu graphMenu{}; | |
164 |
|
163 | |||
165 | // Iterates on variables (unique keys) |
|
164 | // Iterates on variables (unique keys) | |
166 | for (auto it = impl->m_VariableToPlotMultiMap.cbegin(), |
|
165 | for (auto it = impl->m_VariableToPlotMultiMap.cbegin(), | |
167 | end = impl->m_VariableToPlotMultiMap.cend(); |
|
166 | end = impl->m_VariableToPlotMultiMap.cend(); | |
168 | it != end; it = impl->m_VariableToPlotMultiMap.upper_bound(it->first)) { |
|
167 | it != end; it = impl->m_VariableToPlotMultiMap.upper_bound(it->first)) { | |
169 | // 'Remove variable' action |
|
168 | // 'Remove variable' action | |
170 | graphMenu.addAction(tr("Remove variable %1").arg(it->first->name()), |
|
169 | graphMenu.addAction(tr("Remove variable %1").arg(it->first->name()), | |
171 | [ this, var = it->first ]() { removeVariable(var); }); |
|
170 | [ this, var = it->first ]() { removeVariable(var); }); | |
172 | } |
|
171 | } | |
173 |
|
172 | |||
174 | if (!graphMenu.isEmpty()) { |
|
173 | if (!graphMenu.isEmpty()) { | |
175 | graphMenu.exec(mapToGlobal(pos)); |
|
174 | graphMenu.exec(mapToGlobal(pos)); | |
176 | } |
|
175 | } | |
177 | } |
|
176 | } | |
178 |
|
177 | |||
179 | void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1) |
|
178 | void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1) | |
180 | { |
|
179 | { | |
181 |
qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::onRangeChanged") |
|
180 | qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::onRangeChanged") | |
|
181 | << QThread::currentThread()->objectName(); | |||
182 |
|
182 | |||
183 | for (auto it = impl->m_VariableToPlotMultiMap.cbegin(); |
|
183 | for (auto it = impl->m_VariableToPlotMultiMap.cbegin(); | |
184 | it != impl->m_VariableToPlotMultiMap.cend(); ++it) { |
|
184 | it != impl->m_VariableToPlotMultiMap.cend(); ++it) { | |
185 |
|
185 | |||
186 | auto variable = it->first; |
|
186 | auto variable = it->first; | |
187 | auto dateTime = SqpDateTime{t1.lower, t1.upper}; |
|
187 | auto dateTime = SqpDateTime{t1.lower, t1.upper}; | |
188 |
|
188 | |||
189 | if (!variable->contains(dateTime)) { |
|
189 | if (!variable->contains(dateTime)) { | |
190 |
|
190 | |||
191 | auto variableDateTimeWithTolerance = dateTime; |
|
191 | auto variableDateTimeWithTolerance = dateTime; | |
192 | if (!variable->isInside(dateTime)) { |
|
192 | if (!variable->isInside(dateTime)) { | |
193 | auto variableDateTime = variable->dateTime(); |
|
193 | auto variableDateTime = variable->dateTime(); | |
194 | if (variableDateTime.m_TStart < dateTime.m_TStart) { |
|
194 | if (variableDateTime.m_TStart < dateTime.m_TStart) { | |
195 | qCDebug(LOG_VisualizationGraphWidget()) << tr("TDetection pan to right:"); |
|
195 | qCDebug(LOG_VisualizationGraphWidget()) << tr("TDetection pan to right:"); | |
196 |
|
196 | |||
197 | auto diffEndToKeepDelta = dateTime.m_TEnd - variableDateTime.m_TEnd; |
|
197 | auto diffEndToKeepDelta = dateTime.m_TEnd - variableDateTime.m_TEnd; | |
198 | dateTime.m_TStart = variableDateTime.m_TStart + diffEndToKeepDelta; |
|
198 | dateTime.m_TStart = variableDateTime.m_TStart + diffEndToKeepDelta; | |
199 | // Tolerance have to be added to the right |
|
199 | // Tolerance have to be added to the right | |
200 | // add 10% tolerance for right (end) side |
|
200 | // add 10% tolerance for right (end) side | |
201 | auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart); |
|
201 | auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart); | |
202 | variableDateTimeWithTolerance.m_TEnd += tolerance; |
|
202 | variableDateTimeWithTolerance.m_TEnd += tolerance; | |
203 | } |
|
203 | } | |
204 | else if (variableDateTime.m_TEnd > dateTime.m_TEnd) { |
|
204 | else if (variableDateTime.m_TEnd > dateTime.m_TEnd) { | |
205 | qCDebug(LOG_VisualizationGraphWidget()) << tr("Detection pan to left: "); |
|
205 | qCDebug(LOG_VisualizationGraphWidget()) << tr("Detection pan to left: "); | |
206 | auto diffStartToKeepDelta = variableDateTime.m_TStart - dateTime.m_TStart; |
|
206 | auto diffStartToKeepDelta = variableDateTime.m_TStart - dateTime.m_TStart; | |
207 | dateTime.m_TEnd = variableDateTime.m_TEnd - diffStartToKeepDelta; |
|
207 | dateTime.m_TEnd = variableDateTime.m_TEnd - diffStartToKeepDelta; | |
208 | // Tolerance have to be added to the left |
|
208 | // Tolerance have to be added to the left | |
209 | // add 10% tolerance for left (start) side |
|
209 | // add 10% tolerance for left (start) side | |
210 | auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart); |
|
210 | auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart); | |
211 | variableDateTimeWithTolerance.m_TStart -= tolerance; |
|
211 | variableDateTimeWithTolerance.m_TStart -= tolerance; | |
212 | } |
|
212 | } | |
213 | else { |
|
213 | else { | |
214 | qCWarning(LOG_VisualizationGraphWidget()) |
|
214 | qCWarning(LOG_VisualizationGraphWidget()) | |
215 | << tr("Detection anormal zoom detection: "); |
|
215 | << tr("Detection anormal zoom detection: "); | |
216 | } |
|
216 | } | |
217 | } |
|
217 | } | |
218 | else { |
|
218 | else { | |
219 | qCDebug(LOG_VisualizationGraphWidget()) << tr("Detection zoom out: "); |
|
219 | qCDebug(LOG_VisualizationGraphWidget()) << tr("Detection zoom out: "); | |
220 | // add 10% tolerance for each side |
|
220 | // add 10% tolerance for each side | |
221 | auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart); |
|
221 | auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart); | |
222 | variableDateTimeWithTolerance.m_TStart -= tolerance; |
|
222 | variableDateTimeWithTolerance.m_TStart -= tolerance; | |
223 | variableDateTimeWithTolerance.m_TEnd += tolerance; |
|
223 | variableDateTimeWithTolerance.m_TEnd += tolerance; | |
224 | } |
|
224 | } | |
225 | variable->setDateTime(dateTime); |
|
225 | variable->setDateTime(dateTime); | |
226 |
|
226 | |||
227 | // CHangement detected, we need to ask controller to request data loading |
|
227 | // CHangement detected, we need to ask controller to request data loading | |
228 | emit requestDataLoading(variable, variableDateTimeWithTolerance); |
|
228 | emit requestDataLoading(variable, variableDateTimeWithTolerance); | |
229 | } |
|
229 | } | |
230 | else { |
|
230 | else { | |
231 | qCDebug(LOG_VisualizationGraphWidget()) << tr("Detection zoom in: "); |
|
231 | qCDebug(LOG_VisualizationGraphWidget()) << tr("Detection zoom in: "); | |
232 | } |
|
232 | } | |
233 | } |
|
233 | } | |
234 | } |
|
234 | } | |
235 |
|
235 | |||
236 | void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept |
|
236 | void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept | |
237 | { |
|
237 | { | |
238 | auto zoomOrientations = QFlags<Qt::Orientation>{}; |
|
238 | auto zoomOrientations = QFlags<Qt::Orientation>{}; | |
239 |
|
239 | |||
240 | // Lambda that enables a zoom orientation if the key modifier related to this orientation |
|
240 | // Lambda that enables a zoom orientation if the key modifier related to this orientation | |
241 | // has |
|
241 | // has | |
242 | // been pressed |
|
242 | // been pressed | |
243 | auto enableOrientation |
|
243 | auto enableOrientation | |
244 | = [&zoomOrientations, event](const auto &orientation, const auto &modifier) { |
|
244 | = [&zoomOrientations, event](const auto &orientation, const auto &modifier) { | |
245 | auto orientationEnabled = event->modifiers().testFlag(modifier); |
|
245 | auto orientationEnabled = event->modifiers().testFlag(modifier); | |
246 | zoomOrientations.setFlag(orientation, orientationEnabled); |
|
246 | zoomOrientations.setFlag(orientation, orientationEnabled); | |
247 | }; |
|
247 | }; | |
248 | enableOrientation(Qt::Vertical, VERTICAL_ZOOM_MODIFIER); |
|
248 | enableOrientation(Qt::Vertical, VERTICAL_ZOOM_MODIFIER); | |
249 | enableOrientation(Qt::Horizontal, HORIZONTAL_ZOOM_MODIFIER); |
|
249 | enableOrientation(Qt::Horizontal, HORIZONTAL_ZOOM_MODIFIER); | |
250 |
|
250 | |||
251 | ui->widget->axisRect()->setRangeZoom(zoomOrientations); |
|
251 | ui->widget->axisRect()->setRangeZoom(zoomOrientations); | |
252 | } |
|
252 | } | |
253 |
|
253 | |||
254 | void VisualizationGraphWidget::onDataCacheVariableUpdated() |
|
254 | void VisualizationGraphWidget::onDataCacheVariableUpdated() | |
255 | { |
|
255 | { | |
256 | // NOTE: |
|
256 | // NOTE: | |
257 | // We don't want to call the method for each component of a variable unitarily, but for |
|
257 | // We don't want to call the method for each component of a variable unitarily, but for | |
258 | // all |
|
258 | // all | |
259 | // its components at once (eg its three components in the case of a vector). |
|
259 | // its components at once (eg its three components in the case of a vector). | |
260 |
|
260 | |||
261 | // The unordered_multimap does not do this easily, so the question is whether to: |
|
261 | // The unordered_multimap does not do this easily, so the question is whether to: | |
262 | // - use an ordered_multimap and the algos of std to group the values by key |
|
262 | // - use an ordered_multimap and the algos of std to group the values by key | |
263 | // - use a map (unique keys) and store as values directly the list of components |
|
263 | // - use a map (unique keys) and store as values directly the list of components | |
264 |
|
264 | |||
265 | for (auto it = impl->m_VariableToPlotMultiMap.cbegin(); |
|
265 | for (auto it = impl->m_VariableToPlotMultiMap.cbegin(); | |
266 | it != impl->m_VariableToPlotMultiMap.cend(); ++it) { |
|
266 | it != impl->m_VariableToPlotMultiMap.cend(); ++it) { | |
267 | auto variable = it->first; |
|
267 | auto variable = it->first; | |
268 | VisualizationGraphHelper::updateData(QVector<QCPAbstractPlottable *>{} << it->second, |
|
268 | VisualizationGraphHelper::updateData(QVector<QCPAbstractPlottable *>{} << it->second, | |
269 | variable->dataSeries(), variable->dateTime()); |
|
269 | variable->dataSeries(), variable->dateTime()); | |
270 | } |
|
270 | } | |
271 | } |
|
271 | } | |
272 |
|
272 | |||
273 | void VisualizationGraphWidget::updateDisplay(std::shared_ptr<Variable> variable) |
|
273 | void VisualizationGraphWidget::updateDisplay(std::shared_ptr<Variable> variable) | |
274 | { |
|
274 | { | |
275 | auto abstractPlotableItPair = impl->m_VariableToPlotMultiMap.equal_range(variable); |
|
275 | auto abstractPlotableItPair = impl->m_VariableToPlotMultiMap.equal_range(variable); | |
276 |
|
276 | |||
277 | auto abstractPlotableVect = QVector<QCPAbstractPlottable *>{}; |
|
277 | auto abstractPlotableVect = QVector<QCPAbstractPlottable *>{}; | |
278 |
|
278 | |||
279 | for (auto it = abstractPlotableItPair.first; it != abstractPlotableItPair.second; ++it) { |
|
279 | for (auto it = abstractPlotableItPair.first; it != abstractPlotableItPair.second; ++it) { | |
280 | abstractPlotableVect.push_back(it->second); |
|
280 | abstractPlotableVect.push_back(it->second); | |
281 | } |
|
281 | } | |
282 |
|
282 | |||
283 | VisualizationGraphHelper::updateData(abstractPlotableVect, variable->dataSeries(), |
|
283 | VisualizationGraphHelper::updateData(abstractPlotableVect, variable->dataSeries(), | |
284 | variable->dateTime()); |
|
284 | variable->dateTime()); | |
285 | } |
|
285 | } |
1 | NO CONTENT: modified file |
|
NO CONTENT: modified file |
@@ -1,47 +1,50 | |||||
1 | #include "CosinusProvider.h" |
|
1 | #include "CosinusProvider.h" | |
2 |
|
2 | |||
3 | #include <Data/DataProviderParameters.h> |
|
3 | #include <Data/DataProviderParameters.h> | |
4 | #include <Data/ScalarSeries.h> |
|
4 | #include <Data/ScalarSeries.h> | |
5 |
|
5 | |||
6 | #include <cmath> |
|
6 | #include <cmath> | |
7 |
|
7 | |||
8 | #include <QDateTime> |
|
8 | #include <QDateTime> | |
|
9 | #include <QThread> | |||
9 |
|
10 | |||
10 | Q_LOGGING_CATEGORY(LOG_CosinusProvider, "CosinusProvider") |
|
11 | Q_LOGGING_CATEGORY(LOG_CosinusProvider, "CosinusProvider") | |
11 |
|
12 | |||
12 | std::shared_ptr<IDataSeries> |
|
13 | std::shared_ptr<IDataSeries> | |
13 | CosinusProvider::retrieveData(const DataProviderParameters ¶meters) const |
|
14 | CosinusProvider::retrieveData(const DataProviderParameters ¶meters) const | |
14 | { |
|
15 | { | |
15 | auto dateTime = parameters.m_Time; |
|
16 | auto dateTime = parameters.m_Time; | |
16 |
|
17 | |||
17 | auto dataIndex = 0; |
|
18 | auto dataIndex = 0; | |
18 |
|
19 | |||
19 | // Gets the timerange from the parameters |
|
20 | // Gets the timerange from the parameters | |
20 | double freq = 100.0; |
|
21 | double freq = 100.0; | |
21 | double start = dateTime.m_TStart * freq; // 100 htz |
|
22 | double start = dateTime.m_TStart * freq; // 100 htz | |
22 | double end = dateTime.m_TEnd * freq; // 100 htz |
|
23 | double end = dateTime.m_TEnd * freq; // 100 htz | |
23 |
|
24 | |||
24 | // We assure that timerange is valid |
|
25 | // We assure that timerange is valid | |
25 | if (end < start) { |
|
26 | if (end < start) { | |
26 | std::swap(start, end); |
|
27 | std::swap(start, end); | |
27 | } |
|
28 | } | |
28 |
|
29 | |||
29 | // Generates scalar series containing cosinus values (one value per second) |
|
30 | // Generates scalar series containing cosinus values (one value per second) | |
30 | auto scalarSeries |
|
31 | auto scalarSeries | |
31 | = std::make_shared<ScalarSeries>(end - start, Unit{QStringLiteral("t"), true}, Unit{}); |
|
32 | = std::make_shared<ScalarSeries>(end - start, Unit{QStringLiteral("t"), true}, Unit{}); | |
32 |
|
33 | |||
33 | for (auto time = start; time < end; ++time, ++dataIndex) { |
|
34 | for (auto time = start; time < end; ++time, ++dataIndex) { | |
34 | const auto timeOnFreq = time / freq; |
|
35 | const auto timeOnFreq = time / freq; | |
35 | scalarSeries->setData(dataIndex, timeOnFreq, std::cos(timeOnFreq)); |
|
36 | scalarSeries->setData(dataIndex, timeOnFreq, std::cos(timeOnFreq)); | |
36 | } |
|
37 | } | |
37 | return scalarSeries; |
|
38 | return scalarSeries; | |
38 | } |
|
39 | } | |
39 |
|
40 | |||
40 | void CosinusProvider::requestDataLoading(const QVector<SqpDateTime> &dateTimeList) |
|
41 | void CosinusProvider::requestDataLoading(const QVector<SqpDateTime> &dateTimeList) | |
41 | { |
|
42 | { | |
|
43 | qCDebug(LOG_CosinusProvider()) << "CosinusProvider::requestDataLoading" | |||
|
44 | << QThread::currentThread()->objectName(); | |||
42 | // NOTE: Try to use multithread if possible |
|
45 | // NOTE: Try to use multithread if possible | |
43 | for (const auto &dateTime : dateTimeList) { |
|
46 | for (const auto &dateTime : dateTimeList) { | |
44 | auto scalarSeries = this->retrieveData(DataProviderParameters{dateTime}); |
|
47 | auto scalarSeries = this->retrieveData(DataProviderParameters{dateTime}); | |
45 | emit dataProvided(scalarSeries, dateTime); |
|
48 | emit dataProvided(scalarSeries, dateTime); | |
46 | } |
|
49 | } | |
47 | } |
|
50 | } |
General Comments 0
You need to be logged in to leave comments.
Login now