From 54ef43878f50eb99d3773ceef099383886d95bf1 Mon Sep 17 00:00:00 2001 From: James Turner Date: Wed, 19 Jan 2011 23:58:00 +0000 Subject: [PATCH 1/4] Fix bug 259 - don't override existing airport/runway in initPos --- src/Autopilot/route_mgr.cxx | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/Autopilot/route_mgr.cxx b/src/Autopilot/route_mgr.cxx index 127e2c397..bcb5895ac 100644 --- a/src/Autopilot/route_mgr.cxx +++ b/src/Autopilot/route_mgr.cxx @@ -924,11 +924,20 @@ void FGRouteMgr::initAtPosition() } // on the ground - SGGeod pos = SGGeod::fromDegFt(lon->getDoubleValue(), lat->getDoubleValue(), alt->getDoubleValue()); - _departure = FGAirport::findClosest(pos, 20.0); + SGGeod pos = SGGeod::fromDegFt(lon->getDoubleValue(), + lat->getDoubleValue(), alt->getDoubleValue()); if (!_departure) { - SG_LOG(SG_AUTOPILOT, SG_INFO, "initAtPosition: couldn't find an airport within 20nm"); - departure->setStringValue("runway", ""); + _departure = FGAirport::findClosest(pos, 20.0); + if (!_departure) { + SG_LOG(SG_AUTOPILOT, SG_INFO, "initAtPosition: couldn't find an airport within 20nm"); + departure->setStringValue("runway", ""); + return; + } + } + + std::string rwy = departure->getStringValue("runway"); + if (!rwy.empty()) { + // runway already set, fine return; } From 7cbb3a10edf9432292dce65649c1462d61503508 Mon Sep 17 00:00:00 2001 From: James Turner Date: Thu, 20 Jan 2011 00:39:42 +0000 Subject: [PATCH 2/4] Expand route-manager waypoint info, to support smarter FMS functions. --- src/Autopilot/route_mgr.cxx | 19 +++++++++++++++++-- src/GUI/MapWidget.cxx | 4 +++- src/GUI/WaypointList.cxx | 5 ++++- src/Navaids/route.cxx | 23 +++++++++++++++++++---- src/Navaids/route.hxx | 17 ++++++++++++----- 5 files changed, 55 insertions(+), 13 deletions(-) diff --git a/src/Autopilot/route_mgr.cxx b/src/Autopilot/route_mgr.cxx index bcb5895ac..57f7d5d5c 100644 --- a/src/Autopilot/route_mgr.cxx +++ b/src/Autopilot/route_mgr.cxx @@ -310,6 +310,8 @@ void FGRouteMgr::update( double dt ) if (w->flag(WPT_DYNAMIC)) continue; totalDistanceRemaining += SGGeodesy::distanceM(prev->position(), w->position()); prev = w; + + } wpn->setDoubleValue("dist", totalDistanceRemaining * SG_METER_TO_NM); @@ -801,7 +803,9 @@ WayptRef FGRouteMgr::waypointFromString(const string& tgt ) void FGRouteMgr::update_mirror() { mirror->removeChildren("wp"); - for (int i = 0; i < numWaypts(); i++) { + + int num = numWaypts(); + for (int i = 0; i < num; i++) { Waypt* wp = _route[i]; SGPropertyNode *prop = mirror->getChild("wp", i, 1); @@ -811,6 +815,15 @@ void FGRouteMgr::update_mirror() prop->setDoubleValue("longitude-deg", pos.getLongitudeDeg()); prop->setDoubleValue("latitude-deg",pos.getLatitudeDeg()); + // leg course+distance + if (i < (num - 1)) { + Waypt* next = _route[i+1]; + std::pair crsDist = + next->courseAndDistanceFrom(pos); + prop->setDoubleValue("leg-bearing-true-deg", crsDist.first); + prop->setDoubleValue("leg-distance-nm", crsDist.second * SG_METER_TO_NM); + } + if (wp->altitudeRestriction() != RESTRICT_NONE) { double ft = wp->altitudeFt(); prop->setDoubleValue("altitude-m", ft * SG_FEET_TO_METER); @@ -820,7 +833,9 @@ void FGRouteMgr::update_mirror() prop->setDoubleValue("altitude-ft", -9999.9); } - if (wp->speedRestriction() != RESTRICT_NONE) { + if (wp->speedRestriction() == SPEED_RESTRICT_MACH) { + prop->setDoubleValue("speed-mach", wp->speedMach()); + } else if (wp->speedRestriction() != RESTRICT_NONE) { prop->setDoubleValue("speed-kts", wp->speedKts()); } diff --git a/src/GUI/MapWidget.cxx b/src/GUI/MapWidget.cxx index 0b786f5a3..858eea1a1 100644 --- a/src/GUI/MapWidget.cxx +++ b/src/GUI/MapWidget.cxx @@ -714,7 +714,9 @@ void MapWidget::paintRoute() legend << '\n' << SGMiscd::roundToInt(wpt->altitudeFt()) << '\''; } - if (wpt->speedRestriction() != flightgear::RESTRICT_NONE) { + if (wpt->speedRestriction() == flightgear::SPEED_RESTRICT_MACH) { + legend << '\n' << wpt->speedMach() << "M"; + } else if (wpt->speedRestriction() != flightgear::RESTRICT_NONE) { legend << '\n' << SGMiscd::roundToInt(wpt->speedKts()) << "Kts"; } diff --git a/src/GUI/WaypointList.cxx b/src/GUI/WaypointList.cxx index 31c5e480c..b014d1cd3 100644 --- a/src/GUI/WaypointList.cxx +++ b/src/GUI/WaypointList.cxx @@ -467,7 +467,10 @@ void WaypointList::drawRow(int dx, int dy, int rowIndex, int y) } // of valid wp altitude x += 60 + PUSTR_LGAP; - if (wp->speedRestriction() != RESTRICT_NONE) { + if (wp->speedRestriction() == SPEED_RESTRICT_MACH) { + count = ::snprintf(buffer, 126, "%03.2fM", wp->speedMach()); + f->drawString(buffer, x, yy); + } else if (wp->speedRestriction() != RESTRICT_NONE) { count = ::snprintf(buffer, 126, "%dKts", (int) wp->speedKts()); f->drawString(buffer, x, yy); } diff --git a/src/Navaids/route.cxx b/src/Navaids/route.cxx index 580c87c18..cfe25de40 100644 --- a/src/Navaids/route.cxx +++ b/src/Navaids/route.cxx @@ -51,7 +51,7 @@ namespace flightgear { Waypt::Waypt(Route* aOwner) : _altitudeFt(0.0), - _speedKts(0.0), + _speed(0.0), _altRestrict(RESTRICT_NONE), _speedRestrict(RESTRICT_NONE), _owner(aOwner), @@ -100,10 +100,22 @@ void Waypt::setAltitude(double aAlt, RouteRestriction aRestrict) void Waypt::setSpeed(double aSpeed, RouteRestriction aRestrict) { - _speedKts = aSpeed; + _speed = aSpeed; _speedRestrict = aRestrict; } +double Waypt::speedKts() const +{ + assert(_speedRestrict != SPEED_RESTRICT_MACH); + return speed(); +} + +double Waypt::speedMach() const +{ + assert(_speedRestrict == SPEED_RESTRICT_MACH); + return speed(); +} + std::pair Waypt::courseAndDistanceFrom(const SGGeod& aPos) const { @@ -127,6 +139,7 @@ static RouteRestriction restrictionFromString(const char* aStr) if (l == "above") return RESTRICT_ABOVE; if (l == "below") return RESTRICT_BELOW; if (l == "none") return RESTRICT_NONE; + if (l == "mach") return SPEED_RESTRICT_MACH; if (l.empty()) return RESTRICT_NONE; throw sg_io_exception("unknown restriction specification:" + l, @@ -140,6 +153,8 @@ static const char* restrictionToString(RouteRestriction aRestrict) case RESTRICT_BELOW: return "below"; case RESTRICT_ABOVE: return "above"; case RESTRICT_NONE: return "none"; + case SPEED_RESTRICT_MACH: return "mach"; + default: throw sg_exception("invalid route restriction", "Route restrictToString"); @@ -224,7 +239,7 @@ void Waypt::initFromProperties(SGPropertyNode_ptr aProp) if (aProp->hasChild("speed-restrict")) { _speedRestrict = restrictionFromString(aProp->getStringValue("speed-restrict")); - _speedKts = aProp->getDoubleValue("speed-kts"); + _speed = aProp->getDoubleValue("speed"); } @@ -259,7 +274,7 @@ void Waypt::writeToProperties(SGPropertyNode_ptr aProp) const if (_speedRestrict != RESTRICT_NONE) { aProp->setStringValue("speed-restrict", restrictionToString(_speedRestrict)); - aProp->setDoubleValue("speed-kts", _speedKts); + aProp->setDoubleValue("speed", _speed); } } diff --git a/src/Navaids/route.hxx b/src/Navaids/route.hxx index a23d728a7..b0375d15c 100644 --- a/src/Navaids/route.hxx +++ b/src/Navaids/route.hxx @@ -74,7 +74,8 @@ typedef enum { RESTRICT_NONE, RESTRICT_AT, RESTRICT_ABOVE, - RESTRICT_BELOW + RESTRICT_BELOW, + SPEED_RESTRICT_MACH } RouteRestriction; /** @@ -104,9 +105,15 @@ public: virtual double altitudeFt() const { return _altitudeFt; } - virtual double speedKts() const - { return _speedKts; } - + virtual double speed() const + { return _speed; } + +// wrapper - asserts if restriction type is _MACH + double speedKts() const; + +// wrapper - asserts if restriction type is not _MACH + double speedMach() const; + virtual RouteRestriction altitudeRestriction() const { return _altRestrict; } @@ -168,7 +175,7 @@ protected: static void registerFactory(const std::string aNodeType, FactoryFunction* aFactory); double _altitudeFt; - double _speedKts; + double _speed; // knots IAS or mach RouteRestriction _altRestrict; RouteRestriction _speedRestrict; private: From d227258b3b5f58b1de1dfbf161d34ad59a381fc2 Mon Sep 17 00:00:00 2001 From: James Turner Date: Thu, 20 Jan 2011 08:49:09 +0000 Subject: [PATCH 3/4] Lazy caching of magvar on waypoints. Not used yet, but soon. --- src/Navaids/route.cxx | 21 ++++++++++++++++++++- src/Navaids/route.hxx | 8 +++++++- src/Navaids/waypoint.hxx | 3 +++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/Navaids/route.cxx b/src/Navaids/route.cxx index cfe25de40..0dc9b2c0f 100644 --- a/src/Navaids/route.cxx +++ b/src/Navaids/route.cxx @@ -36,8 +36,11 @@ #include #include #include +#include +#include // FlightGear +#include
#include #include #include @@ -49,13 +52,16 @@ using std::fstream; namespace flightgear { +const double NO_MAG_VAR = -1000.0; // an impossible mag-var value + Waypt::Waypt(Route* aOwner) : _altitudeFt(0.0), _speed(0.0), _altRestrict(RESTRICT_NONE), _speedRestrict(RESTRICT_NONE), _owner(aOwner), - _flags(0) + _flags(0), + _magVarDeg(NO_MAG_VAR) { } @@ -127,6 +133,19 @@ Waypt::courseAndDistanceFrom(const SGGeod& aPos) const SGGeodesy::inverse(aPos, position(), course, az2, distance); return std::make_pair(course, distance); } + +double Waypt::magvarDeg() const +{ + if (_magVarDeg == NO_MAG_VAR) { + // derived classes with a default pos must override this method + assert(!(position() == SGGeod())); + + double jd = globals->get_time_params()->getJD(); + _magVarDeg = sgGetMagVar(position(), jd); + } + + return _magVarDeg; +} /////////////////////////////////////////////////////////////////////////// // persistence diff --git a/src/Navaids/route.hxx b/src/Navaids/route.hxx index b0375d15c..cd2114f6d 100644 --- a/src/Navaids/route.hxx +++ b/src/Navaids/route.hxx @@ -156,6 +156,12 @@ public: bool matches(const SGGeod& aPos) const; virtual std::string type() const = 0; + + /** + * Magentic variation at/in the vicinity of the waypoint. + * For some waypoint types this will always return 0. + */ + virtual double magvarDeg() const; protected: friend class NavdataVisitor; @@ -187,7 +193,7 @@ private: Route* _owner; unsigned short _flags; - + mutable double _magVarDeg; }; typedef std::vector WayptVec; diff --git a/src/Navaids/waypoint.hxx b/src/Navaids/waypoint.hxx index 7b5f30f09..0b2ae7d95 100644 --- a/src/Navaids/waypoint.hxx +++ b/src/Navaids/waypoint.hxx @@ -206,6 +206,9 @@ public: double headingDegMagnetic() const { return _magHeading; } + virtual double magvarDeg() const + { return 0.0; } + private: std::string _ident; double _magHeading; From a81103341e7f7de92758a961c0365a21aa84be17 Mon Sep 17 00:00:00 2001 From: Torsten Dreyer Date: Fri, 21 Jan 2011 10:35:04 +0100 Subject: [PATCH 4/4] Fix bug 255, support turbulence to weather menu --- src/Environment/Makefile.am | 2 +- src/Environment/environment.cxx | 8 -------- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/src/Environment/Makefile.am b/src/Environment/Makefile.am index 90b732315..c3b1b5fbf 100644 --- a/src/Environment/Makefile.am +++ b/src/Environment/Makefile.am @@ -17,6 +17,6 @@ libEnvironment_a_SOURCES = \ ridge_lift.cxx ridge_lift.hxx \ ephemeris.cxx ephemeris.hxx \ terrainsampler.cxx terrainsampler.cxx \ - presets.cxx presets.cxx + presets.cxx presets.hxx INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/src diff --git a/src/Environment/environment.cxx b/src/Environment/environment.cxx index a27189b24..4e245554b 100644 --- a/src/Environment/environment.cxx +++ b/src/Environment/environment.cxx @@ -27,14 +27,9 @@ #include -#include -#include -#include #include -#include #include
-#include #include "environment.hxx" #include "atmosphere.hxx" @@ -472,9 +467,6 @@ FGEnvironment::get_wind_from_down_fps () const double FGEnvironment::get_turbulence_magnitude_norm () const { - if( sgEnviro.get_turbulence_enable_state() ) - if (fgGetBool("/environment/realwx/enabled")||fgGetBool("/environment/metar/valid")) - return sgEnviro.get_cloud_turbulence(); return turbulence_magnitude_norm; }