diff --git a/platform/mwm_traits.cpp b/platform/mwm_traits.cpp index f832ead28d..9ec21e7212 100644 --- a/platform/mwm_traits.cpp +++ b/platform/mwm_traits.cpp @@ -22,6 +22,8 @@ MwmTraits::HouseToStreetTableFormat MwmTraits::GetHouseToStreetTableFormat() con bool MwmTraits::HasOffsetsTable() const { return GetFormat() >= version::Format::v6; } +bool MwmTraits::HasCrossMwmSection() const { return GetFormat() >= version::Format::v9; } + bool MwmTraits::HasRoutingIndex() const { uint32_t constexpr kFirstVersionWithRoutingIndex = 161206; diff --git a/platform/mwm_traits.hpp b/platform/mwm_traits.hpp index 2663acd462..019496d32f 100644 --- a/platform/mwm_traits.hpp +++ b/platform/mwm_traits.hpp @@ -46,6 +46,8 @@ public: bool HasOffsetsTable() const; + bool HasCrossMwmSection() const; + // The new routing section with IndexGraph was added in december 2016. // Check whether mwm has routing index section. bool HasRoutingIndex() const; diff --git a/platform/mwm_version.hpp b/platform/mwm_version.hpp index 66b5e57b29..7cfd8a1fdf 100644 --- a/platform/mwm_version.hpp +++ b/platform/mwm_version.hpp @@ -21,7 +21,8 @@ enum class Format v6, // October 2015 (offsets vector is in mwm now). v7, // November 2015 (supply different search index formats). v8, // February 2016 (long strings in metadata; store seconds since epoch in MwmVersion). - lastFormat = v8 + v9, // April 2017 (OSRM sections are deleted and replaced by cross mwm section. + lastFormat = v9 }; string DebugPrint(Format f); diff --git a/routing/car_router.cpp b/routing/car_router.cpp index ba99f2dc96..7115d9f927 100644 --- a/routing/car_router.cpp +++ b/routing/car_router.cpp @@ -239,6 +239,19 @@ IRouter::ResultCode FindSingleOsrmRoute(FeatureGraphNode const & source, return routing::IRouter::NoError; } + +template +void ForEachCountryInfo(Index & index, ToDo && toDo) +{ + vector> infos; + index.GetMwmsInfo(infos); + + for (auto const & info : infos) + { + if (info->GetType() == MwmInfo::COUNTRY) + toDo(*info); + } +} } // namespace // static @@ -404,6 +417,9 @@ CarRouter::ResultCode CarRouter::CalculateRoute(m2::PointD const & startPoint, if (AllMwmsHaveRoutingIndex()) return m_router->CalculateRoute(startPoint, startDirection, finalPoint, delegate, route); + if (ThereIsCrossMwmMix(route)) + return CarRouter::ResultCode::FileTooOld; + my::HighResTimer timer(true); TRoutingMappingPtr startMapping = m_indexManager.GetMappingByPoint(startPoint); @@ -584,18 +600,43 @@ bool CarRouter::DoesEdgeIndexExist(Index::MwmId const & mwmId) bool CarRouter::AllMwmsHaveRoutingIndex() const { - vector> infos; - m_index.GetMwmsInfo(infos); - for (auto const & info : infos) - { - if (info->GetType() != MwmInfo::COUNTRY) - continue; + bool result = true; - if (!version::MwmTraits(info->m_version).HasRoutingIndex()) - return false; + ForEachCountryInfo(m_index, [&](MwmInfo const & info) { + if (!version::MwmTraits(info.m_version).HasRoutingIndex()) + result = false; + }); + + return result; +} + +bool CarRouter::ThereIsCrossMwmMix(Route & route) const +{ + bool oldMwmExists = false; + bool newMwmExists = false; + vector oldMwms; + + ForEachCountryInfo(m_index, [&](MwmInfo const & info) { + if (version::MwmTraits(info.m_version).HasCrossMwmSection()) + { + newMwmExists = true; + } + else + { + oldMwmExists = true; + oldMwms.push_back(info.GetCountryName()); + } + }); + + if (oldMwmExists && newMwmExists) + { + for (auto const & oldMwm : oldMwms) + route.AddAbsentCountry(oldMwm); + + return true; } - return true; + return false; } IRouter::ResultCode CarRouter::FindSingleRouteDispatcher(FeatureGraphNode const & source, diff --git a/routing/car_router.hpp b/routing/car_router.hpp index 6e7e0fdbc7..c3df63612c 100644 --- a/routing/car_router.hpp +++ b/routing/car_router.hpp @@ -88,6 +88,7 @@ private: // this method should be moved to routing loader. bool DoesEdgeIndexExist(Index::MwmId const & mwmId); bool AllMwmsHaveRoutingIndex() const; + bool ThereIsCrossMwmMix(Route & route) const; /*! * \brief Builds a route within one mwm using A* if edge index section is available and osrm