Subversion Repositories Projects

Rev

Rev 711 | Go to most recent revision | 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
 
750 KeyOz 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);
172
//    o_Map->setView(QPointF(o_Settings->NAVI.Longitude,o_Settings->NAVI.Latitude));
173
//    o_Map->setView(QPointF(13.5,52.5));
174
    o_Map->setView(QPointF(13.419805,52.431787));
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;}
212
    if (zoomValue > 17) { zoomValue = 17;}
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;
435
        s_WayPoint.reserve[0]         = 0; // reserve
436
        s_WayPoint.reserve[1]         = 0; // reserve
437
        s_WayPoint.reserve[2]         = 0; // reserve
438
        s_WayPoint.reserve[3]         = 0;
439
 
440
        memcpy((unsigned char *)&c_Data, (unsigned char *)&s_WayPoint, sizeof(s_WayPoint));
750 KeyOz 441
        wg_Connection->send_Data(HandlerMK::make_Frame('s', ADDRESS_NC, c_Data, sizeof(s_WayPoint)).toLatin1().data());
674 KeyOz 442
    }
443
    else
444
    {
445
        QMessageBox::warning(this, QA_NAME,tr("Es wurden noch keine aktuellen Positionsdaten vom Mikrokopter empfangen."), QMessageBox::Ok);
446
    }
447
}
448
 
449
//Waypoint-Liste zum MK senden
450
void dlg_Main::send_WayPoints(QList<sWayPoint> t_WayPoints, int t_Pos)
451
{
452
    s_MK_WayPoint s_WayPoint;
453
    double Longitude, Latitude;
454
 
455
    if (t_Pos == 0)
456
    {   // Waypoint-Liste löschen
457
        s_WayPoint.Position.Status = INVALID;
458
 
459
        memcpy((unsigned char *)&c_Data, (unsigned char *)&s_WayPoint, sizeof(s_WayPoint));
750 KeyOz 460
        wg_Connection->send_Data(HandlerMK::make_Frame('w', ADDRESS_NC, c_Data, sizeof(s_WayPoint)).toLatin1().data(), DATA_WRITE_WAYPOINT);
674 KeyOz 461
    }
462
    else
463
    {
464
        int z = t_Pos - 1;
465
        Longitude = t_WayPoints[z].Longitude;
466
        Latitude  = t_WayPoints[z].Latitude;
467
 
468
        if (Longitude < 100)
469
            Longitude *= 10000000+0.5;
470
 
471
        if (Latitude < 100)
472
            Latitude *= 10000000+0.5;
473
 
474
        //fülle Wegpunkt-Daten
475
        s_WayPoint.Position.Altitude = 0;
476
        s_WayPoint.Position.Longitude = int32_t(Longitude);
477
        s_WayPoint.Position.Latitude =  int32_t(Latitude);
478
        s_WayPoint.Position.Status = NEWDATA;
479
        s_WayPoint.Heading = -1;
480
        s_WayPoint.ToleranceRadius = 5;
481
        s_WayPoint.HoldTime = t_WayPoints[z].Time;
482
        s_WayPoint.Event_Flag = 0;
483
        s_WayPoint.reserve[0] = 0; // reserve
484
        s_WayPoint.reserve[1] = 0; // reserve
485
        s_WayPoint.reserve[2] = 0; // reserve
486
        s_WayPoint.reserve[3] = 0; // reserve
487
 
488
        memcpy((unsigned char *)&c_Data, (unsigned char *)&s_WayPoint, sizeof(s_WayPoint));
750 KeyOz 489
        wg_Connection->send_Data(HandlerMK::make_Frame('w', ADDRESS_NC, c_Data, sizeof(s_WayPoint)).toLatin1().data(), DATA_WRITE_WAYPOINT);
674 KeyOz 490
    }
491
}
492
 
493
///////////
494
// Slots //
495
///////////
496
 
497
// About-Dialog
498
void dlg_Main::slot_ac_About()
499
{
500
    QMessageBox::about(this, trUtf8(("Über ")) + QA_NAME, QA_ABOUT);
501
}
502
 
