libosmscout  1.1.1
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 
27 #include <osmscout/DataTileCache.h>
28 #include <osmscout/DBThread.h>
29 #include <osmscout/Settings.h>
35 
36 #include <memory>
37 
38 #include <QObject>
39 #include <QSettings>
40 
41 namespace osmscout {
42 
46 class OSMSCOUT_CLIENT_QT_API Router : public QObject{
47  Q_OBJECT
48 
49 private:
50  typedef std::function<void(size_t)> ProgressReporter;
51 
52  class QtRoutingProgress : public osmscout::RoutingProgress
53  {
54  private:
55  std::chrono::system_clock::time_point lastDump;
56  double maxPercent;
57  ProgressReporter reporter;
58 
59  public:
60  explicit QtRoutingProgress(ProgressReporter reporter)
61  : lastDump(std::chrono::system_clock::now()),
62  maxPercent(0.0),
63  reporter(std::move(reporter))
64  {
65  // no code
66  }
67 
68  void Reset()
69  {
70  lastDump=std::chrono::system_clock::now();
71  maxPercent=0.0;
72  }
73 
74  void Progress(const Distance &currentMaxDistance,
75  const Distance &overallDistance)
76  {
77  double currentPercent=(currentMaxDistance.AsMeter()*100.0)/overallDistance.AsMeter();
78 
79  std::chrono::system_clock::time_point now=std::chrono::system_clock::now();
80 
81  maxPercent=std::max(maxPercent,currentPercent);
82 
83  if (std::chrono::duration_cast<std::chrono::milliseconds>(now-lastDump).count()>100) {
84  //std::cout << (size_t)maxPercent << "%" << std::endl;
85  reporter((size_t)maxPercent);
86  lastDump=now;
87  }
88  }
89  };
90 
91 private:
92  QThread *thread;
93  SettingsRef settings;
94  DBThreadRef dbThread;
95 
96  osmscout::RouterParameter routerParameter;
97 
98 public slots:
99  void Initialize();
100 
116  void onRouteRequest(LocationEntryRef start,
117  LocationEntryRef target,
118  QmlRoutingProfileRef profile,
119  int requestId,
120  osmscout::BreakerRef breaker);
121 signals:
122  void routeComputed(QtRouteData route,
123  int requestId);
124 
125  void routeFailed(QString reason,
126  int requestId);
127 
128  void routeCanceled(int requestId);
129 
130  void routingProgress(int percent,
131  int requestId);
132 
133 private:
134 
135  void ProcessRouteRequest(osmscout::MultiDBRoutingServiceRef &routingService,
136  const LocationEntryRef &start,
137  const LocationEntryRef &target,
138  osmscout::Vehicle vehicle,
139  int requestId,
140  const osmscout::BreakerRef &breaker);
141 
142  bool CalculateRoute(osmscout::MultiDBRoutingServiceRef &routingService,
143  const osmscout::RoutePosition& start,
144  const osmscout::RoutePosition& target,
145  osmscout::RouteData& route,
146  int requestId,
147  const osmscout::BreakerRef &breaker);
148 
149  RouteDescriptionResult TransformRouteDataToRouteDescription(osmscout::MultiDBRoutingServiceRef &routingService,
150  const osmscout::RouteData& data,
151  const std::string& start,
152  const std::string& target);
153 
154  osmscout::MultiDBRoutingServiceRef MakeRoutingService(const std::list<DBInstanceRef>& databases,
155  const QmlRoutingProfileRef &profile);
156 
157 public:
158  Router(QThread *thread,
159  SettingsRef settings,
160  DBThreadRef dbThread);
161 
162  virtual ~Router();
163 
164 };
165 
166 }
167 
168 Q_DECLARE_METATYPE(osmscout::Vehicle)
169 
170 #endif /* OSMSCOUT_CLIENT_QT_ROUTER_H */
std::shared_ptr< Settings > SettingsRef
Definition: Settings.h:171
#define OSMSCOUT_CLIENT_QT_API
Definition: ClientQtImportExport.h:45
std::shared_ptr< LocationEntry > LocationEntryRef
Definition: LocationEntry.h:112
std::shared_ptr< Breaker > BreakerRef
Definition: Breaker.h:65
Definition: RoutingService.h:153
Vehicle
Definition: OSMScoutTypes.h:55
Definition: QtRouteData.h:40
std::shared_ptr< MultiDBRoutingService > MultiDBRoutingServiceRef
Definition: MultiDBRoutingService.h:154
Definition: RouteData.h:35
std::shared_ptr< QmlRoutingProfile > QmlRoutingProfileRef
Definition: QmlRoutingProfile.h:117
Definition: Area.h:38
std::shared_ptr< DBThread > DBThreadRef
Definition: DBThread.h:239
Setup internal state of renderer for executing next steps with current projection and parameters...
Definition: MapPainter.h:57
Definition: Router.h:46
Definition: Progress.h:34