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