]> git.mxchange.org Git - flightgear.git/blob - src/Main/bfi.cxx
Updates to cloud code to add different basic cloud types. This isn't the
[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   return FGTime::cur_time_params->get_cur_time();
253 }
254
255
256 /**
257  * Set the current Zulu time.
258  */
259 void
260 FGBFI::setTimeGMT (time_t time)
261 {
262                                 // FIXME: need to update lighting
263                                 // and solar system
264   current_options.set_time_offset(time);
265   current_options.set_time_offset_type(fgOPTIONS::FG_TIME_GMT_ABSOLUTE);
266   FGTime::cur_time_params->init( cur_fdm_state->get_Longitude(),
267                                  cur_fdm_state->get_Latitude() );
268   FGTime::cur_time_params->update( cur_fdm_state->get_Longitude(),
269                                    cur_fdm_state->get_Latitude(),
270                                    cur_fdm_state->get_Altitude()
271                                    * FEET_TO_METER );
272   needReinit();
273 }
274
275
276 /**
277  * Return true if the HUD is visible.
278  */
279 bool
280 FGBFI::getHUDVisible ()
281 {
282   return current_options.get_hud_status();
283 }
284
285
286 /**
287  * Ensure that the HUD is visible or hidden.
288  */
289 void
290 FGBFI::setHUDVisible (bool visible)
291 {
292   current_options.set_hud_status(visible);
293 }
294
295
296 /**
297  * Return true if the 2D panel is visible.
298  */
299 bool
300 FGBFI::getPanelVisible ()
301 {
302   return current_options.get_panel_status();
303 }
304
305
306 /**
307  * Ensure that the 2D panel is visible or hidden.
308  */
309 void
310 FGBFI::setPanelVisible (bool visible)
311 {
312   if (current_options.get_panel_status() != visible) {
313     current_options.toggle_panel();
314   }
315 }
316
317
318 \f
319 ////////////////////////////////////////////////////////////////////////
320 // Position
321 ////////////////////////////////////////////////////////////////////////
322
323
324 /**
325  * Return the current latitude in degrees (negative for south).
326  */
327 double
328 FGBFI::getLatitude ()
329 {
330   return current_aircraft.fdm_state->get_Latitude() * RAD_TO_DEG;
331 }
332
333
334 /**
335  * Set the current latitude in degrees (negative for south).
336  */
337 void
338 FGBFI::setLatitude (double latitude)
339 {
340   current_options.set_lat(latitude);
341   current_aircraft.fdm_state->set_Latitude(latitude * DEG_TO_RAD);
342   needReinit();
343 }
344
345
346 /**
347  * Return the current longitude in degrees (negative for west).
348  */
349 double
350 FGBFI::getLongitude ()
351 {
352   return current_aircraft.fdm_state->get_Longitude() * RAD_TO_DEG;
353 }
354
355
356 /**
357  * Set the current longitude in degrees (negative for west).
358  */
359 void
360 FGBFI::setLongitude (double longitude)
361 {
362   current_options.set_lon(longitude);
363   current_aircraft.fdm_state->set_Longitude(longitude * DEG_TO_RAD);
364   needReinit();
365 }
366
367
368 /**
369  * Return the current altitude in feet.
370  */
371 double
372 FGBFI::getAltitude ()
373 {
374   return current_aircraft.fdm_state->get_Altitude();
375 }
376
377
378
379 /**
380  * Return the current altitude in above the terrain.
381  */
382 double
383 FGBFI::getAGL ()
384 {
385   return current_aircraft.fdm_state->get_Altitude()
386          - scenery.cur_elev * METER_TO_FEET;
387 }
388
389
390 /**
391  * Set the current altitude in feet.
392  */
393 void
394 FGBFI::setAltitude (double altitude)
395 {
396   current_options.set_altitude(altitude * FEET_TO_METER);
397   current_aircraft.fdm_state->set_Altitude(altitude);
398   needReinit();
399 }
400
401
402 \f
403 ////////////////////////////////////////////////////////////////////////
404 // Attitude
405 ////////////////////////////////////////////////////////////////////////
406
407
408 /**
409  * Return the current heading in degrees.
410  */
411 double
412 FGBFI::getHeading ()
413 {
414   return current_aircraft.fdm_state->get_Psi() * RAD_TO_DEG;
415 }
416
417
418 /**
419  * Return the current heading in degrees.
420  */
421 double
422 FGBFI::getHeadingMag ()
423 {
424   return current_aircraft.fdm_state->get_Psi() * RAD_TO_DEG - getMagVar();
425 }
426
427
428 /**
429  * Set the current heading in degrees.
430  */
431 void
432 FGBFI::setHeading (double heading)
433 {
434   current_options.set_heading(heading);
435   current_aircraft.fdm_state->set_Euler_Angles(getRoll() * DEG_TO_RAD,
436                                                getPitch() * DEG_TO_RAD,
437                                                heading * DEG_TO_RAD);
438   needReinit();
439 }
440
441
442 /**
443  * Return the current pitch in degrees.
444  */
445 double
446 FGBFI::getPitch ()
447 {
448   return current_aircraft.fdm_state->get_Theta() * RAD_TO_DEG;
449 }
450
451
452 /**
453  * Set the current pitch in degrees.
454  */
455 void
456 FGBFI::setPitch (double pitch)
457 {
458
459   current_options.set_pitch(pitch);
460   current_aircraft.fdm_state->set_Euler_Angles(getRoll() * DEG_TO_RAD,
461                                                pitch * DEG_TO_RAD,
462                                                getHeading() * DEG_TO_RAD);
463   needReinit();
464 }
465
466
467 /**
468  * Return the current roll in degrees.
469  */
470 double
471 FGBFI::getRoll ()
472 {
473   return current_aircraft.fdm_state->get_Phi() * RAD_TO_DEG;
474 }
475
476
477 /**
478  * Set the current roll in degrees.
479  */
480 void
481 FGBFI::setRoll (double roll)
482 {
483   current_options.set_roll(roll);
484   current_aircraft.fdm_state->set_Euler_Angles(roll * DEG_TO_RAD,
485                                                getPitch() * DEG_TO_RAD,
486                                                getHeading() * DEG_TO_RAD);
487   needReinit();
488 }
489
490
491 \f
492 ////////////////////////////////////////////////////////////////////////
493 // Velocities
494 ////////////////////////////////////////////////////////////////////////
495
496
497 /**
498  * Return the current airspeed in knots.
499  */
500 double
501 FGBFI::getAirspeed ()
502 {
503                                 // FIXME: should we add speed-up?
504   return current_aircraft.fdm_state->get_V_calibrated_kts();
505 }
506
507
508 /**
509  * Return the current sideslip (FIXME: units unknown).
510  */
511 double
512 FGBFI::getSideSlip ()
513 {
514   return current_aircraft.fdm_state->get_Beta();
515 }
516
517
518 /**
519  * Return the current climb rate in feet/minute
520  */
521 double
522 FGBFI::getVerticalSpeed ()
523 {
524                                 // What about meters?
525   return current_aircraft.fdm_state->get_Climb_Rate() * 60.0;
526 }
527
528
529 /**
530  * Get the current north velocity (units??).
531  */
532 double
533 FGBFI::getSpeedNorth ()
534 {
535   return current_aircraft.fdm_state->get_V_north();
536 }
537
538
539 /**
540  * Set the current north velocity (units??).
541  */
542 void
543 FGBFI::setSpeedNorth (double speed)
544 {
545   current_options.set_uBody(speed);
546   current_aircraft.fdm_state->set_Velocities_Local(speed,
547                                                    getSpeedEast(),
548                                                    getSpeedDown());
549   needReinit();
550 }
551
552
553 /**
554  * Get the current east velocity (units??).
555  */
556 double
557 FGBFI::getSpeedEast ()
558 {
559   return current_aircraft.fdm_state->get_V_east();
560 }
561
562
563 /**
564  * Set the current east velocity (units??).
565  */
566 void
567 FGBFI::setSpeedEast (double speed)
568 {
569   current_options.set_vBody(speed);
570   current_aircraft.fdm_state->set_Velocities_Local(getSpeedNorth(),
571                                                    speed,
572                                                    getSpeedDown());
573   needReinit();
574 }
575
576
577 /**
578  * Get the current down velocity (units??).
579  */
580 double
581 FGBFI::getSpeedDown ()
582 {
583   return current_aircraft.fdm_state->get_V_down();
584 }
585
586
587 /**
588  * Set the current down velocity (units??).
589  */
590 void
591 FGBFI::setSpeedDown (double speed)
592 {
593   current_options.set_wBody(speed);
594   current_aircraft.fdm_state->set_Velocities_Local(getSpeedNorth(),
595                                                    getSpeedEast(),
596                                                    speed);
597   needReinit();
598 }
599
600
601 \f
602 ////////////////////////////////////////////////////////////////////////
603 // Controls
604 ////////////////////////////////////////////////////////////////////////
605
606
607 /**
608  * Get the throttle setting, from 0.0 (none) to 1.0 (full).
609  */
610 double
611 FGBFI::getThrottle ()
612 {
613                                 // FIXME: add throttle selector
614   return controls.get_throttle(0);
615 }
616
617
618 /**
619  * Set the throttle, from 0.0 (none) to 1.0 (full).
620  */
621 void
622 FGBFI::setThrottle (double throttle)
623 {
624                                 // FIXME: allow throttle selection
625                                 // FIXME: clamp?
626   controls.set_throttle(0, throttle);
627 }
628
629
630 /**
631  * Get the flaps setting, from 0.0 (none) to 1.0 (full).
632  */
633 double
634 FGBFI::getFlaps ()
635 {
636   return controls.get_flaps();
637 }
638
639
640 /**
641  * Set the flaps, from 0.0 (none) to 1.0 (full).
642  */
643 void
644 FGBFI::setFlaps (double flaps)
645 {
646                                 // FIXME: clamp?
647   controls.set_flaps(flaps);
648 }
649
650
651 /**
652  * Get the aileron, from -1.0 (left) to 1.0 (right).
653  */
654 double
655 FGBFI::getAileron ()
656 {
657   return controls.get_aileron();
658 }
659
660
661 /**
662  * Set the aileron, from -1.0 (left) to 1.0 (right).
663  */
664 void
665 FGBFI::setAileron (double aileron)
666 {
667                                 // FIXME: clamp?
668   controls.set_aileron(aileron);
669 }
670
671
672 /**
673  * Get the rudder setting, from -1.0 (left) to 1.0 (right).
674  */
675 double
676 FGBFI::getRudder ()
677 {
678   return controls.get_rudder();
679 }
680
681
682 /**
683  * Set the rudder, from -1.0 (left) to 1.0 (right).
684  */
685 void
686 FGBFI::setRudder (double rudder)
687 {
688                                 // FIXME: clamp?
689   controls.set_rudder(rudder);
690 }
691
692
693 /**
694  * Get the elevator setting, from -1.0 (down) to 1.0 (up).
695  */
696 double
697 FGBFI::getElevator ()
698 {
699   return controls.get_elevator();
700 }
701
702
703 /**
704  * Set the elevator, from -1.0 (down) to 1.0 (up).
705  */
706 void
707 FGBFI::setElevator (double elevator)
708 {
709                                 // FIXME: clamp?
710   controls.set_elevator(elevator);
711 }
712
713
714 /**
715  * Get the elevator trim, from -1.0 (down) to 1.0 (up).
716  */
717 double
718 FGBFI::getElevatorTrim ()
719 {
720   return controls.get_elevator_trim();
721 }
722
723
724 /**
725  * Set the elevator trim, from -1.0 (down) to 1.0 (up).
726  */
727 void
728 FGBFI::setElevatorTrim (double trim)
729 {
730                                 // FIXME: clamp?
731   controls.set_elevator_trim(trim);
732 }
733
734
735 /**
736  * Get the brake setting, from 0.0 (none) to 1.0 (full).
737  */
738 double
739 FGBFI::getBrake ()
740 {
741                                 // FIXME: add brake selector
742   return controls.get_brake(0);
743 }
744
745
746 /**
747  * Set the brake, from 0.0 (none) to 1.0 (full).
748  */
749 void
750 FGBFI::setBrake (double brake)
751 {
752                                 // FIXME: clamp?
753                                 // FIXME: allow brake selection
754   controls.set_brake(0, brake);
755 }
756
757
758 \f
759 ////////////////////////////////////////////////////////////////////////
760 // Autopilot
761 ////////////////////////////////////////////////////////////////////////
762
763
764 /**
765  * Get the autopilot altitude lock (true=on).
766  */
767 bool
768 FGBFI::getAPAltitudeLock ()
769 {
770     return current_autopilot->get_AltitudeEnabled();
771 }
772
773
774 /**
775  * Set the autopilot altitude lock (true=on).
776  */
777 void
778 FGBFI::setAPAltitudeLock (bool lock)
779 {
780   current_autopilot->set_AltitudeMode(FGAutopilot::FG_ALTITUDE_LOCK);
781   current_autopilot->set_AltitudeEnabled(lock);
782 }
783
784
785 /**
786  * Get the autopilot target altitude in feet.
787  */
788 double
789 FGBFI::getAPAltitude ()
790 {
791   return current_autopilot->get_TargetAltitude() * METER_TO_FEET;
792 }
793
794
795 /**
796  * Set the autopilot target altitude in feet.
797  */
798 void
799 FGBFI::setAPAltitude (double altitude)
800 {
801     current_autopilot->set_TargetAltitude( altitude );
802 }
803
804
805 /**
806  * Get the autopilot heading lock (true=on).
807  */
808 bool
809 FGBFI::getAPHeadingLock ()
810 {
811     return
812       (current_autopilot->get_HeadingEnabled() &&
813        current_autopilot->get_HeadingMode() == FGAutopilot::FG_HEADING_LOCK);
814 }
815
816
817 /**
818  * Set the autopilot heading lock (true=on).
819  */
820 void
821 FGBFI::setAPHeadingLock (bool lock)
822 {
823   if (lock) {
824                                 // We need to do this so that
825                                 // it's possible to lock onto a
826                                 // heading other than the current
827                                 // heading.
828     double heading = getAPHeadingMag();
829     current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_LOCK);
830     current_autopilot->set_HeadingEnabled(true);
831     setAPHeadingMag(heading);
832   } else if (current_autopilot->get_HeadingMode() ==
833              FGAutopilot::FG_HEADING_LOCK) {
834     current_autopilot->set_HeadingEnabled(false);
835   }
836 }
837
838
839 /**
840  * Get the autopilot target heading in degrees.
841  */
842 double
843 FGBFI::getAPHeadingMag ()
844 {
845   return current_autopilot->get_TargetHeading() - getMagVar();
846 }
847
848
849 /**
850  * Set the autopilot target heading in degrees.
851  */
852 void
853 FGBFI::setAPHeadingMag (double heading)
854 {
855   current_autopilot->set_TargetHeading( heading + getMagVar() );
856 }
857
858
859 /**
860  * Return true if the autopilot is locked to NAV1.
861  */
862 bool
863 FGBFI::getAPNAV1Lock ()
864 {
865   return
866     (current_autopilot->get_HeadingEnabled() &&
867      current_autopilot->get_HeadingMode() == FGAutopilot::FG_HEADING_NAV1);
868 }
869
870
871 /**
872  * Set the autopilot NAV1 lock.
873  */
874 void
875 FGBFI::setAPNAV1Lock (bool lock)
876 {
877   if (lock) {
878     current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_NAV1);
879     current_autopilot->set_HeadingEnabled(true);
880   } else if (current_autopilot->get_HeadingMode() ==
881              FGAutopilot::FG_HEADING_NAV1) {
882     current_autopilot->set_HeadingEnabled(false);
883   }
884 }
885
886
887 \f
888 ////////////////////////////////////////////////////////////////////////
889 // Radio navigation.
890 ////////////////////////////////////////////////////////////////////////
891
892 double
893 FGBFI::getNAV1Freq ()
894 {
895   return current_radiostack->get_nav1_freq();
896 }
897
898 double
899 FGBFI::getNAV1AltFreq ()
900 {
901   return current_radiostack->get_nav1_alt_freq();
902 }
903
904 double
905 FGBFI::getNAV1Radial ()
906 {
907   return current_radiostack->get_nav1_radial();
908 }
909
910 double
911 FGBFI::getNAV1SelRadial ()
912 {
913   return current_radiostack->get_nav1_sel_radial();
914 }
915
916 double
917 FGBFI::getNAV1DistDME ()
918 {
919   return current_radiostack->get_nav1_dme_dist();
920 }
921
922 bool
923 FGBFI::getNAV1InRange ()
924 {
925   return current_radiostack->get_nav1_inrange();
926 }
927
928 bool
929 FGBFI::getNAV1DMEInRange ()
930 {
931   return (current_radiostack->get_nav1_inrange() &&
932           current_radiostack->get_nav1_has_dme());
933 }
934
935 double
936 FGBFI::getNAV2Freq ()
937 {
938   return current_radiostack->get_nav2_freq();
939 }
940
941 double
942 FGBFI::getNAV2AltFreq ()
943 {
944   return current_radiostack->get_nav2_alt_freq();
945 }
946
947 double
948 FGBFI::getNAV2Radial ()
949 {
950   return current_radiostack->get_nav2_radial();
951 }
952
953 double
954 FGBFI::getNAV2SelRadial ()
955 {
956   return current_radiostack->get_nav2_sel_radial();
957 }
958
959 double
960 FGBFI::getNAV2DistDME ()
961 {
962   return current_radiostack->get_nav2_dme_dist();
963 }
964
965 bool
966 FGBFI::getNAV2InRange ()
967 {
968   return current_radiostack->get_nav2_inrange();
969 }
970
971 bool
972 FGBFI::getNAV2DMEInRange ()
973 {
974   return (current_radiostack->get_nav2_inrange() &&
975           current_radiostack->get_nav2_has_dme());
976 }
977
978 double
979 FGBFI::getADFFreq ()
980 {
981   return current_radiostack->get_adf_freq();
982 }
983
984 double
985 FGBFI::getADFAltFreq ()
986 {
987   return current_radiostack->get_adf_alt_freq();
988 }
989
990 double
991 FGBFI::getADFRotation ()
992 {
993   return current_radiostack->get_adf_rotation();
994 }
995
996 void
997 FGBFI::setNAV1Freq (double freq)
998 {
999   current_radiostack->set_nav1_freq(freq);
1000 }
1001
1002 void
1003 FGBFI::setNAV1AltFreq (double freq)
1004 {
1005   current_radiostack->set_nav1_alt_freq(freq);
1006 }
1007
1008 void
1009 FGBFI::setNAV1SelRadial (double radial)
1010 {
1011   current_radiostack->set_nav1_sel_radial(radial);
1012 }
1013
1014 void
1015 FGBFI::setNAV2Freq (double freq)
1016 {
1017   current_radiostack->set_nav2_freq(freq);
1018 }
1019
1020 void
1021 FGBFI::setNAV2AltFreq (double freq)
1022 {
1023   current_radiostack->set_nav2_alt_freq(freq);
1024 }
1025
1026 void
1027 FGBFI::setNAV2SelRadial (double radial)
1028 {
1029   current_radiostack->set_nav2_sel_radial(radial);
1030 }
1031
1032 void
1033 FGBFI::setADFFreq (double freq)
1034 {
1035   current_radiostack->set_adf_freq(freq);
1036 }
1037
1038 void
1039 FGBFI::setADFAltFreq (double freq)
1040 {
1041   current_radiostack->set_adf_alt_freq(freq);
1042 }
1043
1044 void
1045 FGBFI::setADFRotation (double rot)
1046 {
1047   current_radiostack->set_adf_rotation(rot);
1048 }
1049
1050
1051 \f
1052 ////////////////////////////////////////////////////////////////////////
1053 // GPS
1054 ////////////////////////////////////////////////////////////////////////
1055
1056
1057 /**
1058  * Get the autopilot GPS lock (true=on).
1059  */
1060 bool
1061 FGBFI::getGPSLock ()
1062 {
1063   return (current_autopilot->get_HeadingEnabled() &&
1064           (current_autopilot->get_HeadingMode() ==
1065            FGAutopilot::FG_HEADING_WAYPOINT ));
1066 }
1067
1068
1069 /**
1070  * Set the autopilot GPS lock (true=on).
1071  */
1072 void
1073 FGBFI::setGPSLock (bool lock)
1074 {
1075   if (lock) {
1076     current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_WAYPOINT);
1077     current_autopilot->set_HeadingEnabled(true);
1078   } else if (current_autopilot->get_HeadingMode() ==
1079              FGAutopilot::FG_HEADING_WAYPOINT) {
1080     current_autopilot->set_HeadingEnabled(false);
1081   }
1082 }
1083
1084
1085 /**
1086  * Get the GPS target airport code.
1087  */
1088 const string
1089 FGBFI::getTargetAirport ()
1090 {
1091   return current_options.get_airport_id();
1092 }
1093
1094
1095 /**
1096  * Set the GPS target airport code.
1097  */
1098 void
1099 FGBFI::setTargetAirport (const string &airportId)
1100 {
1101   current_options.set_airport_id(airportId);
1102 }
1103
1104
1105 /**
1106  * Get the GPS target latitude in degrees (negative for south).
1107  */
1108 double
1109 FGBFI::getGPSTargetLatitude ()
1110 {
1111     return current_autopilot->get_TargetLatitude();
1112 }
1113
1114
1115 /**
1116  * Set the GPS target latitude in degrees (negative for south).
1117  */
1118 void
1119 FGBFI::setGPSTargetLatitude (double latitude)
1120 {
1121   current_autopilot->set_TargetLatitude( latitude );
1122 }
1123
1124
1125 /**
1126  * Get the GPS target longitude in degrees (negative for west).
1127  */
1128 double
1129 FGBFI::getGPSTargetLongitude ()
1130 {
1131   return current_autopilot->get_TargetLongitude();
1132 }
1133
1134
1135 /**
1136  * Set the GPS target longitude in degrees (negative for west).
1137  */
1138 void
1139 FGBFI::setGPSTargetLongitude (double longitude)
1140 {
1141   current_autopilot->set_TargetLongitude( longitude );
1142 }
1143
1144
1145 \f
1146 ////////////////////////////////////////////////////////////////////////
1147 // Weather
1148 ////////////////////////////////////////////////////////////////////////
1149
1150
1151 /**
1152  * Get the current visible (units??).
1153  */
1154 double
1155 FGBFI::getVisibility ()
1156 {
1157 #ifndef FG_OLD_WEATHER
1158   return WeatherDatabase->getWeatherVisibility();
1159 #else
1160   return current_weather.get_visibility();
1161 #endif
1162 }
1163
1164
1165 /**
1166  * Check whether clouds are enabled.
1167  */
1168 bool
1169 FGBFI::getClouds ()
1170 {
1171   return current_options.get_clouds();
1172 }
1173
1174
1175 /**
1176  * Check the height of the clouds ASL (units?).
1177  */
1178 double
1179 FGBFI::getCloudsASL ()
1180 {
1181   return current_options.get_clouds_asl();
1182 }
1183
1184
1185 /**
1186  * Set the current visibility (units??).
1187  */
1188 void
1189 FGBFI::setVisibility (double visibility)
1190 {
1191 #ifndef FG_OLD_WEATHER
1192   WeatherDatabase->setWeatherVisibility(visibility);
1193 #else
1194   current_weather.set_visibility(visibility);
1195 #endif
1196 }
1197
1198
1199 /**
1200  * Switch clouds on or off.
1201  */
1202 void
1203 FGBFI::setClouds (bool clouds)
1204 {
1205   cout << "Set clouds to " << clouds << endl;
1206   current_options.set_clouds(clouds);
1207   needReinit();
1208 }
1209
1210
1211 /**
1212  * Set the cloud height.
1213  */
1214 void
1215 FGBFI::setCloudsASL (double cloudsASL)
1216 {
1217   current_options.set_clouds_asl(cloudsASL);
1218   needReinit();
1219 }
1220
1221
1222 \f
1223 ////////////////////////////////////////////////////////////////////////
1224 // Time
1225 ////////////////////////////////////////////////////////////////////////
1226
1227 /**
1228  * Return the magnetic variation
1229  */
1230 double
1231 FGBFI::getMagVar ()
1232 {
1233   return FGTime::cur_time_params->getMagVar() * RAD_TO_DEG;
1234 }
1235
1236
1237 /**
1238  * Return the magnetic variation
1239  */
1240 double
1241 FGBFI::getMagDip ()
1242 {
1243   return FGTime::cur_time_params->getMagDip() * RAD_TO_DEG;
1244 }
1245
1246
1247 // end of bfi.cxx
1248