- string target(boost::to_upper_copy(tgt));
- WayptRef wpt;
-
-// extract altitude
- double altFt = cruise->getDoubleValue("altitude-ft");
- RouteRestriction altSetting = RESTRICT_NONE;
-
- size_t pos = target.find( '@' );
- if ( pos != string::npos ) {
- altFt = atof( target.c_str() + pos + 1 );
- target = target.substr( 0, pos );
- if ( !strcmp(fgGetString("/sim/startup/units"), "meter") )
- altFt *= SG_METER_TO_FEET;
- altSetting = RESTRICT_AT;
- }
-
-// check for lon,lat
- pos = target.find( ',' );
- if ( pos != string::npos ) {
- double lon = atof( target.substr(0, pos).c_str());
- double lat = atof( target.c_str() + pos + 1);
- char buf[32];
- char ew = (lon < 0.0) ? 'W' : 'E';
- char ns = (lat < 0.0) ? 'S' : 'N';
- snprintf(buf, 32, "%c%03d%c%03d", ew, (int) fabs(lon), ns, (int)fabs(lat));
-
- wpt = new BasicWaypt(SGGeod::fromDeg(lon, lat), buf, NULL);
- if (altSetting != RESTRICT_NONE) {
- wpt->setAltitude(altFt, altSetting);
- }
- return wpt;
- }
-
- SGGeod basePosition;
- if (_route.empty()) {
- // route is empty, use current position
- basePosition = SGGeod::fromDeg(lon->getDoubleValue(), lat->getDoubleValue());
- } else {
- basePosition = _route.back()->position();
- }
-
- string_list pieces(simgear::strutils::split(target, "/"));
- FGPositionedRef p = FGPositioned::findClosestWithIdent(pieces.front(), basePosition);
- if (!p) {
- SG_LOG( SG_AUTOPILOT, SG_INFO, "Unable to find FGPositioned with ident:" << pieces.front());
- return NULL;
- }
-
- if (pieces.size() == 1) {
- wpt = new NavaidWaypoint(p, NULL);
- } else if (pieces.size() == 3) {
- // navaid/radial/distance-nm notation
- double radial = atof(pieces[1].c_str()),
- distanceNm = atof(pieces[2].c_str());
- radial += magvar->getDoubleValue(); // convert to true bearing
- wpt = new OffsetNavaidWaypoint(p, NULL, radial, distanceNm);
- } else if (pieces.size() == 2) {
- FGAirport* apt = dynamic_cast<FGAirport*>(p.ptr());
- if (!apt) {
- SG_LOG(SG_AUTOPILOT, SG_INFO, "Waypoint is not an airport:" << pieces.front());
- return NULL;
- }
-
- if (!apt->hasRunwayWithIdent(pieces[1])) {
- SG_LOG(SG_AUTOPILOT, SG_INFO, "No runway: " << pieces[1] << " at " << pieces[0]);
- return NULL;
- }
-
- FGRunway* runway = apt->getRunwayByIdent(pieces[1]);
- wpt = new NavaidWaypoint(runway, NULL);
- } else if (pieces.size() == 4) {
- // navid/radial/navid/radial notation
- FGPositionedRef p2 = FGPositioned::findClosestWithIdent(pieces[2], basePosition);
- if (!p2) {
- SG_LOG( SG_AUTOPILOT, SG_INFO, "Unable to find FGPositioned with ident:" << pieces[2]);
- return NULL;
- }