]> git.mxchange.org Git - flightgear.git/commitdiff
Added support for <condition> elements under <enable> elements.
authortorsten <torsten>
Sat, 28 Feb 2009 16:16:13 +0000 (16:16 +0000)
committerTim Moore <timoore@redhat.com>
Thu, 5 Mar 2009 09:52:02 +0000 (10:52 +0100)
The old <prop> and <value> elements are still supported but ignored, if a <condition> element exists.

src/Autopilot/xmlauto.cxx
src/Autopilot/xmlauto.hxx

index fec641f541fc6f839543e7acdf2cf269854259e3..a5adb1c3de0f4458c58dab846f9f7ef97d8554d8 100644 (file)
 using std::cout;
 using std::endl;
 
+static SGCondition * getCondition( SGPropertyNode * node )
+{
+   const SGPropertyNode* conditionNode = node->getChild("condition");
+   return conditionNode ? sgReadCondition(node, conditionNode) : NULL;
+}
+
 FGPIDController::FGPIDController( SGPropertyNode *node ):
     debug( false ),
     y_n( 0.0 ),
@@ -73,17 +79,20 @@ FGPIDController::FGPIDController( SGPropertyNode *node ):
         } else if ( cname == "debug" ) {
             debug = child->getBoolValue();
         } else if ( cname == "enable" ) {
-            // cout << "parsing enable" << endl;
-            SGPropertyNode *prop = child->getChild( "prop" );
-            if ( prop != NULL ) {
-                // cout << "prop = " << prop->getStringValue() << endl;
-                enable_prop = fgGetNode( prop->getStringValue(), true );
-            } else {
-                // cout << "no prop child" << endl;
-            }
-            SGPropertyNode *val = child->getChild( "value" );
-            if ( val != NULL ) {
-                enable_value = val->getStringValue();
+            _condition = getCondition( child );
+            if( _condition == NULL ) {
+               // cout << "parsing enable" << endl;
+               SGPropertyNode *prop = child->getChild( "prop" );
+               if ( prop != NULL ) {
+                   // cout << "prop = " << prop->getStringValue() << endl;
+                   enable_prop = fgGetNode( prop->getStringValue(), true );
+               } else {
+                   // cout << "no prop child" << endl;
+               }
+               SGPropertyNode *val = child->getChild( "value" );
+               if ( val != NULL ) {
+                   enable_value = val->getStringValue();
+               }
             }
             SGPropertyNode *pass = child->getChild( "honor-passive" );
             if ( pass != NULL ) {
@@ -359,7 +368,8 @@ void FGPIDController::update( double dt ) {
     Ts = elapsedTime;
     elapsedTime = 0.0;
 
-    if (enable_prop != NULL && enable_prop->getStringValue() == enable_value) {
+    if (( _condition && _condition->test() ) ||
+        (enable_prop != NULL && enable_prop->getStringValue() == enable_value)) {
         if ( !enabled ) {
             // first time being enabled, seed u_n with current
             // property tree value
@@ -507,17 +517,20 @@ FGPISimpleController::FGPISimpleController( SGPropertyNode *node ):
         } else if ( cname == "debug" ) {
             debug = child->getBoolValue();
         } else if ( cname == "enable" ) {
-            // cout << "parsing enable" << endl;
-            SGPropertyNode *prop = child->getChild( "prop" );
-            if ( prop != NULL ) {
-                // cout << "prop = " << prop->getStringValue() << endl;
-                enable_prop = fgGetNode( prop->getStringValue(), true );
-            } else {
-                // cout << "no prop child" << endl;
-            }
-            SGPropertyNode *val = child->getChild( "value" );
-            if ( val != NULL ) {
-                enable_value = val->getStringValue();
+            _condition = getCondition( child );
+            if( _condition == NULL ) {
+               // cout << "parsing enable" << endl;
+               SGPropertyNode *prop = child->getChild( "prop" );
+               if ( prop != NULL ) {
+                   // cout << "prop = " << prop->getStringValue() << endl;
+                   enable_prop = fgGetNode( prop->getStringValue(), true );
+               } else {
+                   // cout << "no prop child" << endl;
+               }
+               SGPropertyNode *val = child->getChild( "value" );
+               if ( val != NULL ) {
+                   enable_value = val->getStringValue();
+               }
             }
         } else if ( cname == "input" ) {
             SGPropertyNode *prop = child->getChild( "prop" );
@@ -642,7 +655,8 @@ void FGPISimpleController::update( double dt ) {
     if (umax_prop != NULL)u_max = umax_prop->getDoubleValue();
     if (Kp_prop != NULL)Kp = Kp_prop->getDoubleValue();
 
-    if (enable_prop != NULL && enable_prop->getStringValue() == enable_value) {
+    if (( _condition && _condition->test() ) ||
+        (enable_prop != NULL && enable_prop->getStringValue() == enable_value)) {
         if ( !enabled ) {
             // we have just been enabled, zero out int_sum
             int_sum = 0.0;
index 07d5dd7ced1fa62562122b191f642b467ae1b4b3..f9b0a62b74c0a7ccd01e323371a39284a77a8ff2 100644 (file)
@@ -44,6 +44,7 @@ using std::deque;
 
 #include <simgear/props/props.hxx>
 #include <simgear/structure/subsystem_mgr.hxx>
+#include <simgear/props/condition.hxx>
 
 #include <Main/fg_props.hxx>
 
@@ -68,6 +69,7 @@ protected:
     SGPropertyNode_ptr r_n_prop;
     double r_n_value;
     vector <SGPropertyNode_ptr> output_list;
+    SGSharedPtr<const SGCondition> _condition;
 
 public:
 
@@ -79,7 +81,8 @@ public:
       enabled( false ),
       input_prop( NULL ),
       r_n_prop( NULL ),
-      r_n_value( 0.0 )
+      r_n_value( 0.0 ),
+      _condition( NULL )
     { }
 
     virtual ~FGXMLAutoComponent() {}