From 23422057e4077fc1934ab51ae3154a9fd6a65a53 2017-08-17 14:12:31 From: mperrinel Date: 2017-08-17 14:12:31 Subject: [PATCH] Merge branch 'feature/DisplayDataBeforeAcquisition' into develop --- diff --git a/core/include/Variable/Variable.h b/core/include/Variable/Variable.h index e67ba68..f1d4928 100644 --- a/core/include/Variable/Variable.h +++ b/core/include/Variable/Variable.h @@ -47,6 +47,7 @@ public: bool cacheIsInside(const SqpRange &range) const noexcept; QVector provideNotInCacheRangeList(const SqpRange &range) const noexcept; + QVector provideInCacheRangeList(const SqpRange &range) const noexcept; void setDataSeries(std::shared_ptr dataSeries) noexcept; void mergeDataSeries(std::shared_ptr dataSeries) noexcept; diff --git a/core/include/Variable/VariableController.h b/core/include/Variable/VariableController.h index cf14962..d2b6384 100644 --- a/core/include/Variable/VariableController.h +++ b/core/include/Variable/VariableController.h @@ -73,6 +73,9 @@ signals: /// Signal emitted when a data acquisition is requested on a range for a variable void rangeChanged(std::shared_ptr variable, const SqpRange &range); + /// Signal emitted when a sub range of the cacheRange of the variable can be displayed + void updateVarDisplaying(std::shared_ptr variable, const SqpRange &range); + public slots: /// Request the data loading of the variable whithin range void onRequestDataLoading(QVector > variables, const SqpRange &range, diff --git a/core/src/Variable/Variable.cpp b/core/src/Variable/Variable.cpp index ace298f..aad63c4 100644 --- a/core/src/Variable/Variable.cpp +++ b/core/src/Variable/Variable.cpp @@ -182,6 +182,8 @@ bool Variable::cacheIsInside(const SqpRange &range) const noexcept QVector Variable::provideNotInCacheRangeList(const SqpRange &range) const noexcept { + // This code assume that cach in contigue. Can return 0, 1 or 2 SqpRange + auto notInCache = QVector{}; if (!this->cacheContains(range)) { @@ -209,3 +211,33 @@ QVector Variable::provideNotInCacheRangeList(const SqpRange &range) co return notInCache; } + +QVector Variable::provideInCacheRangeList(const SqpRange &range) const noexcept +{ + // This code assume that cach in contigue. Can return 0 or 1 SqpRange + + auto inCache = QVector{}; + + + if (this->cacheContains(range)) { + if (range.m_TStart <= impl->m_CacheRange.m_TEnd + && range.m_TEnd >= impl->m_CacheRange.m_TEnd) { + inCache << SqpRange{range.m_TStart, impl->m_CacheRange.m_TEnd}; + } + + else if (range.m_TStart >= impl->m_CacheRange.m_TStart + && range.m_TEnd < impl->m_CacheRange.m_TEnd) { + inCache << range; + } + else if (range.m_TStart < impl->m_CacheRange.m_TStart + && range.m_TEnd >= impl->m_CacheRange.m_TStart) { + inCache << SqpRange{impl->m_CacheRange.m_TStart, range.m_TEnd}; + } + else { + qCCritical(LOG_Variable()) << tr("Detection of unknown case.") + << QThread::currentThread(); + } + } + + return inCache; +} diff --git a/core/src/Variable/VariableController.cpp b/core/src/Variable/VariableController.cpp index ad796fd..908db03 100644 --- a/core/src/Variable/VariableController.cpp +++ b/core/src/Variable/VariableController.cpp @@ -80,7 +80,8 @@ struct VariableController::VariableControllerPrivate { m_VariableSelectionModel{new QItemSelectionModel{m_VariableModel, parent}}, m_VariableCacheController{std::make_unique()}, m_VariableCacheStrategy{std::make_unique()}, - m_VariableAcquisitionWorker{std::make_unique()} + m_VariableAcquisitionWorker{std::make_unique()}, + q{parent} { m_VariableAcquisitionWorker->moveToThread(&m_VariableAcquisitionWorkerThread); @@ -126,6 +127,9 @@ struct VariableController::VariableControllerPrivate { m_GroupIdToVariableSynchronizationGroupMap; std::map m_VariableIdGroupIdMap; std::set > m_ProviderSet; + + + VariableController *q; }; @@ -463,6 +467,7 @@ void VariableController::VariableControllerPrivate::processRequest(std::shared_p auto varRangesRequested = m_VariableCacheStrategy->computeCacheRange(var->range(), rangeRequested); auto notInCacheRangeList = var->provideNotInCacheRangeList(varRangesRequested.second); + auto inCacheRangeList = var->provideInCacheRangeList(varRangesRequested.second); if (!notInCacheRangeList.empty()) { auto identifier = m_VariableToIdentifierMap.at(var); @@ -477,6 +482,10 @@ void VariableController::VariableControllerPrivate::processRequest(std::shared_p qCCritical(LOG_VariableController()) << "Impossible to provide data with a null provider"; } + + if (!inCacheRangeList.empty()) { + emit q->updateVarDisplaying(var, inCacheRangeList.first()); + } } else { var->setRange(rangeRequested); diff --git a/gui/include/Visualization/VisualizationGraphWidget.h b/gui/include/Visualization/VisualizationGraphWidget.h index d9a03ac..c40ee8b 100644 --- a/gui/include/Visualization/VisualizationGraphWidget.h +++ b/gui/include/Visualization/VisualizationGraphWidget.h @@ -79,6 +79,8 @@ private slots: void onMouseRelease(QMouseEvent *event) noexcept; void onDataCacheVariableUpdated(); + + void onUpdateVarDisplaying(std::shared_ptr variable, const SqpRange &range); }; #endif // SCIQLOP_VISUALIZATIONGRAPHWIDGET_H diff --git a/gui/src/Visualization/VisualizationGraphHelper.cpp b/gui/src/Visualization/VisualizationGraphHelper.cpp index 17611c9..80ae762 100644 --- a/gui/src/Visualization/VisualizationGraphHelper.cpp +++ b/gui/src/Visualization/VisualizationGraphHelper.cpp @@ -36,33 +36,18 @@ QSharedPointer axisTicker(bool isTimeAxis) } void updateScalarData(QCPAbstractPlottable *component, std::shared_ptr scalarSeries, - const SqpRange &dateTime) + const SqpRange &range) { qCDebug(LOG_VisualizationGraphHelper()) << "TORM: updateScalarData" << QThread::currentThread()->objectName(); if (auto qcpGraph = dynamic_cast(component)) { scalarSeries->lockRead(); { - const auto &xData = scalarSeries->xAxisData()->cdata(); - const auto &valuesData = scalarSeries->valuesData()->cdata(); - - auto xDataBegin = xData.cbegin(); - auto xDataEnd = xData.cend(); - - qCInfo(LOG_VisualizationGraphHelper()) << "TODEBUG: Current points in cache" - << xData.count(); - auto sqpDataContainer = QSharedPointer::create(); qcpGraph->setData(sqpDataContainer); - - auto lowerIt = std::lower_bound(xDataBegin, xDataEnd, dateTime.m_TStart); - auto upperIt = std::upper_bound(xDataBegin, xDataEnd, dateTime.m_TEnd); - auto distance = std::distance(xDataBegin, lowerIt); - - auto valuesDataIt = valuesData.cbegin() + distance; - for (auto xAxisDataIt = lowerIt; xAxisDataIt != upperIt; - ++xAxisDataIt, ++valuesDataIt) { - sqpDataContainer->appendGraphData(QCPGraphData(*xAxisDataIt, *valuesDataIt)); + auto bounds = scalarSeries->subData(range.m_TStart, range.m_TEnd); + for (auto it = bounds.first; it != bounds.second; ++it) { + sqpDataContainer->appendGraphData(QCPGraphData(it->x(), it->value())); } qCInfo(LOG_VisualizationGraphHelper()) << "TODEBUG: Current points displayed" diff --git a/gui/src/Visualization/VisualizationGraphWidget.cpp b/gui/src/Visualization/VisualizationGraphWidget.cpp index 7d2935f..ad7b12a 100644 --- a/gui/src/Visualization/VisualizationGraphWidget.cpp +++ b/gui/src/Visualization/VisualizationGraphWidget.cpp @@ -80,6 +80,9 @@ VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget connect(this, &VisualizationGraphWidget::requestDataLoading, &sqpApp->variableController(), &VariableController::onRequestDataLoading); + + connect(&sqpApp->variableController(), &VariableController::updateVarDisplaying, this, + &VisualizationGraphWidget::onUpdateVarDisplaying); } @@ -305,3 +308,13 @@ void VisualizationGraphWidget::onDataCacheVariableUpdated() } } } + +void VisualizationGraphWidget::onUpdateVarDisplaying(std::shared_ptr variable, + const SqpRange &range) +{ + auto componentsIt = impl->m_VariableToPlotMultiMap.equal_range(variable); + for (auto it = componentsIt.first; it != componentsIt.second;) { + VisualizationGraphHelper::updateData(QVector{} << it->second, + variable->dataSeries(), range); + } +} diff --git a/plugins/amda/tests/TestAmdaResultParser.cpp b/plugins/amda/tests/TestAmdaResultParser.cpp index 13241c2..5bb2133 100644 --- a/plugins/amda/tests/TestAmdaResultParser.cpp +++ b/plugins/amda/tests/TestAmdaResultParser.cpp @@ -258,11 +258,11 @@ void TestAmdaResultParser::testReadScalarTxt_data() QVector{}, QVector{}}; // Invalid files - QTest::newRow("Invalid file (unexisting file)") - << QStringLiteral("UnexistingFile.txt") << ExpectedResults{}; + QTest::newRow("Invalid file (unexisting file)") << QStringLiteral("UnexistingFile.txt") + << ExpectedResults{}; - QTest::newRow("Invalid file (file not found on server)") - << QStringLiteral("FileNotFound.txt") << ExpectedResults{}; + QTest::newRow("Invalid file (file not found on server)") << QStringLiteral("FileNotFound.txt") + << ExpectedResults{}; } void TestAmdaResultParser::testReadScalarTxt()