Subversion Repositories Projects

Rev

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

Rev 711 Rev 750
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
 
19
 
20
#include <QCryptographicHash>
20
#include <QCryptographicHash>
21
#include <QMessageBox>
21
#include <QMessageBox>
22
#include <QDomDocument>
22
#include <QDomDocument>
23
#include <QFile>
23
#include <QFile>
24
 
24
 
25
#include "dlg_Main.h"
25
#include "dlg_Main.h"
26
#include "dlg_MapPos.h"
26
#include "dlg_MapPos.h"
27
 
27
 
28
// Konstruktor Main-Form
28
// Konstruktor Main-Form
29
dlg_Main::dlg_Main()
29
dlg_Main::dlg_Main()
30
{
30
{
31
    setupUi(this);
31
    setupUi(this);
32
 
32
 
33
    o_Settings = new cSettings();
33
    o_Settings = new cSettings();
34
 
34
 
35
    o_Input = new Input();
35
    wg_Connection->set_Client(ID_MAPS, QA_NAME + " " + QA_VERSION, DataFields);
36
 
36
 
37
    o_Map = new MapControl(QSize(25,25));
37
    o_Map = new MapControl(QSize(25,25));
38
    l_RouteWP = new LineString();
38
    l_RouteWP = new LineString();
39
    init_Directorys();
39
    init_Directorys();
40
    init_GUI();
40
    init_GUI();
41
    init_Connections();
41
    init_Connections();
42
}
42
}
43
 
43
 
44
// Grafische Oberfläche initialisieren
44
// Grafische Oberfläche initialisieren
45
void dlg_Main::init_GUI()
45
void dlg_Main::init_GUI()
46
{
46
{
47
    setWindowTitle(QA_NAME + " " + QA_VERSION);
47
    setWindowTitle(QA_NAME + " " + QA_VERSION);
48
 
48
 
49
    resize(o_Settings->GUI.Size);
49
    resize(o_Settings->GUI.Size);
50
    move(o_Settings->GUI.Point);
50
    move(o_Settings->GUI.Point);
51
 
51
 
52
    if (o_Settings->GUI.isMax)
52
    if (o_Settings->GUI.isMax)
53
    {
53
    {
54
        showMaximized();
54
        showMaximized();
55
    }
55
    }
56
 
-
 
57
    for(int z = 0; z < o_Settings->SERVER.IP_MAX; z++)
-
 
58
    {
-
 
59
        if (cb_Server->findText(o_Settings->SERVER.IP[z]) == -1)
-
 
60
        {
-
 
61
            cb_Server->addItem(o_Settings->SERVER.IP[z]);
-
 
62
        }
-
 
63
    }
-
 
64
 
-
 
65
    cb_Server->setCurrentIndex(o_Settings->SERVER.IP_ID);
-
 
66
 
-
 
67
    le_Password->setText(o_Settings->SERVER.Password);
-
 
68
 
56
 
69
    sb_Intervall->setValue(o_Settings->DATA.Intervall);
57
    wg_Connection->set_SelectVisible(false);
70
 
58
 
71
    cb_CenterPos->setChecked(o_Settings->CONFIG.cb_CenterPos);
59
    cb_CenterPos->setChecked(o_Settings->CONFIG.cb_CenterPos);
72
    cb_ShowRoute->setChecked(o_Settings->CONFIG.cb_ShowRoute);
60
    cb_ShowRoute->setChecked(o_Settings->CONFIG.cb_ShowRoute);
73
    cb_ShowWPs->setChecked(o_Settings->CONFIG.cb_ShowWPs);
61
    cb_ShowWPs->setChecked(o_Settings->CONFIG.cb_ShowWPs);
74
    cb_Goto->setChecked(o_Settings->CONFIG.cb_Goto);
62
    cb_Goto->setChecked(o_Settings->CONFIG.cb_Goto);
75
 
63
 
76
//    tb_More->addWidget(cb_Maps);
64
    tb_More->addWidget(cb_Maps);
77
    cb_Maps->setVisible(false);
65
    cb_Maps->setVisible(false);
78
 
66
 
79
    ac_Toolbar->setChecked(o_Settings->GUI.Toolbar);
67
    ac_Toolbar->setChecked(o_Settings->GUI.Toolbar);
80
 
68
 
81
    if (ac_Toolbar->isChecked())
69
    if (ac_Toolbar->isChecked())
82
    {
70
    {
83
        btn_Connect->setVisible(false);
71
        wg_Connection->set_ButtonVisible(false);
84
    }
72
    }
85
    else
73
    else
86
    {
74
    {
87
        ToolBar->setVisible(false);
75
        ToolBar->setVisible(false);
88
        tb_More->setVisible(false);
76
        tb_More->setVisible(false);
89
    }
77
    }
90
}
78
}
91
 
79
 
92
// Signale mit Slots verbinden
80
// Signale mit Slots verbinden
93
void dlg_Main::init_Connections()
81
void dlg_Main::init_Connections()
94
{
82
{
95
    connect(ac_Connect, SIGNAL(triggered()), this, SLOT(slot_ac_Connect()));
83
    connect(ac_Connect, SIGNAL(triggered()), wg_Connection, SLOT(slot_btn_Connect()));
96
    connect(ac_Toolbar, SIGNAL(triggered()), this, SLOT(slot_ac_Toolbar()));
84
    connect(ac_Toolbar, SIGNAL(triggered()), this, SLOT(slot_ac_Toolbar()));
97
 
-
 
98
    connect(sb_Intervall, SIGNAL(valueChanged(int)), this, SLOT(slot_sb_Intervall(int)));
-
 
99
 
85
 
100
    connect(sl_Zoom,   SIGNAL(valueChanged(int)), this, SLOT(slot_Zoom(int)));
86
    connect(sl_Zoom,   SIGNAL(valueChanged(int)), this, SLOT(slot_Zoom(int)));
101
    connect(cb_Maps,   SIGNAL(currentIndexChanged(int)), this, SLOT(slot_ChangeMap(int)));
87
    connect(cb_Maps,   SIGNAL(currentIndexChanged(int)), this, SLOT(slot_ChangeMap(int)));
102
 
88
 
103
    connect(cb_ShowWPs, SIGNAL(toggled(bool)), this, SLOT(slot_ShowWayPoints(bool)));
89
    connect(cb_ShowWPs, SIGNAL(toggled(bool)), this, SLOT(slot_ShowWayPoints(bool)));
104
 
90
 
105
    connect(btn_WPAdd,    SIGNAL(clicked()), this, SLOT(slot_btn_WPAdd()));
91
    connect(btn_WPAdd,    SIGNAL(clicked()), this, SLOT(slot_btn_WPAdd()));
106
    connect(btn_WPFly,    SIGNAL(clicked()), this, SLOT(slot_btn_WPFly()));
92
    connect(btn_WPFly,    SIGNAL(clicked()), this, SLOT(slot_btn_WPFly()));
107
    connect(btn_WPDelete, SIGNAL(clicked()), this, SLOT(slot_btn_WPDelete()));
93
    connect(btn_WPDelete, SIGNAL(clicked()), this, SLOT(slot_btn_WPDelete()));
108
 
94
 
109
    connect(ac_LoadRoute, SIGNAL(triggered()), this, SLOT(slot_ac_LoadWayPoints()));
95
    connect(ac_LoadRoute, SIGNAL(triggered()), this, SLOT(slot_ac_LoadWayPoints()));
110
    connect(ac_SaveRoute, SIGNAL(triggered()), this, SLOT(slot_ac_SaveRoute()));
96
    connect(ac_SaveRoute, SIGNAL(triggered()), this, SLOT(slot_ac_SaveRoute()));
111
 
97
 
112
    connect(ac_LoadMap,     SIGNAL(triggered()), this, SLOT(slot_ac_LoadMapPic()));
98
    connect(ac_LoadMap,     SIGNAL(triggered()), this, SLOT(slot_ac_LoadMapPic()));
113
    connect(ac_Record,      SIGNAL(triggered()), this, SLOT(slot_ac_Record()));
99
    connect(ac_Record,      SIGNAL(triggered()), this, SLOT(slot_ac_Record()));
114
    connect(ac_RouteDelete, SIGNAL(triggered()), this, SLOT(slot_ac_RouteDelete()));
100
    connect(ac_RouteDelete, SIGNAL(triggered()), this, SLOT(slot_ac_RouteDelete()));
115
 
101
 
116
    // About QMK-Kernel & About-QT Dialog einfügen
102
    // About QMK-Kernel & About-QT Dialog einfügen
117
    connect(ac_About, SIGNAL(triggered()), this, SLOT(slot_ac_About()));
103
    connect(ac_About, SIGNAL(triggered()), this, SLOT(slot_ac_About()));
118
    menu_Help->addAction(trUtf8("Über &Qt"), qApp, SLOT(aboutQt()));
104
    menu_Help->addAction(trUtf8("Über &Qt"), qApp, SLOT(aboutQt()));
-
 
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)));
119
}
110
}
120
 
111
 
121
void dlg_Main::init_Directorys()
112
void dlg_Main::init_Directorys()
122
{
113
{
123
    QDir *t_Dir = new QDir();
114
    QDir *t_Dir = new QDir();
124
 
115
 
125
    s_Dir.MainData = QDir::homePath() + "/QMK-Data";
116
    s_Dir.MainData = QDir::homePath() + "/QMK-Data";
126
    if (!t_Dir->exists(s_Dir.MainData))
117
    if (!t_Dir->exists(s_Dir.MainData))
127
    {
118
    {
128
        t_Dir->mkdir(s_Dir.MainData);
119
        t_Dir->mkdir(s_Dir.MainData);
129
    }
120
    }
130
 
121
 
131
    s_Dir.MapCache = s_Dir.MainData + "/Map-Cache";
122
    s_Dir.MapCache = s_Dir.MainData + "/Map-Cache";
132
    if (!t_Dir->exists(s_Dir.MapCache))
123
    if (!t_Dir->exists(s_Dir.MapCache))
133
    {
124
    {
134
        t_Dir->mkdir(s_Dir.MapCache);
125
        t_Dir->mkdir(s_Dir.MapCache);
135
    }
126
    }
136
 
127
 
137
    s_Dir.WPRoutes = s_Dir.MainData + "/WP-Routes";
128
    s_Dir.WPRoutes = s_Dir.MainData + "/WP-Routes";
138
    if (!t_Dir->exists(s_Dir.WPRoutes))
129
    if (!t_Dir->exists(s_Dir.WPRoutes))
139
    {
130
    {
140
        t_Dir->mkdir(s_Dir.WPRoutes);
131
        t_Dir->mkdir(s_Dir.WPRoutes);
141
    }
132
    }
142
 
133
 
143
    s_Dir.MapPics = s_Dir.MainData + "/Map-Pics";
134
    s_Dir.MapPics = s_Dir.MainData + "/Map-Pics";
144
    if (!t_Dir->exists(s_Dir.MapPics))
135
    if (!t_Dir->exists(s_Dir.MapPics))
145
    {
136
    {
146
        t_Dir->mkdir(s_Dir.MapPics);
137
        t_Dir->mkdir(s_Dir.MapPics);
147
    }
138
    }
148
 
139
 
149
    s_Dir.Flights = s_Dir.MainData + "/Flights";
140
    s_Dir.Flights = s_Dir.MainData + "/Flights";
150
    if (!t_Dir->exists(s_Dir.Flights))
141
    if (!t_Dir->exists(s_Dir.Flights))
151
    {
142
    {
152
        t_Dir->mkdir(s_Dir.Flights);
143
        t_Dir->mkdir(s_Dir.Flights);
153
    }
144
    }
154
}
145
}
155
 
