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