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