]> git.mxchange.org Git - flightgear.git/blobdiff - src/Autopilot/auto_gui.cxx
working on the termination of the last hardcoded dialogs in Autopilot/auto_gui.cxx:
[flightgear.git] / src / Autopilot / auto_gui.cxx
index 4e3c19a8492b8c7444110a1025e640458966b4ef..01ebce80e2f4d3595b3789ecf7380532f006e6f7 100644 (file)
@@ -1,7 +1,7 @@
 // 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
 //
@@ -17,7 +17,7 @@
 //
 // You should have received a copy of the GNU General Public License
 // along with this program; if not, write to the Free Software
-// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 //
 // $Id$
 
@@ -36,7 +36,6 @@
 
 #include <Aircraft/aircraft.hxx>
 #include <FDM/flight.hxx>
-#include <Controls/controls.hxx>
 #include <Scenery/scenery.hxx>
 
 #include <simgear/constants.h>
@@ -51,6 +50,8 @@
 #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"
@@ -62,56 +63,56 @@ 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
 
@@ -139,7 +140,7 @@ static puOneShot       *ApAltitudeDialogCancelButton = 0;
 //  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;
@@ -350,6 +351,7 @@ void NewAltitudeInit()
 }
 
 
+#if 0
 static void maxroll_adj( puObject *hs ) {
     float val ;
     
@@ -597,6 +599,7 @@ void fgAPAdjustInit() {
 
 #undef HORIZONTAL
 }
+#endif
 
 // Simple Dialog to input Target Airport
 void TgtAptDialog_Cancel(puObject *)
@@ -638,10 +641,9 @@ void TgtAptDialog_OK (puObject *)
 
 /* 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;
   FGFix f;
 
   double alt = 0.0;
@@ -658,15 +660,15 @@ int NewWaypoint( string Tgt_Alt )
   }
 
   FGRouteMgr *rm = (FGRouteMgr *)globals->get_subsystem("route-manager");
-
-  if ( fgFindAirportID( TgtAptId, &a ) ) {
+  const FGAirport *a = fgFindAirportID( TgtAptId);
+  if (a) {
 
       SG_LOG( SG_GENERAL, SG_INFO,
               "Adding waypoint (airport) = " << TgtAptId );
 
       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 );
 
@@ -675,7 +677,7 @@ int NewWaypoint( string Tgt_Alt )
 
       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 );
 
@@ -689,7 +691,45 @@ int NewWaypoint( string Tgt_Alt )
       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;
+         }
   }
 }