##// END OF EJS Templates
Implementation of V5 acquisition
perrinel -
r510:7c107b5923b0
parent child
Show More
@@ -43,6 +43,16 public:
43 /// @sa IDataSeries::valuesUnit()
43 /// @sa IDataSeries::valuesUnit()
44 Unit valuesUnit() const override { return m_ValuesUnit; }
44 Unit valuesUnit() const override { return m_ValuesUnit; }
45
45
46
47 SqpRange range() const override
48 {
49 if (!m_XAxisData->cdata().isEmpty()) {
50 return SqpRange{m_XAxisData->cdata().first(), m_XAxisData->cdata().last()};
51 }
52
53 return SqpRange{};
54 }
55
46 void clear()
56 void clear()
47 {
57 {
48 m_XAxisData->clear();
58 m_XAxisData->clear();
@@ -34,35 +34,37 public:
34 virtual ~IDataProvider() noexcept = default;
34 virtual ~IDataProvider() noexcept = default;
35
35
36 /**
36 /**
37 * @brief requestDataLoading provide datas for the data identified by identifier and parameters
37 * @brief requestDataLoading provide datas for the data identified by acqIdentifier and
38 * parameters
38 */
39 */
39 virtual void requestDataLoading(QUuid identifier, const DataProviderParameters &parameters) = 0;
40 virtual void requestDataLoading(QUuid acqIdentifier, const DataProviderParameters &parameters)
41 = 0;
40
42
41 /**
43 /**
42 * @brief requestDataAborting stop data loading of the data identified by identifier
44 * @brief requestDataAborting stop data loading of the data identified by acqIdentifier
43 */
45 */
44 virtual void requestDataAborting(QUuid identifier) = 0;
46 virtual void requestDataAborting(QUuid acqIdentifier) = 0;
45
47
46 signals:
48 signals:
47 /**
49 /**
48 * @brief dataProvided send dataSeries under dateTime and that corresponds of the data
50 * @brief dataProvided send dataSeries under dateTime and that corresponds of the data
49 * identified by identifier
51 * identified by acqIdentifier
50 */
52 */
51 void dataProvided(QUuid identifier, std::shared_ptr<IDataSeries> dateSerie,
53 void dataProvided(QUuid acqIdentifier, std::shared_ptr<IDataSeries> dateSeriesAcquired,
52 const SqpRange &dateTime);
54 const SqpRange &dataRangeAcquired);
53
55
54 /**
56 /**
55 * @brief dataProvided send dataSeries under dateTime and that corresponds of the data
57 * @brief dataProvided send dataSeries under dateTime and that corresponds of the data
56 * identified by identifier
58 * identified by identifier
57 */
59 */
58 void dataProvidedProgress(QUuid identifier, double progress);
60 void dataProvidedProgress(QUuid acqIdentifier, double progress);
59
61
60
62
61 /**
63 /**
62 * @brief requestConstructed send a request for the data identified by identifier
64 * @brief requestConstructed send a request for the data identified by acqIdentifier
63 * @callback is the methode call by the reply of the request when it is finished.
65 * @callback is the methode call by the reply of the request when it is finished.
64 */
66 */
65 void requestConstructed(const QNetworkRequest &request, QUuid identifier,
67 void requestConstructed(const QNetworkRequest &request, QUuid acqIdentifier,
66 std::function<void(QNetworkReply *, QUuid)> callback);
68 std::function<void(QNetworkReply *, QUuid)> callback);
67 };
69 };
68
70
@@ -2,6 +2,7
2 #define SCIQLOP_IDATASERIES_H
2 #define SCIQLOP_IDATASERIES_H
3
3
4 #include <Common/MetaTypes.h>
4 #include <Common/MetaTypes.h>
5 #include <Data/SqpRange.h>
5
6
6 #include <memory>
7 #include <memory>
7
8
@@ -55,8 +56,10 public:
55 virtual Unit valuesUnit() const = 0;
56 virtual Unit valuesUnit() const = 0;
56
57
57 virtual void merge(IDataSeries *dataSeries) = 0;
58 virtual void merge(IDataSeries *dataSeries) = 0;
59 virtual std::shared_ptr<IDataSeries> subData(const SqpRange &range) = 0;
58
60
59 virtual std::unique_ptr<IDataSeries> clone() const = 0;
61 virtual std::unique_ptr<IDataSeries> clone() const = 0;
62 virtual SqpRange range() const = 0;
60
63
61 virtual void lockRead() = 0;
64 virtual void lockRead() = 0;
62 virtual void lockWrite() = 0;
65 virtual void lockWrite() = 0;
@@ -19,7 +19,9 public:
19 explicit ScalarSeries(QVector<double> xAxisData, QVector<double> valuesData,
19 explicit ScalarSeries(QVector<double> xAxisData, QVector<double> valuesData,
20 const Unit &xAxisUnit, const Unit &valuesUnit);
20 const Unit &xAxisUnit, const Unit &valuesUnit);
21
21
22 std::unique_ptr<IDataSeries> clone() const;
22 std::unique_ptr<IDataSeries> clone() const override;
23
24 std::shared_ptr<IDataSeries> subData(const SqpRange &range) override;
23 };
25 };
24
26
25 #endif // SCIQLOP_SCALARSERIES_H
27 #endif // SCIQLOP_SCALARSERIES_H
@@ -8,6 +8,8
8 #include <QObject>
8 #include <QObject>
9 #include <QUuid>
9 #include <QUuid>
10
10
11 #include <Data/AcquisitionDataPacket.h>
12 #include <Data/IDataSeries.h>
11 #include <Data/SqpRange.h>
13 #include <Data/SqpRange.h>
12
14
13 #include <QLoggingCategory>
15 #include <QLoggingCategory>
@@ -24,11 +26,34 class SCIQLOP_CORE_EXPORT VariableAcquisitionWorker : public QObject {
24 Q_OBJECT
26 Q_OBJECT
25 public:
27 public:
26 explicit VariableAcquisitionWorker(QObject *parent = 0);
28 explicit VariableAcquisitionWorker(QObject *parent = 0);
29 virtual ~VariableAcquisitionWorker();
27
30
28 void pushVariableRequest(QUuid vIdentifier, SqpRange rangeRequest, SqpRange cacheRangeRequested,
31 void pushVariableRequest(QUuid vIdentifier, SqpRange rangeRequested,
29 DataProviderParameters parameters, IDataProvider *provider);
32 SqpRange cacheRangeRequested, DataProviderParameters parameters,
33 std::shared_ptr<IDataProvider> provider);
34
35 void abortProgressRequested(QUuid vIdentifier);
36
37 void initialize();
38 void finalize();
39 signals:
40 void dataProvided(QUuid vIdentifier, const SqpRange &rangeRequested,
41 const SqpRange &cacheRangeRequested,
42 QVector<AcquisitionDataPacket> dataAcquired);
43
44 void variableRequestInProgress(QUuid vIdentifier, double progress);
45
46 public slots:
47 void onVariableDataAcquired(QUuid acqIdentifier, std::shared_ptr<IDataSeries> dataSeries,
48 SqpRange dataRangeAcquired);
49 void onVariableRetrieveDataInProgress(QUuid acqIdentifier, double progress);
50
51 private slots:
52 void onExecuteRequest(QUuid acqIdentifier);
30
53
31 private:
54 private:
55 void waitForFinish();
56
32 class VariableAcquisitionWorkerPrivate;
57 class VariableAcquisitionWorkerPrivate;
33 spimpl::unique_impl_ptr<VariableAcquisitionWorkerPrivate> impl;
58 spimpl::unique_impl_ptr<VariableAcquisitionWorkerPrivate> impl;
34 };
59 };
@@ -3,6 +3,7
3
3
4 #include "CoreGlobal.h"
4 #include "CoreGlobal.h"
5
5
6 #include <Data/AcquisitionDataPacket.h>
6 #include <Data/SqpRange.h>
7 #include <Data/SqpRange.h>
7
8
8 #include <QLoggingCategory>
9 #include <QLoggingCategory>
@@ -18,6 +19,13 class VariableModel;
18
19
19 Q_DECLARE_LOGGING_CATEGORY(LOG_VariableController)
20 Q_DECLARE_LOGGING_CATEGORY(LOG_VariableController)
20
21
22
23 /**
24 * Possible types of zoom operation
25 */
26 enum class AcquisitionZoomType { ZoomOut, ZoomIn, PanRight, PanLeft, Unknown };
27
28
21 /**
29 /**
22 * @brief The VariableController class aims to handle the variables in SciQlop.
30 * @brief The VariableController class aims to handle the variables in SciQlop.
23 */
31 */
@@ -57,6 +65,7 public:
57 */
65 */
58 void abortProgress(std::shared_ptr<Variable> variable);
66 void abortProgress(std::shared_ptr<Variable> variable);
59
67
68 static AcquisitionZoomType getZoomType(const SqpRange &range, const SqpRange &oldRange);
60 signals:
69 signals:
61 /// Signal emitted when a variable is about to be deleted from the controller
70 /// Signal emitted when a variable is about to be deleted from the controller
62 void variableAboutToBeDeleted(std::shared_ptr<Variable> variable);
71 void variableAboutToBeDeleted(std::shared_ptr<Variable> variable);
@@ -65,8 +74,9 signals:
65 void rangeChanged(std::shared_ptr<Variable> variable, const SqpRange &range);
74 void rangeChanged(std::shared_ptr<Variable> variable, const SqpRange &range);
66
75
67 public slots:
76 public slots:
68 /// Request the data loading of the variable whithin dateTime
77 /// Request the data loading of the variable whithin range
69 void onRequestDataLoading(std::shared_ptr<Variable> variable, const SqpRange &dateTime);
78 void onRequestDataLoading(QVector<std::shared_ptr<Variable> > variables, const SqpRange &range,
79 const SqpRange &oldRange, bool synchronise);
70 /**
80 /**
71 * Creates a new variable and adds it to the model
81 * Creates a new variable and adds it to the model
72 * @param name the name of the new variable
82 * @param name the name of the new variable
@@ -80,10 +90,19 public slots:
80 void onDateTimeOnSelection(const SqpRange &dateTime);
90 void onDateTimeOnSelection(const SqpRange &dateTime);
81
91
82
92
93 void onDataProvided(QUuid vIdentifier, const SqpRange &rangeRequested,
94 const SqpRange &cacheRangeRequested,
95 QVector<AcquisitionDataPacket> dataAcquired);
96
83 void onVariableRetrieveDataInProgress(QUuid identifier, double progress);
97 void onVariableRetrieveDataInProgress(QUuid identifier, double progress);
84
98
99 /// Cancel the current request for the variable
85 void onAbortProgressRequested(std::shared_ptr<Variable> variable);
100 void onAbortProgressRequested(std::shared_ptr<Variable> variable);
86
101
102 /// synchronization group methods
103 void onAddSynchronizationGroupId(QUuid synchronizationGroupId);
104 void onRemoveSynchronizationGroupId(QUuid synchronizationGroupId);
105
87 void initialize();
106 void initialize();
88 void finalize();
107 void finalize();
89
108
@@ -11,3 +11,31 std::unique_ptr<IDataSeries> ScalarSeries::clone() const
11 {
11 {
12 return std::make_unique<ScalarSeries>(*this);
12 return std::make_unique<ScalarSeries>(*this);
13 }
13 }
14
15 std::shared_ptr<IDataSeries> ScalarSeries::subData(const SqpRange &range)
16 {
17 auto subXAxisData = QVector<double>();
18 auto subValuesData = QVector<double>();
19 this->lockRead();
20 {
21 const auto &currentXData = this->xAxisData()->cdata();
22 const auto &currentValuesData = this->valuesData()->cdata();
23
24 auto xDataBegin = currentXData.cbegin();
25 auto xDataEnd = currentXData.cend();
26
27 auto lowerIt = std::lower_bound(xDataBegin, xDataEnd, range.m_TStart);
28 auto upperIt = std::upper_bound(xDataBegin, xDataEnd, range.m_TEnd);
29 auto distance = std::distance(xDataBegin, lowerIt);
30
31 auto valuesDataIt = currentValuesData.cbegin() + distance;
32 for (auto xAxisDataIt = lowerIt; xAxisDataIt != upperIt; ++xAxisDataIt, ++valuesDataIt) {
33 subXAxisData.append(*xAxisDataIt);
34 subValuesData.append(*valuesDataIt);
35 }
36 }
37 this->unlock();
38
39 return std::make_shared<ScalarSeries>(subXAxisData, subValuesData, this->xAxisUnit(),
40 this->valuesUnit());
41 }
@@ -13,15 +13,16 Q_LOGGING_CATEGORY(LOG_NetworkController, "NetworkController")
13
13
14 struct NetworkController::NetworkControllerPrivate {
14 struct NetworkController::NetworkControllerPrivate {
15 explicit NetworkControllerPrivate(NetworkController *parent) : m_WorkingMutex{} {}
15 explicit NetworkControllerPrivate(NetworkController *parent) : m_WorkingMutex{} {}
16
17 void lockRead() { m_Lock.lockForRead(); }
18 void lockWrite() { m_Lock.lockForWrite(); }
19 void unlock() { m_Lock.unlock(); }
20
16 QMutex m_WorkingMutex;
21 QMutex m_WorkingMutex;
17
22
18 QReadWriteLock m_Lock;
23 QReadWriteLock m_Lock;
19 std::unordered_map<QNetworkReply *, QUuid> m_NetworkReplyToVariableId;
24 std::unordered_map<QNetworkReply *, QUuid> m_NetworkReplyToVariableId;
20 std::unique_ptr<QNetworkAccessManager> m_AccessManager{nullptr};
25 std::unique_ptr<QNetworkAccessManager> m_AccessManager{nullptr};
21
22 void lockRead() { m_Lock.lockForRead(); }
23 void lockWrite() { m_Lock.lockForWrite(); }
24 void unlock() { m_Lock.unlock(); }
25 };
26 };
26
27
27 NetworkController::NetworkController(QObject *parent)
28 NetworkController::NetworkController(QObject *parent)
@@ -1,15 +1,35
1 #include "Variable/VariableAcquisitionWorker.h"
1 #include "Variable/VariableAcquisitionWorker.h"
2
2
3 #include "Variable/Variable.h"
3 #include "Variable/Variable.h"
4
5 #include <Data/AcquisitionRequest.h>
6 #include <Data/SqpRange.h>
7
4 #include <unordered_map>
8 #include <unordered_map>
9 #include <utility>
5
10
11 #include <QMutex>
12 #include <QReadWriteLock>
6 #include <QThread>
13 #include <QThread>
14
7 Q_LOGGING_CATEGORY(LOG_VariableAcquisitionWorker, "VariableAcquisitionWorker")
15 Q_LOGGING_CATEGORY(LOG_VariableAcquisitionWorker, "VariableAcquisitionWorker")
8
16
9 struct VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate {
17 struct VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate {
10
18
11 std::unordered_map<std::shared_ptr<Variable>, QVector<SqpRange> >
19 explicit VariableAcquisitionWorkerPrivate() : m_Lock{QReadWriteLock::Recursive} {}
12 m_VariableToSqpDateTimeListMap;
20
21 void lockRead() { m_Lock.lockForRead(); }
22 void lockWrite() { m_Lock.lockForWrite(); }
23 void unlock() { m_Lock.unlock(); }
24
25 void removeVariableRequest(QUuid vIdentifier);
26
27 QMutex m_WorkingMutex;
28 QReadWriteLock m_Lock;
29
30 std::map<QUuid, QVector<AcquisitionDataPacket> > m_AcqIdentifierToAcqDataPacketVectorMap;
31 std::map<QUuid, AcquisitionRequest> m_AcqIdentifierToAcqRequestMap;
32 std::map<QUuid, std::pair<QUuid, QUuid> > m_VIdentifierToCurrrentAcqIdNextIdPairMap;
13 };
33 };
14
34
15
35
@@ -18,9 +38,188 VariableAcquisitionWorker::VariableAcquisitionWorker(QObject *parent)
18 {
38 {
19 }
39 }
20
40
21 void VariableAcquisitionWorker::pushVariableRequest(QUuid vIdentifier, SqpRange rangeRequest,
41 VariableAcquisitionWorker::~VariableAcquisitionWorker()
42 {
43 qCInfo(LOG_VariableAcquisitionWorker()) << tr("VariableAcquisitionWorker destruction")
44 << QThread::currentThread();
45 this->waitForFinish();
46 }
47
48
49 void VariableAcquisitionWorker::pushVariableRequest(QUuid vIdentifier, SqpRange rangeRequested,
22 SqpRange cacheRangeRequested,
50 SqpRange cacheRangeRequested,
23 DataProviderParameters parameters,
51 DataProviderParameters parameters,
24 IDataProvider *provider)
52 std::shared_ptr<IDataProvider> provider)
53 {
54 qCDebug(LOG_VariableAcquisitionWorker())
55 << tr("TORM VariableAcquisitionWorker::pushVariableRequest ") << cacheRangeRequested;
56
57 // Request creation
58 auto acqRequest = AcquisitionRequest{};
59 acqRequest.m_vIdentifier = vIdentifier;
60 acqRequest.m_DataProviderParameters = parameters;
61 acqRequest.m_RangeRequested = rangeRequested;
62 acqRequest.m_CacheRangeRequested = cacheRangeRequested;
63 acqRequest.m_Size = parameters.m_Times.size();
64 acqRequest.m_Provider = provider;
65
66 // Register request
67 impl->lockWrite();
68 impl->m_AcqIdentifierToAcqRequestMap.insert(
69 std::make_pair(acqRequest.m_AcqIdentifier, acqRequest));
70
71 auto it = impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(vIdentifier);
72 if (it != impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) {
73 // A current request already exists, we can replace the next one
74 it->second.second = acqRequest.m_AcqIdentifier;
75 impl->unlock();
76 }
77 else {
78 // First request for the variable, it must be stored and executed
79 impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.insert(
80 std::make_pair(vIdentifier, std::make_pair(acqRequest.m_AcqIdentifier, QUuid())));
81 impl->unlock();
82
83 QMetaObject::invokeMethod(this, "onExecuteRequest", Qt::QueuedConnection,
84 Q_ARG(QUuid, acqRequest.m_AcqIdentifier));
85 }
86 }
87
88 void VariableAcquisitionWorker::abortProgressRequested(QUuid vIdentifier)
89 {
90 // TODO
91 }
92
93 void VariableAcquisitionWorker::onVariableRetrieveDataInProgress(QUuid acqIdentifier,
94 double progress)
95 {
96 // TODO
97 }
98
99 void VariableAcquisitionWorker::onVariableDataAcquired(QUuid acqIdentifier,
100 std::shared_ptr<IDataSeries> dataSeries,
101 SqpRange dataRangeAcquired)
25 {
102 {
103 qCDebug(LOG_VariableAcquisitionWorker()) << tr("onVariableDataAcquired on range ")
104 << acqIdentifier << dataRangeAcquired;
105 impl->lockWrite();
106 auto aIdToARit = impl->m_AcqIdentifierToAcqRequestMap.find(acqIdentifier);
107 if (aIdToARit != impl->m_AcqIdentifierToAcqRequestMap.cend()) {
108 // Store the result
109 auto dataPacket = AcquisitionDataPacket{};
110 dataPacket.m_Range = dataRangeAcquired;
111 dataPacket.m_DateSeries = dataSeries;
112
113 auto aIdToADPVit = impl->m_AcqIdentifierToAcqDataPacketVectorMap.find(acqIdentifier);
114 if (aIdToADPVit != impl->m_AcqIdentifierToAcqDataPacketVectorMap.cend()) {
115 // A current request result already exists, we can update it
116 aIdToADPVit->second.push_back(dataPacket);
117 }
118 else {
119 // First request result for the variable, it must be stored
120 impl->m_AcqIdentifierToAcqDataPacketVectorMap.insert(
121 std::make_pair(acqIdentifier, QVector<AcquisitionDataPacket>() << dataPacket));
122 }
123
124
125 // Decrement the counter of the request
126 auto &acqRequest = aIdToARit->second;
127 acqRequest.m_Size = acqRequest.m_Size - 1;
128
129 // if the counter is 0, we can return data then run the next request if it exists and
130 // removed the finished request
131 if (acqRequest.m_Size == 0) {
132 // Return the data
133 aIdToADPVit = impl->m_AcqIdentifierToAcqDataPacketVectorMap.find(acqIdentifier);
134 if (aIdToADPVit != impl->m_AcqIdentifierToAcqDataPacketVectorMap.cend()) {
135 emit dataProvided(acqRequest.m_vIdentifier, acqRequest.m_RangeRequested,
136 acqRequest.m_CacheRangeRequested, aIdToADPVit->second);
137 }
138
139 // Execute the next one
140 auto it
141 = impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(acqRequest.m_vIdentifier);
142
143 if (it != impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) {
144 if (it->second.second.isNull()) {
note

If we do so, we create a unnecessary intermediate variable. Something like : auto & varNextRequest = it->second if(varNextRequest.second.isNull()) { We gain a little bit in understanding but we lose in memory. I prefer clarify it in the comment : // There is no next request, we can remove the variable request This comment has been added later

145 // There is no next request, we can remove the varibale request
146 impl->removeVariableRequest(acqRequest.m_vIdentifier);
147 }
148 else {
149 auto acqIdentifierToRemove = it->second.first;
150 // Move the next request to the current request
151 it->second.first = it->second.second;
152 it->second.second = QUuid();
153 // Remove AcquisitionRequest and results;
154 impl->m_AcqIdentifierToAcqRequestMap.erase(acqIdentifierToRemove);
155 impl->m_AcqIdentifierToAcqDataPacketVectorMap.erase(acqIdentifierToRemove);
156 // Execute the current request
157 QMetaObject::invokeMethod(this, "onExecuteRequest", Qt::QueuedConnection,
158 Q_ARG(QUuid, it->second.first));
159 }
160 }
161 else {
162 qCCritical(LOG_VariableAcquisitionWorker())
163 << tr("Impossible to execute the acquisition on an unfound variable ");
164 }
165 }
166 }
167 else {
168 qCCritical(LOG_VariableAcquisitionWorker())
169 << tr("Impossible to retrieve AcquisitionRequest for the incoming data");
170 }
171 impl->unlock();
172 }
173
174 void VariableAcquisitionWorker::onExecuteRequest(QUuid acqIdentifier)
175 {
176 qCDebug(LOG_VariableAcquisitionWorker()) << tr("onExecuteRequest") << QThread::currentThread();
177 impl->lockRead();
178 auto it = impl->m_AcqIdentifierToAcqRequestMap.find(acqIdentifier);
179 if (it != impl->m_AcqIdentifierToAcqRequestMap.cend()) {
180 auto request = it->second;
181 impl->unlock();
182 request.m_Provider->requestDataLoading(acqIdentifier, request.m_DataProviderParameters);
183 }
184 else {
185 impl->unlock();
186 // TODO log no acqIdentifier recognized
187 }
188 }
189
190 void VariableAcquisitionWorker::initialize()
191 {
192 qCDebug(LOG_VariableAcquisitionWorker()) << tr("VariableAcquisitionWorker init")
193 << QThread::currentThread();
194 impl->m_WorkingMutex.lock();
195 qCDebug(LOG_VariableAcquisitionWorker()) << tr("VariableAcquisitionWorker init END");
196 }
197
198 void VariableAcquisitionWorker::finalize()
199 {
200 impl->m_WorkingMutex.unlock();
201 }
202
203 void VariableAcquisitionWorker::waitForFinish()
204 {
205 QMutexLocker locker{&impl->m_WorkingMutex};
206 }
207
208 void VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate::removeVariableRequest(
209 QUuid vIdentifier)
210 {
211 lockWrite();
212 auto it = m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(vIdentifier);
213
214 if (it != m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) {
215 // A current request already exists, we can replace the next one
216
217 m_AcqIdentifierToAcqRequestMap.erase(it->second.first);
218 m_AcqIdentifierToAcqDataPacketVectorMap.erase(it->second.first);
219
220 m_AcqIdentifierToAcqRequestMap.erase(it->second.second);
221 m_AcqIdentifierToAcqDataPacketVectorMap.erase(it->second.second);
222 }
223 m_VIdentifierToCurrrentAcqIdNextIdPairMap.erase(vIdentifier);
224 unlock();
26 }
225 }
@@ -1,7 +1,10
1 #include <Variable/Variable.h>
1 #include <Variable/Variable.h>
2 #include <Variable/VariableAcquisitionWorker.h>
2 #include <Variable/VariableCacheController.h>
3 #include <Variable/VariableCacheController.h>
4 #include <Variable/VariableCacheStrategy.h>
3 #include <Variable/VariableController.h>
5 #include <Variable/VariableController.h>
4 #include <Variable/VariableModel.h>
6 #include <Variable/VariableModel.h>
7 #include <Variable/VariableSynchronizationGroup.h>
5
8
6 #include <Data/DataProviderParameters.h>
9 #include <Data/DataProviderParameters.h>
7 #include <Data/IDataProvider.h>
10 #include <Data/IDataProvider.h>
@@ -13,22 +16,97
13 #include <QUuid>
16 #include <QUuid>
14 #include <QtCore/QItemSelectionModel>
17 #include <QtCore/QItemSelectionModel>
15
18
19 #include <set>
16 #include <unordered_map>
20 #include <unordered_map>
17
21
18 Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController")
22 Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController")
19
23
24 namespace {
25
26 SqpRange computeSynchroRangeRequested(const SqpRange &varRange, const SqpRange &grapheRange,
note

ok

27 const SqpRange &oldGraphRange)
28 {
29 auto zoomType = VariableController::getZoomType(grapheRange, oldGraphRange);
30
31 auto varRangeRequested = varRange;
32 switch (zoomType) {
33 case AcquisitionZoomType::ZoomIn: {
34 auto deltaLeft = grapheRange.m_TStart - oldGraphRange.m_TStart;
35 auto deltaRight = oldGraphRange.m_TEnd - grapheRange.m_TEnd;
36 varRangeRequested.m_TStart += deltaLeft;
37 varRangeRequested.m_TEnd -= deltaRight;
38 break;
39 }
40
41 case AcquisitionZoomType::ZoomOut: {
42 auto deltaLeft = oldGraphRange.m_TStart - grapheRange.m_TStart;
43 auto deltaRight = grapheRange.m_TEnd - oldGraphRange.m_TEnd;
44 varRangeRequested.m_TStart -= deltaLeft;
45 varRangeRequested.m_TEnd += deltaRight;
46 break;
47 }
48 case AcquisitionZoomType::PanRight: {
49 auto deltaRight = grapheRange.m_TEnd - oldGraphRange.m_TEnd;
50 varRangeRequested.m_TStart += deltaRight;
51 varRangeRequested.m_TEnd += deltaRight;
52 break;
53 }
54 case AcquisitionZoomType::PanLeft: {
55 auto deltaLeft = oldGraphRange.m_TStart - grapheRange.m_TStart;
56 varRangeRequested.m_TStart -= deltaLeft;
57 varRangeRequested.m_TEnd -= deltaLeft;
58 break;
59 }
60 case AcquisitionZoomType::Unknown: {
61 qCCritical(LOG_VariableController())
62 << VariableController::tr("Impossible to synchronize: zoom type unknown");
63 break;
64 }
65 default:
66 qCCritical(LOG_VariableController()) << VariableController::tr(
67 "Impossible to synchronize: zoom type not take into account");
68 // No action
69 break;
70 }
71
72 return varRangeRequested;
73 }
74 }
75
20 struct VariableController::VariableControllerPrivate {
76 struct VariableController::VariableControllerPrivate {
21 explicit VariableControllerPrivate(VariableController *parent)
77 explicit VariableControllerPrivate(VariableController *parent)
22 : m_WorkingMutex{},
78 : m_WorkingMutex{},
23 m_VariableModel{new VariableModel{parent}},
79 m_VariableModel{new VariableModel{parent}},
24 m_VariableSelectionModel{new QItemSelectionModel{m_VariableModel, parent}},
80 m_VariableSelectionModel{new QItemSelectionModel{m_VariableModel, parent}},
25 m_VariableCacheController{std::make_unique<VariableCacheController>()}
81 m_VariableCacheController{std::make_unique<VariableCacheController>()},
82 m_VariableCacheStrategy{std::make_unique<VariableCacheStrategy>()},
83 m_VariableAcquisitionWorker{std::make_unique<VariableAcquisitionWorker>()}
84 {
85
86 m_VariableAcquisitionWorker->moveToThread(&m_VariableAcquisitionWorkerThread);
87 m_VariableAcquisitionWorkerThread.setObjectName("VariableAcquisitionWorkerThread");
88 }
89
90
91 virtual ~VariableControllerPrivate()
26 {
92 {
93 qCDebug(LOG_VariableController()) << tr("VariableControllerPrivate destruction");
94 m_VariableAcquisitionWorkerThread.quit();
95 m_VariableAcquisitionWorkerThread.wait();
27 }
96 }
28
97
98
99 void processRequest(std::shared_ptr<Variable> var, const SqpRange &rangeRequested);
100
29 QVector<SqpRange> provideNotInCacheDateTimeList(std::shared_ptr<Variable> variable,
101 QVector<SqpRange> provideNotInCacheDateTimeList(std::shared_ptr<Variable> variable,
30 const SqpRange &dateTime);
102 const SqpRange &dateTime);
31
103
104 std::shared_ptr<Variable> findVariable(QUuid vIdentifier);
105 std::shared_ptr<IDataSeries>
106 retrieveDataSeries(const QVector<AcquisitionDataPacket> acqDataPacketVector);
107
108 void registerProvider(std::shared_ptr<IDataProvider> provider);
109
32 QMutex m_WorkingMutex;
110 QMutex m_WorkingMutex;
33 /// Variable model. The VariableController has the ownership
111 /// Variable model. The VariableController has the ownership
34 VariableModel *m_VariableModel;
112 VariableModel *m_VariableModel;
@@ -37,12 +115,20 struct VariableController::VariableControllerPrivate {
37
115
38 TimeController *m_TimeController{nullptr};
116 TimeController *m_TimeController{nullptr};
39 std::unique_ptr<VariableCacheController> m_VariableCacheController;
117 std::unique_ptr<VariableCacheController> m_VariableCacheController;
118 std::unique_ptr<VariableCacheStrategy> m_VariableCacheStrategy;
119 std::unique_ptr<VariableAcquisitionWorker> m_VariableAcquisitionWorker;
120 QThread m_VariableAcquisitionWorkerThread;
40
121
41 std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> >
122 std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> >
42 m_VariableToProviderMap;
123 m_VariableToProviderMap;
43 std::unordered_map<std::shared_ptr<Variable>, QUuid> m_VariableToIdentifierMap;
124 std::unordered_map<std::shared_ptr<Variable>, QUuid> m_VariableToIdentifierMap;
125 std::map<QUuid, std::shared_ptr<VariableSynchronizationGroup> >
126 m_GroupIdToVariableSynchronizationGroupMap;
127 std::map<QUuid, QUuid> m_VariableIdGroupIdMap;
128 std::set<std::shared_ptr<IDataProvider> > m_ProviderSet;
44 };
129 };
45
130
131
46 VariableController::VariableController(QObject *parent)
132 VariableController::VariableController(QObject *parent)
47 : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)}
133 : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)}
48 {
134 {
@@ -51,6 +137,20 VariableController::VariableController(QObject *parent)
51
137
52 connect(impl->m_VariableModel, &VariableModel::abortProgessRequested, this,
138 connect(impl->m_VariableModel, &VariableModel::abortProgessRequested, this,
53 &VariableController::onAbortProgressRequested);
139 &VariableController::onAbortProgressRequested);
140
141 connect(impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::dataProvided, this,
142 &VariableController::onDataProvided);
143 connect(impl->m_VariableAcquisitionWorker.get(),
144 &VariableAcquisitionWorker::variableRequestInProgress, this,
145 &VariableController::onVariableRetrieveDataInProgress);
146
147 connect(&impl->m_VariableAcquisitionWorkerThread, &QThread::started,
148 impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::initialize);
149 connect(&impl->m_VariableAcquisitionWorkerThread, &QThread::finished,
150 impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::finalize);
151
152
153 impl->m_VariableAcquisitionWorkerThread.start();
54 }
154 }
55
155
56 VariableController::~VariableController()
156 VariableController::~VariableController()
@@ -124,45 +224,34 void VariableController::createVariable(const QString &name, const QVariantHash
124 return;
224 return;
125 }
225 }
126
226
127 auto dateTime = impl->m_TimeController->dateTime();
227 auto range = impl->m_TimeController->dateTime();
128
228
129 if (auto newVariable = impl->m_VariableModel->createVariable(name, dateTime, metadata)) {
229 if (auto newVariable = impl->m_VariableModel->createVariable(name, range, metadata)) {
130 auto identifier = QUuid::createUuid();
230 auto identifier = QUuid::createUuid();
131
231
132 // store the provider
232 // store the provider
233 impl->registerProvider(provider);
234
235 // Associate the provider
133 impl->m_VariableToProviderMap[newVariable] = provider;
236 impl->m_VariableToProviderMap[newVariable] = provider;
134 impl->m_VariableToIdentifierMap[newVariable] = identifier;
237 impl->m_VariableToIdentifierMap[newVariable] = identifier;
135
238
136 auto addDateTimeAcquired = [ this, varW = std::weak_ptr<Variable>{newVariable} ](
137 QUuid identifier, auto dataSeriesAcquired, auto dateTimeToPutInCache)
138 {
139 if (auto variable = varW.lock()) {
140 auto varIdentifier = impl->m_VariableToIdentifierMap.at(variable);
141 if (varIdentifier == identifier) {
142 impl->m_VariableCacheController->addDateTime(variable, dateTimeToPutInCache);
143 variable->setDataSeries(dataSeriesAcquired);
144 emit variable->updated();
145 }
146 }
147 };
148
239
149 connect(provider.get(), &IDataProvider::dataProvided, addDateTimeAcquired);
240 impl->processRequest(newVariable, range);
150 connect(provider.get(), &IDataProvider::dataProvidedProgress, this,
151 &VariableController::onVariableRetrieveDataInProgress);
152 this->onRequestDataLoading(newVariable, dateTime);
153 }
241 }
154 }
242 }
155
243
156 void VariableController::onDateTimeOnSelection(const SqpRange &dateTime)
244 void VariableController::onDateTimeOnSelection(const SqpRange &dateTime)
157 {
245 {
246 // TODO check synchronisation
158 qCDebug(LOG_VariableController()) << "VariableController::onDateTimeOnSelection"
247 qCDebug(LOG_VariableController()) << "VariableController::onDateTimeOnSelection"
159 << QThread::currentThread()->objectName();
248 << QThread::currentThread()->objectName();
160 auto selectedRows = impl->m_VariableSelectionModel->selectedRows();
249 auto selectedRows = impl->m_VariableSelectionModel->selectedRows();
161
250
162 for (const auto &selectedRow : qAsConst(selectedRows)) {
251 for (const auto &selectedRow : qAsConst(selectedRows)) {
163 if (auto selectedVariable = impl->m_VariableModel->variable(selectedRow.row())) {
252 if (auto selectedVariable = impl->m_VariableModel->variable(selectedRow.row())) {
164 selectedVariable->setDateTime(dateTime);
253 selectedVariable->setRange(dateTime);
165 this->onRequestDataLoading(selectedVariable, dateTime);
254 impl->processRequest(selectedVariable, dateTime);
166
255
167 // notify that rescale operation has to be done
256 // notify that rescale operation has to be done
168 emit rangeChanged(selectedVariable, dateTime);
257 emit rangeChanged(selectedVariable, dateTime);
@@ -170,14 +259,39 void VariableController::onDateTimeOnSelection(const SqpRange &dateTime)
170 }
259 }
171 }
260 }
172
261
173 void VariableController::onVariableRetrieveDataInProgress(QUuid identifier, double progress)
262 void VariableController::onDataProvided(QUuid vIdentifier, const SqpRange &rangeRequested,
263 const SqpRange &cacheRangeRequested,
264 QVector<AcquisitionDataPacket> dataAcquired)
174 {
265 {
175 auto findReply = [identifier](const auto &entry) { return identifier == entry.second; };
266 qCCritical(LOG_VariableController()) << tr("onDataProvided") << dataAcquired.isEmpty();
note

The comment has been remove later.

176
267
177 auto end = impl->m_VariableToIdentifierMap.cend();
268 auto var = impl->findVariable(vIdentifier);
178 auto it = std::find_if(impl->m_VariableToIdentifierMap.cbegin(), end, findReply);
269 if (var != nullptr) {
note

ok

179 if (it != end) {
270 var->setRange(rangeRequested);
180 impl->m_VariableModel->setDataProgress(it->first, progress);
271 var->setCacheRange(cacheRangeRequested);
272 qCCritical(LOG_VariableController()) << tr("1: onDataProvided") << rangeRequested;
273 qCCritical(LOG_VariableController()) << tr("2: onDataProvided") << cacheRangeRequested;
274
275 auto retrievedDataSeries = impl->retrieveDataSeries(dataAcquired);
276 qCCritical(LOG_VariableController()) << tr("3: onDataProvided")
277 << retrievedDataSeries->range();
278 var->mergeDataSeries(retrievedDataSeries);
279 emit var->updated();
280 }
281 else {
282 qCCritical(LOG_VariableController()) << tr("Impossible to provide data to a null variable");
283 }
284 }
285
286 void VariableController::onVariableRetrieveDataInProgress(QUuid identifier, double progress)
287 {
288 auto var = impl->findVariable(identifier);
289 if (var != nullptr) {
note

ok

290 impl->m_VariableModel->setDataProgress(var, progress);
291 }
292 else {
293 qCCritical(LOG_VariableController())
294 << tr("Impossible to notify progression of a null variable");
181 }
295 }
182 }
296 }
183
297
@@ -197,33 +311,74 void VariableController::onAbortProgressRequested(std::shared_ptr<Variable> vari
197 }
311 }
198 }
312 }
199
313
314 void VariableController::onAddSynchronizationGroupId(QUuid synchronizationGroupId)
315 {
316 auto vSynchroGroup = std::make_shared<VariableSynchronizationGroup>();
317 impl->m_GroupIdToVariableSynchronizationGroupMap.insert(
318 std::make_pair(synchronizationGroupId, vSynchroGroup));
319 }
200
320
201 void VariableController::onRequestDataLoading(std::shared_ptr<Variable> variable,
321 void VariableController::onRemoveSynchronizationGroupId(QUuid synchronizationGroupId)
202 const SqpRange &dateTime)
203 {
322 {
323 impl->m_GroupIdToVariableSynchronizationGroupMap.erase(synchronizationGroupId);
324 }
325
326
327 void VariableController::onRequestDataLoading(QVector<std::shared_ptr<Variable> > variables,
328 const SqpRange &range, const SqpRange &oldRange,
329 bool synchronise)
330 {
331 // NOTE: oldRange isn't really necessary since oldRange == variable->range().
332
204 qCDebug(LOG_VariableController()) << "VariableController::onRequestDataLoading"
333 qCDebug(LOG_VariableController()) << "VariableController::onRequestDataLoading"
205 << QThread::currentThread()->objectName();
334 << QThread::currentThread()->objectName();
206 // we want to load data of the variable for the dateTime.
335 // we want to load data of the variable for the dateTime.
207 // First we check if the cache contains some of them.
336 // First we check if the cache contains some of them.
208 // For the other, we ask the provider to give them.
337 // For the other, we ask the provider to give them.
209 if (variable) {
210
338
211 auto dateTimeListNotInCache
339 foreach (auto var, variables) {
note

Right

212 = impl->m_VariableCacheController->provideNotInCacheDateTimeList(variable, dateTime);
340 qCInfo(LOG_VariableController()) << "processRequest for" << var->name();
341 impl->processRequest(var, range);
342 }
213
343
214 if (!dateTimeListNotInCache.empty()) {
344 if (synchronise) {
215 // Ask the provider for each data on the dateTimeListNotInCache
345 // Get the group ids
216 auto identifier = impl->m_VariableToIdentifierMap.at(variable);
346 qCInfo(LOG_VariableController())
217 impl->m_VariableToProviderMap.at(variable)->requestDataLoading(
347 << "VariableController::onRequestDataLoading for synchro var ENABLE";
218 identifier,
348 auto groupIds = std::set<QUuid>();
219 DataProviderParameters{std::move(dateTimeListNotInCache), variable->metadata()});
349 foreach (auto var, variables) {
note

ok

350 auto vToVIdit = impl->m_VariableToIdentifierMap.find(var);
351 if (vToVIdit != impl->m_VariableToIdentifierMap.cend()) {
note

Yes, I found the same and changed it for varToVarIdIt

352 auto vId = vToVIdit->second;
353
354 auto vIdToGIdit = impl->m_VariableIdGroupIdMap.find(vId);
355 if (vIdToGIdit != impl->m_VariableIdGroupIdMap.cend()) {
356 auto gId = vToVIdit->second;
357 if (groupIds.find(gId) == groupIds.cend()) {
358 groupIds.insert(gId);
359 }
360 }
220 }
361 }
221 else {
222 emit variable->updated();
223 }
362 }
363
364 // We assume here all group ids exist
365 foreach (auto gId, groupIds) {
366 auto vSynchronizationGroup = impl->m_GroupIdToVariableSynchronizationGroupMap.at(gId);
367 auto vSyncIds = vSynchronizationGroup->getIds();
368 for (auto vId : vSyncIds) {
369 auto var = impl->findVariable(vId);
370 if (var != nullptr) {
371 qCInfo(LOG_VariableController()) << "processRequest synchro for" << var->name();
372 auto vSyncRangeRequested
373 = computeSynchroRangeRequested(var->range(), range, oldRange);
374 impl->processRequest(var, vSyncRangeRequested);
224 }
375 }
225 else {
376 else {
226 qCCritical(LOG_VariableController()) << tr("Impossible to load data of a variable null");
377 qCCritical(LOG_VariableController())
378 << tr("Impossible to synchronize a null variable");
379 }
380 }
381 }
227 }
382 }
228 }
383 }
229
384
@@ -245,32 +400,109 void VariableController::waitForFinish()
245 QMutexLocker locker{&impl->m_WorkingMutex};
400 QMutexLocker locker{&impl->m_WorkingMutex};
246 }
401 }
247
402
403 AcquisitionZoomType VariableController::getZoomType(const SqpRange &range, const SqpRange &oldRange)
404 {
405 // t1.m_TStart <= t2.m_TStart && t2.m_TEnd <= t1.m_TEnd
406 auto zoomType = AcquisitionZoomType::Unknown;
407 if (range.m_TStart <= oldRange.m_TStart && oldRange.m_TEnd <= range.m_TEnd) {
408 zoomType = AcquisitionZoomType::ZoomOut;
409 }
410 else if (range.m_TStart > oldRange.m_TStart && range.m_TEnd > oldRange.m_TEnd) {
411 zoomType = AcquisitionZoomType::PanRight;
412 }
413 else if (range.m_TStart < oldRange.m_TStart && range.m_TEnd < oldRange.m_TEnd) {
414 zoomType = AcquisitionZoomType::PanLeft;
415 }
416 else if (range.m_TStart > oldRange.m_TStart && oldRange.m_TEnd > range.m_TEnd) {
417 zoomType = AcquisitionZoomType::ZoomIn;
418 }
419 else {
420 qCCritical(LOG_VariableController()) << "getZoomType: Unknown type detected";
421 }
422 return zoomType;
423 }
248
424
249 QVector<SqpRange> VariableController::VariableControllerPrivate::provideNotInCacheDateTimeList(
425 void VariableController::VariableControllerPrivate::processRequest(std::shared_ptr<Variable> var,
250 std::shared_ptr<Variable> variable, const SqpRange &dateTime)
426 const SqpRange &rangeRequested)
251 {
427 {
252 auto notInCache = QVector<SqpRange>{};
253
428
254 if (!variable->contains(dateTime)) {
429 auto varRangesRequested
255 auto vDateTime = variable->dateTime();
430 = m_VariableCacheStrategy->computeCacheRange(var->range(), rangeRequested);
256 if (dateTime.m_TEnd <= vDateTime.m_TStart || dateTime.m_TStart >= vDateTime.m_TEnd) {
431 auto notInCacheRangeList = var->provideNotInCacheRangeList(varRangesRequested.second);
257 notInCache << dateTime;
432
433 if (!notInCacheRangeList.empty()) {
434 // Display part of data which are already there
435 // Ask the provider for each data on the dateTimeListNotInCache
436 auto identifier = m_VariableToIdentifierMap.at(var);
437 auto varProvider = m_VariableToProviderMap.at(var);
438 if (varProvider != nullptr) {
439 m_VariableAcquisitionWorker->pushVariableRequest(
440 identifier, varRangesRequested.first, varRangesRequested.second,
441 DataProviderParameters{std::move(notInCacheRangeList), var->metadata()},
442 varProvider);
443 }
444 else {
445 qCCritical(LOG_VariableController())
446 << "Impossible to provide data with a null provider";
447 }
258 }
448 }
259 else if (dateTime.m_TStart < vDateTime.m_TStart && dateTime.m_TEnd <= vDateTime.m_TEnd) {
449 else {
260 notInCache << SqpRange{dateTime.m_TStart, vDateTime.m_TStart};
450 var->setRange(rangeRequested);
451 var->setCacheRange(varRangesRequested.second);
452 var->setDataSeries(var->dataSeries()->subData(varRangesRequested.second));
453 emit var->updated();
261 }
454 }
262 else if (dateTime.m_TStart < vDateTime.m_TStart && dateTime.m_TEnd > vDateTime.m_TEnd) {
263 notInCache << SqpRange{dateTime.m_TStart, vDateTime.m_TStart}
264 << SqpRange{vDateTime.m_TEnd, dateTime.m_TStart};
265 }
455 }
266 else if (dateTime.m_TStart < vDateTime.m_TEnd) {
456
267 notInCache << SqpRange{vDateTime.m_TEnd, dateTime.m_TStart};
457 std::shared_ptr<Variable>
458 VariableController::VariableControllerPrivate::findVariable(QUuid vIdentifier)
459 {
460 std::shared_ptr<Variable> var;
461 auto findReply = [vIdentifier](const auto &entry) { return vIdentifier == entry.second; };
462
463 auto end = m_VariableToIdentifierMap.cend();
464 auto it = std::find_if(m_VariableToIdentifierMap.cbegin(), end, findReply);
465 if (it != end) {
466 var = it->first;
268 }
467 }
269 else {
468 else {
270 qCCritical(LOG_VariableController()) << tr("Detection of unknown case.")
469 qCCritical(LOG_VariableController())
271 << QThread::currentThread();
470 << tr("Impossible to find the variable with the identifier: ") << vIdentifier;
471 }
472
473 return var;
474 }
475
476 std::shared_ptr<IDataSeries> VariableController::VariableControllerPrivate::retrieveDataSeries(
477 const QVector<AcquisitionDataPacket> acqDataPacketVector)
478 {
479 qCInfo(LOG_VariableController()) << tr("TORM: retrieveDataSeries acqDataPacketVector size")
480 << acqDataPacketVector.size();
481 std::shared_ptr<IDataSeries> dataSeries;
482 if (!acqDataPacketVector.isEmpty()) {
483 dataSeries = acqDataPacketVector[0].m_DateSeries;
484 for (int i = 1; i < acqDataPacketVector.size(); ++i) {
485 dataSeries->merge(acqDataPacketVector[i].m_DateSeries.get());
272 }
486 }
273 }
487 }
274
488
275 return notInCache;
489 return dataSeries;
490 }
491
492 void VariableController::VariableControllerPrivate::registerProvider(
493 std::shared_ptr<IDataProvider> provider)
494 {
495 if (m_ProviderSet.find(provider) == m_ProviderSet.end()) {
496 qCInfo(LOG_VariableController()) << tr("Registering of a new provider")
497 << provider->objectName();
498 m_ProviderSet.insert(provider);
499 connect(provider.get(), &IDataProvider::dataProvided, m_VariableAcquisitionWorker.get(),
500 &VariableAcquisitionWorker::onVariableDataAcquired);
501 connect(provider.get(), &IDataProvider::dataProvidedProgress,
502 m_VariableAcquisitionWorker.get(),
503 &VariableAcquisitionWorker::onVariableRetrieveDataInProgress);
504 }
505 else {
506 qCInfo(LOG_VariableController()) << tr("Cannot register provider, it already exists ");
507 }
276 }
508 }
@@ -16,11 +16,6 class QCPRange;
16 class SqpRange;
16 class SqpRange;
17 class Variable;
17 class Variable;
18
18
19 /**
20 * Possible types of zoom operation
21 */
22 enum class VisualizationGraphWidgetZoomType { ZoomOut, ZoomIn, PanRight, PanLeft, Unknown };
23
24 namespace Ui {
19 namespace Ui {
25 class VisualizationGraphWidget;
20 class VisualizationGraphWidget;
26 } // namespace Ui
21 } // namespace Ui
@@ -32,7 +27,8 public:
32 explicit VisualizationGraphWidget(const QString &name = {}, QWidget *parent = 0);
27 explicit VisualizationGraphWidget(const QString &name = {}, QWidget *parent = 0);
33 virtual ~VisualizationGraphWidget();
28 virtual ~VisualizationGraphWidget();
34
29
35 void enableSynchronize(bool enable);
30 /// If acquisition isn't enable, requestDataLoading signal cannot be emit
31 void enableAcquisition(bool enable);
36
32
37 void addVariable(std::shared_ptr<Variable> variable);
33 void addVariable(std::shared_ptr<Variable> variable);
38 void addVariableUsingGraph(std::shared_ptr<Variable> variable);
34 void addVariableUsingGraph(std::shared_ptr<Variable> variable);
@@ -51,9 +47,9 public:
51
47
52
48
53 signals:
49 signals:
54 void requestDataLoading(std::shared_ptr<Variable> variable, const SqpRange &dateTime);
50 void synchronize(const SqpRange &range, const SqpRange &oldRange);
55 void synchronize(const SqpRange &dateTime, const SqpRange &oldDateTime,
51 void requestDataLoading(QVector<std::shared_ptr<Variable> > variable, const SqpRange &range,
56 VisualizationGraphWidgetZoomType zoomType);
52 const SqpRange &oldRange, bool synchronise);
57
53
58
54
59 private:
55 private:
@@ -6,6 +6,10
6 #include <QLoggingCategory>
6 #include <QLoggingCategory>
7 #include <QWidget>
7 #include <QWidget>
8
8
9 #include <memory>
10
11 #include <Common/spimpl.h>
12
9 Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationZoneWidget)
13 Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationZoneWidget)
10
14
11 namespace Ui {
15 namespace Ui {
@@ -40,6 +44,9 public:
40
44
41 private:
45 private:
42 Ui::VisualizationZoneWidget *ui;
46 Ui::VisualizationZoneWidget *ui;
47
48 class VisualizationZoneWidgetPrivate;
49 spimpl::unique_impl_ptr<VisualizationZoneWidgetPrivate> impl;
43 };
50 };
44
51
45 #endif // SCIQLOP_VISUALIZATIONZONEWIDGET_H
52 #endif // SCIQLOP_VISUALIZATIONZONEWIDGET_H
@@ -60,7 +60,7 public:
60
60
61 virtual ~SqpApplicationPrivate()
61 virtual ~SqpApplicationPrivate()
62 {
62 {
63 qCInfo(LOG_SqpApplication()) << tr("SqpApplicationPrivate destruction");
63 qCDebug(LOG_SqpApplication()) << tr("SqpApplicationPrivate destruction");
64 m_DataSourceControllerThread.quit();
64 m_DataSourceControllerThread.quit();
65 m_DataSourceControllerThread.wait();
65 m_DataSourceControllerThread.wait();
66
66
@@ -23,28 +23,18 const auto HORIZONTAL_ZOOM_MODIFIER = Qt::NoModifier;
23 /// Key pressed to enable zoom on vertical axis
23 /// Key pressed to enable zoom on vertical axis
24 const auto VERTICAL_ZOOM_MODIFIER = Qt::ControlModifier;
24 const auto VERTICAL_ZOOM_MODIFIER = Qt::ControlModifier;
25
25
26 /// Gets a tolerance value from application settings. If the setting can't be found, the default
27 /// value passed in parameter is returned
28 double toleranceValue(const QString &key, double defaultValue) noexcept
29 {
30 return QSettings{}.value(key, defaultValue).toDouble();
31 }
32
33 } // namespace
26 } // namespace
34
27
35 struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate {
28 struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate {
36
29
37 explicit VisualizationGraphWidgetPrivate()
30 explicit VisualizationGraphWidgetPrivate()
38 : m_DoSynchronize{true}, m_IsCalibration{false}, m_RenderingDelegate{nullptr}
31 : m_DoAcquisition{true}, m_IsCalibration{false}, m_RenderingDelegate{nullptr}
39 {
32 {
40 }
33 }
41
34
42 // Return the operation when range changed
43 VisualizationGraphWidgetZoomType getZoomType(const QCPRange &t1, const QCPRange &t2);
44
45 // 1 variable -> n qcpplot
35 // 1 variable -> n qcpplot
46 std::multimap<std::shared_ptr<Variable>, QCPAbstractPlottable *> m_VariableToPlotMultiMap;
36 std::multimap<std::shared_ptr<Variable>, QCPAbstractPlottable *> m_VariableToPlotMultiMap;
47 bool m_DoSynchronize;
37 bool m_DoAcquisition;
48 bool m_IsCalibration;
38 bool m_IsCalibration;
49 QCPItemTracer *m_TextTracer;
39 QCPItemTracer *m_TextTracer;
50 /// Delegate used to attach rendering features to the plot
40 /// Delegate used to attach rendering features to the plot
@@ -98,9 +88,9 VisualizationGraphWidget::~VisualizationGraphWidget()
98 delete ui;
88 delete ui;
99 }
89 }
100
90
101 void VisualizationGraphWidget::enableSynchronize(bool enable)
91 void VisualizationGraphWidget::enableAcquisition(bool enable)
102 {
92 {
103 impl->m_DoSynchronize = enable;
93 impl->m_DoAcquisition = enable;
104 }
94 }
105
95
106 void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable)
96 void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable)
@@ -116,32 +106,33 void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable)
116 }
106 }
117 void VisualizationGraphWidget::addVariableUsingGraph(std::shared_ptr<Variable> variable)
107 void VisualizationGraphWidget::addVariableUsingGraph(std::shared_ptr<Variable> variable)
118 {
108 {
109 // TODO
110 // // when adding a variable, we need to set its time range to the current graph range
111 // auto grapheRange = ui->widget->xAxis->range();
112 // auto dateTime = SqpRange{grapheRange.lower, grapheRange.upper};
113 // variable->setDateTime(dateTime);
114
115 // auto variableDateTimeWithTolerance = dateTime;
116
117 // // add tolerance for each side
118 // auto toleranceFactor
119 // = toleranceValue(GENERAL_TOLERANCE_AT_INIT_KEY,
120 // GENERAL_TOLERANCE_AT_INIT_DEFAULT_VALUE);
121 // auto tolerance = toleranceFactor * (dateTime.m_TEnd - dateTime.m_TStart);
122 // variableDateTimeWithTolerance.m_TStart -= tolerance;
123 // variableDateTimeWithTolerance.m_TEnd += tolerance;
124
125 // // Uses delegate to create the qcpplot components according to the variable
126 // auto createdPlottables = VisualizationGraphHelper::create(variable, *ui->widget);
127
128 // for (auto createdPlottable : qAsConst(createdPlottables)) {
129 // impl->m_VariableToPlotMultiMap.insert({variable, createdPlottable});
130 // }
119
131
120 // when adding a variable, we need to set its time range to the current graph range
132 // connect(variable.get(), SIGNAL(updated()), this, SLOT(onDataCacheVariableUpdated()));
121 auto grapheRange = ui->widget->xAxis->range();
122 auto dateTime = SqpRange{grapheRange.lower, grapheRange.upper};
123 variable->setDateTime(dateTime);
124
125 auto variableDateTimeWithTolerance = dateTime;
126
127 // add tolerance for each side
128 auto toleranceFactor
129 = toleranceValue(GENERAL_TOLERANCE_AT_INIT_KEY, GENERAL_TOLERANCE_AT_INIT_DEFAULT_VALUE);
130 auto tolerance = toleranceFactor * (dateTime.m_TEnd - dateTime.m_TStart);
131 variableDateTimeWithTolerance.m_TStart -= tolerance;
132 variableDateTimeWithTolerance.m_TEnd += tolerance;
133
134 // Uses delegate to create the qcpplot components according to the variable
135 auto createdPlottables = VisualizationGraphHelper::create(variable, *ui->widget);
136
137 for (auto createdPlottable : qAsConst(createdPlottables)) {
138 impl->m_VariableToPlotMultiMap.insert({variable, createdPlottable});
139 }
140
141 connect(variable.get(), SIGNAL(updated()), this, SLOT(onDataCacheVariableUpdated()));
142
133
143 // CHangement detected, we need to ask controller to request data loading
134 // // CHangement detected, we need to ask controller to request data loading
144 emit requestDataLoading(variable, variableDateTimeWithTolerance);
135 // emit requestDataLoading(variable, variableDateTimeWithTolerance);
145 }
136 }
146
137
147 void VisualizationGraphWidget::removeVariable(std::shared_ptr<Variable> variable) noexcept
138 void VisualizationGraphWidget::removeVariable(std::shared_ptr<Variable> variable) noexcept
@@ -239,102 +230,30 void VisualizationGraphWidget::onGraphMenuRequested(const QPoint &pos) noexcept
239
230
240 void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange &t2)
231 void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange &t2)
241 {
232 {
242 qCInfo(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::onRangeChanged")
233 qCDebug(LOG_VisualizationGraphWidget()) << tr("TORM: VisualizationGraphWidget::onRangeChanged")
243 << QThread::currentThread()->objectName();
234 << QThread::currentThread()->objectName() << "DoAcqui"
235 << impl->m_DoAcquisition;
244
236
245 auto dateTimeRange = SqpRange{t1.lower, t1.upper};
237 auto graphRange = SqpRange{t1.lower, t1.upper};
238 auto oldGraphRange = SqpRange{t2.lower, t2.upper};
246
239
247 auto zoomType = impl->getZoomType(t1, t2);
240 if (impl->m_DoAcquisition) {
248 for (auto it = impl->m_VariableToPlotMultiMap.cbegin();
241 QVector<std::shared_ptr<Variable> > variableUnderGraphVector;
249 it != impl->m_VariableToPlotMultiMap.cend(); ++it) {
250
251 auto variable = it->first;
252 auto currentDateTime = dateTimeRange;
253
254 auto toleranceFactor = toleranceValue(GENERAL_TOLERANCE_AT_UPDATE_KEY,
255 GENERAL_TOLERANCE_AT_UPDATE_DEFAULT_VALUE);
256 auto tolerance = toleranceFactor * (currentDateTime.m_TEnd - currentDateTime.m_TStart);
257 auto variableDateTimeWithTolerance = currentDateTime;
258 variableDateTimeWithTolerance.m_TStart -= tolerance;
259 variableDateTimeWithTolerance.m_TEnd += tolerance;
260
261 qCDebug(LOG_VisualizationGraphWidget()) << "r" << currentDateTime;
262 qCDebug(LOG_VisualizationGraphWidget()) << "t" << variableDateTimeWithTolerance;
263 qCDebug(LOG_VisualizationGraphWidget()) << "v" << variable->dateTime();
264 // If new range with tol is upper than variable datetime parameters. we need to request new
265 // data
266 if (!variable->contains(variableDateTimeWithTolerance)) {
267
268 auto variableDateTimeWithTolerance = currentDateTime;
269 if (!variable->isInside(currentDateTime)) {
270 auto variableDateTime = variable->dateTime();
271 if (variable->contains(variableDateTimeWithTolerance)) {
272 qCDebug(LOG_VisualizationGraphWidget())
273 << tr("TORM: Detection zoom in that need request:");
274 // add tolerance for each side
275 tolerance
276 = toleranceFactor * (currentDateTime.m_TEnd - currentDateTime.m_TStart);
277 variableDateTimeWithTolerance.m_TStart -= tolerance;
278 variableDateTimeWithTolerance.m_TEnd += tolerance;
279 }
280 else if (variableDateTime.m_TStart < currentDateTime.m_TStart) {
281 qCInfo(LOG_VisualizationGraphWidget()) << tr("TORM: Detection pan to right:");
282
283 auto diffEndToKeepDelta = currentDateTime.m_TEnd - variableDateTime.m_TEnd;
284 currentDateTime.m_TStart = variableDateTime.m_TStart + diffEndToKeepDelta;
285 // Tolerance have to be added to the right
286 // add tolerance for right (end) side
287 tolerance
288 = toleranceFactor * (currentDateTime.m_TEnd - currentDateTime.m_TStart);
289 variableDateTimeWithTolerance.m_TEnd += tolerance;
290 }
291 else if (variableDateTime.m_TEnd > currentDateTime.m_TEnd) {
292 qCDebug(LOG_VisualizationGraphWidget()) << tr("TORM: Detection pan to left: ");
293 auto diffStartToKeepDelta
294 = variableDateTime.m_TStart - currentDateTime.m_TStart;
295 currentDateTime.m_TEnd = variableDateTime.m_TEnd - diffStartToKeepDelta;
296 // Tolerance have to be added to the left
297 // add tolerance for left (start) side
298 tolerance
299 = toleranceFactor * (currentDateTime.m_TEnd - currentDateTime.m_TStart);
300 variableDateTimeWithTolerance.m_TStart -= tolerance;
301 }
302 else {
303 qCCritical(LOG_VisualizationGraphWidget())
304 << tr("Detection anormal zoom detection: ");
305 }
306 }
307 else {
308 qCDebug(LOG_VisualizationGraphWidget()) << tr("TORM: Detection zoom out: ");
309 // add tolerance for each side
310 tolerance = toleranceFactor * (currentDateTime.m_TEnd - currentDateTime.m_TStart);
311 variableDateTimeWithTolerance.m_TStart -= tolerance;
312 variableDateTimeWithTolerance.m_TEnd += tolerance;
313 zoomType = VisualizationGraphWidgetZoomType::ZoomOut;
314 }
315 if (!variable->contains(dateTimeRange)) {
316 qCDebug(LOG_VisualizationGraphWidget())
317 << "TORM: Modif on variable datetime detected" << currentDateTime;
318 variable->setDateTime(currentDateTime);
319 }
320
242
321 qCDebug(LOG_VisualizationGraphWidget()) << tr("TORM: Request data detection: ");
243 for (auto it = impl->m_VariableToPlotMultiMap.begin(),
322 // CHangement detected, we need to ask controller to request data loading
244 end = impl->m_VariableToPlotMultiMap.end();
323 emit requestDataLoading(variable, variableDateTimeWithTolerance);
245 it != end; it = impl->m_VariableToPlotMultiMap.upper_bound(it->first)) {
324 }
246 variableUnderGraphVector.push_back(it->first);
325 else {
326 qCInfo(LOG_VisualizationGraphWidget())
327 << tr("TORM: Detection zoom in that doesn't need request: ");
328 zoomType = VisualizationGraphWidgetZoomType::ZoomIn;
329 }
330 }
247 }
248 emit requestDataLoading(std::move(variableUnderGraphVector), graphRange, oldGraphRange,
249 !impl->m_IsCalibration);
331
250
332 if (impl->m_DoSynchronize && !impl->m_IsCalibration) {
251 if (!impl->m_IsCalibration) {
333 auto oldDateTime = SqpRange{t2.lower, t2.upper};
334 qCDebug(LOG_VisualizationGraphWidget())
252 qCDebug(LOG_VisualizationGraphWidget())
335 << tr("TORM: VisualizationGraphWidget::Synchronize notify !!")
253 << tr("TORM: VisualizationGraphWidget::Synchronize notify !!")
336 << QThread::currentThread()->objectName();
254 << QThread::currentThread()->objectName();
337 emit synchronize(dateTimeRange, oldDateTime, zoomType);
255 emit synchronize(graphRange, oldGraphRange);
256 }
338 }
257 }
339 }
258 }
340
259
@@ -390,38 +309,13 void VisualizationGraphWidget::onDataCacheVariableUpdated()
390 it != impl->m_VariableToPlotMultiMap.cend(); ++it) {
309 it != impl->m_VariableToPlotMultiMap.cend(); ++it) {
391 auto variable = it->first;
310 auto variable = it->first;
392 qCDebug(LOG_VisualizationGraphWidget())
311 qCDebug(LOG_VisualizationGraphWidget())
393 << "TORM: VisualizationGraphWidget::onDataCacheVariableUpdated S"
312 << "TORM: VisualizationGraphWidget::onDataCacheVariableUpdated S" << variable->range();
394 << variable->dateTime();
395 qCDebug(LOG_VisualizationGraphWidget())
313 qCDebug(LOG_VisualizationGraphWidget())
396 << "TORM: VisualizationGraphWidget::onDataCacheVariableUpdated E" << dateTime;
314 << "TORM: VisualizationGraphWidget::onDataCacheVariableUpdated E" << dateTime;
397 if (dateTime.contains(variable->dateTime()) || dateTime.intersect(variable->dateTime())) {
315 if (dateTime.contains(variable->range()) || dateTime.intersect(variable->range())) {
398
316
399 VisualizationGraphHelper::updateData(QVector<QCPAbstractPlottable *>{} << it->second,
317 VisualizationGraphHelper::updateData(QVector<QCPAbstractPlottable *>{} << it->second,
400 variable->dataSeries(), variable->dateTime());
318 variable->dataSeries(), variable->range());
401 }
402 }
319 }
403 }
320 }
404
405 VisualizationGraphWidgetZoomType
406 VisualizationGraphWidget::VisualizationGraphWidgetPrivate::getZoomType(const QCPRange &t1,
407 const QCPRange &t2)
408 {
409 // t1.lower <= t2.lower && t2.upper <= t1.upper
410 auto zoomType = VisualizationGraphWidgetZoomType::Unknown;
411 if (t1.lower <= t2.lower && t2.upper <= t1.upper) {
412 zoomType = VisualizationGraphWidgetZoomType::ZoomOut;
413 }
414 else if (t1.lower > t2.lower && t1.upper > t2.upper) {
415 zoomType = VisualizationGraphWidgetZoomType::PanRight;
416 }
417 else if (t1.lower < t2.lower && t1.upper < t2.upper) {
418 zoomType = VisualizationGraphWidgetZoomType::PanLeft;
419 }
420 else if (t1.lower > t2.lower && t2.upper > t1.upper) {
421 zoomType = VisualizationGraphWidgetZoomType::ZoomIn;
422 }
423 else {
424 qCCritical(LOG_VisualizationGraphWidget()) << "getZoomType: Unknown type detected";
425 }
426 return zoomType;
427 }
321 }
@@ -1,12 +1,14
1 #include "Visualization/VisualizationZoneWidget.h"
1 #include "Visualization/VisualizationZoneWidget.h"
2
2
3 #include "Data/SqpRange.h"
4
3
5 #include "Visualization/IVisualizationWidgetVisitor.h"
4 #include "Visualization/IVisualizationWidgetVisitor.h"
6 #include "Visualization/VisualizationGraphWidget.h"
5 #include "Visualization/VisualizationGraphWidget.h"
7 #include "ui_VisualizationZoneWidget.h"
6 #include "ui_VisualizationZoneWidget.h"
8
7
8 #include <Data/SqpRange.h>
9 #include <Variable/VariableController.h>
9
10
11 #include <QUuid>
10 #include <SqpApplication.h>
12 #include <SqpApplication.h>
11
13
12 Q_LOGGING_CATEGORY(LOG_VisualizationZoneWidget, "VisualizationZoneWidget")
14 Q_LOGGING_CATEGORY(LOG_VisualizationZoneWidget, "VisualizationZoneWidget")
@@ -32,8 +34,16 QString defaultGraphName(const QLayout &layout)
32
34
33 } // namespace
35 } // namespace
34
36
37 struct VisualizationZoneWidget::VisualizationZoneWidgetPrivate {
38
39 explicit VisualizationZoneWidgetPrivate() : m_SynchronisationGroupId{QUuid::createUuid()} {}
40 QUuid m_SynchronisationGroupId;
41 };
42
35 VisualizationZoneWidget::VisualizationZoneWidget(const QString &name, QWidget *parent)
43 VisualizationZoneWidget::VisualizationZoneWidget(const QString &name, QWidget *parent)
36 : QWidget{parent}, ui{new Ui::VisualizationZoneWidget}
44 : QWidget{parent},
45 ui{new Ui::VisualizationZoneWidget},
46 impl{spimpl::make_unique_impl<VisualizationZoneWidgetPrivate>()}
37 {
47 {
38 ui->setupUi(this);
48 ui->setupUi(this);
39
49
@@ -43,6 +53,10 VisualizationZoneWidget::VisualizationZoneWidget(const QString &name, QWidget *p
43 setAttribute(Qt::WA_DeleteOnClose);
53 setAttribute(Qt::WA_DeleteOnClose);
44 connect(ui->closeButton, &QToolButton::clicked, this, &VisualizationZoneWidget::close);
54 connect(ui->closeButton, &QToolButton::clicked, this, &VisualizationZoneWidget::close);
45 ui->closeButton->setIcon(sqpApp->style()->standardIcon(QStyle::SP_TitleBarCloseButton));
55 ui->closeButton->setIcon(sqpApp->style()->standardIcon(QStyle::SP_TitleBarCloseButton));
56
57 // Synchronisation id
58 QMetaObject::invokeMethod(&sqpApp->variableController(), "onAddSynchronizationGroupId",
59 Qt::QueuedConnection, Q_ARG(QUuid, impl->m_SynchronisationGroupId));
46 }
60 }
47
61
48 VisualizationZoneWidget::~VisualizationZoneWidget()
62 VisualizationZoneWidget::~VisualizationZoneWidget()
@@ -70,9 +84,10 VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<V
70 graphWidget->addVariable(variable);
84 graphWidget->addVariable(variable);
71
85
72 // Lambda to synchronize zone widget
86 // Lambda to synchronize zone widget
73 auto synchronizeZoneWidget = [this, graphWidget](const SqpRange &dateTime,
87 auto synchronizeZoneWidget = [this, graphWidget](const SqpRange &grapheRange,
74 const SqpRange &oldDateTime,
88 const SqpRange &oldGraphRange) {
75 VisualizationGraphWidgetZoomType zoomType) {
89
90 auto zoomType = VariableController::getZoomType(grapheRange, oldGraphRange);
76 auto frameLayout = ui->visualizationZoneFrame->layout();
91 auto frameLayout = ui->visualizationZoneFrame->layout();
77 for (auto i = 0; i < frameLayout->count(); ++i) {
92 for (auto i = 0; i < frameLayout->count(); ++i) {
78 auto graphChild
93 auto graphChild
@@ -81,9 +96,9 VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<V
81
96
82 auto graphChildRange = graphChild->graphRange();
97 auto graphChildRange = graphChild->graphRange();
83 switch (zoomType) {
98 switch (zoomType) {
84 case VisualizationGraphWidgetZoomType::ZoomIn: {
99 case AcquisitionZoomType::ZoomIn: {
85 auto deltaLeft = dateTime.m_TStart - oldDateTime.m_TStart;
100 auto deltaLeft = grapheRange.m_TStart - oldGraphRange.m_TStart;
86 auto deltaRight = oldDateTime.m_TEnd - dateTime.m_TEnd;
101 auto deltaRight = oldGraphRange.m_TEnd - grapheRange.m_TEnd;
87 graphChildRange.m_TStart += deltaLeft;
102 graphChildRange.m_TStart += deltaLeft;
88 graphChildRange.m_TEnd -= deltaRight;
103 graphChildRange.m_TEnd -= deltaRight;
89 qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: ZoomIn");
104 qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: ZoomIn");
@@ -92,42 +107,42 VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<V
92 qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: deltaRight")
107 qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: deltaRight")
93 << deltaRight;
108 << deltaRight;
94 qCCritical(LOG_VisualizationZoneWidget())
109 qCCritical(LOG_VisualizationZoneWidget())
95 << tr("TORM: dt") << dateTime.m_TEnd - dateTime.m_TStart;
110 << tr("TORM: dt") << grapheRange.m_TEnd - grapheRange.m_TStart;
96
111
97 break;
112 break;
98 }
113 }
99
114
100 case VisualizationGraphWidgetZoomType::ZoomOut: {
115 case AcquisitionZoomType::ZoomOut: {
101 qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: ZoomOut");
116 qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: ZoomOut");
102 auto deltaLeft = oldDateTime.m_TStart - dateTime.m_TStart;
117 auto deltaLeft = oldGraphRange.m_TStart - grapheRange.m_TStart;
103 auto deltaRight = dateTime.m_TEnd - oldDateTime.m_TEnd;
118 auto deltaRight = grapheRange.m_TEnd - oldGraphRange.m_TEnd;
104 qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: deltaLeft")
119 qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: deltaLeft")
105 << deltaLeft;
120 << deltaLeft;
106 qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: deltaRight")
121 qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: deltaRight")
107 << deltaRight;
122 << deltaRight;
108 qCCritical(LOG_VisualizationZoneWidget())
123 qCCritical(LOG_VisualizationZoneWidget())
109 << tr("TORM: dt") << dateTime.m_TEnd - dateTime.m_TStart;
124 << tr("TORM: dt") << grapheRange.m_TEnd - grapheRange.m_TStart;
110 graphChildRange.m_TStart -= deltaLeft;
125 graphChildRange.m_TStart -= deltaLeft;
111 graphChildRange.m_TEnd += deltaRight;
126 graphChildRange.m_TEnd += deltaRight;
112 break;
127 break;
113 }
128 }
114 case VisualizationGraphWidgetZoomType::PanRight: {
129 case AcquisitionZoomType::PanRight: {
115 qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: PanRight");
130 qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: PanRight");
116 auto deltaRight = dateTime.m_TEnd - oldDateTime.m_TEnd;
131 auto deltaRight = grapheRange.m_TEnd - oldGraphRange.m_TEnd;
117 graphChildRange.m_TStart += deltaRight;
132 graphChildRange.m_TStart += deltaRight;
118 graphChildRange.m_TEnd += deltaRight;
133 graphChildRange.m_TEnd += deltaRight;
119 qCCritical(LOG_VisualizationZoneWidget())
134 qCCritical(LOG_VisualizationZoneWidget())
120 << tr("TORM: dt") << dateTime.m_TEnd - dateTime.m_TStart;
135 << tr("TORM: dt") << grapheRange.m_TEnd - grapheRange.m_TStart;
121 break;
136 break;
122 }
137 }
123 case VisualizationGraphWidgetZoomType::PanLeft: {
138 case AcquisitionZoomType::PanLeft: {
124 qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: PanLeft");
139 qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: PanLeft");
125 auto deltaLeft = oldDateTime.m_TStart - dateTime.m_TStart;
140 auto deltaLeft = oldGraphRange.m_TStart - grapheRange.m_TStart;
126 graphChildRange.m_TStart -= deltaLeft;
141 graphChildRange.m_TStart -= deltaLeft;
127 graphChildRange.m_TEnd -= deltaLeft;
142 graphChildRange.m_TEnd -= deltaLeft;
128 break;
143 break;
129 }
144 }
130 case VisualizationGraphWidgetZoomType::Unknown: {
145 case AcquisitionZoomType::Unknown: {
131 qCCritical(LOG_VisualizationZoneWidget())
146 qCCritical(LOG_VisualizationZoneWidget())
132 << tr("Impossible to synchronize: zoom type unknown");
147 << tr("Impossible to synchronize: zoom type unknown");
133 break;
148 break;
@@ -138,7 +153,7 VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<V
138 // No action
153 // No action
139 break;
154 break;
140 }
155 }
141 graphChild->enableSynchronize(false);
156 graphChild->enableAcquisition(false);
142 qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: Range before: ")
157 qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: Range before: ")
143 << graphChild->graphRange();
158 << graphChild->graphRange();
144 qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: Range after : ")
159 qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: Range after : ")
@@ -146,7 +161,7 VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<V
146 qCCritical(LOG_VisualizationZoneWidget())
161 qCCritical(LOG_VisualizationZoneWidget())
147 << tr("TORM: child dt") << graphChildRange.m_TEnd - graphChildRange.m_TStart;
162 << tr("TORM: child dt") << graphChildRange.m_TEnd - graphChildRange.m_TStart;
148 graphChild->setGraphRange(graphChildRange);
163 graphChild->setGraphRange(graphChildRange);
149 graphChild->enableSynchronize(true);
164 graphChild->enableAcquisition(true);
150 }
165 }
151 }
166 }
152 };
167 };
@@ -19,9 +19,9 class SCIQLOP_AMDA_EXPORT AmdaProvider : public IDataProvider {
19 public:
19 public:
20 explicit AmdaProvider();
20 explicit AmdaProvider();
21
21
22 void requestDataLoading(QUuid token, const DataProviderParameters &parameters) override;
22 void requestDataLoading(QUuid acqIdentifier, const DataProviderParameters &parameters) override;
23
23
24 void requestDataAborting(QUuid identifier) override;
24 void requestDataAborting(QUuid acqIdentifier) override;
25
25
26 private:
26 private:
27 void retrieveData(QUuid token, const SqpRange &dateTime, const QVariantHash &data);
27 void retrieveData(QUuid token, const SqpRange &dateTime, const QVariantHash &data);
@@ -55,21 +55,21 AmdaProvider::AmdaProvider()
55 }
55 }
56 }
56 }
57
57
58 void AmdaProvider::requestDataLoading(QUuid token, const DataProviderParameters &parameters)
58 void AmdaProvider::requestDataLoading(QUuid acqIdentifier, const DataProviderParameters &parameters)
59 {
59 {
60 // NOTE: Try to use multithread if possible
60 // NOTE: Try to use multithread if possible
61 const auto times = parameters.m_Times;
61 const auto times = parameters.m_Times;
62 const auto data = parameters.m_Data;
62 const auto data = parameters.m_Data;
63 for (const auto &dateTime : qAsConst(times)) {
63 for (const auto &dateTime : qAsConst(times)) {
64 retrieveData(token, dateTime, data);
64 retrieveData(acqIdentifier, dateTime, data);
65 }
65 }
66 }
66 }
67
67
68 void AmdaProvider::requestDataAborting(QUuid identifier)
68 void AmdaProvider::requestDataAborting(QUuid acqIdentifier)
69 {
69 {
70 if (auto app = sqpApp) {
70 if (auto app = sqpApp) {
71 auto &networkController = app->networkController();
71 auto &networkController = app->networkController();
72 networkController.onReplyCanceled(identifier);
72 networkController.onReplyCanceled(acqIdentifier);
73 }
73 }
74 }
74 }
75
75
@@ -81,7 +81,7 void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVa
81 qCCritical(LOG_AmdaProvider()) << tr("Can't retrieve data: unknown product id");
81 qCCritical(LOG_AmdaProvider()) << tr("Can't retrieve data: unknown product id");
82 return;
82 return;
83 }
83 }
84 qCInfo(LOG_AmdaProvider()) << tr("AmdaProvider::retrieveData") << dateTime;
84 qCDebug(LOG_AmdaProvider()) << tr("AmdaProvider::retrieveData") << dateTime;
85
85
86 // /////////// //
86 // /////////// //
87 // Creates URL //
87 // Creates URL //
@@ -17,15 +17,16 Q_DECLARE_LOGGING_CATEGORY(LOG_CosinusProvider)
17 class SCIQLOP_MOCKPLUGIN_EXPORT CosinusProvider : public IDataProvider {
17 class SCIQLOP_MOCKPLUGIN_EXPORT CosinusProvider : public IDataProvider {
18 public:
18 public:
19 /// @sa IDataProvider::requestDataLoading(). The current impl isn't thread safe.
19 /// @sa IDataProvider::requestDataLoading(). The current impl isn't thread safe.
20 void requestDataLoading(QUuid token, const DataProviderParameters &parameters) override;
20 void requestDataLoading(QUuid acqIdentifier, const DataProviderParameters &parameters) override;
21
21
22
22
23 /// @sa IDataProvider::requestDataAborting(). The current impl isn't thread safe.
23 /// @sa IDataProvider::requestDataAborting(). The current impl isn't thread safe.
24 void requestDataAborting(QUuid identifier) override;
24 void requestDataAborting(QUuid acqIdentifier) override;
25
25
26
26
27 private:
27 private:
28 std::shared_ptr<IDataSeries> retrieveData(QUuid token, const SqpRange &dateTime);
28 std::shared_ptr<IDataSeries> retrieveData(QUuid acqIdentifier,
29 const SqpRange &dataRangeRequested);
29
30
30 QHash<QUuid, bool> m_VariableToEnableProvider;
31 QHash<QUuid, bool> m_VariableToEnableProvider;
31 };
32 };
@@ -11,15 +11,16
11
11
12 Q_LOGGING_CATEGORY(LOG_CosinusProvider, "CosinusProvider")
12 Q_LOGGING_CATEGORY(LOG_CosinusProvider, "CosinusProvider")
13
13
14 std::shared_ptr<IDataSeries> CosinusProvider::retrieveData(QUuid token, const SqpRange &dateTime)
14 std::shared_ptr<IDataSeries> CosinusProvider::retrieveData(QUuid acqIdentifier,
15 const SqpRange &dataRangeRequested)
15 {
16 {
16 // TODO: Add Mutex
17 // TODO: Add Mutex
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 = std::ceil(dateTime.m_TStart * freq); // 100 htz
22 double start = std::ceil(dataRangeRequested.m_TStart * freq); // 100 htz
22 double end = std::floor(dateTime.m_TEnd * freq); // 100 htz
23 double end = std::floor(dataRangeRequested.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) {
@@ -38,7 +39,7 std::shared_ptr<IDataSeries> CosinusProvider::retrieveData(QUuid token, const Sq
38 int progress = 0;
39 int progress = 0;
39 auto progressEnd = dataCount;
40 auto progressEnd = dataCount;
40 for (auto time = start; time < end; ++time, ++dataIndex) {
41 for (auto time = start; time < end; ++time, ++dataIndex) {
41 auto it = m_VariableToEnableProvider.find(token);
42 auto it = m_VariableToEnableProvider.find(acqIdentifier);
42 if (it != m_VariableToEnableProvider.end() && it.value()) {
43 if (it != m_VariableToEnableProvider.end() && it.value()) {
43 const auto timeOnFreq = time / freq;
44 const auto timeOnFreq = time / freq;
44
45
@@ -50,7 +51,7 std::shared_ptr<IDataSeries> CosinusProvider::retrieveData(QUuid token, const Sq
50 if (currentProgress != progress) {
51 if (currentProgress != progress) {
51 progress = currentProgress;
52 progress = currentProgress;
52
53
53 emit dataProvidedProgress(token, progress);
54 emit dataProvidedProgress(acqIdentifier, progress);
54 }
55 }
55 }
56 }
56 else {
57 else {
@@ -61,35 +62,36 std::shared_ptr<IDataSeries> CosinusProvider::retrieveData(QUuid token, const Sq
61 }
62 }
62 }
63 }
63 }
64 }
64 emit dataProvidedProgress(token, 0.0);
65 emit dataProvidedProgress(acqIdentifier, 0.0);
65
66
66 return std::make_shared<ScalarSeries>(std::move(xAxisData), std::move(valuesData),
67 return std::make_shared<ScalarSeries>(std::move(xAxisData), std::move(valuesData),
67 Unit{QStringLiteral("t"), true}, Unit{});
68 Unit{QStringLiteral("t"), true}, Unit{});
68 }
69 }
69
70
70 void CosinusProvider::requestDataLoading(QUuid token, const DataProviderParameters &parameters)
71 void CosinusProvider::requestDataLoading(QUuid acqIdentifier,
72 const DataProviderParameters &parameters)
71 {
73 {
72 // TODO: Add Mutex
74 // TODO: Add Mutex
73 m_VariableToEnableProvider[token] = true;
75 m_VariableToEnableProvider[acqIdentifier] = true;
74 qCDebug(LOG_CosinusProvider()) << "CosinusProvider::requestDataLoading"
76 qCDebug(LOG_CosinusProvider()) << "CosinusProvider::requestDataLoading"
75 << QThread::currentThread()->objectName();
77 << QThread::currentThread()->objectName();
76 // NOTE: Try to use multithread if possible
78 // NOTE: Try to use multithread if possible
77 const auto times = parameters.m_Times;
79 const auto times = parameters.m_Times;
78
80
79 for (const auto &dateTime : qAsConst(times)) {
81 for (const auto &dateTime : qAsConst(times)) {
80 if (m_VariableToEnableProvider[token]) {
82 if (m_VariableToEnableProvider[acqIdentifier]) {
81 auto scalarSeries = this->retrieveData(token, dateTime);
83 auto scalarSeries = this->retrieveData(acqIdentifier, dateTime);
82 emit dataProvided(token, scalarSeries, dateTime);
84 emit dataProvided(acqIdentifier, scalarSeries, dateTime);
83 }
85 }
84 }
86 }
85 }
87 }
86
88
87 void CosinusProvider::requestDataAborting(QUuid identifier)
89 void CosinusProvider::requestDataAborting(QUuid acqIdentifier)
88 {
90 {
89 // TODO: Add Mutex
91 // TODO: Add Mutex
90 qCDebug(LOG_CosinusProvider()) << "CosinusProvider::requestDataAborting" << identifier
92 qCDebug(LOG_CosinusProvider()) << "CosinusProvider::requestDataAborting" << acqIdentifier
91 << QThread::currentThread()->objectName();
93 << QThread::currentThread()->objectName();
92 auto it = m_VariableToEnableProvider.find(identifier);
94 auto it = m_VariableToEnableProvider.find(acqIdentifier);
93 if (it != m_VariableToEnableProvider.end()) {
95 if (it != m_VariableToEnableProvider.end()) {
94 it.value() = false;
96 it.value() = false;
95 }
97 }
General Comments 1
Under Review
author

Auto status change to "Under Review"

You need to be logged in to leave comments. Login now