1
0
Fork 0

GenApts850: Bug fix

#800 Genapts outputs duplicated data
This commit is contained in:
Scott Giese 2018-09-23 00:52:51 -05:00
parent d4d9b9ef0d
commit 5e84fda144
3 changed files with 60 additions and 35 deletions

View file

@ -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 );
}
}

View file

@ -24,19 +24,20 @@
#include <config.h>
#endif
#include <stdio.h>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <set>
#include <string>
#include <simgear/debug/logstream.hxx>
#include <simgear/bucket/newbucket.hxx>
#include <simgear/misc/sg_path.hxx>
#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<bool>(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();
}
}

View file

@ -27,21 +27,23 @@
#include <config.h>
#endif
#include <string>
// 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<std::string> cleanIndexFiles;
#endif