From ff91fec1bb4b59dc2a7084de2a5ab0469abb1f3e Mon Sep 17 00:00:00 2001 From: James Turner Date: Mon, 7 May 2012 23:48:56 +0100 Subject: [PATCH] Fix various route-manager issues reported by Hyde. --- src/Autopilot/route_mgr.cxx | 48 +++++++++++++++++++++++++++++-------- src/Autopilot/route_mgr.hxx | 5 +++- src/GUI/WaypointList.cxx | 21 ++++++++++++---- 3 files changed, 58 insertions(+), 16 deletions(-) diff --git a/src/Autopilot/route_mgr.cxx b/src/Autopilot/route_mgr.cxx index 964f1354c..6164c6474 100644 --- a/src/Autopilot/route_mgr.cxx +++ b/src/Autopilot/route_mgr.cxx @@ -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 @@ -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) diff --git a/src/Autopilot/route_mgr.hxx b/src/Autopilot/route_mgr.hxx index 840ec3160..bb885c7df 100644 --- a/src/Autopilot/route_mgr.hxx +++ b/src/Autopilot/route_mgr.hxx @@ -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; diff --git a/src/GUI/WaypointList.cxx b/src/GUI/WaypointList.cxx index 57b741169..01911c989 100644 --- a/src/GUI/WaypointList.cxx +++ b/src/GUI/WaypointList.cxx @@ -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(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) { -- 2.39.5