-
 
156
void dlg_Main::parse_IP_Data(QString t_Data)
-
 
157
{
-
 
158
    QStringList Data;
-
 
159
    Data = t_Data.split(":");
-
 
160
 
-
 
161
    if (Data.count() > 1)
-
 
162
    {
-
 
163
        int CMD = Data[2].toInt();
-
 
164
 
-
 
165
        switch(CMD)
-
 
166
        {
-
 
167
            case 101 :
-
 
168
            {
-
 
169
                o_Input->send_Data(HandlerIP::make_Frame(ID_MAPS, 101, QA_NAME + " " + QA_VERSION));
-
 
170
            }
-
 
171
            break;
-
 
172
            case 502 :
-
 
173
            {
-
 
174
                switch (Data[3].toInt())
-
 
175
                {
-
 
176
                    case 105 :
-
 
177
                    {
-
 
178
                        QString s_MD5PW;
-
 
179
                        QByteArray a_MD5PW;
-
 
180
 
-
 
181
                        a_MD5PW = QCryptographicHash::hash(le_Password->text().toAscii(),QCryptographicHash::Md5);
-
 
182
 
-
 
183
                        s_MD5PW = QString(a_MD5PW.toHex().data());
-
 
184
 
-
 
185
                        o_Input->send_Data(HandlerIP::make_Frame(ID_MAPS, 105, s_MD5PW));
-
 
186
                    }
-
 
187
                    break;
-
 
188
                    case 106 :
-
 
189
                    {
-
 
190
                        o_Input->send_Data(HandlerIP::make_Frame(ID_MAPS, 106, DataFields));
-
 
191
                    }
-
 
192
                    break;
-
 
193
                }
-
 
194
            }
-
 
195
            break;
-
 
196
            case 505 :
-
 
197
            {
-
 
198
                if (Data[3] == "OK")
-
 
199
                {
-
 
200
                }
-
 
201
                else
-
 
202
                {
-
 
203
                    QMessageBox::warning(this, QA_NAME, trUtf8("Authentifizierung fehlgeschlagen. <br />Daten senden zum Mikrokopter nicht möglich."), QMessageBox::Ok);
-
 
204
                }
-
 
205
            }
-
 
206
            break;
-
 
207
        }
-
 
208
    }
-
 
209
}
-
 
210
 
-
 
211
// Eingangsdaten verarbeiten
-
 
212
void dlg_Main::parse_MK_Data(QString t_Data)
-
 
213
{
-
 
214
    unsigned char OutData[150];
-
 
215
    char *InData = t_Data.toLatin1().data();
-
 
216
 
-
 
217
    if (HandlerMK::Decode_64(InData, t_Data.length(), OutData) != 0)
-
 
218
    {
-
 
219
 
-
 
220
        switch(InData[2])
-
 
221
        {
-
 
222
            case 'V' : // Versions-Info
-
 
223
                {
-
 
224
                    o_Input->stop_Resend(DATA_VERSION);
-
 
225
                    VersionInfo = HandlerMK::parse_Version(OutData, InData[1] - 'a');
-
 
226
                    setWindowTitle(QA_NAME + " " + QA_VERSION + " - " + VersionInfo.Hardware + " " + VersionInfo.Version);
-
 
227
 
-
 
228
                    if (VersionInfo.ID == ADDRESS_NC)
-
 
229
                    {
-
 
230
                        c_Data[0] = sb_Intervall->value() / 10;
-
 
231
                        o_Input->send_Data(HandlerMK::make_Frame('o', ADDRESS_ALL, c_Data, 1).toLatin1().data());
-
 
232
                    }
-
 
233
                    else // TODO: Befehl wenden zum Wechseln auf Navi.
-
 
234
                    {
-
 
235
                    }
-
 
236
                }
-
 
237
            break;
-
 
238
            case 'O' : // Navi-OSD-Data
-
 
239
                {
-
 
240
                    if (InData[1] - 'a' == ADDRESS_NC)
-
 
241
                    {
-
 
242
                        s_MK_NaviData MK_NaviData;
-
 
243
 
-
 
244
                        memcpy((unsigned char *)&MK_NaviData, (unsigned char *)&OutData, sizeof(MK_NaviData));
-
 
245
                        if (MK_NaviData.Version == MK_VERSION_NAVI)
-
 
246
                        {
-
 
247
                            show_Data(MK_NaviData);
-
 
248
                            add_Position(MK_NaviData);
-
 
249
                        }
-
 
250
                    }
-
 
251
                }
-
 
252
            break;
-
 
253
            case 'W' : // WayPoints
-
 
254
                {
-
 
255
                    o_Input->stop_Resend(DATA_WRITE_WAYPOINT);
-
 
256
 
-
 
257
                    if (OutData[0] < l_WayPoints.count())
-
 
258
                    {
-
 
259
                        send_WayPoints(l_WayPoints, OutData[0] + 1);
-
 
260
                    }
-
 
261
                }
-
 
262
            break;
-
 
263
        }
-
 
264
    }
-
 
265
}
-
 
266
 
146
 
267
///////////////////////////////////////////////////////////////////
147
///////////////////////////////////////////////////////////////////
268
// QMK-Maps                                                      //
148
// QMK-Maps                                                      //
269
///////////////////////////////////////////////////////////////////
149
///////////////////////////////////////////////////////////////////
270
 
150
 
271
void dlg_Main::create_Map()
151
void dlg_Main::create_Map()
272
{
152
{
273
    o_Map->resize(w_Map->size() - QSize(25,50));
153
    o_Map->resize(w_Map->size() - QSize(25,50));
274
    o_Map->enablePersistentCache(s_Dir.MapCache);
154
    o_Map->enablePersistentCache(s_Dir.MapCache);
275
    o_Map->showScale(true);
155
    o_Map->showScale(true);
276
 
156
 
277
    o_Adapter = new OSMMapAdapter();
157
    o_Adapter = new OSMMapAdapter();
278
 
158
 
279
    o_Layer   = new MapLayer("MapLayer", o_Adapter);
159
    o_Layer   = new MapLayer("MapLayer", o_Adapter);
280
    o_Click   = new GeometryLayer("Click", o_Adapter);
160
    o_Click   = new GeometryLayer("Click", o_Adapter);
281
    o_Info    = new GeometryLayer("Poute", o_Adapter);
161
    o_Info    = new GeometryLayer("Poute", o_Adapter);
282
    o_RouteWP = new GeometryLayer("Route-WayPoint", o_Adapter);
162
    o_RouteWP = new GeometryLayer("Route-WayPoint", o_Adapter);
283
    o_RouteFL = new GeometryLayer("Route-Flight", o_Adapter);
163
    o_RouteFL = new GeometryLayer("Route-Flight", o_Adapter);
284
 
164
 
285
    o_Map->addLayer(o_Layer);
165
    o_Map->addLayer(o_Layer);
286
    o_Map->addLayer(o_Click);
166
    o_Map->addLayer(o_Click);
287
    o_Map->addLayer(o_Info);
167
    o_Map->addLayer(o_Info);
288
    o_Map->addLayer(o_RouteWP);
168
    o_Map->addLayer(o_RouteWP);
289
    o_Map->addLayer(o_RouteFL);
169
    o_Map->addLayer(o_RouteFL);
290
 
170
 
291
    o_Map->setZoom(17);
171
    o_Map->setZoom(17);
292
//    o_Map->setView(QPointF(o_Settings->NAVI.Longitude,o_Settings->NAVI.Latitude));
172
//    o_Map->setView(QPointF(o_Settings->NAVI.Longitude,o_Settings->NAVI.Latitude));
293
//    o_Map->setView(QPointF(13.5,52.5));
173
//    o_Map->setView(QPointF(13.5,52.5));
294
    o_Map->setView(QPointF(13.419805,52.431787));
174
    o_Map->setView(QPointF(13.419805,52.431787));
295
    connect(o_Map, SIGNAL(mouseEventCoordinate(const QMouseEvent*, const QPointF)), this, SLOT(slot_Click(const QMouseEvent*, const QPointF)));
175
    connect(o_Map, SIGNAL(mouseEventCoordinate(const QMouseEvent*, const QPointF)), this, SLOT(slot_Click(const QMouseEvent*, const QPointF)));
296
 
176
 
297
    l_Map->addWidget(o_Map);
177
    l_Map->addWidget(o_Map);
298
 
178
 
299
    sl_Zoom->setValue(17);
179
    sl_Zoom->setValue(17);
300
 
180
 
301
    // Flight
181
    // Flight
302
    Pen[0] = new QPen(QColor(0,0,255,255));
182
    Pen[0] = new QPen(QColor(0,0,255,255));
303
    Pen[0]->setWidth(2);
183
    Pen[0]->setWidth(2);
304
    Pen[1] = new QPen(QColor(0,0,255,255));
184
    Pen[1] = new QPen(QColor(0,0,255,255));
305
    Pen[1]->setWidth(1);
185
    Pen[1]->setWidth(1);
306
    // WayPoint
186
    // WayPoint
307
    Pen[2] = new QPen(QColor(255,0,0,255));
187
    Pen[2] = new QPen(QColor(255,0,0,255));
308
    Pen[2]->setWidth(2);
188
    Pen[2]->setWidth(2);
309
    Pen[3] = new QPen(QColor(255,0,0,255));
189
    Pen[3] = new QPen(QColor(255,0,0,255));
310
    Pen[3]->setWidth(1);
190
    Pen[3]->setWidth(1);
311
    // Info
191
    // Info
312
    Pen[4] = new QPen(QColor(0,128,128,255));
192
    Pen[4] = new QPen(QColor(0,128,128,255));
313
    Pen[4]->setWidth(2);
193
    Pen[4]->setWidth(2);
314
    Pen[5] = new QPen(QColor(0,128,128,255));
194
    Pen[5] = new QPen(QColor(0,128,128,255));
315
    Pen[5]->setWidth(1);
195
    Pen[5]->setWidth(1);
316
}
196
}
317
 
