-
Notifications
You must be signed in to change notification settings - Fork 83
/
mapwidget.h
268 lines (233 loc) · 8.45 KB
/
mapwidget.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
/*
Copyright 2012 - 2019 Benjamin Vedder benjamin@vedder.se
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MAPWIDGET_H
#define MAPWIDGET_H
#include <QWidget>
#include <QPainter>
#include <QPaintEvent>
#include <QBrush>
#include <QFont>
#include <QPen>
#include <QPalette>
#include <QList>
#include <QInputDialog>
#include <QTimer>
#include <QPinchGesture>
#include <QImage>
#include <QTransform>
#include "locpoint.h"
#include "carinfo.h"
#include "copterinfo.h"
#include "perspectivepixmap.h"
#include "osmclient.h"
class MapModule
{
public:
virtual void processPaint(QPainter &painter, int width, int height, bool highQuality,
QTransform drawTrans, QTransform txtTrans, double scale) = 0;
virtual bool processMouse(bool isPress, bool isRelease, bool isMove, bool isWheel,
QPoint widgetPos, LocPoint mapPos, double wheelAngleDelta,
bool ctrl, bool shift, bool ctrlShift,
bool leftButton, bool rightButton, double scale) = 0;
};
class MapWidget : public QWidget
{
Q_OBJECT
public:
typedef enum {
InteractionModeDefault,
InteractionModeCtrlDown,
InteractionModeShiftDown,
InteractionModeCtrlShiftDown
} InteractionMode;
explicit MapWidget(QWidget *parent = 0);
CarInfo* getCarInfo(int car);
CopterInfo* getCopterInfo(int copter);
void setFollowCar(int car);
void setTraceCar(int car);
void setSelectedCar(int car);
void addCar(const CarInfo &car);
void addCopter(const CopterInfo &copter);
bool removeCar(int carId);
bool removeCopter(int copterId);
void clearCars();
void clearCopters();
LocPoint* getAnchor(int id);
void addAnchor(const LocPoint &anchor);
bool removeAnchor(int id);
void clearAnchors();
QList<LocPoint> getAnchors();
void setScaleFactor(double scale);
double getScaleFactor();
void setRotation(double rotation);
void setXOffset(double offset);
void setYOffset(double offset);
void moveView(double px, double py);
void clearTrace();
void addRoutePoint(double px, double py, double speed = 0.0, qint32 time = 0);
QList<LocPoint> getRoute(int ind = -1);
QList<QList<LocPoint> > getRoutes();
void setRoute(const QList<LocPoint> &route);
void addRoute(const QList<LocPoint> &route);
int getRouteNum();
void clearRoute();
void clearAllRoutes();
void setRoutePointSpeed(double speed);
void addInfoPoint(LocPoint &info, bool updateMap = true);
void clearInfoTrace();
void clearAllInfoTraces();
void addPerspectivePixmap(PerspectivePixmap map);
void clearPerspectivePixmaps();
QPoint getMousePosRelative();
void setAntialiasDrawings(bool antialias);
void setAntialiasOsm(bool antialias);
bool getDrawOpenStreetmap() const;
void setDrawOpenStreetmap(bool drawOpenStreetmap);
void setEnuRef(double lat, double lon, double height);
void getEnuRef(double *llh);
double getOsmRes() const;
void setOsmRes(double osmRes);
double getInfoTraceTextZoom() const;
void setInfoTraceTextZoom(double infoTraceTextZoom);
OsmClient *osmClient();
int getInfoTraceNum();
int getInfoPointsInTrace(int trace);
int setNextEmptyOrCreateNewInfoTrace();
void setAnchorMode(bool anchorMode);
bool getAnchorMode();
void setAnchorId(int id);
void setAnchorHeight(double height);
void removeLastRoutePoint();
void zoomInOnRoute(int id, double margins, double wWidth = -1, double wHeight = -1);
int getOsmMaxZoomLevel() const;
void setOsmMaxZoomLevel(int osmMaxZoomLevel);
int getOsmZoomLevel() const;
bool getDrawGrid() const;
void setDrawGrid(bool drawGrid);
bool getDrawOsmStats() const;
void setDrawOsmStats(bool drawOsmStats);
int getRouteNow() const;
void setRouteNow(int routeNow);
qint32 getRoutePointTime() const;
void setRoutePointTime(const qint32 &routePointTime);
double getTraceMinSpaceCar() const;
void setTraceMinSpaceCar(double traceMinSpaceCar);
double getTraceMinSpaceGps() const;
void setTraceMinSpaceGps(double traceMinSpaceGps);
int getInfoTraceNow() const;
void setInfoTraceNow(int infoTraceNow);
void printPdf(QString path, int width = 0, int height = 0);
void printPng(QString path, int width = 0, int height = 0);
bool getDrawRouteText() const;
void setDrawRouteText(bool drawRouteText);
bool getDrawUwbTrace() const;
void setDrawUwbTrace(bool drawUwbTrace);
void setLastCameraImage(const QImage &lastCameraImage);
double getCameraImageWidth() const;
void setCameraImageWidth(double cameraImageWidth);
double getCameraImageOpacity() const;
void setCameraImageOpacity(double cameraImageOpacity);
MapWidget::InteractionMode getInteractionMode() const;
void setInteractionMode(const MapWidget::InteractionMode &controlMode);
void addMapModule(MapModule *m);
void removeMapModule(MapModule *m);
void removeMapModuleLast();
quint32 getRoutePointAttributes() const;
void setRoutePointAttributes(const quint32 &routePointAttributes);
signals:
void scaleChanged(double newScale);
void offsetChanged(double newXOffset, double newYOffset);
void posSet(quint8 id, LocPoint pos);
void routePointAdded(LocPoint pos);
void lastRoutePointRemoved(LocPoint pos);
void infoTraceChanged(int traceNow);
private slots:
void tileReady(OsmTile tile);
void errorGetTile(QString reason);
void timerSlot();
protected:
void paintEvent(QPaintEvent *event) override;
void mouseMoveEvent (QMouseEvent *e) override;
void mousePressEvent(QMouseEvent *e) override;
void mouseReleaseEvent(QMouseEvent *e) override;
void wheelEvent(QWheelEvent *e) override;
bool event(QEvent *event) override;
private:
QList<CarInfo> mCarInfo;
QList<CopterInfo> mCopterInfo;
QVector<LocPoint> mCarTrace;
QVector<LocPoint> mCarTraceGps;
QVector<LocPoint> mCarTraceUwb;
QList<LocPoint> mAnchors;
QList<QList<LocPoint> > mRoutes;
QList<QList<LocPoint> > mInfoTraces;
QList<LocPoint> mVisibleInfoTracePoints;
QList<PerspectivePixmap> mPerspectivePixmaps;
double mRoutePointSpeed;
qint32 mRoutePointTime;
quint32 mRoutePointAttributes;
qint32 mAnchorId;
double mAnchorHeight;
double mScaleFactor;
double mRotation;
double mXOffset;
double mYOffset;
int mMouseLastX;
int mMouseLastY;
int mFollowCar;
int mTraceCar;
int mSelectedCar;
double xRealPos;
double yRealPos;
bool mAntialiasDrawings;
bool mAntialiasOsm;
double mOsmRes;
double mInfoTraceTextZoom;
OsmClient *mOsm;
int mOsmZoomLevel;
int mOsmMaxZoomLevel;
bool mDrawOpenStreetmap;
bool mDrawOsmStats;
double mRefLat;
double mRefLon;
double mRefHeight;
LocPoint mClosestInfo;
bool mDrawGrid;
int mRoutePointSelected;
int mAnchorSelected;
int mRouteNow;
int mInfoTraceNow;
double mTraceMinSpaceCar;
double mTraceMinSpaceGps;
QList<QPixmap> mPixmaps;
bool mAnchorMode;
bool mDrawRouteText;
bool mDrawUwbTrace;
QImage mLastCameraImage;
double mCameraImageWidth;
double mCameraImageOpacity;
InteractionMode mInteractionMode;
QTimer *mTimer;
QVector<MapModule*> mMapModules;
void updateClosestInfoPoint();
int drawInfoPoints(QPainter &painter, const QList<LocPoint> &pts,
QTransform drawTrans, QTransform txtTrans,
double xStart, double xEnd, double yStart, double yEnd,
double min_dist);
int getClosestPoint(LocPoint p, QList<LocPoint> points, double &dist);
void drawCircleFast(QPainter &painter, QPointF center, double radius, int type = 0);
void paint(QPainter &painter, int width, int height, bool highQuality = false);
void updateTraces();
};
#endif // MAPWIDGET_H