Commit 1be5d2bd authored by Matej Frančeškin's avatar Matej Frančeškin

Show and parse MGRS strings in Edit Position Dialog

parent 36748f71
......@@ -40,5 +40,10 @@
"type": "uint8",
"enumStrings": "North,South",
"enumValues": "0,1"
},
{
"name": "MGRS",
"shortDescription": "MGRS coordinate",
"type": "string"
}
]
......@@ -47,80 +47,108 @@ QGCViewDialog {
rowSpacing: _margin
columns: 2
QGCLabel { text: qsTr("Latitude") }
QGCLabel {
text: qsTr("Latitude")
}
FactTextField {
fact: controller.latitude
Layout.fillWidth: true
}
QGCLabel { text: qsTr("Longitude") }
QGCLabel {
text: qsTr("Longitude")
}
FactTextField {
fact: controller.longitude
Layout.fillWidth: true
}
}
QGCButton {
anchors.right: parent.right
text: qsTr("Set Geographic")
onClicked: {
controller.setFromGeo()
reject()
QGCButton {
text: qsTr("Set Geographic")
Layout.alignment: Qt.AlignRight
Layout.columnSpan: 2
onClicked: {
controller.setFromGeo()
reject()
}
}
}
GridLayout {
anchors.left: parent.left
anchors.right: parent.right
columnSpacing: _margin
rowSpacing: _margin
columns: 2
Item { width: 1; height: ScreenTools.defaultFontPixelHeight; Layout.columnSpan: 2}
QGCLabel { text: qsTr("Zone") }
QGCLabel {
text: qsTr("Zone")
}
FactTextField {
fact: controller.zone
Layout.fillWidth: true
}
QGCLabel { text: qsTr("Hemisphere") }
QGCLabel {
text: qsTr("Hemisphere")
}
FactComboBox {
fact: controller.hemisphere
indexModel: false
Layout.fillWidth: true
}
QGCLabel { text: qsTr("Easting") }
QGCLabel {
text: qsTr("Easting")
}
FactTextField {
fact: controller.easting
Layout.fillWidth: true
}
QGCLabel { text: qsTr("Northing") }
QGCLabel {
text: qsTr("Northing")
}
FactTextField {
fact: controller.northing
Layout.fillWidth: true
}
}
QGCButton {
anchors.right: parent.right
text: qsTr("Set UTM")
QGCButton {
text: qsTr("Set UTM")
Layout.alignment: Qt.AlignRight
Layout.columnSpan: 2
onClicked: {
controller.setFromUTM()
reject()
}
}
onClicked: {
controller.setFromUTM()
reject()
Item { width: 1; height: ScreenTools.defaultFontPixelHeight; Layout.columnSpan: 2}
QGCLabel {
text: qsTr("MGRS")
}
FactTextField {
fact: controller.mgrs
Layout.fillWidth: true
}
}
QGCButton {
anchors.right: parent.right
text: qsTr("Set From Vehicle Position")
visible: QGroundControl.multiVehicleManager.activeVehicle && QGroundControl.multiVehicleManager.activeVehicle.coordinate.isValid
QGCButton {
text: qsTr("Set MGRS")
Layout.alignment: Qt.AlignRight
Layout.columnSpan: 2
onClicked: {
controller.setFromMGRS()
reject()
}
}
onClicked: {
controller.setFromVehicle()
reject()
Item { width: 1; height: ScreenTools.defaultFontPixelHeight; Layout.columnSpan: 2}
QGCButton {
text: qsTr("Set From Vehicle Position")
visible: QGroundControl.multiVehicleManager.activeVehicle && QGroundControl.multiVehicleManager.activeVehicle.coordinate.isValid
Layout.alignment: Qt.AlignRight
Layout.columnSpan: 2
onClicked: {
controller.setFromVehicle()
reject()
}
}
}
} // Column
......
......@@ -17,6 +17,7 @@ const char* EditPositionDialogController::_zoneFactName = "Zone";
const char* EditPositionDialogController::_hemisphereFactName = "Hemisphere";
const char* EditPositionDialogController::_eastingFactName = "Easting";
const char* EditPositionDialogController::_northingFactName = "Northing";
const char* EditPositionDialogController::_mgrsFactName = "MGRS";
QMap<QString, FactMetaData*> EditPositionDialogController::_metaDataMap;
......@@ -27,6 +28,7 @@ EditPositionDialogController::EditPositionDialogController(void)
, _hemisphereFact (0, _hemisphereFactName, FactMetaData::valueTypeUint8)
, _eastingFact (0, _eastingFactName, FactMetaData::valueTypeDouble)
, _northingFact (0, _northingFactName, FactMetaData::valueTypeDouble)
, _mgrsFact (0, _mgrsFactName, FactMetaData::valueTypeString)
{
if (_metaDataMap.isEmpty()) {
_metaDataMap = FactMetaData::createMapFromJsonFile(QStringLiteral(":/json/EditPositionDialog.FactMetaData.json"), nullptr /* QObject parent */);
......@@ -38,6 +40,7 @@ EditPositionDialogController::EditPositionDialogController(void)
_hemisphereFact.setMetaData (_metaDataMap[_hemisphereFactName]);
_eastingFact.setMetaData (_metaDataMap[_eastingFactName]);
_northingFact.setMetaData (_metaDataMap[_northingFactName]);
_mgrsFact.setMetaData (_metaDataMap[_mgrsFactName]);
}
void EditPositionDialogController::setCoordinate(QGeoCoordinate coordinate)
......@@ -55,10 +58,16 @@ void EditPositionDialogController::initValues(void)
double easting, northing;
int zone = convertGeoToUTM(_coordinate, easting, northing);
_zoneFact.setRawValue(zone);
_hemisphereFact.setRawValue(_coordinate.latitude() < 0);
_eastingFact.setRawValue(easting);
_northingFact.setRawValue(northing);
if (zone >= 1 && zone <= 60) {
_zoneFact.setRawValue(zone);
_hemisphereFact.setRawValue(_coordinate.latitude() < 0);
_eastingFact.setRawValue(easting);
_northingFact.setRawValue(northing);
}
QString mgrs = convertGeoToMGRS(_coordinate);
if (!mgrs.isEmpty()) {
_mgrsFact.setRawValue(mgrs);
}
}
void EditPositionDialogController::setFromGeo(void)
......@@ -71,9 +80,21 @@ void EditPositionDialogController::setFromGeo(void)
void EditPositionDialogController::setFromUTM(void)
{
qDebug() << _eastingFact.rawValue().toDouble() << _northingFact.rawValue().toDouble() << _zoneFact.rawValue().toInt() << (_hemisphereFact.rawValue().toInt() == 1);
convertUTMToGeo(_eastingFact.rawValue().toDouble(), _northingFact.rawValue().toDouble(), _zoneFact.rawValue().toInt(), _hemisphereFact.rawValue().toInt() == 1, _coordinate);
qDebug() << _eastingFact.rawValue().toDouble() << _northingFact.rawValue().toDouble() << _zoneFact.rawValue().toInt() << (_hemisphereFact.rawValue().toInt() == 1) << _coordinate;
emit coordinateChanged(_coordinate);
if (convertUTMToGeo(_eastingFact.rawValue().toDouble(), _northingFact.rawValue().toDouble(), _zoneFact.rawValue().toInt(), _hemisphereFact.rawValue().toInt() == 1, _coordinate)) {
qDebug() << _eastingFact.rawValue().toDouble() << _northingFact.rawValue().toDouble() << _zoneFact.rawValue().toInt() << (_hemisphereFact.rawValue().toInt() == 1) << _coordinate;
emit coordinateChanged(_coordinate);
} else {
initValues();
}
}
void EditPositionDialogController::setFromMGRS(void)
{
if (convertMGRSToGeo(_mgrsFact.rawValue().toString(), _coordinate)) {
emit coordinateChanged(_coordinate);
} else {
initValues();
}
}
void EditPositionDialogController::setFromVehicle(void)
......
......@@ -28,6 +28,7 @@ public:
Q_PROPERTY(Fact* hemisphere READ hemisphere CONSTANT)
Q_PROPERTY(Fact* easting READ easting CONSTANT)
Q_PROPERTY(Fact* northing READ northing CONSTANT)
Q_PROPERTY(Fact* mgrs READ mgrs CONSTANT)
QGeoCoordinate coordinate(void) const { return _coordinate; }
Fact* latitude (void) { return &_latitudeFact; }
......@@ -36,12 +37,14 @@ public:
Fact* hemisphere(void) { return &_hemisphereFact; }
Fact* easting (void) { return &_eastingFact; }
Fact* northing (void) { return &_northingFact; }
Fact* mgrs (void) { return &_mgrsFact; }
void setCoordinate(QGeoCoordinate coordinate);
Q_INVOKABLE void initValues(void);
Q_INVOKABLE void setFromGeo(void);
Q_INVOKABLE void setFromUTM(void);
Q_INVOKABLE void setFromMGRS(void);
Q_INVOKABLE void setFromVehicle(void);
signals:
......@@ -58,6 +61,7 @@ private:
Fact _hemisphereFact;
Fact _eastingFact;
Fact _northingFact;
Fact _mgrsFact;
static const char* _latitudeFactName;
static const char* _longitudeFactName;
......@@ -65,4 +69,5 @@ private:
static const char* _hemisphereFactName;
static const char* _eastingFactName;
static const char* _northingFactName;
static const char* _mgrsFactName;
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment