]> git.mxchange.org Git - flightgear.git/blobdiff - src/Airports/runways.cxx
Alex Romosan:
[flightgear.git] / src / Airports / runways.cxx
index e437dda08c4f444a13bde16a419be65a4e3c2547..dcba46e2cf51179dab8abafe000153a5cad93c1d 100644 (file)
 #include <simgear/compiler.h>
 
 #include <simgear/debug/logstream.hxx>
-#include <simgear/misc/sgstream.hxx>
 
 #include STL_STRING
-#include STL_IOSTREAM
 #include <map>
 
 #include "runways.hxx"
@@ -43,48 +41,51 @@ SG_USING_NAMESPACE(std);
 SG_USING_STD(istream);
 SG_USING_STD(multimap);
 
-inline istream&
-operator >> ( istream& in, FGRunway& a )
-{
-    string type;
-    int tmp;
-
-    in >> a.type;
-    if ( a.type == "R" ) {
-        in >> a.id >> a.rwy_no >> a.lat >> a.lon >> a.heading
-           >> a.length >> a.width >> a.surface_flags >> a.end1_flags
-           >> tmp >> tmp >> a.end2_flags >> tmp >> tmp;
-    } else if ( a.type == "T" ) {
-        // in >> a.id >> a.rwy_no >> a.lat >> a.lon >> a.heading
-        //    >> a.length >> a.width >> a.surface_flags;
-        in >> skipeol;
-    } else {
-        in >> skipeol;
-    }
-
-    return in;
-}
-
 
