From: James Turner Date: Wed, 26 May 2010 18:30:33 +0000 (+0100) Subject: Support in autopilot inputs, as well as property and value. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=1d0e9d268a748361de0db8f9fc6f3e86aa756e1e;p=flightgear.git Support in autopilot inputs, as well as property and value. --- diff --git a/src/Autopilot/xmlauto.cxx b/src/Autopilot/xmlauto.cxx index 56df5cf86..e1bedb568 100644 --- a/src/Autopilot/xmlauto.cxx +++ b/src/Autopilot/xmlauto.cxx @@ -32,6 +32,8 @@ #include #include +#include + #include
#include
#include
@@ -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 element, check for 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 or - if ( n == NULL && valueNode == NULL ) { - // no element and no element, use text node + + if (valueNode == NULL) { + // no , or 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(); diff --git a/src/Autopilot/xmlauto.hxx b/src/Autopilot/xmlauto.hxx index ccc17ee56..c1b49d23d 100644 --- a/src/Autopilot/xmlauto.hxx +++ b/src/Autopilot/xmlauto.hxx @@ -47,7 +47,12 @@ and writes properties used only by a few aircraft. #include #include -#include + +template +class SGExpression; + +typedef SGExpression SGExpressiond; +class SGCondition; typedef SGSharedPtr FGXMLAutoInput_ptr; typedef SGSharedPtr FGPeriodicalValue_ptr; @@ -72,7 +77,8 @@ private: FGXMLAutoInput_ptr max; // A maximum clip defaults to no clipping FGPeriodicalValue_ptr periodical; // SGSharedPtr _condition; - + SGSharedPtr _expression; ///< expression to generate the value + public: FGXMLAutoInput( SGPropertyNode_ptr node = NULL, double value = 0.0, double offset = 0.0, double scale = 1.0 );