]> git.mxchange.org Git - flightgear.git/blob - src/Navaids/navrecord.hxx
Remove nav.hxx, which has been superceded by navrecord.hxx and is no longer used...
[flightgear.git] / src / Navaids / navrecord.hxx
1 // navrecord.hxx -- generic vor/dme/ndb class
2 //
3 // Written by Curtis Olson, started May 2004.
4 //
5 // Copyright (C) 2004  Curtis L. Olson - http://www.flightgear.org/~curt
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_NAVRECORD_HXX
25 #define _FG_NAVRECORD_HXX
26
27 #include <stdio.h>
28
29 #include <simgear/compiler.h>
30 #include <simgear/math/sg_geodesy.hxx>
31 #include <simgear/misc/sgstream.hxx>
32 #include <simgear/magvar/magvar.hxx>
33 #include <simgear/timing/sg_time.hxx>
34
35 #ifdef SG_HAVE_STD_INCLUDES
36 #  include <istream>
37 #elif defined( __BORLANDC__ ) || (__APPLE__)
38 #  include <iostream>
39 #else
40 #  include <istream.h>
41 #endif
42
43 SG_USING_STD(istream);
44
45
46 #define FG_NAV_DEFAULT_RANGE 50 // nm
47 #define FG_LOC_DEFAULT_RANGE 18 // nm
48 #define FG_DME_DEFAULT_RANGE 50 // nm
49 #define FG_NAV_MAX_RANGE 300    // nm
50
51
52 class FGNavRecord {
53
54     int type;
55     double lon, lat;            // location in geodetic coords
56     double elev_ft;
57     double x, y, z;             // location in cartesian coords (earth centered)
58     int freq;
59     int range;
60     double multiuse;            // can be slaved variation of VOR
61                                 // (degrees) or localizer heading
62                                 // (degrees) or dme bias (nm)
63
64     string ident;               // navaid ident
65     string name;                // verbose name in nav database
66     string apt_id;              // corresponding airport id
67
68
69     bool serviceable;           // for failure modeling
70     string trans_ident;         // for failure modeling
71
72 public:
73
74     inline FGNavRecord(void);
75     inline ~FGNavRecord(void) {}
76
77     inline int get_type() const { return type; }
78     inline double get_lon() const { return lon; }
79     inline void set_lon( double l ) { lon = l; }
80     inline double get_lat() const { return lat; }
81     inline void set_lat( double l ) { lat = l; }
82     inline double get_elev_ft() const { return elev_ft; }
83     inline void set_elev_ft( double e ) { elev_ft = e; }
84     inline double get_x() const { return x; }
85     inline double get_y() const { return y; }
86     inline double get_z() const { return z; }
87     inline int get_freq() const { return freq; }
88     inline int get_range() const { return range; }
89     inline double get_multiuse() const { return multiuse; }
90     inline void set_multiuse( double m ) { multiuse = m; }
91     inline const char *get_ident() const { return ident.c_str(); }
92     inline const string& get_name() const { return name; }
93     inline const string& get_apt_id() const { return apt_id; }
94     inline bool get_serviceable() const { return serviceable; }
95     inline const char *get_trans_ident() const { return trans_ident.c_str(); }
96
97     friend istream& operator>> ( istream&, FGNavRecord& );
98 };
99
100
101 inline
102 FGNavRecord::FGNavRecord(void) :
103     type(0),
104     lon(0.0), lat(0.0),
105     elev_ft(0.0),
106     x(0.0), y(0.0), z(0.0),
107     freq(0),
108     range(0),
109     multiuse(0.0),
110     ident(""),
111     name(""),
112     apt_id(""),
113     serviceable(true),
114     trans_ident("")
115 {
116 }
117
118
119 inline istream&
120 operator >> ( istream& in, FGNavRecord& n )
121 {
122     in >> n.type;
123     
124     if ( n.type == 99 ) {
125         return in >> skipeol;
126     }
127
128     in >> n.lat >> n.lon >> n.elev_ft >> n.freq >> n.multiuse
129        >> n.ident;
130     getline( in, n.name );
131
132     // silently multiply adf frequencies by 100 so that adf
133     // vs. nav/loc frequency lookups can use the same code.
134     if ( n.type == 2 ) {
135         n.freq *= 100;
136     }
137
138     // Remove any leading spaces before the name
139     while ( n.name.substr(0,1) == " " ) {
140         n.name = n.name.erase(0,1);
141     }
142
143     if ( n.type >= 4 && n.type <= 9 ) {
144         // these types are always associated with an airport id
145         string::size_type pos = n.name.find(" ");
146         n.apt_id = n.name.substr(0, pos);
147     }
148
149     // assign default ranges
150     if ( n.type == 2 || n.type == 3 ) {
151         n.range = FG_NAV_DEFAULT_RANGE;
152     } else if ( n.type == 4 || n.type == 5 || n.type == 6 ) {
153         n.range = FG_LOC_DEFAULT_RANGE;
154     } else if ( n.type == 12 ) {
155         n.range = FG_DME_DEFAULT_RANGE;
156     } else {
157         n.range = FG_LOC_DEFAULT_RANGE;
158     }
159
160     // transmitted ident (same as ident unless modeling a fault)
161     n.trans_ident = n.ident;
162
163     // generate cartesian coordinates
164     Point3D geod( n.lon * SGD_DEGREES_TO_RADIANS,
165                   n.lat * SGD_DEGREES_TO_RADIANS,
166                   n.elev_ft * SG_FEET_TO_METER );
167     Point3D cart = sgGeodToCart( geod );
168     n.x = cart.x();
169     n.y = cart.y();
170     n.z = cart.z();
171
172     return in;
173 }
174
175 class FGTACANRecord {
176
177     string channel;             
178     int freq;
179      
180 public:
181     
182     inline FGTACANRecord(void);
183     inline ~FGTACANRecord(void) {}
184
185     inline const string& get_channel() const { return channel; }
186     inline int get_freq() const { return freq; }
187     friend istream& operator>> ( istream&, FGTACANRecord& );
188     };
189
190
191 inline
192 FGTACANRecord::FGTACANRecord(void) :
193     channel(""),
194     freq(0)
195     
196 {
197 }
198
199 inline istream&
200 operator >> ( istream& in, FGTACANRecord& n )
201 {
202     in >> n.channel >> n.freq ;
203     //getline( in, n.name );
204
205     return in;
206 }
207 #endif // _FG_NAVRECORD_HXX