]> git.mxchange.org Git - flightgear.git/blob - src/Navaids/fixlist.cxx
Changes to keep the various autopilot properties from stepping on each
[flightgear.git] / src / Navaids / fixlist.cxx
1 // fixlist.cxx -- fix list management class
2 //
3 // Written by Curtis Olson, started April 2000.
4 //
5 // Copyright (C) 2000  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 #ifdef HAVE_CONFIG_H
25 #  include <config.h>
26 #endif
27
28 #include <simgear/debug/logstream.hxx>
29 #include <simgear/misc/sgstream.hxx>
30 #include <simgear/math/sg_geodesy.hxx>
31
32 #include "fixlist.hxx"
33
34
35 FGFixList *current_fixlist;
36
37
38 // Constructor
39 FGFixList::FGFixList( void ) {
40 }
41
42
43 // Destructor
44 FGFixList::~FGFixList( void ) {
45 }
46
47
48 // load the navaids and build the map
49 bool FGFixList::init( SGPath path ) {
50     FGFix fix;
51
52     fixlist.erase( fixlist.begin(), fixlist.end() );
53
54     sg_gzifstream in( path.str() );
55     if ( !in.is_open() ) {
56         SG_LOG( SG_GENERAL, SG_ALERT, "Cannot open file: " << path.str() );
57         exit(-1);
58     }
59
60     // read in each line of the file
61
62     in >> skipeol;
63     in >> skipcomment;
64
65 #ifdef __MWERKS__
66
67     char c = 0;
68     while ( in.get(c) && c != '\0' && fix.get_ident() != (string)"[End]" ) {
69         in.putback(c);
70         in >> fix;
71         if ( fix.get_ident() != (string)"[End]" ) {
72             fixlist[fix.get_ident()] = fix;
73         }
74         in >> skipcomment;
75     }
76
77 #else
78
79     while ( ! in.eof() && fix.get_ident() != (string)"[End]" ) {
80         in >> fix;
81         /* cout << "id = " << n.get_ident() << endl;
82         cout << " type = " << n.get_type() << endl;
83         cout << " lon = " << n.get_lon() << endl;
84         cout << " lat = " << n.get_lat() << endl;
85         cout << " elev = " << n.get_elev() << endl;
86         cout << " freq = " << n.get_freq() << endl;
87         cout << " range = " << n.get_range() << endl; */
88         if ( fix.get_ident() != (string)"[End]" ) {
89             fixlist[fix.get_ident()] = fix;
90         }
91         in >> skipcomment;
92     }
93
94 #endif
95
96     return true;
97 }
98
99
100 // query the database for the specified frequency, lon and lat are in
101 // degrees, elev is in meters
102 bool FGFixList::query( const string& ident, double lon, double lat, double elev,
103                        FGFix *fix, double *heading, double *dist )
104 {
105     *fix = fixlist[ident];
106     if ( fix->get_ident() == "" ) {
107         return false;
108     }
109
110     double az1, az2, s;
111     geo_inverse_wgs_84( elev, lat, lon, 
112                         fix->get_lat(), fix->get_lon(),
113                         &az1, &az2, &s );
114     // cout << "  dist = " << s << endl;
115     *heading = az2;
116     *dist = s;
117     return true;
118 }