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