]> git.mxchange.org Git - flightgear.git/blobdiff - src/Navaids/route.cxx
Expose a radio function (receiveBeacon) to the Nasal subsystem
[flightgear.git] / src / Navaids / route.cxx
index cfe25de40b40ac0753d9197cf09519ff9f962164..6a32f112b9413e2c6f4b76d0130648b2f5a20aad 100644 (file)
 #include <simgear/structure/exception.hxx>
 #include <simgear/xml/easyxml.hxx>
 #include <simgear/misc/sg_path.hxx>
+#include <simgear/magvar/magvar.hxx>
+#include <simgear/timing/sg_time.hxx>
 
 // FlightGear
+#include <Main/globals.hxx>
 #include <Navaids/procedure.hxx>
 #include <Navaids/waypoint.hxx>
 #include <Airports/simple.hxx>
@@ -49,16 +52,23 @@ 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)
 {
 }
 
+Waypt::~Waypt()
+{
+}
+  
 std::string Waypt::ident() const
 {
   return "";
@@ -127,6 +137,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