From bf486b19bffa62939ae2883a0f8a1d0310921385 2017-08-14 12:52:49 From: mperrinel Date: 2017-08-14 12:52:49 Subject: [PATCH] Add synchronization part of v5 acquisition --- diff --git a/core/include/Variable/VariableController.h b/core/include/Variable/VariableController.h index 632ae7b..cf14962 100644 --- a/core/include/Variable/VariableController.h +++ b/core/include/Variable/VariableController.h @@ -102,6 +102,7 @@ public slots: /// synchronization group methods void onAddSynchronizationGroupId(QUuid synchronizationGroupId); void onRemoveSynchronizationGroupId(QUuid synchronizationGroupId); + void onAddSynchronized(std::shared_ptr variable, QUuid synchronizationGroupId); void initialize(); void finalize(); diff --git a/core/src/Variable/VariableController.cpp b/core/src/Variable/VariableController.cpp index 4797879..50bc7a1 100644 --- a/core/src/Variable/VariableController.cpp +++ b/core/src/Variable/VariableController.cpp @@ -263,18 +263,16 @@ void VariableController::onDataProvided(QUuid vIdentifier, const SqpRange &range const SqpRange &cacheRangeRequested, QVector dataAcquired) { - qCCritical(LOG_VariableController()) << tr("onDataProvided") << dataAcquired.isEmpty(); - auto var = impl->findVariable(vIdentifier); if (var != nullptr) { var->setRange(rangeRequested); var->setCacheRange(cacheRangeRequested); - qCCritical(LOG_VariableController()) << tr("1: onDataProvided") << rangeRequested; - qCCritical(LOG_VariableController()) << tr("2: onDataProvided") << cacheRangeRequested; + qCDebug(LOG_VariableController()) << tr("1: onDataProvided") << rangeRequested; + qCDebug(LOG_VariableController()) << tr("2: onDataProvided") << cacheRangeRequested; auto retrievedDataSeries = impl->retrieveDataSeries(dataAcquired); - qCCritical(LOG_VariableController()) << tr("3: onDataProvided") - << retrievedDataSeries->range(); + qCDebug(LOG_VariableController()) << tr("3: onDataProvided") + << retrievedDataSeries->range(); var->mergeDataSeries(retrievedDataSeries); emit var->updated(); } @@ -313,6 +311,9 @@ void VariableController::onAbortProgressRequested(std::shared_ptr vari void VariableController::onAddSynchronizationGroupId(QUuid synchronizationGroupId) { + qCDebug(LOG_VariableController()) << "TORM: VariableController::onAddSynchronizationGroupId" + << QThread::currentThread()->objectName() + << synchronizationGroupId; auto vSynchroGroup = std::make_shared(); impl->m_GroupIdToVariableSynchronizationGroupMap.insert( std::make_pair(synchronizationGroupId, vSynchroGroup)); @@ -323,6 +324,33 @@ void VariableController::onRemoveSynchronizationGroupId(QUuid synchronizationGro impl->m_GroupIdToVariableSynchronizationGroupMap.erase(synchronizationGroupId); } +void VariableController::onAddSynchronized(std::shared_ptr variable, + QUuid synchronizationGroupId) + +{ + qCDebug(LOG_VariableController()) << "TORM: VariableController::onAddSynchronized" + << synchronizationGroupId; + auto vToVIdit = impl->m_VariableToIdentifierMap.find(variable); + if (vToVIdit != impl->m_VariableToIdentifierMap.cend()) { + auto itSynchroGroup + = impl->m_GroupIdToVariableSynchronizationGroupMap.find(synchronizationGroupId); + if (itSynchroGroup != impl->m_GroupIdToVariableSynchronizationGroupMap.cend()) { + impl->m_VariableIdGroupIdMap.insert( + std::make_pair(vToVIdit->second, synchronizationGroupId)); + itSynchroGroup->second->addVariableId(vToVIdit->second); + } + else { + qCCritical(LOG_VariableController()) + << tr("Impossible to synchronize a variable with an unknown sycnhronization group") + << variable->name(); + } + } + else { + qCCritical(LOG_VariableController()) + << tr("Impossible to synchronize a variable with no identifier") << variable->name(); + } +} + void VariableController::onRequestDataLoading(QVector > variables, const SqpRange &range, const SqpRange &oldRange, @@ -337,24 +365,24 @@ void VariableController::onRequestDataLoading(QVector // For the other, we ask the provider to give them. foreach (auto var, variables) { - qCInfo(LOG_VariableController()) << "processRequest for" << var->name(); + qCDebug(LOG_VariableController()) << "processRequest for" << var->name(); impl->processRequest(var, range); } if (synchronise) { // Get the group ids - qCInfo(LOG_VariableController()) + qCDebug(LOG_VariableController()) << "VariableController::onRequestDataLoading for synchro var ENABLE"; auto groupIds = std::set(); foreach (auto var, variables) { - auto vToVIdit = impl->m_VariableToIdentifierMap.find(var); - if (vToVIdit != impl->m_VariableToIdentifierMap.cend()) { - auto vId = vToVIdit->second; - - auto vIdToGIdit = impl->m_VariableIdGroupIdMap.find(vId); - if (vIdToGIdit != impl->m_VariableIdGroupIdMap.cend()) { - auto gId = vToVIdit->second; + auto varToVarIdIt = impl->m_VariableToIdentifierMap.find(var); + if (varToVarIdIt != impl->m_VariableToIdentifierMap.cend()) { + auto vId = varToVarIdIt->second; + auto varIdToGroupIdIt = impl->m_VariableIdGroupIdMap.find(vId); + if (varIdToGroupIdIt != impl->m_VariableIdGroupIdMap.cend()) { + auto gId = varIdToGroupIdIt->second; if (groupIds.find(gId) == groupIds.cend()) { + qCDebug(LOG_VariableController()) << "Synchro detect group " << gId; groupIds.insert(gId); } } @@ -365,17 +393,24 @@ void VariableController::onRequestDataLoading(QVector foreach (auto gId, groupIds) { auto vSynchronizationGroup = impl->m_GroupIdToVariableSynchronizationGroupMap.at(gId); auto vSyncIds = vSynchronizationGroup->getIds(); + qCDebug(LOG_VariableController()) << "Var in synchro group "; for (auto vId : vSyncIds) { auto var = impl->findVariable(vId); - if (var != nullptr) { - qCInfo(LOG_VariableController()) << "processRequest synchro for" << var->name(); - auto vSyncRangeRequested - = computeSynchroRangeRequested(var->range(), range, oldRange); - impl->processRequest(var, vSyncRangeRequested); - } - else { - qCCritical(LOG_VariableController()) - << tr("Impossible to synchronize a null variable"); + + // Don't process already processed var + if (!variables.contains(var)) { + if (var != nullptr) { + qCDebug(LOG_VariableController()) << "processRequest synchro for" + << var->name(); + auto vSyncRangeRequested + = computeSynchroRangeRequested(var->range(), range, oldRange); + impl->processRequest(var, vSyncRangeRequested); + } + else { + qCCritical(LOG_VariableController()) + + << tr("Impossible to synchronize a null variable"); + } } } } @@ -503,6 +538,6 @@ void VariableController::VariableControllerPrivate::registerProvider( &VariableAcquisitionWorker::onVariableRetrieveDataInProgress); } else { - qCInfo(LOG_VariableController()) << tr("Cannot register provider, it already exists "); + qCDebug(LOG_VariableController()) << tr("Cannot register provider, it already exists "); } } diff --git a/core/tests/Data/TestOneDimArrayData.cpp b/core/tests/Data/TestOneDimArrayData.cpp index d946465..a7f0720 100644 --- a/core/tests/Data/TestOneDimArrayData.cpp +++ b/core/tests/Data/TestOneDimArrayData.cpp @@ -64,8 +64,8 @@ void TestOneDimArrayData::testDataByComponentIndex_data() // Test cases QTest::newRow("validIndex") << QVector{1., 2., 3., 4., 5.} << 0 << QVector{1., 2., 3., 4., 5.}; - QTest::newRow("invalidIndex1") - << QVector{1., 2., 3., 4., 5.} << -1 << QVector{}; + QTest::newRow("invalidIndex1") << QVector{1., 2., 3., 4., 5.} << -1 + << QVector{}; QTest::newRow("invalidIndex2") << QVector{1., 2., 3., 4., 5.} << 1 << QVector{}; } diff --git a/core/tests/Data/TestTwoDimArrayData.cpp b/core/tests/Data/TestTwoDimArrayData.cpp index 39aef29..a8de502 100644 --- a/core/tests/Data/TestTwoDimArrayData.cpp +++ b/core/tests/Data/TestTwoDimArrayData.cpp @@ -75,8 +75,8 @@ void TestTwoDimArrayData::testCtor_data() QTest::newRow("malformedInput (components of the array data haven't the same size") << DataContainer{{1., 2., 3., 4., 5.}, {6., 7., 8.}, {11., 12.}} << true << DataContainer{{}, {}, {}}; - QTest::newRow("invalidInput (less than tow components") - << DataContainer{{1., 2., 3., 4., 5.}} << false << DataContainer{{}, {}, {}}; + QTest::newRow("invalidInput (less than tow components") << DataContainer{{1., 2., 3., 4., 5.}} + << false << DataContainer{{}, {}, {}}; } void TestTwoDimArrayData::testCtor() diff --git a/gui/include/Visualization/VisualizationGraphWidget.h b/gui/include/Visualization/VisualizationGraphWidget.h index b5d02f0..a39d5fd 100644 --- a/gui/include/Visualization/VisualizationGraphWidget.h +++ b/gui/include/Visualization/VisualizationGraphWidget.h @@ -52,6 +52,9 @@ signals: const SqpRange &oldRange, bool synchronise); + void variableAdded(std::shared_ptr var); + + private: Ui::VisualizationGraphWidget *ui; diff --git a/gui/include/Visualization/VisualizationZoneWidget.h b/gui/include/Visualization/VisualizationZoneWidget.h index a8968d1..1f5125f 100644 --- a/gui/include/Visualization/VisualizationZoneWidget.h +++ b/gui/include/Visualization/VisualizationZoneWidget.h @@ -42,6 +42,10 @@ public: bool contains(const Variable &variable) const override; QString name() const override; + +private slots: + void onVariableAdded(std::shared_ptr variable); + private: Ui::VisualizationZoneWidget *ui; diff --git a/gui/src/Visualization/VisualizationGraphWidget.cpp b/gui/src/Visualization/VisualizationGraphWidget.cpp index a795419..bc6a4e7 100644 --- a/gui/src/Visualization/VisualizationGraphWidget.cpp +++ b/gui/src/Visualization/VisualizationGraphWidget.cpp @@ -95,44 +95,30 @@ void VisualizationGraphWidget::enableAcquisition(bool enable) void VisualizationGraphWidget::addVariable(std::shared_ptr variable) { + auto calibrationState = impl->m_IsCalibration; + impl->m_IsCalibration = true; // Uses delegate to create the qcpplot components according to the variable auto createdPlottables = VisualizationGraphHelper::create(variable, *ui->widget); + impl->m_IsCalibration = calibrationState; for (auto createdPlottable : qAsConst(createdPlottables)) { impl->m_VariableToPlotMultiMap.insert({variable, createdPlottable}); } connect(variable.get(), SIGNAL(updated()), this, SLOT(onDataCacheVariableUpdated())); + + emit variableAdded(variable); } void VisualizationGraphWidget::addVariableUsingGraph(std::shared_ptr variable) { - // TODO - // // when adding a variable, we need to set its time range to the current graph range - // auto grapheRange = ui->widget->xAxis->range(); - // auto dateTime = SqpRange{grapheRange.lower, grapheRange.upper}; - // variable->setDateTime(dateTime); - - // auto variableDateTimeWithTolerance = dateTime; - - // // add tolerance for each side - // auto toleranceFactor - // = toleranceValue(GENERAL_TOLERANCE_AT_INIT_KEY, - // GENERAL_TOLERANCE_AT_INIT_DEFAULT_VALUE); - // auto tolerance = toleranceFactor * (dateTime.m_TEnd - dateTime.m_TStart); - // variableDateTimeWithTolerance.m_TStart -= tolerance; - // variableDateTimeWithTolerance.m_TEnd += tolerance; - - // // Uses delegate to create the qcpplot components according to the variable - // auto createdPlottables = VisualizationGraphHelper::create(variable, *ui->widget); - - // for (auto createdPlottable : qAsConst(createdPlottables)) { - // impl->m_VariableToPlotMultiMap.insert({variable, createdPlottable}); - // } + // Uses delegate to create the qcpplot components according to the variable + this->addVariable(variable); - // connect(variable.get(), SIGNAL(updated()), this, SLOT(onDataCacheVariableUpdated())); + // Request range for the variable + auto graphRange = ui->widget->xAxis->range(); - // // CHangement detected, we need to ask controller to request data loading - // emit requestDataLoading(variable, variableDateTimeWithTolerance); + emit requestDataLoading(QVector >() << variable, + SqpRange{graphRange.lower, graphRange.upper}, variable->range(), false); } void VisualizationGraphWidget::removeVariable(std::shared_ptr variable) noexcept @@ -249,9 +235,9 @@ void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange !impl->m_IsCalibration); if (!impl->m_IsCalibration) { - qCDebug(LOG_VisualizationGraphWidget()) + qCInfo(LOG_VisualizationGraphWidget()) << tr("TORM: VisualizationGraphWidget::Synchronize notify !!") - << QThread::currentThread()->objectName(); + << QThread::currentThread()->objectName() << graphRange << oldGraphRange; emit synchronize(graphRange, oldGraphRange); } } diff --git a/gui/src/Visualization/VisualizationZoneWidget.cpp b/gui/src/Visualization/VisualizationZoneWidget.cpp index 7e4f26a..592c9c1 100644 --- a/gui/src/Visualization/VisualizationZoneWidget.cpp +++ b/gui/src/Visualization/VisualizationZoneWidget.cpp @@ -79,9 +79,6 @@ VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptrsetSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding); graphWidget->setMinimumHeight(GRAPH_MINIMUM_HEIGHT); - this->addGraph(graphWidget); - - graphWidget->addVariable(variable); // Lambda to synchronize zone widget auto synchronizeZoneWidget = [this, graphWidget](const SqpRange &grapheRange, @@ -168,6 +165,12 @@ VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptraddGraph(graphWidget); + + graphWidget->addVariable(variable); return graphWidget; } @@ -213,3 +216,10 @@ QString VisualizationZoneWidget::name() const { return ui->zoneNameLabel->text(); } + +void VisualizationZoneWidget::onVariableAdded(std::shared_ptr variable) +{ + QMetaObject::invokeMethod(&sqpApp->variableController(), "onAddSynchronized", + Qt::QueuedConnection, Q_ARG(std::shared_ptr, variable), + Q_ARG(QUuid, impl->m_SynchronisationGroupId)); +} diff --git a/plugins/amda/src/AmdaProvider.cpp b/plugins/amda/src/AmdaProvider.cpp index b75ff5c..9f90d82 100644 --- a/plugins/amda/src/AmdaProvider.cpp +++ b/plugins/amda/src/AmdaProvider.cpp @@ -61,7 +61,8 @@ void AmdaProvider::requestDataLoading(QUuid acqIdentifier, const DataProviderPar const auto times = parameters.m_Times; const auto data = parameters.m_Data; for (const auto &dateTime : qAsConst(times)) { - retrieveData(acqIdentifier, dateTime, data); + this->retrieveData(acqIdentifier, dateTime, data); + QThread::msleep(200); } }