Subversion Repositories Projects

Rev

Rev 750 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
674 KeyOz 1
/***************************************************************************
2
 *   Copyright (C) 2009 by Manuel Schrape                                  *
3
 *   manuel.schrape@gmx.de                                                 *
4
 *                                                                         *
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  *
7
 *   the Free Software Foundation; either version 2 of the License.        *
8
 *                                                                         *
9
 *   This program is distributed in the hope that it will be useful,       *
10
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12
 *   GNU General Public License for more details.                          *
13
 *                                                                         *
14
 *   You should have received a copy of the GNU General Public License     *
15
 *   along with this program; if not, write to the                         *
16
 *   Free Software Foundation, Inc.,                                       *
17
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
18
 ***************************************************************************/
19
 
711 KeyOz 20
#include <QCryptographicHash>
674 KeyOz 21
#include <QMessageBox>
22
#include <QDomDocument>
23
#include <QFile>
24
 
25
#include "dlg_Main.h"
26
#include "dlg_MapPos.h"
27
 
28
// Konstruktor Main-Form
29
dlg_Main::dlg_Main()
30
{
31
    setupUi(this);
32
 
33
    o_Settings = new cSettings();
34
 
750 KeyOz 35
    wg_Connection->set_Client(ID_MAPS, QA_NAME + " " + QA_VERSION, DataFields);
674 KeyOz 36
 
37
    o_Map = new MapControl(QSize(25,25));
38
    l_RouteWP = new LineString();
39
    init_Directorys();
40
    init_GUI();
41
    init_Connections();
42
}
43
 
44
// Grafische Oberfläche initialisieren
45
void dlg_Main::init_GUI()
46
{
47
    setWindowTitle(QA_NAME + " " + QA_VERSION);
48
 
49
    resize(o_Settings->GUI.Size);
50
    move(o_Settings->GUI.Point);
51
 
52
    if (o_Settings->GUI.isMax)
53
    {
54
        showMaximized();
55
    }
56
 
750 KeyOz 57
    wg_Connection->set_SelectVisible(false);
674 KeyOz 58
 
59
    cb_CenterPos->setChecked(o_Settings->CONFIG.cb_CenterPos);
60
    cb_ShowRoute->setChecked(o_Settings->CONFIG.cb_ShowRoute);
61
    cb_ShowWPs->setChecked(o_Settings->CONFIG.cb_ShowWPs);
62
    cb_Goto->setChecked(o_Settings->CONFIG.cb_Goto);
63
 
801 - 64
//    tb_More->addWidget(cb_Maps);
674 KeyOz 65
    cb_Maps->setVisible(false);
66
 
67
    ac_Toolbar->setChecked(o_Settings->GUI.Toolbar);
68
 
69
    if (ac_Toolbar->isChecked())
70
    {
750 KeyOz 71
        wg_Connection->set_ButtonVisible(false);
674 KeyOz 72
    }
73
    else
74
    {
75
        ToolBar->setVisible(false);
76
        tb_More->setVisible(false);
77
    }
78
}
79
 
80
// Signale mit Slots verbinden
81
void dlg_Main::init_Connections()
82
{
750 KeyOz 83
    connect(ac_Connect, SIGNAL(triggered()), wg_Connection, SLOT(slot_btn_Connect()));
674 KeyOz 84
    connect(ac_Toolbar, SIGNAL(triggered()), this, SLOT(slot_ac_Toolbar()));
85
 
86
    connect(sl_Zoom,   SIGNAL(valueChanged(int)), this, SLOT(slot_Zoom(int)));
87
    connect(cb_Maps,   SIGNAL(currentIndexChanged(int)), this, SLOT(slot_ChangeMap(int)));
88
 
89
    connect(cb_ShowWPs, SIGNAL(toggled(bool)), this, SLOT(slot_ShowWayPoints(bool)));
90
 
91
    connect(btn_WPAdd,    SIGNAL(clicked()), this, SLOT(slot_btn_WPAdd()));
92
    connect(btn_WPFly,    SIGNAL(clicked()), this, SLOT(slot_btn_WPFly()));
93
    connect(btn_WPDelete, SIGNAL(clicked()), this, SLOT(slot_btn_WPDelete()));
94
 
95
    connect(ac_LoadRoute, SIGNAL(triggered()), this, SLOT(slot_ac_LoadWayPoints()));
96
    connect(ac_SaveRoute, SIGNAL(triggered()), this, SLOT(slot_ac_SaveRoute()));
97
 
98
    connect(ac_LoadMap,     SIGNAL(triggered()), this, SLOT(slot_ac_LoadMapPic()));
99
    connect(ac_Record,      SIGNAL(triggered()), this, SLOT(slot_ac_Record()));
100
    connect(ac_RouteDelete, SIGNAL(triggered()), this, SLOT(slot_ac_RouteDelete()));
711 KeyOz 101
 
102
    // About QMK-Kernel & About-QT Dialog einfügen
103
    connect(ac_About, SIGNAL(triggered()), this, SLOT(slot_ac_About()));
104
    menu_Help->addAction(trUtf8("Über &Qt"), qApp, SLOT(aboutQt()));
750 KeyOz 105
 
106
    connect(wg_Connection, SIGNAL(sig_Status(int)), this, SLOT(slot_ConnectionStatus(int)));
107
    connect(wg_Connection, SIGNAL(sig_MK_Version(s_Hardware)), this, SLOT(slot_MK_Version(s_Hardware)));
108
    connect(wg_Connection, SIGNAL(sig_MK_NaviData(s_MK_NaviData)), this, SLOT(slot_MK_NaviData(s_MK_NaviData)));
109
    connect(wg_Connection, SIGNAL(sig_MK_WayPoint(int)), this, SLOT(slot_MK_WayPoint(int)));
674 KeyOz 110
}
111
 
