1
0
Fork 0

Bug #927 - flightplan XML loading.

This bug was caused by the code not tolerating missing navaids / waypoints. Update logic so missing navaids degenerate to basic waypoints without problem. Also tolerate present, but empty, runway properties - don't throw an exception by looking up empty identifiers.
This commit is contained in:
James Turner 2012-11-27 22:42:46 +00:00
parent fe1d04df8a
commit 6434163e65
2 changed files with 26 additions and 9 deletions

View file

@ -612,8 +612,9 @@ void FlightPlan::loadXMLRouteHeader(SGPropertyNode_ptr routeData)
string depIdent = dep->getStringValue("airport"); string depIdent = dep->getStringValue("airport");
setDeparture((FGAirport*) fgFindAirportID(depIdent)); setDeparture((FGAirport*) fgFindAirportID(depIdent));
if (_departure) { if (_departure) {
if (dep->hasChild("runway")) { string rwy(dep->getStringValue("runway"));
setDeparture(_departure->getRunwayByIdent(dep->getStringValue("runway"))); if (_departure->hasRunwayWithIdent(rwy)) {
setDeparture(_departure->getRunwayByIdent(rwy));
} }
if (dep->hasChild("sid")) { if (dep->hasChild("sid")) {
@ -628,8 +629,9 @@ void FlightPlan::loadXMLRouteHeader(SGPropertyNode_ptr routeData)
if (dst) { if (dst) {
setDestination((FGAirport*) fgFindAirportID(dst->getStringValue("airport"))); setDestination((FGAirport*) fgFindAirportID(dst->getStringValue("airport")));
if (_destination) { if (_destination) {
if (dst->hasChild("runway")) { string rwy(dst->getStringValue("runway"));
setDestination(_destination->getRunwayByIdent(dst->getStringValue("runway"))); if (_destination->hasRunwayWithIdent(rwy)) {
setDestination(_destination->getRunwayByIdent(rwy));
} }
if (dst->hasChild("star")) { if (dst->hasChild("star")) {
@ -709,18 +711,23 @@ WayptRef FlightPlan::parseVersion1XMLWaypt(SGPropertyNode* aWP)
} else { } else {
string nid = aWP->getStringValue("navid", ident.c_str()); string nid = aWP->getStringValue("navid", ident.c_str());
FGPositionedRef p = FGPositioned::findClosestWithIdent(nid, lastPos); FGPositionedRef p = FGPositioned::findClosestWithIdent(nid, lastPos);
if (!p) { SGGeod pos;
throw sg_io_exception("bad route file, unknown navid:" + nid);
if (p) {
pos = p->geod();
} else {
SG_LOG(SG_GENERAL, SG_WARN, "unknown navaid in flightplan:" << nid);
pos = SGGeod::fromDeg(aWP->getDoubleValue("longitude-deg"),
aWP->getDoubleValue("latitude-deg"));
} }
SGGeod pos(p->geod());
if (aWP->hasChild("offset-nm") && aWP->hasChild("offset-radial")) { if (aWP->hasChild("offset-nm") && aWP->hasChild("offset-radial")) {
double radialDeg = aWP->getDoubleValue("offset-radial"); double radialDeg = aWP->getDoubleValue("offset-radial");
// convert magnetic radial to a true radial! // convert magnetic radial to a true radial!
radialDeg += magvarDegAt(pos); radialDeg += magvarDegAt(pos);
double offsetNm = aWP->getDoubleValue("offset-nm"); double offsetNm = aWP->getDoubleValue("offset-nm");
double az2; double az2;
SGGeodesy::direct(p->geod(), radialDeg, offsetNm * SG_NM_TO_METER, pos, az2); SGGeodesy::direct(pos, radialDeg, offsetNm * SG_NM_TO_METER, pos, az2);
} }
w = new BasicWaypt(pos, ident, NULL); w = new BasicWaypt(pos, ident, NULL);

View file

@ -237,9 +237,19 @@ WayptRef Waypt::createFromProperties(RouteBase* aOwner, SGPropertyNode_ptr aProp
"Waypt::createFromProperties"); "Waypt::createFromProperties");
} }
try {
WayptRef nd(createInstance(aOwner, aProp->getStringValue("type"))); WayptRef nd(createInstance(aOwner, aProp->getStringValue("type")));
nd->initFromProperties(aProp); nd->initFromProperties(aProp);
return nd; return nd;
} catch (sg_exception& e) {
SG_LOG(SG_GENERAL, SG_WARN, "failed to create waypoint, trying basic:" << e.getMessage());
}
// if we failed to make the waypoint, try again making a basic waypoint.
// this handles the case where a navaid waypoint is missing, for example
WayptRef nd(new BasicWaypt(aOwner));
nd->initFromProperties(aProp);
return nd;
} }
void Waypt::saveAsNode(SGPropertyNode* n) const void Waypt::saveAsNode(SGPropertyNode* n) const