197
 
318
// auf Veränderung der Fenstergröße reagieren
198
// auf Veränderung der Fenstergröße reagieren
319
void dlg_Main::resizeEvent ( QResizeEvent * event )
199
void dlg_Main::resizeEvent ( QResizeEvent * event )
320
{
200
{
321
    event = event;
201
    event = event;
322
    o_Map->resize(w_Map->size() - QSize(25,25));
202
    o_Map->resize(w_Map->size() - QSize(25,25));
323
}
203
}
324
 
204
 
325
void dlg_Main::wheelEvent(QWheelEvent *event)
205
void dlg_Main::wheelEvent(QWheelEvent *event)
326
{
206
{
327
    int zoomValue = sl_Zoom->value();
207
    int zoomValue = sl_Zoom->value();
328
    int numDegrees = event->delta() / 8;
208
    int numDegrees = event->delta() / 8;
329
    int numSteps = numDegrees / 15;
209
    int numSteps = numDegrees / 15;
330
    zoomValue += numSteps;
210
    zoomValue += numSteps;
331
    if (zoomValue < 0) { zoomValue = 0;}
211
    if (zoomValue < 0) { zoomValue = 0;}
332
    if (zoomValue > 17) { zoomValue = 17;}
212
    if (zoomValue > 17) { zoomValue = 17;}
333
    sl_Zoom->setValue(zoomValue);
213
    sl_Zoom->setValue(zoomValue);
334
}
214
}
335
 
215
 
336
QList<sWayPoint> dlg_Main::parse_WayPointKML(QString s_File)
216
QList<sWayPoint> dlg_Main::parse_WayPointKML(QString s_File)
337
{
217
{
338
    QList<sWayPoint> tmp_WayPoints;
218
    QList<sWayPoint> tmp_WayPoints;
339
    sWayPoint tmp_WayPoint;
219
    sWayPoint tmp_WayPoint;
340
 
220
 
341
    QFile f_KML(s_File);
221
    QFile f_KML(s_File);
342
    f_KML.open(QIODevice::ReadOnly | QIODevice::Text);
222
    f_KML.open(QIODevice::ReadOnly | QIODevice::Text);
343
 
223
 
344
    QByteArray s_KML;
224
    QByteArray s_KML;
345
 
225
 
346
    while (!f_KML.atEnd())
226
    while (!f_KML.atEnd())
347
    {
227
    {
348
        s_KML.append(f_KML.readLine());
228
        s_KML.append(f_KML.readLine());
349
     }
229
     }
350
 
230
 
351
    f_KML.close();
231
    f_KML.close();
352
 
232
 
353
    QDomDocument *UserXML;
233
    QDomDocument *UserXML;
354
    UserXML = new QDomDocument;
234
    UserXML = new QDomDocument;
355
 
235
 
356
    UserXML->setContent(s_KML);
236
    UserXML->setContent(s_KML);
357
 
237
 
358
    QDomElement Root       = UserXML->firstChildElement("kml");
238
    QDomElement Root       = UserXML->firstChildElement("kml");
359
    QDomElement Document   = Root.firstChildElement("Document");
239
    QDomElement Document   = Root.firstChildElement("Document");
360
    QDomElement Placemark  = Document.firstChildElement("Placemark");
240
    QDomElement Placemark  = Document.firstChildElement("Placemark");
361
    QDomElement Linestring = Placemark.firstChildElement("LineString");
241
    QDomElement Linestring = Placemark.firstChildElement("LineString");
362
 
242
 
363
    QString Name = Placemark.firstChildElement("name").toElement().text();
243
    QString Name = Placemark.firstChildElement("name").toElement().text();
364
 
244
 
365
    QString Route = Linestring.firstChildElement("coordinates").toElement().text();
245
    QString Route = Linestring.firstChildElement("coordinates").toElement().text();
366
 
246
 
367
    QStringList s_Points = Route.split(" ");
247
    QStringList s_Points = Route.split(" ");
368
 
248
 
369
    QStringList Position;
249
    QStringList Position;
370
 
250
 
371
    for (int z = 0; z < s_Points.count() - 1; z++)
251
    for (int z = 0; z < s_Points.count() - 1; z++)
372
    {
252
    {
373
        if (z != 20)
253
        if (z != 20)
374
        {
254
        {
375
           Position = s_Points[z].split(",");
255
           Position = s_Points[z].split(",");
376
           tmp_WayPoint.Longitude = Position[0].toDouble();
256
           tmp_WayPoint.Longitude = Position[0].toDouble();
377
           tmp_WayPoint.Latitude  = Position[1].toDouble();
257
           tmp_WayPoint.Latitude  = Position[1].toDouble();
378
           tmp_WayPoint.Altitude  = Position[2].toDouble();
258
           tmp_WayPoint.Altitude  = Position[2].toDouble();
379
           tmp_WayPoint.Time      = sb_Time->value();
259
           tmp_WayPoint.Time      = sb_Time->value();
380
 
260
 
381
           tmp_WayPoints.append(tmp_WayPoint);
261
           tmp_WayPoints.append(tmp_WayPoint);
382
        }
262
        }
383
        else
263
        else
384
        {
264
        {
385
            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);
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);
386
 
266
 
387
            btn_WPAdd->setEnabled(false);
267
            btn_WPAdd->setEnabled(false);
388
 
268
 
389
            z = s_Points.count();
269
            z = s_Points.count();
390
        }
270
        }
391
    }
271
    }
392
    return tmp_WayPoints;
272
    return tmp_WayPoints;
393
}
273
}
394
 
274
 
395
QList<sWayPoint> dlg_Main::parse_WayPointMKW(QString s_File)
275
QList<sWayPoint> dlg_Main::parse_WayPointMKW(QString s_File)
396
{
276
{
397
    QList<sWayPoint> tmp_WayPoints;
277
    QList<sWayPoint> tmp_WayPoints;
398
    sWayPoint tmp_WayPoint;
278
    sWayPoint tmp_WayPoint;
399
 
279
 
400
    QFile f_MKW(s_File);
280
    QFile f_MKW(s_File);
401
    f_MKW.open(QIODevice::ReadOnly | QIODevice::Text);
281
    f_MKW.open(QIODevice::ReadOnly | QIODevice::Text);
402
 
282
 
403
    QString s_MKW;
283
    QString s_MKW;
404
 
284
 
405
    while (!f_MKW.atEnd())
285
    while (!f_MKW.atEnd())
406
    {
286
    {
407
        s_MKW.append(f_MKW.readLine());
287
        s_MKW.append(f_MKW.readLine());
408
     }
288
     }
409
 
289
 
410
    f_MKW.close();
290
    f_MKW.close();
411
 
291
 
412
    QStringList s_Points = s_MKW.split(" ");
292
    QStringList s_Points = s_MKW.split(" ");
413
 
293
 
414
    QStringList Position;
294
    QStringList Position;
415
 
295
 
416
    for (int z = 0; z < s_Points.count() - 1; z++)
296
    for (int z = 0; z < s_Points.count() - 1; z++)
417
    {
297
    {
418
        if (z != 20)
298
        if (z != 20)
419
        {
299
        {
420
           Position = s_Points[z].split(",");
300
           Position = s_Points[z].split(",");
421
           tmp_WayPoint.Longitude = Position[0].toDouble();
301
           tmp_WayPoint.Longitude = Position[0].toDouble();
422
           tmp_WayPoint.Latitude  = Position[1].toDouble();
302
           tmp_WayPoint.Latitude  = Position[1].toDouble();
423
           tmp_WayPoint.Altitude  = Position[2].toDouble();
303
           tmp_WayPoint.Altitude  = Position[2].toDouble();
424
           tmp_WayPoint.Time      = Position[3].toInt();
304
           tmp_WayPoint.Time      = Position[3].toInt();
425
 
305
 
426
           tmp_WayPoints.append(tmp_WayPoint);
306
           tmp_WayPoints.append(tmp_WayPoint);
427
        }
307
        }
428
        else
308
        else
429
        {
309
        {
430
            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);
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);
431
 
311
 
432
            btn_WPAdd->setEnabled(false);
312
            btn_WPAdd->setEnabled(false);
433
 
313
 
434
            z = s_Points.count();
314
            z = s_Points.count();
435
        }
315
        }
436
    }
316
    }
437
    return tmp_WayPoints;
317
    return tmp_WayPoints;
438
}
318
}
439
 
319
 
440
// Waypoint-Route anzeigen in Karte
320
// Waypoint-Route anzeigen in Karte
441
void dlg_Main::show_WayPoints(QList<sWayPoint> WayPoints)
321
void dlg_Main::show_WayPoints(QList<sWayPoint> WayPoints)
442
{
322
{
443
    Point* p_Point;
323
    Point* p_Point;
444
 
324
 
445
    o_RouteWP->removeGeometry(l_RouteWP);
325
    o_RouteWP->removeGeometry(l_RouteWP);
446
    p_RouteWP.clear();
326
    p_RouteWP.clear();
447
    l_WayPoints.clear();
327
    l_WayPoints.clear();
448
 
328
 
449
    l_WayPoints = WayPoints;
329
    l_WayPoints = WayPoints;
450
 
330
 
451
    for (int z = 0; z < WayPoints.count(); z++)
331
    for (int z = 0; z < WayPoints.count(); z++)
452
    {
332
    {
453
        p_Point = new Point(WayPoints[z].Longitude, WayPoints[z].Latitude);
333
        p_Point = new Point(WayPoints[z].Longitude, WayPoints[z].Latitude);
454
 
334
 
455
        p_RouteWP.append(p_Point);
335
        p_RouteWP.append(p_Point);
456
    }
336
    }
457
 
337
 
458
    l_RouteWP = new LineString(p_RouteWP, "", Pen[3]);
338
    l_RouteWP = new LineString(p_RouteWP, "", Pen[3]);
459
    o_RouteWP->addGeometry(l_RouteWP);
339
    o_RouteWP->addGeometry(l_RouteWP);
460
 
340
 
461
    o_Map->setView(p_Point);
341
    o_Map->setView(p_Point);
462
 
342
 
463
    o_Map->updateRequestNew();
343
    o_Map->updateRequestNew();
464
}
344
}
465
 
345
 