112
void dlg_Main::init_Directorys()
113
{
114
    QDir *t_Dir = new QDir();
115
 
116
    s_Dir.MainData = QDir::homePath() + "/QMK-Data";
117
    if (!t_Dir->exists(s_Dir.MainData))
118
    {
119
        t_Dir->mkdir(s_Dir.MainData);
120
    }
121
 
122
    s_Dir.MapCache = s_Dir.MainData + "/Map-Cache";
123
    if (!t_Dir->exists(s_Dir.MapCache))
124
    {
125
        t_Dir->mkdir(s_Dir.MapCache);
126
    }
127
 
128
    s_Dir.WPRoutes = s_Dir.MainData + "/WP-Routes";
129
    if (!t_Dir->exists(s_Dir.WPRoutes))
130
    {
131
        t_Dir->mkdir(s_Dir.WPRoutes);
132
    }
133
 
134
    s_Dir.MapPics = s_Dir.MainData + "/Map-Pics";
135
    if (!t_Dir->exists(s_Dir.MapPics))
136
    {
137
        t_Dir->mkdir(s_Dir.MapPics);
138
    }
139
 
140
    s_Dir.Flights = s_Dir.MainData + "/Flights";
141
    if (!t_Dir->exists(s_Dir.Flights))
142
    {
143
        t_Dir->mkdir(s_Dir.Flights);
144
    }
145
}
146
 
147
///////////////////////////////////////////////////////////////////
148
// QMK-Maps                                                      //
149
///////////////////////////////////////////////////////////////////
150
 
151
void dlg_Main::create_Map()
152
{
153
    o_Map->resize(w_Map->size() - QSize(25,50));
154
    o_Map->enablePersistentCache(s_Dir.MapCache);
155
    o_Map->showScale(true);
156
 
157
    o_Adapter = new OSMMapAdapter();
158
 
159
    o_Layer   = new MapLayer("MapLayer", o_Adapter);
160
    o_Click   = new GeometryLayer("Click", o_Adapter);
161
    o_Info    = new GeometryLayer("Poute", o_Adapter);
162
    o_RouteWP = new GeometryLayer("Route-WayPoint", o_Adapter);
163
    o_RouteFL = new GeometryLayer("Route-Flight", o_Adapter);
164
 
165
    o_Map->addLayer(o_Layer);
166
    o_Map->addLayer(o_Click);
167
    o_Map->addLayer(o_Info);
168
    o_Map->addLayer(o_RouteWP);
169
    o_Map->addLayer(o_RouteFL);
170
 
171
    o_Map->setZoom(17);
801 - 172
    o_Map->setView(QPointF(o_Settings->NAVI.Longitude,o_Settings->NAVI.Latitude));
674 KeyOz 173
//    o_Map->setView(QPointF(13.5,52.5));
801 - 174
//    o_Map->setView(QPointF(13.419805,52.431787));
674 KeyOz 175
    connect(o_Map, SIGNAL(mouseEventCoordinate(const QMouseEvent*, const QPointF)), this, SLOT(slot_Click(const QMouseEvent*, const QPointF)));
176
 
177
    l_Map->addWidget(o_Map);
178
 
179
    sl_Zoom->setValue(17);
180
 
181
    // Flight
182
    Pen[0] = new QPen(QColor(0,0,255,255));
183
    Pen[0]->setWidth(2);
184
    Pen[1] = new QPen(QColor(0,0,255,255));
185
    Pen[1]->setWidth(1);
186
    // WayPoint
187
    Pen[2] = new QPen(QColor(255,0,0,255));
188
    Pen[2]->setWidth(2);
189
    Pen[3] = new QPen(QColor(255,0,0,255));
190
    Pen[3]->setWidth(1);
191
    // Info
192
    Pen[4] = new QPen(QColor(0,128,128,255));
193
    Pen[4]->setWidth(2);
194
    Pen[5] = new QPen(QColor(0,128,128,255));
195
    Pen[5]->setWidth(1);
196
}
197
 
198
// auf Veränderung der Fenstergröße reagieren
199
void dlg_Main::resizeEvent ( QResizeEvent * event )
200
{
201
    event = event;
202
    o_Map->resize(w_Map->size() - QSize(25,25));
203
}
204
 
