mirror of
https://codeberg.org/comaps/comaps
synced 2026-01-06 04:24:29 +00:00
[routing] Add possibility to save routes as tracks
Signed-off-by: cyber-toad <the.cyber.toad@proton.me>
This commit is contained in:
committed by
Konstantin Pastbin
parent
9e8accc8f5
commit
45bba5fb5e
@@ -1170,6 +1170,51 @@ dp::Color BookmarkManager::GenerateTrackRecordingColor() const
|
||||
return kml::ColorFromPredefinedColor(kml::GetRandomPredefinedColor());
|
||||
}
|
||||
|
||||
std::string BookmarkManager::GenerateSavedRouteName(std::string const & from, std::string const & to)
|
||||
{
|
||||
if (!from.empty() && !to.empty())
|
||||
return from + " - " + to;
|
||||
if (!from.empty())
|
||||
return from;
|
||||
if (!to.empty())
|
||||
return to;
|
||||
return GenerateTrackRecordingName();
|
||||
}
|
||||
|
||||
kml::TrackId BookmarkManager::SaveRoute(std::vector<m2::PointD> const & points, std::string const & from, std::string const & to)
|
||||
{
|
||||
kml::MultiGeometry geometry;
|
||||
geometry.m_lines.emplace_back();
|
||||
geometry.m_timestamps.emplace_back();
|
||||
auto & line = geometry.m_lines.back();
|
||||
|
||||
for (auto const & pt : points)
|
||||
line.emplace_back(pt);
|
||||
|
||||
kml::TrackData trackData;
|
||||
trackData.m_geometry = std::move(geometry);
|
||||
|
||||
auto trackName = GenerateSavedRouteName(from, to);
|
||||
kml::SetDefaultStr(trackData.m_name, trackName);
|
||||
|
||||
kml::ColorData colorData;
|
||||
colorData.m_rgba = GenerateTrackRecordingColor().GetRGBA();
|
||||
kml::TrackLayer layer;
|
||||
layer.m_color = colorData;
|
||||
std::vector<kml::TrackLayer> m_layers;
|
||||
m_layers.emplace_back(layer);
|
||||
trackData.m_layers = std::move(m_layers);
|
||||
|
||||
trackData.m_timestamp = kml::TimestampClock::now();
|
||||
|
||||
auto editSession = GetEditSession();
|
||||
auto const track = editSession.CreateTrack(std::move(trackData));
|
||||
auto const groupId = LastEditedBMCategory();
|
||||
auto const trackId = track->GetId();
|
||||
AttachTrack(trackId, groupId);
|
||||
return trackId;
|
||||
}
|
||||
|
||||
void BookmarkManager::PrepareBookmarksAddresses(std::vector<SortBookmarkData> & bookmarksForSort,
|
||||
AddressesCollection & newAddresses)
|
||||
{
|
||||
|
||||
@@ -29,7 +29,6 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace storage
|
||||
{
|
||||
class CountryInfoGetter;
|
||||
@@ -436,6 +435,8 @@ public:
|
||||
std::string GenerateTrackRecordingName() const;
|
||||
dp::Color GenerateTrackRecordingColor() const;
|
||||
|
||||
kml::TrackId SaveRoute(std::vector<m2::PointD> const & points, std::string const & from, std::string const & to);
|
||||
|
||||
private:
|
||||
class MarksChangesTracker : public df::UserMarksProvider
|
||||
{
|
||||
@@ -624,6 +625,7 @@ private:
|
||||
void CleanupInvalidMetadata();
|
||||
std::string GetMetadataEntryName(kml::MarkGroupId groupId) const;
|
||||
|
||||
std::string GenerateSavedRouteName(std::string const & from, std::string const & to);
|
||||
void NotifyAboutStartAsyncLoading();
|
||||
void NotifyAboutFinishAsyncLoading(KMLDataCollectionPtr && collection);
|
||||
void NotifyAboutFile(bool success, std::string const & filePath, bool isTemporaryFile);
|
||||
|
||||
@@ -1773,6 +1773,11 @@ bool Framework::IsTrackRecordingEnabled() const
|
||||
return GpsTracker::Instance().IsEnabled();
|
||||
}
|
||||
|
||||
void Framework::SaveRoute()
|
||||
{
|
||||
m_routingManager.SaveRoute();
|
||||
}
|
||||
|
||||
void Framework::OnUpdateGpsTrackPointsCallback(vector<pair<size_t, location::GpsInfo>> && toAdd,
|
||||
pair<size_t, size_t> const & toRemove,
|
||||
TrackStatistics const & trackStatistics)
|
||||
|
||||
@@ -444,6 +444,8 @@ public:
|
||||
void SaveTrackRecordingWithName(std::string const & name);
|
||||
bool IsTrackRecordingEmpty() const;
|
||||
bool IsTrackRecordingEnabled() const;
|
||||
|
||||
void SaveRoute();
|
||||
/// 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();
|
||||
|
||||
@@ -1639,4 +1639,18 @@ UNIT_CLASS_TEST(Runner, Bookmarks_RecentlyDeleted)
|
||||
TEST(!Platform::IsFileExistsByFullPath(filePath), ());
|
||||
TEST(!Platform::IsFileExistsByFullPath(deletedFilePath), ());
|
||||
}
|
||||
|
||||
UNIT_CLASS_TEST(Runner, Bookmarks_TestSaveRoute)
|
||||
{
|
||||
BookmarkManager bmManager(BM_CALLBACKS);
|
||||
bmManager.EnableTestMode(true);
|
||||
auto const points = {m2::PointD(0.0, 0.0), m2::PointD(0.001, 0.001)};
|
||||
auto const trackId = bmManager.SaveRoute(points, "London", "Paris");
|
||||
auto const * track = bmManager.GetTrack(trackId);
|
||||
TEST_EQUAL(track->GetName(), "London - Paris", ());
|
||||
auto const line = track->GetData().m_geometry.m_lines[0];
|
||||
std::vector const expectedLine = {{geometry::PointWithAltitude(m2::PointD(0.0, 0.0)), geometry::PointWithAltitude(m2::PointD(0.001, 0.001))}};
|
||||
TEST_EQUAL(line, expectedLine, ());
|
||||
}
|
||||
|
||||
} // namespace bookmarks_test
|
||||
|
||||
@@ -1091,6 +1091,27 @@ void RoutingManager::SetUserCurrentPosition(m2::PointD const & position)
|
||||
}
|
||||
}
|
||||
|
||||
static std::string GetNameFromPoint(RouteMarkData const & rmd)
|
||||
{
|
||||
if (rmd.m_subTitle.empty())
|
||||
return "";
|
||||
return rmd.m_title;
|
||||
}
|
||||
|
||||
void RoutingManager::SaveRoute()
|
||||
{
|
||||
auto points = GetRoutePolyline().GetPolyline().GetPoints();
|
||||
auto const routePoints = GetRoutePoints();
|
||||
std::string const from = GetNameFromPoint(routePoints.front());
|
||||
std::string const to = GetNameFromPoint(routePoints.back());
|
||||
// remove equal sequential points
|
||||
points.erase(
|
||||
std::unique(points.begin(), points.end(), [](const m2::PointD & p1, const m2::PointD & p2) { return AlmostEqualAbs(p1, p2, kMwmPointAccuracy); }),
|
||||
points.end());
|
||||
|
||||
m_bmManager->SaveRoute(points, from, to);
|
||||
}
|
||||
|
||||
bool RoutingManager::DisableFollowMode()
|
||||
{
|
||||
bool const disabled = m_routingSession.DisableFollowMode();
|
||||
|
||||
@@ -142,6 +142,7 @@ public:
|
||||
// This method was added because we do not want to break the behaviour that is familiar to our
|
||||
// users.
|
||||
bool DisableFollowMode();
|
||||
void SaveRoute();
|
||||
|
||||
void SetRouteBuildingListener(RouteBuildingCallback const & buildingCallback)
|
||||
{
|
||||
@@ -204,7 +205,7 @@ public:
|
||||
return m_routingSession.GetTurnNotificationsLocale();
|
||||
}
|
||||
// @return polyline of the route.
|
||||
routing::FollowedPolyline const & GetRoutePolylineForTests() const
|
||||
routing::FollowedPolyline const & GetRoutePolyline() const
|
||||
{
|
||||
return m_routingSession.GetRouteForTests()->GetFollowedPolyline();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user