]> git.mxchange.org Git - flightgear.git/commitdiff
Fix various route-manager issues reported by Hyde.
authorJames Turner <zakalawe@mac.com>
Mon, 7 May 2012 22:48:56 +0000 (23:48 +0100)
committerJames Turner <zakalawe@mac.com>
Mon, 7 May 2012 22:48:56 +0000 (23:48 +0100)
src/Autopilot/route_mgr.cxx
src/Autopilot/route_mgr.hxx
src/GUI/WaypointList.cxx

index 964f1354c94246227f1205af25d5cb126d1e3061..6164c64740edccb7a932ebc1af3eeeb141d51bcd 100644 (file)
@@ -312,6 +312,7 @@ void FGRouteMgr::init() {
     
   _edited = fgGetNode(RM "signals/edited", true);
   _finished = fgGetNode(RM "signals/finished", true);
+  _flightplanChanged = fgGetNode(RM "signals/flightplan-changed", true);
   
   _currentWpt = fgGetNode(RM "current-wp", true);
   _currentWpt->tie(SGRawValueMethods<FGRouteMgr, int>
@@ -364,6 +365,8 @@ void FGRouteMgr::postinit()
   }
 
   weightOnWheels = fgGetNode("/gear/gear[0]/wow", true);
+  groundSpeed = fgGetNode("/velocities/groundspeed-kt", true);
+  
   // check airbone flag agrees with presets
 }
 
@@ -415,6 +418,8 @@ void FGRouteMgr::setFlightPlan(FlightPlan* plan)
   _plan = plan;
   _plan->setDelegate(this);
   
+  _flightplanChanged->fireValueChanged();
+  
 // fire all the callbacks!
   departureChanged();
   arrivalChanged();
@@ -428,12 +433,18 @@ void FGRouteMgr::update( double dt )
     return; // paused, nothing to do here
   }
   
-  double groundSpeed = fgGetDouble("/velocities/groundspeed-kt", 0.0);
+  double gs = groundSpeed->getDoubleValue();
   if (airborne->getBoolValue()) {
     time_t now = time(NULL);
     elapsedFlightTime->setDoubleValue(difftime(now, _takeoffTime));
+    
+    if (weightOnWheels->getBoolValue()) {
+      // touch down
+      destination->setIntValue("touchdown-time", time(NULL));
+      airborne->setBoolValue(false);
+    }
   } else { // not airborne
-    if (weightOnWheels->getBoolValue() || (groundSpeed < 40)) {
+    if (weightOnWheels->getBoolValue() || (gs < 40)) {
       return;
     }
     
@@ -446,6 +457,10 @@ void FGRouteMgr::update( double dt )
     return;
   }
 
+  if (checkFinished()) {
+    // maybe we're done
+  }
+  
 // basic course/distance information
   SGGeod currentPos = globals->get_aircraft_position();
 
@@ -494,7 +509,7 @@ void FGRouteMgr::update( double dt )
   
   distanceToGo->setDoubleValue(totalDistanceRemaining);
   wpn->setDoubleValue("dist", totalDistanceRemaining);
-  ete->setDoubleValue(totalDistanceRemaining / groundSpeed * 3600.0);
+  ete->setDoubleValue(totalDistanceRemaining / gs * 3600.0);
   setETAPropertyFromDistance(wpn->getChild("eta"), totalDistanceRemaining);
 }
 
@@ -686,7 +701,7 @@ void FGRouteMgr::arrivalChanged()
 
 void FGRouteMgr::buildArrival(WayptRef enroute, WayptVec& wps)
 {
-  FGAirportRef apt = _plan->departureAirport();
+  FGAirportRef apt = _plan->destinationAirport();
   if (!apt.valid()) {
     return;
   }
@@ -935,14 +950,27 @@ bool FGRouteMgr::checkFinished()
     return true;
   }
   
