libosmscout
1.1.1
Toggle main menu visibility
Loading...
Searching...
No Matches
libosmscout-client-qt
include
osmscoutclientqt
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
24
#include <
osmscoutclientqt/ClientQtImportExport.h
>
25
26
#include <
osmscout/routing/RoutePostprocessor.h
>
27
#include <
osmscout/routing/MultiDBRoutingService.h
>
28
#include <
osmscout/routing/RoutingProfile.h
>
29
#include <
osmscout/routing/DBFileOffset.h
>
30
31
#include <
osmscoutmap/DataTileCache.h
>
32
33
#include <osmscoutclient/Settings.h>
34
#include <osmscoutclient/DBThread.h>
35
36
#include <
osmscoutclientqt/RouteDescriptionBuilder.h
>
37
#include <
osmscoutclientqt/QmlRoutingProfile.h
>
38
#include <
osmscoutclientqt/LocationEntry.h
>
39
40
#include <memory>
41
42
#include <QObject>
43
#include <QSettings>
44
45
namespace
osmscout
{
46
50
class
OSMSCOUT_CLIENT_QT_API
Router
:
public
QObject{
51
Q_OBJECT
52
53
private
:
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 ¤tMaxDistance,
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
95
private
:
96
QThread *thread;
97
SettingsRef settings;
98
DBThreadRef dbThread;
99
100
osmscout::RouterParameter routerParameter;
101
102
public
slots:
103
void
Initialize
();
104
121
void
onRouteRequest
(
LocationEntryRef
start,
122
LocationEntryRef
target,
123
QmlRoutingProfileRef
profile,
124
int
requestId,
125
osmscout::BreakerRef
breaker,
126
std::optional<osmscout::Bearing> bearing);
127
signals:
128
void
routeComputed
(
QtRouteData
route,
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
139
private
:
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
184
public
:
185
Router
(QThread *thread,
186
SettingsRef settings,
187
DBThreadRef dbThread);
188
189
virtual
~Router
();
190
191
};
192
193
}
194
195
Q_DECLARE_METATYPE(
osmscout::Vehicle
)
196
197
#endif
/* OSMSCOUT_CLIENT_QT_ROUTER_H */
ClientQtImportExport.h
OSMSCOUT_CLIENT_QT_API
#define OSMSCOUT_CLIENT_QT_API
Definition
ClientQtImportExport.h:45
DBFileOffset.h
DataTileCache.h
LocationEntry.h
MultiDBRoutingService.h
QmlRoutingProfile.h
RouteDescriptionBuilder.h
RoutePostprocessor.h
RoutingProfile.h
osmscout::Progress
Definition
Progress.h:34
osmscout::QtRouteData
Definition
QtRouteData.h:40
osmscout::RouteData
Definition
RouteData.h:36
osmscout::Router::routeComputed
void routeComputed(QtRouteData route, int requestId)
osmscout::Router::routeFailed
void routeFailed(QString reason, int requestId)
osmscout::Router::routingProgress
void routingProgress(int percent, int requestId)
osmscout::Router::onRouteRequest
void onRouteRequest(LocationEntryRef start, LocationEntryRef target, QmlRoutingProfileRef profile, int requestId, osmscout::BreakerRef breaker, std::optional< osmscout::Bearing > bearing)
osmscout::Router::Router
Router(QThread *thread, SettingsRef settings, DBThreadRef dbThread)
osmscout::Router::Initialize
void Initialize()
osmscout::Router::routeCanceled
void routeCanceled(int requestId)
osmscout::Router::~Router
virtual ~Router()
osmscout::RoutingProgress
Definition
RoutingService.h:155
osmscout::MultiDBRoutingServiceRef
std::shared_ptr< MultiDBRoutingService > MultiDBRoutingServiceRef
Definition
MultiDBRoutingService.h:171
osmscout
Definition
Area.h:39
osmscout::BreakerRef
std::shared_ptr< Breaker > BreakerRef
Definition
Breaker.h:64
osmscout::LocationEntryRef
std::shared_ptr< LocationEntry > LocationEntryRef
Definition
LocationEntry.h:119
osmscout::QmlRoutingProfileRef
std::shared_ptr< QmlRoutingProfile > QmlRoutingProfileRef
Definition
QmlRoutingProfile.h:117
osmscout::Vehicle
Vehicle
Definition
OSMScoutTypes.h:55
Generated by
1.17.0