From 389d00224b3cd9cf903126be54f6bb65699676d6 Mon Sep 17 00:00:00 2001 From: Lev Dragunov Date: Tue, 4 Aug 2015 13:59:55 +0300 Subject: [PATCH] GetBestRouter vehicle router file existance check. --- map/framework.cpp | 13 ++++++++++++- map/framework.hpp | 2 +- routing/osrm_router.cpp | 10 ++++++++++ routing/osrm_router.hpp | 10 ++++++++++ 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/map/framework.cpp b/map/framework.cpp index 1e3458b33e..11dcf1b126 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -2316,7 +2316,7 @@ string Framework::GetRoutingErrorMessage(IRouter::ResultCode code) return m_stringsBundle.GetString(messageID); } -RouterType Framework::GetBestRouter(m2::PointD const & startPoint, m2::PointD const & finalPoint) const +RouterType Framework::GetBestRouter(m2::PointD const & startPoint, m2::PointD const & finalPoint) { if (MercatorBounds::DistanceOnEarth(startPoint, finalPoint) < kKeepPedestrianDistanceMeters) { @@ -2324,6 +2324,17 @@ RouterType Framework::GetBestRouter(m2::PointD const & startPoint, m2::PointD co Settings::Get(kRouterTypeKey, routerType); if (routerType == routing::ToString(RouterType::Pedestrian)) return RouterType::Pedestrian; + else + { + // Return on short calls the vehicle router flag only if we are already have routing files. + auto countryFileGetter = [this](m2::PointD const & p) + { + return GetSearchEngine()->GetCountryFile(p); + }; + if (!OsrmRouter::CheckRoutingAbility(startPoint, finalPoint, countryFileGetter, + &m_model.GetIndex())) + return RouterType::Pedestrian; + } } return RouterType::Vehicle; } diff --git a/map/framework.hpp b/map/framework.hpp index 0c24dde99c..5298a68d47 100644 --- a/map/framework.hpp +++ b/map/framework.hpp @@ -575,7 +575,7 @@ public: 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. - routing::RouterType GetBestRouter(m2::PointD const & startPoint, m2::PointD const & finalPoint) const; + routing::RouterType GetBestRouter(m2::PointD const & startPoint, m2::PointD const & finalPoint); // Sound notifications for turn instructions. inline void EnableTurnNotifications(bool enable) { m_routingSession.EnableTurnNotifications(enable); } inline bool AreTurnNotificationsEnabled() const { return m_routingSession.AreTurnNotificationsEnabled(); } diff --git a/routing/osrm_router.cpp b/routing/osrm_router.cpp index 8fa2e10ddf..7adffe9f68 100644 --- a/routing/osrm_router.cpp +++ b/routing/osrm_router.cpp @@ -334,6 +334,16 @@ private: }; } // namespace +// static +bool OsrmRouter::CheckRoutingAbility(m2::PointD const & startPoint, + m2::PointD const & finalPoint, + TCountryFileFn const & countryFileFn, Index * index) +{ + RoutingIndexManager manager(countryFileFn, index); + return manager.GetMappingByPoint(startPoint)->IsValid() && + manager.GetMappingByPoint(finalPoint)->IsValid(); +} + OsrmRouter::OsrmRouter(Index * index, TCountryFileFn const & countryFileFn) : m_pIndex(index), m_indexManager(countryFileFn, index) { diff --git a/routing/osrm_router.hpp b/routing/osrm_router.hpp index e3a0d00cd2..d5b4a83317 100644 --- a/routing/osrm_router.hpp +++ b/routing/osrm_router.hpp @@ -56,6 +56,16 @@ public: TFeatureGraphNodeVec const & target, TDataFacade & facade, RawRoutingResult & rawRoutingResult); + /*! Fast checking ability of route construction + * @param startPoint starting road point + * @param finalPoint final road point + * @param countryFileFn function for getting filename from point + * @oaram index mwmSet index + * @returns true if we can start routing process with a given data. + */ + static bool CheckRoutingAbility(m2::PointD const & startPoint, m2::PointD const & finalPoint, + TCountryFileFn const & countryFileFn, Index * index); + protected: /*! * \brief FindPhantomNodes finds OSRM graph nodes by point and graph name.