503
void dlg_Main::slot_ac_Toolbar()
504
{
505
    if (ac_Toolbar->isChecked())
506
    {
750 KeyOz 507
        wg_Connection->set_ButtonVisible(false);
674 KeyOz 508
        ToolBar->setVisible(true);
509
        tb_More->setVisible(true);
510
    }
511
    else
512
    {
750 KeyOz 513
        wg_Connection->set_ButtonVisible(true);
674 KeyOz 514
        ToolBar->setVisible(false);
515
        tb_More->setVisible(false);
516
    }
517
}
518
 
750 KeyOz 519
void dlg_Main::slot_ConnectionStatus(int li_Status)
674 KeyOz 520
{
750 KeyOz 521
    if (li_Status)
674 KeyOz 522
    {
750 KeyOz 523
        ac_Connect->setChecked(true);
524
        ac_Connect->setText(tr("Trennen"));
674 KeyOz 525
    }
526
    else
527
    {
750 KeyOz 528
        ac_Connect->setChecked(false);
674 KeyOz 529
        ac_Connect->setText(tr("Verbinden"));
530
    }
531
}
532
 
750 KeyOz 533
void dlg_Main::slot_MK_Version(s_Hardware ls_Version)
674 KeyOz 534
{
750 KeyOz 535
    gs_Version = ls_Version;
536
    setWindowTitle(QA_NAME + " " + QA_VERSION + " - " + ls_Version.Hardware + " " + ls_Version.Version);
674 KeyOz 537
}
538
 
750 KeyOz 539
void dlg_Main::slot_MK_NaviData(s_MK_NaviData ps_MK_NaviData)
674 KeyOz 540
{
750 KeyOz 541
    QString Mode = "NC-Flags : ";
542
    if (ps_MK_NaviData.NCFlags &  0x08) {le_Mode->setText(tr("Range Limit")); Mode += "R";}
543
    if (ps_MK_NaviData.NCFlags &  0x10) {le_Mode->setText(tr("Serial Error")); Mode += "S";}
544
    if (ps_MK_NaviData.NCFlags &  0x20) {le_Mode->setText(tr("Target reached")); Mode += "T";}
545
    if (ps_MK_NaviData.NCFlags &  0x40) {le_Mode->setText(tr("Manual Control")); Mode += "M";}
546
    if (ps_MK_NaviData.NCFlags &  0x01) {le_Mode->setText(tr("Free")); Mode += "F";}
547
    if (ps_MK_NaviData.NCFlags &  0x02) {le_Mode->setText(tr("Position Hold")); Mode += "P";}
548
    if (ps_MK_NaviData.NCFlags &  0x04) {le_Mode->setText(tr("Coming Home")); Mode += "C";}
674 KeyOz 549
 
750 KeyOz 550
    le_WP->setText(QString("%1/").arg(ps_MK_NaviData.WaypointIndex) + QString("%1").arg(ps_MK_NaviData.WaypointNumber));
551
    le_WPTime->setText(QString("%1:").arg(ps_MK_NaviData.TargetHoldTime / 60) + (QString("%1").arg(ps_MK_NaviData.TargetHoldTime % 60)).rightJustified(2, '0'));
552
    le_WPDist->setText(QString("%1m").arg(ps_MK_NaviData.TargetPositionDeviation.Distance / 10));
553
    le_HomeDist->setText(QString("%1m").arg(ps_MK_NaviData.HomePositionDeviation.Distance / 10));
711 KeyOz 554
 
750 KeyOz 555
    add_Position(ps_MK_NaviData);
556
}
674 KeyOz 557
 
750 KeyOz 558
void dlg_Main::slot_MK_WayPoint(int pi_WayPointID)
559
{
560
    if (pi_WayPointID < l_WayPoints.count())
674 KeyOz 561
    {
750 KeyOz 562
        send_WayPoints(l_WayPoints, pi_WayPointID + 1);
674 KeyOz 563
    }
564
}
565
///////////////////////////////////////////////////////////////////
566
// QMK-Maps                                                      //
567
///////////////////////////////////////////////////////////////////
568
 
569
// Zoom der Karte ändern
570
void dlg_Main::slot_Zoom(int t_Zoom)
571
{
572
    o_Map->setZoom(t_Zoom);
573
}
574
 