205
void dlg_Main::wheelEvent(QWheelEvent *event)
206
{
207
    int zoomValue = sl_Zoom->value();
208
    int numDegrees = event->delta() / 8;
209
    int numSteps = numDegrees / 15;
210
    zoomValue += numSteps;
211
    if (zoomValue < 0) { zoomValue = 0;}
801 - 212
    if (zoomValue > 18) { zoomValue = 18;}
674 KeyOz 213
    sl_Zoom->setValue(zoomValue);
214
}
215
 
216
QList<sWayPoint> dlg_Main::parse_WayPointKML(QString s_File)
217
{
218
    QList<sWayPoint> tmp_WayPoints;
219
    sWayPoint tmp_WayPoint;
220
 
221
    QFile f_KML(s_File);
222
    f_KML.open(QIODevice::ReadOnly | QIODevice::Text);
223
 
224
    QByteArray s_KML;
225
 
226
    while (!f_KML.atEnd())
227
    {
228
        s_KML.append(f_KML.readLine());
229
     }
230
 
231
    f_KML.close();
232
 
233
    QDomDocument *UserXML;
234
    UserXML = new QDomDocument;
235
 
236
    UserXML->setContent(s_KML);
237
 
238
    QDomElement Root       = UserXML->firstChildElement("kml");
239
    QDomElement Document   = Root.firstChildElement("Document");
240
    QDomElement Placemark  = Document.firstChildElement("Placemark");
241
    QDomElement Linestring = Placemark.firstChildElement("LineString");
242
 
243
    QString Name = Placemark.firstChildElement("name").toElement().text();
244
 
245
    QString Route = Linestring.firstChildElement("coordinates").toElement().text();
246
 
247
    QStringList s_Points = Route.split(" ");
248
 
249
    QStringList Position;
250
 
251
    for (int z = 0; z < s_Points.count() - 1; z++)
252
    {
253
        if (z != 20)
254
        {
255
           Position = s_Points[z].split(",");
256
           tmp_WayPoint.Longitude = Position[0].toDouble();
257
           tmp_WayPoint.Latitude  = Position[1].toDouble();
258
           tmp_WayPoint.Altitude  = Position[2].toDouble();
259
           tmp_WayPoint.Time      = sb_Time->value();
260
 
261
           tmp_WayPoints.append(tmp_WayPoint);
262
        }
263
        else
264
        {
265
            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);
266
 
267
            btn_WPAdd->setEnabled(false);
268
 
269
            z = s_Points.count();
270
        }
271
    }
272
    return tmp_WayPoints;
273
}
274
 
275
QList<sWayPoint> dlg_Main::parse_WayPointMKW(QString s_File)
276
{
277
    QList<sWayPoint> tmp_WayPoints;
278
    sWayPoint tmp_WayPoint;
279
 
280
    QFile f_MKW(s_File);
281
    f_MKW.open(QIODevice::ReadOnly | QIODevice::Text);
282
 
283
    QString s_MKW;
284
 
285
    while (!f_MKW.atEnd())
286
    {
287
        s_MKW.append(f_MKW.readLine());
288
     }
289
 
290
    f_MKW.close();
291
 
292
    QStringList s_Points = s_MKW.split(" ");
293
 
294
    QStringList Position;
295
 
296
    for (int z = 0; z < s_Points.count() - 1; z++)
297
    {
298
        if (z != 20)
299
        {
300
           Position = s_Points[z].split(",");
301
           tmp_WayPoint.Longitude = Position[0].toDouble();
302
           tmp_WayPoint.Latitude  = Position[1].toDouble();
303
           tmp_WayPoint.Altitude  = Position[2].toDouble();
304
           tmp_WayPoint.Time      = Position[3].toInt();
305
 
306
           tmp_WayPoints.append(tmp_WayPoint);
307
        }
308
        else
309
        {
310
            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);
311
 
312
            btn_WPAdd->setEnabled(false);
313
 
314
            z = s_Points.count();
315
        }
316
    }
317
    return tmp_WayPoints;
318
}
319
 
320
// Waypoint-Route anzeigen in Karte
321
void dlg_Main::show_WayPoints(QList<sWayPoint> WayPoints)
322
{
323
    Point* p_Point;
324
 
325
    o_RouteWP->removeGeometry(l_RouteWP);
326
    p_RouteWP.clear();
327
    l_WayPoints.clear();
328
 
329
    l_WayPoints = WayPoints;
330
 
331
    for (int z = 0; z < WayPoints.count(); z++)
332
    {
333
        p_Point = new Point(WayPoints[z].Longitude, WayPoints[z].Latitude);
334
 
335
        p_RouteWP.append(p_Point);
336
    }
337
 
338
    l_RouteWP = new LineString(p_RouteWP, "", Pen[3]);
339
    o_RouteWP->addGeometry(l_RouteWP);
340
 
341
    o_Map->setView(p_Point);
342
 
343
    o_Map->updateRequestNew();
344
}
345
 
