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.
29 #include <simgear/compiler.h>
37 #include <Aircraft/aircraft.hxx>
38 #include <FDM/flight.hxx>
39 #include <Controls/controls.hxx>
40 #include <Scenery/scenery.hxx>
42 #include <simgear/constants.h>
43 #include <simgear/sg_inlines.h>
44 #include <simgear/debug/logstream.hxx>
45 #include <simgear/math/sg_geodesy.hxx>
46 #include <simgear/misc/sg_path.hxx>
48 #include <Airports/simple.hxx>
50 #include <Main/fg_init.hxx>
51 #include <Main/globals.hxx>
52 #include <Main/fg_props.hxx>
53 #include <Navaids/fixlist.hxx>
55 #include "auto_gui.hxx"
56 #include "newauto.hxx"
61 #define mySlider puSlider
63 // Climb speed constants
64 const double min_climb = 70.0; // kts
65 const double best_climb = 75.0; // kts
66 const double ideal_climb_rate = 500.0; // fpm
68 /// These statics will eventually go into the class
69 /// they are just here while I am experimenting -- NHV :-)
70 // AutoPilot Gain Adjuster members
71 static double MaxRollAdjust; // MaxRollAdjust = 2 * APData->MaxRoll;
72 static double RollOutAdjust; // RollOutAdjust = 2 * APData->RollOut;
73 static double MaxAileronAdjust; // MaxAileronAdjust = 2 * APData->MaxAileron;
74 static double RollOutSmoothAdjust; // RollOutSmoothAdjust = 2 * APData->RollOutSmooth;
76 static float MaxRollValue; // 0.1 -> 1.0
77 static float RollOutValue;
78 static float MaxAileronValue;
79 static float RollOutSmoothValue;
81 static float TmpMaxRollValue; // for cancel operation
82 static float TmpRollOutValue;
83 static float TmpMaxAileronValue;
84 static float TmpRollOutSmoothValue;
86 static puDialogBox *APAdjustDialog;
87 static puFrame *APAdjustFrame;
88 static puText *APAdjustDialogMessage;
89 static puFont APAdjustLegendFont;
90 static puFont APAdjustLabelFont;
92 static puOneShot *APAdjustOkButton;
93 static puOneShot *APAdjustResetButton;
94 static puOneShot *APAdjustCancelButton;
96 //static puButton *APAdjustDragButton;
98 static puText *APAdjustMaxRollTitle;
99 static puText *APAdjustRollOutTitle;
100 static puText *APAdjustMaxAileronTitle;
101 static puText *APAdjustRollOutSmoothTitle;
103 static puText *APAdjustMaxAileronText;
104 static puText *APAdjustMaxRollText;
105 static puText *APAdjustRollOutText;
106 static puText *APAdjustRollOutSmoothText;
108 static mySlider *APAdjustHS0;
109 static mySlider *APAdjustHS1;
110 static mySlider *APAdjustHS2;
111 static mySlider *APAdjustHS3;
113 static char SliderText[ 4 ][ 8 ];
115 ///////// AutoPilot New Heading Dialog
117 static puDialogBox *ApHeadingDialog;
118 static puFrame *ApHeadingDialogFrame;
119 static puText *ApHeadingDialogMessage;
120 static puInput *ApHeadingDialogInput;
121 static puOneShot *ApHeadingDialogOkButton;
122 static puOneShot *ApHeadingDialogCancelButton;
125 ///////// AutoPilot New Altitude Dialog
127 static puDialogBox *ApAltitudeDialog = 0;
128 static puFrame *ApAltitudeDialogFrame = 0;
129 static puText *ApAltitudeDialogMessage = 0;
130 static puInput *ApAltitudeDialogInput = 0;
132 static puOneShot *ApAltitudeDialogOkButton = 0;
133 static puOneShot *ApAltitudeDialogCancelButton = 0;
136 /// The beginnings of Lock AutoPilot to target location :-)
137 // Needs cleaning up but works
138 // These statics should disapear when this is a class
139 static puDialogBox *TgtAptDialog = 0;
140 static puFrame *TgtAptDialogFrame = 0;
141 static puText *TgtAptDialogMessage = 0;
142 static puInput *TgtAptDialogInput = 0;
144 static char NewTgtAirportId[16];
145 static char NewTgtAirportLabel[] = "Enter New TgtAirport ID";
147 static puOneShot *TgtAptDialogOkButton = 0;
148 static puOneShot *TgtAptDialogCancelButton = 0;
149 static puOneShot *TgtAptDialogResetButton = 0;
152 // extern char *coord_format_lat(float);
153 // extern char *coord_format_lon(float);
155 // THIS NEEDS IMPROVEMENT !!!!!!!!!!!!!
156 static int scan_number(char *s, double *new_value)
161 char *WordBufPtr = WordBuf;
166 *WordBufPtr++ = *cptr++;
168 while (isdigit(*cptr) ) {
169 *WordBufPtr++ = *cptr++;
173 *WordBufPtr++ = *cptr++; // put the '.' into the string
174 while (isdigit(*cptr)) {
175 *WordBufPtr++ = *cptr++;
180 sscanf(WordBuf, "%lf", new_value);
187 void ApHeadingDialog_Cancel(puObject *)
189 ApHeadingDialogInput->rejectInput();
190 FG_POP_PUI_DIALOG( ApHeadingDialog );
193 void ApHeadingDialog_OK (puObject *me)
198 ApHeadingDialogInput -> getValue( &c );
202 if( scan_number( c, &NewHeading ) )
204 if ( !current_autopilot->get_HeadingEnabled() ) {
205 current_autopilot->set_HeadingEnabled( true );
207 current_autopilot->HeadingSet( NewHeading );
211 s += " is not a valid number.";
214 ApHeadingDialog_Cancel(me);
215 if( error ) mkDialog(s.c_str());
218 void NewHeading(puObject *cb)
220 // string ApHeadingLabel( "Enter New Heading" );
221 // ApHeadingDialogMessage -> setLabel(ApHeadingLabel.c_str());
222 float heading = current_autopilot->get_DGTargetHeading();
223 while ( heading < 0.0 ) { heading += 360.0; }
224 ApHeadingDialogInput -> setValue ( heading );
225 ApHeadingDialogInput -> acceptInput();
226 FG_PUSH_PUI_DIALOG( ApHeadingDialog );
229 void NewHeadingInit()
231 // printf("NewHeadingInit\n");
232 char NewHeadingLabel[] = "Enter New Heading";
235 float heading = fgGetDouble("/orientation/heading-deg");
237 (puGetDefaultLabelFont().getStringWidth( NewHeadingLabel ) / 2 );
239 ApHeadingDialog = new puDialogBox (150, 50);
241 ApHeadingDialogFrame = new puFrame (0, 0, 260, 150);
243 ApHeadingDialogMessage = new puText (len, 110);
244 ApHeadingDialogMessage -> setDefaultValue (NewHeadingLabel);
245 ApHeadingDialogMessage -> getDefaultValue (&s);
246 ApHeadingDialogMessage -> setLabel (s);
248 ApHeadingDialogInput = new puInput ( 50, 70, 210, 100 );
249 ApHeadingDialogInput -> setValue ( heading );
251 ApHeadingDialogOkButton = new puOneShot (50, 10, 110, 50);
252 ApHeadingDialogOkButton -> setLegend (gui_msg_OK);
253 ApHeadingDialogOkButton -> makeReturnDefault (TRUE);
254 ApHeadingDialogOkButton -> setCallback (ApHeadingDialog_OK);
256 ApHeadingDialogCancelButton = new puOneShot (140, 10, 210, 50);
257 ApHeadingDialogCancelButton -> setLegend (gui_msg_CANCEL);
258 ApHeadingDialogCancelButton -> setCallback (ApHeadingDialog_Cancel);
261 FG_FINALIZE_PUI_DIALOG( ApHeadingDialog );
264 void ApAltitudeDialog_Cancel(puObject *)
266 ApAltitudeDialogInput -> rejectInput();
267 FG_POP_PUI_DIALOG( ApAltitudeDialog );
270 void ApAltitudeDialog_OK (puObject *me)
275 ApAltitudeDialogInput->getValue( &c );
279 if( scan_number( c, &NewAltitude) )
281 if ( !current_autopilot->get_AltitudeEnabled() ) {
282 current_autopilot->set_AltitudeEnabled( true );
284 current_autopilot->AltitudeSet( NewAltitude );
288 s += " is not a valid number.";
291 ApAltitudeDialog_Cancel(me);
292 if( error ) mkDialog(s.c_str());
295 void NewAltitude(puObject *cb)
297 float altitude = current_autopilot->get_TargetAltitude() * SG_METER_TO_FEET;
298 ApAltitudeDialogInput -> setValue( altitude );
299 ApAltitudeDialogInput -> acceptInput();
300 FG_PUSH_PUI_DIALOG( ApAltitudeDialog );
303 void NewAltitudeInit()
305 // printf("NewAltitudeInit\n");
306 char NewAltitudeLabel[] = "Enter New Altitude";
309 float alt = cur_fdm_state->get_Altitude();
311 if ( fgGetString("/sim/startup/units") == "meters") {
312 alt *= SG_FEET_TO_METER;
316 (puGetDefaultLabelFont().getStringWidth( NewAltitudeLabel ) / 2);
318 // ApAltitudeDialog = new puDialogBox (150, 50);
319 ApAltitudeDialog = new puDialogBox (150, 200);
321 ApAltitudeDialogFrame = new puFrame (0, 0, 260, 150);
322 ApAltitudeDialogMessage = new puText (len, 110);
323 ApAltitudeDialogMessage -> setDefaultValue (NewAltitudeLabel);
324 ApAltitudeDialogMessage -> getDefaultValue (&s);
325 ApAltitudeDialogMessage -> setLabel (s);
327 ApAltitudeDialogInput = new puInput ( 50, 70, 210, 100 );
328 ApAltitudeDialogInput -> setValue ( alt );
329 // Uncomment the next line to have input active on startup
330 // ApAltitudeDialogInput -> acceptInput ( );
331 // cursor at begining or end of line ?
334 // ApAltitudeDialogInput -> setCursor ( len );
335 // ApAltitudeDialogInput -> setSelectRegion ( 5, 9 );
337 ApAltitudeDialogOkButton = new puOneShot (50, 10, 110, 50);
338 ApAltitudeDialogOkButton -> setLegend (gui_msg_OK);
339 ApAltitudeDialogOkButton -> makeReturnDefault (TRUE);
340 ApAltitudeDialogOkButton -> setCallback (ApAltitudeDialog_OK);
342 ApAltitudeDialogCancelButton = new puOneShot (140, 10, 210, 50);
343 ApAltitudeDialogCancelButton -> setLegend (gui_msg_CANCEL);
344 ApAltitudeDialogCancelButton -> setCallback (ApAltitudeDialog_Cancel);
347 FG_FINALIZE_PUI_DIALOG( ApAltitudeDialog );
351 static void maxroll_adj( puObject *hs ) {
354 hs-> getValue ( &val ) ;
355 SG_CLAMP_RANGE ( val, 0.1f, 1.0f ) ;
356 // printf ( "maxroll_adj( %p ) %f %f\n", hs, val, MaxRollAdjust * val ) ;
357 current_autopilot->set_MaxRoll( MaxRollAdjust * val );
358 sprintf( SliderText[ 0 ], "%05.2f", current_autopilot->get_MaxRoll() );
359 APAdjustMaxRollText -> setLabel ( SliderText[ 0 ] ) ;
362 static void rollout_adj( puObject *hs ) {
365 hs-> getValue ( &val ) ;
366 SG_CLAMP_RANGE ( val, 0.1f, 1.0f ) ;
367 // printf ( "rollout_adj( %p ) %f %f\n", hs, val, RollOutAdjust * val ) ;
368 current_autopilot->set_RollOut( RollOutAdjust * val );
369 sprintf( SliderText[ 1 ], "%05.2f", current_autopilot->get_RollOut() );
370 APAdjustRollOutText -> setLabel ( SliderText[ 1 ] );
373 static void maxaileron_adj( puObject *hs ) {
376 hs-> getValue ( &val ) ;
377 SG_CLAMP_RANGE ( val, 0.1f, 1.0f ) ;
378 // printf ( "maxaileron_adj( %p ) %f %f\n", hs, val, MaxAileronAdjust * val ) ;
379 current_autopilot->set_MaxAileron( MaxAileronAdjust * val );
380 sprintf( SliderText[ 3 ], "%05.2f", current_autopilot->get_MaxAileron() );
381 APAdjustMaxAileronText -> setLabel ( SliderText[ 3 ] );
384 static void rolloutsmooth_adj( puObject *hs ) {
387 hs -> getValue ( &val ) ;
388 SG_CLAMP_RANGE ( val, 0.1f, 1.0f ) ;
389 // printf ( "rolloutsmooth_adj( %p ) %f %f\n", hs, val, RollOutSmoothAdjust * val ) ;
390 current_autopilot->set_RollOutSmooth( RollOutSmoothAdjust * val );
391 sprintf( SliderText[ 2 ], "%5.2f", current_autopilot->get_RollOutSmooth() );
392 APAdjustRollOutSmoothText-> setLabel ( SliderText[ 2 ] );
396 static void goAwayAPAdjust (puObject *)
398 FG_POP_PUI_DIALOG( APAdjustDialog );
401 void cancelAPAdjust( puObject *self ) {
402 current_autopilot->set_MaxRoll( TmpMaxRollValue );
403 current_autopilot->set_RollOut( TmpRollOutValue );
404 current_autopilot->set_MaxAileron( TmpMaxAileronValue );
405 current_autopilot->set_RollOutSmooth( TmpRollOutSmoothValue );
407 goAwayAPAdjust(self);
410 void resetAPAdjust( puObject *self ) {
411 current_autopilot->set_MaxRoll( MaxRollAdjust / 2 );
412 current_autopilot->set_RollOut( RollOutAdjust / 2 );
413 current_autopilot->set_MaxAileron( MaxAileronAdjust / 2 );
414 current_autopilot->set_RollOutSmooth( RollOutSmoothAdjust / 2 );
416 FG_POP_PUI_DIALOG( APAdjustDialog );
421 void fgAPAdjust( puObject *self ) {
422 TmpMaxRollValue = current_autopilot->get_MaxRoll();
423 TmpRollOutValue = current_autopilot->get_RollOut();
424 TmpMaxAileronValue = current_autopilot->get_MaxAileron();
425 TmpRollOutSmoothValue = current_autopilot->get_RollOutSmooth();
427 MaxRollValue = current_autopilot->get_MaxRoll() / MaxRollAdjust;
428 RollOutValue = current_autopilot->get_RollOut() / RollOutAdjust;
429 MaxAileronValue = current_autopilot->get_MaxAileron() / MaxAileronAdjust;
430 RollOutSmoothValue = current_autopilot->get_RollOutSmooth()
431 / RollOutSmoothAdjust;
433 APAdjustHS0-> setValue ( MaxRollValue ) ;
434 APAdjustHS1-> setValue ( RollOutValue ) ;
435 APAdjustHS2-> setValue ( RollOutSmoothValue ) ;
436 APAdjustHS3-> setValue ( MaxAileronValue ) ;
438 FG_PUSH_PUI_DIALOG( APAdjustDialog );
441 // Done once at system initialization
442 void fgAPAdjustInit() {
444 // printf("fgAPAdjustInit\n");
445 #define HORIZONTAL FALSE
449 int DialogWidth = 230;
451 char Label[] = "AutoPilot Adjust";
454 int labelX = (DialogWidth / 2) -
455 (puGetDefaultLabelFont().getStringWidth( Label ) / 2);
456 labelX -= 30; // KLUDGEY
461 int slider_width = 210;
462 int slider_title_x = 15;
463 int slider_value_x = 160;
464 float slider_delta = 0.1f;
466 TmpMaxRollValue = current_autopilot->get_MaxRoll();
467 TmpRollOutValue = current_autopilot->get_RollOut();
468 TmpMaxAileronValue = current_autopilot->get_MaxAileron();
469 TmpRollOutSmoothValue = current_autopilot->get_RollOutSmooth();
471 MaxRollAdjust = 2 * current_autopilot->get_MaxRoll();
472 RollOutAdjust = 2 * current_autopilot->get_RollOut();
473 MaxAileronAdjust = 2 * current_autopilot->get_MaxAileron();
474 RollOutSmoothAdjust = 2 * current_autopilot->get_RollOutSmooth();
476 MaxRollValue = current_autopilot->get_MaxRoll() / MaxRollAdjust;
477 RollOutValue = current_autopilot->get_RollOut() / RollOutAdjust;
478 MaxAileronValue = current_autopilot->get_MaxAileron() / MaxAileronAdjust;
479 RollOutSmoothValue = current_autopilot->get_RollOutSmooth()
480 / RollOutSmoothAdjust;
482 puGetDefaultFonts ( &APAdjustLegendFont, &APAdjustLabelFont );
483 APAdjustDialog = new puDialogBox ( DialogX, DialogY ); {
484 int horiz_slider_height = APAdjustLabelFont.getStringHeight() +
485 APAdjustLabelFont.getStringDescender() +
486 PUSTR_TGAP + PUSTR_BGAP + 5;
488 APAdjustFrame = new puFrame ( 0, 0,
490 85 + nSliders * horiz_slider_height );
492 APAdjustDialogMessage = new puText ( labelX,
494 * horiz_slider_height );
495 APAdjustDialogMessage -> setDefaultValue ( Label );
496 APAdjustDialogMessage -> getDefaultValue ( &s );
497 APAdjustDialogMessage -> setLabel ( s );
499 APAdjustHS0 = new mySlider ( slider_x, slider_y,
500 slider_width, HORIZONTAL ) ;
501 APAdjustHS0-> setDelta ( slider_delta ) ;
502 APAdjustHS0-> setValue ( MaxRollValue ) ;
503 APAdjustHS0-> setCBMode ( PUSLIDER_DELTA ) ;
504 APAdjustHS0-> setCallback ( maxroll_adj ) ;
506 sprintf( SliderText[ 0 ], "%05.2f", current_autopilot->get_MaxRoll() );
507 APAdjustMaxRollTitle = new puText ( slider_title_x, slider_y ) ;
508 APAdjustMaxRollTitle-> setDefaultValue ( "MaxRoll" ) ;
509 APAdjustMaxRollTitle-> getDefaultValue ( &s ) ;
510 APAdjustMaxRollTitle-> setLabel ( s ) ;
511 APAdjustMaxRollText = new puText ( slider_value_x, slider_y ) ;
512 APAdjustMaxRollText-> setLabel ( SliderText[ 0 ] ) ;
514 slider_y += horiz_slider_height;
516 APAdjustHS1 = new mySlider ( slider_x, slider_y, slider_width,
518 APAdjustHS1-> setDelta ( slider_delta ) ;
519 APAdjustHS1-> setValue ( RollOutValue ) ;
520 APAdjustHS1-> setCBMode ( PUSLIDER_DELTA ) ;
521 APAdjustHS1-> setCallback ( rollout_adj ) ;
523 sprintf( SliderText[ 1 ], "%05.2f", current_autopilot->get_RollOut() );
524 APAdjustRollOutTitle = new puText ( slider_title_x, slider_y ) ;
525 APAdjustRollOutTitle-> setDefaultValue ( "AdjustRollOut" ) ;
526 APAdjustRollOutTitle-> getDefaultValue ( &s ) ;
527 APAdjustRollOutTitle-> setLabel ( s ) ;
528 APAdjustRollOutText = new puText ( slider_value_x, slider_y ) ;
529 APAdjustRollOutText-> setLabel ( SliderText[ 1 ] );
531 slider_y += horiz_slider_height;
533 APAdjustHS2 = new mySlider ( slider_x, slider_y, slider_width,
535 APAdjustHS2-> setDelta ( slider_delta ) ;
536 APAdjustHS2-> setValue ( RollOutSmoothValue ) ;
537 APAdjustHS2-> setCBMode ( PUSLIDER_DELTA ) ;
538 APAdjustHS2-> setCallback ( rolloutsmooth_adj ) ;
540 sprintf( SliderText[ 2 ], "%5.2f",
541 current_autopilot->get_RollOutSmooth() );
542 APAdjustRollOutSmoothTitle = new puText ( slider_title_x, slider_y ) ;
543 APAdjustRollOutSmoothTitle-> setDefaultValue ( "RollOutSmooth" ) ;
544 APAdjustRollOutSmoothTitle-> getDefaultValue ( &s ) ;
545 APAdjustRollOutSmoothTitle-> setLabel ( s ) ;
546 APAdjustRollOutSmoothText = new puText ( slider_value_x, slider_y ) ;
547 APAdjustRollOutSmoothText-> setLabel ( SliderText[ 2 ] );
549 slider_y += horiz_slider_height;
551 APAdjustHS3 = new mySlider ( slider_x, slider_y, slider_width,
553 APAdjustHS3-> setDelta ( slider_delta ) ;
554 APAdjustHS3-> setValue ( MaxAileronValue ) ;
555 APAdjustHS3-> setCBMode ( PUSLIDER_DELTA ) ;
556 APAdjustHS3-> setCallback ( maxaileron_adj ) ;
558 sprintf( SliderText[ 3 ], "%05.2f",
559 current_autopilot->get_MaxAileron() );
560 APAdjustMaxAileronTitle = new puText ( slider_title_x, slider_y ) ;
561 APAdjustMaxAileronTitle-> setDefaultValue ( "MaxAileron" ) ;
562 APAdjustMaxAileronTitle-> getDefaultValue ( &s ) ;
563 APAdjustMaxAileronTitle-> setLabel ( s ) ;
564 APAdjustMaxAileronText = new puText ( slider_value_x, slider_y ) ;
565 APAdjustMaxAileronText-> setLabel ( SliderText[ 3 ] );
567 APAdjustOkButton = new puOneShot ( 10, 10, 60, 50 );
568 APAdjustOkButton-> setLegend ( gui_msg_OK );
569 APAdjustOkButton-> makeReturnDefault ( TRUE );
570 APAdjustOkButton-> setCallback ( goAwayAPAdjust );
572 APAdjustCancelButton = new puOneShot ( 70, 10, 150, 50 );
573 APAdjustCancelButton-> setLegend ( gui_msg_CANCEL );
574 APAdjustCancelButton-> setCallback ( cancelAPAdjust );
576 APAdjustResetButton = new puOneShot ( 160, 10, 220, 50 );
577 APAdjustResetButton-> setLegend ( gui_msg_RESET );
578 APAdjustResetButton-> setCallback ( resetAPAdjust );
580 FG_FINALIZE_PUI_DIALOG( APAdjustDialog );
585 // Simple Dialog to input Target Airport
586 void TgtAptDialog_Cancel(puObject *)
588 FG_POP_PUI_DIALOG( TgtAptDialog );
591 void TgtAptDialog_OK (puObject *)
595 // FGTime *t = FGTime::cur_time_params;
596 // int PauseMode = t->getPause();
598 // t->togglePauseMode();
601 TgtAptDialogInput->getValue(&s);
605 unsigned int pos = tmp.find( "@" );
606 if ( pos != string::npos ) {
607 TgtAptId = tmp.substr( 0, pos );
608 string alt_str = tmp.substr( pos + 1 );
609 alt = atof( alt_str.c_str() );
610 if ( fgGetString("/sim/startup/units") == "feet" ) {
611 alt *= SG_FEET_TO_METER;
617 TgtAptDialog_Cancel( NULL );
622 if ( fgFindAirportID( TgtAptId, &a ) ) {
624 SG_LOG( SG_GENERAL, SG_INFO,
625 "Adding waypoint (airport) = " << TgtAptId );
627 sprintf( NewTgtAirportId, "%s", TgtAptId.c_str() );
629 SGWayPoint wp( a.longitude, a.latitude, alt,
630 SGWayPoint::WGS84, TgtAptId );
631 globals->get_route()->add_waypoint( wp );
632 } else if ( current_fixlist->query( TgtAptId, 0.0, 0.0, 0.0,
635 SG_LOG( SG_GENERAL, SG_INFO,
636 "Adding waypoint (fix) = " << TgtAptId );
638 sprintf( NewTgtAirportId, "%s", TgtAptId.c_str() );
640 SGWayPoint wp( f.get_lon(), f.get_lat(), alt,
641 SGWayPoint::WGS84, TgtAptId );
642 globals->get_route()->add_waypoint( wp );
644 TgtAptId += " not in database.";
645 mkDialog(TgtAptId.c_str());
649 void TgtAptDialog_Reset(puObject *)
651 sprintf( NewTgtAirportId, "%s", fgGetString("/sim/startup/airport-id").c_str() );
652 TgtAptDialogInput->setValue ( NewTgtAirportId );
653 TgtAptDialogInput->setCursor( 0 ) ;
656 void AddWayPoint(puObject *cb)
658 sprintf( NewTgtAirportId, "%s", fgGetString("/sim/startup/airport-id").c_str() );
659 TgtAptDialogInput->setValue( NewTgtAirportId );
661 FG_PUSH_PUI_DIALOG( TgtAptDialog );
664 void PopWayPoint(puObject *cb)
666 globals->get_route()->delete_first();
668 // see if there are more waypoints on the list
669 if ( globals->get_route()->size() ) {
671 current_autopilot->set_HeadingMode( FGAutopilot::FG_HEADING_WAYPOINT );
674 current_autopilot->set_HeadingMode( FGAutopilot::FG_TC_HEADING_LOCK );
676 // use current heading
678 ->set_TargetHeading(fgGetDouble("/orientation/heading-deg"));
682 void ClearRoute(puObject *cb)
684 globals->get_route()->clear();
687 void NewTgtAirportInit()
689 SG_LOG( SG_AUTOPILOT, SG_INFO, " enter NewTgtAirportInit()" );
690 sprintf( NewTgtAirportId, "%s",
691 fgGetString("/sim/startup/airport-id").c_str() );
692 SG_LOG( SG_AUTOPILOT, SG_INFO, " NewTgtAirportId " << NewTgtAirportId );
694 - puGetDefaultLabelFont().getStringWidth( NewTgtAirportLabel ) / 2;
696 TgtAptDialog = new puDialogBox (150, 50);
698 TgtAptDialogFrame = new puFrame (0,0,350, 150);
699 TgtAptDialogMessage = new puText (len, 110);
700 TgtAptDialogMessage -> setLabel (NewTgtAirportLabel);
702 TgtAptDialogInput = new puInput (50, 70, 300, 100);
703 TgtAptDialogInput -> setValue (NewTgtAirportId);
704 TgtAptDialogInput -> acceptInput();
706 TgtAptDialogOkButton = new puOneShot (50, 10, 110, 50);
707 TgtAptDialogOkButton -> setLegend (gui_msg_OK);
708 TgtAptDialogOkButton -> setCallback (TgtAptDialog_OK);
709 TgtAptDialogOkButton -> makeReturnDefault(TRUE);
711 TgtAptDialogCancelButton = new puOneShot (140, 10, 210, 50);
712 TgtAptDialogCancelButton -> setLegend (gui_msg_CANCEL);
713 TgtAptDialogCancelButton -> setCallback (TgtAptDialog_Cancel);
715 TgtAptDialogResetButton = new puOneShot (240, 10, 300, 50);
716 TgtAptDialogResetButton -> setLegend (gui_msg_RESET);
717 TgtAptDialogResetButton -> setCallback (TgtAptDialog_Reset);
719 FG_FINALIZE_PUI_DIALOG( TgtAptDialog );
720 printf("leave NewTgtAirportInit()");