]> git.mxchange.org Git - flightgear.git/blobdiff - src/Autopilot/auto_gui.cxx
Make sure when setting autopilot heading via the menu that the current
[flightgear.git] / src / Autopilot / auto_gui.cxx
index 5987610464608ee24681b194eec99412b7f5846a..20ccc7bedd5f46aaf4669f93928eab642e93c876 100644 (file)
 #  include <config.h>
 #endif
 
+#include <simgear/compiler.h>
+
 #include <assert.h>
 #include <stdlib.h>
+#include <string.h>
+
+#include STL_STRING
 
+#include <Aircraft/aircraft.hxx>
+#include <FDM/flight.hxx>
+#include <Controls/controls.hxx>
 #include <Scenery/scenery.hxx>
 
 #include <simgear/constants.h>
+#include <simgear/sg_inlines.h>
 #include <simgear/debug/logstream.hxx>
 #include <simgear/math/sg_geodesy.hxx>
-#include <simgear/misc/fgpath.hxx>
+#include <simgear/misc/sg_path.hxx>
 
 #include <Airports/simple.hxx>
 #include <GUI/gui.h>
-#include <Main/bfi.hxx>
 #include <Main/fg_init.hxx>
 #include <Main/globals.hxx>
-#include <Main/options.hxx>
+#include <Main/fg_props.hxx>
 #include <Navaids/fixlist.hxx>
 
 #include "auto_gui.hxx"
 #include "newauto.hxx"
 
+SG_USING_STD(string);
+
 
 #define mySlider puSlider
 
@@ -209,19 +219,22 @@ void NewHeading(puObject *cb)
 {
     // string ApHeadingLabel( "Enter New Heading" );
     // ApHeadingDialogMessage  -> setLabel(ApHeadingLabel.c_str());
+    float heading = current_autopilot->get_DGTargetHeading();
+    while ( heading < 0.0 ) { heading += 360.0; }
+    ApHeadingDialogInput   ->    setValue ( heading );
     ApHeadingDialogInput    -> acceptInput();
     FG_PUSH_PUI_DIALOG( ApHeadingDialog );
 }
 
