Take streets into account.

This commit is contained in:
Sergey Magidovich 2016-01-21 14:43:09 +03:00 committed by Sergey Yershov
parent 9338907ae8
commit bd2c286e89
7 changed files with 40 additions and 33 deletions

View file

@ -81,8 +81,6 @@ public:
};
*/
inline StringUtf8Multilang const & GetNames() const { return m_params.name; }
template <class T>
inline bool ForEachName(T && fn) const
{

View file

@ -6,9 +6,9 @@
#include "base/assert.hpp"
#include "base/stl_add.hpp"
#include "std/algorithm.hpp"
#include "std/bind.hpp"
#include "std/set.hpp"
#include "std/vector.hpp"
using namespace feature;
@ -40,14 +40,15 @@ void TypesHolder::Remove(uint32_t t)
(void) RemoveIf(EqualFunctor<uint32_t>(t));
}
bool feature::operator==(TypesHolder const & a, TypesHolder const & b)
bool TypesHolder::Equals(TypesHolder const & other) const
{
return set<uint32_t>(a.begin(), a.end()) == set<uint32_t>(b.begin(), b.end());
}
vector<uint32_t> my(this->begin(), this->end());
vector<uint32_t> his(other.begin(), other.end());
bool feature::operator!=(TypesHolder const & a, TypesHolder const & b)
{
return !(a == b);
sort(::begin(my), ::end(my));
sort(::begin(his), ::end(his));
return my == his;
}
namespace

View file

@ -110,8 +110,9 @@ namespace feature
/// Sort types by it's specification (more detailed type goes first).
void SortBySpec();
friend bool operator==(TypesHolder const & a, TypesHolder const & b);
friend bool operator!=(TypesHolder const & a, TypesHolder const & b);
/// Returns true if this->m_types and other.m_types contain same values
/// in any order. Works in O(n log n).
bool Equals(TypesHolder const & other) const;
};
inline string DebugPrint(TypesHolder const & t)

View file

@ -77,14 +77,9 @@ public:
}
}
inline friend bool operator==(MetadataBase const & a, MetadataBase const & b)
inline bool Equals(MetadataBase const & other) const
{
return a.m_metadata == b.m_metadata;
}
inline friend bool operator!=(MetadataBase const & a, MetadataBase const & b)
{
return !(a == b);
return m_metadata == other.m_metadata;
}
protected:

View file

@ -207,18 +207,19 @@ uint32_t MigrateFeatureIndex(XMLFeature const & /*xml*/)
return 0;
}
bool AreFeaturesEqualButStreat(FeatureType const & a, FeatureType const & b)
/// Compares editable fields connected with feature ignoring street.
bool AreFeaturesEqualButStreet(FeatureType const & a, FeatureType const & b)
{
feature::TypesHolder const aTypes(a);
feature::TypesHolder const bTypes(b);
if (aTypes != bTypes)
if (!aTypes.Equals(bTypes))
return false;
if (a.GetHouseNumber() != b.GetHouseNumber())
return false;
if (a.GetMetadata() != b.GetMetadata())
if (!a.GetMetadata().Equals(b.GetMetadata()))
return false;
if (a.GetNames() != b.GetNames())
@ -447,9 +448,8 @@ void Editor::EditFeature(FeatureType const & editedFeature, string const & edite
fti.m_feature.SetHouseNumber(editedHouseNumber);
// TODO(AlexZ): Store edited house number as house name if feature::IsHouseNumber() returned false.
if (AreFeaturesEqualButStreat(fti.m_feature, *originalFeaturePtr)
// TODO(mgsergio): Handle street as well.
)
if (AreFeaturesEqualButStreet(fti.m_feature, *originalFeaturePtr) &&
m_featureOriginalStreet(editedFeature) == editedStreet)
{
// We always have a feature with fid.m_mwmId, fid.m_index at the point.
// Either it was set previously or just now on quering m_features. See code above.
@ -457,7 +457,6 @@ void Editor::EditFeature(FeatureType const & editedFeature, string const & edite
// TODO(AlexZ): Synchronize Save call/make it on a separate thread.
Save(GetEditorFilePath());
Invalidate();
return;
}
@ -672,16 +671,16 @@ void Editor::UploadChanges(string const & key, string const & secret, TChangeset
void Editor::RemoveFeatureFromStorage(MwmSet::MwmId const & mwmId, uint32_t index)
{
auto mwmMatched = m_features.find(mwmId);
if (mwmMatched == m_features.end())
auto matchedMwm = m_features.find(mwmId);
if (matchedMwm == m_features.end())
return;
auto matchedIndex = mwmMatched->second.find(index);
if (matchedIndex != mwmMatched->second.end())
mwmMatched->second.erase(matchedIndex);
auto matchedIndex = matchedMwm->second.find(index);
if (matchedIndex != matchedMwm->second.end())
matchedMwm->second.erase(matchedIndex);
if (mwmMatched->second.empty())
m_features.erase(mwmMatched);
if (matchedMwm->second.empty())
m_features.erase(matchedMwm);
}
void Editor::Invalidate()

View file

@ -29,6 +29,7 @@ public:
using TMwmIdByMapNameFn = function<MwmSet::MwmId(string const & /*map*/)>;
using TInvalidateFn = function<void()>;
using TFeatureLoaderFn = function<unique_ptr<FeatureType> (FeatureID const & /*fid*/)>;
using TFeatureOriginalStreetFn = function<string(FeatureType const & /*ft*/)>;
enum class FeatureStatus
{
@ -43,6 +44,7 @@ public:
void SetMwmIdByNameAndVersionFn(TMwmIdByMapNameFn const & fn) { m_mwmIdByMapNameFn = fn; }
void SetInvalidateFn(TInvalidateFn const & fn) { m_invalidateFn = fn; }
void SetFeatureLoaderFn(TFeatureLoaderFn const & fn) { m_featureLoaderFn = fn; }
void SetFeatureOriginalStretFn(TFeatureOriginalStreetFn const & fn) { m_featureOriginalStreet = fn; }
void LoadMapEdits();
@ -118,6 +120,8 @@ private:
TInvalidateFn m_invalidateFn;
/// Get FeatureType from mwm.
TFeatureLoaderFn m_featureLoaderFn;
/// Get feature original street name or empty string.
TFeatureOriginalStreetFn m_featureOriginalStreet;
}; // class Editor
inline string DebugPrint(Editor::FeatureStatus fs)

View file

@ -17,6 +17,7 @@
#include "search/geometry_utils.hpp"
#include "search/intermediate_result.hpp"
#include "search/result.hpp"
#include "search/reverse_geocoder.hpp"
#include "search/search_engine.hpp"
#include "search/search_query_factory.hpp"
@ -335,6 +336,14 @@ Framework::Framework()
feature->ParseEverything();
return feature;
});
editor.SetFeatureOriginalStretFn([this](FeatureType const & ft) -> string
{
search::ReverseGeocoder const coder(m_model.GetIndex());
auto const streets = coder.GetNearbyFeatureStreets(ft);
if (streets.second < streets.first.size())
return streets.first[streets.second].m_name;
return {};
});
editor.LoadMapEdits();
}