Subversion Repositories Projects

Rev

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

Rev 334 Rev 337
1
/***************************************************************************
1
/***************************************************************************
2
 *   Copyright (C) 2009 by Manuel Schrape                                  *
2
 *   Copyright (C) 2009 by Manuel Schrape                                  *
3
 *   manuel.schrape@gmx.de                                                 *
3
 *   manuel.schrape@gmx.de                                                 *
4
 *                                                                         *
4
 *                                                                         *
5
 *   This program is free software; you can redistribute it and/or modify  *
5
 *   This program is free software; you can redistribute it and/or modify  *
6
 *   it under the terms of the GNU General Public License as published by  *
6
 *   it under the terms of the GNU General Public License as published by  *
7
 *   the Free Software Foundation; either version 2 of the License.        *
7
 *   the Free Software Foundation; either version 2 of the License.        *
8
 *                                                                         *
8
 *                                                                         *
9
 *   This program is distributed in the hope that it will be useful,       *
9
 *   This program is distributed in the hope that it will be useful,       *
10
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
10
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
11
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12
 *   GNU General Public License for more details.                          *
12
 *   GNU General Public License for more details.                          *
13
 *                                                                         *
13
 *                                                                         *
14
 *   You should have received a copy of the GNU General Public License     *
14
 *   You should have received a copy of the GNU General Public License     *
15
 *   along with this program; if not, write to the                         *
15
 *   along with this program; if not, write to the                         *
16
 *   Free Software Foundation, Inc.,                                       *
16
 *   Free Software Foundation, Inc.,                                       *
17
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
17
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
18
 ***************************************************************************/
18
 ***************************************************************************/
19
#include "dlg_Map.h"
19
#include "dlg_Map.h"
20
 
20
 
21
dlg_Map::dlg_Map(QWidget *parent) : QDialog(parent)
21
dlg_Map::dlg_Map(QWidget *parent) : QDialog(parent)
22
{
22
{
23
    setupUi(this);
23
    setupUi(this);
24
 
-
 
25
    // Kartenwahl ausschalten
-
 
26
    //lb_Maps->setVisible(false);
-
 
27
    //cb_Maps->setVisible(false);
-
 
28
 
24
 
29
    cb_Maps->removeItem(5);
25
    cb_Maps->removeItem(5);
30
    cb_Maps->removeItem(4);
26
    cb_Maps->removeItem(4);
31
    cb_Maps->removeItem(3);
27
    cb_Maps->removeItem(3);
32
    cb_Maps->removeItem(2);
28
    cb_Maps->removeItem(2);
33
 
29
 
34
    // Noch nicht eingebaut also Button weg.
30
    // Noch nicht eingebaut also Button weg.
35
    pb_SendWaypoints->setVisible(false);
31
    pb_SendWaypoints->setVisible(false);
36
 
32
 
37
    pb_Add->setEnabled(false);
33
    pb_Add->setEnabled(false);
38
    pb_Goto->setEnabled(false);
34
    pb_Goto->setEnabled(false);
39
}
35
}
40
 
36
 
