]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGJSBBase.h
Remove a bunch of unneede files.
[flightgear.git] / src / FDM / JSBSim / FGJSBBase.h
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3  Header:       FGJSBBase.h
4  Author:       Jon S. Berndt
5  Date started: 07/01/01
6
7  ------------- Copyright (C) 2001  Jon S. Berndt (jsb@hal-pc.org) -------------
8
9  This program is free software; you can redistribute it and/or modify it under
10  the terms of the GNU General Public License as published by the Free Software
11  Foundation; either version 2 of the License, or (at your option) any later
12  version.
13
14  This program is distributed in the hope that it will be useful, but WITHOUT
15  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
17  details.
18
19  You should have received a copy of the GNU General Public License along with
20  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21  Place - Suite 330, Boston, MA  02111-1307, USA.
22
23  Further information about the GNU General Public License can also be found on
24  the world wide web at http://www.gnu.org.
25
26 HISTORY
27 --------------------------------------------------------------------------------
28 07/01/01  JSB  Created
29
30 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31 SENTRY
32 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
33
34 #ifndef FGJSBBASE_H
35 #define FGJSBBASE_H
36
37 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38 INCLUDES
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
40
41 #include <float.h>
42
43 #ifdef FGFS
44 #  include <simgear/compiler.h>
45 #  include <math.h>
46 #  include <queue>
47 #  include STL_STRING
48
49 SG_USING_STD(string);
50
51 #  ifndef M_PI
52 #    include <simgear/constants.h>
53 #    define M_PI SG_PI
54 #  endif
55
56 #else  // JSBSim section
57
58 #  include <queue>
59 #  include <string>
60 #  if defined(sgi) && !defined(__GNUC__)
61 #    include <math.h>
62 #  else
63 #    include <cmath>
64 #  endif
65
66 using std::string;
67
68 #  if defined(_MSC_VER) && _MSC_VER <= 1200
69 #    ifndef max
70 #      define max(a,b)            (((a) > (b)) ? (a) : (b))
71 #    endif
72
73 #    ifndef min
74 #      define min(a,b)            (((a) < (b)) ? (a) : (b))
75 #    endif
76 #  else
77
78 using std::fabs;
79
80 #  endif
81
82 #  ifndef M_PI
83 #    define M_PI 3.14159265358979323846
84 #  endif
85
86 #endif
87
88 #if !defined(WIN32) || defined(__GNUC__)
89 using std::max;
90 #endif
91
92 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
93 DEFINITIONS
94 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
95
96 #define ID_JSBBASE "$Id$"
97
98 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
99 FORWARD DECLARATIONS
100 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
101
102 namespace JSBSim {
103
104 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
105 CLASS DOCUMENTATION
106 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
107
108 /** JSBSim Base class.
109 *   This class provides universal constants, utility functions, messaging
110 *   functions, and enumerated constants to JSBSim.
111     @author Jon S. Berndt
112     @version $Id$
113 */
114
115 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
116 CLASS DECLARATION
117 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
118
119 class FGJSBBase {
120 public:
121   /// Constructor for FGJSBBase.
122   FGJSBBase() {};
123
124   /// Destructor for FGJSBBase.
125   ~FGJSBBase() {};
126
127   /// JSBSim Message structure
128   typedef struct Msg {
129     unsigned int fdmId;
130     unsigned int messageId;
131     string text;
132     string subsystem;
133     enum mType {eText, eInteger, eDouble, eBool} type;
134     bool bVal;
135     int  iVal;
136     double dVal;
137   } Message;
138
139   ///@name JSBSim console output highlighting terms.
140   //@{
141   /// highlights text
142   static char highint[5];
143   /// low intensity text
144   static char halfint[5];
145   /// normal intensity text
146   static char normint[6];
147   /// resets text properties
148   static char reset[5];
149   /// underlines text
150   static char underon[5];
151   /// underline off
152   static char underoff[6];
153   /// blue text
154   static char fgblue[6];
155   /// cyan text
156   static char fgcyan[6];
157   /// red text
158   static char fgred[6];
159   /// green text
160   static char fggreen[6];
161   /// default text
162   static char fgdef[6];
163   //@}
164
165   ///@name JSBSim Messaging functions
166   //@{
167   /** Places a Message structure on the Message queue.
168       @param msg pointer to a Message structure
169       @return pointer to a Message structure */
170   Message* PutMessage(Message* msg);
171   /** Creates a message with the given text and places it on the queue.
172       @param text message text
173       @return pointer to a Message structure */
174   Message* PutMessage(const string& text);
175   /** Creates a message with the given text and boolean value and places it on the queue.
176       @param text message text
177       @param bVal boolean value associated with the message
178       @return pointer to a Message structure */
179   Message* PutMessage(const string& text, bool bVal);
180   /** Creates a message with the given text and integer value and places it on the queue.
181       @param text message text
182       @param iVal integer value associated with the message
183       @return pointer to a Message structure */
184   Message* PutMessage(const string& text, int iVal);
185   /** Creates a message with the given text and double value and places it on the queue.
186       @param text message text
187       @param dVal double value associated with the message
188       @return pointer to a Message structure */
189   Message* PutMessage(const string& text, double dVal);
190   /** Reads the message on the queue (but does not delete it).
191       @return pointer to a Message structure (or NULL if no mesage) */
192   Message* ReadMessage(void);
193   /** Reads the message on the queue and removes it from the queue.
194       @return pointer to a Message structure (or NULL if no mesage) */
195   Message* ProcessMessage(void);
196   //@}
197
198   /** Returns the version number of JSBSim.
199   *   @return The version number of JSBSim. */
200   string GetVersion(void) {return JSBSim_version;}
201
202   /// Disables highlighting in the console output.
203   void disableHighLighting(void);
204
205   static short debug_lvl;
206
207   /** Converts from degrees Kelvin to degrees Fahrenheit.
208   *   @param kelvin The temperature in degrees Kelvin.
209   *   @return The temperature in Fahrenheit. */
210   static double KelvinToFahrenheit (double kelvin) {
211     return 1.8*kelvin - 459.4;
212   }
213
214   /** Converts from degrees Rankine to degrees Celsius.
215   *   @param rankine The temperature in degrees Rankine.
216   *   @return The temperature in Celsius. */
217   static double RankineToCelsius (double rankine) {
218     return (rankine - 491.67)/1.8;
219   }
220
221   /** Converts from degrees Fahrenheit to degrees Celsius.
222   *   @param fahrenheit The temperature in degrees Fahrenheit.
223   *   @return The temperature in Celsius. */
224   static double FahrenheitToCelsius (double fahrenheit) {
225     return (fahrenheit - 32.0)/1.8;
226   }
227
228   /** Converts from degrees Celsius to degrees Fahrenheit.
229   *   @param celsius The temperature in degrees Celsius.
230   *   @return The temperature in Fahrenheit. */
231   static double CelsiusToFahrenheit (double celsius) {
232     return celsius * 1.8 + 32.0;
233   }
234
235   /** Finite precision comparison.
236       @param a first value to compare
237       @param b second value to compare
238       @return if the two values can be considered equal up to roundoff */
239   static bool EqualToRoundoff(double a, double b) {
240     double eps = 2.0*DBL_EPSILON;
241     return fabs(a - b) <= eps*max(fabs(a), fabs(b));
242   }
243
244   /** Finite precision comparison.
245       @param a first value to compare
246       @param b second value to compare
247       @return if the two values can be considered equal up to roundoff */
248   static bool EqualToRoundoff(float a, float b) {
249     float eps = 2.0*FLT_EPSILON;
250     return fabs(a - b) <= eps*max(fabs(a), fabs(b));
251   }
252
253   /** Finite precision comparison.
254       @param a first value to compare
255       @param b second value to compare
256       @return if the two values can be considered equal up to roundoff */
257   static bool EqualToRoundoff(float a, double b) {
258     return EqualToRoundoff(a, (float)b);
259   }
260
261   /** Finite precision comparison.
262       @param a first value to compare
263       @param b second value to compare
264       @return if the two values can be considered equal up to roundoff */
265   static bool EqualToRoundoff(double a, float b) {
266     return EqualToRoundoff((float)a, b);
267   }
268
269 protected:
270   static Message localMsg;
271
272   static std::queue <Message*> Messages;
273
274   void Debug(int from) {};
275
276   static unsigned int frame;
277   static unsigned int messageId;
278
279   static const double radtodeg;
280   static const double degtorad;
281   static const double hptoftlbssec;
282   static const double psftoinhg;
283   static const double psftopa;
284   static const double fpstokts;
285   static const double ktstofps;
286   static const double inchtoft;
287   static const double in3tom3;
288   static double Reng;         // Specific Gas Constant,ft^2/(sec^2*R)
289   static const double SHRatio;
290   static const double lbtoslug;
291   static const double slugtolb;
292   static const string needed_cfg_version;
293   static const string JSBSim_version;
294
295 public:
296 /// Moments L, M, N
297 enum {eL     = 1, eM,     eN    };
298 /// Rates P, Q, R
299 enum {eP     = 1, eQ,     eR    };
300 /// Velocities U, V, W
301 enum {eU     = 1, eV,     eW    };
302 /// Positions X, Y, Z
303 enum {eX     = 1, eY,     eZ    };
304 /// Euler angles Phi, Theta, Psi
305 enum {ePhi   = 1, eTht,   ePsi  };
306 /// Stability axis forces, Drag, Side force, Lift
307 enum {eDrag  = 1, eSide,  eLift };
308 /// Local frame orientation Roll, Pitch, Yaw
309 enum {eRoll  = 1, ePitch, eYaw  };
310 /// Local frame position North, East, Down
311 enum {eNorth = 1, eEast,  eDown };
312 /// Locations Radius, Latitude, Longitude
313 enum {eLat = 1, eLong, eRad     };
314 /// Conversion specifiers
315 enum {inNone = 0, inDegrees, inRadians, inMeters, inFeet };
316
317 };
318
319 }
320 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
321 #endif
322