]> git.mxchange.org Git - flightgear.git/commitdiff
Expand route-manager waypoint info, to support smarter FMS functions.
authorJames Turner <zakalawe@mac.com>
Thu, 20 Jan 2011 00:39:42 +0000 (00:39 +0000)
committerJames Turner <zakalawe@mac.com>
Thu, 20 Jan 2011 00:39:42 +0000 (00:39 +0000)
src/Autopilot/route_mgr.cxx
src/GUI/MapWidget.cxx
src/GUI/WaypointList.cxx
src/Navaids/route.cxx
src/Navaids/route.hxx

index bcb5895acc227b2e9f4bd1a8a3efd43ba34cad18..57f7d5d5c7c3175ab1c10e5fc5cf7809c6d063d6 100644 (file)
@@ -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<double, double> 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());
     }
     
index 0b786f5a34d3538c68ce25732a582d9900936b86..858eea1a1c9cbed75fa890caeb7824e6b2753368 100644 (file)
@@ -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";
     }
        
index 31c5e480c57ad46ddbd909fb3c10109b0188849f..b014d1cd3bc417c9a6ca4f1639c67fa8b12a02f0 100644 (file)
@@ -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);
   }
index 580c87c18170d2c809ac2323a6bfbb9f008c6d6d..cfe25de40b40ac0753d9197cf09519ff9f962164 100644 (file)
@@ -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<double, double>
 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);
   }
 }
 
index a23d728a70e8c4384d94af5ab33980cd75b4e443..b0375d15c980c68d00b76ce255bf5ee4516d6dd4 100644 (file)
@@ -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: