Timeline step next

This commit is contained in:
Dan Paulat 2023-05-26 16:32:21 -05:00
parent 0ddd9d91ea
commit 5f97718469

View file

@ -19,6 +19,12 @@ namespace manager
static const std::string logPrefix_ = "scwx::qt::manager::timeline_manager"; static const std::string logPrefix_ = "scwx::qt::manager::timeline_manager";
static const auto logger_ = scwx::util::Logger::Create(logPrefix_); static const auto logger_ = scwx::util::Logger::Create(logPrefix_);
enum class Direction
{
Back,
Next
};
class TimelineManager::Impl class TimelineManager::Impl
{ {
public: public:
@ -33,7 +39,7 @@ public:
TimelineManager* self_; TimelineManager* self_;
void SelectTime(std::chrono::system_clock::time_point selectedTime = {}); void SelectTime(std::chrono::system_clock::time_point selectedTime = {});
void StepBack(); void Step(Direction direction);
std::string radarSite_ {"?"}; std::string radarSite_ {"?"};
std::string previousRadarSite_ {"?"}; std::string previousRadarSite_ {"?"};
@ -131,7 +137,7 @@ void TimelineManager::AnimationStepBack()
{ {
logger_->debug("AnimationStepBack"); logger_->debug("AnimationStepBack");
p->StepBack(); p->Step(Direction::Back);
} }
void TimelineManager::AnimationPlay() void TimelineManager::AnimationPlay()
@ -147,6 +153,8 @@ void TimelineManager::AnimationPause()
void TimelineManager::AnimationStepNext() void TimelineManager::AnimationStepNext()
{ {
logger_->debug("AnimationStepNext"); logger_->debug("AnimationStepNext");
p->Step(Direction::Next);
} }
void TimelineManager::AnimationStepEnd() void TimelineManager::AnimationStepEnd()
@ -226,10 +234,10 @@ void TimelineManager::Impl::SelectTime(
}); });
} }
void TimelineManager::Impl::StepBack() void TimelineManager::Impl::Step(Direction direction)
{ {
scwx::util::async( scwx::util::async(
[this]() [=, this]()
{ {
// Take a lock for time selection // Take a lock for time selection
std::unique_lock lock {selectTimeMutex_}; std::unique_lock lock {selectTimeMutex_};
@ -247,16 +255,18 @@ void TimelineManager::Impl::StepBack()
auto volumeTimes = auto volumeTimes =
radarProductManager->GetActiveVolumeTimes(queryTime); radarProductManager->GetActiveVolumeTimes(queryTime);
if (volumeTimes.empty())
{
logger_->debug("No products to step through");
return;
}
std::set<std::chrono::system_clock::time_point>::const_iterator it; std::set<std::chrono::system_clock::time_point>::const_iterator it;
if (adjustedTime_ == std::chrono::system_clock::time_point {}) if (adjustedTime_ == std::chrono::system_clock::time_point {})
{ {
// If the adjusted time is live, get the last element in the set // If the adjusted time is live, get the last element in the set
it = volumeTimes.cend(); it = std::prev(volumeTimes.cend());
if (!volumeTimes.empty())
{
--it;
}
} }
else else
{ {
@ -265,6 +275,8 @@ void TimelineManager::Impl::StepBack()
adjustedTime_); adjustedTime_);
} }
if (direction == Direction::Back)
{
// Only if we aren't at the beginning of the volume times set // Only if we aren't at the beginning of the volume times set
if (it != volumeTimes.cbegin()) if (it != volumeTimes.cbegin())
{ {
@ -276,6 +288,24 @@ void TimelineManager::Impl::StepBack()
scwx::util::TimeString(adjustedTime_)); scwx::util::TimeString(adjustedTime_));
emit self_->VolumeTimeUpdated(adjustedTime_); emit self_->VolumeTimeUpdated(adjustedTime_);
emit self_->SelectedTimeUpdated(adjustedTime_);
}
}
else
{
// Only if we aren't at the end of the volume times set
if (it != std::prev(volumeTimes.cend()))
{
// Select the next time
adjustedTime_ = *(++it);
selectedTime_ = adjustedTime_;
logger_->debug("Volume time updated: {}",
scwx::util::TimeString(adjustedTime_));
emit self_->VolumeTimeUpdated(adjustedTime_);
emit self_->SelectedTimeUpdated(adjustedTime_);
}
} }
}); });
} }