KiCad PCB EDA Suite
panel_sym_lib_table.h File Reference

Go to the source code of this file.

Classes

class  PANEL_SYM_LIB_TABLE
 Dialog to show and edit symbol library tables. More...
 

Functions

void InvokeSchEditSymbolLibTable (KIWAY *aKiway, wxWindow *aParent)
 

Function Documentation

◆ InvokeSchEditSymbolLibTable()

void InvokeSchEditSymbolLibTable ( KIWAY aKiway,
wxWindow *  aParent 
)

Definition at line 1004 of file panel_sym_lib_table.cpp.

1005{
1006 auto* schEditor = (SCH_EDIT_FRAME*) aKiway->Player( FRAME_SCH, false );
1007 auto* symbolEditor = (SYMBOL_EDIT_FRAME*) aKiway->Player( FRAME_SCH_SYMBOL_EDITOR, false );
1008 auto* symbolViewer = (SYMBOL_VIEWER_FRAME*) aKiway->Player( FRAME_SCH_VIEWER, false );
1009
1011 wxString globalTablePath = SYMBOL_LIB_TABLE::GetGlobalTableFileName();
1012 SYMBOL_LIB_TABLE* projectTable = nullptr;
1013 wxString projectPath = aKiway->Prj().GetProjectPath();
1014 wxFileName projectTableFn( projectPath, SYMBOL_LIB_TABLE::GetSymbolLibTableFileName() );
1015 wxString msg;
1016 wxString currentLib;
1017
1018 // Don't allow editing project tables if no project is open
1019 if( !aKiway->Prj().IsNullProject() )
1020 projectTable = aKiway->Prj().SchSymbolLibTable();
1021
1022 if( symbolEditor )
1023 {
1024 currentLib = symbolEditor->GetCurLib();
1025
1026 // This prevents an ugly crash on OSX (https://bugs.launchpad.net/kicad/+bug/1765286)
1027 symbolEditor->FreezeLibraryTree();
1028
1029 if( symbolEditor->HasLibModifications() )
1030 {
1031 msg = _( "Modifications have been made to one or more symbol libraries.\n"
1032 "Changes must be saved or discarded before the symbol library "
1033 "table can be modified." );
1034
1035 switch( UnsavedChangesDialog( aParent, msg ) )
1036 {
1037 case wxID_YES: symbolEditor->SaveAll(); break;
1038 case wxID_NO: symbolEditor->RevertAll(); break;
1039 default:
1040 case wxID_CANCEL: symbolEditor->ThawLibraryTree(); return;
1041 }
1042 }
1043 }
1044
1045 DIALOG_EDIT_LIBRARY_TABLES dlg( aParent, _( "Symbol Libraries" ) );
1046 dlg.SetKiway( &dlg, aKiway );
1047
1048 dlg.InstallPanel( new PANEL_SYM_LIB_TABLE( &dlg, &aKiway->Prj(), globalTable, globalTablePath,
1049 projectTable, projectTableFn.GetFullPath() ) );
1050
1051 if( dlg.ShowModal() == wxID_CANCEL )
1052 {
1053 if( symbolEditor )
1054 symbolEditor->ThawLibraryTree();
1055
1056 return;
1057 }
1058
1059 if( dlg.m_GlobalTableChanged )
1060 {
1061 try
1062 {
1063 globalTable->Save( globalTablePath );
1064 }
1065 catch( const IO_ERROR& ioe )
1066 {
1067 msg.Printf( _( "Error saving global library table:\n\n%s" ), ioe.What() );
1068 wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR );
1069 }
1070 }
1071
1072 if( projectTable && dlg.m_ProjectTableChanged )
1073 {
1074 try
1075 {
1076 projectTable->Save( projectTableFn.GetFullPath() );
1077 }
1078 catch( const IO_ERROR& ioe )
1079 {
1080 msg.Printf( _( "Error saving project-specific library table:\n\n%s" ), ioe.What() );
1081 wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR );
1082 }
1083 }
1084
1085 if( schEditor )
1086 schEditor->SyncView();
1087
1088 if( symbolEditor )
1089 {
1090 // Check if the currently selected symbol library been removed or disabled.
1091 if( !currentLib.empty() && projectTable && !projectTable->HasLibrary( currentLib, true ) )
1092 {
1093 symbolEditor->SetCurLib( wxEmptyString );
1094 symbolEditor->emptyScreen();
1095 }
1096
1097 symbolEditor->SyncLibraries( true );
1098 symbolEditor->ThawLibraryTree();
1099 symbolEditor->RefreshLibraryTree();
1100 }
1101
1102 if( symbolViewer )
1103 symbolViewer->ReCreateLibList();
1104}
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:76
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:30
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
Definition: kiway.cpp:394
virtual PROJECT & Prj() const
Return the PROJECT associated with this KIWAY.
Definition: kiway.cpp:192
bool HasLibrary(const wxString &aNickname, bool aCheckEnabled=false) const
Test for the existence of aNickname in the library table.
void Save(const wxString &aFileName) const
Write this library table to aFileName in s-expression form.
Dialog to show and edit symbol library tables.
virtual const wxString GetProjectPath() const
Return the full path of the project.
Definition: project.cpp:122
virtual bool IsNullProject() const
Check if this project is a null project (i.e.
Definition: project.cpp:134
Schematic editor (Eeschema) main window.
The symbol library editor main window.
static SYMBOL_LIB_TABLE & GetGlobalLibTable()
static const wxString & GetSymbolLibTableFileName()
static wxString GetGlobalTableFileName()
Fetch the global symbol library table file name.
Symbol library viewer main window.
int UnsavedChangesDialog(wxWindow *parent, const wxString &aMessage, bool *aApplyToAll)
A specialized version of HandleUnsavedChanges which handles an apply-to-all checkbox.
Definition: confirm.cpp:177
#define _(s)
@ FRAME_SCH_SYMBOL_EDITOR
Definition: frame_type.h:35
@ FRAME_SCH_VIEWER
Definition: frame_type.h:36
@ FRAME_SCH
Definition: frame_type.h:34

References _, FRAME_SCH, FRAME_SCH_SYMBOL_EDITOR, FRAME_SCH_VIEWER, SYMBOL_LIB_TABLE::GetGlobalLibTable(), SYMBOL_LIB_TABLE::GetGlobalTableFileName(), PROJECT::GetProjectPath(), SYMBOL_LIB_TABLE::GetSymbolLibTableFileName(), LIB_TABLE::HasLibrary(), DIALOG_EDIT_LIBRARY_TABLES::InstallPanel(), PROJECT::IsNullProject(), DIALOG_EDIT_LIBRARY_TABLES::m_GlobalTableChanged, DIALOG_EDIT_LIBRARY_TABLES::m_ProjectTableChanged, KIWAY::Player(), KIWAY::Prj(), LIB_TABLE::Save(), KIWAY_HOLDER::SetKiway(), UnsavedChangesDialog(), and IO_ERROR::What().

Referenced by SYMBOL_EDIT_FRAME::SetCurSymbol().