41
// Karte erstellen und anzeigen
37
// Karte erstellen und anzeigen
42
void dlg_Map::create_Map(cSettings *t_Settings)
38
void dlg_Map::create_Map(cSettings *t_Settings)
43
{
39
{
44
    o_Settings = t_Settings;
40
    o_Settings = t_Settings;
45
 
41
 
46
    cb_CenterPos->setChecked(o_Settings->Map.GotoPosition);
42
    cb_CenterPos->setChecked(o_Settings->Map.GotoPosition);
47
    cb_ShowRoute->setChecked(o_Settings->Map.ShowTrack);
43
    cb_ShowRoute->setChecked(o_Settings->Map.ShowTrack);
48
 
44
 
49
    connect(sl_Zoom,   SIGNAL(valueChanged(int)), this, SLOT(slot_Zoom(int)));
45
    connect(sl_Zoom,   SIGNAL(valueChanged(int)), this, SLOT(slot_Zoom(int)));
50
    connect(pb_Add,    SIGNAL(clicked()), this, SLOT(slot_AddWayPoint()));
46
    connect(pb_Add,    SIGNAL(clicked()), this, SLOT(slot_AddWayPoint()));
51
    connect(pb_Delete, SIGNAL(clicked()), this, SLOT(slot_DeleteWayPoints()));
47
    connect(pb_Delete, SIGNAL(clicked()), this, SLOT(slot_DeleteWayPoints()));
52
    connect(pb_Goto,   SIGNAL(clicked()), this, SLOT(slot_GotoTarget()));
48
    connect(pb_Goto,   SIGNAL(clicked()), this, SLOT(slot_GotoTarget()));
53
    connect(cb_Maps,   SIGNAL(currentIndexChanged(int)), this, SLOT(slot_ChangeMap(int)));
49
    connect(cb_Maps,   SIGNAL(currentIndexChanged(int)), this, SLOT(slot_ChangeMap(int)));
54
    connect(this,      SIGNAL(rejected()), this, SLOT(slot_Close()));
50
    connect(this,      SIGNAL(rejected()), this, SLOT(slot_Close()));
55
 
51
 
56
    o_Map = new MapControl(w_Map->size());
52
    o_Map = new MapControl(w_Map->size());
57
    o_Map->enablePersistentCache(o_Settings->DIR.Cache);
53
    o_Map->enablePersistentCache(o_Settings->DIR.Cache);
58
    o_Map->showScale(true);
54
    o_Map->showScale(true);
59
 
55
 
60
    o_Adapter = new OSMMapAdapter();
56
    o_Adapter = new OSMMapAdapter();
61
 
57
 
62
    o_Layer = new MapLayer("MapLayer", o_Adapter);
58
    o_Layer = new MapLayer("MapLayer", o_Adapter);
63
    o_Click = new GeometryLayer("Click", o_Adapter);
59
    o_Click = new GeometryLayer("Click", o_Adapter);
64
    o_Route = new GeometryLayer("Poute", o_Adapter);
60
    o_Route = new GeometryLayer("Poute", o_Adapter);
65
 
61
 
66
    o_Map->addLayer(o_Layer);
62
    o_Map->addLayer(o_Layer);
67
    o_Map->addLayer(o_Click);
63
    o_Map->addLayer(o_Click);
68
    o_Map->addLayer(o_Route);
64
    o_Map->addLayer(o_Route);
69
 
65
 
70
    o_Map->setZoom(17);
66
    o_Map->setZoom(17);
71
//    o_Map->setView(QPointF(13.85615670,52.50787020));
-
 
72
    o_Map->setView(QPointF(13.5,52.5));
67
    o_Map->setView(QPointF(13.5,52.5));
73
 
68
 
74
    connect(o_Map, SIGNAL(mouseEventCoordinate(const QMouseEvent*, const QPointF)), this, SLOT(slot_Click(const QMouseEvent*, const QPointF)));
69
    connect(o_Map, SIGNAL(mouseEventCoordinate(const QMouseEvent*, const QPointF)), this, SLOT(slot_Click(const QMouseEvent*, const QPointF)));
75
 
70
 
76
    l_Map->addWidget(o_Map);
71
    l_Map->addWidget(o_Map);
77
 
72
 
78
    sl_Zoom->setValue(17);
73
    sl_Zoom->setValue(17);
79
 
74
 
80
    Pen[0] = new QPen(QColor(0,0,255,255));
75
    Pen[0] = new QPen(QColor(0,0,255,255));
81
    Pen[0]->setWidth(2);
76
    Pen[0]->setWidth(2);
82
    Pen[1] = new QPen(QColor(255,0,0,255));
77
    Pen[1] = new QPen(QColor(255,0,0,255));
83
    Pen[1]->setWidth(2);
78
    Pen[1]->setWidth(2);
84
}
79
}
85
 
80
 