346
// Waypoint-Liste speichern
347
void dlg_Main::save_WayPointsMKW(QString s_File)
348
{
349
    QFile *f_MKW = new QFile(s_File);
350
 
351
    f_MKW->open(QIODevice::ReadWrite | QIODevice::Text);
352
 
353
    QTextStream out(f_MKW);
354
 
355
    out.setRealNumberPrecision(9);
356
 
357
    for (int z = 0; z < l_WayPoints.count(); z++)
358
    {
359
        out << l_WayPoints[z].Longitude << "," << l_WayPoints[z].Latitude << "," << l_WayPoints[z].Altitude << "," << l_WayPoints[z].Time << " \n";
360
    }
361
 
362
    f_MKW->close();
363
}
364
 
365
// Aktuelle MK-Position hinzufügen
366
void dlg_Main::add_Position(s_MK_NaviData t_NaviData)
367
{
368
    sWayPoint WayPoint;
369
 
370
    WayPoint.Longitude = HandlerMK::Int2Double(t_NaviData.CurrentPosition.Longitude, 7);
371
    WayPoint.Latitude = HandlerMK::Int2Double(t_NaviData.CurrentPosition.Latitude, 7);
372
    WayPoint.Altitude = HandlerMK::Int2Double(t_NaviData.CurrentPosition.Altitude, 3);
373
 
374
    o_Settings->NAVI.Latitude  = WayPoint.Latitude;
375
    o_Settings->NAVI.Longitude = WayPoint.Longitude;
376
 
377
    l_Track.append(WayPoint);
378
 
379
    o_RouteFL->removeGeometry(l_RouteFL);
380
    p_RouteFL.append(new Point(WayPoint.Longitude, WayPoint.Latitude));
381
 
382
    o_Click->removeGeometry(LastPos);
383
 
384
    Point* P = new CirclePoint(WayPoint.Longitude, WayPoint.Latitude, "P1", Point::Middle, Pen[0]);
385
    LastPos = P;
386
//    P->setBaselevel(17);
387
    o_Click->addGeometry(P);
388
 
389
    // Target anzeigen
390
    o_Click->removeGeometry(Target);
391
 
392
    Target = new ImagePoint( HandlerMK::Int2Double(t_NaviData.TargetPosition.Longitude, 7), HandlerMK::Int2Double(t_NaviData.TargetPosition.Latitude, 7), ":/Flags/Global/Images/Flags/Target.png", "Start");
393
    Target->setBaselevel(o_Adapter->adaptedZoom());
394
    o_Click->addGeometry(Target);
395
 
396
    if (cb_CenterPos->isChecked())
397
    {
398
        o_Map->setView(QPointF(WayPoint.Longitude, WayPoint.Latitude));
399
    }
400
 
401
    if (cb_ShowRoute->isChecked())
402
    {
403
        l_RouteFL = new LineString(p_RouteFL, "", Pen[1]);
404
 
405
        o_RouteFL->addGeometry(l_RouteFL);
406
    }
407
    o_Map->updateRequestNew();
408
 
409
    if (ac_Record->isChecked())
410
    {
411
        QTextStream Out(o_Record);
412
 
413
        Out.setRealNumberPrecision(9);
414
 
415
        Out << WayPoint.Longitude << ", " << WayPoint.Latitude << ", " << WayPoint.Altitude << "\n";
416
    }
417
}
418
 
419
// Ein Ziel anfliegen.
420
// TODO: Check auf  Entfernung zur IST-Position.
421
void dlg_Main::send_Target(Point *t_Target)
422
{
711 KeyOz 423
    if (l_Track.count() > 0)
674 KeyOz 424
    {
425
        s_MK_WayPoint s_WayPoint;
426
 
427
        s_WayPoint.Position.Latitude  = int32_t(t_Target->latitude() * 10000000+0.5);
428
        s_WayPoint.Position.Longitude = int32_t(t_Target->longitude() * 10000000+0.5);
429
        s_WayPoint.Position.Altitude  = 0;
430
        s_WayPoint.Position.Status    = NEWDATA;
431
        s_WayPoint.Heading            = -1;
432
        s_WayPoint.ToleranceRadius    = 5;
433
        s_WayPoint.HoldTime           = sb_Time->value();
434
        s_WayPoint.Event_Flag         = 0;
801 - 435
        s_WayPoint.Index              = 1;
674 KeyOz 436
        s_WayPoint.reserve[0]         = 0; // reserve
437
        s_WayPoint.reserve[1]         = 0; // reserve
438
        s_WayPoint.reserve[2]         = 0; // reserve
439
        s_WayPoint.reserve[3]         = 0;
440
 
441
        memcpy((unsigned char *)&c_Data, (unsigned char *)&s_WayPoint, sizeof(s_WayPoint));
750 KeyOz 442
        wg_Connection->send_Data(HandlerMK::make_Frame('s', ADDRESS_NC, c_Data, sizeof(s_WayPoint)).toLatin1().data());
674 KeyOz 443
    }
444
    else
445
    {
446
        QMessageBox::warning(this, QA_NAME,tr("Es wurden noch keine aktuellen Positionsdaten vom Mikrokopter empfangen."), QMessageBox::Ok);
447
    }
448
}
449
 
