]> git.mxchange.org Git - flightgear.git/blob - src/Main/bfi.cxx
1. Added src/Main/fgfs.hxx as a standard, top-level include file for
[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 #include "fgfs.hxx"
24
25 #include <simgear/constants.h>
26 #include <simgear/debug/logstream.hxx>
27 #include <simgear/ephemeris/ephemeris.hxx>
28 #include <simgear/math/sg_types.hxx>
29 #include <simgear/misc/props.hxx>
30 #include <simgear/timing/sg_time.hxx>
31
32 #include <Aircraft/aircraft.hxx>
33 #include <FDM/UIUCModel/uiuc_aircraftdir.h>
34 #include <Controls/controls.hxx>
35 #include <Autopilot/newauto.hxx>
36 #include <Scenery/scenery.hxx>
37 #include <Time/light.hxx>
38 #include <Time/event.hxx>
39 #include <Time/sunpos.hxx>
40 #include <Time/tmp.hxx>
41 #include <Cockpit/radiostack.hxx>
42 #include <Cockpit/panel.hxx>
43 #ifndef FG_OLD_WEATHER
44 #  include <WeatherCM/FGLocalWeatherDatabase.h>
45 #else
46 #  include <Weather/weather.hxx>
47 #endif
48
49 #include "globals.hxx"
50 #include "fg_init.hxx"
51 #include "fg_props.hxx"
52
53 FG_USING_NAMESPACE(std);
54
55
56 #include "bfi.hxx"
57
58
59 \f
60 ////////////////////////////////////////////////////////////////////////
61 // Static variables.
62 ////////////////////////////////////////////////////////////////////////
63
64                                 // Yech -- not thread-safe, etc. etc.
65 static bool _needReinit = false;
66 static string _temp;
67
68 static inline void needReinit ()
69 {
70   _needReinit = true;
71 }
72
73
74 /**
75  * Reinitialize FGFS to use the new BFI settings.
76  */
77 static inline void
78 reinit ()
79 {
80                                 // Save the state of everything
81                                 // that's going to get clobbered
82                                 // when we reinit the subsystems.
83
84   FG_LOG(FG_GENERAL, FG_INFO, "Starting BFI reinit");
85
86                                 // TODO: add more AP stuff
87   double elevator = FGBFI::getElevator();
88   double aileron = FGBFI::getAileron();
89   double rudder = FGBFI::getRudder();
90   double throttle = FGBFI::getThrottle();
91   double elevator_trim = FGBFI::getElevatorTrim();
92   double flaps = FGBFI::getFlaps();
93   double brake = FGBFI::getBrakes();
94   bool apHeadingLock = FGBFI::getAPHeadingLock();
95   double apHeadingMag = FGBFI::getAPHeadingMag();
96   bool apAltitudeLock = FGBFI::getAPAltitudeLock();
97   double apAltitude = FGBFI::getAPAltitude();
98   const string &targetAirport = FGBFI::getTargetAirport();
99   bool gpsLock = FGBFI::getGPSLock();
100   // double gpsLatitude = FGBFI::getGPSTargetLatitude();
101   // double gpsLongitude = FGBFI::getGPSTargetLongitude();
102
103   FGBFI::setTargetAirport("");
104
105   fgReInitSubsystems();
106
107                                 // FIXME: this is wrong.
108                                 // All of these are scheduled events,
109                                 // and it should be possible to force
110                                 // them all to run once.
111   fgUpdateSunPos();
112   fgUpdateMoonPos();
113   cur_light_params.Update();
114   fgUpdateLocalTime();
115   fgUpdateWeatherDatabase();
116   fgRadioSearch();
117
118                                 // Restore all of the old states.
119   FGBFI::setElevator(elevator);
120   FGBFI::setAileron(aileron);
121   FGBFI::setRudder(rudder);
122   FGBFI::setThrottle(throttle);
123   FGBFI::setElevatorTrim(elevator_trim);
124   FGBFI::setFlaps(flaps);
125   FGBFI::setBrakes(brake);
126   FGBFI::setAPHeadingLock(apHeadingLock);
127   FGBFI::setAPHeadingMag(apHeadingMag);
128   FGBFI::setAPAltitudeLock(apAltitudeLock);
129   FGBFI::setAPAltitude(apAltitude);
130   FGBFI::setTargetAirport(targetAirport);
131   FGBFI::setGPSLock(gpsLock);
132
133   _needReinit = false;
134
135   FG_LOG(FG_GENERAL, FG_INFO, "Ending BFI reinit");
136 }
137
138 // BEGIN: kludge 2000-12-07
139 // This is a kludge around a LaRCsim problem; see setAltitude()
140 // for details.
141 static int _altitude_countdown = 0;
142 static double _requested_altitude = -9999;
143 static bool _saved_freeze = false;
144 static inline void _check_altitude ()
145 {
146   if (_altitude_countdown > 0) {
147     _altitude_countdown--;
148     if (_altitude_countdown == 0) {
149       current_aircraft.fdm_state->set_Altitude(_requested_altitude);
150       globals->set_freeze(_saved_freeze);
151     }
152   }
153 }
154
155 static int _lighting_countdown = 0;
156 static inline void _check_lighting ()
157 {
158   if (_lighting_countdown > 0) {
159     _lighting_countdown--;
160     if (_lighting_countdown == 0)
161       fgUpdateSkyAndLightingParams();
162   }
163 }
164 // END: kludge
165
166
167 // BEGIN: kludge
168 // Allow the view to be set from two axes (i.e. a joystick hat)
169 // This needs to be in FGViewer itself, somehow.
170 static double axisLong = 0.0;
171 static double axisLat = 0.0;
172
173 static inline void
174 _set_view_from_axes ()
175 {
176                                 // Take no action when hat is centered
177   if (axisLong == 0 && axisLat == 0)
178     return;
179
180   double viewDir = 0;
181
182   if (axisLong < 0) {           // Longitudinal axis forward
183     if (axisLat < 0)
184       viewDir = 45;
185     else if (axisLat > 0)
186       viewDir = 315;
187     else
188       viewDir = 0;
189   } else if (axisLong > 0) {    // Longitudinal axis backward
190     if (axisLat < 0)
191       viewDir = 135;
192     else if (axisLat > 0)
193       viewDir = 225;
194     else
195       viewDir = 180;
196   } else {                      // Longitudinal axis neutral
197     if (axisLat < 0)
198       viewDir = 90;
199     else
200       viewDir = 270;
201   }
202
203   globals->get_current_view()->set_goal_view_offset(viewDir*DEG_TO_RAD);
204 //   globals->get_current_view()->set_view_offset(viewDir*DEG_TO_RAD);
205 }
206
207 // END: kludge
208
209
210 \f
211 ////////////////////////////////////////////////////////////////////////
212 // Local functions
213 ////////////////////////////////////////////////////////////////////////
214
215 /**
216  * Initialize the BFI by binding its functions to properties.
217  *
218  * TODO: perhaps these should migrate into the individual modules
219  * (i.e. they should register themselves).
220  */
221 void
222 FGBFI::init ()
223 {
224   FG_LOG(FG_GENERAL, FG_INFO, "Starting BFI init");
225                                 // Simulation
226   fgTie("/sim/flight-model", getFlightModel, setFlightModel);
227   fgTie("/sim/aircraft", getAircraft, setAircraft);
228   fgTie("/sim/aircraft-dir", getAircraftDir, setAircraftDir);
229   fgTie("/sim/time/gmt", getDateString, setDateString);
230   fgTie("/sim/time/gmt-string", getGMTString);
231   fgTie("/sim/hud/visibility", getHUDVisible, setHUDVisible);
232   fgTie("/sim/panel/visibility", getPanelVisible, setPanelVisible);
233   fgTie("/sim/panel/x-offset", getPanelXOffset, setPanelXOffset);
234   fgTie("/sim/panel/y-offset", getPanelYOffset, setPanelYOffset);
235
236                                 // Position
237   fgTie("/position/airport-id", getTargetAirport, setTargetAirport);
238   fgTie("/position/latitude", getLatitude, setLatitude);
239   fgTie("/position/longitude", getLongitude, setLongitude);
240   fgTie("/position/altitude", getAltitude, setAltitude);
241   fgTie("/position/altitude-agl", getAGL);
242
243                                 // Orientation
244   fgTie("/orientation/heading", getHeading, setHeading);
245   fgTie("/orientation/heading-magnetic", getHeadingMag);
246   fgTie("/orientation/pitch", getPitch, setPitch);
247   fgTie("/orientation/roll", getRoll, setRoll);
248
249                                 // Engine
250   fgTie("/engines/engine0/rpm", getRPM);
251   fgTie("/engines/engine0/egt", getEGT);
252   fgTie("/engines/engine0/cht", getCHT);
253   fgTie("/engines/engine0/mp", getMP);
254
255                                 // Velocities
256   fgTie("/velocities/airspeed", getAirspeed, setAirspeed);
257   fgTie("/velocities/side-slip", getSideSlip);
258   fgTie("/velocities/vertical-speed", getVerticalSpeed);
259   fgTie("/velocities/speed-north", getSpeedNorth);
260   fgTie("/velocities/speed-east", getSpeedEast);
261   fgTie("/velocities/speed-down", getSpeedDown);
262
263                                 // Controls
264 #if 0
265   fgTie("/controls/throttle", getThrottle, setThrottle);
266   fgTie("/controls/mixture", getMixture, setMixture);
267   fgTie("/controls/propellor-pitch", getPropAdvance, setPropAdvance);
268   fgTie("/controls/flaps", getFlaps, setFlaps);
269   fgTie("/controls/aileron", getAileron, setAileron);
270   fgTie("/controls/rudder", getRudder, setRudder);
271   fgTie("/controls/elevator", getElevator, setElevator);
272   fgTie("/controls/elevator-trim", getElevatorTrim, setElevatorTrim);
273   fgTie("/controls/brakes/all", getBrakes, setBrakes);
274   fgTie("/controls/brakes/left", getLeftBrake, setLeftBrake);
275   fgTie("/controls/brakes/right", getRightBrake, setRightBrake);
276   fgTie("/controls/brakes/center", getRightBrake, setCenterBrake);
277 #endif
278
279                                 // Autopilot
280   fgTie("/autopilot/locks/altitude", getAPAltitudeLock, setAPAltitudeLock);
281   fgTie("/autopilot/settings/altitude", getAPAltitude, setAPAltitude);
282   fgTie("/autopilot/locks/heading", getAPHeadingLock, setAPHeadingLock);
283   fgTie("/autopilot/settings/heading", getAPHeading, setAPHeading);
284   fgTie("/autopilot/settings/heading-magnetic",
285              getAPHeadingMag, setAPHeadingMag);
286   fgTie("/autopilot/locks/nav1", getAPNAV1Lock, setAPNAV1Lock);
287
288                                 // Radio navigation
289   fgTie("/radios/nav1/frequencies/selected", getNAV1Freq, setNAV1Freq);
290   fgTie("/radios/nav1/frequencies/standby", getNAV1AltFreq, setNAV1AltFreq);
291   fgTie("/radios/nav1/radials/actual", getNAV1Radial);
292   fgTie("/radios/nav1/radials/selected",
293              getNAV1SelRadial, setNAV1SelRadial);
294   fgTie("/radios/nav1/dme/distance", getNAV1DistDME);
295   fgTie("/radios/nav1/to-flag", getNAV1TO);
296   fgTie("/radios/nav1/from-flag", getNAV1FROM);
297   fgTie("/radios/nav1/in-range", getNAV1InRange);
298   fgTie("/radios/nav1/dme/in-range", getNAV1DMEInRange);
299                                
300   fgTie("/radios/nav2/frequencies/selected", getNAV2Freq, setNAV2Freq);
301   fgTie("/radios/nav2/frequencies/standby",
302              getNAV2AltFreq, setNAV2AltFreq);
303   fgTie("/radios/nav2/radials/actual", getNAV2Radial);
304   fgTie("/radios/nav2/radials/selected",
305              getNAV2SelRadial, setNAV2SelRadial);
306   fgTie("/radios/nav2/dme/distance", getNAV2DistDME);
307   fgTie("/radios/nav2/to-flag", getNAV2TO);
308   fgTie("/radios/nav2/from-flag", getNAV2FROM);
309   fgTie("/radios/nav2/in-range", getNAV2InRange);
310   fgTie("/radios/nav2/dme/in-range", getNAV2DMEInRange);
311
312   fgTie("/radios/adf/frequencies/selected", getADFFreq, setADFFreq);
313   fgTie("/radios/adf/frequencies/standby", getADFAltFreq, setADFAltFreq);
314   fgTie("/radios/adf/rotation", getADFRotation, setADFRotation);
315
316                                 // Weather
317   fgTie("/environment/visibility", getVisibility, setVisibility);
318   fgTie("/environment/wind-north", getWindNorth);
319   fgTie("/environment/wind-east", getWindEast);
320   fgTie("/environment/wind-down", getWindDown);
321
322                                 // View
323   fgTie("/sim/view/axes/long", (double(*)())0, setViewAxisLong);
324   fgTie("/sim/view/axes/lat", (double(*)())0, setViewAxisLat);
325
326   _needReinit = false;
327
328   FG_LOG(FG_GENERAL, FG_INFO, "Ending BFI init");
329 }
330
331
332 /**
333  * Reinitialize FGFS if required.
334  *
335  * Some changes (especially those in aircraft position) require that
336  * FGFS be reinitialized afterwards.  Rather than reinitialize after
337  * every change, the setter methods simply set a flag so that there
338  * can be a single reinit at the end of the frame.
339  */
340 void
341 FGBFI::update ()
342 {
343   _check_altitude();
344   _check_lighting();
345   _set_view_from_axes();
346   if (_needReinit) {
347     reinit();
348   }
349 }
350
351
352 \f
353 ////////////////////////////////////////////////////////////////////////
354 // Simulation.
355 ////////////////////////////////////////////////////////////////////////
356
357
358 /**
359  * Return the flight model as an integer.
360  *
361  * TODO: use a string instead.
362  */
363 int
364 FGBFI::getFlightModel ()
365 {
366   return globals->get_options()->get_flight_model();
367 }
368
369
370 /**
371  * Return the current aircraft as a string.
372  */
373 string
374 FGBFI::getAircraft ()
375 {
376   _temp = globals->get_options()->get_aircraft();
377   return _temp;
378 }
379
380
381 /**
382  * Return the current aircraft directory (UIUC) as a string.
383  */
384 string 
385 FGBFI::getAircraftDir ()
386 {
387   _temp = aircraft_dir;
388   return _temp;
389 }
390
391
392 /**
393  * Set the flight model as an integer.
394  *
395  * TODO: use a string instead.
396  */
397 void
398 FGBFI::setFlightModel (int model)
399 {
400   if (getFlightModel() != model) {
401     globals->get_options()->set_flight_model(model);
402     needReinit();
403   }
404 }
405
406
407 /**
408  * Set the current aircraft.
409  */
410 void
411 FGBFI::setAircraft (string aircraft)
412 {
413   if (getAircraft() != aircraft) {
414     globals->get_options()->set_aircraft(aircraft);
415     needReinit();
416   }
417 }
418
419
420 /**
421  * Set the current aircraft directory (UIUC).
422  */
423 void
424 FGBFI::setAircraftDir (string dir)
425 {
426   if (getAircraftDir() != dir) {
427     aircraft_dir = dir;
428     needReinit();
429   }
430 }
431
432
433 /**
434  * Return the current Zulu time.
435  */
436 string 
437 FGBFI::getDateString ()
438 {
439   string out;
440   char buf[64];
441   struct tm * t = globals->get_time_params()->getGmt();
442   sprintf(buf, "%.4d-%.2d-%.2dT%.2d:%.2d:%.2d",
443           t->tm_year + 1900, t->tm_mon + 1, t->tm_mday,
444           t->tm_hour, t->tm_min, t->tm_sec);
445   out = buf;
446   return out;
447 }
448
449
450 /**
451  * Set the current Zulu time.
452  */
453 void
454 FGBFI::setDateString (string date_string)
455 // FGBFI::setTimeGMT (time_t time)
456 {
457   SGTime * st = globals->get_time_params();
458   struct tm * current_time = st->getGmt();
459   struct tm new_time;
460
461                                 // Scan for basic ISO format
462                                 // YYYY-MM-DDTHH:MM:SS
463   int ret = sscanf(date_string.c_str(), "%d-%d-%dT%d:%d:%d",
464                    &(new_time.tm_year), &(new_time.tm_mon),
465                    &(new_time.tm_mday), &(new_time.tm_hour),
466                    &(new_time.tm_min), &(new_time.tm_sec));
467
468                                 // Be pretty picky about this, so
469                                 // that strange things don't happen
470                                 // if the save file has been edited
471                                 // by hand.
472   if (ret != 6) {
473     FG_LOG(FG_INPUT, FG_ALERT, "Date/time string " << date_string
474            << " not in YYYY-MM-DDTHH:MM:SS format; skipped");
475     return;
476   }
477
478                                 // OK, it looks like we got six
479                                 // values, one way or another.
480   new_time.tm_year -= 1900;
481   new_time.tm_mon -= 1;
482
483                                 // Now, tell flight gear to use
484                                 // the new time.  This was far
485                                 // too difficult, by the way.
486   long int warp =
487     mktime(&new_time) - mktime(current_time) + globals->get_warp();
488   double lon = current_aircraft.fdm_state->get_Longitude();
489   double lat = current_aircraft.fdm_state->get_Latitude();
490   double alt = current_aircraft.fdm_state->get_Altitude() * FEET_TO_METER;
491   globals->set_warp(warp);
492   st->update(lon, lat, warp);
493   fgUpdateSkyAndLightingParams();
494 }
495
496
497 /**
498  * Return the GMT as a string.
499  */
500 string 
501 FGBFI::getGMTString ()
502 {
503   string out;
504   char buf[16];
505   struct tm * t = globals->get_time_params()->getGmt();
506   sprintf(buf, " %.2d:%.2d:%.2d",
507           t->tm_hour, t->tm_min, t->tm_sec);
508   out = buf;
509   return out;
510 }
511
512
513 /**
514  * Return true if the HUD is visible.
515  */
516 bool
517 FGBFI::getHUDVisible ()
518 {
519   return globals->get_options()->get_hud_status();
520 }
521
522
523 /**
524  * Ensure that the HUD is visible or hidden.
525  */
526 void
527 FGBFI::setHUDVisible (bool visible)
528 {
529   globals->get_options()->set_hud_status(visible);
530 }
531
532
533 /**
534  * Return true if the 2D panel is visible.
535  */
536 bool
537 FGBFI::getPanelVisible ()
538 {
539   return globals->get_options()->get_panel_status();
540 }
541
542
543 /**
544  * Ensure that the 2D panel is visible or hidden.
545  */
546 void
547 FGBFI::setPanelVisible (bool visible)
548 {
549   if (globals->get_options()->get_panel_status() != visible) {
550     globals->get_options()->toggle_panel();
551   }
552 }
553
554
555 /**
556  * Get the panel's current x-shift.
557  */
558 int
559 FGBFI::getPanelXOffset ()
560 {
561   if (current_panel != 0)
562     return current_panel->getXOffset();
563   else
564     return 0;
565 }
566
567
568 /**
569  * Set the panel's current x-shift.
570  */
571 void
572 FGBFI::setPanelXOffset (int offset)
573 {
574   if (current_panel != 0)
575     current_panel->setXOffset(offset);
576 }
577
578
579 /**
580  * Get the panel's current y-shift.
581  */
582 int
583 FGBFI::getPanelYOffset ()
584 {
585   if (current_panel != 0)
586     return current_panel->getYOffset();
587   else
588     return 0;
589 }
590
591
592 /**
593  * Set the panel's current y-shift.
594  */
595 void
596 FGBFI::setPanelYOffset (int offset)
597 {
598   if (current_panel != 0)
599     current_panel->setYOffset(offset);
600 }
601
602
603
604
605 \f
606 ////////////////////////////////////////////////////////////////////////
607 // Position
608 ////////////////////////////////////////////////////////////////////////
609
610
611 /**
612  * Return the current latitude in degrees (negative for south).
613  */
614 double
615 FGBFI::getLatitude ()
616 {
617   return current_aircraft.fdm_state->get_Latitude() * RAD_TO_DEG;
618 }
619
620
621 /**
622  * Set the current latitude in degrees (negative for south).
623  */
624 void
625 FGBFI::setLatitude (double latitude)
626 {
627   current_aircraft.fdm_state->set_Latitude(latitude * DEG_TO_RAD);
628   fgUpdateSkyAndLightingParams();
629   if (_lighting_countdown <= 0)
630     _lighting_countdown = 5;
631 }
632
633
634 /**
635  * Return the current longitude in degrees (negative for west).
636  */
637 double
638 FGBFI::getLongitude ()
639 {
640   return current_aircraft.fdm_state->get_Longitude() * RAD_TO_DEG;
641 }
642
643
644 /**
645  * Set the current longitude in degrees (negative for west).
646  */
647 void
648 FGBFI::setLongitude (double longitude)
649 {
650   current_aircraft.fdm_state->set_Longitude(longitude * DEG_TO_RAD);
651   fgUpdateSkyAndLightingParams();
652   if (_lighting_countdown <= 0)
653     _lighting_countdown = 5;
654 }
655
656
657 /**
658  * Return the current altitude in feet.
659  */
660 double
661 FGBFI::getAltitude ()
662 {
663   return current_aircraft.fdm_state->get_Altitude();
664 }
665
666
667
668 /**
669  * Return the current altitude in above the terrain.
670  */
671 double
672 FGBFI::getAGL ()
673 {
674   return current_aircraft.fdm_state->get_Altitude()
675          - (scenery.cur_elev * METER_TO_FEET);
676 }
677
678
679 /**
680  * Set the current altitude in feet.
681  */
682 void
683 FGBFI::setAltitude (double altitude)
684 {
685   current_aircraft.fdm_state->set_Altitude(altitude);
686
687                                 // 2000-12-07
688                                 // This is an ugly kludge around a
689                                 // LaRCsim problem; if the
690                                 // requested altitude cannot be
691                                 // set right away (because it's
692                                 // below the last-calculated ground
693                                 // level), pause FGFS, wait for
694                                 // five frames, and then try again.
695   if (_altitude_countdown <= 0 &&
696       fabs(getAltitude() - altitude) > 5.0) {
697     _altitude_countdown = 5;
698     _requested_altitude = altitude;
699     _saved_freeze = globals->get_freeze();
700     globals->set_freeze(true);
701   }
702 }
703
704
705 \f
706 ////////////////////////////////////////////////////////////////////////
707 // Attitude
708 ////////////////////////////////////////////////////////////////////////
709
710
711 /**
712  * Return the current heading in degrees.
713  */
714 double
715 FGBFI::getHeading ()
716 {
717   return current_aircraft.fdm_state->get_Psi() * RAD_TO_DEG;
718 }
719
720
721 /**
722  * Return the current heading in degrees.
723  */
724 double
725 FGBFI::getHeadingMag ()
726 {
727   return current_aircraft.fdm_state->get_Psi() * RAD_TO_DEG - getMagVar();
728 }
729
730
731 /**
732  * Set the current heading in degrees.
733  */
734 void
735 FGBFI::setHeading (double heading)
736 {
737   FGInterface * fdm = current_aircraft.fdm_state;
738   fdm->set_Euler_Angles(fdm->get_Phi(), fdm->get_Theta(),
739                         heading * DEG_TO_RAD);
740 }
741
742
743 /**
744  * Return the current pitch in degrees.
745  */
746 double
747 FGBFI::getPitch ()
748 {
749   return current_aircraft.fdm_state->get_Theta() * RAD_TO_DEG;
750 }
751
752
753 /**
754  * Set the current pitch in degrees.
755  */
756 void
757 FGBFI::setPitch (double pitch)
758 {
759   FGInterface * fdm = current_aircraft.fdm_state;
760   fdm->set_Euler_Angles(fdm->get_Phi(), pitch * DEG_TO_RAD, fdm->get_Psi());
761 }
762
763
764 /**
765  * Return the current roll in degrees.
766  */
767 double
768 FGBFI::getRoll ()
769 {
770   return current_aircraft.fdm_state->get_Phi() * RAD_TO_DEG;
771 }
772
773
774 /**
775  * Set the current roll in degrees.
776  */
777 void
778 FGBFI::setRoll (double roll)
779 {
780   FGInterface * fdm = current_aircraft.fdm_state;
781   fdm->set_Euler_Angles(roll * DEG_TO_RAD, fdm->get_Theta(), fdm->get_Psi());
782 }
783
784
785 /**
786  * Return the current engine0 rpm
787  */
788 double
789 FGBFI::getRPM ()
790 {
791   if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
792       return current_aircraft.fdm_state->get_engine(0)->get_RPM();
793   } else {
794       return 0.0;
795   }
796 }
797
798
799 /**
800  * Set the current engine0 rpm
801  */
802 void
803 FGBFI::setRPM (double rpm)
804 {
805     if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
806         if (getRPM() != rpm) {
807             current_aircraft.fdm_state->get_engine(0)->set_RPM( rpm );
808         }
809     }
810 }
811
812
813 /**
814  * Return the current engine0 EGT.
815  */
816 double
817 FGBFI::getEGT ()
818 {
819   if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
820       return current_aircraft.fdm_state->get_engine(0)->get_EGT();
821   } else {
822       return 0.0;
823   }
824 }
825
826
827 /**
828  * Return the current engine0 CHT.
829  */
830 double
831 FGBFI::getCHT ()
832 {
833   if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
834       return current_aircraft.fdm_state->get_engine(0)->get_CHT();
835   } else {
836       return 0.0;
837   }
838 }
839
840
841 /**
842  * Return the current engine0 CHT.
843  */
844 double
845 FGBFI::getMP ()
846 {
847   if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
848       return current_aircraft.fdm_state->get_engine(0)->get_Manifold_Pressure();
849   } else {
850       return 0.0;
851   }
852 }
853
854
855 \f
856 ////////////////////////////////////////////////////////////////////////
857 // Velocities
858 ////////////////////////////////////////////////////////////////////////
859
860
861 /**
862  * Return the current airspeed in knots.
863  */
864 double
865 FGBFI::getAirspeed ()
866 {
867                                 // FIXME: should we add speed-up?
868   return current_aircraft.fdm_state->get_V_calibrated_kts();
869 }
870
871
872 /**
873  * Set the calibrated airspeed in knots.
874  */
875 void
876 FGBFI::setAirspeed (double speed)
877 {
878   current_aircraft.fdm_state->set_V_calibrated_kts(speed);
879 }
880
881
882 /**
883  * Return the current sideslip (FIXME: units unknown).
884  */
885 double
886 FGBFI::getSideSlip ()
887 {
888   return current_aircraft.fdm_state->get_Beta();
889 }
890
891
892 /**
893  * Return the current climb rate in feet/minute
894  */
895 double
896 FGBFI::getVerticalSpeed ()
897 {
898                                 // What about meters?
899   return current_aircraft.fdm_state->get_Climb_Rate() * 60.0;
900 }
901
902
903 /**
904  * Get the current north velocity (units??).
905  */
906 double
907 FGBFI::getSpeedNorth ()
908 {
909   return current_aircraft.fdm_state->get_V_north();
910 }
911
912
913 // /**
914 //  * Set the current north velocity (units??).
915 //  */
916 // void
917 // FGBFI::setSpeedNorth (double speed)
918 // {
919 //   FGInterface * fdm = current_aircraft.fdm_state;
920 // //   fdm->set_Velocities_Local(speed, fdm->get_V_east(), fdm->get_V_down());
921 // }
922
923
924 /**
925  * Get the current east velocity (units??).
926  */
927 double
928 FGBFI::getSpeedEast ()
929 {
930   return current_aircraft.fdm_state->get_V_east();
931 }
932
933
934 // /**
935 //  * Set the current east velocity (units??).
936 //  */
937 // void
938 // FGBFI::setSpeedEast (double speed)
939 // {
940 //   FGInterface * fdm = current_aircraft.fdm_state;
941 // //   fdm->set_Velocities_Local(fdm->get_V_north(), speed, fdm->get_V_down());
942 // }
943
944
945 /**
946  * Get the current down velocity (units??).
947  */
948 double
949 FGBFI::getSpeedDown ()
950 {
951   return current_aircraft.fdm_state->get_V_down();
952 }
953
954
955 // /**
956 //  * Set the current down velocity (units??).
957 //  */
958 // void
959 // FGBFI::setSpeedDown (double speed)
960 // {
961 //   FGInterface * fdm = current_aircraft.fdm_state;
962 // //   fdm->set_Velocities_Local(fdm->get_V_north(), fdm->get_V_east(), speed);
963 // }
964
965
966 \f
967 ////////////////////////////////////////////////////////////////////////
968 // Controls
969 ////////////////////////////////////////////////////////////////////////
970
971
972 /**
973  * Get the throttle setting, from 0.0 (none) to 1.0 (full).
974  */
975 double
976 FGBFI::getThrottle ()
977 {
978                                 // FIXME: add engine selector
979   return controls.get_throttle(0);
980 }
981
982
983 /**
984  * Set the throttle, from 0.0 (none) to 1.0 (full).
985  */
986 void
987 FGBFI::setThrottle (double throttle)
988 {
989                                 // FIXME: allow engine selection
990   controls.set_throttle(0, throttle);
991 }
992
993
994 /**
995  * Get the fuel mixture setting, from 0.0 (none) to 1.0 (full).
996  */
997 double
998 FGBFI::getMixture ()
999 {
1000                                 // FIXME: add engine selector
1001   return controls.get_mixture(0);
1002 }
1003
1004
1005 /**
1006  * Set the fuel mixture, from 0.0 (none) to 1.0 (full).
1007  */
1008 void
1009 FGBFI::setMixture (double mixture)
1010 {
1011                                 // FIXME: allow engine selection
1012   controls.set_mixture(0, mixture);
1013 }
1014
1015
1016 /**
1017  * Get the propellor pitch setting, from 0.0 (none) to 1.0 (full).
1018  */
1019 double
1020 FGBFI::getPropAdvance ()
1021 {
1022                                 // FIXME: add engine selector
1023   return controls.get_prop_advance(0);
1024 }
1025
1026
1027 /**
1028  * Set the propellor pitch, from 0.0 (none) to 1.0 (full).
1029  */
1030 void
1031 FGBFI::setPropAdvance (double pitch)
1032 {
1033                                 // FIXME: allow engine selection
1034   controls.set_prop_advance(0, pitch);
1035 }
1036
1037
1038 /**
1039  * Get the flaps setting, from 0.0 (none) to 1.0 (full).
1040  */
1041 double
1042 FGBFI::getFlaps ()
1043 {
1044   return controls.get_flaps();
1045 }
1046
1047
1048 /**
1049  * Set the flaps, from 0.0 (none) to 1.0 (full).
1050  */
1051 void
1052 FGBFI::setFlaps (double flaps)
1053 {
1054                                 // FIXME: clamp?
1055   controls.set_flaps(flaps);
1056 }
1057
1058
1059 /**
1060  * Get the aileron, from -1.0 (left) to 1.0 (right).
1061  */
1062 double
1063 FGBFI::getAileron ()
1064 {
1065   return controls.get_aileron();
1066 }
1067
1068
1069 /**
1070  * Set the aileron, from -1.0 (left) to 1.0 (right).
1071  */
1072 void
1073 FGBFI::setAileron (double aileron)
1074 {
1075                                 // FIXME: clamp?
1076   controls.set_aileron(aileron);
1077 }
1078
1079
1080 /**
1081  * Get the rudder setting, from -1.0 (left) to 1.0 (right).
1082  */
1083 double
1084 FGBFI::getRudder ()
1085 {
1086   return controls.get_rudder();
1087 }
1088
1089
1090 /**
1091  * Set the rudder, from -1.0 (left) to 1.0 (right).
1092  */
1093 void
1094 FGBFI::setRudder (double rudder)
1095 {
1096                                 // FIXME: clamp?
1097   controls.set_rudder(rudder);
1098 }
1099
1100
1101 /**
1102  * Get the elevator setting, from -1.0 (down) to 1.0 (up).
1103  */
1104 double
1105 FGBFI::getElevator ()
1106 {
1107   return controls.get_elevator();
1108 }
1109
1110
1111 /**
1112  * Set the elevator, from -1.0 (down) to 1.0 (up).
1113  */
1114 void
1115 FGBFI::setElevator (double elevator)
1116 {
1117                                 // FIXME: clamp?
1118   controls.set_elevator(elevator);
1119 }
1120
1121
1122 /**
1123  * Get the elevator trim, from -1.0 (down) to 1.0 (up).
1124  */
1125 double
1126 FGBFI::getElevatorTrim ()
1127 {
1128   return controls.get_elevator_trim();
1129 }
1130
1131
1132 /**
1133  * Set the elevator trim, from -1.0 (down) to 1.0 (up).
1134  */
1135 void
1136 FGBFI::setElevatorTrim (double trim)
1137 {
1138                                 // FIXME: clamp?
1139   controls.set_elevator_trim(trim);
1140 }
1141
1142
1143 /**
1144  * Get the highest brake setting, from 0.0 (none) to 1.0 (full).
1145  */
1146 double
1147 FGBFI::getBrakes ()
1148 {
1149   double b1 = getCenterBrake();
1150   double b2 = getLeftBrake();
1151   double b3 = getRightBrake();
1152   return (b1 > b2 ? (b1 > b3 ? b1 : b3) : (b2 > b3 ? b2 : b3));
1153 }
1154
1155
1156 /**
1157  * Set all brakes, from 0.0 (none) to 1.0 (full).
1158  */
1159 void
1160 FGBFI::setBrakes (double brake)
1161 {
1162   setCenterBrake(brake);
1163   setLeftBrake(brake);
1164   setRightBrake(brake);
1165 }
1166
1167
1168 /**
1169  * Get the center brake, from 0.0 (none) to 1.0 (full).
1170  */
1171 double
1172 FGBFI::getCenterBrake ()
1173 {
1174   return controls.get_brake(2);
1175 }
1176
1177
1178 /**
1179  * Set the center brake, from 0.0 (none) to 1.0 (full).
1180  */
1181 void
1182 FGBFI::setCenterBrake (double brake)
1183 {
1184   controls.set_brake(2, brake);
1185 }
1186
1187
1188 /**
1189  * Get the left brake, from 0.0 (none) to 1.0 (full).
1190  */
1191 double
1192 FGBFI::getLeftBrake ()
1193 {
1194   return controls.get_brake(0);
1195 }
1196
1197
1198 /**
1199  * Set the left brake, from 0.0 (none) to 1.0 (full).
1200  */
1201 void
1202 FGBFI::setLeftBrake (double brake)
1203 {
1204   controls.set_brake(0, brake);
1205 }
1206
1207
1208 /**
1209  * Get the right brake, from 0.0 (none) to 1.0 (full).
1210  */
1211 double
1212 FGBFI::getRightBrake ()
1213 {
1214   return controls.get_brake(1);
1215 }
1216
1217
1218 /**
1219  * Set the right brake, from 0.0 (none) to 1.0 (full).
1220  */
1221 void
1222 FGBFI::setRightBrake (double brake)
1223 {
1224   controls.set_brake(1, brake);
1225 }
1226
1227
1228
1229
1230 \f
1231 ////////////////////////////////////////////////////////////////////////
1232 // Autopilot
1233 ////////////////////////////////////////////////////////////////////////
1234
1235
1236 /**
1237  * Get the autopilot altitude lock (true=on).
1238  */
1239 bool
1240 FGBFI::getAPAltitudeLock ()
1241 {
1242     return current_autopilot->get_AltitudeEnabled();
1243 }
1244
1245
1246 /**
1247  * Set the autopilot altitude lock (true=on).
1248  */
1249 void
1250 FGBFI::setAPAltitudeLock (bool lock)
1251 {
1252   current_autopilot->set_AltitudeMode(FGAutopilot::FG_ALTITUDE_LOCK);
1253   current_autopilot->set_AltitudeEnabled(lock);
1254 }
1255
1256
1257 /**
1258  * Get the autopilot target altitude in feet.
1259  */
1260 double
1261 FGBFI::getAPAltitude ()
1262 {
1263   return current_autopilot->get_TargetAltitude() * METER_TO_FEET;
1264 }
1265
1266
1267 /**
1268  * Set the autopilot target altitude in feet.
1269  */
1270 void
1271 FGBFI::setAPAltitude (double altitude)
1272 {
1273     current_autopilot->set_TargetAltitude( altitude );
1274 }
1275
1276
1277 /**
1278  * Get the autopilot heading lock (true=on).
1279  */
1280 bool
1281 FGBFI::getAPHeadingLock ()
1282 {
1283     return
1284       (current_autopilot->get_HeadingEnabled() &&
1285        current_autopilot->get_HeadingMode() == FGAutopilot::FG_HEADING_LOCK);
1286 }
1287
1288
1289 /**
1290  * Set the autopilot heading lock (true=on).
1291  */
1292 void
1293 FGBFI::setAPHeadingLock (bool lock)
1294 {
1295   if (lock) {
1296                                 // We need to do this so that
1297                                 // it's possible to lock onto a
1298                                 // heading other than the current
1299                                 // heading.
1300     double heading = getAPHeadingMag();
1301     current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_LOCK);
1302     current_autopilot->set_HeadingEnabled(true);
1303     setAPHeadingMag(heading);
1304   } else if (current_autopilot->get_HeadingMode() ==
1305              FGAutopilot::FG_HEADING_LOCK) {
1306     current_autopilot->set_HeadingEnabled(false);
1307   }
1308 }
1309
1310
1311 /**
1312  * Get the autopilot target heading in degrees.
1313  */
1314 double
1315 FGBFI::getAPHeading ()
1316 {
1317   return current_autopilot->get_TargetHeading();
1318 }
1319
1320
1321 /**
1322  * Set the autopilot target heading in degrees.
1323  */
1324 void
1325 FGBFI::setAPHeading (double heading)
1326 {
1327   current_autopilot->set_TargetHeading( heading );
1328 }
1329
1330
1331 /**
1332  * Get the autopilot target heading in degrees.
1333  */
1334 double
1335 FGBFI::getAPHeadingMag ()
1336 {
1337   return current_autopilot->get_TargetHeading() - getMagVar();
1338 }
1339
1340
1341 /**
1342  * Set the autopilot target heading in degrees.
1343  */
1344 void
1345 FGBFI::setAPHeadingMag (double heading)
1346 {
1347   current_autopilot->set_TargetHeading( heading + getMagVar() );
1348 }
1349
1350
1351 /**
1352  * Return true if the autopilot is locked to NAV1.
1353  */
1354 bool
1355 FGBFI::getAPNAV1Lock ()
1356 {
1357   return
1358     (current_autopilot->get_HeadingEnabled() &&
1359      current_autopilot->get_HeadingMode() == FGAutopilot::FG_HEADING_NAV1);
1360 }
1361
1362
1363 /**
1364  * Set the autopilot NAV1 lock.
1365  */
1366 void
1367 FGBFI::setAPNAV1Lock (bool lock)
1368 {
1369   if (lock) {
1370     current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_NAV1);
1371     current_autopilot->set_HeadingEnabled(true);
1372   } else if (current_autopilot->get_HeadingMode() ==
1373              FGAutopilot::FG_HEADING_NAV1) {
1374     current_autopilot->set_HeadingEnabled(false);
1375   }
1376 }
1377
1378
1379 \f
1380 ////////////////////////////////////////////////////////////////////////
1381 // Radio navigation.
1382 ////////////////////////////////////////////////////////////////////////
1383
1384 double
1385 FGBFI::getNAV1Freq ()
1386 {
1387   return current_radiostack->get_nav1_freq();
1388 }
1389
1390 double
1391 FGBFI::getNAV1AltFreq ()
1392 {
1393   return current_radiostack->get_nav1_alt_freq();
1394 }
1395
1396 double
1397 FGBFI::getNAV1Radial ()
1398 {
1399   return current_radiostack->get_nav1_radial();
1400 }
1401
1402 double
1403 FGBFI::getNAV1SelRadial ()
1404 {
1405   return current_radiostack->get_nav1_sel_radial();
1406 }
1407
1408 double
1409 FGBFI::getNAV1DistDME ()
1410 {
1411   return current_radiostack->get_nav1_dme_dist();
1412 }
1413
1414 bool 
1415 FGBFI::getNAV1TO ()
1416 {
1417   if (current_radiostack->get_nav1_inrange()) {
1418     double heading = current_radiostack->get_nav1_heading();
1419     double radial = current_radiostack->get_nav1_radial();
1420 //     double var = FGBFI::getMagVar();
1421     if (current_radiostack->get_nav1_loc()) {
1422       double offset = fabs(heading - radial);
1423       return (offset<= 8.0 || offset >= 352.0);
1424     } else {
1425 //       double offset =
1426 //      fabs(heading - var - radial);
1427       double offset = fabs(heading - radial);
1428       return (offset <= 20.0 || offset >= 340.0);
1429     }
1430   } else {
1431     return false;
1432   }
1433 }
1434
1435 bool
1436 FGBFI::getNAV1FROM ()
1437 {
1438   if (current_radiostack->get_nav1_inrange()) {
1439     double heading = current_radiostack->get_nav1_heading();
1440     double radial = current_radiostack->get_nav1_radial();
1441 //     double var = FGBFI::getMagVar();
1442     if (current_radiostack->get_nav1_loc()) {
1443       double offset = fabs(heading - radial);
1444       return (offset >= 172.0 && offset<= 188.0);
1445     } else {
1446 //       double offset =
1447 //      fabs(heading - var - radial);
1448       double offset = fabs(heading - radial);
1449       return (offset >= 160.0 && offset <= 200.0);
1450     }
1451   } else {
1452     return false;
1453   }
1454 }
1455
1456 bool
1457 FGBFI::getNAV1InRange ()
1458 {
1459   return current_radiostack->get_nav1_inrange();
1460 }
1461
1462 bool
1463 FGBFI::getNAV1DMEInRange ()
1464 {
1465   return (current_radiostack->get_nav1_inrange() &&
1466           current_radiostack->get_nav1_has_dme());
1467 }
1468
1469 double
1470 FGBFI::getNAV2Freq ()
1471 {
1472   return current_radiostack->get_nav2_freq();
1473 }
1474
1475 double
1476 FGBFI::getNAV2AltFreq ()
1477 {
1478   return current_radiostack->get_nav2_alt_freq();
1479 }
1480
1481 double
1482 FGBFI::getNAV2Radial ()
1483 {
1484   return current_radiostack->get_nav2_radial();
1485 }
1486
1487 double
1488 FGBFI::getNAV2SelRadial ()
1489 {
1490   return current_radiostack->get_nav2_sel_radial();
1491 }
1492
1493 double
1494 FGBFI::getNAV2DistDME ()
1495 {
1496   return current_radiostack->get_nav2_dme_dist();
1497 }
1498
1499 bool 
1500 FGBFI::getNAV2TO ()
1501 {
1502   if (current_radiostack->get_nav2_inrange()) {
1503     double heading = current_radiostack->get_nav2_heading();
1504     double radial = current_radiostack->get_nav2_radial();
1505 //     double var = FGBFI::getMagVar();
1506     if (current_radiostack->get_nav2_loc()) {
1507       double offset = fabs(heading - radial);
1508       return (offset<= 8.0 || offset >= 352.0);
1509     } else {
1510 //       double offset =
1511 //      fabs(heading - var - radial);
1512       double offset = fabs(heading - radial);
1513       return (offset <= 20.0 || offset >= 340.0);
1514     }
1515   } else {
1516     return false;
1517   }
1518 }
1519
1520 bool 
1521 FGBFI::getNAV2FROM ()
1522 {
1523   if (current_radiostack->get_nav2_inrange()) {
1524     double heading = current_radiostack->get_nav2_heading();
1525     double radial = current_radiostack->get_nav2_radial();
1526 //     double var = FGBFI::getMagVar();
1527     if (current_radiostack->get_nav2_loc()) {
1528       double offset = fabs(heading - radial);
1529       return (offset >= 172.0 && offset<= 188.0);
1530     } else {
1531 //       double offset =
1532 //      fabs(heading - var - radial);
1533       double offset = fabs(heading - radial);
1534       return (offset >= 160.0 && offset <= 200.0);
1535     }
1536   } else {
1537     return false;
1538   }
1539 }
1540
1541
1542 bool
1543 FGBFI::getNAV2InRange ()
1544 {
1545   return current_radiostack->get_nav2_inrange();
1546 }
1547
1548 bool
1549 FGBFI::getNAV2DMEInRange ()
1550 {
1551   return (current_radiostack->get_nav2_inrange() &&
1552           current_radiostack->get_nav2_has_dme());
1553 }
1554
1555 double
1556 FGBFI::getADFFreq ()
1557 {
1558   return current_radiostack->get_adf_freq();
1559 }
1560
1561 double
1562 FGBFI::getADFAltFreq ()
1563 {
1564   return current_radiostack->get_adf_alt_freq();
1565 }
1566
1567 double
1568 FGBFI::getADFRotation ()
1569 {
1570   return current_radiostack->get_adf_rotation();
1571 }
1572
1573 void
1574 FGBFI::setNAV1Freq (double freq)
1575 {
1576   current_radiostack->set_nav1_freq(freq);
1577 }
1578
1579 void
1580 FGBFI::setNAV1AltFreq (double freq)
1581 {
1582   current_radiostack->set_nav1_alt_freq(freq);
1583 }
1584
1585 void
1586 FGBFI::setNAV1SelRadial (double radial)
1587 {
1588   current_radiostack->set_nav1_sel_radial(radial);
1589 }
1590
1591 void
1592 FGBFI::setNAV2Freq (double freq)
1593 {
1594   current_radiostack->set_nav2_freq(freq);
1595 }
1596
1597 void
1598 FGBFI::setNAV2AltFreq (double freq)
1599 {
1600   current_radiostack->set_nav2_alt_freq(freq);
1601 }
1602
1603 void
1604 FGBFI::setNAV2SelRadial (double radial)
1605 {
1606   current_radiostack->set_nav2_sel_radial(radial);
1607 }
1608
1609 void
1610 FGBFI::setADFFreq (double freq)
1611 {
1612   current_radiostack->set_adf_freq(freq);
1613 }
1614
1615 void
1616 FGBFI::setADFAltFreq (double freq)
1617 {
1618   current_radiostack->set_adf_alt_freq(freq);
1619 }
1620
1621 void
1622 FGBFI::setADFRotation (double rot)
1623 {
1624   current_radiostack->set_adf_rotation(rot);
1625 }
1626
1627
1628 \f
1629 ////////////////////////////////////////////////////////////////////////
1630 // GPS
1631 ////////////////////////////////////////////////////////////////////////
1632
1633
1634 /**
1635  * Get the autopilot GPS lock (true=on).
1636  */
1637 bool
1638 FGBFI::getGPSLock ()
1639 {
1640   return (current_autopilot->get_HeadingEnabled() &&
1641           (current_autopilot->get_HeadingMode() ==
1642            FGAutopilot::FG_HEADING_WAYPOINT ));
1643 }
1644
1645
1646 /**
1647  * Set the autopilot GPS lock (true=on).
1648  */
1649 void
1650 FGBFI::setGPSLock (bool lock)
1651 {
1652   if (lock) {
1653     current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_WAYPOINT);
1654     current_autopilot->set_HeadingEnabled(true);
1655   } else if (current_autopilot->get_HeadingMode() ==
1656              FGAutopilot::FG_HEADING_WAYPOINT) {
1657     current_autopilot->set_HeadingEnabled(false);
1658   }
1659 }
1660
1661
1662 /**
1663  * Get the GPS target airport code.
1664  */
1665 string 
1666 FGBFI::getTargetAirport ()
1667 {
1668   // FIXME: not thread-safe
1669   static string out;
1670   out = globals->get_options()->get_airport_id();
1671
1672   return out;
1673 }
1674
1675
1676 /**
1677  * Set the GPS target airport code.
1678  */
1679 void
1680 FGBFI::setTargetAirport (string airportId)
1681 {
1682   globals->get_options()->set_airport_id(airportId);
1683 }
1684
1685
1686 /**
1687  * Get the GPS target latitude in degrees (negative for south).
1688  */
1689 double
1690 FGBFI::getGPSTargetLatitude ()
1691 {
1692     return current_autopilot->get_TargetLatitude();
1693 }
1694
1695
1696 /**
1697  * Get the GPS target longitude in degrees (negative for west).
1698  */
1699 double
1700 FGBFI::getGPSTargetLongitude ()
1701 {
1702   return current_autopilot->get_TargetLongitude();
1703 }
1704
1705 #if 0
1706 /**
1707  * Set the GPS target longitude in degrees (negative for west).
1708  */
1709 void
1710 FGBFI::setGPSTargetLongitude (double longitude)
1711 {
1712   current_autopilot->set_TargetLongitude( longitude );
1713 }
1714 #endif
1715
1716
1717 \f
1718 ////////////////////////////////////////////////////////////////////////
1719 // Weather
1720 ////////////////////////////////////////////////////////////////////////
1721
1722
1723 /**
1724  * Get the current visible (units??).
1725  */
1726 double
1727 FGBFI::getVisibility ()
1728 {
1729 #ifndef FG_OLD_WEATHER
1730   return WeatherDatabase->getWeatherVisibility();
1731 #else
1732   return current_weather.get_visibility();
1733 #endif
1734 }
1735
1736
1737 /**
1738  * Set the current visibility (units??).
1739  */
1740 void
1741 FGBFI::setVisibility (double visibility)
1742 {
1743 #ifndef FG_OLD_WEATHER
1744   WeatherDatabase->setWeatherVisibility(visibility);
1745 #else
1746   current_weather.set_visibility(visibility);
1747 #endif
1748 }
1749
1750
1751 /**
1752  * Get the current wind north velocity.
1753  */
1754 double
1755 FGBFI::getWindNorth ()
1756 {
1757   return current_aircraft.fdm_state->get_V_north_airmass();
1758 }
1759
1760
1761 /**
1762  * Get the current wind east velocity.
1763  */
1764 double
1765 FGBFI::getWindEast ()
1766 {
1767   return current_aircraft.fdm_state->get_V_east_airmass();
1768 }
1769
1770
1771 /**
1772  * Get the current wind down velocity.
1773  */
1774 double
1775 FGBFI::getWindDown ()
1776 {
1777   return current_aircraft.fdm_state->get_V_down_airmass();
1778 }
1779
1780
1781 \f
1782 ////////////////////////////////////////////////////////////////////////
1783 // View.
1784 ////////////////////////////////////////////////////////////////////////
1785
1786 void
1787 FGBFI::setViewAxisLong (double axis)
1788 {
1789   axisLong = axis;
1790 }
1791
1792 void
1793 FGBFI::setViewAxisLat (double axis)
1794 {
1795   axisLat = axis;
1796 }
1797
1798 \f
1799 ////////////////////////////////////////////////////////////////////////
1800 // Time
1801 ////////////////////////////////////////////////////////////////////////
1802
1803 /**
1804  * Return the magnetic variation
1805  */
1806 double
1807 FGBFI::getMagVar ()
1808 {
1809   return globals->get_mag()->get_magvar() * RAD_TO_DEG;
1810 }
1811
1812
1813 /**
1814  * Return the magnetic variation
1815  */
1816 double
1817 FGBFI::getMagDip ()
1818 {
1819   return globals->get_mag()->get_magdip() * RAD_TO_DEG;
1820 }
1821
1822
1823 // end of bfi.cxx
1824