(Re)allow duplicate names for A/P stages
Don't ignore autpilot stages with duplicate names but rename the dups to a unique name by adding '_' plus a sequence number.
This commit is contained in:
parent
aa16a1e12a
commit
ff408dc540
2 changed files with 20 additions and 3 deletions
|
@ -93,11 +93,16 @@ void Autopilot::add_component( Component * component )
|
||||||
{
|
{
|
||||||
if( component == NULL ) return;
|
if( component == NULL ) return;
|
||||||
|
|
||||||
|
// check for duplicate name
|
||||||
std::string name = component->get_name();
|
std::string name = component->get_name();
|
||||||
if( get_subsystem( name.c_str() ) != NULL ) {
|
for( unsigned i = 0; get_subsystem( name.c_str() ) != NULL; i++ ) {
|
||||||
SG_LOG( SG_ALL, SG_ALERT, "Duplicate autopilot component " << name << " ignored" );
|
ostringstream buf;
|
||||||
return;
|
buf << name << "_" << i;
|
||||||
|
name = buf.str();
|
||||||
}
|
}
|
||||||
|
if( name != component->get_name() )
|
||||||
|
SG_LOG( SG_ALL, SG_ALERT, "Duplicate autopilot component " << component->get_name() << ", renamed to " << name );
|
||||||
|
|
||||||
set_subsystem( name.c_str(), component );
|
set_subsystem( name.c_str(), component );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -177,6 +177,18 @@ void FGXMLAutopilotGroup::init()
|
||||||
apName = buf.str();
|
apName = buf.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
// check for duplicate names
|
||||||
|
string name = apName;
|
||||||
|
for( unsigned i = 0; get_subsystem( apName.c_str() ) != NULL; i++ ) {
|
||||||
|
ostringstream buf;
|
||||||
|
buf << apName << "_" << i;
|
||||||
|
apName = buf.str();
|
||||||
|
}
|
||||||
|
if( apName != name )
|
||||||
|
SG_LOG( SG_ALL, SG_ALERT, "Duplicate autopilot component " << name << ", renamed to " << apName );
|
||||||
|
}
|
||||||
|
|
||||||
if( get_subsystem( apName.c_str() ) != NULL ) {
|
if( get_subsystem( apName.c_str() ) != NULL ) {
|
||||||
SG_LOG( SG_ALL, SG_ALERT, "Duplicate autopilot configuration name " << apName << " ignored" );
|
SG_LOG( SG_ALL, SG_ALERT, "Duplicate autopilot configuration name " << apName << " ignored" );
|
||||||
continue;
|
continue;
|
||||||
|
|
Loading…
Add table
Reference in a new issue