}
if (checkFinished()) {
- // maybe we're done
+ endOfRoute();
}
// basic course/distance information
Waypt* FGRouteMgr::wayptAtIndex(int index) const
{
- if (_plan) {
- FlightPlan::Leg* leg = _plan->legAtIndex(index);
- if (leg) {
- return leg->waypoint();
- }
+ if (!_plan) {
+ throw sg_range_exception("wayptAtindex: no flightplan");
}
- return NULL;
+ return _plan->legAtIndex(index)->waypoint();
}
int FGRouteMgr::numLegs() const
void FGRouteMgr::waypointsChanged()
{
update_mirror();
- _edited->fireValueChanged();
- checkFinished();
+ _edited->fireValueChanged();
+
+// removing waypoints, deactivate if we hit the end.
+ if (currentIndex() >= numLegs()) {
+ endOfRoute();
+ }
}
// mirror internal route to the property system for inspection by other subsystems
return;
}
- if (checkFinished()) {
+ int nextIndex = _plan->currentIndex() + 1;
+ if (nextIndex >= _plan->numLegs()) {
+ SG_LOG(SG_AUTOPILOT, SG_INFO, "sequenced on final leg, deactivating route");
+ endOfRoute();
return;
}
-
- _plan->setCurrentIndex(_plan->currentIndex() + 1);
+
+ _plan->setCurrentIndex(nextIndex);
+}
+
+void FGRouteMgr::endOfRoute()
+{
+ SG_LOG(SG_AUTOPILOT, SG_INFO, "reached end of active route");
+ _finished->fireValueChanged();
+ active->setBoolValue(false);
}
bool FGRouteMgr::checkFinished()
done = weightOnWheels->getBoolValue() && (gs < 25);
}
-// 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);
+ SG_LOG(SG_AUTOPILOT, SG_INFO, "checkFinished: on the ground on destination runway, we're done");
}
return done;
void GPS::computeTurnData()
{
_computeTurnData = false;
- if (_mode != "leg") { // and approach modes in the future
+ int nextIndex = _routeMgr->currentIndex() + 1;
+ if ((_mode != "leg") || (nextIndex >= _routeMgr->numWaypts())) {
_anticipateTurn = false;
return;
}
- WayptRef next = _routeMgr->wayptAtIndex(_routeMgr->currentIndex() + 1);
- if (!next || next->flag(WPT_DYNAMIC)) {
- _anticipateTurn = false;
- return;
- }
-
- if (!_config.turnAnticipationEnabled()) {
+ WayptRef next = _routeMgr->wayptAtIndex(nextIndex);
+ if (next->flag(WPT_DYNAMIC) || !_config.turnAnticipationEnabled()) {
_anticipateTurn = false;
return;
}