-void NewHeadingInit(void)
+void NewHeadingInit()
 {
     // printf("NewHeadingInit\n");
     char NewHeadingLabel[] = "Enter New Heading";
     char *s;
 
-    float heading = FGBFI::getHeading();
+    float heading = fgGetDouble("/orientation/heading-deg");
     int len = 260/2 -
-       (puGetStringWidth( puGetDefaultLabelFont(), NewHeadingLabel ) /2 );
+       (puGetDefaultLabelFont().getStringWidth( NewHeadingLabel ) / 2 );
 
     ApHeadingDialog = new puDialogBox (150, 50);
     {
@@ -281,11 +294,13 @@ void ApAltitudeDialog_OK (puObject *me)
 
 void NewAltitude(puObject *cb)
 {
+    float altitude = current_autopilot->get_TargetAltitude() * SG_METER_TO_FEET;
+    ApAltitudeDialogInput -> setValue( altitude );
     ApAltitudeDialogInput -> acceptInput();
     FG_PUSH_PUI_DIALOG( ApAltitudeDialog );
 }
 
-void NewAltitudeInit(void)
+void NewAltitudeInit()
 {
     // printf("NewAltitudeInit\n");
     char NewAltitudeLabel[] = "Enter New Altitude";
@@ -293,12 +308,12 @@ void NewAltitudeInit(void)
 
     float alt = cur_fdm_state->get_Altitude();
 
-    if ( globals->get_options()->get_units() == FGOptions::FG_UNITS_METERS) {
-       alt *= FEET_TO_METER;
+    if ( fgGetString("/sim/startup/units") == "meters") {
+       alt *= SG_FEET_TO_METER;
     }
 
     int len = 260/2 -
-       (puGetStringWidth( puGetDefaultLabelFont(), NewAltitudeLabel )/2);
+       (puGetDefaultLabelFont().getStringWidth( NewAltitudeLabel ) / 2);
 
     // ApAltitudeDialog = new puDialogBox (150, 50);
     ApAltitudeDialog = new puDialogBox (150, 200);
@@ -332,15 +347,12 @@ void NewAltitudeInit(void)
     FG_FINALIZE_PUI_DIALOG( ApAltitudeDialog );
 }
 
-/////// simple AutoPilot GAIN / LIMITS ADJUSTER
-
-#define fgAP_CLAMP(val,min,max) ( (val) = (val) > (max) ? (max) : (val) < (min) ? (min) : (val) )
 
 static void maxroll_adj( puObject *hs ) {
     float val ;
     
     hs-> getValue ( &val ) ;
-    fgAP_CLAMP ( val, 0.1, 1.0 ) ;
+    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() );
@@ -351,7 +363,7 @@ static void rollout_adj( puObject *hs ) {
     float val ;
 
     hs-> getValue ( &val ) ;
-    fgAP_CLAMP ( val, 0.1, 1.0 ) ;
+    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() );
@@ -362,7 +374,7 @@ static void maxaileron_adj( puObject *hs ) {
     float val ;
 
     hs-> getValue ( &val ) ;
-    fgAP_CLAMP ( val, 0.1, 1.0 ) ;
+    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() );
@@ -373,7 +385,7 @@ static void rolloutsmooth_adj( puObject *hs ) {
     float val ;
 
     hs -> getValue ( &val ) ;
-    fgAP_CLAMP ( val, 0.1, 1.0 ) ;
+    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() );
@@ -406,7 +418,7 @@ void resetAPAdjust( puObject *self ) {
     fgAPAdjust( self );
 }
 
-void fgAPAdjust( puObject * ) {
+void fgAPAdjust( puObject *self ) {
     TmpMaxRollValue       = current_autopilot->get_MaxRoll();
     TmpRollOutValue       = current_autopilot->get_RollOut();
     TmpMaxAileronValue    = current_autopilot->get_MaxAileron();
@@ -427,7 +439,7 @@ void fgAPAdjust( puObject * ) {
 }
 
 // Done once at system initialization
-void fgAPAdjustInit( void ) {
+void fgAPAdjustInit() {
 
     // printf("fgAPAdjustInit\n");
 #define HORIZONTAL  FALSE
@@ -440,7 +452,7 @@ void fgAPAdjustInit( void ) {
     char *s;
 
     int labelX = (DialogWidth / 2) -
-       (puGetStringWidth( puGetDefaultLabelFont(), Label ) / 2);
+       (puGetDefaultLabelFont().getStringWidth( Label ) / 2);
     labelX -= 30;  // KLUDGEY
 
     int nSliders = 4;
@@ -469,8 +481,8 @@ void fgAPAdjustInit( void ) {
 
     puGetDefaultFonts (  &APAdjustLegendFont,  &APAdjustLabelFont );
     APAdjustDialog = new puDialogBox ( DialogX, DialogY ); {
-       int horiz_slider_height = puGetStringHeight (APAdjustLabelFont) +
-           puGetStringDescender (APAdjustLabelFont) +
+       int horiz_slider_height = APAdjustLabelFont.getStringHeight() +
+           APAdjustLabelFont.getStringDescender() +
            PUSTR_TGAP + PUSTR_BGAP + 5;
 
        APAdjustFrame = new puFrame ( 0, 0,
@@ -590,13 +602,13 @@ void TgtAptDialog_OK (puObject *)
 
     string tmp = s;
     double alt = 0.0;
-    int pos = tmp.find( "@" );
+    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 ( globals->get_options()->get_units() == FGOptions::FG_UNITS_FEET ) {
-           alt *= FEET_TO_METER;
+       if ( fgGetString("/sim/startup/units") == "feet" ) {
+           alt *= SG_FEET_TO_METER;
        }
     } else {
        TgtAptId = tmp;
@@ -609,7 +621,7 @@ void TgtAptDialog_OK (puObject *)
     double t1, t2;
     if ( fgFindAirportID( TgtAptId, &a ) ) {
 
-        FG_LOG( FG_GENERAL, FG_INFO,
+        SG_LOG( SG_GENERAL, SG_INFO,
                 "Adding waypoint (airport) = " << TgtAptId );
         
         sprintf( NewTgtAirportId, "%s", TgtAptId.c_str() );
@@ -620,7 +632,7 @@ void TgtAptDialog_OK (puObject *)
     } else if ( current_fixlist->query( TgtAptId, 0.0, 0.0, 0.0,
                                        &f, &t1, &t2 ) )
     {
-        FG_LOG( FG_GENERAL, FG_INFO,
+        SG_LOG( SG_GENERAL, SG_INFO,
                 "Adding waypoint (fix) = " << TgtAptId );
         
         sprintf( NewTgtAirportId, "%s", TgtAptId.c_str() );
@@ -636,16 +648,14 @@ void TgtAptDialog_OK (puObject *)
 
 void TgtAptDialog_Reset(puObject *)
 {
-    //  strncpy( NewAirportId, globals->get_options()->get_airport_id().c_str(), 16 );
-    sprintf( NewTgtAirportId, "%s", globals->get_options()->get_airport_id().c_str() );
+    sprintf( NewTgtAirportId, "%s", fgGetString("/sim/startup/airport-id").c_str() );
     TgtAptDialogInput->setValue ( NewTgtAirportId );
     TgtAptDialogInput->setCursor( 0 ) ;
 }
 
 void AddWayPoint(puObject *cb)
 {
-    //  strncpy( NewAirportId, globals->get_options()->get_airport_id().c_str(), 16 );
-    sprintf( NewTgtAirportId, "%s", globals->get_options()->get_airport_id().c_str() );
+    sprintf( NewTgtAirportId, "%s", fgGetString("/sim/startup/airport-id").c_str() );
     TgtAptDialogInput->setValue( NewTgtAirportId );
     
     FG_PUSH_PUI_DIALOG( TgtAptDialog );
@@ -661,10 +671,11 @@ void PopWayPoint(puObject *cb)
        current_autopilot->set_HeadingMode( FGAutopilot::FG_HEADING_WAYPOINT );
     } else {
        // end of the line
-       current_autopilot->set_HeadingMode( FGAutopilot::FG_HEADING_LOCK );
+       current_autopilot->set_HeadingMode( FGAutopilot::FG_TC_HEADING_LOCK );
 
        // use current heading
-       current_autopilot->set_TargetHeading( FGBFI::getHeading() );
+       current_autopilot
+            ->set_TargetHeading(fgGetDouble("/orientation/heading-deg"));
     }
 }
 
@@ -673,15 +684,14 @@ void ClearRoute(puObject *cb)
     globals->get_route()->clear();
 }
 
-void NewTgtAirportInit(void)
+void NewTgtAirportInit()
 {
-    FG_LOG( FG_AUTOPILOT, FG_INFO, " enter NewTgtAirportInit()" );
-    // fgAPset_tgt_airport_id( globals->get_options()->get_airport_id() );     
-    sprintf( NewTgtAirportId, "%s", globals->get_options()->get_airport_id().c_str() );
-    FG_LOG( FG_AUTOPILOT, FG_INFO, " NewTgtAirportId " << NewTgtAirportId );
-    // printf(" NewTgtAirportId %s\n", NewTgtAirportId);
-    int len = 150 - puGetStringWidth( puGetDefaultLabelFont(),
-                                      NewTgtAirportLabel ) / 2;
+    SG_LOG( SG_AUTOPILOT, SG_INFO, " enter NewTgtAirportInit()" );
+    sprintf( NewTgtAirportId, "%s",
+             fgGetString("/sim/startup/airport-id").c_str() );
+    SG_LOG( SG_AUTOPILOT, SG_INFO, " NewTgtAirportId " << NewTgtAirportId );
+    int len = 150
+        - puGetDefaultLabelFont().getStringWidth( NewTgtAirportLabel ) / 2;
     
     TgtAptDialog = new puDialogBox (150, 50);
     {