[debug] Added command to “search” by feature id

This commit is contained in:
r.kuznetsov 2019-04-23 14:31:51 +03:00 committed by mpimenov
parent 9e0e9ceb07
commit 293102a022
2 changed files with 64 additions and 0 deletions

View file

@ -99,6 +99,7 @@
#include "base/math.hpp"
#include "base/scope_guard.hpp"
#include "base/stl_helpers.hpp"
#include "base/string_utils.hpp"
#include "base/timer.hpp"
#include "std/algorithm.hpp"
@ -2996,6 +2997,39 @@ bool Framework::ParseEditorDebugCommand(search::SearchParams const & params)
osm::Editor::Instance().ClearAllLocalEdits();
return true;
}
static std::string const kFindFeatureDebugKey = "?fid ";
if (params.m_query.find(kFindFeatureDebugKey) == 0)
{
// Format: ?fid<space>index<space>.
auto fidStr = params.m_query.substr(kFindFeatureDebugKey.size());
bool const canSearch = !fidStr.empty() && fidStr.back() == ' ';
strings::Trim(fidStr);
uint32_t index = 0;
if (canSearch && strings::to_uint(fidStr, index))
{
bool isShown = false;
auto const features = FindFeaturesByIndex(index);
for (auto const & fid : features)
{
FeaturesLoaderGuard guard(m_model.GetDataSource(), fid.m_mwmId);
auto ft = guard.GetFeatureByIndex(fid.m_index);
if (!ft)
continue;
// Show the first feature on the map.
if (!isShown)
{
ShowFeatureByMercator(feature::GetCenter(*ft));
isShown = true;
}
// Log found features.
LOG(LINFO, ("Feature found:", fid, MercatorBounds::ToLatLon(feature::GetCenter(*ft))));
}
}
return true;
}
return false;
}
@ -3643,6 +3677,33 @@ MwmSet::MwmId Framework::GetMwmIdByName(string const & name) const
return m_model.GetDataSource().GetMwmIdByCountryFile(platform::CountryFile(name));
}
vector<FeatureID> Framework::FindFeaturesByIndex(uint32_t featureIndex) const
{
vector<FeatureID> result;
auto mwms = GetMwmsByRect(m_currentModelView.ClipRect(), false /* rough */);
set<MwmSet::MwmId> s(mwms.begin(), mwms.end());
vector<shared_ptr<LocalCountryFile>> maps;
m_storage.GetLocalMaps(maps);
for (auto const & localFile : maps)
{
auto mwmId = GetMwmIdByName(localFile->GetCountryName());
if (s.find(mwmId) != s.end())
continue;
if (mwmId.IsAlive())
mwms.push_back(move(mwmId));
}
for (auto const & mwmId : mwms)
{
FeaturesLoaderGuard const guard(m_model.GetDataSource(), mwmId);
if (featureIndex < guard.GetNumFeatures() && guard.GetFeatureByIndex(featureIndex))
result.emplace_back(mwmId, featureIndex);
}
return result;
}
void Framework::ReadFeatures(function<void(FeatureType &)> const & reader,
vector<FeatureID> const & features)
{

View file

@ -427,6 +427,9 @@ public:
vector<MwmSet::MwmId> GetMwmsByRect(m2::RectD const & rect, bool rough) const;
MwmSet::MwmId GetMwmIdByName(string const & name) const;
// Use only for debug purposes!
vector<FeatureID> FindFeaturesByIndex(uint32_t featureIndex) const;
void ReadFeatures(function<void(FeatureType &)> const & reader,
vector<FeatureID> const & features);