From 27cfc32e4ef50873e5ad17e17219c5db50f89ded Mon Sep 17 00:00:00 2001 From: curt Date: Fri, 15 Oct 2004 20:14:38 +0000 Subject: [PATCH] First stab at code changes to support the X-Plane data format directly. --- src/Airports/GenAirports/build.cxx | 241 ++++++++++-------------- src/Airports/GenAirports/build.hxx | 1 - src/Airports/GenAirports/lights.cxx | 236 +++++++++++------------ src/Airports/GenAirports/main.cxx | 161 +++++++++------- src/Airports/GenAirports/runway.hxx | 9 +- src/Airports/GenAirports/rwy_visual.cxx | 3 +- 6 files changed, 310 insertions(+), 341 deletions(-) diff --git a/src/Airports/GenAirports/build.cxx b/src/Airports/GenAirports/build.cxx index dce0f3eb..42ac8ac2 100644 --- a/src/Airports/GenAirports/build.cxx +++ b/src/Airports/GenAirports/build.cxx @@ -29,6 +29,7 @@ #include #include +#include #include #include @@ -236,82 +237,89 @@ static void build_runway( const TGRunway& rwy_info, TGPolygon *apt_base, TGPolygon *apt_clearing ) { - SG_LOG(SG_GENERAL, SG_DEBUG, "surface flags = " << rwy_info.surface_flags); - string surface_flag = rwy_info.surface_flags.substr(1, 1); - string light_flag = rwy_info.surface_flags.substr(2, 1); - SG_LOG(SG_GENERAL, SG_DEBUG, "surface flag = " << surface_flag); + SG_LOG(SG_GENERAL, SG_DEBUG, "surface code = " << rwy_info.surface_code); + int surface_code = rwy_info.surface_code; + SG_LOG(SG_GENERAL, SG_DEBUG, "surface code = " << surface_code); + string lighting_flags = rwy_info.lighting_flags; + SG_LOG(SG_GENERAL, SG_DEBUG, "lighting flags = " << lighting_flags); + + string vasi1 = lighting_flags.substr(0,1); + string rwylt1 = lighting_flags.substr(1,1); + string apprch1 = lighting_flags.substr(2,1); + string vasi2 = lighting_flags.substr(3,1); + string rwylt2 = lighting_flags.substr(4,1); + string apprch2 = lighting_flags.substr(5,1); string material; - if ( surface_flag == "A" ) { + if ( surface_code == 1 /* Asphalt */ ) { if ( !rwy_info.really_taxiway ) { - material = "pa_"; // asphalt + material = "pa_"; } else { - if ( rwy_info.width <= 150 && light_flag == "B" ) + if ( rwy_info.width <= 150 && rwylt1 == "6" ) { material = "pa_taxiway"; - else + } else { material = "pa_tiedown"; + } } - } else if ( surface_flag == "C" ) { + } else if ( surface_code == 2 /* Concrete */ ) { if ( !rwy_info.really_taxiway ) { - material = "pc_"; // concrete + material = "pc_"; } else { - if ( rwy_info.width <= 150 && light_flag == "B" ) + if ( rwy_info.width <= 150 && rwylt1 == "6" ) { material = "pc_taxiway"; - else + } else { material = "pc_tiedown"; + } } - } else if ( surface_flag == "D" ) { - material = "dirt_rwy"; - } else if ( surface_flag == "G" ) { + } else if ( surface_code == 3 /* Turf/Grass */ ) { material = "grass_rwy"; - } else if ( surface_flag == "L" ) { + } else if ( surface_code == 4 /* Dirt */ + || surface_code == 5 /* Gravel */ ) { + material = "dirt_rwy"; + } else if ( surface_code == 12 /* Dry Lakebed */ ) { if ( rwy_info.really_taxiway ) { material = "lakebed_taxiway"; } else { material = "dirt_rwy"; } - } else if ( surface_flag == "T" ) { - material = "grass_rwy"; - } else if ( surface_flag == "W" ) { - // water ??? + } else if ( surface_code == 13 /* Water runway (buoy's?) */ ) { + // water } else { throw sg_exception("unknown runway type!"); } - string type_flag = rwy_info.surface_flags.substr(2, 1); - SG_LOG(SG_GENERAL, SG_DEBUG, "type flag = " << type_flag); + SG_LOG(SG_GENERAL, SG_DEBUG, "marking code = " << rwy_info.marking_code); if ( rwy_info.really_taxiway ) { gen_taxiway( rwy_info, alt_m, material, rwy_polys, texparams, accum ); - } else if ( surface_flag == "D" || surface_flag == "G" || - surface_flag == "T" ) + } else if ( surface_code == 3 /* Turf/Grass */ + || surface_code == 4 /* Dirt */ + || surface_code == 5 /* Gravel */ ) { gen_simple_rwy( rwy_info, alt_m, material, rwy_polys, texparams, accum ); - } else if ( type_flag == "P" ) { + } else if ( rwy_info.marking_code == 3 /* Precision */ ) { // precision runway markings gen_precision_rwy( rwy_info, alt_m, material, rwy_polys, texparams, accum ); - } else if ( type_flag == "R" ) { + } else if ( rwy_info.marking_code == 2 /* Non-precision */ ) { // non-precision runway markings gen_non_precision_rwy( rwy_info, alt_m, material, rwy_polys, texparams, accum ); - } else if ( type_flag == "V" ) { + } else if ( rwy_info.marking_code == 1 /* Visual */ ) { // visual runway markings gen_visual_rwy( rwy_info, alt_m, material, rwy_polys, texparams, accum ); - } else if ( type_flag == "B" ) { - // bouys (sea plane base) - // do nothing for now. - } else if ( type_flag == "H" ) { - // helipad + } else if ( surface_code == 13 /* Water buoys */ ) { // do nothing for now. } else { // unknown runway code ... hehe, I know, let's just die // right here so the programmer has to fix his code if a // new code ever gets introduced. :-) + SG_LOG( SG_GENERAL, SG_ALERT, "Unknown runway code = " << + rwy_info.marking_code ); throw sg_exception("Unknown runway code in build.cxx:build_airport()"); } @@ -337,7 +345,6 @@ 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, string_list& beacons_raw, string_list& towers_raw, string_list& windsocks_raw, @@ -365,81 +372,74 @@ void build_airport( string airport_id, float alt_m, SG_LOG( SG_GENERAL, SG_INFO, "Building " << airport_id ); - // parse runways and generate the vertex list - runway_list runways; - runways.clear(); - string rwy_str; + // parse runways/taxiways and generate the vertex list + runway_list runways; runways.clear(); + runway_list taxiways; taxiways.clear(); for ( i = 0; i < (int)runways_raw.size(); ++i ) { ++rwy_count; - rwy_str = runways_raw[i]; + string rwy_str = runways_raw[i]; + vector token = simgear::strutils::split( rwy_str ); TGRunway rwy; - rwy.really_taxiway = false; - SG_LOG(SG_GENERAL, SG_DEBUG, rwy_str); - rwy.rwy_no = rwy_str.substr(7, 4); + rwy.rwy_no = token[3]; + rwy.really_taxiway = (rwy.rwy_no == "xxx"); - string rwy_lat = rwy_str.substr(11, 10); - rwy.lat = atof( rwy_lat.c_str() ); + rwy.lat = atof( token[1].c_str() ); apt_lat += rwy.lat; - string rwy_lon = rwy_str.substr(22, 11); - rwy.lon = atof( rwy_lon.c_str() ); + rwy.lon = atof( token[2].c_str() ); apt_lon += rwy.lon; - string rwy_hdg = rwy_str.substr(34, 6); - rwy.heading = atof( rwy_hdg.c_str() ); + rwy.heading = atof( token[4].c_str() ); - string rwy_len = rwy_str.substr(41, 5); - rwy.length = atoi( rwy_len.c_str() ); + rwy.length = atoi( token[5].c_str() ); + rwy.width = atoi( token[8].c_str() ); - string rwy_width = rwy_str.substr(47, 5); - rwy.width = atoi( rwy_width.c_str() ); + string rwy_displ_threshold = token[6]; + vector displ + = simgear::strutils::split( rwy_displ_threshold, "." ); + rwy.disp_thresh1 = atoi( displ[0].c_str() ); + rwy.disp_thresh2 = atoi( displ[1].c_str() ); - rwy.surface_flags = rwy_str.substr(53, 5); + string rwy_stopway = token[7]; + vector stop + = simgear::strutils::split( rwy_stopway, "." ); + rwy.stopway1 = atoi( stop[0].c_str() ); + rwy.stopway2 = atoi( stop[1].c_str() ); - rwy.end1_flags = rwy_str.substr(59, 4); - - string rwy_disp_threshold1 = rwy_str.substr(64, 4); - rwy.disp_thresh1 = atoi( rwy_disp_threshold1.c_str() ); - - string rwy_stopway1 = rwy_str.substr(69, 4); - rwy.stopway1 = atoi( rwy_stopway1.c_str() ); - - rwy.end2_flags = rwy_str.substr(74, 4); - - string rwy_disp_threshold2 = rwy_str.substr(79, 4); - rwy.disp_thresh2 = atoi( rwy_disp_threshold2.c_str() ); - - string rwy_stopway2 = rwy_str.substr(83, 4); - rwy.stopway2 = atoi( rwy_stopway2.c_str() ); + rwy.lighting_flags = token[9]; + rwy.surface_code = atoi( token[10].c_str() ); + rwy.shoulder_code = token[11]; + rwy.marking_code = atoi( token[12].c_str() ); + rwy.smoothness = atof( token[13].c_str() ); + rwy.dist_remaining = (atoi( token[14].c_str() ) == 1 ); SG_LOG( SG_GENERAL, SG_DEBUG, " no = " << rwy.rwy_no); - SG_LOG( SG_GENERAL, SG_DEBUG, " lat = " << rwy_lat << " " << rwy.lat); - SG_LOG( SG_GENERAL, SG_DEBUG, " lon = " << rwy_lon << " " << rwy.lon); - SG_LOG( SG_GENERAL, SG_DEBUG, " hdg = " << rwy_hdg << " " - << rwy.heading); - SG_LOG( SG_GENERAL, SG_DEBUG, " len = " << rwy_len << " " - << rwy.length); - SG_LOG( SG_GENERAL, SG_DEBUG, " width = " << rwy_width << " " - << rwy.width); - SG_LOG( SG_GENERAL, SG_DEBUG, " sfc = " << rwy.surface_flags); - SG_LOG( SG_GENERAL, SG_DEBUG, " end1 = " << rwy.end1_flags); - SG_LOG( SG_GENERAL, SG_DEBUG, " dspth1= " << rwy_disp_threshold1 - << " " << rwy.disp_thresh1); - SG_LOG( SG_GENERAL, SG_DEBUG, " stop1 = " << rwy_stopway1 << " " - << rwy.stopway1); - SG_LOG( SG_GENERAL, SG_DEBUG, " end2 = " << rwy.end2_flags); - SG_LOG( SG_GENERAL, SG_DEBUG, " dspth2= " << rwy_disp_threshold2 - << " " << rwy.disp_thresh2); - SG_LOG( SG_GENERAL, SG_DEBUG, " stop2 = " << rwy_stopway2 << " " - << rwy.stopway2); + SG_LOG( SG_GENERAL, SG_DEBUG, " lat = " << rwy.lat); + SG_LOG( SG_GENERAL, SG_DEBUG, " lon = " << rwy.lon); + SG_LOG( SG_GENERAL, SG_DEBUG, " hdg = " << rwy.heading); + SG_LOG( SG_GENERAL, SG_DEBUG, " len = " << rwy.length); + SG_LOG( SG_GENERAL, SG_DEBUG, " width = " << rwy.width); + SG_LOG( SG_GENERAL, SG_DEBUG, " lighting = " << rwy.lighting_flags); + SG_LOG( SG_GENERAL, SG_DEBUG, " sfc = " << rwy.surface_code); + SG_LOG( SG_GENERAL, SG_DEBUG, " mrkgs = " << rwy.marking_code); + SG_LOG( SG_GENERAL, SG_DEBUG, " dspth1= " << rwy.disp_thresh1); + SG_LOG( SG_GENERAL, SG_DEBUG, " stop1 = " << rwy.stopway1); + SG_LOG( SG_GENERAL, SG_DEBUG, " dspth2= " << rwy.disp_thresh2); + SG_LOG( SG_GENERAL, SG_DEBUG, " stop2 = " << rwy.stopway2); - runways.push_back( rwy ); + if ( rwy.really_taxiway ) { + taxiways.push_back( rwy ); + } else { + runways.push_back( rwy ); + } } + SG_LOG(SG_GENERAL, SG_INFO, "Runway count = " << runways.size() ); + SG_LOG(SG_GENERAL, SG_INFO, "Taxiway count = " << taxiways.size() ); SGBucket b( apt_lon / (double)rwy_count, apt_lat / (double)rwy_count ); SG_LOG(SG_GENERAL, SG_INFO, b.gen_base_path() << "/" << b.gen_index_str()); @@ -447,52 +447,6 @@ void build_airport( string airport_id, float alt_m, b.get_center_lat() * SGD_DEGREES_TO_RADIANS, 0 ); Point3D gbs_center = sgGeodToCart( center_geod ); - // parse taxiways and generate the vertex list - runway_list taxiways; - taxiways.clear(); - - for ( i = 0; i < (int)taxiways_raw.size(); ++i ) { - string taxi_str = taxiways_raw[i]; - - TGRunway taxi; - - taxi.really_taxiway = true; - taxi.generated = false; - - SG_LOG(SG_GENERAL, SG_INFO, taxi_str); - - string taxi_lat = taxi_str.substr(11, 10); - taxi.lat = atof( taxi_lat.c_str() ); - - string taxi_lon = taxi_str.substr(22, 11); - taxi.lon = atof( taxi_lon.c_str() ); - - string taxi_hdg = taxi_str.substr(34, 6); - taxi.heading = atof( taxi_hdg.c_str() ); - - string taxi_len = taxi_str.substr(41, 5); - taxi.length = atoi( taxi_len.c_str() ); - - string taxi_width = taxi_str.substr(47, 5); - taxi.width = atoi( taxi_width.c_str() ); - - taxi.surface_flags = taxi_str.substr(53, 5); - - SG_LOG( SG_GENERAL, SG_DEBUG, " lat = " << taxi_lat << " " - << taxi.lat); - SG_LOG( SG_GENERAL, SG_DEBUG, " lon = " << taxi_lon << " " - << taxi.lon); - SG_LOG( SG_GENERAL, SG_DEBUG, " hdg = " << taxi_hdg << " " - << taxi.heading); - SG_LOG( SG_GENERAL, SG_DEBUG, " len = " << taxi_len << " " - << taxi.length); - SG_LOG( SG_GENERAL, SG_DEBUG, " width = " << taxi_width << " " - << taxi.width); - SG_LOG( SG_GENERAL, SG_DEBUG, " sfc = " << taxi.surface_flags); - - taxiways.push_back( taxi ); - } - point_list beacons; beacons.clear(); for ( i = 0; i < (int)beacons_raw.size(); ++i ) { string beacon_str = beacons_raw[i]; @@ -568,8 +522,7 @@ void build_airport( string airport_id, float alt_m, // First pass: generate the precision runways since these have // precidence for ( i = 0; i < (int)runways.size(); ++i ) { - string type_flag = runways[i].surface_flags.substr(2, 1); - if ( type_flag == "P" ) { + if ( runways[i].marking_code == 3 /* Precision */ ) { build_runway( runways[i], alt_m, &rwy_polys, &texparams, &accum, &apt_base, &apt_clearing ); @@ -578,10 +531,10 @@ void build_airport( string airport_id, float alt_m, // 2nd pass: generate the non-precision and visual runways for ( i = 0; i < (int)runways.size(); ++i ) { - string type_flag = runways[i].surface_flags.substr(2, 1); - string surface_flag = runways[i].surface_flags.substr(1, 1); - if ( type_flag == "R" || type_flag == "V" ) { - if ( surface_flag != "W" ) { + if ( runways[i].marking_code == 2 /* Non-precision */ + || runways[i].marking_code == 1 /* Visual */ ) + { + if ( runways[i].surface_code != 13 /* Water */ ) { // only build non-water runways build_runway( runways[i], alt_m, &rwy_polys, &texparams, &accum, @@ -592,11 +545,11 @@ void build_airport( string airport_id, float alt_m, // 3rd pass: generate all remaining runways not covered in the first pass for ( i = 0; i < (int)runways.size(); ++i ) { - string type_flag = runways[i].surface_flags.substr(2, 1); - string surface_flag = runways[i].surface_flags.substr(1, 1); - if ( type_flag != string("P") && type_flag != string("R") - && type_flag != string("V") ) { - if ( surface_flag != "W" ) { + if ( runways[i].marking_code != 3 /* Precision */ + && runways[i].marking_code != 2 /* Non-precision */ + && runways[i].marking_code != 1 /* Visual */ ) + { + if ( runways[i].surface_code != 13 ) { // only build non-water runways build_runway( runways[i], alt_m, &rwy_polys, &texparams, &accum, diff --git a/src/Airports/GenAirports/build.hxx b/src/Airports/GenAirports/build.hxx index 497fcbcb..3022cdb7 100644 --- a/src/Airports/GenAirports/build.hxx +++ b/src/Airports/GenAirports/build.hxx @@ -36,7 +36,6 @@ // build 3d airport void build_airport( string airport_id, float alt_m, string_list& runways_raw, - string_list& taxiways_raw, string_list& beacons_raw, string_list& towers_raw, string_list& windsocks_raw, diff --git a/src/Airports/GenAirports/lights.cxx b/src/Airports/GenAirports/lights.cxx index 821fd1a0..42d6ea47 100644 --- a/src/Airports/GenAirports/lights.cxx +++ b/src/Airports/GenAirports/lights.cxx @@ -85,7 +85,7 @@ static Point3D gen_runway_light_vector( const TGRunway& rwy_info, // generate runway edge lighting // 60 meters spacing or the next number down that divides evenly. static superpoly_list gen_runway_edge_lights( const TGRunway& rwy_info, - const string& kind, bool recip ) + const int kind, bool recip ) { point_list w_lights; w_lights.clear(); point_list y_lights; y_lights.clear(); @@ -160,13 +160,12 @@ static superpoly_list gen_runway_edge_lights( const TGRunway& rwy_info, TGSuperPoly white; white.set_poly( lights_poly ); white.set_normals( normals_poly ); - if ( kind == "H" ) { - white.set_material( "RWY_WHITE_LIGHTS" ); - } else if ( kind == "M" ) { - white.set_material( "RWY_WHITE_MEDIUM_LIGHTS" ); - } else if ( kind == "L" ) { - white.set_material( "RWY_WHITE_LOW_LIGHTS" ); - } + white.set_material( "RWY_WHITE_LIGHTS" ); + /* other intensities for when the data file supports it + * + * white.set_material( "RWY_WHITE_MEDIUM_LIGHTS" ); + * white.set_material( "RWY_WHITE_LOW_LIGHTS" ); + */ lights_poly.erase(); normals_poly.erase(); @@ -176,13 +175,12 @@ static superpoly_list gen_runway_edge_lights( const TGRunway& rwy_info, TGSuperPoly yellow; yellow.set_poly( lights_poly ); yellow.set_normals( normals_poly ); - if ( kind == "H" ) { - yellow.set_material( "RWY_YELLOW_LIGHTS" ); - } else if ( kind == "M" ) { - yellow.set_material( "RWY_YELLOW_MEDIUM_LIGHTS" ); - } else if ( kind == "L" ) { - yellow.set_material( "RWY_YELLOW_LOW_LIGHTS" ); - } + yellow.set_material( "RWY_YELLOW_LIGHTS" ); + /* other intensities for when the data file supports it + * + * yellow.set_material( "RWY_YELLOW_MEDIUM_LIGHTS" ); + * yellow.set_material( "RWY_YELLOW_LOW_LIGHTS" ); + */ superpoly_list result; result.clear(); @@ -196,7 +194,7 @@ static superpoly_list gen_runway_edge_lights( const TGRunway& rwy_info, // generate taxiway edge lighting // 100 meters spacing or the next number down that divides evenly. static superpoly_list gen_taxiway_edge_lights( const TGRunway& rwy_info, - const string& kind, bool recip ) + const int kind, bool recip ) { point_list b_lights; b_lights.clear(); point_list b_normals; b_normals.clear(); @@ -279,7 +277,7 @@ static superpoly_list gen_taxiway_edge_lights( const TGRunway& rwy_info, // generate threshold lights for a 3 degree approach static superpoly_list gen_runway_threshold_lights( const TGRunway& rwy_info, - const string& kind, + const int kind, float alt_m, bool recip ) { point_list g_lights; g_lights.clear(); @@ -369,17 +367,11 @@ static superpoly_list gen_runway_threshold_lights( const TGRunway& rwy_info, green.set_poly( lights_poly ); green.set_normals( normals_poly ); green.set_material( "RWY_GREEN_LIGHTS" ); - if ( kind == "H" ) { - green.set_material( "RWY_GREEN_LIGHTS" ); - } else if ( kind == "M" ) { - green.set_material( "RWY_GREEN_MEDIUM_LIGHTS" ); - } else if ( kind == "L" ) { - green.set_material( "RWY_GREEN_LOW_LIGHTS" ); - } else { - // this is a catch all in case there is an oddity in the input - // data - green.set_material( "RWY_GREEN_LIGHTS" ); - } + /* other intensities for when the data file supports it + * + * green.set_material( "RWY_GREEN_MEDIUM_LIGHTS" ); + * green.set_material( "RWY_GREEN_LOW_LIGHTS" ); + */ lights_poly.erase(); normals_poly.erase(); @@ -389,17 +381,12 @@ static superpoly_list gen_runway_threshold_lights( const TGRunway& rwy_info, TGSuperPoly red; red.set_poly( lights_poly ); red.set_normals( normals_poly ); - if ( kind == "H" ) { - red.set_material( "RWY_RED_LIGHTS" ); - } else if ( kind == "M" ) { - red.set_material( "RWY_RED_MEDIUM_LIGHTS" ); - } else if ( kind == "L" ) { - red.set_material( "RWY_RED_LOW_LIGHTS" ); - } else { - // this is a catch all in case there is an oddity in the input - // data - red.set_material( "RWY_RED_LIGHTS" ); - } + red.set_material( "RWY_RED_LIGHTS" ); + /* other intensities for when the data file supports it + * + * red.set_material( "RWY_RED_MEDIUM_LIGHTS" ); + * red.set_material( "RWY_RED_LOW_LIGHTS" ); + */ superpoly_list result; result.clear(); @@ -2578,82 +2565,85 @@ static superpoly_list gen_malsx( const TGRunway& rwy_info, void gen_runway_lights( const TGRunway& rwy_info, float alt_m, superpoly_list &lights ) { - SG_LOG(SG_GENERAL, SG_DEBUG, "gen runway lights " << rwy_info.rwy_no << " " - << rwy_info.end1_flags << " " << rwy_info.end2_flags); + string lighting_flags = rwy_info.lighting_flags; + SG_LOG( SG_GENERAL, SG_DEBUG, "gen runway lights " << rwy_info.rwy_no << " " + << rwy_info.lighting_flags ); + + int vasi1 = atoi( lighting_flags.substr(0,1).c_str() ); + int rwylt1 = atoi( lighting_flags.substr(1,1).c_str() ); + int app1 = atoi( lighting_flags.substr(2,1).c_str() ); + int vasi2 = atoi( lighting_flags.substr(3,1).c_str() ); + int rwylt2 = atoi( lighting_flags.substr(4,1).c_str() ); + int app2 = atoi( lighting_flags.substr(5,1).c_str() ); unsigned int i; // Make edge lighting - string edge_type = rwy_info.surface_flags.substr(3,1); - if ( edge_type != (string)"N" ) { + if ( rwylt1 >= 2 /* Has edge lighting */ ) { // forward direction - superpoly_list s; - s = gen_runway_edge_lights( rwy_info, edge_type, false ); + superpoly_list s = gen_runway_edge_lights( rwy_info, rwylt1, false ); for ( i = 0; i < s.size(); ++i ) { lights.push_back( s[i] ); } - + } + if ( rwylt2 >= 2 /* Has edge lighting */ ) { // reverse direction - s = gen_runway_edge_lights( rwy_info, edge_type, true ); + superpoly_list s = gen_runway_edge_lights( rwy_info, rwylt2, true ); for ( i = 0; i < s.size(); ++i ) { lights.push_back( s[i] ); } } // Centerline lighting - if ( rwy_info.surface_flags.substr(0,1) == "Y" ) { + if ( rwylt1 >= 4 /* Has centerline lighting */ ) { // forward direction - superpoly_list s; - s = gen_runway_center_line_lights( rwy_info, false ); + superpoly_list s = gen_runway_center_line_lights( rwy_info, false ); for ( i = 0; i < s.size(); ++i ) { lights.push_back( s[i] ); } - + } + if ( rwylt2 >= 4 /* Has centerline lighting */ ) { // reverse direction - s = gen_runway_center_line_lights( rwy_info, true ); + superpoly_list s = gen_runway_center_line_lights( rwy_info, true ); for ( i = 0; i < s.size(); ++i ) { lights.push_back( s[i] ); } } // Touchdown zone lighting - if ( rwy_info.end1_flags.substr(0,1) == "Y" ) { + if ( rwylt1 >= 5 /* Has touchdown zone lighting */ ) { TGSuperPoly s = gen_touchdown_zone_lights( rwy_info, alt_m, false ); lights.push_back( s ); } - if ( rwy_info.end2_flags.substr(0,1) == "Y" ) { + if ( rwylt2 >= 5 /* Has touchdown zone lighting */ ) { TGSuperPoly s = gen_touchdown_zone_lights( rwy_info, alt_m, true ); lights.push_back( s ); } // REIL lighting - if ( rwy_info.end1_flags.substr(1,1) == "Y" ) { + if ( rwylt1 >= 3 /* Has REIL lighting */ ) { TGSuperPoly s = gen_reil( rwy_info, alt_m, false ); lights.push_back( s ); } - if ( rwy_info.end2_flags.substr(1,1) == "Y" ) { + if ( rwylt2 >= 3 /* Has REIL lighting */ ) { TGSuperPoly s = gen_reil( rwy_info, alt_m, true ); lights.push_back( s ); } - // PAPI lighting - if ( rwy_info.end1_flags.substr(2,1) == "P" ) { + // VASI/PAPI lighting + if ( vasi1 == 2 /* Has VASI */ ) { + TGSuperPoly s = gen_vasi( rwy_info, alt_m, false ); + lights.push_back( s ); + } else if ( vasi1 == 3 /* Has PAPI */ ) { TGSuperPoly s = gen_papi( rwy_info, alt_m, false ); lights.push_back( s ); } - if ( rwy_info.end2_flags.substr(2,1) == "P" ) { - TGSuperPoly s = gen_papi( rwy_info, alt_m, true ); - lights.push_back( s ); - } - - // VASI lighting - if ( rwy_info.end1_flags.substr(2,1) == "V" ) { - TGSuperPoly s = gen_vasi( rwy_info, alt_m, false ); - lights.push_back( s ); - } - if ( rwy_info.end2_flags.substr(2,1) == "V" ) { + if ( vasi2 == 2 /* Has VASI */ ) { TGSuperPoly s = gen_vasi( rwy_info, alt_m, true ); lights.push_back( s ); + } else if ( vasi2 == 3 /* Has PAPI */ ) { + TGSuperPoly s = gen_papi( rwy_info, alt_m, true ); + lights.push_back( s ); } // Approach lighting @@ -2666,28 +2656,26 @@ void gen_runway_lights( const TGRunway& rwy_info, float alt_m, // Please send me documentation for this configuration //////////////////////////////////////////////////////////// - // ALSF-I - if ( rwy_info.end1_flags.substr(3,1) == "B" ) { + if ( app1 == 4 /* ALSF-I */ ) { superpoly_list s = gen_alsf( rwy_info, alt_m, "1", false ); for ( i = 0; i < s.size(); ++i ) { lights.push_back( s[i] ); } } - if ( rwy_info.end2_flags.substr(3,1) == "B" ) { + if ( app2 == 4 /* ALSF-I */ ) { superpoly_list s = gen_alsf( rwy_info, alt_m, "1", true ); for ( i = 0; i < s.size(); ++i ) { lights.push_back( s[i] ); } } - // ALSF-II - if ( rwy_info.end1_flags.substr(3,1) == "C" ) { + if ( app1 == 5 /* ALSF-II */ ) { superpoly_list s = gen_alsf( rwy_info, alt_m, "2", false ); for ( i = 0; i < s.size(); ++i ) { lights.push_back( s[i] ); } } - if ( rwy_info.end2_flags.substr(3,1) == "C" ) { + if ( app2 == 5 /* ALSF-II */ ) { superpoly_list s = gen_alsf( rwy_info, alt_m, "2", true ); for ( i = 0; i < s.size(); ++i ) { lights.push_back( s[i] ); @@ -2704,13 +2692,13 @@ void gen_runway_lights( const TGRunway& rwy_info, float alt_m, // Please send me documentation for this configuration //////////////////////////////////////////////////////////// - if ( rwy_info.end2_flags.substr(3,1) == "D" ) { + if ( app1 == 7 || app1 == 8 /* Calvert 1, 2, and 3 */ ) { superpoly_list s = gen_calvert( rwy_info, alt_m, "1", true ); for ( i = 0; i < s.size(); ++i ) { lights.push_back( s[i] ); } } - if ( rwy_info.end2_flags.substr(3,1) == "E" ) { + if ( app2 == 7 || app2 == 8 /* Calvert 1, 2, and 3 */ ) { superpoly_list s = gen_calvert( rwy_info, alt_m, "2", true ); for ( i = 0; i < s.size(); ++i ) { lights.push_back( s[i] ); @@ -2725,28 +2713,26 @@ void gen_runway_lights( const TGRunway& rwy_info, float alt_m, // data is provided in our database //////////////////////////////////////////////////////////// - // MALS - if ( rwy_info.end1_flags.substr(3,1) == "G" ) { + if ( app1 == -1 /* MALS not supported by data base */ ) { superpoly_list s = gen_malsx( rwy_info, alt_m, "x", false ); for ( i = 0; i < s.size(); ++i ) { lights.push_back( s[i] ); } } - if ( rwy_info.end2_flags.substr(3,1) == "G" ) { + if ( app2 == -1 /* MALS not supported by data base */ ) { superpoly_list s = gen_malsx( rwy_info, alt_m, "x", true ); for ( i = 0; i < s.size(); ++i ) { lights.push_back( s[i] ); } } - // MALSF - if ( rwy_info.end1_flags.substr(3,1) == "H" ) { + if ( app1 == -1 /* MALSF not supported by data base */ ) { superpoly_list s = gen_malsx( rwy_info, alt_m, "F", false ); for ( i = 0; i < s.size(); ++i ) { lights.push_back( s[i] ); } } - if ( rwy_info.end2_flags.substr(3,1) == "H" ) { + if ( app2 == -1 /* MALSF not supported by data base */ ) { superpoly_list s = gen_malsx( rwy_info, alt_m, "F", true ); for ( i = 0; i < s.size(); ++i ) { lights.push_back( s[i] ); @@ -2761,14 +2747,13 @@ void gen_runway_lights( const TGRunway& rwy_info, float alt_m, // This is also likely airport specific //////////////////////////////////////////////////////////// - // MALSR - if ( rwy_info.end1_flags.substr(3,1) == "J" ) { + if ( app1 == -1 /* MALSR not supported by data base */ ) { superpoly_list s = gen_malsx( rwy_info, alt_m, "R", false ); for ( i = 0; i < s.size(); ++i ) { lights.push_back( s[i] ); } } - if ( rwy_info.end2_flags.substr(3,1) == "J" ) { + if ( app2 == -1 /* MALSR not supported by data base */ ) { superpoly_list s = gen_malsx( rwy_info, alt_m, "R", true ); for ( i = 0; i < s.size(); ++i ) { lights.push_back( s[i] ); @@ -2783,12 +2768,11 @@ void gen_runway_lights( const TGRunway& rwy_info, float alt_m, // No clue ... //////////////////////////////////////////////////////////// - // ODALS Omni-directional approach light system - if ( rwy_info.end1_flags.substr(3,1) == "L" ) { + if ( app1 == 6 /* ODALS Omni-directional approach light system */ ) { TGSuperPoly s = gen_odals( rwy_info, alt_m, false ); lights.push_back( s ); } - if ( rwy_info.end2_flags.substr(3,1) == "L" ) { + if ( app2 == 6 /* ODALS Omni-directional approach light system */ ) { TGSuperPoly s = gen_odals( rwy_info, alt_m, true ); lights.push_back( s ); } @@ -2802,69 +2786,65 @@ void gen_runway_lights( const TGRunway& rwy_info, float alt_m, // SALS (Essentially ALSF-1 without the lead in rabbit lights, and // a shorter center bar) - if ( rwy_info.end1_flags.substr(3,1) == "O" ) { + if ( app1 == -1 /* SALS not supported by database */ ) { superpoly_list s = gen_alsf( rwy_info, alt_m, "O", false ); for ( i = 0; i < s.size(); ++i ) { lights.push_back( s[i] ); } } - if ( rwy_info.end2_flags.substr(3,1) == "O" ) { + if ( app2 == -1 /* SALS not supported by database */ ) { superpoly_list s = gen_alsf( rwy_info, alt_m, "O", true ); for ( i = 0; i < s.size(); ++i ) { lights.push_back( s[i] ); } } - // SALSF - if ( rwy_info.end1_flags.substr(3,1) == "P" ) { + if ( app1 == 3 /* SALSF */ ) { superpoly_list s = gen_alsf( rwy_info, alt_m, "P", false ); for ( i = 0; i < s.size(); ++i ) { lights.push_back( s[i] ); } } - if ( rwy_info.end2_flags.substr(3,1) == "P" ) { + if ( app2 == 3 /* SALSF */ ) { superpoly_list s = gen_alsf( rwy_info, alt_m, "P", true ); for ( i = 0; i < s.size(); ++i ) { lights.push_back( s[i] ); } } - // SSALF - if ( rwy_info.end1_flags.substr(3,1) == "Q" ) { + if ( app1 == -1 /* SSALF not supported by database */ ) { superpoly_list s = gen_ssalx( rwy_info, alt_m, "F", false ); for ( i = 0; i < s.size(); ++i ) { lights.push_back( s[i] ); } } - if ( rwy_info.end2_flags.substr(3,1) == "Q" ) { + if ( app2 == -1 /* SSALF not supported by database */ ) { superpoly_list s = gen_ssalx( rwy_info, alt_m, "F", true ); for ( i = 0; i < s.size(); ++i ) { lights.push_back( s[i] ); } } - // SSALR - if ( rwy_info.end1_flags.substr(3,1) == "R" ) { + if ( app1 == -1 /* SSALR not supported by database */ ) { superpoly_list s = gen_ssalx( rwy_info, alt_m, "R", false ); for ( i = 0; i < s.size(); ++i ) { lights.push_back( s[i] ); } } - if ( rwy_info.end2_flags.substr(3,1) == "R" ) { + if ( app2 == -1 /* SSALR not supported by database */ ) { superpoly_list s = gen_ssalx( rwy_info, alt_m, "R", true ); for ( i = 0; i < s.size(); ++i ) { lights.push_back( s[i] ); } } - // SSALS - if ( rwy_info.end1_flags.substr(3,1) == "S" ) { + if ( app1 == 2 /* SSALS */ ) { superpoly_list s = gen_ssalx( rwy_info, alt_m, "S", false ); for ( i = 0; i < s.size(); ++i ) { lights.push_back( s[i] ); } } - if ( rwy_info.end2_flags.substr(3,1) == "S" ) { + if ( app2 == 2 /* SSALS */ ) { superpoly_list s = gen_ssalx( rwy_info, alt_m, "S", true ); for ( i = 0; i < s.size(); ++i ) { lights.push_back( s[i] ); @@ -2875,25 +2855,25 @@ void gen_runway_lights( const TGRunway& rwy_info, float alt_m, // needed, but for those that don't (i.e. REIL, ODALS, or Edge // lights defined but no approach lights.) // Make threshold lighting - if ( rwy_info.end1_flags.substr(1,1) == "Y" || - rwy_info.end1_flags.substr(3,1) == "L" || - ( rwy_info.surface_flags.substr(3,1) != (string)"N" && - rwy_info.end1_flags.substr(3,1) == "N") ) + if ( rwylt1 >= 3 /* Has REIL lighting */ + || app1 == 6 /* ODALS Omni-directional approach light system */ + || ( rwylt1 >= 2 /* Has edge lighting */ + && app1 == 0 /* No approach lighting */ ) ) { // forward direction - superpoly_list s = gen_runway_threshold_lights( rwy_info, edge_type, + superpoly_list s = gen_runway_threshold_lights( rwy_info, rwylt1, alt_m, false ); for ( i = 0; i < s.size(); ++i ) { lights.push_back( s[i] ); } } - if ( rwy_info.end2_flags.substr(1,1) == "Y" || - rwy_info.end2_flags.substr(3,1) == "L" || - ( rwy_info.surface_flags.substr(3,1) != (string)"N" && - rwy_info.end2_flags.substr(3,1) == "N" ) ) + if ( rwylt2 >= 3 /* Has REIL lighting */ + || app2 == 6 /* ODALS Omni-directional approach light system */ + || ( rwylt2 >= 2 /* Has edge lighting */ + && app2 == 0 /* No approach lighting */ ) ) { // reverse direction - superpoly_list s = gen_runway_threshold_lights( rwy_info, edge_type, + superpoly_list s = gen_runway_threshold_lights( rwy_info, rwylt1, alt_m, true ); for ( i = 0; i < s.size(); ++i ) { lights.push_back( s[i] ); @@ -2904,35 +2884,43 @@ void gen_runway_lights( const TGRunway& rwy_info, float alt_m, // top level taxiway light generator void gen_taxiway_lights( const TGRunway& taxiway_info, float alt_m, - superpoly_list &lights ) { + superpoly_list &lights ) +{ + SG_LOG( SG_GENERAL, SG_DEBUG, "gen taxiway lights " + << taxiway_info.rwy_no << " " + << taxiway_info.lighting_flags ); - SG_LOG(SG_GENERAL, SG_DEBUG, "gen taxiway lights " << taxiway_info.rwy_no << " " - << taxiway_info.end1_flags << " " << taxiway_info.end2_flags); + string lighting_flags = taxiway_info.lighting_flags; + int rwylt1 = atoi( lighting_flags.substr(1,1).c_str() ); + int rwylt2 = atoi( lighting_flags.substr(4,1).c_str() ); unsigned int i; // Centerline lighting - if ( taxiway_info.surface_flags.substr(0,1) == "Y" ) { + if ( rwylt1 == 6 /* taxiway lit, assume centerline too */ ) { // forward direction - superpoly_list s; - s = gen_taxiway_center_line_lights( taxiway_info, false ); + superpoly_list s + = gen_taxiway_center_line_lights( taxiway_info, false ); for ( i = 0; i < s.size(); ++i ) { lights.push_back( s[i] ); } + } + if ( rwylt2 == 6 /* taxiway lit, assume centerline too */ ) { // reverse direction - s = gen_taxiway_center_line_lights( taxiway_info, true ); + superpoly_list s + = gen_taxiway_center_line_lights( taxiway_info, true ); for ( i = 0; i < s.size(); ++i ) { lights.push_back( s[i] ); } } // Make edge lighting - string edge_type = taxiway_info.surface_flags.substr(2,1); - if ( taxiway_info.surface_flags.substr(2,1) == "B" ) { - // forward direction + if ( rwylt1 == 6 /* taxiway blue lit */ ) { + // forward direction (blue lights are omni-directional so we + // don't need to generate the reverse direction superpoly_list s; - s = gen_taxiway_edge_lights( taxiway_info, "B", false ); + s = gen_taxiway_edge_lights( taxiway_info, rwylt1, false ); for ( i = 0; i < s.size(); ++i ) { lights.push_back( s[i] ); } diff --git a/src/Airports/GenAirports/main.cxx b/src/Airports/GenAirports/main.cxx index dfb91a6c..95f22c55 100644 --- a/src/Airports/GenAirports/main.cxx +++ b/src/Airports/GenAirports/main.cxx @@ -34,6 +34,8 @@ #endif #include +#include +SG_USING_STD(vector); #include #include @@ -43,6 +45,7 @@ #include #include #include +#include #include #include @@ -54,6 +57,8 @@ # include #endif + + int nudge = 10; @@ -232,11 +237,11 @@ int main( int argc, char **argv ) { } string_list runways_list; - string_list taxiways_list; string_list beacon_list; string_list tower_list; string_list windsock_list; + vector token; string last_apt_id = ""; string last_apt_info = ""; string line; @@ -245,37 +250,51 @@ int main( int argc, char **argv ) { while ( ! in.eof() ) { in.getline(tmp, 2048); line = tmp; - SG_LOG( SG_GENERAL, SG_DEBUG, "-> " << line ); + SG_LOG( SG_GENERAL, SG_DEBUG, "-> '" << line << "'" ); + if ( line.length() ) { + token = simgear::strutils::split( line ); + SG_LOG( SG_GENERAL, SG_DEBUG, "token[0] " << token[0] ); + } else { + token.clear(); + } - if ( line.length() == 0 ) { - // empty, skip - } else if (( line[0] == '#' ) || (line[0] == '/' && line[1] == '/')) { + if ( !line.length() ) { + // empty line, skip + } else if ( (token[0] == "#") || (token[0] == "//") ) { // comment, skip - } else if ( line[0] == 'A' || line[0] == 'H' || line[0] == 'S' ) { - // extract some airport runway info - char ctmp, tmpid[32], rwy[32]; - string id; - float lat, lon; - int elev = 0; + } else if ( token[0] == "I" ) { + // First line, indicates IBM (i.e. DOS line endings I + // believe.) - sscanf( line.c_str(), "%c %s %d", - &ctmp, tmpid, &elev ); - id = tmpid; - SG_LOG( SG_GENERAL, SG_DEBUG, "Next airport = " << id << " " + // move past this line and read and discard the next line + // which is the version and copyright information + in.getline(tmp, 2048); + vector vers_token = simgear::strutils::split( tmp ); + SG_LOG( SG_GENERAL, SG_INFO, "Data version = " << vers_token[0] ); + } else if ( token[0] == "1" /* Airport */ + || token[0] == "16" /* Seaplane Base */ + || token[0] == "17" /* Heliport */ ) + { + // extract some airport runway info + string rwy; + float lat, lon; + + string id = token[4]; + int elev = atoi( token[1].c_str() ); + SG_LOG( SG_GENERAL, SG_INFO, "Next airport = " << id << " " << elev ); if ( !last_apt_id.empty()) { if ( runways_list.size() ) { - sscanf( runways_list[0].c_str(), "%c %s %s %f %f", - &ctmp, tmpid, rwy, &lat, &lon ); - } + vector rwy_token + = simgear::strutils::split( runways_list[0] ); + rwy = token[3]; + lat = atof( token[1].c_str() ); + lon = atof( token[2].c_str() ); - if ( lon >= min_lon && lon <= max_lon && - lat >= min_lat && lat <= max_lat ) - { - if ( airport_id.length() && airport_id == last_apt_id ) { - ready_to_go = true; - } else if ( start_id.length() && start_id == last_apt_id ) { + if ( airport_id.length() && airport_id == last_apt_id ) { + ready_to_go = true; + } else if ( start_id.length() && start_id == last_apt_id ) { ready_to_go = true; } @@ -290,9 +309,11 @@ int main( int argc, char **argv ) { // process previous record // process_airport(last_apt_id, runways_list, argv[2]); try { - build_airport( last_apt_id, elev * SG_FEET_TO_METER, - runways_list, taxiways_list, - beacon_list, tower_list, + build_airport( last_apt_id, + elev * SG_FEET_TO_METER, + runways_list, + beacon_list, + tower_list, windsock_list, work_dir, elev_src ); } catch (sg_exception &e) { @@ -303,37 +324,44 @@ int main( int argc, char **argv ) { << e.getMessage() ); exit(-1); } - if(airport_id.length()) ready_to_go = false; + if ( airport_id.length() ) { + ready_to_go = false; + } } } else { if(!airport_id.length()) { - SG_LOG(SG_GENERAL, SG_INFO, "Skipping airport " << id); + SG_LOG(SG_GENERAL, SG_INFO, + "ERRO: No runways, skipping = " << id); } } - } + } + last_apt_id = id; last_apt_info = line; // clear runway list for start of next airport runways_list.clear(); - taxiways_list.clear(); beacon_list.clear(); tower_list.clear(); windsock_list.clear(); - } else if ( line[0] == 'R' ) { + } else if ( token[0] == "10" ) { // runway entry runways_list.push_back(line); - } else if ( line[0] == 'T' ) { - // taxiway entry - taxiways_list.push_back(line); - } else if ( line[0] == 'B' ) { + } else if ( token[0] == "18" ) { // beacon entry beacon_list.push_back(line); - } else if ( line[0] == 'C' ) { + } else if ( token[0] == "14" ) { // control tower entry tower_list.push_back(line); - } else if ( line[0] == 'W' ) { - // control tower entry + } else if ( token[0] == "19" ) { + // windsock entry windsock_list.push_back(line); + } else if ( token[0] == "15" ) { + // ignore custom startup locations + } else if ( token[0] == "50" || token[0] == "51" || token[0] == "52" + || token[0] == "53" || token[0] == "54" || token[0] == "55" + || token[0] == "56" ) + { + // ignore frequency entries } else { SG_LOG( SG_GENERAL, SG_ALERT, "Unknown line in file: " << line ); @@ -354,37 +382,34 @@ int main( int argc, char **argv ) { &ctmp, tmpid, rwy, &lat, &lon ); } - if ( lon >= min_lon && lon <= max_lon && - lat >= min_lat && lat <= max_lat ) - { - if ( start_id.length() && start_id == last_apt_id ) { - ready_to_go = true; - } + if ( start_id.length() && start_id == last_apt_id ) { + ready_to_go = true; + } - if ( ready_to_go ) { - // check point our location - char command[256]; - sprintf( command, - "echo before building %s >> last_apt", - last_apt_id.c_str() ); - system( command ); + if ( ready_to_go ) { + // check point our location + char command[256]; + sprintf( command, + "echo before building %s >> last_apt", + last_apt_id.c_str() ); + system( command ); - // process previous record - // process_airport(last_apt_id, runways_list, argv[2]); - try { - build_airport( last_apt_id, elev * SG_FEET_TO_METER, - runways_list, taxiways_list, - beacon_list, tower_list, - windsock_list, - work_dir, elev_src ); - } catch (sg_exception &e) { - SG_LOG( SG_GENERAL, SG_ALERT, - "Failed to build airport = " - << last_apt_id ); - SG_LOG( SG_GENERAL, SG_ALERT, "Exception: " - << e.getMessage() ); - exit(-1); - } + // process previous record + // process_airport(last_apt_id, runways_list, argv[2]); + try { + build_airport( last_apt_id, elev * SG_FEET_TO_METER, + runways_list, + beacon_list, + tower_list, + windsock_list, + work_dir, elev_src ); + } catch (sg_exception &e) { + SG_LOG( SG_GENERAL, SG_ALERT, + "Failed to build airport = " + << last_apt_id ); + SG_LOG( SG_GENERAL, SG_ALERT, "Exception: " + << e.getMessage() ); + exit(-1); } } else { SG_LOG(SG_GENERAL, SG_INFO, "Skipping airport " << id); diff --git a/src/Airports/GenAirports/runway.hxx b/src/Airports/GenAirports/runway.hxx index e859dcb0..aae1eb10 100644 --- a/src/Airports/GenAirports/runway.hxx +++ b/src/Airports/GenAirports/runway.hxx @@ -47,9 +47,12 @@ struct TGRunway { double stopway1; double stopway2; - string surface_flags; - string end1_flags; - string end2_flags; + string lighting_flags; + int surface_code; + string shoulder_code; + int marking_code; + double smoothness; + bool dist_remaining; TGPolygon threshold; TGPolygon tens, tens_margin, ones, ones_margin; diff --git a/src/Airports/GenAirports/rwy_visual.cxx b/src/Airports/GenAirports/rwy_visual.cxx index caa6af99..ec0b81f4 100644 --- a/src/Airports/GenAirports/rwy_visual.cxx +++ b/src/Airports/GenAirports/rwy_visual.cxx @@ -94,7 +94,8 @@ void gen_visual_rwy( const TGRunway& rwy_info, double length = rwy_info.length / 2.0 + 2.0; if ( length < 1150 ) { SG_LOG(SG_GENERAL, SG_ALERT, - "This runway is not long enough for visual markings!"); + "This runway is not long enough for visual markings = " + << rwy_info.length ); } double start1_pct = 0.0;