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