From da58e9ee4c86d3bb36a23ea67ceb46e6f9714ef4 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Thu, 11 Nov 2021 16:42:25 +0000 Subject: [PATCH] Don't rely on selection when updating edited symbol in schematic. Fixes https://gitlab.com/kicad/code/kicad/issues/9600 --- eeschema/sch_edit_frame.cpp | 33 +++++--------------- eeschema/sch_edit_frame.h | 7 +++-- eeschema/symbol_editor/symbol_edit_frame.cpp | 3 +- eeschema/symbol_editor/symbol_edit_frame.h | 1 + eeschema/symbol_editor/symbol_editor.cpp | 2 +- 5 files changed, 16 insertions(+), 30 deletions(-) diff --git a/eeschema/sch_edit_frame.cpp b/eeschema/sch_edit_frame.cpp index e5d5518ab9..2a4feebf66 100644 --- a/eeschema/sch_edit_frame.cpp +++ b/eeschema/sch_edit_frame.cpp @@ -1633,29 +1633,16 @@ void SCH_EDIT_FRAME::onSize( wxSizeEvent& aEvent ) } -void SCH_EDIT_FRAME::SaveSymbolToSchematic( const LIB_SYMBOL& aSymbol ) +void SCH_EDIT_FRAME::SaveSymbolToSchematic( const LIB_SYMBOL& aSymbol, + const KIID& aSchematicSymbolUUID ) { wxString msg; bool appendToUndo = false; - wxCHECK( m_toolManager, /* void */ ); + SCH_SHEET_PATH sheetPath; + SCH_ITEM* item = Schematic().GetSheets().GetItem( aSchematicSymbolUUID, &sheetPath ); - EE_SELECTION_TOOL* selectionTool = m_toolManager->GetTool(); - - wxCHECK( selectionTool, /* void */ ); - - EE_SELECTION& selection = selectionTool->RequestSelection( EE_COLLECTOR::SymbolsOnly ); - - if( selection.Empty() ) - return; - - SCH_SCREEN* currentScreen = GetScreen(); - - wxCHECK( currentScreen, /* void */ ); - - // This should work for multiple selections of the same symbol even though the editor - // only works for a single symbol selection. - for( EDA_ITEM* item : selection ) + if( item ) { SCH_SYMBOL* symbol = dynamic_cast( item ); @@ -1663,11 +1650,11 @@ void SCH_EDIT_FRAME::SaveSymbolToSchematic( const LIB_SYMBOL& aSymbol ) // This needs to be done before the LIB_SYMBOL is changed to prevent stale library // symbols in the schematic file. - currentScreen->Remove( symbol ); + sheetPath.LastScreen()->Remove( symbol ); if( !symbol->IsNew() ) { - SaveCopyInUndoList( currentScreen, symbol, UNDO_REDO::CHANGED, appendToUndo ); + SaveCopyInUndoList( sheetPath.LastScreen(), symbol, UNDO_REDO::CHANGED, appendToUndo ); appendToUndo = true; } @@ -1679,14 +1666,10 @@ void SCH_EDIT_FRAME::SaveSymbolToSchematic( const LIB_SYMBOL& aSymbol ) false, /* reset ref */ false /* reset other fields */ ); - currentScreen->Append( symbol ); - selectionTool->SelectHighlightItem( symbol ); + sheetPath.LastScreen()->Append( symbol ); GetCanvas()->GetView()->Update( symbol ); } - if( selection.IsHover() ) - m_toolManager->RunAction( EE_ACTIONS::clearSelection, true ); - GetCanvas()->Refresh(); OnModify(); } diff --git a/eeschema/sch_edit_frame.h b/eeschema/sch_edit_frame.h index f7a90bcb69..44965424d3 100644 --- a/eeschema/sch_edit_frame.h +++ b/eeschema/sch_edit_frame.h @@ -807,13 +807,14 @@ public: void FocusOnItem( SCH_ITEM* aItem ); /** - * Update the #LIB_SYMBOL of the currently selected symbol. + * Update a schematic symbol from a LIB_SYMBOL. * * This is typically called from the symbol editor when editing symbols in place. * - * @param aSymbol is the #LIB_SYMBOL to update. + * @param aSymbol is the new symbol data. + * @param aSchematicSymbolUUID refers to the schematic symbol to update. */ - void SaveSymbolToSchematic( const LIB_SYMBOL& aSymbol ); + void SaveSymbolToSchematic( const LIB_SYMBOL& aSymbol, const KIID& aSchematicSymbolUUID ); /** * Update the schematic's page reference map for all global labels, and refresh the labels diff --git a/eeschema/symbol_editor/symbol_edit_frame.cpp b/eeschema/symbol_editor/symbol_edit_frame.cpp index d5a981b238..fd693c5de6 100644 --- a/eeschema/symbol_editor/symbol_edit_frame.cpp +++ b/eeschema/symbol_editor/symbol_edit_frame.cpp @@ -519,7 +519,7 @@ bool SYMBOL_EDIT_FRAME::canCloseWindow( wxCloseEvent& aEvent ) { case wxID_YES: if( schframe && GetCurSymbol() ) // Should be always the case - schframe->SaveSymbolToSchematic( *GetCurSymbol()); + schframe->SaveSymbolToSchematic( *GetCurSymbol(), m_schematicSymbolUUID ); return true; @@ -1310,6 +1310,7 @@ void SYMBOL_EDIT_FRAME::LoadSymbolFromSchematic( SCH_SYMBOL* aSymbol ) SetCurSymbol( nullptr, false ); m_isSymbolFromSchematic = true; + m_schematicSymbolUUID = aSymbol->m_Uuid; m_reference = symbol->GetFieldById( REFERENCE_FIELD )->GetText(); m_unit = std::max( 1, aSymbol->GetUnit() ); m_convert = std::max( 1, aSymbol->GetConvert() ); diff --git a/eeschema/symbol_editor/symbol_edit_frame.h b/eeschema/symbol_editor/symbol_edit_frame.h index ffbd9a55ad..f2e4d19292 100644 --- a/eeschema/symbol_editor/symbol_edit_frame.h +++ b/eeschema/symbol_editor/symbol_edit_frame.h @@ -547,6 +547,7 @@ private: ///< Flag if the symbol being edited was loaded directly from a schematic. bool m_isSymbolFromSchematic; + KIID m_schematicSymbolUUID; ///< RefDes of the symbol (only valid if symbol was loaded from schematic) wxString m_reference; diff --git a/eeschema/symbol_editor/symbol_editor.cpp b/eeschema/symbol_editor/symbol_editor.cpp index 5d3b66c951..45149ace0a 100644 --- a/eeschema/symbol_editor/symbol_editor.cpp +++ b/eeschema/symbol_editor/symbol_editor.cpp @@ -555,7 +555,7 @@ void SYMBOL_EDIT_FRAME::Save() } else { - schframe->SaveSymbolToSchematic( *m_symbol ); + schframe->SaveSymbolToSchematic( *m_symbol, m_schematicSymbolUUID ); GetScreen()->SetContentModified( false ); } }