@@ -1,66 +1,65 | |||
|
1 | 1 | #ifndef SCIQLOP_VARIABLE_H |
|
2 | 2 | #define SCIQLOP_VARIABLE_H |
|
3 | 3 | |
|
4 | 4 | #include "CoreGlobal.h" |
|
5 | 5 | |
|
6 | 6 | #include <Data/SqpRange.h> |
|
7 | 7 | |
|
8 | 8 | #include <QLoggingCategory> |
|
9 | 9 | #include <QObject> |
|
10 | 10 | |
|
11 | 11 | #include <Common/MetaTypes.h> |
|
12 | 12 | #include <Common/spimpl.h> |
|
13 | 13 | |
|
14 | 14 | Q_DECLARE_LOGGING_CATEGORY(LOG_Variable) |
|
15 | 15 | |
|
16 | 16 | class IDataSeries; |
|
17 | 17 | class QString; |
|
18 | 18 | |
|
19 | 19 | /** |
|
20 | 20 | * @brief The Variable class represents a variable in SciQlop. |
|
21 | 21 | */ |
|
22 | 22 | class SCIQLOP_CORE_EXPORT Variable : public QObject { |
|
23 | 23 | |
|
24 | 24 | Q_OBJECT |
|
25 | 25 | |
|
26 | 26 | public: |
|
27 | 27 | explicit Variable(const QString &name, const SqpRange &dateTime, |
|
28 | 28 | const QVariantHash &metadata = {}); |
|
29 | 29 | |
|
30 | 30 | QString name() const noexcept; |
|
31 | 31 | SqpRange range() const noexcept; |
|
32 | 32 | void setRange(const SqpRange &range) noexcept; |
|
33 | 33 | SqpRange cacheRange() const noexcept; |
|
34 | 34 | void setCacheRange(const SqpRange &cacheRange) noexcept; |
|
35 | 35 | |
|
36 | 36 | /// @return the data of the variable, nullptr if there is no data |
|
37 | 37 | IDataSeries *dataSeries() const noexcept; |
|
38 | 38 | |
|
39 | 39 | QVariantHash metadata() const noexcept; |
|
40 | 40 | |
|
41 | 41 | bool contains(const SqpRange &range) const noexcept; |
|
42 | 42 | bool intersect(const SqpRange &range) const noexcept; |
|
43 | 43 | bool isInside(const SqpRange &range) const noexcept; |
|
44 | 44 | |
|
45 | 45 | bool cacheContains(const SqpRange &range) const noexcept; |
|
46 | 46 | bool cacheIntersect(const SqpRange &range) const noexcept; |
|
47 | 47 | bool cacheIsInside(const SqpRange &range) const noexcept; |
|
48 | 48 | |
|
49 | 49 | QVector<SqpRange> provideNotInCacheRangeList(const SqpRange &range); |
|
50 | ||
|
51 | ||
|
52 | public slots: | |
|
53 | 50 | void setDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept; |
|
51 | void mergeDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept; | |
|
54 | 52 | |
|
55 | 53 | signals: |
|
56 | 54 | void updated(); |
|
57 | 55 | |
|
58 | 56 | private: |
|
59 | 57 | class VariablePrivate; |
|
60 | 58 | spimpl::unique_impl_ptr<VariablePrivate> impl; |
|
61 | 59 | }; |
|
62 | 60 | |
|
63 | 61 | // Required for using shared_ptr in signals/slots |
|
64 | 62 | SCIQLOP_REGISTER_META_TYPE(VARIABLE_PTR_REGISTRY, std::shared_ptr<Variable>) |
|
63 | SCIQLOP_REGISTER_META_TYPE(VARIABLE_PTR_VECTOR_REGISTRY, QVector<std::shared_ptr<Variable> >) | |
|
65 | 64 | |
|
66 | 65 | #endif // SCIQLOP_VARIABLE_H |
@@ -1,142 +1,169 | |||
|
1 | 1 | #include "Variable/Variable.h" |
|
2 | 2 | |
|
3 | 3 | #include <Data/IDataSeries.h> |
|
4 | 4 | #include <Data/SqpRange.h> |
|
5 | 5 | |
|
6 | 6 | #include <QReadWriteLock> |
|
7 | 7 | #include <QThread> |
|
8 | 8 | |
|
9 | 9 | Q_LOGGING_CATEGORY(LOG_Variable, "Variable") |
|
10 | 10 | |
|
11 | 11 | struct Variable::VariablePrivate { |
|
12 | 12 | explicit VariablePrivate(const QString &name, const SqpRange &dateTime, |
|
13 | 13 | const QVariantHash &metadata) |
|
14 | 14 | : m_Name{name}, m_Range{dateTime}, m_Metadata{metadata}, m_DataSeries{nullptr} |
|
15 | 15 | { |
|
16 | 16 | } |
|
17 | 17 | |
|
18 | 18 | QString m_Name; |
|
19 | 19 | |
|
20 | 20 | SqpRange m_Range; |
|
21 | 21 | SqpRange m_CacheRange; |
|
22 | 22 | QVariantHash m_Metadata; |
|
23 | 23 | std::unique_ptr<IDataSeries> m_DataSeries; |
|
24 | 24 | }; |
|
25 | 25 | |
|
26 | 26 | Variable::Variable(const QString &name, const SqpRange &dateTime, const QVariantHash &metadata) |
|
27 | 27 | : impl{spimpl::make_unique_impl<VariablePrivate>(name, dateTime, metadata)} |
|
28 | 28 | { |
|
29 | 29 | } |
|
30 | 30 | |
|
31 | 31 | QString Variable::name() const noexcept |
|
32 | 32 | { |
|
33 | 33 | return impl->m_Name; |
|
34 | 34 | } |
|
35 | 35 | |
|
36 | 36 | SqpRange Variable::range() const noexcept |
|
37 | 37 | { |
|
38 | 38 | return impl->m_Range; |
|
39 | 39 | } |
|
40 | 40 | |
|
41 | 41 | void Variable::setRange(const SqpRange &range) noexcept |
|
42 | 42 | { |
|
43 | 43 | impl->m_Range = range; |
|
44 | 44 | } |
|
45 | 45 | |
|
46 | 46 | SqpRange Variable::cacheRange() const noexcept |
|
47 | 47 | { |
|
48 | 48 | return impl->m_CacheRange; |
|
49 | 49 | } |
|
50 | 50 | |
|
51 | 51 | void Variable::setCacheRange(const SqpRange &cacheRange) noexcept |
|
52 | 52 | { |
|
53 | 53 | impl->m_CacheRange = cacheRange; |
|
54 | 54 | } |
|
55 | 55 | |
|
56 | 56 | void Variable::setDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept |
|
57 | 57 | { |
|
58 | 58 | qCDebug(LOG_Variable()) << "Variable::setDataSeries" << QThread::currentThread()->objectName(); |
|
59 | 59 | if (!dataSeries) { |
|
60 | 60 | /// @todo ALX : log |
|
61 | 61 | return; |
|
62 | 62 | } |
|
63 | 63 | |
|
64 | impl->m_DataSeries = dataSeries->clone(); | |
|
65 | ||
|
66 | // // Inits the data series of the variable | |
|
67 | // if (!impl->m_DataSeries) { | |
|
68 | // impl->m_DataSeries = dataSeries->clone(); | |
|
69 | // } | |
|
70 | // else { | |
|
71 | // impl->m_DataSeries->merge(dataSeries.get()); | |
|
72 | // } | |
|
73 | } | |
|
74 | ||
|
75 | void Variable::mergeDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept | |
|
76 | { | |
|
77 | qCDebug(LOG_Variable()) << "Variable::setDataSeries" << QThread::currentThread()->objectName(); | |
|
78 | if (!dataSeries) { | |
|
79 | /// @todo ALX : log | |
|
80 | return; | |
|
81 | } | |
|
82 | ||
|
83 | // Add or merge the data | |
|
64 | 84 | // Inits the data series of the variable |
|
65 | 85 | if (!impl->m_DataSeries) { |
|
66 | 86 | impl->m_DataSeries = dataSeries->clone(); |
|
67 | 87 | } |
|
68 | 88 | else { |
|
69 | 89 | impl->m_DataSeries->merge(dataSeries.get()); |
|
70 | 90 | } |
|
91 | ||
|
92 | // sub the data | |
|
93 | auto subData = this->dataSeries()->subData(this->cacheRange()); | |
|
94 | qCCritical(LOG_Variable()) << "TORM: Variable::mergeDataSeries sub" << subData->range(); | |
|
95 | this->setDataSeries(subData); | |
|
96 | qCCritical(LOG_Variable()) << "TORM: Variable::mergeDataSeries set" | |
|
97 | << this->dataSeries()->range(); | |
|
71 | 98 | } |
|
72 | 99 | |
|
73 | 100 | IDataSeries *Variable::dataSeries() const noexcept |
|
74 | 101 | { |
|
75 | 102 | return impl->m_DataSeries.get(); |
|
76 | 103 | } |
|
77 | 104 | |
|
78 | 105 | QVariantHash Variable::metadata() const noexcept |
|
79 | 106 | { |
|
80 | 107 | return impl->m_Metadata; |
|
81 | 108 | } |
|
82 | 109 | |
|
83 | 110 | bool Variable::contains(const SqpRange &range) const noexcept |
|
84 | 111 | { |
|
85 | 112 | return impl->m_Range.contains(range); |
|
86 | 113 | } |
|
87 | 114 | |
|
88 | 115 | bool Variable::intersect(const SqpRange &range) const noexcept |
|
89 | 116 | { |
|
90 | 117 | return impl->m_Range.intersect(range); |
|
91 | 118 | } |
|
92 | 119 | |
|
93 | 120 | bool Variable::isInside(const SqpRange &range) const noexcept |
|
94 | 121 | { |
|
95 | 122 | return range.contains(SqpRange{impl->m_Range.m_TStart, impl->m_Range.m_TEnd}); |
|
96 | 123 | } |
|
97 | 124 | |
|
98 | 125 | bool Variable::cacheContains(const SqpRange &range) const noexcept |
|
99 | 126 | { |
|
100 | 127 | return impl->m_CacheRange.contains(range); |
|
101 | 128 | } |
|
102 | 129 | |
|
103 | 130 | bool Variable::cacheIntersect(const SqpRange &range) const noexcept |
|
104 | 131 | { |
|
105 | 132 | return impl->m_CacheRange.intersect(range); |
|
106 | 133 | } |
|
107 | 134 | |
|
108 | 135 | bool Variable::cacheIsInside(const SqpRange &range) const noexcept |
|
109 | 136 | { |
|
110 | 137 | return range.contains(SqpRange{impl->m_CacheRange.m_TStart, impl->m_CacheRange.m_TEnd}); |
|
111 | 138 | } |
|
112 | 139 | |
|
113 | 140 | |
|
114 | 141 | QVector<SqpRange> Variable::provideNotInCacheRangeList(const SqpRange &range) |
|
115 | 142 | { |
|
116 | 143 | auto notInCache = QVector<SqpRange>{}; |
|
117 | 144 | |
|
118 | 145 | if (!this->cacheContains(range)) { |
|
119 | 146 | if (range.m_TEnd <= impl->m_CacheRange.m_TStart |
|
120 | 147 | || range.m_TStart >= impl->m_CacheRange.m_TEnd) { |
|
121 | 148 | notInCache << range; |
|
122 | 149 | } |
|
123 | 150 | else if (range.m_TStart < impl->m_CacheRange.m_TStart |
|
124 | 151 | && range.m_TEnd <= impl->m_CacheRange.m_TEnd) { |
|
125 | 152 | notInCache << SqpRange{range.m_TStart, impl->m_CacheRange.m_TStart}; |
|
126 | 153 | } |
|
127 | 154 | else if (range.m_TStart < impl->m_CacheRange.m_TStart |
|
128 | 155 | && range.m_TEnd > impl->m_CacheRange.m_TEnd) { |
|
129 | 156 | notInCache << SqpRange{range.m_TStart, impl->m_CacheRange.m_TStart} |
|
130 |
<< SqpRange{impl->m_CacheRange.m_TEnd, range.m_T |
|
|
157 | << SqpRange{impl->m_CacheRange.m_TEnd, range.m_TEnd}; | |
|
131 | 158 | } |
|
132 | 159 | else if (range.m_TStart < impl->m_CacheRange.m_TEnd) { |
|
133 |
notInCache << SqpRange{impl->m_CacheRange.m_TEnd, range.m_T |
|
|
160 | notInCache << SqpRange{impl->m_CacheRange.m_TEnd, range.m_TEnd}; | |
|
134 | 161 | } |
|
135 | 162 | else { |
|
136 | 163 | qCCritical(LOG_Variable()) << tr("Detection of unknown case.") |
|
137 | 164 | << QThread::currentThread(); |
|
138 | 165 | } |
|
139 | 166 | } |
|
140 | 167 | |
|
141 | 168 | return notInCache; |
|
142 | 169 | } |
General Comments 0
You need to be logged in to leave comments.
Login now