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