diff --git a/map/framework.cpp b/map/framework.cpp index 251cc808fb..b894790e99 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -2290,7 +2290,7 @@ void Framework::CheckLocationForRouting(GpsInfo const & info) return; m2::PointD const & position = GetLocationState()->Position(); - if (m_routingSession.OnLocationPositionChanged(position, info) == RoutingSession::RouteNeedRebuild) + if (m_routingSession.OnLocationPositionChanged(position, info, m_model.GetIndex()) == RoutingSession::RouteNeedRebuild) { auto readyCallback = [this](Route const & route, IRouter::ResultCode code) { diff --git a/map/framework.hpp b/map/framework.hpp index a91f31afbc..2d30557cd8 100644 --- a/map/framework.hpp +++ b/map/framework.hpp @@ -595,7 +595,7 @@ public: void SetRouteProgressListener(TRouteProgressCallback const & progressCallback) { m_progressCallback = progressCallback; } void FollowRoute(); void CloseRouting(); - void GetRouteFollowingInfo(location::FollowingInfo & info) const { m_routingSession.GetRouteFollowingInfo(info, m_model.GetIndex()); } + void GetRouteFollowingInfo(location::FollowingInfo & info) const { m_routingSession.GetRouteFollowingInfo(info); } m2::PointD GetRouteEndPoint() const { return m_routingSession.GetEndPoint(); } void SetLastUsedRouter(routing::RouterType type); /// Returns the most situable router engine type. Bases on distance and the last used router. diff --git a/routing/routing_session.cpp b/routing/routing_session.cpp index b366ad0a81..8045f1ab83 100644 --- a/routing/routing_session.cpp +++ b/routing/routing_session.cpp @@ -43,7 +43,8 @@ RoutingSession::RoutingSession() m_route(string()), m_state(RoutingNotActive), m_endPoint(m2::PointD::Zero()), - m_speedMpS(0), + m_lastWarnedSpeedCamera(0), + m_speedWarningSignal(false), m_passedDistanceOnRouteMeters(0.0) { } @@ -131,10 +132,12 @@ void RoutingSession::Reset() m_passedDistanceOnRouteMeters = 0.0; m_lastWarnedSpeedCamera = 0; + m_speedWarningSignal = false; } RoutingSession::State RoutingSession::OnLocationPositionChanged(m2::PointD const & position, - GpsInfo const & info) + GpsInfo const & info, + Index const & index) { ASSERT(m_state != RoutingNotActive, ()); ASSERT(m_router != nullptr, ()); @@ -148,7 +151,6 @@ RoutingSession::State RoutingSession::OnLocationPositionChanged(m2::PointD const ASSERT(m_route.IsValid(), ()); m_turnsSound.SetSpeedMetersPerSecond(info.m_speed); - m_speedMpS = info.m_speed; if (m_route.MoveIterator(info)) { @@ -165,7 +167,26 @@ RoutingSession::State RoutingSession::OnLocationPositionChanged(m2::PointD const alohalytics::LogEvent("RouteTracking_ReachedDestination", params); } else + { m_state = OnRoute; + + // Warning signals checks + if (m_routingSettings.m_speedCameraWarning && !m_speedWarningSignal) + { + double const warningDistanceM = max(kSpeedCameraMinimalWarningMeters, + info.m_speed * kSpeedCameraWarningSeconds); + SpeedCameraRestriction cam(0, 0); + double const camDistance = m_route.GetCurrentCam(cam, index); + if (Route::kInvalidSpeedCameraDistance != camDistance && camDistance < warningDistanceM) + { + if (cam.m_index > m_lastWarnedSpeedCamera && info.m_speed > cam.m_maxSpeed * kMpsToKmh) + { + m_speedWarningSignal = true; + m_lastWarnedSpeedCamera = cam.m_index; + } + } + } + } m_lastGoodPosition = position; } else @@ -194,7 +215,7 @@ RoutingSession::State RoutingSession::OnLocationPositionChanged(m2::PointD const return m_state; } -void RoutingSession::GetRouteFollowingInfo(FollowingInfo & info, Index const & index) const +void RoutingSession::GetRouteFollowingInfo(FollowingInfo & info) const { auto formatDistFn = [](double dist, string & value, string & suffix) { @@ -271,22 +292,9 @@ void RoutingSession::GetRouteFollowingInfo(FollowingInfo & info, Index const & i info.m_lanes.clear(); } - // Warning signals checks - if (m_routingSettings.m_speedCameraWarning) - { - double const warningDistanceM = max(kSpeedCameraMinimalWarningMeters, - m_speedMpS * kSpeedCameraWarningSeconds); - SpeedCameraRestriction cam(0, 0); - double const camDistance = m_route.GetCurrentCam(cam, index); - if (Route::kInvalidSpeedCameraDistance != camDistance && camDistance < warningDistanceM) - { - if (cam.m_index > m_lastWarnedSpeedCamera && m_speedMpS > cam.m_maxSpeed * kMpsToKmh) - { - info.m_speedWarningSignal = true; - m_lastWarnedSpeedCamera = cam.m_index; - } - } - } + // Speedcam signal information. + info.m_speedWarningSignal = m_speedWarningSignal; + m_speedWarningSignal = false; // Pedestrian info m2::PointD pos; diff --git a/routing/routing_session.hpp b/routing/routing_session.hpp index f6880f944b..ab12c7214d 100644 --- a/routing/routing_session.hpp +++ b/routing/routing_session.hpp @@ -77,8 +77,9 @@ public: bool IsOnRoute() const { return (m_state == OnRoute); } void Reset(); - State OnLocationPositionChanged(m2::PointD const & position, location::GpsInfo const & info); - void GetRouteFollowingInfo(location::FollowingInfo & info, Index const & index) const; + State OnLocationPositionChanged(m2::PointD const & position, location::GpsInfo const & info, + Index const & index); + void GetRouteFollowingInfo(location::FollowingInfo & info) const; void MatchLocationToRoute(location::GpsInfo & location, location::RouteMatchingInfo & routeMatchingInfo) const; @@ -124,8 +125,11 @@ private: Route m_route; State m_state; m2::PointD m_endPoint; - double m_speedMpS; - mutable size_t m_lastWarnedSpeedCamera; + size_t m_lastWarnedSpeedCamera; + // TODO (ldragunov) Rewrite UI interop to message queue and avoid mutable. + /// It is mutable, because a speed warning ring must be only one time per camera. So we need + /// to modify it in a getter. + mutable bool m_speedWarningSignal; mutable threads::Mutex m_routeSessionMutex;