##// END OF EJS Templates
Add synchronization part of v5 acquisition
perrinel -
r540:bf486b19bffa
parent child
Show More
@@ -102,6 +102,7 public slots:
102 /// synchronization group methods
102 /// synchronization group methods
103 void onAddSynchronizationGroupId(QUuid synchronizationGroupId);
103 void onAddSynchronizationGroupId(QUuid synchronizationGroupId);
104 void onRemoveSynchronizationGroupId(QUuid synchronizationGroupId);
104 void onRemoveSynchronizationGroupId(QUuid synchronizationGroupId);
105 void onAddSynchronized(std::shared_ptr<Variable> variable, QUuid synchronizationGroupId);
105
106
106 void initialize();
107 void initialize();
107 void finalize();
108 void finalize();
@@ -263,18 +263,16 void VariableController::onDataProvided(QUuid vIdentifier, const SqpRange &range
263 const SqpRange &cacheRangeRequested,
263 const SqpRange &cacheRangeRequested,
264 QVector<AcquisitionDataPacket> dataAcquired)
264 QVector<AcquisitionDataPacket> dataAcquired)
265 {
265 {
266 qCCritical(LOG_VariableController()) << tr("onDataProvided") << dataAcquired.isEmpty();
267
268 auto var = impl->findVariable(vIdentifier);
266 auto var = impl->findVariable(vIdentifier);
269 if (var != nullptr) {
267 if (var != nullptr) {
270 var->setRange(rangeRequested);
268 var->setRange(rangeRequested);
271 var->setCacheRange(cacheRangeRequested);
269 var->setCacheRange(cacheRangeRequested);
272 qCCritical(LOG_VariableController()) << tr("1: onDataProvided") << rangeRequested;
270 qCDebug(LOG_VariableController()) << tr("1: onDataProvided") << rangeRequested;
273 qCCritical(LOG_VariableController()) << tr("2: onDataProvided") << cacheRangeRequested;
271 qCDebug(LOG_VariableController()) << tr("2: onDataProvided") << cacheRangeRequested;
274
272
275 auto retrievedDataSeries = impl->retrieveDataSeries(dataAcquired);
273 auto retrievedDataSeries = impl->retrieveDataSeries(dataAcquired);
276 qCCritical(LOG_VariableController()) << tr("3: onDataProvided")
274 qCDebug(LOG_VariableController()) << tr("3: onDataProvided")
277 << retrievedDataSeries->range();
275 << retrievedDataSeries->range();
278 var->mergeDataSeries(retrievedDataSeries);
276 var->mergeDataSeries(retrievedDataSeries);
279 emit var->updated();
277 emit var->updated();
280 }
278 }
@@ -313,6 +311,9 void VariableController::onAbortProgressRequested(std::shared_ptr<Variable> vari
313
311
314 void VariableController::onAddSynchronizationGroupId(QUuid synchronizationGroupId)
312 void VariableController::onAddSynchronizationGroupId(QUuid synchronizationGroupId)
315 {
313 {
314 qCDebug(LOG_VariableController()) << "TORM: VariableController::onAddSynchronizationGroupId"
315 << QThread::currentThread()->objectName()
316 << synchronizationGroupId;
316 auto vSynchroGroup = std::make_shared<VariableSynchronizationGroup>();
317 auto vSynchroGroup = std::make_shared<VariableSynchronizationGroup>();
317 impl->m_GroupIdToVariableSynchronizationGroupMap.insert(
318 impl->m_GroupIdToVariableSynchronizationGroupMap.insert(
318 std::make_pair(synchronizationGroupId, vSynchroGroup));
319 std::make_pair(synchronizationGroupId, vSynchroGroup));
@@ -323,6 +324,33 void VariableController::onRemoveSynchronizationGroupId(QUuid synchronizationGro
323 impl->m_GroupIdToVariableSynchronizationGroupMap.erase(synchronizationGroupId);
324 impl->m_GroupIdToVariableSynchronizationGroupMap.erase(synchronizationGroupId);
324 }
325 }
325
326
327 void VariableController::onAddSynchronized(std::shared_ptr<Variable> variable,
328 QUuid synchronizationGroupId)
329
330 {
331 qCDebug(LOG_VariableController()) << "TORM: VariableController::onAddSynchronized"
332 << synchronizationGroupId;
333 auto vToVIdit = impl->m_VariableToIdentifierMap.find(variable);
334 if (vToVIdit != impl->m_VariableToIdentifierMap.cend()) {
335 auto itSynchroGroup
336 = impl->m_GroupIdToVariableSynchronizationGroupMap.find(synchronizationGroupId);
337 if (itSynchroGroup != impl->m_GroupIdToVariableSynchronizationGroupMap.cend()) {
338 impl->m_VariableIdGroupIdMap.insert(
339 std::make_pair(vToVIdit->second, synchronizationGroupId));
340 itSynchroGroup->second->addVariableId(vToVIdit->second);
341 }
342 else {
343 qCCritical(LOG_VariableController())
344 << tr("Impossible to synchronize a variable with an unknown sycnhronization group")
345 << variable->name();
346 }
347 }
348 else {
349 qCCritical(LOG_VariableController())
350 << tr("Impossible to synchronize a variable with no identifier") << variable->name();
351 }
352 }
353
326
354
327 void VariableController::onRequestDataLoading(QVector<std::shared_ptr<Variable> > variables,
355 void VariableController::onRequestDataLoading(QVector<std::shared_ptr<Variable> > variables,
328 const SqpRange &range, const SqpRange &oldRange,
356 const SqpRange &range, const SqpRange &oldRange,
@@ -337,24 +365,24 void VariableController::onRequestDataLoading(QVector<std::shared_ptr<Variable>
337 // For the other, we ask the provider to give them.
365 // For the other, we ask the provider to give them.
338
366
339 foreach (auto var, variables) {
367 foreach (auto var, variables) {
340 qCInfo(LOG_VariableController()) << "processRequest for" << var->name();
368 qCDebug(LOG_VariableController()) << "processRequest for" << var->name();
341 impl->processRequest(var, range);
369 impl->processRequest(var, range);
342 }
370 }
343
371
344 if (synchronise) {
372 if (synchronise) {
345 // Get the group ids
373 // Get the group ids
346 qCInfo(LOG_VariableController())
374 qCDebug(LOG_VariableController())
347 << "VariableController::onRequestDataLoading for synchro var ENABLE";
375 << "VariableController::onRequestDataLoading for synchro var ENABLE";
348 auto groupIds = std::set<QUuid>();
376 auto groupIds = std::set<QUuid>();
349 foreach (auto var, variables) {
377 foreach (auto var, variables) {
350 auto vToVIdit = impl->m_VariableToIdentifierMap.find(var);
378 auto varToVarIdIt = impl->m_VariableToIdentifierMap.find(var);
351 if (vToVIdit != impl->m_VariableToIdentifierMap.cend()) {
379 if (varToVarIdIt != impl->m_VariableToIdentifierMap.cend()) {
352 auto vId = vToVIdit->second;
380 auto vId = varToVarIdIt->second;
353
381 auto varIdToGroupIdIt = impl->m_VariableIdGroupIdMap.find(vId);
354 auto vIdToGIdit = impl->m_VariableIdGroupIdMap.find(vId);
382 if (varIdToGroupIdIt != impl->m_VariableIdGroupIdMap.cend()) {
355 if (vIdToGIdit != impl->m_VariableIdGroupIdMap.cend()) {
383 auto gId = varIdToGroupIdIt->second;
356 auto gId = vToVIdit->second;
357 if (groupIds.find(gId) == groupIds.cend()) {
384 if (groupIds.find(gId) == groupIds.cend()) {
385 qCDebug(LOG_VariableController()) << "Synchro detect group " << gId;
358 groupIds.insert(gId);
386 groupIds.insert(gId);
359 }
387 }
360 }
388 }
@@ -365,17 +393,24 void VariableController::onRequestDataLoading(QVector<std::shared_ptr<Variable>
365 foreach (auto gId, groupIds) {
393 foreach (auto gId, groupIds) {
366 auto vSynchronizationGroup = impl->m_GroupIdToVariableSynchronizationGroupMap.at(gId);
394 auto vSynchronizationGroup = impl->m_GroupIdToVariableSynchronizationGroupMap.at(gId);
367 auto vSyncIds = vSynchronizationGroup->getIds();
395 auto vSyncIds = vSynchronizationGroup->getIds();
396 qCDebug(LOG_VariableController()) << "Var in synchro group ";
368 for (auto vId : vSyncIds) {
397 for (auto vId : vSyncIds) {
369 auto var = impl->findVariable(vId);
398 auto var = impl->findVariable(vId);
370 if (var != nullptr) {
399
371 qCInfo(LOG_VariableController()) << "processRequest synchro for" << var->name();
400 // Don't process already processed var
372 auto vSyncRangeRequested
401 if (!variables.contains(var)) {
373 = computeSynchroRangeRequested(var->range(), range, oldRange);
402 if (var != nullptr) {
374 impl->processRequest(var, vSyncRangeRequested);
403 qCDebug(LOG_VariableController()) << "processRequest synchro for"
375 }
404 << var->name();
376 else {
405 auto vSyncRangeRequested
377 qCCritical(LOG_VariableController())
406 = computeSynchroRangeRequested(var->range(), range, oldRange);
378 << tr("Impossible to synchronize a null variable");
407 impl->processRequest(var, vSyncRangeRequested);
408 }
409 else {
410 qCCritical(LOG_VariableController())
411
412 << tr("Impossible to synchronize a null variable");
413 }
379 }
414 }
380 }
415 }
381 }
416 }
@@ -503,6 +538,6 void VariableController::VariableControllerPrivate::registerProvider(
503 &VariableAcquisitionWorker::onVariableRetrieveDataInProgress);
538 &VariableAcquisitionWorker::onVariableRetrieveDataInProgress);
504 }
539 }
505 else {
540 else {
506 qCInfo(LOG_VariableController()) << tr("Cannot register provider, it already exists ");
541 qCDebug(LOG_VariableController()) << tr("Cannot register provider, it already exists ");
507 }
542 }
508 }
543 }
@@ -64,8 +64,8 void TestOneDimArrayData::testDataByComponentIndex_data()
64 // Test cases
64 // Test cases
65 QTest::newRow("validIndex") << QVector<double>{1., 2., 3., 4., 5.} << 0
65 QTest::newRow("validIndex") << QVector<double>{1., 2., 3., 4., 5.} << 0
66 << QVector<double>{1., 2., 3., 4., 5.};
66 << QVector<double>{1., 2., 3., 4., 5.};
67 QTest::newRow("invalidIndex1")
67 QTest::newRow("invalidIndex1") << QVector<double>{1., 2., 3., 4., 5.} << -1
68 << QVector<double>{1., 2., 3., 4., 5.} << -1 << QVector<double>{};
68 << QVector<double>{};
69 QTest::newRow("invalidIndex2") << QVector<double>{1., 2., 3., 4., 5.} << 1 << QVector<double>{};
69 QTest::newRow("invalidIndex2") << QVector<double>{1., 2., 3., 4., 5.} << 1 << QVector<double>{};
70 }
70 }
71
71
@@ -75,8 +75,8 void TestTwoDimArrayData::testCtor_data()
75 QTest::newRow("malformedInput (components of the array data haven't the same size")
75 QTest::newRow("malformedInput (components of the array data haven't the same size")
76 << DataContainer{{1., 2., 3., 4., 5.}, {6., 7., 8.}, {11., 12.}} << true
76 << DataContainer{{1., 2., 3., 4., 5.}, {6., 7., 8.}, {11., 12.}} << true
77 << DataContainer{{}, {}, {}};
77 << DataContainer{{}, {}, {}};
78 QTest::newRow("invalidInput (less than tow components")
78 QTest::newRow("invalidInput (less than tow components") << DataContainer{{1., 2., 3., 4., 5.}}
79 << DataContainer{{1., 2., 3., 4., 5.}} << false << DataContainer{{}, {}, {}};
79 << false << DataContainer{{}, {}, {}};
80 }
80 }
81
81
82 void TestTwoDimArrayData::testCtor()
82 void TestTwoDimArrayData::testCtor()
@@ -52,6 +52,9 signals:
52 const SqpRange &oldRange, bool synchronise);
52 const SqpRange &oldRange, bool synchronise);
53
53
54
54
55 void variableAdded(std::shared_ptr<Variable> var);
56
57
55 private:
58 private:
56 Ui::VisualizationGraphWidget *ui;
59 Ui::VisualizationGraphWidget *ui;
57
60
@@ -42,6 +42,10 public:
42 bool contains(const Variable &variable) const override;
42 bool contains(const Variable &variable) const override;
43 QString name() const override;
43 QString name() const override;
44
44
45
46 private slots:
47 void onVariableAdded(std::shared_ptr<Variable> variable);
48
45 private:
49 private:
46 Ui::VisualizationZoneWidget *ui;
50 Ui::VisualizationZoneWidget *ui;
47
51
@@ -95,44 +95,30 void VisualizationGraphWidget::enableAcquisition(bool enable)
95
95
96 void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable)
96 void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable)
97 {
97 {
98 auto calibrationState = impl->m_IsCalibration;
99 impl->m_IsCalibration = true;
98 // Uses delegate to create the qcpplot components according to the variable
100 // Uses delegate to create the qcpplot components according to the variable
99 auto createdPlottables = VisualizationGraphHelper::create(variable, *ui->widget);
101 auto createdPlottables = VisualizationGraphHelper::create(variable, *ui->widget);
102 impl->m_IsCalibration = calibrationState;
100
103
101 for (auto createdPlottable : qAsConst(createdPlottables)) {
104 for (auto createdPlottable : qAsConst(createdPlottables)) {
102 impl->m_VariableToPlotMultiMap.insert({variable, createdPlottable});
105 impl->m_VariableToPlotMultiMap.insert({variable, createdPlottable});
103 }
106 }
104
107
105 connect(variable.get(), SIGNAL(updated()), this, SLOT(onDataCacheVariableUpdated()));
108 connect(variable.get(), SIGNAL(updated()), this, SLOT(onDataCacheVariableUpdated()));
109
110 emit variableAdded(variable);
106 }
111 }
107 void VisualizationGraphWidget::addVariableUsingGraph(std::shared_ptr<Variable> variable)
112 void VisualizationGraphWidget::addVariableUsingGraph(std::shared_ptr<Variable> variable)
108 {
113 {
109 // TODO
114 // Uses delegate to create the qcpplot components according to the variable
110 // // when adding a variable, we need to set its time range to the current graph range
115 this->addVariable(variable);
111 // auto grapheRange = ui->widget->xAxis->range();
112 // auto dateTime = SqpRange{grapheRange.lower, grapheRange.upper};
113 // variable->setDateTime(dateTime);
114
115 // auto variableDateTimeWithTolerance = dateTime;
116
117 // // add tolerance for each side
118 // auto toleranceFactor
119 // = toleranceValue(GENERAL_TOLERANCE_AT_INIT_KEY,
120 // GENERAL_TOLERANCE_AT_INIT_DEFAULT_VALUE);
121 // auto tolerance = toleranceFactor * (dateTime.m_TEnd - dateTime.m_TStart);
122 // variableDateTimeWithTolerance.m_TStart -= tolerance;
123 // variableDateTimeWithTolerance.m_TEnd += tolerance;
124
125 // // Uses delegate to create the qcpplot components according to the variable
126 // auto createdPlottables = VisualizationGraphHelper::create(variable, *ui->widget);
127
128 // for (auto createdPlottable : qAsConst(createdPlottables)) {
129 // impl->m_VariableToPlotMultiMap.insert({variable, createdPlottable});
130 // }
131
116
132 // connect(variable.get(), SIGNAL(updated()), this, SLOT(onDataCacheVariableUpdated()));
117 // Request range for the variable
118 auto graphRange = ui->widget->xAxis->range();
133
119
134 // // CHangement detected, we need to ask controller to request data loading
120 emit requestDataLoading(QVector<std::shared_ptr<Variable> >() << variable,
135 // emit requestDataLoading(variable, variableDateTimeWithTolerance);
121 SqpRange{graphRange.lower, graphRange.upper}, variable->range(), false);
136 }
122 }
137
123
138 void VisualizationGraphWidget::removeVariable(std::shared_ptr<Variable> variable) noexcept
124 void VisualizationGraphWidget::removeVariable(std::shared_ptr<Variable> variable) noexcept
@@ -249,9 +235,9 void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange
249 !impl->m_IsCalibration);
235 !impl->m_IsCalibration);
250
236
251 if (!impl->m_IsCalibration) {
237 if (!impl->m_IsCalibration) {
252 qCDebug(LOG_VisualizationGraphWidget())
238 qCInfo(LOG_VisualizationGraphWidget())
253 << tr("TORM: VisualizationGraphWidget::Synchronize notify !!")
239 << tr("TORM: VisualizationGraphWidget::Synchronize notify !!")
254 << QThread::currentThread()->objectName();
240 << QThread::currentThread()->objectName() << graphRange << oldGraphRange;
255 emit synchronize(graphRange, oldGraphRange);
241 emit synchronize(graphRange, oldGraphRange);
256 }
242 }
257 }
243 }
@@ -79,9 +79,6 VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<V
79 graphWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding);
79 graphWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding);
80 graphWidget->setMinimumHeight(GRAPH_MINIMUM_HEIGHT);
80 graphWidget->setMinimumHeight(GRAPH_MINIMUM_HEIGHT);
81
81
82 this->addGraph(graphWidget);
83
84 graphWidget->addVariable(variable);
85
82
86 // Lambda to synchronize zone widget
83 // Lambda to synchronize zone widget
87 auto synchronizeZoneWidget = [this, graphWidget](const SqpRange &grapheRange,
84 auto synchronizeZoneWidget = [this, graphWidget](const SqpRange &grapheRange,
@@ -168,6 +165,12 VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<V
168
165
169 // connection for synchronization
166 // connection for synchronization
170 connect(graphWidget, &VisualizationGraphWidget::synchronize, synchronizeZoneWidget);
167 connect(graphWidget, &VisualizationGraphWidget::synchronize, synchronizeZoneWidget);
168 connect(graphWidget, &VisualizationGraphWidget::variableAdded, this,
169 &VisualizationZoneWidget::onVariableAdded);
170
171 this->addGraph(graphWidget);
172
173 graphWidget->addVariable(variable);
171
174
172 return graphWidget;
175 return graphWidget;
173 }
176 }
@@ -213,3 +216,10 QString VisualizationZoneWidget::name() const
213 {
216 {
214 return ui->zoneNameLabel->text();
217 return ui->zoneNameLabel->text();
215 }
218 }
219
220 void VisualizationZoneWidget::onVariableAdded(std::shared_ptr<Variable> variable)
221 {
222 QMetaObject::invokeMethod(&sqpApp->variableController(), "onAddSynchronized",
223 Qt::QueuedConnection, Q_ARG(std::shared_ptr<Variable>, variable),
224 Q_ARG(QUuid, impl->m_SynchronisationGroupId));
225 }
@@ -61,7 +61,8 void AmdaProvider::requestDataLoading(QUuid acqIdentifier, const DataProviderPar
61 const auto times = parameters.m_Times;
61 const auto times = parameters.m_Times;
62 const auto data = parameters.m_Data;
62 const auto data = parameters.m_Data;
63 for (const auto &dateTime : qAsConst(times)) {
63 for (const auto &dateTime : qAsConst(times)) {
64 retrieveData(acqIdentifier, dateTime, data);
64 this->retrieveData(acqIdentifier, dateTime, data);
65 QThread::msleep(200);
65 }
66 }
66 }
67 }
67
68
General Comments 0
You need to be logged in to leave comments. Login now