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

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

#include "gui/element.hpp"

#include "geometry/point2d.hpp"

#include "base/timer.hpp"

#include "routing/turns.hpp"

#include "platform/location.hpp"

#include "std/function.hpp"
#include "std/shared_ptr.hpp"
#include "std/unique_ptr.hpp"
#include "std/map.hpp"


class Framework;
class ScreenBase;

namespace graphics { class DisplayList; }
namespace anim { class Task;}

namespace location
{
  class GpsInfo;
  class CompassInfo;

  // Class, that handles position and compass updates,
  // centers, scales and rotates map according to this updates
  // and draws location and compass marks.
  class State : public gui::Element
  {
    typedef gui::Element TBase;

  public:
    struct Params : TBase::Params
    {
      graphics::Color m_locationAreaColor;
      Framework * m_framework;
      Params();
    };

    // Do not change the order and values
    enum Mode
    {
      UnknownPosition = 0x0,
      PendingPosition = 0x1,
      NotFollow = 0x2,
      Follow = 0x3,
      RotateAndFollow = 0x4,
    };

    typedef function<void(Mode)> TStateModeListener;
    typedef function<void (m2::PointD const &)> TPositionListener;

    State(Params const & p);

    /// @return GPS center point in mercator
    m2::PointD const & Position() const;
    double GetErrorRadius() const;
    double GetDirection() const { return m_drawDirection; }
    bool IsDirectionKnown() const;

    Mode GetMode() const;
    bool IsModeChangeViewport() const;
    bool IsModeHasPosition() const;
    void SwitchToNextMode();

    void RouteBuilded();
    void StartRouteFollow(int scale);
    void StopRoutingMode();

    int  AddStateModeListener(TStateModeListener const & l);
    void RemoveStateModeListener(int slotID);

    int  AddPositionChangedListener(TPositionListener const & func);
    void RemovePositionChangedListener(int slotID);

    void InvalidatePosition();
    void TurnOff();
    void StopCompassFollowing();
    void StopLocationFollow(bool callListeners = true);
    void SetFixedZoom();
    void SetRoutingNotFollow();

    /// @name User input notification block
    //@{
    void DragStarted();
    void DragEnded();

    void ScaleStarted();
    void CorrectScalePoint(m2::PointD & pt) const;
    void CorrectScalePoint(m2::PointD & pt1, m2::PointD & pt2) const;
    void ScaleEnded();

    void Rotated();
    //@}

    void OnCompassTaped();

    void OnSize(m2::RectD const & oldPixelRect);

    /// @name GPS location updates routine.
    //@{
    void OnLocationUpdate(location::GpsInfo const & info, bool isNavigable, location::RouteMatchingInfo const & routeMatchingInfo);
    void OnCompassUpdate(location::CompassInfo const & info);
    //@}

    RouteMatchingInfo const & GetRouteMatchingInfo() const { return m_routeMatchingInfo; }
    void ResetRouteMatchingInfo() { m_routeMatchingInfo.Reset(); }
    void ResetDirection();

    /// @name Override from graphics::OverlayElement and gui::Element.
    //@{
    virtual m2::RectD GetBoundRect() const { return m2::RectD(); }

    void draw(graphics::OverlayRenderer * r, math::Matrix<double, 3, 3> const & m) const;
    bool hitTest(m2::PointD const & /*pt*/) const { return false; }

    void cache();
    void purge();
    void update();
    //@}

  private:
    void AnimateStateTransition(Mode oldMode, Mode newMode);
    void AnimateFollow();

    void RotateOnNorth();

    void CallPositionChangedListeners(m2::PointD const & pt);
    void CallStateModeListeners();

#ifndef USE_DRAPE
    void CachePositionArrow();
    void CacheRoutingArrow();
    void CacheLocationMark();

    void CacheArrow(graphics::DisplayList * dl, string const & iconName);
#endif // USE_DRAPE

    bool IsRotationActive() const;
    bool IsInRouting() const;
    bool IsRoutingFollowingDisabled() const;

    m2::PointD const GetModeDefaultPixelBinding(Mode mode) const;
    m2::PointD const GetRaFModeDefaultPxBind() const;

    void SetModeInfo(uint16_t modeInfo, bool callListeners = true);

    void StopAllAnimations();

    ScreenBase const & GetModelView() const;

    void Assign(location::GpsInfo const & info, bool isNavigable);
    bool Assign(location::CompassInfo const & info);
    void SetDirection(double bearing);
    const m2::PointD GetPositionForDraw() const;

  private:
    
    enum ExternalMode
    {
      RoutingNotFollowBit = 0x10,
      FixedZoomBit = 0x20,
      RoutingSessionBit = 0x40,
      KnownDirectionBit = 0x80
    };
    static uint16_t const s_cacheRadius = 500.0f;

    uint16_t m_modeInfo; // combination of Mode enum and "Mode bits"
    uint16_t m_dragModeInfo = 0;
    uint16_t m_scaleModeInfo = 0;
    Framework * m_framework;

    double m_errorRadius;   //< error radius in mercator
    m2::PointD m_position;  //< position in mercator
    double m_drawDirection;
    my::Timer m_lastGPSBearing;
    Mode m_afterPendingMode;

    RouteMatchingInfo m_routeMatchingInfo;

    typedef map<int, TStateModeListener> TModeListeners;
    typedef map<int, TPositionListener> TPositionListeners;

    TModeListeners m_modeListeners;
    TPositionListeners m_positionListeners;
    int m_currentSlotID;

    /// @name Compass Rendering Parameters
    //@{
#ifndef USE_DRAPE
    unique_ptr<graphics::DisplayList> m_positionArrow;
    unique_ptr<graphics::DisplayList> m_locationMarkDL;
    unique_ptr<graphics::DisplayList> m_positionMarkDL;
    unique_ptr<graphics::DisplayList> m_routingArrow;
#endif // USE_DRAPE
    graphics::Color m_locationAreaColor;
    //@}

    /// @name Rotation mode animation
    //@{
    shared_ptr<anim::Task> m_animTask;
    bool FollowCompass();
    void CreateAnimTask();
    void CreateAnimTask(m2::PointD const & srcPx, m2::PointD const & dstPx);
    void EndAnimation();
    //@}
  };
}