466
// Waypoint-Liste speichern
346
// Waypoint-Liste speichern
467
void dlg_Main::save_WayPointsMKW(QString s_File)
347
void dlg_Main::save_WayPointsMKW(QString s_File)
468
{
348
{
469
    QFile *f_MKW = new QFile(s_File);
349
    QFile *f_MKW = new QFile(s_File);
470
 
350
 
471
    f_MKW->open(QIODevice::ReadWrite | QIODevice::Text);
351
    f_MKW->open(QIODevice::ReadWrite | QIODevice::Text);
472
 
352
 
473
    QTextStream out(f_MKW);
353
    QTextStream out(f_MKW);
474
 
354
 
475
    out.setRealNumberPrecision(9);
355
    out.setRealNumberPrecision(9);
476
 
356
 
477
    for (int z = 0; z < l_WayPoints.count(); z++)
357
    for (int z = 0; z < l_WayPoints.count(); z++)
478
    {
358
    {
479
        out << l_WayPoints[z].Longitude << "," << l_WayPoints[z].Latitude << "," << l_WayPoints[z].Altitude << "," << l_WayPoints[z].Time << " \n";
359
        out << l_WayPoints[z].Longitude << "," << l_WayPoints[z].Latitude << "," << l_WayPoints[z].Altitude << "," << l_WayPoints[z].Time << " \n";
480
    }
360
    }
481
 
361
 
482
    f_MKW->close();
362
    f_MKW->close();
483
}
363
}
484
 
-
 
485
void dlg_Main::show_Data(s_MK_NaviData t_NaviData)
-
 
486
{
-
 
487
    QString Mode = "NC-Flags : ";
-
 
488
    if (t_NaviData.NCFlags &  0x08) {le_Mode->setText(tr("Range Limit")); Mode += "R";}
-
 
489
    if (t_NaviData.NCFlags &  0x10) {le_Mode->setText(tr("Serial Error")); Mode += "S";}
-
 
490
    if (t_NaviData.NCFlags &  0x20) {le_Mode->setText(tr("Target reached")); Mode += "T";}
-
 
491
    if (t_NaviData.NCFlags &  0x40) {le_Mode->setText(tr("Manual Control")); Mode += "M";}
-
 
492
    if (t_NaviData.NCFlags &  0x01) {le_Mode->setText(tr("Free")); Mode += "F";}
-
 
493
    if (t_NaviData.NCFlags &  0x02) {le_Mode->setText(tr("Position Hold")); Mode += "P";}
-
 
494
    if (t_NaviData.NCFlags &  0x04) {le_Mode->setText(tr("Coming Home")); Mode += "C";}
-
 
495
 
-
 
496
    //qDebug(Mode.toLatin1().data());
-
 
497
 
-
 
498
    le_WP->setText(QString("%1/").arg(t_NaviData.WaypointIndex) + QString("%1").arg(t_NaviData.WaypointNumber));
-
 
499
    le_WPTime->setText(QString("%1:").arg(t_NaviData.TargetHoldTime / 60) + (QString("%1").arg(t_NaviData.TargetHoldTime % 60)).rightJustified(2, '0'));
-
 
500
    le_WPDist->setText(QString("%1m").arg(t_NaviData.TargetPositionDeviation.Distance / 10));
-
 
501
    le_HomeDist->setText(QString("%1m").arg(t_NaviData.HomePositionDeviation.Distance / 10));
-
 
502
}
-
 
503
 
364
 
504
// Aktuelle MK-Position hinzufügen
365
// Aktuelle MK-Position hinzufügen
505
void dlg_Main::add_Position(s_MK_NaviData t_NaviData)
366
void dlg_Main::add_Position(s_MK_NaviData t_NaviData)
506
{
367
{
507
    sWayPoint WayPoint;
368
    sWayPoint WayPoint;
508
 
369
 
509
    WayPoint.Longitude = HandlerMK::Int2Double(t_NaviData.CurrentPosition.Longitude, 7);
370
    WayPoint.Longitude = HandlerMK::Int2Double(t_NaviData.CurrentPosition.Longitude, 7);
510
    WayPoint.Latitude = HandlerMK::Int2Double(t_NaviData.CurrentPosition.Latitude, 7);
371
    WayPoint.Latitude = HandlerMK::Int2Double(t_NaviData.CurrentPosition.Latitude, 7);
511
    WayPoint.Altitude = HandlerMK::Int2Double(t_NaviData.CurrentPosition.Altitude, 3);
372
    WayPoint.Altitude = HandlerMK::Int2Double(t_NaviData.CurrentPosition.Altitude, 3);
512
 
373
 
513
    o_Settings->NAVI.Latitude  = WayPoint.Latitude;
374
    o_Settings->NAVI.Latitude  = WayPoint.Latitude;
514
    o_Settings->NAVI.Longitude = WayPoint.Longitude;
375
    o_Settings->NAVI.Longitude = WayPoint.Longitude;
515
 
376
 
516
    l_Track.append(WayPoint);
377
    l_Track.append(WayPoint);
517
 
378
 
518
    o_RouteFL->removeGeometry(l_RouteFL);
379
    o_RouteFL->removeGeometry(l_RouteFL);
519
    p_RouteFL.append(new Point(WayPoint.Longitude, WayPoint.Latitude));
380
    p_RouteFL.append(new Point(WayPoint.Longitude, WayPoint.Latitude));
520
 
381
 
521
    o_Click->removeGeometry(LastPos);
382
    o_Click->removeGeometry(LastPos);
522
 
383
 
523
    Point* P = new CirclePoint(WayPoint.Longitude, WayPoint.Latitude, "P1", Point::Middle, Pen[0]);
384
    Point* P = new CirclePoint(WayPoint.Longitude, WayPoint.Latitude, "P1", Point::Middle, Pen[0]);
524
    LastPos = P;
385
    LastPos = P;
525
//    P->setBaselevel(17);
386
//    P->setBaselevel(17);
526
    o_Click->addGeometry(P);
387
    o_Click->addGeometry(P);
527
 
388
 
528
    // Target anzeigen
389
    // Target anzeigen
529
    o_Click->removeGeometry(Target);
390
    o_Click->removeGeometry(Target);
530
 
391
 
531
    Target = new ImagePoint( HandlerMK::Int2Double(t_NaviData.TargetPosition.Longitude, 7), HandlerMK::Int2Double(t_NaviData.TargetPosition.Latitude, 7), ":/Flags/Global/Images/Flags/Target.png", "Start");
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");
532
    Target->setBaselevel(o_Adapter->adaptedZoom());
393
    Target->setBaselevel(o_Adapter->adaptedZoom());
533
    o_Click->addGeometry(Target);
394
    o_Click->addGeometry(Target);
534
 
395
 
535
    if (cb_CenterPos->isChecked())
396
    if (cb_CenterPos->isChecked())
536
    {
397
    {
537
        o_Map->setView(QPointF(WayPoint.Longitude, WayPoint.Latitude));
398
        o_Map->setView(QPointF(WayPoint.Longitude, WayPoint.Latitude));
538
    }
399
    }
539
 
400
 
540
    if (cb_ShowRoute->isChecked())
401
    if (cb_ShowRoute->isChecked())
541
    {
402
    {
542
        l_RouteFL = new LineString(p_RouteFL, "", Pen[1]);
403
        l_RouteFL = new LineString(p_RouteFL, "", Pen[1]);
543
 
404
 
544
        o_RouteFL->addGeometry(l_RouteFL);
405
        o_RouteFL->addGeometry(l_RouteFL);
545
    }
406
    }
546
    o_Map->updateRequestNew();
407
    o_Map->updateRequestNew();
547
 
408
 
548
    if (ac_Record->isChecked())
409
    if (ac_Record->isChecked())
549
    {
410
    {
550
        QTextStream Out(o_Record);
411
        QTextStream Out(o_Record);
551
 
412
 
552
        Out.setRealNumberPrecision(9);
413
        Out.setRealNumberPrecision(9);
553
 
414
 
554
        Out << WayPoint.Longitude << ", " << WayPoint.Latitude << ", " << WayPoint.Altitude << "\n";
415
        Out << WayPoint.Longitude << ", " << WayPoint.Latitude << ", " << WayPoint.Altitude << "\n";
555
    }
416
    }
556
}
417
}
557
 
418
 
558
// Ein Ziel anfliegen.
419
// Ein Ziel anfliegen.
559
// TODO: Check auf  Entfernung zur IST-Position.
420
// TODO: Check auf  Entfernung zur IST-Position.
560
void dlg_Main::send_Target(Point *t_Target)
421
void dlg_Main::send_Target(Point *t_Target)
561
{
422
{
562
    if (l_Track.count() > 0)
423
    if (l_Track.count() > 0)
563
    {
424
    {
564
        s_MK_WayPoint s_WayPoint;
425
        s_MK_WayPoint s_WayPoint;
565
 
426
 
566
        s_WayPoint.Position.Latitude  = int32_t(t_Target->latitude() * 10000000+0.5);
427
        s_WayPoint.Position.Latitude  = int32_t(t_Target->latitude() * 10000000+0.5);
567
        s_WayPoint.Position.Longitude = int32_t(t_Target->longitude() * 10000000+0.5);
428
        s_WayPoint.Position.Longitude = int32_t(t_Target->longitude() * 10000000+0.5);
568
        s_WayPoint.Position.Altitude  = 0;
429
        s_WayPoint.Position.Altitude  = 0;
569
        s_WayPoint.Position.Status    = NEWDATA;
430
        s_WayPoint.Position.Status    = NEWDATA;
570
        s_WayPoint.Heading            = -1;
431
        s_WayPoint.Heading            = -1;
571
        s_WayPoint.ToleranceRadius    = 5;
432
        s_WayPoint.ToleranceRadius    = 5;
572
        s_WayPoint.HoldTime           = sb_Time->value();
433
        s_WayPoint.HoldTime           = sb_Time->value();
573
        s_WayPoint.Event_Flag         = 0;
434
        s_WayPoint.Event_Flag         = 0;
574
        s_WayPoint.reserve[0]         = 0; // reserve
435
        s_WayPoint.reserve[0]         = 0; // reserve
575
        s_WayPoint.reserve[1]         = 0; // reserve
436
        s_WayPoint.reserve[1]         = 0; // reserve
576
        s_WayPoint.reserve[2]         = 0; // reserve
437
        s_WayPoint.reserve[2]         = 0; // reserve
577
        s_WayPoint.reserve[3]         = 0;
438
        s_WayPoint.reserve[3]         = 0;
578
 
439
 
579
        memcpy((unsigned char *)&c_Data, (unsigned char *)&s_WayPoint, sizeof(s_WayPoint));
440
        memcpy((unsigned char *)&c_Data, (unsigned char *)&s_WayPoint, sizeof(s_WayPoint));
580
        o_Input->send_Data(HandlerMK::make_Frame('s', ADDRESS_NC, c_Data, sizeof(s_WayPoint)).toLatin1().data());
441
        wg_Connection->send_Data(HandlerMK::make_Frame('s', ADDRESS_NC, c_Data, sizeof(s_WayPoint)).toLatin1().data());
581
    }
442
    }
582
    else
443
    else
583
    {
444
    {
584
        QMessageBox::warning(this, QA_NAME,tr("Es wurden noch keine aktuellen Positionsdaten vom Mikrokopter empfangen."), QMessageBox::Ok);
445
        QMessageBox::warning(this, QA_NAME,tr("Es wurden noch keine aktuellen Positionsdaten vom Mikrokopter empfangen."), QMessageBox::Ok);
585
    }
446
    }
586
}
447
}
587
 