86
// Position zum Flug-Track hinzufügen
81
// Position zum Flug-Track hinzufügen
87
void dlg_Map::add_Position(double x, double y)
82
void dlg_Map::add_Position(double x, double y)
88
{
83
{
89
    sWayPoint WayPoint;
84
    sWayPoint WayPoint;
90
 
85
 
91
    WayPoint.Longitude = x;
86
    WayPoint.Longitude = x;
92
    WayPoint.Latitude = y;
87
    WayPoint.Latitude = y;
93
    WayPoint.Time = sb_Time->value();
88
    WayPoint.Time = sb_Time->value();
94
 
89
 
95
    l_WayPoint.append(WayPoint);
90
    l_WayPoint.append(WayPoint);
96
 
91
 
97
    o_Route->removeGeometry(l_RouteFL);
92
    o_Route->removeGeometry(l_RouteFL);
98
    p_RouteFL.append(new Point(x,y));
93
    p_RouteFL.append(new Point(x,y));
99
 
94
 
100
    o_Click->removeGeometry(LastPos);
95
    o_Click->removeGeometry(LastPos);
101
 
96
 
102
    Point* P = new CirclePoint(x, y, "P1", Point::Middle, Pen[0]);
97
    Point* P = new CirclePoint(x, y, "P1", Point::Middle, Pen[0]);
103
    LastPos = P;
98
    LastPos = P;
104
    P->setBaselevel(17);
99
    P->setBaselevel(17);
105
    o_Click->addGeometry(P);
100
    o_Click->addGeometry(P);
106
 
101
 
107
    if (cb_CenterPos->isChecked())
102
    if (cb_CenterPos->isChecked())
108
    {
103
    {
109
        o_Map->setView(QPointF(x, y));
104
        o_Map->setView(QPointF(x, y));
110
    }
105
    }
111
 
106
 
112
    if (cb_ShowRoute->isChecked())
107
    if (cb_ShowRoute->isChecked())
113
    {
108
    {
114
        l_RouteFL = new LineString(p_RouteFL, "", Pen[1]);
109
        l_RouteFL = new LineString(p_RouteFL, "", Pen[1]);
115
 
110
 
116
        o_Route->addGeometry(l_RouteFL);
111
        o_Route->addGeometry(l_RouteFL);
117
    }
112
    }
118
    o_Map->updateRequestNew();
113
    o_Map->updateRequestNew();
119
}
114
}
120
 
115
 
121
// Zoom der Karte ändern
116
// Zoom der Karte ändern
122
void dlg_Map::slot_Zoom(int t_Zoom)
117
void dlg_Map::slot_Zoom(int t_Zoom)
123
{
118
{
124
    o_Map->setZoom(t_Zoom);
119
    o_Map->setZoom(t_Zoom);
125
}
120
}
126
 
121
 
127
// Waypoint zur Liste hinzufügen
122
// Waypoint zur Liste hinzufügen
128
void dlg_Map::slot_AddWayPoint()
123
void dlg_Map::slot_AddWayPoint()
129
{
124
{
130
    o_Route->removeGeometry(l_RouteWP);
125
    o_Route->removeGeometry(l_RouteWP);
131
 
126
 
132
    p_RouteWP.append(LastClick);
127
    p_RouteWP.append(LastClick);
133
    l_RouteWP = new LineString(p_RouteWP, "", Pen[0]);
128
    l_RouteWP = new LineString(p_RouteWP, "", Pen[0]);
134
 
129
 
135
    o_Route->addGeometry(l_RouteWP);
130
    o_Route->addGeometry(l_RouteWP);
136
    o_Map->updateRequestNew();
131
    o_Map->updateRequestNew();
137
}
132
}
138
 
133
 
139
// Waypoint-Liste löschen
134
// Waypoint-Liste löschen
140
void dlg_Map::slot_DeleteWayPoints()
135
void dlg_Map::slot_DeleteWayPoints()
141
{
136
{
142
    o_Route->removeGeometry(l_RouteWP);
137
    o_Route->removeGeometry(l_RouteWP);
143
    p_RouteWP.clear();
138
    p_RouteWP.clear();
144
    l_WayPoint.clear();
139
    l_WayPoint.clear();
145
    o_Map->updateRequestNew();
140
    o_Map->updateRequestNew();
146
}
141
}
147
 
142
 
148
// Zum Zielpunkt fliegen
143
// Zum Zielpunkt fliegen
149
void dlg_Map::slot_GotoTarget()
144
void dlg_Map::slot_GotoTarget()
150
{
145
{
151
    sWayPoint Target;
146
    sWayPoint Target;
152
 
147
 
153
    Target.Longitude = LastClick->longitude();
148
    Target.Longitude = LastClick->longitude();
154
    Target.Latitude = LastClick->latitude();
149
    Target.Latitude = LastClick->latitude();
155
    Target.Time = sb_Time->value();
150
    Target.Time = sb_Time->value();
156
 
151
 
157
    emit(set_Target(Target));
152
    emit(set_Target(Target));
158
}
153
}
159
 
