From 71002dce288a73a457fbdd4b99ea09e6d96bac57 Mon Sep 17 00:00:00 2001 From: JamesJCode <13408010-JamesJCode@users.noreply.gitlab.com> Date: Mon, 30 Jan 2023 21:36:59 +0000 Subject: [PATCH] Eeschema: Fix export symbols to new library Exporting symbols to new library now saves the library and forces update of symbol links Fixes #13494 --- eeschema/tools/sch_editor_control.cpp | 54 +++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/eeschema/tools/sch_editor_control.cpp b/eeschema/tools/sch_editor_control.cpp index 1f4ba67b2a..549cbaa3b9 100644 --- a/eeschema/tools/sch_editor_control.cpp +++ b/eeschema/tools/sch_editor_control.cpp @@ -438,8 +438,62 @@ int SCH_EDITOR_CONTROL::ExportSymbolsToLibrary( const TOOL_EVENT& aEvent ) } } + // Save the modified symbol library table. We need to look this up by name in each table to find + // whether the new library is a global or project entity as the code above to choose the library + // returns a different type depending on whether a global or project library is chosen. + SYMBOL_LIB_TABLE* globalTable = &SYMBOL_LIB_TABLE::GetGlobalLibTable(); + SYMBOL_LIB_TABLE* projectTable = nullptr; + + if( !m_frame->Prj().IsNullProject() ) + projectTable = m_frame->Prj().SchSymbolLibTable(); + + if( globalTable->FindRow( targetLib ) ) + { + try + { + wxString globalTablePath = SYMBOL_LIB_TABLE::GetGlobalTableFileName(); + globalTable->Save( globalTablePath ); + } + catch( const IO_ERROR& ioe ) + { + wxString msg; + msg.Printf( _( "Error saving global library table:\n\n%s" ), ioe.What() ); + wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR ); + } + } + else if( projectTable && projectTable->FindRow( targetLib ) ) + { + try + { + wxString projectPath = m_frame->Prj().GetProjectPath(); + wxFileName projectTableFn( projectPath, SYMBOL_LIB_TABLE::GetSymbolLibTableFileName() ); + projectTable->Save( projectTableFn.GetFullPath() ); + } + catch( const IO_ERROR& ioe ) + { + wxString msg; + msg.Printf( _( "Error saving project-specific library table:\n\n%s" ), ioe.What() ); + wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR ); + } + } + if( append ) + { + std::set processedScreens; + SCH_SHEET_LIST sheets = m_frame->Schematic().GetSheets(); + + for( SCH_SHEET_PATH& sheet : sheets ) + { + SCH_SCREEN* screen = sheet.LastScreen(); + if( processedScreens.find( ( screen ) ) == processedScreens.end() ) + { + processedScreens.insert( screen ); + screen->UpdateSymbolLinks(); + } + } + m_frame->OnModify(); + } return 0; }