diff options
author | Constantin Shalnev <c.shalnev@corp.mail.ru> | 2015-08-07 11:15:13 +0300 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 02:59:40 +0300 |
commit | 51ba7c3b5fa9b3ea9e2f2f7c029554cb85283939 (patch) | |
tree | 0e1a52369d12e9b9ade672b29760e454e1deec1f /routing | |
parent | e261d4dd28830f2723503dc91a9abad3252ff5a8 (diff) |
Cancel directions generation when routing is cancelled
Diffstat (limited to 'routing')
-rw-r--r-- | routing/directions_engine.hpp | 5 | ||||
-rw-r--r-- | routing/pedestrian_directions.cpp | 19 | ||||
-rw-r--r-- | routing/pedestrian_directions.hpp | 9 | ||||
-rw-r--r-- | routing/road_graph_router.cpp | 10 | ||||
-rw-r--r-- | routing/road_graph_router.hpp | 3 |
5 files changed, 33 insertions, 13 deletions
diff --git a/routing/directions_engine.hpp b/routing/directions_engine.hpp index 8abcc22f96..3706db21a2 100644 --- a/routing/directions_engine.hpp +++ b/routing/directions_engine.hpp @@ -3,6 +3,8 @@ #include "routing/road_graph.hpp" #include "routing/route.hpp" +#include "base/cancellable.hpp" + namespace routing { @@ -14,7 +16,8 @@ public: virtual void Generate(IRoadGraph const & graph, vector<Junction> const & path, Route::TTimes & times, Route::TTurns & turnsDir, - turns::TTurnsGeom & turnsGeom) = 0; + turns::TTurnsGeom & turnsGeom, + my::Cancellable const & cancellable) = 0; }; } // namespace routing diff --git a/routing/pedestrian_directions.cpp b/routing/pedestrian_directions.cpp index 44ac7cdaa8..00dc0fef98 100644 --- a/routing/pedestrian_directions.cpp +++ b/routing/pedestrian_directions.cpp @@ -38,14 +38,15 @@ PedestrianDirectionsEngine::PedestrianDirectionsEngine() void PedestrianDirectionsEngine::Generate(IRoadGraph const & graph, vector<Junction> const & path, Route::TTimes & times, Route::TTurns & turnsDir, - turns::TTurnsGeom & turnsGeom) + turns::TTurnsGeom & turnsGeom, + my::Cancellable const & cancellable) { CHECK_GREATER(path.size(), 1, ()); CalculateTimes(graph, path, times); vector<Edge> routeEdges; - if (!ReconstructPath(graph, path, routeEdges)) + if (!ReconstructPath(graph, path, routeEdges, cancellable)) { LOG(LDEBUG, ("Couldn't reconstruct path")); // use only "arrival" direction @@ -53,7 +54,7 @@ void PedestrianDirectionsEngine::Generate(IRoadGraph const & graph, vector<Junct return; } - CalculateTurns(graph, routeEdges, turnsDir); + CalculateTurns(graph, routeEdges, turnsDir, cancellable); // Do not show arrows for pedestrian routing until a good design solution // turns::CalculateTurnGeometry(path, turnsDir, turnsGeom); @@ -61,7 +62,8 @@ void PedestrianDirectionsEngine::Generate(IRoadGraph const & graph, vector<Junct } bool PedestrianDirectionsEngine::ReconstructPath(IRoadGraph const & graph, vector<Junction> const & path, - vector<Edge> & routeEdges) const + vector<Edge> & routeEdges, + my::Cancellable const & cancellable) const { routeEdges.reserve(path.size() - 1); @@ -69,6 +71,9 @@ bool PedestrianDirectionsEngine::ReconstructPath(IRoadGraph const & graph, vecto vector<Edge> currEdges; for (size_t i = 1; i < path.size(); ++i) { + if (cancellable.IsCancelled()) + return false; + Junction const & next = path[i]; currEdges.clear(); @@ -121,10 +126,14 @@ void PedestrianDirectionsEngine::CalculateTimes(IRoadGraph const & graph, vector } void PedestrianDirectionsEngine::CalculateTurns(IRoadGraph const & graph, vector<Edge> const & routeEdges, - Route::TTurns & turnsDir) const + Route::TTurns & turnsDir, + my::Cancellable const & cancellable) const { for (size_t i = 0; i < routeEdges.size(); ++i) { + if (cancellable.IsCancelled()) + return; + Edge const & edge = routeEdges[i]; feature::TypesHolder types; diff --git a/routing/pedestrian_directions.hpp b/routing/pedestrian_directions.hpp index e6e94e8147..162a9e37f4 100644 --- a/routing/pedestrian_directions.hpp +++ b/routing/pedestrian_directions.hpp @@ -14,17 +14,20 @@ public: void Generate(IRoadGraph const & graph, vector<Junction> const & path, Route::TTimes & times, Route::TTurns & turnsDir, - turns::TTurnsGeom & turnsGeom) override; + turns::TTurnsGeom & turnsGeom, + my::Cancellable const & cancellable) override; private: bool ReconstructPath(IRoadGraph const & graph, vector<Junction> const & path, - vector<Edge> & routeEdges) const; + vector<Edge> & routeEdges, + my::Cancellable const & cancellable) const; void CalculateTimes(IRoadGraph const & graph, vector<Junction> const & path, Route::TTimes & times) const; void CalculateTurns(IRoadGraph const & graph, vector<Edge> const & routeEdges, - Route::TTurns & turnsDir) const; + Route::TTurns & turnsDir, + my::Cancellable const & cancellable) const; uint32_t const m_typeSteps; uint32_t const m_typeLiftGate; diff --git a/routing/road_graph_router.cpp b/routing/road_graph_router.cpp index 4dd42a00a2..81dc0c3fbd 100644 --- a/routing/road_graph_router.cpp +++ b/routing/road_graph_router.cpp @@ -145,15 +145,19 @@ IRouter::ResultCode RoadGraphRouter::CalculateRoute(m2::PointD const & startPoin ASSERT(!path.empty(), ()); ASSERT_EQUAL(path.front(), startPos, ()); ASSERT_EQUAL(path.back(), finalPos, ()); - ReconstructRoute(move(path), route); + ReconstructRoute(move(path), route, delegate); } m_roadGraph->ResetFakes(); + if (delegate.IsCancelled()) + return IRouter::Cancelled; + return Convert(resultCode); } -void RoadGraphRouter::ReconstructRoute(vector<Junction> && path, Route & route) const +void RoadGraphRouter::ReconstructRoute(vector<Junction> && path, Route & route, + my::Cancellable const & cancellable) const { CHECK(!path.empty(), ("Can't reconstruct route from an empty list of positions.")); @@ -172,7 +176,7 @@ void RoadGraphRouter::ReconstructRoute(vector<Junction> && path, Route & route) Route::TTurns turnsDir; turns::TTurnsGeom turnsGeom; if (m_directionsEngine) - m_directionsEngine->Generate(*m_roadGraph, path, times, turnsDir, turnsGeom); + m_directionsEngine->Generate(*m_roadGraph, path, times, turnsDir, turnsGeom, cancellable); route.SetGeometry(geometry.begin(), geometry.end()); route.SetSectionTimes(times); diff --git a/routing/road_graph_router.hpp b/routing/road_graph_router.hpp index e3174b8610..048852d7a5 100644 --- a/routing/road_graph_router.hpp +++ b/routing/road_graph_router.hpp @@ -37,7 +37,8 @@ public: Route & route) override; private: - void ReconstructRoute(vector<Junction> && junctions, Route & route) const; + void ReconstructRoute(vector<Junction> && junctions, Route & route, + my::Cancellable const & cancellable) const; string const m_name; unique_ptr<IRoutingAlgorithm> const m_algorithm; |