]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGJSBBase.cpp
Sync with JSBSim CVS again
[flightgear.git] / src / FDM / JSBSim / FGJSBBase.cpp
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3  Module:       FGJSBBase.cpp
4  Author:       Jon S. Berndt
5  Date started: 07/01/01
6  Purpose:      Encapsulates the JSBBase object
7
8  ------------- Copyright (C) 2001  Jon S. Berndt (jon@jsbsim.org) -------------
9
10  This program is free software; you can redistribute it and/or modify it under
11  the terms of the GNU Lesser General Public License as published by the Free Software
12  Foundation; either version 2 of the License, or (at your option) any later
13  version.
14
15  This program is distributed in the hope that it will be useful, but WITHOUT
16  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17  FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
18  details.
19
20  You should have received a copy of the GNU Lesser General Public License along with
21  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
22  Place - Suite 330, Boston, MA  02111-1307, USA.
23
24  Further information about the GNU Lesser General Public License can also be found on
25  the world wide web at http://www.gnu.org.
26
27 FUNCTIONAL DESCRIPTION
28 --------------------------------------------------------------------------------
29
30 HISTORY
31 --------------------------------------------------------------------------------
32 07/01/01  JSB  Created
33
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35 INCLUDES
36 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
37
38 #define BASE
39
40 #include "FGJSBBase.h"
41 #include <iostream>
42
43 namespace JSBSim {
44
45 static const char *IdSrc = "$Id$";
46 static const char *IdHdr = ID_JSBBASE;
47
48 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
49 CLASS IMPLEMENTATION
50 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
51
52 #ifndef _MSC_VER
53     char FGJSBBase::highint[5]  = {27, '[', '1', 'm', '\0'      };
54     char FGJSBBase::halfint[5]  = {27, '[', '2', 'm', '\0'      };
55     char FGJSBBase::normint[6]  = {27, '[', '2', '2', 'm', '\0' };
56     char FGJSBBase::reset[5]    = {27, '[', '0', 'm', '\0'      };
57     char FGJSBBase::underon[5]  = {27, '[', '4', 'm', '\0'      };
58     char FGJSBBase::underoff[6] = {27, '[', '2', '4', 'm', '\0' };
59     char FGJSBBase::fgblue[6]   = {27, '[', '3', '4', 'm', '\0' };
60     char FGJSBBase::fgcyan[6]   = {27, '[', '3', '6', 'm', '\0' };
61     char FGJSBBase::fgred[6]    = {27, '[', '3', '1', 'm', '\0' };
62     char FGJSBBase::fggreen[6]  = {27, '[', '3', '2', 'm', '\0' };
63     char FGJSBBase::fgdef[6]    = {27, '[', '3', '9', 'm', '\0' };
64 #else
65     char FGJSBBase::highint[5]  = {'\0' };
66     char FGJSBBase::halfint[5]  = {'\0' };
67     char FGJSBBase::normint[6]  = {'\0' };
68     char FGJSBBase::reset[5]    = {'\0' };
69     char FGJSBBase::underon[5]  = {'\0' };
70     char FGJSBBase::underoff[6] = {'\0' };
71     char FGJSBBase::fgblue[6]   = {'\0' };
72     char FGJSBBase::fgcyan[6]   = {'\0' };
73     char FGJSBBase::fgred[6]    = {'\0' };
74     char FGJSBBase::fggreen[6]  = {'\0' };
75     char FGJSBBase::fgdef[6]    = {'\0' };
76 #endif
77
78 const double FGJSBBase::radtodeg = 57.29578;
79 const double FGJSBBase::degtorad = 1.745329E-2;
80 const double FGJSBBase::hptoftlbssec = 550.0;
81 const double FGJSBBase::psftoinhg = 0.014138;
82 const double FGJSBBase::psftopa = 47.88;
83 const double FGJSBBase::fpstokts = 0.592484;
84 const double FGJSBBase::ktstofps = 1.68781;
85 const double FGJSBBase::inchtoft = 0.08333333;
86 const double FGJSBBase::in3tom3 = 1.638706E-5;
87 const double FGJSBBase::m3toft3 = 1.0/(fttom*fttom*fttom);
88 const double FGJSBBase::inhgtopa = 3386.38;
89 const double FGJSBBase::fttom = 0.3048;
90 double FGJSBBase::Reng = 1716.0;
91 const double FGJSBBase::SHRatio = 1.40;
92
93 // Note that definition of lbtoslug by the inverse of slugtolb and not
94 // to a different constant you can also get from some tables will make
95 // lbtoslug*slugtolb == 1 up to the magnitude of roundoff. So converting from
96 // slug to lb and back will yield to the original value you started with up
97 // to the magnitude of roundoff.
98 // Taken from units gnu commandline tool
99 const double FGJSBBase::slugtolb = 32.174049;
100 const double FGJSBBase::lbtoslug = 1.0/slugtolb;
101 const double FGJSBBase::kgtolb = 2.20462;
102 const double FGJSBBase::kgtoslug = 0.06852168;
103
104 const string FGJSBBase::needed_cfg_version = "2.0";
105 const string FGJSBBase::JSBSim_version = "1.0 "__DATE__" "__TIME__;
106
107 std::queue <FGJSBBase::Message> FGJSBBase::Messages;
108 FGJSBBase::Message FGJSBBase::localMsg;
109 unsigned int FGJSBBase::messageId = 0;
110
111 short FGJSBBase::debug_lvl  = 1;
112
113 using std::cerr;
114 using std::cout;
115 using std::endl;
116
117 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
118
119 void FGJSBBase::PutMessage(const Message& msg)
120 {
121   Messages.push(msg);
122 }
123
124 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
125
126 void FGJSBBase::PutMessage(const string& text)
127 {
128   Message msg;
129   msg.text = text;
130   msg.messageId = messageId++;
131   msg.subsystem = "FDM";
132   msg.type = Message::eText;
133   Messages.push(msg);
134 }
135
136 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
137
138 void FGJSBBase::PutMessage(const string& text, bool bVal)
139 {
140   Message msg;
141   msg.text = text;
142   msg.messageId = messageId++;
143   msg.subsystem = "FDM";
144   msg.type = Message::eBool;
145   msg.bVal = bVal;
146   Messages.push(msg);
147 }
148
149 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
150
151 void FGJSBBase::PutMessage(const string& text, int iVal)
152 {
153   Message msg;
154   msg.text = text;
155   msg.messageId = messageId++;
156   msg.subsystem = "FDM";
157   msg.type = Message::eInteger;
158   msg.bVal = (iVal != 0);
159   Messages.push(msg);
160 }
161
162 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
163
164 void FGJSBBase::PutMessage(const string& text, double dVal)
165 {
166   Message msg;
167   msg.text = text;
168   msg.messageId = messageId++;
169   msg.subsystem = "FDM";
170   msg.type = Message::eDouble;
171   msg.bVal = (dVal != 0.0);
172   Messages.push(msg);
173 }
174
175 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
176
177 int FGJSBBase::SomeMessages(void)
178 {
179   return !Messages.empty();
180 }
181
182 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
183
184 void FGJSBBase::ProcessMessage(void)
185 {
186   if (Messages.empty()) return;
187   localMsg = Messages.front();
188
189   while (Messages.size() > 0) {
190       switch (localMsg.type) {
191       case JSBSim::FGJSBBase::Message::eText:
192         cout << localMsg.messageId << ": " << localMsg.text << endl;
193         break;
194       case JSBSim::FGJSBBase::Message::eBool:
195         cout << localMsg.messageId << ": " << localMsg.text << " " << localMsg.bVal << endl;
196         break;
197       case JSBSim::FGJSBBase::Message::eInteger:
198         cout << localMsg.messageId << ": " << localMsg.text << " " << localMsg.iVal << endl;
199         break;
200       case JSBSim::FGJSBBase::Message::eDouble:
201         cout << localMsg.messageId << ": " << localMsg.text << " " << localMsg.dVal << endl;
202         break;
203       default:
204         cerr << "Unrecognized message type." << endl;
205         break;
206       }
207       Messages.pop();
208       if (Messages.size() > 0) localMsg = Messages.front();
209       else break;
210   }
211
212 }
213
214 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
215
216 FGJSBBase::Message* FGJSBBase::ProcessNextMessage(void)
217 {
218   if (Messages.empty()) return NULL;
219   localMsg = Messages.front();
220
221   Messages.pop();
222   return &localMsg;
223 }
224
225 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
226
227 void FGJSBBase::disableHighLighting(void) {
228   highint[0]='\0';
229   halfint[0]='\0';
230   normint[0]='\0';
231   reset[0]='\0';
232   underon[0]='\0';
233   underoff[0]='\0';
234   fgblue[0]='\0';
235   fgcyan[0]='\0';
236   fgred[0]='\0';
237   fggreen[0]='\0';
238   fgdef[0]='\0';
239 }
240
241 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
242
243 } // namespace JSBSim
244