# include <simgear/compiler.h>
#endif
+#include <simgear/misc/exception.hxx>
+
#include STL_IOSTREAM
-#include <Autopilot/newauto.hxx>
+#include <ATC/ATCdisplay.hxx>
#include <Aircraft/aircraft.hxx>
#include <Time/tmp.hxx>
#include <FDM/UIUCModel/uiuc_aircraftdir.h>
-#ifndef FG_OLD_WEATHER
+#ifndef FG_NEW_ENVIRONMENT
# include <WeatherCM/FGLocalWeatherDatabase.h>
#else
-# include <Weather/weather.hxx>
-#endif
+# include <Environment/environment.hxx>
+#endif // FG_NEW_ENVIRONMENT
#include <Objects/matlib.hxx>
+#include <GUI/gui.h>
+
+#include "globals.hxx"
#include "fgfs.hxx"
#include "fg_props.hxx"
+#include "viewmgr.hxx"
#if !defined(SG_HAVE_NATIVE_SGI_COMPILERS)
SG_USING_STD(istream);
SG_USING_STD(ostream);
#endif
+#if !defined(FG_NEW_ENVIRONMENT)
static double getWindNorth ();
static double getWindEast ();
static double getWindDown ();
+#endif // FG_NEW_ENVIRONMENT
// Allow the view to be set from two axes (i.e. a joystick hat)
// This needs to be in FGViewer itself, somehow.
static double axisLong = 0.0;
static double axisLat = 0.0;
+static bool winding_ccw = true; // FIXME: temporary
+
+static bool fdm_data_logging = false; // FIXME: temporary
+
+
/**
* Utility function.
*/
// Default property bindings (not yet handled by any module).
////////////////////////////////////////////////////////////////////////
+struct LogClassMapping {
+ sgDebugClass c;
+ string name;
+ LogClassMapping(sgDebugClass cc, string nname) { c = cc; name = nname; }
+};
+
+LogClassMapping log_class_mappings [] = {
+ LogClassMapping(SG_NONE, "none"),
+ LogClassMapping(SG_TERRAIN, "terrain"),
+ LogClassMapping(SG_ASTRO, "astro"),
+ LogClassMapping(SG_FLIGHT, "flight"),
+ LogClassMapping(SG_INPUT, "input"),
+ LogClassMapping(SG_GL, "gl"),
+ LogClassMapping(SG_VIEW, "view"),
+ LogClassMapping(SG_COCKPIT, "cockpit"),
+ LogClassMapping(SG_GENERAL, "general"),
+ LogClassMapping(SG_MATH, "math"),
+ LogClassMapping(SG_EVENT, "event"),
+ LogClassMapping(SG_AIRCRAFT, "aircraft"),
+ LogClassMapping(SG_AUTOPILOT, "autopilot"),
+ LogClassMapping(SG_IO, "io"),
+ LogClassMapping(SG_CLIPPER, "clipper"),
+ LogClassMapping(SG_NETWORK, "network"),
+ LogClassMapping(SG_UNDEFD, "")
+};
+
+
+/**
+ * Get the logging classes.
+ */
+static string
+getLoggingClasses ()
+{
+ sgDebugClass classes = logbuf::get_log_classes();
+ string result = "";
+ for (int i = 0; log_class_mappings[i].c != SG_UNDEFD; i++) {
+ if ((classes&log_class_mappings[i].c) > 0) {
+ if (result != (string)"")
+ result += '|';
+ result += log_class_mappings[i].name;
+ }
+ }
+ return result;
+}
+
+
+static void addLoggingClass (const string &name)
+{
+ sgDebugClass classes = logbuf::get_log_classes();
+ for (int i = 0; log_class_mappings[i].c != SG_UNDEFD; i++) {
+ if (name == log_class_mappings[i].name) {
+ logbuf::set_log_classes(sgDebugClass(classes|log_class_mappings[i].c));
+ return;
+ }
+ }
+ SG_LOG(SG_GENERAL, SG_ALERT, "Unknown logging class: " << name);
+}
+
+
+/**
+ * Set the logging classes.
+ */
+static void
+setLoggingClasses (string classes)
+{
+ logbuf::set_log_classes(SG_NONE);
+
+ if (classes == "none") {
+ SG_LOG(SG_GENERAL, SG_INFO, "Disabled all logging classes");
+ return;
+ }
+
+ if (classes == "" || classes == "all") { // default
+ logbuf::set_log_classes(SG_ALL);
+ SG_LOG(SG_GENERAL, SG_INFO, "Enabled all logging classes: "
+ << getLoggingClasses());
+ return;
+ }
+
+ string rest = classes;
+ string name = "";
+ int sep = rest.find('|');
+ while (sep > 0) {
+ name = rest.substr(0, sep);
+ rest = rest.substr(sep+1);
+ addLoggingClass(name);
+ sep = rest.find('|');
+ }
+ addLoggingClass(rest);
+ SG_LOG(SG_GENERAL, SG_INFO, "Set logging classes to "
+ << getLoggingClasses());
+}
+
+
+/**
+ * Get the logging priority.
+ */
+static string
+getLoggingPriority ()
+{
+ switch (logbuf::get_log_priority()) {
+ case SG_BULK:
+ return "bulk";
+ case SG_DEBUG:
+ return "debug";
+ case SG_INFO:
+ return "info";
+ case SG_WARN:
+ return "warn";
+ case SG_ALERT:
+ return "alert";
+ default:
+ SG_LOG(SG_GENERAL, SG_WARN, "Internal: Unknown logging priority number: "
+ << logbuf::get_log_priority());
+ return "unknown";
+ }
+}
+
+
+/**
+ * Set the logging priority.
+ */
+static void
+setLoggingPriority (string priority)
+{
+ if (priority == "bulk") {
+ logbuf::set_log_priority(SG_BULK);
+ } else if (priority == "debug") {
+ logbuf::set_log_priority(SG_DEBUG);
+ } else if (priority == "" || priority == "info") { // default
+ logbuf::set_log_priority(SG_INFO);
+ } else if (priority == "warn") {
+ logbuf::set_log_priority(SG_WARN);
+ } else if (priority == "alert") {
+ logbuf::set_log_priority(SG_ALERT);
+ } else {
+ SG_LOG(SG_GENERAL, SG_WARN, "Unknown logging priority " << priority);
+ }
+ SG_LOG(SG_GENERAL, SG_INFO, "Logging priority is " << getLoggingPriority());
+}
+
+#if 0
/**
* Get the pause state of the sim.
*/
static void
setFreeze (bool freeze)
{
- globals->set_freeze(freeze);
+ globals->set_freeze(freeze);
+ if ( freeze ) {
+ // BusyCursor( 0 );
+ current_atcdisplay->CancelRepeatingMessage();
+ current_atcdisplay->RegisterRepeatingMessage("**** SIM IS FROZEN **** SIM IS FROZEN ****");
+ } else {
+ // BusyCursor( 1 );
+ current_atcdisplay->CancelRepeatingMessage();
+ }
}
+#endif
/**
* Return the current aircraft directory (UIUC) as a string.
offset -= 360.0;
}
// Snap to center if we are close
- if ( fabs( offset ) < 1.0 ) {
+ if ( fabs(offset) < 1.0 || fabs(offset) > 359.0 ) {
offset = 0.0;
}
->set_goal_view_offset(offset * SGD_DEGREES_TO_RADIANS);
}
+/**
+ * Get the current view tilt in degrees.
+ */
+static double
+getViewTilt ()
+{
+ return (globals->get_current_view()
+ ->get_view_tilt() * SGD_RADIANS_TO_DEGREES);
+}
+
+
+static void
+setViewTilt (double tilt)
+{
+ globals->get_current_view()->set_view_tilt(tilt * SGD_DEGREES_TO_RADIANS);
+}
+
+static double
+getGoalViewTilt ()
+{
+ return (globals->get_current_view()
+ ->get_goal_view_tilt() * SGD_RADIANS_TO_DEGREES);
+}
+
+static void
+setGoalViewTilt (double tilt)
+{
+ while ( tilt < 0 ) {
+ tilt += 360.0;
+ }
+ while ( tilt > 360.0 ) {
+ tilt -= 360.0;
+ }
+ // Snap to center if we are close
+ if ( fabs(tilt) < 1.0 || fabs(tilt) > 359.0 ) {
+ tilt = 0.0;
+ }
+
+ globals->get_current_view()
+ ->set_goal_view_tilt(tilt * SGD_DEGREES_TO_RADIANS);
+}
+
+
+/**
+ * Pilot position offset from CG.
+ */
+static float
+getPilotPositionXOffset ()
+{
+ FGViewer * pilot_view = globals->get_viewmgr()->get_view(0);
+ float * offset = pilot_view->get_pilot_offset();
+ return offset[0];
+}
+
+static void
+setPilotPositionXOffset (float x)
+{
+ FGViewer * pilot_view = globals->get_viewmgr()->get_view(0);
+ float * offset = pilot_view->get_pilot_offset();
+ pilot_view->set_pilot_offset(x, offset[1], offset[2]);
+}
+
+static float
+getPilotPositionYOffset ()
+{
+ FGViewer * pilot_view = globals->get_viewmgr()->get_view(0);
+ float * offset = pilot_view->get_pilot_offset();
+ return offset[1];
+}
+
+static void
+setPilotPositionYOffset (float y)
+{
+ FGViewer * pilot_view = globals->get_viewmgr()->get_view(0);
+ float * offset = pilot_view->get_pilot_offset();
+ pilot_view->set_pilot_offset(offset[0], y, offset[2]);
+}
+
+static float
+getPilotPositionZOffset ()
+{
+ FGViewer * pilot_view = globals->get_viewmgr()->get_view(0);
+ float * offset = pilot_view->get_pilot_offset();
+ return offset[2];
+}
+
+static void
+setPilotPositionZOffset (float z)
+{
+ FGViewer * pilot_view = globals->get_viewmgr()->get_view(0);
+ float * offset = pilot_view->get_pilot_offset();
+ pilot_view->set_pilot_offset(offset[0], offset[1], z);
+}
+
+
+/**
+ * Return the number of milliseconds elapsed since simulation started.
+ */
+static long
+getElapsedTime_ms ()
+{
+ return globals->get_elapsed_time_ms();
+}
+
/**
* Return the current Zulu time.
static void
setDateString (string date_string)
{
+ static const SGPropertyNode *cur_time_override
+ = fgGetNode("/sim/time/cur-time-override", true);
+
SGTime * st = globals->get_time_params();
struct tm * current_time = st->getGmt();
struct tm new_time;
double lon = current_aircraft.fdm_state->get_Longitude();
double lat = current_aircraft.fdm_state->get_Latitude();
globals->set_warp(warp);
- st->update(lon, lat, warp);
+ st->update(lon, lat, cur_time_override->getLongValue(), warp);
fgUpdateSkyAndLightingParams();
}
{
string out;
char buf[16];
- struct tm * t = globals->get_time_params()->getGmt();
+ struct tm *t = globals->get_time_params()->getGmt();
sprintf(buf, " %.2d:%.2d:%.2d",
t->tm_hour, t->tm_min, t->tm_sec);
+ // cout << t << " " << buf << endl;
out = buf;
return out;
}
}
-/**
- * Return the current engine0 rpm
- */
-static double
-getRPM ()
-{
- if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
- return current_aircraft.fdm_state->get_engine(0)->get_RPM();
- } else {
- return 0.0;
- }
-}
-
+#if !defined(FG_NEW_ENVIRONMENT)
/**
- * Return the current engine0 EGT.
+ * Get the current visibility (meters).
*/
static double
-getEGT ()
+getVisibility ()
{
- if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
- return current_aircraft.fdm_state->get_engine(0)->get_EGT();
- } else {
- return 0.0;
- }
+ return WeatherDatabase->getWeatherVisibility();
}
+
/**
- * Return the current engine0 CHT.
+ * Set the current visibility (meters).
*/
-static double
-getCHT ()
+static void
+setVisibility (double visibility)
{
- if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
- return current_aircraft.fdm_state->get_engine(0)->get_CHT();
- } else {
- return 0.0;
- }
+ WeatherDatabase->setWeatherVisibility(visibility);
}
/**
- * Return the current engine0 Manifold Pressure.
+ * Get the current wind north velocity (feet/second).
*/
static double
-getMP ()
+getWindNorth ()
{
- if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
- return current_aircraft.fdm_state->get_engine(0)->get_Manifold_Pressure();
- } else {
- return 0.0;
- }
+ return current_aircraft.fdm_state->get_V_north_airmass();
}
/**
- * Return the current engine0 fuel flow
+ * Set the current wind north velocity (feet/second).
*/
-static double
-getFuelFlow ()
+static void
+setWindNorth (double speed)
{
- if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
- return current_aircraft.fdm_state->get_engine(0)->get_Fuel_Flow();
- } else {
- return 0.0;
- }
+ current_aircraft.fdm_state
+ ->set_Velocities_Local_Airmass(speed, getWindEast(), getWindDown());
}
+
/**
- * Return the fuel level in tank 1
+ * Get the current wind east velocity (feet/second).
*/
static double
-getTank1Fuel ()
+getWindEast ()
{
- return current_aircraft.fdm_state->get_Tank1Fuel();
+ return current_aircraft.fdm_state->get_V_east_airmass();
}
-static void
-setTank1Fuel ( double gals )
-{
- current_aircraft.fdm_state->set_Tank1Fuel( gals );
-}
/**
- * Return the fuel level in tank 2
+ * Set the current wind east velocity (feet/second).
*/
-static double
-getTank2Fuel ()
-{
- return current_aircraft.fdm_state->get_Tank2Fuel();
-}
-
static void
-setTank2Fuel ( double gals )
+setWindEast (double speed)
{
- current_aircraft.fdm_state->set_Tank2Fuel( gals );
+ cout << "Set wind-east to " << speed << endl;
+ current_aircraft.fdm_state->set_Velocities_Local_Airmass(getWindNorth(),
+ speed,
+ getWindDown());
}
/**
- * Get the autopilot altitude lock (true=on).
+ * Get the current wind down velocity (feet/second).
*/
-static bool
-getAPAltitudeLock ()
+static double
+getWindDown ()
{
- return (current_autopilot->get_AltitudeEnabled() &&
- current_autopilot->get_AltitudeMode()
- == FGAutopilot::FG_ALTITUDE_LOCK);
+ return current_aircraft.fdm_state->get_V_down_airmass();
}
/**
- * Set the autopilot altitude lock (true=on).
+ * Set the current wind down velocity (feet/second).
*/
static void
-setAPAltitudeLock (bool lock)
+setWindDown (double speed)
{
- current_autopilot->set_AltitudeMode(FGAutopilot::FG_ALTITUDE_LOCK);
- current_autopilot->set_AltitudeEnabled(lock);
+ current_aircraft.fdm_state->set_Velocities_Local_Airmass(getWindNorth(),
+ getWindEast(),
+ speed);
}
+#endif // FG_NEW_ENVIRONMENT
-/**
- * Get the autopilot target altitude in feet.
- */
static double
-getAPAltitude ()
+getFOV ()
{
- return current_autopilot->get_TargetAltitude() * SG_METER_TO_FEET;
+ return globals->get_current_view()->get_fov();
}
-
-/**
- * Set the autopilot target altitude in feet.
- */
static void
-setAPAltitude (double altitude)
+setFOV (double fov)
{
- current_autopilot->set_TargetAltitude( altitude * SG_FEET_TO_METER );
+ if ( fov < 180 ) {
+ globals->get_current_view()->set_fov( fov );
+ }
}
-/**
- * Get the autopilot altitude lock (true=on).
- */
-static bool
-getAPGSLock ()
+static long
+getWarp ()
{
- return (current_autopilot->get_AltitudeEnabled() &&
- (current_autopilot->get_AltitudeMode()
- == FGAutopilot::FG_ALTITUDE_GS1));
+ return globals->get_warp();
}
-
-/**
- * Set the autopilot altitude lock (true=on).
- */
static void
-setAPGSLock (bool lock)
+setWarp (long warp)
{
- current_autopilot->set_AltitudeMode(FGAutopilot::FG_ALTITUDE_GS1);
- current_autopilot->set_AltitudeEnabled(lock);
+ globals->set_warp(warp);
}
-
-/**
- * Get the autopilot terrain lock (true=on).
- */
-static bool
-getAPTerrainLock ()
+static long
+getWarpDelta ()
{
- return (current_autopilot->get_AltitudeEnabled() &&
- (current_autopilot->get_AltitudeMode()
- == FGAutopilot::FG_ALTITUDE_TERRAIN));
+ return globals->get_warp_delta();
}
-
-/**
- * Set the autopilot terrain lock (true=on).
- */
static void
-setAPTerrainLock (bool lock)
+setWarpDelta (long delta)
{
- current_autopilot->set_AltitudeMode(FGAutopilot::FG_ALTITUDE_TERRAIN);
- current_autopilot->set_AltitudeEnabled(lock);
+ globals->set_warp_delta(delta);
}
-
-/**
- * Get the autopilot target altitude in feet.
- */
-static double
-getAPClimb ()
+static void
+setViewAxisLong (double axis)
{
- return current_autopilot->get_TargetClimbRate() * SG_METER_TO_FEET;
+ axisLong = axis;
}
-
-/**
- * Set the autopilot target altitude in feet.
- */
static void
-setAPClimb (double rate)
+setViewAxisLat (double axis)
{
- current_autopilot->set_TargetClimbRate( rate * SG_FEET_TO_METER );
+ axisLat = axis;
}
-
-/**
- * Get the autopilot heading lock (true=on).
- */
static bool
-getAPHeadingLock ()
+getWindingCCW ()
{
- return
- (current_autopilot->get_HeadingEnabled() &&
- current_autopilot->get_HeadingMode() == DEFAULT_AP_HEADING_LOCK);
+ return winding_ccw;
}
-
-/**
- * Set the autopilot heading lock (true=on).
- */
static void
-setAPHeadingLock (bool lock)
+setWindingCCW (bool state)
{
- if (lock) {
- current_autopilot->set_HeadingMode(DEFAULT_AP_HEADING_LOCK);
- current_autopilot->set_HeadingEnabled(true);
- } else {
- current_autopilot->set_HeadingEnabled(false);
- }
+ winding_ccw = state;
+ if ( winding_ccw )
+ glFrontFace ( GL_CCW );
+ else
+ glFrontFace ( GL_CW );
}
-
-/**
- * Get the autopilot heading bug in degrees.
- */
-static double
-getAPHeadingBug ()
+static bool
+getFullScreen ()
{
- return current_autopilot->get_DGTargetHeading();
+#if defined(FX) && !defined(WIN32)
+ return globals->get_fullscreen();
+#else
+ return false;
+#endif
}
-
-/**
- * Set the autopilot heading bug in degrees.
- */
static void
-setAPHeadingBug (double heading)
+setFullScreen (bool state)
{
- current_autopilot->set_DGTargetHeading( heading );
+#if defined(FX) && !defined(WIN32)
+ globals->set_fullscreen(state);
+# if defined(XMESA_FX_FULLSCREEN) && defined(XMESA_FX_WINDOW)
+ XMesaSetFXmode( state ? XMESA_FX_FULLSCREEN : XMESA_FX_WINDOW );
+# endif
+#endif
}
-
-/**
- * Get the autopilot wing leveler lock (true=on).
- */
static bool
-getAPWingLeveler ()
+getFDMDataLogging ()
{
- return
- (current_autopilot->get_HeadingEnabled() &&
- current_autopilot->get_HeadingMode() == FGAutopilot::FG_TC_HEADING_LOCK);
+ return fdm_data_logging;
}
-
-/**
- * Set the autopilot wing leveler lock (true=on).
- */
static void
-setAPWingLeveler (bool lock)
-{
- if (lock) {
- current_autopilot->set_HeadingMode(FGAutopilot::FG_TC_HEADING_LOCK);
- current_autopilot->set_HeadingEnabled(true);
- } else {
- current_autopilot->set_HeadingEnabled(false);
- }
-}
-
-/**
- * Return true if the autopilot is locked to NAV1.
- */
-static bool
-getAPNAV1Lock ()
+setFDMDataLogging (bool state)
{
- return
- (current_autopilot->get_HeadingEnabled() &&
- current_autopilot->get_HeadingMode() == FGAutopilot::FG_HEADING_NAV1);
+ // kludge; no getter or setter available
+ if (state != fdm_data_logging) {
+ fgToggleFDMdataLogging();
+ fdm_data_logging = state;
+ }
}
+\f
+////////////////////////////////////////////////////////////////////////
+// Tie the properties.
+////////////////////////////////////////////////////////////////////////
-/**
- * Set the autopilot NAV1 lock.
- */
-static void
-setAPNAV1Lock (bool lock)
-{
- if (lock) {
- current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_NAV1);
- current_autopilot->set_HeadingEnabled(true);
- } else if (current_autopilot->get_HeadingMode() ==
- FGAutopilot::FG_HEADING_NAV1) {
- current_autopilot->set_HeadingEnabled(false);
- }
+void
+fgInitProps ()
+{
+ // Simulation
+ fgTie("/sim/logging/priority", getLoggingPriority, setLoggingPriority);
+ fgTie("/sim/logging/classes", getLoggingClasses, setLoggingClasses);
+ // fgTie("/sim/freeze", getFreeze, setFreeze);
+ fgTie("/sim/aircraft-dir", getAircraftDir, setAircraftDir);
+ fgTie("/sim/view/offset-deg", getViewOffset, setViewOffset, false);
+ fgSetArchivable("/sim/view/offset-deg");
+ fgTie("/sim/view/goal-offset-deg", getGoalViewOffset, setGoalViewOffset, false);
+ fgTie("/sim/view/tilt-deg", getViewTilt, setViewTilt, false);
+ fgSetArchivable("/sim/view/tilt-deg");
+ fgTie("/sim/view/goal-tilt-deg", getGoalViewTilt, setGoalViewTilt, false);
+ fgSetArchivable("/sim/view/goal-offset-deg");
+ fgTie("/sim/view/pilot/x-offset-m",
+ getPilotPositionXOffset, setPilotPositionXOffset);
+ fgSetArchivable("/sim/view/pilot/x-offset-m");
+ fgTie("/sim/view/pilot/y-offset-m",
+ getPilotPositionYOffset, setPilotPositionYOffset);
+ fgSetArchivable("/sim/view/pilot/y-offset-m");
+ fgTie("/sim/view/pilot/z-offset-m",
+ getPilotPositionZOffset, setPilotPositionZOffset);
+ fgSetArchivable("/sim/view/pilot/z-offset-m");
+ fgTie("/sim/time/elapsed-ms", getElapsedTime_ms);
+ fgTie("/sim/time/gmt", getDateString, setDateString);
+ fgSetArchivable("/sim/time/gmt");
+ fgTie("/sim/time/gmt-string", getGMTString);
+ fgTie("/sim/rendering/textures", getTextures, setTextures);
+
+ // Orientation
+ fgTie("/orientation/heading-magnetic-deg", getHeadingMag);
+
+ // Environment
+#if !defined(FG_NEW_ENVIRONMENT)
+ fgTie("/environment/visibility-m", getVisibility, setVisibility);
+ fgSetArchivable("/environment/visibility-m");
+ fgTie("/environment/wind-from-north-fps", getWindNorth, setWindNorth);
+ fgSetArchivable("/environment/wind-from-north-fps");
+ fgTie("/environment/wind-from-east-fps", getWindEast, setWindEast);
+ fgSetArchivable("/environment/wind-from-east-fps");
+ fgTie("/environment/wind-from-down-fps", getWindDown, setWindDown);
+ fgSetArchivable("/environment/wind-from-down-fps");
+#endif
+
+ fgTie("/environment/magnetic-variation-deg", getMagVar);
+ fgTie("/environment/magnetic-dip-deg", getMagDip);
+
+ // View
+ fgTie("/sim/field-of-view", getFOV, setFOV);
+ fgSetArchivable("/sim/field-of-view");
+ fgTie("/sim/time/warp", getWarp, setWarp, false);
+ fgTie("/sim/time/warp-delta", getWarpDelta, setWarpDelta);
+ fgTie("/sim/view/axes/long", (double(*)())0, setViewAxisLong);
+ fgTie("/sim/view/axes/lat", (double(*)())0, setViewAxisLat);
+
+ // Misc. Temporary junk.
+ fgTie("/sim/temp/winding-ccw", getWindingCCW, setWindingCCW, false);
+ fgTie("/sim/temp/full-screen", getFullScreen, setFullScreen);
+ fgTie("/sim/temp/fdm-data-logging", getFDMDataLogging, setFDMDataLogging);
+
}
+
+void
+fgUpdateProps ()
+{
+ _set_view_from_axes();
+}
+
+
+\f
+////////////////////////////////////////////////////////////////////////
+// Save and restore.
+////////////////////////////////////////////////////////////////////////
+
+
/**
- * Get the autopilot autothrottle lock.
+ * Save the current state of the simulator to a stream.
*/
-static bool
-getAPAutoThrottleLock ()
+bool
+fgSaveFlight (ostream &output, bool write_all)
{
- return current_autopilot->get_AutoThrottleEnabled();
+ try {
+ writeProperties(output, globals->get_props(), write_all);
+ } catch (const sg_exception &e) {
+ guiErrorMessage("Error saving flight: ", e);
+ return false;
+ }
+ return true;
}
/**
- * Set the autothrottle lock.
+ * Restore the current state of the simulator from a stream.
*/
-static void
-setAPAutoThrottleLock (bool lock)
+bool
+fgLoadFlight (istream &input)
{
- current_autopilot->set_AutoThrottleEnabled(lock);
+ SGPropertyNode props;
+ try {
+ readProperties(input, &props);
+ } catch (const sg_exception &e) {
+ guiErrorMessage("Error reading saved flight: ", e);
+ return false;
+ }
+ copyProperties(&props, globals->get_props());
+ // When loading a flight, make it the
+ // new initial state.
+ globals->saveInitialState();
+ return true;
}
-// kludge
-static double
-getAPRudderControl ()
+\f
+////////////////////////////////////////////////////////////////////////
+// Implementation of FGCondition.
+////////////////////////////////////////////////////////////////////////
+
+FGCondition::FGCondition ()
{
- if (getAPHeadingLock())
- return current_autopilot->get_TargetHeading();
- else
- return controls.get_rudder();
}
-// kludge
-static void
-setAPRudderControl (double value)
+FGCondition::~FGCondition ()
{
- if (getAPHeadingLock()) {
- SG_LOG(SG_GENERAL, SG_DEBUG, "setAPRudderControl " << value );
- value -= current_autopilot->get_TargetHeading();
- current_autopilot->HeadingAdjust(value < 0.0 ? -1.0 : 1.0);
- } else {
- controls.set_rudder(value);
- }
}
-// kludge
-static double
-getAPElevatorControl ()
+
+\f
+////////////////////////////////////////////////////////////////////////
+// Implementation of FGPropertyCondition.
+////////////////////////////////////////////////////////////////////////
+
+FGPropertyCondition::FGPropertyCondition (const string &propname)
+ : _node(fgGetNode(propname, true))
{
- if (getAPAltitudeLock())
- return current_autopilot->get_TargetAltitude();
- else
- return controls.get_elevator();
}
-// kludge
-static void
-setAPElevatorControl (double value)
+FGPropertyCondition::~FGPropertyCondition ()
{
- if (getAPAltitudeLock()) {
- SG_LOG(SG_GENERAL, SG_DEBUG, "setAPElevatorControl " << value );
- value -= current_autopilot->get_TargetAltitude();
- current_autopilot->AltitudeAdjust(value < 0.0 ? 100.0 : -100.0);
- } else {
- controls.set_elevator(value);
- }
}
-// kludge
-static double
-getAPThrottleControl ()
+
+\f
+////////////////////////////////////////////////////////////////////////
+// Implementation of FGNotCondition.
+////////////////////////////////////////////////////////////////////////
+
+FGNotCondition::FGNotCondition (FGCondition * condition)
+ : _condition(condition)
{
- if (getAPAutoThrottleLock())
- return 0.0; // always resets
- else
- return controls.get_throttle(0);
}
-// kludge
-static void
-setAPThrottleControl (double value)
+FGNotCondition::~FGNotCondition ()
{
- if (getAPAutoThrottleLock())
- current_autopilot->AutoThrottleAdjust(value < 0.0 ? -0.01 : 0.01);
- else
- controls.set_throttle(0, value);
+ delete _condition;
}
-
-/**
- * Get the current visibility (meters).
- */
-static double
-getVisibility ()
+bool
+FGNotCondition::test () const
{
-#ifndef FG_OLD_WEATHER
- return WeatherDatabase->getWeatherVisibility();
-#else
- return current_weather.get_visibility();
-#endif
+ return !(_condition->test());
}
-/**
- * Set the current visibility (meters).
- */
-static void
-setVisibility (double visibility)
+\f
+////////////////////////////////////////////////////////////////////////
+// Implementation of FGAndCondition.
+////////////////////////////////////////////////////////////////////////
+
+FGAndCondition::FGAndCondition ()
{
-#ifndef FG_OLD_WEATHER
- WeatherDatabase->setWeatherVisibility(visibility);
-#else
- current_weather.set_visibility(visibility);
-#endif
}
-/**
- * Get the current wind north velocity (feet/second).
- */
-static double
-getWindNorth ()
+FGAndCondition::~FGAndCondition ()
{
- return current_aircraft.fdm_state->get_V_north_airmass();
+ for (unsigned int i = 0; i < _conditions.size(); i++)
+ delete _conditions[i];
}
-
-/**
- * Set the current wind north velocity (feet/second).
- */
-static void
-setWindNorth (double speed)
+bool
+FGAndCondition::test () const
{
- current_aircraft.fdm_state
- ->set_Velocities_Local_Airmass(speed, getWindEast(), getWindDown());
+ int nConditions = _conditions.size();
+ for (int i = 0; i < nConditions; i++) {
+ if (!_conditions[i]->test())
+ return false;
+ }
+ return true;
}
-
-/**
- * Get the current wind east velocity (feet/second).
- */
-static double
-getWindEast ()
+void
+FGAndCondition::addCondition (FGCondition * condition)
{
- return current_aircraft.fdm_state->get_V_east_airmass();
+ _conditions.push_back(condition);
}
-/**
- * Set the current wind east velocity (feet/second).
- */
-static void
-setWindEast (double speed)
+\f
+////////////////////////////////////////////////////////////////////////
+// Implementation of FGOrCondition.
+////////////////////////////////////////////////////////////////////////
+
+FGOrCondition::FGOrCondition ()
{
- cout << "Set wind-east to " << speed << endl;
- current_aircraft.fdm_state->set_Velocities_Local_Airmass(getWindNorth(),
- speed,
- getWindDown());
}
-
-/**
- * Get the current wind down velocity (feet/second).
- */
-static double
-getWindDown ()
+FGOrCondition::~FGOrCondition ()
{
- return current_aircraft.fdm_state->get_V_down_airmass();
+ for (unsigned int i = 0; i < _conditions.size(); i++)
+ delete _conditions[i];
}
-
-/**
- * Set the current wind down velocity (feet/second).
- */
-static void
-setWindDown (double speed)
+bool
+FGOrCondition::test () const
{
- current_aircraft.fdm_state->set_Velocities_Local_Airmass(getWindNorth(),
- getWindEast(),
- speed);
+ int nConditions = _conditions.size();
+ for (int i = 0; i < nConditions; i++) {
+ if (_conditions[i]->test())
+ return true;
+ }
+ return false;
}
-static double
-getFOV ()
+void
+FGOrCondition::addCondition (FGCondition * condition)
{
- return globals->get_current_view()->get_fov();
+ _conditions.push_back(condition);
}
-static void
-setFOV (double fov)
-{
- globals->get_current_view()->set_fov( fov );
+
+\f
+////////////////////////////////////////////////////////////////////////
+// Implementation of FGComparisonCondition.
+////////////////////////////////////////////////////////////////////////
+
+static int
+doComparison (const SGPropertyNode * left, const SGPropertyNode *right)
+{
+ switch (left->getType()) {
+ case SGPropertyNode::BOOL: {
+ bool v1 = left->getBoolValue();
+ bool v2 = right->getBoolValue();
+ if (v1 < v2)
+ return FGComparisonCondition::LESS_THAN;
+ else if (v1 > v2)
+ return FGComparisonCondition::GREATER_THAN;
+ else
+ return FGComparisonCondition::EQUALS;
+ break;
+ }
+ case SGPropertyNode::INT: {
+ int v1 = left->getIntValue();
+ int v2 = right->getIntValue();
+ if (v1 < v2)
+ return FGComparisonCondition::LESS_THAN;
+ else if (v1 > v2)
+ return FGComparisonCondition::GREATER_THAN;
+ else
+ return FGComparisonCondition::EQUALS;
+ break;
+ }
+ case SGPropertyNode::LONG: {
+ long v1 = left->getLongValue();
+ long v2 = right->getLongValue();
+ if (v1 < v2)
+ return FGComparisonCondition::LESS_THAN;
+ else if (v1 > v2)
+ return FGComparisonCondition::GREATER_THAN;
+ else
+ return FGComparisonCondition::EQUALS;
+ break;
+ }
+ case SGPropertyNode::FLOAT: {
+ float v1 = left->getFloatValue();
+ float v2 = right->getFloatValue();
+ if (v1 < v2)
+ return FGComparisonCondition::LESS_THAN;
+ else if (v1 > v2)
+ return FGComparisonCondition::GREATER_THAN;
+ else
+ return FGComparisonCondition::EQUALS;
+ break;
+ }
+ case SGPropertyNode::DOUBLE: {
+ double v1 = left->getDoubleValue();
+ double v2 = right->getDoubleValue();
+ if (v1 < v2)
+ return FGComparisonCondition::LESS_THAN;
+ else if (v1 > v2)
+ return FGComparisonCondition::GREATER_THAN;
+ else
+ return FGComparisonCondition::EQUALS;
+ break;
+ }
+ case SGPropertyNode::STRING:
+ case SGPropertyNode::NONE:
+ case SGPropertyNode::UNSPECIFIED: {
+ string v1 = left->getStringValue();
+ string v2 = right->getStringValue();
+ if (v1 < v2)
+ return FGComparisonCondition::LESS_THAN;
+ else if (v1 > v2)
+ return FGComparisonCondition::GREATER_THAN;
+ else
+ return FGComparisonCondition::EQUALS;
+ break;
+ }
+ }
+ throw sg_exception("Unrecognized node type");
+ return 0;
}
-static long
-getWarp ()
+
+FGComparisonCondition::FGComparisonCondition (Type type, bool reverse)
+ : _type(type),
+ _reverse(reverse),
+ _left_property(0),
+ _right_property(0),
+ _right_value(0)
{
- return globals->get_warp();
}
-static void
-setWarp (long warp)
+FGComparisonCondition::~FGComparisonCondition ()
{
- globals->set_warp(warp);
+ delete _right_value;
}
-static long
-getWarpDelta ()
+bool
+FGComparisonCondition::test () const
{
- return globals->get_warp_delta();
+ // Always fail if incompletely specified
+ if (_left_property == 0 ||
+ (_right_property == 0 && _right_value == 0))
+ return false;
+
+ // Get LESS_THAN, EQUALS, or GREATER_THAN
+ int cmp =
+ doComparison(_left_property,
+ (_right_property != 0 ? _right_property : _right_value));
+ if (!_reverse)
+ return (cmp == _type);
+ else
+ return (cmp != _type);
}
-static void
-setWarpDelta (long delta)
+void
+FGComparisonCondition::setLeftProperty (const string &propname)
{
- globals->set_warp_delta(delta);
+ _left_property = fgGetNode(propname, true);
}
-static void
-setViewAxisLong (double axis)
+void
+FGComparisonCondition::setRightProperty (const string &propname)
{
- axisLong = axis;
+ delete _right_value;
+ _right_value = 0;
+ _right_property = fgGetNode(propname, true);
}
-static void
-setViewAxisLat (double axis)
+void
+FGComparisonCondition::setRightValue (const SGPropertyNode *node)
{
- axisLat = axis;
+ _right_property = 0;
+ delete _right_value;
+ _right_value = new SGPropertyNode(*node);
}
-void
-fgInitProps ()
-{
- // Simulation
- fgTie("/sim/freeze", getFreeze, setFreeze);
- fgTie("/sim/aircraft-dir", getAircraftDir, setAircraftDir);
- fgTie("/sim/view/offset-deg", getViewOffset, setViewOffset);
- fgTie("/sim/view/goal-offset-deg", getGoalViewOffset, setGoalViewOffset);
- fgTie("/sim/time/gmt", getDateString, setDateString);
- fgTie("/sim/time/gmt-string", getGMTString);
- fgTie("/sim/rendering/textures", getTextures, setTextures);
+\f
+////////////////////////////////////////////////////////////////////////
+// Read a condition and use it if necessary.
+////////////////////////////////////////////////////////////////////////
- // Orientation
- fgTie("/orientation/heading-magnetic-deg", getHeadingMag);
+ // Forward declaration
+static FGCondition * readCondition (const SGPropertyNode * node);
- // Engine
- fgTie("/engines/engine[0]/rpm", getRPM);
- fgTie("/engines/engine[0]/egt-degf", getEGT);
- fgTie("/engines/engine[0]/cht-degf", getCHT);
- fgTie("/engines/engine[0]/mp-osi", getMP);
- fgTie("/engines/engine[0]/fuel-flow-gph", getFuelFlow);
-
- //consumables
- fgTie("/consumables/fuel/tank[0]/level-gal_us", getTank1Fuel, setTank1Fuel, false);
- fgTie("/consumables/fuel/tank2/level-gal_us", getTank2Fuel, setTank2Fuel, false);
-
- // Autopilot
- fgTie("/autopilot/locks/altitude", getAPAltitudeLock, setAPAltitudeLock);
- fgTie("/autopilot/settings/altitude-ft", getAPAltitude, setAPAltitude);
- fgTie("/autopilot/locks/glide-slope", getAPGSLock, setAPGSLock);
- fgTie("/autopilot/locks/terrain", getAPTerrainLock, setAPTerrainLock);
- fgTie("/autopilot/settings/climb-rate-fpm", getAPClimb, setAPClimb, false);
- fgTie("/autopilot/locks/heading", getAPHeadingLock, setAPHeadingLock);
- fgTie("/autopilot/settings/heading-bug-deg", getAPHeadingBug, setAPHeadingBug,
- false);
- fgTie("/autopilot/locks/wing-leveler", getAPWingLeveler, setAPWingLeveler);
- fgTie("/autopilot/locks/nav[0]", getAPNAV1Lock, setAPNAV1Lock);
- fgTie("/autopilot/locks/auto-throttle",
- getAPAutoThrottleLock, setAPAutoThrottleLock);
- fgTie("/autopilot/control-overrides/rudder",
- getAPRudderControl, setAPRudderControl);
- fgTie("/autopilot/control-overrides/elevator",
- getAPElevatorControl, setAPElevatorControl);
- fgTie("/autopilot/control-overrides/throttle",
- getAPThrottleControl, setAPThrottleControl);
+static FGCondition *
+readPropertyCondition (const SGPropertyNode * node)
+{
+ return new FGPropertyCondition(node->getStringValue());
+}
- // Environment
- fgTie("/environment/visibility-m", getVisibility, setVisibility);
- fgTie("/environment/wind-north-fps", getWindNorth, setWindNorth);
- fgTie("/environment/wind-east-fps", getWindEast, setWindEast);
- fgTie("/environment/wind-down-fps", getWindDown, setWindDown);
- fgTie("/environment/magnetic-variation-deg", getMagVar);
- fgTie("/environment/magnetic-dip-deg", getMagDip);
+static FGCondition *
+readNotCondition (const SGPropertyNode * node)
+{
+ int nChildren = node->nChildren();
+ for (int i = 0; i < nChildren; i++) {
+ const SGPropertyNode * child = node->getChild(i);
+ FGCondition * condition = readCondition(child);
+ if (condition != 0)
+ return new FGNotCondition(condition);
+ }
+ SG_LOG(SG_COCKPIT, SG_ALERT, "Panel: empty 'not' condition");
+ return 0;
+}
- // View
- fgTie("/sim/field-of-view", getFOV, setFOV);
- fgTie("/sim/time/warp", getWarp, setWarp, false);
- fgTie("/sim/time/warp-delta", getWarpDelta, setWarpDelta);
- fgTie("/sim/view/axes/long", (double(*)())0, setViewAxisLong);
- fgTie("/sim/view/axes/lat", (double(*)())0, setViewAxisLat);
+static FGCondition *
+readAndConditions (const SGPropertyNode * node)
+{
+ FGAndCondition * andCondition = new FGAndCondition;
+ int nChildren = node->nChildren();
+ for (int i = 0; i < nChildren; i++) {
+ const SGPropertyNode * child = node->getChild(i);
+ FGCondition * condition = readCondition(child);
+ if (condition != 0)
+ andCondition->addCondition(condition);
+ }
+ return andCondition;
}
+static FGCondition *
+readOrConditions (const SGPropertyNode * node)
+{
+ FGOrCondition * orCondition = new FGOrCondition;
+ int nChildren = node->nChildren();
+ for (int i = 0; i < nChildren; i++) {
+ const SGPropertyNode * child = node->getChild(i);
+ FGCondition * condition = readCondition(child);
+ if (condition != 0)
+ orCondition->addCondition(condition);
+ }
+ return orCondition;
+}
-void
-fgUpdateProps ()
+static FGCondition *
+readComparison (const SGPropertyNode * node,
+ FGComparisonCondition::Type type,
+ bool reverse)
{
- _set_view_from_axes();
+ FGComparisonCondition * condition = new FGComparisonCondition(type, reverse);
+ condition->setLeftProperty(node->getStringValue("property[0]"));
+ if (node->hasValue("property[1]"))
+ condition->setRightProperty(node->getStringValue("property[1]"));
+ else
+ condition->setRightValue(node->getChild("value", 0));
+
+ return condition;
+}
+
+static FGCondition *
+readCondition (const SGPropertyNode * node)
+{
+ const string &name = node->getName();
+ if (name == "property")
+ return readPropertyCondition(node);
+ else if (name == "not")
+ return readNotCondition(node);
+ else if (name == "and")
+ return readAndConditions(node);
+ else if (name == "or")
+ return readOrConditions(node);
+ else if (name == "less-than")
+ return readComparison(node, FGComparisonCondition::LESS_THAN, false);
+ else if (name == "less-than-equals")
+ return readComparison(node, FGComparisonCondition::GREATER_THAN, true);
+ else if (name == "greater-than")
+ return readComparison(node, FGComparisonCondition::GREATER_THAN, false);
+ else if (name == "greater-than-equals")
+ return readComparison(node, FGComparisonCondition::LESS_THAN, true);
+ else if (name == "equals")
+ return readComparison(node, FGComparisonCondition::EQUALS, false);
+ else if (name == "not-equals")
+ return readComparison(node, FGComparisonCondition::EQUALS, true);
+ else
+ return 0;
}
\f
////////////////////////////////////////////////////////////////////////
-// Save and restore.
+// Implementation of FGConditional.
////////////////////////////////////////////////////////////////////////
+FGConditional::FGConditional ()
+ : _condition (0)
+{
+}
-/**
- * Save the current state of the simulator to a stream.
- */
-bool
-fgSaveFlight (ostream &output)
+FGConditional::~FGConditional ()
{
- return writeProperties(output, globals->get_props());
+ delete _condition;
}
+void
+FGConditional::setCondition (FGCondition * condition)
+{
+ delete _condition;
+ _condition = condition;
+}
-/**
- * Restore the current state of the simulator from a stream.
- */
bool
-fgLoadFlight (istream &input)
+FGConditional::test () const
{
- SGPropertyNode props;
- if (readProperties(input, &props)) {
- copyProperties(&props, globals->get_props());
- // When loading a flight, make it the
- // new initial state.
- globals->saveInitialState();
- } else {
- SG_LOG(SG_INPUT, SG_ALERT, "Error restoring flight; aborted");
- return false;
- }
+ return ((_condition == 0) || _condition->test());
+}
- return true;
+
+\f
+// The top-level is always an implicit 'and' group
+FGCondition *
+fgReadCondition (const SGPropertyNode * node)
+{
+ return readAndConditions(node);
}
+
// end of fg_props.cxx