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: 1d3fc661d709e3b23fc76758d992199118aadbd4 (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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
#pragma once

#include "events.hpp"
#include "render_policy.hpp"
#include "information_display.hpp"
#include "window_handle.hpp"
#include "location_state.hpp"
#include "navigator.hpp"
#include "animator.hpp"
#include "feature_vec_model.hpp"
#include "bookmark.hpp"

#include "../defines.hpp"

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

#include "../storage/storage.hpp"

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

#include "../graphics/defines.hpp"
#include "../graphics/screen.hpp"
#include "../graphics/color.hpp"

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

#include "../base/logging.hpp"
#include "../base/strings_bundle.hpp"

#include "../std/vector.hpp"
#include "../std/shared_ptr.hpp"
#include "../std/scoped_ptr.hpp"
#include "../std/target_os.hpp"


//#define DRAW_TOUCH_POINTS

namespace search { class Result; }
namespace gui { class Controller; }
namespace anim { class Controller; }

class CountryStatusDisplay;
class BenchmarkEngine;

/// Uncomment line to make fixed position settings and
/// build version for screenshots.
//#define FIXED_LOCATION

class Framework
{
#ifdef FIXED_LOCATION
  class FixedPosition
  {
    pair<double, double> m_latlon;
    double m_dirFromNorth;
    bool m_fixedLatLon, m_fixedDir;

  public:
    FixedPosition();

    void GetLat(double & l) const { if (m_fixedLatLon) l = m_latlon.first; }
    void GetLon(double & l) const { if (m_fixedLatLon) l = m_latlon.second; }

    void GetNorth(double & n) const { if (m_fixedDir) n = m_dirFromNorth; }
    bool HasNorth() const { return m_fixedDir; }

  } m_fixedPos;
#endif

protected:
  friend class BenchmarkEngine;

  StringsBundle m_stringsBundle;

  mutable scoped_ptr<search::Engine> m_pSearchEngine;
  model::FeaturesFetcher m_model;
  Navigator m_navigator;
  Animator m_animator;

  vector<BookmarkCategory *> m_bookmarks;

  typedef vector<BookmarkCategory *>::iterator CategoryIter;
  CategoryIter FindBmCategory(string const & name);
  void DeleteBmCategory(CategoryIter i);

  scoped_ptr<RenderPolicy> m_renderPolicy;

  /// Safe function to get current visual scale.
  /// Call it when you need do calculate pixel rect (not matter if m_renderPolicy == 0).
  /// @return 1.0 if m_renderPolicy == 0 (possible for Android).
  double GetVisualScale() const;

  double m_StartForegroundTime;

  /// @todo Need deep analyzing in future.
  /// Now it's like a replacement of "m_hasPendingXXX" stuff.
  int m_etalonSize;

  //bool m_hasPendingInvalidate, m_doForceUpdate, m_queryMaxScaleMode, m_drawPlacemark, m_hasPendingShowRectFixed;
  bool m_queryMaxScaleMode, m_drawPlacemark;

  //m2::RectD m_pendingFixedRect;
  //m2::AnyRectD m_invalidRect;
  m2::PointD m_placemark;

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

  int m_width;
  int m_height;

  location::ECompassProcessMode m_dragCompassProcessMode;
  location::ELocationProcessMode m_dragLocationProcessMode;

  void StopLocationFollow();

  //mutable threads::Mutex m_modelSyn;

  storage::Storage m_storage;
  scoped_ptr<gui::Controller> m_guiController;
  scoped_ptr<anim::Controller> m_animController;
  InformationDisplay m_informationDisplay;

  /// This function is called by m_storage to notify that country downloading is finished.
  /// @param[in] file Country file name (without extensions).
  void UpdateAfterDownload(string const & file);

  //my::Timer m_timer;
  inline double ElapsedSeconds() const
  {
    //return m_timer.ElapsedSeconds();
    return 0.0;
  }

  /// Stores lowest loaded map version
  /// Holds -1 if no maps were added
  /// @see feature::DataHeader::Version
  //int m_lowestMapVersion;

  void DrawAdditionalInfo(shared_ptr<PaintEvent> const & e);

  BenchmarkEngine * m_benchmarkEngine;

  void ClearAllCaches();

public:
  Framework();
  virtual ~Framework();

  /*
  /// @name Used on iPhone for upgrade from April 1.0.1 version
  //@{
  /// @return true if client should display delete old maps dialog before using downloader
  bool NeedToDeleteOldMaps() const;
  void DeleteOldMaps();
  //@}
  */

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

  /// @name Process storage connecting/disconnecting.
  //@{
  void AddLocalMaps();
  void RemoveLocalMaps();
  //@}

  /// @return File names without path.
  void GetLocalMaps(vector<string> & outMaps) const;

  /// @name This functions is used by Downloader UI.
  //@{
  void DeleteCountry(storage::TIndex const & index);

  storage::TStatus GetCountryStatus(storage::TIndex const & index) const;

  /// Get country rect from borders (not from mwm file).
  /// @param[in] file Pass country file name without extension as an id.
  m2::RectD GetCountryBounds(string const & file) const;
  m2::RectD GetCountryBounds(storage::TIndex const & index) const;

  void ShowCountry(storage::TIndex const & index);
  //@}

  /// Scans and loads all kml files with bookmarks in WritableDir
  void LoadBookmarks();

  // Always returns existing or newly created bookmark category
  BookmarkCategory * AddBookmark(string const & category, Bookmark const & bm);
  inline size_t GetBmCategoriesCount() const { return m_bookmarks.size(); }
  /// @returns 0 if category is not found
  BookmarkCategory * GetBmCategory(size_t index) const;
  /// Always creates not existing category
  BookmarkCategory * GetBmCategory(string const & name);
  /// Delete bookmarks category with all bookmarks
  /// @return true if category was deleted
  //@{
  bool DeleteBmCategory(size_t index);
  bool DeleteBmCategory(string const & name);
  //@}

  /// Get bookmark by touch.
  /// @param[in]  pixPt   Coordinates of touch point in pixels.
  /// @return     NULL    If there is no bookmark found
  BookmarkAndCategory GetBookmark(m2::PointD const & pxPoint) const;
  BookmarkAndCategory GetBookmark(m2::PointD const & pxPoint, double visualScale) const;

  void ShowBookmark(Bookmark const & bm);

  void ClearBookmarks();

  inline m2::PointD PtoG(m2::PointD const & p) const { return m_navigator.PtoG(p); }
  inline m2::PointD GtoP(m2::PointD const & p) const { return m_navigator.GtoP(p); }

  storage::Storage & Storage() { return m_storage; }

  /// @name GPS location updates routine.
  //@{

  void StartLocation();
  void StopLocation();

  void OnLocationError(location::TLocationError error);
  void OnLocationUpdate(location::GpsInfo const & info);
  void OnCompassUpdate(location::CompassInfo const & info);
  //@}

  void SetRenderPolicy(RenderPolicy * renderPolicy);
  RenderPolicy * GetRenderPolicy() const;

  InformationDisplay & GetInformationDisplay();
  CountryStatusDisplay * GetCountryStatusDisplay() const;

  void PrepareToShutdown();

  void SetupMeasurementSystem();

  RenderPolicy::TRenderFn DrawModelFn();

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

private:
  search::Engine * GetSearchEngine() const;

public:
  m2::RectD GetCurrentViewport() const;

  /// Call this function before entering search GUI.
  /// While it's loading, we can cache features near user's position.
  /// @param[in] hasPt Are (lat, lon) valid
  /// @param[in] (lat, lon) Current user's position
  void PrepareSearch(bool hasPt, double lat = 0.0, double lon = 0.0);
  bool Search(search::SearchParams const & params);
  bool GetCurrentPosition(double & lat, double & lon) const;
  void ShowSearchResult(search::Result const & res);

  /// Calculate distance and direction to POI for the given position.
  /// @param[in]  point             POI's position;
  /// @param[in]  lat, lon, north   Current position and heading from north;
  /// @param[out] distance          Formatted distance string;
  /// @param[out] azimut            Azimut to point from (lat, lon);
  /// @return true  If the POI is near the current position (distance < 25 km);
  bool GetDistanceAndAzimut(m2::PointD const & point,
                            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;

  /// @return country code in ISO 3166-1 alpha-2 format (two small letters) or empty string
  string GetCountryCodeByPosition(double lat, double lon) const;

  void SetMaxWorldRect();

  void Invalidate(bool doForceUpdate = false);
  void InvalidateRect(m2::RectD const & rect, bool doForceUpdate = false);

  void SaveState();
  bool LoadState();

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

  bool SetUpdatesEnabled(bool doEnable);

  //double GetCurrentScale() const;
  int GetDrawScale() const;

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

  bool SetViewportByURL(string const & url);

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

  inline void XorQueryMaxScaleMode()
  {
    m_queryMaxScaleMode = !m_queryMaxScaleMode;
    Invalidate(true);
  }

  /// Get classificator types for nearest features.
  /// @param[in] pixPt Current touch point in device pixel coordinates.
  void GetFeatureTypes(m2::PointD pixPt, vector<string> & types) const;

  struct AddressInfo
  {
    string m_country, m_city, m_street, m_house, m_name;
    vector<string> m_types;

    void MakeFrom(search::Result const & res);

    string FormatAddress() const;
    string FormatTypes() const;
    char const * GetBestType() const;

    void Clear();
  };

  /// Get address information for point on map.
  void GetAddressInfo(m2::PointD const & pxPoint, AddressInfo & info) const;

private:
  void GetAddressInfo(FeatureType const & ft, m2::PointD const & pt, AddressInfo & info) const;
  void GetLocality(m2::PointD const & pt, AddressInfo & info) const;

public:
  bool GetVisiblePOI(m2::PointD const & pxPoint, m2::PointD & pxPivot, AddressInfo & info) const;

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

private:
  m2::AnyRectD ToRotated(m2::RectD const & rect) const;
  void CheckMinGlobalRect(m2::AnyRectD & rect) const;
  void CheckMinVisibleScale(m2::RectD & rect) const;
  void ShowRectFixed(m2::AnyRectD const & rect);

public:
  /// Set navigator viewport by rect as-is.
  void ShowRect(m2::RectD const & rect);
  /// - Use navigator rotate angle.
  /// - Check for fixed scales from navigator.
  void ShowRectEx(m2::RectD const & rect);
  /// - Check minimal visible scale according to downloaded countries.
  void ShowRectExVisibleScale(m2::RectD rect);

  void DrawPlacemark(m2::PointD const & pt);
  void DisablePlacemark();

  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.
  //@{
private:
  m2::PointD GetPixelCenter() const;
public:
  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);

private:
  void CalcScalePoints(ScaleEvent const & e, m2::PointD & pt1, m2::PointD & pt2) const;
public:
  void StartScale(ScaleEvent const & e);
  void DoScale(ScaleEvent const & e);
  void StopScale(ScaleEvent const & e);
  //@}

  gui::Controller * GetGuiController() const;
  anim::Controller * GetAnimController() const;

  Animator & GetAnimator();
  Navigator & GetNavigator();

  /// Set the localized strings bundle
  inline void AddString(string const & name, string const & value)
  {
    m_stringsBundle.SetString(name, value);
  }

  bool IsBenchmarking() const;

  /// Checks, whether the country which contains
  /// the specified point is loaded
  bool IsCountryLoaded(m2::PointD const & pt) const;

  shared_ptr<location::State> const & GetLocationState() const;
};