KiCad PCB EDA Suite
panel_fp_lib_table.cpp File Reference
#include <set>
#include <wx/dir.h>
#include <wx/regex.h>
#include <wx/grid.h>
#include <wx/dirdlg.h>
#include <wx/filedlg.h>
#include <project.h>
#include <3d_viewer/eda_3d_viewer_frame.h>
#include <panel_fp_lib_table.h>
#include <lib_id.h>
#include <fp_lib_table.h>
#include <lib_table_lexer.h>
#include <invoke_pcb_dialog.h>
#include <bitmaps.h>
#include <grid_tricks.h>
#include <widgets/wx_grid.h>
#include <confirm.h>
#include <lib_table_grid.h>
#include <wildcards_and_files_ext.h>
#include <pgm_base.h>
#include <pcb_edit_frame.h>
#include <env_paths.h>
#include <dialogs/dialog_edit_library_tables.h>
#include <footprint_viewer_frame.h>
#include <footprint_edit_frame.h>
#include <kiway.h>
#include <widgets/grid_readonly_text_helpers.h>
#include <widgets/grid_text_button_helpers.h>
#include <pcbnew_id.h>
#include <settings/settings_manager.h>
#include <paths.h>
#include <macros.h>

Go to the source code of this file.

Classes

struct  SUPPORTED_FILE_TYPE
 Container that describes file type info for the add a library options. More...
 
class  LIBRARY_TRAVERSER
 Traverser implementation that looks to find any and all "folder" libraries by looking for files with a specific extension inside folders. More...
 
class  FP_LIB_TABLE_GRID
 This class builds a wxGridTableBase by wrapping an FP_LIB_TABLE object. More...
 
class  FP_GRID_TRICKS
 

Macros

#define MYID_OPTIONS_EDITOR   15151
 

Enumerations

enum  { ID_PANEL_FPLIB_ADD_KICADMOD = ID_PCBNEW_END_LIST, ID_PANEL_FPLIB_ADD_EAGLE6, ID_PANEL_FPLIB_ADD_KICADLEGACY, ID_PANEL_FPLIB_ADD_GEDA }
 Event IDs for the menu items in the split button menu for add a library. More...
 

Functions

static const std::map< int, SUPPORTED_FILE_TYPE > & fileTypes ()
 Map with event id as the key to supported file types that will be listed for the add a library option. More...
 
void InvokePcbLibTableEditor (KIWAY *aKiway, wxWindow *aCaller)
 Function InvokePcbLibTableEditor shows the modal DIALOG_FP_LIB_TABLE for purposes of editing the global and project library tables. More...
 

Macro Definition Documentation

◆ MYID_OPTIONS_EDITOR

#define MYID_OPTIONS_EDITOR   15151

Definition at line 238 of file panel_fp_lib_table.cpp.

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_FPLIB_ADD_KICADMOD 
ID_PANEL_FPLIB_ADD_EAGLE6 
ID_PANEL_FPLIB_ADD_KICADLEGACY 
ID_PANEL_FPLIB_ADD_GEDA 

Definition at line 85 of file panel_fp_lib_table.cpp.

Function Documentation

◆ fileTypes()

static const std::map<int, SUPPORTED_FILE_TYPE>& 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 97 of file panel_fp_lib_table.cpp.

98 {
99  /*
100  * TODO(C++20): Clean this up
101  * This is wrapped inside a function to prevent a static initialization order fiasco
102  * with the file extension variables. Once C++20 is allowed in KiCad code, those file
103  * extensions can be made constexpr and this can be removed from a function call and
104  * placed in the file normally.
105  */
106  static const std::map<int, SUPPORTED_FILE_TYPE> fileTypes =
107  {
109  {
110  "KiCad (folder with .kicad_mod files)", "", KiCadFootprintFileExtension,
111  false, IO_MGR::KICAD_SEXP
112  }
113  },
115  {
116  "Eagle 6.x (*.lbr)", EagleFootprintLibPathWildcard(), "", true, IO_MGR::EAGLE
117  }
118  },
120  {
121  "KiCad legacy (*.mod)", LegacyFootprintLibPathWildcard(), "", true, IO_MGR::LEGACY
122  }
123  },
125  {
126  "Geda (folder with *.fp files)", "", GedaPcbFootprintLibFileExtension, false,
128  }
129  },
130  };
131 
132  return fileTypes;
133 }
wxString EagleFootprintLibPathWildcard()
const std::string KiCadFootprintFileExtension
static const std::map< int, SUPPORTED_FILE_TYPE > & fileTypes()
Map with event id as the key to supported file types that will be listed for the add a library option...
wxString LegacyFootprintLibPathWildcard()
Geda PCB file formats.
Definition: io_mgr.h:64
Legacy Pcbnew file formats prior to s-expression.
Definition: io_mgr.h:55
const std::string GedaPcbFootprintLibFileExtension
S-expression Pcbnew file format.
Definition: io_mgr.h:56

