13 changed files with 4 additions and 320 deletions
@ -1,186 +0,0 @@ |
|||||||
/****************************************************************************
|
|
||||||
* |
|
||||||
* (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
|
|
||||||
* |
|
||||||
* QGroundControl is licensed according to the terms in the file |
|
||||||
* COPYING.md in the root of the source code directory. |
|
||||||
* |
|
||||||
****************************************************************************/ |
|
||||||
|
|
||||||
|
|
||||||
#include <QList> |
|
||||||
#include <QApplication> |
|
||||||
#include <QTimer> |
|
||||||
#include <QSettings> |
|
||||||
#include <QtQml> |
|
||||||
|
|
||||||
#include "UAS.h" |
|
||||||
#include "UASInterface.h" |
|
||||||
#include "HomePositionManager.h" |
|
||||||
#include "QGC.h" |
|
||||||
#include "QGCApplication.h" |
|
||||||
#include "MultiVehicleManager.h" |
|
||||||
|
|
||||||
#define PI 3.1415926535897932384626433832795 |
|
||||||
#define MEAN_EARTH_DIAMETER 12756274.0 |
|
||||||
#define UMR 0.017453292519943295769236907684886 |
|
||||||
|
|
||||||
const char* HomePositionManager::_settingsGroup = "HomePositionManager"; |
|
||||||
const char* HomePositionManager::_latitudeKey = "Latitude"; |
|
||||||
const char* HomePositionManager::_longitudeKey = "Longitude"; |
|
||||||
const char* HomePositionManager::_altitudeKey = "Altitude"; |
|
||||||
|
|
||||||
HomePositionManager::HomePositionManager(QGCApplication* app) |
|
||||||
: QGCTool(app) |
|
||||||
, homeLat(47.3769) |
|
||||||
, homeLon(8.549444) |
|
||||||
, homeAlt(470.0) |
|
||||||
{ |
|
||||||
qmlRegisterUncreatableType<HomePositionManager> ("QGroundControl", 1, 0, "HomePositionManager", "Reference only"); |
|
||||||
} |
|
||||||
|
|
||||||
void HomePositionManager::setToolbox(QGCToolbox *toolbox) |
|
||||||
{ |
|
||||||
QGCTool::setToolbox(toolbox); |
|
||||||
|
|
||||||
|
|
||||||
_loadSettings(); |
|
||||||
} |
|
||||||
|
|
||||||
void HomePositionManager::_storeSettings(void) |
|
||||||
{ |
|
||||||
QSettings settings; |
|
||||||
|
|
||||||
settings.remove(_settingsGroup); |
|
||||||
settings.beginGroup(_settingsGroup); |
|
||||||
|
|
||||||
for (int i=0; i<_homePositions.count(); i++) { |
|
||||||
HomePosition* homePos = qobject_cast<HomePosition*>(_homePositions[i]); |
|
||||||
|
|
||||||
qDebug() << "Saving" << homePos->name(); |
|
||||||
|
|
||||||
settings.beginGroup(homePos->name()); |
|
||||||
settings.setValue(_latitudeKey, homePos->coordinate().latitude()); |
|
||||||
settings.setValue(_longitudeKey, homePos->coordinate().longitude()); |
|
||||||
settings.setValue(_altitudeKey, homePos->coordinate().altitude()); |
|
||||||
settings.endGroup(); |
|
||||||
} |
|
||||||
|
|
||||||
settings.endGroup(); |
|
||||||
|
|
||||||
// Deprecated settings for old editor
|
|
||||||
settings.beginGroup("QGC_UASMANAGER"); |
|
||||||
settings.setValue("HOMELAT", homeLat); |
|
||||||
settings.setValue("HOMELON", homeLon); |
|
||||||
settings.setValue("HOMEALT", homeAlt); |
|
||||||
settings.endGroup(); |
|
||||||
} |
|
||||||
|
|
||||||
void HomePositionManager::_loadSettings(void) |
|
||||||
{ |
|
||||||
QSettings settings; |
|
||||||
|
|
||||||
_homePositions.clear(); |
|
||||||
|
|
||||||
settings.beginGroup(_settingsGroup); |
|
||||||
|
|
||||||
foreach(const QString &name, settings.childGroups()) { |
|
||||||
QGeoCoordinate coordinate; |
|
||||||
|
|
||||||
qDebug() << "Load setting" << name; |
|
||||||
|
|
||||||
settings.beginGroup(name); |
|
||||||
coordinate.setLatitude(settings.value(_latitudeKey).toDouble()); |
|
||||||
coordinate.setLongitude(settings.value(_longitudeKey).toDouble()); |
|
||||||
coordinate.setAltitude(settings.value(_altitudeKey).toDouble()); |
|
||||||
settings.endGroup(); |
|
||||||
|
|
||||||
_homePositions.append(new HomePosition(name, coordinate, this)); |
|
||||||
} |
|
||||||
|
|
||||||
settings.endGroup(); |
|
||||||
|
|
||||||
if (_homePositions.count() == 0) { |
|
||||||
_homePositions.append(new HomePosition("ETH Campus", QGeoCoordinate(47.3769, 8.549444, 470.0), this)); |
|
||||||
}
|
|
||||||
} |
|
||||||
|
|
||||||
void HomePositionManager::updateHomePosition(const QString& name, const QGeoCoordinate& coordinate) |
|
||||||
{ |
|
||||||
HomePosition * homePos = NULL; |
|
||||||
|
|
||||||
for (int i=0; i<_homePositions.count(); i++) { |
|
||||||
homePos = qobject_cast<HomePosition*>(_homePositions[i]); |
|
||||||
if (homePos->name() == name) { |
|
||||||
break; |
|
||||||
} |
|
||||||
homePos = NULL; |
|
||||||
} |
|
||||||
|
|
||||||
if (homePos == NULL) { |
|
||||||
HomePosition* homePos = new HomePosition(name, coordinate, this); |
|
||||||
_homePositions.append(homePos); |
|
||||||
} else { |
|
||||||
homePos->setName(name); |
|
||||||
homePos->setCoordinate(coordinate); |
|
||||||
} |
|
||||||
|
|
||||||
_storeSettings(); |
|
||||||
} |
|
||||||
|
|
||||||
void HomePositionManager::deleteHomePosition(const QString& name) |
|
||||||
{ |
|
||||||
// Don't allow delete of last position
|
|
||||||
if (_homePositions.count() == 1) { |
|
||||||
return; |
|
||||||
} |
|
||||||
|
|
||||||
qDebug() << "Attempting delete" << name; |
|
||||||
|
|
||||||
for (int i=0; i<_homePositions.count(); i++) { |
|
||||||
if (qobject_cast<HomePosition*>(_homePositions[i])->name() == name) { |
|
||||||
qDebug() << "Deleting" << name; |
|
||||||
_homePositions.removeAt(i); |
|
||||||
break; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
_storeSettings(); |
|
||||||
} |
|
||||||
|
|
||||||
HomePosition::HomePosition(const QString& name, const QGeoCoordinate& coordinate, HomePositionManager* homePositionManager, QObject* parent) |
|
||||||
: QObject(parent) |
|
||||||
, _coordinate(coordinate) |
|
||||||
, _homePositionManager(homePositionManager) |
|
||||||
{ |
|
||||||
setObjectName(name); |
|
||||||
} |
|
||||||
|
|
||||||
HomePosition::~HomePosition() |
|
||||||
{ |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
QString HomePosition::name(void) |
|
||||||
{ |
|
||||||
return objectName(); |
|
||||||
} |
|
||||||
|
|
||||||
void HomePosition::setName(const QString& name) |
|
||||||
{ |
|
||||||
setObjectName(name); |
|
||||||
_homePositionManager->_storeSettings(); |
|
||||||
emit nameChanged(name); |
|
||||||
} |
|
||||||
|
|
||||||
QGeoCoordinate HomePosition::coordinate(void) |
|
||||||
{ |
|
||||||
return _coordinate; |
|
||||||
} |
|
||||||
|
|
||||||
void HomePosition::setCoordinate(const QGeoCoordinate& coordinate) |
|
||||||
{ |
|
||||||
_coordinate = coordinate; |
|
||||||
_homePositionManager->_storeSettings(); |
|
||||||
emit coordinateChanged(coordinate); |
|
||||||
} |
|
@ -1,108 +0,0 @@ |
|||||||
/****************************************************************************
|
|
||||||
* |
|
||||||
* (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
|
|
||||||
* |
|
||||||
* QGroundControl is licensed according to the terms in the file |
|
||||||
* COPYING.md in the root of the source code directory. |
|
||||||
* |
|
||||||
****************************************************************************/ |
|
||||||
|
|
||||||
|
|
||||||
#ifndef HomePositionManager_H |
|
||||||
#define HomePositionManager_H |
|
||||||
|
|
||||||
#include "QmlObjectListModel.h" |
|
||||||
#include "QGCToolbox.h" |
|
||||||
|
|
||||||
#include <QGeoCoordinate> |
|
||||||
|
|
||||||
class HomePositionManager; |
|
||||||
|
|
||||||
class HomePosition : public QObject |
|
||||||
{ |
|
||||||
Q_OBJECT |
|
||||||
|
|
||||||
public: |
|
||||||
HomePosition(const QString& name, const QGeoCoordinate& coordinate, HomePositionManager* homePositionManager, QObject* parent = NULL); |
|
||||||
~HomePosition(); |
|
||||||
|
|
||||||
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) |
|
||||||
Q_PROPERTY(QGeoCoordinate coordinate READ coordinate WRITE setCoordinate NOTIFY coordinateChanged) |
|
||||||
|
|
||||||
// Property accessors
|
|
||||||
|
|
||||||
QString name(void); |
|
||||||
void setName(const QString& name); |
|
||||||
|
|
||||||
QGeoCoordinate coordinate(void); |
|
||||||
void setCoordinate(const QGeoCoordinate& coordinate); |
|
||||||
|
|
||||||
signals: |
|
||||||
void nameChanged(const QString& name); |
|
||||||
void coordinateChanged(const QGeoCoordinate& coordinate); |
|
||||||
|
|
||||||
private: |
|
||||||
QGeoCoordinate _coordinate; |
|
||||||
HomePositionManager* _homePositionManager; |
|
||||||
}; |
|
||||||
|
|
||||||
class HomePositionManager : public QGCTool |
|
||||||
{ |
|
||||||
Q_OBJECT |
|
||||||
|
|
||||||
public: |
|
||||||
HomePositionManager(QGCApplication* app); |
|
||||||
|
|
||||||
Q_PROPERTY(QmlObjectListModel* homePositions READ homePositions CONSTANT) |
|
||||||
|
|
||||||
/// If name is not already a home position a new one will be added, otherwise the existing
|
|
||||||
/// home position will be updated
|
|
||||||
Q_INVOKABLE void updateHomePosition(const QString& name, const QGeoCoordinate& coordinate); |
|
||||||
|
|
||||||
Q_INVOKABLE void deleteHomePosition(const QString& name); |
|
||||||
|
|
||||||
// Property accesors
|
|
||||||
|
|
||||||
QmlObjectListModel* homePositions(void) { return &_homePositions; } |
|
||||||
|
|
||||||
// Should only be called by HomePosition
|
|
||||||
void _storeSettings(void); |
|
||||||
|
|
||||||
// Override from QGCTool
|
|
||||||
virtual void setToolbox(QGCToolbox *toolbox); |
|
||||||
|
|
||||||
private: |
|
||||||
void _loadSettings(void); |
|
||||||
|
|
||||||
QmlObjectListModel _homePositions; |
|
||||||
|
|
||||||
static const char* _settingsGroup; |
|
||||||
static const char* _latitudeKey; |
|
||||||
static const char* _longitudeKey; |
|
||||||
static const char* _altitudeKey; |
|
||||||
|
|
||||||
// Everything below is deprecated and will be removed once old Map code is removed
|
|
||||||
public: |
|
||||||
|
|
||||||
// Deprecated methods
|
|
||||||
|
|
||||||
/** @brief Get home position latitude */ |
|
||||||
double getHomeLatitude() const { |
|
||||||
return homeLat; |
|
||||||
} |
|
||||||
/** @brief Get home position longitude */ |
|
||||||
double getHomeLongitude() const { |
|
||||||
return homeLon; |
|
||||||
} |
|
||||||
/** @brief Get home position altitude */ |
|
||||||
double getHomeAltitude() const { |
|
||||||
return homeAlt; |
|
||||||
} |
|
||||||
|
|
||||||
protected: |
|
||||||
double homeLat; |
|
||||||
double homeLon; |
|
||||||
double homeAlt; |
|
||||||
}; |
|
||||||
|
|
||||||
#endif |
|
Loading…
Reference in new issue