]> git.mxchange.org Git - flightgear.git/blobdiff - src/Systems/electrical.hxx
Moved random ground cover object management code (userdata.[ch]xx) over
[flightgear.git] / src / Systems / electrical.hxx
index 04c71f3e7c318ced2f9b1d6a330c4cca154fae3f..9761a955c644b6297dac8e1542cf0bbd8363b8b0 100644 (file)
 SG_USING_STD(string);
 SG_USING_STD(vector);
 
-#include <simgear/misc/props.hxx>
+#include <simgear/props/props.hxx>
+
 #include <Main/fgfs.hxx>
 
 
+// Forward declaration
+class FGElectricalSystem;
+
+
 #define FG_UNKNOWN  -1
 #define FG_SUPPLIER  0
 #define FG_BUS       1
@@ -51,48 +56,79 @@ SG_USING_STD(vector);
 // Base class for other electrical components
 class FGElectricalComponent {
 
+protected:
+
     typedef vector<FGElectricalComponent *> comp_list;
     typedef vector<string> string_list;
 
+    int kind;
+    string name;
+    double value;
+
+    comp_list inputs;
+    comp_list outputs;
+    string_list props;
+
 public:
 
-    FGElectricalComponent() {}
+    FGElectricalComponent();
     virtual ~FGElectricalComponent() {}
 
-    virtual string get_name() { return ""; }
+    inline string get_name() { return name; }
+
+    inline int get_kind() const { return kind; }
+    inline double get_value() const { return value; }
+    inline void set_value( double val ) { value = val; }
+
+    inline int get_num_inputs() const { return outputs.size(); }
+    inline FGElectricalComponent *get_input( const int i ) {
+        return inputs[i];
+    }
+    inline void add_input( FGElectricalComponent *c ) {
+        inputs.push_back( c );
+    }
+
+    inline int get_num_outputs() const { return outputs.size(); }
+    inline FGElectricalComponent *get_output( const int i ) {
+        return outputs[i];
+    }
+    inline void add_output( FGElectricalComponent *c ) {
+        outputs.push_back( c );
+    }
+
+    inline int get_num_props() const { return props.size(); }
+    inline string get_prop( const int i ) {
+        return props[i];
+    }
+    inline void add_prop( const string &s ) {
+        props.push_back( s );
+    }
 
-    int kind;
-    inline int get_kind() { return kind; }
 };
 
 
 // Electrical supplier
 class FGElectricalSupplier : public FGElectricalComponent {
 
+    SGPropertyNode_ptr _rpm_node;
+
     enum FGSupplierType {
         FG_BATTERY = 0,
         FG_ALTERNATOR = 1,
         FG_EXTERNAL = 2
     };
 
-    string name;
+    string rpm_src;
     int model;
     double volts;
     double amps;
 
-    comp_list outputs;
-
 public:
 
-    FGElectricalSupplier ( string _name, string _model,
-                           double _volts, double _amps );
+    FGElectricalSupplier ( SGPropertyNode *node );
     ~FGElectricalSupplier () {}
 
-    void add_output( FGElectricalComponent *c ) {
-        outputs.push_back( c );
-    }
-
-    string get_name() const { return name; }
+    double get_output();
 };
 
 
@@ -100,24 +136,10 @@ public:
 // outputs)
 class FGElectricalBus : public FGElectricalComponent {
 
-    string name;
-    comp_list inputs;
-    comp_list outputs;
-
 public:
 
-    FGElectricalBus ( string _name );
+    FGElectricalBus ( SGPropertyNode *node );
     ~FGElectricalBus () {}
-
-    void add_input( FGElectricalComponent *c ) {
-        inputs.push_back( c );
-    }
-
-    void add_output( FGElectricalComponent *c ) {
-        outputs.push_back( c );
-    }
-
-    string get_name() const { return name; }
 };
 
 
@@ -125,19 +147,10 @@ public:
 // flexibility
 class FGElectricalOutput : public FGElectricalComponent {
 
-    string name;
-    comp_list inputs;
-
 public:
 
-    FGElectricalOutput ( string _name );
+    FGElectricalOutput ( SGPropertyNode *node );
     ~FGElectricalOutput () {}
-
-    void add_input( FGElectricalComponent *c ) {
-        inputs.push_back( c );
-    }
-
-    string get_name() const { return name; }
 };
 
 
@@ -147,39 +160,27 @@ class FGElectricalConnector : public FGElectricalComponent {
 
     comp_list inputs;
     comp_list outputs;
-    string_list switches;
+    typedef vector<SGPropertyNode *> switch_list;
+    switch_list switches;
 
 public:
 
-    FGElectricalConnector ();
+    FGElectricalConnector ( SGPropertyNode *node, FGElectricalSystem *es );
     ~FGElectricalConnector () {}
 
-    void add_input( FGElectricalComponent *c ) {
-        inputs.push_back( c );
-    }
-
-    void add_output( FGElectricalComponent *c ) {
-        outputs.push_back( c );
+    void add_switch( SGPropertyNode *node ) {
+        switches.push_back( node );
     }
 
-    void add_switch( const string &s ) {
-        switches.push_back( s );
-    }
+    // set all switches to the specified state
+    void set_switches( bool state );
 
-    string get_name() const { return ""; }
+    bool get_state();
 };
 
 
 /**
- * Model an electrical system.  This is a simple system with the
- * alternator hardwired to engine[0]/rpm
- *
- * Input properties:
- *
- * /engines/engine[0]/rpm
- *
- * Output properties:
- *
+ * Model an electrical system.  This is a fairly simplistic system
  * 
  */
 
@@ -197,21 +198,26 @@ public:
     virtual void update (double dt);
 
     bool build ();
+    void propagate( FGElectricalComponent *node, double val, string s = "" );
     FGElectricalComponent *find ( const string &name );
 
+protected:
+
+    typedef vector<FGElectricalComponent *> comp_list;
+
 private:
 
     SGPropertyNode *config_props;
-    // SGPropertyNode_ptr _serviceable_node;
 
     bool enabled;
 
-    typedef vector<FGElectricalComponent *> comp_list;
-
     comp_list suppliers;
     comp_list buses;
     comp_list outputs;
     comp_list connectors;
+
+    SGPropertyNode *_volts_out;
+    SGPropertyNode *_amps_out;
 };