-FGRunwayList::FGRunwayList( const string& file ) {
-    SG_LOG( SG_GENERAL, SG_DEBUG, "Reading runway list: " << file );
+// add an entry to the list
+void FGRunwayList::add( const string& id, const string& rwy_no,
+                        const double longitude, const double latitude,
+                        const double heading, const double length,
+                        const double width,
+                        const double displ_thresh1, const double displ_thresh2,
+                        const double stopway1, const double stopway2,
+                        const string& lighting_flags, const int surface_code,
+                        const string& shoulder_code, const int marking_code,
+                        const double smoothness, const bool dist_remaining )
+{
+    FGRunway rwy;
 
-    // open the specified file for reading
-    sg_gzifstream in( file );
-    if ( !in.is_open() ) {
-        SG_LOG( SG_GENERAL, SG_ALERT, "Cannot open file: " << file );
-       exit(-1);
+    rwy._id = id;
+    rwy._rwy_no = rwy_no;
+    // strip trailing "x" if it exists in runway number
+    string tmp = rwy._rwy_no.substr(2, 1);
+    if ( tmp == "x" ) {
+        rwy._rwy_no = rwy._rwy_no.substr(0, 2);
     }
 
-    // skip header line
-    in >> skipeol;
-
-    FGRunway rwy;
-    while ( in ) {
-        in >> rwy;
-        if(rwy.type == "R") {
-            runways.insert(pair<const string, FGRunway>(rwy.id, rwy));
-        }
+    rwy._lon = longitude;
+    rwy._lat = latitude;
+    rwy._heading = heading;
+    rwy._length = length;
+    rwy._width = width;
+    rwy._displ_thresh1 = displ_thresh1;
+    rwy._displ_thresh2 = displ_thresh2;
+    rwy._stopway1 = stopway1;
+    rwy._stopway2 = stopway2;
+
+    rwy._lighting_flags = lighting_flags;
+    rwy._surface_code = surface_code;
+    rwy._shoulder_code = shoulder_code;
+    rwy._marking_code = marking_code;
+    rwy._smoothness = smoothness;
+    rwy._dist_remaining = dist_remaining;
+
+    if ( rwy_no == "xxx" ) {
+        rwy._type = "taxiway";
+        // don't insert taxiways into the DB for now
+    } else {
+        rwy._type = "runway";
+        runways.insert(pair<const string, FGRunway>(rwy._id, rwy));
     }
 }
 
@@ -92,7 +93,7 @@ FGRunwayList::FGRunwayList( const string& file ) {
 // Return reverse rwy number
 // eg 01 -> 19
 // 03L -> 21R
-static string GetReverseRunwayNo(string rwyno) {       
+static string GetReverseRunwayNo(string& rwyno) {      
     // cout << "Original rwyno = " << rwyNo << '\n';
     
     // standardize input number
@@ -171,11 +172,11 @@ bool FGRunwayList::search( const string& aptid, const string& rwyno,
     for ( pos = runways.lower_bound( aptid );
           pos != runways.upper_bound( aptid ); ++pos)
     {
-        if ( pos->second.rwy_no == runwayno ) {
+        if ( pos->second._rwy_no == runwayno ) {
             current = pos;
             *r = pos->second;
             return true;
-        } else if ( pos->second.rwy_no == revrwyno ) {
+        } else if ( pos->second._rwy_no == revrwyno ) {
             // Search again with the other-end runway number.
             // Remember we have to munge the heading and rwy_no
             // results if this one matches
@@ -183,11 +184,8 @@ bool FGRunwayList::search( const string& aptid, const string& rwyno,
             *r = pos->second;
             // NOTE - matching revrwyno implies that runwayno was
             // actually correct.
-            r->rwy_no = runwayno;
-            r->heading += 180.0;
-            string tmp = r->end1_flags;
-            r->end1_flags = r->end2_flags;
-            r->end2_flags = tmp;
+            r->_rwy_no = runwayno;
+            r->_heading += 180.0;
             return true;
         }
     }
@@ -218,8 +216,8 @@ string FGRunwayList::search( const string& aptid, const int tgt_hdg ) {
     FGRunway r;
     FGRunway tmp_r;    
     string rn;
-    double found_dir = 0.0;  
+    double found_dir = 0.0;
+
     if ( !search( aptid, &tmp_r ) ) {
        SG_LOG( SG_GENERAL, SG_ALERT,
                 "Failed to find " << aptid << " in database." );
@@ -229,48 +227,44 @@ string FGRunwayList::search( const string& aptid, const int tgt_hdg ) {
     double diff;
     double min_diff = 360.0;
     
-    while ( tmp_r.id == aptid ) {
-       r = tmp_r;
-       
+    while ( tmp_r._id == aptid ) {
        // forward direction
-       diff = tgt_hdg - r.heading;
+       diff = tgt_hdg - tmp_r._heading;
        while ( diff < -180.0 ) { diff += 360.0; }
        while ( diff >  180.0 ) { diff -= 360.0; }
        diff = fabs(diff);
         // SG_LOG( SG_GENERAL, SG_INFO,
-        //        "Runway " << r.rwy_no << " heading = " << r.heading <<
-        //        " diff = " << diff );
+        //        "Runway " << tmp_r._rwy_no << " heading = "
+       //         << tmp_r._heading << " diff = " << diff );
        if ( diff < min_diff ) {
            min_diff = diff;
-           rn = r.rwy_no;
+           r = tmp_r;
            found_dir = 0;
        }
        
        // reverse direction
-       diff = tgt_hdg - r.heading - 180.0;
+       diff = tgt_hdg - tmp_r._heading - 180.0;
        while ( diff < -180.0 ) { diff += 360.0; }
        while ( diff >  180.0 ) { diff -= 360.0; }
        diff = fabs(diff);
         // SG_LOG( SG_GENERAL, SG_INFO,
-        //        "Runway -" << r.rwy_no << " heading = " <<
-        //        r.heading + 180.0 <<
+        //        "Runway -" << tmp_r._rwy_no << " heading = " <<
+        //        tmp_r._heading + 180.0 <<
         //        " diff = " << diff );
        if ( diff < min_diff ) {
            min_diff = diff;
-           rn = r.rwy_no;
+           r = tmp_r;
            found_dir = 180.0;
        }
        
        next( &tmp_r );
     }
     
-    // SG_LOG( SG_GENERAL, SG_INFO, "closest runway = " << r.rwy_no
+    // SG_LOG( SG_GENERAL, SG_INFO, "closest runway = " << r._rwy_no
     //        << " + " << found_dir );
-    rn = r.rwy_no;
-    // cout << "In search, rn = " << rn << endl;
+    rn = r._rwy_no;
     if ( found_dir == 180 ) {
        rn = GetReverseRunwayNo(rn);
-       //cout << "New rn = " << rn << '\n';
     }  
     
     return rn;