KiCad PCB EDA Suite
panel_sym_lib_table.cpp File Reference
#include <set>
#include <wx/regex.h>
#include <project.h>
#include <panel_sym_lib_table.h>
#include <lib_id.h>
#include <symbol_lib_table.h>
#include <lib_table_lexer.h>
#include <grid_tricks.h>
#include <widgets/wx_grid.h>
#include <confirm.h>
#include <bitmaps.h>
#include <lib_table_grid.h>
#include <wildcards_and_files_ext.h>
#include <env_paths.h>
#include <eeschema_id.h>
#include <lib_edit_frame.h>
#include <lib_view_frame.h>
#include <sch_edit_frame.h>
#include <kiway.h>
#include <pgm_base.h>
#include <sch_screen.h>
#include <settings/settings_manager.h>
#include <widgets/grid_readonly_text_helpers.h>
#include <widgets/grid_text_button_helpers.h>

Go to the source code of this file.

Classes

struct  supportedFileType
 Container that describes file type info for the add a library options. More...
 
class  SYMBOL_LIB_TABLE_GRID
 Build a wxGridTableBase by wrapping an SYMBOL_LIB_TABLE object. More...
 
class  SYMBOL_GRID_TRICKS
 

Enumerations

enum  { ID_PANEL_SYM_LIB_KICAD = ID_END_EESCHEMA_ID_LIST, ID_PANEL_SYM_LIB_LEGACY }
 Event IDs for the menu items in the split button menu for add a library. More...
 

Functions

static const std::map< int, supportedFileType > & fileTypes ()
 Map with event id as the key to supported file types that will be listed for the add a library option. More...
 
void InvokeSchEditSymbolLibTable (KIWAY *aKiway, wxWindow *aParent)
 

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Event IDs for the menu items in the split button menu for add a library.

Enumerator
ID_PANEL_SYM_LIB_KICAD 
ID_PANEL_SYM_LIB_LEGACY 

Definition at line 67 of file panel_sym_lib_table.cpp.

Function Documentation

◆ fileTypes()

static const std::map<int, supportedFileType>& fileTypes ( )
static

Map with event id as the key to supported file types that will be listed for the add a library option.

Definition at line 77 of file panel_sym_lib_table.cpp.

78 {
79  static const std::map<int, supportedFileType> fileTypes =
80  {
82  {
83  "KiCad legacy symbol library file (*.lib)",
85  "",
86  true,
87  SCH_IO_MGR::SCH_LEGACY
88  }
89  },
90  {
92  {
93  "KiCad s-expression symbol library file (*.kicad_sym)",
95  "",
96  true,
97  SCH_IO_MGR::SCH_KICAD
98  }
99  }
100  };
101 
102  return fileTypes;
103 }
wxString KiCadSymbolLibFileWildcard()
wxString LegacySymbolLibFileWildcard()
static const std::map< int, supportedFileType > & fileTypes()
Map with event id as the key to supported file types that will be listed for the add a library option...

References ID_PANEL_SYM_LIB_KICAD, ID_PANEL_SYM_LIB_LEGACY, KiCadSymbolLibFileWildcard(), and LegacySymbolLibFileWildcard().

◆ InvokeSchEditSymbolLibTable()

void InvokeSchEditSymbolLibTable ( KIWAY aKiway,
wxWindow *  aParent 
)

Definition at line 835 of file panel_sym_lib_table.cpp.

836 {
837  SCH_EDIT_FRAME* schEditor = (SCH_EDIT_FRAME*) aKiway->Player( FRAME_SCH, false );
838  LIB_EDIT_FRAME* libEditor = (LIB_EDIT_FRAME*) aKiway->Player( FRAME_SCH_LIB_EDITOR, false );
839  LIB_VIEW_FRAME* libViewer = (LIB_VIEW_FRAME*) aKiway->Player( FRAME_SCH_VIEWER, false );
840 
842  wxString globalTablePath = SYMBOL_LIB_TABLE::GetGlobalTableFileName();
843  SYMBOL_LIB_TABLE* projectTable = nullptr;
844  wxString projectPath = aKiway->Prj().GetProjectPath();
845  wxFileName projectTableFn( projectPath, SYMBOL_LIB_TABLE::GetSymbolLibTableFileName() );
846  wxString msg;
847  wxString currentLib;
848 
849  // Don't allow editing project tables if no project is open
850  if( !aKiway->Prj().IsNullProject() )
851  projectTable = aKiway->Prj().SchSymbolLibTable();
852 
853  if( libEditor )
854  {
855  currentLib = libEditor->GetCurLib();
856 
857  // This prevents an ugly crash on OSX (https://bugs.launchpad.net/kicad/+bug/1765286)
858  libEditor->FreezeSearchTree();
859 
860  if( libEditor->HasLibModifications() )
861  {
862  msg = _( "Modifications have been made to one or more symbol libraries.\n"
863  "Changes must be saved or discarded before the symbol library "
864  "table can be modified." );
865 
866  switch( UnsavedChangesDialog( aParent, msg ) )
867  {
868  case wxID_YES: libEditor->SaveAll(); break;
869  case wxID_NO: libEditor->RevertAll(); break;
870  default:
871  case wxID_CANCEL: libEditor->ThawSearchTree(); return;
872  }
873  }
874  }
875 
876  DIALOG_EDIT_LIBRARY_TABLES dlg( aParent, _( "Symbol Libraries" ) );
877 
878  dlg.InstallPanel( new PANEL_SYM_LIB_TABLE( &dlg, globalTable, globalTablePath,
879  projectTable, projectTableFn.GetFullPath(),
880  aKiway->Prj().GetProjectPath() ) );
881 
882  if( dlg.ShowModal() == wxID_CANCEL )
883  {
884  if( libEditor )
885  libEditor->ThawSearchTree();
886 
887  return;
888  }
889 
890  if( dlg.m_GlobalTableChanged )
891  {
892  try
893  {
894  globalTable->Save( globalTablePath );
895  }
896  catch( const IO_ERROR& ioe )
897  {
898  msg.Printf( _( "Error saving global library table:\n\n%s" ), ioe.What() );
899  wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR );
900  }
901  }
902 
903  if( projectTable && dlg.m_ProjectTableChanged )
904  {
905  try
906  {
907  projectTable->Save( projectTableFn.GetFullPath() );
908  }
909  catch( const IO_ERROR& ioe )
910  {
911  msg.Printf( _( "Error saving project-specific library table:\n\n%s" ), ioe.What() );
912  wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR );
913  }
914  }
915 
916  if( schEditor )
917  schEditor->SyncView();
918 
919  if( libEditor )
920  {
921  // Check if the currently selected symbol library been removed or disabled.
922  if( !currentLib.empty() && projectTable && !projectTable->HasLibrary( currentLib, true ) )
923  {
924  libEditor->SetCurLib( wxEmptyString );
925  libEditor->emptyScreen();
926  }
927 
928  libEditor->SyncLibraries( true );
929  libEditor->ThawSearchTree();
930  }
931 
932  if( libViewer )
933  libViewer->ReCreateListLib();
934 }
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:173
Schematic editor (Eeschema) main window.
VTBL_ENTRY const wxString GetProjectPath() const
Function GetProjectPath returns the full path of the project.
Definition: project.cpp:121
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:343
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:29
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:149
VTBL_ENTRY bool IsNullProject() const
Checks if this project is a null project (i.e.
Definition: project.cpp:133
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(), PROJECT::IsNullProject(), 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().