References IO_MGR::EAGLE, EagleFootprintLibPathWildcard(), IO_MGR::GEDA_PCB, GedaPcbFootprintLibFileExtension, ID_PANEL_FPLIB_ADD_EAGLE6, ID_PANEL_FPLIB_ADD_GEDA, ID_PANEL_FPLIB_ADD_KICADLEGACY, ID_PANEL_FPLIB_ADD_KICADMOD, IO_MGR::KICAD_SEXP, KiCadFootprintFileExtension, IO_MGR::LEGACY, and LegacyFootprintLibPathWildcard().

Referenced by PANEL_FP_LIB_TABLE::browseLibrariesHandler(), and PANEL_FP_LIB_TABLE::PANEL_FP_LIB_TABLE().

◆ InvokePcbLibTableEditor()

void InvokePcbLibTableEditor ( KIWAY aKiway,
wxWindow *  aCaller 
)

Function InvokePcbLibTableEditor shows the modal DIALOG_FP_LIB_TABLE for purposes of editing the global and project library tables.

Parameters
aCalleris the wxWindow which is invoking the dialog.
Returns
true if either table changed.

Definition at line 1069 of file panel_fp_lib_table.cpp.

1070 {
1071  FP_LIB_TABLE* globalTable = &GFootprintTable;
1072  wxString globalTablePath = FP_LIB_TABLE::GetGlobalTableFileName();
1073  FP_LIB_TABLE* projectTable = aKiway->Prj().PcbFootprintLibs();
1074  wxString projectTablePath = aKiway->Prj().FootprintLibTblName();
1075  wxString msg;
1076 
1077  DIALOG_EDIT_LIBRARY_TABLES dlg( aCaller, _( "Footprint Libraries" ) );
1078  dlg.SetKiway( &dlg, aKiway );
1079 
1080  if( aKiway->Prj().IsNullProject() )
1081  projectTable = nullptr;
1082 
1083  dlg.InstallPanel( new PANEL_FP_LIB_TABLE( &dlg, globalTable, globalTablePath,
1084  projectTable, projectTablePath,
1085  aKiway->Prj().GetProjectPath() ) );
1086 
1087  if( dlg.ShowModal() == wxID_CANCEL )
1088  return;
1089 
1090  if( dlg.m_GlobalTableChanged )
1091  {
1092  try
1093  {
1094  globalTable->Save( globalTablePath );
1095  }
1096  catch( const IO_ERROR& ioe )
1097  {
1098  msg.Printf( _( "Error saving global library table:\n\n%s" ), ioe.What() );
1099  wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR );
1100  }
1101  }
1102 
1103  if( projectTable && dlg.m_ProjectTableChanged )
1104  {
1105  try
1106  {
1107  projectTable->Save( projectTablePath );
1108  }
1109  catch( const IO_ERROR& ioe )
1110  {
1111  msg.Printf( _( "Error saving project-specific library table:\n\n%s" ), ioe.What() );
1112  wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR );
1113  }
1114  }
1115 
1116  auto editor = (FOOTPRINT_EDIT_FRAME*) aKiway->Player( FRAME_FOOTPRINT_EDITOR, false );
1117 
1118  if( editor )
1119  {
1120  editor->SyncLibraryTree( true );
1121  editor->RefreshLibraryTree();
1122  }
1123 
1124  auto viewer = (FOOTPRINT_VIEWER_FRAME*) aKiway->Player( FRAME_FOOTPRINT_VIEWER, false );
1125 
1126  if( viewer )
1127  viewer->ReCreateLibraryList();
1128 }
FP_LIB_TABLE GFootprintTable
The global footprint library table.
Definition: cvpcb.cpp:134
virtual PROJECT & Prj() const
Return the PROJECT associated with this KIWAY.
Definition: kiway.cpp:190
Component 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:383
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
#define _(s)
virtual bool IsNullProject() const
Check if this project is a null project (i.e.
Definition: project.cpp:134
virtual FP_LIB_TABLE * PcbFootprintLibs(KIWAY &aKiway)
Return the table of footprint libraries.
Definition: project.cpp:283
void Save(const wxString &aFileName) const
Write this library table to aFileName in s-expression form.
Dialog to show and edit symbol library tables.
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:75
virtual const wxString FootprintLibTblName() const
Returns the path and filename of this project's footprint library table.
Definition: project.cpp:146
static wxString GetGlobalTableFileName()

References _, editor, PROJECT::FootprintLibTblName(), FRAME_FOOTPRINT_EDITOR, FRAME_FOOTPRINT_VIEWER, FP_LIB_TABLE::GetGlobalTableFileName(), PROJECT::GetProjectPath(), GFootprintTable, DIALOG_EDIT_LIBRARY_TABLES::InstallPanel(), PROJECT::IsNullProject(), DIALOG_EDIT_LIBRARY_TABLES::m_GlobalTableChanged, DIALOG_EDIT_LIBRARY_TABLES::m_ProjectTableChanged, PROJECT::PcbFootprintLibs(), KIWAY::Player(), KIWAY::Prj(), LIB_TABLE::Save(), KIWAY_HOLDER::SetKiway(), and IO_ERROR::What().

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