Don't rely on selection when updating edited symbol in schematic.

Fixes https://gitlab.com/kicad/code/kicad/issues/9600
This commit is contained in:
Jeff Young 2021-11-11 16:42:25 +00:00
parent 23e0751b2e
commit da58e9ee4c
5 changed files with 16 additions and 30 deletions

View File

@ -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; wxString msg;
bool appendToUndo = false; 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<EE_SELECTION_TOOL>(); if( item )
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 )
{ {
SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( item ); SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( 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 // This needs to be done before the LIB_SYMBOL is changed to prevent stale library
// symbols in the schematic file. // symbols in the schematic file.
currentScreen->Remove( symbol ); sheetPath.LastScreen()->Remove( symbol );
if( !symbol->IsNew() ) if( !symbol->IsNew() )
{ {
SaveCopyInUndoList( currentScreen, symbol, UNDO_REDO::CHANGED, appendToUndo ); SaveCopyInUndoList( sheetPath.LastScreen(), symbol, UNDO_REDO::CHANGED, appendToUndo );
appendToUndo = true; appendToUndo = true;
} }
@ -1679,14 +1666,10 @@ void SCH_EDIT_FRAME::SaveSymbolToSchematic( const LIB_SYMBOL& aSymbol )
false, /* reset ref */ false, /* reset ref */
false /* reset other fields */ ); false /* reset other fields */ );
currentScreen->Append( symbol ); sheetPath.LastScreen()->Append( symbol );
selectionTool->SelectHighlightItem( symbol );
GetCanvas()->GetView()->Update( symbol ); GetCanvas()->GetView()->Update( symbol );
} }
if( selection.IsHover() )
m_toolManager->RunAction( EE_ACTIONS::clearSelection, true );
GetCanvas()->Refresh(); GetCanvas()->Refresh();
OnModify(); OnModify();
} }

View File

@ -807,13 +807,14 @@ public:
void FocusOnItem( SCH_ITEM* aItem ); 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. * 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 * Update the schematic's page reference map for all global labels, and refresh the labels

View File

@ -519,7 +519,7 @@ bool SYMBOL_EDIT_FRAME::canCloseWindow( wxCloseEvent& aEvent )
{ {
case wxID_YES: case wxID_YES:
if( schframe && GetCurSymbol() ) // Should be always the case if( schframe && GetCurSymbol() ) // Should be always the case
schframe->SaveSymbolToSchematic( *GetCurSymbol()); schframe->SaveSymbolToSchematic( *GetCurSymbol(), m_schematicSymbolUUID );
return true; return true;
@ -1310,6 +1310,7 @@ void SYMBOL_EDIT_FRAME::LoadSymbolFromSchematic( SCH_SYMBOL* aSymbol )
SetCurSymbol( nullptr, false ); SetCurSymbol( nullptr, false );
m_isSymbolFromSchematic = true; m_isSymbolFromSchematic = true;
m_schematicSymbolUUID = aSymbol->m_Uuid;
m_reference = symbol->GetFieldById( REFERENCE_FIELD )->GetText(); m_reference = symbol->GetFieldById( REFERENCE_FIELD )->GetText();
m_unit = std::max( 1, aSymbol->GetUnit() ); m_unit = std::max( 1, aSymbol->GetUnit() );
m_convert = std::max( 1, aSymbol->GetConvert() ); m_convert = std::max( 1, aSymbol->GetConvert() );

View File

@ -547,6 +547,7 @@ private:
///< Flag if the symbol being edited was loaded directly from a schematic. ///< Flag if the symbol being edited was loaded directly from a schematic.
bool m_isSymbolFromSchematic; bool m_isSymbolFromSchematic;
KIID m_schematicSymbolUUID;
///< RefDes of the symbol (only valid if symbol was loaded from schematic) ///< RefDes of the symbol (only valid if symbol was loaded from schematic)
wxString m_reference; wxString m_reference;

View File

@ -555,7 +555,7 @@ void SYMBOL_EDIT_FRAME::Save()
} }
else else
{ {
schframe->SaveSymbolToSchematic( *m_symbol ); schframe->SaveSymbolToSchematic( *m_symbol, m_schematicSymbolUUID );
GetScreen()->SetContentModified( false ); GetScreen()->SetContentModified( false );
} }
} }