From 5a84f39f8390ddec268b4fe400dbda2842784e66 Mon Sep 17 00:00:00 2001
From: curt <curt>
Date: Wed, 3 Sep 2003 16:38:50 +0000
Subject: [PATCH] Allow additional or non-standard terrain source directories
 to be specified on the command line with the --terrain= option.  You can
 specify as many as you like.  Directories specified on the command line will
 take precidence over the default directories and the directories will be
 searched in the order specified.

---
 src/Airports/GenAirports/apt_surface.cxx | 18 ++++++++++--------
 src/Airports/GenAirports/apt_surface.hxx |  3 ++-
 src/Airports/GenAirports/build.cxx       |  6 ++++--
 src/Airports/GenAirports/build.hxx       |  4 +++-
 src/Airports/GenAirports/main.cxx        | 18 ++++++++++++++++--
 5 files changed, 35 insertions(+), 14 deletions(-)

diff --git a/src/Airports/GenAirports/apt_surface.cxx b/src/Airports/GenAirports/apt_surface.cxx
index a9c48b98..b15c7832 100644
--- a/src/Airports/GenAirports/apt_surface.cxx
+++ b/src/Airports/GenAirports/apt_surface.cxx
@@ -37,13 +37,14 @@ SG_USING_NAMESPACE( PLib );
 
 
 // fix node elevations.  Offset is added to the final elevation
