1 // component.cxx - Base class for autopilot components
3 // Written by Torsten Dreyer
4 // Based heavily on work created by Curtis Olson, started January 2004.
6 // Copyright (C) 2004 Curtis L. Olson - http://www.flightgear.org/~curt
7 // Copyright (C) 2010 Torsten Dreyer - Torsten (at) t3r (dot) de
9 // This program is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU General Public License as
11 // published by the Free Software Foundation; either version 2 of the
12 // License, or (at your option) any later version.
14 // This program is distributed in the hope that it will be useful, but
15 // WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // General Public License for more details.
19 // You should have received a copy of the GNU General Public License
20 // along with this program; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 #include "component.hxx"
24 #include <Main/fg_props.hxx>
25 #include <simgear/structure/exception.hxx>
26 #include <simgear/props/condition.hxx>
28 using namespace FGXMLAutopilot;
30 Component::Component() :
38 Component::~Component()
43 //------------------------------------------------------------------------------
44 bool Component::configure( SGPropertyNode& prop_root,
47 for( int i = 0; i < cfg.nChildren(); ++i )
49 SGPropertyNode_ptr child = cfg.getChild(i);
50 std::string cname(child->getName());
52 if( !configure(*child, cname, prop_root)
53 && cname != "params" ) // 'params' is usually used to specify parameters
54 // in PropertList files.
59 "Component::configure: unknown node: " << cname
66 //------------------------------------------------------------------------------
67 bool Component::configure( SGPropertyNode& cfg_node,
68 const std::string& cfg_name,
69 SGPropertyNode& prop_root )
71 if ( cfg_name == "name" )
73 _name = cfg_node.getStringValue();
77 if ( cfg_name == "debug" )
79 _debug = cfg_node.getBoolValue();
83 if ( cfg_name == "enable" )
85 SGPropertyNode_ptr prop;
87 if( (prop = cfg_node.getChild("condition")) != NULL ) {
88 _condition = sgReadCondition(fgGetNode("/"), prop);
91 if ( (prop = cfg_node.getChild( "property" )) != NULL ) {
92 _enable_prop = fgGetNode( prop->getStringValue(), true );
95 if ( (prop = cfg_node.getChild( "prop" )) != NULL ) {
96 _enable_prop = fgGetNode( prop->getStringValue(), true );
99 if ( (prop = cfg_node.getChild( "value" )) != NULL ) {
100 delete _enable_value;
101 _enable_value = new std::string(prop->getStringValue());
104 if ( (prop = cfg_node.getChild( "honor-passive" )) != NULL ) {
105 _honor_passive = prop->getBoolValue();
114 //------------------------------------------------------------------------------
115 bool Component::isPropertyEnabled()
118 return _condition->test();
121 if( _enable_value ) {
122 return *_enable_value == _enable_prop->getStringValue();
124 return _enable_prop->getBoolValue();
130 void Component::update( double dt )
132 bool firstTime = false;
133 if( isPropertyEnabled() ) {
134 firstTime = !_enabled;
140 if( _enabled ) update( firstTime, dt );