From a634d49196c669f7a7d3303d711d063d0dd67777 2017-07-03 13:34:40 From: mperrinel Date: 2017-07-03 13:34:40 Subject: [PATCH] Merge branch 'feature/addTimeToCache' into develop --- diff --git a/core/include/Data/SqpDateTime.h b/core/include/Data/SqpDateTime.h index 0a936e2..3ea0484 100644 --- a/core/include/Data/SqpDateTime.h +++ b/core/include/Data/SqpDateTime.h @@ -17,12 +17,12 @@ struct SqpDateTime { /// End time double m_TEnd; - bool contains(const SqpDateTime &dateTime) + bool contains(const SqpDateTime &dateTime) const noexcept { return (m_TStart <= dateTime.m_TStart && m_TEnd >= dateTime.m_TEnd); } - bool intersect(const SqpDateTime &dateTime) + bool intersect(const SqpDateTime &dateTime) const noexcept { return (m_TEnd >= dateTime.m_TStart && m_TStart <= dateTime.m_TEnd); } diff --git a/core/include/Variable/Variable.h b/core/include/Variable/Variable.h index 1bd730c..0232cb1 100644 --- a/core/include/Variable/Variable.h +++ b/core/include/Variable/Variable.h @@ -34,8 +34,9 @@ public: /// @return the data of the variable, nullptr if there is no data IDataSeries *dataSeries() const noexcept; - bool contains(const SqpDateTime &dateTime); - bool intersect(const SqpDateTime &dateTime); + bool contains(const SqpDateTime &dateTime) const noexcept; + bool intersect(const SqpDateTime &dateTime) const noexcept; + bool isInside(const SqpDateTime &dateTime) const noexcept; public slots: void setDataSeries(std::shared_ptr dataSeries) noexcept; diff --git a/core/include/Variable/VariableModel.h b/core/include/Variable/VariableModel.h index 02b204b..7fa865a 100644 --- a/core/include/Variable/VariableModel.h +++ b/core/include/Variable/VariableModel.h @@ -25,12 +25,10 @@ public: * Creates a new variable in the model * @param name the name of the new variable * @param dateTime the dateTime of the new variable - * @param defaultDataSeries the default data of the new variable * @return the pointer to the new variable */ - std::shared_ptr - createVariable(const QString &name, const SqpDateTime &dateTime, - std::shared_ptr defaultDataSeries) noexcept; + std::shared_ptr createVariable(const QString &name, + const SqpDateTime &dateTime) noexcept; std::shared_ptr variable(int index) const; diff --git a/core/src/Variable/Variable.cpp b/core/src/Variable/Variable.cpp index 7f98687..17795a3 100644 --- a/core/src/Variable/Variable.cpp +++ b/core/src/Variable/Variable.cpp @@ -78,12 +78,17 @@ IDataSeries *Variable::dataSeries() const noexcept return impl->m_DataSeries.get(); } -bool Variable::contains(const SqpDateTime &dateTime) +bool Variable::contains(const SqpDateTime &dateTime) const noexcept { return impl->m_DateTime.contains(dateTime); } -bool Variable::intersect(const SqpDateTime &dateTime) +bool Variable::intersect(const SqpDateTime &dateTime) const noexcept { return impl->m_DateTime.intersect(dateTime); } + +bool Variable::isInside(const SqpDateTime &dateTime) const noexcept +{ + return dateTime.contains(SqpDateTime{impl->m_DateTime.m_TStart, impl->m_DateTime.m_TEnd}); +} diff --git a/core/src/Variable/VariableCacheController.cpp b/core/src/Variable/VariableCacheController.cpp index b5cbd3b..a648b4d 100644 --- a/core/src/Variable/VariableCacheController.cpp +++ b/core/src/Variable/VariableCacheController.cpp @@ -55,7 +55,7 @@ void VariableCacheController::addDateTime(std::shared_ptr variable, impl->m_VariableToSqpDateTimeListMap.at(variable), 0); } catch (const std::out_of_range &e) { - qCWarning(LOG_VariableCacheController()) << e.what(); + qCWarning(LOG_VariableCacheController()) << "addDateTime" << e.what(); } } } @@ -71,13 +71,12 @@ VariableCacheController::provideNotInCacheDateTimeList(std::shared_ptr // list of date time request associated to the variable // We assume that the list is ordered in a way that l(0) < l(1). We assume also a < b // (with a & b of type SqpDateTime) means ts(b) > te(a) - - try { - impl->addInCacheDataByStart(dateTime, impl->m_VariableToSqpDateTimeListMap.at(variable), - notInCache, 0, dateTime.m_TStart); + auto it = impl->m_VariableToSqpDateTimeListMap.find(variable); + if (it != impl->m_VariableToSqpDateTimeListMap.end()) { + impl->addInCacheDataByStart(dateTime, it->second, notInCache, 0, dateTime.m_TStart); } - catch (const std::out_of_range &e) { - qCWarning(LOG_VariableCacheController()) << e.what(); + else { + notInCache << dateTime; } return notInCache; diff --git a/core/src/Variable/VariableController.cpp b/core/src/Variable/VariableController.cpp index 41021cb..0ac0a8b 100644 --- a/core/src/Variable/VariableController.cpp +++ b/core/src/Variable/VariableController.cpp @@ -99,17 +99,21 @@ void VariableController::createVariable(const QString &name, /// - default data are generated for the variable, without taking into account the timerange set /// in sciqlop auto dateTime = impl->m_TimeController->dateTime(); - if (auto newVariable = impl->m_VariableModel->createVariable( - name, dateTime, generateDefaultDataSeries(*provider, dateTime))) { + if (auto newVariable = impl->m_VariableModel->createVariable(name, dateTime)) { // store the provider impl->m_VariableToProviderMap[newVariable] = provider; - connect(provider.get(), &IDataProvider::dataProvided, newVariable.get(), - &Variable::setDataSeries); + auto addDateTimeAcquired + = [this, newVariable](auto dataSeriesAcquired, auto dateTimeToPutInCache) { - // store in cache - impl->m_VariableCacheController->addDateTime(newVariable, dateTime); + impl->m_VariableCacheController->addDateTime(newVariable, dateTimeToPutInCache); + newVariable->setDataSeries(dataSeriesAcquired); + + }; + + connect(provider.get(), &IDataProvider::dataProvided, addDateTimeAcquired); + this->onRequestDataLoading(newVariable, dateTime); // notify the creation emit variableCreated(newVariable); @@ -144,8 +148,6 @@ void VariableController::onRequestDataLoading(std::shared_ptr variable // Ask the provider for each data on the dateTimeListNotInCache impl->m_VariableToProviderMap.at(variable)->requestDataLoading( std::move(dateTimeListNotInCache)); - // store in cache - impl->m_VariableCacheController->addDateTime(variable, dateTime); } else { emit variable->updated(); diff --git a/core/src/Variable/VariableModel.cpp b/core/src/Variable/VariableModel.cpp index f03350b..9d6c6f1 100644 --- a/core/src/Variable/VariableModel.cpp +++ b/core/src/Variable/VariableModel.cpp @@ -52,9 +52,8 @@ VariableModel::VariableModel(QObject *parent) { } -std::shared_ptr -VariableModel::createVariable(const QString &name, const SqpDateTime &dateTime, - std::shared_ptr defaultDataSeries) noexcept +std::shared_ptr VariableModel::createVariable(const QString &name, + const SqpDateTime &dateTime) noexcept { auto insertIndex = rowCount(); beginInsertRows({}, insertIndex, insertIndex); @@ -62,7 +61,6 @@ VariableModel::createVariable(const QString &name, const SqpDateTime &dateTime, /// @todo For the moment, the other data of the variable is initialized with default values auto variable = std::make_shared(name, QStringLiteral("unit"), QStringLiteral("mission"), dateTime); - variable->setDataSeries(std::move(defaultDataSeries)); impl->m_Variables.push_back(variable); diff --git a/gui/src/Visualization/VisualizationGraphHelper.cpp b/gui/src/Visualization/VisualizationGraphHelper.cpp index 0d094f7..b80cb8f 100644 --- a/gui/src/Visualization/VisualizationGraphHelper.cpp +++ b/gui/src/Visualization/VisualizationGraphHelper.cpp @@ -42,7 +42,6 @@ void updateScalarData(QCPAbstractPlottable *component, ScalarSeries &scalarSerie const auto &valuesData = scalarSeries.valuesData()->data(); const auto count = xData.count(); qCInfo(LOG_VisualizationGraphHelper()) << "TORM: Current points in cache" << xData.count(); - auto xValue = QVector(count); auto vValue = QVector(count); @@ -65,7 +64,6 @@ void updateScalarData(QCPAbstractPlottable *component, ScalarSeries &scalarSerie qcpGraph->setData(xValue, vValue); // Display all data - // component->parentPlot()->xAxis->setRange(dateTime.m_TStart, dateTime.m_TEnd); component->rescaleAxes(); component->parentPlot()->replot(); } diff --git a/gui/src/Visualization/VisualizationGraphWidget.cpp b/gui/src/Visualization/VisualizationGraphWidget.cpp index c8f4ce9..2c37585 100644 --- a/gui/src/Visualization/VisualizationGraphWidget.cpp +++ b/gui/src/Visualization/VisualizationGraphWidget.cpp @@ -177,9 +177,10 @@ void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1) if (!variable->contains(dateTime)) { auto variableDateTimeWithTolerance = dateTime; - if (variable->intersect(dateTime)) { + if (!variable->isInside(dateTime)) { auto variableDateTime = variable->dateTime(); if (variableDateTime.m_TStart < dateTime.m_TStart) { + qCDebug(LOG_VisualizationGraphWidget()) << tr("TDetection pan to right:"); auto diffEndToKeepDelta = dateTime.m_TEnd - variableDateTime.m_TEnd; dateTime.m_TStart = variableDateTime.m_TStart + diffEndToKeepDelta; @@ -188,7 +189,8 @@ void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1) auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart); variableDateTimeWithTolerance.m_TEnd += tolerance; } - if (variableDateTime.m_TEnd > dateTime.m_TEnd) { + else if (variableDateTime.m_TEnd > dateTime.m_TEnd) { + qCDebug(LOG_VisualizationGraphWidget()) << tr("Detection pan to left: "); auto diffStartToKeepDelta = variableDateTime.m_TStart - dateTime.m_TStart; dateTime.m_TEnd = variableDateTime.m_TEnd - diffStartToKeepDelta; // Tolerance have to be added to the left @@ -196,8 +198,13 @@ void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1) auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart); variableDateTimeWithTolerance.m_TStart -= tolerance; } + else { + qCWarning(LOG_VisualizationGraphWidget()) + << tr("Detection anormal zoom detection: "); + } } else { + qCDebug(LOG_VisualizationGraphWidget()) << tr("Detection zoom out: "); // add 10% tolerance for each side auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart); variableDateTimeWithTolerance.m_TStart -= tolerance; @@ -208,6 +215,9 @@ void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1) // CHangement detected, we need to ask controller to request data loading emit requestDataLoading(variable, variableDateTimeWithTolerance); } + else { + qCDebug(LOG_VisualizationGraphWidget()) << tr("Detection zoom in: "); + } } }