From ff408dc540b0944061b0b88bdad93b5de17dbab9 Mon Sep 17 00:00:00 2001 From: Torsten Dreyer Date: Sat, 24 Jul 2010 17:17:33 +0200 Subject: [PATCH] (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. --- src/Autopilot/autopilot.cxx | 11 ++++++++--- src/Autopilot/autopilotgroup.cxx | 12 ++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/Autopilot/autopilot.cxx b/src/Autopilot/autopilot.cxx index d37c38d7d..809001d61 100644 --- a/src/Autopilot/autopilot.cxx +++ b/src/Autopilot/autopilot.cxx @@ -93,11 +93,16 @@ void Autopilot::add_component( Component * component ) { if( component == NULL ) return; + // check for duplicate name std::string name = component->get_name(); - if( get_subsystem( name.c_str() ) != NULL ) { - SG_LOG( SG_ALL, SG_ALERT, "Duplicate autopilot component " << name << " ignored" ); - return; + for( unsigned i = 0; get_subsystem( name.c_str() ) != NULL; i++ ) { + ostringstream buf; + 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 ); } diff --git a/src/Autopilot/autopilotgroup.cxx b/src/Autopilot/autopilotgroup.cxx index be1572a7a..81b4d8101 100644 --- a/src/Autopilot/autopilotgroup.cxx +++ b/src/Autopilot/autopilotgroup.cxx @@ -177,6 +177,18 @@ void FGXMLAutopilotGroup::init() 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 ) { SG_LOG( SG_ALL, SG_ALERT, "Duplicate autopilot configuration name " << apName << " ignored" ); continue;