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 1011 of file panel_sym_lib_table.cpp.

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

References _, FRAME_SCH, FRAME_SCH_SYMBOL_EDITOR, FRAME_SCH_VIEWER, SYMBOL_LIB_TABLE::GetGlobalLibTable(), SYMBOL_LIB_TABLE::GetGlobalTableFileName(), PROJECT::GetProjectPath(), SYMBOL_LIB_TABLE::GetSymbolLibTableFileName(), 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 SCH::IFACE::CreateWindow(), and SYMBOL_EDIT_FRAME::SetCurSymbol().