154
 
160
// Click in der Karte
155
// Click in der Karte
161
void dlg_Map::slot_Click(const QMouseEvent* Event, const QPointF Coord)
156
void dlg_Map::slot_Click(const QMouseEvent* Event, const QPointF Coord)
162
{
157
{
163
    if ((Event->type() == QEvent::MouseButtonPress) && ((Event->button() == Qt::RightButton) || (Event->button() == Qt::MidButton)))
158
    if ((Event->type() == QEvent::MouseButtonPress) && ((Event->button() == Qt::RightButton) || (Event->button() == Qt::MidButton)))
164
    {
159
    {
165
        sl_Zoom->setValue(o_Adapter->adaptedZoom());
160
        sl_Zoom->setValue(o_Adapter->adaptedZoom());
166
    }
161
    }
167
 
162
 
168
    // Überwachen ob Karte verschoben wird
163
    // Überwachen ob Karte verschoben wird
169
    if ((Event->type() == QEvent::MouseButtonPress) && (Event->button() == Qt::LeftButton))
164
    if ((Event->type() == QEvent::MouseButtonPress) && (Event->button() == Qt::LeftButton))
170
    {
165
    {
171
        MapCenter = o_Map->currentCoordinate();
166
        MapCenter = o_Map->currentCoordinate();
172
    }
167
    }
173
 
168
 
174
    // Nur wenn nicht Verschoben dann einen Punkt setzen
169
    // Nur wenn nicht Verschoben dann einen Punkt setzen
175
    if ((Event->type() == QEvent::MouseButtonRelease) && (Event->button() == Qt::LeftButton))
170
    if ((Event->type() == QEvent::MouseButtonRelease) && (Event->button() == Qt::LeftButton))
176
    {
171
    {
177
        if (o_Map->currentCoordinate() == MapCenter)
172
        if (o_Map->currentCoordinate() == MapCenter)
178
        {
173
        {
179
            pb_Add->setEnabled(true);
174
            pb_Add->setEnabled(true);
180
            pb_Goto->setEnabled(true);
175
            pb_Goto->setEnabled(true);
181
 
176
 
182
            o_Click->removeGeometry(ClickPoint);
177
            o_Click->removeGeometry(ClickPoint);
183
 
178
 
184
            ClickPoint = new CirclePoint(Coord.x(), Coord.y(), 6, "P1", Point::Middle, Pen[1]);
179
            ClickPoint = new CirclePoint(Coord.x(), Coord.y(), 6, "P1", Point::Middle, Pen[1]);
185
//            LastPoint = P;
180
//            LastPoint = P;
186
 
181
 
187
            LastClick = new Point(Coord.x(), Coord.y());
182
            LastClick = new Point(Coord.x(), Coord.y());
188
 
183
 
189
            ClickPoint->setBaselevel(o_Adapter->adaptedZoom());
184
            ClickPoint->setBaselevel(o_Adapter->adaptedZoom());
190
            o_Click->addGeometry(ClickPoint);
185
            o_Click->addGeometry(ClickPoint);
191
        }
186
        }
192
    }
187
    }
193
 
188
 
194
    o_Map->updateRequestNew();
189
    o_Map->updateRequestNew();
195
//    qDebug(QString("%1").arg(Coord.x()).toLatin1().data());
190
//    qDebug(QString("%1").arg(Coord.x()).toLatin1().data());
196
//    qDebug(QString("%1").arg(Coord.y()).toLatin1().data());
191
//    qDebug(QString("%1").arg(Coord.y()).toLatin1().data());
197
}
192
}
198
 
193
 
199
// auf Veränderung der Fenstergröße reagieren
194
// auf Veränderung der Fenstergröße reagieren
200
void dlg_Map::resizeEvent ( QResizeEvent * event )
195
void dlg_Map::resizeEvent ( QResizeEvent * event )
201
{
196
{
202
    event = event;
197
    event = event;
203
    o_Map->resize(w_Map->size() - QSize(20,20));
198
    o_Map->resize(w_Map->size() - QSize(20,20));
204
}
199
}
205
 
200
 
