+
+
+
+\f
+////////////////////////////////////////////////////////////////////////
+// Kludged methods for tying to properties.
+//
+// These should change eventually; they all used to be static
+// functions.
+////////////////////////////////////////////////////////////////////////
+
+/**
+ * Get the autopilot altitude lock (true=on).
+ */
+bool
+FGAutopilot::getAPAltitudeLock () const
+{
+ return (get_AltitudeEnabled() &&
+ get_AltitudeMode()
+ == FGAutopilot::FG_ALTITUDE_LOCK);
+}
+
+
+/**
+ * Set the autopilot altitude lock (true=on).
+ */
+void
+FGAutopilot::setAPAltitudeLock (bool lock)
+{
+ if (lock)
+ set_AltitudeMode(FGAutopilot::FG_ALTITUDE_LOCK);
+ if (get_AltitudeMode() == FGAutopilot::FG_ALTITUDE_LOCK)
+ set_AltitudeEnabled(lock);
+}
+
+
+/**
+ * Get the autopilot target altitude in feet.
+ */
+double
+FGAutopilot::getAPAltitude () const
+{
+ return get_TargetAltitude() * SG_METER_TO_FEET;
+}
+
+
+/**
+ * Set the autopilot target altitude in feet.
+ */
+void
+FGAutopilot::setAPAltitude (double altitude)
+{
+ set_TargetAltitude( altitude * SG_FEET_TO_METER );
+}
+
+/**
+ * Get the autopilot altitude lock (true=on).
+ */
+bool
+FGAutopilot::getAPGSLock () const
+{
+ return (get_AltitudeEnabled() &&
+ (get_AltitudeMode()
+ == FGAutopilot::FG_ALTITUDE_GS1));
+}
+
+
+/**
+ * Set the autopilot altitude lock (true=on).
+ */
+void
+FGAutopilot::setAPGSLock (bool lock)
+{
+ if (lock)
+ set_AltitudeMode(FGAutopilot::FG_ALTITUDE_GS1);
+ if (get_AltitudeMode() == FGAutopilot::FG_ALTITUDE_GS1)
+ set_AltitudeEnabled(lock);
+}
+
+
+/**
+ * Get the autopilot terrain lock (true=on).
+ */
+bool
+FGAutopilot::getAPTerrainLock () const
+{
+ return (get_AltitudeEnabled() &&
+ (get_AltitudeMode()
+ == FGAutopilot::FG_ALTITUDE_TERRAIN));
+}
+
+
+/**
+ * Set the autopilot terrain lock (true=on).
+ */
+void
+FGAutopilot::setAPTerrainLock (bool lock)
+{
+ if (lock) {
+ set_AltitudeMode(FGAutopilot::FG_ALTITUDE_TERRAIN);
+ set_TargetAGL(fgGetFloat("/position/altitude-agl-ft") *
+ SG_FEET_TO_METER);
+ }
+ if (get_AltitudeMode() == FGAutopilot::FG_ALTITUDE_TERRAIN)
+ set_AltitudeEnabled(lock);
+}
+
+
+/**
+ * Get the autopilot target altitude in feet.
+ */
+double
+FGAutopilot::getAPClimb () const
+{
+ return get_TargetClimbRate() * SG_METER_TO_FEET;
+}
+
+
+/**
+ * Set the autopilot target altitude in feet.
+ */
+void
+FGAutopilot::setAPClimb (double rate)
+{
+ set_TargetClimbRate( rate * SG_FEET_TO_METER );
+}
+
+
+/**
+ * Get the autopilot heading lock (true=on).
+ */
+bool
+FGAutopilot::getAPHeadingLock () const
+{
+ return
+ (get_HeadingEnabled() &&
+ get_HeadingMode() == DEFAULT_AP_HEADING_LOCK);
+}
+
+
+/**
+ * Set the autopilot heading lock (true=on).
+ */
+void
+FGAutopilot::setAPHeadingLock (bool lock)
+{
+ if (lock)
+ set_HeadingMode(DEFAULT_AP_HEADING_LOCK);
+ if (get_HeadingMode() == DEFAULT_AP_HEADING_LOCK)
+ set_HeadingEnabled(lock);
+}
+
+
+/**
+ * Get the autopilot heading bug in degrees.
+ */
+double
+FGAutopilot::getAPHeadingBug () const
+{
+ return get_DGTargetHeading();
+}
+
+
+/**
+ * Set the autopilot heading bug in degrees.
+ */
+void
+FGAutopilot::setAPHeadingBug (double heading)
+{
+ set_DGTargetHeading( heading );
+}
+
+
+/**
+ * Get the autopilot wing leveler lock (true=on).
+ */
+bool
+FGAutopilot::getAPWingLeveler () const
+{
+ return
+ (get_HeadingEnabled() &&
+ get_HeadingMode() == FGAutopilot::FG_TC_HEADING_LOCK);
+}
+
+
+/**
+ * Set the autopilot wing leveler lock (true=on).
+ */
+void
+FGAutopilot::setAPWingLeveler (bool lock)
+{
+ if (lock)
+ set_HeadingMode(FGAutopilot::FG_TC_HEADING_LOCK);
+ if (get_HeadingMode() == FGAutopilot::FG_TC_HEADING_LOCK)
+ set_HeadingEnabled(lock);
+}
+
+/**
+ * Return true if the autopilot is locked to NAV1.
+ */
+bool
+FGAutopilot::getAPNAV1Lock () const
+{
+ return
+ (get_HeadingEnabled() &&
+ get_HeadingMode() == FGAutopilot::FG_HEADING_NAV1);
+}
+
+
+/**
+ * Set the autopilot NAV1 lock.
+ */
+void
+FGAutopilot::setAPNAV1Lock (bool lock)
+{
+ if (lock)
+ set_HeadingMode(FGAutopilot::FG_HEADING_NAV1);
+ if (get_HeadingMode() == FGAutopilot::FG_HEADING_NAV1)
+ set_HeadingEnabled(lock);
+}
+
+/**
+ * Get the autopilot autothrottle lock.
+ */
+bool
+FGAutopilot::getAPAutoThrottleLock () const
+{
+ return get_AutoThrottleEnabled();
+}
+
+
+/**
+ * Set the autothrottle lock.
+ */
+void
+FGAutopilot::setAPAutoThrottleLock (bool lock)
+{
+ set_AutoThrottleEnabled(lock);
+}
+
+
+// kludge
+double
+FGAutopilot::getAPRudderControl () const
+{
+ if (getAPHeadingLock())
+ return get_TargetHeading();
+ else
+ return globals->get_controls()->get_rudder();
+}
+
+// kludge
+void
+FGAutopilot::setAPRudderControl (double value)
+{
+ if (getAPHeadingLock()) {
+ SG_LOG(SG_GENERAL, SG_DEBUG, "setAPRudderControl " << value );
+ value -= get_TargetHeading();
+ HeadingAdjust(value < 0.0 ? -1.0 : 1.0);
+ } else {
+ globals->get_controls()->set_rudder(value);
+ }
+}
+
+// kludge
+double
+FGAutopilot::getAPElevatorControl () const
+{
+ if (getAPAltitudeLock())
+ return get_TargetAltitude();
+ else
+ return globals->get_controls()->get_elevator();
+}
+
+// kludge
+void
+FGAutopilot::setAPElevatorControl (double value)
+{
+ if (value != 0 && getAPAltitudeLock()) {
+ SG_LOG(SG_GENERAL, SG_DEBUG, "setAPElevatorControl " << value );
+ value -= get_TargetAltitude();
+ AltitudeAdjust(value < 0.0 ? 100.0 : -100.0);
+ } else {
+ globals->get_controls()->set_elevator(value);
+ }
+}
+
+// kludge
+double
+FGAutopilot::getAPThrottleControl () const
+{
+ if (getAPAutoThrottleLock())
+ return 0.0; // always resets
+ else
+ return globals->get_controls()->get_throttle(0);
+}
+
+// kludge
+void
+FGAutopilot::setAPThrottleControl (double value)
+{
+ if (getAPAutoThrottleLock())
+ AutoThrottleAdjust(value < 0.0 ? -0.01 : 0.01);
+ else
+ globals->get_controls()->set_throttle(FGControls::ALL_ENGINES, value);
+}
+
+// end of newauto.cxx
+