diff --git a/search/v2/features_layer_matcher.hpp b/search/v2/features_layer_matcher.hpp index ba2fa5cae0..8f164e316a 100644 --- a/search/v2/features_layer_matcher.hpp +++ b/search/v2/features_layer_matcher.hpp @@ -335,7 +335,10 @@ private: inline void GetByIndex(uint32_t id, FeatureType & ft) const { /// @todo Add Cache for feature id -> (point, name / house number). - m_context->GetFeature(id, ft); + /// TODO(vng): GetFeature below can retur false if feature was deleted by user in the Editor. + /// This code should be fixed to take that into an account. + /// Until we don't show "Delete" button to our users, this code will work correctly. + UNUSED_VALUE(m_context->GetFeature(id, ft)); } MwmContext * m_context; diff --git a/search/v2/geocoder.cpp b/search/v2/geocoder.cpp index 3866d48c66..c7ffb7bcdf 100644 --- a/search/v2/geocoder.cpp +++ b/search/v2/geocoder.cpp @@ -152,7 +152,8 @@ public: void GetNames(uint32_t featureId, vector & names) const override { FeatureType ft; - m_context.GetFeature(featureId, ft); + if (!m_context.GetFeature(featureId, ft)) + return; // Feature was deleted by user. for (auto const & lang : m_params.m_langs) { string name; @@ -1448,7 +1449,7 @@ SearchModel::SearchType Geocoder::GetSearchTypeInGeocoding(uint32_t featureId) return SearchModel::SEARCH_TYPE_VILLAGE; FeatureType feature; - m_context->m_vector.GetByIndex(featureId, feature); + m_context->GetFeature(featureId, feature); return m_model.GetSearchType(feature); } diff --git a/search/v2/mwm_context.cpp b/search/v2/mwm_context.cpp index 538c240b3c..af61657aa4 100644 --- a/search/v2/mwm_context.cpp +++ b/search/v2/mwm_context.cpp @@ -21,10 +21,21 @@ MwmContext::MwmContext(MwmSet::MwmHandle handle) { } -void MwmContext::GetFeature(uint32_t index, FeatureType & ft) const +bool MwmContext::GetFeature(uint32_t index, FeatureType & ft) const { - m_vector.GetByIndex(index, ft); - ft.SetID(FeatureID(GetId(), index)); + switch (GetEditedStatus(index)) + { + case osm::Editor::FeatureStatus::Deleted: + return false; + case osm::Editor::FeatureStatus::Modified: + case osm::Editor::FeatureStatus::Created: + VERIFY(osm::Editor::Instance().GetEditedFeature(GetId(), index, ft), ()); + return true; + case osm::Editor::FeatureStatus::Untouched: + m_vector.GetByIndex(index, ft); + ft.SetID(FeatureID(GetId(), index)); + return true; + } } } // namespace v2 diff --git a/search/v2/mwm_context.hpp b/search/v2/mwm_context.hpp index 3e76188dff..108da07843 100644 --- a/search/v2/mwm_context.hpp +++ b/search/v2/mwm_context.hpp @@ -35,6 +35,7 @@ struct MwmContext { ForEachIndexImpl(intervals, scale, [&](uint32_t index) { + // TODO: Optimize deleted checks by getting vector of deleted indexes from the Editor. if (GetEditedStatus(index) != osm::Editor::FeatureStatus::Deleted) fn(index); }); @@ -50,25 +51,12 @@ struct MwmContext [&](uint32_t index) { FeatureType ft; - - switch (GetEditedStatus(index)) - { - case osm::Editor::FeatureStatus::Deleted: return; - case osm::Editor::FeatureStatus::Modified: - VERIFY(osm::Editor::Instance().GetEditedFeature(GetId(), index, ft), ()); + if (GetFeature(index, ft)) fn(ft); - return; - case osm::Editor::FeatureStatus::Created: - CHECK(false, ("Created features index should be generated.")); - case osm::Editor::FeatureStatus::Untouched: break; - } - - GetFeature(index, ft); - fn(ft); }); } - void GetFeature(uint32_t index, FeatureType & ft) const; + bool GetFeature(uint32_t index, FeatureType & ft) const; private: osm::Editor::FeatureStatus GetEditedStatus(uint32_t index) const @@ -79,6 +67,7 @@ private: template void ForEachIndexImpl(covering::IntervalsT const & intervals, uint32_t scale, TFn && fn) const { + // TODO(vng): checkUnique is not used in this code. Do we really need it? CheckUniqueIndexes checkUnique(m_value.GetHeader().GetFormat() >= version::Format::v5); for (auto const & i : intervals) m_index.ForEachInIntervalAndScale([&] (uint32_t index) { fn(index); }, i.first, i.second, scale); diff --git a/search/v2/street_vicinity_loader.cpp b/search/v2/street_vicinity_loader.cpp index 5f88ba1302..235cbc7256 100644 --- a/search/v2/street_vicinity_loader.cpp +++ b/search/v2/street_vicinity_loader.cpp @@ -49,7 +49,8 @@ StreetVicinityLoader::Street const & StreetVicinityLoader::GetStreet(uint32_t fe void StreetVicinityLoader::LoadStreet(uint32_t featureId, Street & street) { FeatureType feature; - m_context->GetFeature(featureId, feature); + if (!m_context->GetFeature(featureId, feature)) + return; // Feature was deleted by user. if (feature.GetFeatureType() != feature::GEOM_LINE) return; diff --git a/search/v2/street_vicinity_loader.hpp b/search/v2/street_vicinity_loader.hpp index ea3f32b7dd..e260cd564e 100644 --- a/search/v2/street_vicinity_loader.hpp +++ b/search/v2/street_vicinity_loader.hpp @@ -68,7 +68,8 @@ public: continue; FeatureType ft; - m_context->GetFeature(id, ft); + if (!m_context->GetFeature(id, ft)) + continue; // Feature was deleted. if (calculator.GetProjection(feature::GetCenter(ft, FeatureType::WORST_GEOMETRY), proj) && proj.m_distMeters <= offsetMeters)