206
// Karte wechseln
201
// Karte wechseln
207
void dlg_Map::slot_ChangeMap(int t_Set)
202
void dlg_Map::slot_ChangeMap(int t_Set)
208
{
203
{
209
    int zoom = o_Adapter->adaptedZoom();
204
    int zoom = o_Adapter->adaptedZoom();
210
    QPointF a = o_Map->currentCoordinate();
205
    QPointF a = o_Map->currentCoordinate();
211
 
206
 
212
    o_Map->setZoom(0);
207
    o_Map->setZoom(0);
213
 
208
 
214
    switch(t_Set)
209
    switch(t_Set)
215
    {
210
    {
216
        case 0 : // OpenStreetMap
211
        case 0 : // OpenStreetMap
217
        {
212
        {
218
            o_Adapter = new OSMMapAdapter();
213
            o_Adapter = new OSMMapAdapter();
219
        }
214
        }
220
        break;
215
        break;
221
        case 1 : // Yahoo Sat
216
        case 1 : // Yahoo Sat
222
        {
217
        {
223
            o_Adapter = new WMSMapAdapter("openaerialmap.org", "/wms/wms.asp?wms=WorldMap&LAYERS=world&FORMAT=image/png&VERSION=1.1.1&SERVICE=WMS&REQUEST=GetMap&STYLES=&EXCEPTIONS=application/vnd.ogc.se_inimage&SRS=EPSG:4326&TRANSPARENT=FALSE", 256);
218
            o_Adapter = new WMSMapAdapter("openaerialmap.org", "/wms/wms.asp?wms=WorldMap&LAYERS=world&FORMAT=image/png&VERSION=1.1.1&SERVICE=WMS&REQUEST=GetMap&STYLES=&EXCEPTIONS=application/vnd.ogc.se_inimage&SRS=EPSG:4326&TRANSPARENT=FALSE", 256);
224
        }
219
        }
225
        break;
220
        break;
226
        case 2 : // Google Maps
221
        case 2 : // Google Maps
227
        {
222
        {
228
            o_Adapter = new GoogleMapAdapter();
223
            o_Adapter = new GoogleMapAdapter();
229
        }
224
        }
230
        break;
225
        break;
231
        case 3 : // Google Sat
226
        case 3 : // Google Sat
232
        {
227
        {
233
            o_Adapter = new GoogleSatMapAdapter();
228
            o_Adapter = new GoogleSatMapAdapter();
234
        }
229
        }
235
        break;
230
        break;
236
        case 4 : // Yahoo Maps
231
        case 4 : // Yahoo Maps
237
        {
232
        {
238
            o_Adapter = new YahooMapAdapter();
233
            o_Adapter = new YahooMapAdapter();
239
        }
234
        }
240
        break;
235
        break;
241
        case 5 : // Yahoo Sat
236
        case 5 : // Yahoo Sat
242
        {
237
        {
243
            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");
238
            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");
244
        }
239
        }
245
        break;
240
        break;
246
    }
241
    }
247
 
242
 
248
    o_Layer->setMapAdapter(o_Adapter);
243
    o_Layer->setMapAdapter(o_Adapter);
249
    o_Click->setMapAdapter(o_Adapter);
244
    o_Click->setMapAdapter(o_Adapter);
250
    o_Route->setMapAdapter(o_Adapter);
245
    o_Route->setMapAdapter(o_Adapter);
251
 
246
 
252
    o_Map->updateRequestNew();
247
    o_Map->updateRequestNew();
253
    o_Map->setZoom(zoom);
248
    o_Map->setZoom(zoom);
254
}
249
}
255
 
250
 
256
// Fenster wird geschlossen.
251
// Fenster wird geschlossen.
257
void dlg_Map::slot_Close()
252
void dlg_Map::slot_Close()
258
{
253
{
259
    o_Settings->Map.GotoPosition = cb_CenterPos->isChecked();
254
    o_Settings->Map.GotoPosition = cb_CenterPos->isChecked();
260
    o_Settings->Map.ShowTrack    = cb_ShowRoute->isChecked();
255
    o_Settings->Map.ShowTrack    = cb_ShowRoute->isChecked();
261
    emit set_Settings(o_Settings);
256
    emit set_Settings(o_Settings);
262
}
257
}
263
 
258
 
264
 
259