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

bookmark.hpp « map - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1ef6bce63196a34fc14103e0c0e22ff732e0d8c4 (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
#pragma once

#include "map/user_mark.hpp"
#include "map/user_mark_container.hpp"

#include "coding/reader.hpp"

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

#include "base/timer.hpp"

#include "std/string.hpp"
#include "std/noncopyable.hpp"
#include "std/iostream.hpp"
#include "std/shared_ptr.hpp"

namespace anim
{
  class Task;
}

class Track;

class BookmarkData
{
public:
  BookmarkData()
    : m_scale(-1.0)
    , m_timeStamp(my::INVALID_TIME_STAMP)
  {
  }

  BookmarkData(string const & name, string const & type,
                     string const & description = "", double scale = -1.0,
                     time_t timeStamp = my::INVALID_TIME_STAMP)
    : m_name(name)
    , m_description(description)
    , m_type(type)
    , m_scale(scale)
    , m_timeStamp(timeStamp)
  {
  }

  string const & GetName() const { return m_name; }
  void SetName(const string & name) { m_name = name; }

  string const & GetDescription() const { return m_description; }
  void SetDescription(const string & description) { m_description = description; }

  string const & GetType() const { return m_type; }
  void SetType(const string & type) { m_type = type; }

  double const & GetScale() const { return m_scale; }
  void SetScale(double scale) { m_scale = scale; }

  time_t const & GetTimeStamp() const { return m_timeStamp; }
  void SetTimeStamp(const time_t & timeStamp) { m_timeStamp = timeStamp; }

private:
  string m_name;
  string m_description;
  string m_type;  ///< Now it stores bookmark color (category style).
  double m_scale; ///< Viewport scale. -1.0 - is a default value (no scale set).
  time_t m_timeStamp;
};

class Bookmark : public ICustomDrawable
{
  BookmarkData m_data;
  double m_animScaleFactor;

public:
  Bookmark(m2::PointD const & ptOrg, UserMarkContainer * container)
    : ICustomDrawable(ptOrg, container)
    , m_animScaleFactor(1.0)
  {
  }

  Bookmark(BookmarkData const & data,
           m2::PointD const & ptOrg,
           UserMarkContainer * container)
    : ICustomDrawable(ptOrg, container)
    , m_data(data)
    , m_animScaleFactor(1.0)
  {
  }

  void SetData(BookmarkData const & data) { m_data = data; }
  BookmarkData const & GetData() const { return m_data; }

  virtual Type GetMarkType() const override { return UserMark::Type::BOOKMARK; }
  virtual void FillLogEvent(TEventContainer & details) const override;

  string const & GetName() const { return m_data.GetName(); }
  void SetName(string const & name) { m_data.SetName(name); }
  /// @return Now its a bookmark color - name of icon file
  string const & GetType() const { return m_data.GetType(); }
  void SetType(string const & type) { m_data.SetType(type); }
  m2::RectD GetViewport() const { return m2::RectD(GetOrg(), GetOrg()); }

  string const & GetDescription() const { return m_data.GetDescription(); }
  void SetDescription(string const & description) { m_data.SetDescription(description); }

  /// @return my::INVALID_TIME_STAMP if bookmark has no timestamp
  time_t GetTimeStamp() const { return m_data.GetTimeStamp(); }
  void SetTimeStamp(time_t timeStamp) { m_data.SetTimeStamp(timeStamp); }

  double GetScale() const { return m_data.GetScale(); }
  void SetScale(double scale) { m_data.SetScale(scale); }

  unique_ptr<UserMarkCopy> Copy() const override;

  virtual graphics::DisplayList * GetDisplayList(UserMarkDLCache * cache) const override;
  virtual double GetAnimScaleFactor() const override;
  virtual m2::PointD const & GetPixelOffset() const override;
  shared_ptr<anim::Task> CreateAnimTask(Framework & fm);
};

class BookmarkCategory : public UserMarkContainer
{
  typedef UserMarkContainer base_t;
  /// @name Data
  //@{
  /// TODO move track into UserMarkContainer as a IDrawable custom data
  vector<Track *> m_tracks;
  //@}

  string m_name;
  /// Stores file name from which category was loaded
  string m_file;

public:
  BookmarkCategory(string const & name, Framework & framework);
  ~BookmarkCategory();

  virtual Type GetType() const { return BOOKMARK_MARK; }

  void ClearBookmarks();
  void ClearTracks();

  static string GetDefaultType();

  /// @name Theese functions are called from Framework only.
  //@{
  Bookmark* AddBookmark(m2::PointD const & ptOrg, BookmarkData const & bm);
  void ReplaceBookmark(size_t index, BookmarkData const & bm);
  //@}

  /// @name Tracks routine.
  //@{
  /// @note Move semantics is used here.
  void AddTrack(Track & track);
  Track const * GetTrack(size_t index) const;
  inline size_t GetTracksCount() const { return m_tracks.size(); }
  void DeleteTrack(size_t index);
  //@}

  void SetName(string const & name) { m_name = name; }
  string const & GetName() const { return m_name; }
  string const & GetFileName() const { return m_file; }

  size_t GetBookmarksCount() const;

  Bookmark const * GetBookmark(size_t index) const;
  Bookmark * GetBookmark(size_t index);
  void DeleteBookmark(size_t index);

  // Returns index of the bookmark if exists, otherwise returns
  // total number of bookmarks.
  size_t FindBookmark(Bookmark const * bookmark) const;

  /// @name Theese fuctions are public for unit tests only.
  /// You don't need to call them from client code.
  //@{
  bool LoadFromKML(ReaderPtr<Reader> const & reader);
  void SaveToKML(ostream & s);

  /// Uses the same file name from which was loaded, or
  /// creates unique file name on first save and uses it every time.
  bool SaveToKMLFile();

  /// @return 0 in the case of error
  static BookmarkCategory * CreateFromKMLFile(string const & file, Framework & framework);

  /// Get valid file name from input (remove illegal symbols).
  static string RemoveInvalidSymbols(string const & name);
  /// Get unique bookmark file name from path and valid file name.
  static string GenerateUniqueFileName(const string & path, string name);
  //@}

protected:
  virtual string GetTypeName() const { return "search-result"; }
  virtual string GetActiveTypeName() const { return "search-result-active"; }
  virtual UserMark * AllocateUserMark(m2::PointD const & ptOrg);

private:
  void ReleaseAnimations();
  
private:
  bool m_blockAnimation;
  typedef pair<UserMark *, shared_ptr<anim::Task> > anim_node_t;
  vector<anim_node_t> m_anims;
};

/// <category index, bookmark index>
typedef pair<int, int> BookmarkAndCategory;
inline BookmarkAndCategory MakeEmptyBookmarkAndCategory()
{
  return BookmarkAndCategory(int(-1), int(-1));
}

inline bool IsValid(BookmarkAndCategory const & bmc)
{
  return (bmc.first >= 0 && bmc.second >= 0);
}