]> git.mxchange.org Git - flightgear.git/blobdiff - src/Instrumentation/KLN89/kln89_page_apt.cxx
Merge branch 'maint2' into next
[flightgear.git] / src / Instrumentation / KLN89 / kln89_page_apt.cxx
index 7bf0b93f611a59b0087ffff414979d5669ab55cd..62031c760b6bbd7f299c0c6c971bb787eb3b474a 100644 (file)
 #endif
 
 #include "kln89_page_apt.hxx"
-#include <ATC/commlist.hxx>
-#include <Main/globals.hxx>
+#include "ATCDCL/commlist.hxx"
+#include "Main/globals.hxx"
+#include "Airports/runways.hxx"
+#include "Airports/simple.hxx"
 
 // This function is copied from Airports/runways.cxx
 // TODO - Make the original properly available and remove this instance!!!!
@@ -202,8 +204,8 @@ void KLN89AptPage::Update(double dt) {
                        // I guess we can make a heuristic guess as to fuel availability from the runway sizes
                        // For now assume that airports with asphalt or concrete runways will have at least 100L,
                        // and that runways over 4000ft will have JET.
-                       if(_aptRwys[0]._surface_code <= 2) {
-                               if(_aptRwys[0]._length >= 4000) {
+                       if(_aptRwys[0]->surface() <= 2) {
+                               if(_aptRwys[0]->lengthFt() >= 4000) {
                                        _kln89->DrawText("JET 100L", 2, 0, 1);
                                } else {
                                        _kln89->DrawText("100L", 2, 0, 1);
@@ -223,17 +225,17 @@ void KLN89AptPage::Update(double dt) {
                        string s;
                        if(i < _aptRwys.size()) {
                                // Rwy No.
-                               string s = _aptRwys[i]._rwy_no;
+                               string s = _aptRwys[i]->ident();
                                _kln89->DrawText(s, 2, 9, 3);
                                _kln89->DrawText("/", 2, 12, 3);
                                _kln89->DrawText(GetReverseRunwayNo(s), 2, 13, 3);
                                // Length
-                               s = GPSitoa(int(float(_aptRwys[i]._length) * (_kln89->_altUnits == GPS_ALT_UNITS_FT ? 1.0 : SG_FEET_TO_METER) + 0.5));
+                               s = GPSitoa(int(float(_aptRwys[i]->lengthFt()) * (_kln89->_altUnits == GPS_ALT_UNITS_FT ? 1.0 : SG_FEET_TO_METER) + 0.5));
                                _kln89->DrawText(s, 2, 5 - s.size(), 2);
                                _kln89->DrawText((_kln89->_altUnits == GPS_ALT_UNITS_FT ? "ft" : "m"), 2, 5, 2);
                                // Surface
                                // TODO - why not store these strings as an array?
-                               switch(_aptRwys[i]._surface_code) {
+                               switch(_aptRwys[i]->surface()) {
                                case 1:
                                        // Asphalt - fall through
                                case 2:
@@ -271,17 +273,17 @@ void KLN89AptPage::Update(double dt) {
                        i++;
                        if(i < _aptRwys.size()) {
                                // Rwy No.
-                               string s = _aptRwys[i]._rwy_no;
+                               string s = _aptRwys[i]->ident();
                                _kln89->DrawText(s, 2, 9, 1);
                                _kln89->DrawText("/", 2, 12, 1);
                                _kln89->DrawText(GetReverseRunwayNo(s), 2, 13, 1);
                                // Length
-                               s = GPSitoa(int(float(_aptRwys[i]._length) * (_kln89->_altUnits == GPS_ALT_UNITS_FT ? 1.0 : SG_FEET_TO_METER) + 0.5));
+                               s = GPSitoa(int(float(_aptRwys[i]->lengthFt()) * (_kln89->_altUnits == GPS_ALT_UNITS_FT ? 1.0 : SG_FEET_TO_METER) + 0.5));
                                _kln89->DrawText(s, 2, 5 - s.size(), 0);
                                _kln89->DrawText((_kln89->_altUnits == GPS_ALT_UNITS_FT ? "ft" : "m"), 2, 5, 0);
                                // Surface
                                // TODO - why not store these strings as an array?
-                               switch(_aptRwys[i]._surface_code) {
+                               switch(_aptRwys[i]->surface()) {
                                case 1:
                                        // Asphalt - fall through
                                case 2:
@@ -468,10 +470,17 @@ void KLN89AptPage::Update(double dt) {
 }
 
 void KLN89AptPage::SetId(const string& s) {
+       if(s != _apt_id || s != _last_apt_id) {
+               UpdateAirport(s);       // If we don't do this here we break things if s is the same as the current ID since the update wouldn't get called then.
+               /*
+                       DCL: Hmmm - I wrote the comment above, but I don't quite understand it!
+                       I'm not quite sure why I don't simply set _apt_id here (and NOT _last_apt_id)
+                       and let the logic in Update(...) handle the airport details cache update.
+               */
+       }
        _last_apt_id = _apt_id;
        _save_apt_id = _apt_id;
        _apt_id = s;
-       UpdateAirport(s);       // If we don't do this here we break things if s is the same as the current ID since the update wouldn't get called then.
 }
 
 // Update the cached airport details
@@ -507,23 +516,19 @@ void KLN89AptPage::UpdateAirport(const string& id) {
        
        // Runways
        _aptRwys.clear();
-       FGRunway r;
-       bool haveRwy = globals->get_runways()->search(id, &r);
-       while(haveRwy && r._id == id) {
-               // Insert the runway with longest at the start of the array
-               for(unsigned int i = 0; i <= _aptRwys.size(); ++i) {
-                       if(i == _aptRwys.size()) {
-                               _aptRwys.push_back(r);
-                               break;
-                       } else {
-                               if(r._length > _aptRwys[i]._length) {
-                                       _aptRwys.insert(_aptRwys.begin() + i, r);
-                                       break;
-                               }
-                       }
-               }
-               haveRwy = globals->get_runways()->next(&r);
-       }
+  const FGAirport* apt = fgFindAirportID(id);
+  assert(apt);
+  
+  // build local array, longest runway first
+  for (unsigned int r=0; r<apt->numRunways(); ++r) {
+    FGRunway* rwy(apt->getRunwayByIndex(r));
+    if ((r > 0) && (rwy->lengthFt() > _aptRwys.front()->lengthFt())) {
+      _aptRwys.insert(_aptRwys.begin(), rwy);
+    } else {
+      _aptRwys.push_back(rwy);
+    }
+  }
+  
        _nRwyPages = (_aptRwys.size() + 1) / 2; // 2 runways per page.
        if(_nFreqPages < 1) _nFreqPages = 1;
        if(_nRwyPages < 1) _nRwyPages = 1;
@@ -535,7 +540,16 @@ void KLN89AptPage::UpdateAirport(const string& id) {
        if(itr != _kln89->_np_iap.end()) {
                _iaps = itr->second;
        }
-       if(_subPage == 7) _maxULinePos = 4 + _iaps.size();      // We shouldn't need to check the crsr for out-of-bounds here since we only update the airport details when the airport code is changed - ie. _uLinePos <= 4!
+       if(_subPage == 7) { 
+               if(_iafDialog || _addDialog || _replaceDialog) {
+                       // Eek - major logic error if an airport details cache update occurs
+                       // with one of these dialogs active.
+                       // TODO - output a warning.
+                       //cout << "HELP!!!!!!!!!!\n";
+               } else {
+                       _maxULinePos = 4 + _iaps.size();        // We shouldn't need to check the crsr for out-of-bounds here since we only update the airport details when the airport code is changed - ie. _uLinePos <= 4!
+               }
+       }
 }
 
 void KLN89AptPage::CrsrPressed() {
@@ -617,16 +631,13 @@ void KLN89AptPage::ClrPressed() {
 }
 
 void KLN89AptPage::EntPressed() {
-       //cout << "A\n"
        if(_entInvert) {
                _entInvert = false;
                _last_apt_id = _apt_id;
                _apt_id = _save_apt_id;
        } else if(_subPage == 7 && _kln89->_mode == KLN89_MODE_CRSR && _uLinePos > 0) {
-               //cout << "B\n";
                // We are selecting an approach
                if(_iafDialog) {
-                       //cout << "C\n";
                        if(_uLinePos > 0) {
                                // Record the IAF that was picked
                                if(_uLinePos == 3) {