diff options
author | Yuri Gorshenin <y@maps.me> | 2016-06-10 15:06:09 +0300 |
---|---|---|
committer | Yuri Gorshenin <y@maps.me> | 2016-06-10 15:56:09 +0300 |
commit | 7f45a4eb1dbeb71c1cc93984d157191948072283 (patch) | |
tree | 6ebe1dc0909bae3a205971bcb7806f3019169350 /routing | |
parent | 1895a30bd742122bdc4d06b31beef0bb7b7bc635 (diff) |
[routing][ui] Fixes to UI crash on long routing planning completion.
Diffstat (limited to 'routing')
-rw-r--r-- | routing/directions_engine.cpp | 2 | ||||
-rw-r--r-- | routing/road_graph.hpp | 7 | ||||
-rw-r--r-- | routing/road_graph_router.cpp | 32 | ||||
-rw-r--r-- | routing/routing_session.cpp | 39 | ||||
-rw-r--r-- | routing/routing_session.hpp | 4 |
5 files changed, 54 insertions, 30 deletions
diff --git a/routing/directions_engine.cpp b/routing/directions_engine.cpp index 63115de536..6b162e5d51 100644 --- a/routing/directions_engine.cpp +++ b/routing/directions_engine.cpp @@ -69,7 +69,7 @@ bool IDirectionsEngine::ReconstructPath(IRoadGraph const & graph, vector<Junctio bool found = false; for (auto const & e : currEdges) { - if (e.GetEndJunction() == next) + if (AlmostEqualAbs(e.GetEndJunction(), next)) { routeEdges.emplace_back(e); found = true; diff --git a/routing/road_graph.hpp b/routing/road_graph.hpp index e97a9cb0f2..b995a3e2d8 100644 --- a/routing/road_graph.hpp +++ b/routing/road_graph.hpp @@ -26,7 +26,7 @@ public: inline bool operator==(Junction const & r) const { return m_point == r.m_point; } inline bool operator<(Junction const & r) const { return m_point < r.m_point; } - m2::PointD const & GetPoint() const { return m_point; } + inline m2::PointD const & GetPoint() const { return m_point; } private: friend string DebugPrint(Junction const & r); @@ -35,6 +35,11 @@ private: m2::PointD m_point; }; +inline bool AlmostEqualAbs(Junction const & lhs, Junction const & rhs) +{ + return my::AlmostEqualAbs(lhs.GetPoint(), rhs.GetPoint(), kPointsEqualEpsilon); +} + /// The Edge class represents an edge description on a road network graph class Edge { diff --git a/routing/road_graph_router.cpp b/routing/road_graph_router.cpp index 83934557e8..2539087a22 100644 --- a/routing/road_graph_router.cpp +++ b/routing/road_graph_router.cpp @@ -38,18 +38,6 @@ size_t constexpr kTestConnectivityVisitJunctionsLimit = 25; uint64_t constexpr kMinPedestrianMwmVersion = 150713; -IRouter::ResultCode Convert(IRoutingAlgorithm::Result value) -{ - switch (value) - { - case IRoutingAlgorithm::Result::OK: return IRouter::ResultCode::NoError; - case IRoutingAlgorithm::Result::NoPath: return IRouter::ResultCode::RouteNotFound; - case IRoutingAlgorithm::Result::Cancelled: return IRouter::ResultCode::Cancelled; - } - ASSERT(false, ("Unexpected IRoutingAlgorithm::Result value:", value)); - return IRouter::ResultCode::RouteNotFound; -} - // Check if the found edges lays on mwm with pedestrian routing support. bool CheckMwmVersion(vector<pair<Edge, m2::PointD>> const & vicinities, vector<string> & mwmNames) { @@ -166,13 +154,13 @@ IRouter::ResultCode RoadGraphRouter::CalculateRoute(m2::PointD const & startPoin RouterDelegate const & delegate, Route & route) { if (!CheckMapExistence(startPoint, route) || !CheckMapExistence(finalPoint, route)) - return RouteFileNotExist; + return IRouter::RouteFileNotExist; vector<pair<Edge, m2::PointD>> finalVicinity; FindClosestEdges(*m_roadGraph, finalPoint, finalVicinity); if (finalVicinity.empty()) - return EndPointNotFound; + return IRouter::EndPointNotFound; // TODO (ldragunov) Remove this check after several releases. (Estimated in november) vector<string> mwmNames; @@ -186,7 +174,7 @@ IRouter::ResultCode RoadGraphRouter::CalculateRoute(m2::PointD const & startPoin FindClosestEdges(*m_roadGraph, startPoint, startVicinity); if (startVicinity.empty()) - return StartPointNotFound; + return IRouter::StartPointNotFound; // TODO (ldragunov) Remove this check after several releases. (Estimated in november) if (CheckMwmVersion(startVicinity, mwmNames)) @@ -196,7 +184,7 @@ IRouter::ResultCode RoadGraphRouter::CalculateRoute(m2::PointD const & startPoin } if (!route.GetAbsentCountries().empty()) - return FileTooOld; + return IRouter::FileTooOld; Junction const startPos(startPoint); Junction const finalPos(finalPoint); @@ -223,7 +211,17 @@ IRouter::ResultCode RoadGraphRouter::CalculateRoute(m2::PointD const & startPoin if (delegate.IsCancelled()) return IRouter::Cancelled; - return Convert(resultCode); + if (!route.IsValid()) + return IRouter::RouteNotFound; + + switch (resultCode) + { + case IRoutingAlgorithm::Result::OK: return IRouter::NoError; + case IRoutingAlgorithm::Result::NoPath: return IRouter::RouteNotFound; + case IRoutingAlgorithm::Result::Cancelled: return IRouter::Cancelled; + } + ASSERT(false, ("Unexpected IRoutingAlgorithm::Result code:", resultCode)); + return IRouter::RouteNotFound; } void RoadGraphRouter::ReconstructRoute(vector<Junction> && path, Route & route, diff --git a/routing/routing_session.cpp b/routing/routing_session.cpp index d522b609e1..1d93e13a48 100644 --- a/routing/routing_session.cpp +++ b/routing/routing_session.cpp @@ -88,7 +88,7 @@ void RoutingSession::RebuildRoute(m2::PointD const & startPoint, ASSERT(m_router != nullptr, ()); ASSERT_NOT_EQUAL(m_endPoint, m2::PointD::Zero(), ("End point was not set")); RemoveRoute(); - m_state = RouteBuilding; + SetState(RouteBuilding); m_routingRebuildCount++; m_lastCompletionPercent = 0; @@ -119,7 +119,7 @@ void RoutingSession::DoReadyCallback::operator()(Route & route, IRouter::ResultC void RoutingSession::RemoveRouteImpl() { - m_state = RoutingNotActive; + SetState(RoutingNotActive); m_lastDistance = 0.0; m_moveAwayCounter = 0; m_turnNotificationsMgr.Reset(); @@ -177,7 +177,7 @@ RoutingSession::State RoutingSession::OnLocationPositionChanged(GpsInfo const & if (m_route.IsCurrentOnEnd()) { m_passedDistanceOnRouteMeters += m_route.GetTotalDistanceMeters(); - m_state = RouteFinished; + SetState(RouteFinished); alohalytics::TStringMap params = {{"router", m_route.GetRouterId()}, {"passedDistance", strings::to_string(m_passedDistanceOnRouteMeters)}, @@ -186,7 +186,7 @@ RoutingSession::State RoutingSession::OnLocationPositionChanged(GpsInfo const & } else { - m_state = OnRoute; + SetState(OnRoute); // Warning signals checks if (m_routingSettings.m_speedCameraWarning && !m_speedWarningSignal) @@ -225,7 +225,7 @@ RoutingSession::State RoutingSession::OnLocationPositionChanged(GpsInfo const & if (m_moveAwayCounter > kOnRouteMissedCount) { m_passedDistanceOnRouteMeters += m_route.GetCurrentDistanceFromBeginMeters(); - m_state = RouteNeedRebuild; + SetState(RouteNeedRebuild); alohalytics::TStringMap params = { {"router", m_route.GetRouterId()}, {"percent", strings::to_string(GetCompletionPercent())}, @@ -364,15 +364,17 @@ void RoutingSession::AssignRoute(Route & route, IRouter::ResultCode e) if (e != IRouter::Cancelled) { if (route.IsValid()) - m_state = RouteNotStarted; + SetState(RouteNotStarted); else - m_state = RoutingNotActive; + SetState(RoutingNotActive); if (e != IRouter::NoError) - m_state = RouteNotReady; + SetState(RouteNotReady); } else - m_state = RoutingNotActive; + { + SetState(RoutingNotActive); + } route.SetRoutingSettings(m_routingSettings); m_route.Swap(route); @@ -405,7 +407,7 @@ bool RoutingSession::DisableFollowMode() LOG(LINFO, ("Routing disables a following mode. State: ", m_state)); if (m_state == RouteNotStarted || m_state == OnRoute) { - m_state = RouteNoFollowing; + SetState(RouteNoFollowing); m_isFollowing = false; return true; } @@ -417,7 +419,7 @@ bool RoutingSession::EnableFollowMode() LOG(LINFO, ("Routing enables a following mode. State: ", m_state)); if (m_state == RouteNotStarted || m_state == OnRoute) { - m_state = OnRoute; + SetState(OnRoute); m_isFollowing = true; } return m_isFollowing; @@ -519,4 +521,19 @@ void RoutingSession::EmitCloseRoutingEvent() const {"rebuildCount", strings::to_string(m_routingRebuildCount)}}, alohalytics::Location::FromLatLon(lastGoodPoint.lat, lastGoodPoint.lon)); } + +string DebugPrint(RoutingSession::State state) +{ + switch (state) + { + case RoutingSession::RoutingNotActive: return "RoutingNotActive"; + case RoutingSession::RouteBuilding: return "RouteBuilding"; + case RoutingSession::RouteNotReady: return "RouteNotReady"; + case RoutingSession::RouteNotStarted: return "RouteNotStarted"; + case RoutingSession::OnRoute: return "OnRoute"; + case RoutingSession::RouteNeedRebuild: return "RouteNeedRebuild"; + case RoutingSession::RouteFinished: return "RouteFinished"; + case RoutingSession::RouteNoFollowing: return "RouteNoFollowing"; + } +} } // namespace routing diff --git a/routing/routing_session.hpp b/routing/routing_session.hpp index 036f16ffde..3b01269282 100644 --- a/routing/routing_session.hpp +++ b/routing/routing_session.hpp @@ -90,6 +90,8 @@ public: bool IsFollowing() const { return m_isFollowing; } void Reset(); + inline void SetState(State state) { m_state = state; } + Route const & GetRoute() const { return m_route; } State OnLocationPositionChanged(location::GpsInfo const & info, Index const & index); @@ -187,4 +189,6 @@ private: int m_routingRebuildCount; mutable double m_lastCompletionPercent; }; + +string DebugPrint(RoutingSession::State state); } // namespace routing |