]> git.mxchange.org Git - flightgear.git/blobdiff - src/Airports/simple.cxx
testair.cxx is a 21 lines long, obsolete test application. After removing
[flightgear.git] / src / Airports / simple.cxx
index af1e0de195e04eb42219494a52aaed80ce140e6d..6a1334cc10f40f53c30f4e31f01655f436a4446c 100644 (file)
 #  include <config.h>
 #endif
 
-#include <math.h>
-#include <algorithm>
-
-#include <simgear/compiler.h>
+#include "simple.hxx"
 
-#include <Environment/environment_mgr.hxx>
-#include <Environment/environment.hxx>
 #include <simgear/misc/sg_path.hxx>
 #include <simgear/props/props.hxx>
-#include <simgear/structure/subsystem_mgr.hxx>
 #include <simgear/debug/logstream.hxx>
-#include <Main/globals.hxx>
+#include <simgear/sg_inlines.h>
+
+#include <Environment/environment_mgr.hxx>
+#include <Environment/environment.hxx>
 #include <Main/fg_props.hxx>
 #include <Airports/runways.hxx>
 #include <Airports/dynamics.hxx>
-
-#include <string>
-
-#include "simple.hxx"
-#include "xmlloader.hxx"
-
-using std::sort;
-using std::random_shuffle;
+#include <Airports/xmlloader.hxx>
 
 // magic import of a helper which uses FGPositioned internals
 extern char** searchAirportNamesAndIdents(const std::string& aFilter);
@@ -102,6 +92,9 @@ FGAirportDynamics * FGAirport::getDynamics()
         FGRunwayPreference rwyPrefs(this);
         XMLLoader::load(&rwyPrefs);
         _dynamics->setRwyUse(rwyPrefs);
+
+        //FGSidStar SIDs(this);
+        XMLLoader::load(_dynamics->getSIDs());
    }
     return _dynamics;
 }
@@ -151,19 +144,6 @@ FGAirport::getIteratorForRunwayIdent(const string& aIdent) const
   return it; // end()
 }
 
-static double normaliseBearing(double aBearing)
-{
-  while (aBearing < -180) {
-    aBearing += 360.0;
-  }
-  
-  while (aBearing > 180.0) {
-    aBearing -= 360.0;
-  }
-  
-  return aBearing;
-}
-
 FGRunway* FGAirport::findBestRunwayForHeading(double aHeading) const
 {
   Runway_iterator it = mRunways.begin();
@@ -179,7 +159,8 @@ FGRunway* FGAirport::findBestRunwayForHeading(double aHeading) const
   for (; it != mRunways.end(); ++it) {
     double good = (*it)->score(lengthWeight, widthWeight, surfaceWeight);
     
-    double dev = normaliseBearing(aHeading - (*it)->headingDeg());
+    double dev = aHeading - (*it)->headingDeg();
+    SG_NORMALIZE_RANGE(dev, -180.0, 180.0);
     double bad = fabs(deviationWeight * dev) + 1e-20;
     double quality = good / bad;
     
@@ -214,21 +195,22 @@ unsigned int FGAirport::numTaxiways() const
   return mTaxiways.size();
 }
 
-FGRunway* FGAirport::getTaxiwayByIndex(unsigned int aIndex) const
+FGTaxiway* FGAirport::getTaxiwayByIndex(unsigned int aIndex) const
 {
   assert(aIndex >= 0 && aIndex < mTaxiways.size());
   return mTaxiways[aIndex];
 }
 
-void FGAirport::addRunway(FGRunway* aRunway)
+void FGAirport::setRunwaysAndTaxiways(vector<FGRunwayPtr>& rwys,
+       vector<FGTaxiwayPtr>& txwys)
 {
-  aRunway->setAirport(this);
-  
-  if (aRunway->isTaxiway()) {
-    mTaxiways.push_back(aRunway);
-  } else {
-    mRunways.push_back(aRunway);
+  mRunways.swap(rwys);
+  Runway_iterator it = mRunways.begin();
+  for (; it != mRunways.end(); ++it) {
+    (*it)->setAirport(this);
   }
+  
+  mTaxiways.swap(txwys);
 }
 
 FGRunway* FGAirport::getActiveRunwayForUsage() const
@@ -270,13 +252,9 @@ FGAirport::HardSurfaceFilter::HardSurfaceFilter(double minLengthFt) :
 {
 }
       
-bool FGAirport::HardSurfaceFilter::pass(FGPositioned* aPos) const
+bool FGAirport::HardSurfaceFilter::passAirport(FGAirport* aApt) const
 {
-  if (aPos->type() != AIRPORT) {
-    return false; // exclude seaports and heliports as well, we need a runways
-  }
-   
-  return static_cast<FGAirport*>(aPos)->hasHardRunwayOfLengthFt(mMinLengthFt);
+  return aApt->hasHardRunwayOfLengthFt(mMinLengthFt);
 }
 
 FGAirport* FGAirport::findByIdent(const std::string& aIdent)
@@ -308,49 +286,6 @@ char** FGAirport::searchNamesAndIdents(const std::string& aFilter)
   return searchAirportNamesAndIdents(aFilter);
 }
 
-/******************************************************************************
- * FGAirportList
- *****************************************************************************/
-
-FGAirportList::FGAirportList()
-{
-}
-
-
-FGAirportList::~FGAirportList( void )
-{
-    for (unsigned int i = 0; i < airports_array.size(); ++i) {
-        delete airports_array[i];
-    }
-}
-
-
-// add an entry to the list
-FGAirport* FGAirportList::add( const string &id, const SGGeod& location, const SGGeod& tower_location,
-                         const string &name, bool has_metar, FGPositioned::Type aType)
-{
-    FGAirport* a = new FGAirport(id, location, tower_location, name, has_metar, aType);
-    // try and read in an auxilary file
-    airports_array.push_back( a );
-    return a;
-}
-
-int
-FGAirportList::size () const
-{
-    return airports_array.size();
-}
-
-
-const FGAirport *FGAirportList::getAirport( unsigned int index ) const
-{
-    if (index < airports_array.size()) {
-        return(airports_array[index]);
-    } else {
-        return(NULL);
-    }
-}
-
 // find basic airport location info from airport database
 const FGAirport *fgFindAirportID( const string& id)
 {
@@ -378,7 +313,7 @@ double fgGetAirportElev( const string& id )
 
 
 // get airport position
-Point3D fgGetAirportPos( const string& id )
+SGGeod fgGetAirportPos( const string& id )
 {
     SG_LOG( SG_ATC, SG_BULK,
             "Finding position for airport: " << id );
@@ -386,8 +321,8 @@ Point3D fgGetAirportPos( const string& id )
     const FGAirport *a = fgFindAirportID( id);
 
     if (a) {
-        return Point3D(a->getLongitude(), a->getLatitude(), a->getElevation());
+        return SGGeod::fromDegM(a->getLongitude(), a->getLatitude(), a->getElevation());
     } else {
-        return Point3D(0.0, 0.0, -9999.0);
+        return SGGeod::fromDegM(0.0, 0.0, -9999.0);
     }
 }