450
//Waypoint-Liste zum MK senden
451
void dlg_Main::send_WayPoints(QList<sWayPoint> t_WayPoints, int t_Pos)
452
{
453
    s_MK_WayPoint s_WayPoint;
454
    double Longitude, Latitude;
455
 
456
    if (t_Pos == 0)
457
    {   // Waypoint-Liste löschen
458
        s_WayPoint.Position.Status = INVALID;
459
 
460
        memcpy((unsigned char *)&c_Data, (unsigned char *)&s_WayPoint, sizeof(s_WayPoint));
750 KeyOz 461
        wg_Connection->send_Data(HandlerMK::make_Frame('w', ADDRESS_NC, c_Data, sizeof(s_WayPoint)).toLatin1().data(), DATA_WRITE_WAYPOINT);
674 KeyOz 462
    }
463
    else
464
    {
465
        int z = t_Pos - 1;
466
        Longitude = t_WayPoints[z].Longitude;
467
        Latitude  = t_WayPoints[z].Latitude;
468
 
469
        if (Longitude < 100)
470
            Longitude *= 10000000+0.5;
471
 
472
        if (Latitude < 100)
473
            Latitude *= 10000000+0.5;
474
 
475
        //fülle Wegpunkt-Daten
476
        s_WayPoint.Position.Altitude = 0;
477
        s_WayPoint.Position.Longitude = int32_t(Longitude);
478
        s_WayPoint.Position.Latitude =  int32_t(Latitude);
479
        s_WayPoint.Position.Status = NEWDATA;
480
        s_WayPoint.Heading = -1;
481
        s_WayPoint.ToleranceRadius = 5;
482
        s_WayPoint.HoldTime = t_WayPoints[z].Time;
483
        s_WayPoint.Event_Flag = 0;
801 - 484
        s_WayPoint.Index      = t_Pos;
674 KeyOz 485
        s_WayPoint.reserve[0] = 0; // reserve
486
        s_WayPoint.reserve[1] = 0; // reserve
487
        s_WayPoint.reserve[2] = 0; // reserve
488
        s_WayPoint.reserve[3] = 0; // reserve
489
 
490
        memcpy((unsigned char *)&c_Data, (unsigned char *)&s_WayPoint, sizeof(s_WayPoint));
750 KeyOz 491
        wg_Connection->send_Data(HandlerMK::make_Frame('w', ADDRESS_NC, c_Data, sizeof(s_WayPoint)).toLatin1().data(), DATA_WRITE_WAYPOINT);
674 KeyOz 492
    }
493
}
494
 
495
///////////
496
// Slots //
497
///////////
498
 
499
// About-Dialog
500
void dlg_Main::slot_ac_About()
501
{
502
    QMessageBox::about(this, trUtf8(("Über ")) + QA_NAME, QA_ABOUT);
503
}
504
 
505
void dlg_Main::slot_ac_Toolbar()
506
{
507
    if (ac_Toolbar->isChecked())
508
    {
750 KeyOz 509
        wg_Connection->set_ButtonVisible(false);
674 KeyOz 510
        ToolBar->setVisible(true);
511
        tb_More->setVisible(true);
512
    }
513
    else
514
    {
750 KeyOz 515
        wg_Connection->set_ButtonVisible(true);
674 KeyOz 516
        ToolBar->setVisible(false);
517
        tb_More->setVisible(false);
518
    }
519
}
520
 
750 KeyOz 521
void dlg_Main::slot_ConnectionStatus(int li_Status)
674 KeyOz 522
{
750 KeyOz 523
    if (li_Status)
674 KeyOz 524
    {
750 KeyOz 525
        ac_Connect->setChecked(true);
526
        ac_Connect->setText(tr("Trennen"));
674 KeyOz 527
    }
528
    else
529
    {
750 KeyOz 530
        ac_Connect->setChecked(false);
674 KeyOz 531
        ac_Connect->setText(tr("Verbinden"));
532
    }
533
}
534
 
750 KeyOz 535
void dlg_Main::slot_MK_Version(s_Hardware ls_Version)
674 KeyOz 536
{
750 KeyOz 537
    gs_Version = ls_Version;
538
    setWindowTitle(QA_NAME + " " + QA_VERSION + " - " + ls_Version.Hardware + " " + ls_Version.Version);
674 KeyOz 539
}
540
 