448
 
588
//Waypoint-Liste zum MK senden
449
//Waypoint-Liste zum MK senden
589
void dlg_Main::send_WayPoints(QList<sWayPoint> t_WayPoints, int t_Pos)
450
void dlg_Main::send_WayPoints(QList<sWayPoint> t_WayPoints, int t_Pos)
590
{
451
{
591
    s_MK_WayPoint s_WayPoint;
452
    s_MK_WayPoint s_WayPoint;
592
    double Longitude, Latitude;
453
    double Longitude, Latitude;
593
 
454
 
594
    if (t_Pos == 0)
455
    if (t_Pos == 0)
595
    {   // Waypoint-Liste löschen
456
    {   // Waypoint-Liste löschen
596
        s_WayPoint.Position.Status = INVALID;
457
        s_WayPoint.Position.Status = INVALID;
597
 
458
 
598
        memcpy((unsigned char *)&c_Data, (unsigned char *)&s_WayPoint, sizeof(s_WayPoint));
459
        memcpy((unsigned char *)&c_Data, (unsigned char *)&s_WayPoint, sizeof(s_WayPoint));
599
        o_Input->send_Data(HandlerMK::make_Frame('w', ADDRESS_NC, c_Data, sizeof(s_WayPoint)).toLatin1().data(), DATA_WRITE_WAYPOINT);
460
        wg_Connection->send_Data(HandlerMK::make_Frame('w', ADDRESS_NC, c_Data, sizeof(s_WayPoint)).toLatin1().data(), DATA_WRITE_WAYPOINT);
600
    }
461
    }
601
    else
462
    else
602
    {
463
    {
603
        int z = t_Pos - 1;
464
        int z = t_Pos - 1;
604
        Longitude = t_WayPoints[z].Longitude;
465
        Longitude = t_WayPoints[z].Longitude;
605
        Latitude  = t_WayPoints[z].Latitude;
466
        Latitude  = t_WayPoints[z].Latitude;
606
 
467
 
607
        if (Longitude < 100)
468
        if (Longitude < 100)
608
            Longitude *= 10000000+0.5;
469
            Longitude *= 10000000+0.5;
609
 
470
 
610
        if (Latitude < 100)
471
        if (Latitude < 100)
611
            Latitude *= 10000000+0.5;
472
            Latitude *= 10000000+0.5;
612
 
473
 
613
        //fülle Wegpunkt-Daten
474
        //fülle Wegpunkt-Daten
614
        s_WayPoint.Position.Altitude = 0;
475
        s_WayPoint.Position.Altitude = 0;
615
        s_WayPoint.Position.Longitude = int32_t(Longitude);
476
        s_WayPoint.Position.Longitude = int32_t(Longitude);
616
        s_WayPoint.Position.Latitude =  int32_t(Latitude);
477
        s_WayPoint.Position.Latitude =  int32_t(Latitude);
617
        s_WayPoint.Position.Status = NEWDATA;
478
        s_WayPoint.Position.Status = NEWDATA;
618
        s_WayPoint.Heading = -1;
479
        s_WayPoint.Heading = -1;
619
        s_WayPoint.ToleranceRadius = 5;
480
        s_WayPoint.ToleranceRadius = 5;
620
        s_WayPoint.HoldTime = t_WayPoints[z].Time;
481
        s_WayPoint.HoldTime = t_WayPoints[z].Time;
621
        s_WayPoint.Event_Flag = 0;
482
        s_WayPoint.Event_Flag = 0;
622
        s_WayPoint.reserve[0] = 0; // reserve
483
        s_WayPoint.reserve[0] = 0; // reserve
623
        s_WayPoint.reserve[1] = 0; // reserve
484
        s_WayPoint.reserve[1] = 0; // reserve
624
        s_WayPoint.reserve[2] = 0; // reserve
485
        s_WayPoint.reserve[2] = 0; // reserve
625
        s_WayPoint.reserve[3] = 0; // reserve
486
        s_WayPoint.reserve[3] = 0; // reserve
626
 
487
 
627
        memcpy((unsigned char *)&c_Data, (unsigned char *)&s_WayPoint, sizeof(s_WayPoint));
488
        memcpy((unsigned char *)&c_Data, (unsigned char *)&s_WayPoint, sizeof(s_WayPoint));
628
        o_Input->send_Data(HandlerMK::make_Frame('w', ADDRESS_NC, c_Data, sizeof(s_WayPoint)).toLatin1().data(), DATA_WRITE_WAYPOINT);
489
        wg_Connection->send_Data(HandlerMK::make_Frame('w', ADDRESS_NC, c_Data, sizeof(s_WayPoint)).toLatin1().data(), DATA_WRITE_WAYPOINT);
629
    }
490
    }
630
}
491
}
631
 
492
 
632
///////////
493
///////////
633
// Slots //
494
// Slots //
634
///////////
495
///////////
635
 
496
 
636
// About-Dialog
497
// About-Dialog
637
void dlg_Main::slot_ac_About()
498
void dlg_Main::slot_ac_About()
638
{
499
{
639
    QMessageBox::about(this, trUtf8(("Über ")) + QA_NAME, QA_ABOUT);
500
    QMessageBox::about(this, trUtf8(("Über ")) + QA_NAME, QA_ABOUT);
640
}
501
}
641
 
502
 
642
void dlg_Main::slot_ac_Toolbar()
503
void dlg_Main::slot_ac_Toolbar()
643
{
504
{
644
    if (ac_Toolbar->isChecked())
505
    if (ac_Toolbar->isChecked())
645
    {
506
    {
646
        btn_Connect->setVisible(false);
507
        wg_Connection->set_ButtonVisible(false);
647
        ToolBar->setVisible(true);
508
        ToolBar->setVisible(true);
648
        tb_More->setVisible(true);
509
        tb_More->setVisible(true);
649
    }
510
    }
650
    else
511
    else
651
    {
512
    {
652
        btn_Connect->setVisible(true);
513
        wg_Connection->set_ButtonVisible(true);
653
        ToolBar->setVisible(false);
514
        ToolBar->setVisible(false);
654
        tb_More->setVisible(false);
515
        tb_More->setVisible(false);
655
    }
516
    }
656
}
517
}
657
 
-
 
658
 
-
 
659
// Datenintervall geändert.
518
 
660
void dlg_Main::slot_sb_Intervall(int t_Intervall)
-
 
661
{
-
 
662
    if (t_Intervall == 0)
-
 
663
    {
-
 
664
        c_Data[0] = 0;
-
 
665
    }
-
 
666
    else
519
void dlg_Main::slot_ConnectionStatus(int li_Status)
667
    {
-
 
668
        c_Data[0] = t_Intervall / 10;
-
 
669
    }
-
 
670
    o_Input->send_Data(HandlerMK::make_Frame('o', ADDRESS_ALL, c_Data, 1).toLatin1().data());
-
 
671
}
-
 
672
 
-
 
673
// Verbindung zum Server auf    f_Settings = new wdg_Settings( this );bauen
-
 
674
void dlg_Main::slot_ac_Connect()
-
 
675
{
520
{
676
    if (!o_Input->IsOpen())
-
 
677
    {
-
 
678
        if (cb_Server->findText(cb_Server->currentText()) == -1)
-
 
679
        {
-
 
680
            cb_Server->addItem(cb_Server->currentText());
-
 
681
            cb_Server->setCurrentIndex(cb_Server->findText(cb_Server->currentText()));
-
 
682
        }
-
 
683
 
-
 
684
        cb_Server->setEnabled(false);
-
 
685
        le_Password->setEnabled(false);
-
 
686
 
-
 
687
        if (cb_Server->currentText().startsWith('/'))
-
 
688
        {
-
 
689
            o_Input = new Input_TTY();
-
 
690
            o_Input->Init();
-
 
691
 
-
 
692
            set_Input s_Input;
-
 
693
            s_Input.Main = cb_Server->currentText();
-
 
694
 
-
 
695
            if (o_Input->Open(s_Input) == true)
521
    if (li_Status)
-
 
522
    {
696
            {
523
        ac_Connect->setChecked(true);
697
                ac_Connect->setText(tr("Trennen"));
-
 
698
                connect(o_Input, SIGNAL(sig_NewData(QString)), this, SLOT(slot_Input_Data(QString)));
-
 
699
 
-
 
700
                o_Input->send_Data(HandlerMK::make_Frame('v', 0, c_Data, 0).toLatin1().data(), DATA_VERSION);
524
        ac_Connect->setText(tr("Trennen"));
701
            }
525
    }
702
            else
526
    else
703
            {
527
    {
704
                cb_Server->setEnabled(true);
-
 
705
                le_Password->setEnabled(true);
-
 
706
            }
-
 
707
 
-
 
708
        }
-
 
709
        else //  Connect über TCPIP
-
 
710
        {
-
 
711
            o_Input = new Input_TCP();
-
 
712
            o_Input->Init();
-
 
713
 
-
 
714
            set_Input s_Input;
-
 
715
 
-
 
716
            QStringList Server = cb_Server->currentText().split(":");
-
 
717
 
-
 
718
            s_Input.Main = Server[0];
-
 
719
            s_Input.Sub  = Server[1];
-
 
720
 
-
 
721
            if (o_Input->Open(s_Input) == true)
-
 
722
            {
-
 
723
                connect(o_Input, SIGNAL(sig_Disconnected(int)), this, SLOT(slot_Input_Disconnected(int)));
-
 
724
                connect(o_Input, SIGNAL(sig_Connected()), this, SLOT(slot_Input_Connected()));
-
 
725
            }
-
 
726
        }
-
 
727
    }
-
 
728
    else
-
 
729
    {
-
 
730
        cb_Server->setEnabled(true);
528
        ac_Connect->setChecked(false);
731
        le_Password->setEnabled(true);
-
 
732
 
-
 
733
        ac_Connect->setText(tr("Verbinden"));
529
        ac_Connect->setText(tr("Verbinden"));
734
        o_Input->Close();
-
 
735
        disconnect(o_Input, SIGNAL(sig_NewData(QString)), 0, 0);
-
 
736
        if (o_Input->Mode() == TCP)
-
 
737
        {
-
 
738
            disconnect(o_Input, SIGNAL(sig_Disconnected(int)), 0, 0);
-
 
739
            disconnect(o_Input, SIGNAL(sig_Connected()), 0, 0);
-
 
740
        }
-
 
741
    }
530
    }
742
}
531
}
743
 
-
 
744
// Neue Daten empfangen.
532
 
