KiCad PCB EDA Suite
panel_sym_lib_table.cpp File Reference
#include <set>
#include <wx/regex.h>
#include <fctsys.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 <lib_edit_frame.h>
#include <sch_edit_frame.h>
#include <viewlib_frame.h>
#include <kiway.h>
#include <sch_screen.h>
#include <widgets/grid_readonly_text_helpers.h>
#include <widgets/grid_text_button_helpers.h>

Go to the source code of this file.

Classes

class  SYMBOL_LIB_TABLE_GRID
 Build a wxGridTableBase by wrapping an SYMBOL_LIB_TABLE object. More...
 
class  SYMBOL_GRID_TRICKS
 

Functions

void InvokeSchEditSymbolLibTable (KIWAY *aKiway, wxWindow *aParent)
 

Function Documentation

◆ InvokeSchEditSymbolLibTable()

void InvokeSchEditSymbolLibTable ( KIWAY aKiway,
wxWindow *  aParent 
)

Definition at line 706 of file panel_sym_lib_table.cpp.

707 {
708  SCH_EDIT_FRAME* schEditor = (SCH_EDIT_FRAME*) aKiway->Player( FRAME_SCH, false );
709  LIB_EDIT_FRAME* libEditor = (LIB_EDIT_FRAME*) aKiway->Player( FRAME_SCH_LIB_EDITOR, false );
710  LIB_VIEW_FRAME* libViewer = (LIB_VIEW_FRAME*) aKiway->Player( FRAME_SCH_VIEWER, false );
711 
713  wxString globalTablePath = SYMBOL_LIB_TABLE::GetGlobalTableFileName();
714  SYMBOL_LIB_TABLE* projectTable = aKiway->Prj().SchSymbolLibTable();
715  wxString projectPath = aKiway->Prj().GetProjectPath();
716  wxFileName projectTableFn( projectPath, SYMBOL_LIB_TABLE::GetSymbolLibTableFileName() );
717  wxString msg;
718  wxString currentLib;
719 
720  if( libEditor )
721  {
722  currentLib = libEditor->GetCurLib();
723 
724  // This prevents an ugly crash on OSX (https://bugs.launchpad.net/kicad/+bug/1765286)
725  libEditor->FreezeSearchTree();
726 
727  if( libEditor->HasLibModifications() )
728  {
729  msg = _( "Modifications have been made to one or more symbol libraries.\n"
730  "Changes must be saved or discarded before the symbol library "
731  "table can be modified." );
732 
733  switch( UnsavedChangesDialog( aParent, msg ) )
734  {
735  case wxID_YES: libEditor->SaveAll(); break;
736  case wxID_NO: libEditor->RevertAll(); break;
737  default:
738  case wxID_CANCEL: libEditor->ThawSearchTree(); return;
739  }
740  }
741  }
742 
743  DIALOG_EDIT_LIBRARY_TABLES dlg( aParent, _( "Symbol Libraries" ) );
744 
745  dlg.InstallPanel( new PANEL_SYM_LIB_TABLE( &dlg, globalTable, globalTablePath,
746  projectTable, projectTableFn.GetFullPath(),
747  aKiway->Prj().GetProjectPath() ) );
748 
749  if( dlg.ShowModal() == wxID_CANCEL )
750  {
751  if( libEditor )
752  libEditor->ThawSearchTree();
753 
754  return;
755  }
756 
757  if( dlg.m_GlobalTableChanged )
758  {
759  try
760  {
761  globalTable->Save( globalTablePath );
762  }
763  catch( const IO_ERROR& ioe )
764  {
765  msg.Printf( _( "Error saving global library table:\n\n%s" ), ioe.What() );
766  wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR );
767  }
768  }
769 
770  if( dlg.m_ProjectTableChanged )
771  {
772  try
773  {
774  projectTable->Save( projectTableFn.GetFullPath() );
775  }
776  catch( const IO_ERROR& ioe )
777  {
778  msg.Printf( _( "Error saving project-specific library table:\n\n%s" ), ioe.What() );
779  wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR );
780  }
781  }
782 
783  SCH_SCREENS schematic;
784 
785  schematic.UpdateSymbolLinks( true ); // Update all symbol library links for all sheets.
786 
787  if( schEditor )
788  schEditor->SyncView();
789 
790  if( libEditor )
791  {
792  // Check if the currently selected symbol library been removed or disabled.
793  if( !currentLib.empty()
794  && !projectTable->HasLibrary( currentLib, true ) )
795  {
796  libEditor->SetCurLib( wxEmptyString );
797  libEditor->emptyScreen();
798  }
799 
800  libEditor->SyncLibraries( true );
801  libEditor->ThawSearchTree();
802  }
803 
804  if( libViewer )
805  libViewer->ReCreateListLib();
806 }
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:163
Schematic editor (Eeschema) main window.
VTBL_ENTRY const wxString GetProjectPath() const
Function GetProjectPath returns the full path of the project.
Definition: project.cpp:102
Symbol library viewer main window.
Definition: viewlib_frame.h:43
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:321
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:33
void SaveAll()
Saves all modified parts and libraries.
Definition: libedit.cpp:266
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:155
#define _(s)
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.
void UpdateSymbolLinks(bool aForce=false)
Initialize or reinitialize the weak reference to the LIB_PART for each SCH_COMPONENT found in the ful...
bool HasLibModifications() const
Check if any pending libraries have been modified.
void Save(const wxString &aFileName) const
Write this library table to aFileName in s-expression form.
void RevertAll()
Definition: libedit.cpp:708
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.
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
Definition: sch_screen.h:486

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(), SCH_SCREENS::UpdateSymbolLinks(), and IO_ERROR::What().

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