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

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

#include "drape/batcher.hpp"
#include "drape/render_bucket.hpp"
#include "drape/render_state.hpp"
#include "drape/texture_manager.hpp"

#include "transit/transit_display_info.hpp"

#include <functional>
#include <map>
#include <set>
#include <string>
#include <vector>

namespace df
{
extern int const kTransitSchemeMinZoomLevel;
extern float const kTransitLineHalfWidth;
extern std::vector<float> const kTransitLinesWidthInPixel;

struct TransitRenderData
{
  enum class Type
  {
    LinesCaps,
    Lines,
    Markers,
    Text,
    Stubs
  };

  Type m_type;
  dp::RenderState m_state;
  uint32_t m_recacheId;
  MwmSet::MwmId m_mwmId;
  m2::PointD m_pivot;
  drape_ptr<dp::RenderBucket> m_bucket;

  TransitRenderData(Type type, dp::RenderState const & state, uint32_t recacheId,
                    MwmSet::MwmId const & mwmId, m2::PointD const pivot,
                    drape_ptr<dp::RenderBucket> && bucket)
    : m_type(type)
    , m_state(state)
    , m_recacheId(recacheId)
    , m_mwmId(mwmId)
    , m_pivot(pivot)
    , m_bucket(std::move(bucket))
  {}
};

struct LineParams
{
  LineParams() = default;
  LineParams(std::string const & color, float depth)
    : m_color(color), m_depth(depth)
  {}
  std::string m_color;
  float m_depth;
};

struct ShapeParams
{
  std::vector<routing::transit::LineId> m_forwardLines;
  std::vector<routing::transit::LineId> m_backwardLines;
  std::vector<m2::PointD> m_polyline;
};

struct ShapeInfo
{
  m2::PointD m_direction;
  size_t m_linesCount;
};

struct StopInfo
{
  StopInfo() = default;
  StopInfo(std::string const & name, FeatureID const & featureId)
    : m_name(name)
    , m_featureId(featureId)
  {}

  std::string m_name;
  FeatureID m_featureId;
  std::set<routing::transit::LineId> m_lines;
};

struct StopNodeParams
{
  bool m_isTransfer = false;
  m2::PointD m_pivot;
  std::map<routing::transit::ShapeId, ShapeInfo> m_shapesInfo;
  std::map<uint32_t, StopInfo> m_stopsInfo;
};

class TransitSchemeBuilder
{
public:
  enum class Priority : uint16_t
  {
    Default = 0,
    Stub = 1,
    StopMin = 2,
    StopMax = 30,
    TransferMin = 31,
    TransferMax = 60
  };

  using TFlushRenderDataFn = std::function<void(TransitRenderData && renderData)>;

  explicit TransitSchemeBuilder(TFlushRenderDataFn const & flushFn)
    : m_flushRenderDataFn(flushFn)
  {}

  void UpdateSchemes(ref_ptr<dp::GraphicsContext> context,
                     TransitDisplayInfos const & transitDisplayInfos,
                     ref_ptr<dp::TextureManager> textures);

  void RebuildSchemes(ref_ptr<dp::GraphicsContext> context,
                      ref_ptr<dp::TextureManager> textures);

  void Clear();
  void Clear(MwmSet::MwmId const & mwmId);

private:
  struct MwmSchemeData
  {
    m2::PointD m_pivot;

    std::map<routing::transit::LineId, LineParams> m_lines;
    std::map<routing::transit::ShapeId, ShapeParams> m_shapes;
    std::map<routing::transit::StopId, StopNodeParams> m_stops;
    std::map<routing::transit::TransferId, StopNodeParams> m_transfers;
  };

  void BuildScheme(ref_ptr<dp::GraphicsContext> context, MwmSet::MwmId const & mwmId,
                   ref_ptr<dp::TextureManager> textures);

  void CollectStops(TransitDisplayInfo const & transitDisplayInfo,
                    MwmSet::MwmId const & mwmId, MwmSchemeData & scheme);

  void CollectLines(TransitDisplayInfo const & transitDisplayInfo, MwmSchemeData & scheme);

  void CollectShapes(TransitDisplayInfo const & transitDisplayInfo, MwmSchemeData & scheme);
  void FindShapes(routing::transit::StopId stop1Id, routing::transit::StopId stop2Id,
                  routing::transit::LineId lineId,
                  std::vector<routing::transit::LineId> const & sameLines,
                  TransitDisplayInfo const & transitDisplayInfo, MwmSchemeData & scheme);
  void AddShape(TransitDisplayInfo const & transitDisplayInfo, routing::transit::StopId stop1Id,
                routing::transit::StopId stop2Id, routing::transit::LineId lineId, MwmSchemeData & scheme);

  void PrepareScheme(MwmSchemeData & scheme);

  void GenerateShapes(ref_ptr<dp::GraphicsContext> context, MwmSet::MwmId const & mwmId);

  void GenerateStops(ref_ptr<dp::GraphicsContext> context, MwmSet::MwmId const & mwmId,
                     ref_ptr<dp::TextureManager> textures);

  void GenerateMarker(ref_ptr<dp::GraphicsContext> context, m2::PointD const & pt,
                      m2::PointD widthDir, float linesCountWidth, float linesCountHeight,
                      float scaleWidth, float scaleHeight, float depth, dp::Color const & color,
                      dp::Batcher & batcher);

  void GenerateTransfer(ref_ptr<dp::GraphicsContext> context, StopNodeParams const & params,
                        m2::PointD const & pivot, dp::Batcher & batcher);

  void GenerateStop(ref_ptr<dp::GraphicsContext> context, StopNodeParams const & params,
                    m2::PointD const & pivot,
                    std::map<routing::transit::LineId, LineParams> const & lines,
                    dp::Batcher & batcher);

  void GenerateTitles(ref_ptr<dp::GraphicsContext> context, StopNodeParams const & params,
                      m2::PointD const & pivot, std::vector<m2::PointF> const & markerSizes,
                      ref_ptr<dp::TextureManager> textures, dp::Batcher & batcher);

  void GenerateLine(ref_ptr<dp::GraphicsContext> context, std::vector<m2::PointD> const & path,
                    m2::PointD const & pivot, dp::Color const & colorConst, float lineOffset,
                    float halfWidth, float depth, dp::Batcher & batcher);

  using TransitSchemes = std::map<MwmSet::MwmId, MwmSchemeData>;
  TransitSchemes m_schemes;

  TFlushRenderDataFn m_flushRenderDataFn;

  uint32_t m_recacheId = 0;
};
}  // namespace df