575
// Karte wechseln
576
void dlg_Main::slot_ChangeMap(int t_Set)
577
{
578
    int zoom = o_Adapter->adaptedZoom();
579
    QPointF a = o_Map->currentCoordinate();
580
 
581
    o_Map->setZoom(0);
582
 
583
    switch(t_Set)
584
    {
585
        case 0 : // OpenStreetMap
586
        {
587
            o_Adapter = new OSMMapAdapter();
588
        }
589
        break;
590
        case 1 : // Yahoo Sat
591
        {
592
            o_Adapter = new TileMapAdapter("tile.openaerialmap.org", "/tiles/1.0.0/openaerialmap-900913/%1/%2/%3.png", 256, 0, 17);
593
        }
594
        break;
595
        case 2 : // Google Maps
596
        {
597
            o_Adapter = new GoogleMapAdapter();
598
        }
599
        break;
600
        case 3 : // Google Sat
601
        {
602
            o_Adapter = new GoogleSatMapAdapter();
603
        }
604
        break;
605
        case 4 : // Yahoo Maps
606
        {
607
            o_Adapter = new YahooMapAdapter();
608
        }
609
        break;
610
        case 5 : // Yahoo Sat
611
        {
612
            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");
613
        }
614
        break;
615
    }
616
 
617
    o_Layer->setMapAdapter(o_Adapter);
618
    o_Click->setMapAdapter(o_Adapter);
619
    o_Info->setMapAdapter(o_Adapter);
620
    o_RouteWP->setMapAdapter(o_Adapter);
621
    o_RouteFL->setMapAdapter(o_Adapter);
622
 
623
    o_Map->updateRequestNew();
624
    o_Map->setZoom(zoom);
625
}
626
 
627
// Click in die Karte
628
void dlg_Main::slot_Click(const QMouseEvent* Event, const QPointF Coord)
629
{
630
    if ((Event->type() == QEvent::MouseButtonPress) && ((Event->button() == Qt::RightButton) || (Event->button() == Qt::MidButton)))
631
    {
632
        sl_Zoom->setValue(o_Adapter->adaptedZoom());
633
    }
634
 
635
    // Überwachen ob Karte verschoben wird
636
    if ((Event->type() == QEvent::MouseButtonPress) && (Event->button() == Qt::LeftButton))
637
    {
638
        MapCenter = o_Map->currentCoordinate();
639
    }
640
 
641
    // Nur wenn nicht Verschoben dann einen Punkt setzen
642
    if ((Event->type() == QEvent::MouseButtonRelease) && (Event->button() == Qt::LeftButton))
643
    {
644
        if (o_Map->currentCoordinate() == MapCenter)
645
        {
646
            if (l_WayPoints.count() < 20)
647
            {
648
                btn_WPAdd->setEnabled(true);
649
            }
650
 
651
            o_Click->removeGeometry(ClickPoint);
652
 
653
            ClickPoint = new CirclePoint(Coord.x(), Coord.y(), 6, "P1", Point::Middle, Pen[2]);
654
 
655
 
656
            LastClick = new Point(Coord.x(), Coord.y());
657
 
658
            ClickPoint->setBaselevel(o_Adapter->adaptedZoom());
659
            o_Click->addGeometry(ClickPoint);
660
 
661
//            o_Click->removeGeometry(Flag);
662
//            Flag = new ImagePoint(Coord.x(), Coord.y(), ":/Flags/Global/Images/Flags/Target.png", "Start");
663
//            Flag->setBaselevel(o_Adapter->adaptedZoom());
664
//            o_Click->addGeometry(Flag);
665
 
666
 
667
            if (cb_Goto->isChecked())
668
            {
669
                send_Target(LastClick);
670
            }
671
        }
672
    }
673
 
674
    o_Map->updateRequestNew();
675
//    qDebug(QString("%1").arg(Coord.x()).toLatin1().data());
676
//    qDebug(QString("%1").arg(Coord.y()).toLatin1().data());
677
}
678
 
