From 50586f733615712eb70b358f75257afa47ca4d78 Mon Sep 17 00:00:00 2001 From: vng Date: Tue, 6 Dec 2011 18:51:35 +0300 Subject: [PATCH] [Experimental] Code for advanced definition of countries, needed to download for frame. --- indexer/mwm_set.cpp | 5 +++++ indexer/mwm_set.hpp | 2 ++ map/feature_vec_model.hpp | 5 +++++ map/framework.cpp | 16 ++++++++++++++-- map/framework.hpp | 9 ++++----- map/partial_render_policy.cpp | 5 +++++ map/partial_render_policy.hpp | 1 + map/render_policy.hpp | 3 +++ map/render_policy_mt.cpp | 5 +++++ map/render_policy_mt.hpp | 1 + map/render_queue.hpp | 3 +++ map/render_queue_routine.hpp | 5 +++++ search/search_engine.cpp | 5 +++++ search/search_engine.hpp | 2 ++ storage/country_info.cpp | 11 +++++++++++ storage/country_info.hpp | 1 + 16 files changed, 72 insertions(+), 7 deletions(-) diff --git a/indexer/mwm_set.cpp b/indexer/mwm_set.cpp index 10b946e298..eeb275cdac 100644 --- a/indexer/mwm_set.cpp +++ b/indexer/mwm_set.cpp @@ -153,6 +153,11 @@ void MwmSet::Remove(string const & fileName) } } +bool MwmSet::IsLoaded(string const & fName) const +{ + return (const_cast(this)->GetIdByName(fName + DATA_FILE_EXTENSION) != INVALID_MWM_ID); +} + void MwmSet::GetMwmInfo(vector & info) const { threads::MutexGuard mutexGuard(m_lock); diff --git a/indexer/mwm_set.hpp b/indexer/mwm_set.hpp index 0f5172b98b..c9f30d23fb 100644 --- a/indexer/mwm_set.hpp +++ b/indexer/mwm_set.hpp @@ -71,6 +71,8 @@ public: // Remove mwm. void Remove(string const & fileName); + bool IsLoaded(string const & fName) const; + // Get ids of all mwms. Some of them may be marked to remove. void GetMwmInfo(vector & info) const; diff --git a/map/feature_vec_model.hpp b/map/feature_vec_model.hpp index 53507bf7fd..1d3c47df2f 100644 --- a/map/feature_vec_model.hpp +++ b/map/feature_vec_model.hpp @@ -39,6 +39,11 @@ namespace model void Clean(); void ClearCaches(); + inline bool IsLoaded(string const & fName) const + { + return m_multiIndex.IsLoaded(fName); + } + /// @name Features enumeration. //@{ template diff --git a/map/framework.cpp b/map/framework.cpp index 8c84022ef8..5bea1ee281 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -155,10 +155,12 @@ void Framework::GetLocalMaps(vector & outMaps) outMaps.erase(unique(outMaps.begin(), outMaps.end()), outMaps.end()); } -bool Framework::IsEmptyModel() +/* +bool Framework::IsEmptyModel() const { return m_model.GetWorldRect() == m2::RectD::GetEmptyRect(); } +*/ // Cleanup. void Framework::Clean() @@ -286,6 +288,15 @@ void Framework::DrawModel(shared_ptr const & e, Invalidate(); } +bool Framework::IsEmptyModel(m2::PointD const & pt) +{ + string const fName = GetSearchEngine()->GetCountryFile(pt); + if (fName.empty()) + return false; + + return !m_model.IsLoaded(fName); +} + void Framework::BeginPaint(shared_ptr const & e) { m_renderPolicy->BeginFrame(e, m_navigator.Screen()); @@ -307,7 +318,7 @@ void Framework::DoPaint(shared_ptr const & e) m_informationDisplay.setDebugInfo(0/*m_renderQueue.renderState().m_duration*/, my::rounds(GetCurrentScale())); - m_informationDisplay.enableRuler(!IsEmptyModel()); + m_informationDisplay.enableRuler(true/*!IsEmptyModel()*/); m2::PointD const center = m_navigator.Screen().GlobalRect().GlobalCenter(); @@ -634,6 +645,7 @@ void Framework::SetRenderPolicy(RenderPolicy * renderPolicy) if (m_renderPolicy.get()) { m_renderPolicy->SetRenderFn(DrawModelFn()); + m_renderPolicy->SetEmptyModelFn(bind(&Framework::IsEmptyModel, this, _1)); m_navigator.SetSupportRotation(m_renderPolicy->DoSupportRotation()); diff --git a/map/framework.hpp b/map/framework.hpp index 561b6b19f9..5750676199 100644 --- a/map/framework.hpp +++ b/map/framework.hpp @@ -125,10 +125,6 @@ public: void SetRenderPolicy(RenderPolicy * renderPolicy); RenderPolicy * GetRenderPolicy() const; - bool IsEmptyModel(); - - InformationDisplay & GetInformationDisplay(); - // Cleanup. void Clean(); @@ -220,5 +216,8 @@ public: void DoScale(ScaleEvent const & e); void StopScale(ScaleEvent const & e); //@} -}; +private: + //bool IsEmptyModel() const; + bool IsEmptyModel(m2::PointD const & pt); +}; diff --git a/map/partial_render_policy.cpp b/map/partial_render_policy.cpp index 7134e601a0..3022f0531f 100644 --- a/map/partial_render_policy.cpp +++ b/map/partial_render_policy.cpp @@ -140,6 +140,11 @@ void PartialRenderPolicy::SetRenderFn(TRenderFn renderFn) m_renderQueue->initializeGL(m_primaryRC, m_resourceManager); } +void PartialRenderPolicy::SetEmptyModelFn(TEmptyModelFn const & checkFn) +{ + m_renderQueue->SetEmptyModelFn(checkFn); +} + PartialRenderPolicy::~PartialRenderPolicy() { LOG(LINFO, ("destroying PartialRenderPolicy")); diff --git a/map/partial_render_policy.hpp b/map/partial_render_policy.hpp index 100d0ab8f0..0f04333b24 100644 --- a/map/partial_render_policy.hpp +++ b/map/partial_render_policy.hpp @@ -61,4 +61,5 @@ public: RenderQueue & GetRenderQueue(); void SetRenderFn(TRenderFn renderFn); + void SetEmptyModelFn(TEmptyModelFn const & checkFn); }; diff --git a/map/render_policy.hpp b/map/render_policy.hpp index 15b00bb194..baf0591cff 100644 --- a/map/render_policy.hpp +++ b/map/render_policy.hpp @@ -35,6 +35,8 @@ public: m2::RectD const &, int)> TRenderFn; + typedef function TEmptyModelFn; + protected: yg::Color m_bgColor; @@ -77,6 +79,7 @@ public: /// the start point of rendering in renderpolicy. virtual void SetRenderFn(TRenderFn renderFn); + virtual void SetEmptyModelFn(TEmptyModelFn const &) {} bool DoSupportRotation() const; bool IsTiling() const; diff --git a/map/render_policy_mt.cpp b/map/render_policy_mt.cpp index c2f04a99e9..b68048f036 100644 --- a/map/render_policy_mt.cpp +++ b/map/render_policy_mt.cpp @@ -138,6 +138,11 @@ void RenderPolicyMT::SetRenderFn(TRenderFn renderFn) m_renderQueue->initializeGL(m_primaryRC, m_resourceManager); } +void RenderPolicyMT::SetEmptyModelFn(TEmptyModelFn const & checkFn) +{ + m_renderQueue->SetEmptyModelFn(checkFn); +} + m2::RectI const RenderPolicyMT::OnSize(int w, int h) { RenderPolicy::OnSize(w, h); diff --git a/map/render_policy_mt.hpp b/map/render_policy_mt.hpp index 419248de64..76140f9ea8 100644 --- a/map/render_policy_mt.hpp +++ b/map/render_policy_mt.hpp @@ -46,4 +46,5 @@ public: RenderQueue & GetRenderQueue(); void SetRenderFn(TRenderFn renderFn); + void SetEmptyModelFn(TEmptyModelFn const & checkFn); }; diff --git a/map/render_queue.hpp b/map/render_queue.hpp index bd074a2f7b..eeb9e0100c 100644 --- a/map/render_queue.hpp +++ b/map/render_queue.hpp @@ -54,6 +54,9 @@ public: void SetRedrawAll(); + template + inline void SetEmptyModelFn(TFn const & fn) { m_routine->SetEmptyModelFn(fn); } + void SetVisualScale(double visualScale); /// add window handle to notify when rendering operation finishes diff --git a/map/render_queue_routine.hpp b/map/render_queue_routine.hpp index b4b31749a9..a94bae1eed 100644 --- a/map/render_queue_routine.hpp +++ b/map/render_queue_routine.hpp @@ -40,6 +40,7 @@ class RenderQueueRoutine : public threads::IRoutine public: typedef function, ScreenBase const &, m2::RectD const &, m2::RectD const &, int)> render_fn_t; + typedef function TEmptyModelFn; private: @@ -92,6 +93,8 @@ private: yg::Color m_bgColor; ThreadedList * m_glQueue; + TEmptyModelFn m_emptyModelFn; + void waitForRenderCommand(list > & cmdList, threads::ConditionGuard & guard); @@ -114,6 +117,8 @@ public: void onSize(int w, int h); + void SetEmptyModelFn(TEmptyModelFn const checkFn) { m_emptyModelFn = checkFn; } + /// Check, whether the resize command is queued, and resize accordingly. void processResize(ScreenBase const & frameScreen); /// Get update areas for the current render state diff --git a/search/search_engine.cpp b/search/search_engine.cpp index b9ce1545e0..2288846040 100644 --- a/search/search_engine.cpp +++ b/search/search_engine.cpp @@ -100,4 +100,9 @@ void Engine::Search(string const & queryText, function co f(Result::GetEndResult()); } +string Engine::GetCountryFile(m2::PointD const & pt) const +{ + return m_pData->m_infoGetter.GetRegionFile(pt); +} + } // namespace search diff --git a/search/search_engine.hpp b/search/search_engine.hpp index 3ee33f679b..a1c1e50689 100644 --- a/search/search_engine.hpp +++ b/search/search_engine.hpp @@ -36,6 +36,8 @@ public: void SetPreferredLanguage(int lang); void Search(string const & query, function const & f); + string GetCountryFile(m2::PointD const & pt) const; + private: void InitializeCategoriesAndSuggestStrings(CategoriesHolder const & categories); diff --git a/storage/country_info.cpp b/storage/country_info.cpp index 2e44a10e65..7eaf7a5198 100644 --- a/storage/country_info.cpp +++ b/storage/country_info.cpp @@ -53,6 +53,17 @@ namespace storage return true; } + string CountryInfoGetter::GetRegionFile(m2::PointD const & pt) const + { + GetByPoint doGet(*this, pt); + ForEachCountry(pt, doGet); + + if (doGet.m_res != -1) + return m_countries[doGet.m_res].m_name; + else + return string(); + } + string CountryInfoGetter::GetRegionName(m2::PointD const & pt) const { GetByPoint doGet(*this, pt); diff --git a/storage/country_info.hpp b/storage/country_info.hpp index 45f0c6180b..4c4a3fd41e 100644 --- a/storage/country_info.hpp +++ b/storage/country_info.hpp @@ -32,6 +32,7 @@ namespace storage public: CountryInfoGetter(ModelReaderPtr polyR, ModelReaderPtr countryR); + string GetRegionFile(m2::PointD const & pt) const; string GetRegionName(m2::PointD const & pt) const; string GetRegionName(string const & id) const; };