Welcome to mirror list, hosted at ThFree Co, Russian Federation.

framework.hpp « map - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: dce076fbd1e1ddaa939852a56a022dcaaaaf751c (plain)
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
#pragma once

#include "events.hpp"
#include "drawer_yg.hpp"
#include "tile_renderer.hpp"
#include "information_display.hpp"
#include "window_handle.hpp"
#include "location_state.hpp"
#include "navigator.hpp"

#include "../defines.hpp"

#include "../indexer/mercator.hpp"
#include "../indexer/data_header.hpp"
#include "../indexer/scales.hpp"

#include "../platform/platform.hpp"
#include "../platform/location.hpp"

#include "../yg/defines.hpp"
#include "../yg/screen.hpp"
#include "../yg/color.hpp"
#include "../yg/render_state.hpp"
#include "../yg/skin.hpp"
#include "../yg/resource_manager.hpp"
#include "../yg/info_layer.hpp"

#include "../coding/file_reader.hpp"
#include "../coding/file_writer.hpp"

#include "../geometry/rect2d.hpp"
#include "../geometry/screenbase.hpp"

#include "../base/logging.hpp"
#include "../base/mutex.hpp"
#include "../base/timer.hpp"

#include "../std/bind.hpp"
#include "../std/function.hpp"
#include "../std/vector.hpp"
#include "../std/shared_ptr.hpp"
#include "../std/target_os.hpp"

#include "../search/search_engine.hpp"

//#define DRAW_TOUCH_POINTS

namespace search { class Engine; }

struct BenchmarkRectProvider;

namespace search { class Result; }
typedef function<void (search::Result const &)> SearchCallbackT;

typedef function<void (location::TLocationStatus)> LocationRetrievedCallbackT;

class DrawerYG;
class RenderPolicy;

struct PathAppender
{
  string const & m_path;
  PathAppender(string const & path) : m_path(path) {}
  void operator()(string & elem)
  {
    elem.insert(elem.begin(), m_path.begin(), m_path.end());
  }
};

class ReadersAdder
{
protected:

  typedef vector<string> maps_list_t;

private:
  Platform & m_pl;
  maps_list_t & m_lst;

public:
  ReadersAdder(Platform & pl, maps_list_t & lst) : m_pl(pl), m_lst(lst) {}

  void operator() (string const & name)
  {
    m_lst.push_back(name);
  }
};

template
<
  class TModel
>
class Framework
{
protected:
  typedef TModel model_t;

  typedef Framework<model_t> this_type;

  scoped_ptr<search::Engine> m_pSearchEngine;
  model_t m_model;
  Navigator m_navigator;

  shared_ptr<WindowHandle> m_windowHandle;
  shared_ptr<RenderPolicy> m_renderPolicy;

  InformationDisplay m_informationDisplay;

  double const m_metresMinWidth;
  double const m_metresMaxWidth;
  int const m_minRulerWidth;

  enum TGpsCenteringMode
  {
    EDoNothing,
    ECenterAndScale,
    ECenterOnly
  };

  TGpsCenteringMode m_centeringMode;
  LocationRetrievedCallbackT m_locationObserver;
  location::State m_locationState;

  mutable threads::Mutex m_modelSyn;

  int m_tileSize;

  my::Timer m_timer;

  typedef typename TModel::ReaderT ReaderT;

  void AddMap(string const & file);
  void RemoveMap(string const & datFile);

public:
  void OnGpsUpdate(location::GpsInfo const & info);

  void OnCompassUpdate(location::CompassInfo const & info);

  Framework(shared_ptr<WindowHandle> windowHandle,
            size_t bottomShift);

  void SetRenderPolicy(shared_ptr<RenderPolicy> const & rp);

  void InitializeGL(shared_ptr<yg::gl::RenderContext> const & primaryContext,
                    shared_ptr<yg::ResourceManager> const & resourceManager);

  model_t & get_model();

  typedef vector<string> maps_list_t;
  virtual void EnumLocalMaps(maps_list_t & filesList);

  /// Initialization.
  template <class TStorage>
  void InitStorage(TStorage & storage)
  {
    m_model.InitClassificator();

    typename TStorage::TEnumMapsFunction enumMapsFn;

    enumMapsFn = bind(&Framework::EnumLocalMaps, this, _1);

    LOG(LINFO, ("Initializing storage"));
    // initializes model with locally downloaded maps
    storage.Init(bind(&Framework::AddMap, this, _1),
                 bind(&Framework::RemoveMap, this, _1),
                 bind(&Framework::InvalidateRect, this, _1),
                 enumMapsFn);
    LOG(LINFO, ("Storage initialized"));
  }

  void StartLocationService(LocationRetrievedCallbackT observer);
  void StopLocationService();

  bool IsEmptyModel();

  // Cleanup.
  void Clean();

  void PrepareToShutdown();

public:

  void DrawModel(shared_ptr<PaintEvent> const & e,
                 ScreenBase const & screen,
                 m2::RectD const & selectRect,
                 m2::RectD const & clipRect,
                 int scaleLevel,
                 bool isTiling);

  void Search(string const & text, SearchCallbackT callback);
  search::Engine * GetSearchEngine();

  void SetMaxWorldRect();

  void Invalidate();
  void InvalidateRect(m2::RectD const & rect);

  void SaveState();
  bool LoadState();

  /// Resize event from window.
  virtual void OnSize(int w, int h);

  bool SetUpdatesEnabled(bool doEnable);

  /// respond to device orientation changes
  void SetOrientation(EOrientation orientation);

  double GetCurrentScale() const;

  m2::PointD GetViewportCenter() const;
  void SetViewportCenter(m2::PointD const & pt);

  bool NeedRedraw() const;
  void SetNeedRedraw(bool flag);

  virtual void BeginPaint(shared_ptr<PaintEvent> const & e);
  /// Function for calling from platform dependent-paint function.
  virtual void DoPaint(shared_ptr<PaintEvent> const & e);

  virtual void EndPaint(shared_ptr<PaintEvent> const & e);

  void ShowRect(m2::RectD rect);

  void MemoryWarning();

  void EnterBackground();

  void EnterForeground();

  /// @TODO refactor to accept point and min visible length
  void CenterAndScaleViewport();

  /// Show all model by it's world rect.
  void ShowAll();

  /// @name Drag implementation.
  //@{
  void StartDrag(DragEvent const & e);
  void DoDrag(DragEvent const & e);
  void StopDrag(DragEvent const & e);
  void Move(double azDir, double factor);
  //@}

  /// @name Rotation implementation
  //@{
  void StartRotate(RotateEvent const & e);
  void DoRotate(RotateEvent const & e);
  void StopRotate(RotateEvent const & e);
  //@}

  /// @name Scaling.
  //@{
  void ScaleToPoint(ScaleToPointEvent const & e);
  void ScaleDefault(bool enlarge);
  void Scale(double scale);
  void StartScale(ScaleEvent const & e);
  void DoScale(ScaleEvent const & e);
  void StopScale(ScaleEvent const & e);
  //@}
};