dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
kmlexport.h
Go to the documentation of this file.
1 
11 /*
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful, but
18  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20  * for more details.
21  *
22  * You should have received a copy of the GNU General Public License along
23  * with this program; if not, see <http://www.gnu.org/licenses/>
24  */
25 
26 #ifndef KMLEXPORT_H
27 #define KMLEXPORT_H
28 
29 #include <QIODevice>
30 #include <QTime>
31 #include <QTimer>
32 #include <QDebug>
33 #include <QBuffer>
34 #include <math.h>
35 
36 #include "kml/base/file.h"
37 #include "kml/dom.h"
38 #include "kml/engine.h"
39 
40 #include "./uavtalk/uavtalk.h"
41 
42 #include "airspeedactual.h"
43 #include "attitudeactual.h"
44 #include "homelocation.h"
45 #include "gpsposition.h"
46 #include "positionactual.h"
47 #include "velocityactual.h"
48 
49 using namespace kmldom;
50 
51 // This struct holds the 4D LLA-Velocity coordinates
53 {
54  double latitude;
55  double longitude;
56  double altitude;
57  double groundspeed; // in [m/s]
58 };
59 
64 class KmlExport : public QObject
65 {
66  Q_OBJECT
67 public:
68  explicit KmlExport(QString inputFileName, QString outputFileName);
69  qint64 bytesAvailable() const;
70  qint64 bytesToWrite() { return logFile.bytesToWrite(); }
71  bool open();
72  void setFileName(QString name) { logFile.setFileName(name); }
73 
74  bool preparseLogFile();
75  bool stopExport();
76  bool exportToKML();
77 
78 private slots:
79  void gpsPositionUpdated(UAVObject *);
80  void homeLocationUpdated(UAVObject *);
81  void positionActualUpdated(UAVObject *);
82 
83 signals:
84  void readReady();
85  void replayStarted();
86  void replayFinished();
87 
88 protected:
89  QFile logFile;
90 
91 private:
92  QList<quint32> timestampBuffer;
93  QList<quint32> timestampPos;
94 
95  UAVTalk *kmlTalk;
96 
97  AirspeedActual *airspeedActual;
98  AttitudeActual *attitudeActual;
99  GPSPosition *gpsPosition;
100  HomeLocation *homeLocation;
101  PositionActual *positionActual;
102  VelocityActual *velocityActual;
103 
104  GPSPosition::DataFields gpsPositionData;
105  HomeLocation::DataFields homeLocationData;
106 
107  DocumentPtr document;
108  FolderPtr trackFolder;
109  FolderPtr timestampFolder;
110  KmlFactory *factory;
111 
112  QString outputFileName;
113  LLAVCoordinates oldPoint;
114  quint32 timeStamp;
115  quint32 lastPlacemarkTime;
116  QString informationString;
117  QVector<CoordinatesPtr> wallAxes;
118  static QString dateTimeFormat;
119 
120  void parseLogFile();
121  StylePtr createGroundTrackStyle();
122  StyleMapPtr createWallAxesStyle();
123  StyleMapPtr createCustomBalloonStyle();
124  PlacemarkPtr CreateLineStringPlacemark(const LLAVCoordinates &startPoint,
125  const LLAVCoordinates &endPoint,
126  quint32 newPlacemarkTime);
127  PlacemarkPtr createTimespanPlacemark(const LLAVCoordinates &point, quint32 lastPlacemarkTime,
128  quint32 newPlacemarkTime);
129 
130  kmlbase::Color32 mapVelocity2Color(double velocity, quint8 alpha = 255);
131 };
132 
134 #define COLORMAP_JET \
135  { \
136  { 0, 0, 0.5156 }, { 0, 0, 0.5312 }, { 0, 0, 0.5469 }, { 0, 0, 0.5625 }, { 0, 0, 0.5781 }, \
137  { 0, 0, 0.5938 }, { 0, 0, 0.6094 }, { 0, 0, 0.6250 }, { 0, 0, 0.6406 }, \
138  { 0, 0, 0.6562 }, { 0, 0, 0.6719 }, { 0, 0, 0.6875 }, { 0, 0, 0.7031 }, \
139  { 0, 0, 0.7188 }, { 0, 0, 0.7344 }, { 0, 0, 0.7500 }, { 0, 0, 0.7656 }, \
140  { 0, 0, 0.7812 }, { 0, 0, 0.7969 }, { 0, 0, 0.8125 }, { 0, 0, 0.8281 }, \
141  { 0, 0, 0.8438 }, { 0, 0, 0.8594 }, { 0, 0, 0.8750 }, { 0, 0, 0.8906 }, \
142  { 0, 0, 0.9062 }, { 0, 0, 0.9219 }, { 0, 0, 0.9375 }, { 0, 0, 0.9531 }, \
143  { 0, 0, 0.9688 }, { 0, 0, 0.9844 }, { 0, 0, 1.0000 }, { 0, 0.0156, 1.0000 }, \
144  { 0, 0.0312, 1.0000 }, { 0, 0.0469, 1.0000 }, { 0, 0.0625, 1.0000 }, \
145  { 0, 0.0781, 1.0000 }, { 0, 0.0938, 1.0000 }, { 0, 0.1094, 1.0000 }, \
146  { 0, 0.1250, 1.0000 }, { 0, 0.1406, 1.0000 }, { 0, 0.1562, 1.0000 }, \
147  { 0, 0.1719, 1.0000 }, { 0, 0.1875, 1.0000 }, { 0, 0.2031, 1.0000 }, \
148  { 0, 0.2188, 1.0000 }, { 0, 0.2344, 1.0000 }, { 0, 0.2500, 1.0000 }, \
149  { 0, 0.2656, 1.0000 }, { 0, 0.2812, 1.0000 }, { 0, 0.2969, 1.0000 }, \
150  { 0, 0.3125, 1.0000 }, { 0, 0.3281, 1.0000 }, { 0, 0.3438, 1.0000 }, \
151  { 0, 0.3594, 1.0000 }, { 0, 0.3750, 1.0000 }, { 0, 0.3906, 1.0000 }, \
152  { 0, 0.4062, 1.0000 }, { 0, 0.4219, 1.0000 }, { 0, 0.4375, 1.0000 }, \
153  { 0, 0.4531, 1.0000 }, { 0, 0.4688, 1.0000 }, { 0, 0.4844, 1.0000 }, \
154  { 0, 0.5000, 1.0000 }, { 0, 0.5156, 1.0000 }, { 0, 0.5312, 1.0000 }, \
155  { 0, 0.5469, 1.0000 }, { 0, 0.5625, 1.0000 }, { 0, 0.5781, 1.0000 }, \
156  { 0, 0.5938, 1.0000 }, { 0, 0.6094, 1.0000 }, { 0, 0.6250, 1.0000 }, \
157  { 0, 0.6406, 1.0000 }, { 0, 0.6562, 1.0000 }, { 0, 0.6719, 1.0000 }, \
158  { 0, 0.6875, 1.0000 }, { 0, 0.7031, 1.0000 }, { 0, 0.7188, 1.0000 }, \
159  { 0, 0.7344, 1.0000 }, { 0, 0.7500, 1.0000 }, { 0, 0.7656, 1.0000 }, \
160  { 0, 0.7812, 1.0000 }, { 0, 0.7969, 1.0000 }, { 0, 0.8125, 1.0000 }, \
161  { 0, 0.8281, 1.0000 }, { 0, 0.8438, 1.0000 }, { 0, 0.8594, 1.0000 }, \
162  { 0, 0.8750, 1.0000 }, { 0, 0.8906, 1.0000 }, { 0, 0.9062, 1.0000 }, \
163  { 0, 0.9219, 1.0000 }, { 0, 0.9375, 1.0000 }, { 0, 0.9531, 1.0000 }, \
164  { 0, 0.9688, 1.0000 }, { 0, 0.9844, 1.0000 }, { 0, 1.0000, 1.0000 }, \
165  { 0.0156, 1.0000, 0.9844 }, { 0.0312, 1.0000, 0.9688 }, { 0.0469, 1.0000, 0.9531 }, \
166  { 0.0625, 1.0000, 0.9375 }, { 0.0781, 1.0000, 0.9219 }, { 0.0938, 1.0000, 0.9062 }, \
167  { 0.1094, 1.0000, 0.8906 }, { 0.1250, 1.0000, 0.8750 }, { 0.1406, 1.0000, 0.8594 }, \
168  { 0.1562, 1.0000, 0.8438 }, { 0.1719, 1.0000, 0.8281 }, { 0.1875, 1.0000, 0.8125 }, \
169  { 0.2031, 1.0000, 0.7969 }, { 0.2188, 1.0000, 0.7812 }, { 0.2344, 1.0000, 0.7656 }, \
170  { 0.2500, 1.0000, 0.7500 }, { 0.2656, 1.0000, 0.7344 }, { 0.2812, 1.0000, 0.7188 }, \
171  { 0.2969, 1.0000, 0.7031 }, { 0.3125, 1.0000, 0.6875 }, { 0.3281, 1.0000, 0.6719 }, \
172  { 0.3438, 1.0000, 0.6562 }, { 0.3594, 1.0000, 0.6406 }, { 0.3750, 1.0000, 0.6250 }, \
173  { 0.3906, 1.0000, 0.6094 }, { 0.4062, 1.0000, 0.5938 }, { 0.4219, 1.0000, 0.5781 }, \
174  { 0.4375, 1.0000, 0.5625 }, { 0.4531, 1.0000, 0.5469 }, { 0.4688, 1.0000, 0.5312 }, \
175  { 0.4844, 1.0000, 0.5156 }, { 0.5000, 1.0000, 0.5000 }, { 0.5156, 1.0000, 0.4844 }, \
176  { 0.5312, 1.0000, 0.4688 }, { 0.5469, 1.0000, 0.4531 }, { 0.5625, 1.0000, 0.4375 }, \
177  { 0.5781, 1.0000, 0.4219 }, { 0.5938, 1.0000, 0.4062 }, { 0.6094, 1.0000, 0.3906 }, \
178  { 0.6250, 1.0000, 0.3750 }, { 0.6406, 1.0000, 0.3594 }, { 0.6562, 1.0000, 0.3438 }, \
179  { 0.6719, 1.0000, 0.3281 }, { 0.6875, 1.0000, 0.3125 }, { 0.7031, 1.0000, 0.2969 }, \
180  { 0.7188, 1.0000, 0.2812 }, { 0.7344, 1.0000, 0.2656 }, { 0.7500, 1.0000, 0.2500 }, \
181  { 0.7656, 1.0000, 0.2344 }, { 0.7812, 1.0000, 0.2188 }, { 0.7969, 1.0000, 0.2031 }, \
182  { 0.8125, 1.0000, 0.1875 }, { 0.8281, 1.0000, 0.1719 }, { 0.8438, 1.0000, 0.1562 }, \
183  { 0.8594, 1.0000, 0.1406 }, { 0.8750, 1.0000, 0.1250 }, { 0.8906, 1.0000, 0.1094 }, \
184  { 0.9062, 1.0000, 0.0938 }, { 0.9219, 1.0000, 0.0781 }, { 0.9375, 1.0000, 0.0625 }, \
185  { 0.9531, 1.0000, 0.0469 }, { 0.9688, 1.0000, 0.0312 }, { 0.9844, 1.0000, 0.0156 }, \
186  { 1.0000, 1.0000, 0 }, { 1.0000, 0.9844, 0 }, { 1.0000, 0.9688, 0 }, \
187  { 1.0000, 0.9531, 0 }, { 1.0000, 0.9375, 0 }, { 1.0000, 0.9219, 0 }, \
188  { 1.0000, 0.9062, 0 }, { 1.0000, 0.8906, 0 }, { 1.0000, 0.8750, 0 }, \
189  { 1.0000, 0.8594, 0 }, { 1.0000, 0.8438, 0 }, { 1.0000, 0.8281, 0 }, \
190  { 1.0000, 0.8125, 0 }, { 1.0000, 0.7969, 0 }, { 1.0000, 0.7812, 0 }, \
191  { 1.0000, 0.7656, 0 }, { 1.0000, 0.7500, 0 }, { 1.0000, 0.7344, 0 }, \
192  { 1.0000, 0.7188, 0 }, { 1.0000, 0.7031, 0 }, { 1.0000, 0.6875, 0 }, \
193  { 1.0000, 0.6719, 0 }, { 1.0000, 0.6562, 0 }, { 1.0000, 0.6406, 0 }, \
194  { 1.0000, 0.6250, 0 }, { 1.0000, 0.6094, 0 }, { 1.0000, 0.5938, 0 }, \
195  { 1.0000, 0.5781, 0 }, { 1.0000, 0.5625, 0 }, { 1.0000, 0.5469, 0 }, \
196  { 1.0000, 0.5312, 0 }, { 1.0000, 0.5156, 0 }, { 1.0000, 0.5000, 0 }, \
197  { 1.0000, 0.4844, 0 }, { 1.0000, 0.4688, 0 }, { 1.0000, 0.4531, 0 }, \
198  { 1.0000, 0.4375, 0 }, { 1.0000, 0.4219, 0 }, { 1.0000, 0.4062, 0 }, \
199  { 1.0000, 0.3906, 0 }, { 1.0000, 0.3750, 0 }, { 1.0000, 0.3594, 0 }, \
200  { 1.0000, 0.3438, 0 }, { 1.0000, 0.3281, 0 }, { 1.0000, 0.3125, 0 }, \
201  { 1.0000, 0.2969, 0 }, { 1.0000, 0.2812, 0 }, { 1.0000, 0.2656, 0 }, \
202  { 1.0000, 0.2500, 0 }, { 1.0000, 0.2344, 0 }, { 1.0000, 0.2188, 0 }, \
203  { 1.0000, 0.2031, 0 }, { 1.0000, 0.1875, 0 }, { 1.0000, 0.1719, 0 }, \
204  { 1.0000, 0.1562, 0 }, { 1.0000, 0.1406, 0 }, { 1.0000, 0.1250, 0 }, \
205  { 1.0000, 0.1094, 0 }, { 1.0000, 0.0938, 0 }, { 1.0000, 0.0781, 0 }, \
206  { 1.0000, 0.0625, 0 }, { 1.0000, 0.0469, 0 }, { 1.0000, 0.0312, 0 }, \
207  { 1.0000, 0.0156, 0 }, { 1.0000, 0, 0 }, { 0.9844, 0, 0 }, { 0.9688, 0, 0 }, \
208  { 0.9531, 0, 0 }, { 0.9375, 0, 0 }, { 0.9219, 0, 0 }, { 0.9062, 0, 0 }, \
209  { 0.8906, 0, 0 }, { 0.8750, 0, 0 }, { 0.8594, 0, 0 }, { 0.8438, 0, 0 }, \
210  { 0.8281, 0, 0 }, { 0.8125, 0, 0 }, { 0.7969, 0, 0 }, { 0.7812, 0, 0 }, \
211  { 0.7656, 0, 0 }, { 0.7500, 0, 0 }, { 0.7344, 0, 0 }, { 0.7188, 0, 0 }, \
212  { 0.7031, 0, 0 }, { 0.6875, 0, 0 }, { 0.6719, 0, 0 }, { 0.6562, 0, 0 }, \
213  { 0.6406, 0, 0 }, { 0.6250, 0, 0 }, { 0.6094, 0, 0 }, { 0.5938, 0, 0 }, \
214  { 0.5781, 0, 0 }, { 0.5625, 0, 0 }, { 0.5469, 0, 0 }, { 0.5312, 0, 0 }, \
215  { 0.5156, 0, 0 }, \
216  { \
217  0.5000, 0, 0 \
218  } \
219  }
220 
221 #endif // KMLEXPORT_H
double longitude
Definition: kmlexport.h:55
double groundspeed
Definition: kmlexport.h:57
void setFileName(QString name)
Definition: kmlexport.h:72
QFile logFile
Definition: kmlexport.h:89
qint64 bytesToWrite()
Definition: kmlexport.h:70
double altitude
Definition: kmlexport.h:56
double latitude
Definition: kmlexport.h:54