745
void dlg_Main::slot_Input_Data(QString t_Data)
533
void dlg_Main::slot_MK_Version(s_Hardware ls_Version)
746
{
534
{
747
    if ((t_Data[0] == '#'))
-
 
748
    {
-
 
749
        if ((HandlerMK::Check_CRC(t_Data.toLatin1().data(), t_Data.length() - 1)) || ((o_Input->Mode() == TTY) && (HandlerMK::Check_CRC(t_Data.toLatin1().data(), t_Data.length()))))
-
 
750
        {
-
 
751
            parse_MK_Data(t_Data);
-
 
752
        }
-
 
753
        else
-
 
754
        {
535
    gs_Version = ls_Version;
755
//            qDebug(QString("CRC-Error - " + t_Data).toLatin1().data());
-
 
756
        }
-
 
757
    }
-
 
758
    else if ((o_Input->Mode() == TCP) && (t_Data[0] == '$'))
-
 
759
    {
-
 
760
            parse_IP_Data(t_Data);
-
 
761
    }
536
    setWindowTitle(QA_NAME + " " + QA_VERSION + " - " + ls_Version.Hardware + " " + ls_Version.Version);
762
}
-
 
763
 
537
}
764
// Serververbindung beendet
538
 
765
void dlg_Main::slot_Input_Disconnected(int Error)
539
void dlg_Main::slot_MK_NaviData(s_MK_NaviData ps_MK_NaviData)
766
{
540
{
767
    cb_Server->setEnabled(true);
-
 
768
    le_Password->setEnabled(true);
541
    QString Mode = "NC-Flags : ";
-
 
542
    if (ps_MK_NaviData.NCFlags &  0x08) {le_Mode->setText(tr("Range Limit")); Mode += "R";}
769
 
543
    if (ps_MK_NaviData.NCFlags &  0x10) {le_Mode->setText(tr("Serial Error")); Mode += "S";}
770
    disconnect(o_Input, SIGNAL(sig_NewData(QString)), 0, 0);
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";}
771
    disconnect(o_Input, SIGNAL(sig_Disconnected(int)), 0, 0);
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";}
772
    disconnect(o_Input, SIGNAL(sig_Connected()), 0, 0);
549
 
773
 
550
    le_WP->setText(QString("%1/").arg(ps_MK_NaviData.WaypointIndex) + QString("%1").arg(ps_MK_NaviData.WaypointNumber));
774
    ac_Connect->setChecked(false);
-
 
775
    ac_Connect->setText(tr("Verbinden"));
-
 
776
    btn_Connect->setChecked(false);
551
    le_WPTime->setText(QString("%1:").arg(ps_MK_NaviData.TargetHoldTime / 60) + (QString("%1").arg(ps_MK_NaviData.TargetHoldTime % 60)).rightJustified(2, '0'));
777
 
-
 
778
    switch (Error)
-
 
779
    {
-
 
780
        case REMOTECLOSED :
552
    le_WPDist->setText(QString("%1m").arg(ps_MK_NaviData.TargetPositionDeviation.Distance / 10));
781
        {
-
 
782
//            lb_Status->setText(tr("Verbindung vom Server beendet."));
-
 
783
            QMessageBox::warning(this, QA_NAME,tr("QMK-Datenserver: Verbindung wurde vom Server beendet."), QMessageBox::Ok);
553
    le_HomeDist->setText(QString("%1m").arg(ps_MK_NaviData.HomePositionDeviation.Distance / 10));
784
        }
554
 
785
        break;
-
 
786
        case REFUSED :
-
 
787
        {
-
 
788
//            lb_Status->setText(tr("Server nicht gefunden."));
-
 
789
            QMessageBox::warning(this, QA_NAME,tr("QMK-Datenserver: Kann nicht zum Server verbinden."), QMessageBox::Ok);
555
    add_Position(ps_MK_NaviData);
790
        }
556
}
791
        break;
-
 
792
        case 3 :
-
 
793
        {
-
 
794
//            lb_Status->setText(tr("Serververbindung getrennt. Logindaten falsch."));
-
 
795
            QMessageBox::warning(this, QA_NAME,tr("QMK-Datenserver: Loginname oder Password falsch."), QMessageBox::Ok);
557
 
796
        }
558
void dlg_Main::slot_MK_WayPoint(int pi_WayPointID)
797
        break;
-
 
798
        default :
-
 
799
        {
559
{
800
//            lb_Status->setText(tr("Getrennt vom QMK-Datenserver."));
-
 
801
        }
560
    if (pi_WayPointID < l_WayPoints.count())
802
        break;
-
 
803
    }
-
 
804
 
-
 
805
}
-
 
806
 
-
 
807
// Serververbindung hergestellt
-
 
808
void dlg_Main::slot_Input_Connected()
-
 
809
{
-
 
810
    connect(o_Input, SIGNAL(sig_NewData(QString)), this, SLOT(slot_Input_Data(QString)));
-
 
811
 
-
 
812
    o_Input->send_Data(HandlerMK::make_Frame('v', 0, c_Data, 0).toLatin1().data(), DATA_VERSION);
561
    {
813
    ac_Connect->setText(tr("Trennen"));
562
        send_WayPoints(l_WayPoints, pi_WayPointID + 1);
814
}
563
    }
815
 
564
}
816
///////////////////////////////////////////////////////////////////
565
///////////////////////////////////////////////////////////////////
817
// QMK-Maps                                                      //
566
// QMK-Maps                                                      //
818
///////////////////////////////////////////////////////////////////
567
///////////////////////////////////////////////////////////////////
819
 
568
 
820
// Zoom der Karte ändern
569
// Zoom der Karte ändern
821
void dlg_Main::slot_Zoom(int t_Zoom)
570
void dlg_Main::slot_Zoom(int t_Zoom)
822
{
571
{
823
    o_Map->setZoom(t_Zoom);
572
    o_Map->setZoom(t_Zoom);
824
}
573
}
825
 
574
 
826
// Karte wechseln
575
// Karte wechseln
827
void dlg_Main::slot_ChangeMap(int t_Set)
576
void dlg_Main::slot_ChangeMap(int t_Set)
828
{
577
{
829
    int zoom = o_Adapter->adaptedZoom();
578
    int zoom = o_Adapter->adaptedZoom();
830
    QPointF a = o_Map->currentCoordinate();
579
    QPointF a = o_Map->currentCoordinate();
831
 
580
 
832
    o_Map->setZoom(0);
581
    o_Map->setZoom(0);
833
 
582
 
834
    switch(t_Set)
583
    switch(t_Set)
835
    {
584
    {
836
        case 0 : // OpenStreetMap
585
        case 0 : // OpenStreetMap
837
        {
586
        {
838
            o_Adapter = new OSMMapAdapter();
587
            o_Adapter = new OSMMapAdapter();
839
        }
588
        }
840
        break;
589
        break;
841
        case 1 : // Yahoo Sat
590
        case 1 : // Yahoo Sat
842
        {
591
        {
843
            o_Adapter = new TileMapAdapter("tile.openaerialmap.org", "/tiles/1.0.0/openaerialmap-900913/%1/%2/%3.png", 256, 0, 17);
592
            o_Adapter = new TileMapAdapter("tile.openaerialmap.org", "/tiles/1.0.0/openaerialmap-900913/%1/%2/%3.png", 256, 0, 17);
844
        }
593
        }
845
        break;
594
        break;
846
        case 2 : // Google Maps
595
        case 2 : // Google Maps
847
        {
596
        {
848
            o_Adapter = new GoogleMapAdapter();
597
            o_Adapter = new GoogleMapAdapter();
849
        }
598
        }
850
        break;
599
        break;
851
        case 3 : // Google Sat
600
        case 3 : // Google Sat
852
        {
601
        {
853
            o_Adapter = new GoogleSatMapAdapter();
602
            o_Adapter = new GoogleSatMapAdapter();
854
        }
603
        }
855
        break;
604
        break;
856
        case 4 : // Yahoo Maps
605
        case 4 : // Yahoo Maps
857
        {
606
        {
858
            o_Adapter = new YahooMapAdapter();
607
            o_Adapter = new YahooMapAdapter();
859
        }
608
        }
860
        break;
609
        break;
861
        case 5 : // Yahoo Sat
610
        case 5 : // Yahoo Sat
862
        {
611
        {
863
            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");
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");
864
        }
613
        }
865
        break;
614
        break;
866
    }
615
    }
867
 
616
 
868
    o_Layer->setMapAdapter(o_Adapter);
617
    o_Layer->setMapAdapter(o_Adapter);
869
    o_Click->setMapAdapter(o_Adapter);
618
    o_Click->setMapAdapter(o_Adapter);
870
    o_Info->setMapAdapter(o_Adapter);
619
    o_Info->setMapAdapter(o_Adapter);
871
    o_RouteWP->setMapAdapter(o_Adapter);
620
    o_RouteWP->setMapAdapter(o_Adapter);
872
    o_RouteFL->setMapAdapter(o_Adapter);
621
    o_RouteFL->setMapAdapter(o_Adapter);
873
 
622
 
874
    o_Map->updateRequestNew();
623
    o_Map->updateRequestNew();
875
    o_Map->setZoom(zoom);
624
    o_Map->setZoom(zoom);
876
}
625
}
877
 
626
 
