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

767 {
768  SCH_EDIT_FRAME* schEditor = (SCH_EDIT_FRAME*) aKiway->Player( FRAME_SCH, false );
769  LIB_EDIT_FRAME* libEditor = (LIB_EDIT_FRAME*) aKiway->Player( FRAME_SCH_LIB_EDITOR, false );
770  LIB_VIEW_FRAME* libViewer = (LIB_VIEW_FRAME*) aKiway->Player( FRAME_SCH_VIEWER, false );
771 
773  wxString globalTablePath = SYMBOL_LIB_TABLE::GetGlobalTableFileName();
774  SYMBOL_LIB_TABLE* projectTable = aKiway->Prj().SchSymbolLibTable();
775  wxString projectPath = aKiway->Prj().GetProjectPath();
776  wxFileName projectTableFn( projectPath, SYMBOL_LIB_TABLE::GetSymbolLibTableFileName() );
777  wxString msg;
778  wxString currentLib;
779 
780  if( libEditor )
781  {
782  currentLib = libEditor->GetCurLib();
783 
784  // This prevents an ugly crash on OSX (https://bugs.launchpad.net/kicad/+bug/1765286)
785  libEditor->FreezeSearchTree();
786 
787  if( libEditor->HasLibModifications() )
788  {
789  msg = _( "Modifications have been made to one or more symbol libraries.\n"
790  "Changes must be saved or discarded before the symbol library "
791  "table can be modified." );
792 
793  switch( UnsavedChangesDialog( aParent, msg ) )
794  {
795  case wxID_YES: libEditor->SaveAll(); break;
796  case wxID_NO: libEditor->RevertAll(); break;
797  default:
798  case wxID_CANCEL: libEditor->ThawSearchTree(); return;
799  }
800  }
801  }
802 
803  DIALOG_EDIT_LIBRARY_TABLES dlg( aParent, _( "Symbol Libraries" ) );
804 
805  dlg.InstallPanel( new PANEL_SYM_LIB_TABLE( &dlg, globalTable, globalTablePath,
806  projectTable, projectTableFn.GetFullPath(),
807  aKiway->Prj().GetProjectPath() ) );
808 
809  if( dlg.ShowModal() == wxID_CANCEL )
810  {
811  if( libEditor )
812  libEditor->ThawSearchTree();
813 
814  return;
815  }
816 
817  if( dlg.m_GlobalTableChanged )
818  {
819  try
820  {
821  globalTable->Save( globalTablePath );
822  }
823  catch( const IO_ERROR& ioe )
824  {
825  msg.Printf( _( "Error saving global library table:\n\n%s" ), ioe.What() );
826  wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR );
827  }
828  }
829 
830  if( dlg.m_ProjectTableChanged )
831  {
832  try
833  {
834  projectTable->Save( projectTableFn.GetFullPath() );
835  }
836  catch( const IO_ERROR& ioe )
837  {
838  msg.Printf( _( "Error saving project-specific library table:\n\n%s" ), ioe.What() );
839  wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR );
840  }
841  }
842 
843  if( schEditor )
844  schEditor->SyncView();
845 
846  if( libEditor )
847  {
848  // Check if the currently selected symbol library been removed or disabled.
849  if( !currentLib.empty()
850  && !projectTable->HasLibrary( currentLib, true ) )
851  {
852  libEditor->SetCurLib( wxEmptyString );
853  libEditor->emptyScreen();
854  }
855 
856  libEditor->SyncLibraries( true );
857  libEditor->ThawSearchTree();
858  }
859 
860  if( libViewer )
861  libViewer->ReCreateListLib();
862 }
static const wxString & GetSymbolLibTableFileName()
static SYMBOL_LIB_TABLE & GetGlobalLibTable()
bool HasLibrary(const wxString &aNickname, bool aCheckEnabled=false) const
Test for the existence of aNickname in the library table.
VTBL_ENTRY PROJECT & Prj() const
Function Prj returns the PROJECT associated with this KIWAY.
Definition: kiway.cpp:171
Schematic editor (Eeschema) main window.
VTBL_ENTRY const wxString GetProjectPath() const
Function GetProjectPath returns the full path of the project.
Definition: project.cpp:114
Symbol library viewer main window.
wxString GetCurLib() const
The nickname of the current library being edited and empty string if none.
VTBL_ENTRY KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=NULL)
Function Player returns the KIWAY_PLAYER* given a FRAME_T.
Definition: kiway.cpp:341
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:33
void SaveAll()
Saves all modified parts and libraries.
void SyncView()
Mark all items for refresh.
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:148
void emptyScreen()
Restores the empty editor screen, without any part or library selected.
void SyncLibraries(bool aShowProgress)
Synchronize the library manager to the symbol library table, and then the symbol tree to the library ...
The symbol library editor main window.
bool HasLibModifications() const
Check if any pending libraries have been modified.
#define _(s)
Definition: 3d_actions.cpp:33
void Save(const wxString &aFileName) const
Write this library table to aFileName in s-expression form.
wxString SetCurLib(const wxString &aLibNickname)
Sets the current library nickname and returns the old library nickname.
bool ReCreateListLib()
Creates or recreates a sorted list of currently loaded libraries.
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:76
static wxString GetGlobalTableFileName()
Fetch the global symbol library table file name.

References _, LIB_EDIT_FRAME::emptyScreen(), FRAME_SCH, FRAME_SCH_LIB_EDITOR, FRAME_SCH_VIEWER, LIB_EDIT_FRAME::FreezeSearchTree(), LIB_EDIT_FRAME::GetCurLib(), SYMBOL_LIB_TABLE::GetGlobalLibTable(), SYMBOL_LIB_TABLE::GetGlobalTableFileName(), PROJECT::GetProjectPath(), SYMBOL_LIB_TABLE::GetSymbolLibTableFileName(), LIB_EDIT_FRAME::HasLibModifications(), LIB_TABLE::HasLibrary(), DIALOG_EDIT_LIBRARY_TABLES::InstallPanel(), DIALOG_EDIT_LIBRARY_TABLES::m_GlobalTableChanged, DIALOG_EDIT_LIBRARY_TABLES::m_ProjectTableChanged, KIWAY::Player(), KIWAY::Prj(), LIB_VIEW_FRAME::ReCreateListLib(), LIB_EDIT_FRAME::RevertAll(), LIB_TABLE::Save(), LIB_EDIT_FRAME::SaveAll(), LIB_EDIT_FRAME::SetCurLib(), LIB_EDIT_FRAME::SyncLibraries(), SCH_BASE_FRAME::SyncView(), LIB_EDIT_FRAME::ThawSearchTree(), UnsavedChangesDialog(), and IO_ERROR::What().

Referenced by SCH::IFACE::CreateWindow().