1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
#include "map/feature_vec_model.hpp"
#include "platform/platform.hpp"
#include "indexer/cell_coverer.hpp"
#include "indexer/scales.hpp"
#include "indexer/classificator_loader.hpp"
#include "base/assert.hpp"
#include "base/logging.hpp"
#include "std/bind.hpp"
using platform::CountryFile;
using platform::LocalCountryFile;
namespace model
{
FeaturesFetcher::FeaturesFetcher()
{
m_dataSource.AddObserver(*this);
}
FeaturesFetcher::~FeaturesFetcher()
{
m_dataSource.RemoveObserver(*this);
}
// While reading any files (classificator or mwm), there are 2 types of possible exceptions:
// Reader::Exception, FileAbsentException.
// Let's process RootException everywhere, to supress such errors.
void FeaturesFetcher::InitClassificator()
{
try
{
classificator::Load();
}
catch (RootException const & e)
{
LOG(LERROR, ("Classificator read error: ", e.what()));
}
}
pair<MwmSet::MwmId, MwmSet::RegResult> FeaturesFetcher::RegisterMap(
LocalCountryFile const & localFile)
{
try
{
auto result = m_dataSource.RegisterMap(localFile);
if (result.second != MwmSet::RegResult::Success)
{
LOG(LWARNING, ("Can't add map", localFile.GetCountryName(), "(", result.second, ").",
"Probably it's already added or has newer data version."));
}
else
{
MwmSet::MwmId const & id = result.first;
ASSERT(id.IsAlive(), ());
m_rect.Add(id.GetInfo()->m_bordersRect);
}
return result;
}
catch (RootException const & ex)
{
LOG(LERROR, ("IO error while adding", localFile.GetCountryName(), "map.", ex.Msg()));
return make_pair(MwmSet::MwmId(), MwmSet::RegResult::BadFile);
}
}
bool FeaturesFetcher::DeregisterMap(CountryFile const & countryFile)
{
return m_dataSource.Deregister(countryFile);
}
void FeaturesFetcher::Clear() { m_dataSource.Clear(); }
void FeaturesFetcher::ClearCaches()
{
m_dataSource.ClearCache();
}
void FeaturesFetcher::OnMapUpdated(platform::LocalCountryFile const & newFile,
platform::LocalCountryFile const & oldFile)
{
if (m_onMapDeregistered)
m_onMapDeregistered(oldFile);
}
void FeaturesFetcher::OnMapDeregistered(platform::LocalCountryFile const & localFile)
{
if (m_onMapDeregistered)
m_onMapDeregistered(localFile);
}
m2::RectD FeaturesFetcher::GetWorldRect() const
{
if (m_rect == m2::RectD())
{
// rect is empty when now countries are loaded
// return max global rect
return MercatorBounds::FullRect();
}
return m_rect;
}
}
|