1 // fg_props.cxx -- support for FlightGear properties.
3 // Written by David Megginson, started 2000.
5 // Copyright (C) 2000, 2001 David Megginson - david@megginson.com
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.
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.
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.
24 # include <simgear/compiler.h>
27 #include <simgear/misc/exception.hxx>
31 #include <ATC/ATCdisplay.hxx>
32 #include <Autopilot/newauto.hxx>
33 #include <Aircraft/aircraft.hxx>
34 #include <Time/tmp.hxx>
35 #include <FDM/UIUCModel/uiuc_aircraftdir.h>
36 #ifndef FG_OLD_WEATHER
37 # include <WeatherCM/FGLocalWeatherDatabase.h>
39 # include <Weather/weather.hxx>
41 #include <Objects/matlib.hxx>
45 #include "globals.hxx"
47 #include "fg_props.hxx"
48 #include "viewmgr.hxx"
50 #if !defined(SG_HAVE_NATIVE_SGI_COMPILERS)
51 SG_USING_STD(istream);
52 SG_USING_STD(ostream);
55 static double getWindNorth ();
56 static double getWindEast ();
57 static double getWindDown ();
59 // Allow the view to be set from two axes (i.e. a joystick hat)
60 // This needs to be in FGViewer itself, somehow.
61 static double axisLong = 0.0;
62 static double axisLat = 0.0;
64 static bool winding_ccw = true; // FIXME: temporary
66 static bool fdm_data_logging = false; // FIXME: temporary
73 _set_view_from_axes ()
75 // Take no action when hat is centered
76 if ( ( axisLong < 0.01 ) &&
77 ( axisLong > -0.01 ) &&
85 /* Do all the quick and easy cases */
86 if (axisLong < 0) { // Longitudinal axis forward
87 if (axisLat == axisLong)
89 else if (axisLat == - axisLong)
91 else if (axisLat == 0)
93 } else if (axisLong > 0) { // Longitudinal axis backward
94 if (axisLat == - axisLong)
96 else if (axisLat == axisLong)
98 else if (axisLat == 0)
100 } else if (axisLong == 0) { // Longitudinal axis neutral
103 else if (axisLat > 0)
105 else return; /* And assertion failure maybe? */
108 /* Do all the difficult cases */
110 viewDir = SGD_RADIANS_TO_DEGREES * atan2 ( -axisLat, -axisLong );
111 if ( viewDir < -1 ) viewDir += 360;
113 // SG_LOG(SG_INPUT, SG_ALERT, "Joystick Lat=" << axisLat << " and Long="
114 // << axisLong << " gave angle=" << viewDir );
116 globals->get_current_view()->set_goal_view_offset(viewDir*SGD_DEGREES_TO_RADIANS);
117 // globals->get_current_view()->set_view_offset(viewDir*SGD_DEGREES_TO_RADIANS);
121 ////////////////////////////////////////////////////////////////////////
122 // Default property bindings (not yet handled by any module).
123 ////////////////////////////////////////////////////////////////////////
125 struct LogClassMapping {
128 LogClassMapping(sgDebugClass cc, string nname) { c = cc; name = nname; }
131 LogClassMapping log_class_mappings [] = {
132 LogClassMapping(SG_NONE, "none"),
133 LogClassMapping(SG_TERRAIN, "terrain"),
134 LogClassMapping(SG_ASTRO, "astro"),
135 LogClassMapping(SG_FLIGHT, "flight"),
136 LogClassMapping(SG_INPUT, "input"),
137 LogClassMapping(SG_GL, "gl"),
138 LogClassMapping(SG_VIEW, "view"),
139 LogClassMapping(SG_COCKPIT, "cockpit"),
140 LogClassMapping(SG_GENERAL, "general"),
141 LogClassMapping(SG_MATH, "math"),
142 LogClassMapping(SG_EVENT, "event"),
143 LogClassMapping(SG_AIRCRAFT, "aircraft"),
144 LogClassMapping(SG_AUTOPILOT, "autopilot"),
145 LogClassMapping(SG_IO, "io"),
146 LogClassMapping(SG_CLIPPER, "clipper"),
147 LogClassMapping(SG_NETWORK, "network"),
148 LogClassMapping(SG_UNDEFD, "")
153 * Get the logging classes.
158 sgDebugClass classes = logbuf::get_log_classes();
160 for (int i = 0; log_class_mappings[i].c != SG_UNDEFD; i++) {
161 if ((classes&log_class_mappings[i].c) > 0) {
162 if (result != (string)"")
164 result += log_class_mappings[i].name;
171 static void addLoggingClass (const string &name)
173 sgDebugClass classes = logbuf::get_log_classes();
174 for (int i = 0; log_class_mappings[i].c != SG_UNDEFD; i++) {
175 if (name == log_class_mappings[i].name) {
176 logbuf::set_log_classes(sgDebugClass(classes|log_class_mappings[i].c));
180 SG_LOG(SG_GENERAL, SG_ALERT, "Unknown logging class: " << name);
185 * Set the logging classes.
188 setLoggingClasses (string classes)
190 logbuf::set_log_classes(SG_NONE);
192 if (classes == "none") {
193 SG_LOG(SG_GENERAL, SG_INFO, "Disabled all logging classes");
197 if (classes == "" || classes == "all") { // default
198 logbuf::set_log_classes(SG_ALL);
199 SG_LOG(SG_GENERAL, SG_INFO, "Enabled all logging classes: "
200 << getLoggingClasses());
204 string rest = classes;
206 int sep = rest.find('|');
208 name = rest.substr(0, sep);
209 rest = rest.substr(sep+1);
210 addLoggingClass(name);
211 sep = rest.find('|');
213 addLoggingClass(rest);
214 SG_LOG(SG_GENERAL, SG_INFO, "Set logging classes to "
215 << getLoggingClasses());
220 * Get the logging priority.
223 getLoggingPriority ()
225 switch (logbuf::get_log_priority()) {
237 SG_LOG(SG_GENERAL, SG_WARN, "Internal: Unknown logging priority number: "
238 << logbuf::get_log_priority());
245 * Set the logging priority.
248 setLoggingPriority (string priority)
250 if (priority == "bulk") {
251 logbuf::set_log_priority(SG_BULK);
252 } else if (priority == "debug") {
253 logbuf::set_log_priority(SG_DEBUG);
254 } else if (priority == "" || priority == "info") { // default
255 logbuf::set_log_priority(SG_INFO);
256 } else if (priority == "warn") {
257 logbuf::set_log_priority(SG_WARN);
258 } else if (priority == "alert") {
259 logbuf::set_log_priority(SG_ALERT);
261 SG_LOG(SG_GENERAL, SG_WARN, "Unknown logging priority " << priority);
263 SG_LOG(SG_GENERAL, SG_INFO, "Logging priority is " << getLoggingPriority());
268 * Get the pause state of the sim.
273 return globals->get_freeze();
278 * Set the pause state of the sim.
281 setFreeze (bool freeze)
283 globals->set_freeze(freeze);
286 current_atcdisplay->CancelRepeatingMessage();
287 current_atcdisplay->RegisterRepeatingMessage("**** SIM IS FROZEN **** SIM IS FROZEN ****");
290 current_atcdisplay->CancelRepeatingMessage();
295 * Return the current aircraft directory (UIUC) as a string.
305 * Set the current aircraft directory (UIUC).
308 setAircraftDir (string dir)
310 if (getAircraftDir() != dir) {
312 // needReinit(); FIXME!!
318 * Get the current view offset in degrees.
323 return (globals->get_current_view()
324 ->get_view_offset() * SGD_RADIANS_TO_DEGREES);
329 setViewOffset (double offset)
331 globals->get_current_view()->set_view_offset(offset * SGD_DEGREES_TO_RADIANS);
337 return (globals->get_current_view()
338 ->get_goal_view_offset() * SGD_RADIANS_TO_DEGREES);
342 setGoalViewOffset (double offset)
344 while ( offset < 0 ) {
347 while ( offset > 360.0 ) {
350 // Snap to center if we are close
351 if ( fabs(offset) < 1.0 || fabs(offset) > 359.0 ) {
355 globals->get_current_view()
356 ->set_goal_view_offset(offset * SGD_DEGREES_TO_RADIANS);
360 * Get the current view tilt in degrees.
365 return (globals->get_current_view()
366 ->get_view_tilt() * SGD_RADIANS_TO_DEGREES);
371 setViewTilt (double tilt)
373 globals->get_current_view()->set_view_tilt(tilt * SGD_DEGREES_TO_RADIANS);
379 return (globals->get_current_view()
380 ->get_goal_view_tilt() * SGD_RADIANS_TO_DEGREES);
384 setGoalViewTilt (double tilt)
389 while ( tilt > 360.0 ) {
392 // Snap to center if we are close
393 if ( fabs(tilt) < 1.0 || fabs(tilt) > 359.0 ) {
397 globals->get_current_view()
398 ->set_goal_view_tilt(tilt * SGD_DEGREES_TO_RADIANS);
403 * Pilot position offset from CG.
406 getPilotPositionXOffset ()
408 FGViewer * pilot_view = globals->get_viewmgr()->get_view(0);
409 float * offset = pilot_view->get_pilot_offset();
414 setPilotPositionXOffset (float x)
416 FGViewer * pilot_view = globals->get_viewmgr()->get_view(0);
417 float * offset = pilot_view->get_pilot_offset();
418 pilot_view->set_pilot_offset(x, offset[1], offset[2]);
422 getPilotPositionYOffset ()
424 FGViewer * pilot_view = globals->get_viewmgr()->get_view(0);
425 float * offset = pilot_view->get_pilot_offset();
430 setPilotPositionYOffset (float y)
432 FGViewer * pilot_view = globals->get_viewmgr()->get_view(0);
433 float * offset = pilot_view->get_pilot_offset();
434 pilot_view->set_pilot_offset(offset[0], y, offset[2]);
438 getPilotPositionZOffset ()
440 FGViewer * pilot_view = globals->get_viewmgr()->get_view(0);
441 float * offset = pilot_view->get_pilot_offset();
446 setPilotPositionZOffset (float z)
448 FGViewer * pilot_view = globals->get_viewmgr()->get_view(0);
449 float * offset = pilot_view->get_pilot_offset();
450 pilot_view->set_pilot_offset(offset[0], offset[1], z);
455 * Return the current Zulu time.
462 struct tm * t = globals->get_time_params()->getGmt();
463 sprintf(buf, "%.4d-%.2d-%.2dT%.2d:%.2d:%.2d",
464 t->tm_year + 1900, t->tm_mon + 1, t->tm_mday,
465 t->tm_hour, t->tm_min, t->tm_sec);
472 * Set the current Zulu time.
475 setDateString (string date_string)
477 SGTime * st = globals->get_time_params();
478 struct tm * current_time = st->getGmt();
481 // Scan for basic ISO format
482 // YYYY-MM-DDTHH:MM:SS
483 int ret = sscanf(date_string.c_str(), "%d-%d-%dT%d:%d:%d",
484 &(new_time.tm_year), &(new_time.tm_mon),
485 &(new_time.tm_mday), &(new_time.tm_hour),
486 &(new_time.tm_min), &(new_time.tm_sec));
488 // Be pretty picky about this, so
489 // that strange things don't happen
490 // if the save file has been edited
493 SG_LOG(SG_INPUT, SG_ALERT, "Date/time string " << date_string
494 << " not in YYYY-MM-DDTHH:MM:SS format; skipped");
498 // OK, it looks like we got six
499 // values, one way or another.
500 new_time.tm_year -= 1900;
501 new_time.tm_mon -= 1;
503 // Now, tell flight gear to use
504 // the new time. This was far
505 // too difficult, by the way.
507 mktime(&new_time) - mktime(current_time) + globals->get_warp();
508 double lon = current_aircraft.fdm_state->get_Longitude();
509 double lat = current_aircraft.fdm_state->get_Latitude();
510 globals->set_warp(warp);
511 st->update(lon, lat, warp);
512 fgUpdateSkyAndLightingParams();
516 * Return the GMT as a string.
523 struct tm * t = globals->get_time_params()->getGmt();
524 sprintf(buf, " %.2d:%.2d:%.2d",
525 t->tm_hour, t->tm_min, t->tm_sec);
532 * Get the texture rendering state.
537 return (material_lib.get_step() == 0);
542 * Set the texture rendering state.
545 setTextures (bool textures)
548 material_lib.set_step(0);
550 material_lib.set_step(1);
555 * Return the magnetic variation
560 return globals->get_mag()->get_magvar() * SGD_RADIANS_TO_DEGREES;
565 * Return the magnetic dip
570 return globals->get_mag()->get_magdip() * SGD_RADIANS_TO_DEGREES;
575 * Return the current heading in degrees.
580 return current_aircraft.fdm_state->get_Psi() * SGD_RADIANS_TO_DEGREES - getMagVar();
585 * Get the autopilot altitude lock (true=on).
590 return (current_autopilot->get_AltitudeEnabled() &&
591 current_autopilot->get_AltitudeMode()
592 == FGAutopilot::FG_ALTITUDE_LOCK);
597 * Set the autopilot altitude lock (true=on).
600 setAPAltitudeLock (bool lock)
603 current_autopilot->set_AltitudeMode(FGAutopilot::FG_ALTITUDE_LOCK);
604 if (current_autopilot->get_AltitudeMode() == FGAutopilot::FG_ALTITUDE_LOCK)
605 current_autopilot->set_AltitudeEnabled(lock);
610 * Get the autopilot target altitude in feet.
615 return current_autopilot->get_TargetAltitude() * SG_METER_TO_FEET;
620 * Set the autopilot target altitude in feet.
623 setAPAltitude (double altitude)
625 current_autopilot->set_TargetAltitude( altitude * SG_FEET_TO_METER );
629 * Get the autopilot altitude lock (true=on).
634 return (current_autopilot->get_AltitudeEnabled() &&
635 (current_autopilot->get_AltitudeMode()
636 == FGAutopilot::FG_ALTITUDE_GS1));
641 * Set the autopilot altitude lock (true=on).
644 setAPGSLock (bool lock)
647 current_autopilot->set_AltitudeMode(FGAutopilot::FG_ALTITUDE_GS1);
648 if (current_autopilot->get_AltitudeMode() == FGAutopilot::FG_ALTITUDE_GS1)
649 current_autopilot->set_AltitudeEnabled(lock);
654 * Get the autopilot terrain lock (true=on).
659 return (current_autopilot->get_AltitudeEnabled() &&
660 (current_autopilot->get_AltitudeMode()
661 == FGAutopilot::FG_ALTITUDE_TERRAIN));
666 * Set the autopilot terrain lock (true=on).
669 setAPTerrainLock (bool lock)
672 current_autopilot->set_AltitudeMode(FGAutopilot::FG_ALTITUDE_TERRAIN);
674 ->set_TargetAGL(current_aircraft.fdm_state->get_Altitude_AGL() *
676 cout << "Target AGL = "
677 << current_aircraft.fdm_state->get_Altitude_AGL() * SG_FEET_TO_METER
680 if (current_autopilot->get_AltitudeMode() == FGAutopilot::FG_ALTITUDE_TERRAIN)
681 current_autopilot->set_AltitudeEnabled(lock);
686 * Get the autopilot target altitude in feet.
691 return current_autopilot->get_TargetClimbRate() * SG_METER_TO_FEET;
696 * Set the autopilot target altitude in feet.
699 setAPClimb (double rate)
701 current_autopilot->set_TargetClimbRate( rate * SG_FEET_TO_METER );
706 * Get the autopilot heading lock (true=on).
712 (current_autopilot->get_HeadingEnabled() &&
713 current_autopilot->get_HeadingMode() == DEFAULT_AP_HEADING_LOCK);
718 * Set the autopilot heading lock (true=on).
721 setAPHeadingLock (bool lock)
724 current_autopilot->set_HeadingMode(DEFAULT_AP_HEADING_LOCK);
725 if (current_autopilot->get_HeadingMode() == DEFAULT_AP_HEADING_LOCK)
726 current_autopilot->set_HeadingEnabled(lock);
731 * Get the autopilot heading bug in degrees.
736 return current_autopilot->get_DGTargetHeading();
741 * Set the autopilot heading bug in degrees.
744 setAPHeadingBug (double heading)
746 current_autopilot->set_DGTargetHeading( heading );
751 * Get the autopilot wing leveler lock (true=on).
757 (current_autopilot->get_HeadingEnabled() &&
758 current_autopilot->get_HeadingMode() == FGAutopilot::FG_TC_HEADING_LOCK);
763 * Set the autopilot wing leveler lock (true=on).
766 setAPWingLeveler (bool lock)
769 current_autopilot->set_HeadingMode(FGAutopilot::FG_TC_HEADING_LOCK);
770 if (current_autopilot->get_HeadingMode() == FGAutopilot::FG_TC_HEADING_LOCK)
771 current_autopilot->set_HeadingEnabled(lock);
775 * Return true if the autopilot is locked to NAV1.
781 (current_autopilot->get_HeadingEnabled() &&
782 current_autopilot->get_HeadingMode() == FGAutopilot::FG_HEADING_NAV1);
787 * Set the autopilot NAV1 lock.
790 setAPNAV1Lock (bool lock)
793 current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_NAV1);
794 if (current_autopilot->get_HeadingMode() == FGAutopilot::FG_HEADING_NAV1)
795 current_autopilot->set_HeadingEnabled(lock);
799 * Get the autopilot autothrottle lock.
802 getAPAutoThrottleLock ()
804 return current_autopilot->get_AutoThrottleEnabled();
809 * Set the autothrottle lock.
812 setAPAutoThrottleLock (bool lock)
814 current_autopilot->set_AutoThrottleEnabled(lock);
820 getAPRudderControl ()
822 if (getAPHeadingLock())
823 return current_autopilot->get_TargetHeading();
825 return globals->get_controls()->get_rudder();
830 setAPRudderControl (double value)
832 if (getAPHeadingLock()) {
833 SG_LOG(SG_GENERAL, SG_DEBUG, "setAPRudderControl " << value );
834 value -= current_autopilot->get_TargetHeading();
835 current_autopilot->HeadingAdjust(value < 0.0 ? -1.0 : 1.0);
837 globals->get_controls()->set_rudder(value);
843 getAPElevatorControl ()
845 if (getAPAltitudeLock())
846 return current_autopilot->get_TargetAltitude();
848 return globals->get_controls()->get_elevator();
853 setAPElevatorControl (double value)
855 if (value != 0 && getAPAltitudeLock()) {
856 SG_LOG(SG_GENERAL, SG_DEBUG, "setAPElevatorControl " << value );
857 value -= current_autopilot->get_TargetAltitude();
858 current_autopilot->AltitudeAdjust(value < 0.0 ? 100.0 : -100.0);
860 globals->get_controls()->set_elevator(value);
866 getAPThrottleControl ()
868 if (getAPAutoThrottleLock())
869 return 0.0; // always resets
871 return globals->get_controls()->get_throttle(0);
876 setAPThrottleControl (double value)
878 if (getAPAutoThrottleLock())
879 current_autopilot->AutoThrottleAdjust(value < 0.0 ? -0.01 : 0.01);
881 globals->get_controls()->set_throttle(FGControls::ALL_ENGINES, value);
886 * Get the current visibility (meters).
891 #ifndef FG_OLD_WEATHER
892 return WeatherDatabase->getWeatherVisibility();
894 return current_weather.get_visibility();
900 * Set the current visibility (meters).
903 setVisibility (double visibility)
905 #ifndef FG_OLD_WEATHER
906 WeatherDatabase->setWeatherVisibility(visibility);
908 current_weather.set_visibility(visibility);
913 * Get the current wind north velocity (feet/second).
918 return current_aircraft.fdm_state->get_V_north_airmass();
923 * Set the current wind north velocity (feet/second).
926 setWindNorth (double speed)
928 current_aircraft.fdm_state
929 ->set_Velocities_Local_Airmass(speed, getWindEast(), getWindDown());
934 * Get the current wind east velocity (feet/second).
939 return current_aircraft.fdm_state->get_V_east_airmass();
944 * Set the current wind east velocity (feet/second).
947 setWindEast (double speed)
949 cout << "Set wind-east to " << speed << endl;
950 current_aircraft.fdm_state->set_Velocities_Local_Airmass(getWindNorth(),
957 * Get the current wind down velocity (feet/second).
962 return current_aircraft.fdm_state->get_V_down_airmass();
967 * Set the current wind down velocity (feet/second).
970 setWindDown (double speed)
972 current_aircraft.fdm_state->set_Velocities_Local_Airmass(getWindNorth(),
980 return globals->get_current_view()->get_fov();
987 globals->get_current_view()->set_fov( fov );
994 return globals->get_warp();
1000 globals->set_warp(warp);
1006 return globals->get_warp_delta();
1010 setWarpDelta (long delta)
1012 globals->set_warp_delta(delta);
1016 setViewAxisLong (double axis)
1022 setViewAxisLat (double axis)
1034 setWindingCCW (bool state)
1036 winding_ccw = state;
1038 glFrontFace ( GL_CCW );
1040 glFrontFace ( GL_CW );
1046 #if defined(FX) && !defined(WIN32)
1047 return globals->get_fullscreen();
1054 setFullScreen (bool state)
1056 #if defined(FX) && !defined(WIN32)
1057 globals->set_fullscreen(state);
1058 # if defined(XMESA_FX_FULLSCREEN) && defined(XMESA_FX_WINDOW)
1059 XMesaSetFXmode( state ? XMESA_FX_FULLSCREEN : XMESA_FX_WINDOW );
1065 getFDMDataLogging ()
1067 return fdm_data_logging;
1071 setFDMDataLogging (bool state)
1073 // kludge; no getter or setter available
1074 if (state != fdm_data_logging) {
1075 fgToggleFDMdataLogging();
1076 fdm_data_logging = state;
1081 ////////////////////////////////////////////////////////////////////////
1082 // Tie the properties.
1083 ////////////////////////////////////////////////////////////////////////
1089 fgTie("/sim/logging/priority", getLoggingPriority, setLoggingPriority);
1090 fgTie("/sim/logging/classes", getLoggingClasses, setLoggingClasses);
1091 fgTie("/sim/freeze", getFreeze, setFreeze);
1092 fgTie("/sim/aircraft-dir", getAircraftDir, setAircraftDir);
1093 fgTie("/sim/view/offset-deg", getViewOffset, setViewOffset, false);
1094 fgSetArchivable("/sim/view/offset-deg");
1095 fgTie("/sim/view/goal-offset-deg", getGoalViewOffset, setGoalViewOffset, false);
1096 fgTie("/sim/view/tilt-deg", getViewTilt, setViewTilt, false);
1097 fgSetArchivable("/sim/view/tilt-deg");
1098 fgTie("/sim/view/goal-tilt-deg", getGoalViewTilt, setGoalViewTilt, false);
1099 fgSetArchivable("/sim/view/goal-offset-deg");
1100 fgTie("/sim/view/pilot/x-offset-m",
1101 getPilotPositionXOffset, setPilotPositionXOffset);
1102 fgSetArchivable("/sim/view/pilot/x-offset-m");
1103 fgTie("/sim/view/pilot/y-offset-m",
1104 getPilotPositionYOffset, setPilotPositionYOffset);
1105 fgSetArchivable("/sim/view/pilot/y-offset-m");
1106 fgTie("/sim/view/pilot/z-offset-m",
1107 getPilotPositionZOffset, setPilotPositionZOffset);
1108 fgSetArchivable("/sim/view/pilot/z-offset-m");
1109 fgTie("/sim/time/gmt", getDateString, setDateString);
1110 fgSetArchivable("/sim/time/gmt");
1111 fgTie("/sim/time/gmt-string", getGMTString);
1112 fgTie("/sim/rendering/textures", getTextures, setTextures);
1115 fgTie("/orientation/heading-magnetic-deg", getHeadingMag);
1118 fgTie("/autopilot/locks/altitude", getAPAltitudeLock, setAPAltitudeLock);
1119 fgSetArchivable("/autopilot/locks/altitude");
1120 fgTie("/autopilot/settings/altitude-ft", getAPAltitude, setAPAltitude);
1121 fgSetArchivable("/autopilot/settings/altitude-ft");
1122 fgTie("/autopilot/locks/glide-slope", getAPGSLock, setAPGSLock);
1123 fgSetArchivable("/autopilot/locks/glide-slope");
1124 fgTie("/autopilot/locks/terrain", getAPTerrainLock, setAPTerrainLock);
1125 fgSetArchivable("/autopilot/locks/terrain");
1126 fgTie("/autopilot/settings/climb-rate-fpm", getAPClimb, setAPClimb, false);
1127 fgSetArchivable("/autopilot/settings/climb-rate-fpm");
1128 fgTie("/autopilot/locks/heading", getAPHeadingLock, setAPHeadingLock);
1129 fgSetArchivable("/autopilot/locks/heading");
1130 fgTie("/autopilot/settings/heading-bug-deg",
1131 getAPHeadingBug, setAPHeadingBug);
1132 fgSetArchivable("/autopilot/settings/heading-bug-deg");
1133 fgTie("/autopilot/locks/wing-leveler", getAPWingLeveler, setAPWingLeveler);
1134 fgSetArchivable("/autopilot/locks/wing-leveler");
1135 fgTie("/autopilot/locks/nav[0]", getAPNAV1Lock, setAPNAV1Lock);
1136 fgSetArchivable("/autopilot/locks/nav[0]");
1137 fgTie("/autopilot/locks/auto-throttle",
1138 getAPAutoThrottleLock, setAPAutoThrottleLock);
1139 fgSetArchivable("/autopilot/locks/auto-throttle");
1140 fgTie("/autopilot/control-overrides/rudder",
1141 getAPRudderControl, setAPRudderControl);
1142 fgSetArchivable("/autopilot/control-overrides/rudder");
1143 fgTie("/autopilot/control-overrides/elevator",
1144 getAPElevatorControl, setAPElevatorControl);
1145 fgSetArchivable("/autopilot/control-overrides/elevator");
1146 fgTie("/autopilot/control-overrides/throttle",
1147 getAPThrottleControl, setAPThrottleControl);
1148 fgSetArchivable("/autopilot/control-overrides/throttle");
1151 fgTie("/environment/visibility-m", getVisibility, setVisibility);
1152 fgSetArchivable("/environment/visibility-m");
1153 fgTie("/environment/wind-north-fps", getWindNorth, setWindNorth);
1154 fgSetArchivable("/environment/wind-north-fps");
1155 fgTie("/environment/wind-east-fps", getWindEast, setWindEast);
1156 fgSetArchivable("/environment/wind-east-fps");
1157 fgTie("/environment/wind-down-fps", getWindDown, setWindDown);
1158 fgSetArchivable("/environment/wind-down-fps");
1160 fgTie("/environment/magnetic-variation-deg", getMagVar);
1161 fgTie("/environment/magnetic-dip-deg", getMagDip);
1164 fgTie("/sim/field-of-view", getFOV, setFOV);
1165 fgSetArchivable("/sim/field-of-view");
1166 fgTie("/sim/time/warp", getWarp, setWarp, false);
1167 fgTie("/sim/time/warp-delta", getWarpDelta, setWarpDelta);
1168 fgTie("/sim/view/axes/long", (double(*)())0, setViewAxisLong);
1169 fgTie("/sim/view/axes/lat", (double(*)())0, setViewAxisLat);
1171 // Misc. Temporary junk.
1172 fgTie("/sim/temp/winding-ccw", getWindingCCW, setWindingCCW, false);
1173 fgTie("/sim/temp/full-screen", getFullScreen, setFullScreen);
1174 fgTie("/sim/temp/fdm-data-logging", getFDMDataLogging, setFDMDataLogging);
1182 _set_view_from_axes();
1187 ////////////////////////////////////////////////////////////////////////
1188 // Save and restore.
1189 ////////////////////////////////////////////////////////////////////////
1193 * Save the current state of the simulator to a stream.
1196 fgSaveFlight (ostream &output)
1199 writeProperties(output, globals->get_props());
1200 } catch (const sg_exception &e) {
1201 guiErrorMessage("Error saving flight: ", e);
1209 * Restore the current state of the simulator from a stream.
1212 fgLoadFlight (istream &input)
1214 SGPropertyNode props;
1216 readProperties(input, &props);
1217 } catch (const sg_exception &e) {
1218 guiErrorMessage("Error reading saved flight: ", e);
1221 copyProperties(&props, globals->get_props());
1222 // When loading a flight, make it the
1223 // new initial state.
1224 globals->saveInitialState();
1230 ////////////////////////////////////////////////////////////////////////
1231 // Implementation of FGCondition.
1232 ////////////////////////////////////////////////////////////////////////
1234 FGCondition::FGCondition ()
1238 FGCondition::~FGCondition ()
1244 ////////////////////////////////////////////////////////////////////////
1245 // Implementation of FGPropertyCondition.
1246 ////////////////////////////////////////////////////////////////////////
1248 FGPropertyCondition::FGPropertyCondition (const string &propname)
1249 : _node(fgGetNode(propname, true))
1253 FGPropertyCondition::~FGPropertyCondition ()
1259 ////////////////////////////////////////////////////////////////////////
1260 // Implementation of FGNotCondition.
1261 ////////////////////////////////////////////////////////////////////////
1263 FGNotCondition::FGNotCondition (FGCondition * condition)
1264 : _condition(condition)
1268 FGNotCondition::~FGNotCondition ()
1274 FGNotCondition::test () const
1276 return !(_condition->test());
1281 ////////////////////////////////////////////////////////////////////////
1282 // Implementation of FGAndCondition.
1283 ////////////////////////////////////////////////////////////////////////
1285 FGAndCondition::FGAndCondition ()
1289 FGAndCondition::~FGAndCondition ()
1291 for (unsigned int i = 0; i < _conditions.size(); i++)
1292 delete _conditions[i];
1296 FGAndCondition::test () const
1298 int nConditions = _conditions.size();
1299 for (int i = 0; i < nConditions; i++) {
1300 if (!_conditions[i]->test())
1307 FGAndCondition::addCondition (FGCondition * condition)
1309 _conditions.push_back(condition);
1314 ////////////////////////////////////////////////////////////////////////
1315 // Implementation of FGOrCondition.
1316 ////////////////////////////////////////////////////////////////////////
1318 FGOrCondition::FGOrCondition ()
1322 FGOrCondition::~FGOrCondition ()
1324 for (unsigned int i = 0; i < _conditions.size(); i++)
1325 delete _conditions[i];
1329 FGOrCondition::test () const
1331 int nConditions = _conditions.size();
1332 for (int i = 0; i < nConditions; i++) {
1333 if (_conditions[i]->test())
1340 FGOrCondition::addCondition (FGCondition * condition)
1342 _conditions.push_back(condition);
1347 ////////////////////////////////////////////////////////////////////////
1348 // Implementation of FGComparisonCondition.
1349 ////////////////////////////////////////////////////////////////////////
1352 doComparison (const SGPropertyNode * left, const SGPropertyNode *right)
1354 switch (left->getType()) {
1355 case SGPropertyNode::BOOL: {
1356 bool v1 = left->getBoolValue();
1357 bool v2 = right->getBoolValue();
1359 return FGComparisonCondition::LESS_THAN;
1361 return FGComparisonCondition::GREATER_THAN;
1363 return FGComparisonCondition::EQUALS;
1366 case SGPropertyNode::INT: {
1367 int v1 = left->getIntValue();
1368 int v2 = right->getIntValue();
1370 return FGComparisonCondition::LESS_THAN;
1372 return FGComparisonCondition::GREATER_THAN;
1374 return FGComparisonCondition::EQUALS;
1377 case SGPropertyNode::LONG: {
1378 long v1 = left->getLongValue();
1379 long v2 = right->getLongValue();
1381 return FGComparisonCondition::LESS_THAN;
1383 return FGComparisonCondition::GREATER_THAN;
1385 return FGComparisonCondition::EQUALS;
1388 case SGPropertyNode::FLOAT: {
1389 float v1 = left->getFloatValue();
1390 float v2 = right->getFloatValue();
1392 return FGComparisonCondition::LESS_THAN;
1394 return FGComparisonCondition::GREATER_THAN;
1396 return FGComparisonCondition::EQUALS;
1399 case SGPropertyNode::DOUBLE: {
1400 double v1 = left->getDoubleValue();
1401 double v2 = right->getDoubleValue();
1403 return FGComparisonCondition::LESS_THAN;
1405 return FGComparisonCondition::GREATER_THAN;
1407 return FGComparisonCondition::EQUALS;
1410 case SGPropertyNode::STRING:
1411 case SGPropertyNode::NONE:
1412 case SGPropertyNode::UNSPECIFIED: {
1413 string v1 = left->getStringValue();
1414 string v2 = right->getStringValue();
1416 return FGComparisonCondition::LESS_THAN;
1418 return FGComparisonCondition::GREATER_THAN;
1420 return FGComparisonCondition::EQUALS;
1424 throw sg_exception("Unrecognized node type");
1429 FGComparisonCondition::FGComparisonCondition (Type type, bool reverse)
1438 FGComparisonCondition::~FGComparisonCondition ()
1440 delete _right_value;
1444 FGComparisonCondition::test () const
1446 // Always fail if incompletely specified
1447 if (_left_property == 0 ||
1448 (_right_property == 0 && _right_value == 0))
1451 // Get LESS_THAN, EQUALS, or GREATER_THAN
1453 doComparison(_left_property,
1454 (_right_property != 0 ? _right_property : _right_value));
1456 return (cmp == _type);
1458 return (cmp != _type);
1462 FGComparisonCondition::setLeftProperty (const string &propname)
1464 _left_property = fgGetNode(propname, true);
1468 FGComparisonCondition::setRightProperty (const string &propname)
1470 delete _right_value;
1472 _right_property = fgGetNode(propname, true);
1476 FGComparisonCondition::setRightValue (const SGPropertyNode *node)
1478 _right_property = 0;
1479 delete _right_value;
1480 _right_value = new SGPropertyNode(*node);
1485 ////////////////////////////////////////////////////////////////////////
1486 // Read a condition and use it if necessary.
1487 ////////////////////////////////////////////////////////////////////////
1489 // Forward declaration
1490 static FGCondition * readCondition (const SGPropertyNode * node);
1492 static FGCondition *
1493 readPropertyCondition (const SGPropertyNode * node)
1495 return new FGPropertyCondition(node->getStringValue());
1498 static FGCondition *
1499 readNotCondition (const SGPropertyNode * node)
1501 int nChildren = node->nChildren();
1502 for (int i = 0; i < nChildren; i++) {
1503 const SGPropertyNode * child = node->getChild(i);
1504 FGCondition * condition = readCondition(child);
1506 return new FGNotCondition(condition);
1508 SG_LOG(SG_COCKPIT, SG_ALERT, "Panel: empty 'not' condition");
1512 static FGCondition *
1513 readAndConditions (const SGPropertyNode * node)
1515 FGAndCondition * andCondition = new FGAndCondition;
1516 int nChildren = node->nChildren();
1517 for (int i = 0; i < nChildren; i++) {
1518 const SGPropertyNode * child = node->getChild(i);
1519 FGCondition * condition = readCondition(child);
1521 andCondition->addCondition(condition);
1523 return andCondition;
1526 static FGCondition *
1527 readOrConditions (const SGPropertyNode * node)
1529 FGOrCondition * orCondition = new FGOrCondition;
1530 int nChildren = node->nChildren();
1531 for (int i = 0; i < nChildren; i++) {
1532 const SGPropertyNode * child = node->getChild(i);
1533 FGCondition * condition = readCondition(child);
1535 orCondition->addCondition(condition);
1540 static FGCondition *
1541 readComparison (const SGPropertyNode * node,
1542 FGComparisonCondition::Type type,
1545 FGComparisonCondition * condition = new FGComparisonCondition(type, reverse);
1546 condition->setLeftProperty(node->getStringValue("property[0]"));
1547 if (node->hasValue("property[1]"))
1548 condition->setRightProperty(node->getStringValue("property[1]"));
1550 condition->setRightValue(node->getChild("value", 0));
1555 static FGCondition *
1556 readCondition (const SGPropertyNode * node)
1558 const string &name = node->getName();
1559 if (name == "property")
1560 return readPropertyCondition(node);
1561 else if (name == "not")
1562 return readNotCondition(node);
1563 else if (name == "and")
1564 return readAndConditions(node);
1565 else if (name == "or")
1566 return readOrConditions(node);
1567 else if (name == "less-than")
1568 return readComparison(node, FGComparisonCondition::LESS_THAN, false);
1569 else if (name == "less-than-equals")
1570 return readComparison(node, FGComparisonCondition::GREATER_THAN, true);
1571 else if (name == "greater-than")
1572 return readComparison(node, FGComparisonCondition::GREATER_THAN, false);
1573 else if (name == "greater-than-equals")
1574 return readComparison(node, FGComparisonCondition::LESS_THAN, true);
1575 else if (name == "equals")
1576 return readComparison(node, FGComparisonCondition::EQUALS, false);
1577 else if (name == "not-equals")
1578 return readComparison(node, FGComparisonCondition::EQUALS, true);
1585 ////////////////////////////////////////////////////////////////////////
1586 // Implementation of FGConditional.
1587 ////////////////////////////////////////////////////////////////////////
1589 FGConditional::FGConditional ()
1594 FGConditional::~FGConditional ()
1600 FGConditional::setCondition (FGCondition * condition)
1603 _condition = condition;
1607 FGConditional::test () const
1609 return ((_condition == 0) || _condition->test());
1614 // The top-level is always an implicit 'and' group
1616 fgReadCondition (const SGPropertyNode * node)
1618 return readAndConditions(node);
1622 // end of fg_props.cxx