diff --git a/map/framework.cpp b/map/framework.cpp index 329b6d04d7..f96a8f253c 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -1739,6 +1739,11 @@ void Framework::SetTrackRecordingUpdateHandler(TrackRecordingUpdateHandler && tr m_trackRecordingUpdateHandler(GpsTracker::Instance().GetTrackStatistics()); } +const ElevationInfo & Framework::GetTrackRecordingElevationInfo() +{ + return GpsTracker::Instance().GetElevationInfo(); +} + void Framework::StopTrackRecording() { m_connectToGpsTrack = false; diff --git a/map/framework.hpp b/map/framework.hpp index 16dd6a0217..51ad421cc0 100644 --- a/map/framework.hpp +++ b/map/framework.hpp @@ -444,6 +444,9 @@ public: void SaveTrackRecordingWithName(std::string const & name); bool IsTrackRecordingEmpty() const; bool IsTrackRecordingEnabled() const; + /// Returns the elevation profile data of the currently recorded track. + /// To get the data on the every track recording state update, this function should be called after receiving the callback from the `SetTrackRecordingUpdateHandler`. + static const ElevationInfo & GetTrackRecordingElevationInfo(); void SetMapStyle(MapStyle mapStyle); void MarkMapStyle(MapStyle mapStyle); diff --git a/map/gps_track.cpp b/map/gps_track.cpp index 9392263d69..a1dbb26cd2 100644 --- a/map/gps_track.cpp +++ b/map/gps_track.cpp @@ -84,6 +84,11 @@ TrackStatistics GpsTrack::GetTrackStatistics() const return m_collection ? m_collection->GetTrackStatistics() : TrackStatistics(); } +const ElevationInfo & GpsTrack::GetElevationInfo() const +{ + return m_collection->UpdateAndGetElevationInfo(); +} + void GpsTrack::Clear() { { diff --git a/map/gps_track.hpp b/map/gps_track.hpp index 494ab7c0fa..0c0bf197ca 100644 --- a/map/gps_track.hpp +++ b/map/gps_track.hpp @@ -32,7 +32,8 @@ public: /// Returns track statistics TrackStatistics GetTrackStatistics() const; - + const ElevationInfo & GetElevationInfo() const; + /// Clears any previous tracking info /// @note Callback is called with 'toRemove' points, if some points were removed. void Clear(); diff --git a/map/gps_track_collection.cpp b/map/gps_track_collection.cpp index a49d4c3caa..147ad052b7 100644 --- a/map/gps_track_collection.cpp +++ b/map/gps_track_collection.cpp @@ -33,6 +33,7 @@ size_t const GpsTrackCollection::kInvalidId = std::numeric_limits::max() GpsTrackCollection::GpsTrackCollection() : m_lastId(0) + , m_elevationInfoDirty(true) {} std::pair GpsTrackCollection::Add(std::vector const & items) @@ -54,6 +55,8 @@ std::pair GpsTrackCollection::Add(std::vector const & ite ++added; } + m_elevationInfoDirty = true; + rollbacker.Reset(); if (0 == added) @@ -85,6 +88,7 @@ std::pair GpsTrackCollection::Clear(bool resetIds) m_items.clear(); m_items.shrink_to_fit(); m_statistics = {}; + m_elevationInfo = {}; if (resetIds) m_lastId = 0; @@ -97,6 +101,21 @@ size_t GpsTrackCollection::GetSize() const return m_items.size(); } +const ElevationInfo & GpsTrackCollection::UpdateAndGetElevationInfo() +{ + if (!m_elevationInfoDirty) + return m_elevationInfo; + + auto const elevationInfoSize = m_elevationInfo.GetSize(); + if (elevationInfoSize < m_items.size()) + { + std::vector const missedPoints(m_items.begin() + elevationInfoSize, m_items.end()); + m_elevationInfo.AddGpsPoints(missedPoints); + } + m_elevationInfoDirty = false; + return m_elevationInfo; +} + bool GpsTrackCollection::IsEmpty() const { return m_items.empty(); diff --git a/map/gps_track_collection.hpp b/map/gps_track_collection.hpp index f1e91dc87f..49cfd1c54e 100644 --- a/map/gps_track_collection.hpp +++ b/map/gps_track_collection.hpp @@ -41,6 +41,8 @@ public: /// Returns track statistics. const TrackStatistics GetTrackStatistics() const { return m_statistics; } + /// Updates the elevation info with the missed points and returns a reference. + const ElevationInfo & UpdateAndGetElevationInfo(); /// Enumerates items in the collection. /// @param f - callable object, which is called with params - item and item id, @@ -67,4 +69,6 @@ private: size_t m_lastId; TrackStatistics m_statistics; + ElevationInfo m_elevationInfo; + bool m_elevationInfoDirty; }; diff --git a/map/gps_tracker.cpp b/map/gps_tracker.cpp index 9fa961adf4..583e65d9af 100644 --- a/map/gps_tracker.cpp +++ b/map/gps_tracker.cpp @@ -85,6 +85,11 @@ TrackStatistics GpsTracker::GetTrackStatistics() const return m_track.GetTrackStatistics(); } +const ElevationInfo & GpsTracker::GetElevationInfo() const +{ + return m_track.GetElevationInfo(); +} + void GpsTracker::Connect(TGpsTrackDiffCallback const & fn) { m_track.SetCallback(fn); diff --git a/map/gps_tracker.hpp b/map/gps_tracker.hpp index 6840ec0c63..8ec07a6848 100644 --- a/map/gps_tracker.hpp +++ b/map/gps_tracker.hpp @@ -19,6 +19,7 @@ public: bool IsEmpty() const; size_t GetTrackSize() const; TrackStatistics GetTrackStatistics() const; + const ElevationInfo & GetElevationInfo() const; using TGpsTrackDiffCallback = std::function> && toAdd,