-static void calc_elevations( const string &root, Matrix_Point3Df &Pts ) {
-    string_list elev_src;
-    elev_src.clear();
-    elev_src.push_back( "SRTM-1" );
-    elev_src.push_back( "SRTM-3" );
-    elev_src.push_back( "DEM-3" );
-    elev_src.push_back( "DEM-30" );
+static void calc_elevations( const string &root, const string_list elev_src,
+                             Matrix_Point3Df &Pts ) {
+    // string_list elev_src;
+    // elev_src.clear();
+    // elev_src.push_back( "SRTM-1" );
+    // elev_src.push_back( "SRTM-3" );
+    // elev_src.push_back( "DEM-3" );
+    // elev_src.push_back( "DEM-30" );
 
     bool done = false;
     int i, j;
@@ -164,6 +165,7 @@ static void calc_elevations( const string &root, Matrix_Point3Df &Pts ) {
 // Constructor, specify min and max coordinates of desired area in
 // lon/lat degrees
 TGAptSurface::TGAptSurface( const string& path,
+                            const string_list& elev_src,
                             Point3D _min_deg, Point3D _max_deg )
 {
     // Calculate desired size of grid
@@ -208,7 +210,7 @@ TGAptSurface::TGAptSurface( const string& path,
     }
 
     // Determine elevation of the grid points
-    calc_elevations( path, dPts );
+    calc_elevations( path, elev_src, dPts );
 
     // Build the normal res input grid from the double res version
     Matrix_Point3Df Pts(xdivs + 1, ydivs + 1);
diff --git a/src/Airports/GenAirports/apt_surface.hxx b/src/Airports/GenAirports/apt_surface.hxx
index bf0f95f2..797a713d 100644
--- a/src/Airports/GenAirports/apt_surface.hxx
+++ b/src/Airports/GenAirports/apt_surface.hxx
@@ -61,7 +61,8 @@ public:
 
     // Constructor, specify min and max coordinates of desired area in
     // lon/lat degrees
-    TGAptSurface( const string &path, Point3D _min_deg, Point3D _max_deg );
+    TGAptSurface( const string &path, const string_list& elev_src,
+                  Point3D _min_deg, Point3D _max_deg );
 
     // Destructor
     ~TGAptSurface();
diff --git a/src/Airports/GenAirports/build.cxx b/src/Airports/GenAirports/build.cxx
index 15da8476..d334ca62 100644
--- a/src/Airports/GenAirports/build.cxx
+++ b/src/Airports/GenAirports/build.cxx
@@ -323,7 +323,9 @@ static void build_runway( const TGRunway& rwy_info,
 // build 3d airport
 void build_airport( string airport_id, float alt_m,
                     string_list& runways_raw,
-                    string_list& taxiways_raw, const string& root )
+                    string_list& taxiways_raw,
+                    const string& root,
+                    const string_list& elev_src )
 {
     int i, j, k;
 
@@ -911,7 +913,7 @@ void build_airport( string airport_id, float alt_m,
     min_deg.setlat( min_deg.lat() - 0.1 * dlat );
     max_deg.setlat( max_deg.lat() + 0.1 * dlat );
 
-    TGAptSurface apt_surf( root, min_deg, max_deg );
+    TGAptSurface apt_surf( root, elev_src, min_deg, max_deg );
     cout << "Surface created" << endl;
 
     // calculate node elevations
diff --git a/src/Airports/GenAirports/build.hxx b/src/Airports/GenAirports/build.hxx
index fa6ad283..052b7757 100644
--- a/src/Airports/GenAirports/build.hxx
+++ b/src/Airports/GenAirports/build.hxx
@@ -35,7 +35,9 @@
 
 // build 3d airport
 void build_airport( string airport_id, float alt_m, string_list& runways_raw,
-                    string_list& taxiways_raw, const string& root );
+                    string_list& taxiways_raw,
+                    const string& root,
+                    const string_list& elev_src );
 
 
 
diff --git a/src/Airports/GenAirports/main.cxx b/src/Airports/GenAirports/main.cxx
index e0c007f7..d6e1652f 100644
--- a/src/Airports/GenAirports/main.cxx
+++ b/src/Airports/GenAirports/main.cxx
@@ -76,6 +76,9 @@ int main( int argc, char **argv ) {
     float max_lat = 90;
     bool ready_to_go = true;
 
+    string_list elev_src;
+    elev_src.clear();
+
     sglog().setLogLevels( SG_GENERAL, SG_INFO );
 
     // parse arguments
@@ -89,6 +92,8 @@ int main( int argc, char **argv ) {
             work_dir = arg.substr(7);
 	} else if ( arg.find("--input=") == 0 ) {
 	    input_file = arg.substr(8);
+        } else if ( arg.find("--terrain=") == 0 ) {
+            elev_src.push_back( arg.substr(10) );
  	} else if ( arg.find("--start-id=") == 0 ) {
 	    start_id = arg.substr(11);
 	    ready_to_go = false;
@@ -114,7 +119,16 @@ int main( int argc, char **argv ) {
 	}
     }
 
+    elev_src.push_back( "SRTM-1" );
+    elev_src.push_back( "SRTM-3" );
+    elev_src.push_back( "DEM-3" );
+    elev_src.push_back( "DEM-30" );
+
     SG_LOG(SG_GENERAL, SG_INFO, "Input file = " << input_file);
+    SG_LOG(SG_GENERAL, SG_INFO, "Terrain sources = ");
+    for ( unsigned int i = 0; i < elev_src.size(); ++i ) {
+        SG_LOG(SG_GENERAL, SG_INFO, "  " << work_dir << "/" << elev_src[i] );
+    }
     SG_LOG(SG_GENERAL, SG_INFO, "Work directory = " << work_dir);
     SG_LOG(SG_GENERAL, SG_INFO, "Nudge = " << nudge);
     SG_LOG(SG_GENERAL, SG_INFO, "Longitude = " << min_lon << ':' << max_lon);
@@ -215,7 +229,7 @@ int main( int argc, char **argv ) {
                         try {
                             build_airport( last_apt_id, elev * SG_FEET_TO_METER,
                                            runways_list, taxiways_list,
-                                           work_dir );
+                                           work_dir, elev_src );
                         } catch (sg_exception &e) {
                             SG_LOG( SG_GENERAL, SG_ALERT,
                                     "Failed to build airport = "
@@ -286,7 +300,7 @@ int main( int argc, char **argv ) {
                     try {
                         build_airport( last_apt_id, elev * SG_FEET_TO_METER,
                                        runways_list, taxiways_list,
-                                       work_dir );
+                                       work_dir, elev_src );
                     } catch (sg_exception &e) {
                         SG_LOG( SG_GENERAL, SG_ALERT,
                                 "Failed to build airport = "