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 ApHeadingDialogInput -> setValue ( heading );
224 ApHeadingDialogInput -> acceptInput();
225 FG_PUSH_PUI_DIALOG( ApHeadingDialog );
228 void NewHeadingInit()
230 // printf("NewHeadingInit\n");
231 char NewHeadingLabel[] = "Enter New Heading";
234 float heading = fgGetDouble("/orientation/heading-deg");
236 (puGetDefaultLabelFont().getStringWidth( NewHeadingLabel ) / 2 );
238 ApHeadingDialog = new puDialogBox (150, 50);
240 ApHeadingDialogFrame = new puFrame (0, 0, 260, 150);
242 ApHeadingDialogMessage = new puText (len, 110);
243 ApHeadingDialogMessage -> setDefaultValue (NewHeadingLabel);
244 ApHeadingDialogMessage -> getDefaultValue (&s);
245 ApHeadingDialogMessage -> setLabel (s);
247 ApHeadingDialogInput = new puInput ( 50, 70, 210, 100 );
248 ApHeadingDialogInput -> setValue ( heading );
250 ApHeadingDialogOkButton = new puOneShot (50, 10, 110, 50);
251 ApHeadingDialogOkButton -> setLegend (gui_msg_OK);
252 ApHeadingDialogOkButton -> makeReturnDefault (TRUE);
253 ApHeadingDialogOkButton -> setCallback (ApHeadingDialog_OK);
255 ApHeadingDialogCancelButton = new puOneShot (140, 10, 210, 50);
256 ApHeadingDialogCancelButton -> setLegend (gui_msg_CANCEL);
257 ApHeadingDialogCancelButton -> setCallback (ApHeadingDialog_Cancel);
260 FG_FINALIZE_PUI_DIALOG( ApHeadingDialog );
263 void ApAltitudeDialog_Cancel(puObject *)
265 ApAltitudeDialogInput -> rejectInput();
266 FG_POP_PUI_DIALOG( ApAltitudeDialog );
269 void ApAltitudeDialog_OK (puObject *me)
274 ApAltitudeDialogInput->getValue( &c );
278 if( scan_number( c, &NewAltitude) )
280 if ( !current_autopilot->get_AltitudeEnabled() ) {
281 current_autopilot->set_AltitudeEnabled( true );
283 current_autopilot->AltitudeSet( NewAltitude );
287 s += " is not a valid number.";
290 ApAltitudeDialog_Cancel(me);
291 if( error ) mkDialog(s.c_str());
294 void NewAltitude(puObject *cb)
296 float altitude = current_autopilot->get_TargetAltitude() * SG_METER_TO_FEET;
297 ApAltitudeDialogInput -> setValue( altitude );
298 ApAltitudeDialogInput -> acceptInput();
299 FG_PUSH_PUI_DIALOG( ApAltitudeDialog );
302 void NewAltitudeInit()
304 // printf("NewAltitudeInit\n");
305 char NewAltitudeLabel[] = "Enter New Altitude";
308 float alt = cur_fdm_state->get_Altitude();
310 if ( fgGetString("/sim/startup/units") == "meters") {
311 alt *= SG_FEET_TO_METER;
315 (puGetDefaultLabelFont().getStringWidth( NewAltitudeLabel ) / 2);
317 // ApAltitudeDialog = new puDialogBox (150, 50);
318 ApAltitudeDialog = new puDialogBox (150, 200);
320 ApAltitudeDialogFrame = new puFrame (0, 0, 260, 150);
321 ApAltitudeDialogMessage = new puText (len, 110);
322 ApAltitudeDialogMessage -> setDefaultValue (NewAltitudeLabel);
323 ApAltitudeDialogMessage -> getDefaultValue (&s);
324 ApAltitudeDialogMessage -> setLabel (s);
326 ApAltitudeDialogInput = new puInput ( 50, 70, 210, 100 );
327 ApAltitudeDialogInput -> setValue ( alt );
328 // Uncomment the next line to have input active on startup
329 // ApAltitudeDialogInput -> acceptInput ( );
330 // cursor at begining or end of line ?
333 // ApAltitudeDialogInput -> setCursor ( len );
334 // ApAltitudeDialogInput -> setSelectRegion ( 5, 9 );
336 ApAltitudeDialogOkButton = new puOneShot (50, 10, 110, 50);
337 ApAltitudeDialogOkButton -> setLegend (gui_msg_OK);
338 ApAltitudeDialogOkButton -> makeReturnDefault (TRUE);
339 ApAltitudeDialogOkButton -> setCallback (ApAltitudeDialog_OK);
341 ApAltitudeDialogCancelButton = new puOneShot (140, 10, 210, 50);
342 ApAltitudeDialogCancelButton -> setLegend (gui_msg_CANCEL);
343 ApAltitudeDialogCancelButton -> setCallback (ApAltitudeDialog_Cancel);
346 FG_FINALIZE_PUI_DIALOG( ApAltitudeDialog );
350 static void maxroll_adj( puObject *hs ) {
353 hs-> getValue ( &val ) ;
354 SG_CLAMP_RANGE ( val, 0.1f, 1.0f ) ;
355 // printf ( "maxroll_adj( %p ) %f %f\n", hs, val, MaxRollAdjust * val ) ;
356 current_autopilot->set_MaxRoll( MaxRollAdjust * val );
357 sprintf( SliderText[ 0 ], "%05.2f", current_autopilot->get_MaxRoll() );
358 APAdjustMaxRollText -> setLabel ( SliderText[ 0 ] ) ;
361 static void rollout_adj( puObject *hs ) {
364 hs-> getValue ( &val ) ;
365 SG_CLAMP_RANGE ( val, 0.1f, 1.0f ) ;
366 // printf ( "rollout_adj( %p ) %f %f\n", hs, val, RollOutAdjust * val ) ;
367 current_autopilot->set_RollOut( RollOutAdjust * val );
368 sprintf( SliderText[ 1 ], "%05.2f", current_autopilot->get_RollOut() );
369 APAdjustRollOutText -> setLabel ( SliderText[ 1 ] );
372 static void maxaileron_adj( puObject *hs ) {
375 hs-> getValue ( &val ) ;
376 SG_CLAMP_RANGE ( val, 0.1f, 1.0f ) ;
377 // printf ( "maxaileron_adj( %p ) %f %f\n", hs, val, MaxAileronAdjust * val ) ;
378 current_autopilot->set_MaxAileron( MaxAileronAdjust * val );
379 sprintf( SliderText[ 3 ], "%05.2f", current_autopilot->get_MaxAileron() );
380 APAdjustMaxAileronText -> setLabel ( SliderText[ 3 ] );
383 static void rolloutsmooth_adj( puObject *hs ) {
386 hs -> getValue ( &val ) ;
387 SG_CLAMP_RANGE ( val, 0.1f, 1.0f ) ;
388 // printf ( "rolloutsmooth_adj( %p ) %f %f\n", hs, val, RollOutSmoothAdjust * val ) ;
389 current_autopilot->set_RollOutSmooth( RollOutSmoothAdjust * val );
390 sprintf( SliderText[ 2 ], "%5.2f", current_autopilot->get_RollOutSmooth() );
391 APAdjustRollOutSmoothText-> setLabel ( SliderText[ 2 ] );
395 static void goAwayAPAdjust (puObject *)
397 FG_POP_PUI_DIALOG( APAdjustDialog );
400 void cancelAPAdjust( puObject *self ) {
401 current_autopilot->set_MaxRoll( TmpMaxRollValue );
402 current_autopilot->set_RollOut( TmpRollOutValue );
403 current_autopilot->set_MaxAileron( TmpMaxAileronValue );
404 current_autopilot->set_RollOutSmooth( TmpRollOutSmoothValue );
406 goAwayAPAdjust(self);
409 void resetAPAdjust( puObject *self ) {
410 current_autopilot->set_MaxRoll( MaxRollAdjust / 2 );
411 current_autopilot->set_RollOut( RollOutAdjust / 2 );
412 current_autopilot->set_MaxAileron( MaxAileronAdjust / 2 );
413 current_autopilot->set_RollOutSmooth( RollOutSmoothAdjust / 2 );
415 FG_POP_PUI_DIALOG( APAdjustDialog );
420 void fgAPAdjust( puObject *self ) {
421 TmpMaxRollValue = current_autopilot->get_MaxRoll();
422 TmpRollOutValue = current_autopilot->get_RollOut();
423 TmpMaxAileronValue = current_autopilot->get_MaxAileron();
424 TmpRollOutSmoothValue = current_autopilot->get_RollOutSmooth();
426 MaxRollValue = current_autopilot->get_MaxRoll() / MaxRollAdjust;
427 RollOutValue = current_autopilot->get_RollOut() / RollOutAdjust;
428 MaxAileronValue = current_autopilot->get_MaxAileron() / MaxAileronAdjust;
429 RollOutSmoothValue = current_autopilot->get_RollOutSmooth()
430 / RollOutSmoothAdjust;
432 APAdjustHS0-> setValue ( MaxRollValue ) ;
433 APAdjustHS1-> setValue ( RollOutValue ) ;
434 APAdjustHS2-> setValue ( RollOutSmoothValue ) ;
435 APAdjustHS3-> setValue ( MaxAileronValue ) ;
437 FG_PUSH_PUI_DIALOG( APAdjustDialog );
440 // Done once at system initialization
441 void fgAPAdjustInit() {
443 // printf("fgAPAdjustInit\n");
444 #define HORIZONTAL FALSE
448 int DialogWidth = 230;
450 char Label[] = "AutoPilot Adjust";
453 int labelX = (DialogWidth / 2) -
454 (puGetDefaultLabelFont().getStringWidth( Label ) / 2);
455 labelX -= 30; // KLUDGEY
460 int slider_width = 210;
461 int slider_title_x = 15;
462 int slider_value_x = 160;
463 float slider_delta = 0.1f;
465 TmpMaxRollValue = current_autopilot->get_MaxRoll();
466 TmpRollOutValue = current_autopilot->get_RollOut();
467 TmpMaxAileronValue = current_autopilot->get_MaxAileron();
468 TmpRollOutSmoothValue = current_autopilot->get_RollOutSmooth();
470 MaxRollAdjust = 2 * current_autopilot->get_MaxRoll();
471 RollOutAdjust = 2 * current_autopilot->get_RollOut();
472 MaxAileronAdjust = 2 * current_autopilot->get_MaxAileron();
473 RollOutSmoothAdjust = 2 * current_autopilot->get_RollOutSmooth();
475 MaxRollValue = current_autopilot->get_MaxRoll() / MaxRollAdjust;
476 RollOutValue = current_autopilot->get_RollOut() / RollOutAdjust;
477 MaxAileronValue = current_autopilot->get_MaxAileron() / MaxAileronAdjust;
478 RollOutSmoothValue = current_autopilot->get_RollOutSmooth()
479 / RollOutSmoothAdjust;
481 puGetDefaultFonts ( &APAdjustLegendFont, &APAdjustLabelFont );
482 APAdjustDialog = new puDialogBox ( DialogX, DialogY ); {
483 int horiz_slider_height = APAdjustLabelFont.getStringHeight() +
484 APAdjustLabelFont.getStringDescender() +
485 PUSTR_TGAP + PUSTR_BGAP + 5;
487 APAdjustFrame = new puFrame ( 0, 0,
489 85 + nSliders * horiz_slider_height );
491 APAdjustDialogMessage = new puText ( labelX,
493 * horiz_slider_height );
494 APAdjustDialogMessage -> setDefaultValue ( Label );
495 APAdjustDialogMessage -> getDefaultValue ( &s );
496 APAdjustDialogMessage -> setLabel ( s );
498 APAdjustHS0 = new mySlider ( slider_x, slider_y,
499 slider_width, HORIZONTAL ) ;
500 APAdjustHS0-> setDelta ( slider_delta ) ;
501 APAdjustHS0-> setValue ( MaxRollValue ) ;
502 APAdjustHS0-> setCBMode ( PUSLIDER_DELTA ) ;
503 APAdjustHS0-> setCallback ( maxroll_adj ) ;
505 sprintf( SliderText[ 0 ], "%05.2f", current_autopilot->get_MaxRoll() );
506 APAdjustMaxRollTitle = new puText ( slider_title_x, slider_y ) ;
507 APAdjustMaxRollTitle-> setDefaultValue ( "MaxRoll" ) ;
508 APAdjustMaxRollTitle-> getDefaultValue ( &s ) ;
509 APAdjustMaxRollTitle-> setLabel ( s ) ;
510 APAdjustMaxRollText = new puText ( slider_value_x, slider_y ) ;
511 APAdjustMaxRollText-> setLabel ( SliderText[ 0 ] ) ;
513 slider_y += horiz_slider_height;
515 APAdjustHS1 = new mySlider ( slider_x, slider_y, slider_width,
517 APAdjustHS1-> setDelta ( slider_delta ) ;
518 APAdjustHS1-> setValue ( RollOutValue ) ;
519 APAdjustHS1-> setCBMode ( PUSLIDER_DELTA ) ;
520 APAdjustHS1-> setCallback ( rollout_adj ) ;
522 sprintf( SliderText[ 1 ], "%05.2f", current_autopilot->get_RollOut() );
523 APAdjustRollOutTitle = new puText ( slider_title_x, slider_y ) ;
524 APAdjustRollOutTitle-> setDefaultValue ( "AdjustRollOut" ) ;
525 APAdjustRollOutTitle-> getDefaultValue ( &s ) ;
526 APAdjustRollOutTitle-> setLabel ( s ) ;
527 APAdjustRollOutText = new puText ( slider_value_x, slider_y ) ;
528 APAdjustRollOutText-> setLabel ( SliderText[ 1 ] );
530 slider_y += horiz_slider_height;
532 APAdjustHS2 = new mySlider ( slider_x, slider_y, slider_width,
534 APAdjustHS2-> setDelta ( slider_delta ) ;
535 APAdjustHS2-> setValue ( RollOutSmoothValue ) ;
536 APAdjustHS2-> setCBMode ( PUSLIDER_DELTA ) ;
537 APAdjustHS2-> setCallback ( rolloutsmooth_adj ) ;
539 sprintf( SliderText[ 2 ], "%5.2f",
540 current_autopilot->get_RollOutSmooth() );
541 APAdjustRollOutSmoothTitle = new puText ( slider_title_x, slider_y ) ;
542 APAdjustRollOutSmoothTitle-> setDefaultValue ( "RollOutSmooth" ) ;
543 APAdjustRollOutSmoothTitle-> getDefaultValue ( &s ) ;
544 APAdjustRollOutSmoothTitle-> setLabel ( s ) ;
545 APAdjustRollOutSmoothText = new puText ( slider_value_x, slider_y ) ;
546 APAdjustRollOutSmoothText-> setLabel ( SliderText[ 2 ] );
548 slider_y += horiz_slider_height;
550 APAdjustHS3 = new mySlider ( slider_x, slider_y, slider_width,
552 APAdjustHS3-> setDelta ( slider_delta ) ;
553 APAdjustHS3-> setValue ( MaxAileronValue ) ;
554 APAdjustHS3-> setCBMode ( PUSLIDER_DELTA ) ;
555 APAdjustHS3-> setCallback ( maxaileron_adj ) ;
557 sprintf( SliderText[ 3 ], "%05.2f",
558 current_autopilot->get_MaxAileron() );
559 APAdjustMaxAileronTitle = new puText ( slider_title_x, slider_y ) ;
560 APAdjustMaxAileronTitle-> setDefaultValue ( "MaxAileron" ) ;
561 APAdjustMaxAileronTitle-> getDefaultValue ( &s ) ;
562 APAdjustMaxAileronTitle-> setLabel ( s ) ;
563 APAdjustMaxAileronText = new puText ( slider_value_x, slider_y ) ;
564 APAdjustMaxAileronText-> setLabel ( SliderText[ 3 ] );
566 APAdjustOkButton = new puOneShot ( 10, 10, 60, 50 );
567 APAdjustOkButton-> setLegend ( gui_msg_OK );
568 APAdjustOkButton-> makeReturnDefault ( TRUE );
569 APAdjustOkButton-> setCallback ( goAwayAPAdjust );
571 APAdjustCancelButton = new puOneShot ( 70, 10, 150, 50 );
572 APAdjustCancelButton-> setLegend ( gui_msg_CANCEL );
573 APAdjustCancelButton-> setCallback ( cancelAPAdjust );
575 APAdjustResetButton = new puOneShot ( 160, 10, 220, 50 );
576 APAdjustResetButton-> setLegend ( gui_msg_RESET );
577 APAdjustResetButton-> setCallback ( resetAPAdjust );
579 FG_FINALIZE_PUI_DIALOG( APAdjustDialog );
584 // Simple Dialog to input Target Airport
585 void TgtAptDialog_Cancel(puObject *)
587 FG_POP_PUI_DIALOG( TgtAptDialog );
590 void TgtAptDialog_OK (puObject *)
594 // FGTime *t = FGTime::cur_time_params;
595 // int PauseMode = t->getPause();
597 // t->togglePauseMode();
600 TgtAptDialogInput->getValue(&s);
604 unsigned int pos = tmp.find( "@" );
605 if ( pos != string::npos ) {
606 TgtAptId = tmp.substr( 0, pos );
607 string alt_str = tmp.substr( pos + 1 );
608 alt = atof( alt_str.c_str() );
609 if ( fgGetString("/sim/startup/units") == "feet" ) {
610 alt *= SG_FEET_TO_METER;
616 TgtAptDialog_Cancel( NULL );
621 if ( fgFindAirportID( TgtAptId, &a ) ) {
623 SG_LOG( SG_GENERAL, SG_INFO,
624 "Adding waypoint (airport) = " << TgtAptId );
626 sprintf( NewTgtAirportId, "%s", TgtAptId.c_str() );
628 SGWayPoint wp( a.longitude, a.latitude, alt,
629 SGWayPoint::WGS84, TgtAptId );
630 globals->get_route()->add_waypoint( wp );
631 } else if ( current_fixlist->query( TgtAptId, 0.0, 0.0, 0.0,
634 SG_LOG( SG_GENERAL, SG_INFO,
635 "Adding waypoint (fix) = " << TgtAptId );
637 sprintf( NewTgtAirportId, "%s", TgtAptId.c_str() );
639 SGWayPoint wp( f.get_lon(), f.get_lat(), alt,
640 SGWayPoint::WGS84, TgtAptId );
641 globals->get_route()->add_waypoint( wp );
643 TgtAptId += " not in database.";
644 mkDialog(TgtAptId.c_str());
648 void TgtAptDialog_Reset(puObject *)
650 sprintf( NewTgtAirportId, "%s", fgGetString("/sim/startup/airport-id").c_str() );
651 TgtAptDialogInput->setValue ( NewTgtAirportId );
652 TgtAptDialogInput->setCursor( 0 ) ;
655 void AddWayPoint(puObject *cb)
657 sprintf( NewTgtAirportId, "%s", fgGetString("/sim/startup/airport-id").c_str() );
658 TgtAptDialogInput->setValue( NewTgtAirportId );
660 FG_PUSH_PUI_DIALOG( TgtAptDialog );
663 void PopWayPoint(puObject *cb)
665 globals->get_route()->delete_first();
667 // see if there are more waypoints on the list
668 if ( globals->get_route()->size() ) {
670 current_autopilot->set_HeadingMode( FGAutopilot::FG_HEADING_WAYPOINT );
673 current_autopilot->set_HeadingMode( FGAutopilot::FG_TC_HEADING_LOCK );
675 // use current heading
677 ->set_TargetHeading(fgGetDouble("/orientation/heading-deg"));
681 void ClearRoute(puObject *cb)
683 globals->get_route()->clear();
686 void NewTgtAirportInit()
688 SG_LOG( SG_AUTOPILOT, SG_INFO, " enter NewTgtAirportInit()" );
689 sprintf( NewTgtAirportId, "%s",
690 fgGetString("/sim/startup/airport-id").c_str() );
691 SG_LOG( SG_AUTOPILOT, SG_INFO, " NewTgtAirportId " << NewTgtAirportId );
693 - puGetDefaultLabelFont().getStringWidth( NewTgtAirportLabel ) / 2;
695 TgtAptDialog = new puDialogBox (150, 50);
697 TgtAptDialogFrame = new puFrame (0,0,350, 150);
698 TgtAptDialogMessage = new puText (len, 110);
699 TgtAptDialogMessage -> setLabel (NewTgtAirportLabel);
701 TgtAptDialogInput = new puInput (50, 70, 300, 100);
702 TgtAptDialogInput -> setValue (NewTgtAirportId);
703 TgtAptDialogInput -> acceptInput();
705 TgtAptDialogOkButton = new puOneShot (50, 10, 110, 50);
706 TgtAptDialogOkButton -> setLegend (gui_msg_OK);
707 TgtAptDialogOkButton -> setCallback (TgtAptDialog_OK);
708 TgtAptDialogOkButton -> makeReturnDefault(TRUE);
710 TgtAptDialogCancelButton = new puOneShot (140, 10, 210, 50);
711 TgtAptDialogCancelButton -> setLegend (gui_msg_CANCEL);
712 TgtAptDialogCancelButton -> setCallback (TgtAptDialog_Cancel);
714 TgtAptDialogResetButton = new puOneShot (240, 10, 300, 50);
715 TgtAptDialogResetButton -> setLegend (gui_msg_RESET);
716 TgtAptDialogResetButton -> setCallback (TgtAptDialog_Reset);
718 FG_FINALIZE_PUI_DIALOG( TgtAptDialog );
719 printf("leave NewTgtAirportInit()");