QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
TransformPositionController.cc
Go to the documentation of this file.
2
3#include "Fact.h"
4#include "FactMetaData.h"
6#include "QGCGeo.h"
8#include "SettingsManager.h"
9#include "UnitsSettings.h"
10#include "Vehicle.h"
11
12QGC_LOGGING_CATEGORY(TransformPositionControllerLog, "QMLControls.TransformPositionController")
13
14QMap<QString, FactMetaData*> TransformPositionController::_metaDataMap;
15
17 : QObject(parent)
18 , _latitudeFact(new Fact(0, _latitudeFactName, FactMetaData::valueTypeDouble, this))
19 , _longitudeFact(new Fact(0, _longitudeFactName, FactMetaData::valueTypeDouble, this))
20 , _latitudeDMSFact(new Fact(0, _latitudeDMSFactName, FactMetaData::valueTypeString, this))
21 , _longitudeDMSFact(new Fact(0, _longitudeDMSFactName, FactMetaData::valueTypeString, this))
22 , _zoneFact(new Fact(0, _zoneFactName, FactMetaData::valueTypeUint8, this))
23 , _hemisphereFact(new Fact(0, _hemisphereFactName, FactMetaData::valueTypeUint8, this))
24 , _eastingFact(new Fact(0, _eastingFactName, FactMetaData::valueTypeDouble, this))
25 , _northingFact(new Fact(0, _northingFactName, FactMetaData::valueTypeDouble, this))
26 , _mgrsFact(new Fact(0, _mgrsFactName, FactMetaData::valueTypeString, this))
27 , _offsetEastFact(new Fact(0, _offsetEastFactName, FactMetaData::valueTypeDouble, this))
28 , _offsetNorthFact(new Fact(0, _offsetNorthFactName, FactMetaData::valueTypeDouble, this))
29 , _offsetUpFact(new Fact(0, _offsetUpFactName, FactMetaData::valueTypeDouble, this))
30 , _rotateDegreesCWFact(new Fact(0, _rotateDegreesCWFactName, FactMetaData::valueTypeDouble, this))
31{
32 // qCDebug(TransformPositionControllerLog) << Q_FUNC_INFO << this;
33
34 if (_metaDataMap.isEmpty()) {
35 _metaDataMap = FactMetaData::createMapFromJsonFile(QStringLiteral(":/json/TransformPositionController.FactMetaData.json"), nullptr /* QObject parent */);
36 }
37
38 _latitudeFact->setMetaData(_metaDataMap[_latitudeFactName]);
39 _longitudeFact->setMetaData(_metaDataMap[_longitudeFactName]);
40 _latitudeDMSFact->setMetaData(_metaDataMap[_latitudeDMSFactName]);
41 _longitudeDMSFact->setMetaData(_metaDataMap[_longitudeDMSFactName]);
42 _zoneFact->setMetaData(_metaDataMap[_zoneFactName]);
43 _hemisphereFact->setMetaData(_metaDataMap[_hemisphereFactName]);
44 _eastingFact->setMetaData(_metaDataMap[_eastingFactName]);
45 _northingFact->setMetaData(_metaDataMap[_northingFactName]);
46 _mgrsFact->setMetaData(_metaDataMap[_mgrsFactName]);
47 _offsetEastFact->setMetaData(_metaDataMap[_offsetEastFactName]);
48 _offsetNorthFact->setMetaData(_metaDataMap[_offsetNorthFactName]);
49 _offsetUpFact->setMetaData(_metaDataMap[_offsetUpFactName]);
50 _rotateDegreesCWFact->setMetaData(_metaDataMap[_rotateDegreesCWFactName]);
51}
52
54{
55 // qCDebug(TransformPositionControllerLog) << Q_FUNC_INFO << this;
56}
57
59{
60 if (!coordinate.isValid()) {
61 qCWarning(TransformPositionControllerLog) << "Attempt to set invalid coordinate";
62 return;
63 }
64
65 if (coordinate == _coordinate) {
66 return;
67 }
68
69 const bool wasInvalid = !_coordinate.isValid();
70 _coordinate = coordinate;
71
72 // Do not emit on the initial invalid->valid transition to prevent
73 // onCoordinateChanged handlers from firing on initial dialog setup.
74 if (!wasInvalid) {
75 emit coordinateChanged(_coordinate);
76 }
77}
78
80{
81 if (!_coordinate.isValid()) {
82 return;
83 }
84
85 _latitudeFact->setRawValue(_coordinate.latitude());
86 _longitudeFact->setRawValue(_coordinate.longitude());
87 _latitudeDMSFact->setRawValue(QGCGeo::convertDegreesToDMS(_coordinate.latitude(), true));
88 _longitudeDMSFact->setRawValue(QGCGeo::convertDegreesToDMS(_coordinate.longitude(), false));
89
90 double easting, northing;
91 const int zone = QGCGeo::convertGeoToUTM(_coordinate, easting, northing);
92 if ((zone >= 1) && (zone <= 60)) {
93 _zoneFact->setRawValue(zone);
94 _hemisphereFact->setRawValue(_coordinate.latitude() < 0);
95 _eastingFact->setRawValue(easting);
96 _northingFact->setRawValue(northing);
97 }
98
99 const QString mgrs = QGCGeo::convertGeoToMGRS(_coordinate);
100 if (!mgrs.isEmpty()) {
101 _mgrsFact->setRawValue(mgrs);
102 }
103}
104
106{
107 QGeoCoordinate newCoordinate = _coordinate;
108 newCoordinate.setLatitude(_latitudeFact->rawValue().toDouble());
109 newCoordinate.setLongitude(_longitudeFact->rawValue().toDouble());
110 setCoordinate(newCoordinate);
111}
112
114{
115 QGeoCoordinate newCoordinate = _coordinate;
116 if (QGCGeo::convertDMSToGeo(_latitudeDMSFact->rawValue().toString(), _longitudeDMSFact->rawValue().toString(), newCoordinate)) {
117 setCoordinate(newCoordinate);
118 return true;
119 }
120
121 initValues();
122 return false;
123}
124
126{
127 qCDebug(TransformPositionControllerLog) << _eastingFact->rawValue().toDouble() << _northingFact->rawValue().toDouble() << _zoneFact->rawValue().toInt() << (_hemisphereFact->rawValue().toInt() == 1);
128 QGeoCoordinate newCoordinate;
129 if (QGCGeo::convertUTMToGeo(_eastingFact->rawValue().toDouble(), _northingFact->rawValue().toDouble(), _zoneFact->rawValue().toInt(), _hemisphereFact->rawValue().toInt() == 1, newCoordinate)) {
130 qCDebug(TransformPositionControllerLog) << _eastingFact->rawValue().toDouble() << _northingFact->rawValue().toDouble() << _zoneFact->rawValue().toInt() << (_hemisphereFact->rawValue().toInt() == 1) << newCoordinate;
131 setCoordinate(newCoordinate);
132 return true;
133 }
134
135 initValues();
136 return false;
137}
138
140{
141 QGeoCoordinate newCoordinate;
142 if (QGCGeo::convertMGRSToGeo(_mgrsFact->rawValue().toString(), newCoordinate)) {
143 setCoordinate(newCoordinate);
144 return true;
145 }
146
147 initValues();
148 return false;
149}
150
152{
154 if (!activeVehicle) {
155 qCWarning(TransformPositionControllerLog) << "Cannot set coordinate from vehicle: no active vehicle";
156 return;
157 }
158
159 setCoordinate(activeVehicle->coordinate());
160}
161
163{
164 return SettingsManager::instance()->unitsSettings()->coordinateFormat()->rawValue().toInt();
165}
Geographic coordinate conversion utilities using GeographicLib.
#define QGC_LOGGING_CATEGORY(name, categoryStr)
Holds the meta data associated with a Fact.
A Fact is used to hold a single value within the system.
Definition Fact.h:15
static MultiVehicleManager * instance()
Vehicle * activeVehicle() const
UnitsSettings * unitsSettings() const
static SettingsManager * instance()
void coordinateChanged(QGeoCoordinate coordinate)
TransformPositionController(QObject *parent=nullptr)
static int defaultCoordinateSystem()
UnitsSettings::coordinateFormat, which matches the coordinate system combo index in the position dial...
void setCoordinate(QGeoCoordinate coordinate)
QGeoCoordinate coordinate()
Definition Vehicle.h:430
QString convertGeoToMGRS(const QGeoCoordinate &coord)
Definition QGCGeo.cc:181
bool convertDMSToGeo(const QString &latitude, const QString &longitude, QGeoCoordinate &coord)
Definition QGCGeo.cc:318
int convertGeoToUTM(const QGeoCoordinate &coord, double &easting, double &northing)
Definition QGCGeo.cc:150
bool convertUTMToGeo(double easting, double northing, int zone, bool southhemi, QGeoCoordinate &coord)
Definition QGCGeo.cc:163
QString convertDegreesToDMS(double value, bool isLatitude)
Definition QGCGeo.cc:231
bool convertMGRSToGeo(const QString &mgrs, QGeoCoordinate &coord)
Definition QGCGeo.cc:207