16 , _latitudeFact(new
Fact(0, _latitudeFactName,
FactMetaData::valueTypeDouble, this))
17 , _longitudeFact(new
Fact(0, _longitudeFactName,
FactMetaData::valueTypeDouble, this))
19 , _hemisphereFact(new
Fact(0, _hemisphereFactName,
FactMetaData::valueTypeUint8, this))
20 , _eastingFact(new
Fact(0, _eastingFactName,
FactMetaData::valueTypeDouble, this))
21 , _northingFact(new
Fact(0, _northingFactName,
FactMetaData::valueTypeDouble, this))
23 , _offsetEastFact(new
Fact(0, _offsetEastFactName,
FactMetaData::valueTypeDouble, this))
24 , _offsetNorthFact(new
Fact(0, _offsetNorthFactName,
FactMetaData::valueTypeDouble, this))
25 , _offsetUpFact(new
Fact(0, _offsetUpFactName,
FactMetaData::valueTypeDouble, this))
26 , _rotateDegreesCWFact(new
Fact(0, _rotateDegreesCWFactName,
FactMetaData::valueTypeDouble, this))
30 if (_metaDataMap.isEmpty()) {
34 _latitudeFact->setMetaData(_metaDataMap[_latitudeFactName]);
35 _longitudeFact->setMetaData(_metaDataMap[_longitudeFactName]);
36 _zoneFact->setMetaData(_metaDataMap[_zoneFactName]);
37 _hemisphereFact->setMetaData(_metaDataMap[_hemisphereFactName]);
38 _eastingFact->setMetaData(_metaDataMap[_eastingFactName]);
39 _northingFact->setMetaData(_metaDataMap[_northingFactName]);
40 _mgrsFact->setMetaData(_metaDataMap[_mgrsFactName]);
41 _offsetEastFact->setMetaData(_metaDataMap[_offsetEastFactName]);
42 _offsetNorthFact->setMetaData(_metaDataMap[_offsetNorthFactName]);
43 _offsetUpFact->setMetaData(_metaDataMap[_offsetUpFactName]);
44 _rotateDegreesCWFact->setMetaData(_metaDataMap[_rotateDegreesCWFactName]);
47TransformPositionController::~TransformPositionController()
52void TransformPositionController::setCoordinate(QGeoCoordinate coordinate)
54 if (!coordinate.isValid()) {
55 qCWarning(TransformPositionControllerLog) <<
"Attempt to set invalid coordinate";
59 if (coordinate == _coordinate) {
63 const bool wasInvalid = !_coordinate.isValid();
64 _coordinate = coordinate;
73void TransformPositionController::initValues()
75 if (!_coordinate.isValid()) {
79 _latitudeFact->setRawValue(_coordinate.latitude());
80 _longitudeFact->setRawValue(_coordinate.longitude());
82 double easting, northing;
84 if ((zone >= 1) && (zone <= 60)) {
85 _zoneFact->setRawValue(zone);
86 _hemisphereFact->setRawValue(_coordinate.latitude() < 0);
87 _eastingFact->setRawValue(easting);
88 _northingFact->setRawValue(northing);
92 if (!mgrs.isEmpty()) {
93 _mgrsFact->setRawValue(mgrs);
97void TransformPositionController::setFromGeo()
99 QGeoCoordinate newCoordinate = _coordinate;
100 newCoordinate.setLatitude(_latitudeFact->rawValue().toDouble());
101 newCoordinate.setLongitude(_longitudeFact->rawValue().toDouble());
102 setCoordinate(newCoordinate);
105void TransformPositionController::setFromUTM()
107 qCDebug(TransformPositionControllerLog) << _eastingFact->rawValue().toDouble() << _northingFact->rawValue().toDouble() << _zoneFact->rawValue().toInt() << (_hemisphereFact->rawValue().toInt() == 1);
108 QGeoCoordinate newCoordinate;
109 if (
QGCGeo::convertUTMToGeo(_eastingFact->rawValue().toDouble(), _northingFact->rawValue().toDouble(), _zoneFact->rawValue().toInt(), _hemisphereFact->rawValue().toInt() == 1, newCoordinate)) {
110 qCDebug(TransformPositionControllerLog) << _eastingFact->rawValue().toDouble() << _northingFact->rawValue().toDouble() << _zoneFact->rawValue().toInt() << (_hemisphereFact->rawValue().toInt() == 1) << newCoordinate;
111 setCoordinate(newCoordinate);
117void TransformPositionController::setFromMGRS()
119 QGeoCoordinate newCoordinate;
121 setCoordinate(newCoordinate);
127void TransformPositionController::setFromVehicle()
129 Vehicle* activeVehicle = MultiVehicleManager::instance()->activeVehicle();
130 if (!activeVehicle) {
131 qCWarning(TransformPositionControllerLog) <<
"Cannot set coordinate from vehicle: no active vehicle";
Geographic coordinate conversion utilities using GeographicLib.
#define QGC_LOGGING_CATEGORY(name, categoryStr)
A Fact is used to hold a single value within the system.
QGeoCoordinate coordinate()
QString convertGeoToMGRS(const QGeoCoordinate &coord)
int convertGeoToUTM(const QGeoCoordinate &coord, double &easting, double &northing)
bool convertUTMToGeo(double easting, double northing, int zone, bool southhemi, QGeoCoordinate &coord)
bool convertMGRSToGeo(const QString &mgrs, QGeoCoordinate &coord)