libosmscout 1.1.1
Loading...
Searching...
No Matches
Router.h
Go to the documentation of this file.
1#ifndef OSMSCOUT_CLIENT_QT_ROUTER_H
2#define OSMSCOUT_CLIENT_QT_ROUTER_H
3
4/*
5 OSMScout - a Qt backend for libosmscout and libosmscout-map
6 Copyright (C) 2010 Tim Teulings
7 Copyright (C) 2017 Lukas Karas
8
9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Lesser General Public
11 License as published by the Free Software Foundation; either
12 version 2.1 of the License, or (at your option) any later version.
13
14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public
20 License along with this library; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
25
30
32
33#include <osmscoutclient/Settings.h>
34#include <osmscoutclient/DBThread.h>
35
39
40#include <memory>
41
42#include <QObject>
43#include <QSettings>
44
45namespace osmscout {
46
50class OSMSCOUT_CLIENT_QT_API Router : public QObject{
51 Q_OBJECT
52
53private:
54 typedef std::function<void(size_t)> ProgressReporter;
55
56 class QtRoutingProgress : public osmscout::RoutingProgress
57 {
58 private:
59 std::chrono::system_clock::time_point lastDump;
60 double maxPercent;
61 ProgressReporter reporter;
62
63 public:
64 explicit QtRoutingProgress(ProgressReporter reporter)
65 : lastDump(std::chrono::system_clock::now()),
66 maxPercent(0.0),
67 reporter(std::move(reporter))
68 {
69 // no code
70 }
71
72 void Reset()
73 {
74 lastDump=std::chrono::system_clock::now();
75 maxPercent=0.0;
76 }
77
78 void Progress(const Distance &currentMaxDistance,
79 const Distance &overallDistance)
80 {
81 double currentPercent=(currentMaxDistance.AsMeter()*100.0)/overallDistance.AsMeter();
82
83 std::chrono::system_clock::time_point now=std::chrono::system_clock::now();
84
85 maxPercent=std::max(maxPercent,currentPercent);
86
87 if (std::chrono::duration_cast<std::chrono::milliseconds>(now-lastDump).count()>100) {
88 //std::cout << (size_t)maxPercent << "%" << std::endl;
89 reporter((size_t)maxPercent);
90 lastDump=now;
91 }
92 }
93 };
94
95private:
96 QThread *thread;
97 SettingsRef settings;
98 DBThreadRef dbThread;
99
100 osmscout::RouterParameter routerParameter;
101
102public slots:
104
122 LocationEntryRef target,
123 QmlRoutingProfileRef profile,
124 int requestId,
125 osmscout::BreakerRef breaker,
126 std::optional<osmscout::Bearing> bearing);
127signals:
129 int requestId);
130
131 void routeFailed(QString reason,
132 int requestId);
133
134 void routeCanceled(int requestId);
135
136 void routingProgress(int percent,
137 int requestId);
138
139private:
140
148 std::optional<RoutePosition> LocationToRoutePosition(osmscout::MultiDBRoutingServiceRef &routingService,
149 const LocationEntryRef &location);
150
161 void ProcessRouteRequest(osmscout::MultiDBRoutingServiceRef &routingService,
162 const LocationEntryRef &start,
163 const LocationEntryRef &target,
164 int requestId,
165 const osmscout::BreakerRef &breaker,
166 const std::optional<osmscout::Bearing> &bearing);
167
168 bool CalculateRoute(osmscout::MultiDBRoutingServiceRef &routingService,
169 const osmscout::RoutePosition& start,
170 const osmscout::RoutePosition& target,
171 const std::optional<osmscout::Bearing> &bearing,
172 osmscout::RouteData& route,
173 int requestId,
174 const osmscout::BreakerRef &breaker);
175
176 RouteDescriptionResult TransformRouteDataToRouteDescription(osmscout::MultiDBRoutingServiceRef &routingService,
177 const osmscout::RouteData& data,
178 const std::string& start,
179 const std::string& target);
180
181 osmscout::MultiDBRoutingServiceRef MakeRoutingService(const std::list<DBInstanceRef>& databases,
182 const QmlRoutingProfileRef &profile);
183
184public:
185 Router(QThread *thread,
186 SettingsRef settings,
187 DBThreadRef dbThread);
188
189 virtual ~Router();
190
191};
192
193}
194
195Q_DECLARE_METATYPE(osmscout::Vehicle)
196
197#endif /* OSMSCOUT_CLIENT_QT_ROUTER_H */
#define OSMSCOUT_CLIENT_QT_API
Definition ClientQtImportExport.h:45
Definition Progress.h:34
Definition QtRouteData.h:40
Definition RouteData.h:36
void routeComputed(QtRouteData route, int requestId)
void routeFailed(QString reason, int requestId)
void routingProgress(int percent, int requestId)
void onRouteRequest(LocationEntryRef start, LocationEntryRef target, QmlRoutingProfileRef profile, int requestId, osmscout::BreakerRef breaker, std::optional< osmscout::Bearing > bearing)
Router(QThread *thread, SettingsRef settings, DBThreadRef dbThread)
void routeCanceled(int requestId)
virtual ~Router()
Definition RoutingService.h:155
std::shared_ptr< MultiDBRoutingService > MultiDBRoutingServiceRef
Definition MultiDBRoutingService.h:171
Definition Area.h:39
std::shared_ptr< Breaker > BreakerRef
Definition Breaker.h:64
std::shared_ptr< LocationEntry > LocationEntryRef
Definition LocationEntry.h:119
std::shared_ptr< QmlRoutingProfile > QmlRoutingProfileRef
Definition QmlRoutingProfile.h:117
Vehicle
Definition OSMScoutTypes.h:55