]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGJSBBase.h
Encapsulate the interpolstion version of FGEnvironment and fix some bugs
[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 #ifdef FGFS
42 #  include <simgear/compiler.h>
43 #  include <math.h>
44 #  include <queue>
45 #  include STL_STRING
46
47 SG_USING_STD(string);
48
49 # ifndef M_PI
50 #  include <simgear/constants.h>
51 #  define M_PI SG_PI
52 # endif
53
54 #else
55
56 #  include <queue>
57 #  include <string>
58 #  if defined(sgi) && !defined(__GNUC__)
59 #    include <math.h>
60 #  else
61 #    include <cmath>
62 #  endif
63
64 using std::string;
65
66 # ifndef M_PI
67 #  define M_PI 3.14159265358979323846
68 # endif
69
70 #endif
71
72 #if !defined(WIN32) || defined(__GNUC__)
73 using std::max;
74 #endif
75
76 #ifdef __FreeBSD__ // define gcvt on FreeBSD
77
78 #include <stdio.h>
79
80 static char *gcvt(double number, size_t ndigit, char *buf)
81 {
82   sprintf(buf, "%f", number);
83   return buf;
84 }
85 #endif
86
87 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
88 DEFINITIONS
89 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
90
91 #define ID_JSBBASE "$Id$"
92
93 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
94 FORWARD DECLARATIONS
95 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
96
97 namespace JSBSim {
98
99 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
100 CLASS DOCUMENTATION
101 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
102
103 /** JSBSim Base class.
104     @author Jon S. Berndt
105     @version $Id$
106 */
107
108 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
109 CLASS DECLARATION
110 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
111
112 class FGJSBBase {
113 public:
114   /// Constructor for FGJSBBase.
115   FGJSBBase();
116
117   /// Destructor for FGJSBBase.
118   virtual ~FGJSBBase() {};
119
120   /// JSBSim Message structure
121   typedef struct Msg {
122     unsigned int fdmId;
123     unsigned int messageId;
124     string text;
125     string subsystem;
126     enum mType {eText, eInteger, eDouble, eBool} type;
127     bool bVal;
128     int  iVal;
129     double dVal;
130   } Message;
131
132   ///@name JSBSim Enums.
133   //@{
134   /// Moments L, M, N
135   enum {eL     = 1, eM,     eN    };
136   /// Rates P, Q, R
137   enum {eP     = 1, eQ,     eR    };
138   /// Velocities U, V, W
139   enum {eU     = 1, eV,     eW    };
140   /// Positions X, Y, Z
141   enum {eX     = 1, eY,     eZ    };
142   /// Euler angles Phi, Theta, Psi
143   enum {ePhi   = 1, eTht,   ePsi  };
144   /// Stability axis forces, Drag, Side force, Lift
145   enum {eDrag  = 1, eSide,  eLift };
146   /// Local frame orientation Roll, Pitch, Yaw
147   enum {eRoll  = 1, ePitch, eYaw  };
148   /// Local frame position North, East, Down
149   enum {eNorth = 1, eEast,  eDown };
150   //@}
151   
152   ///@name JSBSim console output highlighting terms.
153   //@{
154   /// highlights text
155   static char highint[5];
156   /// low intensity text
157   static char halfint[5];
158   /// normal intensity text
159   static char normint[6];
160   /// resets text properties
161   static char reset[5];
162   /// underlines text
163   static char underon[5];
164   /// underline off
165   static char underoff[6];
166   /// blue text
167   static char fgblue[6];
168   /// cyan text
169   static char fgcyan[6];
170   /// red text
171   static char fgred[6];
172   /// green text
173   static char fggreen[6];
174   /// default text
175   static char fgdef[6];
176   //@}
177
178   ///@name JSBSim Messaging functions
179   //@{
180   /** Places a Message structure on the Message queue.
181       @param msg pointer to a Message structure
182       @return pointer to a Message structure */
183   Message* PutMessage(Message* msg);
184   /** Creates a message with the given text and places it on the queue.
185       @param text message text
186       @return pointer to a Message structure */
187   Message* PutMessage(string text);
188   /** Creates a message with the given text and boolean value and places it on the queue.
189       @param text message text
190       @param bVal boolean value associated with the message
191       @return pointer to a Message structure */
192   Message* PutMessage(string text, bool bVal);
193   /** Creates a message with the given text and integer value and places it on the queue.
194       @param text message text
195       @param iVal integer value associated with the message
196       @return pointer to a Message structure */
197   Message* PutMessage(string text, int iVal);
198   /** Creates a message with the given text and double value and places it on the queue.
199       @param text message text
200       @param dVal double value associated with the message
201       @return pointer to a Message structure */
202   Message* PutMessage(string text, double dVal);
203   /** Reads the message on the queue (but does not delete it).
204       @return pointer to a Message structure (or NULL if no mesage) */
205   Message* ReadMessage(void);
206   /** Reads the message on the queue and removes it from the queue.
207       @return pointer to a Message structure (or NULL if no mesage) */
208   Message* ProcessMessage(void);
209   //@}
210   string GetVersion(void) {return JSBSim_version;}
211   
212   void disableHighLighting(void);
213
214   static short debug_lvl;
215   double KelvinToFahrenheit (double kelvin) {
216     return 1.8*kelvin - 459.4;
217   }
218
219   double RankineToCelsius (double rankine) {
220     return (rankine - 491.67)/1.8;
221   }
222
223 protected:
224   static Message localMsg;
225   
226   static std::queue <Message*> Messages;
227
228   virtual void Debug(int from) {};
229
230   static unsigned int frame;
231   static unsigned int messageId;
232   
233   static const double radtodeg;
234   static const double degtorad;
235   static const double hptoftlbssec;
236   static const double psftoinhg;
237   static const double fpstokts;
238   static const double ktstofps;
239   static const double inchtoft;
240   static const double in3tom3;
241   static double Reng;         // Specific Gas Constant,ft^2/(sec^2*R)
242   static const double SHRatio;
243   static const string needed_cfg_version;
244   static const string JSBSim_version;
245 };
246 }
247 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
248 #endif
249