libosmscout  1.1.1
VoiceInstructionAgent.h
Go to the documentation of this file.
1 #ifndef LIBOSMSCOUT_VOICEINSTRUCTIONAGENT_H
2 #define LIBOSMSCOUT_VOICEINSTRUCTIONAGENT_H
3 
4 /*
5  This source is part of the libosmscout library
6  Copyright (C) 2020 Lukas Karas
7 
8  This library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU Lesser General Public
10  License as published by the Free Software Foundation; either
11  version 2.1 of the License, or (at your option) any later version.
12 
13  This library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public
19  License along with this library; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21  */
22 
26 #include "PositionAgent.h"
27 
28 namespace osmscout {
29 
30 struct OSMSCOUT_API VoiceInstructionMessage CLASS_FINAL : public NavigationMessage
31 {
32  enum class VoiceSample {
33  After,
34  AhExitLeft,
35  AhExit,
36  AhExitRight,
37  AhFerry,
38  AhKeepLeft,
39  AhKeepRight,
40  AhLeftTurn,
41  AhRightTurn,
42  AhUTurn,
43  Arrive,
44  BearLeft,
45  BearRight,
46  Depart,
47  GpsFound,
48  GpsLost,
49  Charge,
50  KeepLeft,
51  KeepRight,
52  LnLeft,
53  LnRight,
54  Marble,
55  Meters,
56  MwEnter,
57  MwExitLeft,
58  MwExit,
59  MwExitRight,
60  RbBack,
61  RbCross,
62  RbExit1,
63  RbExit2,
64  RbExit3,
65  RbExit4,
66  RbExit5,
67  RbExit6,
68  RbLeft,
69  RbRight,
70  RoadEnd,
71  RouteCalculated,
72  RouteDeviated,
73  SharpLeft,
74  SharpRight,
75  Straight,
76  TakeFerry,
77  Then,
78  TryUTurn,
79  TurnLeft,
80  TurnRight,
81  UTurn,
82  Yards,
83  Take2ndLeft,
84  Take2ndRight,
85  Take3rdLeft,
86  Take3rdRight,
87  Distance50,
88  Distance80,
89  Distance100,
90  Distance200,
91  Distance300,
92  Distance400,
93  Distance500,
94  Distance600,
95  Distance700,
96  Distance800,
97  };
98 
99  std::vector<VoiceSample> message;
100 
101  inline VoiceInstructionMessage(const Timestamp& timestamp, std::vector<VoiceSample> &&message):
102  NavigationMessage(timestamp), message(message)
103  {}
104 };
105 
117 class OSMSCOUT_API VoiceInstructionAgent CLASS_FINAL : public NavigationAgent
118 {
119 public:
120 
121  enum class MessageType {
122  NoMessage,
123 
124  LeaveRbExit1,
125  LeaveRbExit2,
126  LeaveRbExit3,
127  LeaveRbExit4,
128  LeaveRbExit5,
129  LeaveRbExit6,
130 
131  TargetReached,
132 
133  SharpLeft,
134  TurnLeft,
135  StraightOn,
136  TurnRight,
137  SharpRight
138 
139  };
140 
141  struct MessageStruct {
142  MessageType type{MessageType::NoMessage};
143  Distance distance;
144 
145  MessageStruct() = default;
146  MessageStruct(const MessageStruct&) = default;
147  MessageStruct(MessageStruct &&) = default;
148 
149  MessageStruct(MessageType type, const Distance &distance):
150  type{type}, distance{distance} {}
151 
152  ~MessageStruct() = default;
153 
154  MessageStruct &operator=(const MessageStruct&) = default;
155  MessageStruct &operator=(MessageStruct&&) = default;
156 
157  operator bool() const
158  {
159  return type != MessageType::NoMessage;
160  }
161 
162  bool operator==(const MessageStruct &other) const
163  {
164  return type==other.type && distance==other.distance;
165  }
166 
167  bool operator!=(const MessageStruct &other) const
168  {
169  return !(*this==other);
170  }
171  };
172 
173 private:
175 
176  // state used for triggering GpsFound / GpsLost messages
177  bool prevGpsSignal{true};
178  Timestamp lastSeenGpsSignal{Timestamp::min()};
179 
180  MessageStruct lastMessage;
181  Distance lastMessagePosition; // where we trigger last message (it is before lastMessage.disntace usually)
182 
183 public:
185  units{units}
186  {};
187 
188  ~VoiceInstructionAgent() override = default;
189 
190  std::list<NavigationMessageRef> Process(const NavigationMessageRef& message) override;
191 
192 private:
193  void toSamples(std::vector<VoiceInstructionMessage::VoiceSample> &samples,
194  const MessageType &messageType);
195 
196  std::vector<VoiceInstructionMessage::VoiceSample> toSamples(const Distance &distanceFromStart,
197  const MessageStruct &message,
198  const MessageStruct &then);
199 };
200 }
201 
202 #endif //LIBOSMSCOUT_VOICEINSTRUCTIONAGENT_H
DistanceUnitSystem
Definition: Distance.h:35
std::chrono::system_clock::time_point Timestamp
Definition: Time.h:27
VoiceInstructionAgent(DistanceUnitSystem units)
Definition: VoiceInstructionAgent.h:184
Definition: VoiceInstructionAgent.h:141
VoiceSample
Definition: VoiceInstructionAgent.h:32
std::vector< VoiceSample > message
Definition: VoiceInstructionAgent.h:99
Distance distance
Definition: VoiceInstructionAgent.h:143
VoiceInstructionMessage(const Timestamp &timestamp, std::vector< VoiceSample > &&message)
Definition: VoiceInstructionAgent.h:101
Definition: Area.h:38
MessageType type
Definition: VoiceInstructionAgent.h:142
#define CLASS_FINAL
Definition: Compiler.h:26
#define OSMSCOUT_API
Definition: CoreImportExport.h:45
Distance Meters(double m)
Definition: Distance.h:358
bool operator==(const MessageStruct &other) const
Definition: VoiceInstructionAgent.h:162
MessageStruct(MessageType type, const Distance &distance)
Definition: VoiceInstructionAgent.h:149
MessageType
Definition: VoiceInstructionAgent.h:121
bool operator!=(const MessageStruct &other) const
Definition: VoiceInstructionAgent.h:167
std::shared_ptr< NavigationMessage > NavigationMessageRef
Definition: Engine.h:56
Definition: Engine.h:48