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