Rev 361 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 361 | Rev 395 | ||
---|---|---|---|
1 | /*************************************************************************** |
1 | /*************************************************************************** |
2 | * Copyright (C) 2009 by Manuel Schrape * |
2 | * Copyright (C) 2009 by Manuel Schrape * |
3 | * manuel.schrape@gmx.de * |
3 | * manuel.schrape@gmx.de * |
4 | * * |
4 | * * |
5 | * This program is free software; you can redistribute it and/or modify * |
5 | * This program is free software; you can redistribute it and/or modify * |
6 | * it under the terms of the GNU General Public License as published by * |
6 | * it under the terms of the GNU General Public License as published by * |
7 | * the Free Software Foundation; either version 2 of the License. * |
7 | * the Free Software Foundation; either version 2 of the License. * |
8 | * * |
8 | * * |
9 | * This program is distributed in the hope that it will be useful, * |
9 | * This program is distributed in the hope that it will be useful, * |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
12 | * GNU General Public License for more details. * |
12 | * GNU General Public License for more details. * |
13 | * * |
13 | * * |
14 | * You should have received a copy of the GNU General Public License * |
14 | * You should have received a copy of the GNU General Public License * |
15 | * along with this program; if not, write to the * |
15 | * along with this program; if not, write to the * |
16 | * Free Software Foundation, Inc., * |
16 | * Free Software Foundation, Inc., * |
17 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
17 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
18 | ***************************************************************************/ |
18 | ***************************************************************************/ |
19 | #include "dlg_Map.h" |
19 | #include "dlg_Map.h" |
20 | #include <QDomDocument> |
20 | #include <QDomDocument> |
21 | #include <QFile> |
21 | #include <QFile> |
22 | 22 | ||
23 | dlg_Map::dlg_Map(QWidget *parent) : QDialog(parent) |
23 | dlg_Map::dlg_Map(QWidget *parent) : QDialog(parent) |
24 | { |
24 | { |
25 | setupUi(this); |
25 | setupUi(this); |
26 | 26 | ||
27 | cb_Maps->removeItem(5); |
27 | cb_Maps->removeItem(5); |
28 | cb_Maps->removeItem(4); |
28 | cb_Maps->removeItem(4); |
29 | cb_Maps->removeItem(3); |
29 | // cb_Maps->removeItem(3); |
30 | cb_Maps->removeItem(2); |
30 | // cb_Maps->removeItem(2); |
31 | 31 | ||
32 | pb_Add->setEnabled(false); |
32 | pb_Add->setEnabled(false); |
33 | pb_Goto->setEnabled(false); |
33 | pb_Goto->setEnabled(false); |
34 | } |
34 | } |
35 | 35 | ||
36 | // Karte erstellen und anzeigen |
36 | // Karte erstellen und anzeigen |
37 | void dlg_Map::create_Map(cSettings *t_Settings) |
37 | void dlg_Map::create_Map(cSettings *t_Settings) |
38 | { |
38 | { |
39 | o_Settings = t_Settings; |
39 | o_Settings = t_Settings; |
40 | 40 | ||
41 | cb_CenterPos->setChecked(o_Settings->Map.GotoPosition); |
41 | cb_CenterPos->setChecked(o_Settings->Map.GotoPosition); |
42 | cb_ShowRoute->setChecked(o_Settings->Map.ShowTrack); |
42 | cb_ShowRoute->setChecked(o_Settings->Map.ShowTrack); |
43 | 43 | ||
44 | connect(sl_Zoom, SIGNAL(valueChanged(int)), this, SLOT(slot_Zoom(int))); |
44 | connect(sl_Zoom, SIGNAL(valueChanged(int)), this, SLOT(slot_Zoom(int))); |
45 | connect(pb_Add, SIGNAL(clicked()), this, SLOT(slot_AddWayPoint())); |
45 | connect(pb_Add, SIGNAL(clicked()), this, SLOT(slot_AddWayPoint())); |
46 | connect(pb_Delete, SIGNAL(clicked()), this, SLOT(slot_DeleteWayPoints())); |
46 | connect(pb_Delete, SIGNAL(clicked()), this, SLOT(slot_DeleteWayPoints())); |
47 | connect(pb_Goto, SIGNAL(clicked()), this, SLOT(slot_GotoTarget())); |
47 | connect(pb_Goto, SIGNAL(clicked()), this, SLOT(slot_GotoTarget())); |
48 | connect(pb_SendWaypoints, SIGNAL(clicked()), this, SLOT(slot_SendWayPoints())); |
48 | connect(pb_SendWaypoints, SIGNAL(clicked()), this, SLOT(slot_SendWayPoints())); |
- | 49 | connect(pb_LoadPic, SIGNAL(clicked()), this, SLOT(slot_LoadMapPic())); |
|
49 | 50 | ||
50 | connect(pb_Load, SIGNAL(clicked()), this, SLOT(slot_LoadWayPoints())); |
51 | connect(pb_Load, SIGNAL(clicked()), this, SLOT(slot_LoadWayPoints())); |
51 | connect(pb_Save, SIGNAL(clicked()), this, SLOT(slot_SaveWayPoints())); |
52 | connect(pb_Save, SIGNAL(clicked()), this, SLOT(slot_SaveWayPoints())); |
52 | 53 | ||
53 | connect(cb_Maps, SIGNAL(currentIndexChanged(int)), this, SLOT(slot_ChangeMap(int))); |
54 | connect(cb_Maps, SIGNAL(currentIndexChanged(int)), this, SLOT(slot_ChangeMap(int))); |
54 | connect(cb_ShowWPs, SIGNAL(toggled(bool)), this, SLOT(slot_ShowWayPoints(bool))); |
55 | connect(cb_ShowWPs, SIGNAL(toggled(bool)), this, SLOT(slot_ShowWayPoints(bool))); |
55 | 56 | ||
56 | connect(this, SIGNAL(rejected()), this, SLOT(slot_Close())); |
57 | connect(this, SIGNAL(rejected()), this, SLOT(slot_Close())); |
57 | 58 | ||
58 | o_Map = new MapControl(w_Map->size()); |
59 | o_Map = new MapControl(w_Map->size()); |
59 | o_Map->enablePersistentCache(o_Settings->DIR.Cache); |
60 | o_Map->enablePersistentCache(o_Settings->DIR.Cache); |
60 | o_Map->showScale(true); |
61 | o_Map->showScale(true); |
61 | 62 | ||
62 | o_Adapter = new OSMMapAdapter(); |
63 | o_Adapter = new OSMMapAdapter(); |
63 | 64 | ||
64 | o_Layer = new MapLayer("MapLayer", o_Adapter); |
65 | o_Layer = new MapLayer("MapLayer", o_Adapter); |
65 | o_Click = new GeometryLayer("Click", o_Adapter); |
66 | o_Click = new GeometryLayer("Click", o_Adapter); |
66 | o_Route = new GeometryLayer("Poute", o_Adapter); |
67 | o_Route = new GeometryLayer("Poute", o_Adapter); |
67 | 68 | ||
68 | o_Map->addLayer(o_Layer); |
69 | o_Map->addLayer(o_Layer); |
69 | o_Map->addLayer(o_Click); |
70 | o_Map->addLayer(o_Click); |
70 | o_Map->addLayer(o_Route); |
71 | o_Map->addLayer(o_Route); |
71 | 72 | ||
72 | o_Map->setZoom(17); |
73 | o_Map->setZoom(17); |
73 | o_Map->setView(QPointF(13.5,52.5)); |
74 | o_Map->setView(QPointF(13.5,52.5)); |
74 | 75 | ||
75 | connect(o_Map, SIGNAL(mouseEventCoordinate(const QMouseEvent*, const QPointF)), this, SLOT(slot_Click(const QMouseEvent*, const QPointF))); |
76 | connect(o_Map, SIGNAL(mouseEventCoordinate(const QMouseEvent*, const QPointF)), this, SLOT(slot_Click(const QMouseEvent*, const QPointF))); |
76 | 77 | ||
77 | l_Map->addWidget(o_Map); |
78 | l_Map->addWidget(o_Map); |
78 | 79 | ||
79 | sl_Zoom->setValue(17); |
80 | sl_Zoom->setValue(17); |
80 | 81 | ||
81 | Pen[0] = new QPen(QColor(0,0,255,255)); |
82 | Pen[0] = new QPen(QColor(0,0,255,255)); |
82 | Pen[0]->setWidth(2); |
83 | Pen[0]->setWidth(2); |
83 | Pen[1] = new QPen(QColor(255,0,0,255)); |
84 | Pen[1] = new QPen(QColor(255,0,0,255)); |
84 | Pen[1]->setWidth(2); |
85 | Pen[1]->setWidth(2); |
85 | } |
86 | } |
86 | 87 | ||
87 | QList<sWayPoint> dlg_Map::parse_WayPointKML(QString s_File) |
88 | QList<sWayPoint> dlg_Map::parse_WayPointKML(QString s_File) |
88 | { |
89 | { |
89 | QList<sWayPoint> tmp_WayPoints; |
90 | QList<sWayPoint> tmp_WayPoints; |
90 | sWayPoint tmp_WayPoint; |
91 | sWayPoint tmp_WayPoint; |
91 | 92 | ||
92 | QFile f_KML(s_File); |
93 | QFile f_KML(s_File); |
93 | f_KML.open(QIODevice::ReadOnly | QIODevice::Text); |
94 | f_KML.open(QIODevice::ReadOnly | QIODevice::Text); |
94 | 95 | ||
95 | QByteArray s_KML; |
96 | QByteArray s_KML; |
96 | 97 | ||
97 | while (!f_KML.atEnd()) |
98 | while (!f_KML.atEnd()) |
98 | { |
99 | { |
99 | s_KML.append(f_KML.readLine()); |
100 | s_KML.append(f_KML.readLine()); |
100 | } |
101 | } |
101 | 102 | ||
102 | f_KML.close(); |
103 | f_KML.close(); |
103 | 104 | ||
104 | QDomDocument *UserXML; |
105 | QDomDocument *UserXML; |
105 | UserXML = new QDomDocument; |
106 | UserXML = new QDomDocument; |
106 | 107 | ||
107 | UserXML->setContent(s_KML); |
108 | UserXML->setContent(s_KML); |
108 | 109 | ||
109 | QDomElement Root = UserXML->firstChildElement("kml"); |
110 | QDomElement Root = UserXML->firstChildElement("kml"); |
110 | QDomElement Document = Root.firstChildElement("Document"); |
111 | QDomElement Document = Root.firstChildElement("Document"); |
111 | QDomElement Placemark = Document.firstChildElement("Placemark"); |
112 | QDomElement Placemark = Document.firstChildElement("Placemark"); |
112 | QDomElement Linestring = Placemark.firstChildElement("LineString"); |
113 | QDomElement Linestring = Placemark.firstChildElement("LineString"); |
113 | 114 | ||
114 | QString Name = Placemark.firstChildElement("name").toElement().text(); |
115 | QString Name = Placemark.firstChildElement("name").toElement().text(); |
115 | 116 | ||
116 | QString Route = Linestring.firstChildElement("coordinates").toElement().text(); |
117 | QString Route = Linestring.firstChildElement("coordinates").toElement().text(); |
117 | 118 | ||
118 | QStringList s_Points = Route.split(" "); |
119 | QStringList s_Points = Route.split(" "); |
119 | 120 | ||
120 | QStringList Position; |
121 | QStringList Position; |
121 | 122 | ||
122 | for (int z = 0; z < s_Points.count() - 1; z++) |
123 | for (int z = 0; z < s_Points.count() - 1; z++) |
123 | { |
124 | { |
124 | if (z != 20) |
125 | if (z != 20) |
125 | { |
126 | { |
126 | Position = s_Points[z].split(","); |
127 | Position = s_Points[z].split(","); |
127 | tmp_WayPoint.Longitude = Position[0].toDouble(); |
128 | tmp_WayPoint.Longitude = Position[0].toDouble(); |
128 | tmp_WayPoint.Latitude = Position[1].toDouble(); |
129 | tmp_WayPoint.Latitude = Position[1].toDouble(); |
129 | tmp_WayPoint.Altitude = Position[2].toDouble(); |
130 | tmp_WayPoint.Altitude = Position[2].toDouble(); |
130 | tmp_WayPoint.Time = sb_Time->value(); |
131 | tmp_WayPoint.Time = sb_Time->value(); |
131 | 132 | ||
132 | tmp_WayPoints.append(tmp_WayPoint); |
133 | tmp_WayPoints.append(tmp_WayPoint); |
133 | } |
134 | } |
134 | else |
135 | else |
135 | { |
136 | { |
136 | QMessageBox::warning(this, QA_NAME,trUtf8("Die Wegpunkt-Liste umfasst mehr als 20 Einträge. Es werden nur die ersten 20 Einträge übernommen."), QMessageBox::Ok); |
137 | QMessageBox::warning(this, QA_NAME,trUtf8("Die Wegpunkt-Liste umfasst mehr als 20 Einträge. Es werden nur die ersten 20 Einträge übernommen."), QMessageBox::Ok); |
137 | 138 | ||
138 | pb_Add->setEnabled(false); |
139 | pb_Add->setEnabled(false); |
139 | 140 | ||
140 | z = s_Points.count(); |
141 | z = s_Points.count(); |
141 | } |
142 | } |
142 | } |
143 | } |
143 | return tmp_WayPoints; |
144 | return tmp_WayPoints; |
144 | } |
145 | } |
145 | 146 | ||
146 | QList<sWayPoint> dlg_Map::parse_WayPointMKW(QString s_File) |
147 | QList<sWayPoint> dlg_Map::parse_WayPointMKW(QString s_File) |
147 | { |
148 | { |
148 | QList<sWayPoint> tmp_WayPoints; |
149 | QList<sWayPoint> tmp_WayPoints; |
149 | sWayPoint tmp_WayPoint; |
150 | sWayPoint tmp_WayPoint; |
150 | 151 | ||
151 | QFile f_MKW(s_File); |
152 | QFile f_MKW(s_File); |
152 | f_MKW.open(QIODevice::ReadOnly | QIODevice::Text); |
153 | f_MKW.open(QIODevice::ReadOnly | QIODevice::Text); |
153 | 154 | ||
154 | QString s_MKW; |
155 | QString s_MKW; |
155 | 156 | ||
156 | while (!f_MKW.atEnd()) |
157 | while (!f_MKW.atEnd()) |
157 | { |
158 | { |
158 | s_MKW.append(f_MKW.readLine()); |
159 | s_MKW.append(f_MKW.readLine()); |
159 | } |
160 | } |
160 | 161 | ||
161 | f_MKW.close(); |
162 | f_MKW.close(); |
162 | 163 | ||
163 | QStringList s_Points = s_MKW.split(" "); |
164 | QStringList s_Points = s_MKW.split(" "); |
164 | 165 | ||
165 | QStringList Position; |
166 | QStringList Position; |
166 | 167 | ||
167 | for (int z = 0; z < s_Points.count() - 1; z++) |
168 | for (int z = 0; z < s_Points.count() - 1; z++) |
168 | { |
169 | { |
169 | if (z != 20) |
170 | if (z != 20) |
170 | { |
171 | { |
171 | Position = s_Points[z].split(","); |
172 | Position = s_Points[z].split(","); |
172 | tmp_WayPoint.Longitude = Position[0].toDouble(); |
173 | tmp_WayPoint.Longitude = Position[0].toDouble(); |
173 | tmp_WayPoint.Latitude = Position[1].toDouble(); |
174 | tmp_WayPoint.Latitude = Position[1].toDouble(); |
174 | tmp_WayPoint.Altitude = Position[2].toDouble(); |
175 | tmp_WayPoint.Altitude = Position[2].toDouble(); |
175 | tmp_WayPoint.Time = Position[3].toInt(); |
176 | tmp_WayPoint.Time = Position[3].toInt(); |
176 | 177 | ||
177 | tmp_WayPoints.append(tmp_WayPoint); |
178 | tmp_WayPoints.append(tmp_WayPoint); |
178 | } |
179 | } |
179 | else |
180 | else |
180 | { |
181 | { |
181 | QMessageBox::warning(this, QA_NAME,trUtf8("Die Wegpunkt-Liste umfasst mehr als 20 Einträge. Es werden nur die ersten 20 Einträge übernommen."), QMessageBox::Ok); |
182 | QMessageBox::warning(this, QA_NAME,trUtf8("Die Wegpunkt-Liste umfasst mehr als 20 Einträge. Es werden nur die ersten 20 Einträge übernommen."), QMessageBox::Ok); |
182 | 183 | ||
183 | pb_Add->setEnabled(false); |
184 | pb_Add->setEnabled(false); |
184 | 185 | ||
185 | z = s_Points.count(); |
186 | z = s_Points.count(); |
186 | } |
187 | } |
187 | } |
188 | } |
188 | return tmp_WayPoints; |
189 | return tmp_WayPoints; |
189 | } |
190 | } |
190 | 191 | ||
191 | void dlg_Map::show_WayPoints(QList<sWayPoint> WayPoints) |
192 | void dlg_Map::show_WayPoints(QList<sWayPoint> WayPoints) |
192 | { |
193 | { |
193 | Point* p_Point; |
194 | Point* p_Point; |
194 | 195 | ||
195 | o_Route->removeGeometry(l_RouteWP); |
196 | o_Route->removeGeometry(l_RouteWP); |
196 | p_RouteWP.clear(); |
197 | p_RouteWP.clear(); |
197 | l_WayPoints.clear(); |
198 | l_WayPoints.clear(); |
198 | 199 | ||
199 | l_WayPoints = WayPoints; |
200 | l_WayPoints = WayPoints; |
200 | 201 | ||
201 | for (int z = 0; z < WayPoints.count(); z++) |
202 | for (int z = 0; z < WayPoints.count(); z++) |
202 | { |
203 | { |
203 | p_Point = new Point(WayPoints[z].Longitude, WayPoints[z].Latitude); |
204 | p_Point = new Point(WayPoints[z].Longitude, WayPoints[z].Latitude); |
204 | 205 | ||
205 | p_RouteWP.append(p_Point); |
206 | p_RouteWP.append(p_Point); |
206 | } |
207 | } |
207 | 208 | ||
208 | l_RouteWP = new LineString(p_RouteWP, "", Pen[0]); |
209 | l_RouteWP = new LineString(p_RouteWP, "", Pen[0]); |
209 | o_Route->addGeometry(l_RouteWP); |
210 | o_Route->addGeometry(l_RouteWP); |
210 | 211 | ||
211 | o_Map->setView(p_Point); |
212 | o_Map->setView(p_Point); |
212 | 213 | ||
213 | o_Map->updateRequestNew(); |
214 | o_Map->updateRequestNew(); |
214 | } |
215 | } |
215 | 216 | ||
216 | void dlg_Map::save_WayPointsMKW(QString s_File) |
217 | void dlg_Map::save_WayPointsMKW(QString s_File) |
217 | { |
218 | { |
218 | QFile *f_MKW = new QFile(s_File); |
219 | QFile *f_MKW = new QFile(s_File); |
219 | 220 | ||
220 | f_MKW->open(QIODevice::ReadWrite | QIODevice::Text); |
221 | f_MKW->open(QIODevice::ReadWrite | QIODevice::Text); |
221 | 222 | ||
222 | QTextStream out(f_MKW); |
223 | QTextStream out(f_MKW); |
223 | 224 | ||
224 | out.setRealNumberPrecision(9); |
225 | out.setRealNumberPrecision(9); |
225 | 226 | ||
226 | for (int z = 0; z < l_WayPoints.count(); z++) |
227 | for (int z = 0; z < l_WayPoints.count(); z++) |
227 | { |
228 | { |
228 | out << l_WayPoints[z].Longitude << "," << l_WayPoints[z].Latitude << "," << l_WayPoints[z].Altitude << "," << l_WayPoints[z].Time << " \n"; |
229 | out << l_WayPoints[z].Longitude << "," << l_WayPoints[z].Latitude << "," << l_WayPoints[z].Altitude << "," << l_WayPoints[z].Time << " \n"; |
229 | } |
230 | } |
230 | 231 | ||
231 | f_MKW->close(); |
232 | f_MKW->close(); |
232 | } |
233 | } |
233 | 234 | ||
234 | void dlg_Map::slot_LoadWayPoints() |
235 | void dlg_Map::slot_LoadWayPoints() |
235 | { |
236 | { |
236 | QString Filename = QFileDialog::getOpenFileName(this, "WayPoint-Route laden", o_Settings->DIR.Logging, "Mikrokopter WayPoints(*.mkw);;KML-Datei(*.kml);;Alle Dateien (*)"); |
237 | QString Filename = QFileDialog::getOpenFileName(this, "WayPoint-Route laden", o_Settings->DIR.Logging, "Mikrokopter WayPoints(*.mkw);;KML-Datei(*.kml);;Alle Dateien (*)"); |
237 | 238 | ||
238 | if (!Filename.isEmpty()) |
239 | if (!Filename.isEmpty()) |
239 | { |
240 | { |
240 | if (Filename.endsWith(".kml", Qt::CaseInsensitive)) |
241 | if (Filename.endsWith(".kml", Qt::CaseInsensitive)) |
241 | { |
242 | { |
242 | cb_ShowWPs->setChecked(true); |
243 | cb_ShowWPs->setChecked(true); |
243 | pb_SendWaypoints->setEnabled(true); |
244 | pb_SendWaypoints->setEnabled(true); |
244 | 245 | ||
245 | show_WayPoints(parse_WayPointKML(Filename)); |
246 | show_WayPoints(parse_WayPointKML(Filename)); |
246 | } |
247 | } |
247 | if (Filename.endsWith(".mkw", Qt::CaseInsensitive)) |
248 | if (Filename.endsWith(".mkw", Qt::CaseInsensitive)) |
248 | { |
249 | { |
249 | cb_ShowWPs->setChecked(true); |
250 | cb_ShowWPs->setChecked(true); |
250 | pb_SendWaypoints->setEnabled(true); |
251 | pb_SendWaypoints->setEnabled(true); |
251 | 252 | ||
252 | show_WayPoints(parse_WayPointMKW(Filename)); |
253 | show_WayPoints(parse_WayPointMKW(Filename)); |
253 | } |
254 | } |
254 | } |
255 | } |
255 | } |
256 | } |
256 | 257 | ||
257 | void dlg_Map::slot_SaveWayPoints() |
258 | void dlg_Map::slot_SaveWayPoints() |
258 | { |
259 | { |
259 | QString Filename = QFileDialog::getSaveFileName(this, "WayPoint-Route speichern", o_Settings->DIR.Logging, "Mikrokopter WayPoints(*.mkw);;Alle Dateien (*)"); |
260 | QString Filename = QFileDialog::getSaveFileName(this, "WayPoint-Route speichern", o_Settings->DIR.Logging, "Mikrokopter WayPoints(*.mkw);;Alle Dateien (*)"); |
260 | 261 | ||
261 | if (!Filename.isEmpty()) |
262 | if (!Filename.isEmpty()) |
262 | { |
263 | { |
263 | if (!(Filename.endsWith(".mkw", Qt::CaseInsensitive))) |
264 | if (!(Filename.endsWith(".mkw", Qt::CaseInsensitive))) |
264 | { |
265 | { |
265 | Filename = Filename + QString(".mkw"); |
266 | Filename = Filename + QString(".mkw"); |
266 | } |
267 | } |
267 | 268 | ||
268 | save_WayPointsMKW(Filename); |
269 | save_WayPointsMKW(Filename); |
269 | } |
270 | } |
270 | } |
271 | } |
271 | 272 | ||
272 | void dlg_Map::slot_ShowWayPoints(bool Show) |
273 | void dlg_Map::slot_ShowWayPoints(bool Show) |
273 | { |
274 | { |
274 | if (Show == true) |
275 | if (Show == true) |
275 | { |
276 | { |
276 | qDebug("An"); |
277 | qDebug("An"); |
277 | o_Route->addGeometry(l_RouteWP); |
278 | o_Route->addGeometry(l_RouteWP); |
278 | o_Map->updateRequestNew(); |
279 | o_Map->updateRequestNew(); |
279 | } |
280 | } |
280 | else |
281 | else |
281 | { |
282 | { |
282 | qDebug("Aus"); |
283 | qDebug("Aus"); |
283 | o_Route->removeGeometry(l_RouteWP); |
284 | o_Route->removeGeometry(l_RouteWP); |
284 | o_Map->updateRequestNew(); |
285 | o_Map->updateRequestNew(); |
285 | } |
286 | } |
286 | } |
287 | } |
287 | 288 | ||
288 | // Position zum Flug-Track hinzufügen |
289 | // Position zum Flug-Track hinzufügen |
289 | void dlg_Map::add_Position(double x, double y) |
290 | void dlg_Map::add_Position(double x, double y) |
290 | { |
291 | { |
291 | sWayPoint WayPoint; |
292 | sWayPoint WayPoint; |
292 | 293 | ||
293 | WayPoint.Longitude = x; |
294 | WayPoint.Longitude = x; |
294 | WayPoint.Latitude = y; |
295 | WayPoint.Latitude = y; |
295 | // WayPoint.Time = sb_Time->value(); |
296 | // WayPoint.Time = sb_Time->value(); |
296 | 297 | ||
297 | l_Track.append(WayPoint); |
298 | l_Track.append(WayPoint); |
298 | 299 | ||
299 | o_Route->removeGeometry(l_RouteFL); |
300 | o_Route->removeGeometry(l_RouteFL); |
300 | p_RouteFL.append(new Point(x,y)); |
301 | p_RouteFL.append(new Point(x,y)); |
301 | 302 | ||
302 | o_Click->removeGeometry(LastPos); |
303 | o_Click->removeGeometry(LastPos); |
303 | 304 | ||
304 | Point* P = new CirclePoint(x, y, "P1", Point::Middle, Pen[0]); |
305 | Point* P = new CirclePoint(x, y, "P1", Point::Middle, Pen[0]); |
305 | LastPos = P; |
306 | LastPos = P; |
306 | P->setBaselevel(17); |
307 | P->setBaselevel(17); |
307 | o_Click->addGeometry(P); |
308 | o_Click->addGeometry(P); |
308 | 309 | ||
309 | if (cb_CenterPos->isChecked()) |
310 | if (cb_CenterPos->isChecked()) |
310 | { |
311 | { |
311 | o_Map->setView(QPointF(x, y)); |
312 | o_Map->setView(QPointF(x, y)); |
312 | } |
313 | } |
313 | 314 | ||
314 | if (cb_ShowRoute->isChecked()) |
315 | if (cb_ShowRoute->isChecked()) |
315 | { |
316 | { |
316 | l_RouteFL = new LineString(p_RouteFL, "", Pen[1]); |
317 | l_RouteFL = new LineString(p_RouteFL, "", Pen[1]); |
317 | 318 | ||
318 | o_Route->addGeometry(l_RouteFL); |
319 | o_Route->addGeometry(l_RouteFL); |
319 | } |
320 | } |
320 | o_Map->updateRequestNew(); |
321 | o_Map->updateRequestNew(); |
321 | } |
322 | } |
322 | 323 | ||
323 | // Zoom der Karte ändern |
324 | // Zoom der Karte ändern |
324 | void dlg_Map::slot_Zoom(int t_Zoom) |
325 | void dlg_Map::slot_Zoom(int t_Zoom) |
325 | { |
326 | { |
326 | o_Map->setZoom(t_Zoom); |
327 | o_Map->setZoom(t_Zoom); |
327 | } |
328 | } |
328 | 329 | ||
329 | // Waypoint zur Liste hinzufügen |
330 | // Waypoint zur Liste hinzufügen |
330 | void dlg_Map::slot_AddWayPoint() |
331 | void dlg_Map::slot_AddWayPoint() |
331 | { |
332 | { |
332 | cb_ShowWPs->setChecked(true); |
333 | cb_ShowWPs->setChecked(true); |
333 | 334 | ||
334 | sWayPoint WayPoint; |
335 | sWayPoint WayPoint; |
335 | 336 | ||
336 | WayPoint.Longitude = LastClick->longitude(); |
337 | WayPoint.Longitude = LastClick->longitude(); |
337 | WayPoint.Latitude = LastClick->latitude(); |
338 | WayPoint.Latitude = LastClick->latitude(); |
338 | WayPoint.Time = sb_Time->value(); |
339 | WayPoint.Time = sb_Time->value(); |
339 | 340 | ||
340 | l_WayPoints.append(WayPoint); |
341 | l_WayPoints.append(WayPoint); |
341 | 342 | ||
342 | o_Route->removeGeometry(l_RouteWP); |
343 | o_Route->removeGeometry(l_RouteWP); |
343 | 344 | ||
344 | p_RouteWP.append(LastClick); |
345 | p_RouteWP.append(LastClick); |
345 | l_RouteWP = new LineString(p_RouteWP, "", Pen[0]); |
346 | l_RouteWP = new LineString(p_RouteWP, "", Pen[0]); |
346 | 347 | ||
347 | o_Route->addGeometry(l_RouteWP); |
348 | o_Route->addGeometry(l_RouteWP); |
348 | o_Map->updateRequestNew(); |
349 | o_Map->updateRequestNew(); |
349 | 350 | ||
350 | pb_SendWaypoints->setEnabled(true); |
351 | pb_SendWaypoints->setEnabled(true); |
351 | 352 | ||
352 | if (l_WayPoints.count() == 20) |
353 | if (l_WayPoints.count() == 20) |
353 | { |
354 | { |
354 | QMessageBox::warning(this, QA_NAME,trUtf8("Wegpunkt-Liste ist voll. Es können maximal 20 Wegpunkte benutzt werden."), QMessageBox::Ok); |
355 | QMessageBox::warning(this, QA_NAME,trUtf8("Wegpunkt-Liste ist voll. Es können maximal 20 Wegpunkte benutzt werden."), QMessageBox::Ok); |
355 | pb_Add->setEnabled(false); |
356 | pb_Add->setEnabled(false); |
356 | } |
357 | } |
357 | 358 | ||
358 | } |
359 | } |
359 | 360 | ||
360 | // Waypoint-Liste löschen |
361 | // Waypoint-Liste löschen |
361 | void dlg_Map::slot_DeleteWayPoints() |
362 | void dlg_Map::slot_DeleteWayPoints() |
362 | { |
363 | { |
363 | o_Route->removeGeometry(l_RouteWP); |
364 | o_Route->removeGeometry(l_RouteWP); |
364 | p_RouteWP.clear(); |
365 | p_RouteWP.clear(); |
365 | l_WayPoints.clear(); |
366 | l_WayPoints.clear(); |
366 | o_Map->updateRequestNew(); |
367 | o_Map->updateRequestNew(); |
367 | 368 | ||
368 | pb_Add->setEnabled(pb_Goto->isEnabled()); |
369 | pb_Add->setEnabled(pb_Goto->isEnabled()); |
369 | } |
370 | } |
370 | 371 | ||
371 | void dlg_Map::slot_SendWayPoints() |
372 | void dlg_Map::slot_SendWayPoints() |
372 | { |
373 | { |
373 | emit(set_WayPoints(l_WayPoints)); |
374 | emit(set_WayPoints(l_WayPoints)); |
374 | } |
375 | } |
375 | 376 | ||
376 | // Zum Zielpunkt fliegen |
377 | // Zum Zielpunkt fliegen |
377 | void dlg_Map::slot_GotoTarget() |
378 | void dlg_Map::slot_GotoTarget() |
378 | { |
379 | { |
379 | sWayPoint Target; |
380 | sWayPoint Target; |
380 | 381 | ||
381 | Target.Longitude = LastClick->longitude(); |
382 | Target.Longitude = LastClick->longitude(); |
382 | Target.Latitude = LastClick->latitude(); |
383 | Target.Latitude = LastClick->latitude(); |
383 | Target.Time = sb_Time->value(); |
384 | Target.Time = sb_Time->value(); |
384 | 385 | ||
385 | emit(set_Target(Target)); |
386 | emit(set_Target(Target)); |
386 | } |
387 | } |
387 | 388 | ||
388 | // Click in der Karte |
389 | // Click in der Karte |
389 | void dlg_Map::slot_Click(const QMouseEvent* Event, const QPointF Coord) |
390 | void dlg_Map::slot_Click(const QMouseEvent* Event, const QPointF Coord) |
390 | { |
391 | { |
391 | if ((Event->type() == QEvent::MouseButtonPress) && ((Event->button() == Qt::RightButton) || (Event->button() == Qt::MidButton))) |
392 | if ((Event->type() == QEvent::MouseButtonPress) && ((Event->button() == Qt::RightButton) || (Event->button() == Qt::MidButton))) |
392 | { |
393 | { |
393 | sl_Zoom->setValue(o_Adapter->adaptedZoom()); |
394 | sl_Zoom->setValue(o_Adapter->adaptedZoom()); |
394 | } |
395 | } |
395 | 396 | ||
396 | // Überwachen ob Karte verschoben wird |
397 | // Überwachen ob Karte verschoben wird |
397 | if ((Event->type() == QEvent::MouseButtonPress) && (Event->button() == Qt::LeftButton)) |
398 | if ((Event->type() == QEvent::MouseButtonPress) && (Event->button() == Qt::LeftButton)) |
398 | { |
399 | { |
399 | MapCenter = o_Map->currentCoordinate(); |
400 | MapCenter = o_Map->currentCoordinate(); |
400 | } |
401 | } |
401 | 402 | ||
402 | // Nur wenn nicht Verschoben dann einen Punkt setzen |
403 | // Nur wenn nicht Verschoben dann einen Punkt setzen |
403 | if ((Event->type() == QEvent::MouseButtonRelease) && (Event->button() == Qt::LeftButton)) |
404 | if ((Event->type() == QEvent::MouseButtonRelease) && (Event->button() == Qt::LeftButton)) |
404 | { |
405 | { |
405 | if (o_Map->currentCoordinate() == MapCenter) |
406 | if (o_Map->currentCoordinate() == MapCenter) |
406 | { |
407 | { |
407 | if (l_WayPoints.count() < 20) |
408 | if (l_WayPoints.count() < 20) |
408 | { |
409 | { |
409 | pb_Add->setEnabled(true); |
410 | pb_Add->setEnabled(true); |
410 | } |
411 | } |
411 | pb_Goto->setEnabled(true); |
412 | pb_Goto->setEnabled(true); |
412 | 413 | ||
413 | o_Click->removeGeometry(ClickPoint); |
414 | o_Click->removeGeometry(ClickPoint); |
414 | 415 | ||
415 | ClickPoint = new CirclePoint(Coord.x(), Coord.y(), 6, "P1", Point::Middle, Pen[1]); |
416 | ClickPoint = new CirclePoint(Coord.x(), Coord.y(), 6, "P1", Point::Middle, Pen[1]); |
416 | 417 | ||
417 | LastClick = new Point(Coord.x(), Coord.y()); |
418 | LastClick = new Point(Coord.x(), Coord.y()); |
418 | 419 | ||
419 | ClickPoint->setBaselevel(o_Adapter->adaptedZoom()); |
420 | ClickPoint->setBaselevel(o_Adapter->adaptedZoom()); |
420 | o_Click->addGeometry(ClickPoint); |
421 | o_Click->addGeometry(ClickPoint); |
421 | } |
422 | } |
422 | } |
423 | } |
423 | 424 | ||
424 | o_Map->updateRequestNew(); |
425 | o_Map->updateRequestNew(); |
- | 426 | ||
425 | // qDebug(QString("%1").arg(Coord.x()).toLatin1().data()); |
427 | // qDebug(QString("%1").arg(Coord.x()).toLatin1().data()); |
426 | // qDebug(QString("%1").arg(Coord.y()).toLatin1().data()); |
428 | // qDebug(QString("%1").arg(Coord.y()).toLatin1().data()); |
427 | } |
429 | } |
- | 430 | ||
- | 431 | ||
- | 432 | void dlg_Map::slot_LoadMapPic() |
|
- | 433 | { |
|
- | 434 | QString Filename = QFileDialog::getOpenFileName(this, "Bild als Karte", o_Settings->DIR.Logging, "Bilddatei(*.jpg *.png *.gif);;Alle Dateien (*)"); |
|
- | 435 | ||
- | 436 | if (!Filename.isEmpty()) |
|
- | 437 | { |
|
- | 438 | QFile f_Points(Filename + ".pos"); |
|
- | 439 | ||
- | 440 | if (f_Points.exists()) |
|
- | 441 | { |
|
- | 442 | f_Points.open(QIODevice::ReadOnly | QIODevice::Text); |
|
- | 443 | ||
- | 444 | QString s_Points; |
|
- | 445 | ||
- | 446 | while (!f_Points.atEnd()) |
|
- | 447 | { |
|
- | 448 | s_Points.append(f_Points.readLine()); |
|
- | 449 | } |
|
- | 450 | ||
- | 451 | f_Points.close(); |
|
- | 452 | ||
- | 453 | QStringList s_Pos = s_Points.split(","); |
|
- | 454 | ||
- | 455 | FixedImageOverlay* fip = new FixedImageOverlay(s_Pos[0].toDouble(), s_Pos[1].toDouble(), s_Pos[2].toDouble(), s_Pos[3].toDouble(), Filename); |
|
- | 456 | ||
- | 457 | o_Layer->addGeometry(fip); |
|
- | 458 | o_Map->updateRequestNew(); |
|
- | 459 | } |
|
- | 460 | } |
|
- | 461 | } |
|
428 | 462 | ||
429 | // auf Veränderung der Fenstergröße reagieren |
463 | // auf Veränderung der Fenstergröße reagieren |
430 | void dlg_Map::resizeEvent ( QResizeEvent * event ) |
464 | void dlg_Map::resizeEvent ( QResizeEvent * event ) |
431 | { |
465 | { |
432 | event = event; |
466 | event = event; |
433 | o_Map->resize(w_Map->size() - QSize(20,20)); |
467 | o_Map->resize(w_Map->size() - QSize(20,20)); |
434 | } |
468 | } |
435 | 469 | ||
436 | // Karte wechseln |
470 | // Karte wechseln |
437 | void dlg_Map::slot_ChangeMap(int t_Set) |
471 | void dlg_Map::slot_ChangeMap(int t_Set) |
438 | { |
472 | { |
439 | int zoom = o_Adapter->adaptedZoom(); |
473 | int zoom = o_Adapter->adaptedZoom(); |
440 | QPointF a = o_Map->currentCoordinate(); |
474 | QPointF a = o_Map->currentCoordinate(); |
441 | 475 | ||
442 | o_Map->setZoom(0); |
476 | o_Map->setZoom(0); |
443 | 477 | ||
444 | switch(t_Set) |
478 | switch(t_Set) |
445 | { |
479 | { |
446 | case 0 : // OpenStreetMap |
480 | case 0 : // OpenStreetMap |
447 | { |
481 | { |
448 | o_Adapter = new OSMMapAdapter(); |
482 | o_Adapter = new OSMMapAdapter(); |
449 | } |
483 | } |
450 | break; |
484 | break; |
451 | case 1 : // Yahoo Sat |
485 | case 1 : // Yahoo Sat |
452 | { |
486 | { |
453 | o_Adapter = new TileMapAdapter("tile.openaerialmap.org", "/tiles/1.0.0/openaerialmap-900913/%1/%2/%3.png", 256, 0, 17); |
487 | o_Adapter = new TileMapAdapter("tile.openaerialmap.org", "/tiles/1.0.0/openaerialmap-900913/%1/%2/%3.png", 256, 0, 17); |
454 | } |
488 | } |
455 | break; |
489 | break; |
456 | case 2 : // Google Maps |
490 | case 2 : // Google Maps |
457 | { |
491 | { |
458 | o_Adapter = new GoogleMapAdapter(); |
492 | o_Adapter = new GoogleMapAdapter(); |
459 | } |
493 | } |
460 | break; |
494 | break; |
461 | case 3 : // Google Sat |
495 | case 3 : // Google Sat |
462 | { |
496 | { |
463 | o_Adapter = new GoogleSatMapAdapter(); |
497 | o_Adapter = new GoogleSatMapAdapter(); |
464 | } |
498 | } |
465 | break; |
499 | break; |
466 | case 4 : // Yahoo Maps |
500 | case 4 : // Yahoo Maps |
467 | { |
501 | { |
468 | o_Adapter = new YahooMapAdapter(); |
502 | o_Adapter = new YahooMapAdapter(); |
469 | } |
503 | } |
470 | break; |
504 | break; |
471 | case 5 : // Yahoo Sat |
505 | case 5 : // Yahoo Sat |
472 | { |
506 | { |
473 | o_Adapter = new YahooMapAdapter("us.maps3.yimg.com", "/aerial.maps.yimg.com/png?v=1.7&t=a&s=256&x=%2&y=%3&z=%1"); |
507 | o_Adapter = new YahooMapAdapter("us.maps3.yimg.com", "/aerial.maps.yimg.com/png?v=1.7&t=a&s=256&x=%2&y=%3&z=%1"); |
474 | } |
508 | } |
475 | break; |
509 | break; |
476 | } |
510 | } |
477 | 511 | ||
478 | o_Layer->setMapAdapter(o_Adapter); |
512 | o_Layer->setMapAdapter(o_Adapter); |
479 | o_Click->setMapAdapter(o_Adapter); |
513 | o_Click->setMapAdapter(o_Adapter); |
480 | o_Route->setMapAdapter(o_Adapter); |
514 | o_Route->setMapAdapter(o_Adapter); |
481 | 515 | ||
482 | o_Map->updateRequestNew(); |
516 | o_Map->updateRequestNew(); |
483 | o_Map->setZoom(zoom); |
517 | o_Map->setZoom(zoom); |
484 | } |
518 | } |
485 | 519 | ||
486 | // Fenster wird geschlossen. |
520 | // Fenster wird geschlossen. |
487 | void dlg_Map::slot_Close() |
521 | void dlg_Map::slot_Close() |
488 | { |
522 | { |
489 | o_Settings->Map.GotoPosition = cb_CenterPos->isChecked(); |
523 | o_Settings->Map.GotoPosition = cb_CenterPos->isChecked(); |
490 | o_Settings->Map.ShowTrack = cb_ShowRoute->isChecked(); |
524 | o_Settings->Map.ShowTrack = cb_ShowRoute->isChecked(); |
491 | emit set_Settings(o_Settings); |
525 | emit set_Settings(o_Settings); |
492 | } |
526 | } |
493 | 527 | ||
494 | 528 |