##// END OF EJS Templates
Next range of a variable synchronized is now computed using:...
perrinel -
r627:4e5df98215ef
parent child
Show More
@@ -1,238 +1,238
1 #include "Variable/VariableAcquisitionWorker.h"
1 #include "Variable/VariableAcquisitionWorker.h"
2
2
3 #include "Variable/Variable.h"
3 #include "Variable/Variable.h"
4
4
5 #include <Data/AcquisitionRequest.h>
5 #include <Data/AcquisitionRequest.h>
6 #include <Data/SqpRange.h>
6 #include <Data/SqpRange.h>
7
7
8 #include <unordered_map>
8 #include <unordered_map>
9 #include <utility>
9 #include <utility>
10
10
11 #include <QMutex>
11 #include <QMutex>
12 #include <QReadWriteLock>
12 #include <QReadWriteLock>
13 #include <QThread>
13 #include <QThread>
14
14
15 Q_LOGGING_CATEGORY(LOG_VariableAcquisitionWorker, "VariableAcquisitionWorker")
15 Q_LOGGING_CATEGORY(LOG_VariableAcquisitionWorker, "VariableAcquisitionWorker")
16
16
17 struct VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate {
17 struct VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate {
18
18
19 explicit VariableAcquisitionWorkerPrivate() : m_Lock{QReadWriteLock::Recursive} {}
19 explicit VariableAcquisitionWorkerPrivate() : m_Lock{QReadWriteLock::Recursive} {}
20
20
21 void lockRead() { m_Lock.lockForRead(); }
21 void lockRead() { m_Lock.lockForRead(); }
22 void lockWrite() { m_Lock.lockForWrite(); }
22 void lockWrite() { m_Lock.lockForWrite(); }
23 void unlock() { m_Lock.unlock(); }
23 void unlock() { m_Lock.unlock(); }
24
24
25 void removeVariableRequest(QUuid vIdentifier);
25 void removeVariableRequest(QUuid vIdentifier);
26
26
27 QMutex m_WorkingMutex;
27 QMutex m_WorkingMutex;
28 QReadWriteLock m_Lock;
28 QReadWriteLock m_Lock;
29
29
30 std::map<QUuid, QVector<AcquisitionDataPacket> > m_AcqIdentifierToAcqDataPacketVectorMap;
30 std::map<QUuid, QVector<AcquisitionDataPacket> > m_AcqIdentifierToAcqDataPacketVectorMap;
31 std::map<QUuid, AcquisitionRequest> m_AcqIdentifierToAcqRequestMap;
31 std::map<QUuid, AcquisitionRequest> m_AcqIdentifierToAcqRequestMap;
32 std::map<QUuid, std::pair<QUuid, QUuid> > m_VIdentifierToCurrrentAcqIdNextIdPairMap;
32 std::map<QUuid, std::pair<QUuid, QUuid> > m_VIdentifierToCurrrentAcqIdNextIdPairMap;
33 };
33 };
34
34
35
35
36 VariableAcquisitionWorker::VariableAcquisitionWorker(QObject *parent)
36 VariableAcquisitionWorker::VariableAcquisitionWorker(QObject *parent)
37 : QObject{parent}, impl{spimpl::make_unique_impl<VariableAcquisitionWorkerPrivate>()}
37 : QObject{parent}, impl{spimpl::make_unique_impl<VariableAcquisitionWorkerPrivate>()}
38 {
38 {
39 }
39 }
40
40
41 VariableAcquisitionWorker::~VariableAcquisitionWorker()
41 VariableAcquisitionWorker::~VariableAcquisitionWorker()
42 {
42 {
43 qCInfo(LOG_VariableAcquisitionWorker()) << tr("VariableAcquisitionWorker destruction")
43 qCInfo(LOG_VariableAcquisitionWorker()) << tr("VariableAcquisitionWorker destruction")
44 << QThread::currentThread();
44 << QThread::currentThread();
45 this->waitForFinish();
45 this->waitForFinish();
46 }
46 }
47
47
48
48
49 QUuid VariableAcquisitionWorker::pushVariableRequest(QUuid varRequestId, QUuid vIdentifier,
49 QUuid VariableAcquisitionWorker::pushVariableRequest(QUuid varRequestId, QUuid vIdentifier,
50 SqpRange rangeRequested,
50 SqpRange rangeRequested,
51 SqpRange cacheRangeRequested,
51 SqpRange cacheRangeRequested,
52 DataProviderParameters parameters,
52 DataProviderParameters parameters,
53 std::shared_ptr<IDataProvider> provider)
53 std::shared_ptr<IDataProvider> provider)
54 {
54 {
55 qCInfo(LOG_VariableAcquisitionWorker())
55 qCDebug(LOG_VariableAcquisitionWorker())
56 << tr("TORM VariableAcquisitionWorker::pushVariableRequest ") << cacheRangeRequested;
56 << tr("TORM VariableAcquisitionWorker::pushVariableRequest ") << cacheRangeRequested;
57 auto varRequestIdCanceled = QUuid();
57 auto varRequestIdCanceled = QUuid();
58
58
59 // Request creation
59 // Request creation
60 auto acqRequest = AcquisitionRequest{};
60 auto acqRequest = AcquisitionRequest{};
61 acqRequest.m_VarRequestId = varRequestId;
61 acqRequest.m_VarRequestId = varRequestId;
62 acqRequest.m_vIdentifier = vIdentifier;
62 acqRequest.m_vIdentifier = vIdentifier;
63 acqRequest.m_DataProviderParameters = parameters;
63 acqRequest.m_DataProviderParameters = parameters;
64 acqRequest.m_RangeRequested = rangeRequested;
64 acqRequest.m_RangeRequested = rangeRequested;
65 acqRequest.m_CacheRangeRequested = cacheRangeRequested;
65 acqRequest.m_CacheRangeRequested = cacheRangeRequested;
66 acqRequest.m_Size = parameters.m_Times.size();
66 acqRequest.m_Size = parameters.m_Times.size();
67 acqRequest.m_Provider = provider;
67 acqRequest.m_Provider = provider;
68
68
69
69
70 // Register request
70 // Register request
71 impl->lockWrite();
71 impl->lockWrite();
72 impl->m_AcqIdentifierToAcqRequestMap.insert(
72 impl->m_AcqIdentifierToAcqRequestMap.insert(
73 std::make_pair(acqRequest.m_AcqIdentifier, acqRequest));
73 std::make_pair(acqRequest.m_AcqIdentifier, acqRequest));
74
74
75 auto it = impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(vIdentifier);
75 auto it = impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(vIdentifier);
76 if (it != impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) {
76 if (it != impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) {
77 // A current request already exists, we can replace the next one
77 // A current request already exists, we can replace the next one
78 auto nextAcqId = it->second.second;
78 auto nextAcqId = it->second.second;
79 auto acqIdentifierToAcqRequestMapIt = impl->m_AcqIdentifierToAcqRequestMap.find(nextAcqId);
79 auto acqIdentifierToAcqRequestMapIt = impl->m_AcqIdentifierToAcqRequestMap.find(nextAcqId);
80 if (acqIdentifierToAcqRequestMapIt != impl->m_AcqIdentifierToAcqRequestMap.cend()) {
80 if (acqIdentifierToAcqRequestMapIt != impl->m_AcqIdentifierToAcqRequestMap.cend()) {
81 auto request = acqIdentifierToAcqRequestMapIt->second;
81 auto request = acqIdentifierToAcqRequestMapIt->second;
82 varRequestIdCanceled = request.m_VarRequestId;
82 varRequestIdCanceled = request.m_VarRequestId;
83 }
83 }
84
84
85 it->second.second = acqRequest.m_AcqIdentifier;
85 it->second.second = acqRequest.m_AcqIdentifier;
86 impl->unlock();
86 impl->unlock();
87 }
87 }
88 else {
88 else {
89 // First request for the variable, it must be stored and executed
89 // First request for the variable, it must be stored and executed
90 impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.insert(
90 impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.insert(
91 std::make_pair(vIdentifier, std::make_pair(acqRequest.m_AcqIdentifier, QUuid())));
91 std::make_pair(vIdentifier, std::make_pair(acqRequest.m_AcqIdentifier, QUuid())));
92 impl->unlock();
92 impl->unlock();
93
93
94 QMetaObject::invokeMethod(this, "onExecuteRequest", Qt::QueuedConnection,
94 QMetaObject::invokeMethod(this, "onExecuteRequest", Qt::QueuedConnection,
95 Q_ARG(QUuid, acqRequest.m_AcqIdentifier));
95 Q_ARG(QUuid, acqRequest.m_AcqIdentifier));
96 }
96 }
97
97
98 return varRequestIdCanceled;
98 return varRequestIdCanceled;
99 }
99 }
100
100
101 void VariableAcquisitionWorker::abortProgressRequested(QUuid vIdentifier)
101 void VariableAcquisitionWorker::abortProgressRequested(QUuid vIdentifier)
102 {
102 {
103 // TODO
103 // TODO
104 }
104 }
105
105
106 void VariableAcquisitionWorker::onVariableRetrieveDataInProgress(QUuid acqIdentifier,
106 void VariableAcquisitionWorker::onVariableRetrieveDataInProgress(QUuid acqIdentifier,
107 double progress)
107 double progress)
108 {
108 {
109 // TODO
109 // TODO
110 }
110 }
111
111
112 void VariableAcquisitionWorker::onVariableDataAcquired(QUuid acqIdentifier,
112 void VariableAcquisitionWorker::onVariableDataAcquired(QUuid acqIdentifier,
113 std::shared_ptr<IDataSeries> dataSeries,
113 std::shared_ptr<IDataSeries> dataSeries,
114 SqpRange dataRangeAcquired)
114 SqpRange dataRangeAcquired)
115 {
115 {
116 qCDebug(LOG_VariableAcquisitionWorker()) << tr("onVariableDataAcquired on range ")
116 qCDebug(LOG_VariableAcquisitionWorker()) << tr("onVariableDataAcquired on range ")
117 << acqIdentifier << dataRangeAcquired;
117 << acqIdentifier << dataRangeAcquired;
118 impl->lockWrite();
118 impl->lockWrite();
119 auto aIdToARit = impl->m_AcqIdentifierToAcqRequestMap.find(acqIdentifier);
119 auto aIdToARit = impl->m_AcqIdentifierToAcqRequestMap.find(acqIdentifier);
120 if (aIdToARit != impl->m_AcqIdentifierToAcqRequestMap.cend()) {
120 if (aIdToARit != impl->m_AcqIdentifierToAcqRequestMap.cend()) {
121 // Store the result
121 // Store the result
122 auto dataPacket = AcquisitionDataPacket{};
122 auto dataPacket = AcquisitionDataPacket{};
123 dataPacket.m_Range = dataRangeAcquired;
123 dataPacket.m_Range = dataRangeAcquired;
124 dataPacket.m_DateSeries = dataSeries;
124 dataPacket.m_DateSeries = dataSeries;
125
125
126 auto aIdToADPVit = impl->m_AcqIdentifierToAcqDataPacketVectorMap.find(acqIdentifier);
126 auto aIdToADPVit = impl->m_AcqIdentifierToAcqDataPacketVectorMap.find(acqIdentifier);
127 if (aIdToADPVit != impl->m_AcqIdentifierToAcqDataPacketVectorMap.cend()) {
127 if (aIdToADPVit != impl->m_AcqIdentifierToAcqDataPacketVectorMap.cend()) {
128 // A current request result already exists, we can update it
128 // A current request result already exists, we can update it
129 aIdToADPVit->second.push_back(dataPacket);
129 aIdToADPVit->second.push_back(dataPacket);
130 }
130 }
131 else {
131 else {
132 // First request result for the variable, it must be stored
132 // First request result for the variable, it must be stored
133 impl->m_AcqIdentifierToAcqDataPacketVectorMap.insert(
133 impl->m_AcqIdentifierToAcqDataPacketVectorMap.insert(
134 std::make_pair(acqIdentifier, QVector<AcquisitionDataPacket>() << dataPacket));
134 std::make_pair(acqIdentifier, QVector<AcquisitionDataPacket>() << dataPacket));
135 }
135 }
136
136
137
137
138 // Decrement the counter of the request
138 // Decrement the counter of the request
139 auto &acqRequest = aIdToARit->second;
139 auto &acqRequest = aIdToARit->second;
140 acqRequest.m_Size = acqRequest.m_Size - 1;
140 acqRequest.m_Size = acqRequest.m_Size - 1;
141
141
142 // if the counter is 0, we can return data then run the next request if it exists and
142 // if the counter is 0, we can return data then run the next request if it exists and
143 // removed the finished request
143 // removed the finished request
144 if (acqRequest.m_Size == 0) {
144 if (acqRequest.m_Size == 0) {
145 // Return the data
145 // Return the data
146 aIdToADPVit = impl->m_AcqIdentifierToAcqDataPacketVectorMap.find(acqIdentifier);
146 aIdToADPVit = impl->m_AcqIdentifierToAcqDataPacketVectorMap.find(acqIdentifier);
147 if (aIdToADPVit != impl->m_AcqIdentifierToAcqDataPacketVectorMap.cend()) {
147 if (aIdToADPVit != impl->m_AcqIdentifierToAcqDataPacketVectorMap.cend()) {
148 emit dataProvided(acqRequest.m_vIdentifier, acqRequest.m_RangeRequested,
148 emit dataProvided(acqRequest.m_vIdentifier, acqRequest.m_RangeRequested,
149 acqRequest.m_CacheRangeRequested, aIdToADPVit->second);
149 acqRequest.m_CacheRangeRequested, aIdToADPVit->second);
150 }
150 }
151
151
152 // Execute the next one
152 // Execute the next one
153 auto it
153 auto it
154 = impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(acqRequest.m_vIdentifier);
154 = impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(acqRequest.m_vIdentifier);
155
155
156 if (it != impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) {
156 if (it != impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) {
157 if (it->second.second.isNull()) {
157 if (it->second.second.isNull()) {
158 // There is no next request, we can remove the variable request
158 // There is no next request, we can remove the variable request
159 impl->removeVariableRequest(acqRequest.m_vIdentifier);
159 impl->removeVariableRequest(acqRequest.m_vIdentifier);
160 }
160 }
161 else {
161 else {
162 auto acqIdentifierToRemove = it->second.first;
162 auto acqIdentifierToRemove = it->second.first;
163 // Move the next request to the current request
163 // Move the next request to the current request
164 it->second.first = it->second.second;
164 it->second.first = it->second.second;
165 it->second.second = QUuid();
165 it->second.second = QUuid();
166 // Remove AcquisitionRequest and results;
166 // Remove AcquisitionRequest and results;
167 impl->m_AcqIdentifierToAcqRequestMap.erase(acqIdentifierToRemove);
167 impl->m_AcqIdentifierToAcqRequestMap.erase(acqIdentifierToRemove);
168 impl->m_AcqIdentifierToAcqDataPacketVectorMap.erase(acqIdentifierToRemove);
168 impl->m_AcqIdentifierToAcqDataPacketVectorMap.erase(acqIdentifierToRemove);
169 // Execute the current request
169 // Execute the current request
170 QMetaObject::invokeMethod(this, "onExecuteRequest", Qt::QueuedConnection,
170 QMetaObject::invokeMethod(this, "onExecuteRequest", Qt::QueuedConnection,
171 Q_ARG(QUuid, it->second.first));
171 Q_ARG(QUuid, it->second.first));
172 }
172 }
173 }
173 }
174 else {
174 else {
175 qCCritical(LOG_VariableAcquisitionWorker())
175 qCCritical(LOG_VariableAcquisitionWorker())
176 << tr("Impossible to execute the acquisition on an unfound variable ");
176 << tr("Impossible to execute the acquisition on an unfound variable ");
177 }
177 }
178 }
178 }
179 }
179 }
180 else {
180 else {
181 qCCritical(LOG_VariableAcquisitionWorker())
181 qCCritical(LOG_VariableAcquisitionWorker())
182 << tr("Impossible to retrieve AcquisitionRequest for the incoming data");
182 << tr("Impossible to retrieve AcquisitionRequest for the incoming data");
183 }
183 }
184 impl->unlock();
184 impl->unlock();
185 }
185 }
186
186
187 void VariableAcquisitionWorker::onExecuteRequest(QUuid acqIdentifier)
187 void VariableAcquisitionWorker::onExecuteRequest(QUuid acqIdentifier)
188 {
188 {
189 qCInfo(LOG_VariableAcquisitionWorker()) << tr("onExecuteRequest") << QThread::currentThread();
189 qCDebug(LOG_VariableAcquisitionWorker()) << tr("onExecuteRequest") << QThread::currentThread();
190 impl->lockRead();
190 impl->lockRead();
191 auto it = impl->m_AcqIdentifierToAcqRequestMap.find(acqIdentifier);
191 auto it = impl->m_AcqIdentifierToAcqRequestMap.find(acqIdentifier);
192 if (it != impl->m_AcqIdentifierToAcqRequestMap.cend()) {
192 if (it != impl->m_AcqIdentifierToAcqRequestMap.cend()) {
193 auto request = it->second;
193 auto request = it->second;
194 impl->unlock();
194 impl->unlock();
195 request.m_Provider->requestDataLoading(acqIdentifier, request.m_DataProviderParameters);
195 request.m_Provider->requestDataLoading(acqIdentifier, request.m_DataProviderParameters);
196 }
196 }
197 else {
197 else {
198 impl->unlock();
198 impl->unlock();
199 // TODO log no acqIdentifier recognized
199 // TODO log no acqIdentifier recognized
200 }
200 }
201 }
201 }
202
202
203 void VariableAcquisitionWorker::initialize()
203 void VariableAcquisitionWorker::initialize()
204 {
204 {
205 qCDebug(LOG_VariableAcquisitionWorker()) << tr("VariableAcquisitionWorker init")
205 qCDebug(LOG_VariableAcquisitionWorker()) << tr("VariableAcquisitionWorker init")
206 << QThread::currentThread();
206 << QThread::currentThread();
207 impl->m_WorkingMutex.lock();
207 impl->m_WorkingMutex.lock();
208 qCDebug(LOG_VariableAcquisitionWorker()) << tr("VariableAcquisitionWorker init END");
208 qCDebug(LOG_VariableAcquisitionWorker()) << tr("VariableAcquisitionWorker init END");
209 }
209 }
210
210
211 void VariableAcquisitionWorker::finalize()
211 void VariableAcquisitionWorker::finalize()
212 {
212 {
213 impl->m_WorkingMutex.unlock();
213 impl->m_WorkingMutex.unlock();
214 }
214 }
215
215
216 void VariableAcquisitionWorker::waitForFinish()
216 void VariableAcquisitionWorker::waitForFinish()
217 {
217 {
218 QMutexLocker locker{&impl->m_WorkingMutex};
218 QMutexLocker locker{&impl->m_WorkingMutex};
219 }
219 }
220
220
221 void VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate::removeVariableRequest(
221 void VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate::removeVariableRequest(
222 QUuid vIdentifier)
222 QUuid vIdentifier)
223 {
223 {
224 lockWrite();
224 lockWrite();
225 auto it = m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(vIdentifier);
225 auto it = m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(vIdentifier);
226
226
227 if (it != m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) {
227 if (it != m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) {
228 // A current request already exists, we can replace the next one
228 // A current request already exists, we can replace the next one
229
229
230 m_AcqIdentifierToAcqRequestMap.erase(it->second.first);
230 m_AcqIdentifierToAcqRequestMap.erase(it->second.first);
231 m_AcqIdentifierToAcqDataPacketVectorMap.erase(it->second.first);
231 m_AcqIdentifierToAcqDataPacketVectorMap.erase(it->second.first);
232
232
233 m_AcqIdentifierToAcqRequestMap.erase(it->second.second);
233 m_AcqIdentifierToAcqRequestMap.erase(it->second.second);
234 m_AcqIdentifierToAcqDataPacketVectorMap.erase(it->second.second);
234 m_AcqIdentifierToAcqDataPacketVectorMap.erase(it->second.second);
235 }
235 }
236 m_VIdentifierToCurrrentAcqIdNextIdPairMap.erase(vIdentifier);
236 m_VIdentifierToCurrrentAcqIdNextIdPairMap.erase(vIdentifier);
237 unlock();
237 unlock();
238 }
238 }
@@ -1,734 +1,738
1 #include <Variable/Variable.h>
1 #include <Variable/Variable.h>
2 #include <Variable/VariableAcquisitionWorker.h>
2 #include <Variable/VariableAcquisitionWorker.h>
3 #include <Variable/VariableCacheController.h>
4 #include <Variable/VariableCacheStrategy.h>
3 #include <Variable/VariableCacheStrategy.h>
5 #include <Variable/VariableController.h>
4 #include <Variable/VariableController.h>
6 #include <Variable/VariableModel.h>
5 #include <Variable/VariableModel.h>
7 #include <Variable/VariableSynchronizationGroup.h>
6 #include <Variable/VariableSynchronizationGroup.h>
8
7
9 #include <Data/DataProviderParameters.h>
8 #include <Data/DataProviderParameters.h>
10 #include <Data/IDataProvider.h>
9 #include <Data/IDataProvider.h>
11 #include <Data/IDataSeries.h>
10 #include <Data/IDataSeries.h>
12 #include <Data/VariableRequest.h>
11 #include <Data/VariableRequest.h>
13 #include <Time/TimeController.h>
12 #include <Time/TimeController.h>
14
13
15 #include <QMutex>
14 #include <QMutex>
16 #include <QThread>
15 #include <QThread>
17 #include <QUuid>
16 #include <QUuid>
18 #include <QtCore/QItemSelectionModel>
17 #include <QtCore/QItemSelectionModel>
19
18
20 #include <deque>
19 #include <deque>
21 #include <set>
20 #include <set>
22 #include <unordered_map>
21 #include <unordered_map>
23
22
24 Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController")
23 Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController")
25
24
26 namespace {
25 namespace {
27
26
28 SqpRange computeSynchroRangeRequested(const SqpRange &varRange, const SqpRange &graphRange,
27 SqpRange computeSynchroRangeRequested(const SqpRange &varRange, const SqpRange &graphRange,
29 const SqpRange &oldGraphRange)
28 const SqpRange &oldGraphRange)
30 {
29 {
31 auto zoomType = VariableController::getZoomType(graphRange, oldGraphRange);
30 auto zoomType = VariableController::getZoomType(graphRange, oldGraphRange);
32
31
33 auto varRangeRequested = varRange;
32 auto varRangeRequested = varRange;
34 switch (zoomType) {
33 switch (zoomType) {
35 case AcquisitionZoomType::ZoomIn: {
34 case AcquisitionZoomType::ZoomIn: {
36 auto deltaLeft = graphRange.m_TStart - oldGraphRange.m_TStart;
35 auto deltaLeft = graphRange.m_TStart - oldGraphRange.m_TStart;
37 auto deltaRight = oldGraphRange.m_TEnd - graphRange.m_TEnd;
36 auto deltaRight = oldGraphRange.m_TEnd - graphRange.m_TEnd;
38 varRangeRequested.m_TStart += deltaLeft;
37 varRangeRequested.m_TStart += deltaLeft;
39 varRangeRequested.m_TEnd -= deltaRight;
38 varRangeRequested.m_TEnd -= deltaRight;
40 break;
39 break;
41 }
40 }
42
41
43 case AcquisitionZoomType::ZoomOut: {
42 case AcquisitionZoomType::ZoomOut: {
44 auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart;
43 auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart;
45 auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd;
44 auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd;
46 varRangeRequested.m_TStart -= deltaLeft;
45 varRangeRequested.m_TStart -= deltaLeft;
47 varRangeRequested.m_TEnd += deltaRight;
46 varRangeRequested.m_TEnd += deltaRight;
48 break;
47 break;
49 }
48 }
50 case AcquisitionZoomType::PanRight: {
49 case AcquisitionZoomType::PanRight: {
51 auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd;
50 auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd;
52 varRangeRequested.m_TStart += deltaRight;
51 varRangeRequested.m_TStart += deltaRight;
53 varRangeRequested.m_TEnd += deltaRight;
52 varRangeRequested.m_TEnd += deltaRight;
54 break;
53 break;
55 }
54 }
56 case AcquisitionZoomType::PanLeft: {
55 case AcquisitionZoomType::PanLeft: {
57 auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart;
56 auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart;
58 varRangeRequested.m_TStart -= deltaLeft;
57 varRangeRequested.m_TStart -= deltaLeft;
59 varRangeRequested.m_TEnd -= deltaLeft;
58 varRangeRequested.m_TEnd -= deltaLeft;
60 break;
59 break;
61 }
60 }
62 case AcquisitionZoomType::Unknown: {
61 case AcquisitionZoomType::Unknown: {
63 qCCritical(LOG_VariableController())
62 qCCritical(LOG_VariableController())
64 << VariableController::tr("Impossible to synchronize: zoom type unknown");
63 << VariableController::tr("Impossible to synchronize: zoom type unknown");
65 break;
64 break;
66 }
65 }
67 default:
66 default:
68 qCCritical(LOG_VariableController()) << VariableController::tr(
67 qCCritical(LOG_VariableController()) << VariableController::tr(
69 "Impossible to synchronize: zoom type not take into account");
68 "Impossible to synchronize: zoom type not take into account");
70 // No action
69 // No action
71 break;
70 break;
72 }
71 }
73
72
74 return varRangeRequested;
73 return varRangeRequested;
75 }
74 }
76 }
75 }
77
76
78 struct VariableController::VariableControllerPrivate {
77 struct VariableController::VariableControllerPrivate {
79 explicit VariableControllerPrivate(VariableController *parent)
78 explicit VariableControllerPrivate(VariableController *parent)
80 : m_WorkingMutex{},
79 : m_WorkingMutex{},
81 m_VariableModel{new VariableModel{parent}},
80 m_VariableModel{new VariableModel{parent}},
82 m_VariableSelectionModel{new QItemSelectionModel{m_VariableModel, parent}},
81 m_VariableSelectionModel{new QItemSelectionModel{m_VariableModel, parent}},
83 m_VariableCacheController{std::make_unique<VariableCacheController>()},
84 m_VariableCacheStrategy{std::make_unique<VariableCacheStrategy>()},
82 m_VariableCacheStrategy{std::make_unique<VariableCacheStrategy>()},
85 m_VariableAcquisitionWorker{std::make_unique<VariableAcquisitionWorker>()},
83 m_VariableAcquisitionWorker{std::make_unique<VariableAcquisitionWorker>()},
86 q{parent}
84 q{parent}
87 {
85 {
88
86
89 m_VariableAcquisitionWorker->moveToThread(&m_VariableAcquisitionWorkerThread);
87 m_VariableAcquisitionWorker->moveToThread(&m_VariableAcquisitionWorkerThread);
90 m_VariableAcquisitionWorkerThread.setObjectName("VariableAcquisitionWorkerThread");
88 m_VariableAcquisitionWorkerThread.setObjectName("VariableAcquisitionWorkerThread");
91 }
89 }
92
90
93
91
94 virtual ~VariableControllerPrivate()
92 virtual ~VariableControllerPrivate()
95 {
93 {
96 qCDebug(LOG_VariableController()) << tr("VariableControllerPrivate destruction");
94 qCDebug(LOG_VariableController()) << tr("VariableControllerPrivate destruction");
97 m_VariableAcquisitionWorkerThread.quit();
95 m_VariableAcquisitionWorkerThread.quit();
98 m_VariableAcquisitionWorkerThread.wait();
96 m_VariableAcquisitionWorkerThread.wait();
99 }
97 }
100
98
101
99
102 void processRequest(std::shared_ptr<Variable> var, const SqpRange &rangeRequested,
100 void processRequest(std::shared_ptr<Variable> var, const SqpRange &rangeRequested,
103 QUuid varRequestId);
101 QUuid varRequestId);
104
102
105 QVector<SqpRange> provideNotInCacheDateTimeList(std::shared_ptr<Variable> variable,
103 QVector<SqpRange> provideNotInCacheDateTimeList(std::shared_ptr<Variable> variable,
106 const SqpRange &dateTime);
104 const SqpRange &dateTime);
107
105
108 std::shared_ptr<Variable> findVariable(QUuid vIdentifier);
106 std::shared_ptr<Variable> findVariable(QUuid vIdentifier);
109 std::shared_ptr<IDataSeries>
107 std::shared_ptr<IDataSeries>
110 retrieveDataSeries(const QVector<AcquisitionDataPacket> acqDataPacketVector);
108 retrieveDataSeries(const QVector<AcquisitionDataPacket> acqDataPacketVector);
111
109
112 void registerProvider(std::shared_ptr<IDataProvider> provider);
110 void registerProvider(std::shared_ptr<IDataProvider> provider);
113
111
114 void storeVariableRequest(QUuid varId, QUuid varRequestId, const VariableRequest &varRequest);
112 void storeVariableRequest(QUuid varId, QUuid varRequestId, const VariableRequest &varRequest);
115 QUuid acceptVariableRequest(QUuid varId, std::shared_ptr<IDataSeries> dataSeries);
113 QUuid acceptVariableRequest(QUuid varId, std::shared_ptr<IDataSeries> dataSeries);
116 void updateVariableRequest(QUuid varRequestId);
114 void updateVariableRequest(QUuid varRequestId);
117 void cancelVariableRequest(QUuid varRequestId);
115 void cancelVariableRequest(QUuid varRequestId);
118
116
119 QMutex m_WorkingMutex;
117 QMutex m_WorkingMutex;
120 /// Variable model. The VariableController has the ownership
118 /// Variable model. The VariableController has the ownership
121 VariableModel *m_VariableModel;
119 VariableModel *m_VariableModel;
122 QItemSelectionModel *m_VariableSelectionModel;
120 QItemSelectionModel *m_VariableSelectionModel;
123
121
124
122
125 TimeController *m_TimeController{nullptr};
123 TimeController *m_TimeController{nullptr};
126 std::unique_ptr<VariableCacheController> m_VariableCacheController;
127 std::unique_ptr<VariableCacheStrategy> m_VariableCacheStrategy;
124 std::unique_ptr<VariableCacheStrategy> m_VariableCacheStrategy;
128 std::unique_ptr<VariableAcquisitionWorker> m_VariableAcquisitionWorker;
125 std::unique_ptr<VariableAcquisitionWorker> m_VariableAcquisitionWorker;
129 QThread m_VariableAcquisitionWorkerThread;
126 QThread m_VariableAcquisitionWorkerThread;
130
127
131 std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> >
128 std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> >
132 m_VariableToProviderMap;
129 m_VariableToProviderMap;
133 std::unordered_map<std::shared_ptr<Variable>, QUuid> m_VariableToIdentifierMap;
130 std::unordered_map<std::shared_ptr<Variable>, QUuid> m_VariableToIdentifierMap;
134 std::map<QUuid, std::shared_ptr<VariableSynchronizationGroup> >
131 std::map<QUuid, std::shared_ptr<VariableSynchronizationGroup> >
135 m_GroupIdToVariableSynchronizationGroupMap;
132 m_GroupIdToVariableSynchronizationGroupMap;
136 std::map<QUuid, QUuid> m_VariableIdGroupIdMap;
133 std::map<QUuid, QUuid> m_VariableIdGroupIdMap;
137 std::set<std::shared_ptr<IDataProvider> > m_ProviderSet;
134 std::set<std::shared_ptr<IDataProvider> > m_ProviderSet;
138
135
139 std::map<QUuid, std::map<QUuid, VariableRequest> > m_VarRequestIdToVarIdVarRequestMap;
136 std::map<QUuid, std::map<QUuid, VariableRequest> > m_VarRequestIdToVarIdVarRequestMap;
140
137
141 std::map<QUuid, std::deque<QUuid> > m_VarIdToVarRequestIdQueueMap;
138 std::map<QUuid, std::deque<QUuid> > m_VarIdToVarRequestIdQueueMap;
142
139
143
140
144 VariableController *q;
141 VariableController *q;
145 };
142 };
146
143
147
144
148 VariableController::VariableController(QObject *parent)
145 VariableController::VariableController(QObject *parent)
149 : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)}
146 : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)}
150 {
147 {
151 qCDebug(LOG_VariableController()) << tr("VariableController construction")
148 qCDebug(LOG_VariableController()) << tr("VariableController construction")
152 << QThread::currentThread();
149 << QThread::currentThread();
153
150
154 connect(impl->m_VariableModel, &VariableModel::abortProgessRequested, this,
151 connect(impl->m_VariableModel, &VariableModel::abortProgessRequested, this,
155 &VariableController::onAbortProgressRequested);
152 &VariableController::onAbortProgressRequested);
156
153
157 connect(impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::dataProvided, this,
154 connect(impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::dataProvided, this,
158 &VariableController::onDataProvided);
155 &VariableController::onDataProvided);
159 connect(impl->m_VariableAcquisitionWorker.get(),
156 connect(impl->m_VariableAcquisitionWorker.get(),
160 &VariableAcquisitionWorker::variableRequestInProgress, this,
157 &VariableAcquisitionWorker::variableRequestInProgress, this,
161 &VariableController::onVariableRetrieveDataInProgress);
158 &VariableController::onVariableRetrieveDataInProgress);
162
159
163 connect(&impl->m_VariableAcquisitionWorkerThread, &QThread::started,
160 connect(&impl->m_VariableAcquisitionWorkerThread, &QThread::started,
164 impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::initialize);
161 impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::initialize);
165 connect(&impl->m_VariableAcquisitionWorkerThread, &QThread::finished,
162 connect(&impl->m_VariableAcquisitionWorkerThread, &QThread::finished,
166 impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::finalize);
163 impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::finalize);
167
164
168
165
169 impl->m_VariableAcquisitionWorkerThread.start();
166 impl->m_VariableAcquisitionWorkerThread.start();
170 }
167 }
171
168
172 VariableController::~VariableController()
169 VariableController::~VariableController()
173 {
170 {
174 qCDebug(LOG_VariableController()) << tr("VariableController destruction")
171 qCDebug(LOG_VariableController()) << tr("VariableController destruction")
175 << QThread::currentThread();
172 << QThread::currentThread();
176 this->waitForFinish();
173 this->waitForFinish();
177 }
174 }
178
175
179 VariableModel *VariableController::variableModel() noexcept
176 VariableModel *VariableController::variableModel() noexcept
180 {
177 {
181 return impl->m_VariableModel;
178 return impl->m_VariableModel;
182 }
179 }
183
180
184 QItemSelectionModel *VariableController::variableSelectionModel() noexcept
181 QItemSelectionModel *VariableController::variableSelectionModel() noexcept
185 {
182 {
186 return impl->m_VariableSelectionModel;
183 return impl->m_VariableSelectionModel;
187 }
184 }
188
185
189 void VariableController::setTimeController(TimeController *timeController) noexcept
186 void VariableController::setTimeController(TimeController *timeController) noexcept
190 {
187 {
191 impl->m_TimeController = timeController;
188 impl->m_TimeController = timeController;
192 }
189 }
193
190
194 void VariableController::deleteVariable(std::shared_ptr<Variable> variable) noexcept
191 void VariableController::deleteVariable(std::shared_ptr<Variable> variable) noexcept
195 {
192 {
196 if (!variable) {
193 if (!variable) {
197 qCCritical(LOG_VariableController()) << "Can't delete variable: variable is null";
194 qCCritical(LOG_VariableController()) << "Can't delete variable: variable is null";
198 return;
195 return;
199 }
196 }
200
197
201 // Spreads in SciQlop that the variable will be deleted, so that potential receivers can
198 // Spreads in SciQlop that the variable will be deleted, so that potential receivers can
202 // make some treatments before the deletion
199 // make some treatments before the deletion
203 emit variableAboutToBeDeleted(variable);
200 emit variableAboutToBeDeleted(variable);
204
201
205 // Deletes identifier
202 // Deletes identifier
206 impl->m_VariableToIdentifierMap.erase(variable);
203 impl->m_VariableToIdentifierMap.erase(variable);
207
204
208 // Deletes provider
205 // Deletes provider
209 auto nbProvidersDeleted = impl->m_VariableToProviderMap.erase(variable);
206 auto nbProvidersDeleted = impl->m_VariableToProviderMap.erase(variable);
210 qCDebug(LOG_VariableController())
207 qCDebug(LOG_VariableController())
211 << tr("Number of providers deleted for variable %1: %2")
208 << tr("Number of providers deleted for variable %1: %2")
212 .arg(variable->name(), QString::number(nbProvidersDeleted));
209 .arg(variable->name(), QString::number(nbProvidersDeleted));
213
210
214 // Clears cache
215 impl->m_VariableCacheController->clear(variable);
216
211
217 // Deletes from model
212 // Deletes from model
218 impl->m_VariableModel->deleteVariable(variable);
213 impl->m_VariableModel->deleteVariable(variable);
219 }
214 }
220
215
221 void VariableController::deleteVariables(
216 void VariableController::deleteVariables(
222 const QVector<std::shared_ptr<Variable> > &variables) noexcept
217 const QVector<std::shared_ptr<Variable> > &variables) noexcept
223 {
218 {
224 for (auto variable : qAsConst(variables)) {
219 for (auto variable : qAsConst(variables)) {
225 deleteVariable(variable);
220 deleteVariable(variable);
226 }
221 }
227 }
222 }
228
223
229 void VariableController::abortProgress(std::shared_ptr<Variable> variable)
224 void VariableController::abortProgress(std::shared_ptr<Variable> variable)
230 {
225 {
231 }
226 }
232
227
233 std::shared_ptr<Variable>
228 std::shared_ptr<Variable>
234 VariableController::createVariable(const QString &name, const QVariantHash &metadata,
229 VariableController::createVariable(const QString &name, const QVariantHash &metadata,
235 std::shared_ptr<IDataProvider> provider) noexcept
230 std::shared_ptr<IDataProvider> provider) noexcept
236 {
231 {
237 if (!impl->m_TimeController) {
232 if (!impl->m_TimeController) {
238 qCCritical(LOG_VariableController())
233 qCCritical(LOG_VariableController())
239 << tr("Impossible to create variable: The time controller is null");
234 << tr("Impossible to create variable: The time controller is null");
240 return nullptr;
235 return nullptr;
241 }
236 }
242
237
243 auto range = impl->m_TimeController->dateTime();
238 auto range = impl->m_TimeController->dateTime();
244
239
245 if (auto newVariable = impl->m_VariableModel->createVariable(name, range, metadata)) {
240 if (auto newVariable = impl->m_VariableModel->createVariable(name, range, metadata)) {
246 auto identifier = QUuid::createUuid();
241 auto identifier = QUuid::createUuid();
247
242
248 // store the provider
243 // store the provider
249 impl->registerProvider(provider);
244 impl->registerProvider(provider);
250
245
251 // Associate the provider
246 // Associate the provider
252 impl->m_VariableToProviderMap[newVariable] = provider;
247 impl->m_VariableToProviderMap[newVariable] = provider;
253 impl->m_VariableToIdentifierMap[newVariable] = identifier;
248 impl->m_VariableToIdentifierMap[newVariable] = identifier;
254
249
255
250
256 auto varRequestId = QUuid::createUuid();
251 auto varRequestId = QUuid::createUuid();
257 qCInfo(LOG_VariableController()) << "processRequest for" << name << varRequestId;
252 qCInfo(LOG_VariableController()) << "processRequest for" << name << varRequestId;
258 impl->processRequest(newVariable, range, varRequestId);
253 impl->processRequest(newVariable, range, varRequestId);
259 impl->updateVariableRequest(varRequestId);
254 impl->updateVariableRequest(varRequestId);
260
255
261 return newVariable;
256 return newVariable;
262 }
257 }
263 }
258 }
264
259
265 void VariableController::onDateTimeOnSelection(const SqpRange &dateTime)
260 void VariableController::onDateTimeOnSelection(const SqpRange &dateTime)
266 {
261 {
267 // TODO check synchronisation and Rescale
262 // TODO check synchronisation and Rescale
268 qCDebug(LOG_VariableController()) << "VariableController::onDateTimeOnSelection"
263 qCDebug(LOG_VariableController()) << "VariableController::onDateTimeOnSelection"
269 << QThread::currentThread()->objectName();
264 << QThread::currentThread()->objectName();
270 auto selectedRows = impl->m_VariableSelectionModel->selectedRows();
265 auto selectedRows = impl->m_VariableSelectionModel->selectedRows();
271 auto varRequestId = QUuid::createUuid();
266 auto varRequestId = QUuid::createUuid();
272
267
273 for (const auto &selectedRow : qAsConst(selectedRows)) {
268 for (const auto &selectedRow : qAsConst(selectedRows)) {
274 if (auto selectedVariable = impl->m_VariableModel->variable(selectedRow.row())) {
269 if (auto selectedVariable = impl->m_VariableModel->variable(selectedRow.row())) {
275 selectedVariable->setRange(dateTime);
270 selectedVariable->setRange(dateTime);
276 impl->processRequest(selectedVariable, dateTime, varRequestId);
271 impl->processRequest(selectedVariable, dateTime, varRequestId);
277
272
278 // notify that rescale operation has to be done
273 // notify that rescale operation has to be done
279 emit rangeChanged(selectedVariable, dateTime);
274 emit rangeChanged(selectedVariable, dateTime);
280 }
275 }
281 }
276 }
282 impl->updateVariableRequest(varRequestId);
277 impl->updateVariableRequest(varRequestId);
283 }
278 }
284
279
285 void VariableController::onDataProvided(QUuid vIdentifier, const SqpRange &rangeRequested,
280 void VariableController::onDataProvided(QUuid vIdentifier, const SqpRange &rangeRequested,
286 const SqpRange &cacheRangeRequested,
281 const SqpRange &cacheRangeRequested,
287 QVector<AcquisitionDataPacket> dataAcquired)
282 QVector<AcquisitionDataPacket> dataAcquired)
288 {
283 {
289 auto retrievedDataSeries = impl->retrieveDataSeries(dataAcquired);
284 auto retrievedDataSeries = impl->retrieveDataSeries(dataAcquired);
290 auto varRequestId = impl->acceptVariableRequest(vIdentifier, retrievedDataSeries);
285 auto varRequestId = impl->acceptVariableRequest(vIdentifier, retrievedDataSeries);
291 if (!varRequestId.isNull()) {
286 if (!varRequestId.isNull()) {
292 impl->updateVariableRequest(varRequestId);
287 impl->updateVariableRequest(varRequestId);
293 }
288 }
294 }
289 }
295
290
296 void VariableController::onVariableRetrieveDataInProgress(QUuid identifier, double progress)
291 void VariableController::onVariableRetrieveDataInProgress(QUuid identifier, double progress)
297 {
292 {
298 if (auto var = impl->findVariable(identifier)) {
293 if (auto var = impl->findVariable(identifier)) {
299 impl->m_VariableModel->setDataProgress(var, progress);
294 impl->m_VariableModel->setDataProgress(var, progress);
300 }
295 }
301 else {
296 else {
302 qCCritical(LOG_VariableController())
297 qCCritical(LOG_VariableController())
303 << tr("Impossible to notify progression of a null variable");
298 << tr("Impossible to notify progression of a null variable");
304 }
299 }
305 }
300 }
306
301
307 void VariableController::onAbortProgressRequested(std::shared_ptr<Variable> variable)
302 void VariableController::onAbortProgressRequested(std::shared_ptr<Variable> variable)
308 {
303 {
309 qCDebug(LOG_VariableController()) << "TORM: VariableController::onAbortProgressRequested"
304 qCDebug(LOG_VariableController()) << "TORM: VariableController::onAbortProgressRequested"
310 << QThread::currentThread()->objectName();
305 << QThread::currentThread()->objectName();
311
306
312 auto it = impl->m_VariableToIdentifierMap.find(variable);
307 auto it = impl->m_VariableToIdentifierMap.find(variable);
313 if (it != impl->m_VariableToIdentifierMap.cend()) {
308 if (it != impl->m_VariableToIdentifierMap.cend()) {
314 impl->m_VariableToProviderMap.at(variable)->requestDataAborting(it->second);
309 impl->m_VariableToProviderMap.at(variable)->requestDataAborting(it->second);
315 }
310 }
316 else {
311 else {
317 qCWarning(LOG_VariableController())
312 qCWarning(LOG_VariableController())
318 << tr("Aborting progression of inexistant variable detected !!!")
313 << tr("Aborting progression of inexistant variable detected !!!")
319 << QThread::currentThread()->objectName();
314 << QThread::currentThread()->objectName();
320 }
315 }
321 }
316 }
322
317
323 void VariableController::onAddSynchronizationGroupId(QUuid synchronizationGroupId)
318 void VariableController::onAddSynchronizationGroupId(QUuid synchronizationGroupId)
324 {
319 {
325 qCDebug(LOG_VariableController()) << "TORM: VariableController::onAddSynchronizationGroupId"
320 qCDebug(LOG_VariableController()) << "TORM: VariableController::onAddSynchronizationGroupId"
326 << QThread::currentThread()->objectName()
321 << QThread::currentThread()->objectName()
327 << synchronizationGroupId;
322 << synchronizationGroupId;
328 auto vSynchroGroup = std::make_shared<VariableSynchronizationGroup>();
323 auto vSynchroGroup = std::make_shared<VariableSynchronizationGroup>();
329 impl->m_GroupIdToVariableSynchronizationGroupMap.insert(
324 impl->m_GroupIdToVariableSynchronizationGroupMap.insert(
330 std::make_pair(synchronizationGroupId, vSynchroGroup));
325 std::make_pair(synchronizationGroupId, vSynchroGroup));
331 }
326 }
332
327
333 void VariableController::onRemoveSynchronizationGroupId(QUuid synchronizationGroupId)
328 void VariableController::onRemoveSynchronizationGroupId(QUuid synchronizationGroupId)
334 {
329 {
335 impl->m_GroupIdToVariableSynchronizationGroupMap.erase(synchronizationGroupId);
330 impl->m_GroupIdToVariableSynchronizationGroupMap.erase(synchronizationGroupId);
336 }
331 }
337
332
338 void VariableController::onAddSynchronized(std::shared_ptr<Variable> variable,
333 void VariableController::onAddSynchronized(std::shared_ptr<Variable> variable,
339 QUuid synchronizationGroupId)
334 QUuid synchronizationGroupId)
340
335
341 {
336 {
342 qCDebug(LOG_VariableController()) << "TORM: VariableController::onAddSynchronized"
337 qCDebug(LOG_VariableController()) << "TORM: VariableController::onAddSynchronized"
343 << synchronizationGroupId;
338 << synchronizationGroupId;
344 auto varToVarIdIt = impl->m_VariableToIdentifierMap.find(variable);
339 auto varToVarIdIt = impl->m_VariableToIdentifierMap.find(variable);
345 if (varToVarIdIt != impl->m_VariableToIdentifierMap.cend()) {
340 if (varToVarIdIt != impl->m_VariableToIdentifierMap.cend()) {
346 auto groupIdToVSGIt
341 auto groupIdToVSGIt
347 = impl->m_GroupIdToVariableSynchronizationGroupMap.find(synchronizationGroupId);
342 = impl->m_GroupIdToVariableSynchronizationGroupMap.find(synchronizationGroupId);
348 if (groupIdToVSGIt != impl->m_GroupIdToVariableSynchronizationGroupMap.cend()) {
343 if (groupIdToVSGIt != impl->m_GroupIdToVariableSynchronizationGroupMap.cend()) {
349 impl->m_VariableIdGroupIdMap.insert(
344 impl->m_VariableIdGroupIdMap.insert(
350 std::make_pair(varToVarIdIt->second, synchronizationGroupId));
345 std::make_pair(varToVarIdIt->second, synchronizationGroupId));
351 groupIdToVSGIt->second->addVariableId(varToVarIdIt->second);
346 groupIdToVSGIt->second->addVariableId(varToVarIdIt->second);
352 }
347 }
353 else {
348 else {
354 qCCritical(LOG_VariableController())
349 qCCritical(LOG_VariableController())
355 << tr("Impossible to synchronize a variable with an unknown sycnhronization group")
350 << tr("Impossible to synchronize a variable with an unknown sycnhronization group")
356 << variable->name();
351 << variable->name();
357 }
352 }
358 }
353 }
359 else {
354 else {
360 qCCritical(LOG_VariableController())
355 qCCritical(LOG_VariableController())
361 << tr("Impossible to synchronize a variable with no identifier") << variable->name();
356 << tr("Impossible to synchronize a variable with no identifier") << variable->name();
362 }
357 }
363 }
358 }
364
359
365
360
366 void VariableController::onRequestDataLoading(QVector<std::shared_ptr<Variable> > variables,
361 void VariableController::onRequestDataLoading(QVector<std::shared_ptr<Variable> > variables,
367 const SqpRange &range, const SqpRange &oldRange,
362 const SqpRange &range, const SqpRange &oldRange,
368 bool synchronise)
363 bool synchronise)
369 {
364 {
370 // NOTE: oldRange isn't really necessary since oldRange == variable->range().
365 // NOTE: oldRange isn't really necessary since oldRange == variable->range().
371
366
372 qCDebug(LOG_VariableController()) << "VariableController::onRequestDataLoading"
373 << QThread::currentThread()->objectName();
374 // we want to load data of the variable for the dateTime.
367 // we want to load data of the variable for the dateTime.
375 // First we check if the cache contains some of them.
368 // First we check if the cache contains some of them.
376 // For the other, we ask the provider to give them.
369 // For the other, we ask the provider to give them.
377
370
378 auto varRequestId = QUuid::createUuid();
371 auto varRequestId = QUuid::createUuid();
372 qCInfo(LOG_VariableController()) << "VariableController::onRequestDataLoading"
373 << QThread::currentThread()->objectName() << varRequestId;
379
374
380 for (const auto &var : variables) {
375 for (const auto &var : variables) {
381 qCInfo(LOG_VariableController()) << "processRequest for" << var->name() << varRequestId;
376 qCDebug(LOG_VariableController()) << "processRequest for" << var->name() << varRequestId;
382 impl->processRequest(var, range, varRequestId);
377 impl->processRequest(var, range, varRequestId);
383 }
378 }
384
379
385 if (synchronise) {
380 if (synchronise) {
386 // Get the group ids
381 // Get the group ids
387 qCDebug(LOG_VariableController())
382 qCDebug(LOG_VariableController())
388 << "TORM VariableController::onRequestDataLoading for synchro var ENABLE";
383 << "TORM VariableController::onRequestDataLoading for synchro var ENABLE";
389 auto groupIds = std::set<QUuid>();
384 auto groupIds = std::set<QUuid>{};
385 auto groupIdToOldRangeMap = std::map<QUuid, SqpRange>{};
390 for (const auto &var : variables) {
386 for (const auto &var : variables) {
391 auto varToVarIdIt = impl->m_VariableToIdentifierMap.find(var);
387 auto varToVarIdIt = impl->m_VariableToIdentifierMap.find(var);
392 if (varToVarIdIt != impl->m_VariableToIdentifierMap.cend()) {
388 if (varToVarIdIt != impl->m_VariableToIdentifierMap.cend()) {
393 auto vId = varToVarIdIt->second;
389 auto vId = varToVarIdIt->second;
394 auto varIdToGroupIdIt = impl->m_VariableIdGroupIdMap.find(vId);
390 auto varIdToGroupIdIt = impl->m_VariableIdGroupIdMap.find(vId);
395 if (varIdToGroupIdIt != impl->m_VariableIdGroupIdMap.cend()) {
391 if (varIdToGroupIdIt != impl->m_VariableIdGroupIdMap.cend()) {
396 auto gId = varIdToGroupIdIt->second;
392 auto gId = varIdToGroupIdIt->second;
393 groupIdToOldRangeMap.insert(std::make_pair(gId, var->range()));
397 if (groupIds.find(gId) == groupIds.cend()) {
394 if (groupIds.find(gId) == groupIds.cend()) {
398 qCDebug(LOG_VariableController()) << "Synchro detect group " << gId;
395 qCDebug(LOG_VariableController()) << "Synchro detect group " << gId;
399 groupIds.insert(gId);
396 groupIds.insert(gId);
400 }
397 }
401 }
398 }
402 }
399 }
403 }
400 }
404
401
405 // We assume here all group ids exist
402 // We assume here all group ids exist
406 for (const auto &gId : groupIds) {
403 for (const auto &gId : groupIds) {
407 auto vSynchronizationGroup = impl->m_GroupIdToVariableSynchronizationGroupMap.at(gId);
404 auto vSynchronizationGroup = impl->m_GroupIdToVariableSynchronizationGroupMap.at(gId);
408 auto vSyncIds = vSynchronizationGroup->getIds();
405 auto vSyncIds = vSynchronizationGroup->getIds();
409 qCDebug(LOG_VariableController()) << "Var in synchro group ";
406 qCDebug(LOG_VariableController()) << "Var in synchro group ";
410 for (auto vId : vSyncIds) {
407 for (auto vId : vSyncIds) {
411 auto var = impl->findVariable(vId);
408 auto var = impl->findVariable(vId);
412
409
413 // Don't process already processed var
410 // Don't process already processed var
414 if (!variables.contains(var)) {
411 if (!variables.contains(var)) {
415 if (var != nullptr) {
412 if (var != nullptr) {
416 qCDebug(LOG_VariableController()) << "processRequest synchro for"
413 qCDebug(LOG_VariableController()) << "processRequest synchro for"
417 << var->name();
414 << var->name();
418 auto vSyncRangeRequested
415 auto vSyncRangeRequested = computeSynchroRangeRequested(
419 = computeSynchroRangeRequested(var->range(), range, oldRange);
416 var->range(), range, groupIdToOldRangeMap.at(gId));
417 qCDebug(LOG_VariableController()) << "synchro RR" << vSyncRangeRequested;
420 impl->processRequest(var, vSyncRangeRequested, varRequestId);
418 impl->processRequest(var, vSyncRangeRequested, varRequestId);
421 }
419 }
422 else {
420 else {
423 qCCritical(LOG_VariableController())
421 qCCritical(LOG_VariableController())
424
422
425 << tr("Impossible to synchronize a null variable");
423 << tr("Impossible to synchronize a null variable");
426 }
424 }
427 }
425 }
428 }
426 }
429 }
427 }
430 }
428 }
431
429
432 impl->updateVariableRequest(varRequestId);
430 impl->updateVariableRequest(varRequestId);
433 }
431 }
434
432
435
433
436 void VariableController::initialize()
434 void VariableController::initialize()
437 {
435 {
438 qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread();
436 qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread();
439 impl->m_WorkingMutex.lock();
437 impl->m_WorkingMutex.lock();
440 qCDebug(LOG_VariableController()) << tr("VariableController init END");
438 qCDebug(LOG_VariableController()) << tr("VariableController init END");
441 }
439 }
442
440
443 void VariableController::finalize()
441 void VariableController::finalize()
444 {
442 {
445 impl->m_WorkingMutex.unlock();
443 impl->m_WorkingMutex.unlock();
446 }
444 }
447
445
448 void VariableController::waitForFinish()
446 void VariableController::waitForFinish()
449 {
447 {
450 QMutexLocker locker{&impl->m_WorkingMutex};
448 QMutexLocker locker{&impl->m_WorkingMutex};
451 }
449 }
452
450
453 AcquisitionZoomType VariableController::getZoomType(const SqpRange &range, const SqpRange &oldRange)
451 AcquisitionZoomType VariableController::getZoomType(const SqpRange &range, const SqpRange &oldRange)
454 {
452 {
455 // t1.m_TStart <= t2.m_TStart && t2.m_TEnd <= t1.m_TEnd
453 // t1.m_TStart <= t2.m_TStart && t2.m_TEnd <= t1.m_TEnd
456 auto zoomType = AcquisitionZoomType::Unknown;
454 auto zoomType = AcquisitionZoomType::Unknown;
457 if (range.m_TStart <= oldRange.m_TStart && oldRange.m_TEnd <= range.m_TEnd) {
455 if (range.m_TStart <= oldRange.m_TStart && oldRange.m_TEnd <= range.m_TEnd) {
458 zoomType = AcquisitionZoomType::ZoomOut;
456 zoomType = AcquisitionZoomType::ZoomOut;
459 }
457 }
460 else if (range.m_TStart > oldRange.m_TStart && range.m_TEnd > oldRange.m_TEnd) {
458 else if (range.m_TStart > oldRange.m_TStart && range.m_TEnd > oldRange.m_TEnd) {
461 zoomType = AcquisitionZoomType::PanRight;
459 zoomType = AcquisitionZoomType::PanRight;
462 }
460 }
463 else if (range.m_TStart < oldRange.m_TStart && range.m_TEnd < oldRange.m_TEnd) {
461 else if (range.m_TStart < oldRange.m_TStart && range.m_TEnd < oldRange.m_TEnd) {
464 zoomType = AcquisitionZoomType::PanLeft;
462 zoomType = AcquisitionZoomType::PanLeft;
465 }
463 }
466 else if (range.m_TStart > oldRange.m_TStart && oldRange.m_TEnd > range.m_TEnd) {
464 else if (range.m_TStart > oldRange.m_TStart && oldRange.m_TEnd > range.m_TEnd) {
467 zoomType = AcquisitionZoomType::ZoomIn;
465 zoomType = AcquisitionZoomType::ZoomIn;
468 }
466 }
469 else {
467 else {
470 qCCritical(LOG_VariableController()) << "getZoomType: Unknown type detected";
468 qCCritical(LOG_VariableController()) << "getZoomType: Unknown type detected";
471 }
469 }
472 return zoomType;
470 return zoomType;
473 }
471 }
474
472
475 void VariableController::VariableControllerPrivate::processRequest(std::shared_ptr<Variable> var,
473 void VariableController::VariableControllerPrivate::processRequest(std::shared_ptr<Variable> var,
476 const SqpRange &rangeRequested,
474 const SqpRange &rangeRequested,
477 QUuid varRequestId)
475 QUuid varRequestId)
478 {
476 {
479
477
480 // TODO: protect at
478 // TODO: protect at
481 auto varRequest = VariableRequest{};
479 auto varRequest = VariableRequest{};
482 auto varId = m_VariableToIdentifierMap.at(var);
480 auto varId = m_VariableToIdentifierMap.at(var);
483
481
484
485 auto varStrategyRangesRequested
482 auto varStrategyRangesRequested
486 = m_VariableCacheStrategy->computeStrategyRanges(var->range(), rangeRequested);
483 = m_VariableCacheStrategy->computeStrategyRanges(var->range(), rangeRequested);
487 auto notInCacheRangeList = var->provideNotInCacheRangeList(varStrategyRangesRequested.second);
484 auto notInCacheRangeList = var->provideNotInCacheRangeList(varStrategyRangesRequested.second);
488 auto inCacheRangeList = var->provideInCacheRangeList(varStrategyRangesRequested.second);
485 auto inCacheRangeList = var->provideInCacheRangeList(varStrategyRangesRequested.second);
489
486
490 if (!notInCacheRangeList.empty()) {
487 if (!notInCacheRangeList.empty()) {
491 varRequest.m_RangeRequested = varStrategyRangesRequested.first;
488 varRequest.m_RangeRequested = varStrategyRangesRequested.first;
492 varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second;
489 varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second;
490 qCDebug(LOG_VariableAcquisitionWorker()) << tr("TORM processRequest RR ") << rangeRequested;
491 qCDebug(LOG_VariableAcquisitionWorker()) << tr("TORM processRequest R ")
492 << varStrategyRangesRequested.first;
493 qCDebug(LOG_VariableAcquisitionWorker()) << tr("TORM processRequest CR ")
494 << varStrategyRangesRequested.second;
493 // store VarRequest
495 // store VarRequest
494 storeVariableRequest(varId, varRequestId, varRequest);
496 storeVariableRequest(varId, varRequestId, varRequest);
495
497
496 auto varProvider = m_VariableToProviderMap.at(var);
498 auto varProvider = m_VariableToProviderMap.at(var);
497 if (varProvider != nullptr) {
499 if (varProvider != nullptr) {
498 auto varRequestIdCanceled = m_VariableAcquisitionWorker->pushVariableRequest(
500 auto varRequestIdCanceled = m_VariableAcquisitionWorker->pushVariableRequest(
499 varRequestId, varId, varStrategyRangesRequested.first,
501 varRequestId, varId, varStrategyRangesRequested.first,
500 varStrategyRangesRequested.second,
502 varStrategyRangesRequested.second,
501 DataProviderParameters{std::move(notInCacheRangeList), var->metadata()},
503 DataProviderParameters{std::move(notInCacheRangeList), var->metadata()},
502 varProvider);
504 varProvider);
503
505
504 if (!varRequestIdCanceled.isNull()) {
506 if (!varRequestIdCanceled.isNull()) {
507 qCInfo(LOG_VariableAcquisitionWorker()) << tr("varRequestIdCanceled: ")
508 << varRequestIdCanceled;
505 cancelVariableRequest(varRequestIdCanceled);
509 cancelVariableRequest(varRequestIdCanceled);
506 }
510 }
507 }
511 }
508 else {
512 else {
509 qCCritical(LOG_VariableController())
513 qCCritical(LOG_VariableController())
510 << "Impossible to provide data with a null provider";
514 << "Impossible to provide data with a null provider";
511 }
515 }
512
516
513 if (!inCacheRangeList.empty()) {
517 if (!inCacheRangeList.empty()) {
514 emit q->updateVarDisplaying(var, inCacheRangeList.first());
518 emit q->updateVarDisplaying(var, inCacheRangeList.first());
515 }
519 }
516 }
520 }
517 else {
521 else {
518
522
519 varRequest.m_RangeRequested = varStrategyRangesRequested.first;
523 varRequest.m_RangeRequested = varStrategyRangesRequested.first;
520 varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second;
524 varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second;
521 // store VarRequest
525 // store VarRequest
522 storeVariableRequest(varId, varRequestId, varRequest);
526 storeVariableRequest(varId, varRequestId, varRequest);
523 acceptVariableRequest(varId,
527 acceptVariableRequest(varId,
524 var->dataSeries()->subDataSeries(varStrategyRangesRequested.second));
528 var->dataSeries()->subDataSeries(varStrategyRangesRequested.second));
525 }
529 }
526 }
530 }
527
531
528 std::shared_ptr<Variable>
532 std::shared_ptr<Variable>
529 VariableController::VariableControllerPrivate::findVariable(QUuid vIdentifier)
533 VariableController::VariableControllerPrivate::findVariable(QUuid vIdentifier)
530 {
534 {
531 std::shared_ptr<Variable> var;
535 std::shared_ptr<Variable> var;
532 auto findReply = [vIdentifier](const auto &entry) { return vIdentifier == entry.second; };
536 auto findReply = [vIdentifier](const auto &entry) { return vIdentifier == entry.second; };
533
537
534 auto end = m_VariableToIdentifierMap.cend();
538 auto end = m_VariableToIdentifierMap.cend();
535 auto it = std::find_if(m_VariableToIdentifierMap.cbegin(), end, findReply);
539 auto it = std::find_if(m_VariableToIdentifierMap.cbegin(), end, findReply);
536 if (it != end) {
540 if (it != end) {
537 var = it->first;
541 var = it->first;
538 }
542 }
539 else {
543 else {
540 qCCritical(LOG_VariableController())
544 qCCritical(LOG_VariableController())
541 << tr("Impossible to find the variable with the identifier: ") << vIdentifier;
545 << tr("Impossible to find the variable with the identifier: ") << vIdentifier;
542 }
546 }
543
547
544 return var;
548 return var;
545 }
549 }
546
550
547 std::shared_ptr<IDataSeries> VariableController::VariableControllerPrivate::retrieveDataSeries(
551 std::shared_ptr<IDataSeries> VariableController::VariableControllerPrivate::retrieveDataSeries(
548 const QVector<AcquisitionDataPacket> acqDataPacketVector)
552 const QVector<AcquisitionDataPacket> acqDataPacketVector)
549 {
553 {
550 qCDebug(LOG_VariableController()) << tr("TORM: retrieveDataSeries acqDataPacketVector size")
554 qCDebug(LOG_VariableController()) << tr("TORM: retrieveDataSeries acqDataPacketVector size")
551 << acqDataPacketVector.size();
555 << acqDataPacketVector.size();
552 std::shared_ptr<IDataSeries> dataSeries;
556 std::shared_ptr<IDataSeries> dataSeries;
553 if (!acqDataPacketVector.isEmpty()) {
557 if (!acqDataPacketVector.isEmpty()) {
554 dataSeries = acqDataPacketVector[0].m_DateSeries;
558 dataSeries = acqDataPacketVector[0].m_DateSeries;
555 for (int i = 1; i < acqDataPacketVector.size(); ++i) {
559 for (int i = 1; i < acqDataPacketVector.size(); ++i) {
556 dataSeries->merge(acqDataPacketVector[i].m_DateSeries.get());
560 dataSeries->merge(acqDataPacketVector[i].m_DateSeries.get());
557 }
561 }
558 }
562 }
559 qCDebug(LOG_VariableController()) << tr("TORM: retrieveDataSeries acqDataPacketVector size END")
563 qCDebug(LOG_VariableController()) << tr("TORM: retrieveDataSeries acqDataPacketVector size END")
560 << acqDataPacketVector.size();
564 << acqDataPacketVector.size();
561 return dataSeries;
565 return dataSeries;
562 }
566 }
563
567
564 void VariableController::VariableControllerPrivate::registerProvider(
568 void VariableController::VariableControllerPrivate::registerProvider(
565 std::shared_ptr<IDataProvider> provider)
569 std::shared_ptr<IDataProvider> provider)
566 {
570 {
567 if (m_ProviderSet.find(provider) == m_ProviderSet.end()) {
571 if (m_ProviderSet.find(provider) == m_ProviderSet.end()) {
568 qCDebug(LOG_VariableController()) << tr("Registering of a new provider")
572 qCDebug(LOG_VariableController()) << tr("Registering of a new provider")
569 << provider->objectName();
573 << provider->objectName();
570 m_ProviderSet.insert(provider);
574 m_ProviderSet.insert(provider);
571 connect(provider.get(), &IDataProvider::dataProvided, m_VariableAcquisitionWorker.get(),
575 connect(provider.get(), &IDataProvider::dataProvided, m_VariableAcquisitionWorker.get(),
572 &VariableAcquisitionWorker::onVariableDataAcquired);
576 &VariableAcquisitionWorker::onVariableDataAcquired);
573 connect(provider.get(), &IDataProvider::dataProvidedProgress,
577 connect(provider.get(), &IDataProvider::dataProvidedProgress,
574 m_VariableAcquisitionWorker.get(),
578 m_VariableAcquisitionWorker.get(),
575 &VariableAcquisitionWorker::onVariableRetrieveDataInProgress);
579 &VariableAcquisitionWorker::onVariableRetrieveDataInProgress);
576 }
580 }
577 else {
581 else {
578 qCDebug(LOG_VariableController()) << tr("Cannot register provider, it already exists ");
582 qCDebug(LOG_VariableController()) << tr("Cannot register provider, it already exists ");
579 }
583 }
580 }
584 }
581
585
582 void VariableController::VariableControllerPrivate::storeVariableRequest(
586 void VariableController::VariableControllerPrivate::storeVariableRequest(
583 QUuid varId, QUuid varRequestId, const VariableRequest &varRequest)
587 QUuid varId, QUuid varRequestId, const VariableRequest &varRequest)
584 {
588 {
585 // First request for the variable. we can create an entry for it
589 // First request for the variable. we can create an entry for it
586 auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.find(varId);
590 auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.find(varId);
587 if (varIdToVarRequestIdQueueMapIt == m_VarIdToVarRequestIdQueueMap.cend()) {
591 if (varIdToVarRequestIdQueueMapIt == m_VarIdToVarRequestIdQueueMap.cend()) {
588 auto varRequestIdQueue = std::deque<QUuid>{};
592 auto varRequestIdQueue = std::deque<QUuid>{};
589 qCDebug(LOG_VariableController()) << tr("Store REQUEST in QUEUE");
593 qCDebug(LOG_VariableController()) << tr("Store REQUEST in QUEUE");
590 varRequestIdQueue.push_back(varRequestId);
594 varRequestIdQueue.push_back(varRequestId);
591 m_VarIdToVarRequestIdQueueMap.insert(std::make_pair(varId, std::move(varRequestIdQueue)));
595 m_VarIdToVarRequestIdQueueMap.insert(std::make_pair(varId, std::move(varRequestIdQueue)));
592 }
596 }
593 else {
597 else {
594 qCDebug(LOG_VariableController()) << tr("Store REQUEST in EXISTING QUEUE");
598 qCDebug(LOG_VariableController()) << tr("Store REQUEST in EXISTING QUEUE");
595 auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second;
599 auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second;
596 varRequestIdQueue.push_back(varRequestId);
600 varRequestIdQueue.push_back(varRequestId);
597 }
601 }
598
602
599 auto varRequestIdToVarIdVarRequestMapIt = m_VarRequestIdToVarIdVarRequestMap.find(varRequestId);
603 auto varRequestIdToVarIdVarRequestMapIt = m_VarRequestIdToVarIdVarRequestMap.find(varRequestId);
600 if (varRequestIdToVarIdVarRequestMapIt == m_VarRequestIdToVarIdVarRequestMap.cend()) {
604 if (varRequestIdToVarIdVarRequestMapIt == m_VarRequestIdToVarIdVarRequestMap.cend()) {
601 auto varIdToVarRequestMap = std::map<QUuid, VariableRequest>{};
605 auto varIdToVarRequestMap = std::map<QUuid, VariableRequest>{};
602 varIdToVarRequestMap.insert(std::make_pair(varId, varRequest));
606 varIdToVarRequestMap.insert(std::make_pair(varId, varRequest));
603 qCDebug(LOG_VariableController()) << tr("Store REQUESTID in MAP");
607 qCDebug(LOG_VariableController()) << tr("Store REQUESTID in MAP");
604 m_VarRequestIdToVarIdVarRequestMap.insert(
608 m_VarRequestIdToVarIdVarRequestMap.insert(
605 std::make_pair(varRequestId, std::move(varIdToVarRequestMap)));
609 std::make_pair(varRequestId, std::move(varIdToVarRequestMap)));
606 }
610 }
607 else {
611 else {
608 auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second;
612 auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second;
609 qCDebug(LOG_VariableController()) << tr("Store REQUESTID in EXISTING MAP");
613 qCDebug(LOG_VariableController()) << tr("Store REQUESTID in EXISTING MAP");
610 varIdToVarRequestMap.insert(std::make_pair(varId, varRequest));
614 varIdToVarRequestMap.insert(std::make_pair(varId, varRequest));
611 }
615 }
612 }
616 }
613
617
614 QUuid VariableController::VariableControllerPrivate::acceptVariableRequest(
618 QUuid VariableController::VariableControllerPrivate::acceptVariableRequest(
615 QUuid varId, std::shared_ptr<IDataSeries> dataSeries)
619 QUuid varId, std::shared_ptr<IDataSeries> dataSeries)
616 {
620 {
617 QUuid varRequestId;
621 QUuid varRequestId;
618 auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.find(varId);
622 auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.find(varId);
619 if (varIdToVarRequestIdQueueMapIt != m_VarIdToVarRequestIdQueueMap.cend()) {
623 if (varIdToVarRequestIdQueueMapIt != m_VarIdToVarRequestIdQueueMap.cend()) {
620 auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second;
624 auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second;
621 varRequestId = varRequestIdQueue.front();
625 varRequestId = varRequestIdQueue.front();
622 auto varRequestIdToVarIdVarRequestMapIt
626 auto varRequestIdToVarIdVarRequestMapIt
623 = m_VarRequestIdToVarIdVarRequestMap.find(varRequestId);
627 = m_VarRequestIdToVarIdVarRequestMap.find(varRequestId);
624 if (varRequestIdToVarIdVarRequestMapIt != m_VarRequestIdToVarIdVarRequestMap.cend()) {
628 if (varRequestIdToVarIdVarRequestMapIt != m_VarRequestIdToVarIdVarRequestMap.cend()) {
625 auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second;
629 auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second;
626 auto varIdToVarRequestMapIt = varIdToVarRequestMap.find(varId);
630 auto varIdToVarRequestMapIt = varIdToVarRequestMap.find(varId);
627 if (varIdToVarRequestMapIt != varIdToVarRequestMap.cend()) {
631 if (varIdToVarRequestMapIt != varIdToVarRequestMap.cend()) {
628 qCDebug(LOG_VariableController()) << tr("acceptVariableRequest");
632 qCDebug(LOG_VariableController()) << tr("acceptVariableRequest");
629 auto &varRequest = varIdToVarRequestMapIt->second;
633 auto &varRequest = varIdToVarRequestMapIt->second;
630 varRequest.m_DataSeries = dataSeries;
634 varRequest.m_DataSeries = dataSeries;
631 varRequest.m_CanUpdate = true;
635 varRequest.m_CanUpdate = true;
632 }
636 }
633 else {
637 else {
634 qCDebug(LOG_VariableController())
638 qCDebug(LOG_VariableController())
635 << tr("Impossible to acceptVariableRequest of a unknown variable id attached "
639 << tr("Impossible to acceptVariableRequest of a unknown variable id attached "
636 "to a variableRequestId")
640 "to a variableRequestId")
637 << varRequestId << varId;
641 << varRequestId << varId;
638 }
642 }
639 }
643 }
640 else {
644 else {
641 qCCritical(LOG_VariableController())
645 qCCritical(LOG_VariableController())
642 << tr("Impossible to acceptVariableRequest of a unknown variableRequestId")
646 << tr("Impossible to acceptVariableRequest of a unknown variableRequestId")
643 << varRequestId;
647 << varRequestId;
644 }
648 }
645
649
646 qCDebug(LOG_VariableController()) << tr("1: erase REQUEST in QUEUE ?")
650 qCDebug(LOG_VariableController()) << tr("1: erase REQUEST in QUEUE ?")
647 << varRequestIdQueue.size();
651 << varRequestIdQueue.size();
648 varRequestIdQueue.pop_front();
652 varRequestIdQueue.pop_front();
649 qCDebug(LOG_VariableController()) << tr("2: erase REQUEST in QUEUE ?")
653 qCDebug(LOG_VariableController()) << tr("2: erase REQUEST in QUEUE ?")
650 << varRequestIdQueue.size();
654 << varRequestIdQueue.size();
651 if (varRequestIdQueue.empty()) {
655 if (varRequestIdQueue.empty()) {
652 m_VarIdToVarRequestIdQueueMap.erase(varId);
656 m_VarIdToVarRequestIdQueueMap.erase(varId);
653 }
657 }
654 }
658 }
655 else {
659 else {
656 qCCritical(LOG_VariableController())
660 qCCritical(LOG_VariableController())
657 << tr("Impossible to acceptVariableRequest of a unknown variable id") << varId;
661 << tr("Impossible to acceptVariableRequest of a unknown variable id") << varId;
658 }
662 }
659
663
660 return varRequestId;
664 return varRequestId;
661 }
665 }
662
666
663 void VariableController::VariableControllerPrivate::updateVariableRequest(QUuid varRequestId)
667 void VariableController::VariableControllerPrivate::updateVariableRequest(QUuid varRequestId)
664 {
668 {
665
669
666 auto varRequestIdToVarIdVarRequestMapIt = m_VarRequestIdToVarIdVarRequestMap.find(varRequestId);
670 auto varRequestIdToVarIdVarRequestMapIt = m_VarRequestIdToVarIdVarRequestMap.find(varRequestId);
667 if (varRequestIdToVarIdVarRequestMapIt != m_VarRequestIdToVarIdVarRequestMap.cend()) {
671 if (varRequestIdToVarIdVarRequestMapIt != m_VarRequestIdToVarIdVarRequestMap.cend()) {
668 bool processVariableUpdate = true;
672 bool processVariableUpdate = true;
669 auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second;
673 auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second;
670 for (auto varIdToVarRequestMapIt = varIdToVarRequestMap.cbegin();
674 for (auto varIdToVarRequestMapIt = varIdToVarRequestMap.cbegin();
671 (varIdToVarRequestMapIt != varIdToVarRequestMap.cend()) && processVariableUpdate;
675 (varIdToVarRequestMapIt != varIdToVarRequestMap.cend()) && processVariableUpdate;
672 ++varIdToVarRequestMapIt) {
676 ++varIdToVarRequestMapIt) {
673 processVariableUpdate &= varIdToVarRequestMapIt->second.m_CanUpdate;
677 processVariableUpdate &= varIdToVarRequestMapIt->second.m_CanUpdate;
674 qCDebug(LOG_VariableController()) << tr("updateVariableRequest")
678 qCDebug(LOG_VariableController()) << tr("updateVariableRequest")
675 << processVariableUpdate;
679 << processVariableUpdate;
676 }
680 }
677
681
678 if (processVariableUpdate) {
682 if (processVariableUpdate) {
679 for (auto varIdToVarRequestMapIt = varIdToVarRequestMap.cbegin();
683 for (auto varIdToVarRequestMapIt = varIdToVarRequestMap.cbegin();
680 varIdToVarRequestMapIt != varIdToVarRequestMap.cend(); ++varIdToVarRequestMapIt) {
684 varIdToVarRequestMapIt != varIdToVarRequestMap.cend(); ++varIdToVarRequestMapIt) {
681 if (auto var = findVariable(varIdToVarRequestMapIt->first)) {
685 if (auto var = findVariable(varIdToVarRequestMapIt->first)) {
682 auto &varRequest = varIdToVarRequestMapIt->second;
686 auto &varRequest = varIdToVarRequestMapIt->second;
683 var->setRange(varRequest.m_RangeRequested);
687 var->setRange(varRequest.m_RangeRequested);
684 var->setCacheRange(varRequest.m_CacheRangeRequested);
688 var->setCacheRange(varRequest.m_CacheRangeRequested);
685 qCInfo(LOG_VariableController()) << tr("1: onDataProvided")
689 qCDebug(LOG_VariableController()) << tr("1: onDataProvided")
686 << varRequest.m_RangeRequested;
690 << varRequest.m_RangeRequested;
687 qCInfo(LOG_VariableController()) << tr("2: onDataProvided")
691 qCDebug(LOG_VariableController()) << tr("2: onDataProvided")
688 << varRequest.m_CacheRangeRequested;
692 << varRequest.m_CacheRangeRequested;
689 var->mergeDataSeries(varRequest.m_DataSeries);
693 var->mergeDataSeries(varRequest.m_DataSeries);
690 qCInfo(LOG_VariableController()) << tr("3: onDataProvided")
694 qCDebug(LOG_VariableController()) << tr("3: onDataProvided")
691 << varRequest.m_DataSeries->range();
695 << varRequest.m_DataSeries->range();
692 qCDebug(LOG_VariableController()) << tr("4: onDataProvided");
696 qCDebug(LOG_VariableController()) << tr("4: onDataProvided");
693 emit var->updated();
697 emit var->updated();
694 }
698 }
695 else {
699 else {
696 qCCritical(LOG_VariableController())
700 qCCritical(LOG_VariableController())
697 << tr("Impossible to update data to a null variable");
701 << tr("Impossible to update data to a null variable");
698 }
702 }
699 }
703 }
700
704
701 // cleaning varRequestId
705 // cleaning varRequestId
702 qCDebug(LOG_VariableController()) << tr("0: erase REQUEST in MAP ?")
706 qCDebug(LOG_VariableController()) << tr("0: erase REQUEST in MAP ?")
703 << m_VarRequestIdToVarIdVarRequestMap.size();
707 << m_VarRequestIdToVarIdVarRequestMap.size();
704 m_VarRequestIdToVarIdVarRequestMap.erase(varRequestId);
708 m_VarRequestIdToVarIdVarRequestMap.erase(varRequestId);
705 qCDebug(LOG_VariableController()) << tr("1: erase REQUEST in MAP ?")
709 qCDebug(LOG_VariableController()) << tr("1: erase REQUEST in MAP ?")
706 << m_VarRequestIdToVarIdVarRequestMap.size();
710 << m_VarRequestIdToVarIdVarRequestMap.size();
707 }
711 }
708 }
712 }
709 else {
713 else {
710 qCCritical(LOG_VariableController())
714 qCCritical(LOG_VariableController())
711 << tr("Cannot updateVariableRequest for a unknow varRequestId") << varRequestId;
715 << tr("Cannot updateVariableRequest for a unknow varRequestId") << varRequestId;
712 }
716 }
713 }
717 }
714
718
715 void VariableController::VariableControllerPrivate::cancelVariableRequest(QUuid varRequestId)
719 void VariableController::VariableControllerPrivate::cancelVariableRequest(QUuid varRequestId)
716 {
720 {
717 // cleaning varRequestId
721 // cleaning varRequestId
718 m_VarRequestIdToVarIdVarRequestMap.erase(varRequestId);
722 m_VarRequestIdToVarIdVarRequestMap.erase(varRequestId);
719
723
720 for (auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.begin();
724 for (auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.begin();
721 varIdToVarRequestIdQueueMapIt != m_VarIdToVarRequestIdQueueMap.end();) {
725 varIdToVarRequestIdQueueMapIt != m_VarIdToVarRequestIdQueueMap.end();) {
722 auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second;
726 auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second;
723 varRequestIdQueue.erase(
727 varRequestIdQueue.erase(
724 std::remove(varRequestIdQueue.begin(), varRequestIdQueue.end(), varRequestId),
728 std::remove(varRequestIdQueue.begin(), varRequestIdQueue.end(), varRequestId),
725 varRequestIdQueue.end());
729 varRequestIdQueue.end());
726 if (varRequestIdQueue.empty()) {
730 if (varRequestIdQueue.empty()) {
727 varIdToVarRequestIdQueueMapIt
731 varIdToVarRequestIdQueueMapIt
728 = m_VarIdToVarRequestIdQueueMap.erase(varIdToVarRequestIdQueueMapIt);
732 = m_VarIdToVarRequestIdQueueMap.erase(varIdToVarRequestIdQueueMapIt);
729 }
733 }
730 else {
734 else {
731 ++varIdToVarRequestIdQueueMapIt;
735 ++varIdToVarRequestIdQueueMapIt;
732 }
736 }
733 }
737 }
734 }
738 }
@@ -1,257 +1,257
1 #include "Visualization/VisualizationZoneWidget.h"
1 #include "Visualization/VisualizationZoneWidget.h"
2
2
3
3
4 #include "Visualization/IVisualizationWidgetVisitor.h"
4 #include "Visualization/IVisualizationWidgetVisitor.h"
5 #include "Visualization/VisualizationGraphWidget.h"
5 #include "Visualization/VisualizationGraphWidget.h"
6 #include "ui_VisualizationZoneWidget.h"
6 #include "ui_VisualizationZoneWidget.h"
7
7
8 #include <Data/SqpRange.h>
8 #include <Data/SqpRange.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 <QUuid>
12 #include <QUuid>
13 #include <SqpApplication.h>
13 #include <SqpApplication.h>
14 #include <cmath>
14 #include <cmath>
15
15
16 Q_LOGGING_CATEGORY(LOG_VisualizationZoneWidget, "VisualizationZoneWidget")
16 Q_LOGGING_CATEGORY(LOG_VisualizationZoneWidget, "VisualizationZoneWidget")
17
17
18 namespace {
18 namespace {
19
19
20 /// Minimum height for graph added in zones (in pixels)
20 /// Minimum height for graph added in zones (in pixels)
21 const auto GRAPH_MINIMUM_HEIGHT = 300;
21 const auto GRAPH_MINIMUM_HEIGHT = 300;
22
22
23 /// Generates a default name for a new graph, according to the number of graphs already displayed in
23 /// Generates a default name for a new graph, according to the number of graphs already displayed in
24 /// the zone
24 /// the zone
25 QString defaultGraphName(const QLayout &layout)
25 QString defaultGraphName(const QLayout &layout)
26 {
26 {
27 auto count = 0;
27 auto count = 0;
28 for (auto i = 0; i < layout.count(); ++i) {
28 for (auto i = 0; i < layout.count(); ++i) {
29 if (dynamic_cast<VisualizationGraphWidget *>(layout.itemAt(i)->widget())) {
29 if (dynamic_cast<VisualizationGraphWidget *>(layout.itemAt(i)->widget())) {
30 count++;
30 count++;
31 }
31 }
32 }
32 }
33
33
34 return QObject::tr("Graph %1").arg(count + 1);
34 return QObject::tr("Graph %1").arg(count + 1);
35 }
35 }
36
36
37 } // namespace
37 } // namespace
38
38
39 struct VisualizationZoneWidget::VisualizationZoneWidgetPrivate {
39 struct VisualizationZoneWidget::VisualizationZoneWidgetPrivate {
40
40
41 explicit VisualizationZoneWidgetPrivate() : m_SynchronisationGroupId{QUuid::createUuid()} {}
41 explicit VisualizationZoneWidgetPrivate() : m_SynchronisationGroupId{QUuid::createUuid()} {}
42 QUuid m_SynchronisationGroupId;
42 QUuid m_SynchronisationGroupId;
43 };
43 };
44
44
45 VisualizationZoneWidget::VisualizationZoneWidget(const QString &name, QWidget *parent)
45 VisualizationZoneWidget::VisualizationZoneWidget(const QString &name, QWidget *parent)
46 : QWidget{parent},
46 : QWidget{parent},
47 ui{new Ui::VisualizationZoneWidget},
47 ui{new Ui::VisualizationZoneWidget},
48 impl{spimpl::make_unique_impl<VisualizationZoneWidgetPrivate>()}
48 impl{spimpl::make_unique_impl<VisualizationZoneWidgetPrivate>()}
49 {
49 {
50 ui->setupUi(this);
50 ui->setupUi(this);
51
51
52 ui->zoneNameLabel->setText(name);
52 ui->zoneNameLabel->setText(name);
53
53
54 // 'Close' options : widget is deleted when closed
54 // 'Close' options : widget is deleted when closed
55 setAttribute(Qt::WA_DeleteOnClose);
55 setAttribute(Qt::WA_DeleteOnClose);
56 connect(ui->closeButton, &QToolButton::clicked, this, &VisualizationZoneWidget::close);
56 connect(ui->closeButton, &QToolButton::clicked, this, &VisualizationZoneWidget::close);
57 ui->closeButton->setIcon(sqpApp->style()->standardIcon(QStyle::SP_TitleBarCloseButton));
57 ui->closeButton->setIcon(sqpApp->style()->standardIcon(QStyle::SP_TitleBarCloseButton));
58
58
59 // Synchronisation id
59 // Synchronisation id
60 QMetaObject::invokeMethod(&sqpApp->variableController(), "onAddSynchronizationGroupId",
60 QMetaObject::invokeMethod(&sqpApp->variableController(), "onAddSynchronizationGroupId",
61 Qt::QueuedConnection, Q_ARG(QUuid, impl->m_SynchronisationGroupId));
61 Qt::QueuedConnection, Q_ARG(QUuid, impl->m_SynchronisationGroupId));
62 }
62 }
63
63
64 VisualizationZoneWidget::~VisualizationZoneWidget()
64 VisualizationZoneWidget::~VisualizationZoneWidget()
65 {
65 {
66 delete ui;
66 delete ui;
67 }
67 }
68
68
69 void VisualizationZoneWidget::addGraph(VisualizationGraphWidget *graphWidget)
69 void VisualizationZoneWidget::addGraph(VisualizationGraphWidget *graphWidget)
70 {
70 {
71 ui->visualizationZoneFrame->layout()->addWidget(graphWidget);
71 ui->visualizationZoneFrame->layout()->addWidget(graphWidget);
72 }
72 }
73
73
74 VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<Variable> variable)
74 VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<Variable> variable)
75 {
75 {
76 auto graphWidget = new VisualizationGraphWidget{
76 auto graphWidget = new VisualizationGraphWidget{
77 defaultGraphName(*ui->visualizationZoneFrame->layout()), this};
77 defaultGraphName(*ui->visualizationZoneFrame->layout()), this};
78
78
79
79
80 // Set graph properties
80 // Set graph properties
81 graphWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding);
81 graphWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding);
82 graphWidget->setMinimumHeight(GRAPH_MINIMUM_HEIGHT);
82 graphWidget->setMinimumHeight(GRAPH_MINIMUM_HEIGHT);
83
83
84
84
85 // Lambda to synchronize zone widget
85 // Lambda to synchronize zone widget
86 auto synchronizeZoneWidget = [this, graphWidget](const SqpRange &graphRange,
86 auto synchronizeZoneWidget = [this, graphWidget](const SqpRange &graphRange,
87 const SqpRange &oldGraphRange) {
87 const SqpRange &oldGraphRange) {
88
88
89 auto zoomType = VariableController::getZoomType(graphRange, oldGraphRange);
89 auto zoomType = VariableController::getZoomType(graphRange, oldGraphRange);
90 auto frameLayout = ui->visualizationZoneFrame->layout();
90 auto frameLayout = ui->visualizationZoneFrame->layout();
91 for (auto i = 0; i < frameLayout->count(); ++i) {
91 for (auto i = 0; i < frameLayout->count(); ++i) {
92 auto graphChild
92 auto graphChild
93 = dynamic_cast<VisualizationGraphWidget *>(frameLayout->itemAt(i)->widget());
93 = dynamic_cast<VisualizationGraphWidget *>(frameLayout->itemAt(i)->widget());
94 if (graphChild && (graphChild != graphWidget)) {
94 if (graphChild && (graphChild != graphWidget)) {
95
95
96 auto graphChildRange = graphChild->graphRange();
96 auto graphChildRange = graphChild->graphRange();
97 switch (zoomType) {
97 switch (zoomType) {
98 case AcquisitionZoomType::ZoomIn: {
98 case AcquisitionZoomType::ZoomIn: {
99 auto deltaLeft = graphRange.m_TStart - oldGraphRange.m_TStart;
99 auto deltaLeft = graphRange.m_TStart - oldGraphRange.m_TStart;
100 auto deltaRight = oldGraphRange.m_TEnd - graphRange.m_TEnd;
100 auto deltaRight = oldGraphRange.m_TEnd - graphRange.m_TEnd;
101 graphChildRange.m_TStart += deltaLeft;
101 graphChildRange.m_TStart += deltaLeft;
102 graphChildRange.m_TEnd -= deltaRight;
102 graphChildRange.m_TEnd -= deltaRight;
103 qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: ZoomIn");
103 qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: ZoomIn");
104 qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: deltaLeft")
104 qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: deltaLeft")
105 << deltaLeft;
105 << deltaLeft;
106 qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: deltaRight")
106 qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: deltaRight")
107 << deltaRight;
107 << deltaRight;
108 qCCritical(LOG_VisualizationZoneWidget())
108 qCDebug(LOG_VisualizationZoneWidget())
109 << tr("TORM: dt") << graphRange.m_TEnd - graphRange.m_TStart;
109 << tr("TORM: dt") << graphRange.m_TEnd - graphRange.m_TStart;
110
110
111 break;
111 break;
112 }
112 }
113
113
114 case AcquisitionZoomType::ZoomOut: {
114 case AcquisitionZoomType::ZoomOut: {
115 qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: ZoomOut");
115 qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: ZoomOut");
116 auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart;
116 auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart;
117 auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd;
117 auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd;
118 qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: deltaLeft")
118 qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: deltaLeft")
119 << deltaLeft;
119 << deltaLeft;
120 qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: deltaRight")
120 qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: deltaRight")
121 << deltaRight;
121 << deltaRight;
122 qCCritical(LOG_VisualizationZoneWidget())
122 qCDebug(LOG_VisualizationZoneWidget())
123 << tr("TORM: dt") << graphRange.m_TEnd - graphRange.m_TStart;
123 << tr("TORM: dt") << graphRange.m_TEnd - graphRange.m_TStart;
124 graphChildRange.m_TStart -= deltaLeft;
124 graphChildRange.m_TStart -= deltaLeft;
125 graphChildRange.m_TEnd += deltaRight;
125 graphChildRange.m_TEnd += deltaRight;
126 break;
126 break;
127 }
127 }
128 case AcquisitionZoomType::PanRight: {
128 case AcquisitionZoomType::PanRight: {
129 qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: PanRight");
129 qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: PanRight");
130 auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd;
130 auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd;
131 graphChildRange.m_TStart += deltaRight;
131 graphChildRange.m_TStart += deltaRight;
132 graphChildRange.m_TEnd += deltaRight;
132 graphChildRange.m_TEnd += deltaRight;
133 qCCritical(LOG_VisualizationZoneWidget())
133 qCDebug(LOG_VisualizationZoneWidget())
134 << tr("TORM: dt") << graphRange.m_TEnd - graphRange.m_TStart;
134 << tr("TORM: dt") << graphRange.m_TEnd - graphRange.m_TStart;
135 break;
135 break;
136 }
136 }
137 case AcquisitionZoomType::PanLeft: {
137 case AcquisitionZoomType::PanLeft: {
138 qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: PanLeft");
138 qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: PanLeft");
139 auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart;
139 auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart;
140 graphChildRange.m_TStart -= deltaLeft;
140 graphChildRange.m_TStart -= deltaLeft;
141 graphChildRange.m_TEnd -= deltaLeft;
141 graphChildRange.m_TEnd -= deltaLeft;
142 break;
142 break;
143 }
143 }
144 case AcquisitionZoomType::Unknown: {
144 case AcquisitionZoomType::Unknown: {
145 qCCritical(LOG_VisualizationZoneWidget())
145 qCDebug(LOG_VisualizationZoneWidget())
146 << tr("Impossible to synchronize: zoom type unknown");
146 << tr("Impossible to synchronize: zoom type unknown");
147 break;
147 break;
148 }
148 }
149 default:
149 default:
150 qCCritical(LOG_VisualizationZoneWidget())
150 qCCritical(LOG_VisualizationZoneWidget())
151 << tr("Impossible to synchronize: zoom type not take into account");
151 << tr("Impossible to synchronize: zoom type not take into account");
152 // No action
152 // No action
153 break;
153 break;
154 }
154 }
155 graphChild->enableAcquisition(false);
155 graphChild->enableAcquisition(false);
156 qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: Range before: ")
156 qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: Range before: ")
157 << graphChild->graphRange();
157 << graphChild->graphRange();
158 qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: Range after : ")
158 qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: Range after : ")
159 << graphChildRange;
159 << graphChildRange;
160 qCCritical(LOG_VisualizationZoneWidget())
160 qCDebug(LOG_VisualizationZoneWidget())
161 << tr("TORM: child dt") << graphChildRange.m_TEnd - graphChildRange.m_TStart;
161 << tr("TORM: child dt") << graphChildRange.m_TEnd - graphChildRange.m_TStart;
162 graphChild->setGraphRange(graphChildRange);
162 graphChild->setGraphRange(graphChildRange);
163 graphChild->enableAcquisition(true);
163 graphChild->enableAcquisition(true);
164 }
164 }
165 }
165 }
166 };
166 };
167
167
168 // connection for synchronization
168 // connection for synchronization
169 connect(graphWidget, &VisualizationGraphWidget::synchronize, synchronizeZoneWidget);
169 connect(graphWidget, &VisualizationGraphWidget::synchronize, synchronizeZoneWidget);
170 connect(graphWidget, &VisualizationGraphWidget::variableAdded, this,
170 connect(graphWidget, &VisualizationGraphWidget::variableAdded, this,
171 &VisualizationZoneWidget::onVariableAdded);
171 &VisualizationZoneWidget::onVariableAdded);
172
172
173 auto range = SqpRange{};
173 auto range = SqpRange{};
174
174
175 // Apply visitor to graph children
175 // Apply visitor to graph children
176 auto layout = ui->visualizationZoneFrame->layout();
176 auto layout = ui->visualizationZoneFrame->layout();
177 if (layout->count() > 0) {
177 if (layout->count() > 0) {
178 // Case of a new graph in a existant zone
178 // Case of a new graph in a existant zone
179 if (auto visualizationGraphWidget
179 if (auto visualizationGraphWidget
180 = dynamic_cast<VisualizationGraphWidget *>(layout->itemAt(0)->widget())) {
180 = dynamic_cast<VisualizationGraphWidget *>(layout->itemAt(0)->widget())) {
181 range = visualizationGraphWidget->graphRange();
181 range = visualizationGraphWidget->graphRange();
182 }
182 }
183 }
183 }
184 else {
184 else {
185 // Case of a new graph as the first of the zone
185 // Case of a new graph as the first of the zone
186 range = variable->range();
186 range = variable->range();
187 }
187 }
188
188
189 this->addGraph(graphWidget);
189 this->addGraph(graphWidget);
190
190
191 graphWidget->addVariable(variable, range);
191 graphWidget->addVariable(variable, range);
192
192
193 // get y using variable range
193 // get y using variable range
194 if (auto dataSeries = variable->dataSeries()) {
194 if (auto dataSeries = variable->dataSeries()) {
195 auto valuesBounds = dataSeries->valuesBounds(range.m_TStart, range.m_TEnd);
195 auto valuesBounds = dataSeries->valuesBounds(range.m_TStart, range.m_TEnd);
196 auto end = dataSeries->cend();
196 auto end = dataSeries->cend();
197 if (valuesBounds.first != end && valuesBounds.second != end) {
197 if (valuesBounds.first != end && valuesBounds.second != end) {
198 auto rangeValue = [](const auto &value) { return std::isnan(value) ? 0. : value; };
198 auto rangeValue = [](const auto &value) { return std::isnan(value) ? 0. : value; };
199
199
200 auto minValue = rangeValue(valuesBounds.first->minValue());
200 auto minValue = rangeValue(valuesBounds.first->minValue());
201 auto maxValue = rangeValue(valuesBounds.second->maxValue());
201 auto maxValue = rangeValue(valuesBounds.second->maxValue());
202
202
203 graphWidget->setYRange(SqpRange{minValue, maxValue});
203 graphWidget->setYRange(SqpRange{minValue, maxValue});
204 }
204 }
205 }
205 }
206
206
207 return graphWidget;
207 return graphWidget;
208 }
208 }
209
209
210 void VisualizationZoneWidget::accept(IVisualizationWidgetVisitor *visitor)
210 void VisualizationZoneWidget::accept(IVisualizationWidgetVisitor *visitor)
211 {
211 {
212 if (visitor) {
212 if (visitor) {
213 visitor->visitEnter(this);
213 visitor->visitEnter(this);
214
214
215 // Apply visitor to graph children
215 // Apply visitor to graph children
216 auto layout = ui->visualizationZoneFrame->layout();
216 auto layout = ui->visualizationZoneFrame->layout();
217 for (auto i = 0; i < layout->count(); ++i) {
217 for (auto i = 0; i < layout->count(); ++i) {
218 if (auto item = layout->itemAt(i)) {
218 if (auto item = layout->itemAt(i)) {
219 // Widgets different from graphs are not visited (no action)
219 // Widgets different from graphs are not visited (no action)
220 if (auto visualizationGraphWidget
220 if (auto visualizationGraphWidget
221 = dynamic_cast<VisualizationGraphWidget *>(item->widget())) {
221 = dynamic_cast<VisualizationGraphWidget *>(item->widget())) {
222 visualizationGraphWidget->accept(visitor);
222 visualizationGraphWidget->accept(visitor);
223 }
223 }
224 }
224 }
225 }
225 }
226
226
227 visitor->visitLeave(this);
227 visitor->visitLeave(this);
228 }
228 }
229 else {
229 else {
230 qCCritical(LOG_VisualizationZoneWidget()) << tr("Can't visit widget : the visitor is null");
230 qCCritical(LOG_VisualizationZoneWidget()) << tr("Can't visit widget : the visitor is null");
231 }
231 }
232 }
232 }
233
233
234 bool VisualizationZoneWidget::canDrop(const Variable &variable) const
234 bool VisualizationZoneWidget::canDrop(const Variable &variable) const
235 {
235 {
236 // A tab can always accomodate a variable
236 // A tab can always accomodate a variable
237 Q_UNUSED(variable);
237 Q_UNUSED(variable);
238 return true;
238 return true;
239 }
239 }
240
240
241 bool VisualizationZoneWidget::contains(const Variable &variable) const
241 bool VisualizationZoneWidget::contains(const Variable &variable) const
242 {
242 {
243 Q_UNUSED(variable);
243 Q_UNUSED(variable);
244 return false;
244 return false;
245 }
245 }
246
246
247 QString VisualizationZoneWidget::name() const
247 QString VisualizationZoneWidget::name() const
248 {
248 {
249 return ui->zoneNameLabel->text();
249 return ui->zoneNameLabel->text();
250 }
250 }
251
251
252 void VisualizationZoneWidget::onVariableAdded(std::shared_ptr<Variable> variable)
252 void VisualizationZoneWidget::onVariableAdded(std::shared_ptr<Variable> variable)
253 {
253 {
254 QMetaObject::invokeMethod(&sqpApp->variableController(), "onAddSynchronized",
254 QMetaObject::invokeMethod(&sqpApp->variableController(), "onAddSynchronized",
255 Qt::QueuedConnection, Q_ARG(std::shared_ptr<Variable>, variable),
255 Qt::QueuedConnection, Q_ARG(std::shared_ptr<Variable>, variable),
256 Q_ARG(QUuid, impl->m_SynchronisationGroupId));
256 Q_ARG(QUuid, impl->m_SynchronisationGroupId));
257 }
257 }
@@ -1,197 +1,197
1 #include "AmdaProvider.h"
1 #include "AmdaProvider.h"
2 #include "AmdaResultParser.h"
2 #include "AmdaResultParser.h"
3
3
4 #include "SqpApplication.h"
4 #include "SqpApplication.h"
5 #include <Data/DataSeries.h>
5 #include <Data/DataSeries.h>
6 #include <Data/IDataSeries.h>
6 #include <Data/IDataSeries.h>
7 #include <Data/ScalarSeries.h>
7 #include <Data/ScalarSeries.h>
8 #include <Time/TimeController.h>
8 #include <Time/TimeController.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 <QObject>
12 #include <QObject>
13 #include <QtTest>
13 #include <QtTest>
14
14
15 #include <memory>
15 #include <memory>
16
16
17 // TEST with REF:
17 // TEST with REF:
18 // AmdaData-2012-01-01-12-00-00_2012-01-03-12-00-00
18 // AmdaData-2012-01-01-12-00-00_2012-01-03-12-00-00
19 // imf(0) - Type : Local Parameter @ CDPP/AMDA -
19 // imf(0) - Type : Local Parameter @ CDPP/AMDA -
20 // Name : bx_gse - Units : nT - Size : 1 -
20 // Name : bx_gse - Units : nT - Size : 1 -
21 // Frame : GSE - Mission : ACE -
21 // Frame : GSE - Mission : ACE -
22 // Instrument : MFI - Dataset : mfi_final-prelim
22 // Instrument : MFI - Dataset : mfi_final-prelim
23 // REFERENCE DOWNLOAD FILE =
23 // REFERENCE DOWNLOAD FILE =
24 // http://amda.irap.omp.eu/php/rest/getParameter.php?startTime=2012-01-01T12:00:00&stopTime=2012-01-03T12:00:00&parameterID=imf(0)&outputFormat=ASCII&timeFormat=ISO8601&gzip=0
24 // http://amda.irap.omp.eu/php/rest/getParameter.php?startTime=2012-01-01T12:00:00&stopTime=2012-01-03T12:00:00&parameterID=imf(0)&outputFormat=ASCII&timeFormat=ISO8601&gzip=0
25
25
26 namespace {
26 namespace {
27
27
28 /// Path for the tests
28 /// Path for the tests
29 const auto TESTS_RESOURCES_PATH
29 const auto TESTS_RESOURCES_PATH
30 = QFileInfo{QString{AMDA_TESTS_RESOURCES_DIR}, "TestAmdaAcquisition"}.absoluteFilePath();
30 = QFileInfo{QString{AMDA_TESTS_RESOURCES_DIR}, "TestAmdaAcquisition"}.absoluteFilePath();
31
31
32 const auto TESTS_AMDA_REF_FILE = QString{"AmdaData-2012-01-01-12-00-00_2012-01-03-12-00-00.txt"};
32 const auto TESTS_AMDA_REF_FILE = QString{"AmdaData-2012-01-01-12-00-00_2012-01-03-12-00-00.txt"};
33
33
34 template <typename T>
34 template <typename T>
35 bool compareDataSeries(std::shared_ptr<IDataSeries> candidate, SqpRange candidateCacheRange,
35 bool compareDataSeries(std::shared_ptr<IDataSeries> candidate, SqpRange candidateCacheRange,
36 std::shared_ptr<IDataSeries> reference)
36 std::shared_ptr<IDataSeries> reference)
37 {
37 {
38 auto compareLambda = [](const auto &it1, const auto &it2) {
38 auto compareLambda = [](const auto &it1, const auto &it2) {
39 return (it1.x() == it2.x()) && (it1.value() == it2.value());
39 return (it1.x() == it2.x()) && (it1.value() == it2.value());
40 };
40 };
41
41
42 auto candidateDS = std::dynamic_pointer_cast<T>(candidate);
42 auto candidateDS = std::dynamic_pointer_cast<T>(candidate);
43 auto referenceDS = std::dynamic_pointer_cast<T>(reference);
43 auto referenceDS = std::dynamic_pointer_cast<T>(reference);
44
44
45 if (candidateDS && referenceDS) {
45 if (candidateDS && referenceDS) {
46
46
47 auto itRefs
47 auto itRefs
48 = referenceDS->xAxisRange(candidateCacheRange.m_TStart, candidateCacheRange.m_TEnd);
48 = referenceDS->xAxisRange(candidateCacheRange.m_TStart, candidateCacheRange.m_TEnd);
49 qDebug() << " DISTANCE" << std::distance(candidateDS->cbegin(), candidateDS->cend())
49 qDebug() << " DISTANCE" << std::distance(candidateDS->cbegin(), candidateDS->cend())
50 << std::distance(itRefs.first, itRefs.second);
50 << std::distance(itRefs.first, itRefs.second);
51
51
52 // auto xcValue = candidateDS->valuesData()->data();
52 // auto xcValue = candidateDS->valuesData()->data();
53 // auto dist = std::distance(itRefs.first, itRefs.second);
53 // auto dist = std::distance(itRefs.first, itRefs.second);
54 // auto it = itRefs.first;
54 // auto it = itRefs.first;
55 // for (auto i = 0; i < dist - 1; ++i) {
55 // for (auto i = 0; i < dist - 1; ++i) {
56 // ++it;
56 // ++it;
57 // qInfo() << "END:" << it->value();
57 // qInfo() << "END:" << it->value();
58 // }
58 // }
59 // qDebug() << "END:" << it->value() << xcValue.last();
59 // qDebug() << "END:" << it->value() << xcValue.last();
60
60
61 return std::equal(candidateDS->cbegin(), candidateDS->cend(), itRefs.first, itRefs.second,
61 return std::equal(candidateDS->cbegin(), candidateDS->cend(), itRefs.first, itRefs.second,
62 compareLambda);
62 compareLambda);
63 }
63 }
64 else {
64 else {
65 return false;
65 return false;
66 }
66 }
67 }
67 }
68 }
68 }
69
69
70 class TestAmdaAcquisition : public QObject {
70 class TestAmdaAcquisition : public QObject {
71 Q_OBJECT
71 Q_OBJECT
72
72
73 private slots:
73 private slots:
74 void testAcquisition();
74 void testAcquisition();
75 };
75 };
76
76
77 void TestAmdaAcquisition::testAcquisition()
77 void TestAmdaAcquisition::testAcquisition()
78 {
78 {
79 // READ the ref file:
79 // READ the ref file:
80 auto filePath = QFileInfo{TESTS_RESOURCES_PATH, TESTS_AMDA_REF_FILE}.absoluteFilePath();
80 auto filePath = QFileInfo{TESTS_RESOURCES_PATH, TESTS_AMDA_REF_FILE}.absoluteFilePath();
81 auto results = AmdaResultParser::readTxt(filePath, AmdaResultParser::ValueType::SCALAR);
81 auto results = AmdaResultParser::readTxt(filePath, AmdaResultParser::ValueType::SCALAR);
82
82
83 auto provider = std::make_shared<AmdaProvider>();
83 auto provider = std::make_shared<AmdaProvider>();
84 auto timeController = std::make_unique<TimeController>();
84 auto timeController = std::make_unique<TimeController>();
85
85
86 auto varRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 3, 0, 0}};
86 auto varRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 3, 0, 0}};
87 auto varRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 4, 0, 0}};
87 auto varRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 4, 0, 0}};
88
88
89 auto sqpR = SqpRange{DateUtils::secondsSinceEpoch(varRS), DateUtils::secondsSinceEpoch(varRE)};
89 auto sqpR = SqpRange{DateUtils::secondsSinceEpoch(varRS), DateUtils::secondsSinceEpoch(varRE)};
90
90
91 timeController->onTimeToUpdate(sqpR);
91 timeController->onTimeToUpdate(sqpR);
92
92
93 QVariantHash metaData;
93 QVariantHash metaData;
94 metaData.insert("dataType", "scalar");
94 metaData.insert("dataType", "scalar");
95 metaData.insert("xml:id", "imf(0)");
95 metaData.insert("xml:id", "imf(0)");
96
96
97 VariableController vc;
97 VariableController vc;
98 vc.setTimeController(timeController.get());
98 vc.setTimeController(timeController.get());
99
99
100 auto var = vc.createVariable("bx_gse", metaData, provider);
100 auto var = vc.createVariable("bx_gse", metaData, provider);
101
101
102 // 1 : Variable creation
102 // 1 : Variable creation
103 QCOMPARE(var->range().m_TStart, sqpR.m_TStart);
103 QCOMPARE(var->range().m_TStart, sqpR.m_TStart);
104 QCOMPARE(var->range().m_TEnd, sqpR.m_TEnd);
104 QCOMPARE(var->range().m_TEnd, sqpR.m_TEnd);
105
105
106 qDebug() << " 1: TIMECONTROLLER" << timeController->dateTime();
106 qDebug() << " 1: TIMECONTROLLER" << timeController->dateTime();
107 qDebug() << " 1: RANGE " << var->range();
107 qDebug() << " 1: RANGE " << var->range();
108 qDebug() << " 1: CACHERANGE" << var->cacheRange();
108 qDebug() << " 1: CACHERANGE" << var->cacheRange();
109
109
110 // wait for 10 sec before asking next request toi permit asynchrone process to finish.
110 // wait for 10 sec before asking next request toi permit asynchrone process to finish.
111 auto timeToWaitMs = 10000;
111 auto timeToWaitMs = 10000;
112
112
113 QEventLoop loop;
113 QEventLoop loop;
114 QTimer::singleShot(timeToWaitMs, &loop, &QEventLoop::quit);
114 QTimer::singleShot(timeToWaitMs, &loop, &QEventLoop::quit);
115 loop.exec();
115 loop.exec();
116
116
117 // Tests on acquisition operation
117 // Tests on acquisition operation
118
118
119 int count = 1;
119 int count = 1;
120
120
121 auto requestDataLoading = [&vc, var, timeToWaitMs, results, &count](auto tStart, auto tEnd) {
121 auto requestDataLoading = [&vc, var, timeToWaitMs, results, &count](auto tStart, auto tEnd) {
122 ++count;
122 ++count;
123
123
124 auto nextSqpR
124 auto nextSqpR
125 = SqpRange{DateUtils::secondsSinceEpoch(tStart), DateUtils::secondsSinceEpoch(tEnd)};
125 = SqpRange{DateUtils::secondsSinceEpoch(tStart), DateUtils::secondsSinceEpoch(tEnd)};
126 vc.onRequestDataLoading(QVector<std::shared_ptr<Variable> >{} << var, nextSqpR,
126 vc.onRequestDataLoading(QVector<std::shared_ptr<Variable> >{} << var, nextSqpR,
127 var->range(), true);
127 var->range(), true);
128
128
129 QEventLoop loop;
129 QEventLoop loop;
130 QTimer::singleShot(timeToWaitMs, &loop, &QEventLoop::quit);
130 QTimer::singleShot(timeToWaitMs, &loop, &QEventLoop::quit);
131 loop.exec();
131 loop.exec();
132
132
133 qDebug() << count << "RANGE " << var->range();
133 qInfo() << count << "RANGE " << var->range();
134 qDebug() << count << "CACHERANGE" << var->cacheRange();
134 qInfo() << count << "CACHERANGE" << var->cacheRange();
135
135
136 QCOMPARE(var->range().m_TStart, nextSqpR.m_TStart);
136 QCOMPARE(var->range().m_TStart, nextSqpR.m_TStart);
137 QCOMPARE(var->range().m_TEnd, nextSqpR.m_TEnd);
137 QCOMPARE(var->range().m_TEnd, nextSqpR.m_TEnd);
138
138
139 // Verify dataserie
139 // Verify dataserie
140 QVERIFY(compareDataSeries<ScalarSeries>(var->dataSeries(), var->cacheRange(), results));
140 QVERIFY(compareDataSeries<ScalarSeries>(var->dataSeries(), var->cacheRange(), results));
141
141
142 };
142 };
143
143
144 // 2 : pan (jump) left for one hour
144 // 2 : pan (jump) left for one hour
145 auto nextVarRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 1, 0, 0}};
145 auto nextVarRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 1, 0, 0}};
146 auto nextVarRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 2, 0, 0}};
146 auto nextVarRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 2, 0, 0}};
147 // requestDataLoading(nextVarRS, nextVarRE);
147 requestDataLoading(nextVarRS, nextVarRE);
148
148
149
149
150 // 3 : pan (jump) right for one hour
150 // 3 : pan (jump) right for one hour
151 nextVarRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 5, 0, 0}};
151 nextVarRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 5, 0, 0}};
152 nextVarRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 6, 0, 0}};
152 nextVarRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 6, 0, 0}};
153 requestDataLoading(nextVarRS, nextVarRE);
153 requestDataLoading(nextVarRS, nextVarRE);
154
154
155 // 4 : pan (overlay) right for 30 min
155 // 4 : pan (overlay) right for 30 min
156 nextVarRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 5, 30, 0}};
156 nextVarRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 5, 30, 0}};
157 nextVarRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 6, 30, 0}};
157 nextVarRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 6, 30, 0}};
158 // requestDataLoading(nextVarRS, nextVarRE);
158 // requestDataLoading(nextVarRS, nextVarRE);
159
159
160 // 5 : pan (overlay) left for 30 min
160 // 5 : pan (overlay) left for 30 min
161 nextVarRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 5, 0, 0}};
161 nextVarRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 5, 0, 0}};
162 nextVarRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 6, 0, 0}};
162 nextVarRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 6, 0, 0}};
163 // requestDataLoading(nextVarRS, nextVarRE);
163 // requestDataLoading(nextVarRS, nextVarRE);
164
164
165 // 6 : pan (overlay) left for 30 min - BIS
165 // 6 : pan (overlay) left for 30 min - BIS
166 nextVarRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 4, 30, 0}};
166 nextVarRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 4, 30, 0}};
167 nextVarRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 5, 30, 0}};
167 nextVarRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 5, 30, 0}};
168 // requestDataLoading(nextVarRS, nextVarRE);
168 // requestDataLoading(nextVarRS, nextVarRE);
169
169
170 // 7 : Zoom in Inside 20 min range
170 // 7 : Zoom in Inside 20 min range
171 nextVarRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 4, 50, 0}};
171 nextVarRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 4, 50, 0}};
172 nextVarRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 5, 10, 0}};
172 nextVarRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 5, 10, 0}};
173 // requestDataLoading(nextVarRS, nextVarRE);
173 // requestDataLoading(nextVarRS, nextVarRE);
174
174
175 // 8 : Zoom out Inside 2 hours range
175 // 8 : Zoom out Inside 2 hours range
176 nextVarRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 4, 0, 0}};
176 nextVarRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 4, 0, 0}};
177 nextVarRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 6, 0, 0}};
177 nextVarRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 6, 0, 0}};
178 // requestDataLoading(nextVarRS, nextVarRE);
178 // requestDataLoading(nextVarRS, nextVarRE);
179
179
180
180
181 // Close the app after 10 sec
181 // Close the app after 10 sec
182 QTimer::singleShot(timeToWaitMs, &loop, &QEventLoop::quit);
182 QTimer::singleShot(timeToWaitMs, &loop, &QEventLoop::quit);
183 loop.exec();
183 loop.exec();
184 }
184 }
185
185
186 int main(int argc, char *argv[])
186 int main(int argc, char *argv[])
187 {
187 {
188 SqpApplication app(argc, argv);
188 SqpApplication app(argc, argv);
189 app.setAttribute(Qt::AA_Use96Dpi, true);
189 app.setAttribute(Qt::AA_Use96Dpi, true);
190 TestAmdaAcquisition tc;
190 TestAmdaAcquisition tc;
191 QTEST_SET_MAIN_SOURCE_PATH
191 QTEST_SET_MAIN_SOURCE_PATH
192 return QTest::qExec(&tc, argc, argv);
192 return QTest::qExec(&tc, argc, argv);
193 }
193 }
194
194
195 // QTEST_MAIN(TestAmdaAcquisition)
195 // QTEST_MAIN(TestAmdaAcquisition)
196
196
197 #include "TestAmdaAcquisition.moc"
197 #include "TestAmdaAcquisition.moc"
General Comments 0
You need to be logged in to leave comments. Login now