FGRouteMgr::FGRouteMgr() :
_currentIndex(0),
input(fgGetNode( RM "input", true )),
- mirror(fgGetNode( RM "route", true ))
+ mirror(fgGetNode( RM "route", true )),
+ _departureWatcher(NULL),
+ _arrivalWatcher(NULL)
{
listener = new InputListener(this);
input->setStringValue("");
{
input->removeChangeListener(listener);
delete listener;
+ delete _departureWatcher;
+ delete _arrivalWatcher;
}
&FGRouteMgr::getDepartureName, NULL));
departure->setStringValue("runway", "");
+ delete _departureWatcher;
_departureWatcher = createWatcher(this, &FGRouteMgr::departureChanged);
_departureWatcher->watch(departure->getChild("runway"));
destination->tie("name", SGRawValueMethods<FGRouteMgr, const char*>(*this,
&FGRouteMgr::getDestinationName, NULL));
+ delete _arrivalWatcher;
_arrivalWatcher = createWatcher(this, &FGRouteMgr::arrivalChanged);
_arrivalWatcher->watch(destination->getChild("runway", 0, true));
totalDistance = fgGetNode(RM "total-distance", true);
totalDistance->setDoubleValue(0.0);
+ distanceToGo = fgGetNode(RM "distance-remaining-nm", true);
+ distanceToGo->setDoubleValue(0.0);
ete = fgGetNode(RM "ete", true);
ete->setDoubleValue(0.0);
}
SG_LOG(SG_AUTOPILOT, SG_INFO, "loaded initial waypoints:" << _route.size());
+ update_mirror();
}
- update_mirror();
weightOnWheels = fgGetNode("/gear/gear[0]/wow", true);
// check airbone flag agrees with presets
double distanceM;
boost::tie(courseDeg, distanceM) = curWpt->courseAndDistanceFrom(currentPos);
-// update wp0 / wp1 / wp-last for legacy users
+// update wp0 / wp1 / wp-last
wp0->setDoubleValue("dist", distanceM * SG_METER_TO_NM);
+ wp0->setDoubleValue("true-bearing-deg", courseDeg);
courseDeg -= magvar->getDoubleValue(); // expose magnetic bearing
wp0->setDoubleValue("bearing-deg", courseDeg);
setETAPropertyFromDistance(wp0->getChild("eta"), distanceM);
+ double totalPathDistance = totalDistance->getDoubleValue() * SG_NM_TO_METER;
double totalDistanceRemaining = distanceM; // distance to current waypoint
+ double pathDistance = cachedWaypointPathTotalDistance(_currentIndex);
+
+// total distance to go, is direct distance to wp0, plus the remaining
+// path distance from wp0
+ totalDistanceRemaining += (totalPathDistance - pathDistance);
+
+ wp0->setDoubleValue("distance-along-route-nm",
+ pathDistance * SG_METER_TO_NM);
+ wp0->setDoubleValue("remaining-distance-nm",
+ (totalPathDistance - pathDistance) * SG_METER_TO_NM);
Waypt* nextWpt = nextWaypt();
if (nextWpt) {
boost::tie(courseDeg, distanceM) = nextWpt->courseAndDistanceFrom(currentPos);
wp1->setDoubleValue("dist", distanceM * SG_METER_TO_NM);
+ wp1->setDoubleValue("true-bearing-deg", courseDeg);
courseDeg -= magvar->getDoubleValue(); // expose magnetic bearing
wp1->setDoubleValue("bearing-deg", courseDeg);
setETAPropertyFromDistance(wp1->getChild("eta"), distanceM);
- }
-
- Waypt* prev = curWpt;
- for (unsigned int i=_currentIndex + 1; i<_route.size(); ++i) {
- Waypt* w = _route[i];
- if (w->flag(WPT_DYNAMIC)) continue;
- totalDistanceRemaining += SGGeodesy::distanceM(prev->position(), w->position());
- prev = w;
-
+ double pathDistance = cachedWaypointPathTotalDistance(_currentIndex + 1);
+ wp1->setDoubleValue("distance-along-route-nm",
+ pathDistance * SG_METER_TO_NM);
+ wp1->setDoubleValue("remaining-distance-nm",
+ (totalPathDistance - pathDistance) * SG_METER_TO_NM);
}
+ distanceToGo->setDoubleValue(totalDistanceRemaining * SG_METER_TO_NM);
wpn->setDoubleValue("dist", totalDistanceRemaining * SG_METER_TO_NM);
ete->setDoubleValue(totalDistanceRemaining * SG_METER_TO_NM / groundSpeed * 3600.0);
setETAPropertyFromDistance(wpn->getChild("eta"), totalDistanceRemaining);
mirror->removeChildren("wp");
int num = numWaypts();
+ double totalDistanceEnroute = 0.0;
+
for (int i = 0; i < num; i++) {
Waypt* wp = _route[i];
SGPropertyNode *prop = mirror->getChild("wp", i, 1);
next->courseAndDistanceFrom(pos);
prop->setDoubleValue("leg-bearing-true-deg", crsDist.first);
prop->setDoubleValue("leg-distance-nm", crsDist.second * SG_METER_TO_NM);
+ prop->setDoubleValue("distance-along-route-nm", totalDistanceEnroute);
+ totalDistanceEnroute += crsDist.second * SG_METER_TO_NM;
}
if (wp->altitudeRestriction() != RESTRICT_NONE) {
if (rmDlg) {
rmDlg->updateValues();
}
+
+ if (_departure) {
+ departure->setDoubleValue("field-elevation-ft", _departure->getElevation());
+ }
+
+ if (_destination) {
+ destination->setDoubleValue("field-elevation-ft", _destination->getElevation());
+ }
+
+ totalDistance->setDoubleValue(totalDistanceEnroute);
+}
+
+double FGRouteMgr::cachedLegPathDistanceM(int index) const
+{
+ SGPropertyNode *prop = mirror->getChild("wp", index, 1);
+ return prop->getDoubleValue("leg-distance-nm") * SG_NM_TO_METER;
+}
+
+double FGRouteMgr::cachedWaypointPathTotalDistance(int index) const
+{
+ SGPropertyNode *prop = mirror->getChild("wp", index, 1);
+ return prop->getDoubleValue("distance-along-route-nm") * SG_NM_TO_METER;
}
// command interface /autopilot/route-manager/input:
SG_LOG(SG_IO, SG_INFO, "going to read flight-plan from:" << path.str());
+ bool Status = false;
try {
readProperties(path.str(), routeData);
} catch (sg_exception& ) {
// if XML parsing fails, the file might be simple textual list of waypoints
- return loadPlainTextRoute(path);
+ Status = loadPlainTextRoute(path);
+ routeData = 0;
}
-
- try {
- int version = routeData->getIntValue("version", 1);
- if (version == 1) {
- loadVersion1XMLRoute(routeData);
- } else if (version == 2) {
- loadVersion2XMLRoute(routeData);
- } else {
- throw sg_io_exception("unsupported XML route version");
- }
- return true;
- } catch (sg_exception& e) {
- SG_LOG(SG_IO, SG_ALERT, "Failed to load flight-plan '" << e.getOrigin()
- << "'. " << e.getMessage());
- return false;
+
+ if (routeData.valid())
+ {
+ try {
+ int version = routeData->getIntValue("version", 1);
+ if (version == 1) {
+ loadVersion1XMLRoute(routeData);
+ } else if (version == 2) {
+ loadVersion2XMLRoute(routeData);
+ } else {
+ throw sg_io_exception("unsupported XML route version");
+ }
+ Status = true;
+ } catch (sg_exception& e) {
+ SG_LOG(SG_IO, SG_ALERT, "Failed to load flight-plan '" << e.getOrigin()
+ << "'. " << e.getMessage());
+ Status = false;
+ }
}
+
+ update_mirror();
+
+ return Status;
}
void FGRouteMgr::loadXMLRouteHeader(SGPropertyNode_ptr routeData)