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