]> git.mxchange.org Git - flightgear.git/blob - src/Autopilot/component.hxx
Autopilot: Optionally write (internal) state to property tree
[flightgear.git] / src / Autopilot / component.hxx
1 // component.hxx - Base class for autopilot components
2 //
3 // Written by Torsten Dreyer
4 // Based heavily on work created by Curtis Olson, started January 2004.
5 //
6 // Copyright (C) 2004  Curtis L. Olson  - http://www.flightgear.org/~curt
7 // Copyright (C) 2010  Torsten Dreyer - Torsten (at) t3r (dot) de
8 //
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.
13 //
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.
18 //
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.
22 //
23 #ifndef __COMPONENT_HXX
24 #define __COMPONENT_HXX 1
25
26 #ifdef HAVE_CONFIG_H
27 #  include <config.h>
28 #endif
29
30 #include <simgear/structure/subsystem_mgr.hxx>
31 #include <simgear/props/propsfwd.hxx>
32
33 namespace FGXMLAutopilot {
34
35 /**
36  * @brief Base class for other autopilot components
37  */
38 class Component : public SGSubsystem {
39
40 private:
41
42     SGSharedPtr<const SGCondition> _condition;
43     SGPropertyNode_ptr _enable_prop;
44     std::string * _enable_value;
45     std::string _name;
46     bool _enabled;
47
48 protected:
49
50     virtual bool configure( const std::string & nodeName, SGPropertyNode_ptr configNode );
51
52     
53    /**
54     * @brief the implementation of the update() method of the SGSubsystem
55     */
56     virtual void update( double dt );
57
58    /** 
59     * @brief pure virtual function to be implemented by the derived classes. Gets called from
60     * the update method if it's not disabled with the firstTime parameter set to true if this
61     * is the first call after being enabled 
62     * @param firstTime set to true if this is the first update call since this component has
63              been enabled. Set to false for every subsequent call.
64     * @param dt  the elapsed time since the last call
65     */
66     virtual void update( bool firstTime, double dt ) = 0;
67
68    /**
69     * @brief overideable method being called from the update() method if this component
70     *        is disabled. It's a noop by default.
71     */
72     virtual void disabled( double dt ) {}
73
74     /** 
75      * @brief debug flag, true if this component should generate some useful output
76      * on every iteration
77      */
78     bool _debug;
79
80     /**
81      * @brief property node to write debug values in child nodes on every
82      *        iteration
83      */
84     SGPropertyNode_ptr _debug_node;
85
86     /** 
87      * @brief a (historic) flag signalling the derived class that it should compute it's internal
88      *        state but shall not set the output properties if /autopilot/locks/passive-mode is true.
89      */
90     bool _honor_passive;
91     
92 public:
93     
94     /**
95      * @brief A constructor for an empty Component.
96      */
97     Component();
98
99     /**
100      * virtual destructor to clean up resources
101      */
102     virtual ~Component();
103
104     /**
105      * @brief configure this component from a property node. Iterates through all nodes found
106      *        as childs under configNode and calls configure of the derived class for each child.
107      * @param configNode the property node containing the configuration 
108      */
109     bool configure( SGPropertyNode_ptr configNode );
110
111     /**
112      * @brief getter for the name property
113      * @return the name of the component
114      */
115     inline const std::string& get_name() const { return _name; }
116
117     /**
118      * @brief setter for the name property
119      * @param name the name of the component
120      */
121     inline void set_name( const std::string & name ) { _name = name; }
122
123     /**
124      * @brief check if this component is enabled as configured in the
125      * &lt;enable&gt; section
126      * @return true if the enable-condition is true.
127      *
128      * If a &lt;condition&gt; is defined, this condition is evaluated, 
129      * &lt;prop&gt; and &lt;value&gt; tags are ignored.
130      *
131      * If a &lt;prop&gt; is defined and no &lt;value&gt; is defined, the property
132      * named in the &lt;prop&gt;&lt;prop&gt; tags is evaluated as boolean.
133      *
134      * If a &lt;prop&gt; is defined and a &lt;value&gt; is defined, the property named
135      * in &lt;prop&gt;&lt;/prop&gt; is compared (as a string) to the value defined in
136      * &lt;value&gt;&lt;/value&gt;
137      *
138      * Returns true, if neither &lt;condition&gt; nor &lt;prop&gt; exists
139      */
140     bool isPropertyEnabled();
141 };
142
143
144 }
145 #endif // COMPONENT_HXX