From 74eead41f138b19e76181c32766ce4e1f54c69d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Jos=C3=A9=20Pereira?= Date: Tue, 25 Jul 2017 16:17:17 -0300 Subject: [PATCH] Add KML header and source MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Patrick José Pereira --- qgroundcontrol.pro | 2 + src/MissionManager/KML.cc | 128 ++++++++++++++++++++++++++++++ src/MissionManager/KML.h | 42 ++++++++++ src/MissionManager/PlanMasterController.h | 2 + 4 files changed, 174 insertions(+) create mode 100644 src/MissionManager/KML.cc create mode 100644 src/MissionManager/KML.h diff --git a/qgroundcontrol.pro b/qgroundcontrol.pro index 170838f..47e517c 100644 --- a/qgroundcontrol.pro +++ b/qgroundcontrol.pro @@ -501,6 +501,7 @@ HEADERS += \ src/MissionManager/FixedWingLandingComplexItem.h \ src/MissionManager/GeoFenceController.h \ src/MissionManager/GeoFenceManager.h \ + src/MissionManager/KML.h \ src/MissionManager/MissionCommandList.h \ src/MissionManager/MissionCommandTree.h \ src/MissionManager/MissionCommandUIInfo.h \ @@ -685,6 +686,7 @@ SOURCES += \ src/MissionManager/FixedWingLandingComplexItem.cc \ src/MissionManager/GeoFenceController.cc \ src/MissionManager/GeoFenceManager.cc \ + src/MissionManager/KML.cc \ src/MissionManager/MissionCommandList.cc \ src/MissionManager/MissionCommandTree.cc \ src/MissionManager/MissionCommandUIInfo.cc \ diff --git a/src/MissionManager/KML.cc b/src/MissionManager/KML.cc new file mode 100644 index 0000000..164cce9 --- /dev/null +++ b/src/MissionManager/KML.cc @@ -0,0 +1,128 @@ +/**************************************************************************** + * + * (c) 2009-2016 QGROUNDCONTROL PROJECT + * + * QGroundControl is licensed according to the terms in the file + * COPYING.md in the root of the source code directory. + * + ****************************************************************************/ + +#include "KML.h" + +#include +#include + +const QString Kml::_version("version=\"1.0\""); +const QString Kml::_encoding("encoding=\"UTF-8\""); +const QString Kml::_opengis("http://www.opengis.net/kml/2.2"); +const QString Kml::_qgckml("QGC KML"); + +Kml::Kml() +{ + //create header + createHeader(); + //name + createTextElement(_docEle, "name", _qgckml); + //open + createTextElement(_docEle, "open", "1"); + //create style + createStyles(); +} + +void Kml::points(const QStringList& points) +{ + //create placemark + QDomElement placemark = _domDocument.createElement("Placemark"); + _docEle.appendChild(placemark); + createTextElement(placemark, "styleUrl", "yellowLineGreenPoly"); + createTextElement(placemark, "name", "Absolute"); + createTextElement(placemark, "visibility", "0"); + createTextElement(placemark, "description", "Transparent purple line"); + + QStringList latLonAlt = points[0].split(","); + QStringList lookAtList({latLonAlt[0], latLonAlt[1], "0" \ + , "-100", "45", "2500"}); + createLookAt(placemark, lookAtList); + + //Add linestring + QDomElement lineString = _domDocument.createElement("LineString"); + placemark.appendChild(lineString); + + //extruder + createTextElement(lineString, "extruder", "1"); + createTextElement(lineString, "tessellate", "1"); + createTextElement(lineString, "altitudeMode", "absolute"); + QString coordinates; + for(const auto& point : points) { + coordinates += point + "\n"; + } + createTextElement(lineString, "coordinates", coordinates); +} + +void Kml::save(QDomDocument& document) +{ + document = _domDocument; +} + +void Kml::createHeader() +{ + QDomProcessingInstruction header = _domDocument.createProcessingInstruction("xml", _version + " " + _encoding); + _domDocument.appendChild(header); + QDomElement kml = _domDocument.createElement("kml"); + kml.setAttribute("xmlns", _opengis); + _docEle = _domDocument.createElement("Document"); + kml.appendChild(_docEle); + _domDocument.appendChild(kml); +} + +void Kml::createStyles() +{ + QDomElement style = _domDocument.createElement("Style"); + style.setAttribute("id", "yellowLineGreenPoly"); + createStyleLine(style, "7f00ffff", "4", "7f00ff00"); + _docEle.appendChild(style); +} + +void Kml::createLookAt(QDomElement& placemark, const QStringList &lookAtList) +{ + QDomElement lookAt = _domDocument.createElement("LookAt"); + placemark.appendChild(lookAt); + createTextElement(lookAt, "longitude", lookAtList[0]); + createTextElement(lookAt, "latitude", lookAtList[1]); + createTextElement(lookAt, "altitude", lookAtList[2]); + createTextElement(lookAt, "heading", lookAtList[3]); + createTextElement(lookAt, "tilt", lookAtList[4]); + createTextElement(lookAt, "range", lookAtList[5]); +} + +void Kml::createTextElement(QDomElement& domEle, const QString& elementName, const QString& textElement) +{ + // textElement + auto element = _domDocument.createElement(elementName); + element.appendChild(_domDocument.createTextNode(textElement)); + domEle.appendChild(element); +} + +void Kml::createStyleLine(QDomElement& domEle, const QString& lineColor, const QString& lineWidth, const QString& polyColor) +{ + /* + + 7f00ffff + 4 + + + 7f00ff00 + + */ + auto lineStyle = _domDocument.createElement("LineStyle"); + auto polyStyle = _domDocument.createElement("PolyStyle"); + domEle.appendChild(lineStyle); + domEle.appendChild(polyStyle); + createTextElement(lineStyle, "color", lineColor); + createTextElement(lineStyle, "width", lineWidth); + createTextElement(polyStyle, "color", polyColor); +} + +Kml::~Kml() +{ +} diff --git a/src/MissionManager/KML.h b/src/MissionManager/KML.h new file mode 100644 index 0000000..15d6245 --- /dev/null +++ b/src/MissionManager/KML.h @@ -0,0 +1,42 @@ +/**************************************************************************** + * + * (c) 2009-2016 QGROUNDCONTROL PROJECT + * + * QGroundControl is licensed according to the terms in the file + * COPYING.md in the root of the source code directory. + * + ****************************************************************************/ + +#ifndef KML_H +#define KML_H + +#include +#include + +class Kml +{ + +public: + Kml(); + ~Kml(); + + void points(const QStringList& points); + void polygon(const QStringList& points); + void save(QDomDocument& document); + +private: + void createHeader(); + void createLookAt(QDomElement& placemark, const QStringList &lookAtList); + void createStyles(); + void createStyleLine(QDomElement& domEle, const QString& lineColor, const QString& lineWidth, const QString& polyColor); + void createTextElement(QDomElement& domEle, const QString& elementName, const QString& textElement); + + QDomDocument _domDocument; + QDomElement _docEle; + static const QString _encoding; + static const QString _opengis; + static const QString _qgckml; + static const QString _version; +}; + +#endif diff --git a/src/MissionManager/PlanMasterController.h b/src/MissionManager/PlanMasterController.h index 82c6e3d..6e388a4 100644 --- a/src/MissionManager/PlanMasterController.h +++ b/src/MissionManager/PlanMasterController.h @@ -39,6 +39,8 @@ public: Q_PROPERTY(bool syncInProgress READ syncInProgress NOTIFY syncInProgressChanged) ///< true: Information is currently being saved/sent, false: no active save/send in progress Q_PROPERTY(bool dirty READ dirty WRITE setDirty NOTIFY dirtyChanged) ///< true: Unsaved/sent changes are present, false: no changes since last save/send Q_PROPERTY(QString fileExtension READ fileExtension CONSTANT) ///< File extension for missions + Q_PROPERTY(QString kmlFileExtension READ kmlFileExtension CONSTANT) + ///< kml file extension for missions Q_PROPERTY(QStringList loadNameFilters READ loadNameFilters CONSTANT) ///< File filter list loading plan files Q_PROPERTY(QStringList saveNameFilters READ saveNameFilters CONSTANT) ///< File filter list saving plan files