]> git.mxchange.org Git - flightgear.git/commitdiff
Support <expression> in autopilot inputs, as well as property and value.
authorJames Turner <zakalawe@mac.com>
Wed, 26 May 2010 18:30:33 +0000 (19:30 +0100)
committerJames Turner <zakalawe@mac.com>
Wed, 26 May 2010 18:30:33 +0000 (19:30 +0100)
src/Autopilot/xmlauto.cxx
src/Autopilot/xmlauto.hxx

index 56df5cf86ae309beb5934c0948dffc14fe469994..e1bedb5688cdb5c8152011fedb6c8137d2987f6a 100644 (file)
@@ -32,6 +32,8 @@
 #include <simgear/sg_inlines.h>
 #include <simgear/props/props_io.hxx>
 
+#include <simgear/structure/SGExpression.hxx>
+
 #include <Main/fg_props.hxx>
 #include <Main/globals.hxx>
 #include <Main/util.hxx>
@@ -43,6 +45,9 @@ using std::endl;
 
 using simgear::PropertyList;
 
+
+
+
 FGPeriodicalValue::FGPeriodicalValue( SGPropertyNode_ptr root )
 {
   SGPropertyNode_ptr minNode = root->getChild( "min" );
@@ -78,8 +83,7 @@ double FGPeriodicalValue::normalize( double value )
 
 FGXMLAutoInput::FGXMLAutoInput( SGPropertyNode_ptr node, double value, double offset, double scale) :
   value(0.0),
-  abs(false),
-  _condition(NULL) 
+  abs(false)
 {
   parse( node, value, offset, scale );
 }
@@ -133,6 +137,11 @@ void FGXMLAutoInput::parse( SGPropertyNode_ptr node, double aValue, double aOffs
         value = valueNode->getDoubleValue();
     }
 
+    if ((n = node->getChild("expression")) != NULL) {
+      _expression = SGReadDoubleExpression(fgGetNode("/"), n->getChild(0));
+      return;
+    }
+    
     n = node->getChild( "property" );
     // if no <property> element, check for <prop> element for backwards
     // compatibility
@@ -150,10 +159,13 @@ void FGXMLAutoInput::parse( SGPropertyNode_ptr node, double aValue, double aOffs
             else
               property->setDoubleValue( 0 ); // if scale is zero, value*scale is zero
         }
-    }
+        
+        return;
+    } // of have a <property> or <prop>
 
-    if ( n == NULL && valueNode == NULL ) {
-        // no <value> element and no <prop> element, use text node 
+    
+    if (valueNode == NULL) {
+        // no <value>, <prop> or <expression> element, use text node 
         const char * textnode = node->getStringValue();
         char * endp = NULL;
         // try to convert to a double value. If the textnode does not start with a number
@@ -168,6 +180,9 @@ void FGXMLAutoInput::parse( SGPropertyNode_ptr node, double aValue, double aOffs
 
 void FGXMLAutoInput::set_value( double aValue ) 
 {
+    if (!property)
+      return;
+      
     double s = get_scale();
     if( s != 0 )
         property->setDoubleValue( (aValue - get_offset())/s );
@@ -177,9 +192,13 @@ void FGXMLAutoInput::set_value( double aValue )
 
 double FGXMLAutoInput::get_value() 
 {
-    if( property != NULL ) 
+    if (_expression) {
+        // compute the expression value
+        value = _expression->getValue(NULL);
+    } else if( property != NULL ) {
         value = property->getDoubleValue();
-
+    }
+    
     if( scale ) 
         value *= scale->get_value();
 
index ccc17ee5667675dde3c26733563d7b95fe989444..c1b49d23d51b51435d21be8d844e01219c6fbe5e 100644 (file)
@@ -47,7 +47,12 @@ and writes properties used only by a few aircraft.
 
 #include <simgear/props/props.hxx>
 #include <simgear/structure/subsystem_mgr.hxx>
-#include <simgear/props/condition.hxx>
+
+template<typename T>
+class SGExpression;
+
+typedef SGExpression<double> SGExpressiond;
+class SGCondition;
 
 typedef SGSharedPtr<class FGXMLAutoInput> FGXMLAutoInput_ptr;
 typedef SGSharedPtr<class FGPeriodicalValue> FGPeriodicalValue_ptr;
@@ -72,7 +77,8 @@ private:
      FGXMLAutoInput_ptr max;      // A maximum clip defaults to no clipping
      FGPeriodicalValue_ptr  periodical; //
      SGSharedPtr<const SGCondition> _condition;
-
+     SGSharedPtr<SGExpressiond> _expression;  ///< expression to generate the value
+     
 public:
     FGXMLAutoInput( SGPropertyNode_ptr node = NULL, double value = 0.0, double offset = 0.0, double scale = 1.0 );