]> git.mxchange.org Git - flightgear.git/blob - src/Navaids/ils.hxx
Roy Vegard Ovesen:
[flightgear.git] / src / Navaids / ils.hxx
1 // ils.hxx -- navaid class
2 //
3 // Written by Curtis Olson, started April 2000.
4 //
5 // Copyright (C) 2000  Curtis L. Olson - curt@flightgear.org
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
24 #ifndef _FG_ILS_HXX
25 #define _FG_ILS_HXX
26
27
28 #include <simgear/compiler.h>
29 #include <simgear/constants.h>
30 #include <simgear/math/sg_geodesy.hxx>
31 #include <simgear/misc/sgstream.hxx>
32
33 #ifdef SG_HAVE_STD_INCLUDES
34 #  include <istream>
35 #elif defined( __BORLANDC__ ) || (__APPLE__)
36 #  include <iostream>
37 #else
38 #  include <istream.h>
39 #endif
40
41 SG_USING_STD(istream);
42
43
44 #define FG_ILS_DEFAULT_RANGE 18
45
46 class FGILS {
47
48     char ilstype;
49     char ilstypename[6];
50     char aptcode[5];
51     char rwyno[4];
52     int  locfreq;
53     char locident[5];           // official ident
54     double locheading;
55     double loclat;
56     double loclon;
57     double x, y, z;
58     bool has_gs;
59     double gselev;
60     double gsangle;
61     double gslat;
62     double gslon;
63     double gs_x, gs_y, gs_z;
64     bool has_dme;
65     double dmelat;
66     double dmelon;
67     double dme_x, dme_y, dme_z;
68     double omlat;
69     double omlon;
70     double mmlat;
71     double mmlon;
72     double imlat;
73     double imlon;
74
75     // for failure modeling
76     string trans_ident;         // transmitted ident
77     bool loc_failed;            // localizer failed?
78     bool gs_failed;             // glide slope failed?
79     bool dme_failed;            // dme failed?
80
81 public:
82
83     inline FGILS(void);
84     inline ~FGILS(void) {}
85
86     inline char get_ilstype() const { return ilstype; }
87     inline char *get_ilstypename() { return ilstypename; }
88     inline char *get_aptcode() { return aptcode; }
89     inline char *get_rwyno() { return rwyno; }
90     inline int get_locfreq() const { return locfreq; }
91     inline char *get_locident() { return locident; }
92     inline string get_trans_ident() { return trans_ident; }
93     inline double get_locheading() const { return locheading; }
94     inline double get_loclat() const { return loclat; }
95     inline double get_loclon() const { return loclon; }
96     inline double get_x() const { return x; }
97     inline double get_y() const { return y; }
98     inline double get_z() const { return z; }
99     inline bool get_has_gs() const { return has_gs; }
100     inline double get_gselev() const { return gselev; }
101     inline double get_gsangle() const { return gsangle; }
102     inline double get_gslat() const { return gslat; }
103     inline double get_gslon() const { return gslon; }
104     inline double get_gs_x() const { return gs_x; }
105     inline double get_gs_y() const { return gs_y; }
106     inline double get_gs_z() const { return gs_z; }
107     inline bool get_has_dme() const { return has_dme; }
108     inline double get_dmelat() const { return dmelat; }
109     inline double get_dmelon() const { return dmelon; }
110     inline double get_dme_x() const { return dme_x; }
111     inline double get_dme_y() const { return dme_y; }
112     inline double get_dme_z() const { return dme_z; }
113     inline double get_omlat() const { return omlat; }
114     inline double get_omlon() const { return omlon; }
115     inline double get_mmlat() const { return mmlat; }
116     inline double get_mmlon() const { return mmlon; }
117     inline double get_imlat() const { return imlat; }
118     inline double get_imlon() const { return imlon; }
119
120     friend istream& operator>> ( istream&, FGILS& );
121 };
122
123
124 inline
125 FGILS::FGILS(void)
126   : ilstype(0),
127     locfreq(0),
128     locheading(0.0),
129     loclat(0.0),
130     loclon(0.0),
131     x(0.0), y(0.0), z(0.0),
132     has_gs(false),
133     gselev(0.0),
134     gsangle(0.0),
135     gslat(0.0),
136     gslon(0.0),
137     gs_x(0.0), gs_y(0.0), gs_z(0.0),
138     has_dme(false),
139     dmelat(0.0),
140     dmelon(0.0),
141     dme_x(0.0), dme_y(0.0), dme_z(0.0),
142     omlat(0.0),
143     omlon(0.0),
144     mmlat(0.0),
145     mmlon(0.0),
146     imlat(0.0),
147     imlon(0.0),
148     trans_ident(""),
149     loc_failed(false),
150     gs_failed(false),
151     dme_failed(false)
152 {
153     ilstypename[0] = '\0';
154     aptcode[0] = '\0';
155     rwyno[0] = '\0';
156     locident[0] = '\0';
157 }
158
159     
160 inline istream&
161 operator >> ( istream& in, FGILS& i )
162 {
163     double f;
164     in >> i.ilstype;
165     
166     if ( i.ilstype == '[' )
167           return in;
168
169     in >> i.ilstypename >> i.aptcode >> i.rwyno 
170        >> f >> i.locident >> i.locheading >> i.loclat >> i.loclon
171        >> i.gselev >> i.gsangle >> i.gslat >> i.gslon
172        >> i.dmelat >> i.dmelon
173        >> i.omlat >> i.omlon
174        >> i.mmlat >> i.mmlon
175        >> i.imlat >> i.imlon;
176         
177
178     i.locfreq = (int)(f*100.0 + 0.5);
179
180     // generate cartesian coordinates
181     Point3D geod, cart;
182
183     geod = Point3D( i.loclon * SGD_DEGREES_TO_RADIANS,
184                     i.loclat * SGD_DEGREES_TO_RADIANS,
185                     i.gselev * SG_FEET_TO_METER );
186     cart = sgGeodToCart( geod );
187     i.x = cart.x();
188     i.y = cart.y();
189     i.z = cart.z();
190
191     if ( i.gslon < SG_EPSILON && i.gslat < SG_EPSILON ) {
192         i.has_gs = false;
193     } else {
194         i.has_gs = true;
195
196         geod = Point3D( i.gslon * SGD_DEGREES_TO_RADIANS,
197                         i.gslat * SGD_DEGREES_TO_RADIANS,
198                         i.gselev * SG_FEET_TO_METER );
199         cart = sgGeodToCart( geod );
200         i.gs_x = cart.x();
201         i.gs_y = cart.y();
202         i.gs_z = cart.z();
203         // cout << "gs = " << cart << endl;
204     }
205
206     if ( i.dmelon < SG_EPSILON && i.dmelat < SG_EPSILON ) {
207         i.has_dme = false;
208     } else {
209         i.has_dme = true;
210
211         geod = Point3D( i.dmelon * SGD_DEGREES_TO_RADIANS,
212                         i.dmelat * SGD_DEGREES_TO_RADIANS,
213                         i.gselev * SG_FEET_TO_METER );
214         cart = sgGeodToCart( geod );
215         i.dme_x = cart.x();
216         i.dme_y = cart.y();
217         i.dme_z = cart.z();
218         // cout << "dme = " << cart << endl;
219     }
220
221     i.trans_ident = "I";
222     i.trans_ident += i.locident;
223     i.loc_failed = i.gs_failed = i.dme_failed = false;
224    
225     // return in >> skipeol;
226     return in;
227 }
228
229
230 #endif // _FG_ILS_HXX