[search][editor] Correctly process Modified and Created features.

Partially process deleted features.
This commit is contained in:
Alex Zolotarev 2016-03-05 22:12:34 +03:00 committed by Sergey Yershov
parent 4fc5dc218a
commit 36b83eb5c9
6 changed files with 29 additions and 23 deletions

View file

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

View file

@ -152,7 +152,8 @@ public:
void GetNames(uint32_t featureId, vector<string> & 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);
}

View file

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

View file

@ -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 <class TFn> 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);

View file

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

View file

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