From 3f0e9b016183d17bd0b5b259db83be5191899008 Mon Sep 17 00:00:00 2001 From: torsten Date: Sat, 28 Feb 2009 16:16:13 +0000 Subject: [PATCH] Added support for elements under elements. The old and elements are still supported but ignored, if a element exists. --- src/Autopilot/xmlauto.cxx | 62 ++++++++++++++++++++++++--------------- src/Autopilot/xmlauto.hxx | 5 +++- 2 files changed, 42 insertions(+), 25 deletions(-) diff --git a/src/Autopilot/xmlauto.cxx b/src/Autopilot/xmlauto.cxx index fec641f54..a5adb1c3d 100644 --- a/src/Autopilot/xmlauto.cxx +++ b/src/Autopilot/xmlauto.cxx @@ -40,6 +40,12 @@ 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; diff --git a/src/Autopilot/xmlauto.hxx b/src/Autopilot/xmlauto.hxx index 07d5dd7ce..f9b0a62b7 100644 --- a/src/Autopilot/xmlauto.hxx +++ b/src/Autopilot/xmlauto.hxx @@ -44,6 +44,7 @@ using std::deque; #include #include +#include #include
@@ -68,6 +69,7 @@ protected: SGPropertyNode_ptr r_n_prop; double r_n_value; vector output_list; + SGSharedPtr _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() {} -- 2.39.5