1 // electrical.hxx - a flexible, generic electrical system model.
3 // Written by Curtis Olson, started September 2002.
5 // Copyright (C) 2002 Curtis L. Olson - curt@flightgear.org
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #ifndef _SYSTEMS_ELECTRICAL_HXX
25 #define _SYSTEMS_ELECTRICAL_HXX 1
28 # error This library requires C++
41 #include <simgear/misc/props.hxx>
42 #include <Main/fgfs.hxx>
45 // Forward declaration
46 class FGElectricalSystem;
53 #define FG_CONNECTOR 3
55 // Base class for other electrical components
56 class FGElectricalComponent {
60 typedef vector<FGElectricalComponent *> comp_list;
61 typedef vector<string> string_list;
73 FGElectricalComponent();
74 virtual ~FGElectricalComponent() {}
76 inline string get_name() { return name; }
78 inline int get_kind() const { return kind; }
79 inline double get_value() const { return value; }
80 inline void set_value( double val ) { value = val; }
82 inline int get_num_inputs() const { return outputs.size(); }
83 inline FGElectricalComponent *get_input( const int i ) {
86 inline void add_input( FGElectricalComponent *c ) {
87 inputs.push_back( c );
90 inline int get_num_outputs() const { return outputs.size(); }
91 inline FGElectricalComponent *get_output( const int i ) {
94 inline void add_output( FGElectricalComponent *c ) {
95 outputs.push_back( c );
98 inline int get_num_props() const { return props.size(); }
99 inline string get_prop( const int i ) {
102 inline void add_prop( const string &s ) {
103 props.push_back( s );
109 // Electrical supplier
110 class FGElectricalSupplier : public FGElectricalComponent {
112 SGPropertyNode_ptr _rpm_node;
114 enum FGSupplierType {
127 FGElectricalSupplier ( SGPropertyNode *node );
128 ~FGElectricalSupplier () {}
134 // Electrical bus (can take multiple inputs and provide multiple
136 class FGElectricalBus : public FGElectricalComponent {
140 FGElectricalBus ( SGPropertyNode *node );
141 ~FGElectricalBus () {}
145 // A lot like an FGElectricalBus, but here for convenience and future
147 class FGElectricalOutput : public FGElectricalComponent {
151 FGElectricalOutput ( SGPropertyNode *node );
152 ~FGElectricalOutput () {}
156 // Connects multiple sources to multiple destinations with optional
157 // switches/fuses/circuit breakers inline
158 class FGElectricalConnector : public FGElectricalComponent {
162 typedef vector<SGPropertyNode *> switch_list;
163 switch_list switches;
167 FGElectricalConnector ( SGPropertyNode *node, FGElectricalSystem *es );
168 ~FGElectricalConnector () {}
170 void add_switch( SGPropertyNode *node ) {
171 switches.push_back( node );
174 // set all switches to the specified state
175 void set_switches( bool state );
182 * Model an electrical system. This is a fairly simplistic system
186 class FGElectricalSystem : public FGSubsystem
191 FGElectricalSystem ();
192 virtual ~FGElectricalSystem ();
194 virtual void init ();
195 virtual void bind ();
196 virtual void unbind ();
197 virtual void update (double dt);
200 void propagate( FGElectricalComponent *node, double val, string s = "" );
201 FGElectricalComponent *find ( const string &name );
205 typedef vector<FGElectricalComponent *> comp_list;
209 SGPropertyNode *config_props;
216 comp_list connectors;
220 #endif // _SYSTEMS_ELECTRICAL_HXX