]> git.mxchange.org Git - flightgear.git/commitdiff
James Turner:
authorehofman <ehofman>
Sat, 13 Sep 2008 08:07:22 +0000 (08:07 +0000)
committerehofman <ehofman>
Sat, 13 Sep 2008 08:07:22 +0000 (08:07 +0000)
Trivial patch, but an important milestone:

Convert FGAirport to inherit FGPositioned. This concludes the first phase of the FGPositioned changes, and hopefully the most intrusive ones - adding in the base class. There's lots (and lots) of further work to do on the indexing and querying side, as well as cleaning up the accessors, but that will happen in single source files, or a group of related files at a time.

As a trivial note, this patch does fix a bug where the very last airport in apt.dat would get an invalid type. So for all you people who just love to fly to EHYB (Ypenburg, The Hague), things may work a little more sanely.

I'll intentionally let the dust settle after this patch, so any weird behaviour I may potentially have introduced shows up. Just to re-iterate, so far there should be absolutely no user-visible change in the behaviour of anything - navaids, position init, the route manager, AI flight plans, etc. If there is, please let me know and I'll fix it ASAP.

src/Airports/apt_loader.cxx
src/Airports/simple.cxx
src/Airports/simple.hxx

index 1f92be4d5ed3b11be5058ccfdc8f4db5f758efe6..85f803191ccf4d8fe72d165b002ccd5ecc6c2b70 100644 (file)
@@ -36,6 +36,7 @@
 #include <simgear/debug/logstream.hxx>
 #include <simgear/misc/sgstream.hxx>
 #include <simgear/misc/strutils.hxx>
+#include <simgear/structure/exception.hxx>
 
 #include <string>
 
 
 #include "apt_loader.hxx"
 
+static FGPositioned::Type fptypeFromRobinType(int aType)
+{
+  switch (aType) {
+  case 1: return FGPositioned::AIRPORT;
+  case 16: return FGPositioned::SEAPORT;
+  case 17: return FGPositioned::HELIPORT;
+  default:
+    SG_LOG(SG_GENERAL, SG_ALERT, "unsupported type:" << aType);
+    throw sg_range_exception("Unsupported airport type", "fptypeFromRobinType");
+  }
+}
+
 FGAirport* addAirport(FGAirportList *airports, const string& apt_id, const string& apt_name,
     int rwy_count, double rwy_lat_accum, double rwy_lon_accum, double last_rwy_heading,
     double apt_elev, SGGeod& tower, bool got_tower, int type)
@@ -69,8 +82,10 @@ FGAirport* addAirport(FGAirportList *airports, const string& apt_id, const strin
         tower = SGGeod::fromDegFt(lon + fudge_lon, lat + fudge_lat, apt_elev + tower_height);
     }
 
+  
+
     return airports->add(apt_id, SGGeod::fromDegFt(lon, lat, apt_elev), tower, apt_name, false,
-            type == 1/*airport*/, type == 16/*seaport*/, type == 17/*heliport*/);
+        fptypeFromRobinType(type));
 }
 
 // Load the airport data base from the specified aptdb file.  The
@@ -213,14 +228,14 @@ bool fgAirportDBLoad( FGAirportList *airports,
             int surface_code = atoi( token[10].c_str() );
 
             FGRunway* rwy = new FGRunway(NULL, rwy_no, lon, lat, heading, length,
-                width, displ_thresh1, stopway1, surface_code, false);
+                          width, displ_thresh1, stopway1, surface_code, false);
             
             FGRunway* reciprocal = new FGRunway(NULL, FGRunway::reverseIdent(rwy_no), 
                           lon, lat, heading + 180.0, length, width, 
                           displ_thresh2, stopway2, surface_code, true);
-                          
             runways.push_back(rwy);
             runways.push_back(reciprocal);
+            
         } else if ( line_id == 18 ) {
             // beacon entry (ignore)
         } else if ( line_id == 14 ) {
@@ -252,7 +267,7 @@ bool fgAirportDBLoad( FGAirportList *airports,
 
     // add the last airport being processed if any
     addAirport(airports, last_apt_id, last_apt_name, rwy_count, rwy_lat_accum, rwy_lon_accum,
-        last_rwy_heading, last_apt_elev, last_tower, got_tower, 0);
+        last_rwy_heading, last_apt_elev, last_tower, got_tower, last_apt_type);
 
 
     //
index 9a0a4dab40ca849962a2e6ff729dde35ef0dd4b8..8f8c8752974ccea875e5b20d4575a69b6e7da930 100644 (file)
 
 #include <simgear/compiler.h>
 
-#include <plib/sg.h>
-#include <plib/ul.h>
-
 #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/route/waypoint.hxx>
 #include <simgear/debug/logstream.hxx>
 #include <Main/globals.hxx>
 #include <Main/fg_props.hxx>
 #include <Airports/runways.hxx>
 #include <Airports/dynamics.hxx>
-#include <Airports/runways.hxx>
 
 #include <string>
 
@@ -63,21 +58,13 @@ using std::random_shuffle;
 /***************************************************************************
  * FGAirport
  ***************************************************************************/
-FGAirport::FGAirport() : _dynamics(0)
-{
-}
 
 FGAirport::FGAirport(const string &id, const SGGeod& location, const SGGeod& tower_location,
-        const string &name, bool has_metar, bool is_airport, bool is_seaport,
-        bool is_heliport) :
-    _id(id),
-    _location(location),
+        const string &name, bool has_metar, Type aType) :
+    FGPositioned(aType, id, location),
     _tower_location(tower_location),
     _name(name),
     _has_metar(has_metar),
