Update symbol instances after sheet rename.

Fixes https://gitlab.com/kicad/code/kicad/issues/11782
This commit is contained in:
Jeff Young 2022-06-12 15:46:11 +01:00
parent bccc2f5792
commit 69c1f88e53
1 changed files with 12 additions and 8 deletions

View File

@ -431,10 +431,13 @@ bool DIALOG_SHEET_PROPERTIES::onSheetFilenameChanged( const wxString& aNewFilena
return false; return false;
} }
SCH_SHEET_LIST fullHierarchy = m_frame->Schematic().GetFullHierarchy(); SCHEMATIC& schematic = m_frame->Schematic();
std::vector<SCH_SHEET_INSTANCE> sheetInstances = fullHierarchy.GetSheetInstances(); SCH_SCREEN* rootScreen = schematic.RootScreen();
wxFileName screenFileName( sheetFileName ); SCH_SHEET_LIST fullHierarchy = schematic.GetFullHierarchy();
wxFileName tmp( sheetFileName ); std::vector<SCH_SHEET_INSTANCE> sheetInstances = fullHierarchy.GetSheetInstances();
std::vector<SYMBOL_INSTANCE_REFERENCE> symbolInstances = rootScreen->GetSymbolInstances();
wxFileName screenFileName( sheetFileName );
wxFileName tmp( sheetFileName );
SCH_SCREEN* currentScreen = m_frame->GetCurrentSheet().LastScreen(); SCH_SCREEN* currentScreen = m_frame->GetCurrentSheet().LastScreen();
@ -469,7 +472,7 @@ bool DIALOG_SHEET_PROPERTIES::onSheetFilenameChanged( const wxString& aNewFilena
// Search for a schematic file having the same filename already in use in the hierarchy // Search for a schematic file having the same filename already in use in the hierarchy
// or on disk, in order to reuse it. // or on disk, in order to reuse it.
if( !m_frame->Schematic().Root().SearchHierarchy( newAbsoluteFilename, &useScreen ) ) if( !schematic.Root().SearchHierarchy( newAbsoluteFilename, &useScreen ) )
{ {
loadFromFile = wxFileExists( newAbsoluteFilename ); loadFromFile = wxFileExists( newAbsoluteFilename );
@ -581,7 +584,7 @@ bool DIALOG_SHEET_PROPERTIES::onSheetFilenameChanged( const wxString& aNewFilena
try try
{ {
pi->Save( newAbsoluteFilename, m_sheet, &m_frame->Schematic() ); pi->Save( newAbsoluteFilename, m_sheet, &schematic );
} }
catch( const IO_ERROR& ioe ) catch( const IO_ERROR& ioe )
{ {
@ -612,7 +615,7 @@ bool DIALOG_SHEET_PROPERTIES::onSheetFilenameChanged( const wxString& aNewFilena
if( useScreen ) if( useScreen )
{ {
// Create a temporary sheet for recursion testing to prevent a possible recursion error. // Create a temporary sheet for recursion testing to prevent a possible recursion error.
std::unique_ptr< SCH_SHEET> tmpSheet = std::make_unique<SCH_SHEET>( &m_frame->Schematic() ); std::unique_ptr< SCH_SHEET> tmpSheet = std::make_unique<SCH_SHEET>( &schematic );
tmpSheet->GetFields()[SHEETNAME] = m_fields->at( SHEETNAME ); tmpSheet->GetFields()[SHEETNAME] = m_fields->at( SHEETNAME );
tmpSheet->GetFields()[SHEETFILENAME].SetText( sheetFileName.GetFullPath() ); tmpSheet->GetFields()[SHEETFILENAME].SetText( sheetFileName.GetFullPath() );
tmpSheet->SetScreen( useScreen ); tmpSheet->SetScreen( useScreen );
@ -656,8 +659,9 @@ bool DIALOG_SHEET_PROPERTIES::onSheetFilenameChanged( const wxString& aNewFilena
currentSheet.LastScreen()->Append( m_sheet ); currentSheet.LastScreen()->Append( m_sheet );
// The full hierarchy needs to be reloaded because due to the addition of a new sheet. // The full hierarchy needs to be reloaded because due to the addition of a new sheet.
fullHierarchy = m_frame->Schematic().GetFullHierarchy(); fullHierarchy = schematic.GetFullHierarchy();
fullHierarchy.UpdateSheetInstances( sheetInstances ); fullHierarchy.UpdateSheetInstances( sheetInstances );
fullHierarchy.UpdateSymbolInstances( symbolInstances );
} }
if( m_clearAnnotationNewItems ) if( m_clearAnnotationNewItems )