Be more clever about making sheet names unique.
Fixes https://gitlab.com/kicad/code/kicad/issues/6123
This commit is contained in:
parent
cce11e40a1
commit
c5a86126d2
|
@ -863,8 +863,16 @@ int SCH_EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent )
|
||||||
SCH_SHEET* sheet = (SCH_SHEET*) newItem;
|
SCH_SHEET* sheet = (SCH_SHEET*) newItem;
|
||||||
SCH_FIELD& nameField = sheet->GetFields()[SHEETNAME];
|
SCH_FIELD& nameField = sheet->GetFields()[SHEETNAME];
|
||||||
wxString baseName = nameField.GetText();
|
wxString baseName = nameField.GetText();
|
||||||
wxString candidateName = baseName;
|
wxString number;
|
||||||
int uniquifier = 1;
|
|
||||||
|
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 ) )
|
while( hierarchy.NameExists( candidateName ) )
|
||||||
candidateName = wxString::Format( wxT( "%s%d" ), baseName, uniquifier++ );
|
candidateName = wxString::Format( wxT( "%s%d" ), baseName, uniquifier++ );
|
||||||
|
|
|
@ -1483,7 +1483,15 @@ int SCH_EDITOR_CONTROL::Paste( const TOOL_EVENT& aEvent )
|
||||||
SCH_SCREEN* existingScreen = nullptr;
|
SCH_SCREEN* existingScreen = nullptr;
|
||||||
wxString baseName = nameField.GetText();
|
wxString baseName = nameField.GetText();
|
||||||
wxString candidateName = baseName;
|
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 ) )
|
while( hierarchy.NameExists( candidateName ) )
|
||||||
candidateName = wxString::Format( wxT( "%s%d" ), baseName, uniquifier++ );
|
candidateName = wxString::Format( wxT( "%s%d" ), baseName, uniquifier++ );
|
||||||
|
|
Loading…
Reference in New Issue