-    _is_airport(is_airport),
-    _is_seaport(is_seaport),
-    _is_heliport(is_heliport),
     _dynamics(0)
 {
 }
@@ -88,6 +75,20 @@ FGAirport::~FGAirport()
     delete _dynamics;
 }
 
+bool FGAirport::isAirport() const
+{
+  return type() == AIRPORT;
+}
+
+bool FGAirport::isSeaport() const
+{
+  return type() == SEAPORT;
+}
+
+bool FGAirport::isHeliport() const
+{
+  return type() == HELIPORT;
+}
 
 FGAirportDynamics * FGAirport::getDynamics()
 {
@@ -125,8 +126,8 @@ FGRunway* FGAirport::getRunwayByIdent(const string& aIdent) const
 {
   Runway_iterator it = getIteratorForRunwayIdent(aIdent);
   if (it == mRunways.end()) {
-    SG_LOG(SG_GENERAL, SG_ALERT, "no such runway '" << aIdent << "' at airport " << _id);
-    throw sg_range_exception("unknown runway " + aIdent + " at airport:" + _id, "FGAirport::getRunwayByIdent");
+    SG_LOG(SG_GENERAL, SG_ALERT, "no such runway '" << aIdent << "' at airport " << ident());
+    throw sg_range_exception("unknown runway " + aIdent + " at airport:" + ident(), "FGAirport::getRunwayByIdent");
   }
   
   return *it;
@@ -220,7 +221,7 @@ FGRunway* FGAirport::getActiveRunwayForUsage() const
     envMgr = (FGEnvironmentMgr *) globals->get_subsystem("environment");
   }
   
-  FGEnvironment stationWeather(envMgr->getEnvironment(_location));
+  FGEnvironment stationWeather(envMgr->getEnvironment(mPosition));
   
   double windSpeed = stationWeather.get_wind_speed_kt();
   double hdg = stationWeather.get_wind_from_heading_deg();
@@ -271,12 +272,9 @@ FGAirportList::~FGAirportList( void )
 
 // 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, bool is_airport, bool is_seaport,
-                         bool is_heliport)
+                         const string &name, bool has_metar, FGPositioned::Type aType)
 {
-    FGAirport* a = new FGAirport(id, location, tower_location, name, has_metar,
-            is_airport, is_seaport, is_heliport);
-
+    FGAirport* a = new FGAirport(id, location, tower_location, name, has_metar, aType);
     airports_by_id[a->getId()] = a;
     // try and read in an auxilary file
 
index 2236b76607a3677262a2eae5cb90b8a0fa5f5fd3..2ec8a917395386aedf7e15ee33b6d452e70b2578 100644 (file)
@@ -35,7 +35,6 @@
 #include <vector>
 
 #include <simgear/math/point3d.hxx>
-
 #include "Navaids/positioned.hxx"
 
 // forward decls
@@ -47,41 +46,33 @@ typedef SGSharedPtr<FGRunway> FGRunwayPtr;
 /***************************************************************************************
  *
  **************************************************************************************/
-class FGAirport {
+class FGAirport : public FGPositioned
+{
 private:
-    std::string _id;
-    SGGeod _location;
     SGGeod _tower_location;
     std::string _name;
     bool _has_metar;
-    bool _is_airport;
-    bool _is_seaport;
-    bool _is_heliport;
     FGAirportDynamics *_dynamics;
 
 public:
-    FGAirport();
-    // FGAirport(const FGAirport &other);
     FGAirport(const std::string& id, const SGGeod& location, const SGGeod& tower, 
-            const std::string& name,
-            bool has_metar, bool is_airport, bool is_seaport, bool is_heliport);
+            const std::string& name, bool has_metar, Type aType);
     ~FGAirport();
 
-    const std::string& getId() const { return _id; }
+    const std::string& getId() const { return ident(); }
     const std::string& getName() const { return _name; }
-    double getLongitude() const { return _location.getLongitudeDeg(); }
+    double getLongitude() const { return longitude(); }
     // Returns degrees
-    double getLatitude()  const { return _location.getLatitudeDeg(); }
+    double getLatitude()  const { return latitude(); }
     // Returns ft
-    double getElevation() const { return _location.getElevationFt(); }
+    double getElevation() const { return elevation(); }
     bool   getMetar()     const { return _has_metar; }
-    bool   isAirport()    const { return _is_airport; }
-    bool   isSeaport()    const { return _is_seaport; }
-    bool   isHeliport()   const { return _is_heliport; }
+    bool   isAirport()    const;
+    bool   isSeaport()    const;
+    bool   isHeliport()   const;
 
     const SGGeod& getTowerLocation() const { return _tower_location; }
 
-    void setId(const std::string& id) { _id = id; }
     void setMetar(bool value) { _has_metar = value; }
 
     FGRunway* getActiveRunwayForUsage() const;
@@ -101,7 +92,6 @@ public:
     void addRunway(FGRunway* aRunway);
 private:
     typedef std::vector<FGRunwayPtr>::const_iterator Runway_iterator;
-    
     /**
      * Helper to locate a runway by ident
      */
@@ -156,8 +146,7 @@ public:
 
     // add an entry to the list
     FGAirport* add( const std::string& id, const SGGeod& location, const SGGeod& tower,
-              const std::string& name, bool has_metar, bool is_airport,
-              bool is_seaport, bool is_heliport );
+              const std::string& name, bool has_metar, FGPositioned::Type aType);
 
     // search for the specified id.
     // Returns NULL if unsucessfull.