From 266be01d8f5645a25de43e3fc1593bd8728dd2c2 Mon Sep 17 00:00:00 2001 From: Dan Paulat Date: Mon, 22 May 2023 22:46:48 -0500 Subject: [PATCH] Timeline manager time selection --- .../scwx/qt/manager/timeline_manager.cpp | 42 +++++++++++++++++-- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/scwx-qt/source/scwx/qt/manager/timeline_manager.cpp b/scwx-qt/source/scwx/qt/manager/timeline_manager.cpp index b3d2e94e..cb4df207 100644 --- a/scwx-qt/source/scwx/qt/manager/timeline_manager.cpp +++ b/scwx-qt/source/scwx/qt/manager/timeline_manager.cpp @@ -1,8 +1,12 @@ #include +#include #include +#include #include #include +#include + #include namespace scwx @@ -28,10 +32,13 @@ public: std::string radarSite_ {"?"}; std::chrono::system_clock::time_point pinnedTime_ {}; - std::chrono::system_clock::time_point currentTime_ {}; + std::chrono::system_clock::time_point currentAdjustedTime_ {}; + std::chrono::system_clock::time_point currentSelectedTime_ {}; types::MapTime viewType_ {types::MapTime::Live}; std::chrono::minutes loopTime_ {30}; double loopSpeed_ {1.0}; + + std::mutex selectTimeMutex_ {}; }; TimelineManager::TimelineManager() : p(std::make_unique(this)) {} @@ -123,13 +130,42 @@ void TimelineManager::AnimationStepEnd() void TimelineManager::Impl::SelectTime( std::chrono::system_clock::time_point selectedTime) { - if (currentTime_ == selectedTime) + if (currentSelectedTime_ == selectedTime) { // Nothing to do return; } - currentTime_ = selectedTime; + scwx::util::async( + [=, this]() + { + // Take a lock for time selection + std::unique_lock lock {selectTimeMutex_}; + + // Request active volume times + auto radarProductManager = + manager::RadarProductManager::Instance(radarSite_); + auto volumeTimes = + radarProductManager->GetActiveVolumeTimes(selectedTime); + + // Find the best match bounded time + auto elementPtr = + util::GetBoundedElementPointer(volumeTimes, selectedTime); + + if (elementPtr != nullptr) + { + // If the time was found, select it + currentAdjustedTime_ = *elementPtr; + currentSelectedTime_ = selectedTime; + + emit self_->TimeUpdated(currentAdjustedTime_); + } + else + { + // No volume time was found + logger_->info("No volume scan found for {}", selectedTime); + } + }); } std::shared_ptr TimelineManager::Instance()