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 <Autopilot/newauto.hxx>
32 #include <Aircraft/aircraft.hxx>
33 #include <Time/tmp.hxx>
34 #include <FDM/UIUCModel/uiuc_aircraftdir.h>
35 #ifndef FG_OLD_WEATHER
36 # include <WeatherCM/FGLocalWeatherDatabase.h>
38 # include <Weather/weather.hxx>
40 #include <Objects/matlib.hxx>
45 #include "fg_props.hxx"
46 #include "viewmgr.hxx"
48 #if !defined(SG_HAVE_NATIVE_SGI_COMPILERS)
49 SG_USING_STD(istream);
50 SG_USING_STD(ostream);
53 static double getWindNorth ();
54 static double getWindEast ();
55 static double getWindDown ();
57 // Allow the view to be set from two axes (i.e. a joystick hat)
58 // This needs to be in FGViewer itself, somehow.
59 static double axisLong = 0.0;
60 static double axisLat = 0.0;
62 static bool winding_ccw = true; // FIXME: temporary
64 static bool fdm_data_logging = false; // FIXME: temporary
71 _set_view_from_axes ()
73 // Take no action when hat is centered
74 if ( ( axisLong < 0.01 ) &&
75 ( axisLong > -0.01 ) &&
83 /* Do all the quick and easy cases */
84 if (axisLong < 0) { // Longitudinal axis forward
85 if (axisLat == axisLong)
87 else if (axisLat == - axisLong)
89 else if (axisLat == 0)
91 } else if (axisLong > 0) { // Longitudinal axis backward
92 if (axisLat == - axisLong)
94 else if (axisLat == axisLong)
96 else if (axisLat == 0)
98 } else if (axisLong == 0) { // Longitudinal axis neutral
101 else if (axisLat > 0)
103 else return; /* And assertion failure maybe? */
106 /* Do all the difficult cases */
108 viewDir = SGD_RADIANS_TO_DEGREES * atan2 ( -axisLat, -axisLong );
109 if ( viewDir < -1 ) viewDir += 360;
111 // SG_LOG(SG_INPUT, SG_ALERT, "Joystick Lat=" << axisLat << " and Long="
112 // << axisLong << " gave angle=" << viewDir );
114 globals->get_current_view()->set_goal_view_offset(viewDir*SGD_DEGREES_TO_RADIANS);
115 // globals->get_current_view()->set_view_offset(viewDir*SGD_DEGREES_TO_RADIANS);
119 ////////////////////////////////////////////////////////////////////////
120 // Default property bindings (not yet handled by any module).
121 ////////////////////////////////////////////////////////////////////////
123 struct LogClassMapping {
128 LogClassMapping log_class_mappings [] = {
130 {SG_TERRAIN, "terrain"},
132 {SG_FLIGHT, "flight"},
136 {SG_COCKPIT, "cockpit"},
137 {SG_GENERAL, "general"},
140 {SG_AIRCRAFT, "aircraft"},
141 {SG_AUTOPILOT, "autopilot"},
143 {SG_CLIPPER, "clipper"},
144 {SG_NETWORK, "network"},
150 * Get the logging classes.
155 sgDebugClass classes = logbuf::get_log_classes();
157 for (int i = 0; log_class_mappings[i].c != SG_UNDEFD; i++) {
158 if ((classes&log_class_mappings[i].c) > 0) {
161 result += log_class_mappings[i].name;
168 static void addLoggingClass (const string &name)
170 sgDebugClass classes = logbuf::get_log_classes();
171 for (int i = 0; log_class_mappings[i].c != SG_UNDEFD; i++) {
172 if (name == log_class_mappings[i].name) {
173 logbuf::set_log_classes(sgDebugClass(classes|log_class_mappings[i].c));
177 SG_LOG(SG_GENERAL, SG_ALERT, "Unknown logging class: " << name);
182 * Set the logging classes.
185 setLoggingClasses (string classes)
187 logbuf::set_log_classes(SG_NONE);
189 if (classes == "none") {
190 SG_LOG(SG_GENERAL, SG_INFO, "Disabled all logging classes");
194 if (classes == "" || classes == "all") { // default
195 logbuf::set_log_classes(SG_ALL);
196 SG_LOG(SG_GENERAL, SG_INFO, "Enabled all logging classes: "
197 << getLoggingClasses());
201 string rest = classes;
203 int sep = rest.find('|');
205 name = rest.substr(0, sep);
206 rest = rest.substr(sep+1);
207 addLoggingClass(name);
208 sep = rest.find('|');
210 addLoggingClass(rest);
211 SG_LOG(SG_GENERAL, SG_INFO, "Set logging classes to "
212 << getLoggingClasses());
217 * Get the logging priority.
220 getLoggingPriority ()
222 switch (logbuf::get_log_priority()) {
234 SG_LOG(SG_GENERAL, SG_WARN, "Internal: Unknown logging priority number: "
235 << logbuf::get_log_priority());
242 * Set the logging priority.
245 setLoggingPriority (string priority)
247 if (priority == "bulk") {
248 logbuf::set_log_priority(SG_BULK);
249 } else if (priority == "debug") {
250 logbuf::set_log_priority(SG_DEBUG);
251 } else if (priority == "" || priority == "info") { // default
252 logbuf::set_log_priority(SG_INFO);
253 } else if (priority == "warn") {
254 logbuf::set_log_priority(SG_WARN);
255 } else if (priority == "alert") {
256 logbuf::set_log_priority(SG_ALERT);
258 SG_LOG(SG_GENERAL, SG_WARN, "Unknown logging priority " << priority);
260 SG_LOG(SG_GENERAL, SG_INFO, "Logging priority is " << getLoggingPriority());
265 * Get the pause state of the sim.
270 return globals->get_freeze();
275 * Set the pause state of the sim.
278 setFreeze (bool freeze)
280 globals->set_freeze(freeze);
284 * Return the current aircraft directory (UIUC) as a string.
294 * Set the current aircraft directory (UIUC).
297 setAircraftDir (string dir)
299 if (getAircraftDir() != dir) {
301 // needReinit(); FIXME!!
307 * Get the current view offset in degrees.
312 return (globals->get_current_view()
313 ->get_view_offset() * SGD_RADIANS_TO_DEGREES);
318 setViewOffset (double offset)
320 globals->get_current_view()->set_view_offset(offset * SGD_DEGREES_TO_RADIANS);
326 return (globals->get_current_view()
327 ->get_goal_view_offset() * SGD_RADIANS_TO_DEGREES);
331 setGoalViewOffset (double offset)
333 while ( offset < 0 ) {
336 while ( offset > 360.0 ) {
339 // Snap to center if we are close
340 if ( fabs(offset) < 1.0 || fabs(offset) > 359.0 ) {
344 globals->get_current_view()
345 ->set_goal_view_offset(offset * SGD_DEGREES_TO_RADIANS);
350 * Pilot position offset from CG.
353 getPilotPositionXOffset ()
355 FGViewer * pilot_view = globals->get_viewmgr()->get_view(0);
356 float * offset = pilot_view->get_pilot_offset();
361 setPilotPositionXOffset (float x)
363 FGViewer * pilot_view = globals->get_viewmgr()->get_view(0);
364 float * offset = pilot_view->get_pilot_offset();
365 pilot_view->set_pilot_offset(x, offset[1], offset[2]);
369 getPilotPositionYOffset ()
371 FGViewer * pilot_view = globals->get_viewmgr()->get_view(0);
372 float * offset = pilot_view->get_pilot_offset();
377 setPilotPositionYOffset (float y)
379 FGViewer * pilot_view = globals->get_viewmgr()->get_view(0);
380 float * offset = pilot_view->get_pilot_offset();
381 pilot_view->set_pilot_offset(offset[0], y, offset[2]);
385 getPilotPositionZOffset ()
387 FGViewer * pilot_view = globals->get_viewmgr()->get_view(0);
388 float * offset = pilot_view->get_pilot_offset();
393 setPilotPositionZOffset (float z)
395 FGViewer * pilot_view = globals->get_viewmgr()->get_view(0);
396 float * offset = pilot_view->get_pilot_offset();
397 pilot_view->set_pilot_offset(offset[0], offset[1], z);
402 * Return the current Zulu time.
409 struct tm * t = globals->get_time_params()->getGmt();
410 sprintf(buf, "%.4d-%.2d-%.2dT%.2d:%.2d:%.2d",
411 t->tm_year + 1900, t->tm_mon + 1, t->tm_mday,
412 t->tm_hour, t->tm_min, t->tm_sec);
419 * Set the current Zulu time.
422 setDateString (string date_string)
424 SGTime * st = globals->get_time_params();
425 struct tm * current_time = st->getGmt();
428 // Scan for basic ISO format
429 // YYYY-MM-DDTHH:MM:SS
430 int ret = sscanf(date_string.c_str(), "%d-%d-%dT%d:%d:%d",
431 &(new_time.tm_year), &(new_time.tm_mon),
432 &(new_time.tm_mday), &(new_time.tm_hour),
433 &(new_time.tm_min), &(new_time.tm_sec));
435 // Be pretty picky about this, so
436 // that strange things don't happen
437 // if the save file has been edited
440 SG_LOG(SG_INPUT, SG_ALERT, "Date/time string " << date_string
441 << " not in YYYY-MM-DDTHH:MM:SS format; skipped");
445 // OK, it looks like we got six
446 // values, one way or another.
447 new_time.tm_year -= 1900;
448 new_time.tm_mon -= 1;
450 // Now, tell flight gear to use
451 // the new time. This was far
452 // too difficult, by the way.
454 mktime(&new_time) - mktime(current_time) + globals->get_warp();
455 double lon = current_aircraft.fdm_state->get_Longitude();
456 double lat = current_aircraft.fdm_state->get_Latitude();
457 globals->set_warp(warp);
458 st->update(lon, lat, warp);
459 fgUpdateSkyAndLightingParams();
463 * Return the GMT as a string.
470 struct tm * t = globals->get_time_params()->getGmt();
471 sprintf(buf, " %.2d:%.2d:%.2d",
472 t->tm_hour, t->tm_min, t->tm_sec);
479 * Get the texture rendering state.
484 return (material_lib.get_step() == 0);
489 * Set the texture rendering state.
492 setTextures (bool textures)
495 material_lib.set_step(0);
497 material_lib.set_step(1);
502 * Return the magnetic variation
507 return globals->get_mag()->get_magvar() * SGD_RADIANS_TO_DEGREES;
512 * Return the magnetic dip
517 return globals->get_mag()->get_magdip() * SGD_RADIANS_TO_DEGREES;
522 * Return the current heading in degrees.
527 return current_aircraft.fdm_state->get_Psi() * SGD_RADIANS_TO_DEGREES - getMagVar();
532 * Return the fuel level in tank 1
537 return current_aircraft.fdm_state->get_Tank1Fuel();
541 setTank1Fuel ( double gals )
543 current_aircraft.fdm_state->set_Tank1Fuel( gals );
547 * Return the fuel level in tank 2
552 return current_aircraft.fdm_state->get_Tank2Fuel();
556 setTank2Fuel ( double gals )
558 current_aircraft.fdm_state->set_Tank2Fuel( gals );
563 * Get the autopilot altitude lock (true=on).
568 return (current_autopilot->get_AltitudeEnabled() &&
569 current_autopilot->get_AltitudeMode()
570 == FGAutopilot::FG_ALTITUDE_LOCK);
575 * Set the autopilot altitude lock (true=on).
578 setAPAltitudeLock (bool lock)
580 current_autopilot->set_AltitudeMode(FGAutopilot::FG_ALTITUDE_LOCK);
581 current_autopilot->set_AltitudeEnabled(lock);
586 * Get the autopilot target altitude in feet.
591 return current_autopilot->get_TargetAltitude() * SG_METER_TO_FEET;
596 * Set the autopilot target altitude in feet.
599 setAPAltitude (double altitude)
601 current_autopilot->set_TargetAltitude( altitude * SG_FEET_TO_METER );
605 * Get the autopilot altitude lock (true=on).
610 return (current_autopilot->get_AltitudeEnabled() &&
611 (current_autopilot->get_AltitudeMode()
612 == FGAutopilot::FG_ALTITUDE_GS1));
617 * Set the autopilot altitude lock (true=on).
620 setAPGSLock (bool lock)
622 current_autopilot->set_AltitudeMode(FGAutopilot::FG_ALTITUDE_GS1);
623 current_autopilot->set_AltitudeEnabled(lock);
628 * Get the autopilot terrain lock (true=on).
633 return (current_autopilot->get_AltitudeEnabled() &&
634 (current_autopilot->get_AltitudeMode()
635 == FGAutopilot::FG_ALTITUDE_TERRAIN));
640 * Set the autopilot terrain lock (true=on).
643 setAPTerrainLock (bool lock)
645 current_autopilot->set_AltitudeMode(FGAutopilot::FG_ALTITUDE_TERRAIN);
646 current_autopilot->set_AltitudeEnabled(lock);
647 current_autopilot->set_TargetAGL(
648 current_aircraft.fdm_state->get_Altitude_AGL() * SG_FEET_TO_METER
650 cout << "Target AGL = "
651 << current_aircraft.fdm_state->get_Altitude_AGL() * SG_FEET_TO_METER
657 * Get the autopilot target altitude in feet.
662 return current_autopilot->get_TargetClimbRate() * SG_METER_TO_FEET;
667 * Set the autopilot target altitude in feet.
670 setAPClimb (double rate)
672 current_autopilot->set_TargetClimbRate( rate * SG_FEET_TO_METER );
677 * Get the autopilot heading lock (true=on).
683 (current_autopilot->get_HeadingEnabled() &&
684 current_autopilot->get_HeadingMode() == DEFAULT_AP_HEADING_LOCK);
689 * Set the autopilot heading lock (true=on).
692 setAPHeadingLock (bool lock)
695 current_autopilot->set_HeadingMode(DEFAULT_AP_HEADING_LOCK);
696 current_autopilot->set_HeadingEnabled(true);
698 current_autopilot->set_HeadingEnabled(false);
704 * Get the autopilot heading bug in degrees.
709 return current_autopilot->get_DGTargetHeading();
714 * Set the autopilot heading bug in degrees.
717 setAPHeadingBug (double heading)
719 current_autopilot->set_DGTargetHeading( heading );
724 * Get the autopilot wing leveler lock (true=on).
730 (current_autopilot->get_HeadingEnabled() &&
731 current_autopilot->get_HeadingMode() == FGAutopilot::FG_TC_HEADING_LOCK);
736 * Set the autopilot wing leveler lock (true=on).
739 setAPWingLeveler (bool lock)
742 current_autopilot->set_HeadingMode(FGAutopilot::FG_TC_HEADING_LOCK);
743 current_autopilot->set_HeadingEnabled(true);
745 current_autopilot->set_HeadingEnabled(false);
750 * Return true if the autopilot is locked to NAV1.
756 (current_autopilot->get_HeadingEnabled() &&
757 current_autopilot->get_HeadingMode() == FGAutopilot::FG_HEADING_NAV1);
762 * Set the autopilot NAV1 lock.
765 setAPNAV1Lock (bool lock)
768 current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_NAV1);
769 current_autopilot->set_HeadingEnabled(true);
770 } else if (current_autopilot->get_HeadingMode() ==
771 FGAutopilot::FG_HEADING_NAV1) {
772 current_autopilot->set_HeadingEnabled(false);
777 * Get the autopilot autothrottle lock.
780 getAPAutoThrottleLock ()
782 return current_autopilot->get_AutoThrottleEnabled();
787 * Set the autothrottle lock.
790 setAPAutoThrottleLock (bool lock)
792 current_autopilot->set_AutoThrottleEnabled(lock);
798 getAPRudderControl ()
800 if (getAPHeadingLock())
801 return current_autopilot->get_TargetHeading();
803 return globals->get_controls()->get_rudder();
808 setAPRudderControl (double value)
810 if (getAPHeadingLock()) {
811 SG_LOG(SG_GENERAL, SG_DEBUG, "setAPRudderControl " << value );
812 value -= current_autopilot->get_TargetHeading();
813 current_autopilot->HeadingAdjust(value < 0.0 ? -1.0 : 1.0);
815 globals->get_controls()->set_rudder(value);
821 getAPElevatorControl ()
823 if (getAPAltitudeLock())
824 return current_autopilot->get_TargetAltitude();
826 return globals->get_controls()->get_elevator();
831 setAPElevatorControl (double value)
833 if (getAPAltitudeLock()) {
834 SG_LOG(SG_GENERAL, SG_DEBUG, "setAPElevatorControl " << value );
835 value -= current_autopilot->get_TargetAltitude();
836 current_autopilot->AltitudeAdjust(value < 0.0 ? 100.0 : -100.0);
838 globals->get_controls()->set_elevator(value);
844 getAPThrottleControl ()
846 if (getAPAutoThrottleLock())
847 return 0.0; // always resets
849 return globals->get_controls()->get_throttle(0);
854 setAPThrottleControl (double value)
856 if (getAPAutoThrottleLock())
857 current_autopilot->AutoThrottleAdjust(value < 0.0 ? -0.01 : 0.01);
859 globals->get_controls()->set_throttle(0, value);
864 * Get the current visibility (meters).
869 #ifndef FG_OLD_WEATHER
870 return WeatherDatabase->getWeatherVisibility();
872 return current_weather.get_visibility();
878 * Set the current visibility (meters).
881 setVisibility (double visibility)
883 #ifndef FG_OLD_WEATHER
884 WeatherDatabase->setWeatherVisibility(visibility);
886 current_weather.set_visibility(visibility);
891 * Get the current wind north velocity (feet/second).
896 return current_aircraft.fdm_state->get_V_north_airmass();
901 * Set the current wind north velocity (feet/second).
904 setWindNorth (double speed)
906 current_aircraft.fdm_state
907 ->set_Velocities_Local_Airmass(speed, getWindEast(), getWindDown());
912 * Get the current wind east velocity (feet/second).
917 return current_aircraft.fdm_state->get_V_east_airmass();
922 * Set the current wind east velocity (feet/second).
925 setWindEast (double speed)
927 cout << "Set wind-east to " << speed << endl;
928 current_aircraft.fdm_state->set_Velocities_Local_Airmass(getWindNorth(),
935 * Get the current wind down velocity (feet/second).
940 return current_aircraft.fdm_state->get_V_down_airmass();
945 * Set the current wind down velocity (feet/second).
948 setWindDown (double speed)
950 current_aircraft.fdm_state->set_Velocities_Local_Airmass(getWindNorth(),
956 * Set the current engine0 running flag.
959 setRunningFlag (bool flag)
961 if ( current_aircraft.fdm_state->get_num_engines() > 0 ) {
962 current_aircraft.fdm_state->get_engine(0)->set_Running_Flag( flag );
967 * Set the current engine0 cranking flag.
969 //Although there is no real reason to want to tell the engine that it is cranking,
970 //this is currently necessary to avoid the cranking sound being played
971 //before the engine inits.
973 setCrankingFlag (bool flag)
975 if ( current_aircraft.fdm_state->get_num_engines() > 0 ) {
976 current_aircraft.fdm_state->get_engine(0)->set_Cranking_Flag( flag );
983 return globals->get_current_view()->get_fov();
990 globals->get_current_view()->set_fov( fov );
997 return globals->get_warp();
1003 globals->set_warp(warp);
1009 return globals->get_warp_delta();
1013 setWarpDelta (long delta)
1015 globals->set_warp_delta(delta);
1019 setViewAxisLong (double axis)
1025 setViewAxisLat (double axis)
1037 setWindingCCW (bool state)
1039 winding_ccw = state;
1041 glFrontFace ( GL_CCW );
1043 glFrontFace ( GL_CW );
1049 #if defined(FX) && !defined(WIN32)
1050 return global_fullscreen;
1057 setFullScreen (bool state)
1059 #if defined(FX) && !defined(WIN32)
1060 global_fullscreen = state;
1061 # if defined(XMESA_FX_FULLSCREEN) && defined(XMESA_FX_WINDOW)
1062 XMesaSetFXmode( global_fullscreen ? XMESA_FX_FULLSCREEN : XMESA_FX_WINDOW );
1068 getFDMDataLogging ()
1070 return fdm_data_logging;
1074 setFDMDataLogging (bool state)
1076 // kludge; no getter or setter available
1077 if (state != fdm_data_logging) {
1078 fgToggleFDMdataLogging();
1079 fdm_data_logging = state;
1084 ////////////////////////////////////////////////////////////////////////
1085 // Tie the properties.
1086 ////////////////////////////////////////////////////////////////////////
1092 fgTie("/sim/logging/priority", getLoggingPriority, setLoggingPriority);
1093 fgTie("/sim/logging/classes", getLoggingClasses, setLoggingClasses);
1094 fgTie("/sim/freeze", getFreeze, setFreeze);
1095 fgTie("/sim/aircraft-dir", getAircraftDir, setAircraftDir);
1096 fgTie("/sim/view/offset-deg", getViewOffset, setViewOffset);
1097 fgSetArchivable("/sim/view/offset-deg");
1098 fgTie("/sim/view/goal-offset-deg", getGoalViewOffset, setGoalViewOffset);
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("/consumables/fuel/tank[0]/level-gal_us",
1119 getTank1Fuel, setTank1Fuel, false);
1120 fgSetArchivable("/consumables/fuel/tank[0]/level-gal_us");
1121 fgTie("/consumables/fuel/tank[1]/level-gal_us",
1122 getTank2Fuel, setTank2Fuel, false);
1123 fgSetArchivable("/consumables/fuel/tank[1]/level-gal_us");
1126 fgTie("/autopilot/locks/altitude", getAPAltitudeLock, setAPAltitudeLock);
1127 fgSetArchivable("/autopilot/locks/altitude");
1128 fgTie("/autopilot/settings/altitude-ft", getAPAltitude, setAPAltitude);
1129 fgSetArchivable("/autopilot/settings/altitude-ft");
1130 fgTie("/autopilot/locks/glide-slope", getAPGSLock, setAPGSLock);
1131 fgSetArchivable("/autopilot/locks/glide-slope");
1132 fgTie("/autopilot/locks/terrain", getAPTerrainLock, setAPTerrainLock);
1133 fgSetArchivable("/autopilot/locks/terrain");
1134 fgTie("/autopilot/settings/agl-ft", getAPAltitude, setAPAltitude);
1135 fgSetArchivable("/autopilot/settings/agl-ft");
1136 fgTie("/autopilot/settings/climb-rate-fpm", getAPClimb, setAPClimb, false);
1137 fgSetArchivable("/autopilot/settings/climb-rate-fpm");
1138 fgTie("/autopilot/locks/heading", getAPHeadingLock, setAPHeadingLock);
1139 fgSetArchivable("/autopilot/locks/heading");
1140 fgTie("/autopilot/settings/heading-bug-deg",
1141 getAPHeadingBug, setAPHeadingBug, false);
1142 fgSetArchivable("/autopilot/settings/heading-bug-deg");
1143 fgTie("/autopilot/locks/wing-leveler", getAPWingLeveler, setAPWingLeveler);
1144 fgSetArchivable("/autopilot/locks/wing-leveler");
1145 fgTie("/autopilot/locks/nav[0]", getAPNAV1Lock, setAPNAV1Lock);
1146 fgSetArchivable("/autopilot/locks/nav[0]");
1147 fgTie("/autopilot/locks/auto-throttle",
1148 getAPAutoThrottleLock, setAPAutoThrottleLock);
1149 fgSetArchivable("/autopilot/locks/auto-throttle");
1150 fgTie("/autopilot/control-overrides/rudder",
1151 getAPRudderControl, setAPRudderControl);
1152 fgSetArchivable("/autopilot/control-overrides/rudder");
1153 fgTie("/autopilot/control-overrides/elevator",
1154 getAPElevatorControl, setAPElevatorControl);
1155 fgSetArchivable("/autopilot/control-overrides/elevator");
1156 fgTie("/autopilot/control-overrides/throttle",
1157 getAPThrottleControl, setAPThrottleControl);
1158 fgSetArchivable("/autopilot/control-overrides/throttle");
1161 fgTie("/environment/visibility-m", getVisibility, setVisibility);
1162 fgSetArchivable("/environment/visibility-m");
1163 fgTie("/environment/wind-north-fps", getWindNorth, setWindNorth);
1164 fgSetArchivable("/environment/wind-north-fps");
1165 fgTie("/environment/wind-east-fps", getWindEast, setWindEast);
1166 fgSetArchivable("/environment/wind-east-fps");
1167 fgTie("/environment/wind-down-fps", getWindDown, setWindDown);
1168 fgSetArchivable("/environment/wind-down-fps");
1170 fgTie("/environment/magnetic-variation-deg", getMagVar);
1171 fgTie("/environment/magnetic-dip-deg", getMagDip);
1174 fgTie("/sim/field-of-view", getFOV, setFOV);
1175 fgSetArchivable("/sim/field-of-view");
1176 fgTie("/sim/time/warp", getWarp, setWarp, false);
1177 fgTie("/sim/time/warp-delta", getWarpDelta, setWarpDelta);
1178 fgTie("/sim/view/axes/long", (double(*)())0, setViewAxisLong);
1179 fgTie("/sim/view/axes/lat", (double(*)())0, setViewAxisLat);
1181 // Misc. Temporary junk.
1182 fgTie("/sim/temp/winding-ccw", getWindingCCW, setWindingCCW, false);
1183 fgTie("/sim/temp/full-screen", getFullScreen, setFullScreen);
1184 fgTie("/sim/temp/fdm-data-logging", getFDMDataLogging, setFDMDataLogging);
1192 _set_view_from_axes();
1197 ////////////////////////////////////////////////////////////////////////
1198 // Save and restore.
1199 ////////////////////////////////////////////////////////////////////////
1203 * Save the current state of the simulator to a stream.
1206 fgSaveFlight (ostream &output)
1209 writeProperties(output, globals->get_props());
1210 } catch (const sg_exception &e) {
1211 guiErrorMessage("Error saving flight: ", e);
1219 * Restore the current state of the simulator from a stream.
1222 fgLoadFlight (istream &input)
1224 SGPropertyNode props;
1226 readProperties(input, &props);
1227 } catch (const sg_exception &e) {
1228 guiErrorMessage("Error reading saved flight: ", e);
1231 copyProperties(&props, globals->get_props());
1232 // When loading a flight, make it the
1233 // new initial state.
1234 globals->saveInitialState();
1240 ////////////////////////////////////////////////////////////////////////
1241 // Implementation of FGCondition.
1242 ////////////////////////////////////////////////////////////////////////
1244 FGCondition::FGCondition ()
1248 FGCondition::~FGCondition ()
1254 ////////////////////////////////////////////////////////////////////////
1255 // Implementation of FGPropertyCondition.
1256 ////////////////////////////////////////////////////////////////////////
1258 FGPropertyCondition::FGPropertyCondition (const string &propname)
1259 : _node(fgGetNode(propname, true))
1263 FGPropertyCondition::~FGPropertyCondition ()
1269 ////////////////////////////////////////////////////////////////////////
1270 // Implementation of FGNotCondition.
1271 ////////////////////////////////////////////////////////////////////////
1273 FGNotCondition::FGNotCondition (FGCondition * condition)
1274 : _condition(condition)
1278 FGNotCondition::~FGNotCondition ()
1284 FGNotCondition::test () const
1286 return !(_condition->test());
1291 ////////////////////////////////////////////////////////////////////////
1292 // Implementation of FGAndCondition.
1293 ////////////////////////////////////////////////////////////////////////
1295 FGAndCondition::FGAndCondition ()
1299 FGAndCondition::~FGAndCondition ()
1301 for (unsigned int i = 0; i < _conditions.size(); i++)
1302 delete _conditions[i];
1306 FGAndCondition::test () const
1308 int nConditions = _conditions.size();
1309 for (int i = 0; i < nConditions; i++) {
1310 if (!_conditions[i]->test())
1317 FGAndCondition::addCondition (FGCondition * condition)
1319 _conditions.push_back(condition);
1324 ////////////////////////////////////////////////////////////////////////
1325 // Implementation of FGOrCondition.
1326 ////////////////////////////////////////////////////////////////////////
1328 FGOrCondition::FGOrCondition ()
1332 FGOrCondition::~FGOrCondition ()
1334 for (unsigned int i = 0; i < _conditions.size(); i++)
1335 delete _conditions[i];
1339 FGOrCondition::test () const
1341 int nConditions = _conditions.size();
1342 for (int i = 0; i < nConditions; i++) {
1343 if (_conditions[i]->test())
1350 FGOrCondition::addCondition (FGCondition * condition)
1352 _conditions.push_back(condition);
1357 ////////////////////////////////////////////////////////////////////////
1358 // Implementation of FGComparisonCondition.
1359 ////////////////////////////////////////////////////////////////////////
1362 doComparison (const SGPropertyNode * left, const SGPropertyNode *right)
1364 switch (left->getType()) {
1365 case SGPropertyNode::BOOL: {
1366 bool v1 = left->getBoolValue();
1367 bool v2 = right->getBoolValue();
1369 return FGComparisonCondition::LESS_THAN;
1371 return FGComparisonCondition::GREATER_THAN;
1373 return FGComparisonCondition::EQUALS;
1376 case SGPropertyNode::INT: {
1377 int v1 = left->getIntValue();
1378 int v2 = right->getIntValue();
1380 return FGComparisonCondition::LESS_THAN;
1382 return FGComparisonCondition::GREATER_THAN;
1384 return FGComparisonCondition::EQUALS;
1387 case SGPropertyNode::LONG: {
1388 long v1 = left->getLongValue();
1389 long v2 = right->getLongValue();
1391 return FGComparisonCondition::LESS_THAN;
1393 return FGComparisonCondition::GREATER_THAN;
1395 return FGComparisonCondition::EQUALS;
1398 case SGPropertyNode::FLOAT: {
1399 float v1 = left->getFloatValue();
1400 float v2 = right->getFloatValue();
1402 return FGComparisonCondition::LESS_THAN;
1404 return FGComparisonCondition::GREATER_THAN;
1406 return FGComparisonCondition::EQUALS;
1409 case SGPropertyNode::DOUBLE: {
1410 double v1 = left->getDoubleValue();
1411 double v2 = right->getDoubleValue();
1413 return FGComparisonCondition::LESS_THAN;
1415 return FGComparisonCondition::GREATER_THAN;
1417 return FGComparisonCondition::EQUALS;
1420 case SGPropertyNode::STRING:
1421 case SGPropertyNode::NONE:
1422 case SGPropertyNode::UNSPECIFIED: {
1423 string v1 = left->getStringValue();
1424 string v2 = right->getStringValue();
1426 return FGComparisonCondition::LESS_THAN;
1428 return FGComparisonCondition::GREATER_THAN;
1430 return FGComparisonCondition::EQUALS;
1434 throw sg_exception("Unrecognized node type");
1439 FGComparisonCondition::FGComparisonCondition (Type type, bool reverse)
1448 FGComparisonCondition::~FGComparisonCondition ()
1450 delete _right_value;
1454 FGComparisonCondition::test () const
1456 // Always fail if incompletely specified
1457 if (_left_property == 0 ||
1458 (_right_property == 0 && _right_value == 0))
1461 // Get LESS_THAN, EQUALS, or GREATER_THAN
1463 doComparison(_left_property,
1464 (_right_property != 0 ? _right_property : _right_value));
1466 return (cmp == _type);
1468 return (cmp != _type);
1472 FGComparisonCondition::setLeftProperty (const string &propname)
1474 _left_property = fgGetNode(propname, true);
1478 FGComparisonCondition::setRightProperty (const string &propname)
1480 delete _right_value;
1482 _right_property = fgGetNode(propname, true);
1486 FGComparisonCondition::setRightValue (const SGPropertyNode *node)
1488 _right_property = 0;
1489 delete _right_value;
1490 _right_value = new SGPropertyNode(*node);
1495 ////////////////////////////////////////////////////////////////////////
1496 // Read a condition and use it if necessary.
1497 ////////////////////////////////////////////////////////////////////////
1499 // Forward declaration
1500 static FGCondition * readCondition (const SGPropertyNode * node);
1502 static FGCondition *
1503 readPropertyCondition (const SGPropertyNode * node)
1505 return new FGPropertyCondition(node->getStringValue());
1508 static FGCondition *
1509 readNotCondition (const SGPropertyNode * node)
1511 int nChildren = node->nChildren();
1512 for (int i = 0; i < nChildren; i++) {
1513 const SGPropertyNode * child = node->getChild(i);
1514 FGCondition * condition = readCondition(child);
1516 return new FGNotCondition(condition);
1518 SG_LOG(SG_COCKPIT, SG_ALERT, "Panel: empty 'not' condition");
1522 static FGCondition *
1523 readAndConditions (const SGPropertyNode * node)
1525 FGAndCondition * andCondition = new FGAndCondition;
1526 int nChildren = node->nChildren();
1527 for (int i = 0; i < nChildren; i++) {
1528 const SGPropertyNode * child = node->getChild(i);
1529 FGCondition * condition = readCondition(child);
1531 andCondition->addCondition(condition);
1533 return andCondition;
1536 static FGCondition *
1537 readOrConditions (const SGPropertyNode * node)
1539 FGOrCondition * orCondition = new FGOrCondition;
1540 int nChildren = node->nChildren();
1541 for (int i = 0; i < nChildren; i++) {
1542 const SGPropertyNode * child = node->getChild(i);
1543 FGCondition * condition = readCondition(child);
1545 orCondition->addCondition(condition);
1550 static FGCondition *
1551 readComparison (const SGPropertyNode * node,
1552 FGComparisonCondition::Type type,
1555 FGComparisonCondition * condition = new FGComparisonCondition(type, reverse);
1556 condition->setLeftProperty(node->getStringValue("property[0]"));
1557 if (node->hasValue("property[1]"))
1558 condition->setRightProperty(node->getStringValue("property[1]"));
1560 condition->setRightValue(node->getChild("value", 0));
1565 static FGCondition *
1566 readCondition (const SGPropertyNode * node)
1568 const string &name = node->getName();
1569 if (name == "property")
1570 return readPropertyCondition(node);
1571 else if (name == "not")
1572 return readNotCondition(node);
1573 else if (name == "and")
1574 return readAndConditions(node);
1575 else if (name == "or")
1576 return readOrConditions(node);
1577 else if (name == "less-than")
1578 return readComparison(node, FGComparisonCondition::LESS_THAN, false);
1579 else if (name == "less-than-equals")
1580 return readComparison(node, FGComparisonCondition::GREATER_THAN, true);
1581 else if (name == "greater-than")
1582 return readComparison(node, FGComparisonCondition::GREATER_THAN, false);
1583 else if (name == "greater-than-equals")
1584 return readComparison(node, FGComparisonCondition::LESS_THAN, true);
1585 else if (name == "equals")
1586 return readComparison(node, FGComparisonCondition::EQUALS, false);
1587 else if (name == "not-equals")
1588 return readComparison(node, FGComparisonCondition::EQUALS, true);
1595 ////////////////////////////////////////////////////////////////////////
1596 // Implementation of FGConditional.
1597 ////////////////////////////////////////////////////////////////////////
1599 FGConditional::FGConditional ()
1604 FGConditional::~FGConditional ()
1610 FGConditional::setCondition (FGCondition * condition)
1613 _condition = condition;
1617 FGConditional::test () const
1619 return ((_condition == 0) || _condition->test());
1624 // The top-level is always an implicit 'and' group
1626 fgReadCondition (const SGPropertyNode * node)
1628 return readAndConditions(node);
1632 // end of fg_props.cxx