]> git.mxchange.org Git - flightgear.git/blob - src/Navaids/navrecord.hxx
ab1ca85c0281d632e7bf4f87f88732363baf057d
[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 - 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_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
47 #define FG_LOC_DEFAULT_RANGE 18
48 #define FG_DME_DEFAULT_RANGE 50
49
50
51 class FGNavRecord {
52
53     int type;
54     double lon, lat;            // location in geodetic coords
55     double elev_ft;
56     double x, y, z;             // location in cartesian coords (earth centered)
57     int freq;
58     int range;
59     double multiuse;            // can be slaved variation of VOR
60                                 // (degrees) or localizer heading
61                                 // (degrees) or dme bias (nm)
62
63     string ident;               // navaid ident
64     string name;                // verbose name in nav database
65     string apt_id;              // corresponding airport id
66
67
68     bool serviceable;           // for failure modeling
69     string trans_ident;         // for failure modeling
70
71 public:
72
73     inline FGNavRecord(void);
74     inline ~FGNavRecord(void) {}
75
76     inline int get_type() const { return type; }
77     inline double get_lon() const { return lon; }
78     inline void set_lon( double l ) { lon = l; }
79     inline double get_lat() const { return lat; }
80     inline void set_lat( double l ) { lat = l; }
81     inline double get_elev_ft() const { return elev_ft; }
82     inline void set_elev_ft( double e ) { elev_ft = e; }
83     inline double get_x() const { return x; }
84     inline double get_y() const { return y; }
85     inline double get_z() const { return z; }
86     inline int get_freq() const { return freq; }
87     inline int get_range() const { return range; }
88     inline double get_multiuse() const { return multiuse; }
89     inline void set_multiuse( double m ) { multiuse = m; }
90     inline const char *get_ident() { return ident.c_str(); }
91     inline string get_name() { return name; }
92     inline string get_apt_id() { return apt_id; }
93     inline bool get_serviceable() { return serviceable; }
94     inline const char *get_trans_ident() { return trans_ident.c_str(); }
95
96     friend istream& operator>> ( istream&, FGNavRecord& );
97 };
98
99
100 inline
101 FGNavRecord::FGNavRecord(void) :
102     type(0),
103     lon(0.0), lat(0.0),
104     elev_ft(0.0),
105     x(0.0), y(0.0), z(0.0),
106     freq(0),
107     range(0),
108     multiuse(0.0),
109     ident(""),
110     name(""),
111     apt_id(""),
112     serviceable(true),
113     trans_ident("")
114 {
115 }
116
117
118 inline istream&
119 operator >> ( istream& in, FGNavRecord& n )
120 {
121     in >> n.type;
122     
123     if ( n.type == 99 ) {
124         return in >> skipeol;
125     }
126
127     in >> n.lat >> n.lon >> n.elev_ft >> n.freq >> n.multiuse
128        >> n.ident;
129     getline( in, n.name );
130
131     // silently multiply adf frequencies by 100 so that adf
132     // vs. nav/loc frequency lookups can use the same code.
133     if ( n.type == 2 ) {
134         n.freq *= 100;
135     }
136
137     // Remove any leading spaces before the name
138     while ( n.name.substr(0,1) == " " ) {
139         n.name = n.name.erase(0,1);
140     }
141
142     if ( n.type >= 4 && n.type <= 9 ) {
143         // these types are always associated with an airport id
144         string::size_type pos = n.name.find(" ");
145         n.apt_id = n.name.substr(0, pos);
146     }
147
148     // assign default ranges
149     if ( n.type == 2 || n.type == 3 ) {
150         n.range = FG_NAV_DEFAULT_RANGE;
151     } else if ( n.type == 4 || n.type == 5 || n.type == 6 ) {
152         n.range = FG_LOC_DEFAULT_RANGE;
153     } else if ( n.type == 12 ) {
154         n.range = FG_DME_DEFAULT_RANGE;
155     } else {
156         n.range = FG_LOC_DEFAULT_RANGE;
157     }
158
159     // transmitted ident (same as ident unless modeling a fault)
160     n.trans_ident = n.ident;
161
162     // generate cartesian coordinates
163     Point3D geod( n.lon * SGD_DEGREES_TO_RADIANS,
164                   n.lat * SGD_DEGREES_TO_RADIANS,
165                   n.elev_ft * SG_FEET_TO_METER );
166     Point3D cart = sgGeodToCart( geod );
167     n.x = cart.x();
168     n.y = cart.y();
169     n.z = cart.z();
170
171     return in;
172 }
173
174
175 #endif // _FG_NAVRECORD_HXX