GetBestRouter vehicle router file existance check.

This commit is contained in:
Lev Dragunov 2015-08-04 13:59:55 +03:00 committed by Alex Zolotarev
parent 5d4b22d746
commit 389d00224b
4 changed files with 33 additions and 2 deletions

View file

@ -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;
}

View file

@ -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(); }

View file

@ -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)
{

View file

@ -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.