1 // navrecord.cxx -- generic vor/dme/ndb class
3 // Written by Curtis Olson, started May 2004.
5 // Copyright (C) 2004 Curtis L. Olson - http://www.flightgear.org/~curt
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.
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.
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.
29 #include <simgear/misc/sgstream.hxx>
30 #include <simgear/structure/exception.hxx>
31 #include <simgear/debug/logstream.hxx>
32 #include <simgear/sg_inlines.h>
34 #include <Navaids/navrecord.hxx>
35 #include <Navaids/navdb.hxx>
36 #include <Airports/runways.hxx>
37 #include <Main/fg_props.hxx>
39 FGNavRecord::FGNavRecord(Type aTy, const std::string& aIdent,
40 const std::string& aName, const SGGeod& aPos,
41 int aFreq, int aRange, double aMultiuse) :
42 FGPositioned(aTy, aIdent, aPos),
51 initAirportRelation();
53 // Ranges are included with the latest data format, no need to
54 // assign our own defaults, unless the range is not set for some
57 SG_LOG(SG_GENERAL, SG_WARN, "navaid " << ident() << " has no range set, using defaults");
61 range = FG_NAV_DEFAULT_RANGE;
67 range = FG_LOC_DEFAULT_RANGE;
71 range = FG_DME_DEFAULT_RANGE;
75 range = FG_LOC_DEFAULT_RANGE;
81 void FGNavRecord::initAirportRelation()
83 if ((type() < ILS) || (type() > GS)) {
84 return; // not airport-located
87 mRunway = getRunwayFromName(_name);
88 // fudge elevation to the runway elevation if it's not specified
89 if (fabs(elevation()) < 0.01) {
90 mPosition.setElevationFt(mRunway->elevation());
94 mRunway->setILS(this);
97 // align localizers with their runway
98 if ((type() == ILS) || (type() == LOC)) {
99 if (!fgGetBool("/sim/navdb/localizers/auto-align", true)) {
104 = fgGetDouble( "/sim/navdb/localizers/auto-align-threshold-deg", 5.0 );
105 alignLocaliserWithRunway(threshold);
109 void FGNavRecord::alignLocaliserWithRunway(double aThreshold)
111 // find the distance from the threshold to the localizer
112 SGGeod runwayThreshold(mRunway->threshold());
113 double dist, az1, az2;
114 SGGeodesy::inverse(mPosition, runwayThreshold, az1, az2, dist);
116 // back project that distance along the runway center line
117 SGGeod newPos = mRunway->pointOnCenterline(dist);
119 double hdg_diff = get_multiuse() - mRunway->headingDeg();
120 SG_NORMALIZE_RANGE(hdg_diff, -180.0, 180.0);
122 if ( fabs(hdg_diff) <= aThreshold ) {
124 set_multiuse( mRunway->headingDeg() );
126 SG_LOG(SG_GENERAL, SG_WARN, "localizer:" << ident() << ", aligning with runway "
127 << mRunway->ident() << " exceeded heading threshold");
131 FGTACANRecord::FGTACANRecord(void) :
139 operator >> ( std::istream& in, FGTACANRecord& n )
141 in >> n.channel >> n.freq ;
142 //getline( in, n.name );