+void FGXMLAutoInput::parse( SGPropertyNode_ptr node, double aValue, double aOffset, double aScale )
+{
+ value = aValue;
+ property = NULL;
+ offset = NULL;
+ scale = NULL;
+ min = NULL;
+ max = NULL;
+
+ if( node == NULL )
+ return;
+
+ SGPropertyNode * n;
+
+ if( (n = node->getChild("condition")) != NULL ) {
+ _condition = sgReadCondition(node, n);
+ }
+
+ if( (n = node->getChild( "scale" )) != NULL ) {
+ scale = new FGXMLAutoInput( n, aScale );
+ }
+
+ if( (n = node->getChild( "offset" )) != NULL ) {
+ offset = new FGXMLAutoInput( n, aOffset );
+ }
+
+ if( (n = node->getChild( "max" )) != NULL ) {
+ max = new FGXMLAutoInput( n );
+ }
+
+ if( (n = node->getChild( "min" )) != NULL ) {
+ min = new FGXMLAutoInput( n );
+ }
+
+ if( (n = node->getChild( "abs" )) != NULL ) {
+ abs = n->getBoolValue();
+ }
+
+ SGPropertyNode *valueNode = node->getChild( "value" );
+ if ( valueNode != NULL ) {
+ value = valueNode->getDoubleValue();
+ }
+
+ n = node->getChild( "property" );
+ // if no <property> element, check for <prop> element for backwards
+ // compatibility
+ if( n == NULL )
+ n = node->getChild( "prop" );
+
+ if ( n != NULL ) {
+ property = fgGetNode( n->getStringValue(), true );
+ if ( valueNode != NULL ) {
+ // initialize property with given value
+ // if both <prop> and <value> exist
+ double s = get_scale();
+ if( s != 0 )
+ property->setDoubleValue( (value - get_offset())/s );
+ else
+ property->setDoubleValue( 0 ); // if scale is zero, value*scale is zero
+ }
+ }
+
+ if ( n == NULL && valueNode == NULL ) {
+ // no <value> element and no <prop> 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
+ // endp will point to the beginning of the string. We assume this should be
+ // a property name
+ value = strtod( textnode, &endp );
+ if( endp == textnode ) {
+ property = fgGetNode( textnode, true );
+ }
+ }
+}
+
+void FGXMLAutoInput::set_value( double aValue )
+{
+ double s = get_scale();
+ if( s != 0 )
+ property->setDoubleValue( (aValue - get_offset())/s );
+ else
+ property->setDoubleValue( 0 ); // if scale is zero, value*scale is zero
+}
+
+double FGXMLAutoInput::get_value()
+{
+ if( property != NULL )
+ value = property->getDoubleValue();
+
+ if( scale )
+ value *= scale->get_value();
+
+ if( offset )
+ value += offset->get_value();
+
+ if( min ) {
+ double m = min->get_value();
+ if( value < m )
+ value = m;
+ }
+
+ if( max ) {
+ double m = max->get_value();
+ if( value > m )
+ value = m;
+ }
+
+ return abs ? fabs(value) : value;
+}
+
+FGXMLAutoComponent::FGXMLAutoComponent( SGPropertyNode * node ) :
+ _condition( NULL ),
+ enable_prop( NULL ),
+ enable_value( NULL ),
+ passive_mode( fgGetNode("/autopilot/locks/passive-mode", true) ),
+ honor_passive( false ),
+ name(""),
+ feedback_if_disabled( false ),
+ debug(false),
+ enabled( false )