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: 98364bec7f5719fde961aef52cbe1c9f3b6a6b33 (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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
#pragma once

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

#include "../defines.hpp"

#include "../indexer/drawing_rule_def.hpp"
#include "../indexer/mercator.hpp"
#include "../indexer/data_header.hpp"
#include "../indexer/scales.hpp"
#include "../indexer/feature.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/tiler.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/profiler.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"


//#define DRAW_TOUCH_POINTS

namespace di { class DrawInfo; }
namespace drule { class BaseRule; }
namespace search { class Engine; }

class redraw_operation_cancelled {};

struct BenchmarkRectProvider;

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

namespace fwork
{
  class DrawProcessor
  {
    m2::RectD m_rect;

    ScreenBase const & m_convertor;

    shared_ptr<PaintEvent> m_paintEvent;
    vector<drule::Key> m_keys;

    int m_zoom;
    shared_ptr<yg::gl::RenderState> m_renderState;
    yg::GlyphCache * m_glyphCache;

#ifdef PROFILER_DRAWING
    size_t m_drawCount;
#endif

    inline DrawerYG * GetDrawer() const { return m_paintEvent->drawer().get(); }

    void PreProcessKeys();

    static const int reserve_rules_count = 16;

  public:

    DrawProcessor(m2::RectD const & r,
                  ScreenBase const & convertor,
                  shared_ptr<PaintEvent> const & paintEvent,
                  int scaleLevel,
                  shared_ptr<yg::gl::RenderState> const & renderState,
                  yg::GlyphCache * glyphCache);

    bool operator() (FeatureType const & f);
  };
}


typedef function<void (void)> LocationRetrievedCallbackT;

template
<
  class TModel
>
class FrameWork
{
  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;

  bool m_isBenchmarking;
  bool m_isBenchmarkInitialized;

  yg::Color m_bgColor;

  RenderQueue m_renderQueue;
  shared_ptr<yg::ResourceManager> m_resourceManager;
  InformationDisplay m_informationDisplay;

  /// is AddRedrawCommand enabled?
  bool m_isRedrawEnabled;
  double const m_metresMinWidth;
  int const m_minRulerWidth;

  enum TGpsCenteringMode
  {
    EDoNothing,
    ECenterAndScale,
    ECenterOnly
  };

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

  mutable threads::Mutex m_modelSyn;

  void AddRedrawCommandSure();
  void AddRedrawCommand();

  double m_maxDuration;
  m2::RectD m_maxDurationRect;
  m2::RectD m_curBenchmarkRect;

  int m_tileSize;

  struct BenchmarkResult
  {
    string m_name;
    m2::RectD m_rect;
    double m_time;
  };

  vector<BenchmarkResult> m_benchmarkResults;
  my::Timer m_benchmarksTimer;
  string m_startTime;
  my::Timer m_timer;

  struct Benchmark
  {
    shared_ptr<BenchmarkRectProvider> m_provider;
    string m_name;
  };

  vector<Benchmark> m_benchmarks;
  size_t m_curBenchmark;

  yg::Tiler m_tiler;

  void BenchmarkCommandFinished();
  void NextBenchmarkCommand();
  void SaveBenchmarkResults();
  void SendBenchmarkResults();

  void MarkBenchmarkResultsStart();
  void MarkBenchmarkResultsEnd();

  typedef typename TModel::ReaderT ReaderT;

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

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

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

public:
  FrameWork(shared_ptr<WindowHandle> windowHandle,
            size_t bottomShift);
  ~FrameWork();

  void InitBenchmark();

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

  model_t & get_model();

  typedef vector<ReaderT> maps_list_t;
  void EnumLocalMaps(maps_list_t & filesList);
  void EnumBenchmarkMaps(maps_list_t & filesList);

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

    typename TStorage::TEnumMapsFunction enumMapsFn;
    if (m_isBenchmarking)
      enumMapsFn = bind(&FrameWork::EnumBenchmarkMaps, this, _1);
    else
      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::RepaintRect, this, _1),
                 enumMapsFn);
    LOG(LINFO, ("Storage initialized"));
  }

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

  bool IsEmptyModel();

  // Cleanup.
  void Clean();

  void PrepareToShutdown();

public:

  void Search(string const & text, SearchCallbackT callback);

  void SetMaxWorldRect();
  void UpdateNow();
  void Invalidate();
  void SaveState();
  bool LoadState();

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

  bool SetUpdatesEnabled(bool doEnable);

  /// enabling/disabling AddRedrawCommand
  void SetRedrawEnabled(bool isRedrawEnabled);

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

  double GetCurrentScale() const;

  /// Actual rendering function.
  /// Called, as the renderQueue processes RenderCommand
  /// Usually it happens in the separate thread.
  void PaintImpl(shared_ptr<PaintEvent> e,
                 ScreenBase const & screen,
                 m2::RectD const & selectRect,
                 int scaleLevel
                 );

  /// Function for calling from platform dependent-paint function.
  void Paint(shared_ptr<PaintEvent> e);

  void CenterViewport(m2::PointD const & pt);

  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();

  void Repaint();

  void RepaintRect(m2::RectD const & rect);

  /// @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 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);
  //@}
};