From d7923f551254136df78a19e8230d01e727a2c166 Mon Sep 17 00:00:00 2001 From: David Martinez <47610359+dvdmrtnz@users.noreply.github.com> Date: Sat, 3 Feb 2024 12:53:09 +0100 Subject: [PATCH] [core] Add runtime FMD_WHEELCHAIR metadata Signed-off-by: David Martinez <47610359+dvdmrtnz@users.noreply.github.com> --- generator/osm2meta.cpp | 1 + indexer/feature_meta.cpp | 1 + indexer/feature_meta.hpp | 1 + indexer/feature_utils.cpp | 22 ++++++++++++++++++++++ indexer/feature_utils.hpp | 3 +++ indexer/ftypes_matcher.cpp | 6 ++++++ indexer/ftypes_matcher.hpp | 8 ++++++++ indexer/map_object.cpp | 3 +++ 8 files changed, 45 insertions(+) diff --git a/generator/osm2meta.cpp b/generator/osm2meta.cpp index 39d0069134..7562b6b920 100644 --- a/generator/osm2meta.cpp +++ b/generator/osm2meta.cpp @@ -534,6 +534,7 @@ void MetadataTagProcessor::operator()(std::string const & k, std::string const & case Metadata::FMD_PRICE_RATES: case Metadata::FMD_RATINGS: case Metadata::FMD_EXTERNAL_URI: + case Metadata::FMD_WHEELCHAIR: case Metadata::FMD_COUNT: CHECK(false, (mdType, "should not be parsed from OSM.")); } diff --git a/indexer/feature_meta.cpp b/indexer/feature_meta.cpp index a89c464235..048b889124 100644 --- a/indexer/feature_meta.cpp +++ b/indexer/feature_meta.cpp @@ -240,6 +240,7 @@ string ToString(Metadata::EType type) case Metadata::FMD_BUILDING_MIN_LEVEL: return "building:min_level"; case Metadata::FMD_WIKIMEDIA_COMMONS: return "wikimedia_commons"; case Metadata::FMD_CAPACITY: return "capacity"; + case Metadata::FMD_WHEELCHAIR: return "wheelchair"; case Metadata::FMD_COUNT: CHECK(false, ("FMD_COUNT can not be used as a type.")); }; diff --git a/indexer/feature_meta.hpp b/indexer/feature_meta.hpp index 9b9c640b67..3c6e6b69e5 100644 --- a/indexer/feature_meta.hpp +++ b/indexer/feature_meta.hpp @@ -148,6 +148,7 @@ public: FMD_BUILDING_MIN_LEVEL = 40, FMD_WIKIMEDIA_COMMONS = 41, FMD_CAPACITY = 42, + FMD_WHEELCHAIR = 43, // Value is runtime only, data is taken from the classificator types FMD_COUNT }; diff --git a/indexer/feature_utils.cpp b/indexer/feature_utils.cpp index 8358665a2a..edfd9ebace 100644 --- a/indexer/feature_utils.cpp +++ b/indexer/feature_utils.cpp @@ -174,6 +174,18 @@ vector GetRawTypeSecond(ftypes::BaseChecker const & checker, TypesHolder return res; } +vector GetReadableTypes(ftypes::BaseChecker const & checker, TypesHolder const & types) +{ + auto const & c = classif(); + vector readable; + for (auto const t : types) + { + if (checker(t)) + readable.push_back(c.GetReadableObjectName(t)); + } + return readable; +} + vector GetLocalizedTypes(ftypes::BaseChecker const & checker, TypesHolder const & types) { auto const & c = classif(); @@ -438,6 +450,16 @@ string GetLocalizedFeeType(TypesHolder const & types) return localized_types[0]; } +string GetReadableWheelchairType(TypesHolder const & types) +{ + auto const & isWheelchairType = ftypes::IsWheelchairTypeChecker::Instance(); + auto readableTypes = GetReadableTypes(isWheelchairType, types); + ASSERT_LESS_OR_EQUAL ( readableTypes.size(), 1, () ); + if (readableTypes.empty()) + return ""; + return readableTypes[0]; +} + bool HasAtm(TypesHolder const & types) { auto const & isAtmType = ftypes::IsATMChecker::Instance(); diff --git a/indexer/feature_utils.hpp b/indexer/feature_utils.hpp index b2e12de225..03545e980c 100644 --- a/indexer/feature_utils.hpp +++ b/indexer/feature_utils.hpp @@ -129,6 +129,9 @@ namespace feature // Returns fee type localized by platform. std::string GetLocalizedFeeType(TypesHolder const & types); + // Returns readable wheelchair type. + std::string GetReadableWheelchairType(TypesHolder const & types); + /// Returns true if feature has ATM type. bool HasAtm(TypesHolder const & types); diff --git a/indexer/ftypes_matcher.cpp b/indexer/ftypes_matcher.cpp index d54d746f2e..d6c6faf424 100644 --- a/indexer/ftypes_matcher.cpp +++ b/indexer/ftypes_matcher.cpp @@ -765,6 +765,12 @@ IsFeeTypeChecker::IsFeeTypeChecker() : BaseChecker(1 /* level */) m_types.push_back(c.GetTypeByPath({"fee"})); } +IsWheelchairTypeChecker::IsWheelchairTypeChecker() : BaseChecker(1 /* level */) +{ + Classificator const & c = classif(); + m_types.push_back(c.GetTypeByPath({"wheelchair"})); +} + IsToiletsChecker::IsToiletsChecker() : BaseChecker(2 /* level */) { Classificator const & c = classif(); diff --git a/indexer/ftypes_matcher.hpp b/indexer/ftypes_matcher.hpp index 3792a1dffb..70ffc3efe4 100644 --- a/indexer/ftypes_matcher.hpp +++ b/indexer/ftypes_matcher.hpp @@ -476,6 +476,14 @@ public: DECLARE_CHECKER_INSTANCE(IsFeeTypeChecker); }; +class IsWheelchairTypeChecker : public BaseChecker +{ + IsWheelchairTypeChecker(); + +public: + DECLARE_CHECKER_INSTANCE(IsWheelchairTypeChecker); +}; + class IsToiletsChecker : public BaseChecker { IsToiletsChecker(); diff --git a/indexer/map_object.cpp b/indexer/map_object.cpp index 9e57e9b2c6..47f86351b6 100644 --- a/indexer/map_object.cpp +++ b/indexer/map_object.cpp @@ -73,6 +73,9 @@ void MapObject::SetFromFeatureType(FeatureType & ft) assign_range(m_triangles, ft.GetTrianglesAsPoints(FeatureType::BEST_GEOMETRY)); else if (m_geomType == feature::GeomType::Line) assign_range(m_points, ft.GetPoints(FeatureType::BEST_GEOMETRY)); + + // Fill runtime metadata + m_metadata.Set(feature::Metadata::EType::FMD_WHEELCHAIR, feature::GetReadableWheelchairType(m_types)); #ifdef DEBUG if (ftypes::IsWifiChecker::Instance()(ft))