]> git.mxchange.org Git - flightgear.git/blob - src/Autopilot/auto_gui.cxx
Latest JSBSim changes.
[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/sg_path.hxx>
38
39 #include <Airports/simple.hxx>
40 #include <GUI/gui.h>
41 #include <Main/fg_init.hxx>
42 #include <Main/globals.hxx>
43 #include <Main/fg_props.hxx>
44 #include <Navaids/fixlist.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 = fgGetDouble("/orientation/heading-deg");
222     int len = 260/2 -
223         (puGetDefaultLabelFont().getStringWidth( 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 ( fgGetString("/sim/startup/units") == "meters") {
296         alt *= SG_FEET_TO_METER;
297     }
298
299     int len = 260/2 -
300         (puGetDefaultLabelFont().getStringWidth( 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         (puGetDefaultLabelFont().getStringWidth( 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 = APAdjustLabelFont.getStringHeight() +
472             APAdjustLabelFont.getStringDescender() +
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
590     string tmp = s;
591     double alt = 0.0;
592     unsigned int pos = tmp.find( "@" );
593     if ( pos != string::npos ) {
594         TgtAptId = tmp.substr( 0, pos );
595         string alt_str = tmp.substr( pos + 1 );
596         alt = atof( alt_str.c_str() );
597         if ( fgGetString("/sim/startup/units") == "feet" ) {
598             alt *= SG_FEET_TO_METER;
599         }
600     } else {
601         TgtAptId = tmp;
602     }
603
604     TgtAptDialog_Cancel( NULL );
605     
606     FGAirport a;
607     FGFix f;
608     double t1, t2;
609     if ( fgFindAirportID( TgtAptId, &a ) ) {
610
611          SG_LOG( SG_GENERAL, SG_INFO,
612                  "Adding waypoint (airport) = " << TgtAptId );
613         
614          sprintf( NewTgtAirportId, "%s", TgtAptId.c_str() );
615
616          SGWayPoint wp( a.longitude, a.latitude, alt,
617                         SGWayPoint::WGS84, TgtAptId );
618          globals->get_route()->add_waypoint( wp );
619     } else if ( current_fixlist->query( TgtAptId, 0.0, 0.0, 0.0,
620                                         &f, &t1, &t2 ) )
621     {
622          SG_LOG( SG_GENERAL, SG_INFO,
623                  "Adding waypoint (fix) = " << TgtAptId );
624         
625          sprintf( NewTgtAirportId, "%s", TgtAptId.c_str() );
626
627          SGWayPoint wp( f.get_lon(), f.get_lat(), alt,
628                         SGWayPoint::WGS84, TgtAptId );
629          globals->get_route()->add_waypoint( wp );
630     } else {
631         TgtAptId  += " not in database.";
632         mkDialog(TgtAptId.c_str());
633     }
634 }
635
636 void TgtAptDialog_Reset(puObject *)
637 {
638     sprintf( NewTgtAirportId, "%s", fgGetString("/sim/startup/airport-id").c_str() );
639     TgtAptDialogInput->setValue ( NewTgtAirportId );
640     TgtAptDialogInput->setCursor( 0 ) ;
641 }
642
643 void AddWayPoint(puObject *cb)
644 {
645     sprintf( NewTgtAirportId, "%s", fgGetString("/sim/startup/airport-id").c_str() );
646     TgtAptDialogInput->setValue( NewTgtAirportId );
647     
648     FG_PUSH_PUI_DIALOG( TgtAptDialog );
649 }
650
651 void PopWayPoint(puObject *cb)
652 {
653     globals->get_route()->delete_first();
654
655     // see if there are more waypoints on the list
656     if ( globals->get_route()->size() ) {
657         // more waypoints
658         current_autopilot->set_HeadingMode( FGAutopilot::FG_HEADING_WAYPOINT );
659     } else {
660         // end of the line
661         current_autopilot->set_HeadingMode( FGAutopilot::FG_TC_HEADING_LOCK );
662
663         // use current heading
664         current_autopilot
665             ->set_TargetHeading(fgGetDouble("/orientation/heading-deg"));
666     }
667 }
668
669 void ClearRoute(puObject *cb)
670 {
671     globals->get_route()->clear();
672 }
673
674 void NewTgtAirportInit(void)
675 {
676     SG_LOG( SG_AUTOPILOT, SG_INFO, " enter NewTgtAirportInit()" );
677     sprintf( NewTgtAirportId, "%s",
678              fgGetString("/sim/startup/airport-id").c_str() );
679     SG_LOG( SG_AUTOPILOT, SG_INFO, " NewTgtAirportId " << NewTgtAirportId );
680     int len = 150
681         - puGetDefaultLabelFont().getStringWidth( NewTgtAirportLabel ) / 2;
682     
683     TgtAptDialog = new puDialogBox (150, 50);
684     {
685         TgtAptDialogFrame   = new puFrame           (0,0,350, 150);
686         TgtAptDialogMessage = new puText            (len, 110);
687         TgtAptDialogMessage ->    setLabel          (NewTgtAirportLabel);
688         
689         TgtAptDialogInput   = new puInput           (50, 70, 300, 100);
690         TgtAptDialogInput   ->    setValue          (NewTgtAirportId);
691         TgtAptDialogInput   ->    acceptInput();
692         
693         TgtAptDialogOkButton     =  new puOneShot   (50, 10, 110, 50);
694         TgtAptDialogOkButton     ->     setLegend   (gui_msg_OK);
695         TgtAptDialogOkButton     ->     setCallback (TgtAptDialog_OK);
696         TgtAptDialogOkButton     ->     makeReturnDefault(TRUE);
697         
698         TgtAptDialogCancelButton =  new puOneShot   (140, 10, 210, 50);
699         TgtAptDialogCancelButton ->     setLegend   (gui_msg_CANCEL);
700         TgtAptDialogCancelButton ->     setCallback (TgtAptDialog_Cancel);
701         
702         TgtAptDialogResetButton  =  new puOneShot   (240, 10, 300, 50);
703         TgtAptDialogResetButton  ->     setLegend   (gui_msg_RESET);
704         TgtAptDialogResetButton  ->     setCallback (TgtAptDialog_Reset);
705     }
706     FG_FINALIZE_PUI_DIALOG( TgtAptDialog );
707     printf("leave NewTgtAirportInit()");
708 }