Support <expression> in autopilot inputs, as well as property and value.
This commit is contained in:
parent
386aefe693
commit
1d0e9d268a
2 changed files with 34 additions and 9 deletions
src/Autopilot
|
@ -32,6 +32,8 @@
|
||||||
#include <simgear/sg_inlines.h>
|
#include <simgear/sg_inlines.h>
|
||||||
#include <simgear/props/props_io.hxx>
|
#include <simgear/props/props_io.hxx>
|
||||||
|
|
||||||
|
#include <simgear/structure/SGExpression.hxx>
|
||||||
|
|
||||||
#include <Main/fg_props.hxx>
|
#include <Main/fg_props.hxx>
|
||||||
#include <Main/globals.hxx>
|
#include <Main/globals.hxx>
|
||||||
#include <Main/util.hxx>
|
#include <Main/util.hxx>
|
||||||
|
@ -43,6 +45,9 @@ using std::endl;
|
||||||
|
|
||||||
using simgear::PropertyList;
|
using simgear::PropertyList;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
FGPeriodicalValue::FGPeriodicalValue( SGPropertyNode_ptr root )
|
FGPeriodicalValue::FGPeriodicalValue( SGPropertyNode_ptr root )
|
||||||
{
|
{
|
||||||
SGPropertyNode_ptr minNode = root->getChild( "min" );
|
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) :
|
FGXMLAutoInput::FGXMLAutoInput( SGPropertyNode_ptr node, double value, double offset, double scale) :
|
||||||
value(0.0),
|
value(0.0),
|
||||||
abs(false),
|
abs(false)
|
||||||
_condition(NULL)
|
|
||||||
{
|
{
|
||||||
parse( node, value, offset, scale );
|
parse( node, value, offset, scale );
|
||||||
}
|
}
|
||||||
|
@ -133,6 +137,11 @@ void FGXMLAutoInput::parse( SGPropertyNode_ptr node, double aValue, double aOffs
|
||||||
value = valueNode->getDoubleValue();
|
value = valueNode->getDoubleValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((n = node->getChild("expression")) != NULL) {
|
||||||
|
_expression = SGReadDoubleExpression(fgGetNode("/"), n->getChild(0));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
n = node->getChild( "property" );
|
n = node->getChild( "property" );
|
||||||
// if no <property> element, check for <prop> element for backwards
|
// if no <property> element, check for <prop> element for backwards
|
||||||
// compatibility
|
// compatibility
|
||||||
|
@ -150,10 +159,13 @@ void FGXMLAutoInput::parse( SGPropertyNode_ptr node, double aValue, double aOffs
|
||||||
else
|
else
|
||||||
property->setDoubleValue( 0 ); // if scale is zero, value*scale is zero
|
property->setDoubleValue( 0 ); // if scale is zero, value*scale is zero
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if ( n == NULL && valueNode == NULL ) {
|
return;
|
||||||
// no <value> element and no <prop> element, use text node
|
} // of have a <property> or <prop>
|
||||||
|
|
||||||
|
|
||||||
|
if (valueNode == NULL) {
|
||||||
|
// no <value>, <prop> or <expression> element, use text node
|
||||||
const char * textnode = node->getStringValue();
|
const char * textnode = node->getStringValue();
|
||||||
char * endp = NULL;
|
char * endp = NULL;
|
||||||
// try to convert to a double value. If the textnode does not start with a number
|
// 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 )
|
void FGXMLAutoInput::set_value( double aValue )
|
||||||
{
|
{
|
||||||
|
if (!property)
|
||||||
|
return;
|
||||||
|
|
||||||
double s = get_scale();
|
double s = get_scale();
|
||||||
if( s != 0 )
|
if( s != 0 )
|
||||||
property->setDoubleValue( (aValue - get_offset())/s );
|
property->setDoubleValue( (aValue - get_offset())/s );
|
||||||
|
@ -177,8 +192,12 @@ void FGXMLAutoInput::set_value( double aValue )
|
||||||
|
|
||||||
double FGXMLAutoInput::get_value()
|
double FGXMLAutoInput::get_value()
|
||||||
{
|
{
|
||||||
if( property != NULL )
|
if (_expression) {
|
||||||
|
// compute the expression value
|
||||||
|
value = _expression->getValue(NULL);
|
||||||
|
} else if( property != NULL ) {
|
||||||
value = property->getDoubleValue();
|
value = property->getDoubleValue();
|
||||||
|
}
|
||||||
|
|
||||||
if( scale )
|
if( scale )
|
||||||
value *= scale->get_value();
|
value *= scale->get_value();
|
||||||
|
|
|
@ -47,7 +47,12 @@ and writes properties used only by a few aircraft.
|
||||||
|
|
||||||
#include <simgear/props/props.hxx>
|
#include <simgear/props/props.hxx>
|
||||||
#include <simgear/structure/subsystem_mgr.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 FGXMLAutoInput> FGXMLAutoInput_ptr;
|
||||||
typedef SGSharedPtr<class FGPeriodicalValue> FGPeriodicalValue_ptr;
|
typedef SGSharedPtr<class FGPeriodicalValue> FGPeriodicalValue_ptr;
|
||||||
|
@ -72,6 +77,7 @@ private:
|
||||||
FGXMLAutoInput_ptr max; // A maximum clip defaults to no clipping
|
FGXMLAutoInput_ptr max; // A maximum clip defaults to no clipping
|
||||||
FGPeriodicalValue_ptr periodical; //
|
FGPeriodicalValue_ptr periodical; //
|
||||||
SGSharedPtr<const SGCondition> _condition;
|
SGSharedPtr<const SGCondition> _condition;
|
||||||
|
SGSharedPtr<SGExpressiond> _expression; ///< expression to generate the value
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FGXMLAutoInput( SGPropertyNode_ptr node = NULL, double value = 0.0, double offset = 0.0, double scale = 1.0 );
|
FGXMLAutoInput( SGPropertyNode_ptr node = NULL, double value = 0.0, double offset = 0.0, double scale = 1.0 );
|
||||||
|
|
Loading…
Add table
Reference in a new issue