Unverified Commit 0aad76c5 authored by Don Gagne's avatar Don Gagne Committed by GitHub

Merge pull request #5913 from DonLakeFlyer/FWLandingPatternOverrides

Fixed Window landing pattern defaults override support
parents a5c6b0da 0092cf2c
...@@ -7,12 +7,10 @@ ...@@ -7,12 +7,10 @@
* *
****************************************************************************/ ****************************************************************************/
/// @file
/// @author Don Gagne <don@thegagnes.com>
#include "Fact.h" #include "Fact.h"
#include "QGCMAVLink.h" #include "QGCMAVLink.h"
#include "QGCApplication.h"
#include "QGCCorePlugin.h"
#include <QtQml> #include <QtQml>
#include <QQmlEngine> #include <QQmlEngine>
...@@ -50,6 +48,21 @@ Fact::Fact(int componentId, QString name, FactMetaData::ValueType_t type, QObjec ...@@ -50,6 +48,21 @@ Fact::Fact(int componentId, QString name, FactMetaData::ValueType_t type, QObjec
QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership); QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
} }
Fact::Fact(FactMetaData* metaData, QObject* parent)
: QObject(parent)
, _name (metaData->name())
, _componentId (0)
, _rawValue (0)
, _type (metaData->type())
, _metaData (NULL)
, _sendValueChangedSignals (true)
, _deferredValueChangeSignal(false)
{
// Allow core plugin a chance to override the default value
qgcApp()->toolbox()->corePlugin()->adjustSettingMetaData(*metaData);
setMetaData(metaData, true /* setDefaultFromMetaData */);
}
Fact::Fact(const Fact& other, QObject* parent) Fact::Fact(const Fact& other, QObject* parent)
: QObject(parent) : QObject(parent)
{ {
......
...@@ -31,6 +31,10 @@ public: ...@@ -31,6 +31,10 @@ public:
Fact(int componentId, QString name, FactMetaData::ValueType_t type, QObject* parent = NULL); Fact(int componentId, QString name, FactMetaData::ValueType_t type, QObject* parent = NULL);
Fact(const Fact& other, QObject* parent = NULL); Fact(const Fact& other, QObject* parent = NULL);
/// Creates a Fact using the name and type from metaData. Also calls QGCCorePlugin::adjustSettingsMetaData allowing
/// custom builds to override the metadata.
Fact(FactMetaData* metaData, QObject* parent = NULL);
const Fact& operator=(const Fact& other); const Fact& operator=(const Fact& other);
Q_PROPERTY(int componentId READ componentId CONSTANT) Q_PROPERTY(int componentId READ componentId CONSTANT)
......
...@@ -986,29 +986,58 @@ FactMetaData* FactMetaData::createFromJsonObject(const QJsonObject& json, QObjec ...@@ -986,29 +986,58 @@ FactMetaData* FactMetaData::createFromJsonObject(const QJsonObject& json, QObjec
if (json.contains(_unitsJsonKey)) { if (json.contains(_unitsJsonKey)) {
metaData->setRawUnits(json[_unitsJsonKey].toString()); metaData->setRawUnits(json[_unitsJsonKey].toString());
} }
QString defaultValueJsonKey;
#ifdef __mobile__ #ifdef __mobile__
if (json.contains(_mobileDefaultValueJsonKey)) { if (json.contains(_mobileDefaultValueJsonKey)) {
metaData->setRawDefaultValue(json[_mobileDefaultValueJsonKey].toVariant()); defaultValueJsonKey = _mobileDefaultValueJsonKey;
} else if (json.contains(_defaultValueJsonKey)) {
metaData->setRawDefaultValue(json[_defaultValueJsonKey].toVariant());
}
#else
if (json.contains(_defaultValueJsonKey)) {
metaData->setRawDefaultValue(json[_defaultValueJsonKey].toVariant());
} }
#endif #endif
if (defaultValueJsonKey.isEmpty() && json.contains(_defaultValueJsonKey)) {
defaultValueJsonKey = _defaultValueJsonKey;
}
if (!defaultValueJsonKey.isEmpty()) {
QVariant typedValue;
QString errorString;
QVariant initialValue = json[defaultValueJsonKey].toVariant();
if (metaData->convertAndValidateRaw(initialValue, true /* convertOnly */, typedValue, errorString)) {
metaData->setRawDefaultValue(typedValue);
} else {
qWarning() << "Invalid default value, name:" << metaData->name()
<< " type:" << metaData->type()
<< " value:" << initialValue
<< " error:" << errorString;
}
}
if (json.contains(_minJsonKey)) { if (json.contains(_minJsonKey)) {
QVariant typedValue; QVariant typedValue;
QString errorString; QString errorString;
metaData->convertAndValidateRaw(json[_minJsonKey].toVariant(), true /* convertOnly */, typedValue, errorString); QVariant initialValue = json[_minJsonKey].toVariant();
metaData->setRawMin(typedValue); if (metaData->convertAndValidateRaw(initialValue, true /* convertOnly */, typedValue, errorString)) {
metaData->setRawMin(typedValue);
} else {
qWarning() << "Invalid min value, name:" << metaData->name()
<< " type:" << metaData->type()
<< " value:" << initialValue
<< " error:" << errorString;
}
} }
if (json.contains(_maxJsonKey)) { if (json.contains(_maxJsonKey)) {
QVariant typedValue; QVariant typedValue;
QString errorString; QString errorString;
metaData->convertAndValidateRaw(json[_maxJsonKey].toVariant(), true /* convertOnly */, typedValue, errorString); QVariant initialValue = json[_maxJsonKey].toVariant();
metaData->setRawMax(typedValue); if (metaData->convertAndValidateRaw(initialValue, true /* convertOnly */, typedValue, errorString)) {
metaData->setRawMax(typedValue);
} else {
qWarning() << "Invalid max value, name:" << metaData->name()
<< " type:" << metaData->type()
<< " value:" << initialValue
<< " error:" << errorString;
}
} }
if (json.contains(_hasControlJsonKey)) { if (json.contains(_hasControlJsonKey)) {
metaData->setHasControl(json[_hasControlJsonKey].toBool()); metaData->setHasControl(json[_hasControlJsonKey].toBool());
} else { } else {
......
[ [
{ {
"name": "Landing dist", "name": "LandingDistance",
"shortDescription": "Distance between landing and loiter points.", "shortDescription": "Distance between landing and loiter points.",
"type": "double", "type": "double",
"units": "m", "units": "m",
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
"defaultValue": 300.0 "defaultValue": 300.0
}, },
{ {
"name": "Landing heading", "name": "LandingHeading",
"shortDescription": "Heading from loiter point to land point.", "shortDescription": "Heading from loiter point to land point.",
"type": "double", "type": "double",
"units": "deg", "units": "deg",
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
"defaultValue": 270.0 "defaultValue": 270.0
}, },
{ {
"name": "Loiter altitude", "name": "LoiterAltitude",
"shortDescription": "Aircraft will proceed to the loiter point and loiter until it reaches this altitude. Once altitude is reached the aircraft will proceed to land.", "shortDescription": "Aircraft will proceed to the loiter point and loiter until it reaches this altitude. Once altitude is reached the aircraft will proceed to land.",
"type": "double", "type": "double",
"units": "m", "units": "m",
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
"defaultValue": 40.0 "defaultValue": 40.0
}, },
{ {
"name": "Loiter radius", "name": "LoiterRadius",
"shortDescription": "Loiter radius.", "shortDescription": "Loiter radius.",
"type": "double", "type": "double",
"decimalPlaces": 1, "decimalPlaces": 1,
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
"defaultValue": 75.0 "defaultValue": 75.0
}, },
{ {
"name": "Landing altitude", "name": "LandingAltitude",
"shortDescription": "Altitude for landing point.", "shortDescription": "Altitude for landing point.",
"type": "double", "type": "double",
"units": "m", "units": "m",
...@@ -44,7 +44,7 @@ ...@@ -44,7 +44,7 @@
"defaultValue": 0.0 "defaultValue": 0.0
}, },
{ {
"name": "Descent rate", "name": "DescentRate",
"shortDescription": "Descent rate between landing and loiter altitude.", "shortDescription": "Descent rate between landing and loiter altitude.",
"type": "double", "type": "double",
"units": "%", "units": "%",
......
...@@ -20,12 +20,12 @@ QGC_LOGGING_CATEGORY(FixedWingLandingComplexItemLog, "FixedWingLandingComplexIte ...@@ -20,12 +20,12 @@ QGC_LOGGING_CATEGORY(FixedWingLandingComplexItemLog, "FixedWingLandingComplexIte
const char* FixedWingLandingComplexItem::jsonComplexItemTypeValue = "fwLandingPattern"; const char* FixedWingLandingComplexItem::jsonComplexItemTypeValue = "fwLandingPattern";
const char* FixedWingLandingComplexItem::_loiterToLandDistanceName = "Landing dist"; const char* FixedWingLandingComplexItem::loiterToLandDistanceName = "LandingDistance";
const char* FixedWingLandingComplexItem::_landingHeadingName = "Landing heading"; const char* FixedWingLandingComplexItem::landingHeadingName = "LandingHeading";
const char* FixedWingLandingComplexItem::_loiterAltitudeName = "Loiter altitude"; const char* FixedWingLandingComplexItem::loiterAltitudeName = "LoiterAltitude";
const char* FixedWingLandingComplexItem::_loiterRadiusName = "Loiter radius"; const char* FixedWingLandingComplexItem::loiterRadiusName = "LoiterRadius";
const char* FixedWingLandingComplexItem::_landingAltitudeName = "Landing altitude"; const char* FixedWingLandingComplexItem::landingAltitudeName = "LandingAltitude";
const char* FixedWingLandingComplexItem::_fallRateName = "Descent rate"; const char* FixedWingLandingComplexItem::fallRateName = "DescentRate";
const char* FixedWingLandingComplexItem::_jsonLoiterCoordinateKey = "loiterCoordinate"; const char* FixedWingLandingComplexItem::_jsonLoiterCoordinateKey = "loiterCoordinate";
const char* FixedWingLandingComplexItem::_jsonLoiterRadiusKey = "loiterRadius"; const char* FixedWingLandingComplexItem::_jsonLoiterRadiusKey = "loiterRadius";
...@@ -35,44 +35,25 @@ const char* FixedWingLandingComplexItem::_jsonLandingCoordinateKey = "lan ...@@ -35,44 +35,25 @@ const char* FixedWingLandingComplexItem::_jsonLandingCoordinateKey = "lan
const char* FixedWingLandingComplexItem::_jsonLandingAltitudeRelativeKey = "landAltitudeRelative"; const char* FixedWingLandingComplexItem::_jsonLandingAltitudeRelativeKey = "landAltitudeRelative";
const char* FixedWingLandingComplexItem::_jsonFallRateKey = "fallRate"; const char* FixedWingLandingComplexItem::_jsonFallRateKey = "fallRate";
QMap<QString, FactMetaData*> FixedWingLandingComplexItem::_metaDataMap;
FixedWingLandingComplexItem::FixedWingLandingComplexItem(Vehicle* vehicle, QObject* parent) FixedWingLandingComplexItem::FixedWingLandingComplexItem(Vehicle* vehicle, QObject* parent)
: ComplexMissionItem(vehicle, parent) : ComplexMissionItem (vehicle, parent)
, _sequenceNumber(0) , _sequenceNumber (0)
, _dirty(false) , _dirty (false)
, _landingCoordSet(false) , _landingCoordSet (false)
, _ignoreRecalcSignals(false) , _ignoreRecalcSignals (false)
, _landingDistanceFact (0, _loiterToLandDistanceName, FactMetaData::valueTypeDouble) , _metaDataMap (FactMetaData::createMapFromJsonFile(QStringLiteral(":/json/FWLandingPattern.FactMetaData.json"), this))
, _loiterAltitudeFact (0, _loiterAltitudeName, FactMetaData::valueTypeDouble) , _landingDistanceFact (_metaDataMap[loiterToLandDistanceName])
, _loiterRadiusFact (0, _loiterRadiusName, FactMetaData::valueTypeDouble) , _loiterAltitudeFact (_metaDataMap[loiterAltitudeName])
, _landingHeadingFact (0, _landingHeadingName, FactMetaData::valueTypeDouble) , _loiterRadiusFact (_metaDataMap[loiterRadiusName])
, _landingAltitudeFact (0, _landingAltitudeName, FactMetaData::valueTypeDouble) , _landingHeadingFact (_metaDataMap[landingHeadingName])
, _fallRateFact (0, _fallRateName, FactMetaData::valueTypeDouble) , _landingAltitudeFact (_metaDataMap[landingAltitudeName])
, _loiterClockwise(true) , _fallRateFact (_metaDataMap[fallRateName])
, _loiterAltitudeRelative(true) , _loiterClockwise (true)
, _landingAltitudeRelative(true) , _loiterAltitudeRelative (true)
, _landingAltitudeRelative (true)
{ {
_editorQml = "qrc:/qml/FWLandingPatternEditor.qml"; _editorQml = "qrc:/qml/FWLandingPatternEditor.qml";
if (_metaDataMap.isEmpty()) {
_metaDataMap = FactMetaData::createMapFromJsonFile(QStringLiteral(":/json/FWLandingPattern.FactMetaData.json"), NULL /* metaDataParent */);
}
_landingDistanceFact.setMetaData (_metaDataMap[_loiterToLandDistanceName]);
_loiterAltitudeFact.setMetaData (_metaDataMap[_loiterAltitudeName]);
_loiterRadiusFact.setMetaData (_metaDataMap[_loiterRadiusName]);
_landingHeadingFact.setMetaData (_metaDataMap[_landingHeadingName]);
_landingAltitudeFact.setMetaData (_metaDataMap[_landingAltitudeName]);
_fallRateFact.setMetaData (_metaDataMap[_fallRateName]);
_landingDistanceFact.setRawValue (_landingDistanceFact.rawDefaultValue());
_loiterAltitudeFact.setRawValue (_loiterAltitudeFact.rawDefaultValue());
_loiterRadiusFact.setRawValue (_loiterRadiusFact.rawDefaultValue());
_landingHeadingFact.setRawValue (_landingHeadingFact.rawDefaultValue());
_landingAltitudeFact.setRawValue (_landingAltitudeFact.rawDefaultValue());
_fallRateFact.setRawValue (_fallRateFact.rawDefaultValue());
connect(&_loiterAltitudeFact, &Fact::valueChanged, this, &FixedWingLandingComplexItem::_updateLoiterCoodinateAltitudeFromFact); connect(&_loiterAltitudeFact, &Fact::valueChanged, this, &FixedWingLandingComplexItem::_updateLoiterCoodinateAltitudeFromFact);
connect(&_landingAltitudeFact, &Fact::valueChanged, this, &FixedWingLandingComplexItem::_updateLandingCoodinateAltitudeFromFact); connect(&_landingAltitudeFact, &Fact::valueChanged, this, &FixedWingLandingComplexItem::_updateLandingCoodinateAltitudeFromFact);
......
...@@ -92,6 +92,13 @@ public: ...@@ -92,6 +92,13 @@ public:
static const char* jsonComplexItemTypeValue; static const char* jsonComplexItemTypeValue;
static const char* loiterToLandDistanceName;
static const char* loiterAltitudeName;
static const char* loiterRadiusName;
static const char* landingHeadingName;
static const char* landingAltitudeName;
static const char* fallRateName;
signals: signals:
void loiterCoordinateChanged (QGeoCoordinate coordinate); void loiterCoordinateChanged (QGeoCoordinate coordinate);
void loiterTangentCoordinateChanged (QGeoCoordinate coordinate); void loiterTangentCoordinateChanged (QGeoCoordinate coordinate);
...@@ -122,6 +129,8 @@ private: ...@@ -122,6 +129,8 @@ private:
bool _landingCoordSet; bool _landingCoordSet;
bool _ignoreRecalcSignals; bool _ignoreRecalcSignals;
QMap<QString, FactMetaData*> _metaDataMap;
Fact _landingDistanceFact; Fact _landingDistanceFact;
Fact _loiterAltitudeFact; Fact _loiterAltitudeFact;
Fact _loiterRadiusFact; Fact _loiterRadiusFact;
...@@ -133,15 +142,6 @@ private: ...@@ -133,15 +142,6 @@ private:
bool _loiterAltitudeRelative; bool _loiterAltitudeRelative;
bool _landingAltitudeRelative; bool _landingAltitudeRelative;
static QMap<QString, FactMetaData*> _metaDataMap;
static const char* _loiterToLandDistanceName;
static const char* _loiterAltitudeName;
static const char* _loiterRadiusName;
static const char* _landingHeadingName;
static const char* _landingAltitudeName;
static const char* _fallRateName;
static const char* _jsonLoiterCoordinateKey; static const char* _jsonLoiterCoordinateKey;
static const char* _jsonLoiterRadiusKey; static const char* _jsonLoiterRadiusKey;
static const char* _jsonLoiterClockwiseKey; static const char* _jsonLoiterClockwiseKey;
......
...@@ -52,6 +52,7 @@ Rectangle { ...@@ -52,6 +52,7 @@ Rectangle {
anchors.left: parent.left anchors.left: parent.left
anchors.right: parent.right anchors.right: parent.right
factList: [ missionItem.loiterAltitude, missionItem.loiterRadius ] factList: [ missionItem.loiterAltitude, missionItem.loiterRadius ]
factLabels: [ qsTr("Altitude"), qsTr("Radius") ]
} }
Item { width: 1; height: _spacer } Item { width: 1; height: _spacer }
...@@ -82,14 +83,14 @@ Rectangle { ...@@ -82,14 +83,14 @@ Rectangle {
anchors.right: parent.right anchors.right: parent.right
columns: 2 columns: 2
QGCLabel { text: missionItem.landingHeading.name } QGCLabel { text: qsTr("Heading") }
FactTextField { FactTextField {
Layout.fillWidth: true Layout.fillWidth: true
fact: missionItem.landingHeading fact: missionItem.landingHeading
} }
QGCLabel { text: missionItem.landingAltitude.name } QGCLabel { text: qsTr("Altitude") }
FactTextField { FactTextField {
Layout.fillWidth: true Layout.fillWidth: true
...@@ -98,7 +99,7 @@ Rectangle { ...@@ -98,7 +99,7 @@ Rectangle {
QGCRadioButton { QGCRadioButton {
id: useLandingDistance id: useLandingDistance
text: missionItem.landingDistance.name text: qsTr("Landing dist")
checked: !useFallRate.checked checked: !useFallRate.checked
onClicked: { onClicked: {
useFallRate.checked = false useFallRate.checked = false
...@@ -115,7 +116,7 @@ Rectangle { ...@@ -115,7 +116,7 @@ Rectangle {
QGCRadioButton { QGCRadioButton {
id: useFallRate id: useFallRate
text: missionItem.fallRate.name text: qsTr("Descent rate")
checked: !useLandingDistance.checked checked: !useLandingDistance.checked
onClicked: { onClicked: {
useLandingDistance.checked = false useLandingDistance.checked = false
...@@ -160,19 +161,12 @@ Rectangle { ...@@ -160,19 +161,12 @@ Rectangle {
Column { Column {
id: editorColumnNeedLandingPoint id: editorColumnNeedLandingPoint
anchors.margins: _margin anchors.margins: _margin
anchors.top: parent.top
anchors.left: parent.left anchors.left: parent.left
anchors.right: parent.right anchors.right: parent.right
visible: !missionItem.landingCoordSet visible: !missionItem.landingCoordSet
spacing: ScreenTools.defaultFontPixelHeight spacing: ScreenTools.defaultFontPixelHeight
QGCLabel {
anchors.left: parent.left
anchors.right: parent.right
wrapMode: Text.WordWrap
font.pointSize: ScreenTools.smallFontPointSize
text: qsTr("WIP (NOT FOR REAL FLIGHT!)")
}
QGCLabel { QGCLabel {
anchors.left: parent.left anchors.left: parent.left
anchors.right: parent.right anchors.right: parent.right
......
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