]> git.mxchange.org Git - flightgear.git/blob - src/FDM/UIUCModel/uiuc_menu_engine.cpp
- rename fgcommand "set-mouse" to "set-cursor"
[flightgear.git] / src / FDM / UIUCModel / uiuc_menu_engine.cpp
1 /**********************************************************************
2                                                                        
3  FILENAME:     uiuc_menu_engine.cpp
4
5 ----------------------------------------------------------------------
6
7  DESCRIPTION:  reads input data for specified aircraft and creates 
8                approporiate data storage space
9
10 ----------------------------------------------------------------------
11
12  STATUS:       alpha version
13
14 ----------------------------------------------------------------------
15
16  REFERENCES:   based on "menu reader" format of Michael Selig
17
18 ----------------------------------------------------------------------
19
20  HISTORY:      04/04/2003   initial release
21                06/30/2003   (RD) replaced istrstream with istringstream
22                             to get rid of the annoying warning about
23                             using the strstream header
24
25 ----------------------------------------------------------------------
26
27  AUTHOR(S):    Robert Deters      <rdeters@uiuc.edu>
28                Michael Selig      <m-selig@uiuc.edu>
29
30 ----------------------------------------------------------------------
31
32  VARIABLES:
33
34 ----------------------------------------------------------------------
35
36  INPUTS:       n/a
37
38 ----------------------------------------------------------------------
39
40  OUTPUTS:      n/a
41
42 ----------------------------------------------------------------------
43
44  CALLED BY:    uiuc_menu()
45
46 ----------------------------------------------------------------------
47
48  CALLS TO:     check_float() if needed
49                d_2_to_3() if needed
50                d_1_to_2() if needed
51                i_1_to_2() if needed
52                d_1_to_1() if needed
53
54  ----------------------------------------------------------------------
55
56  COPYRIGHT:    (C) 2003 by Michael Selig
57
58  This program is free software; you can redistribute it and/or
59  modify it under the terms of the GNU General Public License
60  as published by the Free Software Foundation.
61
62  This program is distributed in the hope that it will be useful,
63  but WITHOUT ANY WARRANTY; without even the implied warranty of
64  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
65  GNU General Public License for more details.
66
67  You should have received a copy of the GNU General Public License
68  along with this program; if not, write to the Free Software
69  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
70
71 **********************************************************************/
72
73 #include <simgear/compiler.h>
74
75 #if defined( __MWERKS__ )
76 // -dw- optimizer chokes (big-time) trying to optimize humongous
77 // loop/switch statements
78 #pragma optimization_level 0
79 #endif
80
81 #include <cstdlib>
82 #include <string>
83 #include STL_IOSTREAM
84
85 #include "uiuc_menu_engine.h"
86
87 SG_USING_STD(cerr);
88 SG_USING_STD(cout);
89 SG_USING_STD(endl);
90
91 #ifndef _MSC_VER
92 SG_USING_STD(exit);
93 #endif
94
95 void parse_engine( const string& linetoken2, const string& linetoken3,
96                    const string& linetoken4, const string& linetoken5, 
97                    const string& linetoken6, const string& linetoken7, 
98                    const string& linetoken8, const string& linetoken9,
99                    const string& linetoken10,const string& aircraft_directory,
100                    LIST command_line ) {
101     double token_value;
102     int token_value_convert1, token_value_convert2;
103     istringstream token3(linetoken3.c_str());
104     istringstream token4(linetoken4.c_str());
105     istringstream token5(linetoken5.c_str());
106     istringstream token6(linetoken6.c_str());
107     istringstream token7(linetoken7.c_str());
108     istringstream token8(linetoken8.c_str());
109     istringstream token9(linetoken9.c_str());
110     istringstream token10(linetoken10.c_str());
111
112     switch(engine_map[linetoken2])
113       {
114       case simpleSingle_flag:
115         {
116           if (check_float(linetoken3))
117             token3 >> token_value;
118           else
119             uiuc_warnings_errors(1, *command_line);
120           
121           simpleSingleMaxThrust = token_value; 
122           engineParts -> storeCommands (*command_line);
123           break;
124         }
125       case simpleSingleModel_flag:
126         {
127           simpleSingleModel = true;
128           /* input the thrust at zero speed */
129           if (check_float(linetoken3))
130             token3 >> token_value;
131           else
132             uiuc_warnings_errors(1, *command_line);
133           t_v0 = token_value; 
134           /* input slope of thrust at speed for which thrust is zero */
135           if (check_float(linetoken4))
136             token4 >> token_value;
137           else
138             uiuc_warnings_errors(1, *command_line);
139           dtdv_t0 = token_value; 
140           /* input speed at which thrust is zero */
141           if (check_float(linetoken5))
142             token5 >> token_value;
143           else
144             uiuc_warnings_errors(1, *command_line);
145           v_t0 = token_value; 
146           dtdvvt = -dtdv_t0 * v_t0 / t_v0;
147           engineParts -> storeCommands (*command_line);
148           break;
149         }
150       case c172_flag:
151         {
152           engineParts -> storeCommands (*command_line);
153           break;
154         }
155       case cherokee_flag:
156         {
157           engineParts -> storeCommands (*command_line);
158           break;
159         }
160       case Throttle_pct_input_flag:
161         {
162           Throttle_pct_input = true;
163           Throttle_pct_input_file = aircraft_directory + linetoken3;
164           token4 >> token_value_convert1;
165           token5 >> token_value_convert2;
166           convert_y = uiuc_convert(token_value_convert1);
167           convert_x = uiuc_convert(token_value_convert2);
168           uiuc_1DdataFileReader(Throttle_pct_input_file,
169                                 Throttle_pct_input_timeArray,
170                                 Throttle_pct_input_dTArray,
171                                 Throttle_pct_input_ntime);
172           token6 >> token_value;
173           Throttle_pct_input_startTime = token_value;
174           break;
175         }
176       case gyroForce_Q_body_flag:
177         {
178           /* include gyroscopic forces due to pitch */
179           gyroForce_Q_body = true;
180           break;
181         }
182       case gyroForce_R_body_flag:
183         {
184           /* include gyroscopic forces due to yaw */
185           gyroForce_R_body = true;
186           break;
187         }
188
189       case slipstream_effects_flag:
190         {
191         // include slipstream effects
192           b_slipstreamEffects = true;
193           if (!simpleSingleModel)
194             uiuc_warnings_errors(3, *command_line);
195           break;
196         }
197       case propDia_flag:
198         {
199           if (check_float(linetoken3))
200             token3 >> token_value;
201           else
202             uiuc_warnings_errors(1, *command_line);
203           propDia = token_value;
204           break;
205         }
206       case eta_q_Cm_q_flag:
207         {
208         // include slipstream effects due to Cm_q
209           if (check_float(linetoken3))
210             token3 >> token_value;
211           else
212             uiuc_warnings_errors(1, *command_line);
213           eta_q_Cm_q_fac = token_value;
214           if (eta_q_Cm_q_fac == 0.0) {eta_q_Cm_q_fac = 1.0;}
215           break;
216         }
217       case eta_q_Cm_adot_flag:
218         {
219         // include slipstream effects due to Cm_adot
220           if (check_float(linetoken3))
221             token3 >> token_value;
222           else
223             uiuc_warnings_errors(1, *command_line);
224           eta_q_Cm_adot_fac = token_value;
225           if (eta_q_Cm_adot_fac == 0.0) {eta_q_Cm_adot_fac = 1.0;}
226           break;
227         }
228       case eta_q_Cmfade_flag:
229         {
230         // include slipstream effects due to Cmfade
231           if (check_float(linetoken3))
232             token3 >> token_value;
233           else
234             uiuc_warnings_errors(1, *command_line);
235           eta_q_Cmfade_fac = token_value;
236           if (eta_q_Cmfade_fac == 0.0) {eta_q_Cmfade_fac = 1.0;}
237           break;
238         }
239       case eta_q_Cm_de_flag:
240         {
241         // include slipstream effects due to Cmfade
242           if (check_float(linetoken3))
243             token3 >> token_value;
244           else
245             uiuc_warnings_errors(1, *command_line);
246           eta_q_Cm_de_fac = token_value;
247           if (eta_q_Cm_de_fac == 0.0) {eta_q_Cm_de_fac = 1.0;}
248           break;
249         }
250       case eta_q_Cl_beta_flag:
251         {
252         // include slipstream effects due to Cl_beta
253           if (check_float(linetoken3))
254             token3 >> token_value;
255           else
256             uiuc_warnings_errors(1, *command_line);
257           eta_q_Cl_beta_fac = token_value;
258           if (eta_q_Cl_beta_fac == 0.0) {eta_q_Cl_beta_fac = 1.0;}
259           break;
260         }
261       case eta_q_Cl_p_flag:
262         {
263         // include slipstream effects due to Cl_p
264           if (check_float(linetoken3))
265             token3 >> token_value;
266           else
267             uiuc_warnings_errors(1, *command_line);
268           eta_q_Cl_p_fac = token_value;
269           if (eta_q_Cl_p_fac == 0.0) {eta_q_Cl_p_fac = 1.0;}
270           break;
271         }
272       case eta_q_Cl_r_flag:
273         {
274         // include slipstream effects due to Cl_r
275           if (check_float(linetoken3))
276             token3 >> token_value;
277           else
278             uiuc_warnings_errors(1, *command_line);
279           eta_q_Cl_r_fac = token_value;
280           if (eta_q_Cl_r_fac == 0.0) {eta_q_Cl_r_fac = 1.0;}
281           break;
282         }
283       case eta_q_Cl_dr_flag:
284         {
285         // include slipstream effects due to Cl_dr
286           if (check_float(linetoken3))
287             token3 >> token_value;
288           else
289             uiuc_warnings_errors(1, *command_line);
290           eta_q_Cl_dr_fac = token_value;
291           if (eta_q_Cl_dr_fac == 0.0) {eta_q_Cl_dr_fac = 1.0;}
292           break;
293         }
294       case eta_q_CY_beta_flag:
295         {
296         // include slipstream effects due to CY_beta
297           if (check_float(linetoken3))
298             token3 >> token_value;
299           else
300             uiuc_warnings_errors(1, *command_line);
301           eta_q_CY_beta_fac = token_value;
302           if (eta_q_CY_beta_fac == 0.0) {eta_q_CY_beta_fac = 1.0;}
303           break;
304         }
305       case eta_q_CY_p_flag:
306         {
307         // include slipstream effects due to CY_p
308           if (check_float(linetoken3))
309             token3 >> token_value;
310           else
311             uiuc_warnings_errors(1, *command_line);
312           eta_q_CY_p_fac = token_value;
313           if (eta_q_CY_p_fac == 0.0) {eta_q_CY_p_fac = 1.0;}
314           break;
315         }
316       case eta_q_CY_r_flag:
317         {
318         // include slipstream effects due to CY_r
319           if (check_float(linetoken3))
320             token3 >> token_value;
321           else
322             uiuc_warnings_errors(1, *command_line);
323           eta_q_CY_r_fac = token_value;
324           if (eta_q_CY_r_fac == 0.0) {eta_q_CY_r_fac = 1.0;}
325           break;
326         }
327       case eta_q_CY_dr_flag:
328         {
329         // include slipstream effects due to CY_dr
330           if (check_float(linetoken3))
331             token3 >> token_value;
332           else
333             uiuc_warnings_errors(1, *command_line);
334           eta_q_CY_dr_fac = token_value;
335           if (eta_q_CY_dr_fac == 0.0) {eta_q_CY_dr_fac = 1.0;}
336           break;
337         }
338       case eta_q_Cn_beta_flag:
339         {
340         // include slipstream effects due to Cn_beta
341           if (check_float(linetoken3))
342             token3 >> token_value;
343           else
344             uiuc_warnings_errors(1, *command_line);
345           eta_q_Cn_beta_fac = token_value;
346           if (eta_q_Cn_beta_fac == 0.0) {eta_q_Cn_beta_fac = 1.0;}
347           break;
348         }
349       case eta_q_Cn_p_flag:
350         {
351         // include slipstream effects due to Cn_p
352           if (check_float(linetoken3))
353             token3 >> token_value;
354           else
355             uiuc_warnings_errors(1, *command_line);
356           eta_q_Cn_p_fac = token_value;
357           if (eta_q_Cn_p_fac == 0.0) {eta_q_Cn_p_fac = 1.0;}
358           break;
359         }
360       case eta_q_Cn_r_flag:
361         {
362         // include slipstream effects due to Cn_r
363           if (check_float(linetoken3))
364             token3 >> token_value;
365           else
366             uiuc_warnings_errors(1, *command_line);
367           eta_q_Cn_r_fac = token_value;
368           if (eta_q_Cn_r_fac == 0.0) {eta_q_Cn_r_fac = 1.0;}
369           break;
370         }
371       case eta_q_Cn_dr_flag:
372         {
373         // include slipstream effects due to Cn_dr
374           if (check_float(linetoken3))
375             token3 >> token_value;
376           else
377             uiuc_warnings_errors(1, *command_line);
378           eta_q_Cn_dr_fac = token_value;
379           if (eta_q_Cn_dr_fac == 0.0) {eta_q_Cn_dr_fac = 1.0;}
380           break;
381         }
382
383       case omega_flag:
384         {
385           if (check_float(linetoken3))
386             token3 >> token_value;
387           else
388             uiuc_warnings_errors(1, *command_line);
389           minOmega = token_value; 
390           if (check_float(linetoken4))
391             token4 >> token_value;
392           else
393             uiuc_warnings_errors(1, *command_line);
394           maxOmega = token_value; 
395           break;
396         }
397       case omegaRPM_flag:
398         {
399           if (check_float(linetoken3))
400             token3 >> token_value;
401           else
402             uiuc_warnings_errors(1, *command_line);
403           minOmegaRPM = token_value; 
404           minOmega    = minOmegaRPM * 2.0 * LS_PI / 60;
405           if (check_float(linetoken4))
406             token4 >> token_value;
407           else
408             uiuc_warnings_errors(1, *command_line);
409           maxOmegaRPM = token_value; 
410           maxOmega    = maxOmegaRPM * 2.0 * LS_PI / 60;
411           break;
412         }
413       case polarInertia_flag:
414         {
415           if (check_float(linetoken3))
416             token3 >> token_value;
417           else
418             uiuc_warnings_errors(1, *command_line);
419           polarInertia = token_value; 
420           break;
421         }
422       case forcemom_flag:
423         {
424           engineParts -> storeCommands (*command_line);
425           break;
426         }
427       case Xp_input_flag:
428         {
429           Xp_input = true;
430           Xp_input_file = aircraft_directory + linetoken3;
431           token4 >> token_value_convert1;
432           token5 >> token_value_convert2;
433           convert_y = uiuc_convert(token_value_convert1);
434           convert_x = uiuc_convert(token_value_convert2);
435           uiuc_1DdataFileReader(Xp_input_file,
436                                 Xp_input_timeArray,
437                                 Xp_input_XpArray,
438                                 Xp_input_ntime);
439           token6 >> token_value;
440           Xp_input_startTime = token_value;
441           break;
442         }
443       case Zp_input_flag:
444         {
445           Zp_input = true;
446           Zp_input_file = aircraft_directory + linetoken3;
447           token4 >> token_value_convert1;
448           token5 >> token_value_convert2;
449           convert_y = uiuc_convert(token_value_convert1);
450           convert_x = uiuc_convert(token_value_convert2);
451           uiuc_1DdataFileReader(Zp_input_file,
452                                 Zp_input_timeArray,
453                                 Zp_input_ZpArray,
454                                 Zp_input_ntime);
455           token6 >> token_value;
456           Zp_input_startTime = token_value;
457           break;
458         }
459       case Mp_input_flag:
460         {
461           Mp_input = true;
462           Mp_input_file = aircraft_directory + linetoken3;
463           token4 >> token_value_convert1;
464           token5 >> token_value_convert2;
465           convert_y = uiuc_convert(token_value_convert1);
466           convert_x = uiuc_convert(token_value_convert2);
467           uiuc_1DdataFileReader(Mp_input_file,
468                                 Mp_input_timeArray,
469                                 Mp_input_MpArray,
470                                 Mp_input_ntime);
471           token6 >> token_value;
472           Mp_input_startTime = token_value;
473           break;
474         }
475       default:
476         {
477           if (ignore_unknown_keywords) {
478             // do nothing
479           } else {
480             // print error message
481             uiuc_warnings_errors(2, *command_line);
482           }
483           break;
484         }
485       };
486 }