// auto_gui.cxx -- autopilot gui interface
//
// Written by Norman Vine <nhv@cape.com>
-// Arranged by Curt Olson <curt@flightgear.org>
+// Arranged by Curt Olson <http://www.flightgear.org/~curt>
//
// Copyright (C) 1998 - 2000
//
#include <Aircraft/aircraft.hxx>
#include <FDM/flight.hxx>
-#include <Controls/controls.hxx>
#include <Scenery/scenery.hxx>
#include <simgear/constants.h>
#include <Main/globals.hxx>
#include <Main/fg_props.hxx>
#include <Navaids/fixlist.hxx>
+#include <Navaids/navlist.hxx>
+#include <Navaids/navrecord.hxx>
#include "auto_gui.hxx"
#include "route_mgr.hxx"
/* add new waypoint (either from above popup window 'ok button or telnet session) */
-int NewWaypoint( string Tgt_Alt )
+int NewWaypoint( const string& Tgt_Alt )
{
string TgtAptId;
FGAirport a;
sprintf( NewTgtAirportId, "%s", TgtAptId.c_str() );
- SGWayPoint wp( a.longitude, a.latitude, alt,
+ SGWayPoint wp( a.getLongitude(), a.getLatitude(), alt,
SGWayPoint::WGS84, TgtAptId );
rm->add_waypoint( wp );
return 1;
- } else if ( current_fixlist->query( TgtAptId, &f ) ) {
+ } else if ( globals->get_fixlist()->query( TgtAptId, &f ) ) {
SG_LOG( SG_GENERAL, SG_INFO,
"Adding waypoint (fix) = " << TgtAptId );
fgSetString( "/autopilot/locks/heading", "true-heading-hold" );
return 2;
} else {
- return 0;
+ // Try finding a nav matching the ID
+ double lat, lon;
+ // The base lon/lat are determined by the last WP,
+ // or the current pos if the WP list is empty.
+ const int wps = rm->size();
+ if (wps > 0) {
+ SGWayPoint wp = rm->get_waypoint(wps-1);
+ lat = wp.get_target_lat();
+ lon = wp.get_target_lon();
+ }
+ else {
+ lat = fgGetNode("/position/latitude-deg")->getDoubleValue();
+ lon = fgGetNode("/position/longitude-deg")->getDoubleValue();
+ }
+
+ lat *= SGD_DEGREES_TO_RADIANS;
+ lon *= SGD_DEGREES_TO_RADIANS;
+
+ SG_LOG( SG_GENERAL, SG_INFO,
+ "Looking for nav " << TgtAptId << " at " << lon << " " << lat);
+ if (FGNavRecord* nav =
+ globals->get_navlist()->findByIdent(TgtAptId.c_str(), lon, lat))
+ {
+ SG_LOG( SG_GENERAL, SG_INFO,
+ "Adding waypoint (nav) = " << TgtAptId );
+
+ sprintf( NewTgtAirportId, "%s", TgtAptId.c_str() );
+
+ SGWayPoint wp( nav->get_lon(), nav->get_lat(), alt,
+ SGWayPoint::WGS84, TgtAptId );
+ rm->add_waypoint( wp );
+
+ /* and turn on the autopilot */
+ fgSetString( "/autopilot/locks/heading", "true-heading-hold" );
+ return 3;
+ }
+ else {
+ return 0;
+ }
}
}
TgtAptDialogWPList = new puListBox ( 50, 130, 300, 320 ) ;
TgtAptDialogWPList -> setLabel ( "Flight Plan" );
- TgtAptDialogWPList -> setLabelPlace ( PUPLACE_ABOVE ) ;
+ TgtAptDialogWPList -> setLabelPlace ( PUPLACE_TOP_LEFT ) ;
TgtAptDialogWPList -> setStyle ( -PUSTYLE_SMALL_SHADED ) ;
TgtAptDialogWPList -> setValue ( 0 ) ;
TgtAptDialogInput = new puInput (50, 70, 300, 100);
TgtAptDialogInput -> setLabel ( NewTgtAirportLabel );
- TgtAptDialogInput -> setLabelPlace ( PUPLACE_ABOVE ) ;
+ TgtAptDialogInput -> setLabelPlace ( PUPLACE_TOP_LEFT ) ;
TgtAptDialogInput -> setValue (NewTgtAirportId);
TgtAptDialogInput -> acceptInput();