Fix crash: Under some circumstances the command "Export symbols to (new) library"

produces a crash when the library links are updated, and a power symbol is not found
in any loaded library.
Add also an option to export all symbols or all not pwer symbols
From master branch
Fixes #16229
https://gitlab.com/kicad/code/kicad/-/issues/
This commit is contained in:
jean-pierre charras 2023-12-04 18:12:51 +01:00
parent c5cdff6213
commit 5ae1b271e7
2 changed files with 6 additions and 3 deletions

View File

@ -1030,6 +1030,7 @@ void SCH_SCREEN::UpdateSymbolLinks( REPORTER* aReporter )
} }
} }
if( libSymbol.get() ) // Only change the old link if the new link exists
symbol->SetLibSymbol( libSymbol.release() ); symbol->SetLibSymbol( libSymbol.release() );
} }

View File

@ -332,10 +332,12 @@ void SCH_EDITOR_CONTROL::doCrossProbeSchToPcb( const TOOL_EVENT& aEvent, bool aF
int SCH_EDITOR_CONTROL::ExportSymbolsToLibrary( const TOOL_EVENT& aEvent ) int SCH_EDITOR_CONTROL::ExportSymbolsToLibrary( const TOOL_EVENT& aEvent )
{ {
bool savePowerSymbols = IsOK( m_frame, _( "Include power symbols in schematic to the library?" ) );
bool createNew = aEvent.IsAction( &EE_ACTIONS::exportSymbolsToNewLibrary ); bool createNew = aEvent.IsAction( &EE_ACTIONS::exportSymbolsToNewLibrary );
SCH_REFERENCE_LIST symbols; SCH_REFERENCE_LIST symbols;
m_frame->Schematic().GetSheets().GetSymbols( symbols, false ); m_frame->Schematic().GetSheets().GetSymbols( symbols, savePowerSymbols );
std::map<LIB_ID, LIB_SYMBOL*> libSymbols; std::map<LIB_ID, LIB_SYMBOL*> libSymbols;
std::map<LIB_ID, std::vector<SCH_SYMBOL*>> symbolMap; std::map<LIB_ID, std::vector<SCH_SYMBOL*>> symbolMap;
@ -430,7 +432,6 @@ int SCH_EDITOR_CONTROL::ExportSymbolsToLibrary( const TOOL_EVENT& aEvent )
LIB_ID id = it.first; LIB_ID id = it.first;
id.SetLibNickname( targetLib ); id.SetLibNickname( targetLib );
for( SCH_SYMBOL* symbol : symbolMap[it.first] ) for( SCH_SYMBOL* symbol : symbolMap[it.first] )
{ {
m_frame->SaveCopyInUndoList( m_frame->GetScreen(), symbol, UNDO_REDO::CHANGED, append, false); m_frame->SaveCopyInUndoList( m_frame->GetScreen(), symbol, UNDO_REDO::CHANGED, append, false);
@ -487,6 +488,7 @@ int SCH_EDITOR_CONTROL::ExportSymbolsToLibrary( const TOOL_EVENT& aEvent )
for( SCH_SHEET_PATH& sheet : sheets ) for( SCH_SHEET_PATH& sheet : sheets )
{ {
SCH_SCREEN* screen = sheet.LastScreen(); SCH_SCREEN* screen = sheet.LastScreen();
if( processedScreens.find( ( screen ) ) == processedScreens.end() ) if( processedScreens.find( ( screen ) ) == processedScreens.end() )
{ {
processedScreens.insert( screen ); processedScreens.insert( screen );