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

rule_drawer.cpp « drape_frontend - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 083c31894de0267055f277cf54ac90bca1d1a3e2 (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
#include "rule_drawer.hpp"
#include "stylist.hpp"
#include "engine_context.hpp"
#include "apply_feature_functors.hpp"
#include "visual_params.hpp"

#include "../indexer/feature.hpp"
#include "../indexer/feature_algo.hpp"

#include "../base/assert.hpp"
#include "../std/bind.hpp"

namespace df
{

RuleDrawer::RuleDrawer(drawer_callback_fn const & fn, TileKey const & tileKey, EngineContext & context)
  : m_callback(fn)
  , m_tileKey(tileKey)
  , m_context(context)
{
  m_globalRect = m_tileKey.GetGlobalRect();

  int32_t tileSize = df::VisualParams::Instance().GetTileSize();
  m_geometryConvertor.OnSize(0, 0, tileSize, tileSize);
  m_geometryConvertor.SetFromRect(m2::AnyRectD(m_globalRect));
  m_currentScaleGtoP = 1.0f / m_geometryConvertor.GetScale();
}

void RuleDrawer::operator()(FeatureType const & f)
{
  Stylist s;
  m_callback(f, s);

  if (s.IsEmpty())
    return;

  if (s.IsCoastLine() && (!m_coastlines.insert(s.GetCaptionDescription().GetMainText()).second))
    return;

#ifdef DEBUG
  // Validate on feature styles
  if (s.AreaStyleExists() == false)
  {
    int checkFlag = s.PointStyleExists() ? 1 : 0;
    checkFlag += s.LineStyleExists() ? 1 : 0;
    ASSERT(checkFlag == 1, ());
  }
#endif

  if (s.AreaStyleExists())
  {
    ApplyAreaFeature apply(m_context, m_tileKey, f.GetID(), s.GetCaptionDescription());
    f.ForEachTriangleRef(apply, m_tileKey.m_zoomLevel);

    if (s.PointStyleExists())
      apply(feature::GetCenter(f, m_tileKey.m_zoomLevel));

    s.ForEachRule(bind(&ApplyAreaFeature::ProcessRule, &apply, _1));
    apply.Finish();
  }
  else if (s.LineStyleExists())
  {
    ApplyLineFeature apply(m_context, m_tileKey, f.GetID(),
                           s.GetCaptionDescription(),
                           m_currentScaleGtoP);
    f.ForEachPointRef(apply, m_tileKey.m_zoomLevel);

    if (apply.HasGeometry())
      s.ForEachRule(bind(&ApplyLineFeature::ProcessRule, &apply, _1));
    apply.Finish();
  }
  else
  {
    ASSERT(s.PointStyleExists(), ());
    ApplyPointFeature apply(m_context, m_tileKey, f.GetID(), s.GetCaptionDescription());
    f.ForEachPointRef(apply, m_tileKey.m_zoomLevel);

    s.ForEachRule(bind(&ApplyPointFeature::ProcessRule, &apply, _1));
    apply.Finish();
  }
}

} // namespace df