Subversion Repositories Projects

Rev

Rev 395 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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