]> git.mxchange.org Git - flightgear.git/blob - src/Navaids/navrecord.cxx
2aa25424fe9dfc0c9bb36aa9c0a9a4675eb0f6ef
[flightgear.git] / src / Navaids / navrecord.cxx
1 // navrecord.cxx -- 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 #ifdef HAVE_CONFIG_H
24   #include "config.h"
25 #endif
26
27 #include <istream>
28 #include <simgear/misc/sgstream.hxx>
29 #include "Navaids/navrecord.hxx"
30
31 FGNavRecord::FGNavRecord(void) :
32     type(0),
33     pos(SGGeod::fromDeg(0, 0)),
34     cart(0, 0, 0),
35     freq(0),
36     range(0),
37     multiuse(0.0),
38     ident(""),
39     name(""),
40     apt_id(""),
41     serviceable(true),
42     trans_ident("")
43 {
44 }
45
46 FGNavRecord::FGNavRecord(int aTy, const std::string& aIdent, 
47   const std::string& aName, const std::string& aAirport,
48   double lat, double lon, int aFreq, int aRange, double aMultiuse) :
49   type(aTy),
50   freq(aFreq),
51   range(aRange),
52   multiuse(aMultiuse),
53   ident(aIdent),
54   name(aName),
55   apt_id(aAirport),
56   serviceable(true),
57   trans_ident(aIdent)
58 {
59   pos = SGGeod::fromDeg(lon, lat);
60   cart = SGVec3d::fromGeod(pos);
61 }
62
63 fg_nav_types FGNavRecord::get_fg_type() const {
64     switch(type) {
65     case 2: return(FG_NAV_NDB);
66     case 3: return(FG_NAV_VOR);
67     case 4: return(FG_NAV_ILS);
68     default: return(FG_NAV_ANY);
69     }
70 }
71
72
73 std::istream& operator>>( std::istream& in, FGNavRecord& n )
74 {
75     in >> n.type;
76     
77     if ( n.type == 99 ) {
78         return in >> skipeol;
79     }
80
81     double lat, lon, elev_ft;
82     in >> lat >> lon >> elev_ft >> n.freq >> n.range >> n.multiuse
83        >> n.ident;
84     n.pos.setLatitudeDeg(lat);
85     n.pos.setLongitudeDeg(lon);
86     n.pos.setElevationFt(elev_ft);
87     getline( in, n.name );
88
89     // silently multiply adf frequencies by 100 so that adf
90     // vs. nav/loc frequency lookups can use the same code.
91     if ( n.type == 2 ) {
92         n.freq *= 100;
93     }
94
95     // Remove any leading spaces before the name
96     while ( n.name.substr(0,1) == " " ) {
97         n.name = n.name.erase(0,1);
98     }
99
100     if ( n.type >= 4 && n.type <= 9 ) {
101         // these types are always associated with an airport id
102         std::string::size_type pos = n.name.find(" ");
103         n.apt_id = n.name.substr(0, pos);
104     }
105
106     // Ranges are included with the latest data format, no need to
107     // assign our own defaults, unless the range is not set for some
108     // reason.
109
110     if ( n.range < 0.1 ) {
111         // assign default ranges
112     
113         if ( n.type == 2 || n.type == 3 ) {
114             n.range = FG_NAV_DEFAULT_RANGE;
115         } else if ( n.type == 4 || n.type == 5 || n.type == 6 ) {
116             n.range = FG_LOC_DEFAULT_RANGE;
117         } else if ( n.type == 12 ) {
118             n.range = FG_DME_DEFAULT_RANGE;
119         } else {
120             n.range = FG_LOC_DEFAULT_RANGE;
121         }
122     }
123
124     // transmitted ident (same as ident unless modeling a fault)
125     n.trans_ident = n.ident;
126
127     // generate cartesian coordinates
128     n.cart = SGVec3d::fromGeod(n.pos);
129
130     return in;
131 }
132
133
134 FGTACANRecord::FGTACANRecord(void) :
135     channel(""),
136     freq(0)
137     
138 {
139 }
140
141 std::istream&
142 operator >> ( std::istream& in, FGTACANRecord& n )
143 {
144     in >> n.channel >> n.freq ;
145     //getline( in, n.name );
146
147     return in;
148 }