]> git.mxchange.org Git - flightgear.git/commitdiff
(Re)allow duplicate names for A/P stages
authorTorsten Dreyer <Torsten@t3r.de>
Sat, 24 Jul 2010 15:17:33 +0000 (17:17 +0200)
committerTorsten Dreyer <Torsten@t3r.de>
Sat, 24 Jul 2010 15:17:33 +0000 (17:17 +0200)
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
src/Autopilot/autopilotgroup.cxx

index d37c38d7db00b1f9b060a566429c37f26c4478b9..809001d617bd4e32fa014cc1887cc93b4c74e826 100644 (file)
@@ -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 );
 }
 
index be1572a7afd3f2d1fc5d669c70a1a3fd4dd3fd14..81b4d81018e86bdc81b081bc5b2b2dabb0e3ccfc 100644 (file)
@@ -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;