Update Page Number when Duplicating or Pasting sheets
Fixes https://gitlab.com/kicad/code/kicad/-/issues/7872 Also, update hierarchy before renaming pasted sheets Avoids duplicate sheet names when pasting multiple sheets
This commit is contained in:
parent
381cc27548
commit
be51be22a7
|
@ -482,8 +482,8 @@ void SCH_SHEET_LIST::BuildSheetList( SCH_SHEET* aSheet, bool aCheckIntegrity )
|
|||
|
||||
void SCH_SHEET_LIST::SortByPageNumbers( bool aUpdateVirtualPageNums )
|
||||
{
|
||||
std::sort( begin(), end(),
|
||||
[]( SCH_SHEET_PATH a, SCH_SHEET_PATH b ) -> bool
|
||||
std::sort( begin(), end(),
|
||||
[]( SCH_SHEET_PATH a, SCH_SHEET_PATH b ) -> bool
|
||||
{
|
||||
wxString pageA = a.GetPageNumber();
|
||||
wxString pageB = b.GetPageNumber();
|
||||
|
@ -515,6 +515,18 @@ bool SCH_SHEET_LIST::NameExists( const wxString& aSheetName ) const
|
|||
}
|
||||
|
||||
|
||||
bool SCH_SHEET_LIST::PageNumberExists( const wxString& aPageNumber ) const
|
||||
{
|
||||
for( const SCH_SHEET_PATH& sheet : *this )
|
||||
{
|
||||
if( sheet.Last()->GetPageNumber( sheet ) == aPageNumber )
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool SCH_SHEET_LIST::IsModified() const
|
||||
{
|
||||
for( const SCH_SHEET_PATH& sheet : *this )
|
||||
|
|
|
@ -457,6 +457,8 @@ public:
|
|||
|
||||
bool NameExists( const wxString& aSheetName ) const;
|
||||
|
||||
bool PageNumberExists( const wxString& aPageNumber ) const;
|
||||
|
||||
/**
|
||||
* Update all of the symbol instance information using \a aSymbolInstances.
|
||||
* WARNING: Do not call this on anything other than the full hierarchy.
|
||||
|
|
|
@ -861,6 +861,17 @@ int SCH_EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent )
|
|||
nameField.SetText( candidateName );
|
||||
|
||||
sheet->SetParent( m_frame->GetCurrentSheet().Last() );
|
||||
|
||||
SCH_SHEET_PATH sheetpath = m_frame->GetCurrentSheet();
|
||||
sheetpath.push_back( sheet );
|
||||
int page = 1;
|
||||
wxString pageNum = wxString::Format( "%d", page );
|
||||
|
||||
while( hierarchy.PageNumberExists( pageNum ) )
|
||||
pageNum = wxString::Format( "%d", ++page );
|
||||
|
||||
sheet->AddInstance( sheetpath.Path() );
|
||||
sheet->SetPageNumber( sheetpath, pageNum );
|
||||
m_frame->AddToScreen( sheet, m_frame->GetScreen() );
|
||||
|
||||
copiedSheets = true;
|
||||
|
|
|
@ -1485,6 +1485,10 @@ int SCH_EDITOR_CONTROL::Paste( const TOOL_EVENT& aEvent )
|
|||
|
||||
int uniquifier = std::max( 0, wxAtoi( number ) ) + 1;
|
||||
|
||||
// Ensure we have latest hierarchy, as we may have added a sheet in the previous
|
||||
// iteration
|
||||
hierarchy = m_frame->Schematic().GetSheets();
|
||||
|
||||
while( hierarchy.NameExists( candidateName ) )
|
||||
candidateName = wxString::Format( wxT( "%s%d" ), baseName, uniquifier++ );
|
||||
|
||||
|
@ -1531,7 +1535,14 @@ int SCH_EDITOR_CONTROL::Paste( const TOOL_EVENT& aEvent )
|
|||
SCH_SHEET_PATH pastePath = pasteRoot;
|
||||
pastePath.push_back( sheet );
|
||||
|
||||
int page = 1;
|
||||
wxString pageNum = wxString::Format( "%d", page );
|
||||
|
||||
while( hierarchy.PageNumberExists( pageNum ) )
|
||||
pageNum = wxString::Format( "%d", ++page );
|
||||
|
||||
sheet->AddInstance( pastePath.Path() );
|
||||
sheet->SetPageNumber( pastePath, pageNum );
|
||||
updatePastedInstances( pastePath, clipPath, sheet, forceKeepAnnotations );
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue