]> git.mxchange.org Git - flightgear.git/blob - src/Navaids/navrecord.hxx
Fix line endings
[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 // Shield the rest of FG from possibly changing details of Robins navaid type numbering system.
52 // Currently only the GPS code uses this - extra types (LOC, GS etc) may need to be added
53 // should other FG code choose to use this. 
54 enum fg_nav_types {
55     FG_NAV_VOR,
56     FG_NAV_NDB,
57     FG_NAV_ILS,
58     FG_NAV_ANY
59 };
60
61 class FGNavRecord {
62
63     int type;
64     double lon, lat;            // location in geodetic coords (degrees)
65     double elev_ft;
66     double x, y, z;             // location in cartesian coords (earth centered)
67     int freq;
68     int range;
69     double multiuse;            // can be slaved variation of VOR
70                                 // (degrees) or localizer heading
71                                 // (degrees) or dme bias (nm)
72
73     string ident;               // navaid ident
74     string name;                // verbose name in nav database
75     string apt_id;              // corresponding airport id
76
77
78     bool serviceable;           // for failure modeling
79     string trans_ident;         // for failure modeling
80
81 public:
82
83     inline FGNavRecord(void);
84     inline ~FGNavRecord(void) {}
85
86     inline int get_type() const { return type; }
87     inline fg_nav_types get_fg_type() const;
88     inline double get_lon() const { return lon; }       // degrees
89     inline void set_lon( double l ) { lon = l; }        // degrees
90     inline double get_lat() const { return lat; }       // degrees
91     inline void set_lat( double l ) { lat = l; }        // degrees
92     inline double get_elev_ft() const { return elev_ft; }
93     inline void set_elev_ft( double e ) { elev_ft = e; }
94     inline double get_x() const { return x; }
95     inline double get_y() const { return y; }
96     inline double get_z() const { return z; }
97     inline int get_freq() const { return freq; }
98     inline int get_range() const { return range; }
99     inline double get_multiuse() const { return multiuse; }
100     inline void set_multiuse( double m ) { multiuse = m; }
101     inline const char *get_ident() const { return ident.c_str(); }
102     inline const string& get_name() const { return name; }
103     inline const string& get_apt_id() const { return apt_id; }
104     inline bool get_serviceable() const { return serviceable; }
105     inline const char *get_trans_ident() const { return trans_ident.c_str(); }
106
107     friend istream& operator>> ( istream&, FGNavRecord& );
108 };
109
110
111 inline
112 FGNavRecord::FGNavRecord(void) :
113     type(0),
114     lon(0.0), lat(0.0),
115     elev_ft(0.0),
116     x(0.0), y(0.0), z(0.0),
117     freq(0),
118     range(0),
119     multiuse(0.0),
120     ident(""),
121     name(""),
122     apt_id(""),
123     serviceable(true),
124     trans_ident("")
125 {
126 }
127
128
129 inline fg_nav_types FGNavRecord::get_fg_type() const {
130     switch(type) {
131     case 2: return(FG_NAV_NDB);
132     case 3: return(FG_NAV_VOR);
133     case 4: return(FG_NAV_ILS);
134     default: return(FG_NAV_ANY);
135     }
136 }
137
138
139 inline istream&
140 operator >> ( istream& in, FGNavRecord& n )
141 {
142     in >> n.type;
143     
144     if ( n.type == 99 ) {
145         return in >> skipeol;
146     }
147
148     in >> n.lat >> n.lon >> n.elev_ft >> n.freq >> n.range >> n.multiuse
149        >> n.ident;
150     getline( in, n.name );
151
152     // silently multiply adf frequencies by 100 so that adf
153     // vs. nav/loc frequency lookups can use the same code.
154     if ( n.type == 2 ) {
155         n.freq *= 100;
156     }
157
158     // Remove any leading spaces before the name
159     while ( n.name.substr(0,1) == " " ) {
160         n.name = n.name.erase(0,1);
161     }
162
163     if ( n.type >= 4 && n.type <= 9 ) {
164         // these types are always associated with an airport id
165         string::size_type pos = n.name.find(" ");
166         n.apt_id = n.name.substr(0, pos);
167     }
168
169     // Ranges are included with the latest data format, no need to
170     // assign our own defaults, unless the range is not set for some
171     // reason.
172
173     if ( n.range < 0.1 ) {
174         // assign default ranges
175     
176         if ( n.type == 2 || n.type == 3 ) {
177             n.range = FG_NAV_DEFAULT_RANGE;
178         } else if ( n.type == 4 || n.type == 5 || n.type == 6 ) {
179             n.range = FG_LOC_DEFAULT_RANGE;
180         } else if ( n.type == 12 ) {
181             n.range = FG_DME_DEFAULT_RANGE;
182         } else {
183             n.range = FG_LOC_DEFAULT_RANGE;
184         }
185     }
186
187     // transmitted ident (same as ident unless modeling a fault)
188     n.trans_ident = n.ident;
189
190     // generate cartesian coordinates
191     Point3D geod( n.lon * SGD_DEGREES_TO_RADIANS,
192                   n.lat * SGD_DEGREES_TO_RADIANS,
193                   n.elev_ft * SG_FEET_TO_METER );
194     Point3D cart = sgGeodToCart( geod );
195     n.x = cart.x();
196     n.y = cart.y();
197     n.z = cart.z();
198
199     return in;
200 }
201
202 class FGTACANRecord {
203
204     string channel;             
205     int freq;
206      
207 public:
208     
209     inline FGTACANRecord(void);
210     inline ~FGTACANRecord(void) {}
211
212     inline const string& get_channel() const { return channel; }
213     inline int get_freq() const { return freq; }
214     friend istream& operator>> ( istream&, FGTACANRecord& );
215     };
216
217
218 inline
219 FGTACANRecord::FGTACANRecord(void) :
220     channel(""),
221     freq(0)
222     
223 {
224 }
225
226 inline istream&
227 operator >> ( istream& in, FGTACANRecord& n )
228 {
229     in >> n.channel >> n.freq ;
230     //getline( in, n.name );
231
232     return in;
233 }
234 #endif // _FG_NAVRECORD_HXX