diff --git a/map/framework.cpp b/map/framework.cpp index f63743f6e5..dc6c25fa10 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -2407,7 +2407,8 @@ void Framework::CheckLocationForRouting(GpsInfo const & info) }; m_routingSession.RebuildRoute(MercatorBounds::FromLatLon(info.m_latitude, info.m_longitude), - readyCallback, m_progressCallback, 0 /* timeoutSec */); + readyCallback, m_progressCallback, 0 /* timeoutSec */, + routing::RoutingSession::State::RouteRebuilding); } } diff --git a/map/framework.hpp b/map/framework.hpp index 5fde90dcb4..4cbaafec60 100644 --- a/map/framework.hpp +++ b/map/framework.hpp @@ -594,8 +594,14 @@ public: bool IsRoutingActive() const { return m_routingSession.IsActive(); } bool IsRouteBuilt() const { return m_routingSession.IsBuilt(); } bool IsRouteBuilding() const { return m_routingSession.IsBuilding(); } + bool IsRouteBuildingOnly() const { return m_routingSession.IsBuildingOnly(); } + bool IsRouteRebuildingOnly() const { return m_routingSession.IsRebuildingOnly(); } + bool IsRouteNotReady() const { return m_routingSession.IsNotReady(); } + bool IsRouteFinished() const { return m_routingSession.IsFinished(); } + bool IsRouteNoFollowing() const { return m_routingSession.IsNoFollowing(); } bool IsOnRoute() const { return m_routingSession.IsOnRoute(); } bool IsRouteNavigable() const { return m_routingSession.IsNavigable(); } + void BuildRoute(m2::PointD const & finish, uint32_t timeoutSec); void BuildRoute(m2::PointD const & start, m2::PointD const & finish, uint32_t timeoutSec); // FollowRoute has a bug where the router follows the route even if the method hads't been called. diff --git a/routing/routing_session.cpp b/routing/routing_session.cpp index 1d93e13a48..177caf38eb 100644 --- a/routing/routing_session.cpp +++ b/routing/routing_session.cpp @@ -78,17 +78,17 @@ void RoutingSession::BuildRoute(m2::PointD const & startPoint, m2::PointD const m_router->ClearState(); m_isFollowing = false; m_routingRebuildCount = -1; // -1 for the first rebuild. - RebuildRoute(startPoint, readyCallback, progressCallback, timeoutSec); + RebuildRoute(startPoint, readyCallback, progressCallback, timeoutSec, RouteBuilding); } void RoutingSession::RebuildRoute(m2::PointD const & startPoint, TReadyCallback const & readyCallback, - TProgressCallback const & progressCallback, uint32_t timeoutSec) + TProgressCallback const & progressCallback, uint32_t timeoutSec, State routeRebuildingState) { ASSERT(m_router != nullptr, ()); ASSERT_NOT_EQUAL(m_endPoint, m2::PointD::Zero(), ("End point was not set")); RemoveRoute(); - SetState(RouteBuilding); + SetState(routeRebuildingState); m_routingRebuildCount++; m_lastCompletionPercent = 0; @@ -159,8 +159,9 @@ RoutingSession::State RoutingSession::OnLocationPositionChanged(GpsInfo const & ASSERT(m_state != RoutingNotActive, ()); ASSERT(m_router != nullptr, ()); - if (m_state == RouteNeedRebuild || m_state == RouteFinished || m_state == RouteBuilding || - m_state == RouteNotReady || m_state == RouteNoFollowing) + if (m_state == RouteNeedRebuild || m_state == RouteFinished + || m_state == RouteBuilding || m_state == RouteRebuilding + || m_state == RouteNotReady || m_state == RouteNoFollowing) return m_state; threads::MutexGuard guard(m_routeSessionMutex); @@ -534,6 +535,7 @@ string DebugPrint(RoutingSession::State state) case RoutingSession::RouteNeedRebuild: return "RouteNeedRebuild"; case RoutingSession::RouteFinished: return "RouteFinished"; case RoutingSession::RouteNoFollowing: return "RouteNoFollowing"; + case RoutingSession::RouteRebuilding: return "RouteRebuilding"; } } } // namespace routing diff --git a/routing/routing_session.hpp b/routing/routing_session.hpp index 3b01269282..ecc3cb3e39 100644 --- a/routing/routing_session.hpp +++ b/routing/routing_session.hpp @@ -45,13 +45,16 @@ public: OnRoute, // user follows the route RouteNeedRebuild, // user left the route RouteFinished, // destination point is reached but the session isn't closed - RouteNoFollowing // route is built but following mode has been disabled + RouteNoFollowing, // route is built but following mode has been disabled + RouteRebuilding, // we requested a route rebuild and wait when it will be rebuilded }; /* * RoutingNotActive -> RouteBuilding // start route building - * RouteBuilding -> RouteNotReady // waiting for route - * RouteBuilding -> RouteNotStarted // route is builded + * RouteBuilding -> RouteNotReady // waiting for route in case of building a new route + * RouteBuilding -> RouteNotStarted // route is builded in case of building a new route + * RouteRebuilding -> RouteNotReady // waiting for route in case of rebuilding + * RouteRebuilding -> RouteNotStarted // route is builded in case of rebuilding * RouteNotStarted -> OnRoute // user started following the route * RouteNotStarted -> RouteNeedRebuild // user doesn't like the route. * OnRoute -> RouteNeedRebuild // user moves away from route - need to rebuild @@ -79,13 +82,21 @@ public: TReadyCallback const & readyCallback, TProgressCallback const & progressCallback, uint32_t timeoutSec); void RebuildRoute(m2::PointD const & startPoint, TReadyCallback const & readyCallback, - TProgressCallback const & progressCallback, uint32_t timeoutSec); + TProgressCallback const & progressCallback, uint32_t timeoutSec, + State routeRebuildingState); m2::PointD GetEndPoint() const { return m_endPoint; } bool IsActive() const { return (m_state != RoutingNotActive); } bool IsNavigable() const { return (m_state == RouteNotStarted || m_state == OnRoute || m_state == RouteFinished); } - bool IsBuilt() const { return (IsNavigable() || m_state == RouteNeedRebuild || m_state == RouteFinished); } - bool IsBuilding() const { return (m_state == RouteBuilding); } + bool IsBuilt() const { return (IsNavigable() || m_state == RouteNeedRebuild); } + /// \returns true if a new route is in process of building rebuilding or + /// if a route is being rebuilt in case the user left the route, and false otherwise. + bool IsBuilding() const { return (m_state == RouteBuilding || m_state == RouteRebuilding); } + bool IsBuildingOnly() const { return m_state == RouteBuilding; } + bool IsRebuildingOnly() const { return m_state == RouteRebuilding; } + bool IsNotReady() const { return m_state == RouteNotReady; } + bool IsFinished() const { return m_state == RouteFinished; } + bool IsNoFollowing() const { return m_state == RouteNoFollowing; } bool IsOnRoute() const { return (m_state == OnRoute); } bool IsFollowing() const { return m_isFollowing; } void Reset(); diff --git a/routing/routing_tests/routing_session_test.cpp b/routing/routing_tests/routing_session_test.cpp index 2cbeaa5ff4..2ad9e0c363 100644 --- a/routing/routing_tests/routing_session_test.cpp +++ b/routing/routing_tests/routing_session_test.cpp @@ -226,7 +226,7 @@ UNIT_TEST(TestFollowRouteFlagPersistence) { rebuildTimedSignal.Signal(); }, - nullptr, 0); + nullptr, 0, RoutingSession::State::RouteBuilding); TEST(rebuildTimedSignal.WaitUntil(time), ("Route was not built.")); TEST(session.IsFollowing(), ()); }