1
0
Fork 0

Change Via-from-string parsing

Previosu parse had embedded whitespace which is annoying
to parse in other places, switch to using backslash to
seperate terms, similar to how navdaid offsets are defined.
This commit is contained in:
James Turner 2022-01-14 15:18:59 +00:00
parent 395eb58d14
commit 9023a09739

View file

@ -99,24 +99,24 @@ WayptRef intersectionFromString(FGPositionedRef p1,
WayptRef viaFromString(const SGGeod& basePosition, const std::string& target) WayptRef viaFromString(const SGGeod& basePosition, const std::string& target)
{ {
assert(target.find("VIA ") == 0); assert(target.find("VIA-") == 0);
string_list pieces(simgear::strutils::split(target, "/")); string_list pieces(simgear::strutils::split(target.substr(4), "/"));
if ((pieces.size() != 4) || (pieces[2] != "TO")) { if (pieces.size() != 2) {
SG_LOG(SG_NAVAID, SG_WARN, "Malformed VIA specification string:" << target); SG_LOG(SG_NAVAID, SG_WARN, "Malformed VIA specification string:" << target);
return {}; return {};
} }
// TO navaid is pieces[3] // TO navaid is pieces[1]
FGPositionedRef nav = FGPositioned::findClosestWithIdent(pieces[3], basePosition, nullptr); FGPositionedRef nav = FGPositioned::findClosestWithIdent(pieces[1], basePosition, nullptr);
if (!nav) { if (!nav) {
SG_LOG(SG_NAVAID, SG_WARN, "TO navaid:" << pieces[3] << " unknown"); SG_LOG(SG_NAVAID, SG_WARN, "TO navaid:" << pieces[3] << " unknown");
return {}; return {};
} }
// airway ident is pieces[1] // airway ident is pieces[1]
AirwayRef airway = Airway::findByIdentAndNavaid(pieces[1], nav); AirwayRef airway = Airway::findByIdentAndNavaid(pieces[0], nav);
if (!airway) { if (!airway) {
SG_LOG(SG_NAVAID, SG_WARN, "Unknown airway:" << pieces[1]); SG_LOG(SG_NAVAID, SG_WARN, "Unknown airway:" << pieces[0]);
return {}; return {};
} }
@ -308,7 +308,11 @@ WayptRef Waypt::createFromProperties(RouteBase* aOwner, SGPropertyNode_ptr aProp
flightgear::AirwayRef via; flightgear::AirwayRef via;
if (aProp->hasChild("airway")) { if (aProp->hasChild("airway")) {
const auto level = static_cast<flightgear::Airway::Level>(aProp->getIntValue("network")); auto level = Airway::Both;
if (aProp->hasValue("network")) {
level = static_cast<flightgear::Airway::Level>(aProp->getIntValue("network"));
}
via = flightgear::Airway::findByIdent(aProp->getStringValue("airway"), level); via = flightgear::Airway::findByIdent(aProp->getStringValue("airway"), level);
if (via) { if (via) {
// override owner if we are from an airway // override owner if we are from an airway
@ -398,7 +402,7 @@ WayptRef Waypt::createFromString(RouteBase* aOwner, const std::string& s, const
if (wpt) { if (wpt) {
// already handled in the lat/lon test above // already handled in the lat/lon test above
} else if (target.find("VIA ") == 0) { } else if (target.find("VIA-") == 0) {
wpt = viaFromString(vicinity, target); wpt = viaFromString(vicinity, target);
} else { } else {
FGPositioned::TypeFilter filter({FGPositioned::Type::AIRPORT, FGPositioned::Type::HELIPORT, FGPositioned::TypeFilter filter({FGPositioned::Type::AIRPORT, FGPositioned::Type::HELIPORT,