679
// WayPoint zur Liste hinzufügen
680
void dlg_Main::slot_btn_WPAdd()
681
{
682
    cb_ShowWPs->setChecked(true);
683
 
684
    sWayPoint WayPoint;
685
 
686
    WayPoint.Longitude = LastClick->longitude();
687
    WayPoint.Latitude = LastClick->latitude();
688
    WayPoint.Time = sb_Time->value();
689
 
690
    l_WayPoints.append(WayPoint);
691
 
692
    o_RouteWP->removeGeometry(l_RouteWP);
693
 
694
    p_RouteWP.append(LastClick);
695
    l_RouteWP = new LineString(p_RouteWP, "", Pen[3]);
696
 
697
    o_RouteWP->addGeometry(l_RouteWP);
698
    o_Map->updateRequestNew();
699
 
700
    btn_WPFly->setEnabled(true);
701
 
702
    if (l_WayPoints.count() == 20)
703
    {
704
        QMessageBox::warning(this, QA_NAME,trUtf8("Wegpunkt-Liste ist voll. Es können maximal 20 Wegpunkte benutzt werden."), QMessageBox::Ok);
705
        btn_WPAdd->setEnabled(false);
706
    }
707
}
708
 
709
// WayPoint-Liste übertragen
710
void dlg_Main::slot_btn_WPFly()
711
{
712
    send_WayPoints(l_WayPoints, 0);
713
}
714
 
715
// WayPpoint-Liste löschen
716
void dlg_Main::slot_btn_WPDelete()
717
{
718
    p_RouteWP.clear();
719
    l_WayPoints.clear();
720
    o_RouteWP->clearGeometries();
721
    l_RouteWP = new LineString(p_RouteWP, "", Pen[0]);
722
//    o_RouteWP->addGeometry(l_RouteWP);
723
//    o_RouteWP->removeGeometry(l_RouteWP);
724
 
725
    o_Map->updateRequestNew();
726
 
727
    btn_WPFly->setEnabled(false);
728
    btn_WPAdd->setEnabled(true);
729
}
730
 
731
// WayPoint-Liste laden
732
void dlg_Main::slot_ac_LoadWayPoints()
733
{
734
    QString Filename = QFileDialog::getOpenFileName(this, "WayPoint-Route laden",  s_Dir.WPRoutes, "Mikrokopter WayPoints(*.mkw);;KML-Datei(*.kml);;Alle Dateien (*)");
735
 
736
    if (!Filename.isEmpty())
737
    {
738
        if (Filename.endsWith(".kml", Qt::CaseInsensitive))
739
        {
740
            cb_ShowWPs->setChecked(true);
741
            btn_WPFly->setEnabled(true);
742
 
743
            show_WayPoints(parse_WayPointKML(Filename));
744
        }
745
        if (Filename.endsWith(".mkw", Qt::CaseInsensitive))
746
        {
747
            cb_ShowWPs->setChecked(true);
748
            btn_WPFly->setEnabled(true);
749
 
750
            show_WayPoints(parse_WayPointMKW(Filename));
751
        }
752
    }
753
}
754
 
755
// WayPoint-Liste speichern
756
void dlg_Main::slot_ac_SaveRoute()
757
{
758
    QString Filename = QFileDialog::getSaveFileName(this, "WayPoint-Route speichern",  s_Dir.WPRoutes, "Mikrokopter WayPoints(*.mkw);;Alle Dateien (*)");
759
 
760
    if (!Filename.isEmpty())
761
    {
762
        if (!(Filename.endsWith(".mkw", Qt::CaseInsensitive)))
763
        {
764
            Filename = Filename + QString(".mkw");
765
        }
766
 
767
        save_WayPointsMKW(Filename);
768
    }
769
}
770
 
771
// Route anzeigen / ausblenden
772
void dlg_Main::slot_ShowWayPoints(bool Show)
773
{
774
    if (Show == true)
775
    {
776
        if (l_RouteWP->hasPoints())
777
        {
778
            o_RouteWP->addGeometry(l_RouteWP);
779
            o_Map->updateRequestNew();
780
        }
781
    }
782
    else
783
    {
784
        o_RouteWP->removeGeometry(l_RouteWP);
785
        o_Map->updateRequestNew();
786
    }
787
}
788
 
