17,6 → 17,8 |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
***************************************************************************/ |
#include "dlg_Map.h" |
#include <QDomDocument> |
#include <QFile> |
|
dlg_Map::dlg_Map(QWidget *parent) : QDialog(parent) |
{ |
44,7 → 46,13 |
connect(pb_Delete, SIGNAL(clicked()), this, SLOT(slot_DeleteWayPoints())); |
connect(pb_Goto, SIGNAL(clicked()), this, SLOT(slot_GotoTarget())); |
connect(pb_SendWaypoints, SIGNAL(clicked()), this, SLOT(slot_SendWayPoints())); |
|
connect(pb_Load, SIGNAL(clicked()), this, SLOT(slot_LoadWayPoints())); |
connect(pb_Save, SIGNAL(clicked()), this, SLOT(slot_SaveWayPoints())); |
|
connect(cb_Maps, SIGNAL(currentIndexChanged(int)), this, SLOT(slot_ChangeMap(int))); |
connect(cb_ShowWPs, SIGNAL(toggled(bool)), this, SLOT(slot_ShowWayPoints(bool))); |
|
connect(this, SIGNAL(rejected()), this, SLOT(slot_Close())); |
|
o_Map = new MapControl(w_Map->size()); |
76,6 → 84,207 |
Pen[1]->setWidth(2); |
} |
|
QList<sWayPoint> dlg_Map::parse_WayPointKML(QString s_File) |
{ |
QList<sWayPoint> tmp_WayPoints; |
sWayPoint tmp_WayPoint; |
|
QFile f_KML(s_File); |
f_KML.open(QIODevice::ReadOnly | QIODevice::Text); |
|
QByteArray s_KML; |
|
while (!f_KML.atEnd()) |
{ |
s_KML.append(f_KML.readLine()); |
} |
|
f_KML.close(); |
|
QDomDocument *UserXML; |
UserXML = new QDomDocument; |
|
UserXML->setContent(s_KML); |
|
QDomElement Root = UserXML->firstChildElement("kml"); |
QDomElement Document = Root.firstChildElement("Document"); |
QDomElement Placemark = Document.firstChildElement("Placemark"); |
QDomElement Linestring = Placemark.firstChildElement("LineString"); |
|
QString Name = Placemark.firstChildElement("name").toElement().text(); |
|
QString Route = Linestring.firstChildElement("coordinates").toElement().text(); |
|
QStringList s_Points = Route.split(" "); |
|
QStringList Position; |
|
for (int z = 0; z < s_Points.count() - 1; z++) |
{ |
if (z != 20) |
{ |
Position = s_Points[z].split(","); |
tmp_WayPoint.Longitude = Position[0].toDouble(); |
tmp_WayPoint.Latitude = Position[1].toDouble(); |
tmp_WayPoint.Altitude = Position[2].toDouble(); |
tmp_WayPoint.Time = sb_Time->value(); |
|
tmp_WayPoints.append(tmp_WayPoint); |
} |
else |
{ |
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); |
|
pb_Add->setEnabled(false); |
|
z = s_Points.count(); |
} |
} |
return tmp_WayPoints; |
} |
|
QList<sWayPoint> dlg_Map::parse_WayPointMKW(QString s_File) |
{ |
QList<sWayPoint> tmp_WayPoints; |
sWayPoint tmp_WayPoint; |
|
QFile f_MKW(s_File); |
f_MKW.open(QIODevice::ReadOnly | QIODevice::Text); |
|
QString s_MKW; |
|
while (!f_MKW.atEnd()) |
{ |
s_MKW.append(f_MKW.readLine()); |
} |
|
f_MKW.close(); |
|
QStringList s_Points = s_MKW.split(" "); |
|
QStringList Position; |
|
for (int z = 0; z < s_Points.count() - 1; z++) |
{ |
if (z != 20) |
{ |
Position = s_Points[z].split(","); |
tmp_WayPoint.Longitude = Position[0].toDouble(); |
tmp_WayPoint.Latitude = Position[1].toDouble(); |
tmp_WayPoint.Altitude = Position[2].toDouble(); |
tmp_WayPoint.Time = Position[3].toInt(); |
|
tmp_WayPoints.append(tmp_WayPoint); |
} |
else |
{ |
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); |
|
pb_Add->setEnabled(false); |
|
z = s_Points.count(); |
} |
} |
return tmp_WayPoints; |
} |
|
void dlg_Map::show_WayPoints(QList<sWayPoint> WayPoints) |
{ |
Point* p_Point; |
|
o_Route->removeGeometry(l_RouteWP); |
p_RouteWP.clear(); |
l_WayPoints.clear(); |
|
l_WayPoints = WayPoints; |
|
for (int z = 0; z < WayPoints.count(); z++) |
{ |
p_Point = new Point(WayPoints[z].Longitude, WayPoints[z].Latitude); |
|
p_RouteWP.append(p_Point); |
} |
|
l_RouteWP = new LineString(p_RouteWP, "", Pen[0]); |
o_Route->addGeometry(l_RouteWP); |
|
o_Map->setView(p_Point); |
|
o_Map->updateRequestNew(); |
} |
|
void dlg_Map::save_WayPointsMKW(QString s_File) |
{ |
QFile *f_MKW = new QFile(s_File); |
|
f_MKW->open(QIODevice::ReadWrite | QIODevice::Text); |
|
QTextStream out(f_MKW); |
|
out.setRealNumberPrecision(9); |
|
for (int z = 0; z < l_WayPoints.count(); z++) |
{ |
out << l_WayPoints[z].Longitude << "," << l_WayPoints[z].Latitude << "," << l_WayPoints[z].Altitude << "," << l_WayPoints[z].Time << " \n"; |
} |
|
f_MKW->close(); |
} |
|
void dlg_Map::slot_LoadWayPoints() |
{ |
QString Filename = QFileDialog::getOpenFileName(this, "WayPoint-Route laden", o_Settings->DIR.Logging, "Mikrokopter WayPoints(*.mkw);;KML-Datei(*.kml);;Alle Dateien (*)"); |
|
if (!Filename.isEmpty()) |
{ |
if (Filename.endsWith(".kml", Qt::CaseInsensitive)) |
{ |
cb_ShowWPs->setChecked(true); |
pb_SendWaypoints->setEnabled(true); |
|
show_WayPoints(parse_WayPointKML(Filename)); |
} |
if (Filename.endsWith(".mkw", Qt::CaseInsensitive)) |
{ |
cb_ShowWPs->setChecked(true); |
pb_SendWaypoints->setEnabled(true); |
|
show_WayPoints(parse_WayPointMKW(Filename)); |
} |
} |
} |
|
void dlg_Map::slot_SaveWayPoints() |
{ |
QString Filename = QFileDialog::getSaveFileName(this, "WayPoint-Route speichern", o_Settings->DIR.Logging, "Mikrokopter WayPoints(*.mkw);;Alle Dateien (*)"); |
|
if (!Filename.isEmpty()) |
{ |
if (!(Filename.endsWith(".mkw", Qt::CaseInsensitive))) |
{ |
Filename = Filename + QString(".mkw"); |
} |
|
save_WayPointsMKW(Filename); |
} |
} |
|
void dlg_Map::slot_ShowWayPoints(bool Show) |
{ |
if (Show == true) |
{ |
qDebug("An"); |
o_Route->addGeometry(l_RouteWP); |
o_Map->updateRequestNew(); |
} |
else |
{ |
qDebug("Aus"); |
o_Route->removeGeometry(l_RouteWP); |
o_Map->updateRequestNew(); |
} |
} |
|
// Position zum Flug-Track hinzufügen |
void dlg_Map::add_Position(double x, double y) |
{ |
120,6 → 329,8 |
// Waypoint zur Liste hinzufügen |
void dlg_Map::slot_AddWayPoint() |
{ |
cb_ShowWPs->setChecked(true); |
|
sWayPoint WayPoint; |
|
WayPoint.Longitude = LastClick->longitude(); |
137,6 → 348,13 |
o_Map->updateRequestNew(); |
|
pb_SendWaypoints->setEnabled(true); |
|
if (l_WayPoints.count() == 20) |
{ |
QMessageBox::warning(this, QA_NAME,trUtf8("Wegpunkt-Liste ist voll. Es können maximal 20 Wegpunkte benutzt werden."), QMessageBox::Ok); |
pb_Add->setEnabled(false); |
} |
|
} |
|
// Waypoint-Liste löschen |
146,6 → 364,8 |
p_RouteWP.clear(); |
l_WayPoints.clear(); |
o_Map->updateRequestNew(); |
|
pb_Add->setEnabled(pb_Goto->isEnabled()); |
} |
|
void dlg_Map::slot_SendWayPoints() |
184,13 → 404,15 |
{ |
if (o_Map->currentCoordinate() == MapCenter) |
{ |
pb_Add->setEnabled(true); |
if (l_WayPoints.count() < 20) |
{ |
pb_Add->setEnabled(true); |
} |
pb_Goto->setEnabled(true); |
|
o_Click->removeGeometry(ClickPoint); |
|
ClickPoint = new CirclePoint(Coord.x(), Coord.y(), 6, "P1", Point::Middle, Pen[1]); |
// LastPoint = P; |
|
LastClick = new Point(Coord.x(), Coord.y()); |
|