878
// Click in die Karte
627
// Click in die Karte
879
void dlg_Main::slot_Click(const QMouseEvent* Event, const QPointF Coord)
628
void dlg_Main::slot_Click(const QMouseEvent* Event, const QPointF Coord)
880
{
629
{
881
    if ((Event->type() == QEvent::MouseButtonPress) && ((Event->button() == Qt::RightButton) || (Event->button() == Qt::MidButton)))
630
    if ((Event->type() == QEvent::MouseButtonPress) && ((Event->button() == Qt::RightButton) || (Event->button() == Qt::MidButton)))
882
    {
631
    {
883
        sl_Zoom->setValue(o_Adapter->adaptedZoom());
632
        sl_Zoom->setValue(o_Adapter->adaptedZoom());
884
    }
633
    }
885
 
634
 
886
    // Überwachen ob Karte verschoben wird
635
    // Überwachen ob Karte verschoben wird
887
    if ((Event->type() == QEvent::MouseButtonPress) && (Event->button() == Qt::LeftButton))
636
    if ((Event->type() == QEvent::MouseButtonPress) && (Event->button() == Qt::LeftButton))
888
    {
637
    {
889
        MapCenter = o_Map->currentCoordinate();
638
        MapCenter = o_Map->currentCoordinate();
890
    }
639
    }
891
 
640
 
892
    // Nur wenn nicht Verschoben dann einen Punkt setzen
641
    // Nur wenn nicht Verschoben dann einen Punkt setzen
893
    if ((Event->type() == QEvent::MouseButtonRelease) && (Event->button() == Qt::LeftButton))
642
    if ((Event->type() == QEvent::MouseButtonRelease) && (Event->button() == Qt::LeftButton))
894
    {
643
    {
895
        if (o_Map->currentCoordinate() == MapCenter)
644
        if (o_Map->currentCoordinate() == MapCenter)
896
        {
645
        {
897
            if (l_WayPoints.count() < 20)
646
            if (l_WayPoints.count() < 20)
898
            {
647
            {
899
                btn_WPAdd->setEnabled(true);
648
                btn_WPAdd->setEnabled(true);
900
            }
649
            }
901
 
650
 
902
            o_Click->removeGeometry(ClickPoint);
651
            o_Click->removeGeometry(ClickPoint);
903
 
652
 
904
            ClickPoint = new CirclePoint(Coord.x(), Coord.y(), 6, "P1", Point::Middle, Pen[2]);
653
            ClickPoint = new CirclePoint(Coord.x(), Coord.y(), 6, "P1", Point::Middle, Pen[2]);
905
 
654
 
906
 
655
 
907
            LastClick = new Point(Coord.x(), Coord.y());
656
            LastClick = new Point(Coord.x(), Coord.y());
908
 
657
 
909
            ClickPoint->setBaselevel(o_Adapter->adaptedZoom());
658
            ClickPoint->setBaselevel(o_Adapter->adaptedZoom());
910
            o_Click->addGeometry(ClickPoint);
659
            o_Click->addGeometry(ClickPoint);
911
 
660
 
912
//            o_Click->removeGeometry(Flag);
661
//            o_Click->removeGeometry(Flag);
913
//            Flag = new ImagePoint(Coord.x(), Coord.y(), ":/Flags/Global/Images/Flags/Target.png", "Start");
662
//            Flag = new ImagePoint(Coord.x(), Coord.y(), ":/Flags/Global/Images/Flags/Target.png", "Start");
914
//            Flag->setBaselevel(o_Adapter->adaptedZoom());
663
//            Flag->setBaselevel(o_Adapter->adaptedZoom());
915
//            o_Click->addGeometry(Flag);
664
//            o_Click->addGeometry(Flag);
916
 
665
 
917
 
666
 
918
            if (cb_Goto->isChecked())
667
            if (cb_Goto->isChecked())
919
            {
668
            {
920
                send_Target(LastClick);
669
                send_Target(LastClick);
921
            }
670
            }
922
        }
671
        }
923
    }
672
    }
924
 
673
 
925
    o_Map->updateRequestNew();
674
    o_Map->updateRequestNew();
926
//    qDebug(QString("%1").arg(Coord.x()).toLatin1().data());
675
//    qDebug(QString("%1").arg(Coord.x()).toLatin1().data());
927
//    qDebug(QString("%1").arg(Coord.y()).toLatin1().data());
676
//    qDebug(QString("%1").arg(Coord.y()).toLatin1().data());
928
}
677
}
929
 
678
 
930
// WayPoint zur Liste hinzufügen
679
// WayPoint zur Liste hinzufügen
931
void dlg_Main::slot_btn_WPAdd()
680
void dlg_Main::slot_btn_WPAdd()
932
{
681
{
933
    cb_ShowWPs->setChecked(true);
682
    cb_ShowWPs->setChecked(true);
934
 
683
 
935
    sWayPoint WayPoint;
684
    sWayPoint WayPoint;
936
 
685
 
937
    WayPoint.Longitude = LastClick->longitude();
686
    WayPoint.Longitude = LastClick->longitude();
938
    WayPoint.Latitude = LastClick->latitude();
687
    WayPoint.Latitude = LastClick->latitude();
939
    WayPoint.Time = sb_Time->value();
688
    WayPoint.Time = sb_Time->value();
940
 
689
 
941
    l_WayPoints.append(WayPoint);
690
    l_WayPoints.append(WayPoint);
942
 
691
 
943
    o_RouteWP->removeGeometry(l_RouteWP);
692
    o_RouteWP->removeGeometry(l_RouteWP);
944
 
693
 
945
    p_RouteWP.append(LastClick);
694
    p_RouteWP.append(LastClick);
946
    l_RouteWP = new LineString(p_RouteWP, "", Pen[3]);
695
    l_RouteWP = new LineString(p_RouteWP, "", Pen[3]);
947
 
696
 
948
    o_RouteWP->addGeometry(l_RouteWP);
697
    o_RouteWP->addGeometry(l_RouteWP);
949
    o_Map->updateRequestNew();
698
    o_Map->updateRequestNew();
950
 
699
 
951
    btn_WPFly->setEnabled(true);
700
    btn_WPFly->setEnabled(true);
952
 
701
 
953
    if (l_WayPoints.count() == 20)
702
    if (l_WayPoints.count() == 20)
954
    {
703
    {
955
        QMessageBox::warning(this, QA_NAME,trUtf8("Wegpunkt-Liste ist voll. Es können maximal 20 Wegpunkte benutzt werden."), QMessageBox::Ok);
704
        QMessageBox::warning(this, QA_NAME,trUtf8("Wegpunkt-Liste ist voll. Es können maximal 20 Wegpunkte benutzt werden."), QMessageBox::Ok);
956
        btn_WPAdd->setEnabled(false);
705
        btn_WPAdd->setEnabled(false);
957
    }
706
    }
958
}
707
}
959
 
708
 
960
// WayPoint-Liste übertragen
709
// WayPoint-Liste übertragen
961
void dlg_Main::slot_btn_WPFly()
710
void dlg_Main::slot_btn_WPFly()
962
{
711
{
963
    send_WayPoints(l_WayPoints, 0);
712
    send_WayPoints(l_WayPoints, 0);
964
}
713
}
965
 
714
 
966
// WayPpoint-Liste löschen
715
// WayPpoint-Liste löschen
967
void dlg_Main::slot_btn_WPDelete()
716
void dlg_Main::slot_btn_WPDelete()
968
{
717
{
969
    p_RouteWP.clear();
718
    p_RouteWP.clear();
970
    l_WayPoints.clear();
719
    l_WayPoints.clear();
971
    o_RouteWP->clearGeometries();
720
    o_RouteWP->clearGeometries();
972
    l_RouteWP = new LineString(p_RouteWP, "", Pen[0]);
721
    l_RouteWP = new LineString(p_RouteWP, "", Pen[0]);
973
//    o_RouteWP->addGeometry(l_RouteWP);
722
//    o_RouteWP->addGeometry(l_RouteWP);
974
//    o_RouteWP->removeGeometry(l_RouteWP);
723
//    o_RouteWP->removeGeometry(l_RouteWP);
975
 
724
 
976
    o_Map->updateRequestNew();
725
    o_Map->updateRequestNew();
977
 
726
 
978
    btn_WPFly->setEnabled(false);
727
    btn_WPFly->setEnabled(false);
979
    btn_WPAdd->setEnabled(true);
728
    btn_WPAdd->setEnabled(true);
980
}
729
}
981
 
730
 
982
// WayPoint-Liste laden
731
// WayPoint-Liste laden
983
void dlg_Main::slot_ac_LoadWayPoints()
732
void dlg_Main::slot_ac_LoadWayPoints()
984
{
733
{
985
    QString Filename = QFileDialog::getOpenFileName(this, "WayPoint-Route laden",  s_Dir.WPRoutes, "Mikrokopter WayPoints(*.mkw);;KML-Datei(*.kml);;Alle Dateien (*)");
734
    QString Filename = QFileDialog::getOpenFileName(this, "WayPoint-Route laden",  s_Dir.WPRoutes, "Mikrokopter WayPoints(*.mkw);;KML-Datei(*.kml);;Alle Dateien (*)");
986
 
735
 
987
    if (!Filename.isEmpty())
736
    if (!Filename.isEmpty())
988
    {
737
    {
989
        if (Filename.endsWith(".kml", Qt::CaseInsensitive))
738
        if (Filename.endsWith(".kml", Qt::CaseInsensitive))
990
        {
739
        {
991
            cb_ShowWPs->setChecked(true);
740
            cb_ShowWPs->setChecked(true);
992
            btn_WPFly->setEnabled(true);
741
            btn_WPFly->setEnabled(true);
993
 
742
 
994
            show_WayPoints(parse_WayPointKML(Filename));
743
            show_WayPoints(parse_WayPointKML(Filename));
995
        }
744
        }
996
        if (Filename.endsWith(".mkw", Qt::CaseInsensitive))
745
        if (Filename.endsWith(".mkw", Qt::CaseInsensitive))
997
        {
746
        {
998
            cb_ShowWPs->setChecked(true);
747
            cb_ShowWPs->setChecked(true);
999
            btn_WPFly->setEnabled(true);
748
            btn_WPFly->setEnabled(true);
1000
 
749
 
1001
            show_WayPoints(parse_WayPointMKW(Filename));
750
            show_WayPoints(parse_WayPointMKW(Filename));
1002
        }
751
        }
1003
    }
752
    }
1004
}
753
}
1005
 
754
 
1006
// WayPoint-Liste speichern
755
// WayPoint-Liste speichern
1007
void dlg_Main::slot_ac_SaveRoute()
756
void dlg_Main::slot_ac_SaveRoute()
1008
{
757
{
1009
    QString Filename = QFileDialog::getSaveFileName(this, "WayPoint-Route speichern",  s_Dir.WPRoutes, "Mikrokopter WayPoints(*.mkw);;Alle Dateien (*)");
758
    QString Filename = QFileDialog::getSaveFileName(this, "WayPoint-Route speichern",  s_Dir.WPRoutes, "Mikrokopter WayPoints(*.mkw);;Alle Dateien (*)");
1010
 
759
 
1011
    if (!Filename.isEmpty())
760
    if (!Filename.isEmpty())
1012
    {
761
    {
1013
        if (!(Filename.endsWith(".mkw", Qt::CaseInsensitive)))
762
        if (!(Filename.endsWith(".mkw", Qt::CaseInsensitive)))
1014
        {
763
        {
1015
            Filename = Filename + QString(".mkw");
764
            Filename = Filename + QString(".mkw");
1016
        }
765
        }
1017
 
766
 
1018
        save_WayPointsMKW(Filename);
767
        save_WayPointsMKW(Filename);
1019
    }
768
    }
1020
}
769
}
1021
 
770
 
1022
// Route anzeigen / ausblenden
771
// Route anzeigen / ausblenden
1023
void dlg_Main::slot_ShowWayPoints(bool Show)
772
void dlg_Main::slot_ShowWayPoints(bool Show)
1024
{
773
{
1025
    if (Show == true)
774
    if (Show == true)
1026
    {
775
    {
1027
        if (l_RouteWP->hasPoints())
776
        if (l_RouteWP->hasPoints())
1028
        {
777
        {
1029
            o_RouteWP->addGeometry(l_RouteWP);
778
            o_RouteWP->addGeometry(l_RouteWP);
1030
            o_Map->updateRequestNew();
779
            o_Map->updateRequestNew();
1031
        }
780
        }
1032
    }
781
    }
1033
    else
782
    else
1034
    {
783
    {
1035
        o_RouteWP->removeGeometry(l_RouteWP);
784
        o_RouteWP->removeGeometry(l_RouteWP);
1036
        o_Map->updateRequestNew();
785
        o_Map->updateRequestNew();
1037
    }
786
    }
1038
}
787
}
1039
 
