Be more clever about making sheet names unique.

Fixes https://gitlab.com/kicad/code/kicad/issues/6123
This commit is contained in:
Jeff Young 2020-10-23 17:48:07 +01:00
parent cce11e40a1
commit c5a86126d2
2 changed files with 19 additions and 3 deletions

View File

@ -863,8 +863,16 @@ int SCH_EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent )
SCH_SHEET* sheet = (SCH_SHEET*) newItem;
SCH_FIELD& nameField = sheet->GetFields()[SHEETNAME];
wxString baseName = nameField.GetText();
wxString candidateName = baseName;
int uniquifier = 1;
wxString number;
while( !baseName.IsEmpty() && wxIsdigit( baseName.Last() ) )
{
number = baseName.Last() + number;
baseName.RemoveLast();
}
int uniquifier = std::max( 0, wxAtoi( number ) ) + 1;
wxString candidateName = wxString::Format( wxT( "%s%d" ), baseName, uniquifier++ );
while( hierarchy.NameExists( candidateName ) )
candidateName = wxString::Format( wxT( "%s%d" ), baseName, uniquifier++ );

View File

@ -1483,7 +1483,15 @@ int SCH_EDITOR_CONTROL::Paste( const TOOL_EVENT& aEvent )
SCH_SCREEN* existingScreen = nullptr;
wxString baseName = nameField.GetText();
wxString candidateName = baseName;
int uniquifier = 1;
wxString number;
while( !baseName.IsEmpty() && wxIsdigit( baseName.Last() ) )
{
number = baseName.Last() + number;
baseName.RemoveLast();
}
int uniquifier = std::max( 0, wxAtoi( number ) ) + 1;
while( hierarchy.NameExists( candidateName ) )
candidateName = wxString::Format( wxT( "%s%d" ), baseName, uniquifier++ );