diff options
author | r.kuznetsov <r.kuznetsov@corp.mail.ru> | 2019-04-23 14:31:51 +0300 |
---|---|---|
committer | mpimenov <mpimenov@users.noreply.github.com> | 2019-04-26 16:42:05 +0300 |
commit | 293102a022e8bf9206b5b116450ce3213eeeb045 (patch) | |
tree | 09a4af1c0129d528297297ffb7104d48ec988d91 /map | |
parent | 9e0e9ceb07d7410951976af316d4b4d2a5e17b19 (diff) |
[debug] Added command to “search” by feature id
Diffstat (limited to 'map')
-rw-r--r-- | map/framework.cpp | 61 | ||||
-rw-r--r-- | map/framework.hpp | 3 |
2 files changed, 64 insertions, 0 deletions
diff --git a/map/framework.cpp b/map/framework.cpp index 829cc0bc17..8c68e3f977 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -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) { diff --git a/map/framework.hpp b/map/framework.hpp index 8aa2f01d70..0bbd5bbe33 100644 --- a/map/framework.hpp +++ b/map/framework.hpp @@ -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); |