]> git.mxchange.org Git - flightgear.git/blob - src/FDM/YASim/FGFDM.hpp
GUI ‘restore defaults’ support.
[flightgear.git] / src / FDM / YASim / FGFDM.hpp
1 #ifndef _FGFDM_HPP
2 #define _FGFDM_HPP
3
4 #include <simgear/xml/easyxml.hxx>
5 #include <simgear/props/props.hxx>
6
7 #include "Airplane.hpp"
8 #include "Vector.hpp"
9
10 namespace yasim {
11
12 class Wing;
13 class Version;
14
15 // This class forms the "glue" to the FlightGear codebase.  It handles
16 // parsing of XML airplane files, interfacing to the properties
17 // system, and providing data for the use of the FGInterface object.
18 class FGFDM : public XMLVisitor {
19 public:
20     FGFDM();
21     ~FGFDM();
22     void init();
23     void iterate(float dt);
24     void getExternalInput(float dt=1e6);
25
26     Airplane* getAirplane();
27
28     // XML parsing callback from XMLVisitor
29     virtual void startElement(const char* name, const XMLAttributes &atts);
30
31     float getVehicleRadius(void) const { return _vehicle_radius; }
32
33 private:
34     struct AxisRec { char* name; int handle; };
35     struct EngRec { char* prefix; Thruster* eng; };
36     struct WeightRec { char* prop; float size; int handle; };
37     struct PropOut { SGPropertyNode* prop; int handle, type; bool left;
38                      float min, max; };
39
40     void setOutputProperties(float dt);
41
42     Rotor* parseRotor(XMLAttributes* a, const char* name);
43     Wing* parseWing(XMLAttributes* a, const char* name, Version * version);
44     int parseAxis(const char* name);
45     int parseOutput(const char* name);
46     void parseWeight(XMLAttributes* a);
47     void parseTurbineEngine(XMLAttributes* a);
48     void parsePistonEngine(XMLAttributes* a);
49     void parsePropeller(XMLAttributes* a);
50     bool eq(const char* a, const char* b);
51     bool caseeq(const char* a, const char* b);
52     char* dup(const char* s);
53     int attri(XMLAttributes* atts, const char* attr);
54     int attri(XMLAttributes* atts, const char* attr, int def); 
55     float attrf(XMLAttributes* atts, const char* attr);
56     float attrf(XMLAttributes* atts, const char* attr, float def); 
57     double attrd(XMLAttributes* atts, const char* attr);
58     double attrd(XMLAttributes* atts, const char* attr, double def); 
59     bool attrb(XMLAttributes* atts, const char* attr);
60
61     // The core Airplane object we manage.
62     Airplane _airplane;
63
64     // Aerodynamic turbulence model
65     Turbulence* _turb;
66
67     // The list of "axes" that we expect to find as input.  These are
68     // typically property names.
69     Vector _axes;
70
71     // Settable weights
72     Vector _weights;
73
74     // Engine types.  Contains an EngRec structure.
75     Vector _thrusters;
76
77     // Output properties for the ControlMap
78     Vector _controlProps;
79
80     // Radius of the vehicle, for intersection testing.
81     float _vehicle_radius;
82
83     // Parsing temporaries
84     void* _currObj;
85     bool _cruiseCurr;
86     int _nextEngine;
87
88     class FuelProps
89     {
90     public:
91         SGPropertyNode_ptr _out_of_fuel;
92         SGPropertyNode_ptr _fuel_consumed_lbs;
93     };
94
95     class ThrusterProps
96     {
97     public:
98         SGPropertyNode_ptr _running, _cranking;
99         SGPropertyNode_ptr _prop_thrust, _thrust_lbs, _fuel_flow_gph;
100         SGPropertyNode_ptr _rpm, _torque_ftlb, _mp_osi, _mp_inhg;
101         SGPropertyNode_ptr _oil_temperature_degf, _boost_gauge_inhg;
102         SGPropertyNode_ptr _n1, _n2, _epr, _egt_degf;
103     };
104
105     SGPropertyNode_ptr _turb_magnitude_norm, _turb_rate_hz;
106     SGPropertyNode_ptr _gross_weight_lbs;
107     std::vector<SGPropertyNode_ptr> _tank_level_lbs;
108     std::vector<ThrusterProps> _thrust_props;
109     std::vector<FuelProps> _fuel_props;
110 };
111
112 }; // namespace yasim
113 #endif // _FGFDM_HPP