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

turns_tts_text.cpp « routing - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 44caafbbaeaf7c8663bbd235f4fa90d49d4dd55c (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
#include "routing/turns_sound_settings.hpp"
#include "routing/turns_tts_text.hpp"

#include "std/algorithm.hpp"
#include "std/string.hpp"
#include "std/utility.hpp"

namespace
{
using namespace routing::turns::sound;

template <class TIter> string DistToTextId(TIter begin, TIter end, uint32_t dist)
{
  using TValue = typename iterator_traits<TIter>::value_type;

  TIter distToSound = lower_bound(begin, end, dist, [](TValue const & p1, uint32_t p2)
                      {
                        return p1.first < p2;
                      });
  if (distToSound == end)
  {
    ASSERT(false, ("notification.m_distanceUnits is not correct."));
    return "";
  }
  return distToSound->second;
}
}  //  namespace

namespace routing
{
namespace turns
{
namespace sound
{
void GetTtsText::SetLocale(string const & locale)
{
  m_locale = locale;
  m_getCurLang.reset(new platform::GetTextById(platform::TextSource::TtsSound, locale));
  /// @todo Factor out file check from constructor and do not create m_getCurLang object in case of error.
  ASSERT(m_getCurLang, ());
}

void GetTtsText::SetLocaleWithJson(string const & jsonBuffer)
{
  m_getCurLang.reset(new platform::GetTextById(jsonBuffer));
  ASSERT(m_getCurLang && m_getCurLang->IsValid(), ());
}

string GetTtsText::operator()(Notification const & notification) const
{
  if (notification.m_distanceUnits == 0 && !notification.m_useThenInsteadOfDistance)
    return GetTextById(GetDirectionTextId(notification));

  string const distStr = GetTextById(GetDistanceTextId(notification));
  string const dirStr = GetTextById(GetDirectionTextId(notification));
  if (distStr.empty() && dirStr.empty())
    return "";
  return distStr + " " + dirStr;
}

string GetTtsText::GetTextById(string const & textId) const
{
  ASSERT(!textId.empty(), ());

  if (!m_getCurLang || !m_getCurLang->IsValid())
  {
    ASSERT(false, ());
    return "";
  }
  return (*m_getCurLang)(textId);
}

string GetDistanceTextId(Notification const & notification)
{
  if (!notification.IsValid())
  {
    ASSERT(false, ());
    return "";
  }

  if (notification.m_useThenInsteadOfDistance)
    return "then";

  switch (notification.m_lengthUnits)
  {
    case LengthUnits::Undefined:
      ASSERT(false, ());
      return "";
    case LengthUnits::Meters:
      return DistToTextId(GetAllSoundedDistMeters().cbegin(), GetAllSoundedDistMeters().cend(),
                          notification.m_distanceUnits);
    case LengthUnits::Feet:
      return DistToTextId(GetAllSoundedDistFeet().cbegin(), GetAllSoundedDistFeet().cend(),
                          notification.m_distanceUnits);
  }
  ASSERT(false, ());
  return "";
}

string GetDirectionTextId(Notification const & notification)
{
  switch (notification.m_turnDir)
  {
    case TurnDirection::GoStraight:
      return "go_straight";
    case TurnDirection::TurnRight:
      return "make_a_right_turn";
    case TurnDirection::TurnSharpRight:
      return "make_a_sharp_right_turn";
    case TurnDirection::TurnSlightRight:
      return "make_a_slight_right_turn";
    case TurnDirection::TurnLeft:
      return "make_a_left_turn";
    case TurnDirection::TurnSharpLeft:
      return "make_a_sharp_left_turn";
    case TurnDirection::TurnSlightLeft:
      return "make_a_slight_left_turn";
    case TurnDirection::UTurn:
      return "make_a_u_turn";
    case TurnDirection::EnterRoundAbout:
      return "enter_the_roundabout";
    case TurnDirection::LeaveRoundAbout:
      return "leave_the_roundabout";
    case TurnDirection::ReachedYourDestination:
      return "you_have_reached_the_destination";
    case TurnDirection::StayOnRoundAbout:
    case TurnDirection::StartAtEndOfStreet:
    case TurnDirection::TakeTheExit:
    case TurnDirection::NoTurn:
    case TurnDirection::Count:
      ASSERT(false, ());
      return "";
  }
  ASSERT(false, ());
  return "";
}
}  // namespace sound
}  // namespace turns
}  // namespace routing