]> git.mxchange.org Git - flightgear.git/blob - src/Autopilot/analogcomponent.cxx
Cleanup, no functional change
[flightgear.git] / src / Autopilot / analogcomponent.cxx
1 // analogcomponent.cxx - Base class for analog 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 #include "analogcomponent.hxx"
24 #include <Main/fg_props.hxx>
25
26 using namespace FGXMLAutopilot;
27
28 AnalogComponent::AnalogComponent() :
29   Component(),
30   _feedback_if_disabled(false),
31   _passive_mode( fgGetNode("/autopilot/locks/passive-mode", true) )
32 {
33 }
34
35 double AnalogComponent::clamp( double value ) const
36 {
37     //If this is a periodical value, normalize it into our domain 
38     // before clamping
39     if( _periodical )
40       value = _periodical->normalize( value );
41
42     // clamp, if either min or max is defined
43     if( _minInput.size() + _maxInput.size() > 0 ) {
44         double d = _maxInput.get_value();
45         if( value > d ) value = d;
46         d = _minInput.get_value();
47         if( value < d ) value = d;
48     }
49     return value;
50 }
51
52 bool AnalogComponent::configure( SGPropertyNode& cfg_node,
53                                  const std::string& cfg_name,
54                                  SGPropertyNode& prop_root )
55 {
56   if( cfg_name == "feedback-if-disabled" )
57   {
58     _feedback_if_disabled = cfg_node.getBoolValue();
59     return true;
60   } 
61
62   if( cfg_name == "output" )
63   {
64     // grab all <prop> and <property> childs.
65     bool found = false;
66     for( int i = 0; i < cfg_node.nChildren(); ++i )
67     {
68       SGPropertyNode& child = *cfg_node.getChild(i);
69       const std::string& name = child.getNameString();
70
71       // Allow "prop" for backwards compatiblity
72       if( name != "property" && name != "prop" )
73         continue;
74
75       _output_list.push_back( prop_root.getNode(child.getStringValue(), true) );
76       found = true;
77     }
78
79     // no <prop> elements, text node of <output> is property name
80     if( !found )
81       _output_list.push_back
82       (
83         prop_root.getNode(cfg_node.getStringValue(), true)
84       );
85
86     return true;
87   }
88
89   if( cfg_name == "input" )
90   {
91     _valueInput.push_back( new InputValue(prop_root, cfg_node) );
92     return true;
93   }
94
95   if( cfg_name == "reference" )
96   {
97     _referenceInput.push_back( new InputValue(prop_root, cfg_node) );
98     return true;
99   }
100
101   if( cfg_name == "min" || cfg_name == "u_min" )
102   {
103     _minInput.push_back( new InputValue(prop_root, cfg_node) );
104     return true;
105   }
106
107   if( cfg_name == "max" || cfg_name == "u_max" )
108   {
109     _maxInput.push_back( new InputValue(prop_root, cfg_node) );
110     return true;
111   }
112
113   if( cfg_name == "period" )
114   {
115     _periodical = new PeriodicalValue(prop_root, cfg_node);
116     return true;
117   }
118
119   return Component::configure(cfg_node, cfg_name, prop_root);
120 }