From 3744cfd9877c60549456d4adf0a72b84719b046e Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Mon, 15 Jan 2024 13:56:20 -0500 Subject: [PATCH] Fix assertion when pasting schematic sheets. Pasted sheets do not have assigned SCH_SCREEN objects until after they are loaded. Fixes https://gitlab.com/kicad/code/kicad/-/issues/16579 --- eeschema/tools/sch_editor_control.cpp | 62 +++++++-------------------- eeschema/tools/sch_editor_control.h | 6 +-- 2 files changed, 16 insertions(+), 52 deletions(-) diff --git a/eeschema/tools/sch_editor_control.cpp b/eeschema/tools/sch_editor_control.cpp index 303f13c469..d629d3c484 100644 --- a/eeschema/tools/sch_editor_control.cpp +++ b/eeschema/tools/sch_editor_control.cpp @@ -1511,56 +1511,25 @@ SCH_SHEET_PATH SCH_EDITOR_CONTROL::updatePastedSheet( const SCH_SHEET_PATH& aPas } -void SCH_EDITOR_CONTROL::setPastedSheetInstances( const SCH_SHEET* aPastedSheet ) +void SCH_EDITOR_CONTROL::setPastedSymbolInstances( const SCH_SCREEN* aScreen ) { - wxCHECK( aPastedSheet, /* void */ ); + wxCHECK( aScreen, /* void */ ); - for( const SCH_SHEET_INSTANCE& sheetInstance : aPastedSheet->GetInstances() ) + for( SCH_ITEM* item : aScreen->Items() ) { - KIID_PATH pathWithSheet = sheetInstance.m_Path; - - pathWithSheet.push_back( aPastedSheet->m_Uuid ); - m_clipboardSheetInstances[pathWithSheet] = sheetInstance; - } - - const SCH_SCREEN* screen = aPastedSheet->GetScreen(); - - wxCHECK( screen, /* void */ ); - - for( SCH_ITEM* item : screen->Items() ) - { - if( item->Type() == SCH_SHEET_T ) + if( item->Type() == SCH_SYMBOL_T ) { - const SCH_SHEET* sheet = static_cast( item ); + SCH_SYMBOL* symbol = static_cast( item ); - wxCHECK2( sheet, continue ); + wxCHECK2( symbol, continue ); - setPastedSheetInstances( sheet ); - } - } -} - - -void SCH_EDITOR_CONTROL::setPastedSymbolInstances( SCH_SCREENS& aScreenList ) -{ - for( SCH_SCREEN* screen = aScreenList.GetFirst(); screen; screen = aScreenList.GetNext() ) - { - for( SCH_ITEM* item : screen->Items() ) - { - if( item->Type() == SCH_SYMBOL_T ) + for( const SCH_SYMBOL_INSTANCE& symbolInstance : symbol->GetInstanceReferences() ) { - SCH_SYMBOL* symbol = static_cast( item ); + KIID_PATH pathWithSymbol = symbolInstance.m_Path; - wxCHECK2( symbol, continue ); + pathWithSymbol.push_back( symbol->m_Uuid ); - for( const SCH_SYMBOL_INSTANCE& symbolInstance : symbol->GetInstanceReferences() ) - { - KIID_PATH pathWithSymbol = symbolInstance.m_Path; - - pathWithSymbol.push_back( symbol->m_Uuid ); - - m_clipboardSymbolInstances[pathWithSymbol] = symbolInstance; - } + m_clipboardSymbolInstances[pathWithSymbol] = symbolInstance; } } } @@ -1639,15 +1608,11 @@ int SCH_EDITOR_CONTROL::Paste( const TOOL_EVENT& aEvent ) tempScreen->Append( text_item ); } - SCH_SCREENS tempScreens( tempSheet ); - m_pastedSymbols.clear(); - m_clipboardSheetInstances.clear(); m_clipboardSymbolInstances.clear(); - // Save pasted sheet and symbol instances. - setPastedSheetInstances( &tempSheet ); - setPastedSymbolInstances( tempScreens ); + // Save pasted symbol instances. + setPastedSymbolInstances( tempScreen ); tempScreen->MigrateSimModels(); @@ -1850,6 +1815,9 @@ int SCH_EDITOR_CONTROL::Paste( const TOOL_EVENT& aEvent ) m_frame->InitSheet( sheet, sheet->GetFileName() ); } + // Save the symbol instances in case the user chooses to keep the existing + // symbol annotation. + setPastedSymbolInstances( sheet->GetScreen() ); sheetsPasted = true; // Push it to the clipboard path while it still has its old KIID diff --git a/eeschema/tools/sch_editor_control.h b/eeschema/tools/sch_editor_control.h index 2797353a9f..e9b13b295b 100644 --- a/eeschema/tools/sch_editor_control.h +++ b/eeschema/tools/sch_editor_control.h @@ -184,8 +184,7 @@ private: SCH_SHEET_LIST* aPastedSheetsSoFar, SCH_REFERENCE_LIST* aPastedSymbolsSoFar ); - void setPastedSheetInstances( const SCH_SHEET* aPastedSheet ); - void setPastedSymbolInstances( SCH_SCREENS& aScreenList ); + void setPastedSymbolInstances( const SCH_SCREEN* aScreen ); /** * Remove all pasted symbol instances that do not belong to the current project. @@ -239,9 +238,6 @@ private: // A map of KIID_PATH --> symbol instances for the clipboard contents. std::map m_clipboardSymbolInstances; - // A map of KIID_PATH --> sheet instances for the clipboard contents. - std::map m_clipboardSheetInstances; - std::set m_pastedSymbols; };