]> git.mxchange.org Git - flightgear.git/blob - src/Environment/environment_ctrl.hxx
61617a3fc3160b7a6d199c82ad26de36d3b7b4a8
[flightgear.git] / src / Environment / environment_ctrl.hxx
1 // environment-ctrl.hxx -- controller for environment information.
2 //
3 // Written by David Megginson, started May 2002.
4 //
5 // Copyright (C) 2002  David Megginson - david@megginson.com
6 //
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.
11 //
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.
16 //
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.
20 //
21 // $Id$
22
23 #ifndef _ENVIRONMENT_CTRL_HXX
24 #define _ENVIRONMENT_CTRL_HXX
25
26 #include <simgear/compiler.h>
27 #include <simgear/structure/subsystem_mgr.hxx>
28 #include <simgear/environment/metar.hxx>
29
30 #ifdef SG_HAVE_STD_INCLUDES
31 #  include <cmath>
32 #else
33 #  include <math.h>
34 #endif
35
36 #include <vector>
37
38 SG_USING_STD(vector);
39
40 class SGPropertyNode;
41
42 #include "environment.hxx"
43
44
45 \f
46 /**
47  * Interface to control environment information for a specific location.
48  */
49 class FGEnvironmentCtrl : public SGSubsystem
50 {
51
52 public:
53
54   FGEnvironmentCtrl ();
55   virtual ~FGEnvironmentCtrl ();
56
57   virtual void setEnvironment (FGEnvironment * environment);
58
59   virtual FGEnvironment * getEnvironment () const { return _environment; }
60
61   virtual void setLongitudeDeg (double lon_deg);
62   virtual void setLatitudeDeg (double lat_deg);
63   virtual void setElevationFt (double elev_ft);
64   virtual void setPosition (double lon_deg, double lat_deg, double elev_ft);
65
66   virtual double getLongitudeDeg () const { return _lon_deg; }
67   virtual double getLatitudeDeg () const { return _lat_deg; }
68   virtual double getElevationFt () const { return _elev_ft; }
69
70 protected:
71
72   FGEnvironment * _environment;
73   double _lon_deg;
74   double _lat_deg;
75   double _elev_ft;
76
77 };
78
79
80 \f
81 /**
82  * Environment controller using user-supplied parameters.
83  */
84 class FGUserDefEnvironmentCtrl : public FGEnvironmentCtrl
85 {
86 public:
87   FGUserDefEnvironmentCtrl ();
88   virtual ~FGUserDefEnvironmentCtrl ();
89
90   virtual void init ();
91   virtual void update (double dt);
92
93 private:
94
95   SGPropertyNode * _base_wind_speed_node;
96   SGPropertyNode * _gust_wind_speed_node;
97
98   double _current_wind_speed_kt;
99   double _delta_wind_speed_kt;
100
101 };
102
103
104 \f
105 /**
106  * Interplation controller using user-supplied parameters.
107  */
108 class FGInterpolateEnvironmentCtrl : public FGEnvironmentCtrl
109 {
110 public:
111     FGInterpolateEnvironmentCtrl ();
112     virtual ~FGInterpolateEnvironmentCtrl ();
113     
114     virtual void init ();
115     virtual void reinit ();
116     virtual void update (double delta_time_sec);
117
118 private:
119     
120     struct bucket {
121         double altitude_ft;
122         FGEnvironment environment;
123         bool operator< (const bucket &b) const;
124     };
125
126     void read_table (const SGPropertyNode * node, vector<bucket *> &table);
127     void do_interpolate (vector<bucket *> &table, double altitude_ft,
128                          FGEnvironment * environment);
129
130     FGEnvironment env1, env2;   // temporaries
131
132     vector<bucket *> _boundary_table;
133     vector<bucket *> _aloft_table;
134 };
135
136
137 \f
138 /**
139  * Interplation controller using the SGMetar class
140  */
141 class FGMetarEnvironmentCtrl : public FGEnvironmentCtrl
142 {
143 public:
144     FGMetarEnvironmentCtrl ();
145     virtual ~FGMetarEnvironmentCtrl ();
146
147     virtual void init ();
148     virtual void reinit ();
149     virtual void update (double delta_time_sec);
150
151     virtual void setEnvironment (FGEnvironment * environment);
152
153 private:
154     FGInterpolateEnvironmentCtrl *env;
155
156     string _icao;
157     float station_elevation_ft;
158     float update_interval_sec;
159     float elapsed;
160     bool fetch_data (const string &icao);
161     void update_env_config();
162 };
163
164 #endif // _ENVIRONMENT_CTRL_HXX