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: 5c8182289fc04a2eeef66299644677e57ff495d5 (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
#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/noncopyable.hpp"

#include <iostream>
#include <memory>
#include <string>
#include <vector>

namespace anim
{
  class Task;
}

class Track;

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

  BookmarkData(std::string const & name,
               std::string const & type,
               std::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)
  {
  }

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

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

  std::string const & GetType() const { return m_type; }
  void SetType(const std::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:
  std::string m_name;
  std::string m_description;
  std::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 UserMark
{
  using TBase = UserMark;
public:
  Bookmark(m2::PointD const & ptOrg, UserMarkContainer * container);

  Bookmark(BookmarkData const & data, m2::PointD const & ptOrg,
           UserMarkContainer * container);

  void SetData(BookmarkData const & data);
  BookmarkData const & GetData() const;

  dp::Anchor GetAnchor() const override;
  std::string GetSymbolName() const override;

  Type GetMarkType() const override;
  bool HasCreationAnimation() const override;
  void SetCreationAnimationShown(bool shown);

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

  std::string const & GetDescription() const;
  void SetDescription(std::string const & description);

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

  double GetScale() const;
  void SetScale(double scale);

private:
  BookmarkData m_data;
  mutable bool m_hasCreationAnimation;
};

class BookmarkCategory : public UserMarkContainer
{
  typedef UserMarkContainer TBase;
  std::vector<std::unique_ptr<Track>> m_tracks;

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

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

  size_t GetUserLineCount() const override;
  df::UserLineMark const * GetUserLineMark(size_t index) const override;

  static std::string GetDefaultType();

  void ClearTracks();

  /// @name Tracks routine.
  //@{
  void AddTrack(std::unique_ptr<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(std::string const & name) { m_name = name; }
  std::string const & GetName() const { return m_name; }
  std::string const & GetFileName() const { return m_file; }

  /// @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(std::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(std::string const & file, Framework & framework);

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

protected:
  UserMark * AllocateUserMark(m2::PointD const & ptOrg) override;
};

struct BookmarkAndCategory
{
  BookmarkAndCategory() = default;
  BookmarkAndCategory(size_t bookmarkIndex, size_t categoryIndex) : m_bookmarkIndex(bookmarkIndex),
                                                              m_categoryIndex(categoryIndex) {}

  bool IsValid() const
  {
    return m_bookmarkIndex != numeric_limits<size_t>::max() &&
                          m_categoryIndex != numeric_limits<size_t>::max();
  };

  size_t m_bookmarkIndex = numeric_limits<size_t>::max();
  size_t m_categoryIndex = numeric_limits<size_t>::max();
};