750 KeyOz 541
void dlg_Main::slot_MK_NaviData(s_MK_NaviData ps_MK_NaviData)
674 KeyOz 542
{
750 KeyOz 543
    QString Mode = "NC-Flags : ";
544
    if (ps_MK_NaviData.NCFlags &  0x08) {le_Mode->setText(tr("Range Limit")); Mode += "R";}
545
    if (ps_MK_NaviData.NCFlags &  0x10) {le_Mode->setText(tr("Serial Error")); Mode += "S";}
546
    if (ps_MK_NaviData.NCFlags &  0x20) {le_Mode->setText(tr("Target reached")); Mode += "T";}
547
    if (ps_MK_NaviData.NCFlags &  0x40) {le_Mode->setText(tr("Manual Control")); Mode += "M";}
548
    if (ps_MK_NaviData.NCFlags &  0x01) {le_Mode->setText(tr("Free")); Mode += "F";}
549
    if (ps_MK_NaviData.NCFlags &  0x02) {le_Mode->setText(tr("Position Hold")); Mode += "P";}
550
    if (ps_MK_NaviData.NCFlags &  0x04) {le_Mode->setText(tr("Coming Home")); Mode += "C";}
674 KeyOz 551
 
750 KeyOz 552
    le_WP->setText(QString("%1/").arg(ps_MK_NaviData.WaypointIndex) + QString("%1").arg(ps_MK_NaviData.WaypointNumber));
553
    le_WPTime->setText(QString("%1:").arg(ps_MK_NaviData.TargetHoldTime / 60) + (QString("%1").arg(ps_MK_NaviData.TargetHoldTime % 60)).rightJustified(2, '0'));
554
    le_WPDist->setText(QString("%1m").arg(ps_MK_NaviData.TargetPositionDeviation.Distance / 10));
555
    le_HomeDist->setText(QString("%1m").arg(ps_MK_NaviData.HomePositionDeviation.Distance / 10));
801 - 556
    le_Sats->setText(QString("%1").arg(ps_MK_NaviData.SatsInUse));
711 KeyOz 557
 
750 KeyOz 558
    add_Position(ps_MK_NaviData);
559
}
674 KeyOz 560
 
750 KeyOz 561
void dlg_Main::slot_MK_WayPoint(int pi_WayPointID)
562
{
563
    if (pi_WayPointID < l_WayPoints.count())
674 KeyOz 564
    {
750 KeyOz 565
        send_WayPoints(l_WayPoints, pi_WayPointID + 1);
674 KeyOz 566
    }
567
}
568
///////////////////////////////////////////////////////////////////
569
// QMK-Maps                                                      //
570
///////////////////////////////////////////////////////////////////
571
 
572
// Zoom der Karte ändern
573
void dlg_Main::slot_Zoom(int t_Zoom)
574
{
575
    o_Map->setZoom(t_Zoom);
576
}
577
 
578
// Karte wechseln
579
void dlg_Main::slot_ChangeMap(int t_Set)
580
{
581
    int zoom = o_Adapter->adaptedZoom();
582
    QPointF a = o_Map->currentCoordinate();
583
 
584
    o_Map->setZoom(0);
585
 
586
    switch(t_Set)
587
    {
588
        case 0 : // OpenStreetMap
589
        {
590
            o_Adapter = new OSMMapAdapter();
591
        }
592
        break;
593
        case 1 : // Yahoo Sat
594
        {
595
            o_Adapter = new TileMapAdapter("tile.openaerialmap.org", "/tiles/1.0.0/openaerialmap-900913/%1/%2/%3.png", 256, 0, 17);
596
        }
597
        break;
598
        case 2 : // Google Maps
599
        {
600
            o_Adapter = new GoogleMapAdapter();
601
        }
602
        break;
603
        case 3 : // Google Sat
604
        {
605
            o_Adapter = new GoogleSatMapAdapter();
606
        }
607
        break;
608
        case 4 : // Yahoo Maps
609
        {
610
            o_Adapter = new YahooMapAdapter();
611
        }
612
        break;
613
        case 5 : // Yahoo Sat
614
        {
615
            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");
616
        }
617
        break;
618
    }
619
 
620
    o_Layer->setMapAdapter(o_Adapter);
621
    o_Click->setMapAdapter(o_Adapter);
622
    o_Info->setMapAdapter(o_Adapter);
623
    o_RouteWP->setMapAdapter(o_Adapter);
624
    o_RouteFL->setMapAdapter(o_Adapter);
625
 
626
    o_Map->updateRequestNew();
627
    o_Map->setZoom(zoom);
628
}
629
 
630
// Click in die Karte
631
void dlg_Main::slot_Click(const QMouseEvent* Event, const QPointF Coord)
632
{
633
    if ((Event->type() == QEvent::MouseButtonPress) && ((Event->button() == Qt::RightButton) || (Event->button() == Qt::MidButton)))
634
    {
635
        sl_Zoom->setValue(o_Adapter->adaptedZoom());
636
    }
637
 
638
    // Überwachen ob Karte verschoben wird
639
    if ((Event->type() == QEvent::MouseButtonPress) && (Event->button() == Qt::LeftButton))
640
    {
641
        MapCenter = o_Map->currentCoordinate();
642
    }
643
 
644
    // Nur wenn nicht Verschoben dann einen Punkt setzen
645
    if ((Event->type() == QEvent::MouseButtonRelease) && (Event->button() == Qt::LeftButton))
646
    {
647
        if (o_Map->currentCoordinate() == MapCenter)
648
        {
649
            if (l_WayPoints.count() < 20)
650
            {
651
                btn_WPAdd->setEnabled(true);
652
            }
653
 
654
            o_Click->removeGeometry(ClickPoint);
655
 
656
            ClickPoint = new CirclePoint(Coord.x(), Coord.y(), 6, "P1", Point::Middle, Pen[2]);
657
 
658
 
659
            LastClick = new Point(Coord.x(), Coord.y());
660
 
661
            ClickPoint->setBaselevel(o_Adapter->adaptedZoom());
662
            o_Click->addGeometry(ClickPoint);
663
 
664
//            o_Click->removeGeometry(Flag);
665
//            Flag = new ImagePoint(Coord.x(), Coord.y(), ":/Flags/Global/Images/Flags/Target.png", "Start");
666
//            Flag->setBaselevel(o_Adapter->adaptedZoom());
667
//            o_Click->addGeometry(Flag);
668
 
669
 
670
            if (cb_Goto->isChecked())
671
            {
672
                send_Target(LastClick);
673
            }
674
        }
675
    }
676
 
677
    o_Map->updateRequestNew();
678
//    qDebug(QString("%1").arg(Coord.x()).toLatin1().data());
679
//    qDebug(QString("%1").arg(Coord.y()).toLatin1().data());
680
}
681
 
