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;