]> git.mxchange.org Git - flightgear.git/blob - src/Autopilot/auto_gui.cxx
Modified to use a relative path for aircraft_dir rather than an
[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     ApHeadingDialogInput    -> acceptInput();
223     FG_PUSH_PUI_DIALOG( ApHeadingDialog );
224 }
225
226 void NewHeadingInit()
227 {
228     //  printf("NewHeadingInit\n");
229     char NewHeadingLabel[] = "Enter New Heading";
230     char *s;
231
232     float heading = fgGetDouble("/orientation/heading-deg");
233     int len = 260/2 -
234         (puGetDefaultLabelFont().getStringWidth( NewHeadingLabel ) / 2 );
235
236     ApHeadingDialog = new puDialogBox (150, 50);
237     {
238         ApHeadingDialogFrame   = new puFrame (0, 0, 260, 150);
239
240         ApHeadingDialogMessage = new puText   (len, 110);
241         ApHeadingDialogMessage    -> setDefaultValue (NewHeadingLabel);
242         ApHeadingDialogMessage    -> getDefaultValue (&s);
243         ApHeadingDialogMessage    -> setLabel        (s);
244
245         ApHeadingDialogInput   = new puInput  ( 50, 70, 210, 100 );
246         ApHeadingDialogInput   ->    setValue ( heading );
247
248         ApHeadingDialogOkButton     =  new puOneShot         (50, 10, 110, 50);
249         ApHeadingDialogOkButton     ->     setLegend         (gui_msg_OK);
250         ApHeadingDialogOkButton     ->     makeReturnDefault (TRUE);
251         ApHeadingDialogOkButton     ->     setCallback       (ApHeadingDialog_OK);
252
253         ApHeadingDialogCancelButton =  new puOneShot         (140, 10, 210, 50);
254         ApHeadingDialogCancelButton ->     setLegend         (gui_msg_CANCEL);
255         ApHeadingDialogCancelButton ->     setCallback       (ApHeadingDialog_Cancel);
256
257     }
258     FG_FINALIZE_PUI_DIALOG( ApHeadingDialog );
259 }
260
261 void ApAltitudeDialog_Cancel(puObject *)
262 {
263     ApAltitudeDialogInput -> rejectInput();
264     FG_POP_PUI_DIALOG( ApAltitudeDialog );
265 }
266
267 void ApAltitudeDialog_OK (puObject *me)
268 {
269     int error = 0;
270     string s;
271     char *c;
272     ApAltitudeDialogInput->getValue( &c );
273
274     if( strlen( c ) ) {
275         double NewAltitude;
276         if( scan_number( c, &NewAltitude) )
277             {
278                 if ( !current_autopilot->get_AltitudeEnabled() ) {
279                     current_autopilot->set_AltitudeEnabled( true );
280                 }
281                 current_autopilot->AltitudeSet( NewAltitude );
282             } else {
283                 error = 1;
284                 s = c;
285                 s += " is not a valid number.";
286             }
287     }
288     ApAltitudeDialog_Cancel(me);
289     if( error )  mkDialog(s.c_str());
290 }
291
292 void NewAltitude(puObject *cb)
293 {
294     ApAltitudeDialogInput -> acceptInput();
295     FG_PUSH_PUI_DIALOG( ApAltitudeDialog );
296 }
297
298 void NewAltitudeInit()
299 {
300     //  printf("NewAltitudeInit\n");
301     char NewAltitudeLabel[] = "Enter New Altitude";
302     char *s;
303
304     float alt = cur_fdm_state->get_Altitude();
305
306     if ( fgGetString("/sim/startup/units") == "meters") {
307         alt *= SG_FEET_TO_METER;
308     }
309
310     int len = 260/2 -
311         (puGetDefaultLabelFont().getStringWidth( NewAltitudeLabel ) / 2);
312
313     //  ApAltitudeDialog = new puDialogBox (150, 50);
314     ApAltitudeDialog = new puDialogBox (150, 200);
315     {
316         ApAltitudeDialogFrame   = new puFrame  (0, 0, 260, 150);
317         ApAltitudeDialogMessage = new puText   (len, 110);
318         ApAltitudeDialogMessage    -> setDefaultValue (NewAltitudeLabel);
319         ApAltitudeDialogMessage    -> getDefaultValue (&s);
320         ApAltitudeDialogMessage    -> setLabel (s);
321
322         ApAltitudeDialogInput   = new puInput  ( 50, 70, 210, 100 );
323         ApAltitudeDialogInput      -> setValue ( alt );
324         // Uncomment the next line to have input active on startup
325         // ApAltitudeDialogInput   ->    acceptInput       ( );
326         // cursor at begining or end of line ?
327         //len = strlen(s);
328         //              len = 0;
329         //              ApAltitudeDialogInput   ->    setCursor         ( len );
330         //              ApAltitudeDialogInput   ->    setSelectRegion   ( 5, 9 );
331
332         ApAltitudeDialogOkButton     =  new puOneShot         (50, 10, 110, 50);
333         ApAltitudeDialogOkButton     ->     setLegend         (gui_msg_OK);
334         ApAltitudeDialogOkButton     ->     makeReturnDefault (TRUE);
335         ApAltitudeDialogOkButton     ->     setCallback       (ApAltitudeDialog_OK);
336
337         ApAltitudeDialogCancelButton =  new puOneShot         (140, 10, 210, 50);
338         ApAltitudeDialogCancelButton ->     setLegend         (gui_msg_CANCEL);
339         ApAltitudeDialogCancelButton ->     setCallback       (ApAltitudeDialog_Cancel);
340
341     }
342     FG_FINALIZE_PUI_DIALOG( ApAltitudeDialog );
343 }
344
345
346 static void maxroll_adj( puObject *hs ) {
347     float val ;
348     
349     hs-> getValue ( &val ) ;
350     SG_CLAMP_RANGE ( val, 0.1f, 1.0f ) ;
351     //    printf ( "maxroll_adj( %p ) %f %f\n", hs, val, MaxRollAdjust * val ) ;
352     current_autopilot->set_MaxRoll( MaxRollAdjust * val );
353     sprintf( SliderText[ 0 ], "%05.2f", current_autopilot->get_MaxRoll() );
354     APAdjustMaxRollText -> setLabel ( SliderText[ 0 ] ) ;
355 }
356
357 static void rollout_adj( puObject *hs ) {
358     float val ;
359
360     hs-> getValue ( &val ) ;
361     SG_CLAMP_RANGE ( val, 0.1f, 1.0f ) ;
362     //    printf ( "rollout_adj( %p ) %f %f\n", hs, val, RollOutAdjust * val ) ;
363     current_autopilot->set_RollOut( RollOutAdjust * val );
364     sprintf( SliderText[ 1 ], "%05.2f", current_autopilot->get_RollOut() );
365     APAdjustRollOutText -> setLabel ( SliderText[ 1 ] );
366 }
367
368 static void maxaileron_adj( puObject *hs ) {
369     float val ;
370
371     hs-> getValue ( &val ) ;
372     SG_CLAMP_RANGE ( val, 0.1f, 1.0f ) ;
373     //    printf ( "maxaileron_adj( %p ) %f %f\n", hs, val, MaxAileronAdjust * val ) ;
374     current_autopilot->set_MaxAileron( MaxAileronAdjust * val );
375     sprintf( SliderText[ 3 ], "%05.2f", current_autopilot->get_MaxAileron() );
376     APAdjustMaxAileronText -> setLabel ( SliderText[ 3 ] );
377 }
378
379 static void rolloutsmooth_adj( puObject *hs ) {
380     float val ;
381
382     hs -> getValue ( &val ) ;
383     SG_CLAMP_RANGE ( val, 0.1f, 1.0f ) ;
384     //    printf ( "rolloutsmooth_adj( %p ) %f %f\n", hs, val, RollOutSmoothAdjust * val ) ;
385     current_autopilot->set_RollOutSmooth( RollOutSmoothAdjust * val );
386     sprintf( SliderText[ 2 ], "%5.2f", current_autopilot->get_RollOutSmooth() );
387     APAdjustRollOutSmoothText-> setLabel ( SliderText[ 2 ] );
388
389 }
390
391 static void goAwayAPAdjust (puObject *)
392 {
393     FG_POP_PUI_DIALOG( APAdjustDialog );
394 }
395
396 void cancelAPAdjust( puObject *self ) {
397     current_autopilot->set_MaxRoll( TmpMaxRollValue );
398     current_autopilot->set_RollOut( TmpRollOutValue );
399     current_autopilot->set_MaxAileron( TmpMaxAileronValue );
400     current_autopilot->set_RollOutSmooth( TmpRollOutSmoothValue );
401
402     goAwayAPAdjust(self);
403 }
404
405 void resetAPAdjust( puObject *self ) {
406     current_autopilot->set_MaxRoll( MaxRollAdjust / 2 );
407     current_autopilot->set_RollOut( RollOutAdjust / 2 );
408     current_autopilot->set_MaxAileron( MaxAileronAdjust / 2 );
409     current_autopilot->set_RollOutSmooth( RollOutSmoothAdjust / 2 );
410
411     FG_POP_PUI_DIALOG( APAdjustDialog );
412
413     fgAPAdjust( self );
414 }
415
416 void fgAPAdjust( puObject *self ) {
417     TmpMaxRollValue       = current_autopilot->get_MaxRoll();
418     TmpRollOutValue       = current_autopilot->get_RollOut();
419     TmpMaxAileronValue    = current_autopilot->get_MaxAileron();
420     TmpRollOutSmoothValue = current_autopilot->get_RollOutSmooth();
421
422     MaxRollValue       = current_autopilot->get_MaxRoll() / MaxRollAdjust;
423     RollOutValue       = current_autopilot->get_RollOut() / RollOutAdjust;
424     MaxAileronValue    = current_autopilot->get_MaxAileron() / MaxAileronAdjust;
425     RollOutSmoothValue = current_autopilot->get_RollOutSmooth()
426         / RollOutSmoothAdjust;
427
428     APAdjustHS0-> setValue ( MaxRollValue ) ;
429     APAdjustHS1-> setValue ( RollOutValue ) ;
430     APAdjustHS2-> setValue ( RollOutSmoothValue ) ;
431     APAdjustHS3-> setValue ( MaxAileronValue ) ;
432
433     FG_PUSH_PUI_DIALOG( APAdjustDialog );
434 }
435
436 // Done once at system initialization
437 void fgAPAdjustInit() {
438
439     //  printf("fgAPAdjustInit\n");
440 #define HORIZONTAL  FALSE
441
442     int DialogX = 40;
443     int DialogY = 100;
444     int DialogWidth = 230;
445
446     char Label[] =  "AutoPilot Adjust";
447     char *s;
448
449     int labelX = (DialogWidth / 2) -
450         (puGetDefaultLabelFont().getStringWidth( Label ) / 2);
451     labelX -= 30;  // KLUDGEY
452
453     int nSliders = 4;
454     int slider_x = 10;
455     int slider_y = 55;
456     int slider_width = 210;
457     int slider_title_x = 15;
458     int slider_value_x = 160;
459     float slider_delta = 0.1f;
460
461     TmpMaxRollValue       = current_autopilot->get_MaxRoll();
462     TmpRollOutValue       = current_autopilot->get_RollOut();
463     TmpMaxAileronValue    = current_autopilot->get_MaxAileron();
464     TmpRollOutSmoothValue = current_autopilot->get_RollOutSmooth();
465
466     MaxRollAdjust = 2 * current_autopilot->get_MaxRoll();
467     RollOutAdjust = 2 * current_autopilot->get_RollOut();
468     MaxAileronAdjust = 2 * current_autopilot->get_MaxAileron();
469     RollOutSmoothAdjust = 2 * current_autopilot->get_RollOutSmooth();
470
471     MaxRollValue       = current_autopilot->get_MaxRoll() / MaxRollAdjust;
472     RollOutValue       = current_autopilot->get_RollOut() / RollOutAdjust;
473     MaxAileronValue    = current_autopilot->get_MaxAileron() / MaxAileronAdjust;
474     RollOutSmoothValue = current_autopilot->get_RollOutSmooth()
475         / RollOutSmoothAdjust;
476
477     puGetDefaultFonts (  &APAdjustLegendFont,  &APAdjustLabelFont );
478     APAdjustDialog = new puDialogBox ( DialogX, DialogY ); {
479         int horiz_slider_height = APAdjustLabelFont.getStringHeight() +
480             APAdjustLabelFont.getStringDescender() +
481             PUSTR_TGAP + PUSTR_BGAP + 5;
482
483         APAdjustFrame = new puFrame ( 0, 0,
484                                       DialogWidth,
485                                       85 + nSliders * horiz_slider_height );
486
487         APAdjustDialogMessage = new puText ( labelX,
488                                              52 + nSliders
489                                              * horiz_slider_height );
490         APAdjustDialogMessage -> setDefaultValue ( Label );
491         APAdjustDialogMessage -> getDefaultValue ( &s );
492         APAdjustDialogMessage -> setLabel        ( s );
493
494         APAdjustHS0 = new mySlider ( slider_x, slider_y,
495                                      slider_width, HORIZONTAL ) ;
496         APAdjustHS0-> setDelta ( slider_delta ) ;
497         APAdjustHS0-> setValue ( MaxRollValue ) ;
498         APAdjustHS0-> setCBMode ( PUSLIDER_DELTA ) ;
499         APAdjustHS0-> setCallback ( maxroll_adj ) ;
500
501         sprintf( SliderText[ 0 ], "%05.2f", current_autopilot->get_MaxRoll() );
502         APAdjustMaxRollTitle = new puText ( slider_title_x, slider_y ) ;
503         APAdjustMaxRollTitle-> setDefaultValue ( "MaxRoll" ) ;
504         APAdjustMaxRollTitle-> getDefaultValue ( &s ) ;
505         APAdjustMaxRollTitle-> setLabel ( s ) ;
506         APAdjustMaxRollText = new puText ( slider_value_x, slider_y ) ;
507         APAdjustMaxRollText-> setLabel ( SliderText[ 0 ] ) ;
508
509         slider_y += horiz_slider_height;
510
511         APAdjustHS1 = new mySlider ( slider_x, slider_y, slider_width,
512                                      HORIZONTAL ) ;
513         APAdjustHS1-> setDelta ( slider_delta ) ;
514         APAdjustHS1-> setValue ( RollOutValue ) ;
515         APAdjustHS1-> setCBMode ( PUSLIDER_DELTA ) ;
516         APAdjustHS1-> setCallback ( rollout_adj ) ;
517
518         sprintf( SliderText[ 1 ], "%05.2f", current_autopilot->get_RollOut() );
519         APAdjustRollOutTitle = new puText ( slider_title_x, slider_y ) ;
520         APAdjustRollOutTitle-> setDefaultValue ( "AdjustRollOut" ) ;
521         APAdjustRollOutTitle-> getDefaultValue ( &s ) ;
522         APAdjustRollOutTitle-> setLabel ( s ) ;
523         APAdjustRollOutText = new puText ( slider_value_x, slider_y ) ;
524         APAdjustRollOutText-> setLabel ( SliderText[ 1 ] );
525
526         slider_y += horiz_slider_height;
527
528         APAdjustHS2 = new mySlider ( slider_x, slider_y, slider_width,
529                                      HORIZONTAL ) ;
530         APAdjustHS2-> setDelta ( slider_delta ) ;
531         APAdjustHS2-> setValue ( RollOutSmoothValue ) ;
532         APAdjustHS2-> setCBMode ( PUSLIDER_DELTA ) ;
533         APAdjustHS2-> setCallback ( rolloutsmooth_adj ) ;
534
535         sprintf( SliderText[ 2 ], "%5.2f", 
536                  current_autopilot->get_RollOutSmooth() );
537         APAdjustRollOutSmoothTitle = new puText ( slider_title_x, slider_y ) ;
538         APAdjustRollOutSmoothTitle-> setDefaultValue ( "RollOutSmooth" ) ;
539         APAdjustRollOutSmoothTitle-> getDefaultValue ( &s ) ;
540         APAdjustRollOutSmoothTitle-> setLabel ( s ) ;
541         APAdjustRollOutSmoothText = new puText ( slider_value_x, slider_y ) ;
542         APAdjustRollOutSmoothText-> setLabel ( SliderText[ 2 ] );
543
544         slider_y += horiz_slider_height;
545
546         APAdjustHS3 = new mySlider ( slider_x, slider_y, slider_width,
547                                      HORIZONTAL ) ;
548         APAdjustHS3-> setDelta ( slider_delta ) ;
549         APAdjustHS3-> setValue ( MaxAileronValue ) ;
550         APAdjustHS3-> setCBMode ( PUSLIDER_DELTA ) ;
551         APAdjustHS3-> setCallback ( maxaileron_adj ) ;
552
553         sprintf( SliderText[ 3 ], "%05.2f", 
554                  current_autopilot->get_MaxAileron() );
555         APAdjustMaxAileronTitle = new puText ( slider_title_x, slider_y ) ;
556         APAdjustMaxAileronTitle-> setDefaultValue ( "MaxAileron" ) ;
557         APAdjustMaxAileronTitle-> getDefaultValue ( &s ) ;
558         APAdjustMaxAileronTitle-> setLabel ( s ) ;
559         APAdjustMaxAileronText = new puText ( slider_value_x, slider_y ) ;
560         APAdjustMaxAileronText-> setLabel ( SliderText[ 3 ] );
561
562         APAdjustOkButton = new puOneShot ( 10, 10, 60, 50 );
563         APAdjustOkButton-> setLegend ( gui_msg_OK );
564         APAdjustOkButton-> makeReturnDefault ( TRUE );
565         APAdjustOkButton-> setCallback ( goAwayAPAdjust );
566
567         APAdjustCancelButton = new puOneShot ( 70, 10, 150, 50 );
568         APAdjustCancelButton-> setLegend ( gui_msg_CANCEL );
569         APAdjustCancelButton-> setCallback ( cancelAPAdjust );
570
571         APAdjustResetButton = new puOneShot ( 160, 10, 220, 50 );
572         APAdjustResetButton-> setLegend ( gui_msg_RESET );
573         APAdjustResetButton-> setCallback ( resetAPAdjust );
574     }
575     FG_FINALIZE_PUI_DIALOG( APAdjustDialog );
576
577 #undef HORIZONTAL
578 }
579
580 // Simple Dialog to input Target Airport
581 void TgtAptDialog_Cancel(puObject *)
582 {
583     FG_POP_PUI_DIALOG( TgtAptDialog );
584 }
585
586 void TgtAptDialog_OK (puObject *)
587 {
588     string TgtAptId;
589     
590     //    FGTime *t = FGTime::cur_time_params;
591     //    int PauseMode = t->getPause();
592     //    if(!PauseMode)
593     //        t->togglePauseMode();
594     
595     char *s;
596     TgtAptDialogInput->getValue(&s);
597
598     string tmp = s;
599     double alt = 0.0;
600     unsigned int pos = tmp.find( "@" );
601     if ( pos != string::npos ) {
602         TgtAptId = tmp.substr( 0, pos );
603         string alt_str = tmp.substr( pos + 1 );
604         alt = atof( alt_str.c_str() );
605         if ( fgGetString("/sim/startup/units") == "feet" ) {
606             alt *= SG_FEET_TO_METER;
607         }
608     } else {
609         TgtAptId = tmp;
610     }
611
612     TgtAptDialog_Cancel( NULL );
613     
614     FGAirport a;
615     FGFix f;
616     double t1, t2;
617     if ( fgFindAirportID( TgtAptId, &a ) ) {
618
619          SG_LOG( SG_GENERAL, SG_INFO,
620                  "Adding waypoint (airport) = " << TgtAptId );
621         
622          sprintf( NewTgtAirportId, "%s", TgtAptId.c_str() );
623
624          SGWayPoint wp( a.longitude, a.latitude, alt,
625                         SGWayPoint::WGS84, TgtAptId );
626          globals->get_route()->add_waypoint( wp );
627     } else if ( current_fixlist->query( TgtAptId, 0.0, 0.0, 0.0,
628                                         &f, &t1, &t2 ) )
629     {
630          SG_LOG( SG_GENERAL, SG_INFO,
631                  "Adding waypoint (fix) = " << TgtAptId );
632         
633          sprintf( NewTgtAirportId, "%s", TgtAptId.c_str() );
634
635          SGWayPoint wp( f.get_lon(), f.get_lat(), alt,
636                         SGWayPoint::WGS84, TgtAptId );
637          globals->get_route()->add_waypoint( wp );
638     } else {
639         TgtAptId  += " not in database.";
640         mkDialog(TgtAptId.c_str());
641     }
642 }
643
644 void TgtAptDialog_Reset(puObject *)
645 {
646     sprintf( NewTgtAirportId, "%s", fgGetString("/sim/startup/airport-id").c_str() );
647     TgtAptDialogInput->setValue ( NewTgtAirportId );
648     TgtAptDialogInput->setCursor( 0 ) ;
649 }
650
651 void AddWayPoint(puObject *cb)
652 {
653     sprintf( NewTgtAirportId, "%s", fgGetString("/sim/startup/airport-id").c_str() );
654     TgtAptDialogInput->setValue( NewTgtAirportId );
655     
656     FG_PUSH_PUI_DIALOG( TgtAptDialog );
657 }
658
659 void PopWayPoint(puObject *cb)
660 {
661     globals->get_route()->delete_first();
662
663     // see if there are more waypoints on the list
664     if ( globals->get_route()->size() ) {
665         // more waypoints
666         current_autopilot->set_HeadingMode( FGAutopilot::FG_HEADING_WAYPOINT );
667     } else {
668         // end of the line
669         current_autopilot->set_HeadingMode( FGAutopilot::FG_TC_HEADING_LOCK );
670
671         // use current heading
672         current_autopilot
673             ->set_TargetHeading(fgGetDouble("/orientation/heading-deg"));
674     }
675 }
676
677 void ClearRoute(puObject *cb)
678 {
679     globals->get_route()->clear();
680 }
681
682 void NewTgtAirportInit()
683 {
684     SG_LOG( SG_AUTOPILOT, SG_INFO, " enter NewTgtAirportInit()" );
685     sprintf( NewTgtAirportId, "%s",
686              fgGetString("/sim/startup/airport-id").c_str() );
687     SG_LOG( SG_AUTOPILOT, SG_INFO, " NewTgtAirportId " << NewTgtAirportId );
688     int len = 150
689         - puGetDefaultLabelFont().getStringWidth( NewTgtAirportLabel ) / 2;
690     
691     TgtAptDialog = new puDialogBox (150, 50);
692     {
693         TgtAptDialogFrame   = new puFrame           (0,0,350, 150);
694         TgtAptDialogMessage = new puText            (len, 110);
695         TgtAptDialogMessage ->    setLabel          (NewTgtAirportLabel);
696         
697         TgtAptDialogInput   = new puInput           (50, 70, 300, 100);
698         TgtAptDialogInput   ->    setValue          (NewTgtAirportId);
699         TgtAptDialogInput   ->    acceptInput();
700         
701         TgtAptDialogOkButton     =  new puOneShot   (50, 10, 110, 50);
702         TgtAptDialogOkButton     ->     setLegend   (gui_msg_OK);
703         TgtAptDialogOkButton     ->     setCallback (TgtAptDialog_OK);
704         TgtAptDialogOkButton     ->     makeReturnDefault(TRUE);
705         
706         TgtAptDialogCancelButton =  new puOneShot   (140, 10, 210, 50);
707         TgtAptDialogCancelButton ->     setLegend   (gui_msg_CANCEL);
708         TgtAptDialogCancelButton ->     setCallback (TgtAptDialog_Cancel);
709         
710         TgtAptDialogResetButton  =  new puOneShot   (240, 10, 300, 50);
711         TgtAptDialogResetButton  ->     setLegend   (gui_msg_RESET);
712         TgtAptDialogResetButton  ->     setCallback (TgtAptDialog_Reset);
713     }
714     FG_FINALIZE_PUI_DIALOG( TgtAptDialog );
715     printf("leave NewTgtAirportInit()");
716 }