789
// Bilddatei als Karteladen.
790
void dlg_Main::slot_ac_LoadMapPic()
791
{
792
    QString Filename = QFileDialog::getOpenFileName(this, "Bild als Karte",  s_Dir.MapPics, "Bilddatei(*.jpg *.png *.gif);;Alle Dateien (*)");
793
 
794
    if (!Filename.isEmpty())
795
    {
796
        QFile *f_Points = new QFile(Filename + ".pos");
797
 
798
        if (f_Points->exists())
799
        {
800
            f_Points->open(QIODevice::ReadOnly | QIODevice::Text);
801
 
802
            QString s_Points;
803
 
804
            while (!f_Points->atEnd())
805
            {
806
                s_Points.append(f_Points->readLine());
807
            }
808
 
809
            f_Points->close();
810
 
811
            QStringList s_Pos = s_Points.split(",");
812
 
813
            FixedImageOverlay* fip = new FixedImageOverlay(s_Pos[0].toDouble(), s_Pos[1].toDouble(), s_Pos[2].toDouble(), s_Pos[3].toDouble(), Filename);
814
 
815
            o_Layer->addGeometry(fip);
816
            o_Map->setView(QPointF(((s_Pos[0].toDouble() + s_Pos[2].toDouble()) / 2),((s_Pos[1].toDouble() + s_Pos[3].toDouble()) / 2)));
817
 
818
            o_Map->updateRequestNew();
819
        }
820
        else
821
        {
822
            dlg_MapPos *f_MapPos = new dlg_MapPos(this);
823
 
824
            if (f_MapPos->exec()==QDialog::Accepted)
825
            {
826
                QString Data = f_MapPos->get_Data();
827
 
828
                f_Points->open(QIODevice::ReadWrite | QIODevice::Text);
829
 
830
                QTextStream out(f_Points);
831
 
832
                out.setRealNumberPrecision(9);
833
 
834
                out << Data << "\n";
835
 
836
                f_Points->close();
837
 
838
                QStringList s_Pos = Data.split(",");
839
 
840
                FixedImageOverlay* fip = new FixedImageOverlay(s_Pos[0].toDouble(), s_Pos[1].toDouble(), s_Pos[2].toDouble(), s_Pos[3].toDouble(), Filename);
841
 
842
                o_Layer->addGeometry(fip);
843
                o_Map->updateRequestNew();
844
            }
845
 
846
        }
847
    }
848
}
849
 
850
// Flug als KML aufzeichnen
851
void dlg_Main::slot_ac_Record()
852
{
853
    if (ac_Record->isChecked())
854
    {
855
        QString f_Name = s_Dir.Flights + "/" + QDate::currentDate().toString(("yyyy-MM-dd")) + "_" + QTime::currentTime().toString("hh-mm");
856
 
857
        ac_Record->setText(tr("Stoppen"));
858
 
859
        o_Record = new QFile(f_Name + ".kml");
860
        o_Record->open(QIODevice::Append | QIODevice::Text);
861
 
862
        QTextStream Out(o_Record);
863
        Out << HandlerKML::get_Header(tr("Mikrokopter Flugaufzeichnung")) << "\n";
864
 
865
    }
866
    else
867
    {
868
        QTextStream Out(o_Record);
869
        Out << HandlerKML::get_Footer() << "\n";
870
        o_Record->close();
871
        ac_Record->setText(tr("Aufzeichnen"));
872
    }
873
}
874
 
875
// WayPpoint-Liste löschen
876
void dlg_Main::slot_ac_RouteDelete()
877
{
878
    p_RouteFL.clear();
879
    l_Track.clear();
880
    o_RouteFL->clearGeometries();
881
    l_RouteFL = new LineString(p_RouteFL, "", Pen[0]);
882
//    o_RouteFL->removeGeometry(l_RouteFL);
883
 
884
    o_Map->updateRequestNew();
885
}
886
 
887
// Programm Ende
888
dlg_Main::~dlg_Main()
889
{
890
    o_Settings->GUI.isMax       = isMaximized();
891
    o_Settings->GUI.Size        = size();
892
    o_Settings->GUI.Point       = pos();
893
    o_Settings->GUI.Toolbar     = ac_Toolbar->isChecked();
894
 
895
    o_Settings->CONFIG.cb_CenterPos = cb_CenterPos->isChecked();
896
    o_Settings->CONFIG.cb_ShowRoute = cb_ShowRoute->isChecked();
897
    o_Settings->CONFIG.cb_ShowWPs   = cb_ShowWPs->isChecked();
898
    o_Settings->CONFIG.cb_Goto      = cb_Goto->isChecked();
899
 
900
    o_Settings->NAVI.StayTime = sb_Time->value();
901
 
902
    o_Settings->write_Settings();
903
 
904
//    qDebug("Ende.");
905
}