forked from organicmaps/organicmaps
Handle storage::TIndex to get downloaded country instead of country name.
This commit is contained in:
parent
0280b0b129
commit
15e39284a0
19 changed files with 87 additions and 56 deletions
|
@ -128,7 +128,7 @@ void BasicTilingRenderPolicy::DrawFrame(shared_ptr<PaintEvent> const & e, Screen
|
|||
{
|
||||
m_IsEmptyModel = curCvg->IsEmptyDrawingCoverage() && curCvg->IsEmptyModelAtCoverageCenter();
|
||||
if (m_IsEmptyModel)
|
||||
m_CountryName = curCvg->GetCountryNameAtCoverageCenter();
|
||||
m_countryIndex = curCvg->GetCountryIndexAtCoverageCenter();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -229,9 +229,9 @@ bool BasicTilingRenderPolicy::IsEmptyModel() const
|
|||
return m_IsEmptyModel;
|
||||
}
|
||||
|
||||
string const BasicTilingRenderPolicy::GetCountryName() const
|
||||
storage::TIndex BasicTilingRenderPolicy::GetCountryIndex() const
|
||||
{
|
||||
return m_CountryName;
|
||||
return m_countryIndex;
|
||||
}
|
||||
|
||||
bool BasicTilingRenderPolicy::NeedRedraw() const
|
||||
|
|
|
@ -2,10 +2,12 @@
|
|||
|
||||
#include "render_policy.hpp"
|
||||
|
||||
#include "../graphics/overlay.hpp"
|
||||
|
||||
#include "../geometry/screenbase.hpp"
|
||||
|
||||
#include "../std/shared_ptr.hpp"
|
||||
#include "../graphics/overlay.hpp"
|
||||
|
||||
|
||||
class TileRenderer;
|
||||
class CoverageGenerator;
|
||||
|
@ -34,7 +36,7 @@ protected:
|
|||
ScreenBase m_CurrentScreen;
|
||||
int m_DrawScale;
|
||||
bool m_IsEmptyModel;
|
||||
string m_CountryName;
|
||||
storage::TIndex m_countryIndex;
|
||||
bool m_DoRecreateCoverage;
|
||||
bool m_IsNavigating;
|
||||
bool m_WasAnimatingLastFrame;
|
||||
|
@ -72,8 +74,8 @@ public:
|
|||
bool NeedRedraw() const;
|
||||
bool IsTiling() const;
|
||||
bool IsEmptyModel() const;
|
||||
string const GetCountryName() const;
|
||||
int GetDrawScale(ScreenBase const & s) const;
|
||||
storage::TIndex GetCountryIndex() const;
|
||||
int GetDrawScale(ScreenBase const & s) const;
|
||||
size_t ScaleEtalonSize() const;
|
||||
size_t TileSize() const;
|
||||
|
||||
|
|
|
@ -217,17 +217,17 @@ void CountryStatusDisplay::UpdateStatusAndProgress()
|
|||
}
|
||||
}
|
||||
|
||||
void CountryStatusDisplay::setCountryName(string const & name)
|
||||
void CountryStatusDisplay::setCountryIndex(storage::TIndex const & idx)
|
||||
{
|
||||
if (m_fullName != name)
|
||||
if (m_countryIdx != idx)
|
||||
{
|
||||
storage::CountryInfo::FullName2GroupAndMap(name, m_mapGroupName, m_mapName);
|
||||
m_countryIdx = idx;
|
||||
|
||||
m_storage->GetGroupAndCountry(idx, m_mapGroupName, m_mapName);
|
||||
LOG(LDEBUG, (m_mapName, m_mapGroupName));
|
||||
|
||||
m_countryIdx = m_storage->FindIndexByName(m_mapName);
|
||||
UpdateStatusAndProgress();
|
||||
|
||||
m_fullName = name;
|
||||
m_notEnoughSpace = false;
|
||||
|
||||
setIsDirtyDrawing(true);
|
||||
|
|
|
@ -32,8 +32,6 @@ private:
|
|||
shared_ptr<gui::Button> m_downloadButton;
|
||||
/// country status message
|
||||
shared_ptr<gui::TextView> m_statusMsg;
|
||||
/// full name, could be in the form "Country, Province"
|
||||
string m_fullName;
|
||||
/// current map name, "Province" part of the fullName
|
||||
string m_mapName;
|
||||
/// current map group name, "Country" part of the fullName
|
||||
|
@ -73,7 +71,7 @@ public:
|
|||
/// set download button listener
|
||||
void setDownloadListener(gui::Button::TOnClickListener const & l);
|
||||
/// set current country name
|
||||
void setCountryName(string const & name);
|
||||
void setCountryIndex(storage::TIndex const & idx);
|
||||
/// reposition element
|
||||
void setPivot(m2::PointD const & pv);
|
||||
/// attach element to controller.
|
||||
|
|
|
@ -21,12 +21,12 @@ CoverageGenerator::CoverageGenerator(
|
|||
shared_ptr<graphics::RenderContext> const & primaryRC,
|
||||
shared_ptr<graphics::ResourceManager> const & rm,
|
||||
graphics::PacketsQueue * glQueue,
|
||||
RenderPolicy::TCountryNameFn countryNameFn)
|
||||
RenderPolicy::TCountryIndexFn const & countryIndexFn)
|
||||
: m_queue(1),
|
||||
m_tileRenderer(tileRenderer),
|
||||
m_sequenceID(0),
|
||||
m_windowHandle(windowHandle),
|
||||
m_countryNameFn(countryNameFn),
|
||||
m_countryIndexFn(countryIndexFn),
|
||||
m_glQueue(glQueue),
|
||||
m_skinName(skinName),
|
||||
m_fenceManager(2),
|
||||
|
@ -321,9 +321,9 @@ shared_ptr<graphics::ResourceManager> const & CoverageGenerator::resourceManager
|
|||
return m_resourceManager;
|
||||
}
|
||||
|
||||
string CoverageGenerator::GetCountryName(m2::PointD const & pt) const
|
||||
storage::TIndex CoverageGenerator::GetCountryIndex(m2::PointD const & pt) const
|
||||
{
|
||||
return m_countryNameFn(pt);
|
||||
return m_countryIndexFn(pt);
|
||||
}
|
||||
|
||||
void CoverageGenerator::CancelCommands()
|
||||
|
|
|
@ -58,7 +58,7 @@ private:
|
|||
|
||||
threads::Mutex m_mutex;
|
||||
|
||||
RenderPolicy::TCountryNameFn m_countryNameFn;
|
||||
RenderPolicy::TCountryIndexFn m_countryIndexFn;
|
||||
|
||||
graphics::PacketsQueue * m_glQueue;
|
||||
string m_skinName;
|
||||
|
@ -79,7 +79,7 @@ public:
|
|||
shared_ptr<graphics::RenderContext> const & primaryRC,
|
||||
shared_ptr<graphics::ResourceManager> const & rm,
|
||||
graphics::PacketsQueue * glQueue,
|
||||
RenderPolicy::TCountryNameFn countryNameFn);
|
||||
RenderPolicy::TCountryIndexFn const & countryIndexFn);
|
||||
|
||||
~CoverageGenerator();
|
||||
|
||||
|
@ -112,7 +112,7 @@ public:
|
|||
|
||||
void WaitForEmptyAndFinished();
|
||||
|
||||
string GetCountryName(m2::PointD const & pt) const;
|
||||
storage::TIndex GetCountryIndex(m2::PointD const & pt) const;
|
||||
|
||||
ScreenCoverage * CurrentCoverage();
|
||||
|
||||
|
|
|
@ -711,7 +711,7 @@ void Framework::DrawAdditionalInfo(shared_ptr<PaintEvent> const & e)
|
|||
bool const isEmptyModel = m_renderPolicy->IsEmptyModel();
|
||||
|
||||
if (isEmptyModel)
|
||||
m_informationDisplay.setEmptyCountryName(m_renderPolicy->GetCountryName());
|
||||
m_informationDisplay.setEmptyCountryIndex(m_renderPolicy->GetCountryIndex());
|
||||
|
||||
m_informationDisplay.enableCountryStatusDisplay(isEmptyModel);
|
||||
m_informationDisplay.enableCompassArrow(m_navigator.Screen().GetAngle() != 0);
|
||||
|
@ -1163,6 +1163,11 @@ search::Engine * Framework::GetSearchEngine() const
|
|||
return m_pSearchEngine.get();
|
||||
}
|
||||
|
||||
storage::TIndex Framework::GetCountryIndex(m2::PointD const & pt) const
|
||||
{
|
||||
return m_storage.FindIndexByFile(GetSearchEngine()->GetCountryFile(pt));
|
||||
}
|
||||
|
||||
string Framework::GetCountryName(m2::PointD const & pt) const
|
||||
{
|
||||
return GetSearchEngine()->GetCountryName(pt);
|
||||
|
@ -1281,8 +1286,7 @@ void Framework::SetRenderPolicy(RenderPolicy * renderPolicy)
|
|||
|
||||
m_guiController->SetRenderParams(rp);
|
||||
|
||||
string (Framework::*pFn)(m2::PointD const &) const = &Framework::GetCountryName;
|
||||
m_renderPolicy->SetCountryNameFn(bind(pFn, this, _1));
|
||||
m_renderPolicy->SetCountryIndexFn(bind(&Framework::GetCountryIndex, this, _1));
|
||||
|
||||
m_renderPolicy->SetRenderFn(DrawModelFn());
|
||||
|
||||
|
|
|
@ -271,6 +271,9 @@ public:
|
|||
double lat, double lon, double north,
|
||||
string & distance, double & azimut);
|
||||
|
||||
private:
|
||||
storage::TIndex GetCountryIndex(m2::PointD const & pt) const;
|
||||
public:
|
||||
string GetCountryName(m2::PointD const & pt) const;
|
||||
/// @param[in] id Country file name without an extension.
|
||||
string GetCountryName(string const & id) const;
|
||||
|
|
|
@ -393,9 +393,9 @@ void InformationDisplay::enableCountryStatusDisplay(bool doEnable)
|
|||
m_countryStatusDisplay->setIsVisible(doEnable);
|
||||
}
|
||||
|
||||
void InformationDisplay::setEmptyCountryName(string const & country)
|
||||
void InformationDisplay::setEmptyCountryIndex(storage::TIndex const & idx)
|
||||
{
|
||||
m_countryStatusDisplay->setCountryName(country);
|
||||
m_countryStatusDisplay->setCountryIndex(idx);
|
||||
}
|
||||
|
||||
void InformationDisplay::setDownloadListener(gui::Button::TOnClickListener l)
|
||||
|
|
|
@ -2,12 +2,18 @@
|
|||
|
||||
#include "window_handle.hpp"
|
||||
#include "ruler.hpp"
|
||||
|
||||
#include "../storage/index.hpp"
|
||||
|
||||
#include "../gui/button.hpp"
|
||||
|
||||
#include "../geometry/point2d.hpp"
|
||||
#include "../geometry/rect2d.hpp"
|
||||
#include "../geometry/screenbase.hpp"
|
||||
|
||||
#include "../base/timer.hpp"
|
||||
#include "../base/logging.hpp"
|
||||
#include "../gui/button.hpp"
|
||||
|
||||
|
||||
namespace location
|
||||
{
|
||||
|
@ -135,7 +141,7 @@ public:
|
|||
|
||||
void enableCountryStatusDisplay(bool doEnable);
|
||||
void setDownloadListener(gui::Button::TOnClickListener l);
|
||||
void setEmptyCountryName(string const & country);
|
||||
void setEmptyCountryIndex(storage::TIndex const & idx);
|
||||
|
||||
shared_ptr<CountryStatusDisplay> const & countryStatusDisplay() const;
|
||||
|
||||
|
|
|
@ -169,9 +169,9 @@ void RenderPolicy::SetRenderFn(TRenderFn renderFn)
|
|||
m_renderFn = renderFn;
|
||||
}
|
||||
|
||||
void RenderPolicy::SetCountryNameFn(TCountryNameFn countryNameFn)
|
||||
void RenderPolicy::SetCountryIndexFn(TCountryIndexFn const & fn)
|
||||
{
|
||||
m_countryNameFn = countryNameFn;
|
||||
m_countryIndexFn = fn;
|
||||
}
|
||||
|
||||
bool RenderPolicy::DoForceUpdate() const
|
||||
|
@ -199,11 +199,6 @@ bool RenderPolicy::IsEmptyModel() const
|
|||
return false;
|
||||
}
|
||||
|
||||
string const RenderPolicy::GetCountryName() const
|
||||
{
|
||||
return string();
|
||||
}
|
||||
|
||||
int RenderPolicy::GetDrawScale(ScreenBase const & s) const
|
||||
{
|
||||
m2::PointD textureCenter(s.PixelRect().Center());
|
||||
|
|
|
@ -2,12 +2,15 @@
|
|||
|
||||
#include "drawer.hpp"
|
||||
|
||||
#include "../storage/index.hpp"
|
||||
|
||||
#include "../graphics/color.hpp"
|
||||
|
||||
#include "../geometry/rect2d.hpp"
|
||||
|
||||
#include "../std/function.hpp"
|
||||
#include "../std/shared_ptr.hpp"
|
||||
|
||||
#include "../geometry/rect2d.hpp"
|
||||
|
||||
class PaintEvent;
|
||||
class ScreenBase;
|
||||
|
@ -47,7 +50,7 @@ public:
|
|||
bool)> TRenderFn;
|
||||
|
||||
typedef function<bool (m2::PointD const &)> TEmptyModelFn;
|
||||
typedef function<string (m2::PointD const &)> TCountryNameFn;
|
||||
typedef function<storage::TIndex (m2::PointD const &)> TCountryIndexFn;
|
||||
|
||||
protected:
|
||||
|
||||
|
@ -59,7 +62,7 @@ protected:
|
|||
shared_ptr<WindowHandle> m_windowHandle;
|
||||
shared_ptr<Drawer> m_drawer;
|
||||
TRenderFn m_renderFn;
|
||||
TCountryNameFn m_countryNameFn;
|
||||
TCountryIndexFn m_countryIndexFn;
|
||||
bool m_doSupportRotation;
|
||||
bool m_doForceUpdate;
|
||||
m2::AnyRectD m_invalidRect;
|
||||
|
@ -117,7 +120,8 @@ public:
|
|||
|
||||
/// the start point of rendering in renderpolicy.
|
||||
virtual void SetRenderFn(TRenderFn renderFn);
|
||||
virtual void SetCountryNameFn(TCountryNameFn countryNameFn);
|
||||
|
||||
void SetCountryIndexFn(TCountryIndexFn const & fn);
|
||||
void SetAnimController(anim::Controller * controller);
|
||||
|
||||
bool DoSupportRotation() const;
|
||||
|
@ -125,7 +129,7 @@ public:
|
|||
|
||||
virtual bool NeedRedraw() const;
|
||||
virtual bool IsEmptyModel() const;
|
||||
virtual string const GetCountryName() const;
|
||||
virtual storage::TIndex GetCountryIndex() const { return storage::TIndex(); }
|
||||
virtual int GetDrawScale(ScreenBase const & s) const;
|
||||
|
||||
bool DoForceUpdate() const;
|
||||
|
|
|
@ -54,7 +54,7 @@ void ScreenCoverage::CopyInto(ScreenCoverage & cvg)
|
|||
cvg.m_isEmptyDrawingCoverage = m_isEmptyDrawingCoverage;
|
||||
cvg.m_isEmptyModelAtCoverageCenter = m_isEmptyModelAtCoverageCenter;
|
||||
cvg.m_leafTilesToRender = m_leafTilesToRender;
|
||||
cvg.m_countryNameAtCoverageCenter = m_countryNameAtCoverageCenter;
|
||||
cvg.m_countryIndexAtCoverageCenter = m_countryIndexAtCoverageCenter;
|
||||
|
||||
TileCache * tileCache = &m_tileRenderer->GetTileCache();
|
||||
|
||||
|
@ -452,18 +452,18 @@ void ScreenCoverage::ResetEmptyModelAtCoverageCenter()
|
|||
m_isEmptyModelAtCoverageCenter = false;
|
||||
}
|
||||
|
||||
string ScreenCoverage::GetCountryNameAtCoverageCenter() const
|
||||
storage::TIndex ScreenCoverage::GetCountryIndexAtCoverageCenter() const
|
||||
{
|
||||
return m_countryNameAtCoverageCenter;
|
||||
return m_countryIndexAtCoverageCenter;
|
||||
}
|
||||
|
||||
void ScreenCoverage::CheckEmptyModelAtCoverageCenter()
|
||||
{
|
||||
if (!IsPartialCoverage() && IsEmptyDrawingCoverage())
|
||||
{
|
||||
m2::PointD centerPt = m_screen.GlobalRect().GetGlobalRect().Center();
|
||||
m_countryNameAtCoverageCenter = m_coverageGenerator->GetCountryName(centerPt);
|
||||
m_isEmptyModelAtCoverageCenter = !m_countryNameAtCoverageCenter.empty();
|
||||
m2::PointD const centerPt = m_screen.GlobalRect().GetGlobalRect().Center();
|
||||
m_countryIndexAtCoverageCenter = m_coverageGenerator->GetCountryIndex(centerPt);
|
||||
m_isEmptyModelAtCoverageCenter = m_countryIndexAtCoverageCenter.IsValid();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ private:
|
|||
bool m_isEmptyModelAtCoverageCenter;
|
||||
/// Which country this coverage points to at its center?
|
||||
/// It's valid only if m_isEmptyModelAtCoverageCenter is true
|
||||
string m_countryNameAtCoverageCenter;
|
||||
storage::TIndex m_countryIndexAtCoverageCenter;
|
||||
/// How many "leaf" tiles we should render to cover the screen.
|
||||
/// This is efficiently the size of newLeafTileRects and is cached for
|
||||
/// quick check.
|
||||
|
@ -110,7 +110,7 @@ public:
|
|||
void ResetEmptyModelAtCoverageCenter();
|
||||
/// What country is at this coverage center.
|
||||
/// @warning check this flag only if IsEmptyModelAtCoverageCenter is true
|
||||
string GetCountryNameAtCoverageCenter() const;
|
||||
storage::TIndex GetCountryIndexAtCoverageCenter() const;
|
||||
/// Check, whether the model is empty at the center of the coverage.
|
||||
void CheckEmptyModelAtCoverageCenter();
|
||||
/// Getter for Overlay
|
||||
|
|
|
@ -181,5 +181,5 @@ void TilingRenderPolicyMT::SetRenderFn(TRenderFn renderFn)
|
|||
m_primaryRC,
|
||||
m_resourceManager,
|
||||
0,
|
||||
m_countryNameFn));
|
||||
m_countryIndexFn));
|
||||
}
|
||||
|
|
|
@ -210,5 +210,5 @@ void TilingRenderPolicyST::SetRenderFn(TRenderFn renderFn)
|
|||
m_primaryRC,
|
||||
m_resourceManager,
|
||||
m_QueuedRenderer->GetPacketsQueue(cpuCores),
|
||||
m_countryNameFn));
|
||||
m_countryIndexFn));
|
||||
}
|
||||
|
|
|
@ -15,6 +15,8 @@ namespace storage
|
|||
TIndex(int group = INVALID, int country = INVALID, int region = INVALID)
|
||||
: m_group(group), m_country(country), m_region(region) {}
|
||||
|
||||
bool IsValid() const { return (m_group != INVALID && m_country != INVALID); }
|
||||
|
||||
bool operator==(TIndex const & other) const
|
||||
{
|
||||
return (m_group == other.m_group &&
|
||||
|
|
|
@ -99,6 +99,13 @@ namespace storage
|
|||
return NodeFromIndex(m_countries, index).Value();
|
||||
}
|
||||
|
||||
void Storage::GetGroupAndCountry(TIndex const & index, string & group, string & country) const
|
||||
{
|
||||
string fName = CountryByIndex(index).GetFile().m_fileName;
|
||||
CountryInfo::FileName2FullName(fName);
|
||||
CountryInfo::FullName2GroupAndMap(fName, group, country);
|
||||
}
|
||||
|
||||
size_t Storage::CountriesCount(TIndex const & index) const
|
||||
{
|
||||
return NodeFromIndex(m_countries, index).SiblingsCount();
|
||||
|
@ -353,21 +360,30 @@ namespace storage
|
|||
return baseUrl + OMIM_OS_NAME "/" + strings::to_string(m_currentVersion) + "/" + UrlEncode(fName);
|
||||
}
|
||||
|
||||
TIndex const Storage::FindIndexByName(string const & name) const
|
||||
bool IsEqualFileName(SimpleTree<Country> const & node, string const & name)
|
||||
{
|
||||
Country const & c = node.Value();
|
||||
if (c.GetFilesCount() > 0)
|
||||
return (c.GetFile().m_fileName == name);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
TIndex Storage::FindIndexByFile(string const & name) const
|
||||
{
|
||||
for (unsigned i = 0; i < m_countries.SiblingsCount(); ++i)
|
||||
{
|
||||
if (m_countries[i].Value().Name() == name)
|
||||
if (IsEqualFileName(m_countries[i], name))
|
||||
return TIndex(i);
|
||||
|
||||
for (unsigned j = 0; j < m_countries[i].SiblingsCount(); ++j)
|
||||
{
|
||||
if (m_countries[i][j].Value().Name() == name)
|
||||
if (IsEqualFileName(m_countries[i][j], name))
|
||||
return TIndex(i, j);
|
||||
|
||||
for (unsigned k = 0; k < m_countries[i][j].SiblingsCount(); ++k)
|
||||
{
|
||||
if (m_countries[i][j][k].Value().Name() == name)
|
||||
if (IsEqualFileName(m_countries[i][j][k], name))
|
||||
return TIndex(i, j, k);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -103,7 +103,8 @@ namespace storage
|
|||
//@}
|
||||
|
||||
Country const & CountryByIndex(TIndex const & index) const;
|
||||
TIndex const FindIndexByName(string const & name) const;
|
||||
TIndex FindIndexByFile(string const & name) const;
|
||||
void GetGroupAndCountry(TIndex const & index, string & group, string & country) const;
|
||||
|
||||
size_t CountriesCount(TIndex const & index) const;
|
||||
string const & CountryName(TIndex const & index) const;
|
||||
|
|
Loading…
Add table
Reference in a new issue