diff --git a/core/src/Variable/VariableAcquisitionWorker.cpp b/core/src/Variable/VariableAcquisitionWorker.cpp index e84ab16..3d10846 100644 --- a/core/src/Variable/VariableAcquisitionWorker.cpp +++ b/core/src/Variable/VariableAcquisitionWorker.cpp @@ -142,7 +142,7 @@ void VariableAcquisitionWorker::onVariableDataAcquired(QUuid acqIdentifier, if (it != impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) { if (it->second.second.isNull()) { - // There is no next request, we can remove the varibale request + // There is no next request, we can remove the variable request impl->removeVariableRequest(acqRequest.m_vIdentifier); } else { diff --git a/core/src/Variable/VariableController.cpp b/core/src/Variable/VariableController.cpp index b2703f8..a7a67df 100644 --- a/core/src/Variable/VariableController.cpp +++ b/core/src/Variable/VariableController.cpp @@ -23,36 +23,36 @@ Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController") namespace { -SqpRange computeSynchroRangeRequested(const SqpRange &varRange, const SqpRange &grapheRange, +SqpRange computeSynchroRangeRequested(const SqpRange &varRange, const SqpRange &graphRange, const SqpRange &oldGraphRange) { - auto zoomType = VariableController::getZoomType(grapheRange, oldGraphRange); + auto zoomType = VariableController::getZoomType(graphRange, oldGraphRange); auto varRangeRequested = varRange; switch (zoomType) { case AcquisitionZoomType::ZoomIn: { - auto deltaLeft = grapheRange.m_TStart - oldGraphRange.m_TStart; - auto deltaRight = oldGraphRange.m_TEnd - grapheRange.m_TEnd; + auto deltaLeft = graphRange.m_TStart - oldGraphRange.m_TStart; + auto deltaRight = oldGraphRange.m_TEnd - graphRange.m_TEnd; varRangeRequested.m_TStart += deltaLeft; varRangeRequested.m_TEnd -= deltaRight; break; } case AcquisitionZoomType::ZoomOut: { - auto deltaLeft = oldGraphRange.m_TStart - grapheRange.m_TStart; - auto deltaRight = grapheRange.m_TEnd - oldGraphRange.m_TEnd; + auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart; + auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd; varRangeRequested.m_TStart -= deltaLeft; varRangeRequested.m_TEnd += deltaRight; break; } case AcquisitionZoomType::PanRight: { - auto deltaRight = grapheRange.m_TEnd - oldGraphRange.m_TEnd; + auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd; varRangeRequested.m_TStart += deltaRight; varRangeRequested.m_TEnd += deltaRight; break; } case AcquisitionZoomType::PanLeft: { - auto deltaLeft = oldGraphRange.m_TStart - grapheRange.m_TStart; + auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart; varRangeRequested.m_TStart -= deltaLeft; varRangeRequested.m_TEnd -= deltaLeft; break; @@ -263,8 +263,7 @@ void VariableController::onDataProvided(QUuid vIdentifier, const SqpRange &range const SqpRange &cacheRangeRequested, QVector dataAcquired) { - auto var = impl->findVariable(vIdentifier); - if (var != nullptr) { + if (auto var = impl->findVariable(vIdentifier)) { var->setRange(rangeRequested); var->setCacheRange(cacheRangeRequested); qCDebug(LOG_VariableController()) << tr("1: onDataProvided") << rangeRequested; @@ -284,8 +283,7 @@ void VariableController::onDataProvided(QUuid vIdentifier, const SqpRange &range void VariableController::onVariableRetrieveDataInProgress(QUuid identifier, double progress) { - auto var = impl->findVariable(identifier); - if (var != nullptr) { + if (auto var = impl->findVariable(identifier)) { impl->m_VariableModel->setDataProgress(var, progress); } else { @@ -331,14 +329,14 @@ void VariableController::onAddSynchronized(std::shared_ptr variable, { qCDebug(LOG_VariableController()) << "TORM: VariableController::onAddSynchronized" << synchronizationGroupId; - auto vToVIdit = impl->m_VariableToIdentifierMap.find(variable); - if (vToVIdit != impl->m_VariableToIdentifierMap.cend()) { - auto itSynchroGroup + auto varToVarIdIt = impl->m_VariableToIdentifierMap.find(variable); + if (varToVarIdIt != impl->m_VariableToIdentifierMap.cend()) { + auto groupIdToVSGIt = impl->m_GroupIdToVariableSynchronizationGroupMap.find(synchronizationGroupId); - if (itSynchroGroup != impl->m_GroupIdToVariableSynchronizationGroupMap.cend()) { + if (groupIdToVSGIt != impl->m_GroupIdToVariableSynchronizationGroupMap.cend()) { impl->m_VariableIdGroupIdMap.insert( - std::make_pair(vToVIdit->second, synchronizationGroupId)); - itSynchroGroup->second->addVariableId(vToVIdit->second); + std::make_pair(varToVarIdIt->second, synchronizationGroupId)); + groupIdToVSGIt->second->addVariableId(varToVarIdIt->second); } else { qCCritical(LOG_VariableController()) @@ -359,13 +357,13 @@ void VariableController::onRequestDataLoading(QVector { // NOTE: oldRange isn't really necessary since oldRange == variable->range(). - qCInfo(LOG_VariableController()) << "VariableController::onRequestDataLoading" - << QThread::currentThread()->objectName(); + qCDebug(LOG_VariableController()) << "VariableController::onRequestDataLoading" + << QThread::currentThread()->objectName(); // we want to load data of the variable for the dateTime. // First we check if the cache contains some of them. // For the other, we ask the provider to give them. - foreach (auto var, variables) { + for (const auto &var : variables) { qCDebug(LOG_VariableController()) << "processRequest for" << var->name(); impl->processRequest(var, range); } @@ -373,9 +371,9 @@ void VariableController::onRequestDataLoading(QVector if (synchronise) { // Get the group ids qCDebug(LOG_VariableController()) - << "VariableController::onRequestDataLoading for synchro var ENABLE"; + << "TORM VariableController::onRequestDataLoading for synchro var ENABLE"; auto groupIds = std::set(); - foreach (auto var, variables) { + for (const auto &var : variables) { auto varToVarIdIt = impl->m_VariableToIdentifierMap.find(var); if (varToVarIdIt != impl->m_VariableToIdentifierMap.cend()) { auto vId = varToVarIdIt->second; @@ -391,7 +389,7 @@ void VariableController::onRequestDataLoading(QVector } // We assume here all group ids exist - foreach (auto gId, groupIds) { + for (const auto &gId : groupIds) { auto vSynchronizationGroup = impl->m_GroupIdToVariableSynchronizationGroupMap.at(gId); auto vSyncIds = vSynchronizationGroup->getIds(); qCDebug(LOG_VariableController()) << "Var in synchro group "; diff --git a/gui/include/Visualization/VisualizationGraphHelper.h b/gui/include/Visualization/VisualizationGraphHelper.h index c0d4b3d..b721858 100644 --- a/gui/include/Visualization/VisualizationGraphHelper.h +++ b/gui/include/Visualization/VisualizationGraphHelper.h @@ -30,6 +30,8 @@ struct VisualizationGraphHelper { */ static QVector create(std::shared_ptr variable, QCustomPlot &plot) noexcept; + static QVector createV2(std::shared_ptr variable, + QCustomPlot &plot) noexcept; static void updateData(QVector plotableVect, std::shared_ptr dataSeries, const SqpRange &dateTime); diff --git a/gui/include/Visualization/VisualizationGraphWidget.h b/gui/include/Visualization/VisualizationGraphWidget.h index a39d5fd..d9a03ac 100644 --- a/gui/include/Visualization/VisualizationGraphWidget.h +++ b/gui/include/Visualization/VisualizationGraphWidget.h @@ -30,12 +30,13 @@ public: /// If acquisition isn't enable, requestDataLoading signal cannot be emit void enableAcquisition(bool enable); - void addVariable(std::shared_ptr variable); - void addVariableUsingGraph(std::shared_ptr variable); + void addVariable(std::shared_ptr variable, SqpRange range); + /// Removes a variable from the graph void removeVariable(std::shared_ptr variable) noexcept; void setRange(std::shared_ptr variable, const SqpRange &range); + void setYRange(const SqpRange &range); SqpRange graphRange() const noexcept; void setGraphRange(const SqpRange &range); diff --git a/gui/src/Visualization/VisualizationGraphHelper.cpp b/gui/src/Visualization/VisualizationGraphHelper.cpp index a67534c..17611c9 100644 --- a/gui/src/Visualization/VisualizationGraphHelper.cpp +++ b/gui/src/Visualization/VisualizationGraphHelper.cpp @@ -79,6 +79,29 @@ void updateScalarData(QCPAbstractPlottable *component, std::shared_ptr scalarSeries, + QCustomPlot &plot) +{ + auto component = plot.addGraph(); + + if (component) { + // Axes properties + /// @todo : for the moment, no control is performed on the axes: the units and the tickers + /// are fixed for the default x-axis and y-axis of the plot, and according to the new graph + + auto setAxisProperties = [](auto axis, const auto &unit) { + // label (unit name) + axis->setLabel(unit.m_Name); + + // ticker (depending on the type of unit) + axis->setTicker(axisTicker(unit.m_TimeUnit)); + }; + setAxisProperties(plot.xAxis, scalarSeries->xAxisUnit()); + setAxisProperties(plot.yAxis, scalarSeries->valuesUnit()); + } + return component; +} + QCPAbstractPlottable *createScalarSeriesComponent(std::shared_ptr scalarSeries, QCustomPlot &plot, const SqpRange &dateTime) { @@ -119,6 +142,30 @@ QCPAbstractPlottable *createScalarSeriesComponent(std::shared_ptr } // namespace +QVector +VisualizationGraphHelper::createV2(std::shared_ptr variable, QCustomPlot &plot) noexcept +{ + auto result = QVector{}; + + if (variable) { + // Gets the data series of the variable to call the creation of the right components + // according to its type + if (auto scalarSeries = std::dynamic_pointer_cast(variable->dataSeries())) { + result.append(createScalarSeriesComponentV2(scalarSeries, plot)); + } + else { + qCDebug(LOG_VisualizationGraphHelper()) + << QObject::tr("Can't create graph plottables : unmanaged data series type"); + } + } + else { + qCDebug(LOG_VisualizationGraphHelper()) + << QObject::tr("Can't create graph plottables : the variable is null"); + } + + return result; +} + QVector VisualizationGraphHelper::create(std::shared_ptr variable, QCustomPlot &plot) noexcept { diff --git a/gui/src/Visualization/VisualizationGraphWidget.cpp b/gui/src/Visualization/VisualizationGraphWidget.cpp index 1ed0384..7d2935f 100644 --- a/gui/src/Visualization/VisualizationGraphWidget.cpp +++ b/gui/src/Visualization/VisualizationGraphWidget.cpp @@ -93,13 +93,10 @@ void VisualizationGraphWidget::enableAcquisition(bool enable) impl->m_DoAcquisition = enable; } -void VisualizationGraphWidget::addVariable(std::shared_ptr variable) +void VisualizationGraphWidget::addVariable(std::shared_ptr variable, SqpRange range) { - 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; + auto createdPlottables = VisualizationGraphHelper::createV2(variable, *ui->widget); for (auto createdPlottable : qAsConst(createdPlottables)) { impl->m_VariableToPlotMultiMap.insert({variable, createdPlottable}); @@ -107,18 +104,16 @@ void VisualizationGraphWidget::addVariable(std::shared_ptr variable) connect(variable.get(), SIGNAL(updated()), this, SLOT(onDataCacheVariableUpdated())); - emit variableAdded(variable); -} -void VisualizationGraphWidget::addVariableUsingGraph(std::shared_ptr variable) -{ - // Uses delegate to create the qcpplot components according to the variable - this->addVariable(variable); + auto varRange = variable->range(); - // Request range for the variable - auto graphRange = ui->widget->xAxis->range(); + this->enableAcquisition(false); + this->setGraphRange(range); + this->enableAcquisition(true); + + emit requestDataLoading(QVector >() << variable, range, varRange, + false); - emit requestDataLoading(QVector >() << variable, - SqpRange{graphRange.lower, graphRange.upper}, variable->range(), false); + emit variableAdded(variable); } void VisualizationGraphWidget::removeVariable(std::shared_ptr variable) noexcept @@ -147,10 +142,15 @@ void VisualizationGraphWidget::setRange(std::shared_ptr variable, cons ui->widget->replot(); } +void VisualizationGraphWidget::setYRange(const SqpRange &range) +{ + ui->widget->yAxis->setRange(range.m_TStart, range.m_TEnd); +} + SqpRange VisualizationGraphWidget::graphRange() const noexcept { - auto grapheRange = ui->widget->xAxis->range(); - return SqpRange{grapheRange.lower, grapheRange.upper}; + auto graphRange = ui->widget->xAxis->range(); + return SqpRange{graphRange.lower, graphRange.upper}; } void VisualizationGraphWidget::setGraphRange(const SqpRange &range) @@ -288,8 +288,8 @@ void VisualizationGraphWidget::onDataCacheVariableUpdated() // - use an ordered_multimap and the algos of std to group the values by key // - use a map (unique keys) and store as values directly the list of components - auto grapheRange = ui->widget->xAxis->range(); - auto dateTime = SqpRange{grapheRange.lower, grapheRange.upper}; + auto graphRange = ui->widget->xAxis->range(); + auto dateTime = SqpRange{graphRange.lower, graphRange.upper}; for (auto it = impl->m_VariableToPlotMultiMap.cbegin(); it != impl->m_VariableToPlotMultiMap.cend(); ++it) { diff --git a/gui/src/Visualization/VisualizationZoneWidget.cpp b/gui/src/Visualization/VisualizationZoneWidget.cpp index 592c9c1..8a5ee5e 100644 --- a/gui/src/Visualization/VisualizationZoneWidget.cpp +++ b/gui/src/Visualization/VisualizationZoneWidget.cpp @@ -6,6 +6,7 @@ #include "ui_VisualizationZoneWidget.h" #include +#include #include #include @@ -81,10 +82,10 @@ VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptrvisualizationZoneFrame->layout(); for (auto i = 0; i < frameLayout->count(); ++i) { auto graphChild @@ -94,8 +95,8 @@ VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptrgraphRange(); switch (zoomType) { case AcquisitionZoomType::ZoomIn: { - auto deltaLeft = grapheRange.m_TStart - oldGraphRange.m_TStart; - auto deltaRight = oldGraphRange.m_TEnd - grapheRange.m_TEnd; + auto deltaLeft = graphRange.m_TStart - oldGraphRange.m_TStart; + auto deltaRight = oldGraphRange.m_TEnd - graphRange.m_TEnd; graphChildRange.m_TStart += deltaLeft; graphChildRange.m_TEnd -= deltaRight; qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: ZoomIn"); @@ -104,37 +105,37 @@ VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptrvisualizationZoneFrame->layout(); + if (layout->count() > 0) { + // Case of a new graph in a existant zone + if (auto visualizationGraphWidget + = dynamic_cast(layout->itemAt(0)->widget())) { + range = visualizationGraphWidget->graphRange(); + } + } + else { + // Case of a new graph as the first of the zone + range = variable->range(); + } + this->addGraph(graphWidget); - graphWidget->addVariable(variable); + graphWidget->addVariable(variable, range); + // TODO: get y using variable range + graphWidget->setYRange(SqpRange{-10, 10}); return graphWidget; } diff --git a/gui/src/Visualization/operations/GenerateVariableMenuOperation.cpp b/gui/src/Visualization/operations/GenerateVariableMenuOperation.cpp index 41592e1..f9f4d37 100644 --- a/gui/src/Visualization/operations/GenerateVariableMenuOperation.cpp +++ b/gui/src/Visualization/operations/GenerateVariableMenuOperation.cpp @@ -155,6 +155,7 @@ void GenerateVariableMenuOperation::visitEnter(VisualizationZoneWidget *zoneWidg void GenerateVariableMenuOperation::visitLeave(VisualizationZoneWidget *zoneWidget) { + qCCritical(LOG_GenerateVariableMenuOperation(), "Open in a new graph DETECTED !!"); if (zoneWidget) { // 'Plot' menu impl->visitNodeLeavePlot( @@ -181,7 +182,7 @@ void GenerateVariableMenuOperation::visit(VisualizationGraphWidget *graphWidget) impl->visitLeafPlot(*graphWidget, QObject::tr("Open in %1").arg(graphWidget->name()), [ varW = std::weak_ptr{impl->m_Variable}, graphWidget ]() { if (auto var = varW.lock()) { - graphWidget->addVariableUsingGraph(var); + graphWidget->addVariable(var, graphWidget->graphRange()); } }); diff --git a/plugins/amda/src/AmdaProvider.cpp b/plugins/amda/src/AmdaProvider.cpp index 9f90d82..baa2b00 100644 --- a/plugins/amda/src/AmdaProvider.cpp +++ b/plugins/amda/src/AmdaProvider.cpp @@ -62,7 +62,9 @@ void AmdaProvider::requestDataLoading(QUuid acqIdentifier, const DataProviderPar const auto data = parameters.m_Data; for (const auto &dateTime : qAsConst(times)) { this->retrieveData(acqIdentifier, dateTime, data); - QThread::msleep(200); + + // TORM + // QThread::msleep(200); } } @@ -92,7 +94,7 @@ void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVa auto endDate = dateFormat(dateTime.m_TEnd); auto url = QUrl{QString{AMDA_URL_FORMAT}.arg(startDate, endDate, productId)}; - qCInfo(LOG_AmdaProvider()) << tr("AmdaProvider::retrieveData url:") << url; + qCInfo(LOG_AmdaProvider()) << tr("TORM AmdaProvider::retrieveData url:") << url; auto tempFile = std::make_shared(); // LAMBDA @@ -128,8 +130,8 @@ void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVa auto downloadFileUrl = QUrl{QString{reply->readAll()}}; - qCInfo(LOG_AmdaProvider()) << tr("AmdaProvider::retrieveData downloadFileUrl:") - << downloadFileUrl; + qCInfo(LOG_AmdaProvider()) + << tr("TORM AmdaProvider::retrieveData downloadFileUrl:") << downloadFileUrl; // Executes request for downloading file // // Creates destination file diff --git a/plugins/mockplugin/src/CosinusProvider.cpp b/plugins/mockplugin/src/CosinusProvider.cpp index ab3b4c0..cbf2073 100644 --- a/plugins/mockplugin/src/CosinusProvider.cpp +++ b/plugins/mockplugin/src/CosinusProvider.cpp @@ -73,7 +73,7 @@ void CosinusProvider::requestDataLoading(QUuid acqIdentifier, { // TODO: Add Mutex m_VariableToEnableProvider[acqIdentifier] = true; - qCDebug(LOG_CosinusProvider()) << "CosinusProvider::requestDataLoading" + qCDebug(LOG_CosinusProvider()) << "TORM: CosinusProvider::requestDataLoading" << QThread::currentThread()->objectName(); // NOTE: Try to use multithread if possible const auto times = parameters.m_Times; @@ -81,7 +81,7 @@ void CosinusProvider::requestDataLoading(QUuid acqIdentifier, for (const auto &dateTime : qAsConst(times)) { if (m_VariableToEnableProvider[acqIdentifier]) { auto scalarSeries = this->retrieveData(acqIdentifier, dateTime); - qCCritical(LOG_CosinusProvider()) << "CosinusProvider::dataProvided"; + qCDebug(LOG_CosinusProvider()) << "TORM: CosinusProvider::dataProvided"; emit dataProvided(acqIdentifier, scalarSeries, dateTime); } }