1 // auto_gui.cxx -- autopilot gui interface
3 // Written by Norman Vine <nhv@cape.com>
4 // Arranged by Curt Olson <curt@flightgear.org>
6 // Copyright (C) 1998 - 2000
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.
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.
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.
32 #include <Scenery/scenery.hxx>
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>
39 #include <Airports/simple.hxx>
41 #include <Main/bfi.hxx>
42 #include <Main/fg_init.hxx>
43 #include <Main/globals.hxx>
44 #include <Main/fg_props.hxx>
45 #include <Navaids/fixlist.hxx>
47 #include "auto_gui.hxx"
48 #include "newauto.hxx"
51 #define mySlider puSlider
53 // Climb speed constants
54 const double min_climb = 70.0; // kts
55 const double best_climb = 75.0; // kts
56 const double ideal_climb_rate = 500.0; // fpm
58 /// These statics will eventually go into the class
59 /// they are just here while I am experimenting -- NHV :-)
60 // AutoPilot Gain Adjuster members
61 static double MaxRollAdjust; // MaxRollAdjust = 2 * APData->MaxRoll;
62 static double RollOutAdjust; // RollOutAdjust = 2 * APData->RollOut;
63 static double MaxAileronAdjust; // MaxAileronAdjust = 2 * APData->MaxAileron;
64 static double RollOutSmoothAdjust; // RollOutSmoothAdjust = 2 * APData->RollOutSmooth;
66 static float MaxRollValue; // 0.1 -> 1.0
67 static float RollOutValue;
68 static float MaxAileronValue;
69 static float RollOutSmoothValue;
71 static float TmpMaxRollValue; // for cancel operation
72 static float TmpRollOutValue;
73 static float TmpMaxAileronValue;
74 static float TmpRollOutSmoothValue;
76 static puDialogBox *APAdjustDialog;
77 static puFrame *APAdjustFrame;
78 static puText *APAdjustDialogMessage;
79 static puFont APAdjustLegendFont;
80 static puFont APAdjustLabelFont;
82 static puOneShot *APAdjustOkButton;
83 static puOneShot *APAdjustResetButton;
84 static puOneShot *APAdjustCancelButton;
86 //static puButton *APAdjustDragButton;
88 static puText *APAdjustMaxRollTitle;
89 static puText *APAdjustRollOutTitle;
90 static puText *APAdjustMaxAileronTitle;
91 static puText *APAdjustRollOutSmoothTitle;
93 static puText *APAdjustMaxAileronText;
94 static puText *APAdjustMaxRollText;
95 static puText *APAdjustRollOutText;
96 static puText *APAdjustRollOutSmoothText;
98 static mySlider *APAdjustHS0;
99 static mySlider *APAdjustHS1;
100 static mySlider *APAdjustHS2;
101 static mySlider *APAdjustHS3;
103 static char SliderText[ 4 ][ 8 ];
105 ///////// AutoPilot New Heading Dialog
107 static puDialogBox *ApHeadingDialog;
108 static puFrame *ApHeadingDialogFrame;
109 static puText *ApHeadingDialogMessage;
110 static puInput *ApHeadingDialogInput;
111 static puOneShot *ApHeadingDialogOkButton;
112 static puOneShot *ApHeadingDialogCancelButton;
115 ///////// AutoPilot New Altitude Dialog
117 static puDialogBox *ApAltitudeDialog = 0;
118 static puFrame *ApAltitudeDialogFrame = 0;
119 static puText *ApAltitudeDialogMessage = 0;
120 static puInput *ApAltitudeDialogInput = 0;
122 static puOneShot *ApAltitudeDialogOkButton = 0;
123 static puOneShot *ApAltitudeDialogCancelButton = 0;
126 /// The beginnings of Lock AutoPilot to target location :-)
127 // Needs cleaning up but works
128 // These statics should disapear when this is a class
129 static puDialogBox *TgtAptDialog = 0;
130 static puFrame *TgtAptDialogFrame = 0;
131 static puText *TgtAptDialogMessage = 0;
132 static puInput *TgtAptDialogInput = 0;
134 static char NewTgtAirportId[16];
135 static char NewTgtAirportLabel[] = "Enter New TgtAirport ID";
137 static puOneShot *TgtAptDialogOkButton = 0;
138 static puOneShot *TgtAptDialogCancelButton = 0;
139 static puOneShot *TgtAptDialogResetButton = 0;
142 // extern char *coord_format_lat(float);
143 // extern char *coord_format_lon(float);
145 // THIS NEEDS IMPROVEMENT !!!!!!!!!!!!!
146 static int scan_number(char *s, double *new_value)
151 char *WordBufPtr = WordBuf;
156 *WordBufPtr++ = *cptr++;
158 while (isdigit(*cptr) ) {
159 *WordBufPtr++ = *cptr++;
163 *WordBufPtr++ = *cptr++; // put the '.' into the string
164 while (isdigit(*cptr)) {
165 *WordBufPtr++ = *cptr++;
170 sscanf(WordBuf, "%lf", new_value);
177 void ApHeadingDialog_Cancel(puObject *)
179 ApHeadingDialogInput->rejectInput();
180 FG_POP_PUI_DIALOG( ApHeadingDialog );
183 void ApHeadingDialog_OK (puObject *me)
188 ApHeadingDialogInput -> getValue( &c );
192 if( scan_number( c, &NewHeading ) )
194 if ( !current_autopilot->get_HeadingEnabled() ) {
195 current_autopilot->set_HeadingEnabled( true );
197 current_autopilot->HeadingSet( NewHeading );
201 s += " is not a valid number.";
204 ApHeadingDialog_Cancel(me);
205 if( error ) mkDialog(s.c_str());
208 void NewHeading(puObject *cb)
210 // string ApHeadingLabel( "Enter New Heading" );
211 // ApHeadingDialogMessage -> setLabel(ApHeadingLabel.c_str());
212 ApHeadingDialogInput -> acceptInput();
213 FG_PUSH_PUI_DIALOG( ApHeadingDialog );
216 void NewHeadingInit(void)
218 // printf("NewHeadingInit\n");
219 char NewHeadingLabel[] = "Enter New Heading";
222 float heading = FGBFI::getHeading();
224 (puGetStringWidth( puGetDefaultLabelFont(), NewHeadingLabel ) /2 );
226 ApHeadingDialog = new puDialogBox (150, 50);
228 ApHeadingDialogFrame = new puFrame (0, 0, 260, 150);
230 ApHeadingDialogMessage = new puText (len, 110);
231 ApHeadingDialogMessage -> setDefaultValue (NewHeadingLabel);
232 ApHeadingDialogMessage -> getDefaultValue (&s);
233 ApHeadingDialogMessage -> setLabel (s);
235 ApHeadingDialogInput = new puInput ( 50, 70, 210, 100 );
236 ApHeadingDialogInput -> setValue ( heading );
238 ApHeadingDialogOkButton = new puOneShot (50, 10, 110, 50);
239 ApHeadingDialogOkButton -> setLegend (gui_msg_OK);
240 ApHeadingDialogOkButton -> makeReturnDefault (TRUE);
241 ApHeadingDialogOkButton -> setCallback (ApHeadingDialog_OK);
243 ApHeadingDialogCancelButton = new puOneShot (140, 10, 210, 50);
244 ApHeadingDialogCancelButton -> setLegend (gui_msg_CANCEL);
245 ApHeadingDialogCancelButton -> setCallback (ApHeadingDialog_Cancel);
248 FG_FINALIZE_PUI_DIALOG( ApHeadingDialog );
251 void ApAltitudeDialog_Cancel(puObject *)
253 ApAltitudeDialogInput -> rejectInput();
254 FG_POP_PUI_DIALOG( ApAltitudeDialog );
257 void ApAltitudeDialog_OK (puObject *me)
262 ApAltitudeDialogInput->getValue( &c );
266 if( scan_number( c, &NewAltitude) )
268 if ( !current_autopilot->get_AltitudeEnabled() ) {
269 current_autopilot->set_AltitudeEnabled( true );
271 current_autopilot->AltitudeSet( NewAltitude );
275 s += " is not a valid number.";
278 ApAltitudeDialog_Cancel(me);
279 if( error ) mkDialog(s.c_str());
282 void NewAltitude(puObject *cb)
284 ApAltitudeDialogInput -> acceptInput();
285 FG_PUSH_PUI_DIALOG( ApAltitudeDialog );
288 void NewAltitudeInit(void)
290 // printf("NewAltitudeInit\n");
291 char NewAltitudeLabel[] = "Enter New Altitude";
294 float alt = cur_fdm_state->get_Altitude();
296 if ( fgGetString("/sim/startup/units") == "meters") {
297 alt *= SG_FEET_TO_METER;
301 (puGetStringWidth( puGetDefaultLabelFont(), NewAltitudeLabel )/2);
303 // ApAltitudeDialog = new puDialogBox (150, 50);
304 ApAltitudeDialog = new puDialogBox (150, 200);
306 ApAltitudeDialogFrame = new puFrame (0, 0, 260, 150);
307 ApAltitudeDialogMessage = new puText (len, 110);
308 ApAltitudeDialogMessage -> setDefaultValue (NewAltitudeLabel);
309 ApAltitudeDialogMessage -> getDefaultValue (&s);
310 ApAltitudeDialogMessage -> setLabel (s);
312 ApAltitudeDialogInput = new puInput ( 50, 70, 210, 100 );
313 ApAltitudeDialogInput -> setValue ( alt );
314 // Uncomment the next line to have input active on startup
315 // ApAltitudeDialogInput -> acceptInput ( );
316 // cursor at begining or end of line ?
319 // ApAltitudeDialogInput -> setCursor ( len );
320 // ApAltitudeDialogInput -> setSelectRegion ( 5, 9 );
322 ApAltitudeDialogOkButton = new puOneShot (50, 10, 110, 50);
323 ApAltitudeDialogOkButton -> setLegend (gui_msg_OK);
324 ApAltitudeDialogOkButton -> makeReturnDefault (TRUE);
325 ApAltitudeDialogOkButton -> setCallback (ApAltitudeDialog_OK);
327 ApAltitudeDialogCancelButton = new puOneShot (140, 10, 210, 50);
328 ApAltitudeDialogCancelButton -> setLegend (gui_msg_CANCEL);
329 ApAltitudeDialogCancelButton -> setCallback (ApAltitudeDialog_Cancel);
332 FG_FINALIZE_PUI_DIALOG( ApAltitudeDialog );
335 /////// simple AutoPilot GAIN / LIMITS ADJUSTER
337 #define fgAP_CLAMP(val,min,max) ( (val) = (val) > (max) ? (max) : (val) < (min) ? (min) : (val) )
339 static void maxroll_adj( puObject *hs ) {
342 hs-> getValue ( &val ) ;
343 fgAP_CLAMP ( val, 0.1, 1.0 ) ;
344 // printf ( "maxroll_adj( %p ) %f %f\n", hs, val, MaxRollAdjust * val ) ;
345 current_autopilot->set_MaxRoll( MaxRollAdjust * val );
346 sprintf( SliderText[ 0 ], "%05.2f", current_autopilot->get_MaxRoll() );
347 APAdjustMaxRollText -> setLabel ( SliderText[ 0 ] ) ;
350 static void rollout_adj( puObject *hs ) {
353 hs-> getValue ( &val ) ;
354 fgAP_CLAMP ( val, 0.1, 1.0 ) ;
355 // printf ( "rollout_adj( %p ) %f %f\n", hs, val, RollOutAdjust * val ) ;
356 current_autopilot->set_RollOut( RollOutAdjust * val );
357 sprintf( SliderText[ 1 ], "%05.2f", current_autopilot->get_RollOut() );
358 APAdjustRollOutText -> setLabel ( SliderText[ 1 ] );
361 static void maxaileron_adj( puObject *hs ) {
364 hs-> getValue ( &val ) ;
365 fgAP_CLAMP ( val, 0.1, 1.0 ) ;
366 // printf ( "maxaileron_adj( %p ) %f %f\n", hs, val, MaxAileronAdjust * val ) ;
367 current_autopilot->set_MaxAileron( MaxAileronAdjust * val );
368 sprintf( SliderText[ 3 ], "%05.2f", current_autopilot->get_MaxAileron() );
369 APAdjustMaxAileronText -> setLabel ( SliderText[ 3 ] );
372 static void rolloutsmooth_adj( puObject *hs ) {
375 hs -> getValue ( &val ) ;
376 fgAP_CLAMP ( val, 0.1, 1.0 ) ;
377 // printf ( "rolloutsmooth_adj( %p ) %f %f\n", hs, val, RollOutSmoothAdjust * val ) ;
378 current_autopilot->set_RollOutSmooth( RollOutSmoothAdjust * val );
379 sprintf( SliderText[ 2 ], "%5.2f", current_autopilot->get_RollOutSmooth() );
380 APAdjustRollOutSmoothText-> setLabel ( SliderText[ 2 ] );
384 static void goAwayAPAdjust (puObject *)
386 FG_POP_PUI_DIALOG( APAdjustDialog );
389 void cancelAPAdjust( puObject *self ) {
390 current_autopilot->set_MaxRoll( TmpMaxRollValue );
391 current_autopilot->set_RollOut( TmpRollOutValue );
392 current_autopilot->set_MaxAileron( TmpMaxAileronValue );
393 current_autopilot->set_RollOutSmooth( TmpRollOutSmoothValue );
395 goAwayAPAdjust(self);
398 void resetAPAdjust( puObject *self ) {
399 current_autopilot->set_MaxRoll( MaxRollAdjust / 2 );
400 current_autopilot->set_RollOut( RollOutAdjust / 2 );
401 current_autopilot->set_MaxAileron( MaxAileronAdjust / 2 );
402 current_autopilot->set_RollOutSmooth( RollOutSmoothAdjust / 2 );
404 FG_POP_PUI_DIALOG( APAdjustDialog );
409 void fgAPAdjust( puObject * ) {
410 TmpMaxRollValue = current_autopilot->get_MaxRoll();
411 TmpRollOutValue = current_autopilot->get_RollOut();
412 TmpMaxAileronValue = current_autopilot->get_MaxAileron();
413 TmpRollOutSmoothValue = current_autopilot->get_RollOutSmooth();
415 MaxRollValue = current_autopilot->get_MaxRoll() / MaxRollAdjust;
416 RollOutValue = current_autopilot->get_RollOut() / RollOutAdjust;
417 MaxAileronValue = current_autopilot->get_MaxAileron() / MaxAileronAdjust;
418 RollOutSmoothValue = current_autopilot->get_RollOutSmooth()
419 / RollOutSmoothAdjust;
421 APAdjustHS0-> setValue ( MaxRollValue ) ;
422 APAdjustHS1-> setValue ( RollOutValue ) ;
423 APAdjustHS2-> setValue ( RollOutSmoothValue ) ;
424 APAdjustHS3-> setValue ( MaxAileronValue ) ;
426 FG_PUSH_PUI_DIALOG( APAdjustDialog );
429 // Done once at system initialization
430 void fgAPAdjustInit( void ) {
432 // printf("fgAPAdjustInit\n");
433 #define HORIZONTAL FALSE
437 int DialogWidth = 230;
439 char Label[] = "AutoPilot Adjust";
442 int labelX = (DialogWidth / 2) -
443 (puGetStringWidth( puGetDefaultLabelFont(), Label ) / 2);
444 labelX -= 30; // KLUDGEY
449 int slider_width = 210;
450 int slider_title_x = 15;
451 int slider_value_x = 160;
452 float slider_delta = 0.1f;
454 TmpMaxRollValue = current_autopilot->get_MaxRoll();
455 TmpRollOutValue = current_autopilot->get_RollOut();
456 TmpMaxAileronValue = current_autopilot->get_MaxAileron();
457 TmpRollOutSmoothValue = current_autopilot->get_RollOutSmooth();
459 MaxRollAdjust = 2 * current_autopilot->get_MaxRoll();
460 RollOutAdjust = 2 * current_autopilot->get_RollOut();
461 MaxAileronAdjust = 2 * current_autopilot->get_MaxAileron();
462 RollOutSmoothAdjust = 2 * current_autopilot->get_RollOutSmooth();
464 MaxRollValue = current_autopilot->get_MaxRoll() / MaxRollAdjust;
465 RollOutValue = current_autopilot->get_RollOut() / RollOutAdjust;
466 MaxAileronValue = current_autopilot->get_MaxAileron() / MaxAileronAdjust;
467 RollOutSmoothValue = current_autopilot->get_RollOutSmooth()
468 / RollOutSmoothAdjust;
470 puGetDefaultFonts ( &APAdjustLegendFont, &APAdjustLabelFont );
471 APAdjustDialog = new puDialogBox ( DialogX, DialogY ); {
472 int horiz_slider_height = puGetStringHeight (APAdjustLabelFont) +
473 puGetStringDescender (APAdjustLabelFont) +
474 PUSTR_TGAP + PUSTR_BGAP + 5;
476 APAdjustFrame = new puFrame ( 0, 0,
478 85 + nSliders * horiz_slider_height );
480 APAdjustDialogMessage = new puText ( labelX,
482 * horiz_slider_height );
483 APAdjustDialogMessage -> setDefaultValue ( Label );
484 APAdjustDialogMessage -> getDefaultValue ( &s );
485 APAdjustDialogMessage -> setLabel ( s );
487 APAdjustHS0 = new mySlider ( slider_x, slider_y,
488 slider_width, HORIZONTAL ) ;
489 APAdjustHS0-> setDelta ( slider_delta ) ;
490 APAdjustHS0-> setValue ( MaxRollValue ) ;
491 APAdjustHS0-> setCBMode ( PUSLIDER_DELTA ) ;
492 APAdjustHS0-> setCallback ( maxroll_adj ) ;
494 sprintf( SliderText[ 0 ], "%05.2f", current_autopilot->get_MaxRoll() );
495 APAdjustMaxRollTitle = new puText ( slider_title_x, slider_y ) ;
496 APAdjustMaxRollTitle-> setDefaultValue ( "MaxRoll" ) ;
497 APAdjustMaxRollTitle-> getDefaultValue ( &s ) ;
498 APAdjustMaxRollTitle-> setLabel ( s ) ;
499 APAdjustMaxRollText = new puText ( slider_value_x, slider_y ) ;
500 APAdjustMaxRollText-> setLabel ( SliderText[ 0 ] ) ;
502 slider_y += horiz_slider_height;
504 APAdjustHS1 = new mySlider ( slider_x, slider_y, slider_width,
506 APAdjustHS1-> setDelta ( slider_delta ) ;
507 APAdjustHS1-> setValue ( RollOutValue ) ;
508 APAdjustHS1-> setCBMode ( PUSLIDER_DELTA ) ;
509 APAdjustHS1-> setCallback ( rollout_adj ) ;
511 sprintf( SliderText[ 1 ], "%05.2f", current_autopilot->get_RollOut() );
512 APAdjustRollOutTitle = new puText ( slider_title_x, slider_y ) ;
513 APAdjustRollOutTitle-> setDefaultValue ( "AdjustRollOut" ) ;
514 APAdjustRollOutTitle-> getDefaultValue ( &s ) ;
515 APAdjustRollOutTitle-> setLabel ( s ) ;
516 APAdjustRollOutText = new puText ( slider_value_x, slider_y ) ;
517 APAdjustRollOutText-> setLabel ( SliderText[ 1 ] );
519 slider_y += horiz_slider_height;
521 APAdjustHS2 = new mySlider ( slider_x, slider_y, slider_width,
523 APAdjustHS2-> setDelta ( slider_delta ) ;
524 APAdjustHS2-> setValue ( RollOutSmoothValue ) ;
525 APAdjustHS2-> setCBMode ( PUSLIDER_DELTA ) ;
526 APAdjustHS2-> setCallback ( rolloutsmooth_adj ) ;
528 sprintf( SliderText[ 2 ], "%5.2f",
529 current_autopilot->get_RollOutSmooth() );
530 APAdjustRollOutSmoothTitle = new puText ( slider_title_x, slider_y ) ;
531 APAdjustRollOutSmoothTitle-> setDefaultValue ( "RollOutSmooth" ) ;
532 APAdjustRollOutSmoothTitle-> getDefaultValue ( &s ) ;
533 APAdjustRollOutSmoothTitle-> setLabel ( s ) ;
534 APAdjustRollOutSmoothText = new puText ( slider_value_x, slider_y ) ;
535 APAdjustRollOutSmoothText-> setLabel ( SliderText[ 2 ] );
537 slider_y += horiz_slider_height;
539 APAdjustHS3 = new mySlider ( slider_x, slider_y, slider_width,
541 APAdjustHS3-> setDelta ( slider_delta ) ;
542 APAdjustHS3-> setValue ( MaxAileronValue ) ;
543 APAdjustHS3-> setCBMode ( PUSLIDER_DELTA ) ;
544 APAdjustHS3-> setCallback ( maxaileron_adj ) ;
546 sprintf( SliderText[ 3 ], "%05.2f",
547 current_autopilot->get_MaxAileron() );
548 APAdjustMaxAileronTitle = new puText ( slider_title_x, slider_y ) ;
549 APAdjustMaxAileronTitle-> setDefaultValue ( "MaxAileron" ) ;
550 APAdjustMaxAileronTitle-> getDefaultValue ( &s ) ;
551 APAdjustMaxAileronTitle-> setLabel ( s ) ;
552 APAdjustMaxAileronText = new puText ( slider_value_x, slider_y ) ;
553 APAdjustMaxAileronText-> setLabel ( SliderText[ 3 ] );
555 APAdjustOkButton = new puOneShot ( 10, 10, 60, 50 );
556 APAdjustOkButton-> setLegend ( gui_msg_OK );
557 APAdjustOkButton-> makeReturnDefault ( TRUE );
558 APAdjustOkButton-> setCallback ( goAwayAPAdjust );
560 APAdjustCancelButton = new puOneShot ( 70, 10, 150, 50 );
561 APAdjustCancelButton-> setLegend ( gui_msg_CANCEL );
562 APAdjustCancelButton-> setCallback ( cancelAPAdjust );
564 APAdjustResetButton = new puOneShot ( 160, 10, 220, 50 );
565 APAdjustResetButton-> setLegend ( gui_msg_RESET );
566 APAdjustResetButton-> setCallback ( resetAPAdjust );
568 FG_FINALIZE_PUI_DIALOG( APAdjustDialog );
573 // Simple Dialog to input Target Airport
574 void TgtAptDialog_Cancel(puObject *)
576 FG_POP_PUI_DIALOG( TgtAptDialog );
579 void TgtAptDialog_OK (puObject *)
583 // FGTime *t = FGTime::cur_time_params;
584 // int PauseMode = t->getPause();
586 // t->togglePauseMode();
589 TgtAptDialogInput->getValue(&s);
593 int pos = tmp.find( "@" );
594 if ( pos != string::npos ) {
595 TgtAptId = tmp.substr( 0, pos );
596 string alt_str = tmp.substr( pos + 1 );
597 alt = atof( alt_str.c_str() );
598 if ( fgGetString("/sim/startup/units") == "feet" ) {
599 alt *= SG_FEET_TO_METER;
605 TgtAptDialog_Cancel( NULL );
610 if ( fgFindAirportID( TgtAptId, &a ) ) {
612 SG_LOG( SG_GENERAL, SG_INFO,
613 "Adding waypoint (airport) = " << TgtAptId );
615 sprintf( NewTgtAirportId, "%s", TgtAptId.c_str() );
617 SGWayPoint wp( a.longitude, a.latitude, alt,
618 SGWayPoint::WGS84, TgtAptId );
619 globals->get_route()->add_waypoint( wp );
620 } else if ( current_fixlist->query( TgtAptId, 0.0, 0.0, 0.0,
623 SG_LOG( SG_GENERAL, SG_INFO,
624 "Adding waypoint (fix) = " << TgtAptId );
626 sprintf( NewTgtAirportId, "%s", TgtAptId.c_str() );
628 SGWayPoint wp( f.get_lon(), f.get_lat(), alt,
629 SGWayPoint::WGS84, TgtAptId );
630 globals->get_route()->add_waypoint( wp );
632 TgtAptId += " not in database.";
633 mkDialog(TgtAptId.c_str());
637 void TgtAptDialog_Reset(puObject *)
639 // strncpy( NewAirportId, fgGetString("/sim/startup/airport-id").c_str(), 16 );
640 sprintf( NewTgtAirportId, "%s", fgGetString("/sim/startup/airport-id").c_str() );
641 TgtAptDialogInput->setValue ( NewTgtAirportId );
642 TgtAptDialogInput->setCursor( 0 ) ;
645 void AddWayPoint(puObject *cb)
647 // strncpy( NewAirportId, fgGetString("/sim/startup/airport-id").c_str(), 16 );
648 sprintf( NewTgtAirportId, "%s", fgGetString("/sim/startup/airport-id").c_str() );
649 TgtAptDialogInput->setValue( NewTgtAirportId );
651 FG_PUSH_PUI_DIALOG( TgtAptDialog );
654 void PopWayPoint(puObject *cb)
656 globals->get_route()->delete_first();
658 // see if there are more waypoints on the list
659 if ( globals->get_route()->size() ) {
661 current_autopilot->set_HeadingMode( FGAutopilot::FG_HEADING_WAYPOINT );
664 current_autopilot->set_HeadingMode( FGAutopilot::FG_TC_HEADING_LOCK );
666 // use current heading
667 current_autopilot->set_TargetHeading( FGBFI::getHeading() );
671 void ClearRoute(puObject *cb)
673 globals->get_route()->clear();
676 void NewTgtAirportInit(void)
678 SG_LOG( SG_AUTOPILOT, SG_INFO, " enter NewTgtAirportInit()" );
679 // fgAPset_tgt_airport_id( fgGetString("/sim/startup/airport-id") );
680 sprintf( NewTgtAirportId, "%s", fgGetString("/sim/startup/airport-id").c_str() );
681 SG_LOG( SG_AUTOPILOT, SG_INFO, " NewTgtAirportId " << NewTgtAirportId );
682 // printf(" NewTgtAirportId %s\n", NewTgtAirportId);
683 int len = 150 - puGetStringWidth( puGetDefaultLabelFont(),
684 NewTgtAirportLabel ) / 2;
686 TgtAptDialog = new puDialogBox (150, 50);
688 TgtAptDialogFrame = new puFrame (0,0,350, 150);
689 TgtAptDialogMessage = new puText (len, 110);
690 TgtAptDialogMessage -> setLabel (NewTgtAirportLabel);
692 TgtAptDialogInput = new puInput (50, 70, 300, 100);
693 TgtAptDialogInput -> setValue (NewTgtAirportId);
694 TgtAptDialogInput -> acceptInput();
696 TgtAptDialogOkButton = new puOneShot (50, 10, 110, 50);
697 TgtAptDialogOkButton -> setLegend (gui_msg_OK);
698 TgtAptDialogOkButton -> setCallback (TgtAptDialog_OK);
699 TgtAptDialogOkButton -> makeReturnDefault(TRUE);
701 TgtAptDialogCancelButton = new puOneShot (140, 10, 210, 50);
702 TgtAptDialogCancelButton -> setLegend (gui_msg_CANCEL);
703 TgtAptDialogCancelButton -> setCallback (TgtAptDialog_Cancel);
705 TgtAptDialogResetButton = new puOneShot (240, 10, 300, 50);
706 TgtAptDialogResetButton -> setLegend (gui_msg_RESET);
707 TgtAptDialogResetButton -> setCallback (TgtAptDialog_Reset);
709 FG_FINALIZE_PUI_DIALOG( TgtAptDialog );
710 printf("leave NewTgtAirportInit()");