-  if (_plan->currentIndex() < _plan->numLegs()) {
-    return false;
+  bool done = false;
+// done if we're stopped on the destination runway 
+  if (_plan->currentLeg() && 
+      (_plan->currentLeg()->waypoint()->source() == _plan->destinationRunway())) 
+  {
+    double gs = groundSpeed->getDoubleValue();
+    done = weightOnWheels->getBoolValue() && (gs < 25);
   }
   
-  SG_LOG(SG_AUTOPILOT, SG_INFO, "reached end of active route");
-  _finished->fireValueChanged();
-  active->setBoolValue(false);
-  return true;
+// also done if we hit the final waypoint
+  if (_plan->currentIndex() >= _plan->numLegs()) {
+    done = true;
+  }
+  
+  if (done) {
+    SG_LOG(SG_AUTOPILOT, SG_INFO, "reached end of active route");
+    _finished->fireValueChanged();
+    active->setBoolValue(false);
+  }
+  
+  return done;
 }
 
 void FGRouteMgr::jumpToIndex(int index)
index 840ec31609a44fcc9d79bd01c8f60dd172c149d6..bb885c7df30b96de86276cb50c02a8e580a5624f 100644 (file)
@@ -169,6 +169,8 @@ private:
      */
     SGPropertyNode_ptr _finished;
     
+    SGPropertyNode_ptr _flightplanChanged;
+  
     void setETAPropertyFromDistance(SGPropertyNode_ptr aProp, double aDistance);
     
     /**
@@ -187,7 +189,8 @@ private:
 
     SGPropertyNode_ptr input;
     SGPropertyNode_ptr weightOnWheels;
-    
+    SGPropertyNode_ptr groundSpeed;
+  
     InputListener *listener;
     SGPropertyNode_ptr mirror;    
   
index 57b741169d49ff9617ac9460f85829d0b9d68c7c..01911c989bb41c8d801c0104d206347f72fd965a 100644 (file)
@@ -46,13 +46,17 @@ public:
     _fp(fp)
   {    
     SGPropertyNode* routeEdited = fgGetNode("/autopilot/route-manager/signals/edited", true);
+    SGPropertyNode* flightplanChanged = fgGetNode("/autopilot/route-manager/signals/flightplan-changed", true);
     routeEdited->addChangeListener(this);
+    flightplanChanged->addChangeListener(this);
   }
   
   ~FlightPlanWaypointModel()
   {
     SGPropertyNode* routeEdited = fgGetNode("/autopilot/route-manager/signals/edited", true);
+    SGPropertyNode* flightplanChanged = fgGetNode("/autopilot/route-manager/signals/flightplan-changed", true);
     routeEdited->removeChangeListener(this);
+    flightplanChanged->removeChangeListener(this);
   }
   
 // implement WaypointList::Model
@@ -108,8 +112,15 @@ public:
 // implement SGPropertyChangeListener
   void valueChanged(SGPropertyNode *prop)
   {
-    if (_cb) {
-      (*_cb)();
+    if (prop->getNameString() == "edited") {
+      if (_cb) {
+        (*_cb)();
+      }
+    }
+    
+    if (prop->getNameString() == "flightplan-changed") {
+      _fp = 
+        static_cast<FGRouteMgr*>(globals->get_subsystem("route-manager"))->flightPlan();
     }
   }
 private:
@@ -402,12 +413,12 @@ void WaypointList::drawRow(int dx, int dy, int rowIndex, int y)
   if (wp->flag(WPT_MISS)) {
     drawBox = true;
     puSetColor(col, 1.0, 0.0, 0.0, 0.3);  // red
-  } else if (wp->flag(WPT_ARRIVAL)) {
+  } else if (wp->flag(WPT_ARRIVAL) || wp->flag(WPT_DEPARTURE)) {
     drawBox = true;
     puSetColor(col, 0.0, 0.0, 0.0, 0.3);
-  } else if (wp->flag(WPT_DEPARTURE)) {
+  } else if (wp->flag(WPT_APPROACH)) {
     drawBox = true;
-    puSetColor(col, 0.0, 0.0, 0.0, 0.3);
+    puSetColor(col, 0.0, 0.0, 0.1, 0.3);
   }
   
   if (isDragSource) {