diff --git a/scwx-qt/source/scwx/qt/map/alert_layer.cpp b/scwx-qt/source/scwx/qt/map/alert_layer.cpp index 15fc4af0..1cd5ff5f 100644 --- a/scwx-qt/source/scwx/qt/map/alert_layer.cpp +++ b/scwx-qt/source/scwx/qt/map/alert_layer.cpp @@ -125,7 +125,12 @@ public: ConnectSignals(); } - ~Impl() { receiver_ = nullptr; }; + ~Impl() + { + receiver_ = nullptr; + + std::unique_lock lock(linesMutex_); + }; void AddAlert( const std::shared_ptr& segmentRecord); @@ -148,7 +153,8 @@ public: float width, std::chrono::system_clock::time_point startTime, std::chrono::system_clock::time_point endTime, - std::vector>& drawItems); + boost::container::stable_vector< + std::shared_ptr>& drawItems); const awips::Phenomenon phenomenon_; @@ -156,6 +162,12 @@ public: std::unordered_map> geoLines_; + std::unordered_map, + boost::container::stable_vector< + std::shared_ptr>> + linesBySegment_ {}; + std::mutex linesMutex_ {}; + std::unordered_map lineColor_; std::chrono::system_clock::time_point selectedTime_ {}; @@ -316,6 +328,18 @@ void AlertLayer::Impl::ConnectSignals() AddAlert(segmentRecord); } }); + QObject::connect( + &AlertLayerHandler::Instance(), + &AlertLayerHandler::AlertUpdated, + receiver_.get(), + [this]( + const std::shared_ptr& segmentRecord) + { + if (segmentRecord->key_.phenomenon_ == phenomenon_) + { + UpdateAlert(segmentRecord); + } + }); QObject::connect(timelineManager.get(), &manager::TimelineManager::SelectedTimeUpdated, @@ -340,7 +364,11 @@ void AlertLayer::Impl::AddAlert( const auto& coordinates = segment->codedLocation_->coordinates(); - std::vector> drawItems {}; + // Take a mutex before modifying lines by segment + std::unique_lock lock {linesMutex_}; + + boost::container::stable_vector>& + drawItems = linesBySegment_[segmentRecord]; AddLines( geoLines, coordinates, kBlack_, 5.0f, startTime, endTime, drawItems); @@ -349,10 +377,29 @@ void AlertLayer::Impl::AddAlert( } void AlertLayer::Impl::UpdateAlert( - [[maybe_unused]] const std::shared_ptr& - segmentRecord) + const std::shared_ptr& segmentRecord) { - // TODO + // Take a mutex before referencing lines iterators and stable vector + std::unique_lock lock {linesMutex_}; + + auto it = linesBySegment_.find(segmentRecord); + if (it != linesBySegment_.cend()) + { + auto& segment = segmentRecord->segment_; + + auto& vtec = segment->header_->vtecString_.front(); + auto action = vtec.pVtec_.action(); + bool alertActive = (action != awips::PVtec::Action::Canceled); + + auto& geoLines = geoLines_.at(alertActive); + + auto& lines = it->second; + for (auto& line : lines) + { + geoLines->SetLineStartTime(line, segmentRecord->segmentBegin_); + geoLines->SetLineEndTime(line, segmentRecord->segmentEnd_); + } + } } void AlertLayer::Impl::AddLines(