Fix using SI units like speed in km/h and altitude in meters for flight plan in Launcher.
This commit is contained in:
parent
6edf68107e
commit
446299ddaf
4 changed files with 123 additions and 26 deletions
|
@ -310,8 +310,13 @@ void FlightPlanController::onRestore()
|
|||
|
||||
QuantityValue FlightPlanController::cruiseAltitude() const
|
||||
{
|
||||
if (_fp->cruiseFlightLevel() > 0)
|
||||
if (_fp->cruiseFlightLevel() > 0) {
|
||||
return {Units::FlightLevel, _fp->cruiseFlightLevel()};
|
||||
}
|
||||
|
||||
if (_fp->cruiseAltitudeM() > 0) {
|
||||
return {Units::MetersMSL, _fp->cruiseAltitudeM()};
|
||||
}
|
||||
|
||||
return {Units::FeetMSL, _fp->cruiseAltitudeFt()};
|
||||
}
|
||||
|
@ -319,18 +324,28 @@ QuantityValue FlightPlanController::cruiseAltitude() const
|
|||
void FlightPlanController::setCruiseAltitude(QuantityValue alt)
|
||||
{
|
||||
const int ival = static_cast<int>(alt.value);
|
||||
if (alt.unit == Units::FlightLevel) {
|
||||
if (_fp->cruiseFlightLevel() == ival) {
|
||||
return;
|
||||
switch (alt.unit) {
|
||||
case Units::FlightLevel: {
|
||||
if (_fp->cruiseFlightLevel() == ival) {
|
||||
return;
|
||||
}
|
||||
_fp->setCruiseFlightLevel(ival);
|
||||
break;
|
||||
}
|
||||
|
||||
_fp->setCruiseFlightLevel(ival);
|
||||
} else if (alt.unit == Units::FeetMSL) {
|
||||
if (_fp->cruiseAltitudeFt() == ival) {
|
||||
return;
|
||||
case Units::FeetMSL: {
|
||||
if (_fp->cruiseAltitudeFt() == ival) {
|
||||
return;
|
||||
}
|
||||
_fp->setCruiseAltitudeFt(ival);
|
||||
break;
|
||||
}
|
||||
case Units::MetersMSL: {
|
||||
if (_fp->cruiseAltitudeM() == ival) {
|
||||
return;
|
||||
}
|
||||
_fp->setCruiseAltitudeM(ival);
|
||||
break;
|
||||
}
|
||||
|
||||
_fp->setCruiseAltitudeFt(ival);
|
||||
}
|
||||
|
||||
emit infoChanged();
|
||||
|
@ -379,6 +394,10 @@ QuantityValue FlightPlanController::cruiseSpeed() const
|
|||
return {Units::Mach, _fp->cruiseSpeedMach()};
|
||||
}
|
||||
|
||||
if (_fp->cruiseSpeedKilometersPerHour() > 0) {
|
||||
return {Units::KilometersPerHour, _fp->cruiseSpeedKilometersPerHour()};
|
||||
}
|
||||
|
||||
return {Units::Knots, _fp->cruiseSpeedKnots()};
|
||||
}
|
||||
|
||||
|
@ -608,19 +627,33 @@ void FlightPlanController::setAlternate(QmlPositioned *apt)
|
|||
void FlightPlanController::setCruiseSpeed(QuantityValue speed)
|
||||
{
|
||||
qInfo() << Q_FUNC_INFO << speed.unit << speed.value;
|
||||
if (speed.unit == Units::Mach) {
|
||||
if (speed == QuantityValue(Units::Mach, _fp->cruiseSpeedMach())) {
|
||||
return;
|
||||
}
|
||||
switch (speed.unit) {
|
||||
case Units::Mach: {
|
||||
if (speed == QuantityValue(Units::Mach, _fp->cruiseSpeedMach())) {
|
||||
return;
|
||||
}
|
||||
|
||||
_fp->setCruiseSpeedMach(speed.value);
|
||||
} else if (speed.unit == Units::Knots) {
|
||||
const int knotsVal = static_cast<int>(speed.value);
|
||||
if (_fp->cruiseSpeedKnots() == knotsVal) {
|
||||
return;
|
||||
_fp->setCruiseSpeedMach(speed.value);
|
||||
break;
|
||||
}
|
||||
case Units::Knots: {
|
||||
const int knotsVal = static_cast<int>(speed.value);
|
||||
if (_fp->cruiseSpeedKnots() == knotsVal) {
|
||||
return;
|
||||
}
|
||||
|
||||
_fp->setCruiseSpeedKnots(knotsVal);
|
||||
_fp->setCruiseSpeedKnots(knotsVal);
|
||||
break;
|
||||
}
|
||||
case Units::KilometersPerHour: {
|
||||
const int kmhVal = static_cast<int>(speed.value);
|
||||
if (_fp->cruiseSpeedKilometersPerHour() == kmhVal) {
|
||||
return;
|
||||
}
|
||||
|
||||
_fp->setCruiseSpeedKilometersPerHour(kmhVal);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
emit infoChanged();
|
||||
|
|
|
@ -160,12 +160,16 @@ FlightPlanRef FlightPlan::clone(const string& newIdent, bool convertIntoFlightPl
|
|||
c->setCruiseFlightLevel(_cruiseFlightLevel);
|
||||
} else if (_cruiseAltitudeFt > 0) {
|
||||
c->setCruiseAltitudeFt(_cruiseAltitudeFt);
|
||||
} else if (_cruiseAltitudeM > 0) {
|
||||
c->setCruiseAltitudeM(_cruiseAltitudeM);
|
||||
}
|
||||
|
||||
if (_cruiseAirspeedMach > 0) {
|
||||
c->setCruiseSpeedMach(_cruiseAirspeedMach);
|
||||
} else if (_cruiseAirspeedKnots > 0) {
|
||||
c->setCruiseSpeedKnots(_cruiseAirspeedKnots);
|
||||
} else if (_cruiseAirspeedKph > 0) {
|
||||
c->setCruiseSpeedKilometersPerHour(_cruiseAirspeedKph);
|
||||
}
|
||||
|
||||
c->_didLoadFP = true; // set the loaded flag to give delegates a chance
|
||||
|
@ -314,8 +318,10 @@ void FlightPlan::clearAll()
|
|||
|
||||
_cruiseAirspeedMach = 0.0;
|
||||
_cruiseAirspeedKnots = 0;
|
||||
_cruiseAirspeedKph = 0;
|
||||
_cruiseFlightLevel = 0;
|
||||
_cruiseAltitudeFt = 0;
|
||||
_cruiseAltitudeM = 0;
|
||||
|
||||
clearLegs();
|
||||
unlockDelegates();
|
||||
|
@ -712,12 +718,12 @@ void FlightPlan::setEstimatedDurationMinutes(int mins)
|
|||
|
||||
void FlightPlan::computeDurationMinutes()
|
||||
{
|
||||
if ((_cruiseAirspeedMach < 0.01) && (_cruiseAirspeedKnots < 10)) {
|
||||
if ((_cruiseAirspeedMach < 0.01) && (_cruiseAirspeedKnots < 10) && (_cruiseAirspeedKph < 10)) {
|
||||
SG_LOG(SG_AUTOPILOT, SG_WARN, "can't compute duration, no cruise speed set");
|
||||
return;
|
||||
}
|
||||
|
||||
if ((_cruiseAltitudeFt < 100) && (_cruiseFlightLevel < 10)) {
|
||||
if ((_cruiseAltitudeFt < 100) && (_cruiseAltitudeM < 100) && (_cruiseFlightLevel < 10)) {
|
||||
SG_LOG(SG_AUTOPILOT, SG_WARN, "can't compute duration, no cruise altitude set");
|
||||
return;
|
||||
}
|
||||
|
@ -869,12 +875,16 @@ void FlightPlan::saveToProperties(SGPropertyNode* d) const
|
|||
d->setIntValue("cruise/flight-level", _cruiseFlightLevel);
|
||||
} else if (_cruiseAltitudeFt > 0) {
|
||||
d->setIntValue("cruise/altitude-ft", _cruiseAltitudeFt);
|
||||
} else if (_cruiseAltitudeM > 0) {
|
||||
d->setIntValue("cruise/altitude-m", _cruiseAltitudeM);
|
||||
}
|
||||
|
||||
if (_cruiseAirspeedMach > 0.0) {
|
||||
d->setDoubleValue("cruise/mach", _cruiseAirspeedMach);
|
||||
} else if (_cruiseAirspeedKnots > 0) {
|
||||
d->setIntValue("cruise/knots", _cruiseAirspeedKnots);
|
||||
} else if (_cruiseAirspeedKph > 0) {
|
||||
d->setIntValue("cruise/kph", _cruiseAirspeedKph);
|
||||
}
|
||||
|
||||
// route nodes
|
||||
|
@ -1260,12 +1270,16 @@ void FlightPlan::loadXMLRouteHeader(SGPropertyNode_ptr routeData)
|
|||
_cruiseFlightLevel = crs->getIntValue("flight-level");
|
||||
} else if (crs->hasChild("altitude-ft")) {
|
||||
_cruiseAltitudeFt = crs->getIntValue("altitude-ft");
|
||||
} else if (crs->hasChild("altitude-m")) {
|
||||
_cruiseAltitudeM = crs->getIntValue("altitude-m");
|
||||
}
|
||||
|
||||
if (crs->hasChild("mach")) {
|
||||
_cruiseAirspeedMach = crs->getDoubleValue("mach");
|
||||
} else if (crs->hasChild("knots")) {
|
||||
_cruiseAirspeedKnots = crs->getIntValue("knots");
|
||||
} else if (crs->hasChild("kph")) {
|
||||
_cruiseAirspeedKph = crs->getIntValue("kph");
|
||||
}
|
||||
} // of cruise data loading
|
||||
}
|
||||
|
@ -2182,9 +2196,10 @@ ICAOFlightType FlightPlan::flightType() const
|
|||
void FlightPlan::setCruiseSpeedKnots(int kts)
|
||||
{
|
||||
lockDelegates();
|
||||
_cruiseDataChanged = true;
|
||||
_cruiseAirspeedKnots = kts;
|
||||
_cruiseAirspeedMach = 0.0;
|
||||
_cruiseDataChanged = true;
|
||||
_cruiseAirspeedKph = 0;
|
||||
unlockDelegates();
|
||||
}
|
||||
|
||||
|
@ -2197,8 +2212,9 @@ void FlightPlan::setCruiseSpeedMach(double mach)
|
|||
{
|
||||
lockDelegates();
|
||||
_cruiseDataChanged = true;
|
||||
_cruiseAirspeedMach = mach;
|
||||
_cruiseAirspeedKnots = 0;
|
||||
_cruiseAirspeedMach = mach;
|
||||
_cruiseAirspeedKph = 0;
|
||||
unlockDelegates();
|
||||
}
|
||||
|
||||
|
@ -2207,12 +2223,28 @@ double FlightPlan::cruiseSpeedMach() const
|
|||
return _cruiseAirspeedMach;
|
||||
}
|
||||
|
||||
void FlightPlan::setCruiseSpeedKPH(int kph)
|
||||
{
|
||||
lockDelegates();
|
||||
_cruiseDataChanged = true;
|
||||
_cruiseAirspeedKnots = 0;
|
||||
_cruiseAirspeedMach = 0.0;
|
||||
_cruiseAirspeedKph = kph;
|
||||
unlockDelegates();
|
||||
}
|
||||
|
||||
int FlightPlan::cruiseSpeedKPH() const
|
||||
{
|
||||
return _cruiseAirspeedKph;
|
||||
}
|
||||
|
||||
void FlightPlan::setCruiseFlightLevel(int flightLevel)
|
||||
{
|
||||
lockDelegates();
|
||||
_cruiseDataChanged = true;
|
||||
_cruiseFlightLevel = flightLevel;
|
||||
_cruiseAltitudeFt = 0;
|
||||
_cruiseAltitudeM = 0;
|
||||
_cruiseFlightLevel = flightLevel;
|
||||
unlockDelegates();
|
||||
}
|
||||
|
||||
|
@ -2226,6 +2258,7 @@ void FlightPlan::setCruiseAltitudeFt(int altFt)
|
|||
lockDelegates();
|
||||
_cruiseDataChanged = true;
|
||||
_cruiseAltitudeFt = altFt;
|
||||
_cruiseAltitudeM = 0;
|
||||
_cruiseFlightLevel = 0;
|
||||
unlockDelegates();
|
||||
}
|
||||
|
@ -2235,6 +2268,21 @@ int FlightPlan::cruiseAltitudeFt() const
|
|||
return _cruiseAltitudeFt;
|
||||
}
|
||||
|
||||
void FlightPlan::setCruiseAltitudeM(int altM)
|
||||
{
|
||||
lockDelegates();
|
||||
_cruiseDataChanged = true;
|
||||
_cruiseAltitudeFt = 0;
|
||||
_cruiseAltitudeM = altM;
|
||||
_cruiseFlightLevel = 0;
|
||||
unlockDelegates();
|
||||
}
|
||||
|
||||
int FlightPlan::cruiseAltitudeM() const
|
||||
{
|
||||
return _cruiseAltitudeM;
|
||||
}
|
||||
|
||||
void FlightPlan::forEachLeg(const LegVisitor& lv)
|
||||
{
|
||||
std::for_each(_legs.begin(), _legs.end(), lv);
|
||||
|
|
|
@ -405,11 +405,17 @@ public:
|
|||
void setCruiseSpeedMach(double mach);
|
||||
double cruiseSpeedMach() const;
|
||||
|
||||
void setCruiseSpeedKPH(int kmh);
|
||||
int cruiseSpeedKPH() const;
|
||||
|
||||
void setCruiseFlightLevel(int flightLevel);
|
||||
int cruiseFlightLevel() const;
|
||||
|
||||
void setCruiseAltitudeFt(int altFt);
|
||||
int cruiseAltitudeFt() const;
|
||||
|
||||
void setCruiseAltitudeM(int altM);
|
||||
int cruiseAltitudeM() const;
|
||||
|
||||
/**
|
||||
* abstract interface for creating delegates automatically when a
|
||||
|
@ -482,8 +488,10 @@ private:
|
|||
ICAOFlightRules _flightRules = ICAOFlightRules::VFR;
|
||||
int _cruiseAirspeedKnots = 0;
|
||||
double _cruiseAirspeedMach = 0.0;
|
||||
int _cruiseAirspeedKph = 0;
|
||||
int _cruiseFlightLevel = 0;
|
||||
int _cruiseAltitudeFt = 0;
|
||||
int _cruiseAltitudeM = 0;
|
||||
int _estimatedDuration = 0;
|
||||
double _maxFlyByTurnAngle = 90.0;
|
||||
|
||||
|
|
|
@ -649,10 +649,14 @@ static const char* flightplanGhostGetMember(naContext c, void* g, naRef field, n
|
|||
*out = naNum(fp->cruiseAltitudeFt());
|
||||
else if (!strcmp(fieldName, "cruiseFlightLevel"))
|
||||
*out = naNum(fp->cruiseFlightLevel());
|
||||
else if (!strcmp(fieldName, "cruiseAltitudeM"))
|
||||
*out = naNum(fp->cruiseAltitudeM());
|
||||
else if (!strcmp(fieldName, "cruiseSpeedKt"))
|
||||
*out = naNum(fp->cruiseSpeedKnots());
|
||||
else if (!strcmp(fieldName, "cruiseSpeedMach"))
|
||||
*out = naNum(fp->cruiseSpeedMach());
|
||||
else if (!strcmp(fieldName, "cruiseSpeedKPH"))
|
||||
*out = naNum(fp->cruiseSpeedKPH());
|
||||
else if (!strcmp(fieldName, "remarks"))
|
||||
*out = stringToNasal(c, fp->remarks());
|
||||
else if (!strcmp(fieldName, "callsign"))
|
||||
|
@ -960,10 +964,14 @@ static void flightplanGhostSetMember(naContext c, void* g, naRef field, naRef va
|
|||
fp->setFollowLegTrackToFixes(static_cast<bool>(value.num));
|
||||
} else if (!strcmp(fieldName, "cruiseAltitudeFt")) {
|
||||
fp->setCruiseAltitudeFt(static_cast<int>(value.num));
|
||||
} else if (!strcmp(fieldName, "cruiseAltitudeM")) {
|
||||
fp->setCruiseAltitudeM(static_cast<int>(value.num));
|
||||
} else if (!strcmp(fieldName, "cruiseFlightLevel")) {
|
||||
fp->setCruiseFlightLevel(static_cast<int>(value.num));
|
||||
} else if (!strcmp(fieldName, "cruiseSpeedKt")) {
|
||||
fp->setCruiseSpeedKnots(static_cast<int>(value.num));
|
||||
} else if (!strcmp(fieldName, "cruiseSpeedKPH")) {
|
||||
fp->setCruiseSpeedKPH(static_cast<int>(value.num));
|
||||
} else if (!strcmp(fieldName, "cruiseSpeedMach")) {
|
||||
fp->setCruiseSpeedMach(value.num);
|
||||
} else if (!strcmp(fieldName, "callsign")) {
|
||||
|
|
Loading…
Reference in a new issue