788
 
1040
// Bilddatei als Karteladen.
789
// Bilddatei als Karteladen.
1041
void dlg_Main::slot_ac_LoadMapPic()
790
void dlg_Main::slot_ac_LoadMapPic()
1042
{
791
{
1043
    QString Filename = QFileDialog::getOpenFileName(this, "Bild als Karte",  s_Dir.MapPics, "Bilddatei(*.jpg *.png *.gif);;Alle Dateien (*)");
792
    QString Filename = QFileDialog::getOpenFileName(this, "Bild als Karte",  s_Dir.MapPics, "Bilddatei(*.jpg *.png *.gif);;Alle Dateien (*)");
1044
 
793
 
1045
    if (!Filename.isEmpty())
794
    if (!Filename.isEmpty())
1046
    {
795
    {
1047
        QFile *f_Points = new QFile(Filename + ".pos");
796
        QFile *f_Points = new QFile(Filename + ".pos");
1048
 
797
 
1049
        if (f_Points->exists())
798
        if (f_Points->exists())
1050
        {
799
        {
1051
            f_Points->open(QIODevice::ReadOnly | QIODevice::Text);
800
            f_Points->open(QIODevice::ReadOnly | QIODevice::Text);
1052
 
801
 
1053
            QString s_Points;
802
            QString s_Points;
1054
 
803
 
1055
            while (!f_Points->atEnd())
804
            while (!f_Points->atEnd())
1056
            {
805
            {
1057
                s_Points.append(f_Points->readLine());
806
                s_Points.append(f_Points->readLine());
1058
            }
807
            }
1059
 
808
 
1060
            f_Points->close();
809
            f_Points->close();
1061
 
810
 
1062
            QStringList s_Pos = s_Points.split(",");
811
            QStringList s_Pos = s_Points.split(",");
1063
 
812
 
1064
            FixedImageOverlay* fip = new FixedImageOverlay(s_Pos[0].toDouble(), s_Pos[1].toDouble(), s_Pos[2].toDouble(), s_Pos[3].toDouble(), Filename);
813
            FixedImageOverlay* fip = new FixedImageOverlay(s_Pos[0].toDouble(), s_Pos[1].toDouble(), s_Pos[2].toDouble(), s_Pos[3].toDouble(), Filename);
1065
 
814
 
1066
            o_Layer->addGeometry(fip);
815
            o_Layer->addGeometry(fip);
1067
            o_Map->setView(QPointF(((s_Pos[0].toDouble() + s_Pos[2].toDouble()) / 2),((s_Pos[1].toDouble() + s_Pos[3].toDouble()) / 2)));
816
            o_Map->setView(QPointF(((s_Pos[0].toDouble() + s_Pos[2].toDouble()) / 2),((s_Pos[1].toDouble() + s_Pos[3].toDouble()) / 2)));
1068
 
817
 
1069
            o_Map->updateRequestNew();
818
            o_Map->updateRequestNew();
1070
        }
819
        }
1071
        else
820
        else
1072
        {
821
        {
1073
            dlg_MapPos *f_MapPos = new dlg_MapPos(this);
822
            dlg_MapPos *f_MapPos = new dlg_MapPos(this);
1074
 
823
 
1075
            if (f_MapPos->exec()==QDialog::Accepted)
824
            if (f_MapPos->exec()==QDialog::Accepted)
1076
            {
825
            {
1077
                QString Data = f_MapPos->get_Data();
826
                QString Data = f_MapPos->get_Data();
1078
 
827
 
1079
                f_Points->open(QIODevice::ReadWrite | QIODevice::Text);
828
                f_Points->open(QIODevice::ReadWrite | QIODevice::Text);
1080
 
829
 
1081
                QTextStream out(f_Points);
830
                QTextStream out(f_Points);
1082
 
831
 
1083
                out.setRealNumberPrecision(9);
832
                out.setRealNumberPrecision(9);
1084
 
833
 
1085
                out << Data << "\n";
834
                out << Data << "\n";
1086
 
835
 
1087
                f_Points->close();
836
                f_Points->close();
1088
 
837
 
1089
                QStringList s_Pos = Data.split(",");
838
                QStringList s_Pos = Data.split(",");
1090
 
839
 
1091
                FixedImageOverlay* fip = new FixedImageOverlay(s_Pos[0].toDouble(), s_Pos[1].toDouble(), s_Pos[2].toDouble(), s_Pos[3].toDouble(), Filename);
840
                FixedImageOverlay* fip = new FixedImageOverlay(s_Pos[0].toDouble(), s_Pos[1].toDouble(), s_Pos[2].toDouble(), s_Pos[3].toDouble(), Filename);
1092
 
841
 
1093
                o_Layer->addGeometry(fip);
842
                o_Layer->addGeometry(fip);
1094
                o_Map->updateRequestNew();
843
                o_Map->updateRequestNew();
1095
            }
844
            }
1096
 
845
 
1097
        }
846
        }
1098
    }
847
    }
1099
}
848
}
1100
 
849
 
1101
// Flug als KML aufzeichnen
850
// Flug als KML aufzeichnen
1102
void dlg_Main::slot_ac_Record()
851
void dlg_Main::slot_ac_Record()
1103
{
852
{
1104
    if (ac_Record->isChecked())
853
    if (ac_Record->isChecked())
1105
    {
854
    {
1106
        QString f_Name = s_Dir.Flights + "/" + QDate::currentDate().toString(("yyyy-MM-dd")) + "_" + QTime::currentTime().toString("hh-mm");
855
        QString f_Name = s_Dir.Flights + "/" + QDate::currentDate().toString(("yyyy-MM-dd")) + "_" + QTime::currentTime().toString("hh-mm");
1107
 
856
 
1108
        ac_Record->setText(tr("Stoppen"));
857
        ac_Record->setText(tr("Stoppen"));
1109
 
858
 
1110
        o_Record = new QFile(f_Name + ".kml");
859
        o_Record = new QFile(f_Name + ".kml");
1111
        o_Record->open(QIODevice::Append | QIODevice::Text);
860
        o_Record->open(QIODevice::Append | QIODevice::Text);
1112
 
861
 
1113
        QTextStream Out(o_Record);
862
        QTextStream Out(o_Record);
1114
        Out << HandlerKML::get_Header(tr("Mikrokopter Flugaufzeichnung")) << "\n";
863
        Out << HandlerKML::get_Header(tr("Mikrokopter Flugaufzeichnung")) << "\n";
1115
 
864
 
1116
    }
865
    }
1117
    else
866
    else
1118
    {
867
    {
1119
        QTextStream Out(o_Record);
868
        QTextStream Out(o_Record);
1120
        Out << HandlerKML::get_Footer() << "\n";
869
        Out << HandlerKML::get_Footer() << "\n";
1121
        o_Record->close();
870
        o_Record->close();
1122
        ac_Record->setText(tr("Aufzeichnen"));
871
        ac_Record->setText(tr("Aufzeichnen"));
1123
    }
872
    }
1124
}
873
}
1125
 
874
 
1126
// WayPpoint-Liste löschen
875
// WayPpoint-Liste löschen
1127
void dlg_Main::slot_ac_RouteDelete()
876
void dlg_Main::slot_ac_RouteDelete()
1128
{
877
{
1129
    p_RouteFL.clear();
878
    p_RouteFL.clear();
1130
    l_Track.clear();
879
    l_Track.clear();
1131
    o_RouteFL->clearGeometries();
880
    o_RouteFL->clearGeometries();
1132
    l_RouteFL = new LineString(p_RouteFL, "", Pen[0]);
881
    l_RouteFL = new LineString(p_RouteFL, "", Pen[0]);
1133
//    o_RouteFL->removeGeometry(l_RouteFL);
882
//    o_RouteFL->removeGeometry(l_RouteFL);
1134
 
883
 
1135
    o_Map->updateRequestNew();
884
    o_Map->updateRequestNew();
1136
}
885
}
1137
 
886
 
1138
// Programm Ende
887
// Programm Ende
1139
dlg_Main::~dlg_Main()
888
dlg_Main::~dlg_Main()
1140
{
889
{
1141
    o_Settings->GUI.isMax       = isMaximized();
890
    o_Settings->GUI.isMax       = isMaximized();
1142
    o_Settings->GUI.Size        = size();
891
    o_Settings->GUI.Size        = size();
1143
    o_Settings->GUI.Point       = pos();
892
    o_Settings->GUI.Point       = pos();
1144
    o_Settings->GUI.Toolbar     = ac_Toolbar->isChecked();
893
    o_Settings->GUI.Toolbar     = ac_Toolbar->isChecked();
1145
 
-
 
1146
    o_Settings->DATA.Intervall = sb_Intervall->value();
-
 
1147
 
-
 
1148
    o_Settings->SERVER.Password = le_Password->text();
-
 
1149
    o_Settings->SERVER.IP_MAX  = cb_Server->count();
-
 
1150
    o_Settings->SERVER.IP_ID   = cb_Server->currentIndex();
-
 
1151
 
-
 
1152
    for (int z = 0; z < cb_Server->count(); z++)
-
 
1153
    {
-
 
1154
        if (z < 10)
-
 
1155
        {
-
 
1156
            o_Settings->SERVER.IP[z] = cb_Server->itemText(z);
-
 
1157
        }
-
 
1158
    }
-
 
1159
 
894
 
1160
    o_Settings->CONFIG.cb_CenterPos = cb_CenterPos->isChecked();
895
    o_Settings->CONFIG.cb_CenterPos = cb_CenterPos->isChecked();
1161
    o_Settings->CONFIG.cb_ShowRoute = cb_ShowRoute->isChecked();
896
    o_Settings->CONFIG.cb_ShowRoute = cb_ShowRoute->isChecked();
1162
    o_Settings->CONFIG.cb_ShowWPs   = cb_ShowWPs->isChecked();
897
    o_Settings->CONFIG.cb_ShowWPs   = cb_ShowWPs->isChecked();
1163
    o_Settings->CONFIG.cb_Goto      = cb_Goto->isChecked();
898
    o_Settings->CONFIG.cb_Goto      = cb_Goto->isChecked();
1164
 
899
 
1165
    o_Settings->NAVI.StayTime = sb_Time->value();
900
    o_Settings->NAVI.StayTime = sb_Time->value();
1166
 
901
 
1167
    o_Settings->write_Settings();
902
    o_Settings->write_Settings();
1168
 
903
 
1169
//    qDebug("Ende.");
904
//    qDebug("Ende.");
1170
}
905
}
1171
 
906