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 <lib_table_grid_tricks.h>
#include <widgets/wx_grid.h>
#include <widgets/std_bitmap_button.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 <kiway_express.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_ALTIUM , 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 247 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_ALTIUM 
ID_PANEL_FPLIB_ADD_EAGLE6 
ID_PANEL_FPLIB_ADD_KICADLEGACY 
ID_PANEL_FPLIB_ADD_GEDA 

Definition at line 86 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 99 of file panel_fp_lib_table.cpp.

100{
101 /*
102 * TODO(C++20): Clean this up
103 * This is wrapped inside a function to prevent a static initialization order fiasco
104 * with the file extension variables. Once C++20 is allowed in KiCad code, those file
105 * extensions can be made constexpr and this can be removed from a function call and
106 * placed in the file normally.
107 */
108 static const std::map<int, SUPPORTED_FILE_TYPE> fileTypes =
109 {
111 {
112 wxT( "KiCad (folder with .kicad_mod files)" ), wxT( "" ),
114 }
115 },
117 {
118 "Altium (*.PcbLib)", AltiumFootprintLibPathWildcard(), "", true, IO_MGR::ALTIUM_DESIGNER
119 }
120 },
122 {
123 wxT( "Eagle 6.x (*.lbr)" ), EagleFootprintLibPathWildcard(), wxT( "" ),
124 true, IO_MGR::EAGLE
125 }
126 },
128 {
129 wxT( "KiCad legacy (*.mod)" ), LegacyFootprintLibPathWildcard(), wxT( "" ),
130 true, IO_MGR::LEGACY
131 }
132 },
134 {
135 wxT( "Geda (folder with *.fp files)" ), wxT( "" ),
137 }
138 },
139 };
140
141 return fileTypes;
142}
@ LEGACY
Legacy Pcbnew file formats prior to s-expression.
Definition: io_mgr.h:55
@ ALTIUM_DESIGNER
Definition: io_mgr.h:60
@ KICAD_SEXP
S-expression Pcbnew file format.
Definition: io_mgr.h:56
@ EAGLE
Definition: io_mgr.h:57
@ GEDA_PCB
Geda PCB file formats.
Definition: io_mgr.h:64
const std::string KiCadFootprintFileExtension
const std::string GedaPcbFootprintLibFileExtension
wxString EagleFootprintLibPathWildcard()
wxString AltiumFootprintLibPathWildcard()
wxString LegacyFootprintLibPathWildcard()
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...

References IO_MGR::ALTIUM_DESIGNER, AltiumFootprintLibPathWildcard(), IO_MGR::EAGLE, EagleFootprintLibPathWildcard(), fileTypes(), IO_MGR::GEDA_PCB, GedaPcbFootprintLibFileExtension, ID_PANEL_FPLIB_ADD_ALTIUM, 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(), fileTypes(), 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 1086 of file panel_fp_lib_table.cpp.

1087{
1088 FP_LIB_TABLE* globalTable = &GFootprintTable;
1089 wxString globalTablePath = FP_LIB_TABLE::GetGlobalTableFileName();
1090 FP_LIB_TABLE* projectTable = aKiway->Prj().PcbFootprintLibs();
1091 wxString projectTablePath = aKiway->Prj().FootprintLibTblName();
1092 wxString msg;
1093
1094 DIALOG_EDIT_LIBRARY_TABLES dlg( aCaller, _( "Footprint Libraries" ) );
1095 dlg.SetKiway( &dlg, aKiway );
1096
1097 if( aKiway->Prj().IsNullProject() )
1098 projectTable = nullptr;
1099
1100 dlg.InstallPanel( new PANEL_FP_LIB_TABLE( &dlg, globalTable, globalTablePath,
1101 projectTable, projectTablePath,
1102 aKiway->Prj().GetProjectPath() ) );
1103
1104 if( dlg.ShowModal() == wxID_CANCEL )
1105 return;
1106
1107 if( dlg.m_GlobalTableChanged )
1108 {
1109 try
1110 {
1111 globalTable->Save( globalTablePath );
1112 }
1113 catch( const IO_ERROR& ioe )
1114 {
1115 msg.Printf( _( "Error saving global library table:\n\n%s" ), ioe.What() );
1116 wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR );
1117 }
1118 }
1119
1120 if( projectTable && dlg.m_ProjectTableChanged )
1121 {
1122 try
1123 {
1124 projectTable->Save( projectTablePath );
1125 }
1126 catch( const IO_ERROR& ioe )
1127 {
1128 msg.Printf( _( "Error saving project-specific library table:\n\n%s" ), ioe.What() );
1129 wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR );
1130 }
1131 }
1132
1133 std::string payload = "";
1136 aKiway->ExpressMail( FRAME_CVPCB, MAIL_RELOAD_LIB, payload );
1137}
static wxString GetGlobalTableFileName()
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:76
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:30
virtual void ExpressMail(FRAME_T aDestination, MAIL_T aCommand, std::string &aPayload, wxWindow *aSource=nullptr)
Send aPayload to aDestination from aSource.
Definition: kiway.cpp:491
virtual PROJECT & Prj() const
Return the PROJECT associated with this KIWAY.
Definition: kiway.cpp:192
void Save(const wxString &aFileName) const
Write this library table to aFileName in s-expression form.
Dialog to show and edit symbol library tables.
virtual const wxString GetProjectPath() const
Return the full path of the project.
Definition: project.cpp:126
virtual FP_LIB_TABLE * PcbFootprintLibs(KIWAY &aKiway)
Return the table of footprint libraries.
Definition: project.cpp:324
virtual const wxString FootprintLibTblName() const
Returns the path and filename of this project's footprint library table.
Definition: project.cpp:150
virtual bool IsNullProject() const
Check if this project is a null project (i.e.
Definition: project.cpp:138
FP_LIB_TABLE GFootprintTable
The global footprint library table.
Definition: cvpcb.cpp:134
#define _(s)
@ FRAME_FOOTPRINT_VIEWER
Definition: frame_type.h:42
@ FRAME_FOOTPRINT_EDITOR
Definition: frame_type.h:41
@ FRAME_CVPCB
Definition: frame_type.h:48
@ MAIL_RELOAD_LIB
Definition: mail_type.h:55

References _, KIWAY::ExpressMail(), PROJECT::FootprintLibTblName(), FRAME_CVPCB, 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, MAIL_RELOAD_LIB, PROJECT::PcbFootprintLibs(), KIWAY::Prj(), LIB_TABLE::Save(), KIWAY_HOLDER::SetKiway(), and IO_ERROR::What().

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