682
// WayPoint zur Liste hinzufügen
683
void dlg_Main::slot_btn_WPAdd()
684
{
685
    cb_ShowWPs->setChecked(true);
686
 
687
    sWayPoint WayPoint;
688
 
689
    WayPoint.Longitude = LastClick->longitude();
690
    WayPoint.Latitude = LastClick->latitude();
691
    WayPoint.Time = sb_Time->value();
692
 
693
    l_WayPoints.append(WayPoint);
694
 
695
    o_RouteWP->removeGeometry(l_RouteWP);
696
 
697
    p_RouteWP.append(LastClick);
698
    l_RouteWP = new LineString(p_RouteWP, "", Pen[3]);
699
 
700
    o_RouteWP->addGeometry(l_RouteWP);
701
    o_Map->updateRequestNew();
702
 
703
    btn_WPFly->setEnabled(true);
704
 
705
    if (l_WayPoints.count() == 20)
706
    {
707
        QMessageBox::warning(this, QA_NAME,trUtf8("Wegpunkt-Liste ist voll. Es können maximal 20 Wegpunkte benutzt werden."), QMessageBox::Ok);
708
        btn_WPAdd->setEnabled(false);
709
    }
710
}
711
 
712
// WayPoint-Liste übertragen
713
void dlg_Main::slot_btn_WPFly()
714
{
715
    send_WayPoints(l_WayPoints, 0);
716
}
717
 
718
// WayPpoint-Liste löschen
719
void dlg_Main::slot_btn_WPDelete()
720
{
721
    p_RouteWP.clear();
722
    l_WayPoints.clear();
723
    o_RouteWP->clearGeometries();
724
    l_RouteWP = new LineString(p_RouteWP, "", Pen[0]);
725
//    o_RouteWP->addGeometry(l_RouteWP);
726
//    o_RouteWP->removeGeometry(l_RouteWP);
727
 
728
    o_Map->updateRequestNew();
729
 
730
    btn_WPFly->setEnabled(false);
731
    btn_WPAdd->setEnabled(true);
732
}
733
 
734
// WayPoint-Liste laden
735
void dlg_Main::slot_ac_LoadWayPoints()
736
{
737
    QString Filename = QFileDialog::getOpenFileName(this, "WayPoint-Route laden",  s_Dir.WPRoutes, "Mikrokopter WayPoints(*.mkw);;KML-Datei(*.kml);;Alle Dateien (*)");
738
 
739
    if (!Filename.isEmpty())
740
    {
741
        if (Filename.endsWith(".kml", Qt::CaseInsensitive))
742
        {
743
            cb_ShowWPs->setChecked(true);
744
            btn_WPFly->setEnabled(true);
745
 
746
            show_WayPoints(parse_WayPointKML(Filename));
747
        }
748
        if (Filename.endsWith(".mkw", Qt::CaseInsensitive))
749
        {
750
            cb_ShowWPs->setChecked(true);
751
            btn_WPFly->setEnabled(true);
752
 
753
            show_WayPoints(parse_WayPointMKW(Filename));
754
        }
755
    }
756
}
757
 
758
// WayPoint-Liste speichern
759
void dlg_Main::slot_ac_SaveRoute()
760
{
761
    QString Filename = QFileDialog::getSaveFileName(this, "WayPoint-Route speichern",  s_Dir.WPRoutes, "Mikrokopter WayPoints(*.mkw);;Alle Dateien (*)");
762
 
763
    if (!Filename.isEmpty())
764
    {
765
        if (!(Filename.endsWith(".mkw", Qt::CaseInsensitive)))
766
        {
767
            Filename = Filename + QString(".mkw");
768
        }
769
 
770
        save_WayPointsMKW(Filename);
771
    }
772
}
773
 
774
// Route anzeigen / ausblenden
775
void dlg_Main::slot_ShowWayPoints(bool Show)
776
{
777
    if (Show == true)
778
    {
779
        if (l_RouteWP->hasPoints())
780
        {
781
            o_RouteWP->addGeometry(l_RouteWP);
782
            o_Map->updateRequestNew();
783
        }
784
    }
785
    else
786
    {
787
        o_RouteWP->removeGeometry(l_RouteWP);
788
        o_Map->updateRequestNew();
789
    }
790
}
791
 
