libosmscout 1.1.1
Loading...
Searching...
No Matches
NavigationModule.h
Go to the documentation of this file.
1#ifndef OSMSCOUT_CLIENT_QT_NAVIGATIONMODULE_H
2#define OSMSCOUT_CLIENT_QT_NAVIGATIONMODULE_H
3
4/*
5 OSMScout - a Qt backend for libosmscout and libosmscout-map
6 Copyright (C) 2017 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
23#include <osmscoutclient/Settings.h>
24#include <osmscoutclient/DBThread.h>
25
27
40
42
43#include <QtGlobal>
44#include <QObject>
45#include <QTimer>
46#include <QMediaPlayer>
47#include <QDateTime>
48
49#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
50 #include <QMediaPlaylist>
51#endif
52
53#include <optional>
54
55namespace osmscout {
56
57#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
58 using QtMediaPlayerState = QMediaPlayer::State;
59#else
60 using QtMediaPlayerState = QMediaPlayer::PlaybackState;
61#endif
62
63
68 Q_OBJECT
69
70private:
71 Slot<std::string> voiceDirSlot{
72 [this](const std::string &str) { onVoiceChanged(QString::fromStdString(str)); }
73 };
74
75signals:
76 void update(std::list<RouteStep> instructions);
77
78 void updateNext(RouteStep nextRouteInstruction);
79
80 void rerouteRequest(const osmscout::GeoCoord from,
81 const std::optional<osmscout::Bearing> initialBearing,
82 const osmscout::GeoCoord to);
83
84 void positionEstimate(const osmscout::PositionAgent::PositionState state,
85 const osmscout::GeoCoord coord,
86 const std::optional<osmscout::Bearing> bearing);
87
88 void arrivalEstimate(QDateTime arrivalEstimate, osmscout::Distance remainingDistance);
89
90 void targetReached(const osmscout::Bearing targetBearing,
91 const osmscout::Distance targetDistance);
92
93 void currentSpeed(double currentSpeedKmPH);
94 void maxAllowedSpeed(double maxAllowedSpeedKmPh);
95
96 void laneUpdate(osmscout::LaneAgent::Lane lane);
97
98public slots:
100 osmscout::Vehicle vehicle);
101
107 void locationChanged(osmscout::GeoCoord coord,
108 bool horizontalAccuracyValid,
109 double horizontalAccuracy);
110
111 void onTimeout();
112
113 void onVoiceChanged(const QString);
114
116
117public:
118 NavigationModule(QThread *thread,
119 SettingsRef settings,
120 DBThreadRef dbThread);
121
122 bool loadRoutableObjects(const GeoBox &box,
123 const Vehicle &vehicle,
124 const std::map<std::string,DatabaseId> &databaseMapping,
125 RoutableObjectsRef &data);
126
128
129private:
130 void InitPlayer();
131 void ProcessMessages(const std::list<osmscout::NavigationMessageRef>& messages);
132 QString sampleFile(osmscout::VoiceInstructionMessage::VoiceSample sample) const;
133
134private:
135 QThread *thread;
136 SettingsRef settings;
137 DistanceUnitSystem units{Locale::ByEnvironmentSafe().GetDistanceUnits()}; // TODO: make possible to override
138 DBThreadRef dbThread;
139 QTimer timer;
140 std::optional<Bearing> lastBearing;
141
142 // voice route instructions
143 QString voiceDir;
144 // player and playlist should be created in module thread, not in UI thread (constructor)
145 // we setup QObject parents, objects are cleaned after Module destruction
146#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
147 QMediaPlaylist *currentPlaylist{nullptr};
148#endif
149 QMediaPlayer *mediaPlayer{nullptr};
150 std::vector<osmscout::VoiceInstructionMessage::VoiceSample> nextMessage;
151
152 osmscout::RouteDescriptionRef routeDescription;
153
154 using DataAgentInst=DataAgent<NavigationModule>;
155 using DataAgentRef=std::shared_ptr<DataAgentInst>;
156
157 osmscout::NavigationEngine engine{
158 std::make_shared<DataAgent<NavigationModule>>(*this),
159 std::make_shared<PositionAgent>(),
160 std::make_shared<BearingAgent>(),
161 std::make_shared<RouteInstructionAgent<RouteStep, RouteDescriptionBuilder>>(),
162 std::make_shared<VoiceInstructionAgent>(units),
163 std::make_shared<RouteStateAgent>(),
164 std::make_shared<ArrivalEstimateAgent>(),
165 std::make_shared<SpeedAgent>(),
166 std::make_shared<LaneAgent>()
167 };
168
169};
170
171}
172
173#endif // OSMSCOUT_CLIENT_QT_NAVIGATIONMODULE_H
#define OSMSCOUT_CLIENT_QT_API
Definition ClientQtImportExport.h:45
NavigationModule(QThread *thread, SettingsRef settings, DBThreadRef dbThread)
void onVoiceChanged(const QString)
void rerouteRequest(const osmscout::GeoCoord from, const std::optional< osmscout::Bearing > initialBearing, const osmscout::GeoCoord to)
void setupRoute(QtRouteData route, osmscout::Vehicle vehicle)
bool loadRoutableObjects(const GeoBox &box, const Vehicle &vehicle, const std::map< std::string, DatabaseId > &databaseMapping, RoutableObjectsRef &data)
void locationChanged(osmscout::GeoCoord coord, bool horizontalAccuracyValid, double horizontalAccuracy)
void update(std::list< RouteStep > instructions)
void laneUpdate(osmscout::LaneAgent::Lane lane)
void positionEstimate(const osmscout::PositionAgent::PositionState state, const osmscout::GeoCoord coord, const std::optional< osmscout::Bearing > bearing)
void updateNext(RouteStep nextRouteInstruction)
void arrivalEstimate(QDateTime arrivalEstimate, osmscout::Distance remainingDistance)
void targetReached(const osmscout::Bearing targetBearing, const osmscout::Distance targetDistance)
void maxAllowedSpeed(double maxAllowedSpeedKmPh)
void playerStateChanged(QtMediaPlayerState state)
void currentSpeed(double currentSpeedKmPH)
Definition QtRouteData.h:40
Definition RouteStep.h:43
Definition Signal.h:98
Definition Area.h:39
QMediaPlayer::PlaybackState QtMediaPlayerState
Definition NavigationModule.h:60
std::shared_ptr< RouteDescription > RouteDescriptionRef
Definition RouteDescription.h:834
DistanceUnitSystem
Definition Distance.h:36
std::shared_ptr< RoutableObjects > RoutableObjectsRef
Definition DataAgent.h:49
Vehicle
Definition OSMScoutTypes.h:55