map2d_widget
core.h
Go to the documentation of this file.
1 
12 /*
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 * for more details.
22 *
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 */
27 #ifndef CORE_H
28 #define CORE_H
29 
30 #include "debugheader.h"
31 
32 #include "../internals/pointlatlng.h"
33 #include "mousewheelzoomtype.h"
34 #include "../core/size.h"
35 #include "../core/point.h"
36 
37 #include "../core/maptype.h"
38 #include "rectangle.h"
39 #include "QThreadPool"
40 #include "tilematrix.h"
41 #include <QQueue>
42 #include "loadtask.h"
43 #include "copyrightstrings.h"
44 #include "rectlatlng.h"
45 #include "../internals/projections/lks94projection.h"
46 #include "../internals/projections/mercatorprojection.h"
47 #include "../internals/projections/mercatorprojectionyandex.h"
48 #include "../internals/projections/platecarreeprojection.h"
49 #include "../internals/projections/platecarreeprojectionpergo.h"
50 #include "../core/geodecoderstatus.h"
51 #include "../core/opmaps.h"
52 #include "../core/diagnostics.h"
53 
54 #include <QSemaphore>
55 #include <QThread>
56 #include <QDateTime>
57 
58 #include <QObject>
59 
60 namespace mapcontrol
61 {
62  class OPMapControl;
63  class MapGraphicItem;
64 }
65 
66 namespace internals {
67 
68  class Core:public QObject,public QRunnable
69  {
70  Q_OBJECT
71 
74  public:
75  Core();
76  ~Core();
77  void run();
78  PointLatLng CurrentPosition()const{return currentPosition;}
79 
80  void SetCurrentPosition(const PointLatLng &value);
81 
82  core::Point GetcurrentPositionGPixel(){return currentPositionPixel;}
83  void SetcurrentPositionGPixel(const core::Point &value){currentPositionPixel=value;}
84 
85  core::Point GetrenderOffset(){return renderOffset;}
86  void SetrenderOffset(const core::Point &value){renderOffset=value;}
87 
88  core::Point GetcenterTileXYLocation(){return centerTileXYLocation;}
89  void SetcenterTileXYLocation(const core::Point &value){centerTileXYLocation=value;}
90 
91  core::Point GetcenterTileXYLocationLast(){return centerTileXYLocationLast;}
92  void SetcenterTileXYLocationLast(const core::Point &value){centerTileXYLocationLast=value;}
93 
94  core::Point GetdragPoint(){return dragPoint;}
95  void SetdragPoint(const core::Point &value){dragPoint=value;}
96 
97  core::Point GetmouseDown(){return mouseDown;}
98  void SetmouseDown(const core::Point &value){mouseDown=value;}
99 
100  core::Point GetmouseCurrent(){return mouseCurrent;}
101  void SetmouseCurrent(const core::Point &value){mouseCurrent=value;}
102 
103  core::Point GetmouseLastZoom(){return mouseLastZoom;}
104  void SetmouseLastZoom(const core::Point &value){mouseLastZoom=value;}
105 
106  MouseWheelZoomType::Types GetMouseWheelZoomType(){return mousewheelzoomtype;}
107  void SetMouseWheelZoomType(const MouseWheelZoomType::Types &value){mousewheelzoomtype=value;}
108 
109  PointLatLng GetLastLocationInBounds(){return LastLocationInBounds;}
110  void SetLastLocationInBounds(const PointLatLng &value){LastLocationInBounds=value;}
111 
112  Size GetsizeOfMapArea(){return sizeOfMapArea;}
113  void SetsizeOfMapArea(const Size &value){sizeOfMapArea=value;}
114 
115  Size GetminOfTiles(){return minOfTiles;}
116  void SetminOfTiles(const Size &value){minOfTiles=value;}
117 
118  Size GetmaxOfTiles(){return maxOfTiles;}
119  void SetmaxOfTiles(const Size &value){maxOfTiles=value;}
120 
121  Rectangle GettileRect(){return tileRect;}
122  void SettileRect(const Rectangle &value){tileRect=value;}
123 
124  core::Point GettilePoint(){return tilePoint;}
125  void SettilePoint(const core::Point &value){tilePoint=value;}
126 
127  Rectangle GetCurrentRegion(){return CurrentRegion;}
128  void SetCurrentRegion(const Rectangle &value){CurrentRegion=value;}
129 
130  QList<core::Point> tileDrawingList;
131 
133  {
134  return projection;
135  }
137  {
138  projection=value;
139  tileRect=Rectangle(core::Point(0,0),value->TileSize());
140  }
141  bool IsDragging()const{return isDragging;}
142 
143  int Zoom()const{return zoom;}
144  void SetZoom(int const& value);
145 
146  int MaxZoom()const{return maxzoom;}
147 
148  void UpdateBounds();
149 
150  MapType::Types GetMapType(){return mapType;}
151  void SetMapType(MapType::Types const& value);
152 
153  void StartSystem();
154 
156 
157  void OnMapSizeChanged(int const& width, int const& height);//TODO had as slot
158 
159  void OnMapClose();//TODO had as slot
160 
162 
164 
165  PointLatLng FromLocalToLatLng(int const& x, int const& y);
166 
167  Point FromLatLngToLocal(PointLatLng const& latlng);
168 
169  int GetMaxZoomToFitRect(RectLatLng const& rect);
170 
171  void BeginDrag(core::Point const& pt);
172 
173  void EndDrag();
174 
175  void ReloadMap();
176 
177  void GoToCurrentPosition();
178 
180 
181  void DragOffset(core::Point const& offset);
182 
183  void Drag(core::Point const& pt);
184 
185  void CancelAsyncTasks();
186 
187  void FindTilesAround(QList<core::Point> &list);
188 
189  void UpdateGroundResolution();
190 
192 
193  bool isStarted(){return started;}
194 
196  signals:
198  void OnTileLoadComplete();
199  void OnTilesStillToLoad(int number);
200  void OnTileLoadStart();
201  void OnMapDrag();
202  void OnMapZoomChanged();
203  void OnMapTypeChanged(MapType::Types type);
204  void OnEmptyTileError(int zoom, core::Point pos);
205  void OnNeedInvalidation();
206 
207  private:
208 
209 
210  PointLatLng currentPosition;
211  core::Point currentPositionPixel;
212  core::Point renderOffset;
213  core::Point centerTileXYLocation;
214  core::Point centerTileXYLocationLast;
215  core::Point dragPoint;
216  Rectangle tileRect;
217  core::Point mouseDown;
218  bool CanDragMap;
219  core::Point mouseCurrent;
220  PointLatLng LastLocationInBounds;
221  core::Point mouseLastZoom;
222 
223  MouseWheelZoomType::Types mousewheelzoomtype;
224 
225 
226  Size sizeOfMapArea;
227  Size minOfTiles;
228  Size maxOfTiles;
229 
230  core::Point tilePoint;
231 
232  Rectangle CurrentRegion;
233 
234  QQueue<LoadTask> tileLoadQueue;
235 
236  int zoom;
237 
238  PureProjection* projection;
239 
240  bool isDragging;
241 
242  QMutex MtileLoadQueue;
243 
244  QMutex Moverlays;
245 
246  QMutex MtileDrawingList;
247 #ifdef DEBUG_CORE
248  QMutex Mdebug;
249  static qlonglong debugcounter;
250 #endif
251  Size TooltipTextPadding;
252 
253  MapType::Types mapType;
254 
255  QSemaphore loaderLimit;
256 
257  QThreadPool ProcessLoadTaskCallback;
258  QMutex MtileToload;
259  int tilesToload;
260 
261  int maxzoom;
262  QMutex MrunningThreads;
263  int runningThreads;
264  diagnostics diag;
265 
266  protected:
267  bool started;
268 
269  int Width;
270  int Height;
271  int pxRes100m; // 100 meters
272  int pxRes1000m; // 1km
273  int pxRes10km; // 10km
274  int pxRes100km; // 100km
275  int pxRes1000km; // 1000km
276  int pxRes5000km; // 5000km
277  void SetCurrentPositionGPixel(core::Point const& value){currentPositionPixel = value;}
279 
280  };
281 
282 }
283 #endif // CORE_H
bool MouseWheelZooming
Definition: core.h:179
void OnTileLoadStart()
Size GetsizeOfMapArea()
Definition: core.h:112
Definition: tilematrix.h:37
int pxRes1000m
Definition: core.h:272
bool isStarted()
Definition: core.h:193
bool started
Definition: core.h:267
void SetsizeOfMapArea(const Size &value)
Definition: core.h:113
Definition: rectlatlng.h:37
void SetcurrentPositionGPixel(const core::Point &value)
Definition: core.h:83
Types
Definition: maptype.h:39
void SetCurrentPositionGPixel(core::Point const &value)
Definition: core.h:277
core::Point GetrenderOffset()
Definition: core.h:85
void SetmouseDown(const core::Point &value)
Definition: core.h:98
void SetmouseCurrent(const core::Point &value)
Definition: core.h:101
TileMatrix Matrix
Definition: core.h:191
core::Point GettilePoint()
Definition: core.h:124
diagnostics GetDiagnostics()
Definition: core.cpp:226
friend class mapcontrol::OPMapControl
Definition: core.h:72
core::Point GetmouseLastZoom()
Definition: core.h:103
Point FromLatLngToLocal(PointLatLng const &latlng)
Definition: core.cpp:446
int Height
Definition: core.h:270
core::Point GetcenterTileXYLocation()
Definition: core.h:88
virtual Size TileSize() const =0
Definition: size.h:35
Definition: diagnostics.h:30
void SettilePoint(const core::Point &value)
Definition: core.h:125
core::Point GetmouseDown()
Definition: core.h:97
void UpdateCenterTileXYLocation()
Definition: core.cpp:381
Definition: pointlatlng.h:35
MapType::Types GetMapType()
Definition: core.h:150
PointLatLng FromLocalToLatLng(int const &x, int const &y)
Definition: core.cpp:440
int GetMaxZoomToFitRect(RectLatLng const &rect)
Definition: core.cpp:452
int Width
Definition: core.h:269
core::Point GetdragPoint()
Definition: core.h:94
Definition: core.h:68
int MaxZoom() const
Definition: core.h:146
void OnMapTypeChanged(MapType::Types type)
Size GetmaxOfTiles()
Definition: core.h:118
void StartSystem()
Definition: core.cpp:370
MouseWheelZoomType::Types GetMouseWheelZoomType()
Definition: core.h:106
void SetmouseLastZoom(const core::Point &value)
Definition: core.h:104
Types
Definition: mousewheelzoomtype.h:40
Definition: point.h:35
void SetcenterTileXYLocation(const core::Point &value)
Definition: core.h:89
void SetmaxOfTiles(const Size &value)
Definition: core.h:119
int pxRes5000km
Definition: core.h:276
~Core()
Definition: core.cpp:49
void SetdragPoint(const core::Point &value)
Definition: core.h:95
void SetLastLocationInBounds(const PointLatLng &value)
Definition: core.h:110
Definition: rectangle.h:35
void SetZoom(int const &value)
Definition: core.cpp:235
void SettileRect(const Rectangle &value)
Definition: core.h:122
Types
Definition: geodecoderstatus.h:40
int pxRes100m
Definition: core.h:271
PointLatLng CurrentPosition() const
Definition: core.h:78
void SetCurrentPosition(const PointLatLng &value)
Definition: core.cpp:261
void BeginDrag(core::Point const &pt)
Definition: core.cpp:473
void SetcenterTileXYLocationLast(const core::Point &value)
Definition: core.h:92
core::Point GetmouseCurrent()
Definition: core.h:100
PointLatLng GetLastLocationInBounds()
Definition: core.h:109
void run()
Definition: core.cpp:54
int pxRes100km
Definition: core.h:274
Rectangle GetCurrentRegion()
Definition: core.h:127
PureProjection * Projection()
Definition: core.h:132
void Drag(core::Point const &pt)
Definition: core.cpp:571
void ReloadMap()
Definition: core.cpp:485
void OnMapSizeChanged(int const &width, int const &height)
Definition: core.cpp:388
void OnEmptyTileError(int zoom, core::Point pos)
void SetMouseWheelZoomType(const MouseWheelZoomType::Types &value)
Definition: core.h:107
void FindTilesAround(QList< core::Point > &list)
Definition: core.cpp:652
core::Point GetcenterTileXYLocationLast()
Definition: core.h:91
void SetMapType(MapType::Types const &value)
Definition: core.cpp:285
void SetCurrentRegion(const Rectangle &value)
Definition: core.h:128
Definition: pureprojection.h:42
void OnNeedInvalidation()
void DragOffset(core::Point const &offset)
Definition: core.cpp:551
void CancelAsyncTasks()
Definition: core.cpp:596
void OnMapZoomChanged()
void OnMapClose()
Definition: core.cpp:405
void SetrenderOffset(const core::Point &value)
Definition: core.h:86
void GoToCurrentPosition()
Definition: core.cpp:507
void OnTilesStillToLoad(int number)
void UpdateGroundResolution()
Definition: core.cpp:685
core::Point GetcurrentPositionGPixel()
Definition: core.h:82
bool IsDragging() const
Definition: core.h:141
Size GetminOfTiles()
Definition: core.h:115
void GoToCurrentPositionOnZoom()
Definition: core.cpp:517
void EndDrag()
Definition: core.cpp:479
QList< core::Point > tileDrawingList
Definition: core.h:130
int Zoom() const
Definition: core.h:143
int pxRes1000km
Definition: core.h:275
The main graphicsItem used on the widget, contains the map and map logic.
Definition: mapgraphicitem.h:51
GeoCoderStatusCode::Types SetCurrentPositionByKeywords(QString const &keys)
Definition: core.cpp:421
Rectangle GettileRect()
Definition: core.h:121
void SetProjection(PureProjection *value)
Definition: core.h:136
int pxRes10km
Definition: core.h:273
void OnTileLoadComplete()
void OnCurrentPositionChanged(internals::PointLatLng point)
void SetminOfTiles(const Size &value)
Definition: core.h:116
Core()
Definition: core.cpp:36
void UpdateBounds()
Definition: core.cpp:613
RectLatLng CurrentViewArea()
Definition: core.cpp:432