libosmscout  1.1.1
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 <osmscout/DBThread.h>
24 #include <osmscout/Settings.h>
25 #include <osmscout/Router.h>
26 
39 
41 
42 #include <QObject>
43 #include <QTimer>
44 #include <QMediaPlayer>
45 #include <QMediaPlaylist>
46 
47 #include <optional>
48 
49 namespace osmscout {
50 
55  Q_OBJECT
56 
57 signals:
58  void update(std::list<RouteStep> instructions);
59 
60  void updateNext(RouteStep nextRouteInstruction);
61 
62  void rerouteRequest(const osmscout::GeoCoord from,
63  const std::optional<osmscout::Bearing> initialBearing,
64  const osmscout::GeoCoord to);
65 
66  void positionEstimate(const osmscout::PositionAgent::PositionState state,
67  const osmscout::GeoCoord coord,
68  const std::optional<osmscout::Bearing> bearing);
69 
70  void arrivalEstimate(QDateTime arrivalEstimate, osmscout::Distance remainingDistance);
71 
72  void targetReached(const osmscout::Bearing targetBearing,
73  const osmscout::Distance targetDistance);
74 
75  void currentSpeed(double currentSpeedKmPH);
76  void maxAllowedSpeed(double maxAllowedSpeedKmPh);
77 
78  void laneUpdate(osmscout::LaneAgent::Lane lane);
79 
80 public slots:
81  void setupRoute(QtRouteData route,
82  osmscout::Vehicle vehicle);
83 
89  void locationChanged(osmscout::GeoCoord coord,
90  bool horizontalAccuracyValid,
91  double horizontalAccuracy);
92 
93  void onTimeout();
94 
95  void onVoiceChanged(const QString);
96 
97  void playerStateChanged(QMediaPlayer::State state);
98 
99 public:
100  NavigationModule(QThread *thread,
101  SettingsRef settings,
102  DBThreadRef dbThread);
103 
104  bool loadRoutableObjects(const GeoBox &box,
105  const Vehicle &vehicle,
106  const std::map<std::string,DatabaseId> &databaseMapping,
107  RoutableObjectsRef &data);
108 
109  ~NavigationModule() override;
110 
111 private:
112  void InitPlayer();
113  void ProcessMessages(const std::list<osmscout::NavigationMessageRef>& messages);
114  QString sampleFile(osmscout::VoiceInstructionMessage::VoiceSample sample) const;
115 
116 private:
117  QThread *thread;
118  SettingsRef settings;
119  DistanceUnitSystem units{Locale::ByEnvironment().GetDistanceUnits()}; // TODO: make possible to override
120  DBThreadRef dbThread;
121  QTimer timer;
122  std::optional<Bearing> lastBearing;
123 
124  // voice route instructions
125  QString voiceDir;
126  // player and playlist should be created in module thread, not in UI thread (constructor)
127  // we setup QObject parents, objects are cleaned after Module destruction
128  QMediaPlaylist *currentPlaylist{nullptr};
129  QMediaPlayer *mediaPlayer{nullptr};
130  std::vector<osmscout::VoiceInstructionMessage::VoiceSample> nextMessage;
131 
132  osmscout::RouteDescriptionRef routeDescription;
133 
134  using DataAgentInst=DataAgent<NavigationModule>;
135  using DataAgentRef=std::shared_ptr<DataAgentInst>;
136 
138  std::make_shared<DataAgent<NavigationModule>>(*this),
139  std::make_shared<PositionAgent>(),
140  std::make_shared<BearingAgent>(),
141  std::make_shared<RouteInstructionAgent<RouteStep, RouteDescriptionBuilder>>(),
142  std::make_shared<VoiceInstructionAgent>(units),
143  std::make_shared<RouteStateAgent>(),
144  std::make_shared<ArrivalEstimateAgent>(),
145  std::make_shared<SpeedAgent>(),
146  std::make_shared<LaneAgent>()
147  };
148 
149 };
150 
151 }
152 
153 #endif // OSMSCOUT_CLIENT_QT_NAVIGATIONMODULE_H
DistanceUnitSystem
Definition: Distance.h:35
std::shared_ptr< Settings > SettingsRef
Definition: Settings.h:171
#define OSMSCOUT_CLIENT_QT_API
Definition: ClientQtImportExport.h:45
Vehicle
Definition: OSMScoutTypes.h:55
Definition: QtRouteData.h:40
Definition: Area.h:38
std::shared_ptr< DBThread > DBThreadRef
Definition: DBThread.h:239
Definition: RouteStep.h:42
std::shared_ptr< RouteDescription > RouteDescriptionRef
Definition: RouteDescription.h:814
Definition: NavigationModule.h:54
std::shared_ptr< RoutableObjects > RoutableObjectsRef
Definition: DataAgent.h:49
Definition: Engine.h:88