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

964 {
965  auto* schEditor = (SCH_EDIT_FRAME*) aKiway->Player( FRAME_SCH, false );
966  auto* symbolEditor = (SYMBOL_EDIT_FRAME*) aKiway->Player( FRAME_SCH_SYMBOL_EDITOR, false );
967  auto* symbolViewer = (SYMBOL_VIEWER_FRAME*) aKiway->Player( FRAME_SCH_VIEWER, false );
968 
970  wxString globalTablePath = SYMBOL_LIB_TABLE::GetGlobalTableFileName();
971  SYMBOL_LIB_TABLE* projectTable = nullptr;
972  wxString projectPath = aKiway->Prj().GetProjectPath();
973  wxFileName projectTableFn( projectPath, SYMBOL_LIB_TABLE::GetSymbolLibTableFileName() );
974  wxString msg;
975  wxString currentLib;
976 
977  // Don't allow editing project tables if no project is open
978  if( !aKiway->Prj().IsNullProject() )
979  projectTable = aKiway->Prj().SchSymbolLibTable();
980 
981  if( symbolEditor )
982  {
983  currentLib = symbolEditor->GetCurLib();
984 
985  // This prevents an ugly crash on OSX (https://bugs.launchpad.net/kicad/+bug/1765286)
986  symbolEditor->FreezeLibraryTree();
987 
988  if( symbolEditor->HasLibModifications() )
989  {
990  msg = _( "Modifications have been made to one or more symbol libraries.\n"
991  "Changes must be saved or discarded before the symbol library "
992  "table can be modified." );
993 
994  switch( UnsavedChangesDialog( aParent, msg ) )
995  {
996  case wxID_YES: symbolEditor->SaveAll(); break;
997  case wxID_NO: symbolEditor->RevertAll(); break;
998  default:
999  case wxID_CANCEL: symbolEditor->ThawLibraryTree(); return;
1000  }
1001  }
1002  }
1003 
1004  DIALOG_EDIT_LIBRARY_TABLES dlg( aParent, _( "Symbol Libraries" ) );
1005  dlg.SetKiway( &dlg, aKiway );
1006 
1007  dlg.InstallPanel( new PANEL_SYM_LIB_TABLE( &dlg, &aKiway->Prj(), globalTable, globalTablePath,
1008  projectTable, projectTableFn.GetFullPath() ) );
1009 
1010  if( dlg.ShowModal() == wxID_CANCEL )
1011  {
1012  if( symbolEditor )
1013  symbolEditor->ThawLibraryTree();
1014 
1015  return;
1016  }
1017 
1018  if( dlg.m_GlobalTableChanged )
1019  {
1020  try
1021  {
1022  globalTable->Save( globalTablePath );
1023  }
1024  catch( const IO_ERROR& ioe )
1025  {
1026  msg.Printf( _( "Error saving global library table:\n\n%s" ), ioe.What() );
1027  wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR );
1028  }
1029  }
1030 
1031  if( projectTable && dlg.m_ProjectTableChanged )
1032  {
1033  try
1034  {
1035  projectTable->Save( projectTableFn.GetFullPath() );
1036  }
1037  catch( const IO_ERROR& ioe )
1038  {
1039  msg.Printf( _( "Error saving project-specific library table:\n\n%s" ), ioe.What() );
1040  wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR );
1041  }
1042  }
1043 
1044  if( schEditor )
1045  schEditor->SyncView();
1046 
1047  if( symbolEditor )
1048  {
1049  // Check if the currently selected symbol library been removed or disabled.
1050  if( !currentLib.empty() && projectTable && !projectTable->HasLibrary( currentLib, true ) )
1051  {
1052  symbolEditor->SetCurLib( wxEmptyString );
1053  symbolEditor->emptyScreen();
1054  }
1055 
1056  symbolEditor->SyncLibraries( true );
1057  symbolEditor->ThawLibraryTree();
1058  symbolEditor->RefreshLibraryTree();
1059  }
1060 
1061  if( symbolViewer )
1062  symbolViewer->ReCreateLibList();
1063 }
static const wxString & GetSymbolLibTableFileName()
static SYMBOL_LIB_TABLE & GetGlobalLibTable()
virtual PROJECT & Prj() const
Return the PROJECT associated with this KIWAY.
Definition: kiway.cpp:173
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:357
Schematic editor (Eeschema) main window.
virtual const wxString GetProjectPath() const
Return the full path of the project.
Definition: project.cpp:123
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:29
Dialog to show and edit symbol library tables.
int UnsavedChangesDialog(wxWindow *parent, wxString aMessage, bool *aApplyToAll)
A specialized version of HandleUnsavedChanges which handles an apply-to-all checkbox.
Definition: confirm.cpp:154
virtual bool IsNullProject() const
Check if this project is a null project (i.e.
Definition: project.cpp:135
#define _(s)
Definition: 3d_actions.cpp:33
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::SetCurPart().