// 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 "newauto.hxx"
+#include "route_mgr.hxx"
+#include "xmlauto.hxx"
SG_USING_STD(string);
#define mySlider puSlider
// Climb speed constants
-const double min_climb = 70.0; // kts
-const double best_climb = 75.0; // kts
-const double ideal_climb_rate = 500.0; // fpm
+// const double min_climb = 70.0; // kts
+// const double best_climb = 75.0; // kts
+// const double ideal_climb_rate = 500.0; // fpm
/// These statics will eventually go into the class
/// they are just here while I am experimenting -- NHV :-)
// AutoPilot Gain Adjuster members
-static double MaxRollAdjust; // MaxRollAdjust = 2 * APData->MaxRoll;
-static double RollOutAdjust; // RollOutAdjust = 2 * APData->RollOut;
-static double MaxAileronAdjust; // MaxAileronAdjust = 2 * APData->MaxAileron;
-static double RollOutSmoothAdjust; // RollOutSmoothAdjust = 2 * APData->RollOutSmooth;
-
-static float MaxRollValue; // 0.1 -> 1.0
-static float RollOutValue;
-static float MaxAileronValue;
-static float RollOutSmoothValue;
-
-static float TmpMaxRollValue; // for cancel operation
-static float TmpRollOutValue;
-static float TmpMaxAileronValue;
-static float TmpRollOutSmoothValue;
-
-static puDialogBox *APAdjustDialog;
-static puFrame *APAdjustFrame;
-static puText *APAdjustDialogMessage;
-static puFont APAdjustLegendFont;
-static puFont APAdjustLabelFont;
-
-static puOneShot *APAdjustOkButton;
-static puOneShot *APAdjustResetButton;
-static puOneShot *APAdjustCancelButton;
-
-//static puButton *APAdjustDragButton;
-
-static puText *APAdjustMaxRollTitle;
-static puText *APAdjustRollOutTitle;
-static puText *APAdjustMaxAileronTitle;
-static puText *APAdjustRollOutSmoothTitle;
-
-static puText *APAdjustMaxAileronText;
-static puText *APAdjustMaxRollText;
-static puText *APAdjustRollOutText;
-static puText *APAdjustRollOutSmoothText;
-
-static mySlider *APAdjustHS0;
-static mySlider *APAdjustHS1;
-static mySlider *APAdjustHS2;
-static mySlider *APAdjustHS3;
-
-static char SliderText[ 4 ][ 8 ];
+// static double MaxRollAdjust; // MaxRollAdjust = 2 * APData->MaxRoll;
+// static double RollOutAdjust; // RollOutAdjust = 2 * APData->RollOut;
+// static double MaxAileronAdjust; // MaxAileronAdjust = 2 * APData->MaxAileron;
+// static double RollOutSmoothAdjust; // RollOutSmoothAdjust = 2 * APData->RollOutSmooth;
+
+// static float MaxRollValue; // 0.1 -> 1.0
+// static float RollOutValue;
+// static float MaxAileronValue;
+// static float RollOutSmoothValue;
+
+// static float TmpMaxRollValue; // for cancel operation
+// static float TmpRollOutValue;
+// static float TmpMaxAileronValue;
+// static float TmpRollOutSmoothValue;
+
+// static puDialogBox *APAdjustDialog;
+// static puFrame *APAdjustFrame;
+// static puText *APAdjustDialogMessage;
+// static puFont APAdjustLegendFont;
+// static puFont APAdjustLabelFont;
+
+// static puOneShot *APAdjustOkButton;
+// static puOneShot *APAdjustResetButton;
+// static puOneShot *APAdjustCancelButton;
+
+// static puButton *APAdjustDragButton;
+
+// static puText *APAdjustMaxRollTitle;
+// static puText *APAdjustRollOutTitle;
+// static puText *APAdjustMaxAileronTitle;
+// static puText *APAdjustRollOutSmoothTitle;
+
+// static puText *APAdjustMaxAileronText;
+// static puText *APAdjustMaxRollText;
+// static puText *APAdjustRollOutText;
+// static puText *APAdjustRollOutSmoothText;
+
+// static mySlider *APAdjustHS0;
+// static mySlider *APAdjustHS1;
+// static mySlider *APAdjustHS2;
+// static mySlider *APAdjustHS3;
+
+// static char SliderText[ 4 ][ 8 ];
///////// AutoPilot New Heading Dialog
// These statics should disapear when this is a class
static puDialogBox *TgtAptDialog = 0;
static puFrame *TgtAptDialogFrame = 0;
-static puText *TgtAptDialogMessage = 0;
+// static puText *TgtAptDialogMessage = 0;
static puInput *TgtAptDialogInput = 0;
+static puListBox *TgtAptDialogWPList = 0;
+static puSlider *TgtAptDialogSlider = 0;
+static puArrowButton *TgtAptDialogUPArrow = 0;
+static puArrowButton *TgtAptDialogDNArrow = 0;
+static char** WPList;
+static int WPListsize;
static char NewTgtAirportId[16];
-static char NewTgtAirportLabel[] = "Enter New TgtAirport ID";
+static char NewTgtAirportLabel[] = "New Apt/Fix ID";
static puOneShot *TgtAptDialogOkButton = 0;
static puOneShot *TgtAptDialogCancelButton = 0;
char WordBuf[64];
char *cptr = s;
char *WordBufPtr = WordBuf;
-
if (*cptr == '+')
cptr++;
if (*cptr == '-') {
if( strlen(c) ) {
double NewHeading;
- if( scan_number( c, &NewHeading ) )
- {
- if ( !current_autopilot->get_HeadingEnabled() ) {
- current_autopilot->set_HeadingEnabled( true );
- }
- current_autopilot->HeadingSet( NewHeading );
- } else {
- error = 1;
- s = c;
- s += " is not a valid number.";
- }
+ if( scan_number( c, &NewHeading ) ) {
+ fgSetString( "/autopilot/locks/heading", "dg-heading-hold" );
+ fgSetDouble( "/autopilot/settings/heading-bug-deg",
+ NewHeading );
+ } else {
+ error = 1;
+ s = c;
+ s += " is not a valid number.";
+ }
}
ApHeadingDialog_Cancel(me);
- if( error ) mkDialog(s.c_str());
+ if ( error ) mkDialog(s.c_str());
}
void NewHeading(puObject *cb)
{
// string ApHeadingLabel( "Enter New Heading" );
// ApHeadingDialogMessage -> setLabel(ApHeadingLabel.c_str());
+ float heading = fgGetDouble( "/autopilot/settings/heading-bug-deg" );
+ while ( heading < 0.0 ) { heading += 360.0; }
+ ApHeadingDialogInput -> setValue ( heading );
ApHeadingDialogInput -> acceptInput();
FG_PUSH_PUI_DIALOG( ApHeadingDialog );
}
char *c;
ApAltitudeDialogInput->getValue( &c );
- if( strlen( c ) ) {
+ if ( strlen( c ) ) {
double NewAltitude;
- if( scan_number( c, &NewAltitude) )
- {
- if ( !current_autopilot->get_AltitudeEnabled() ) {
- current_autopilot->set_AltitudeEnabled( true );
- }
- current_autopilot->AltitudeSet( NewAltitude );
- } else {
- error = 1;
- s = c;
- s += " is not a valid number.";
- }
+ if ( scan_number( c, &NewAltitude) ) {
+ fgSetString( "/autopilot/locks/altitude", "altitude-hold" );
+ fgSetDouble( "/autopilot/settings/altitude-ft", NewAltitude );
+ } else {
+ error = 1;
+ s = c;
+ s += " is not a valid number.";
+ }
}
ApAltitudeDialog_Cancel(me);
if( error ) mkDialog(s.c_str());
void NewAltitude(puObject *cb)
{
+ float altitude = fgGetDouble("/autopilot/settings/altitude-ft")
+ * SG_METER_TO_FEET;
+ ApAltitudeDialogInput -> setValue( altitude );
ApAltitudeDialogInput -> acceptInput();
FG_PUSH_PUI_DIALOG( ApAltitudeDialog );
}
float alt = cur_fdm_state->get_Altitude();
- if ( fgGetString("/sim/startup/units") == "meters") {
+ if ( !strcmp(fgGetString("/sim/startup/units"), "meters")) {
alt *= SG_FEET_TO_METER;
}
}
+#if 0
static void maxroll_adj( puObject *hs ) {
float val ;
hs-> getValue ( &val ) ;
SG_CLAMP_RANGE ( val, 0.1f, 1.0f ) ;
// printf ( "maxroll_adj( %p ) %f %f\n", hs, val, MaxRollAdjust * val ) ;
- current_autopilot->set_MaxRoll( MaxRollAdjust * val );
- sprintf( SliderText[ 0 ], "%05.2f", current_autopilot->get_MaxRoll() );
+ fgSetDouble( "/autopilot/config/max-roll-deg", MaxRollAdjust * val );
+ sprintf( SliderText[ 0 ], "%05.2f",
+ fgGetDouble("/autopilot/config/max-roll-deg") );
APAdjustMaxRollText -> setLabel ( SliderText[ 0 ] ) ;
}
hs-> getValue ( &val ) ;
SG_CLAMP_RANGE ( val, 0.1f, 1.0f ) ;
// printf ( "rollout_adj( %p ) %f %f\n", hs, val, RollOutAdjust * val ) ;
- current_autopilot->set_RollOut( RollOutAdjust * val );
- sprintf( SliderText[ 1 ], "%05.2f", current_autopilot->get_RollOut() );
+ fgSetDouble( "/autopilot/config/roll-out-deg", RollOutAdjust * val );
+ sprintf( SliderText[ 1 ], "%05.2f",
+ fgGetDouble("/autopilot/config/roll-out-deg") );
APAdjustRollOutText -> setLabel ( SliderText[ 1 ] );
}
hs-> getValue ( &val ) ;
SG_CLAMP_RANGE ( val, 0.1f, 1.0f ) ;
// printf ( "maxaileron_adj( %p ) %f %f\n", hs, val, MaxAileronAdjust * val ) ;
- current_autopilot->set_MaxAileron( MaxAileronAdjust * val );
- sprintf( SliderText[ 3 ], "%05.2f", current_autopilot->get_MaxAileron() );
+ fgSetDouble( "/autopilot/config/max-aileron", MaxAileronAdjust * val );
+ sprintf( SliderText[ 3 ], "%05.2f",
+ fgGetDouble("/autopilot/config/max-aileron") );
APAdjustMaxAileronText -> setLabel ( SliderText[ 3 ] );
}
hs -> getValue ( &val ) ;
SG_CLAMP_RANGE ( val, 0.1f, 1.0f ) ;
// printf ( "rolloutsmooth_adj( %p ) %f %f\n", hs, val, RollOutSmoothAdjust * val ) ;
- current_autopilot->set_RollOutSmooth( RollOutSmoothAdjust * val );
- sprintf( SliderText[ 2 ], "%5.2f", current_autopilot->get_RollOutSmooth() );
+ fgSetDouble( "/autopilot/config/roll-out-smooth-deg",
+ RollOutSmoothAdjust * val );
+ sprintf( SliderText[ 2 ], "%5.2f",
+ fgGetDouble("/autopilot/config/roll-out-smooth-deg") );
APAdjustRollOutSmoothText-> setLabel ( SliderText[ 2 ] );
}
}
void cancelAPAdjust( puObject *self ) {
- current_autopilot->set_MaxRoll( TmpMaxRollValue );
- current_autopilot->set_RollOut( TmpRollOutValue );
- current_autopilot->set_MaxAileron( TmpMaxAileronValue );
- current_autopilot->set_RollOutSmooth( TmpRollOutSmoothValue );
+ fgSetDouble( "/autopilot/config/max-roll-deg", TmpMaxRollValue );
+ fgSetDouble( "/autopilot/config/roll-out-deg", TmpRollOutValue );
+ fgSetDouble( "/autopilot/config/max-aileron", TmpMaxAileronValue );
+ fgSetDouble( "/autopilot/config/roll-out-smooth-deg",
+ TmpRollOutSmoothValue );
goAwayAPAdjust(self);
}
void resetAPAdjust( puObject *self ) {
- current_autopilot->set_MaxRoll( MaxRollAdjust / 2 );
- current_autopilot->set_RollOut( RollOutAdjust / 2 );
- current_autopilot->set_MaxAileron( MaxAileronAdjust / 2 );
- current_autopilot->set_RollOutSmooth( RollOutSmoothAdjust / 2 );
+ fgSetDouble( "/autopilot/config/max-roll-deg", MaxRollAdjust / 2 );
+ fgSetDouble( "/autopilot/config/roll-out-deg", RollOutAdjust / 2 );
+ fgSetDouble( "/autopilot/config/max-aileron", MaxAileronAdjust / 2 );
+ fgSetDouble( "/autopilot/config/roll-out-smooth-deg",
+ RollOutSmoothAdjust / 2 );
FG_POP_PUI_DIALOG( APAdjustDialog );
}
void fgAPAdjust( puObject *self ) {
- TmpMaxRollValue = current_autopilot->get_MaxRoll();
- TmpRollOutValue = current_autopilot->get_RollOut();
- TmpMaxAileronValue = current_autopilot->get_MaxAileron();
- TmpRollOutSmoothValue = current_autopilot->get_RollOutSmooth();
-
- MaxRollValue = current_autopilot->get_MaxRoll() / MaxRollAdjust;
- RollOutValue = current_autopilot->get_RollOut() / RollOutAdjust;
- MaxAileronValue = current_autopilot->get_MaxAileron() / MaxAileronAdjust;
- RollOutSmoothValue = current_autopilot->get_RollOutSmooth()
+ TmpMaxRollValue = fgGetDouble("/autopilot/config/max-roll-deg");
+ TmpRollOutValue = fgGetDouble("/autopilot/config/roll-out-deg");
+ TmpMaxAileronValue = fgGetDouble("/autopilot/config/max-aileron");
+ TmpRollOutSmoothValue = fgGetDouble("/autopilot/config/roll-out-smooth-deg");
+
+ MaxRollValue = fgGetDouble("/autopilot/config/max-roll-deg")
+ / MaxRollAdjust;
+ RollOutValue = fgGetDouble("/autopilot/config/roll-out-deg")
+ / RollOutAdjust;
+ MaxAileronValue = fgGetDouble("/autopilot/config/max-aileron")
+ / MaxAileronAdjust;
+ RollOutSmoothValue = fgGetDouble("/autopilot/config/roll-out-smooth-deg")
/ RollOutSmoothAdjust;
APAdjustHS0-> setValue ( MaxRollValue ) ;
int slider_value_x = 160;
float slider_delta = 0.1f;
- TmpMaxRollValue = current_autopilot->get_MaxRoll();
- TmpRollOutValue = current_autopilot->get_RollOut();
- TmpMaxAileronValue = current_autopilot->get_MaxAileron();
- TmpRollOutSmoothValue = current_autopilot->get_RollOutSmooth();
-
- MaxRollAdjust = 2 * current_autopilot->get_MaxRoll();
- RollOutAdjust = 2 * current_autopilot->get_RollOut();
- MaxAileronAdjust = 2 * current_autopilot->get_MaxAileron();
- RollOutSmoothAdjust = 2 * current_autopilot->get_RollOutSmooth();
-
- MaxRollValue = current_autopilot->get_MaxRoll() / MaxRollAdjust;
- RollOutValue = current_autopilot->get_RollOut() / RollOutAdjust;
- MaxAileronValue = current_autopilot->get_MaxAileron() / MaxAileronAdjust;
- RollOutSmoothValue = current_autopilot->get_RollOutSmooth()
+ TmpMaxRollValue = fgGetDouble("/autopilot/config/max-roll-deg");
+ TmpRollOutValue = fgGetDouble("/autopilot/config/roll-out-deg");
+ TmpMaxAileronValue = fgGetDouble("/autopilot/config/max-aileron");
+ TmpRollOutSmoothValue = fgGetDouble("/autopilot/config/roll-out-smooth-deg");
+ MaxRollAdjust = 2 * fgGetDouble("/autopilot/config/max-roll-deg");
+ RollOutAdjust = 2 * fgGetDouble("/autopilot/config/roll-out-deg");
+ MaxAileronAdjust = 2 * fgGetDouble("/autopilot/config/max-aileron");
+ RollOutSmoothAdjust = 2 * fgGetDouble("/autopilot/config/roll-out-smooth-deg");
+
+ MaxRollValue = fgGetDouble("/autopilot/config/max-roll-deg")
+ / MaxRollAdjust;
+ RollOutValue = fgGetDouble("/autopilot/config/roll-out-deg")
+ / RollOutAdjust;
+ MaxAileronValue = fgGetDouble("/autopilot/config/max-aileron")
+ / MaxAileronAdjust;
+ RollOutSmoothValue = fgGetDouble("/autopilot/config/roll-out-smooth-deg")
/ RollOutSmoothAdjust;
puGetDefaultFonts ( &APAdjustLegendFont, &APAdjustLabelFont );
APAdjustHS0-> setCBMode ( PUSLIDER_DELTA ) ;
APAdjustHS0-> setCallback ( maxroll_adj ) ;
- sprintf( SliderText[ 0 ], "%05.2f", current_autopilot->get_MaxRoll() );
+ sprintf( SliderText[ 0 ], "%05.2f",
+ fgGetDouble("/autopilot/config/max-roll-deg") );
APAdjustMaxRollTitle = new puText ( slider_title_x, slider_y ) ;
APAdjustMaxRollTitle-> setDefaultValue ( "MaxRoll" ) ;
APAdjustMaxRollTitle-> getDefaultValue ( &s ) ;
APAdjustHS1-> setCBMode ( PUSLIDER_DELTA ) ;
APAdjustHS1-> setCallback ( rollout_adj ) ;
- sprintf( SliderText[ 1 ], "%05.2f", current_autopilot->get_RollOut() );
+ sprintf( SliderText[ 1 ], "%05.2f",
+ fgGetDouble("/autopilot/config/roll-out-deg") );
APAdjustRollOutTitle = new puText ( slider_title_x, slider_y ) ;
APAdjustRollOutTitle-> setDefaultValue ( "AdjustRollOut" ) ;
APAdjustRollOutTitle-> getDefaultValue ( &s ) ;
APAdjustHS2-> setCallback ( rolloutsmooth_adj ) ;
sprintf( SliderText[ 2 ], "%5.2f",
- current_autopilot->get_RollOutSmooth() );
+ fgGetDouble("/autopilot/config/roll-out-smooth-deg") );
APAdjustRollOutSmoothTitle = new puText ( slider_title_x, slider_y ) ;
APAdjustRollOutSmoothTitle-> setDefaultValue ( "RollOutSmooth" ) ;
APAdjustRollOutSmoothTitle-> getDefaultValue ( &s ) ;
APAdjustHS3-> setCallback ( maxaileron_adj ) ;
sprintf( SliderText[ 3 ], "%05.2f",
- current_autopilot->get_MaxAileron() );
+ fgGetDouble("/autopilot/config/max-aileron") );
APAdjustMaxAileronTitle = new puText ( slider_title_x, slider_y ) ;
APAdjustMaxAileronTitle-> setDefaultValue ( "MaxAileron" ) ;
APAdjustMaxAileronTitle-> getDefaultValue ( &s ) ;
#undef HORIZONTAL
}
+#endif
// Simple Dialog to input Target Airport
void TgtAptDialog_Cancel(puObject *)
TgtAptDialogInput->getValue(&s);
string tmp = s;
- double alt = 0.0;
unsigned int pos = tmp.find( "@" );
if ( pos != string::npos ) {
TgtAptId = tmp.substr( 0, pos );
- string alt_str = tmp.substr( pos + 1 );
- alt = atof( alt_str.c_str() );
- if ( fgGetString("/sim/startup/units") == "feet" ) {
- alt *= SG_FEET_TO_METER;
- }
} else {
TgtAptId = tmp;
}
TgtAptDialog_Cancel( NULL );
- FGAirport a;
- FGFix f;
- double t1, t2;
- if ( fgFindAirportID( TgtAptId, &a ) ) {
+ /* s = input string, either 'FIX' or FIX@4000' */
+ /* TgtAptId is name of fix only; may get appended to below */
- SG_LOG( SG_GENERAL, SG_INFO,
- "Adding waypoint (airport) = " << TgtAptId );
-
- sprintf( NewTgtAirportId, "%s", TgtAptId.c_str() );
-
- SGWayPoint wp( a.longitude, a.latitude, alt,
- SGWayPoint::WGS84, TgtAptId );
- globals->get_route()->add_waypoint( wp );
- } else if ( current_fixlist->query( TgtAptId, 0.0, 0.0, 0.0,
- &f, &t1, &t2 ) )
+ if ( NewWaypoint( TgtAptId ) == 0)
{
- SG_LOG( SG_GENERAL, SG_INFO,
- "Adding waypoint (fix) = " << TgtAptId );
-
- sprintf( NewTgtAirportId, "%s", TgtAptId.c_str() );
+ TgtAptId += " not in database.";
+ mkDialog(TgtAptId.c_str());
+ }
+}
- SGWayPoint wp( f.get_lon(), f.get_lat(), alt,
- SGWayPoint::WGS84, TgtAptId );
- globals->get_route()->add_waypoint( wp );
- } else {
- TgtAptId += " not in database.";
- mkDialog(TgtAptId.c_str());
+/* add new waypoint (either from above popup window 'ok button or telnet session) */
+
+int NewWaypoint( const string& Tgt_Alt )
+{
+ string TgtAptId;
+ FGAirport a;
+ FGFix f;
+
+ double alt = 0.0;
+ unsigned int pos = Tgt_Alt.find( "@" );
+ if ( pos != string::npos ) {
+ TgtAptId = Tgt_Alt.substr( 0, pos );
+ string alt_str = Tgt_Alt.substr( pos + 1 );
+ alt = atof( alt_str.c_str() );
+ if ( !strcmp(fgGetString("/sim/startup/units"), "feet") ) {
+ alt *= SG_FEET_TO_METER;
}
+ } else {
+ TgtAptId = Tgt_Alt;
+ }
+
+ FGRouteMgr *rm = (FGRouteMgr *)globals->get_subsystem("route-manager");
+
+ if ( fgFindAirportID( TgtAptId, &a ) ) {
+
+ SG_LOG( SG_GENERAL, SG_INFO,
+ "Adding waypoint (airport) = " << TgtAptId );
+
+ sprintf( NewTgtAirportId, "%s", TgtAptId.c_str() );
+
+ SGWayPoint wp( a.getLongitude(), a.getLatitude(), alt,
+ SGWayPoint::WGS84, TgtAptId );
+ rm->add_waypoint( wp );
+
+ /* and turn on the autopilot */
+ fgSetString( "/autopilot/locks/heading", "true-heading-hold" );
+
+ return 1;
+
+ } else if ( globals->get_fixlist()->query( TgtAptId, &f ) ) {
+ SG_LOG( SG_GENERAL, SG_INFO,
+ "Adding waypoint (fix) = " << TgtAptId );
+
+ sprintf( NewTgtAirportId, "%s", TgtAptId.c_str() );
+
+ SGWayPoint wp( f.get_lon(), f.get_lat(), alt,
+ SGWayPoint::WGS84, TgtAptId );
+ rm->add_waypoint( wp );
+
+ /* and turn on the autopilot */
+ fgSetString( "/autopilot/locks/heading", "true-heading-hold" );
+ return 2;
+ } else {
+ // 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;
+ }
+ }
}
+
void TgtAptDialog_Reset(puObject *)
{
- sprintf( NewTgtAirportId, "%s", fgGetString("/sim/startup/airport-id").c_str() );
+ sprintf( NewTgtAirportId, "%s", fgGetString("/sim/presets/airport-id") );
TgtAptDialogInput->setValue ( NewTgtAirportId );
TgtAptDialogInput->setCursor( 0 ) ;
}
+void TgtAptDialog_HandleSlider ( puObject * slider )
+{
+ float val ;
+ slider -> getValue ( &val ) ;
+ val = 1.0f - val ;
+
+ int index = int ( TgtAptDialogWPList -> getNumItems () * val ) ;
+ TgtAptDialogWPList -> setTopItem ( index ) ;
+}
+
+void TgtAptDialog_HandleArrow( puObject *arrow )
+{
+ int type = ((puArrowButton *)arrow)->getArrowType() ;
+ int inc = ( type == PUARROW_DOWN ) ? 1 :
+ ( type == PUARROW_UP ) ? -1 :
+ ( type == PUARROW_FASTDOWN ) ? 10 :
+ ( type == PUARROW_FASTUP ) ? -10 : 0 ;
+
+ float val ;
+ TgtAptDialogSlider -> getValue ( &val ) ;
+ val = 1.0f - val ;
+ int num_items = TgtAptDialogWPList->getNumItems () - 1 ;
+ if ( num_items > 0 )
+ {
+ int index = int ( num_items * val + 0.5 ) + inc ;
+ if ( index > num_items ) index = num_items ;
+ if ( index < 0 ) index = 0 ;
+
+ TgtAptDialogSlider -> setValue ( 1.0f - (float)index / num_items ) ;
+ TgtAptDialogWPList -> setTopItem ( index ) ;
+ }
+
+}
+
void AddWayPoint(puObject *cb)
{
- sprintf( NewTgtAirportId, "%s", fgGetString("/sim/startup/airport-id").c_str() );
+ sprintf( NewTgtAirportId, "%s", fgGetString("/sim/presets/airport-id") );
TgtAptDialogInput->setValue( NewTgtAirportId );
+ /* refresh waypoint list */
+ char WPString[100];
+
+ int i;
+ if ( WPList != NULL ) {
+ for (i = 0; i < WPListsize; i++ ) {
+ delete WPList[i];
+ }
+ delete [] WPList[i];
+ }
+ FGRouteMgr *rm = (FGRouteMgr *)globals->get_subsystem("route-manager");
+ WPListsize = rm->size();
+ if ( WPListsize > 0 ) {
+ WPList = new char* [ WPListsize + 1 ];
+ for (i = 0; i < WPListsize; i++ ) {
+ SGWayPoint wp = rm->get_waypoint(i);
+ sprintf( WPString, "%5s %3.2flon %3.2flat",
+ wp.get_id().c_str(),
+ wp.get_target_lon(),
+ wp.get_target_lat() );
+ WPList [i] = new char[ strlen(WPString)+1 ];
+ strcpy ( WPList [i], WPString );
+ }
+ } else {
+ WPListsize = 1;
+ WPList = new char* [ 2 ];
+ WPList [0] = new char[18];
+ strcpy ( WPList [0], "** List Empty **");
+ }
+ WPList [ WPListsize ] = NULL;
+ TgtAptDialogWPList->newList( WPList );
+
+ // if non-empty list, adjust the size of the slider...
+ TgtAptDialogSlider->setSliderFraction (0.9999f) ;
+ TgtAptDialogSlider->hide();
+ TgtAptDialogUPArrow->hide();
+ TgtAptDialogDNArrow->hide();
+ if (WPListsize > 10) {
+ TgtAptDialogSlider->setSliderFraction (10.0f/(WPListsize-1)) ;
+ TgtAptDialogSlider->reveal();
+ TgtAptDialogUPArrow->reveal();
+ TgtAptDialogDNArrow->reveal();
+ }
+
FG_PUSH_PUI_DIALOG( TgtAptDialog );
}
void PopWayPoint(puObject *cb)
{
- globals->get_route()->delete_first();
-
- // see if there are more waypoints on the list
- if ( globals->get_route()->size() ) {
- // more waypoints
- current_autopilot->set_HeadingMode( FGAutopilot::FG_HEADING_WAYPOINT );
- } else {
- // end of the line
- current_autopilot->set_HeadingMode( FGAutopilot::FG_TC_HEADING_LOCK );
-
- // use current heading
- current_autopilot
- ->set_TargetHeading(fgGetDouble("/orientation/heading-deg"));
- }
+ FGRouteMgr *rm = (FGRouteMgr *)globals->get_subsystem("route-manager");
+ rm->pop_waypoint();
}
void ClearRoute(puObject *cb)
{
- globals->get_route()->clear();
+ FGRouteMgr *rm = (FGRouteMgr *)globals->get_subsystem("route-manager");
+ rm->init();
}
void NewTgtAirportInit()
{
SG_LOG( SG_AUTOPILOT, SG_INFO, " enter NewTgtAirportInit()" );
- sprintf( NewTgtAirportId, "%s",
- fgGetString("/sim/startup/airport-id").c_str() );
+ sprintf( NewTgtAirportId, "%s", fgGetString("/sim/presets/airport-id") );
SG_LOG( SG_AUTOPILOT, SG_INFO, " NewTgtAirportId " << NewTgtAirportId );
- int len = 150
- - puGetDefaultLabelFont().getStringWidth( NewTgtAirportLabel ) / 2;
- TgtAptDialog = new puDialogBox (150, 50);
+ TgtAptDialog = new puDialogBox (150, 350);
{
- TgtAptDialogFrame = new puFrame (0,0,350, 150);
- TgtAptDialogMessage = new puText (len, 110);
- TgtAptDialogMessage -> setLabel (NewTgtAirportLabel);
+ TgtAptDialogFrame = new puFrame (0,0,350, 350);
+ TgtAptDialogWPList = new puListBox ( 50, 130, 300, 320 ) ;
+ TgtAptDialogWPList -> setLabel ( "Flight Plan" );
+ TgtAptDialogWPList -> setLabelPlace ( PUPLACE_TOP_LEFT ) ;
+ TgtAptDialogWPList -> setStyle ( -PUSTYLE_SMALL_SHADED ) ;
+ TgtAptDialogWPList -> setValue ( 0 ) ;
+
+ TgtAptDialogSlider = new puSlider (300, 150, 150 ,TRUE,20);
+ TgtAptDialogSlider->setValue(1.0f);
+ TgtAptDialogSlider->setSliderFraction (0.2f) ;
+ TgtAptDialogSlider->setDelta(0.1f);
+ TgtAptDialogSlider->setCBMode( PUSLIDER_DELTA );
+ TgtAptDialogSlider->setCallback( TgtAptDialog_HandleSlider );
+
+ TgtAptDialogUPArrow = new puArrowButton ( 300, 300, 320, 320, PUARROW_UP ) ;
+ TgtAptDialogUPArrow->setCallback ( TgtAptDialog_HandleArrow ) ;
+
+ TgtAptDialogDNArrow = new puArrowButton ( 300, 130, 320, 150, PUARROW_DOWN ) ;
+ TgtAptDialogDNArrow->setCallback ( TgtAptDialog_HandleArrow ) ;
+
+
TgtAptDialogInput = new puInput (50, 70, 300, 100);
+ TgtAptDialogInput -> setLabel ( NewTgtAirportLabel );
+ TgtAptDialogInput -> setLabelPlace ( PUPLACE_TOP_LEFT ) ;
TgtAptDialogInput -> setValue (NewTgtAirportId);
TgtAptDialogInput -> acceptInput();
TgtAptDialogResetButton = new puOneShot (240, 10, 300, 50);
TgtAptDialogResetButton -> setLegend (gui_msg_RESET);
TgtAptDialogResetButton -> setCallback (TgtAptDialog_Reset);
+
}
+
FG_FINALIZE_PUI_DIALOG( TgtAptDialog );
- printf("leave NewTgtAirportInit()");
+ SG_LOG(SG_GENERAL, SG_DEBUG, "leave NewTgtAirportInit()");
}
+
+
+