792
// Bilddatei als Karteladen.
793
void dlg_Main::slot_ac_LoadMapPic()
794
{
795
    QString Filename = QFileDialog::getOpenFileName(this, "Bild als Karte",  s_Dir.MapPics, "Bilddatei(*.jpg *.png *.gif);;Alle Dateien (*)");
796
 
797
    if (!Filename.isEmpty())
798
    {
799
        QFile *f_Points = new QFile(Filename + ".pos");
800
 
801
        if (f_Points->exists())
802
        {
803
            f_Points->open(QIODevice::ReadOnly | QIODevice::Text);
804
 
805
            QString s_Points;
806
 
807
            while (!f_Points->atEnd())
808
            {
809
                s_Points.append(f_Points->readLine());
810
            }
811
 
812
            f_Points->close();
813
 
814
            QStringList s_Pos = s_Points.split(",");
815
 
816
            FixedImageOverlay* fip = new FixedImageOverlay(s_Pos[0].toDouble(), s_Pos[1].toDouble(), s_Pos[2].toDouble(), s_Pos[3].toDouble(), Filename);
817
 
818
            o_Layer->addGeometry(fip);
819
            o_Map->setView(QPointF(((s_Pos[0].toDouble() + s_Pos[2].toDouble()) / 2),((s_Pos[1].toDouble() + s_Pos[3].toDouble()) / 2)));
820
 
821
            o_Map->updateRequestNew();
822
        }
823
        else
824
        {
825
            dlg_MapPos *f_MapPos = new dlg_MapPos(this);
826
 
827
            if (f_MapPos->exec()==QDialog::Accepted)
828
            {
829
                QString Data = f_MapPos->get_Data();
830
 
831
                f_Points->open(QIODevice::ReadWrite | QIODevice::Text);
832
 
833
                QTextStream out(f_Points);
834
 
835
                out.setRealNumberPrecision(9);
836
 
837
                out << Data << "\n";
838
 
839
                f_Points->close();
840
 
841
                QStringList s_Pos = Data.split(",");
842
 
843
                FixedImageOverlay* fip = new FixedImageOverlay(s_Pos[0].toDouble(), s_Pos[1].toDouble(), s_Pos[2].toDouble(), s_Pos[3].toDouble(), Filename);
844
 
845
                o_Layer->addGeometry(fip);
846
                o_Map->updateRequestNew();
847
            }
848
 
849
        }
850
    }
851
}
852
 
853
// Flug als KML aufzeichnen
854
void dlg_Main::slot_ac_Record()
855
{
856
    if (ac_Record->isChecked())
857
    {
858
        QString f_Name = s_Dir.Flights + "/" + QDate::currentDate().toString(("yyyy-MM-dd")) + "_" + QTime::currentTime().toString("hh-mm");
859
 
860
        ac_Record->setText(tr("Stoppen"));
861
 
862
        o_Record = new QFile(f_Name + ".kml");
863
        o_Record->open(QIODevice::Append | QIODevice::Text);
864
 
865
        QTextStream Out(o_Record);
866
        Out << HandlerKML::get_Header(tr("Mikrokopter Flugaufzeichnung")) << "\n";
867
 
868
    }
869
    else
870
    {
871
        QTextStream Out(o_Record);
872
        Out << HandlerKML::get_Footer() << "\n";
873
        o_Record->close();
874
        ac_Record->setText(tr("Aufzeichnen"));
875
    }
876
}
877
 
878
// WayPpoint-Liste löschen
879
void dlg_Main::slot_ac_RouteDelete()
880
{
881
    p_RouteFL.clear();
882
    l_Track.clear();
883
    o_RouteFL->clearGeometries();
884
    l_RouteFL = new LineString(p_RouteFL, "", Pen[0]);
885
//    o_RouteFL->removeGeometry(l_RouteFL);
886
 
887
    o_Map->updateRequestNew();
888
}
889
 
890
// Programm Ende
891
dlg_Main::~dlg_Main()
892
{
893
    o_Settings->GUI.isMax       = isMaximized();
894
    o_Settings->GUI.Size        = size();
895
    o_Settings->GUI.Point       = pos();
896
    o_Settings->GUI.Toolbar     = ac_Toolbar->isChecked();
897
 
898
    o_Settings->CONFIG.cb_CenterPos = cb_CenterPos->isChecked();
899
    o_Settings->CONFIG.cb_ShowRoute = cb_ShowRoute->isChecked();
900
    o_Settings->CONFIG.cb_ShowWPs   = cb_ShowWPs->isChecked();
901
    o_Settings->CONFIG.cb_Goto      = cb_Goto->isChecked();
902
 
903
    o_Settings->NAVI.StayTime = sb_Time->value();
904
 
905
    o_Settings->write_Settings();
906
 
907
//    qDebug("Ende.");
908
}