From 5e84fda1443eeac9794ab87b83d84ac5061c4698 Mon Sep 17 00:00:00 2001 From: Scott Giese Date: Sun, 23 Sep 2018 00:52:51 -0500 Subject: [PATCH] GenApts850: Bug fix #800 Genapts outputs duplicated data --- src/Airports/GenAirports850/airport.cxx | 43 ++++++++++++++----------- src/Airports/GenAirports850/output.cxx | 32 +++++++++++++----- src/Airports/GenAirports850/output.hxx | 20 ++++++------ 3 files changed, 60 insertions(+), 35 deletions(-) diff --git a/src/Airports/GenAirports850/airport.cxx b/src/Airports/GenAirports850/airport.cxx index 0ffd618c..1ac75a08 100644 --- a/src/Airports/GenAirports850/airport.cxx +++ b/src/Airports/GenAirports850/airport.cxx @@ -1137,16 +1137,23 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src ) throw sg_exception("error writing file. :-("); } + std::string indexFileName = objpath + "/" + b.gen_base_path() + "/" + b.gen_index_str() + ".ind"; + if (cleanIndexFiles.find(indexFileName) == cleanIndexFiles.end()) + { + truncate_index_file(indexFileName); + cleanIndexFiles.insert(indexFileName); + } + // write out airport object reference - write_index( objpath, b, name ); + write_index_object( objpath, b, name ); #if 0 // TODO : along with taxiway signs // write out tower references for ( i = 0; i < (int)tower_nodes.size(); ++i ) { - write_index_shared( objpath, b, tower_nodes[i], - "Models/Airport/tower.xml", - 0.0 ); + write_index_object_shared( objpath, b, tower_nodes[i], + "Models/Airport/tower.xml", + 0.0 ); } #endif @@ -1161,13 +1168,13 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src ) if ( windsocks[i]->IsLit() ) { - write_index_shared( objpath, b, ref_geod, - "Models/Airport/windsock_lit.xml", 0.0 ); + write_index_object_shared( objpath, b, ref_geod, + "Models/Airport/windsock_lit.xml", 0.0 ); } else { - write_index_shared( objpath, b, ref_geod, - "Models/Airport/windsock.xml", 0.0 ); + write_index_object_shared( objpath, b, ref_geod, + "Models/Airport/windsock.xml", 0.0 ); } } @@ -1177,9 +1184,9 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src ) ref_geod = beacons[i]->GetLoc(); ref_geod.setElevationM( apt_surf.calc_elevation( ref_geod, 0.0 ) ); - write_index_shared( objpath, b, ref_geod, - "Models/Airport/beacon.xml", - 0.0 ); + write_index_object_shared( objpath, b, ref_geod, + "Models/Airport/beacon.xml", + 0.0 ); } // write out taxiway signs references @@ -1187,10 +1194,10 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src ) { ref_geod = signs[i]->GetLoc(); ref_geod.setElevationM( apt_surf.calc_elevation( ref_geod, 0.0 ) ); - write_object_sign( objpath, b, ref_geod, - signs[i]->GetDefinition(), - signs[i]->GetHeading(), - signs[i]->GetSize() ); + write_index_object_sign( objpath, b, ref_geod, + signs[i]->GetDefinition(), + signs[i]->GetHeading(), + signs[i]->GetSize() ); } // write out water buoys @@ -1202,9 +1209,9 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src ) { ref_geod = buoys.GetNode(j); ref_geod.setElevationM( apt_surf.calc_elevation( ref_geod, 0.0 ) ); - write_index_shared( objpath, b, ref_geod, - "Models/Airport/water_rw_buoy.xml", - 0.0 ); + write_index_object_shared( objpath, b, ref_geod, + "Models/Airport/water_rw_buoy.xml", + 0.0 ); } } diff --git a/src/Airports/GenAirports850/output.cxx b/src/Airports/GenAirports850/output.cxx index 0b7fa059..f7581e1c 100644 --- a/src/Airports/GenAirports850/output.cxx +++ b/src/Airports/GenAirports850/output.cxx @@ -24,19 +24,20 @@ #include #endif -#include +#include #include +#include +#include +#include #include #include #include -#include "output.hxx" - using std::string; // update index file (list of objects to be included in final scenery build) -void write_index( const string& base, const SGBucket& b, const string& name ) +void write_index_object( const string& base, const SGBucket& b, const string& name ) { string dir = base + "/" + b.gen_base_path(); SGPath sgp( dir ); @@ -57,9 +58,8 @@ void write_index( const string& base, const SGBucket& b, const string& name ) } -// update index file (list of shared objects to be included in final -// scenery build) -void write_index_shared( const string &base, const SGBucket &b, +// update index file (list of shared objects to be included in final scenery build) +void write_index_object_shared( const string &base, const SGBucket &b, const SGGeod &p, const string& name, const double &heading ) { @@ -82,7 +82,9 @@ void write_index_shared( const string &base, const SGBucket &b, fclose( fp ); } -void write_object_sign( const string &base, const SGBucket &b, + +// update index file (list of shared objects to be included in final scenery build) +void write_index_object_sign( const string &base, const SGBucket &b, const SGGeod &p, const string& sign, const double &heading, const int &size) { @@ -104,3 +106,17 @@ void write_object_sign( const string &base, const SGBucket &b, p.getLongitudeDeg(), p.getLatitudeDeg(), p.getElevationM(), heading, size ); fclose( fp ); } + + +// purge the existing index file when it already exists +void truncate_index_file( const std::string& fileName ) +{ + if (static_cast(std::ifstream(fileName))) + { + SG_LOG( SG_GENERAL, SG_DEBUG, "Truncating file " << fileName ); + + std::ofstream fsIndex; + fsIndex.open(fileName, std::ofstream::out | std::ofstream::trunc); + fsIndex.close(); + } +} diff --git a/src/Airports/GenAirports850/output.hxx b/src/Airports/GenAirports850/output.hxx index 23bee3d5..d4f57d83 100644 --- a/src/Airports/GenAirports850/output.hxx +++ b/src/Airports/GenAirports850/output.hxx @@ -27,21 +27,23 @@ #include #endif -#include - // update index file (list of objects to be included in final scenery build) -void write_index( const std::string& base, const SGBucket& b, const std::string& name ); +void write_index_object( const std::string& base, const SGBucket& b, const std::string& name ); -// update index file (list of shared objects to be included in final -// scenery build) -void write_index_shared( const std::string &base, const SGBucket &b, +// update index file (list of shared objects to be included in final scenery build) +void write_index_object_shared( const std::string &base, const SGBucket &b, const SGGeod &p, const std::string& name, const double &heading ); -// update index file (list of shared objects to be included in final -// scenery build) -void write_object_sign( const std::string &base, const SGBucket &b, +// update index file (list of shared objects to be included in final scenery build) +void write_index_object_sign( const std::string &base, const SGBucket &b, const SGGeod &p, const std::string& sign, const double &heading, const int &size ); +// purge the existing index file when it already exists +void truncate_index_file( const std::string& fileName ); + +// record index files that have been cleaned +std::set cleanIndexFiles; + #endif