]> git.mxchange.org Git - flightgear.git/blob - src/Autopilot/auto_gui.cxx
Make sure when setting autopilot heading via the menu that the current
[flightgear.git] / src / Autopilot / auto_gui.cxx
1 // auto_gui.cxx -- autopilot gui interface
2 //
3 // Written by Norman Vine <nhv@cape.com>
4 // Arranged by Curt Olson <curt@flightgear.org>
5 //
6 // Copyright (C) 1998 - 2000
7 //
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License as
10 // published by the Free Software Foundation; either version 2 of the
11 // License, or (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 // General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 //
22 // $Id$
23
24
25 #ifdef HAVE_CONFIG_H
26 #  include <config.h>
27 #endif
28
29 #include <simgear/compiler.h>
30
31 #include <assert.h>
32 #include <stdlib.h>
33 #include <string.h>
34
35 #include STL_STRING
36
37 #include <Aircraft/aircraft.hxx>
38 #include <FDM/flight.hxx>
39 #include <Controls/controls.hxx>
40 #include <Scenery/scenery.hxx>
41
42 #include <simgear/constants.h>
43 #include <simgear/sg_inlines.h>
44 #include <simgear/debug/logstream.hxx>
45 #include <simgear/math/sg_geodesy.hxx>
46 #include <simgear/misc/sg_path.hxx>
47
48 #include <Airports/simple.hxx>
49 #include <GUI/gui.h>
50 #include <Main/fg_init.hxx>
51 #include <Main/globals.hxx>
52 #include <Main/fg_props.hxx>
53 #include <Navaids/fixlist.hxx>
54
55 #include "auto_gui.hxx"
56 #include "newauto.hxx"
57
58 SG_USING_STD(string);
59
60
61 #define mySlider puSlider
62
63 // Climb speed constants
64 const double min_climb = 70.0;  // kts
65 const double best_climb = 75.0; // kts
66 const double ideal_climb_rate = 500.0; // fpm
67
68 /// These statics will eventually go into the class
69 /// they are just here while I am experimenting -- NHV :-)
70 // AutoPilot Gain Adjuster members
71 static double MaxRollAdjust;        // MaxRollAdjust       = 2 * APData->MaxRoll;
72 static double RollOutAdjust;        // RollOutAdjust       = 2 * APData->RollOut;
73 static double MaxAileronAdjust;     // MaxAileronAdjust    = 2 * APData->MaxAileron;
74 static double RollOutSmoothAdjust;  // RollOutSmoothAdjust = 2 * APData->RollOutSmooth;
75
76 static float MaxRollValue;          // 0.1 -> 1.0
77 static float RollOutValue;
78 static float MaxAileronValue;
79 static float RollOutSmoothValue;
80
81 static float TmpMaxRollValue;       // for cancel operation
82 static float TmpRollOutValue;
83 static float TmpMaxAileronValue;
84 static float TmpRollOutSmoothValue;
85
86 static puDialogBox *APAdjustDialog;
87 static puFrame     *APAdjustFrame;
88 static puText      *APAdjustDialogMessage;
89 static puFont      APAdjustLegendFont;
90 static puFont      APAdjustLabelFont;
91
92 static puOneShot *APAdjustOkButton;
93 static puOneShot *APAdjustResetButton;
94 static puOneShot *APAdjustCancelButton;
95
96 //static puButton        *APAdjustDragButton;
97
98 static puText *APAdjustMaxRollTitle;
99 static puText *APAdjustRollOutTitle;
100 static puText *APAdjustMaxAileronTitle;
101 static puText *APAdjustRollOutSmoothTitle;
102
103 static puText *APAdjustMaxAileronText;
104 static puText *APAdjustMaxRollText;
105 static puText *APAdjustRollOutText;
106 static puText *APAdjustRollOutSmoothText;
107
108 static mySlider *APAdjustHS0;
109 static mySlider *APAdjustHS1;
110 static mySlider *APAdjustHS2;
111 static mySlider *APAdjustHS3;
112
113 static char SliderText[ 4 ][ 8 ];
114
115 ///////// AutoPilot New Heading Dialog
116
117 static puDialogBox     *ApHeadingDialog;
118 static puFrame         *ApHeadingDialogFrame;
119 static puText          *ApHeadingDialogMessage;
120 static puInput         *ApHeadingDialogInput;
121 static puOneShot       *ApHeadingDialogOkButton;
122 static puOneShot       *ApHeadingDialogCancelButton;
123
124
125 ///////// AutoPilot New Altitude Dialog
126
127 static puDialogBox     *ApAltitudeDialog = 0;
128 static puFrame         *ApAltitudeDialogFrame = 0;
129 static puText          *ApAltitudeDialogMessage = 0;
130 static puInput         *ApAltitudeDialogInput = 0;
131
132 static puOneShot       *ApAltitudeDialogOkButton = 0;
133 static puOneShot       *ApAltitudeDialogCancelButton = 0;
134
135
136 /// The beginnings of Lock AutoPilot to target location :-)
137 //  Needs cleaning up but works
138 //  These statics should disapear when this is a class
139 static puDialogBox     *TgtAptDialog = 0;
140 static puFrame         *TgtAptDialogFrame = 0;
141 static puText          *TgtAptDialogMessage = 0;
142 static puInput         *TgtAptDialogInput = 0;
143
144 static char NewTgtAirportId[16];
145 static char NewTgtAirportLabel[] = "Enter New TgtAirport ID"; 
146
147 static puOneShot       *TgtAptDialogOkButton = 0;
148 static puOneShot       *TgtAptDialogCancelButton = 0;
149 static puOneShot       *TgtAptDialogResetButton = 0;
150
151
152 // extern char *coord_format_lat(float);
153 // extern char *coord_format_lon(float);
154
155 // THIS NEEDS IMPROVEMENT !!!!!!!!!!!!!
156 static int scan_number(char *s, double *new_value)
157 {
158     int ret = 0;
159     char WordBuf[64];
160     char *cptr = s;
161     char *WordBufPtr = WordBuf;
162
163     if (*cptr == '+')
164         cptr++;
165     if (*cptr == '-') {
166         *WordBufPtr++ = *cptr++;
167     }
168     while (isdigit(*cptr) ) {
169         *WordBufPtr++ = *cptr++;
170         ret = 1;
171     }
172     if (*cptr == '.') 
173         *WordBufPtr++ = *cptr++;  // put the '.' into the string
174     while (isdigit(*cptr)) {
175         *WordBufPtr++ = *cptr++;
176         ret = 1;
177     }
178     if( ret == 1 ) {
179         *WordBufPtr = '\0';
180         sscanf(WordBuf, "%lf", new_value);
181     }
182
183     return(ret);
184 } // scan_number
185
186
187 void ApHeadingDialog_Cancel(puObject *)
188 {
189     ApHeadingDialogInput->rejectInput();
190     FG_POP_PUI_DIALOG( ApHeadingDialog );
191 }
192
193 void ApHeadingDialog_OK (puObject *me)
194 {
195     int error = 0;
196     char *c;
197     string s;
198     ApHeadingDialogInput -> getValue( &c );
199
200     if( strlen(c) ) {
201         double NewHeading;
202         if( scan_number( c, &NewHeading ) )
203             {
204                 if ( !current_autopilot->get_HeadingEnabled() ) {
205                     current_autopilot->set_HeadingEnabled( true );
206                 }
207                 current_autopilot->HeadingSet( NewHeading );
208             } else {
209                 error = 1;
210                 s = c;
211                 s += " is not a valid number.";
212             }
213     }
214     ApHeadingDialog_Cancel(me);
215     if( error )  mkDialog(s.c_str());
216 }
217
218 void NewHeading(puObject *cb)
219 {
220     //  string ApHeadingLabel( "Enter New Heading" );
221     //  ApHeadingDialogMessage  -> setLabel(ApHeadingLabel.c_str());
222     float heading = current_autopilot->get_DGTargetHeading();
223     while ( heading < 0.0 ) { heading += 360.0; }
224     ApHeadingDialogInput   ->    setValue ( heading );
225     ApHeadingDialogInput    -> acceptInput();
226     FG_PUSH_PUI_DIALOG( ApHeadingDialog );
227 }
228
229 void NewHeadingInit()
230 {
231     //  printf("NewHeadingInit\n");
232     char NewHeadingLabel[] = "Enter New Heading";
233     char *s;
234
235     float heading = fgGetDouble("/orientation/heading-deg");
236     int len = 260/2 -
237         (puGetDefaultLabelFont().getStringWidth( NewHeadingLabel ) / 2 );
238
239     ApHeadingDialog = new puDialogBox (150, 50);
240     {
241         ApHeadingDialogFrame   = new puFrame (0, 0, 260, 150);
242
243         ApHeadingDialogMessage = new puText   (len, 110);
244         ApHeadingDialogMessage    -> setDefaultValue (NewHeadingLabel);
245         ApHeadingDialogMessage    -> getDefaultValue (&s);
246         ApHeadingDialogMessage    -> setLabel        (s);
247
248         ApHeadingDialogInput   = new puInput  ( 50, 70, 210, 100 );
249         ApHeadingDialogInput   ->    setValue ( heading );
250
251         ApHeadingDialogOkButton     =  new puOneShot         (50, 10, 110, 50);
252         ApHeadingDialogOkButton     ->     setLegend         (gui_msg_OK);
253         ApHeadingDialogOkButton     ->     makeReturnDefault (TRUE);
254         ApHeadingDialogOkButton     ->     setCallback       (ApHeadingDialog_OK);
255
256         ApHeadingDialogCancelButton =  new puOneShot         (140, 10, 210, 50);
257         ApHeadingDialogCancelButton ->     setLegend         (gui_msg_CANCEL);
258         ApHeadingDialogCancelButton ->     setCallback       (ApHeadingDialog_Cancel);
259
260     }
261     FG_FINALIZE_PUI_DIALOG( ApHeadingDialog );
262 }
263
264 void ApAltitudeDialog_Cancel(puObject *)
265 {
266     ApAltitudeDialogInput -> rejectInput();
267     FG_POP_PUI_DIALOG( ApAltitudeDialog );
268 }
269
270 void ApAltitudeDialog_OK (puObject *me)
271 {
272     int error = 0;
273     string s;
274     char *c;
275     ApAltitudeDialogInput->getValue( &c );
276
277     if( strlen( c ) ) {
278         double NewAltitude;
279         if( scan_number( c, &NewAltitude) )
280             {
281                 if ( !current_autopilot->get_AltitudeEnabled() ) {
282                     current_autopilot->set_AltitudeEnabled( true );
283                 }
284                 current_autopilot->AltitudeSet( NewAltitude );
285             } else {
286                 error = 1;
287                 s = c;
288                 s += " is not a valid number.";
289             }
290     }
291     ApAltitudeDialog_Cancel(me);
292     if( error )  mkDialog(s.c_str());
293 }
294
295 void NewAltitude(puObject *cb)
296 {
297     float altitude = current_autopilot->get_TargetAltitude() * SG_METER_TO_FEET;
298     ApAltitudeDialogInput -> setValue( altitude );
299     ApAltitudeDialogInput -> acceptInput();
300     FG_PUSH_PUI_DIALOG( ApAltitudeDialog );
301 }
302
303 void NewAltitudeInit()
304 {
305     //  printf("NewAltitudeInit\n");
306     char NewAltitudeLabel[] = "Enter New Altitude";
307     char *s;
308
309     float alt = cur_fdm_state->get_Altitude();
310
311     if ( fgGetString("/sim/startup/units") == "meters") {
312         alt *= SG_FEET_TO_METER;
313     }
314
315     int len = 260/2 -
316         (puGetDefaultLabelFont().getStringWidth( NewAltitudeLabel ) / 2);
317
318     //  ApAltitudeDialog = new puDialogBox (150, 50);
319     ApAltitudeDialog = new puDialogBox (150, 200);
320     {
321         ApAltitudeDialogFrame   = new puFrame  (0, 0, 260, 150);
322         ApAltitudeDialogMessage = new puText   (len, 110);
323         ApAltitudeDialogMessage    -> setDefaultValue (NewAltitudeLabel);
324         ApAltitudeDialogMessage    -> getDefaultValue (&s);
325         ApAltitudeDialogMessage    -> setLabel (s);
326
327         ApAltitudeDialogInput   = new puInput  ( 50, 70, 210, 100 );
328         ApAltitudeDialogInput      -> setValue ( alt );
329         // Uncomment the next line to have input active on startup
330         // ApAltitudeDialogInput   ->    acceptInput       ( );
331         // cursor at begining or end of line ?
332         //len = strlen(s);
333         //              len = 0;
334         //              ApAltitudeDialogInput   ->    setCursor         ( len );
335         //              ApAltitudeDialogInput   ->    setSelectRegion   ( 5, 9 );
336
337         ApAltitudeDialogOkButton     =  new puOneShot         (50, 10, 110, 50);
338         ApAltitudeDialogOkButton     ->     setLegend         (gui_msg_OK);
339         ApAltitudeDialogOkButton     ->     makeReturnDefault (TRUE);
340         ApAltitudeDialogOkButton     ->     setCallback       (ApAltitudeDialog_OK);
341
342         ApAltitudeDialogCancelButton =  new puOneShot         (140, 10, 210, 50);
343         ApAltitudeDialogCancelButton ->     setLegend         (gui_msg_CANCEL);
344         ApAltitudeDialogCancelButton ->     setCallback       (ApAltitudeDialog_Cancel);
345
346     }
347     FG_FINALIZE_PUI_DIALOG( ApAltitudeDialog );
348 }
349
350
351 static void maxroll_adj( puObject *hs ) {
352     float val ;
353     
354     hs-> getValue ( &val ) ;
355     SG_CLAMP_RANGE ( val, 0.1f, 1.0f ) ;
356     //    printf ( "maxroll_adj( %p ) %f %f\n", hs, val, MaxRollAdjust * val ) ;
357     current_autopilot->set_MaxRoll( MaxRollAdjust * val );
358     sprintf( SliderText[ 0 ], "%05.2f", current_autopilot->get_MaxRoll() );
359     APAdjustMaxRollText -> setLabel ( SliderText[ 0 ] ) ;
360 }
361
362 static void rollout_adj( puObject *hs ) {
363     float val ;
364
365     hs-> getValue ( &val ) ;
366     SG_CLAMP_RANGE ( val, 0.1f, 1.0f ) ;
367     //    printf ( "rollout_adj( %p ) %f %f\n", hs, val, RollOutAdjust * val ) ;
368     current_autopilot->set_RollOut( RollOutAdjust * val );
369     sprintf( SliderText[ 1 ], "%05.2f", current_autopilot->get_RollOut() );
370     APAdjustRollOutText -> setLabel ( SliderText[ 1 ] );
371 }
372
373 static void maxaileron_adj( puObject *hs ) {
374     float val ;
375
376     hs-> getValue ( &val ) ;
377     SG_CLAMP_RANGE ( val, 0.1f, 1.0f ) ;
378     //    printf ( "maxaileron_adj( %p ) %f %f\n", hs, val, MaxAileronAdjust * val ) ;
379     current_autopilot->set_MaxAileron( MaxAileronAdjust * val );
380     sprintf( SliderText[ 3 ], "%05.2f", current_autopilot->get_MaxAileron() );
381     APAdjustMaxAileronText -> setLabel ( SliderText[ 3 ] );
382 }
383
384 static void rolloutsmooth_adj( puObject *hs ) {
385     float val ;
386
387     hs -> getValue ( &val ) ;
388     SG_CLAMP_RANGE ( val, 0.1f, 1.0f ) ;
389     //    printf ( "rolloutsmooth_adj( %p ) %f %f\n", hs, val, RollOutSmoothAdjust * val ) ;
390     current_autopilot->set_RollOutSmooth( RollOutSmoothAdjust * val );
391     sprintf( SliderText[ 2 ], "%5.2f", current_autopilot->get_RollOutSmooth() );
392     APAdjustRollOutSmoothText-> setLabel ( SliderText[ 2 ] );
393
394 }
395
396 static void goAwayAPAdjust (puObject *)
397 {
398     FG_POP_PUI_DIALOG( APAdjustDialog );
399 }
400
401 void cancelAPAdjust( puObject *self ) {
402     current_autopilot->set_MaxRoll( TmpMaxRollValue );
403     current_autopilot->set_RollOut( TmpRollOutValue );
404     current_autopilot->set_MaxAileron( TmpMaxAileronValue );
405     current_autopilot->set_RollOutSmooth( TmpRollOutSmoothValue );
406
407     goAwayAPAdjust(self);
408 }
409
410 void resetAPAdjust( puObject *self ) {
411     current_autopilot->set_MaxRoll( MaxRollAdjust / 2 );
412     current_autopilot->set_RollOut( RollOutAdjust / 2 );
413     current_autopilot->set_MaxAileron( MaxAileronAdjust / 2 );
414     current_autopilot->set_RollOutSmooth( RollOutSmoothAdjust / 2 );
415
416     FG_POP_PUI_DIALOG( APAdjustDialog );
417
418     fgAPAdjust( self );
419 }
420
421 void fgAPAdjust( puObject *self ) {
422     TmpMaxRollValue       = current_autopilot->get_MaxRoll();
423     TmpRollOutValue       = current_autopilot->get_RollOut();
424     TmpMaxAileronValue    = current_autopilot->get_MaxAileron();
425     TmpRollOutSmoothValue = current_autopilot->get_RollOutSmooth();
426
427     MaxRollValue       = current_autopilot->get_MaxRoll() / MaxRollAdjust;
428     RollOutValue       = current_autopilot->get_RollOut() / RollOutAdjust;
429     MaxAileronValue    = current_autopilot->get_MaxAileron() / MaxAileronAdjust;
430     RollOutSmoothValue = current_autopilot->get_RollOutSmooth()
431         / RollOutSmoothAdjust;
432
433     APAdjustHS0-> setValue ( MaxRollValue ) ;
434     APAdjustHS1-> setValue ( RollOutValue ) ;
435     APAdjustHS2-> setValue ( RollOutSmoothValue ) ;
436     APAdjustHS3-> setValue ( MaxAileronValue ) ;
437
438     FG_PUSH_PUI_DIALOG( APAdjustDialog );
439 }
440
441 // Done once at system initialization
442 void fgAPAdjustInit() {
443
444     //  printf("fgAPAdjustInit\n");
445 #define HORIZONTAL  FALSE
446
447     int DialogX = 40;
448     int DialogY = 100;
449     int DialogWidth = 230;
450
451     char Label[] =  "AutoPilot Adjust";
452     char *s;
453
454     int labelX = (DialogWidth / 2) -
455         (puGetDefaultLabelFont().getStringWidth( Label ) / 2);
456     labelX -= 30;  // KLUDGEY
457
458     int nSliders = 4;
459     int slider_x = 10;
460     int slider_y = 55;
461     int slider_width = 210;
462     int slider_title_x = 15;
463     int slider_value_x = 160;
464     float slider_delta = 0.1f;
465
466     TmpMaxRollValue       = current_autopilot->get_MaxRoll();
467     TmpRollOutValue       = current_autopilot->get_RollOut();
468     TmpMaxAileronValue    = current_autopilot->get_MaxAileron();
469     TmpRollOutSmoothValue = current_autopilot->get_RollOutSmooth();
470
471     MaxRollAdjust = 2 * current_autopilot->get_MaxRoll();
472     RollOutAdjust = 2 * current_autopilot->get_RollOut();
473     MaxAileronAdjust = 2 * current_autopilot->get_MaxAileron();
474     RollOutSmoothAdjust = 2 * current_autopilot->get_RollOutSmooth();
475
476     MaxRollValue       = current_autopilot->get_MaxRoll() / MaxRollAdjust;
477     RollOutValue       = current_autopilot->get_RollOut() / RollOutAdjust;
478     MaxAileronValue    = current_autopilot->get_MaxAileron() / MaxAileronAdjust;
479     RollOutSmoothValue = current_autopilot->get_RollOutSmooth()
480         / RollOutSmoothAdjust;
481
482     puGetDefaultFonts (  &APAdjustLegendFont,  &APAdjustLabelFont );
483     APAdjustDialog = new puDialogBox ( DialogX, DialogY ); {
484         int horiz_slider_height = APAdjustLabelFont.getStringHeight() +
485             APAdjustLabelFont.getStringDescender() +
486             PUSTR_TGAP + PUSTR_BGAP + 5;
487
488         APAdjustFrame = new puFrame ( 0, 0,
489                                       DialogWidth,
490                                       85 + nSliders * horiz_slider_height );
491
492         APAdjustDialogMessage = new puText ( labelX,
493                                              52 + nSliders
494                                              * horiz_slider_height );
495         APAdjustDialogMessage -> setDefaultValue ( Label );
496         APAdjustDialogMessage -> getDefaultValue ( &s );
497         APAdjustDialogMessage -> setLabel        ( s );
498
499         APAdjustHS0 = new mySlider ( slider_x, slider_y,
500                                      slider_width, HORIZONTAL ) ;
501         APAdjustHS0-> setDelta ( slider_delta ) ;
502         APAdjustHS0-> setValue ( MaxRollValue ) ;
503         APAdjustHS0-> setCBMode ( PUSLIDER_DELTA ) ;
504         APAdjustHS0-> setCallback ( maxroll_adj ) ;
505
506         sprintf( SliderText[ 0 ], "%05.2f", current_autopilot->get_MaxRoll() );
507         APAdjustMaxRollTitle = new puText ( slider_title_x, slider_y ) ;
508         APAdjustMaxRollTitle-> setDefaultValue ( "MaxRoll" ) ;
509         APAdjustMaxRollTitle-> getDefaultValue ( &s ) ;
510         APAdjustMaxRollTitle-> setLabel ( s ) ;
511         APAdjustMaxRollText = new puText ( slider_value_x, slider_y ) ;
512         APAdjustMaxRollText-> setLabel ( SliderText[ 0 ] ) ;
513
514         slider_y += horiz_slider_height;
515
516         APAdjustHS1 = new mySlider ( slider_x, slider_y, slider_width,
517                                      HORIZONTAL ) ;
518         APAdjustHS1-> setDelta ( slider_delta ) ;
519         APAdjustHS1-> setValue ( RollOutValue ) ;
520         APAdjustHS1-> setCBMode ( PUSLIDER_DELTA ) ;
521         APAdjustHS1-> setCallback ( rollout_adj ) ;
522
523         sprintf( SliderText[ 1 ], "%05.2f", current_autopilot->get_RollOut() );
524         APAdjustRollOutTitle = new puText ( slider_title_x, slider_y ) ;
525         APAdjustRollOutTitle-> setDefaultValue ( "AdjustRollOut" ) ;
526         APAdjustRollOutTitle-> getDefaultValue ( &s ) ;
527         APAdjustRollOutTitle-> setLabel ( s ) ;
528         APAdjustRollOutText = new puText ( slider_value_x, slider_y ) ;
529         APAdjustRollOutText-> setLabel ( SliderText[ 1 ] );
530
531         slider_y += horiz_slider_height;
532
533         APAdjustHS2 = new mySlider ( slider_x, slider_y, slider_width,
534                                      HORIZONTAL ) ;
535         APAdjustHS2-> setDelta ( slider_delta ) ;
536         APAdjustHS2-> setValue ( RollOutSmoothValue ) ;
537         APAdjustHS2-> setCBMode ( PUSLIDER_DELTA ) ;
538         APAdjustHS2-> setCallback ( rolloutsmooth_adj ) ;
539
540         sprintf( SliderText[ 2 ], "%5.2f", 
541                  current_autopilot->get_RollOutSmooth() );
542         APAdjustRollOutSmoothTitle = new puText ( slider_title_x, slider_y ) ;
543         APAdjustRollOutSmoothTitle-> setDefaultValue ( "RollOutSmooth" ) ;
544         APAdjustRollOutSmoothTitle-> getDefaultValue ( &s ) ;
545         APAdjustRollOutSmoothTitle-> setLabel ( s ) ;
546         APAdjustRollOutSmoothText = new puText ( slider_value_x, slider_y ) ;
547         APAdjustRollOutSmoothText-> setLabel ( SliderText[ 2 ] );
548
549         slider_y += horiz_slider_height;
550
551         APAdjustHS3 = new mySlider ( slider_x, slider_y, slider_width,
552                                      HORIZONTAL ) ;
553         APAdjustHS3-> setDelta ( slider_delta ) ;
554         APAdjustHS3-> setValue ( MaxAileronValue ) ;
555         APAdjustHS3-> setCBMode ( PUSLIDER_DELTA ) ;
556         APAdjustHS3-> setCallback ( maxaileron_adj ) ;
557
558         sprintf( SliderText[ 3 ], "%05.2f", 
559                  current_autopilot->get_MaxAileron() );
560         APAdjustMaxAileronTitle = new puText ( slider_title_x, slider_y ) ;
561         APAdjustMaxAileronTitle-> setDefaultValue ( "MaxAileron" ) ;
562         APAdjustMaxAileronTitle-> getDefaultValue ( &s ) ;
563         APAdjustMaxAileronTitle-> setLabel ( s ) ;
564         APAdjustMaxAileronText = new puText ( slider_value_x, slider_y ) ;
565         APAdjustMaxAileronText-> setLabel ( SliderText[ 3 ] );
566
567         APAdjustOkButton = new puOneShot ( 10, 10, 60, 50 );
568         APAdjustOkButton-> setLegend ( gui_msg_OK );
569         APAdjustOkButton-> makeReturnDefault ( TRUE );
570         APAdjustOkButton-> setCallback ( goAwayAPAdjust );
571
572         APAdjustCancelButton = new puOneShot ( 70, 10, 150, 50 );
573         APAdjustCancelButton-> setLegend ( gui_msg_CANCEL );
574         APAdjustCancelButton-> setCallback ( cancelAPAdjust );
575
576         APAdjustResetButton = new puOneShot ( 160, 10, 220, 50 );
577         APAdjustResetButton-> setLegend ( gui_msg_RESET );
578         APAdjustResetButton-> setCallback ( resetAPAdjust );
579     }
580     FG_FINALIZE_PUI_DIALOG( APAdjustDialog );
581
582 #undef HORIZONTAL
583 }
584
585 // Simple Dialog to input Target Airport
586 void TgtAptDialog_Cancel(puObject *)
587 {
588     FG_POP_PUI_DIALOG( TgtAptDialog );
589 }
590
591 void TgtAptDialog_OK (puObject *)
592 {
593     string TgtAptId;
594     
595     //    FGTime *t = FGTime::cur_time_params;
596     //    int PauseMode = t->getPause();
597     //    if(!PauseMode)
598     //        t->togglePauseMode();
599     
600     char *s;
601     TgtAptDialogInput->getValue(&s);
602
603     string tmp = s;
604     double alt = 0.0;
605     unsigned int pos = tmp.find( "@" );
606     if ( pos != string::npos ) {
607         TgtAptId = tmp.substr( 0, pos );
608         string alt_str = tmp.substr( pos + 1 );
609         alt = atof( alt_str.c_str() );
610         if ( fgGetString("/sim/startup/units") == "feet" ) {
611             alt *= SG_FEET_TO_METER;
612         }
613     } else {
614         TgtAptId = tmp;
615     }
616
617     TgtAptDialog_Cancel( NULL );
618     
619     FGAirport a;
620     FGFix f;
621     double t1, t2;
622     if ( fgFindAirportID( TgtAptId, &a ) ) {
623
624          SG_LOG( SG_GENERAL, SG_INFO,
625                  "Adding waypoint (airport) = " << TgtAptId );
626         
627          sprintf( NewTgtAirportId, "%s", TgtAptId.c_str() );
628
629          SGWayPoint wp( a.longitude, a.latitude, alt,
630                         SGWayPoint::WGS84, TgtAptId );
631          globals->get_route()->add_waypoint( wp );
632     } else if ( current_fixlist->query( TgtAptId, 0.0, 0.0, 0.0,
633                                         &f, &t1, &t2 ) )
634     {
635          SG_LOG( SG_GENERAL, SG_INFO,
636                  "Adding waypoint (fix) = " << TgtAptId );
637         
638          sprintf( NewTgtAirportId, "%s", TgtAptId.c_str() );
639
640          SGWayPoint wp( f.get_lon(), f.get_lat(), alt,
641                         SGWayPoint::WGS84, TgtAptId );
642          globals->get_route()->add_waypoint( wp );
643     } else {
644         TgtAptId  += " not in database.";
645         mkDialog(TgtAptId.c_str());
646     }
647 }
648
649 void TgtAptDialog_Reset(puObject *)
650 {
651     sprintf( NewTgtAirportId, "%s", fgGetString("/sim/startup/airport-id").c_str() );
652     TgtAptDialogInput->setValue ( NewTgtAirportId );
653     TgtAptDialogInput->setCursor( 0 ) ;
654 }
655
656 void AddWayPoint(puObject *cb)
657 {
658     sprintf( NewTgtAirportId, "%s", fgGetString("/sim/startup/airport-id").c_str() );
659     TgtAptDialogInput->setValue( NewTgtAirportId );
660     
661     FG_PUSH_PUI_DIALOG( TgtAptDialog );
662 }
663
664 void PopWayPoint(puObject *cb)
665 {
666     globals->get_route()->delete_first();
667
668     // see if there are more waypoints on the list
669     if ( globals->get_route()->size() ) {
670         // more waypoints
671         current_autopilot->set_HeadingMode( FGAutopilot::FG_HEADING_WAYPOINT );
672     } else {
673         // end of the line
674         current_autopilot->set_HeadingMode( FGAutopilot::FG_TC_HEADING_LOCK );
675
676         // use current heading
677         current_autopilot
678             ->set_TargetHeading(fgGetDouble("/orientation/heading-deg"));
679     }
680 }
681
682 void ClearRoute(puObject *cb)
683 {
684     globals->get_route()->clear();
685 }
686
687 void NewTgtAirportInit()
688 {
689     SG_LOG( SG_AUTOPILOT, SG_INFO, " enter NewTgtAirportInit()" );
690     sprintf( NewTgtAirportId, "%s",
691              fgGetString("/sim/startup/airport-id").c_str() );
692     SG_LOG( SG_AUTOPILOT, SG_INFO, " NewTgtAirportId " << NewTgtAirportId );
693     int len = 150
694         - puGetDefaultLabelFont().getStringWidth( NewTgtAirportLabel ) / 2;
695     
696     TgtAptDialog = new puDialogBox (150, 50);
697     {
698         TgtAptDialogFrame   = new puFrame           (0,0,350, 150);
699         TgtAptDialogMessage = new puText            (len, 110);
700         TgtAptDialogMessage ->    setLabel          (NewTgtAirportLabel);
701         
702         TgtAptDialogInput   = new puInput           (50, 70, 300, 100);
703         TgtAptDialogInput   ->    setValue          (NewTgtAirportId);
704         TgtAptDialogInput   ->    acceptInput();
705         
706         TgtAptDialogOkButton     =  new puOneShot   (50, 10, 110, 50);
707         TgtAptDialogOkButton     ->     setLegend   (gui_msg_OK);
708         TgtAptDialogOkButton     ->     setCallback (TgtAptDialog_OK);
709         TgtAptDialogOkButton     ->     makeReturnDefault(TRUE);
710         
711         TgtAptDialogCancelButton =  new puOneShot   (140, 10, 210, 50);
712         TgtAptDialogCancelButton ->     setLegend   (gui_msg_CANCEL);
713         TgtAptDialogCancelButton ->     setCallback (TgtAptDialog_Cancel);
714         
715         TgtAptDialogResetButton  =  new puOneShot   (240, 10, 300, 50);
716         TgtAptDialogResetButton  ->     setLegend   (gui_msg_RESET);
717         TgtAptDialogResetButton  ->     setCallback (TgtAptDialog_Reset);
718     }
719     FG_FINALIZE_PUI_DIALOG( TgtAptDialog );
720     printf("leave NewTgtAirportInit()");
721 }