]> git.mxchange.org Git - flightgear.git/blob - src/Main/bfi.cxx
c87ce8b9bdfc85dbf468c0500320bc630657308a
[flightgear.git] / src / Main / bfi.cxx
1 // bfi.cxx - Big Friendly Interface implementation
2 //
3 // Written by David Megginson, started February, 2000.
4 //
5 // Copyright (C) 2000  David Megginson - david@megginson.com
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 //
21 // $Id$
22
23
24 #ifdef HAVE_CONFIG_H
25 #  include <config.h>
26 #endif
27
28 #if defined( FG_HAVE_NATIVE_SGI_COMPILERS )
29 #  include <iostream.h>
30 #else
31 #  include <iostream>
32 #endif
33
34 #include <simgear/constants.h>
35 #include <simgear/debug/logstream.hxx>
36 #include <simgear/math/fg_types.hxx>
37
38 #include <Aircraft/aircraft.hxx>
39 #include <FDM/UIUCModel/uiuc_aircraftdir.h>
40 #include <Controls/controls.hxx>
41 #include <Autopilot/newauto.hxx>
42 #include <Scenery/scenery.hxx>
43 #include <Time/fg_time.hxx>
44 #include <Time/light.hxx>
45 #include <Time/event.hxx>
46 #include <Time/sunpos.hxx>
47 #include <Cockpit/radiostack.hxx>
48 #include <Ephemeris/ephemeris.hxx>
49 #ifndef FG_OLD_WEATHER
50 #  include <WeatherCM/FGLocalWeatherDatabase.h>
51 #else
52 #  include <Weather/weather.hxx>
53 #endif
54
55 #include "options.hxx"
56 #include "save.hxx"
57 #include "fg_init.hxx"
58
59 FG_USING_NAMESPACE(std);
60
61
62 #include "bfi.hxx"
63
64
65 \f
66 ////////////////////////////////////////////////////////////////////////
67 // Static variables.
68 ////////////////////////////////////////////////////////////////////////
69
70 bool FGBFI::_needReinit = false;
71
72
73 \f
74 ////////////////////////////////////////////////////////////////////////
75 // Local functions
76 ////////////////////////////////////////////////////////////////////////
77
78
79 /**
80  * Reinitialize FGFS if required.
81  *
82  * Some changes (especially those in aircraft position) require that
83  * FGFS be reinitialized afterwards.  Rather than reinitialize after
84  * every change, the setter methods simply set a flag so that there
85  * can be a single reinit at the end of the frame.
86  */
87 void
88 FGBFI::update ()
89 {
90   if (_needReinit) {
91     reinit();
92   }
93 }
94
95
96 /**
97  * Reinitialize FGFS to use the new BFI settings.
98  */
99 void
100 FGBFI::reinit ()
101 {
102                                 // Save the state of everything
103                                 // that's going to get clobbered
104                                 // when we reinit the subsystems.
105
106   cout << "BFI: start reinit\n";
107
108   setHeading(getHeading());
109   setPitch(getPitch());
110   setRoll(getRoll());
111   setSpeedNorth(getSpeedNorth());
112   setSpeedEast(getSpeedEast());
113   setSpeedDown(getSpeedDown());
114   setLatitude(getLatitude());
115   setLongitude(getLongitude());
116   setAltitude(getAltitude());
117
118                                 // TODO: add more AP stuff
119   double elevator = getElevator();
120   double aileron = getAileron();
121   double rudder = getRudder();
122   double throttle = getThrottle();
123   double elevator_trim = getElevatorTrim();
124   double flaps = getFlaps();
125   double brake = getBrake();
126   bool apHeadingLock = getAPHeadingLock();
127   double apHeadingMag = getAPHeadingMag();
128   bool apAltitudeLock = getAPAltitudeLock();
129   double apAltitude = getAPAltitude();
130   const string &targetAirport = getTargetAirport();
131   bool gpsLock = getGPSLock();
132   double gpsLatitude = getGPSTargetLatitude();
133   double gpsLongitude = getGPSTargetLongitude();
134
135   setTargetAirport("");
136   cout << "Target airport is " << current_options.get_airport_id() << endl;
137   fgReInitSubsystems();
138
139                                 // FIXME: this is wrong.
140                                 // All of these are scheduled events,
141                                 // and it should be possible to force
142                                 // them all to run once.
143   fgUpdateSunPos();
144   fgUpdateMoonPos();
145   cur_light_params.Update();
146   FGTime::cur_time_params->updateLocal();
147   fgUpdateWeatherDatabase();
148   fgRadioSearch();
149
150                                 // Restore all of the old states.
151   setElevator(elevator);
152   setAileron(aileron);
153   setRudder(rudder);
154   setThrottle(throttle);
155   setElevatorTrim(elevator_trim);
156   setFlaps(flaps);
157   setBrake(brake);
158   setAPHeadingLock(apHeadingLock);
159   setAPHeadingMag(apHeadingMag);
160   setAPAltitudeLock(apAltitudeLock);
161   setAPAltitude(apAltitude);
162   setTargetAirport(targetAirport);
163   setGPSLock(gpsLock);
164   setGPSTargetLatitude(gpsLatitude);
165   setGPSTargetLongitude(gpsLongitude);
166
167   _needReinit = false;
168
169   cout << "BFI: end reinit\n";
170 }
171
172
173 \f
174 ////////////////////////////////////////////////////////////////////////
175 // Simulation.
176 ////////////////////////////////////////////////////////////////////////
177
178
179 /**
180  * Return the flight model as an integer.
181  *
182  * TODO: use a string instead.
183  */
184 int
185 FGBFI::getFlightModel ()
186 {
187   return current_options.get_flight_model();
188 }
189
190
191 /**
192  * Return the current aircraft as a string.
193  */
194 const string
195 FGBFI::getAircraft ()
196 {
197   return current_options.get_aircraft();
198 }
199
200
201 /**
202  * Return the current aircraft directory (UIUC) as a string.
203  */
204 const string
205 FGBFI::getAircraftDir ()
206 {
207   return aircraft_dir;
208 }
209
210
211 /**
212  * Set the flight model as an integer.
213  *
214  * TODO: use a string instead.
215  */
216 void
217 FGBFI::setFlightModel (int model)
218 {
219   current_options.set_flight_model(model);
220   needReinit();
221 }
222
223
224 /**
225  * Set the current aircraft.
226  */
227 void
228 FGBFI::setAircraft (const string &aircraft)
229 {
230   current_options.set_aircraft(aircraft);
231   needReinit();
232 }
233
234
235 /**
236  * Set the current aircraft directory (UIUC).
237  */
238 void
239 FGBFI::setAircraftDir (const string &dir)
240 {
241   aircraft_dir = dir;
242   needReinit();
243 }
244
245
246 /**
247  * Return the current Zulu time.
248  */
249 time_t
250 FGBFI::getTimeGMT ()
251 {
252                                 // FIXME: inefficient
253   return mktime(FGTime::cur_time_params->getGmt());
254 }
255
256
257 /**
258  * Set the current Zulu time.
259  */
260 void
261 FGBFI::setTimeGMT (time_t time)
262 {
263                                 // FIXME: need to update lighting
264                                 // and solar system
265   current_options.set_time_offset(time);
266   current_options.set_time_offset_type(fgOPTIONS::FG_TIME_GMT_ABSOLUTE);
267   FGTime::cur_time_params->init( cur_fdm_state->get_Longitude(),
268                                  cur_fdm_state->get_Latitude() );
269   FGTime::cur_time_params->update( cur_fdm_state->get_Longitude(),
270                                    cur_fdm_state->get_Latitude(),
271                                    cur_fdm_state->get_Altitude()
272                                    * FEET_TO_METER );
273   needReinit();
274 }
275
276
277 /**
278  * Return true if the HUD is visible.
279  */
280 bool
281 FGBFI::getHUDVisible ()
282 {
283   return current_options.get_hud_status();
284 }
285
286
287 /**
288  * Ensure that the HUD is visible or hidden.
289  */
290 void
291 FGBFI::setHUDVisible (bool visible)
292 {
293   current_options.set_hud_status(visible);
294 }
295
296
297 /**
298  * Return true if the 2D panel is visible.
299  */
300 bool
301 FGBFI::getPanelVisible ()
302 {
303   return current_options.get_panel_status();
304 }
305
306
307 /**
308  * Ensure that the 2D panel is visible or hidden.
309  */
310 void
311 FGBFI::setPanelVisible (bool visible)
312 {
313   if (current_options.get_panel_status() != visible) {
314     current_options.toggle_panel();
315   }
316 }
317
318
319 \f
320 ////////////////////////////////////////////////////////////////////////
321 // Position
322 ////////////////////////////////////////////////////////////////////////
323
324
325 /**
326  * Return the current latitude in degrees (negative for south).
327  */
328 double
329 FGBFI::getLatitude ()
330 {
331   return current_aircraft.fdm_state->get_Latitude() * RAD_TO_DEG;
332 }
333
334
335 /**
336  * Set the current latitude in degrees (negative for south).
337  */
338 void
339 FGBFI::setLatitude (double latitude)
340 {
341   current_options.set_lat(latitude);
342   current_aircraft.fdm_state->set_Latitude(latitude * DEG_TO_RAD);
343   needReinit();
344 }
345
346
347 /**
348  * Return the current longitude in degrees (negative for west).
349  */
350 double
351 FGBFI::getLongitude ()
352 {
353   return current_aircraft.fdm_state->get_Longitude() * RAD_TO_DEG;
354 }
355
356
357 /**
358  * Set the current longitude in degrees (negative for west).
359  */
360 void
361 FGBFI::setLongitude (double longitude)
362 {
363   current_options.set_lon(longitude);
364   current_aircraft.fdm_state->set_Longitude(longitude * DEG_TO_RAD);
365   needReinit();
366 }
367
368
369 /**
370  * Return the current altitude in feet.
371  */
372 double
373 FGBFI::getAltitude ()
374 {
375   return current_aircraft.fdm_state->get_Altitude();
376 }
377
378
379
380 /**
381  * Return the current altitude in above the terrain.
382  */
383 double
384 FGBFI::getAGL ()
385 {
386   return current_aircraft.fdm_state->get_Altitude()
387          - scenery.cur_elev * METER_TO_FEET;
388 }
389
390
391 /**
392  * Set the current altitude in feet.
393  */
394 void
395 FGBFI::setAltitude (double altitude)
396 {
397   current_options.set_altitude(altitude * FEET_TO_METER);
398   current_aircraft.fdm_state->set_Altitude(altitude);
399   needReinit();
400 }
401
402
403 \f
404 ////////////////////////////////////////////////////////////////////////
405 // Attitude
406 ////////////////////////////////////////////////////////////////////////
407
408
409 /**
410  * Return the current heading in degrees.
411  */
412 double
413 FGBFI::getHeading ()
414 {
415   return current_aircraft.fdm_state->get_Psi() * RAD_TO_DEG;
416 }
417
418
419 /**
420  * Return the current heading in degrees.
421  */
422 double
423 FGBFI::getHeadingMag ()
424 {
425   return current_aircraft.fdm_state->get_Psi() * RAD_TO_DEG - getMagVar();
426 }
427
428
429 /**
430  * Set the current heading in degrees.
431  */
432 void
433 FGBFI::setHeading (double heading)
434 {
435   current_options.set_heading(heading);
436   current_aircraft.fdm_state->set_Euler_Angles(getRoll() * DEG_TO_RAD,
437                                                getPitch() * DEG_TO_RAD,
438                                                heading * DEG_TO_RAD);
439   needReinit();
440 }
441
442
443 /**
444  * Return the current pitch in degrees.
445  */
446 double
447 FGBFI::getPitch ()
448 {
449   return current_aircraft.fdm_state->get_Theta() * RAD_TO_DEG;
450 }
451
452
453 /**
454  * Set the current pitch in degrees.
455  */
456 void
457 FGBFI::setPitch (double pitch)
458 {
459
460   current_options.set_pitch(pitch);
461   current_aircraft.fdm_state->set_Euler_Angles(getRoll() * DEG_TO_RAD,
462                                                pitch * DEG_TO_RAD,
463                                                getHeading() * DEG_TO_RAD);
464   needReinit();
465 }
466
467
468 /**
469  * Return the current roll in degrees.
470  */
471 double
472 FGBFI::getRoll ()
473 {
474   return current_aircraft.fdm_state->get_Phi() * RAD_TO_DEG;
475 }
476
477
478 /**
479  * Set the current roll in degrees.
480  */
481 void
482 FGBFI::setRoll (double roll)
483 {
484   current_options.set_roll(roll);
485   current_aircraft.fdm_state->set_Euler_Angles(roll * DEG_TO_RAD,
486                                                getPitch() * DEG_TO_RAD,
487                                                getHeading() * DEG_TO_RAD);
488   needReinit();
489 }
490
491
492 \f
493 ////////////////////////////////////////////////////////////////////////
494 // Velocities
495 ////////////////////////////////////////////////////////////////////////
496
497
498 /**
499  * Return the current airspeed in knots.
500  */
501 double
502 FGBFI::getAirspeed ()
503 {
504                                 // FIXME: should we add speed-up?
505   return current_aircraft.fdm_state->get_V_calibrated_kts();
506 }
507
508
509 /**
510  * Return the current sideslip (FIXME: units unknown).
511  */
512 double
513 FGBFI::getSideSlip ()
514 {
515   return current_aircraft.fdm_state->get_Beta();
516 }
517
518
519 /**
520  * Return the current climb rate in feet/minute
521  */
522 double
523 FGBFI::getVerticalSpeed ()
524 {
525                                 // What about meters?
526   return current_aircraft.fdm_state->get_Climb_Rate() * 60.0;
527 }
528
529
530 /**
531  * Get the current north velocity (units??).
532  */
533 double
534 FGBFI::getSpeedNorth ()
535 {
536   return current_aircraft.fdm_state->get_V_north();
537 }
538
539
540 /**
541  * Set the current north velocity (units??).
542  */
543 void
544 FGBFI::setSpeedNorth (double speed)
545 {
546   current_options.set_uBody(speed);
547   current_aircraft.fdm_state->set_Velocities_Local(speed,
548                                                    getSpeedEast(),
549                                                    getSpeedDown());
550   needReinit();
551 }
552
553
554 /**
555  * Get the current east velocity (units??).
556  */
557 double
558 FGBFI::getSpeedEast ()
559 {
560   return current_aircraft.fdm_state->get_V_east();
561 }
562
563
564 /**
565  * Set the current east velocity (units??).
566  */
567 void
568 FGBFI::setSpeedEast (double speed)
569 {
570   current_options.set_vBody(speed);
571   current_aircraft.fdm_state->set_Velocities_Local(getSpeedNorth(),
572                                                    speed,
573                                                    getSpeedDown());
574   needReinit();
575 }
576
577
578 /**
579  * Get the current down velocity (units??).
580  */
581 double
582 FGBFI::getSpeedDown ()
583 {
584   return current_aircraft.fdm_state->get_V_down();
585 }
586
587
588 /**
589  * Set the current down velocity (units??).
590  */
591 void
592 FGBFI::setSpeedDown (double speed)
593 {
594   current_options.set_wBody(speed);
595   current_aircraft.fdm_state->set_Velocities_Local(getSpeedNorth(),
596                                                    getSpeedEast(),
597                                                    speed);
598   needReinit();
599 }
600
601
602 \f
603 ////////////////////////////////////////////////////////////////////////
604 // Controls
605 ////////////////////////////////////////////////////////////////////////
606
607
608 /**
609  * Get the throttle setting, from 0.0 (none) to 1.0 (full).
610  */
611 double
612 FGBFI::getThrottle ()
613 {
614                                 // FIXME: add throttle selector
615   return controls.get_throttle(0);
616 }
617
618
619 /**
620  * Set the throttle, from 0.0 (none) to 1.0 (full).
621  */
622 void
623 FGBFI::setThrottle (double throttle)
624 {
625                                 // FIXME: allow throttle selection
626                                 // FIXME: clamp?
627   controls.set_throttle(0, throttle);
628 }
629
630
631 /**
632  * Get the flaps setting, from 0.0 (none) to 1.0 (full).
633  */
634 double
635 FGBFI::getFlaps ()
636 {
637   return controls.get_flaps();
638 }
639
640
641 /**
642  * Set the flaps, from 0.0 (none) to 1.0 (full).
643  */
644 void
645 FGBFI::setFlaps (double flaps)
646 {
647                                 // FIXME: clamp?
648   controls.set_flaps(flaps);
649 }
650
651
652 /**
653  * Get the aileron, from -1.0 (left) to 1.0 (right).
654  */
655 double
656 FGBFI::getAileron ()
657 {
658   return controls.get_aileron();
659 }
660
661
662 /**
663  * Set the aileron, from -1.0 (left) to 1.0 (right).
664  */
665 void
666 FGBFI::setAileron (double aileron)
667 {
668                                 // FIXME: clamp?
669   controls.set_aileron(aileron);
670 }
671
672
673 /**
674  * Get the rudder setting, from -1.0 (left) to 1.0 (right).
675  */
676 double
677 FGBFI::getRudder ()
678 {
679   return controls.get_rudder();
680 }
681
682
683 /**
684  * Set the rudder, from -1.0 (left) to 1.0 (right).
685  */
686 void
687 FGBFI::setRudder (double rudder)
688 {
689                                 // FIXME: clamp?
690   controls.set_rudder(rudder);
691 }
692
693
694 /**
695  * Get the elevator setting, from -1.0 (down) to 1.0 (up).
696  */
697 double
698 FGBFI::getElevator ()
699 {
700   return controls.get_elevator();
701 }
702
703
704 /**
705  * Set the elevator, from -1.0 (down) to 1.0 (up).
706  */
707 void
708 FGBFI::setElevator (double elevator)
709 {
710                                 // FIXME: clamp?
711   controls.set_elevator(elevator);
712 }
713
714
715 /**
716  * Get the elevator trim, from -1.0 (down) to 1.0 (up).
717  */
718 double
719 FGBFI::getElevatorTrim ()
720 {
721   return controls.get_elevator_trim();
722 }
723
724
725 /**
726  * Set the elevator trim, from -1.0 (down) to 1.0 (up).
727  */
728 void
729 FGBFI::setElevatorTrim (double trim)
730 {
731                                 // FIXME: clamp?
732   controls.set_elevator_trim(trim);
733 }
734
735
736 /**
737  * Get the brake setting, from 0.0 (none) to 1.0 (full).
738  */
739 double
740 FGBFI::getBrake ()
741 {
742                                 // FIXME: add brake selector
743   return controls.get_brake(0);
744 }
745
746
747 /**
748  * Set the brake, from 0.0 (none) to 1.0 (full).
749  */
750 void
751 FGBFI::setBrake (double brake)
752 {
753                                 // FIXME: clamp?
754                                 // FIXME: allow brake selection
755   controls.set_brake(0, brake);
756 }
757
758
759 \f
760 ////////////////////////////////////////////////////////////////////////
761 // Autopilot
762 ////////////////////////////////////////////////////////////////////////
763
764
765 /**
766  * Get the autopilot altitude lock (true=on).
767  */
768 bool
769 FGBFI::getAPAltitudeLock ()
770 {
771     return current_autopilot->get_AltitudeEnabled();
772 }
773
774
775 /**
776  * Set the autopilot altitude lock (true=on).
777  */
778 void
779 FGBFI::setAPAltitudeLock (bool lock)
780 {
781   current_autopilot->set_AltitudeMode(FGAutopilot::FG_ALTITUDE_LOCK);
782   current_autopilot->set_AltitudeEnabled(lock);
783 }
784
785
786 /**
787  * Get the autopilot target altitude in feet.
788  */
789 double
790 FGBFI::getAPAltitude ()
791 {
792   return current_autopilot->get_TargetAltitude() * METER_TO_FEET;
793 }
794
795
796 /**
797  * Set the autopilot target altitude in feet.
798  */
799 void
800 FGBFI::setAPAltitude (double altitude)
801 {
802     current_autopilot->set_TargetAltitude( altitude );
803 }
804
805
806 /**
807  * Get the autopilot heading lock (true=on).
808  */
809 bool
810 FGBFI::getAPHeadingLock ()
811 {
812     return
813       (current_autopilot->get_HeadingEnabled() &&
814        current_autopilot->get_HeadingMode() == FGAutopilot::FG_HEADING_LOCK);
815 }
816
817
818 /**
819  * Set the autopilot heading lock (true=on).
820  */
821 void
822 FGBFI::setAPHeadingLock (bool lock)
823 {
824   if (lock) {
825                                 // We need to do this so that
826                                 // it's possible to lock onto a
827                                 // heading other than the current
828                                 // heading.
829     double heading = getAPHeadingMag();
830     current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_LOCK);
831     current_autopilot->set_HeadingEnabled(true);
832     setAPHeadingMag(heading);
833   } else if (current_autopilot->get_HeadingMode() ==
834              FGAutopilot::FG_HEADING_LOCK) {
835     current_autopilot->set_HeadingEnabled(false);
836   }
837 }
838
839
840 /**
841  * Get the autopilot target heading in degrees.
842  */
843 double
844 FGBFI::getAPHeadingMag ()
845 {
846   return current_autopilot->get_TargetHeading() - getMagVar();
847 }
848
849
850 /**
851  * Set the autopilot target heading in degrees.
852  */
853 void
854 FGBFI::setAPHeadingMag (double heading)
855 {
856   current_autopilot->set_TargetHeading( heading + getMagVar() );
857 }
858
859
860 /**
861  * Return true if the autopilot is locked to NAV1.
862  */
863 bool
864 FGBFI::getAPNAV1Lock ()
865 {
866   return
867     (current_autopilot->get_HeadingEnabled() &&
868      current_autopilot->get_HeadingMode() == FGAutopilot::FG_HEADING_NAV1);
869 }
870
871
872 /**
873  * Set the autopilot NAV1 lock.
874  */
875 void
876 FGBFI::setAPNAV1Lock (bool lock)
877 {
878   if (lock) {
879     current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_NAV1);
880     current_autopilot->set_HeadingEnabled(true);
881   } else if (current_autopilot->get_HeadingMode() ==
882              FGAutopilot::FG_HEADING_NAV1) {
883     current_autopilot->set_HeadingEnabled(false);
884   }
885 }
886
887
888 \f
889 ////////////////////////////////////////////////////////////////////////
890 // Radio navigation.
891 ////////////////////////////////////////////////////////////////////////
892
893 double
894 FGBFI::getNAV1Freq ()
895 {
896   return current_radiostack->get_nav1_freq();
897 }
898
899 double
900 FGBFI::getNAV1AltFreq ()
901 {
902   return current_radiostack->get_nav1_alt_freq();
903 }
904
905 double
906 FGBFI::getNAV1Radial ()
907 {
908   return current_radiostack->get_nav1_radial();
909 }
910
911 double
912 FGBFI::getNAV1SelRadial ()
913 {
914   return current_radiostack->get_nav1_sel_radial();
915 }
916
917 double
918 FGBFI::getNAV1DistDME ()
919 {
920   return current_radiostack->get_nav1_dme_dist();
921 }
922
923 bool
924 FGBFI::getNAV1InRange ()
925 {
926   return current_radiostack->get_nav1_inrange();
927 }
928
929 bool
930 FGBFI::getNAV1DMEInRange ()
931 {
932   return (current_radiostack->get_nav1_inrange() &&
933           current_radiostack->get_nav1_has_dme());
934 }
935
936 double
937 FGBFI::getNAV2Freq ()
938 {
939   return current_radiostack->get_nav2_freq();
940 }
941
942 double
943 FGBFI::getNAV2AltFreq ()
944 {
945   return current_radiostack->get_nav2_alt_freq();
946 }
947
948 double
949 FGBFI::getNAV2Radial ()
950 {
951   return current_radiostack->get_nav2_radial();
952 }
953
954 double
955 FGBFI::getNAV2SelRadial ()
956 {
957   return current_radiostack->get_nav2_sel_radial();
958 }
959
960 double
961 FGBFI::getNAV2DistDME ()
962 {
963   return current_radiostack->get_nav2_dme_dist();
964 }
965
966 bool
967 FGBFI::getNAV2InRange ()
968 {
969   return current_radiostack->get_nav2_inrange();
970 }
971
972 bool
973 FGBFI::getNAV2DMEInRange ()
974 {
975   return (current_radiostack->get_nav2_inrange() &&
976           current_radiostack->get_nav2_has_dme());
977 }
978
979 double
980 FGBFI::getADFFreq ()
981 {
982   return current_radiostack->get_adf_freq();
983 }
984
985 double
986 FGBFI::getADFAltFreq ()
987 {
988   return current_radiostack->get_adf_alt_freq();
989 }
990
991 double
992 FGBFI::getADFRotation ()
993 {
994   return current_radiostack->get_adf_rotation();
995 }
996
997 void
998 FGBFI::setNAV1Freq (double freq)
999 {
1000   current_radiostack->set_nav1_freq(freq);
1001 }
1002
1003 void
1004 FGBFI::setNAV1AltFreq (double freq)
1005 {
1006   current_radiostack->set_nav1_alt_freq(freq);
1007 }
1008
1009 void
1010 FGBFI::setNAV1SelRadial (double radial)
1011 {
1012   current_radiostack->set_nav1_sel_radial(radial);
1013 }
1014
1015 void
1016 FGBFI::setNAV2Freq (double freq)
1017 {
1018   current_radiostack->set_nav2_freq(freq);
1019 }
1020
1021 void
1022 FGBFI::setNAV2AltFreq (double freq)
1023 {
1024   current_radiostack->set_nav2_alt_freq(freq);
1025 }
1026
1027 void
1028 FGBFI::setNAV2SelRadial (double radial)
1029 {
1030   current_radiostack->set_nav2_sel_radial(radial);
1031 }
1032
1033 void
1034 FGBFI::setADFFreq (double freq)
1035 {
1036   current_radiostack->set_adf_freq(freq);
1037 }
1038
1039 void
1040 FGBFI::setADFAltFreq (double freq)
1041 {
1042   current_radiostack->set_adf_alt_freq(freq);
1043 }
1044
1045 void
1046 FGBFI::setADFRotation (double rot)
1047 {
1048   current_radiostack->set_adf_rotation(rot);
1049 }
1050
1051
1052 \f
1053 ////////////////////////////////////////////////////////////////////////
1054 // GPS
1055 ////////////////////////////////////////////////////////////////////////
1056
1057
1058 /**
1059  * Get the autopilot GPS lock (true=on).
1060  */
1061 bool
1062 FGBFI::getGPSLock ()
1063 {
1064   return (current_autopilot->get_HeadingEnabled() &&
1065           (current_autopilot->get_HeadingMode() ==
1066            FGAutopilot::FG_HEADING_WAYPOINT ));
1067 }
1068
1069
1070 /**
1071  * Set the autopilot GPS lock (true=on).
1072  */
1073 void
1074 FGBFI::setGPSLock (bool lock)
1075 {
1076   if (lock) {
1077     current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_WAYPOINT);
1078     current_autopilot->set_HeadingEnabled(true);
1079   } else if (current_autopilot->get_HeadingMode() ==
1080              FGAutopilot::FG_HEADING_WAYPOINT) {
1081     current_autopilot->set_HeadingEnabled(false);
1082   }
1083 }
1084
1085
1086 /**
1087  * Get the GPS target airport code.
1088  */
1089 const string
1090 FGBFI::getTargetAirport ()
1091 {
1092   return current_options.get_airport_id();
1093 }
1094
1095
1096 /**
1097  * Set the GPS target airport code.
1098  */
1099 void
1100 FGBFI::setTargetAirport (const string &airportId)
1101 {
1102   current_options.set_airport_id(airportId);
1103 }
1104
1105
1106 /**
1107  * Get the GPS target latitude in degrees (negative for south).
1108  */
1109 double
1110 FGBFI::getGPSTargetLatitude ()
1111 {
1112     return current_autopilot->get_TargetLatitude();
1113 }
1114
1115
1116 /**
1117  * Set the GPS target latitude in degrees (negative for south).
1118  */
1119 void
1120 FGBFI::setGPSTargetLatitude (double latitude)
1121 {
1122   current_autopilot->set_TargetLatitude( latitude );
1123 }
1124
1125
1126 /**
1127  * Get the GPS target longitude in degrees (negative for west).
1128  */
1129 double
1130 FGBFI::getGPSTargetLongitude ()
1131 {
1132   return current_autopilot->get_TargetLongitude();
1133 }
1134
1135
1136 /**
1137  * Set the GPS target longitude in degrees (negative for west).
1138  */
1139 void
1140 FGBFI::setGPSTargetLongitude (double longitude)
1141 {
1142   current_autopilot->set_TargetLongitude( longitude );
1143 }
1144
1145
1146 \f
1147 ////////////////////////////////////////////////////////////////////////
1148 // Weather
1149 ////////////////////////////////////////////////////////////////////////
1150
1151
1152 /**
1153  * Get the current visible (units??).
1154  */
1155 double
1156 FGBFI::getVisibility ()
1157 {
1158 #ifndef FG_OLD_WEATHER
1159   return WeatherDatabase->getWeatherVisibility();
1160 #else
1161   return current_weather.get_visibility();
1162 #endif
1163 }
1164
1165
1166 /**
1167  * Check whether clouds are enabled.
1168  */
1169 bool
1170 FGBFI::getClouds ()
1171 {
1172   return current_options.get_clouds();
1173 }
1174
1175
1176 /**
1177  * Check the height of the clouds ASL (units?).
1178  */
1179 double
1180 FGBFI::getCloudsASL ()
1181 {
1182   return current_options.get_clouds_asl();
1183 }
1184
1185
1186 /**
1187  * Set the current visibility (units??).
1188  */
1189 void
1190 FGBFI::setVisibility (double visibility)
1191 {
1192 #ifndef FG_OLD_WEATHER
1193   WeatherDatabase->setWeatherVisibility(visibility);
1194 #else
1195   current_weather.set_visibility(visibility);
1196 #endif
1197 }
1198
1199
1200 /**
1201  * Switch clouds on or off.
1202  */
1203 void
1204 FGBFI::setClouds (bool clouds)
1205 {
1206   cout << "Set clouds to " << clouds << endl;
1207   current_options.set_clouds(clouds);
1208   needReinit();
1209 }
1210
1211
1212 /**
1213  * Set the cloud height.
1214  */
1215 void
1216 FGBFI::setCloudsASL (double cloudsASL)
1217 {
1218   current_options.set_clouds_asl(cloudsASL);
1219   needReinit();
1220 }
1221
1222
1223 \f
1224 ////////////////////////////////////////////////////////////////////////
1225 // Time
1226 ////////////////////////////////////////////////////////////////////////
1227
1228 /**
1229  * Return the magnetic variation
1230  */
1231 double
1232 FGBFI::getMagVar ()
1233 {
1234   return FGTime::cur_time_params->getMagVar() * RAD_TO_DEG;
1235 }
1236
1237
1238 /**
1239  * Return the magnetic variation
1240  */
1241 double
1242 FGBFI::getMagDip ()
1243 {
1244   return FGTime::cur_time_params->getMagDip() * RAD_TO_DEG;
1245 }
1246
1247
1248 // end of bfi.cxx
1249