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