]> git.mxchange.org Git - flightgear.git/blobdiff - src/Navaids/ilslist.cxx
- adjusted for no-value constructor for FGPanel
[flightgear.git] / src / Navaids / ilslist.cxx
index fa68f4f7486bfd62d5cb1f5b9814ed6fc52c9865..cf8c9e55fb22b6f56b92e5f968b34361bac76991 100644 (file)
 // $Id$
 
 
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
 #include <simgear/debug/logstream.hxx>
-#include <simgear/misc/fgstream.hxx>
-#include <simgear/math/fg_geodesy.hxx>
+#include <simgear/misc/sgstream.hxx>
+#include <simgear/math/sg_geodesy.hxx>
 
+#include "mkrbeacons.hxx"
 #include "ilslist.hxx"
 
 
@@ -42,14 +47,14 @@ FGILSList::~FGILSList( void ) {
 
 
 // load the navaids and build the map
-bool FGILSList::init( FGPath path ) {
+bool FGILSList::init( SGPath path ) {
     FGILS ils;
 
     ilslist.erase( ilslist.begin(), ilslist.end() );
 
-    fg_gzifstream in( path.str() );
+    sg_gzifstream in( path.str() );
     if ( !in.is_open() ) {
-        FG_LOG( FG_GENERAL, FG_ALERT, "Cannot open file: " << path.str() );
+        SG_LOG( SG_GENERAL, SG_ALERT, "Cannot open file: " << path.str() );
         exit(-1);
     }
 
@@ -61,10 +66,10 @@ bool FGILSList::init( FGPath path ) {
 #ifdef __MWERKS__
 
     char c = 0;
-    while ( in.get(c) && c != '\0' && n.get_ilstype() != '[' ) {
+    while ( in.get(c) && c != '\0' && ils.get_ilstype() != '[' ) {
         in.putback(c);
         in >> ils;
-       if ( ils.get_type() != '[' ) {
+       if ( ils.get_ilstype() != '[' ) {
            ilslist[ils.get_locfreq()].push_back(ils);
        }
         in >> skipcomment;
@@ -95,10 +100,27 @@ bool FGILSList::init( FGPath path ) {
        if ( ils.get_locfreq() > max ) {
            max = ils.get_locfreq();
        }
+
+       // update the marker beacon list
+       if ( fabs(ils.get_omlon()) > SG_EPSILON ||
+            fabs(ils.get_omlat()) > SG_EPSILON ) {
+           current_beacons->add( ils.get_omlon(), ils.get_omlat(),
+                                 ils.get_gselev(), FGMkrBeacon::OUTER );
+       }
+       if ( fabs(ils.get_mmlon()) > SG_EPSILON ||
+            fabs(ils.get_mmlat()) > SG_EPSILON ) {
+           current_beacons->add( ils.get_mmlon(), ils.get_mmlat(),
+                                 ils.get_gselev(), FGMkrBeacon::MIDDLE );
+       }
+       if ( fabs(ils.get_imlon()) > SG_EPSILON ||
+            fabs(ils.get_imlat()) > SG_EPSILON ) {
+           current_beacons->add( ils.get_imlon(), ils.get_imlat(),
+                                 ils.get_gselev(), FGMkrBeacon::INNER );
+       }
     }
 
-    cout << "min freq = " << min << endl;
-    cout << "max freq = " << max << endl;
+    // cout << "min freq = " << min << endl;
+    // cout << "max freq = " << max << endl;
 
 #endif
 
@@ -109,24 +131,38 @@ bool FGILSList::init( FGPath path ) {
 // query the database for the specified frequency, lon and lat are in
 // degrees, elev is in meters
 bool FGILSList::query( double lon, double lat, double elev, double freq,
-                      FGILS *ils, double *heading, double *dist )
+                      FGILS *ils )
 {
     ils_list_type stations = ilslist[(int)(freq*100.0 + 0.5)];
 
     ils_list_iterator current = stations.begin();
     ils_list_iterator last = stations.end();
 
-    double az1, az2, s;
+    // double az1, az2, s;
+    Point3D aircraft = sgGeodToCart( Point3D(lon, lat, elev) );
+    Point3D station;
+    double d;
     for ( ; current != last ; ++current ) {
-       // cout << "testing " << current->get_ident() << endl;
-       geo_inverse_wgs_84( elev, lat, lon, 
-                           current->get_loclat(), current->get_loclon(),
-                           &az1, &az2, &s );
+       // cout << "  testing " << current->get_locident() << endl;
+       station = Point3D(current->get_x(), 
+                         current->get_y(),
+                         current->get_z());
+       // cout << "    aircraft = " << aircraft << " station = " << station 
+       //      << endl;
+
+       d = aircraft.distance3Dsquared( station );
+       // cout << "  distance = " << d << " (" 
+       //      << FG_ILS_DEFAULT_RANGE * SG_NM_TO_METER 
+       //         * FG_ILS_DEFAULT_RANGE * SG_NM_TO_METER
+       //      << ")" << endl;
+
        // cout << "  dist = " << s << endl;
-       if ( s < ( FG_ILS_DEFAULT_RANGE * NM_TO_METER ) ) {
+
+       // match up to twice the published range so we can model
+       // reduced signal strength
+       if ( d < (2* FG_ILS_DEFAULT_RANGE * SG_NM_TO_METER 
+                 * 2 * FG_ILS_DEFAULT_RANGE * SG_NM_TO_METER) ) {
            *ils = *current;
-           *heading = az2;
-           *dist = s;
            return true;
        }
     }